Skip to content

Commit

Permalink
Update Integration tests with Sem Versions in the API context
Browse files Browse the repository at this point in the history
Signed-off-by: Renuka Fernando <[email protected]>
  • Loading branch information
renuka-fernando committed Aug 31, 2023
1 parent 7f7ab87 commit 9425334
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
13 changes: 10 additions & 3 deletions adapter/internal/oasparser/envoyconf/envoyconf_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ func TestGenerateRegex(t *testing.T) {
message: "when the resource ends with *, trailing characters substitution passes",
isMatched: false,
},
{
inputpath: "/v2.0.0/pet/{petId}/images/*",
userInputPath: "/v2x0x0/pet/123/images/123-foo.png",
message: "when the version is semver, the dot should not matched with any character",
isMatched: false,
},
{
inputpath: "/v2/pet/{petId}/images/*",
userInputPath: "/v2/pet/123/images/123-foo.png",
Expand All @@ -416,8 +422,8 @@ func TestGenerateRegex(t *testing.T) {
},
{
inputpath: "/v2/pet/{petId}/images)/*",
userInputPath: "/v2/pet123/images/123-foo.png",
message: "when the resource ends with *, special char in the path and path params in the middle fails",
userInputPath: "/v2/pet/123/images/123-foo.png",
message: "when the resource ends with *, path params in the middle and special char in the path should exists",
isMatched: false,
},
{
Expand Down Expand Up @@ -458,7 +464,8 @@ func TestGenerateRegex(t *testing.T) {
if item.message == "when the resource ends with *" {
log.Default().Println(resultPattern, item.userInputPath, err)
}
assert.Equal(t, item.isMatched, resultIsMatching, item.message)
assert.Equal(t, item.isMatched, resultIsMatching, item.message,
map[string]string{"inputpath": item.inputpath, "resultPattern": resultPattern, "userInputPath": item.userInputPath})
assert.Nil(t, err)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ApiLevelRatelimitTestCase {
public void createApiProject() throws Exception {
API api = new API();
api.setName("ratelimit");
api.setContext("v2/ratelimitService");
api.setContext("v1.0.0/ratelimitService");
api.setVersion("1.0.0");
api.setProvider("admin");

Expand All @@ -55,7 +55,7 @@ public void createApiProject() throws Exception {

testKey = TokenUtil.getJWT(api, applicationDto, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION,
3600, null, true);
endpointURL = Utils.getServiceURLHttps("/v2/ratelimitService/pet/findByStatus");
endpointURL = Utils.getServiceURLHttps("/v1.0.0/ratelimitService/pet/findByStatus");
headers.put("Internal-Key", testKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class OperationLevelRatelimitTestCase {
public void createApiProject() throws Exception {
API api = new API();
api.setName("ratelimit");
api.setContext("v2/operationLevelRL");
api.setContext("v1.0.0/operationLevelRL");
api.setVersion("1.0.0");
api.setProvider("admin");

Expand All @@ -57,7 +57,7 @@ public void createApiProject() throws Exception {

@Test(description = "Test operation level 3 permin rate-limiting with envoy rate-limit service")
public void testRateLimitsWithEnvoyRateLimitService3PerMin() throws Exception {
String endpointURL = Utils.getServiceURLHttps("/v2/operationLevelRL/pet/findByStatus");
String endpointURL = Utils.getServiceURLHttps("/v1.0.0/operationLevelRL/pet/findByStatus");
Assert.assertTrue(RateLimitUtils.isThrottled(
RateLimitUtils.sendMultipleRequests(endpointURL, headers, 4)),
"Operation level rate-limit 3 per min testcase failed.");
Expand All @@ -66,8 +66,8 @@ public void testRateLimitsWithEnvoyRateLimitService3PerMin() throws Exception {
@Test(description = "Test operation level 5 per min rate-limiting with envoy rate-limit service")
public void testRateLimitsWithEnvoyRateLimitService5PerMin() throws Exception {
String requestData = "Payload to create pet 5";
String endpointURL1 = Utils.getServiceURLHttps("/v2/operationLevelRL/pet/3");
String endpointURL2 = Utils.getServiceURLHttps("/v2/operationLevelRL/pet/4");
String endpointURL1 = Utils.getServiceURLHttps("/v1.0.0/operationLevelRL/pet/3");
String endpointURL2 = Utils.getServiceURLHttps("/v1.0.0/operationLevelRL/pet/4");
RateLimitUtils.sendMultipleRequests(endpointURL2, headers, 2);
Assert.assertTrue(RateLimitUtils.isThrottled(
RateLimitUtils.sendMultipleRequests(endpointURL1, headers, 4))
Expand All @@ -81,7 +81,7 @@ public void testRateLimitsWithEnvoyRateLimitService5PerMin() throws Exception {

@Test(description = "Test an operation without defining envoy rate-limits")
public void testOperationWithoutEnvoyRateLimits() throws Exception {
String endpointURL = Utils.getServiceURLHttps("/v2/operationLevelRL/pets/findByTags");
String endpointURL = Utils.getServiceURLHttps("/v1.0.0/operationLevelRL/pets/findByTags");
HttpResponse response = HttpsClientRequest.doGet(endpointURL, headers);
Map<String,String> responseHeadersMap = response.getHeaders();
Assert.assertTrue(!responseHeadersMap.containsKey("x-ratelimit-limit"), "x-ratelimit-limit header available");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: v4.1.0
data:
id: 2b547d7c-4f7b-4f31-ad6b-05b4960dc123
name: operationLevelRateLimit
context: /v2/operationLevelRL
context: /v1.0.0/operationLevelRL
version: 1.0.0
provider: admin
lifeCycleStatus: PUBLISHED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: v4.1.0
data:
id: 2b547d7c-4f7b-4f31-ad6b-05b4960dcbf1
name: ratelimit
context: /v2/ratelimitService
context: /v1.0.0/ratelimitService
version: 1.0.0
apiThrottlingPolicy: 5PerMinute
throttlingLimit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ x-wso2-endpoints:
urls:
- http://mockBackend:2390/v2 # same base path as x-wso2-production-endpoints
type: loadbalance
x-wso2-basePath: /v2/operationLevelRL
x-wso2-basePath: /v1.0.0/operationLevelRL
schemes:
- http
paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ x-wso2-endpoints:
urls:
- http://mockBackend:2390/v2 # same base path as x-wso2-production-endpoints
type: loadbalance
x-wso2-basePath: /v2/ratelimitService
x-wso2-basePath: /v1.0.0/ratelimitService
schemes:
- http
paths:
Expand Down

0 comments on commit 9425334

Please sign in to comment.