use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.
the class OrganizationControllerIntegrationTest method shouldReturn200WhenTryToCreateOrganizationsHasExisted.
@Test
public void shouldReturn200WhenTryToCreateOrganizationsHasExisted() throws Exception {
// given
Organization organization = createOrganization("Test Org");
when(organizationRepository.findByName(organization.getName())).thenReturn(organization);
// when
ResultActions resultActions = mvc.perform(post(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
// then
resultActions.andExpect(status().isOk());
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.
the class OrganizationControllerIntegrationTest method shouldReturn201WhenOrganizationCreatedSuccessfully.
@Test
public void shouldReturn201WhenOrganizationCreatedSuccessfully() throws Exception {
// given
Organization organization = createOrganization("New Org");
when(organizationRepository.save(organization)).thenReturn(organization);
// when
ResultActions resultActions = mvc.perform(post(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
// then
resultActions.andExpect(status().isCreated()).andExpect(jsonPath("$.name", is(organization.getName())));
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.
the class OrganizationControllerIntegrationTest method shouldReturn400WhenReasonWithoutName.
@Test
public void shouldReturn400WhenReasonWithoutName() throws Exception {
// when
ResultActions resultActions = mvc.perform(post(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new Organization())));
// then
resultActions.andExpect(status().isBadRequest());
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.
the class OrganizationControllerIntegrationTest method shouldReturn403WhenUserHasNoPermissionToManageOrganizations.
@Test
public void shouldReturn403WhenUserHasNoPermissionToManageOrganizations() throws Exception {
// given
doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canManageOrganizations();
Organization organization = createOrganization("Would Get 403");
// 1. try to create organization
ResultActions postResult = mvc.perform(post(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
postResult.andExpect(status().isForbidden());
// 2. try to update organization
ResultActions putResult = mvc.perform(put(ORGANIZATION_API + UUID.randomUUID().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
putResult.andExpect(status().isForbidden());
// 3. try to retrieve organizations
ResultActions getResult = mvc.perform(get(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON));
getResult.andExpect(status().isForbidden());
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Organization in project openlmis-stockmanagement by OpenLMIS.
the class OrganizationControllerIntegrationTest method createOrganization.
private Organization createOrganization(String name) {
Organization organization1 = new Organization();
organization1.setName(name);
return organization1;
}
Aggregations