use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementCategoryControllerDocumentation method testGetAll.
@Test
@Override
public void testGetAll() throws Exception {
manager.save(createDataElementCategory('A'));
manager.save(createDataElementCategory('B'));
manager.save(createDataElementCategory('C'));
manager.save(createDataElementCategory('D'));
MockHttpSession session = getSession("ALL");
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll(ResponseDocumentation.pager());
fieldDescriptors.add(fieldWithPath(CategorySchemaDescriptor.PLURAL).description("Data element categories"));
mvc.perform(get("/" + CategorySchemaDescriptor.PLURAL).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$." + CategorySchemaDescriptor.PLURAL).isArray()).andExpect(jsonPath("$." + CategorySchemaDescriptor.PLURAL + ".length()").value(5)).andDo(documentPrettyPrint(CategorySchemaDescriptor.PLURAL + "/all", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementCategoryControllerDocumentation method testCreate.
@Test
@Override
public void testCreate() throws Exception {
MockHttpSession session = getSession("F_CATEGORY_PUBLIC_ADD");
DataElementCategoryOption categoryOptionA = createCategoryOption('A');
DataElementCategoryOption categoryOptionB = createCategoryOption('B');
DataElementCategoryOption categoryOptionC = createCategoryOption('C');
DataElementCategory cat = createDataElementCategory('A', categoryOptionA, categoryOptionB, categoryOptionC);
Schema schema = schemaService.getSchema(DataElementCategory.class);
Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
mvc.perform(post("/" + ENDPOINT).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(TestUtils.convertObjectToJsonBytes(cat))).andExpect(status().is(createdStatus)).andDo(documentPrettyPrint("categories/create", requestFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
cat = manager.getByName(DataElementCategory.class, "DataElementCategoryA");
assertNotNull(cat);
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testFilterLike.
@Test
public void testFilterLike() throws Exception {
MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
DataElement de = createDataElement('A');
manager.save(de);
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll(ResponseDocumentation.pager());
fieldDescriptors.add(fieldWithPath("dataElements").description("Data elements"));
mvc.perform(get("/dataElements?filter=name:like:DataElementA").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.pager.total", new GreaterThan<Integer>(0))).andDo(documentPrettyPrint("data-elements/filter", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testFieldsFilterOk.
@Test
public void testFieldsFilterOk() throws Exception {
MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
DataElement de = createDataElement('A');
manager.save(de);
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll(ResponseDocumentation.pager());
fieldDescriptors.add(fieldWithPath("dataElements").description("Data elements"));
mvc.perform(get("/dataElements?filter=name:eq:DataElementA&fields=id,name,valueType").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.dataElements[*].id").exists()).andExpect(jsonPath("$.dataElements[*].name").exists()).andExpect(jsonPath("$.dataElements[*].valueType").exists()).andExpect(jsonPath("$.dataElements[*].categoryCombo").doesNotExist()).andDo(documentPrettyPrint("data-elements/fields", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class AbstractWebApiTest method testDeleteById404.
@Test
public void testDeleteById404() throws Exception {
MockHttpSession session = getSession("ALL");
mvc.perform(delete(schema.getRelativeApiEndpoint() + "/{id}", "deabcdefghA").session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
}
Aggregations