OrganizationResource extends AbstractResource { @POST public Response postOrganization(@Auth final DbCredential credential, final Organization organization){ if(!credential.getRoles().contains(DbCredential.AvailableRoles.DATA_UPDATER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a post organization request."); DataValidator.validate(organization); final DbOrganization dbOrganization = getModelMapper().getDbOrganization(organization); getOrganizationHandler().store(dbOrganization); return Response.ok().status(HttpStatus.CREATED_201).build(); } OrganizationResource(final RepositoryHandler repositoryHandler, final GrapesServerConfig configuration); @POST Response postOrganization(@Auth final DbCredential credential, final Organization organization); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}" + ServerAPI.GET_CORPORATE_GROUPIDS) Response getCorporateGroupIdPrefix(@PathParam("name") final String organizationId); @POST @Path("/{name}" + ServerAPI.GET_CORPORATE_GROUPIDS) Response addCorporateGroupIdPrefix(@Auth final DbCredential credential, @PathParam("name") final String organizationId, final String corporateGroupId); @DELETE @Path("/{name}" + ServerAPI.GET_CORPORATE_GROUPIDS) Response removeCorporateGroupIdPrefix(@Auth final DbCredential credential, @PathParam("name") final String organizationId, final String corporateGroupId);  }
@Test public void postOrganization(){ Organization organization = DataModelFactory.createOrganization("name"); organization.getCorporateGroupIdPrefixes().add("org.test"); client().addFilter(new HTTPBasicAuthFilter(GrapesTestUtils.USER_4TEST, GrapesTestUtils.PASSWORD_4TEST)); WebResource resource = client().resource("/" + ServerAPI.ORGANIZATION_RESOURCE); ClientResponse response = resource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, organization); assertNotNull(response); assertEquals(HttpStatus.CREATED_201, response.getStatus()); }