test(manager-api): create initial blob rest-test suite
MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ApiManagerApplication.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ApiManagerApplication.java
@@ -20,6 +20,7 @@ import io.apiman.manager.api.config.Version;
import io.apiman.manager.api.exportimport.manager.ExportImportManager;
import io.apiman.manager.api.providers.JacksonObjectMapperProvider;
import io.apiman.manager.api.providers.eager.EagerProvider;
+import io.apiman.manager.api.rest.exceptions.mappers.IllegalArgumentExceptionMapper;
import io.apiman.manager.api.rest.exceptions.mappers.RestExceptionMapper;
import io.apiman.manager.api.rest.interceptors.BlobResourceInterceptorProvider;
import io.apiman.manager.api.rest.interceptors.TotalCountInterceptorProvider;
@@ -82,6 +83,7 @@ public class ApiManagerApplication extends Application {
classes.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
classes.add(RestExceptionMapper.class);
+ classes.add(IllegalArgumentExceptionMapper.class);
registerProviders(
JacksonObjectMapperProvider.class,

MODIFY
manager/test/api/src/main/java/io/apiman/manager/test/server/TestManagerApiApplication.java
manager/test/api/src/main/java/io/apiman/manager/test/server/TestManagerApiApplication.java
*/
package io.apiman.manager.test.server;
+import io.apiman.manager.api.rest.exceptions.mappers.IllegalArgumentExceptionMapper;
import io.apiman.manager.api.rest.exceptions.mappers.RestExceptionMapper;
-import io.apiman.manager.api.rest.impl.*;
+import io.apiman.manager.api.rest.impl.ActionResourceImpl;
+import io.apiman.manager.api.rest.impl.ApiManagerApplication;
+import io.apiman.manager.api.rest.impl.BlobResourceImpl;
+import io.apiman.manager.api.rest.impl.DeveloperPortalResourceImpl;
+import io.apiman.manager.api.rest.impl.DeveloperResourceImpl;
+import io.apiman.manager.api.rest.impl.DownloadResourceImpl;
+import io.apiman.manager.api.rest.impl.EventResourceImpl;
+import io.apiman.manager.api.rest.impl.GatewayResourceImpl;
+import io.apiman.manager.api.rest.impl.OrganizationResourceImpl;
+import io.apiman.manager.api.rest.impl.PluginResourceImpl;
+import io.apiman.manager.api.rest.impl.PolicyDefinitionResourceImpl;
+import io.apiman.manager.api.rest.impl.RoleResourceImpl;
+import io.apiman.manager.api.rest.impl.SearchResourceImpl;
+import io.apiman.manager.api.rest.impl.SystemResourceImpl;
+import io.apiman.manager.api.rest.impl.UserResourceImpl;
-import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
+import javax.ws.rs.core.Application;
/**
* JAX-RS {@link Application} used for testing.
@@ -47,7 +62,13 @@ public class TestManagerApiApplication extends ApiManagerApplication {
classes.add(ActionResourceImpl.class);
classes.add(DownloadResourceImpl.class);
classes.add(DeveloperResourceImpl.class);
+ classes.add(BlobResourceImpl.class);
+ classes.add(EventResourceImpl.class);
+ classes.add(DeveloperPortalResourceImpl.class);
+
classes.add(RestExceptionMapper.class);
+ classes.add(IllegalArgumentExceptionMapper.class);
+
}
@Override

ADD
manager/test/api/src/test/java/io/apiman/manager/test/BlobTest.java
+package io.apiman.manager.test;
+
+import io.apiman.manager.test.junit.ManagerRestTestPlan;
+import io.apiman.manager.test.junit.ManagerRestTester;
+
+import org.junit.runner.RunWith;
+
+/**
+ *
+ *
+ * @author Marc Savy {@literal <marc@blackparrotlabs.io>}
+ */
+@RunWith(ManagerRestTester.class)
+@ManagerRestTestPlan("test-plans/blob-testPlan.xml")
+public class BlobTest {
+
+}

ADD
manager/test/api/src/test/resources/test-plan-data/blob/blob/000_upload-blob.resttest
+POST /blobs admin/admin
+Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryK0tqGVjGnX7JurwW
+
+------WebKitFormBoundaryK0tqGVjGnX7JurwW
+Content-Disposition: form-data; name="image"; filename="blob"
+Content-Type: image/svg
+
+<svg height="100" width="100">
+ <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
+</svg>
+
+------WebKitFormBoundaryK0tqGVjGnX7JurwW--
+
+----
+201
+Content-Type: application/json
+X-RestTest-BindTo-blob-id-1: id
+
+{
+ "mimeType": "image/svg"
+}
\ No newline at end of file

ADD
manager/test/api/src/test/resources/test-plan-data/blob/blob/001_get-blob.resttest
+GET /blobs/${blob-id-1} admin/admin
+
+----
+200
+Content-Type: image/svg
+
+<svg height="100" width="100">
+ <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
+</svg>
\ No newline at end of file

ADD
manager/test/api/src/test/resources/test-plan-data/blob/blob/002_update-api-with-image-blob.resttest
+PUT /organizations/Organization1/apis/API1 admin/admin
+Content-Type: application/json
+
+{
+ "image": "${blob-id-1}"
+}
+----
+204
+

ADD
manager/test/api/src/test/resources/test-plan-data/blob/blob/003_get-api-assert-image.resttest
+GET /organizations/Organization1/apis/API1 admin/admin
+----
+200
+Content-Type: application/json
+
+{
+ "organization" : {
+ "id" : "Organization1"
+ },
+ "id" : "API1",
+ "name" : "API 1",
+ "description" : "This is the description of API 1.",
+ "createdBy" : "admin",
+ "image": "blobs/${blob-id-1}"
+}

ADD
manager/test/api/src/test/resources/test-plan-data/blob/create/000_create-gateway.resttest
+POST /gateways admin/admin
+Content-Type: application/json
+
+{
+ "name" : "The Gateway",
+ "description" : "This is the gateway.",
+ "type" : "REST",
+ "configuration" : "{ \"endpoint\" : \"${apiman.test.gateway.endpoint}\", \"username\" : \"${apiman.test.gateway.username}\", \"password\" : \"${apiman.test.gateway.password}\" }"
+}
+----
+200
+Content-Type: application/json
+
+{
+ "id" : "TheGateway",
+ "name" : "The Gateway",
+ "description" : "This is the gateway.",
+ "type" : "REST",
+ "configuration" : "{\"endpoint\":\"${apiman.test.gateway.endpoint}\",\"username\":\"${apiman.test.gateway.username}\",\"password\":\"${apiman.test.gateway.password}\"}"
+}

ADD
manager/test/api/src/test/resources/test-plan-data/blob/create/001_create-org.resttest
+POST /organizations admin/admin
+Content-Type: application/json
+
+{"name":"Organization 1"}
+----
+200
+Content-Type: application/json
+
+{
+ "name" : "Organization 1",
+ "id" : "Organization1"
+}

ADD
manager/test/api/src/test/resources/test-plan-data/blob/create/002_create-api.resttest
+POST /organizations/Organization1/apis admin/admin
+Content-Type: application/json
+
+{
+ "name" : "API 1",
+ "description" : "This is the description of API 1."
+}
+----
+200
+Content-Type: application/json
+
+{
+ "organization" : {
+ "id" : "Organization1"
+ },
+ "id" : "API1",
+ "name" : "API 1",
+ "description" : "This is the description of API 1.",
+ "createdBy" : "admin"
+}

ADD
manager/test/api/src/test/resources/test-plans/blob-testplan.xml
+<?xml version="1.0" encoding="UTF-8"?>
+<testPlan xmlns="urn:io.apiman.test:2014:02:testPlan" name="Blob service (binary) tests">
+
+ <!-- Create Organizations -->
+ <testGroup name="Initial Creates">
+ <test name="Create Gateway">test-plan-data/blob/create/000_create-gateway.resttest</test>
+ <test name="Create Organization">test-plan-data/blob/create/001_create-org.resttest</test>
+ <test name="Create API">test-plan-data/blob/create/002_create-api.resttest</test>
+ </testGroup>
+
+ <!-- Test API management -->
+ <testGroup name="API Management">
+ <test name="Upload blob (SVG image)">test-plan-data/blob/blob/000_upload-blob.resttest</test>
+ <test name="Get the uploaded blob">test-plan-data/blob/blob/001_get-blob.resttest</test>
+ <test name="Update API to use blob image">test-plan-data/blob/blob/002_update-api-with-image-blob.resttest</test>
+ <test name="Verify API has image attached">test-plan-data/blob/blob/003_get-api-assert-image.resttest</test>
+<!-- <test name="Verify API image"></test>-->
+<!-- <test name="Delete API"></test>-->
+<!-- <test name="Verify API image missing"></test>-->
+ </testGroup>
+</testPlan>
\ No newline at end of file

MODIFY
test/common/src/main/java/io/apiman/test/common/util/TestPlanRunner.java
test/common/src/main/java/io/apiman/test/common/util/TestPlanRunner.java
@@ -31,6 +31,7 @@ import java.io.StringWriter;
import java.net.ProtocolException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.List;
@@ -61,7 +62,6 @@ import org.mvel2.MVEL;
import org.mvel2.integration.PropertyHandler;
import org.mvel2.integration.PropertyHandlerFactory;
import org.mvel2.integration.VariableResolverFactory;
-import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -271,10 +271,15 @@ public class TestPlanRunner {
assertTextPayload(restTest, response);
} else if (ctValueFirst.startsWith("application/xml") || ctValueFirst.startsWith("application/wsdl+xml") || ctValueFirst.startsWith("text/xml")) {
assertXmlPayload(restTest, response);
- } else {
- Assert.fail("Unsupported response payload type: " + ctValueFirst);
+ } else if (ctValueFirst.startsWith("image/")) {
+ assertBinaryEquals(restTest, response);
+ }
}
}
+
+ private void assertBinaryEquals(RestTest restTest, Response response) {
+ byte[] expected = restTest.getExpectedResponsePayload().getBytes(StandardCharsets.UTF_8);
+ assertThat(response.binary()).isEqualTo(expected);
}
/**

MODIFY
test/common/src/main/java/io/apiman/test/common/util/TestUtil.java
test/common/src/main/java/io/apiman/test/common/util/TestUtil.java
@@ -139,7 +139,7 @@ public class TestUtil {
// Request Headers
line = reader.readLine();
- if (!line.trim().startsWith("----")) {
+ if (!line.trim().equals("----")) {
while (line.trim().length() > 0) {
int idx = line.indexOf(':');
String headerName = line.substring(0, idx).trim();
@@ -151,7 +151,7 @@ public class TestUtil {
// Request payload
StringBuilder builder = new StringBuilder();
line = reader.readLine();
- while (!line.trim().startsWith("----")) {
+ while (!line.trim().equals("----")) {
builder.append(line).append("\n");
line = reader.readLine();
line = doPropertyReplacement(line);
@@ -178,7 +178,7 @@ public class TestUtil {
if (line != null) {
StringBuilder builder = new StringBuilder();
line = reader.readLine();
- while (line != null && !line.trim().startsWith("----")) {
+ while (line != null && !line.trim().equals("----")) {
builder.append(line).append("\n");
line = reader.readLine();
}

test(manager-api): create initial blob rest-test suite