Search in sources :

Example 1 with CreateOrganizationDTO

use of org.c4sg.dto.CreateOrganizationDTO in project c4sg-services by Code4SocialGood.

the class OrganizationController method createOrganization.

@CrossOrigin
@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "Create organization", notes = "Creates an organization, and returns the organization created.", response = OrganizationDTO.class)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Internal server error") })
public Map<String, Object> createOrganization(@ApiParam(value = "Organization to create", required = true) @RequestBody @Valid CreateOrganizationDTO createOrganizationDTO) {
    System.out.println("************** OrganizationController.createOrganization()" + ": createOrganizationDTO=" + createOrganizationDTO + " **************");
    Map<String, Object> responseData = null;
    // organizationDTO.setLogo(organizationService.getLogoUploadPath(organizationDTO.getId()));
    try {
        OrganizationDTO createdOrganization = organizationService.createOrganization(createOrganizationDTO);
        responseData = Collections.synchronizedMap(new HashMap<>());
        responseData.put("organization", createdOrganization);
    } catch (Exception e) {
        System.err.println(e);
    }
    return responseData;
}
Also used : HashMap(java.util.HashMap) CreateOrganizationDTO(org.c4sg.dto.CreateOrganizationDTO) OrganizationDTO(org.c4sg.dto.OrganizationDTO) NotFoundException(org.c4sg.exception.NotFoundException) UserOrganizationException(org.c4sg.exception.UserOrganizationException) BadRequestException(org.c4sg.exception.BadRequestException) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CreateOrganizationDTO

use of org.c4sg.dto.CreateOrganizationDTO in project c4sg-services by Code4SocialGood.

the class OrganizationControllerTest method testCreateOrganization.

@Test
public void testCreateOrganization() throws Exception {
    // 1. Only required input field is name
    CreateOrganizationDTO organizationDto = new CreateOrganizationDTO();
    organizationDto.setName("Test Organization 1");
    mockMvc.perform(post(URI_ADD_ORGANIZATION).content(asJsonString(organizationDto)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(jsonPath("$.organization.id", new GreaterThan<Integer>(0))).andExpect(jsonPath("$.organization.name", is("Test Organization 1"))).andExpect(// default category is N
    jsonPath("$.organization.category", is("N"))).andExpect(// default status is A
    jsonPath("$.organization.status", is("A")));
    // 2. Tests all the fields
    organizationDto = new CreateOrganizationDTO();
    organizationDto.setName("Test Organization 2");
    organizationDto.setWebsiteUrl("websiteUrl");
    organizationDto.setDescription("description");
    organizationDto.setAddress1("address1");
    organizationDto.setAddress2("address2");
    organizationDto.setCity("city");
    organizationDto.setState("state");
    organizationDto.setZip("zip");
    organizationDto.setCountry("country");
    organizationDto.setContactName("contactName");
    organizationDto.setContactPhone("contactPhone");
    organizationDto.setContactEmail("contactEmail");
    organizationDto.setCategory("O");
    mockMvc.perform(post(URI_ADD_ORGANIZATION).content(asJsonString(organizationDto)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(jsonPath("$.organization.id", new GreaterThan<Integer>(0))).andExpect(jsonPath("$.organization.name", is("Test Organization 2"))).andExpect(jsonPath("$.organization.websiteUrl", is("websiteUrl"))).andExpect(jsonPath("$.organization.description", is("description"))).andExpect(jsonPath("$.organization.address1", is("address1"))).andExpect(jsonPath("$.organization.address2", is("address2"))).andExpect(jsonPath("$.organization.city", is("city"))).andExpect(jsonPath("$.organization.state", is("state"))).andExpect(jsonPath("$.organization.zip", is("zip"))).andExpect(jsonPath("$.organization.country", is("country"))).andExpect(jsonPath("$.organization.contactName", is("contactName"))).andExpect(jsonPath("$.organization.contactPhone", is("contactPhone"))).andExpect(jsonPath("$.organization.contactEmail", is("contactEmail"))).andExpect(jsonPath("$.organization.category", is("O"))).andExpect(jsonPath("$.organization.status", is("A"))).andExpect(jsonPath("$.organization.createdTime", is(nullValue())));
}
Also used : CreateOrganizationDTO(org.c4sg.dto.CreateOrganizationDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 OrganizationDTO (org.c4sg.dto.OrganizationDTO)1 BadRequestException (org.c4sg.exception.BadRequestException)1 NotFoundException (org.c4sg.exception.NotFoundException)1 UserOrganizationException (org.c4sg.exception.UserOrganizationException)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1