Search in sources :

Example 6 with Organization

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());
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 7 with Organization

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())));
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 8 with Organization

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());
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 9 with Organization

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());
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 10 with Organization

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;
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization)

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