Exemplo n.º 1
1
  @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);
  }
Exemplo n.º 2
0
  @Test
  public void testCreateAndGetPet() throws Exception {
    Pet pet = createRandomPet();
    api.addPet(pet);

    Pet fetched = api.getPetById(pet.getId());
    assertNotNull(fetched);
    assertEquals(pet.getId(), fetched.getId());
    assertNotNull(fetched.getCategory());
    assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
  }
Exemplo n.º 3
0
  @Test
  public void testUpdatePetWithForm() throws Exception {
    Pet pet = createRandomPet();
    pet.setName("frank");
    api.addPet(pet);

    Pet fetched = api.getPetById(pet.getId());

    api.updatePetWithForm(fetched.getId(), "furt", null);
    Pet updated = api.getPetById(fetched.getId());

    assertEquals(updated.getName(), "furt");
  }
Exemplo n.º 4
0
  @Test
  public void testUpdatePet() throws Exception {
    Pet pet = createRandomPet();
    pet.setName("programmer");

    api.updatePet(pet);

    Pet fetched = api.getPetById(pet.getId());
    assertNotNull(fetched);
    assertEquals(pet.getId(), fetched.getId());
    assertNotNull(fetched.getCategory());
    assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
  }
Exemplo n.º 5
0
  @Test
  public void testDeletePet() throws Exception {
    Pet pet = createRandomPet();
    api.addPet(pet);

    Pet fetched = api.getPetById(pet.getId());
    api.deletePet(fetched.getId(), null);

    try {
      fetched = api.getPetById(fetched.getId());
      fail("expected an error");
    } catch (ApiException e) {
      assertEquals(404, e.getCode());
    }
  }
Exemplo n.º 6
0
  @Test
  public void testUploadFile() throws Exception {
    Pet pet = createRandomPet();
    api.addPet(pet);

    File file = new File("hello.txt");
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.write("Hello world!");
    writer.close();

    api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath()));
  }
Exemplo n.º 7
0
  @Test
  public void testFindPetsByStatus() throws Exception {
    Pet pet = createRandomPet();
    pet.setName("programmer");
    pet.setStatus(Pet.StatusEnum.AVAILABLE);

    api.updatePet(pet);

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

    boolean found = false;
    for (Pet fetched : pets) {
      if (fetched.getId().equals(pet.getId())) {
        found = true;
        break;
      }
    }

    assertTrue(found);
  }