Skip to content

Commit 93fabd5

Browse files
committed
Test headless generator when strange names used and multiple generated names.
1 parent 69ff195 commit 93fabd5

File tree

4 files changed

+88
-6
lines changed

4 files changed

+88
-6
lines changed

src/main/java/io/apiman/cli/gatewayapi/command/ListOrgCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ public void setGatewayApiFactory(GatewayApiFactory apiFactory) {
5656
this.apiFactory = apiFactory;
5757
}
5858

59+
protected boolean permitNoArgs() {
60+
return true;
61+
}
5962
}

src/test/java/io/apiman/cli/gatewayapi/command/generate/GenerateHeadlessTest.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void testGenerateConfig_writeToDirectory() throws Exception {
9292
}
9393

9494
@Test
95-
public void testGenerateConfig_withOutputFile() throws Exception {
95+
public void testGenerateConfig_withExplicitOutputFilename() throws Exception {
9696
command.setJsonWriter(mJsonWriter);
9797

9898
command.setDeclarationFile(getResourceAsPath("/gateway/generateHeadless/plugin-and-builtin-policies.yml"));
@@ -107,7 +107,21 @@ public void testGenerateConfig_withOutputFile() throws Exception {
107107
}
108108

109109
@Test
110-
public void testGenerateConfig_withMultipleGatewayConfigs() throws Exception {
110+
public void testGenerateConfig_withTransformedName() throws Exception {
111+
command.setJsonWriter(mJsonWriter);
112+
113+
command.setDeclarationFile(getResourceAsPath("/gateway/generateHeadless/transform-name.yml"));
114+
command.outputFiles.add(Paths.get("/tmp"));
115+
// Run
116+
command.applyDeclaration();
117+
// Verify
118+
HeadlessConfigBean expected = expectJson("/gateway/generateHeadless/transform-name.json", HeadlessConfigBean.class);
119+
// Space-type characters and forward slashes should be substituted with -
120+
verify(mJsonWriter).write(eq(Paths.get("/tmp/gateway-with-various-spaces-in-original-᠎-name-and-forward-slash--.json")), refEq(expected));
121+
}
122+
123+
@Test
124+
public void testGenerateConfig_withMultipleGatewayConfigs_ExplicitName() throws Exception {
111125
command.setJsonWriter(mJsonWriter);
112126

113127
command.setDeclarationFile(getResourceAsPath("/gateway/generateHeadless/plugin-and-builtin-policies_multiple-gateways.yml"));
@@ -116,11 +130,26 @@ public void testGenerateConfig_withMultipleGatewayConfigs() throws Exception {
116130
// Run
117131
command.applyDeclaration();
118132
// Verify it matches our reference configs.
119-
HeadlessConfigBean expectedApi = expectJson("/gateway/generateHeadless/expected-multiple-gateways.json", HeadlessConfigBean.class);
120-
HeadlessConfigBean expectedApi2 = expectJson("/gateway/generateHeadless/expected-multiple-gateways-2.json", HeadlessConfigBean.class);
133+
HeadlessConfigBean expectedConfig1 = expectJson("/gateway/generateHeadless/expected-multiple-gateways.json", HeadlessConfigBean.class);
134+
HeadlessConfigBean expectedConfig2 = expectJson("/gateway/generateHeadless/expected-multiple-gateways-2.json", HeadlessConfigBean.class);
121135

122-
verify(mJsonWriter).write(eq(Paths.get("/tmp/someOutputFile.json")), refEq(expectedApi));
123-
verify(mJsonWriter).write(eq(Paths.get("/tmp/someOutputFile2.json")), refEq(expectedApi2));
136+
verify(mJsonWriter).write(eq(Paths.get("/tmp/someOutputFile.json")), refEq(expectedConfig1));
137+
verify(mJsonWriter).write(eq(Paths.get("/tmp/someOutputFile2.json")), refEq(expectedConfig2));
124138
}
125139

140+
@Test
141+
public void testGenerateConfig_withMultipleGatewayConfigs_GeneratedName() throws Exception {
142+
command.setJsonWriter(mJsonWriter);
143+
144+
command.setDeclarationFile(getResourceAsPath("/gateway/generateHeadless/plugin-and-builtin-policies_multiple-gateways.yml"));
145+
command.outputFiles.add(Paths.get("/tmp")); // Directory.
146+
// Run
147+
command.applyDeclaration();
148+
// Verify it matches our reference configs.
149+
HeadlessConfigBean expectedConfig1 = expectJson("/gateway/generateHeadless/expected-multiple-gateways.json", HeadlessConfigBean.class);
150+
HeadlessConfigBean expectedConfig2 = expectJson("/gateway/generateHeadless/expected-multiple-gateways-2.json", HeadlessConfigBean.class);
151+
152+
verify(mJsonWriter).write(eq(Paths.get("/tmp/test-gw-2.json")), refEq(expectedConfig1)); // Notice generated filenames
153+
verify(mJsonWriter).write(eq(Paths.get("/tmp/test-gw.json")), refEq(expectedConfig2));
154+
}
126155
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"apis" : [ {
3+
"publicAPI" : true,
4+
"organizationId" : "test",
5+
"apiId" : "example",
6+
"version" : "1.0",
7+
"endpoint" : "http://localhost:8080/services/echo",
8+
"endpointType" : "rest",
9+
"endpointContentType" : null,
10+
"endpointProperties" : { },
11+
"parsePayload" : false,
12+
"apiPolicies" : [ {
13+
"policyJsonConfig" : "{\n \"ttl\" : 60\n}",
14+
"policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy"
15+
}, {
16+
"policyJsonConfig" : "{\n \"foo\" : 123\n}",
17+
"policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.3.1.Final:war/io.apiman.plugins.test_policy.TestPolicy"
18+
} ],
19+
"maxPayloadBufferSize" : 0
20+
} ],
21+
"clients" : [ ]
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Simple apiman gateway declaration
2+
---
3+
system:
4+
gateways:
5+
- name: "gateway with various spaces in original ᠎ name and forward slash /"
6+
type: "REST"
7+
plugins:
8+
- name: TestPolicy
9+
groupId: "io.apiman.plugins"
10+
artifactId: "apiman-plugins-test-policy"
11+
version: "1.3.1.Final"
12+
org:
13+
name: "test"
14+
apis:
15+
- name: "example"
16+
version: "1.0"
17+
config:
18+
endpoint: "http://localhost:8080/services/echo"
19+
endpointType: "rest"
20+
public: true
21+
gateway: "gateway with various spaces in original ᠎ name and forward slash /"
22+
policies:
23+
- name: "CachingPolicy"
24+
config:
25+
ttl: 60
26+
- plugin: TestPolicy
27+
config:
28+
foo: 123

0 commit comments

Comments
 (0)