http://git-wip-us.apache.org/repos/asf/isis/blob/5491a130/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_get_accept.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_get_accept.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_get_accept.java deleted file mode 100644 index 25347ee..0000000 --- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_get_accept.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.isis.viewer.restfulobjects.tck.resources.version; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import javax.ws.rs.core.MediaType; - -import org.jboss.resteasy.client.ClientRequest; -import org.jboss.resteasy.client.ClientResponse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import org.apache.isis.core.webserver.WebServer; -import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; -import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; -import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulRequest; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode; -import org.apache.isis.viewer.restfulobjects.applib.user.UserRepresentation; -import org.apache.isis.viewer.restfulobjects.applib.version.VersionRepresentation; -import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; - -public class VersionResourceTest_get_accept { - - @Rule - public IsisWebServerRule webServerRule = new IsisWebServerRule(); - - private RestfulClient client; - - @Before - public void setUp() throws Exception { - client = webServerRule.getClient(); - } - - @Test - public void applicationJson_noProfile_returns200() throws Exception { - - final RestfulRequest request = client.createRequest(RestfulHttpMethod.GET, "version").withHeader(RestfulRequest.Header.ACCEPT, MediaType.APPLICATION_JSON_TYPE); - final RestfulResponse<VersionRepresentation> restfulResponse = request.executeT(); - - assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK)); - assertThat(restfulResponse.getHeader(RestfulResponse.Header.CONTENT_TYPE), is(RepresentationType.VERSION.getMediaType())); - } - - - @Test - public void applicationJson_profileVersion_returns200() throws Exception { - - final RestfulRequest request = client.createRequest(RestfulHttpMethod.GET, "version").withHeader(RestfulRequest.Header.ACCEPT, RepresentationType.VERSION.getMediaType()); - final RestfulResponse<VersionRepresentation> restfulResponse = request.executeT(); - - assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK)); - } - - @Test - public void missingHeader_returns200() throws Exception { - // given - final RestfulRequest restfulReq = client.createRequest(RestfulHttpMethod.GET, "version"); - - // when - final RestfulResponse<VersionRepresentation> restfulResp = restfulReq.executeT(); - - // then - assertThat(restfulResp.getStatus(), is(HttpStatusCode.OK)); - } - - @Test - public void applicationJson_profileIncorrect_returns406() throws Exception { - - final RestfulRequest request = client.createRequest(RestfulHttpMethod.GET, "version").withHeader(RestfulRequest.Header.ACCEPT, RepresentationType.USER.getMediaType()); - final RestfulResponse<VersionRepresentation> restfulResponse = request.executeT(); - - assertThat(restfulResponse.getStatus(), is(HttpStatusCode.NOT_ACCEPTABLE)); - } - - @Test - public void incorrectMediaType_returnsNotAcceptable() throws Exception { - - // given - final ClientRequest clientRequest = client.getClientRequestFactory().createRelativeRequest("version"); - clientRequest.accept(MediaType.APPLICATION_ATOM_XML_TYPE); - - // when - final ClientResponse<?> resp = clientRequest.get(); - final RestfulResponse<JsonRepresentation> restfulResp = RestfulResponse.of(resp); - - // then - assertThat(restfulResp.getStatus(), is(HttpStatusCode.NOT_ACCEPTABLE)); - } -}
http://git-wip-us.apache.org/repos/asf/isis/blob/5491a130/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_representation.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_representation.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_representation.java new file mode 100644 index 0000000..01eff58 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_representation.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.resources.version; + +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.assertThat; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isArray; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isLink; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isMap; +import static org.hamcrest.CoreMatchers.endsWith; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status.Family; + +import org.apache.isis.core.webserver.WebServer; +import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.Rel; +import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; +import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode; +import org.apache.isis.viewer.restfulobjects.applib.version.VersionRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.version.VersionResource; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class VersionResourceTest_representation { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + private RestfulClient client; + private VersionResource resource; + + @Before + public void setUp() throws Exception { + final WebServer webServer = webServerRule.getWebServer(); + client = new RestfulClient(webServer.getBase()); + + resource = client.getVersionResource(); + } + + @Test + public void representation() throws Exception { + + // given + final Response servicesResp = resource.version(); + + // when + final RestfulResponse<VersionRepresentation> restfulResponse = RestfulResponse.ofT(servicesResp); + assertThat(restfulResponse.getStatus().getFamily(), is(Family.SUCCESSFUL)); + + // then + assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK)); + + final VersionRepresentation repr = restfulResponse.getEntity(); + assertThat(repr, is(not(nullValue()))); + assertThat(repr, isMap()); + + assertThat(repr.getSelf(), isLink(client) + .rel(Rel.SELF) + .href(endsWith(":39393/version")) + .httpMethod(RestfulHttpMethod.GET) + .type(RepresentationType.VERSION.getMediaType()) + .returning(HttpStatusCode.OK) + ); + assertThat(repr.getUp(), isLink(client) + .rel(Rel.UP) + .href(endsWith(":39393/")) + .httpMethod(RestfulHttpMethod.GET) + .type(RepresentationType.HOME_PAGE.getMediaType()) + .returning(HttpStatusCode.OK) + ); + + assertThat(repr.getString("specVersion"), is("1.0.0")); + assertThat(repr.getString("implVersion"), is(not(nullValue()))); + //assertThat(repr.getString("implVersion"), is(not("UNKNOWN"))); + + final JsonRepresentation optionalCapbilitiesRepr = repr.getOptionalCapabilities(); + assertThat(optionalCapbilitiesRepr, isMap()); + + assertThat(optionalCapbilitiesRepr.getString("blobsClobs"), is("yes")); + assertThat(optionalCapbilitiesRepr.getString("deleteObjects"), is("yes")); + assertThat(optionalCapbilitiesRepr.getString("domainModel"), is("formal")); + assertThat(optionalCapbilitiesRepr.getString("validateOnly"), is("yes")); + assertThat(optionalCapbilitiesRepr.getString("protoPersistentObjects"), is("yes")); + + assertThat(repr.getLinks(), isArray()); + assertThat(repr.getExtensions(), is(not(nullValue()))); + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/5491a130/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_responseHeaders.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_responseHeaders.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_responseHeaders.java new file mode 100644 index 0000000..1e29d59 --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_responseHeaders.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.resources.version; + +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasMaxAge; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasParameter; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasSubType; +import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasType; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.isis.core.webserver.WebServer; +import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.Header; +import org.apache.isis.viewer.restfulobjects.applib.version.VersionRepresentation; +import org.apache.isis.viewer.restfulobjects.applib.version.VersionResource; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class VersionResourceTest_responseHeaders { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + private RestfulClient client; + private VersionResource resource; + + @Before + public void setUp() throws Exception { + final WebServer webServer = webServerRule.getWebServer(); + client = new RestfulClient(webServer.getBase()); + + resource = client.getVersionResource(); + } + + + @Test + public void contentType_and_cacheControl() throws Exception { + // given + final Response resp = resource.version(); + + // when + final RestfulResponse<VersionRepresentation> restfulResponse = RestfulResponse.ofT(resp); + + // then + final MediaType contentType = restfulResponse.getHeader(Header.CONTENT_TYPE); + assertThat(contentType, hasType("application")); + assertThat(contentType, hasSubType("json")); + assertThat(contentType, hasParameter("profile", "urn:org.restfulobjects:repr-types/version")); + assertThat(contentType, is(RepresentationType.VERSION.getMediaType())); + + // then + final CacheControl cacheControl = restfulResponse.getHeader(Header.CACHE_CONTROL); + assertThat(cacheControl, hasMaxAge(24 * 60 * 60)); + assertThat(cacheControl.getMaxAge(), is(24 * 60 * 60)); + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/5491a130/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_representation.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_representation.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_representation.java deleted file mode 100644 index cd91d7a..0000000 --- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_representation.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.isis.viewer.restfulobjects.tck.resources.version; - -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.assertThat; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasMaxAge; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasParameter; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasSubType; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasType; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isArray; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isFollowableLinkToSelf; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isLink; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.isMap; -import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; - -import java.io.IOException; - -import javax.ws.rs.core.CacheControl; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status.Family; - -import org.apache.isis.core.webserver.WebServer; -import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; -import org.apache.isis.viewer.restfulobjects.applib.Rel; -import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.Header; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode; -import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod; -import org.apache.isis.viewer.restfulobjects.applib.version.VersionRepresentation; -import org.apache.isis.viewer.restfulobjects.applib.version.VersionResource; -import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -public class VersionResourceTest_templated_representation { - - @Rule - public IsisWebServerRule webServerRule = new IsisWebServerRule(); - - private RestfulClient client; - private VersionResource resource; - - @Before - public void setUp() throws Exception { - final WebServer webServer = webServerRule.getWebServer(); - client = new RestfulClient(webServer.getBase()); - - resource = client.getVersionResource(); - } - - @Test - public void representation() throws Exception { - - // given - final Response servicesResp = resource.version(); - - // when - final RestfulResponse<VersionRepresentation> restfulResponse = RestfulResponse.ofT(servicesResp); - assertThat(restfulResponse.getStatus().getFamily(), is(Family.SUCCESSFUL)); - - // then - assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK)); - - final VersionRepresentation repr = restfulResponse.getEntity(); - assertThat(repr, is(not(nullValue()))); - assertThat(repr, isMap()); - - assertThat(repr.getSelf(), isLink(client) - .rel(Rel.SELF) - .href(endsWith(":39393/version")) - .httpMethod(RestfulHttpMethod.GET) - .type(RepresentationType.VERSION.getMediaType()) - .returning(HttpStatusCode.OK) - ); - assertThat(repr.getUp(), isLink(client) - .rel(Rel.UP) - .href(endsWith(":39393/")) - .httpMethod(RestfulHttpMethod.GET) - .type(RepresentationType.HOME_PAGE.getMediaType()) - .returning(HttpStatusCode.OK) - ); - - assertThat(repr.getString("specVersion"), is("1.0.0")); - assertThat(repr.getString("implVersion"), is(not(nullValue()))); - //assertThat(repr.getString("implVersion"), is(not("UNKNOWN"))); - - final JsonRepresentation optionalCapbilitiesRepr = repr.getOptionalCapabilities(); - assertThat(optionalCapbilitiesRepr, isMap()); - - assertThat(optionalCapbilitiesRepr.getString("blobsClobs"), is("yes")); - assertThat(optionalCapbilitiesRepr.getString("deleteObjects"), is("yes")); - assertThat(optionalCapbilitiesRepr.getString("domainModel"), is("formal")); - assertThat(optionalCapbilitiesRepr.getString("validateOnly"), is("yes")); - assertThat(optionalCapbilitiesRepr.getString("protoPersistentObjects"), is("yes")); - - assertThat(repr.getLinks(), isArray()); - assertThat(repr.getExtensions(), is(not(nullValue()))); - } -} http://git-wip-us.apache.org/repos/asf/isis/blob/5491a130/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_responseHeaders.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_responseHeaders.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_responseHeaders.java deleted file mode 100644 index e39644e..0000000 --- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_templated_responseHeaders.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.isis.viewer.restfulobjects.tck.resources.version; - -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasMaxAge; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasParameter; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasSubType; -import static org.apache.isis.viewer.restfulobjects.tck.RepresentationMatchers.hasType; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import javax.ws.rs.core.CacheControl; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.apache.isis.core.webserver.WebServer; -import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; -import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.Header; -import org.apache.isis.viewer.restfulobjects.applib.version.VersionRepresentation; -import org.apache.isis.viewer.restfulobjects.applib.version.VersionResource; -import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -public class VersionResourceTest_templated_responseHeaders { - - @Rule - public IsisWebServerRule webServerRule = new IsisWebServerRule(); - - private RestfulClient client; - private VersionResource resource; - - @Before - public void setUp() throws Exception { - final WebServer webServer = webServerRule.getWebServer(); - client = new RestfulClient(webServer.getBase()); - - resource = client.getVersionResource(); - } - - - @Test - public void headers() throws Exception { - // given - final Response resp = resource.version(); - - // when - final RestfulResponse<VersionRepresentation> restfulResponse = RestfulResponse.ofT(resp); - - // then - final MediaType contentType = restfulResponse.getHeader(Header.CONTENT_TYPE); - assertThat(contentType, hasType("application")); - assertThat(contentType, hasSubType("json")); - assertThat(contentType, hasParameter("profile", "urn:org.restfulobjects:repr-types/version")); - assertThat(contentType, is(RepresentationType.VERSION.getMediaType())); - - // then - final CacheControl cacheControl = restfulResponse.getHeader(Header.CACHE_CONTROL); - assertThat(cacheControl, hasMaxAge(24 * 60 * 60)); - assertThat(cacheControl.getMaxAge(), is(24 * 60 * 60)); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/5491a130/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_xrofollowlinks.java ---------------------------------------------------------------------- diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_xrofollowlinks.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_xrofollowlinks.java new file mode 100644 index 0000000..47f0b2c --- /dev/null +++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/resources/version/VersionResourceTest_xrofollowlinks.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.viewer.restfulobjects.tck.resources.version; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +import org.apache.isis.viewer.restfulobjects.applib.Rel; +import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulRequest; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulRequest.RequestParameter; +import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse; +import org.apache.isis.viewer.restfulobjects.applib.version.VersionRepresentation; +import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class VersionResourceTest_xrofollowlinks { + + @Rule + public IsisWebServerRule webServerRule = new IsisWebServerRule(); + + private RestfulClient client; + + private RestfulRequest request; + private RestfulResponse<VersionRepresentation> restfulResponse; + private VersionRepresentation repr; + + @Before + public void setUp() throws Exception { + client = webServerRule.getClient(); + + } + + @Test + public void noFollow() throws Exception { + + request = client.createRequest(RestfulHttpMethod.GET, "version"); + restfulResponse = request.executeT(); + repr = restfulResponse.getEntity(); + + assertThat(repr.getSelf().getValue(), is(nullValue())); + assertThat(repr.getUp().getValue(), is(nullValue())); + } + + @Test + public void self() throws Exception { + + request = client.createRequest(RestfulHttpMethod.GET, "version") + .withArg(RequestParameter.FOLLOW_LINKS, "links[rel=" + Rel.SELF.getName() + "]"); + restfulResponse = request.executeT(); + repr = restfulResponse.getEntity(); + + assertThat(repr.getSelf().getValue(), is(not(nullValue()))); + } + + @Test + public void up() throws Exception { + + request = client.createRequest(RestfulHttpMethod.GET, "version") + .withArg(RequestParameter.FOLLOW_LINKS, "links[rel=" + Rel.UP.getName() + "]"); + restfulResponse = request.executeT(); + repr = restfulResponse.getEntity(); + + assertThat(repr.getUp().getValue(), is(not(nullValue()))); + } + +}
