@Test
  public void testFindPetsByTags() throws Exception {
    Pet pet = createRandomPet();
    pet.setName("monster");
    pet.setStatus(Pet.StatusEnum.AVAILABLE);

    List<Tag> tags = new ArrayList<Tag>();
    Tag tag1 = new Tag();
    tag1.setName("friendly");
    tags.add(tag1);
    pet.setTags(tags);

    api.updatePet(pet);

    List<Pet> pets = api.findPetsByTags(Arrays.asList(new String[] {"friendly"}));
    assertNotNull(pets);

    boolean found = false;
    for (Pet fetched : pets) {
      if (fetched.getId().equals(pet.getId())) {
        found = true;
        break;
      }
    }
    assertTrue(found);
  }
Esempio n. 2
0
 @Test
 public void testCreateTag() throws FOMException, JSONException, FluidException, IOException {
   // Lets create a tag underneath the user's default root namespace
   Namespace testNamespace = new Namespace(this.fdb, "", this.fdb.getUsername());
   String newName = UUID.randomUUID().toString();
   Tag newTag = testNamespace.createTag(newName, "This is a test tag", true);
   // if we successfully created a tag there'll be an id
   assertEquals(true, newTag.getId().length() > 0);
   testNamespace.getItem(); // not really needed
   assertEquals(true, TestUtils.contains(testNamespace.getTagNames(), newName));
   newTag.delete();
   testNamespace.getItem();
   assertEquals(false, TestUtils.contains(testNamespace.getTagNames(), newName));
   // Lets make sure validation works correctly...
   newName = "this is wrong"; // e.g. space is an invalid character
   String msg = "";
   try {
     newTag = testNamespace.createTag(newName, "This is a test namespace", false);
   } catch (FOMException ex) {
     msg = ex.getMessage();
   }
   assertEquals("Invalid name (incorrect characters or too long)", msg);
   // the new name is too long
   newName =
       "foobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspamfoobarbazhamandeggscheeseandpicklespamspamspamspam";
   msg = "";
   try {
     newTag = testNamespace.createTag(newName, "This is a test namespace", false);
   } catch (FOMException ex) {
     msg = ex.getMessage();
   }
   assertEquals("Invalid name (incorrect characters or too long)", msg);
 }
Esempio n. 3
0
 @Test
 public void testGetTag() throws FOMException, JSONException, FluidException, IOException {
   // Lets create a tag underneath the user's default root namespace
   Namespace testNamespace = new Namespace(this.fdb, "", this.fdb.getUsername());
   String newName = UUID.randomUUID().toString();
   Tag newTag = testNamespace.createTag(newName, "This is a test tag", true);
   // if we successfully created a tag we'll be able to get it from FluidDB
   Tag gotTag = testNamespace.getTag(newName);
   assertEquals(newTag.getId(), gotTag.getId());
   gotTag.delete();
 }
Esempio n. 4
0
 @Test
 public void testGetTagNames() throws FOMException, JSONException, FluidException, IOException {
   Namespace testNamespace = new Namespace(this.fdb, "", this.fdb.getUsername());
   String newName = UUID.randomUUID().toString();
   Tag newTag = testNamespace.createTag(newName, "This is a test tag", true);
   // check the change happens at FluidDB
   testNamespace.getItem();
   assertEquals(true, TestUtils.contains(testNamespace.getTagNames(), newName));
   // delete the tag
   newTag.delete();
   // this *won't* mean the tag is removed from the local object
   assertEquals(true, TestUtils.contains(testNamespace.getTagNames(), newName));
   // need to update from FluidDB
   testNamespace.getItem();
   assertEquals(false, TestUtils.contains(testNamespace.getTagNames(), newName));
 }