use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.
the class SwaggerGeneratorTest method verify403Response.
private void verify403Response(Map<Integer, Response> responses) {
Response response = responses.get(403);
assertNotNull(response);
assertEquals(msg(RESPONSE_FORBIDDEN_KEY), response.getDescription());
}
use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.
the class SwaggerGeneratorTest method verifyExampleEntUpdatePath.
private void verifyExampleEntUpdatePath(PathEntry pathEntry) {
assertNotNull(pathEntry);
verifyExampleEntCommonPath(pathEntry, UPDATE_DESC_KEY, UPDATE_ID_KEY);
List<Parameter> parameters = pathEntry.getParameters();
assertNotNull(parameters);
assertEquals(1, parameters.size());
Parameter bodyParam = parameters.get(0);
assertEquals("ExampleEnt", bodyParam.getName());
assertEquals(msg(UPDATE_BODY_DESC_KEY, "ExampleEnt"), bodyParam.getDescription());
assertEquals(ParameterType.BODY, bodyParam.getIn());
assertNull(bodyParam.getItems());
assertTrue(bodyParam.isRequired());
assertNull(bodyParam.getType());
assertNull(bodyParam.getFormat());
Map<String, String> paramSchema = bodyParam.getSchema();
assertNotNull(paramSchema);
assertEquals(1, paramSchema.size());
assertEquals("#/definitions/org.motechproject.ExampleEnt-new-withId", paramSchema.get("$ref"));
Map<Integer, Response> responses = pathEntry.getResponses();
assertNotNull(responses);
assertEquals(4, responses.size());
verify404Response(responses, "ExampleEnt");
verify400Response(responses);
verify403Response(responses);
Response response = responses.get(200);
assertTrue(response instanceof ResponseWithSchema);
ResponseWithSchema singleItemResponse = (ResponseWithSchema) response;
assertEquals(msg(RESPONSE_UPDATED_DESC_KEY, "ExampleEnt"), singleItemResponse.getDescription());
Map<String, String> newResponseSchema = singleItemResponse.getSchema();
assertNotNull(newResponseSchema);
assertEquals(1, newResponseSchema.size());
assertEquals("#/definitions/org.motechproject.ExampleEnt", newResponseSchema.get("$ref"));
}
use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.
the class SwaggerGeneratorTest method verifyTestEntityLookup.
private void verifyTestEntityLookup(PathEntry pathEntry) {
assertNotNull(pathEntry);
assertEquals("Lookup - Find By Str & Long", pathEntry.getDescription());
assertEquals(asList("org.example.TestEntity"), pathEntry.getTags());
assertEquals("findByStrLong", pathEntry.getOperationId());
assertEquals(json(), pathEntry.getProduces());
List<Parameter> parameters = pathEntry.getParameters();
Parameter strParam = parameters.get(0);
assertNotNull(strParam);
assertEquals("str", strParam.getName());
assertEquals(ParameterType.QUERY, strParam.getIn());
assertEquals("A string field used in tests", strParam.getDescription());
assertEquals(STRING_TYPE, strParam.getType());
assertNull(strParam.getFormat());
assertNull(strParam.getItems());
assertNull(strParam.getSchema());
Parameter longParam = parameters.get(1);
assertNotNull(longParam);
assertEquals("longField", longParam.getName());
assertEquals(ParameterType.QUERY, strParam.getIn());
assertEquals("longField", longParam.getDescription());
assertEquals(INTEGER_TYPE, longParam.getType());
assertEquals(INT64_FORMAT, longParam.getFormat());
assertNull(longParam.getItems());
assertNull(longParam.getSchema());
assertNotNull(parameters);
assertEquals(6, parameters.size());
verifyQueryParameters(pathEntry.getParameters(), asList("str", "integerField", "longField", "timeField", "owner", "creator", "modifiedBy", "modificationDate", "creationDate"), 2);
Map<Integer, Response> responses = pathEntry.getResponses();
assertNotNull(responses);
assertEquals(4, responses.size());
verify400Response(responses);
verify403Response(responses);
Response response = responses.get(404);
assertNotNull(response);
assertEquals(msg(RESPONSE_LOOKUP_NOT_FOUND_KEY, "TestEntity"), response.getDescription());
response = responses.get(200);
assertTrue(response instanceof ResponseWithSchema);
ResponseWithSchema singleItemResponse = (ResponseWithSchema) response;
assertEquals(msg(RESPONSE_SINGLE_DESC_KEY, "TestEntity"), singleItemResponse.getDescription());
Map<String, String> newResponseSchema = singleItemResponse.getSchema();
assertNotNull(newResponseSchema);
assertEquals(1, newResponseSchema.size());
assertEquals("#/definitions/org.example.TestEntity-WithMetadata", newResponseSchema.get("$ref"));
}
use of org.motechproject.mds.docs.swagger.model.Response in project motech by motech.
the class SwaggerGeneratorTest method verifyTestEntityPostPath.
private void verifyTestEntityPostPath(PathEntry pathEntry) {
assertNotNull(pathEntry);
verifyTestEntityPathEntryCommon(pathEntry, CREATE_DESC_KEY, CREATE_ID_KEY);
List<Parameter> parameters = pathEntry.getParameters();
assertNotNull(parameters);
assertEquals(1, parameters.size());
Parameter newParam = parameters.get(0);
assertNotNull(newParam);
assertEquals("TestEntity", newParam.getName());
assertEquals(ParameterType.BODY, newParam.getIn());
assertNull(newParam.getFormat());
assertTrue(newParam.isRequired());
assertEquals(msg(CREATE_BODY_DESC_KEY, "TestEntity"), newParam.getDescription());
Map<String, String> newParamSchema = newParam.getSchema();
assertNotNull(newParamSchema);
assertEquals(1, newParamSchema.size());
assertEquals("#/definitions/org.example.TestEntity-new", newParamSchema.get("$ref"));
Map<Integer, Response> responses = pathEntry.getResponses();
assertNotNull(responses);
assertEquals(3, responses.size());
verify400Response(responses);
verify403Response(responses);
Response response = responses.get(200);
assertTrue(response instanceof ResponseWithSchema);
ResponseWithSchema singleItemResponse = (ResponseWithSchema) response;
assertEquals(msg(RESPONSE_NEW_DESC_KEY, "TestEntity"), singleItemResponse.getDescription());
Map<String, String> newResponseSchema = singleItemResponse.getSchema();
assertNotNull(newResponseSchema);
assertEquals(1, newResponseSchema.size());
assertEquals("#/definitions/org.example.TestEntity", newResponseSchema.get("$ref"));
}
Aggregations