use of org.springframework.restdocs.payload.FieldDescriptor in project dhis2-core by dhis2.
the class AbstractWebApiTest method testGetAll.
@Test
public void testGetAll() throws Exception {
Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaultObjectMap = manager.getDefaults();
IdentifiableObject defaultTestObject = defaultObjectMap.get(testClass);
int valueToTest = defaultTestObject != null ? 5 : 4;
manager.save(createTestObject(testClass, 'A'));
manager.save(createTestObject(testClass, 'B'));
manager.save(createTestObject(testClass, 'C'));
manager.save(createTestObject(testClass, 'D'));
MockHttpSession session = getSession("ALL");
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll(ResponseDocumentation.pager());
fieldDescriptors.add(fieldWithPath(schema.getPlural()).description(schema.getPlural()));
mvc.perform(get(schema.getRelativeApiEndpoint()).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$." + schema.getPlural()).isArray()).andExpect(jsonPath("$." + schema.getPlural() + ".length()").value(valueToTest)).andDo(documentPrettyPrint(schema.getPlural() + "/all", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
use of org.springframework.restdocs.payload.FieldDescriptor in project dhis2-core by dhis2.
the class AbstractWebApiTest method testGetByIdOk.
@Test
public void testGetByIdOk() throws Exception {
MockHttpSession session = getSession("ALL");
T object = createTestObject(testClass, 'A');
manager.save(object);
Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
mvc.perform(get(schema.getRelativeApiEndpoint() + "/{id}", object.getUid()).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.name").value(object.getName())).andDo(documentPrettyPrint(schema.getPlural() + "/id", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
Aggregations