|
| 1 | +:badge-license: https://img.shields.io/badge/License-Apache%202.0-blue.svg?labelColor=313A42 |
| 2 | +:badge-ci: https://github.com/hauner/openapi-processor-test/workflows/ci/badge.svg |
| 3 | +:oaps-ci: https://github.com/hauner/openapi-processor-test/actions?query=workflow%3Aci |
| 4 | +:oaps-license: https://github.com/hauner/openapi-processor-test/blob/master/LICENSE |
| 5 | +:oap-docs: https://hauner.github.com/openapi-processor/spring/current/index.html |
| 6 | +:opa-core: https://github.com/hauner/openapi-processor-test |
| 7 | +:opa-spring: https://github.com/hauner/openapi-processor-spring |
| 8 | + |
| 9 | +// badges |
| 10 | +//link:{oaps-ci}[image:{badge-ci}[]] |
| 11 | +link:{oaps-license}[image:{badge-license}[]] |
| 12 | + |
| 13 | + |
| 14 | +== openapi-processor-test |
| 15 | + |
| 16 | +this contains re-usable code and data for testing openapi-processors. |
| 17 | + |
| 18 | +=== test code/data |
| 19 | + |
| 20 | +A test case does an end-to-end test of an openapi-processor. |
| 21 | + |
| 22 | +`resources/tests` contains the input files of a number of tests. The name of the folder is the name |
| 23 | +of the test case. |
| 24 | + |
| 25 | +A test case contains an `openapi.yaml` and a `mapping.yaml` file in the `inputs` folder. An |
| 26 | +`inputs.yaml` sibling file of the `inputs` folder list the files in the folder. |
| 27 | + |
| 28 | +To provide the expected output of the test case a consumer of oap-test creates a |
| 29 | +`resources/tests/<integration test name>` folder in its *own* resources. Inside it a `generated` folder |
| 30 | +and a `generated.yaml` with the list of expected files in the corresponding folder. |
| 31 | + |
| 32 | +A test case can contain both inputs and outputs. So it is easy to create additional tests without |
| 33 | +touching oap-test. |
| 34 | + |
| 35 | +To run the test cases a consumer creates an `@RunWith(Parameterized)` junit test which extends |
| 36 | +`com.github.hauner.openapi.test.ProcessorTestBase`. The `@Parameterized` method provides the list of |
| 37 | +test cases to run. |
| 38 | + |
| 39 | +==== example |
| 40 | + |
| 41 | +the inputs: |
| 42 | + |
| 43 | + resources/tests/my-test |
| 44 | + +--- inputs.yaml |
| 45 | + \--- inputs |
| 46 | + +--- mapping.yaml |
| 47 | + \--- openapi.yaml |
| 48 | + |
| 49 | +the expected files: |
| 50 | + |
| 51 | + resources/tests/my-test |
| 52 | + +--- generated.yaml |
| 53 | + \--- generated |
| 54 | + +--- api |
| 55 | + | \--- EndpointApi.java |
| 56 | + \--- model |
| 57 | + \--- Foo.java |
| 58 | + |
| 59 | +the `inputs.yaml` and `generated.yaml` use the same simple format: |
| 60 | + |
| 61 | + items: |
| 62 | + - inputs/openapi.yaml |
| 63 | + - inputs/mapping.yaml |
| 64 | + |
| 65 | +or |
| 66 | + |
| 67 | + items: |
| 68 | + - generated/api/EndpointApi.java |
| 69 | + - generated/model/Foo.java |
| 70 | + |
| 71 | + |
| 72 | +Extending `com.github.hauner.openapi.test.ProcessorTestBase` looks like this (using groovy): |
| 73 | + |
| 74 | +[source,groovy] |
| 75 | +---- |
| 76 | +import com.github.hauner.openapi.test.ProcessorTestBase |
| 77 | +import com.github.hauner.openapi.test.TestSet |
| 78 | +
|
| 79 | +@RunWith(Parameterized) |
| 80 | +class ProcessorEndToEndTest extends ProcessorTestBase { |
| 81 | +
|
| 82 | + static def ALL = [ |
| 83 | + 'test-case', // this is the folder name in resources/tests |
| 84 | + // ... more tests |
| 85 | + ] |
| 86 | +
|
| 87 | +
|
| 88 | + @Parameterized.Parameters(name = "{0}") |
| 89 | + static Collection<TestSet> sources () { |
| 90 | + def swagger = ALL.collect { |
| 91 | + new TestSet (name: it, processor: new Processor(), parser: ParserType.SWAGGER.name ()) |
| 92 | + } |
| 93 | +
|
| 94 | + def openapi4j = ALL.collect { |
| 95 | + new TestSet (name: it, processor: new Processor(), parser: ParserType.OPENAPI4J.name ()) |
| 96 | + } |
| 97 | +
|
| 98 | + swagger + openapi4j |
| 99 | + } |
| 100 | +
|
| 101 | + ProcessorEndToEndTest (TestSet testSet) { |
| 102 | + super (testSet) |
| 103 | + } |
| 104 | +
|
| 105 | + @Test |
| 106 | + void "native - processor creates expected files for api set "() { |
| 107 | + runOnNativeFileSystem () |
| 108 | + } |
| 109 | +
|
| 110 | +} |
| 111 | +---- |
| 112 | + |
| 113 | +See link:{oap-core}[openapi-processor-core] and link:{oap-spring}[openapi-processor-spring] for |
| 114 | +working examples. |
| 115 | + |
| 116 | +== openapi-processor Documentation |
| 117 | + |
| 118 | +See link:{oap-docs}[here]. |
0 commit comments