예제 #1
0
  public void testNormalOperation2() throws IOException {

    TopicIF otherTopic = getTopicById(tm, "gamst");
    TopicIF otype = getTopicById(tm, "gamst");
    int numOcc = otherTopic.getOccurrences().size();

    // build params
    List plist = new ArrayList();
    plist.add(Collections.EMPTY_SET);
    plist.add(Collections.singleton(otherTopic));
    plist.add(Collections.singleton(otype));
    ActionParametersIF params = makeParameters(plist, "http://www.sf.net");
    ActionResponseIF response = makeResponse();

    // execute
    action.perform(params, response);

    // test
    assertFalse("Occurrence not added", numOcc >= otherTopic.getOccurrences().size());
    Iterator<OccurrenceIF> i = otherTopic.getOccurrences().iterator();
    boolean hasit = false;
    while (i.hasNext()) {
      OccurrenceIF foo = i.next();
      if (foo.getLocator().getAddress().equals("http://www.sf.net/")) hasit = true;
    }
    assertFalse("Occurrence is not set for the topic", !(hasit));
  }
예제 #2
0
  public void testEmptyURLNoOccurrence() throws IOException {
    TopicIF topic = getTopicById(tm, "tromso");
    TopicIF otype = getTopicById(tm, "tromso");
    int occsbefore = topic.getOccurrences().size();

    List plist = new ArrayList();
    plist.add(Collections.EMPTY_SET);
    plist.add(Collections.singleton(topic));
    plist.add(Collections.singleton(otype));
    ActionParametersIF params = makeParameters(plist, "");
    ActionResponseIF response = makeResponse();
    action.perform(params, response);

    int occsnow = topic.getOccurrences().size();
    assertTrue("Occurrence was created or deleted", occsbefore == occsnow);
  }
예제 #3
0
  public void testEmptyURL() throws IOException {
    TopicIF topic = getTopicById(tm, "tromso");
    OccurrenceIF occ = getOccurrenceWithLocator(topic);
    int occsbefore = topic.getOccurrences().size();

    ActionParametersIF params = makeParameters(occ, "");
    ActionResponseIF response = makeResponse();
    try {
      action.perform(params, response);
      fail("Malformed url for locator");
    } catch (ActionRuntimeException e) {
    }

    int occsnow = topic.getOccurrences().size();
    assertTrue("Occurrence deleted from parent topic", occsbefore == occsnow);
  }
예제 #4
0
 protected OccurrenceIF getOccurrenceWithLocator(TopicIF topic) {
   Iterator<OccurrenceIF> it = topic.getOccurrences().iterator();
   while (it.hasNext()) {
     OccurrenceIF occ = it.next();
     if (occ.getLocator() != null) return occ;
   }
   return null;
 }
예제 #5
0
  private AssociationIF getAssociationOfType(TopicIF type) {
    TopicMapIF topicmap = type.getTopicMap();
    ClassInstanceIndexIF index =
        (ClassInstanceIndexIF)
            topicmap.getIndex("net.ontopia.topicmaps.core.index.ClassInstanceIndexIF");

    return index.getAssociations(type).iterator().next();
  }
예제 #6
0
  public void testSetBothTopics() throws java.io.IOException {

    TopicIF topic = getTopicById(tm, "tromso");
    TopicIF otherTopic = getTopicById(tm, "gamst");
    TopicIF otype = getTopicById(tm, "gamst");
    int numOcc = otherTopic.getOccurrences().size();

    OccurrenceIF occ = topic.getOccurrences().iterator().next();
    String loc = occ.getValue();
    Iterator<OccurrenceIF> occIT = topic.getOccurrences().iterator();
    while (loc == null && occIT.hasNext()) {
      occ = occIT.next();
      loc = occ.getValue();
    }

    // build parms
    ActionParametersIF params = makeParameters(makeList(occ, topic, otype), "http://www.sf.net");
    ActionResponseIF response = makeResponse();

    // execute
    action.perform(params, response);

    // test
    String locNew = occ.getValue();
    assertFalse("The value is not correct for topic which owns occurrence", locNew.equals(loc));

    assertFalse("Occurrence added to other topic", numOcc < otherTopic.getOccurrences().size());
    Iterator<OccurrenceIF> i = otherTopic.getOccurrences().iterator();
    boolean hasit = false;
    while (i.hasNext()) {
      OccurrenceIF foo = i.next();
      if (foo.getValue().equals("http://www.sf.net")) hasit = true;
    }
    assertFalse("Occurrence is set for the other topic", hasit);
  }
예제 #7
0
  public void testEmptyValueNoOcc() throws java.io.IOException {
    // get ready
    TopicIF topic = getTopicById(tm, "tromso");
    TopicIF otype = getTopicById(tm, "tromso");
    int occsbefore = topic.getOccurrences().size();

    // run action
    List plist = new ArrayList();
    plist.add(Collections.EMPTY_SET);
    plist.add(Collections.singleton(topic));
    plist.add(Collections.singleton(otype));
    ActionParametersIF params = makeParameters(plist, "");
    ActionResponseIF response = makeResponse();
    action.perform(params, response);

    // test post-action state
    int occsnow = topic.getOccurrences().size();
    assertTrue("Number of occurrences has changed!", occsbefore == occsnow);
  }
예제 #8
0
  public void testEmptyValue() throws java.io.IOException {
    // get ready
    TopicIF topic = getTopicById(tm, "tromso");
    TopicIF otype = getTopicById(tm, "tromso");
    OccurrenceIF occ = getOccurrenceWithValue(topic);
    int occsbefore = topic.getOccurrences().size();

    // run action
    ActionParametersIF params = makeParameters(makeList(occ, topic, otype), "");
    ActionResponseIF response = makeResponse();
    action.perform(params, response);

    // test post-action state
    int occsnow = topic.getOccurrences().size();
    assertTrue("Number of occurrences has changed!", occsbefore == occsnow);
    assertTrue(
        "Value of occurrence is not empty, but '" + occ.getValue() + "'",
        occ.getValue().equals(""));
  }
예제 #9
0
  public void testNormalOperation() throws IOException {
    TopicIF topic = getTopicById(tm, "tromso");
    OccurrenceIF occ = topic.getOccurrences().iterator().next();
    LocatorIF loc = occ.getLocator();
    Iterator<OccurrenceIF> occIT = topic.getOccurrences().iterator();
    while (loc == null && occIT.hasNext()) {
      occ = occIT.next();
      loc = occ.getLocator();
    }

    // build parms
    ActionParametersIF params = makeParameters(occ, "http://www.sf.net");
    ActionResponseIF response = makeResponse();

    // execute
    action.perform(params, response);

    // test
    LocatorIF locNew = occ.getLocator();
    assertFalse("The locator is not correct", locNew.getAddress().equals(loc.getAddress()));
  }
예제 #10
0
  public void testMalformedURL() throws IOException {

    TopicIF topic = getTopicById(tm, "tromso");
    OccurrenceIF occ = topic.getOccurrences().iterator().next();
    LocatorIF loc = occ.getLocator();
    Iterator<OccurrenceIF> occIT = topic.getOccurrences().iterator();
    while (loc == null && occIT.hasNext()) {
      occ = occIT.next();
      loc = occ.getLocator();
    }

    // build parms
    ActionParametersIF params = makeParameters(occ, "snus");
    ActionResponseIF response = makeResponse();
    try {
      // execute
      action.perform(params, response);
      fail("Malformed url for locator");
    } catch (ActionRuntimeException e) {
    }
  }
예제 #11
0
  public void testBadParam3() throws IOException {
    TopicIF topic = getTopicById(tm, "tromso");
    OccurrenceIF occ = topic.getOccurrences().iterator().next();
    LocatorIF loc = occ.getLocator();
    Iterator<OccurrenceIF> occIT = topic.getOccurrences().iterator();
    while (loc == null && occIT.hasNext()) {
      occ = occIT.next();
      loc = occ.getLocator();
    }

    // build parms
    ActionParametersIF params = makeParameters(makeList(occ, topic, ""), "http://www.sf.net");
    ActionResponseIF response = makeResponse();
    try {
      // execute
      action.perform(params, response);
      // test
      fail("Bad Type param (String)");
    } catch (ActionRuntimeException e) {
    }
  }
예제 #12
0
 protected Collection getClasses(TopicIF instance) {
   Set types = new CompactHashSet();
   Iterator it = instance.getTypes().iterator();
   while (it.hasNext()) types.addAll(getSupertypes((TopicIF) it.next()));
   return types;
 }