test(gateway-test): Test policy failure processing.
MODIFY
gateway/test/src/test/java/io/apiman/gateway/test/PluginTestPolicyTest.java
gateway/test/src/test/java/io/apiman/gateway/test/PluginTestPolicyTest.java
*/
package io.apiman.gateway.test;
+import io.apiman.gateway.test.junit.GatewayRestTestPlan;
+import io.apiman.gateway.test.junit.GatewayRestTester;
+
import java.io.File;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
-import io.apiman.gateway.test.junit.GatewayRestTestPlan;
-import io.apiman.gateway.test.junit.GatewayRestTester;
-
/**
* Make sure plugins work.
*

ADD
gateway/test/src/test/java/io/apiman/gateway/test/Policy_ProcessFailure.java
+/*
+ * Copyright 2018 JBoss Inc
+ *
+ * Licensed 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 io.apiman.gateway.test;
+
+import io.apiman.gateway.test.junit.GatewayRestTestPlan;
+import io.apiman.gateway.test.junit.GatewayRestTester;
+
+import java.io.File;
+
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+
+/**
+ * Process failure tests.
+ *
+ * @author Marc Savy {@literal <marc@rhymewithgravy.com>}
+ */
+@RunWith(GatewayRestTester.class)
+@GatewayRestTestPlan("test-plans/policies/failure-processing-policy-testPlan.xml")
+public class Policy_ProcessFailure {
+
+ @BeforeClass
+ public static void before() {
+ System.setProperty("apiman.gateway.m2-repository-path", new File("src/test/resources/test-plan-data/plugins/.m2/repository").getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}

ADD
gateway/test/src/test/resources/test-plan-data/plugins/.m2/repository/io/apiman/apiman-plugins-test-policy/1.4.4-SNAPSHOT/apiman-plugins-test-policy-1.4.4-SNAPSHOT.war
gateway/test/src/test/resources/test-plan-data/plugins/.m2/repository/io/apiman/apiman-plugins-test-policy/1.4.4-SNAPSHOT/apiman-plugins-test-policy-1.4.4-SNAPSHOT.war
Binary files /dev/null and b/gateway/test/src/test/resources/test-plan-data/plugins/.m2/repository/io/apiman/apiman-plugins-test-policy/1.4.4-SNAPSHOT/apiman-plugins-test-policy-1.4.4-SNAPSHOT.war differ

ADD
gateway/test/src/test/resources/test-plan-data/policies/failure-processing/001-publish-api.resttest
+PUT /apis admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_FailureProcessingTest",
+ "apiId" : "echo",
+ "version" : "1.0.0",
+ "endpointType" : "REST",
+ "endpoint" : "${apiman-gateway-test.endpoints.echo}/"
+}
+----
+204

ADD
gateway/test/src/test/resources/test-plan-data/policies/failure-processing/002-register-client.resttest
+PUT /clients admin/admin
+Content-Type: application/json
+
+{
+ "organizationId" : "Policy_FailureProcessingTest",
+ "clientId" : "test",
+ "version" : "1.0.0",
+ "apiKey" : "12345",
+ "contracts" : [
+ {
+ "apiOrgId" : "Policy_FailureProcessingTest",
+ "apiId" : "echo",
+ "apiVersion" : "1.0.0",
+ "policies" : [
+ {
+ "policyImpl" : "class:io.apiman.gateway.engine.policies.RateLimitingPolicy",
+ "policyJsonConfig" : "{ \"limit\" : 0, \"granularity\" : \"Client\", \"period\" : \"Hour\" }"
+ },
+ {
+ "policyImpl" : "plugin:io.apiman:apiman-plugins-test-policy:1.4.4-SNAPSHOT:war/io.apiman.plugins.test_policy.TestPolicy",
+ "policyJsonConfig" : ""
+ }
+ ]
+ }
+ ]
+}
+----
+204

ADD
gateway/test/src/test/resources/test-plan-data/policies/failure-processing/003-failure.resttest
+GET /Policy_FailureProcessingTest/echo/1.0.0/path/to/app/resource admin/admin
+X-API-Key: 12345
+
+----
+429
+Content-Type: application/json
+X-Policy-Failure-Type: Other
+X-Policy-Failure-Code: 10005
+Test-Policy-Process-Failure: true
+
+{
+ "type" : "Other",
+ "failureCode" : 10005
+}

ADD
gateway/test/src/test/resources/test-plans/policies/failure-processing-policy-testPlan.xml
+<?xml version="1.0" encoding="UTF-8"?>
+<testPlan xmlns="urn:io.apiman.test:2014:02:testPlan">
+
+ <testGroup name="Configure the Gateway" endpoint="api">
+ <test name="Publish Api">test-plan-data/policies/failure-processing/001-publish-api.resttest</test>
+ <test name="Register Client">test-plan-data/policies/failure-processing/002-register-client.resttest</test>
+ </testGroup>
+
+ <testGroup name="Trigger policy failure. Expect processing of failures.">
+ <test name="Hit rate limit, then TestPolicy processes failure.">test-plan-data/policies/failure-processing/003-failure.resttest</test>
+ </testGroup>
+
+</testPlan>

test(gateway-test): Test policy failure processing.

Signed-off-by: Marc Savy <marc@rhymewithgravy.com>