Skip to content

Commit 4256456

Browse files
committed
test with base path properties (#176)
1 parent b17123f commit 4256456

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
items:
2-
- outputs/api/Api.java
2+
- outputs/java/api/Api.java
3+
- outputs/resources/api.properties

openapi-processor-core/src/testInt/resources/tests/server-url/outputs/api/Api.java renamed to openapi-processor-core/src/testInt/resources/tests/server-url/outputs/java/api/Api.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package generated.api;
22

33
import annotation.Mapping;
4-
import annotation.Prefix;
54
import generated.support.Generated;
65

76
@Generated(value = "openapi-processor-core", version = "test")
8-
@Prefix("/foo/bar/v1")
97
public interface Api {
108

119
@Mapping("/foo")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openapi.base.path = /foo/bar/v1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 https://github.com/openapi-processor/openapi-processor-base
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.test
7+
8+
class Expected {
9+
TestSet testSet
10+
String packageName
11+
TestItemsReader reader
12+
13+
String path
14+
Set<String> items
15+
16+
Expected(TestSet testSet, String packageName, TestItemsReader reader) {
17+
this.testSet = testSet
18+
this.packageName = packageName
19+
this.reader = reader
20+
21+
def sourcePath = "/tests/${testSet.name}"
22+
path = "${sourcePath}/${testSet.expected}"
23+
items = files (sourcePath, testSet.expected)
24+
}
25+
26+
/**
27+
* get the expected files (from outputs.yaml) and strips the prefix.
28+
*
29+
* @param path the resource path of the test, i.e. /tests/{test-name}
30+
* @param stripPrefix prefix to strip, i.e. inputs/outputs folder
31+
* @return the expected files
32+
*/
33+
private Set<String> files(String path, String stripPrefix) {
34+
def items = reader.read (path, testSet.outputs)
35+
36+
def wanted = items.items.collect {
37+
it.substring (stripPrefix.size () + 1)
38+
}
39+
40+
def result = new TreeSet<String> ()
41+
result.addAll (wanted)
42+
result
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2024 https://github.com/openapi-processor/openapi-processor-base
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.test
7+
8+
import com.fasterxml.jackson.databind.DeserializationFeature
9+
import com.fasterxml.jackson.databind.ObjectMapper
10+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
11+
12+
class TestItemsReader {
13+
private Class resourceBase
14+
15+
TestItemsReader(Class resourceBase) {
16+
this.resourceBase = resourceBase
17+
}
18+
19+
/**
20+
* read test items yaml
21+
*
22+
* @param resource path
23+
* @param name of test items yaml file
24+
* @return content of yaml
25+
*/
26+
TestItems read (String path, String itemsYaml) {
27+
def source = getResource ("${path}/${itemsYaml}")
28+
if (!source) {
29+
println "ERROR: missing '${path}/${itemsYaml}' configuration file!"
30+
}
31+
32+
def mapper = createYamlParser ()
33+
mapper.readValue (source.text, TestItems)
34+
}
35+
36+
InputStream getResource (String path) {
37+
resourceBase.getResourceAsStream (path)
38+
}
39+
40+
private static ObjectMapper createYamlParser () {
41+
new ObjectMapper (new YAMLFactory ()).configure (DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
42+
}
43+
}

0 commit comments

Comments
 (0)