1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package test.wsmo4j.common;
19
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.wsmo.common.Entity;
24 import org.wsmo.common.IRI;
25
26 import test.wsmo4j.Wsmo4jTestCase;
27
28
29
30
31
32
33
34
35
36 public class NFPTest extends Wsmo4jTestCase {
37
38 private Entity entity;
39 private IRI iri;
40 private String ns = "http://example.org/";
41
42 public void setUp() throws Exception {
43 super.setUp();
44 iri = createIRI(ns+"a");
45 }
46
47 public void testAddRemoveNFPwithIRI() throws Exception {
48 createEntityWithNoNFP();
49
50 entity.addNFPValue(iri, createIRI(ns+"iri1"));
51 assertEquals("Size does not change after new NFP was added!",
52 entity.listNFPValues().size(), 1);
53
54 entity.removeNFP(iri);
55 assertEquals("Size does not change after new NFP was removed!",
56 entity.listNFPValues(createIRI(ns+"a")).size(), 0);
57
58 entity.addNFPValue(iri, createIRI(ns+"iri1"));
59 entity.addNFPValue(iri, createIRI(ns+"iri2"));
60 entity.addNFPValue(iri, createIRI(ns+"iri3"));
61
62
63 assertEquals("NFP values are not stored as an array!",
64 entity.listNFPValues().size(), 1);
65 assertEquals("NFP values array not stored as an array!",
66 entity.listNFPValues(createIRI(ns+"a")).size(), 3);
67
68 Map map = entity.listNFPValues();
69 Set set = entity.listNFPValues(createIRI(ns+"a"));
70
71 assertEquals("NFP values listed by key and all are not eqaul",
72 map.get(iri), set);
73
74 entity.removeNFPValue(iri, createIRI(ns+"iri3"));
75 assertEquals("NFP values are not removed from the key array",
76 entity.listNFPValues(iri).size(), 2);
77
78 entity.removeNFP(iri);
79 assertEquals("All NFP values are note removed",
80 entity.listNFPValues().size(), 0);
81 }
82
83 private void createEntityWithNoNFP() throws Exception {
84 String iriString = "http://testConcept";
85 for (;;) {
86 IRI iri = createIRI(iriString);
87 entity = factory.createConcept(iri);
88 if (entity.listNFPValues().size() == 0)
89 break;
90 iriString += "1";
91 }
92 }
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106