001: /*
002: * LICENSE INFORMATION
003: * Copyright 2005-2007 by FZI (http://www.fzi.de).
004: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
005: * <OWNER> = Max V�lkel
006: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
007: * <YEAR> = 2007
008: *
009: * Project information at http://semweb4j.org/rdf2go
010: */
011:
012: package org.ontoware.rdf2go.model;
013:
014: import org.ontoware.rdf2go.ModelFactory;
015: import org.ontoware.rdf2go.RDF2Go;
016: import org.ontoware.rdf2go.model.impl.NotifyingModelSetLayer;
017: import org.ontoware.rdf2go.model.impl.QuadPatternImpl;
018: import org.ontoware.rdf2go.model.node.URI;
019: import org.ontoware.rdf2go.model.node.Variable;
020: import org.ontoware.rdf2go.model.node.impl.PlainLiteralImpl;
021: import org.ontoware.rdf2go.model.node.impl.URIImpl;
022:
023: public class NotifyingModelSetTest extends AbstractModelSetTest {
024: private NotifyingModelSetLayer model;
025: public static URI context1 = new URIImpl("test://test/context_1");
026: public static URI context2 = new URIImpl("test://test/context_2");
027:
028: public NotifyingModelSetTest() {
029:
030: }
031:
032: @Override
033: public ModelFactory getModelFactory() {
034: return RDF2Go.getModelFactory();
035: }
036:
037: @Override
038: public void setUp() throws Exception {
039: super .setUp();
040: ModelSet plainModel = getModelFactory().createModelSet();
041: assertNotNull(plainModel);
042: model = new NotifyingModelSetLayer(plainModel);
043: }
044:
045: public void testModelConnection() {
046: assertNotNull(model);
047: assertNotNull(model.getDelegatedModelSet());
048: assertFalse(model.isOpen());
049: model.open();
050: assertTrue(model.isOpen());
051: model.close();
052: assertFalse(model.isOpen());
053: }
054:
055: public void testContextNotification() {
056: ModelChangedListener listener = new AbstractModelChangeListener() {
057: public void addedStatement(Statement statement) {
058: assertEquals(context1, statement.getContext());
059: assertEquals(subject, statement.getSubject());
060: assertEquals(predicate, statement.getPredicate());
061: assertEquals(object, statement.getObject());
062: }
063: };
064: QuadPattern pattern = new QuadPatternImpl(context1,
065: Variable.ANY, Variable.ANY, Variable.ANY);
066: model.addModelSetChangedListener(listener, pattern);
067: model.open();
068: model.addStatement(context1, subject, predicate, object);
069: model.close();
070: }
071:
072: public void testContextNotification2() {
073: ModelChangedListener listener = new AbstractModelChangeListener() {
074: };
075: QuadPattern pattern = new QuadPatternImpl(context1,
076: Variable.ANY, Variable.ANY, Variable.ANY);
077: model.addModelSetChangedListener(listener, pattern);
078: model.open();
079: model.addStatement(context2, subject, predicate, object);
080: model.close();
081: }
082:
083: public void testSubjectNotification() {
084: ModelChangedListener listener = new AbstractModelChangeListener() {
085: public void addedStatement(Statement statement) {
086: assertEquals(context1, statement.getContext());
087: assertEquals(subject, statement.getSubject());
088: assertEquals(predicate, statement.getPredicate());
089: assertEquals(object, statement.getObject());
090: }
091: };
092: QuadPattern pattern = new QuadPatternImpl(Variable.ANY,
093: subject, Variable.ANY, Variable.ANY);
094: model.addModelSetChangedListener(listener, pattern);
095: model.open();
096: model.addStatement(context1, subject, predicate, object);
097: model.close();
098: }
099:
100: public void testSubjectNotification2() {
101: ModelChangedListener listener = new AbstractModelChangeListener() {
102: };
103: QuadPattern pattern = new QuadPatternImpl(Variable.ANY,
104: subject, Variable.ANY, Variable.ANY);
105: model.addModelSetChangedListener(listener, pattern);
106: model.open();
107: model.addStatement(context1, predicate, object, subject);
108: model.close();
109: }
110:
111: public void testLiteralNotification() {
112: ModelChangedListener listener = new AbstractModelChangeListener() {
113: public void addedStatement(Statement statement) {
114: assertEquals(context1, statement.getContext());
115: assertEquals(subject, statement.getSubject());
116: assertEquals(predicate, statement.getPredicate());
117: assertEquals(new PlainLiteralImpl("Sebastian Gerke"),
118: statement.getObject());
119: }
120: };
121: QuadPattern pattern = new QuadPatternImpl(Variable.ANY,
122: Variable.ANY, Variable.ANY, new PlainLiteralImpl(
123: "Sebastian Gerke"));
124: model.addModelSetChangedListener(listener, pattern);
125: model.open();
126: model.addStatement(context1, subject, predicate,
127: new PlainLiteralImpl("Sebastian Gerke"));
128: model.close();
129: }
130:
131: public void testLiteralNotification2() {
132: ModelChangedListener listener = new AbstractModelChangeListener() {
133: };
134: QuadPattern pattern = new QuadPatternImpl(Variable.ANY,
135: Variable.ANY, Variable.ANY, new PlainLiteralImpl(
136: "Sebastian"));
137: model.addModelSetChangedListener(listener, pattern);
138: model.open();
139: model.addStatement(context1, subject, predicate,
140: new PlainLiteralImpl("Sebastian Gerke"));
141: model.close();
142: }
143:
144: public void testContextAndSubjectNotification() {
145: ModelChangedListener listener = new AbstractModelChangeListener() {
146: public void addedStatement(Statement statement) {
147: assertEquals(context1, statement.getContext());
148: assertEquals(subject, statement.getSubject());
149: assertEquals(predicate, statement.getPredicate());
150: assertEquals(object, statement.getObject());
151: }
152: };
153: QuadPattern pattern = new QuadPatternImpl(context1, subject,
154: Variable.ANY, Variable.ANY);
155: model.addModelSetChangedListener(listener, pattern);
156: model.open();
157: model.addStatement(context1, subject, predicate, object);
158: model.close();
159: }
160:
161: public void testContextAndSubjectNotification2() {
162: ModelChangedListener listener = new AbstractModelChangeListener() {
163: };
164: QuadPattern pattern = new QuadPatternImpl(context1, subject,
165: Variable.ANY, Variable.ANY);
166: model.addModelSetChangedListener(listener, pattern);
167: model.open();
168: model.addStatement(context1, predicate, object, subject);
169: model.close();
170: }
171:
172: public void testContextAndSubjectNotification3() {
173: ModelChangedListener listener = new AbstractModelChangeListener() {
174: };
175: QuadPattern pattern = new QuadPatternImpl(context1, subject,
176: Variable.ANY, Variable.ANY);
177: model.addModelSetChangedListener(listener, pattern);
178: model.open();
179: model.addStatement(context2, subject, predicate, object);
180: model.close();
181: }
182:
183: public void testPredicateNotification() {
184: ModelChangedListener listener = new AbstractModelChangeListener() {
185: public void addedStatement(Statement statement) {
186: assertEquals(context1, statement.getContext());
187: assertEquals(subject, statement.getSubject());
188: assertEquals(predicate, statement.getPredicate());
189: assertEquals(object, statement.getObject());
190: }
191: };
192: QuadPattern pattern = new QuadPatternImpl(Variable.ANY,
193: Variable.ANY, predicate, Variable.ANY);
194: model.addModelSetChangedListener(listener, pattern);
195: model.open();
196: model.addStatement(context1, subject, predicate, object);
197: model.close();
198: }
199:
200: public void testPredicateNotification2() {
201: ModelChangedListener listener = new AbstractModelChangeListener() {
202: };
203: QuadPattern pattern = new QuadPatternImpl(Variable.ANY,
204: Variable.ANY, predicate, Variable.ANY);
205: model.addModelSetChangedListener(listener, pattern);
206: model.open();
207: model.addStatement(context1, predicate, object, subject);
208: model.close();
209: }
210:
211: }
|