001: package org.ontoware.semversion;
002:
003: import static org.junit.Assert.assertEquals;
004: import static org.junit.Assert.assertNotNull;
005: import static org.junit.Assert.assertTrue;
006:
007: import java.io.File;
008:
009: import org.junit.After;
010: import org.junit.Before;
011: import org.junit.Test;
012: import org.ontoware.rdf2go.model.Model;
013: import org.ontoware.rdf2go.model.Statement;
014: import org.ontoware.rdf2go.model.node.URI;
015: import org.ontoware.rdf2go.model.node.impl.URIImpl;
016: import org.ontoware.semversion.impl.BlankNodeEnrichmentModel;
017:
018: /**
019: *
020: * branch - to tylko etykieta dla zbioru wersji, nie ma wlasciwie takiego
021: * obiektu w systemie jak branch poza zwyklym stringiem jako property dla
022: * ontologii
023: *
024: * root (model) - branch (model) - branch (model)
025: */
026: public class MarcOntTests {
027:
028: private SemVersion semVersion;
029:
030: URI s1 = new URIImpl("urn:test:s1");
031: URI s2 = new URIImpl("urn:test:s2");
032: URI s3 = new URIImpl("urn:test:s3");
033: URI s4 = new URIImpl("urn:test:s4");
034: URI s5 = new URIImpl("urn:test:s5");
035: URI s6 = new URIImpl("urn:test:s6");
036: URI p = new URIImpl("urn:test:p");
037: URI o = new URIImpl("urn:test:o");
038:
039: /**
040: * Create versionedmodel "NewThread", create a new model with two triples,
041: * commit it as root
042: *
043: * @throws Exception
044: */
045: @Before
046: public void setUp() throws Exception {
047:
048: semVersion = new SemVersion();
049: semVersion.startup(new File("./target/tmp/MarcOntUseCase"));
050: semVersion.deleteStore();
051: semVersion.createUser("User", "secret");
052: semVersion.createUser("Admin", "secret");
053:
054: Session session = semVersion.login("Admin", "secret");
055: VersionedModel vm = session.createVersionedModel("NewThread");
056:
057: Model model = session.getModel();
058: model.addStatement(s1, p, o);
059: model.addStatement(s2, p, o);
060: assertEquals(2, model.size());
061: vm.commitRoot(model, "FirstMainVersion");
062: session.close();
063: }
064:
065: @After
066: public void tearDown() throws Exception {
067: semVersion.shutdown();
068: }
069:
070: @Test
071: public void testModel() throws LoginException {
072: Session session = semVersion.login("User", "secret");
073:
074: Model model = session.getModel();
075:
076: Statement s = model.createStatement(s1, p, o);
077: model.addStatement(s);
078: assertTrue(model.contains(s1, p, o));
079: model.removeStatement(s);
080:
081: model.addStatement(s1, p, o);
082: assertTrue(model.contains(s1, p, o));
083:
084: model.addStatement(s2, p, o);
085: assertTrue(model.contains(s2, p, o));
086:
087: assertEquals(2, model.size());
088: session.close();
089: }
090:
091: @Test
092: public void testSV15noLabel() throws Exception {
093: Session session = semVersion.login("User", "secret");
094: VersionedModel vm = session.getVersionedModel("NewThread");
095:
096: Version v = vm.getRoot();
097: Model s1 = v.getContent();
098: s1.addStatement(s3, p, o);
099:
100: String label = "LABEL";
101: String comment = "COMMENT";
102:
103: // Note: This sets the commit 'comment' to the string "LABEL"
104: Version childVersion = v.commit(s1, label, false);
105:
106: // This does the same.
107: childVersion.setComment(comment);
108:
109: // Setting the label
110: childVersion.setLabel(label);
111:
112: URI uri = childVersion.getURI();
113:
114: session.close();
115:
116: session = semVersion.login("User", "secret");
117: vm = session.getVersionedModel("NewThread");
118:
119: v = vm.getVersion(uri);
120:
121: assertTrue(v.getComment().compareTo(comment) == 0);
122: assertNotNull(v.getLabel());
123: assertTrue(v.getLabel().compareTo(label) == 0);
124: }
125:
126: /**
127: * This one works fine
128: */
129: @Test
130: public void addingFewSuggestions() throws LoginException {
131:
132: Session session = semVersion.login("User", "secret");
133: VersionedModel vm = session.getVersionedModel("NewThread");
134:
135: Version v = vm.getRoot();
136: Model suggestion1 = v.getContent();
137: assertEquals(2, suggestion1.size());
138: assertTrue(suggestion1.contains(s1, p, o));
139: assertTrue(suggestion1.contains(s2, p, o));
140: suggestion1.addStatement(s3, p, o);
141: assertTrue(suggestion1.contains(s3, p, o));
142:
143: // commit s1 as a suggestion to root
144: // result: root > suggestion1
145: v.commit(suggestion1, "first sug. comment", true);
146:
147: Model suggestion2 = v.getContent();
148: assertEquals(2, suggestion2.size());
149: suggestion2.addStatement(s4, p, o);
150: v.commit(suggestion2, "second sug. comment", true);
151: // result: root has two children > suggestion1, suggestion2
152:
153: Model suggestion3 = v.getContent();
154: suggestion3.addStatement(s5, p, o);
155: v.commit(suggestion3, "third sug. comment", true);
156: // result: root has three children > suggestion1, suggestion2,
157: // suggestion3
158:
159: Model suggestion4 = v.getContent();
160: suggestion4.addStatement(s6, p, o);
161: v.commit(suggestion4, "fourth sug. comment", true);
162: // result: root has four children > suggestion1, suggestion2,
163: // suggestion3, suggestion4
164:
165: System.out.println(vm.getAllBranches().size());
166: System.out.println(vm.getAllVersions().size());
167:
168: assertTrue(vm.getAllBranches().size() == 1);
169: assertTrue(vm.getAllVersions().size() == 5);
170:
171: // semVersion.dump();
172:
173: session.close();
174: }
175:
176: /**
177: * Here I add to a root model: 1) One suggestion 2) One sub-version 3)
178: * Second suggestion - and I get exception - why?
179: *
180: * I assume that one version can have n suggestions but only 1 sub-version
181: * and after adding this sub-version I can't add anything more to the parent
182: * node - suggestion, nor sub-version. Am I right?
183: *
184: * @throws LoginException
185: */
186: @Test
187: public void addingFewVersions() throws LoginException {
188:
189: Session session = semVersion.login("User", "secret");
190: VersionedModel vm = session.getVersionedModel("NewThread");
191:
192: Version v = vm.getRoot();
193: assertNotNull(v);
194:
195: Model suggestion1 = v.getContent();
196: suggestion1.addStatement(s3, p, o);
197: v.commit(suggestion1, "first sug. comment", true);
198: // result: root > suggestion1
199:
200: Model childVersion1 = v.getContent();
201: childVersion1.addStatement(s4, p, o);
202: v.commit(childVersion1, "first subver. comment", false);
203: // result: root > suggestion1, childVersion1
204:
205: Model suggestion2 = v.getContent();
206: suggestion2.addStatement(s5, p, o);
207: v.commit(suggestion2, "second sug. comment", true);
208: // result: root > suggestion1, childVersion1, suggestion2
209:
210: session.close();
211: }
212:
213: /**
214: * This one works fine
215: */
216: @Test
217: public void addingVersions2LvlDepth() throws LoginException {
218:
219: Session session = semVersion.login("User", "secret");
220: VersionedModel vm = session.getVersionedModel("NewThread");
221:
222: Version v = vm.getRoot();
223:
224: Model s1 = v.getContent();
225: s1.addStatement("http://third", new URIImpl("http://test/uri"),
226: "http://triple");
227: Version child = v.commit(s1, "first ver. comment", false);
228: URI uri = child.getURI();
229:
230: Version ver = vm.getVersion(uri);
231:
232: Model s2 = ver.getContent();
233: s2.addStatement("http://fourth",
234: new URIImpl("http://test/uri"), "http://triple");
235: ver.commit(s2, "second ver. comment", true);
236:
237: Model s3 = ver.getContent();
238: s3.addStatement("http://fifth", new URIImpl("http://test/uri"),
239: "http://triple");
240: ver.commit(s3, "second ver. comment", false);
241:
242: // semVersion.dump();
243:
244: session.close();
245: }
246:
247: /**
248: * Here I try to add a sub-version to root version, successfully. Then I try
249: * to add a sub-version to added sub-version, successfully. But when I try
250: * to add another sub-version to the latest added node, I get an exception.
251: * Why?
252: *
253: * @throws LoginException
254: */
255: @Test
256: public void addingVersions3LvlDepth() throws LoginException {
257:
258: Session session = semVersion.login("User", "secret");
259: VersionedModel vm = session.getVersionedModel("NewThread");
260:
261: Version rootVersion = vm.getRoot();
262:
263: Model childVersion1 = rootVersion.getContent();
264: assertTrue(childVersion1 instanceof BlankNodeEnrichmentModel);
265: childVersion1.addStatement(s3, p, o);
266: Version child = rootVersion.commit(childVersion1,
267: "first ver. comment", false);
268: URI uri = child.getURI();
269:
270: Version ver = vm.getVersion(uri);
271:
272: Model childVersion2 = ver.getContent();
273: assertTrue(childVersion2 instanceof BlankNodeEnrichmentModel);
274: childVersion2.addStatement(s4, p, o);
275: Version ver2 = ver.commit(childVersion2, "second ver. comment",
276: false);
277:
278: Model childVersion3 = ver2.getContent();
279: assertTrue(childVersion3 instanceof BlankNodeEnrichmentModel);
280: childVersion3.addStatement(s5, p, o);
281: ver2.commit(childVersion3, "second ver. comment", false);
282:
283: // semVersion.dump();
284:
285: session.close();
286: }
287:
288: /**
289: * Here I add to a root model: 1) One suggestion 2) One sub-version 3)
290: * Suggestion to sub-version added in point 2 and I get exception - why? I
291: * assume it should work. Do I understand right?
292: *
293: * @throws LoginException
294: */
295: @Test
296: public void addingSuggestionVersionSuggestion()
297: throws LoginException {
298:
299: Session session = semVersion.login("User", "secret");
300: VersionedModel vm = session.getVersionedModel("NewThread");
301:
302: Version v = vm.getRoot();
303:
304: Model s1 = v.getContent();
305: s1.addStatement("http://third", new URIImpl("http://test/uri"),
306: "http://triple");
307: v.commit(s1, "first sug. comment", true);
308:
309: Model s2 = v.getContent();
310: s2.addStatement("http://fourth",
311: new URIImpl("http://test/uri"), "http://triple");
312: v.commit(s2, "first subver. comment", true);
313:
314: Model s3 = v.getContent();
315: s3.addStatement("http://fifth", new URIImpl("http://test/uri"),
316: "http://triple");
317: Version ver = v.commit(s3, "second sug. comment", false);
318:
319: Model s4 = ver.getContent();
320: s4.addStatement("http://sixth", new URIImpl("http://test/uri"),
321: "http://triple");
322: ver.commit(s4, "comment", true);
323:
324: // semVersion.dump();
325:
326: session.close();
327: }
328:
329: }
|