OrganizationResource extends AbstractResource { @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") public Response get(@PathParam("name") final String name){ LOG.info("Got a get organization request."); final DbOrganization dbOrganization = getOrganizationHandler().getOrganization(name); final Organization organization = getModelMapper().getOrganization(dbOrganization); final OrganizationView view = new OrganizationView(organization); return Response.ok(view).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 getDocumentation(){ WebResource resource = client().resource("/" + ServerAPI.ORGANIZATION_RESOURCE); ClientResponse response = resource.type(MediaType.TEXT_HTML).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); }
@Test public void getAllOrganizationNames(){ final List<String> names = new ArrayList<String>(); names.add("organization1"); when(repositoryHandler.getOrganizationNames()).thenReturn(names); WebResource resource = client().resource("/" + ServerAPI.ORGANIZATION_RESOURCE + ServerAPI.GET_NAMES); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); List<?> organization = (List<?>)response.getEntity(List.class); assertNotNull(organization); assertEquals(1, organization.size()); assertEquals("organization1", organization.get(0)); }
@Test public void getAnOrganization(){ final DbOrganization dbOrganization= new DbOrganization(); dbOrganization.setName("organization1"); dbOrganization.getCorporateGroupIdPrefixes().add("org.test"); when(repositoryHandler.getOrganization(dbOrganization.getName())).thenReturn(dbOrganization); WebResource resource = client().resource("/" + ServerAPI.ORGANIZATION_RESOURCE + "/" + dbOrganization.getName()); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); final Organization organization = response.getEntity(Organization.class); assertNotNull(organization); assertEquals(dbOrganization.getName(), organization.getName()); assertEquals(1, organization.getCorporateGroupIdPrefixes().size()); assertEquals(dbOrganization.getCorporateGroupIdPrefixes().get(0), organization.getCorporateGroupIdPrefixes().get(0)); }
@Test public void getCorporateGroupIds(){ final DbOrganization dbOrganization= new DbOrganization(); dbOrganization.setName("organization1"); dbOrganization.getCorporateGroupIdPrefixes().add("org.test"); when(repositoryHandler.getOrganization(dbOrganization.getName())).thenReturn(dbOrganization); client().addFilter(new HTTPBasicAuthFilter(GrapesTestUtils.USER_4TEST, GrapesTestUtils.PASSWORD_4TEST)); WebResource resource = client().resource("/" + ServerAPI.ORGANIZATION_RESOURCE + "/" + dbOrganization.getName() + ServerAPI.GET_CORPORATE_GROUPIDS); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); List<?> corporateGroupIds = (List<?>)response.getEntity(List.class); assertNotNull(corporateGroupIds); assertEquals(1, corporateGroupIds.size()); assertEquals("org.test", corporateGroupIds.get(0)); }