public void testFilteredByTag() {
    ClaimListController claimListController = new ClaimListController();

    int claim1Id =
        claimListController.addClaim(
            "Claim 1",
            new GregorianCalendar().getTime(),
            new GregorianCalendar().getTime(),
            "description",
            new User("Jim", "123"));
    int claim2Id =
        claimListController.addClaim(
            "Claim 2",
            new GregorianCalendar().getTime(),
            new GregorianCalendar().getTime(),
            "description",
            new User("Jim", "123"));

    Claim claim1 = claimListController.getClaim(claim1Id);
    Claim claim2 = claimListController.getClaim(claim2Id);
    try {
      claim1.addTag("cat");
      claim2.addTag("cat");
      ArrayList<String> tags = new ArrayList<String>();
      tags.add("cat");
      assertEquals(
          "there should be two claims with tag 'cat'",
          2,
          claimListController.filterByTag("Jim", tags).size());
    } catch (AlreadyExistsException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public void testFilterByStatus() {
    ClaimListController claimListController = new ClaimListController();

    claimListController.addClaim(
        "Claim 1",
        new GregorianCalendar().getTime(),
        new GregorianCalendar().getTime(),
        "description",
        new User("Jim", "123"));
    int claim2Id =
        claimListController.addClaim(
            "Claim 2",
            new GregorianCalendar().getTime(),
            new GregorianCalendar().getTime(),
            "description",
            new User("Jim", "123"));

    int claim3Id =
        claimListController.addClaim(
            "Claim 3",
            new GregorianCalendar().getTime(),
            new GregorianCalendar().getTime(),
            "description",
            new User("Jim", "123"));

    Claim claim2 = claimListController.getClaim(claim2Id);
    Claim claim3 = claimListController.getClaim(claim3Id);
    claim2.setStatus("Approved");
    claim3.setStatus("Approved");

    ArrayList<Claim> approvedClaims = claimListController.filterByStatus("Approved");

    assertEquals("The number of 'Approved' claims doesn't match", 2, approvedClaims.size());
  }
Ejemplo n.º 3
0
  public void testDeleteTag() throws AlreadyExistsException {
    // Create new claim
    Claim claim =
        new Claim("name", new Date(), new Date(), "description", new User("Test", "User"), 0);

    // Populate tags list with new unique tags
    for (int i = 1; i <= 10; i++) {
      String s = String.valueOf(i);
      claim.addTag(s);
    }

    // Make sure tags list is populated
    assertTrue("Tags list empty after populating", claim.getTagList().size() > 0);

    while (claim.getTagList().size() > 0) {
      // Get tag at index 0
      String tag = claim.getTagList().get(0);

      // Remove tag
      claim.removeTag(0);

      // Make sure tag was removed
      assertFalse("Claim still has removed tag", claim.getTagList().contains(tag));
    }

    // Make sure tags list properly emptied
    assertEquals("Tags list not fully emptied", 0, claim.getTagList().size());
  }
Ejemplo n.º 4
0
  // US03.03.01 As a claimant, I want to filter the list of expense claims by tags, to show only
  // those claims that have at least one tag matching any of a given set of one or more filter tags.
  public void testFilterByTags() throws AlreadyExistsException {
    String username = "******";
    int max = 10;

    // Create user and claim list controller
    User u = new User(username, "Password");
    ClaimListController clt = new ClaimListController();

    // Populate claims list
    for (int i = 1; i <= max; i++) {
      // Add new claim to claims list
      int claimID = clt.addClaim(String.valueOf(i), new Date(), new Date(), "description", u);

      // Add tags to claim ({1, ..., i})
      for (int j = 1; j <= i; j++) {
        clt.addTagToClaim(claimID, String.valueOf(j));
      }
    }

    // Test filtering by tags
    for (int i = 1; i <= max; i++) {
      ArrayList<String> tags = new ArrayList<String>();

      for (int j = i; j <= max; j++) {
        // Add tag to filter tags list
        tags.add(String.valueOf(j));

        // Filtered list
        ArrayList<Claim> fcl = clt.filterByTag(username, tags);

        // Make sure the filtered tags list is correct
        assertEquals(
            "Filtered by tags list has the wrong number of claims", max - (i - 1), fcl.size());
        for (Claim claim : fcl) {
          // Check every claim of filtered list
          boolean bool = false;

          for (String tag : claim.getTagList()) {
            // Compare claim's tag list with filter tag list
            if (tags.contains(tag)) bool = true;
          }

          // Make sure there was a common tag
          assertTrue("Claim has no common tags", bool);
        }
      }
    }
  }
Ejemplo n.º 5
0
  // US03.01.01 As a claimant, I want to give an expense claim one zero or more alphanumeric tags,
  // so that claims can be organized by me into groups.
  public void testAddTag() {
    // Create new claim and obtain tags list
    Claim claim =
        new Claim("name", new Date(), new Date(), "description", new User("Test", "User"), 0);

    // New claim should have no tags
    assertEquals("New claim has tags", 0, claim.getTagList().size());

    // Test populating tags list
    for (int i = 1; i <= 10; i++) {
      try {
        String s = String.valueOf(i);

        // Add new tag
        claim.addTag(s);

        // Make sure tag was properly added
        assertTrue("Tag was not added", claim.getTagList().contains(s));

        // Test adding duplicate tag
        try {
          // Read same tag
          claim.addTag(s);
          fail("Should have thrown an exception when adding duplicate tags");
        } catch (Exception e) {
          // Already exists exception thrown when adding duplicate tag
        }

        // Check size of tags list
        assertEquals("Tags list was incorrectly populated", i, claim.getTagList().size());
      } catch (Exception e) {
        // Already exists exception thrown when adding new tag
        fail("Shouldn't have thrown an exception adding new tags");
      }
    }
  }