Ejemplo n.º 1
0
  @Test
  public void testPutFacilityUuid() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    Facility facility = new OrganisationUnitToFacilityConverter().convert(organisationUnit);
    facility.setName("FacilityB");
    facility.setActive(false);

    MockHttpSession session = getSession("ALL");

    mvc.perform(
            put("/fred/v1/facilities/" + organisationUnit.getUuid())
                .content(objectMapper.writeValueAsString(facility))
                .session(session)
                .contentType(MediaType.APPLICATION_JSON))
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.uuid", Matchers.notNullValue()))
        .andExpect(jsonPath("$.name").value("FacilityB"))
        .andExpect(jsonPath("$.active").value(false))
        .andExpect(jsonPath("$.createdAt", Matchers.notNullValue()))
        .andExpect(jsonPath("$.updatedAt", Matchers.notNullValue()))
        .andExpect(header().string("ETag", Matchers.notNullValue()))
        .andExpect(status().isOk());
  }
Ejemplo n.º 2
0
  @Test
  public void testDeleteFacilityUuid() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    MockHttpSession session = getSession("ALL");

    mvc.perform(delete("/fred/v1/facilities/" + organisationUnit.getUuid()).session(session))
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk());
  }
Ejemplo n.º 3
0
  @Test
  public void testGetFacilitiesWithContent() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    MockHttpSession session = getSession("ALL");

    mvc.perform(get("/fred/v1/facilities").session(session).accept(MediaType.APPLICATION_JSON))
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.facilities").isArray())
        .andExpect(jsonPath("$.facilities[0].name").value("OrgUnitA"))
        .andExpect(status().isOk());
  }
Ejemplo n.º 4
0
  @Test
  public void testPutFacilityWithoutRequiredPropertiesUuid() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    MockHttpSession session = getSession("ALL");

    mvc.perform(
            put("/fred/v1/facilities/" + organisationUnit.getUuid())
                .content("{}")
                .session(session)
                .contentType(MediaType.APPLICATION_JSON))
        .andExpect(status().isUnprocessableEntity());
  }
Ejemplo n.º 5
0
  @Test
  public void testPutInvalidJsonUuid() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    MockHttpSession session = getSession("ALL");

    mvc.perform(
            put("/fred/v1/facilities/" + organisationUnit.getUuid())
                .content("INVALID JSON")
                .session(session)
                .contentType(MediaType.APPLICATION_JSON))
        .andExpect(status().isBadRequest());
  }
Ejemplo n.º 6
0
  @Test
  public void testGetFacilityVerifyPresenceOfETag() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    MockHttpSession session = getSession("ALL");

    mvc.perform(
            get("/fred/v1/facilities/" + organisationUnit.getUid())
                .session(session)
                .accept(MediaType.APPLICATION_JSON))
        .andExpect(header().string("ETag", Matchers.notNullValue()))
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk());
  }
Ejemplo n.º 7
0
  // TODO: this should fail, need to figure out which code to return
  @Test
  public void testPutChangeUuidShouldFail() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnit.setUuid("ddccbbaa-bbaa-bbaa-bbaa-ffeeddccbbaa");
    manager.save(organisationUnit);

    Facility facility = new OrganisationUnitToFacilityConverter().convert(organisationUnit);
    facility.setUuid("aabbccdd-aabb-aabb-aabb-aabbccddeeff");

    MockHttpSession session = getSession("ALL");

    mvc.perform(
            put("/fred/v1/facilities/" + organisationUnit.getUuid())
                .content(objectMapper.writeValueAsString(facility))
                .session(session)
                .contentType(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk());
  }
Ejemplo n.º 8
0
  @Test
  public void testPutInvalidUuidShouldFail() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    Facility facility = new OrganisationUnitToFacilityConverter().convert(organisationUnit);
    facility.setUuid("DUMMY_UUID");

    MockHttpSession session = getSession("ALL");

    mvc.perform(
            put("/fred/v1/facilities/" + organisationUnit.getUuid())
                .content(objectMapper.writeValueAsString(facility))
                .session(session)
                .contentType(MediaType.APPLICATION_JSON))
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(status().isPreconditionFailed());
  }
Ejemplo n.º 9
0
  @Test
  public void testGetFacilityUuid() throws Exception {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    manager.save(organisationUnit);

    MockHttpSession session = getSession("ALL");

    mvc.perform(
            get("/fred/v1/facilities/" + organisationUnit.getUuid())
                .session(session)
                .accept(MediaType.APPLICATION_JSON))
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.uuid", Matchers.notNullValue()))
        .andExpect(jsonPath("$.name").value("OrgUnitA"))
        .andExpect(jsonPath("$.active").value(true))
        .andExpect(jsonPath("$.createdAt", Matchers.notNullValue()))
        .andExpect(jsonPath("$.updatedAt", Matchers.notNullValue()))
        .andExpect(header().string("ETag", Matchers.notNullValue()))
        .andExpect(status().isOk());
  }