示例#1
0
  public void perform(ActionParametersIF params, ActionResponseIF response) {
    // test params
    ActionSignature paramsType = ActionSignature.getSignature("o t? t?");
    paramsType.validateArguments(params, this);

    OccurrenceIF occurrence = (OccurrenceIF) params.get(0);
    String value = params.getStringValue();

    if ((value == null || value.trim().length() == 0) && occurrence != null)
      delete.perform(
          params.cloneAndOverride(Collections.singletonList(Collections.singletonList(occurrence))),
          response);
    else setLocator.perform(params, response);
  }
示例#2
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));
  }
示例#3
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);
  }
示例#4
0
 public void testBadParam() throws java.io.IOException {
   // build parms
   ActionParametersIF params = makeParameters("", "http://www.sf.net");
   ActionResponseIF response = makeResponse();
   try {
     // execute
     action.perform(params, response);
     // test
     fail("Bad OccurrenceType param (String)");
   } catch (ActionRuntimeException e) {
   }
 }
示例#5
0
 public void testNoParam() throws java.io.IOException {
   // build parms
   ActionParametersIF params = makeParameters(Collections.EMPTY_LIST, "http://www.sf.net");
   ActionResponseIF response = makeResponse();
   try {
     // execute
     action.perform(params, response);
     // test
     fail("Collection is empty");
   } catch (ActionRuntimeException e) {
   }
 }
示例#6
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);
  }
示例#7
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);
  }
示例#8
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);
  }
示例#9
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(""));
  }
示例#10
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()));
  }
示例#11
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) {
    }
  }
示例#12
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) {
    }
  }