Mercurial > hg > org.digitalhps.storage.triplestoreimplementation
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:33d1589a61a7 |
---|---|
1 package org.digitalhps.storage.triplestoreimplementation.tests; | |
2 | |
3 | |
4 import org.digitalhps.storage.triplestoreimplementation.events.CreationEvent; | |
5 import org.digitalhps.storage.triplestoreimplementation.events.RelationEvent; | |
6 import org.digitalhps.storage.triplestoreimplementation.exceptions.JSONToObjectTransformException; | |
7 import org.digitalhps.storage.triplestoreimplementation.exceptions.JSONandClassMissmatchException; | |
8 import org.digitalhps.storage.triplestoreimplementation.exceptions.ObjectToJSONTransformException; | |
9 import org.digitalhps.storage.triplestoreimplementation.handler.events.RelationEvents; | |
10 import org.digitalhps.storage.triplestoreimplementation.utils.JSONTools; | |
11 import org.json.JSONException; | |
12 import org.json.JSONObject; | |
13 import org.openrdf.repository.RepositoryException; | |
14 import org.restlet.ext.json.JsonRepresentation; | |
15 import org.restlet.representation.Representation; | |
16 | |
17 import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException; | |
18 | |
19 | |
20 public class EventsTest { | |
21 | |
22 /** | |
23 * @param args | |
24 */ | |
25 public static void main(String[] args) { | |
26 RelationEvents relEv = new RelationEvents(); | |
27 | |
28 CreationEvent ce = new CreationEvent(); | |
29 System.out.println(ce.getId()); | |
30 String source = "{\"sourceReference\":\"sr\"," + | |
31 " \"predecessors\":[{\"id\":\"1\"},{\"id\":\"1\"}] "+ | |
32 "}"; | |
33 | |
34 System.out.println(source); | |
35 JSONObject map; | |
36 try { | |
37 map = new JSONObject(source); | |
38 } catch (JSONException e) { | |
39 // TODO Auto-generated catch block | |
40 e.printStackTrace(); | |
41 return; | |
42 } | |
43 | |
44 Object ob; | |
45 try { | |
46 ob = JSONTools.createObject(RelationEvent.class, map); | |
47 } catch (JSONandClassMissmatchException e) { | |
48 // TODO Auto-generated catch block | |
49 e.printStackTrace(); | |
50 return; | |
51 } catch (JSONToObjectTransformException e) { | |
52 // TODO Auto-generated catch block | |
53 e.printStackTrace(); | |
54 return; | |
55 } | |
56 Object ret; | |
57 try { | |
58 ret = JSONTools.transformToJson(ob); | |
59 } catch (ObjectToJSONTransformException e) { | |
60 // TODO Auto-generated catch block | |
61 e.printStackTrace(); | |
62 return; | |
63 } | |
64 | |
65 System.out.println(ret); | |
66 Representation example = new JsonRepresentation(map); | |
67 relEv.handleJSON(example); | |
68 System.out.println(relEv); | |
69 | |
70 try { | |
71 relEv.writeEventToTripleStore(ob, false); | |
72 } catch (RepositoryException e) { | |
73 // TODO Auto-generated catch block | |
74 e.printStackTrace(); | |
75 } catch (TripleStoreHandlerException e) { | |
76 // TODO Auto-generated catch block | |
77 e.printStackTrace(); | |
78 } catch (ObjectToJSONTransformException e) { | |
79 // TODO Auto-generated catch block | |
80 e.printStackTrace(); | |
81 } | |
82 } | |
83 | |
84 } |