1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3   
4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
5   
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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   * <p>Title: WSMO4J</p>
30   * <p>Description: WSMO API and a Reference Implementation</p>
31   * <p>Copyright:  Copyright (c) 2004-2005</p>
32   * <p>Company: OntoText Lab. / SIRMA </p>
33   * @author not attributable
34   * @version 1.0
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          // all the NFP with the same key are stored in set!
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   * $Log$
97   * Revision 1.4  2005/11/04 06:14:26  holgerlausen
98   * fixed unit tests relying on relative iris
99   *
100  * Revision 1.3  2005/09/12 15:17:53  vassil_momtchev
101  * new line at log section added
102  *
103  * Revision 1.2  2005/09/12 14:41:17  vassil_momtchev
104  * log added
105  *
106  */