@Override public String toString() { return "{" + super.toString() + ", qs=" + qs + "}"; } }
public EurekaHttpResponseBuilder<T> type(MediaType contentType) { headers(HttpHeaders.CONTENT_TYPE, contentType.toString()); return this; }
private <T> String toString(final Map<MediaType, List<T>> set) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); for (final Map.Entry<MediaType, List<T>> e : set.entrySet()) { pw.append(e.getKey().toString()).println(" ->"); for (final T t : e.getValue()) { pw.append(" ").println(t.getClass().getName()); } } pw.flush(); return sw.toString(); }
@Override public DataSource readFrom( final Class<DataSource> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException { return new ByteArrayDataSource(entityStream, (mediaType == null) ? null : mediaType.toString()); }
private Representation getRepresentationByMediaType( final List<Representation> representations, MediaType mediaType) { for (Representation representation : representations) { if (mediaType.toString().equals(representation.getMediaType())) { return representation; } } return null; }
@Override public Representation createRequestRepresentation(org.glassfish.jersey.server.model.Resource r, ResourceMethod m, MediaType mediaType) { Representation wadlRepresentation = new Representation(); wadlRepresentation.setMediaType(mediaType.toString()); return wadlRepresentation; }
@Test public void shouldHaveJsonMediaTypeWhenRetrievingDiscoveryDocument() { JaxRsResponse response = getDiscoveryDocument(); assertThat( response.getType().toString(), containsString( APPLICATION_JSON ) ); response.close(); }
@Test public void shouldBeJSONContentTypeOnResponse() { JaxRsResponse response = sendCreateRequestToServer(); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); }
@Test public void shouldHaveJsonMediaTypeOnResponse() { JaxRsResponse response = retrieveNodeFromService( nodeUri.toString() ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); response.close(); }
@Test public void shouldBeJSONContentTypeOnPropertiesResponse() { String entity = JsonHelper.createJsonFrom( Collections.singletonMap( "foo", "bar" ) ); JaxRsResponse createResource = req.post( functionalTestHelper.dataUri() + "node/", entity ); JaxRsResponse response = req.get( createResource.getLocation().toString() + "/properties" ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); }
@Test public void shouldBeJSONContentTypeOnPropertyResponse() { String entity = JsonHelper.createJsonFrom( Collections.singletonMap( "foo", "bar" ) ); JaxRsResponse createResponse = req.post( functionalTestHelper.dataUri() + "node/", entity ); JaxRsResponse response = req.get( getPropertyUri( createResponse.getLocation().toString(), "foo" ) ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); createResponse.close(); response.close(); }
@Test public void shouldBeJSONContentTypeOnPropertiesResponse() { long relId = helper.createRelationship( "LIKES" ); helper.setRelationshipProperties( relId, Collections.singletonMap( "foo", "bar" ) ); JaxRsResponse response = RestRequest.req().get( functionalTestHelper.dataUri() + "relationship/" + relId + "/properties" ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); response.close(); }
@Test public void shouldRespondWith400IfInvalidJsonSentAsNodePropertiesDuringNodeCreation() { String mangledJsonArray = "{\"myprop\":[1,2,\"three\"]}"; JaxRsResponse response = sendCreateRequestToServer(mangledJsonArray); assertEquals( 400, response.getStatus() ); assertEquals( "text/plain", response.getType() .toString() ); assertThat( response.getEntity(), containsString( mangledJsonArray ) ); }
@Test public void shouldRespondWith200AndEmptyListOfRelationshipRepresentationsWhenGettingIncomingRelationshipsForANodeWithoutRelationships() throws JsonParseException { JaxRsResponse response = sendRetrieveRequestToServer( nodeWithoutRelationships, "/in" ); assertEquals( 200, response.getStatus() ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); verifyRelReps( 0, response.getEntity() ); response.close(); }
@Test public void shouldRespondWith200AndEmptyListOfRelationshipRepresentationsWhenGettingOutgoingRelationshipsForANodeWithoutRelationships() throws JsonParseException { JaxRsResponse response = sendRetrieveRequestToServer( nodeWithoutRelationships, "/out" ); assertEquals( 200, response.getStatus() ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); verifyRelReps( 0, response.getEntity() ); response.close(); }
@Test public void shouldRespondWith200AndListOfRelationshipRepresentationsWhenGettingIncomingTypedRelationshipsForANode() throws JsonParseException { JaxRsResponse response = sendRetrieveRequestToServer( nodeWithRelationships, "/in/LIKES" ); assertEquals( 200, response.getStatus() ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); verifyRelReps( 1, response.getEntity() ); response.close(); }
@Test public void shouldRespondWith400IfInvalidJsonSentAsNodeProperties() { URI nodeLocation = sendCreateRequestToServer().getLocation(); String mangledJsonProperties = "{\"a\":\"b\", \"c\":[1,2,\"three\"]}"; JaxRsResponse response = RestRequest.req().put(nodeLocation.toString() + "/properties", mangledJsonProperties); assertEquals(400, response.getStatus()); assertEquals("text/plain", response.getType() .toString()); assertThat( response.getEntity(), containsString(mangledJsonProperties)); response.close(); }
@Test public void shouldRespondWith200AndListOfRelationshipRepresentationsWhenGettingOutgoingTypedRelationshipsForANode() throws JsonParseException { JaxRsResponse response = sendRetrieveRequestToServer( nodeWithRelationships, "/out/HATES" ); assertEquals( 200, response.getStatus() ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); verifyRelReps( 1, response.getEntity() ); response.close(); }
@Test public void shouldRespondWith400IfInvalidJsonSentAsNodeProperty() { URI nodeLocation = sendCreateRequestToServer().getLocation(); String mangledJsonArray = "[1,2,\"three\"]"; JaxRsResponse response = RestRequest.req().put(nodeLocation.toString() + "/properties/myprop", mangledJsonArray); assertEquals(400, response.getStatus()); assertEquals("text/plain", response.getType() .toString()); assertThat( response.getEntity(), containsString(mangledJsonArray)); response.close(); }
@Test public void shouldBeValidJSONOnResponse() { JaxRsResponse response = RestRequest.req().get( getPropertyUri( "foo" ) ); assertThat( response.getType().toString(), containsString( MediaType.APPLICATION_JSON ) ); assertNotNull( JsonHelper.createJsonFrom( response.getEntity() ) ); response.close(); }