diff --git a/apiman-it-commons/src/main/java/io/apiman/test/integration/DeployedServices.java b/apiman-it-commons/src/main/java/io/apiman/test/integration/DeployedServices.java index 58d18c0..cce9564 100644 --- a/apiman-it-commons/src/main/java/io/apiman/test/integration/DeployedServices.java +++ b/apiman-it-commons/src/main/java/io/apiman/test/integration/DeployedServices.java @@ -30,11 +30,12 @@ public class DeployedServices { public static final String STATUS_CODE_ENDPOINT = REST_ROOT + "/status"; public static final String RESPONSE_REST_ROOT = REST_ROOT + "/response"; + public static final String TRANSFORM_REST_ROOT = REST_ROOT + "/transform"; public static final String REWRITING_REST_ROOT = REST_ROOT + "/url_rewriting"; public static final String DELAYED_RESPONSE = RESPONSE_REST_ROOT + "/delayedResponse"; - public static final String JSON_DATA = RESPONSE_REST_ROOT + "/json"; - public static final String XML_DATA = RESPONSE_REST_ROOT + "/xml"; + public static final String JSON_DATA = TRANSFORM_REST_ROOT + "/json"; + public static final String XML_DATA = TRANSFORM_REST_ROOT + "/xml"; public static final String URL_REWRITING_DATA = REWRITING_REST_ROOT + "/get_data_to_rewrite"; } diff --git a/apiman-it-deployments/src/main/java/io/apiman/test/integration/deployment/rest/TransformationService.java b/apiman-it-deployments/src/main/java/io/apiman/test/integration/deployment/rest/TransformationService.java index d0b30f5..739146d 100644 --- a/apiman-it-deployments/src/main/java/io/apiman/test/integration/deployment/rest/TransformationService.java +++ b/apiman-it-deployments/src/main/java/io/apiman/test/integration/deployment/rest/TransformationService.java @@ -16,19 +16,20 @@ package io.apiman.test.integration.deployment.rest; - - import io.apiman.test.integration.base.entity.TestData; +import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; /** * @author opontes */ -@Path("/response") +@Path("/transform") public class TransformationService { @GET @Path("/json") @Produces(MediaType.APPLICATION_JSON) @@ -36,8 +37,18 @@ public TestData getJSON(){ return new TestData(); } + @POST @Path("/json") @Consumes(MediaType.APPLICATION_JSON) + public Response postJSON(TestData testData){ + return Response.status((testData.equals(new TestData())) ? 200 : 500).build(); + } + @GET @Path("/xml") @Produces(MediaType.APPLICATION_XML) public TestData getXML(){ return new TestData(); } + + @POST @Path("/xml") @Consumes(MediaType.APPLICATION_XML) + public Response postXML(TestData testData){ + return Response.status((testData.equals(new TestData())) ? 200 : 500).build(); + } } diff --git a/apiman-it-rest/pom.xml b/apiman-it-rest/pom.xml index 5bce294..eb02518 100644 --- a/apiman-it-rest/pom.xml +++ b/apiman-it-rest/pom.xml @@ -50,8 +50,10 @@ ${version.jackson} test - - + + org.hamcrest + hamcrest-core + diff --git a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/AbstractTransformationIT.java b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/AbstractTransformationIT.java index ee21ed5..9a651d9 100644 --- a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/AbstractTransformationIT.java +++ b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/AbstractTransformationIT.java @@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.response.Response; + import io.apiman.test.integration.base.AbstractApiTest; import io.apiman.test.integration.base.entity.TestData; import io.apiman.test.integration.runner.annotations.entity.Plugin; @@ -60,6 +62,26 @@ protected String getJsonFromGateway(String link) { prettyPrint(); } + protected void postJsonToGateway(String link, String json){ + givenGateway(). + contentType(ContentType.JSON). + body(json). + when(). + post(link). + then(). + statusCode(200); + } + + protected void postXMLToGateway(String link, String xml){ + givenGateway(). + contentType(ContentType.XML). + body(xml). + when(). + post(link). + then(). + statusCode(200); + } + protected String getXmlFromTestService(String link) { return givenTestServices(). accept("application/xml"). diff --git a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToJsonIT.java b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToJsonIT.java index 60ecefd..d4b499a 100644 --- a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToJsonIT.java +++ b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToJsonIT.java @@ -16,6 +16,9 @@ package io.apiman.test.integration.rest.plugins.policies.transformplugin; +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + import io.apiman.test.integration.DeployedServices; import io.apiman.test.integration.base.entity.TestData; import io.apiman.test.integration.categories.PluginTest; @@ -28,7 +31,6 @@ import java.io.IOException; -import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -45,10 +47,16 @@ public class JsonToJsonIT extends AbstractTransformationIT { private String endpointJsonToJson; @Test - public void shouldNotMakeChangesOnJsonToJsonTransform() throws IOException { - TestData client = jsonToTestDataObject(getJsonFromTestService(DeployedServices.JSON_DATA)); - TestData server = jsonToTestDataObject(getJsonFromGateway(endpointJsonToJson)); - Assert.assertNotNull(client); - Assert.assertEquals(client, server); + public void shouldNotMakeChangesOnJsonToJsonTransformServerToClient() throws IOException { + TestData server = jsonToTestDataObject(getJsonFromTestService(DeployedServices.JSON_DATA)); + TestData client = jsonToTestDataObject(getJsonFromGateway(endpointJsonToJson)); + + assertThat(server, is(not(null))); + assertThat(server, is(equalTo(client))); + } + + @Test + public void shouldNotMakeChangesOnJsonToJsonTransformClientToServer(){ + postJsonToGateway(endpointJsonToJson, getJsonFromTestService(DeployedServices.JSON_DATA)); } } diff --git a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToXmlIT.java b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToXmlIT.java index 56a0b84..54df6f5 100644 --- a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToXmlIT.java +++ b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/JsonToXmlIT.java @@ -18,6 +18,10 @@ import static io.apiman.test.integration.runner.RestAssuredUtils.givenGateway; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + import io.apiman.test.integration.DeployedServices; import io.apiman.test.integration.base.entity.TestData; import io.apiman.test.integration.categories.PluginTest; @@ -30,7 +34,6 @@ import java.io.IOException; -import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -48,11 +51,16 @@ public class JsonToXmlIT extends AbstractTransformationIT { private String endpointJsonToXml; @Test - public void canTransformJsonToXml() throws IOException { - TestData client = jsonToTestDataObject(getJsonFromTestService(DeployedServices.JSON_DATA)); - TestData server = xmlToTestDataObject(getXmlFromGateway(endpointJsonToXml)); + public void canTransformJsonToXmlServerToClient() throws IOException { + TestData server = jsonToTestDataObject(getJsonFromTestService(DeployedServices.JSON_DATA)); + TestData client = xmlToTestDataObject(getXmlFromGateway(endpointJsonToXml)); + + assertThat(server, is(equalTo(client))); + } - Assert.assertEquals(client, server); + @Test + public void canTransformJsonToXmlClientToServer(){ + postXMLToGateway(endpointJsonToXml, getXmlFromTestService(DeployedServices.XML_DATA)); } @Override diff --git a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToJsonIT.java b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToJsonIT.java index 2eb0ae2..b46e6a0 100644 --- a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToJsonIT.java +++ b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToJsonIT.java @@ -16,9 +16,11 @@ package io.apiman.test.integration.rest.plugins.policies.transformplugin; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.apiman.manager.api.beans.apis.ApiVersionBean; -import io.apiman.manager.api.beans.apis.EndpointContentType; +import static io.apiman.test.integration.runner.RestAssuredUtils.givenGateway; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + import io.apiman.test.integration.DeployedServices; import io.apiman.test.integration.base.entity.TestData; import io.apiman.test.integration.base.entity.TestDataRoot; @@ -28,13 +30,14 @@ import io.apiman.test.integration.runner.annotations.misc.ManagedEndpoint; import io.apiman.test.integration.runner.annotations.misc.Policies; import io.apiman.test.integration.runner.annotations.version.ApiVersion; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import io.apiman.manager.api.beans.apis.ApiVersionBean; +import io.apiman.manager.api.beans.apis.EndpointContentType; import java.io.IOException; -import static io.apiman.test.integration.runner.RestAssuredUtils.givenGateway; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; +import org.junit.experimental.categories.Category; /** * @author opontes @@ -50,12 +53,17 @@ public class XmlToJsonIT extends AbstractTransformationIT { private String endpointXmlToJson; @Test - public void canTransformXmlToJson() throws IOException { - TestData client = xmlToTestDataObject(getXmlFromTestService(DeployedServices.XML_DATA)); - TestDataRoot server = jsonToTestDataRootObject(getJsonFromGateway(endpointXmlToJson)); + public void canTransformXmlToJsonServerToClient() throws IOException { + TestData server = xmlToTestDataObject(getXmlFromTestService(DeployedServices.XML_DATA)); + TestDataRoot client = jsonToTestDataRootObject(getJsonFromGateway(endpointXmlToJson)); + + assertThat(server, is(not(null))); + assertThat(server, is(equalTo(client))); + } - Assert.assertNotNull(client); - Assert.assertEquals(client, server.getTestData()); + @Test + public void canTransformXmlToJsonClientToServer(){ + postJsonToGateway(endpointXmlToJson, getJsonFromTestService(DeployedServices.JSON_DATA)); } protected TestDataRoot jsonToTestDataRootObject(String json) throws IOException { diff --git a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToXmlIT.java b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToXmlIT.java index f77f0d7..80de24a 100644 --- a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToXmlIT.java +++ b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/plugins/policies/transformplugin/XmlToXmlIT.java @@ -16,6 +16,9 @@ package io.apiman.test.integration.rest.plugins.policies.transformplugin; +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + import io.apiman.test.integration.DeployedServices; import io.apiman.test.integration.base.entity.TestData; import io.apiman.test.integration.categories.PluginTest; @@ -29,7 +32,6 @@ import java.io.IOException; -import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -47,10 +49,16 @@ public class XmlToXmlIT extends AbstractTransformationIT { private String endpointXmlToXml; @Test - public void shouldNotMakeChangesOnXmlToXmlTransform() throws IOException { - TestData client = xmlToTestDataObject(getXmlFromTestService(DeployedServices.XML_DATA)); - TestData server = xmlToTestDataObject(getXmlFromGateway(endpointXmlToXml)); - Assert.assertNotNull(client); - Assert.assertEquals(client, server); + public void shouldNotMakeChangesOnXmlToXmlTransformServerToClient() throws IOException { + TestData server = xmlToTestDataObject(getXmlFromTestService(DeployedServices.XML_DATA)); + TestData client = xmlToTestDataObject(getXmlFromGateway(endpointXmlToXml)); + + assertThat(server, is(not(null))); + assertThat(server, is(equalTo(client))); + } + + @Test + public void shouldNotMakeChangesOnXmlToXmlTransformClientToServer(){ + postXMLToGateway(endpointXmlToXml, getXmlFromTestService(DeployedServices.XML_DATA)); } } diff --git a/apiman-it-ui/pom.xml b/apiman-it-ui/pom.xml index 4f7ff48..b7ca381 100644 --- a/apiman-it-ui/pom.xml +++ b/apiman-it-ui/pom.xml @@ -62,6 +62,10 @@ org.slf4j slf4j-simple + + org.hamcrest + hamcrest-core + Automated UI tests for Apiman (API Management) by JBoss. diff --git a/pom.xml b/pom.xml index 9164cc1..ee6e9fc 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ 2.9.0 2.6.3 0.7.5.201505241946 + 1.3 @@ -91,6 +92,13 @@ commons-io ${version.commons-io} + + + org.hamcrest + hamcrest-core + ${version.hamcrest} + +