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 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.º 4
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.º 5
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.º 6
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());
  }
  protected void addValues(Object object) {
    OrganisationUnit unit = (OrganisationUnit) object;

    statementBuilder.setInt(unit.getId());
    statementBuilder.setString(unit.getUuid());
    statementBuilder.setString(unit.getName());
    statementBuilder.setString(
        unit.getParent() != null ? String.valueOf(unit.getParent().getId()) : null);
    statementBuilder.setString(unit.getShortName());
    statementBuilder.setString(unit.getOrganisationUnitCode());
    statementBuilder.setDate(unit.getOpeningDate());
    statementBuilder.setDate(unit.getClosedDate());
    statementBuilder.setBoolean(unit.isActive());
    statementBuilder.setString(unit.getComment());
    statementBuilder.setString(unit.getGeoCode());
    statementBuilder.setString(unit.getLatitude());
    statementBuilder.setString(unit.getLongitude());
  }
Ejemplo n.º 8
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());
  }