Skip to content

Commit a117514

Browse files
committed
Adding a test to validate processing rules (@ExternalDocumentation ATM)
1 parent 061d374 commit a117514

4 files changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2020 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.smallrye.openapi.tck.extra;
17+
18+
import io.smallrye.openapi.tck.extra.procrules.WidgetResourceWithAnnotations;
19+
import org.eclipse.microprofile.openapi.tck.AppTestBase;
20+
import org.jboss.arquillian.container.test.api.Deployment;
21+
import org.jboss.arquillian.container.test.api.RunAsClient;
22+
import org.jboss.shrinkwrap.api.ShrinkWrap;
23+
import org.jboss.shrinkwrap.api.spec.WebArchive;
24+
import org.testng.annotations.Test;
25+
26+
import io.restassured.response.ValidatableResponse;
27+
import test.io.smallrye.openapi.tck.ExtraSuiteTestBase;
28+
29+
/**
30+
* NOTE: It's not a TCK test, it only leverages the TCK test setup
31+
*/
32+
public class ProcessingRulesTest extends ExtraSuiteTestBase<ProcessingRulesTest.ProcessingRulesTestArquillian> {
33+
34+
public static class ProcessingRulesTestArquillian extends AppTestBase {
35+
@Deployment(name = "processing-rules")
36+
public static WebArchive createDeployment() {
37+
return ShrinkWrap.create(WebArchive.class, "ProcessingRules.war")
38+
.addPackages(true, new String[] { "io.smallrye.openapi.tck.extra.procrules" })
39+
.addAsManifestResource("set-model-reader.properties", "microprofile-config.properties")
40+
;
41+
}
42+
43+
@RunAsClient
44+
@Test(dataProvider = "formatProvider")
45+
public void testPathItems(String type) {
46+
ValidatableResponse vr = this.callEndpoint(type);
47+
vr.body("externalDocs.url", org.hamcrest.Matchers.notNullValue());
48+
vr.body("externalDocs.url", org.hamcrest.Matchers.is("http://widget-external-docs.org"));
49+
vr.body("externalDocs.description", org.hamcrest.Matchers.notNullValue());
50+
vr.body("externalDocs.description", org.hamcrest.Matchers.is("Widget resource external documentation"));
51+
}
52+
53+
}
54+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.smallrye.openapi.tck.extra.procrules;
2+
3+
import org.eclipse.microprofile.openapi.OASFactory;
4+
import org.eclipse.microprofile.openapi.OASModelReader;
5+
import org.eclipse.microprofile.openapi.models.ExternalDocumentation;
6+
import org.eclipse.microprofile.openapi.models.OpenAPI;
7+
8+
/**
9+
* Generates a base model to be used by the OpenAPI.
10+
*/
11+
public class OpenApiModelReader implements OASModelReader {
12+
/**
13+
* Creates a new {@link ExternalDocumentation} instance, modifying the output OpenAPI document.
14+
*
15+
* @return A new {@link OpenAPI} instance that will serve as base for generation
16+
*/
17+
@Override
18+
public OpenAPI buildModel() {
19+
OpenAPI api = OASFactory.createObject(OpenAPI.class);
20+
ExternalDocumentation externalDocumentation = OASFactory.createExternalDocumentation();
21+
externalDocumentation.setUrl("http://oas-model-reader-based-external-docs.org");
22+
externalDocumentation.setDescription("Could be overridden by static files and/or annotations");
23+
api.setExternalDocs(externalDocumentation);
24+
return api;
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.smallrye.openapi.tck.extra.procrules;
2+
3+
import org.eclipse.microprofile.openapi.annotations.ExternalDocumentation;
4+
5+
import io.smallrye.openapi.tck.extra.jaxrs.WidgetResource;
6+
7+
@ExternalDocumentation(url = "http://widget-external-docs.org", description = "Widget resource external documentation")
8+
public class WidgetResourceWithAnnotations extends WidgetResource {
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mp.openapi.model.reader=io.smallrye.openapi.tck.extra.procrules.OpenApiModelReader

0 commit comments

Comments
 (0)