Source Code Cross Referenced for NotifyingModelTest.java in  » Search-Engine » semweb4j » org » ontoware » rdf2go » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » semweb4j » org.ontoware.rdf2go.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 java.util.Iterator;
015:
016:        import org.ontoware.rdf2go.ModelFactory;
017:        import org.ontoware.rdf2go.RDF2Go;
018:        import org.ontoware.rdf2go.exception.ModelRuntimeException;
019:        import org.ontoware.rdf2go.model.impl.DiffImpl;
020:        import org.ontoware.rdf2go.model.impl.NotifyingModelLayer;
021:        import org.ontoware.rdf2go.model.impl.StatementImpl;
022:        import org.ontoware.rdf2go.model.impl.TriplePatternImpl;
023:        import org.ontoware.rdf2go.model.node.Variable;
024:        import org.ontoware.rdf2go.model.node.impl.PlainLiteralImpl;
025:
026:        public class NotifyingModelTest extends AbstractModelTest {
027:            // abstract superclass for ModelchangeListeners in this test. By default,
028:            // no method of the changelistener should be called, if a method is expected
029:            // to be called, this method has to be overwritten.
030:
031:            NotifyingModelLayer model;
032:
033:            @Override
034:            public ModelFactory getModelFactory() {
035:                return RDF2Go.getModelFactory();
036:            }
037:
038:            @Override
039:            public void setUp() throws ModelRuntimeException, Exception {
040:                super .setUp();
041:                Model plainModel = getModelFactory().createModel();
042:                assertNotNull(plainModel);
043:                this .model = new NotifyingModelLayer(plainModel);
044:            }
045:
046:            public void testModelConnection() {
047:                assertNotNull(this .model);
048:                assertNotNull(this .model.getDelegatedModel());
049:                assertFalse(this .model.isOpen());
050:                this .model.open();
051:                assertTrue(this .model.isOpen());
052:                this .model.close();
053:                assertFalse(this .model.isOpen());
054:            }
055:
056:            public void testAddStatement() {
057:                this .model.open();
058:                this .model.addStatement(predicate, object, subject); // this statement should
059:                // not cause a
060:                // notification
061:                this .model
062:                        .addModelChangedListener(new AbstractModelChangeListener() {
063:
064:                            @Override
065:                            public void addedStatement(Statement statement) {
066:                                assertEquals(new StatementImpl(null, subject,
067:                                        predicate, object), statement);
068:                            }
069:
070:                            @Override
071:                            public void addedStatements(
072:                                    Iterator<? extends Statement> statements) {
073:                                assertTrue(statements.hasNext());
074:                                assertEquals(new StatementImpl(null, subject,
075:                                        predicate, object), statements.next());
076:                                assertFalse(statements.hasNext());
077:                            }
078:                        });
079:                this .model.addStatement(subject, predicate, object);
080:                this .model.close();
081:            }
082:
083:            public void testRemoveStatement() {
084:                this .model.open();
085:                this .model.addStatement(subject, predicate, object);
086:
087:                this .model
088:                        .addModelChangedListener(new AbstractModelChangeListener() {
089:
090:                            @Override
091:                            public void removedStatement(Statement statement) {
092:                                assertEquals(new StatementImpl(null, subject,
093:                                        predicate, object), statement);
094:                            }
095:
096:                            @Override
097:                            public void removedStatements(
098:                                    Iterator<? extends Statement> statements) {
099:                                assertTrue(statements.hasNext());
100:                                assertEquals(new StatementImpl(null, subject,
101:                                        predicate, object), statements.next());
102:                                assertFalse(statements.hasNext());
103:                            }
104:                        });
105:                this .model.close();
106:            }
107:
108:            public void testChangeStatement() {
109:                this .model
110:                        .addModelChangedListener(new AbstractModelChangeListener() {
111:                            @Override
112:                            public void performedUpdate(DiffReader diff) {
113:                                int i = 0;
114:                                for (Statement s : diff.getAdded()) {
115:                                    i++;
116:                                    assertEquals(new StatementImpl(null,
117:                                            subject, predicate, object), s);
118:                                }
119:                                assertEquals(1, i);
120:                                assertFalse(diff.getRemoved().iterator()
121:                                        .hasNext());
122:                            }
123:                        });
124:                this .model.open();
125:                Diff diff = new DiffImpl();
126:                diff.addStatement(subject, predicate, object);
127:                this .model.update(diff);
128:                this .model.close();
129:            }
130:
131:            public void testNotificationOnSubject() {
132:                this .model.open();
133:                ModelChangedListener listener = new AbstractModelChangeListener() {
134:                    @Override
135:                    public void addedStatement(Statement statement) {
136:                        assertEquals(subject, statement.getSubject());
137:                        assertEquals(predicate, statement.getPredicate());
138:                    }
139:
140:                    @Override
141:                    public void addedStatements(
142:                            Iterator<? extends Statement> statements) {
143:                        assertTrue(statements.hasNext());
144:                        Statement next = statements.next();
145:                        assertEquals(subject, next.getSubject());
146:                        assertEquals(predicate, next.getPredicate());
147:                        assertFalse(statements.hasNext());
148:                    }
149:                };
150:                this .model.addModelChangedListener(listener,
151:                        new TriplePatternImpl(subject, Variable.ANY,
152:                                Variable.ANY));
153:
154:                this .model.addStatement(subject, predicate, "Test1");
155:                this .model.addStatement(predicate, object, "Test2");
156:                this .model.addStatement(predicate, subject, "Test3");
157:                this .model.removeModelChangedListener(listener);
158:                listener = new AbstractModelChangeListener() {
159:                    @Override
160:                    public void removedStatement(Statement statement) {
161:                        assertEquals(subject, statement.getSubject());
162:                        assertEquals(predicate, statement.getPredicate());
163:                    }
164:
165:                    @Override
166:                    public void removedStatements(
167:                            Iterator<? extends Statement> statements) {
168:                        assertTrue(statements.hasNext());
169:                        Statement next = statements.next();
170:                        assertEquals(subject, next.getSubject());
171:                        assertEquals(predicate, next.getPredicate());
172:                        assertFalse(statements.hasNext());
173:                    }
174:                };
175:                this .model.removeStatement(subject, predicate, "Test1");
176:                this .model.removeStatement(predicate, object, "Test2");
177:                this .model.removeStatement(predicate, subject, "Test3");
178:                this .model.close();
179:            }
180:
181:            public void testNotificationOnLiteralObject() {
182:                this .model.open();
183:                ModelChangedListener listener = new AbstractModelChangeListener() {
184:                    @Override
185:                    public void addedStatement(Statement statement) {
186:                        assertEquals(new PlainLiteralImpl("Sebastian"),
187:                                statement.getObject());
188:                    }
189:                };
190:                this .model.addModelChangedListener(listener,
191:                        new TriplePatternImpl(Variable.ANY, Variable.ANY,
192:                                new PlainLiteralImpl("Sebastian")));
193:                this .model.addStatement(subject, predicate, "Sebastian Gerke");
194:                this .model.addStatement(predicate, object, "Sebastian");
195:                this .model.close();
196:            }
197:
198:            public void testNotificationOnPredicateAndObject() {
199:                this .model.open();
200:                ModelChangedListener listener = new AbstractModelChangeListener() {
201:                    @Override
202:                    public void addedStatement(Statement statement) {
203:                        System.out.println(statement.getObject().getClass());
204:                        assertEquals(new PlainLiteralImpl("Sebastian"),
205:                                statement.getObject());
206:                        assertEquals(predicate, statement.getPredicate());
207:                    }
208:                };
209:                this .model.addModelChangedListener(listener,
210:                        new TriplePatternImpl(Variable.ANY, predicate,
211:                                new PlainLiteralImpl("Sebastian")));
212:                this .model.addStatement(subject, predicate, "Sebastian Gerke");
213:                this .model.addStatement(subject, predicate, "Sebastian");
214:                this .model.addStatement(predicate, object, "Sebastian");
215:                this.model.close();
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.