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));
}
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));
}
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);
}
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());
}
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())));
}
Aggregations