Mercurial > hg > org.digitalhps.storage.triplestoreimplementation
diff src/org/digitalhps/storage/triplestoreimplementation/tests/EventsTest.java @ 0:33d1589a61a7 default tip
initial
author | dwinter |
---|---|
date | Thu, 08 Dec 2011 09:18:00 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/digitalhps/storage/triplestoreimplementation/tests/EventsTest.java Thu Dec 08 09:18:00 2011 +0100 @@ -0,0 +1,84 @@ +package org.digitalhps.storage.triplestoreimplementation.tests; + + +import org.digitalhps.storage.triplestoreimplementation.events.CreationEvent; +import org.digitalhps.storage.triplestoreimplementation.events.RelationEvent; +import org.digitalhps.storage.triplestoreimplementation.exceptions.JSONToObjectTransformException; +import org.digitalhps.storage.triplestoreimplementation.exceptions.JSONandClassMissmatchException; +import org.digitalhps.storage.triplestoreimplementation.exceptions.ObjectToJSONTransformException; +import org.digitalhps.storage.triplestoreimplementation.handler.events.RelationEvents; +import org.digitalhps.storage.triplestoreimplementation.utils.JSONTools; +import org.json.JSONException; +import org.json.JSONObject; +import org.openrdf.repository.RepositoryException; +import org.restlet.ext.json.JsonRepresentation; +import org.restlet.representation.Representation; + +import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException; + + +public class EventsTest { + + /** + * @param args + */ + public static void main(String[] args) { + RelationEvents relEv = new RelationEvents(); + + CreationEvent ce = new CreationEvent(); + System.out.println(ce.getId()); + String source = "{\"sourceReference\":\"sr\"," + + " \"predecessors\":[{\"id\":\"1\"},{\"id\":\"1\"}] "+ + "}"; + + System.out.println(source); + JSONObject map; + try { + map = new JSONObject(source); + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + + Object ob; + try { + ob = JSONTools.createObject(RelationEvent.class, map); + } catch (JSONandClassMissmatchException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } catch (JSONToObjectTransformException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + Object ret; + try { + ret = JSONTools.transformToJson(ob); + } catch (ObjectToJSONTransformException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + + System.out.println(ret); + Representation example = new JsonRepresentation(map); + relEv.handleJSON(example); + System.out.println(relEv); + + try { + relEv.writeEventToTripleStore(ob, false); + } catch (RepositoryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TripleStoreHandlerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ObjectToJSONTransformException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +}