diff --git a/common/util/src/main/java/io/apiman/common/util/ApimanPathUtils.java b/common/util/src/main/java/io/apiman/common/util/ApimanPathUtils.java index 629054735c..8b8710d73d 100644 --- a/common/util/src/main/java/io/apiman/common/util/ApimanPathUtils.java +++ b/common/util/src/main/java/io/apiman/common/util/ApimanPathUtils.java @@ -69,6 +69,8 @@ public static final ApiRequestPathInfo parseApiRequestPath(String apiVersionHead resource.append('/'); } info.resource = resource.toString(); + } else if (pathInfo.endsWith("/")) { + info.resource = "/"; } } } diff --git a/common/util/src/test/java/io/apiman/common/util/ApimanPathUtilsTest.java b/common/util/src/test/java/io/apiman/common/util/ApimanPathUtilsTest.java new file mode 100644 index 0000000000..e6b1105bb8 --- /dev/null +++ b/common/util/src/test/java/io/apiman/common/util/ApimanPathUtilsTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 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.common.util; + +import org.junit.Assert; +import org.junit.Test; + +import io.apiman.common.util.ApimanPathUtils.ApiRequestPathInfo; + +public class ApimanPathUtilsTest { + + @Test + public void testParseApiRequestPath() { + ApiRequestPathInfo path = ApimanPathUtils.parseApiRequestPath(null, "application/json", "/OrgId/ApiId/VER/path/to/thing"); + Assert.assertEquals("OrgId", path.orgId); + Assert.assertEquals("ApiId", path.apiId); + Assert.assertEquals("VER", path.apiVersion); + Assert.assertEquals("/path/to/thing", path.resource); + + path = ApimanPathUtils.parseApiRequestPath(null, "application/json", "/OrgId/ApiId/VER"); + Assert.assertEquals("OrgId", path.orgId); + Assert.assertEquals("ApiId", path.apiId); + Assert.assertEquals("VER", path.apiVersion); + Assert.assertEquals(null, path.resource); + + path = ApimanPathUtils.parseApiRequestPath(null, "application/json", "/OrgId/ApiId/VER/"); + Assert.assertEquals("OrgId", path.orgId); + Assert.assertEquals("ApiId", path.apiId); + Assert.assertEquals("VER", path.apiVersion); + Assert.assertEquals("/", path.resource); + + path = ApimanPathUtils.parseApiRequestPath("VER", "application/json", "/OrgId/ApiId/path/to/thing"); + Assert.assertEquals("OrgId", path.orgId); + Assert.assertEquals("ApiId", path.apiId); + Assert.assertEquals("VER", path.apiVersion); + Assert.assertEquals("/path/to/thing", path.resource); + + path = ApimanPathUtils.parseApiRequestPath("VER", "application/json", "/OrgId/ApiId"); + Assert.assertEquals("OrgId", path.orgId); + Assert.assertEquals("ApiId", path.apiId); + Assert.assertEquals("VER", path.apiVersion); + Assert.assertEquals(null, path.resource); + + } + +} diff --git a/gateway/test/src/test/java/io/apiman/gateway/test/SimpleEcho1227Test.java b/gateway/test/src/test/java/io/apiman/gateway/test/SimpleEcho1227Test.java new file mode 100644 index 0000000000..13f572582b --- /dev/null +++ b/gateway/test/src/test/java/io/apiman/gateway/test/SimpleEcho1227Test.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 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 org.junit.runner.RunWith; + +/** + * Make sure the gateway and test echo server are working. + * + * @author eric.wittmann@redhat.com + */ +@RunWith(GatewayRestTester.class) +@GatewayRestTestPlan("test-plans/simple/simple-echo-1227-testPlan.xml") +public class SimpleEcho1227Test { + +} diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/001-publish-api.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/001-publish-api.resttest new file mode 100644 index 0000000000..3c6c537bb1 --- /dev/null +++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/001-publish-api.resttest @@ -0,0 +1,14 @@ +PUT /apis admin/admin +Content-Type: application/json + +{ + "organizationId" : "SimpleEcho1227Test", + "apiId" : "echo", + "version" : "1.0", + "publicAPI" : true, + "endpointType" : "REST", + "endpoint" : "${apiman-gateway-test.endpoints.echo}/endpoint/with-trailing-slash/", + "apiPolicies" : [ ] +} +---- +204 diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/002-echo.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/002-echo.resttest new file mode 100644 index 0000000000..6393c8ddde --- /dev/null +++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/002-echo.resttest @@ -0,0 +1,14 @@ +GET /SimpleEcho1227Test/echo/1.0/ admin/admin +Accept: application/json + +---- +200 +Content-Type: application/json + +{ + "method" : "GET", + "resource" : "/endpoint/with-trailing-slash/", + "uri" : "/endpoint/with-trailing-slash/", + "headers" : { + } +} diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/003-echo-2.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/003-echo-2.resttest new file mode 100644 index 0000000000..5c52ff44a2 --- /dev/null +++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/003-echo-2.resttest @@ -0,0 +1,14 @@ +GET /SimpleEcho1227Test/echo/1.0 admin/admin +Accept: application/json + +---- +200 +Content-Type: application/json + +{ + "method" : "GET", + "resource" : "/endpoint/with-trailing-slash", + "uri" : "/endpoint/with-trailing-slash", + "headers" : { + } +} diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/004-echo-3.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/004-echo-3.resttest new file mode 100644 index 0000000000..f86c0215c4 --- /dev/null +++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/004-echo-3.resttest @@ -0,0 +1,14 @@ +GET /SimpleEcho1227Test/echo/1.0/some/resource admin/admin +Accept: application/json + +---- +200 +Content-Type: application/json + +{ + "method" : "GET", + "resource" : "/endpoint/with-trailing-slash/some/resource", + "uri" : "/endpoint/with-trailing-slash/some/resource", + "headers" : { + } +} diff --git a/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/005-echo-4.resttest b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/005-echo-4.resttest new file mode 100644 index 0000000000..7a5cc8121b --- /dev/null +++ b/gateway/test/src/test/resources/test-plan-data/simple/simple-echo-1227/005-echo-4.resttest @@ -0,0 +1,14 @@ +GET /SimpleEcho1227Test/echo/1.0/some/resource/ admin/admin +Accept: application/json + +---- +200 +Content-Type: application/json + +{ + "method" : "GET", + "resource" : "/endpoint/with-trailing-slash/some/resource/", + "uri" : "/endpoint/with-trailing-slash/some/resource/", + "headers" : { + } +} diff --git a/gateway/test/src/test/resources/test-plans/simple/simple-echo-1227-testPlan.xml b/gateway/test/src/test/resources/test-plans/simple/simple-echo-1227-testPlan.xml new file mode 100644 index 0000000000..f86af6d958 --- /dev/null +++ b/gateway/test/src/test/resources/test-plans/simple/simple-echo-1227-testPlan.xml @@ -0,0 +1,16 @@ + + + + + + + test-plan-data/simple/simple-echo-1227/001-publish-api.resttest + + + + test-plan-data/simple/simple-echo-1227/002-echo.resttest + test-plan-data/simple/simple-echo-1227/003-echo-2.resttest + test-plan-data/simple/simple-echo-1227/004-echo-3.resttest + test-plan-data/simple/simple-echo-1227/005-echo-4.resttest + +