Skip to content

Commit

Permalink
[JBPM-9410] Add test and fix missing methods (#2300)
Browse files Browse the repository at this point in the history
Conflicts:
	kie-server-parent/kie-server-remote/kie-server-rest/kie-server-rest-common/src/build/revapi-config.json
	kie-server-parent/kie-server-remote/kie-server-rest/kie-server-rest-jbpm-ui/src/build/revapi-config.json
  • Loading branch information
gmunozfe authored and fjtirado committed Nov 11, 2020
1 parent ce2c121 commit a5f9c76
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 47 deletions.
Expand Up @@ -30,8 +30,37 @@

"ignores": {
"revapi": {
"_comment": "Changes between 7.39.0.Final and the current branch. These changes are desired and thus ignored.",
"ignore": []
"_comment": "Changes between 7.44.0.Final and the current branch. These changes are desired and thus ignored.",
"ignore": [
{
"code": "java.annotation.attributeRemoved",
"annotationType": "io.swagger.annotations.ApiOperation",
"attribute": "response",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
},
{
"code": "java.annotation.attributeRemoved",
"annotationType": "io.swagger.annotations.ApiOperation",
"attribute": "code",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
},
{
"code": "java.annotation.attributeValueChanged",
"annotationType": "io.swagger.annotations.ApiResponses",
"attribute": "value",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
},
{
"code": "java.annotation.attributeAdded",
"annotationType": "io.swagger.annotations.ApiOperation",
"attribute": "response",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
}
]
}
}
}
Expand Up @@ -57,10 +57,9 @@ public KieServerResource(KieContainerCommandService delegate) {
this.delegate = delegate;
}

@ApiOperation(value="Executes one or more KIE Server commands for server-related or container-related operations",
response=ServiceResponsesList.class, code=200)
@ApiOperation(value="Executes one or more KIE Server commands for server-related or container-related operations")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponsesList.class, message = "Successful response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=EXECUTE_CMD_RESPONSE_JSON)})) })
@POST
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
Expand Down
Expand Up @@ -96,21 +96,19 @@ public void setServer(KieServerImpl server) {
}


@ApiOperation(value="Returns information about the KIE Server. The endpoint for this request is the base URL for the REST API.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Returns information about the KIE Server. The endpoint for this request is the base URL for the REST API.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successful response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=GET_SERVER_INF_RESPONSE_JSON)})) })
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getInfo(@Context HttpHeaders headers) {
return createCorrectVariant(server.getInfo(), headers);
}

@ApiOperation(value="Returns a list of KIE containers on the KIE Server.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Returns a list of KIE containers on the KIE Server.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successfull response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=GET_CONTAINERS_RESPONSE_JSON)})) })
@GET
@Path("containers")
Expand Down Expand Up @@ -215,10 +213,9 @@ public Response deactivateContainer( @Context HttpHeaders headers,
return createCorrectVariant( response, headers, Status.BAD_REQUEST );
}

@ApiOperation(value="Returns information about a specified KIE container.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Returns information about a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successful response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=GET_CONTAINER_RESPONSE_JSON)})) })
@GET
@Path("containers/{" + CONTAINER_ID + "}")
Expand Down Expand Up @@ -248,10 +245,9 @@ public Response disposeContainer( @Context HttpHeaders headers,
return createCorrectVariant(server.disposeContainer(id), headers, conversationIdHeader);
}

@ApiOperation(value="Returns information about the KIE scanner used for automatic updates in a specified KIE container, if applicable.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Returns information about the KIE scanner used for automatic updates in a specified KIE container, if applicable.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successful response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=GET_SCANNER_RESPONSE_JSON)})) })
@GET
@Path("containers/{" + CONTAINER_ID + "}/scanner")
Expand All @@ -262,10 +258,9 @@ public Response getScannerInfo( @Context HttpHeaders headers,
return createCorrectVariant(server.getScannerInfo(id), headers, conversationIdHeader);
}

@ApiOperation(value="Starts or stops a KIE scanner that controls polling for updated KIE container deployments, if applicable.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Starts or stops a KIE scanner that controls polling for updated KIE container deployments, if applicable.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successful response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=UPDATE_SCANNER_RESPONSE_JSON)})) })
@POST
@Path("containers/{" + CONTAINER_ID + "}/scanner")
Expand All @@ -289,10 +284,9 @@ public Response updateScanner( @Context HttpHeaders headers,
return createCorrectVariant(server.updateScanner(id, resource), headers, conversationIdHeader);
};

@ApiOperation(value="Returns release ID information (group ID, artifact ID, version) for a specified KIE container.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Returns release ID information (group ID, artifact ID, version) for a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successful response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=GET_RELEASE_ID_RESPONSE_JSON)})) })
@GET
@Path("containers/{" + CONTAINER_ID + "}/release-id")
Expand All @@ -303,10 +297,9 @@ public Response getReleaseId( @Context HttpHeaders headers,
return createCorrectVariant(server.getContainerReleaseId(id), headers, conversationIdHeader);
}

@ApiOperation(value="Updates release ID information (group ID, artifact ID, version) for a specified KIE container.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Updates release ID information (group ID, artifact ID, version) for a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successfull response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=UPDATE_RELEASE_RESPONSE_JSON)})) })
@POST
@Path("containers/{" + CONTAINER_ID + "}/release-id")
Expand All @@ -332,10 +325,9 @@ public Response updateReleaseId( @Context HttpHeaders headers,
return createCorrectVariant(server.updateContainerReleaseId(id, releaseId, resetBeforeUpdate), headers, conversationIdHeader);
}

@ApiOperation(value="Returns information about the current state and configurations of the KIE Server.",
response=ServiceResponse.class, code=200)
@ApiOperation(value="Returns information about the current state and configurations of the KIE Server.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=ServiceResponse.class, message = "Successful response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=GET_SERVER_STATE_RESPONSE_JSON)})) })
@GET
@Path("state")
Expand Down
Expand Up @@ -25,8 +25,37 @@

"ignores": {
"revapi": {
"_comment": "Changes between 7.39.0.Final and the current branch. These changes are desired and thus ignored.",
"ignore": []
"_comment": "Changes between 7.44.0.Final and the current branch. These changes are desired and thus ignored.",
"ignore": [
{
"code": "java.annotation.attributeRemoved",
"annotationType": "io.swagger.annotations.ApiOperation",
"attribute": "response",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
},
{
"code": "java.annotation.attributeRemoved",
"annotationType": "io.swagger.annotations.ApiOperation",
"attribute": "code",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
},
{
"code": "java.annotation.attributeValueChanged",
"annotationType": "io.swagger.annotations.ApiResponses",
"attribute": "value",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
},
{
"code": "java.annotation.attributeAdded",
"annotationType": "io.swagger.annotations.ApiOperation",
"attribute": "response",
"elementKind": "method",
"justification": "[JBPM-9410] No Model definition in KIE Server Swagger API"
}
]
}
}
}
Expand Up @@ -99,11 +99,10 @@ public FormResource(FormServiceBase formServiceBase, FormRendererBase formRender
this.context = context;
}

@ApiOperation(value="Returns the form information for a specified process definition.",
response=String.class, code=200)
@ApiOperation(value="Returns the form information for a specified process definition.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 404, message = "Process definition, form or Container Id not found"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=String.class, message = "Successfull response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=PROCESS_FORM_DEF_JSON)})) })
@GET
@Path(PROCESS_FORM_GET_URI)
Expand Down Expand Up @@ -140,11 +139,10 @@ public Response getProcessForm(@javax.ws.rs.core.Context HttpHeaders headers,
}
}

@ApiOperation(value="Returns the form information for a specified task instance.",
response=String.class, code=200)
@ApiOperation(value="Returns the form information for a specified task instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"),
@ApiResponse(code = 404, message = "Task, form or Container Id not found"),
@ApiResponse(code = 200, message = "Successfull response", examples=@Example(value= {
@ApiResponse(code = 200, response=String.class, message = "Successfull response", examples=@Example(value= {
@ExampleProperty(mediaType=JSON, value=TASK_FORM_DEF_JSON)})) })
@GET
@Path(TASK_FORM_GET_URI)
Expand Down
Expand Up @@ -107,6 +107,14 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-parser</artifactId>
<scope>test</scope>
</dependency>


</dependencies>

<build>
Expand Down
Expand Up @@ -16,7 +16,16 @@

package org.kie.server.integrationtests.swagger;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
Expand All @@ -30,17 +39,21 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;

import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.OK;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class SwaggerIntegrationTest {

protected static final List<String> validStatusGet = Arrays.asList(Integer.toString(OK.getStatusCode()));

protected static final List<String> validStatusPost = Arrays.asList(Integer.toString(OK.getStatusCode()),
Integer.toString(CREATED.getStatusCode()));

private static Logger logger = LoggerFactory.getLogger(SwaggerIntegrationTest.class);
private static Client httpClient;
private String responseStr;

@BeforeClass
public static void buildAndDeployArtifacts() {
Expand All @@ -65,25 +78,42 @@ public void testSwaggerDocs() throws Exception {
}

assertResponse(response);
responseStr = response.readEntity(String.class);
String responseStr = response.readEntity(String.class);
response.close();
assertThat(Jsoup.parse(responseStr).title()).isIn("Execution Server Documentation", "Swagger UI");
}

@Test
@SuppressWarnings("unchecked")
public void testSwaggerJson() throws Exception {
Response response = invokeGet(TestConfig.getKieServerHttpUrl()+"/swagger.json");
assertResponse(response);
responseStr = response.readEntity(String.class);
response.close();

String swaggerStr = getSwaggerJson();

ObjectMapper om = new ObjectMapper();
HashMap<String, Object> hm = (HashMap<String, Object>) om.readValue(responseStr, HashMap.class);
HashMap<String, Object> hm = (HashMap<String, Object>) om.readValue(swaggerStr, HashMap.class);
assertNotNull(hm.get("swagger"));
assertNotNull(hm.get("info"));
assertEquals("KIE Server", ((HashMap<String, Object>) hm.get("info")).get("title"));
}

@Test
public void testSwaggerJsonContainsSchemaInResponse() {
String swaggerStr = getSwaggerJson();

Swagger swagger = new SwaggerParser().parse(swaggerStr);

swagger.getPaths().forEach((key, item) -> {
assertNonNullSchema(item.getGet(), validStatusGet, key);
assertNonNullSchema(item.getPost(), validStatusPost, key);
});
}

protected String getSwaggerJson() {
Response response = invokeGet(TestConfig.getKieServerHttpUrl()+"/swagger.json");
assertResponse(response);
String responseStr = response.readEntity(String.class);
response.close();
return responseStr;
}

protected String getContextRoot(int foldersUp) {
//Navigate to parent path N folders up to get context root
Expand All @@ -106,4 +136,13 @@ private void assertResponse(Response response) {
assertEquals(200, response.getStatus());
assertNotNull(response.getEntity());
}

private void assertNonNullSchema(Operation operation, List<String> validStatus, String path) {
if (operation != null && operation.getResponses() != null) {
operation.getResponses().entrySet().stream()
.filter(e -> validStatus.contains(e.getKey()))
.map(m -> m.getValue().getResponseSchema())
.forEach(r-> assertNotNull("Path ["+path+"] should have a schema in the response, check swagger annotations", r));
}
}
}

0 comments on commit a5f9c76

Please sign in to comment.