/** * Prints the resource's representation. * * @param clientResource * The Restlet client resource. * @throws IOException * @throws ResourceException */ public static void get(ClientResource clientResource) throws IOException, ResourceException { clientResource.get(); if (clientResource.getStatus().isSuccess() && clientResource.getResponse().isEntityAvailable()) { clientResource.getResponseEntity().write(System.out); } }
protected void throwServiceException(ClientResource service, Exception e) throws ServiceException { if (e instanceof ResourceException) { log.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode()); throwServiceException(service.getResponse().getEntityAsText()); } else { log.error("Unexpected Exception", e); throw new ServiceException(e); } } }
public static ChallengeResponse getTestChallengeResponse(final ClientResource clientResource) { return RestletTestUtils.getTestChallengeResponse(clientResource.getChallengeRequests(), ChallengeScheme.HTTP_DIGEST, clientResource.getResponse(), RestletTestUtils.TEST_USERNAME, RestletTestUtils.TEST_PASSWORD); }
public static ChallengeResponse getTestChallengeResponseAdmin(final ClientResource clientResource) { return RestletTestUtils.getTestChallengeResponse(clientResource.getChallengeRequests(), ChallengeScheme.HTTP_DIGEST, clientResource.getResponse(), RestletTestUtils.TEST_ADMIN_USERNAME, RestletTestUtils.TEST_ADMIN_PASSWORD); }
public static void main(String[] args) throws ResourceException, IOException { // Prepare the request ClientResource cr = new ClientResource("http://localhost:8182/"); ChallengeRequest c1 = null; // first try: unauthenticated request try { cr.get(); } catch (ResourceException re) { if (Status.CLIENT_ERROR_UNAUTHORIZED.equals(cr.getStatus())) { c1 = getDigestChallengeRequest(cr); } } // second try: authenticated request if (c1 != null) { ChallengeResponse c2 = new ChallengeResponse(c1, cr.getResponse(), "scott", "tiger".toCharArray()); cr.setChallengeResponse(c2); cr.get().write(System.out); } }
Assert.assertEquals(200, creationClientResource.getResponse().getStatus().getCode());
/** * Test whether the HTML page when there are no annotations is correct. */ @Test public void testAnnotationListEmptyHtml() throws Exception { final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(MediaType.TEXT_HTML); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(MediaType.TEXT_HTML.getName(), results.getMediaType().getName()); final String resultsText = results.getText(); this.assertFreemarker(resultsText); Assert.assertTrue(resultsText.contains("OAS-webservice-impl Annotations list template")); Assert.assertTrue(resultsText.contains("There are no matching annotations for your query")); Assert.assertFalse(resultsText.contains("List of Annotations")); Assert.assertFalse(resultsText.contains("class=\"annotation\"")); }
/** * Test whether Annotations can be listed using an HTTP GET request to retrieve HTML. */ @Test public void testAnnotationListMultipleHtml() throws Exception { this.createTestAnnotations(50); final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(MediaType.TEXT_HTML); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(MediaType.TEXT_HTML.getName(), results.getMediaType().getName()); final String resultsText = results.getText(); this.assertFreemarker(resultsText); Assert.assertTrue(resultsText.contains("OAS-webservice-impl Annotations list template")); Assert.assertFalse(resultsText.contains("There are no matching annotations for your query")); Assert.assertTrue(resultsText.contains("List of Annotations")); Assert.assertTrue(resultsText.contains("class=\"annotation\"")); }
Assert.assertEquals(200, creationClientResource.getResponse().getStatus().getCode());
/** * Test whether Annotations can be listed using an HTTP GET request to retrieve HTML. */ @Test public void testAnnotationListSingleHtml() throws Exception { this.createTestAnnotations(1); final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(MediaType.TEXT_HTML); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(MediaType.TEXT_HTML.getName(), results.getMediaType().getName()); final String resultsText = results.getText(); this.assertFreemarker(resultsText); Assert.assertTrue(resultsText.contains("OAS-webservice-impl Annotations list template")); Assert.assertFalse(resultsText.contains("There are no matching annotations for your query")); Assert.assertTrue(resultsText.contains("List of Annotations")); Assert.assertTrue(resultsText.contains("class=\"annotation\"")); }
Assert.assertEquals(200, creationClientResource.getResponse().getStatus().getCode());
Assert.assertEquals(200, creationClientResource.getResponse().getStatus().getCode());
/** * Test whether Annotations can be stored and retrieved using the application. */ @Test public void testUnknownAnnotationDeletion() { try { // Get the resource and dump it to the console final ClientResource cr = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_ANNOTATION_PATH, OasProps.DEF_ANNOTATION_PATH) + "?annotationId=dummyid")); @SuppressWarnings("unused") final Representation representation = cr.delete(); Assert.assertEquals(400, cr.getResponse().getStatus().getCode()); Assert.fail("Did not find expected exception when deleting resource that did not exist"); } catch(final Exception ex) { } }
Assert.assertEquals(200, creationClientResource.getResponse().getStatus().getCode());
/** * Tests whether the RDF/JSON page when there are no annotations is correct. */ @Test public void testAnnotationListEmptyJson() throws Exception { final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(RestletUtilMediaType.APPLICATION_RDF_JSON.getName(), results.getMediaType().getName()); this.assertRdf(results.getStream(), RDFFormat.RDFJSON, 0); }
/** * Tests whether the RDF/XML page when there are no annotations is correct. */ @Test public void testAnnotationListEmptyRdfXml() throws Exception { final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(MediaType.APPLICATION_RDF_XML); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/rdf+xml MIME type for response Assert.assertEquals(MediaType.APPLICATION_RDF_XML.getName(), results.getMediaType().getName()); this.assertRdf(results.getStream(), RDFFormat.RDFXML, 0); }
/** * Test whether Annotations can be listed using an HTTP GET request to retrieve RDF/XML. */ @Test public void testAnnotationListMultipleRdfXml() throws Exception { this.createTestAnnotations(50); final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(MediaType.APPLICATION_RDF_XML); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(MediaType.APPLICATION_RDF_XML.getName(), results.getMediaType().getName()); final Model resultModel = this.assertRdf(results.getStream(), RDFFormat.RDFXML, 300); Assert.assertTrue(resultModel.contains(null, RDF.TYPE, OasConstants.TAGGING_TAGGING)); }
/** * Test whether Annotations can be listed using an HTTP GET request to retrieve RDF/JSON. */ @Test public void testAnnotationListMultipleJson() throws Exception { this.createTestAnnotations(50); final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(RestletUtilMediaType.APPLICATION_RDF_JSON.getName(), results.getMediaType().getName()); final Model resultModel = this.assertRdf(results.getStream(), RDFFormat.RDFJSON, 300); Assert.assertTrue(resultModel.contains(null, RDF.TYPE, OasConstants.TAGGING_TAGGING)); }
/** * Test whether Annotations can be listed using an HTTP GET request to retrieve RDF/JSON. */ @Test public void testAnnotationListSingleJson() throws Exception { this.createTestAnnotations(1); final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(RestletUtilMediaType.APPLICATION_RDF_JSON.getName(), results.getMediaType().getName()); final Model resultModel = this.assertRdf(results.getStream(), RDFFormat.RDFJSON, 6); Assert.assertTrue(resultModel.contains(null, RDF.TYPE, OasConstants.TAGGING_TAGGING)); }
/** * Test whether Annotations can be listed using an HTTP GET request to retrieve RDF/XML. */ @Test public void testAnnotationListSingleRdfXml() throws Exception { this.createTestAnnotations(1); final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(MediaType.APPLICATION_RDF_XML); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(MediaType.APPLICATION_RDF_XML.getName(), results.getMediaType().getName()); final Model resultModel = this.assertRdf(results.getStream(), RDFFormat.RDFXML, 6); Assert.assertTrue(resultModel.contains(null, RDF.TYPE, OasConstants.TAGGING_TAGGING)); }