001: package org.ontoware.rdfreactor.runtime;
002:
003: import junit.framework.TestCase;
004:
005: import static org.junit.Assert.*;
006:
007: import org.junit.Assert;
008: import org.junit.Before;
009: import org.junit.Ignore;
010: import org.junit.Test;
011: import org.ontoware.rdf2go.RDF2Go;
012: import org.ontoware.rdf2go.exception.ModelRuntimeException;
013: import org.ontoware.rdf2go.model.node.URI;
014: import org.ontoware.rdf2go.model.node.impl.URIImpl;
015: import org.ontoware.rdf2go.vocabulary.RDF;
016: import org.ontoware.rdfreactor.runtime.example.Person;
017:
018: @SuppressWarnings("unused")
019: public class PersonTest {
020:
021: protected org.ontoware.rdf2go.model.node.URI instanceURI;
022:
023: protected org.ontoware.rdf2go.model.Model model;
024:
025: @Before
026: public void setUp() throws Exception {
027: model = RDF2Go.getModelFactory().createModel();
028: model.open();
029: model.removeAll();
030: instanceURI = new URIImpl("data://person-1");
031: }
032:
033: public void testTyping() throws Exception {
034: URI jim = new URIImpl("data://jim");
035: Person p = new Person(model, jim, true);
036: Assert.assertTrue(model.contains(jim, RDF.type, Person.PERSON));
037: }
038:
039: // //////////////
040: // specific tests
041:
042: public void testSetAge() throws RDFDataException {
043: Person p = new Person(model, instanceURI, true);
044: p.setAge(18);
045: int age = p.getAge();
046: assertEquals(18, age);
047: }
048:
049: public void testSetName() throws RDFDataException {
050: Person p = new Person(model, instanceURI, true);
051: p.setName("Max Mustermann");
052: assertEquals("Max Mustermann", p.getName());
053: }
054:
055: public void testHashCode() throws ModelRuntimeException {
056: Person p1 = new Person(model, instanceURI, true);
057: Person p2 = new Person(model, instanceURI, true);
058: Person p3 = new Person(model, new URIImpl("test://otheruri"),
059: true);
060: assertEquals(p1.hashCode(), p2.hashCode());
061: assertNotSame(p1.hashCode(), p3.hashCode());
062: }
063:
064: public void testReactorBaseNamed() {
065: }
066:
067: /*
068: * Class under test for boolean equals(Object)
069: */
070: public void testEqualsObject() throws ModelRuntimeException {
071: Person p1 = new Person(model, instanceURI, true);
072: Person p2 = new Person(model, instanceURI, true);
073: Person p3 = new Person(model, new URIImpl("test://otheruri"),
074: true);
075: assertEquals(p1, p2);
076: assertNotSame(p1, p3);
077: }
078:
079: public void testGetURI() {
080: Person p1 = new Person(model, instanceURI, true);
081: assertEquals(instanceURI, p1.getResource());
082: }
083:
084: /*
085: * Class under test for String toString()
086: */
087: public void testToString() {
088: }
089:
090: public void testGet() throws RDFDataException {
091: Person p1 = new Person(model, instanceURI, true);
092: Integer a = p1.getAge();
093: Assert.assertNull(a);
094: p1.setAge(21);
095: assertEquals(21, (int) p1.getAge());
096: }
097:
098: public void testGetAll() {
099: }
100:
101: public void testSet() {
102: }
103:
104: public void testSetAll() {
105: }
106:
107: public void testUpdate() {
108: }
109:
110: public void testTwoStatements() throws Exception {
111: model.addStatement(instanceURI, instanceURI, "a");
112: model.addStatement(instanceURI, instanceURI, "b");
113: }
114:
115: @Ignore("outdated")
116: @Test
117: public void testAdd() throws Exception {
118: // create Person p
119: Person p = new Person(model, new URIImpl("data://jim"), true);
120: assertTrue("model contains a Person after add", model.contains(
121: p.getResource(), RDF.type, Person.PERSON));
122:
123: // set name
124: p.setName("Jim");
125:
126: assert model.contains(p.getResource(), RDF.type, Person.PERSON);
127: assert model.contains(p.getResource(), Person.NAME, "Jim");
128:
129: // create Persons q1 and q2
130: Person q1 = new Person(model, new URIImpl("data://jon"), true);
131: q1.setName("Jon");
132: Person q2 = new Person(model, new URIImpl("data://joe"), true);
133: q2.setName("Joe");
134:
135: // add friends
136: assertEquals(0, p.getAllFriend().length);
137: p.addFriend(q1);
138: assertEquals(1, p.getAllFriend().length);
139: p.addFriend(q2);
140: assertEquals(2, p.getAllFriend().length);
141: }
142:
143: @Ignore("outdated")
144: @Test
145: public void testRemove() throws ModelRuntimeException {
146: Person p = new Person(model, instanceURI, true);
147: Person q = new Person(model, new URIImpl("data://p1"), true);
148: Person q2 = new Person(model, new URIImpl("data://p2"), true);
149: p.addFriend(q);
150: p.addFriend(q2);
151: assertEquals(2, p.getAllFriend().length);
152:
153: assertTrue(model.contains(p.getResource(), Person.HAS_FRIEND,
154: q2.getResource()));
155:
156: assertTrue(p.removeFriend(q2));
157: assertEquals(1, p.getAllFriend().length);
158: }
159:
160: public void testRemoveAll() {
161: }
162:
163: // /*
164: // * Class under test for Statement getStatement(URI, ReactorBaseNamed)
165: // */
166: // public void testGetStatementURIReactorBaseNamed() {
167: // Person p = new Person(model, instanceURI);
168: // Statement s = p.getStatement(Person.NAME, "Jim");
169: // assertEquals("Jim", s.getObject());
170: // assertEquals(p.getURI(), s.getSubject());
171: // assertEquals(Person.NAME, s.getPredicate());
172: // }
173:
174: public void testDelete() {
175: }
176:
177: /*
178: * Class under test for Statement getStatement(URI, String)
179: */
180: public void testGetStatementURIString() {
181: }
182:
183: }
|