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