Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Add transform tests fot client -> server #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,39 @@

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)
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();
}
}
6 changes: 4 additions & 2 deletions apiman-it-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
<version>${version.jackson}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +31,6 @@

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +34,6 @@

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +32,6 @@

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand All @@ -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));
}
}
4 changes: 4 additions & 0 deletions apiman-it-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</dependency>
</dependencies>

<description>Automated UI tests for Apiman (API Management) by JBoss.</description>
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<version.restassred>2.9.0</version.restassred>
<version.jackson>2.6.3</version.jackson>
<version.jacoco>0.7.5.201505241946</version.jacoco>
<version.hamcrest>1.3</version.hamcrest>
<!-- Build influencing properties -->
<groups></groups>
<groups.exclude></groups.exclude>
Expand Down Expand Up @@ -91,6 +92,13 @@
<artifactId>commons-io</artifactId>
<version>${version.commons-io}</version>
</dependency>
<!-- Assertion -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${version.hamcrest}</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down