Search in sources :

Example 1 with Organization

use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method shouldReturnSourceAssignmentWhenSourceIsAnOrganization.

@Test
public void shouldReturnSourceAssignmentWhenSourceIsAnOrganization() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID sourceId = randomUUID();
    when(sourceRepository.save(any(ValidSourceAssignment.class))).thenReturn(createSourceAssignment(programId, facilityTypeId, createNode(sourceId, false)));
    Organization organization = new Organization();
    organization.setName(ORGANIZATION_NAME);
    when(organizationRepository.exists(sourceId)).thenReturn(true);
    when(organizationRepository.findOne(sourceId)).thenReturn(organization);
    when(nodeRepository.findByReferenceId(sourceId)).thenReturn(null);
    ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
    // when
    ValidSourceDestinationDto assignmentDto = validSourceService.assignSource(assignment);
    // then
    assertThat(assignmentDto.getProgramId(), is(programId));
    assertThat(assignmentDto.getFacilityTypeId(), is(facilityTypeId));
    assertThat(assignmentDto.getIsFreeTextAllowed(), is(true));
    assertThat(assignmentDto.getName(), is(ORGANIZATION_NAME));
    assertThat(assignmentDto.getNode().getReferenceId(), is(sourceId));
    assertThat(assignmentDto.getNode().isRefDataFacility(), is(false));
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 2 with Organization

use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method shouldReturnDestinationAssignmentWhenDestinationIsA_organization.

@Test
public void shouldReturnDestinationAssignmentWhenDestinationIsA_organization() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID destinationId = randomUUID();
    when(destinationRepository.save(any(ValidDestinationAssignment.class))).thenReturn(createDestinationAssignment(programId, facilityTypeId, createNode(destinationId, false)));
    Organization organization = new Organization();
    organization.setName(ORGANIZATION_NAME);
    when(organizationRepository.exists(destinationId)).thenReturn(true);
    when(organizationRepository.findOne(destinationId)).thenReturn(organization);
    when(nodeRepository.findByReferenceId(destinationId)).thenReturn(null);
    ValidDestinationAssignment assignment = createDestination(programId, facilityTypeId, destinationId);
    // when
    ValidSourceDestinationDto assignmentDto = validDestinationService.assignDestination(assignment);
    // then
    assertThat(assignmentDto.getProgramId(), is(programId));
    assertThat(assignmentDto.getFacilityTypeId(), is(facilityTypeId));
    assertThat(assignmentDto.getIsFreeTextAllowed(), is(true));
    assertThat(assignmentDto.getName(), is(ORGANIZATION_NAME));
    assertThat(assignmentDto.getNode().getReferenceId(), is(destinationId));
    assertThat(assignmentDto.getNode().isRefDataFacility(), is(false));
}
Also used : ValidDestinationAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment) Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 3 with Organization

use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.

the class OrganizationController method createOrganization.

/**
 * Create a new organization. If the ID is specified, ID will be ignored.
 *
 * @param organization organization object bound to request body
 * @return created organization.
 */
@RequestMapping(value = "organizations", method = RequestMethod.POST)
public ResponseEntity<Organization> createOrganization(@RequestBody Organization organization) {
    LOGGER.debug("Try to create a new organization.");
    permissionService.canManageOrganizations();
    organization.setId(null);
    checkRequiredFieldsExist(organization);
    Organization foundOrg = organizationRepository.findByName(organization.getName());
    if (foundOrg != null) {
        return new ResponseEntity<>(foundOrg, OK);
    }
    return new ResponseEntity<>(organizationRepository.save(organization), CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Organization

use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.

the class OrganizationControllerIntegrationTest method shouldReturn400WhenWouldBeUpdatedOrganizationContentExists.

@Test
public void shouldReturn400WhenWouldBeUpdatedOrganizationContentExists() throws Exception {
    // given
    Organization updateOrg = createOrganization("Existing Org Name");
    when(organizationRepository.findOne(updateOrg.getId())).thenReturn(updateOrg);
    when(organizationRepository.findByName(updateOrg.getName())).thenReturn(createOrganization("Existing Org Name"));
    // when
    ResultActions resultActions = mvc.perform(put(ORGANIZATION_API + updateOrg.getId()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(updateOrg)));
    // then
    resultActions.andExpect(status().isBadRequest());
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 5 with Organization

use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.

the class OrganizationControllerIntegrationTest method shouldReturn200WhenOrganizationUpdateCompleted.

@Test
public void shouldReturn200WhenOrganizationUpdateCompleted() throws Exception {
    // given
    Organization organization = createOrganization("Updated Org");
    organization.setId(UUID.randomUUID());
    when(organizationRepository.findOne(organization.getId())).thenReturn(organization);
    when(organizationRepository.save(organization)).thenReturn(organization);
    // when
    ResultActions resultActions = mvc.perform(put(ORGANIZATION_API + organization.getId().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
    // then
    resultActions.andExpect(status().isOk()).andExpect(jsonPath("$.id", is(organization.getId().toString()))).andExpect(jsonPath("$.name", is(organization.getName())));
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Aggregations

Organization (org.openlmis.stockmanagement.domain.sourcedestination.Organization)11 Test (org.junit.Test)8 ResultActions (org.springframework.test.web.servlet.ResultActions)6 UUID (java.util.UUID)2 UUID.randomUUID (java.util.UUID.randomUUID)2 ValidSourceDestinationDto (org.openlmis.stockmanagement.dto.ValidSourceDestinationDto)2 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)1 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)1 ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)1 PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)1 Message (org.openlmis.stockmanagement.util.Message)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1