use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class AttributeControllerDocumentation method testDeleteByIdOk.
@Override
public void testDeleteByIdOk() throws Exception {
InputStream input = new ClassPathResource("attribute/SQLViewAttribute.json").getInputStream();
MockHttpSession session = getSession("ALL");
MvcResult postResult = mvc.perform(post(schema.getRelativeApiEndpoint()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(ByteStreams.toByteArray(input))).andExpect(status().is(createdStatus)).andReturn();
String uid = TestUtils.getCreatedUid(postResult.getResponse().getContentAsString());
mvc.perform(delete(schema.getRelativeApiEndpoint() + "/{id}", uid).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().is(deleteStatus)).andDo(documentPrettyPrint(schema.getPlural() + "/delete"));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class LockExceptionControllerDocumentation method testGetLockException.
@Test
public void testGetLockException() throws Exception {
MockHttpSession session = getSession("ALL");
PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
manager.save(period);
OrganisationUnit orgUnit = createOrganisationUnit('B');
manager.save(orgUnit);
DataSet dataSet = createDataSet('A', periodType);
dataSet.addOrganisationUnit(orgUnit);
manager.save(dataSet);
LockException lockException = new LockException(period, orgUnit, dataSet);
dataSetService.addLockException(lockException);
String getUrl = "/lockExceptions?filter=organisationUnit.id:eq:" + orgUnit.getUid() + "&filter=period:eq:201612&filter=dataSet.id:eq:" + dataSet.getUid();
Lists.newArrayList(fieldWithPath("period").description("Property"), fieldWithPath("organisationUnit").description("Property"), fieldWithPath("dataSet").description("Property"));
mvc.perform(get(getUrl).session(session).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(200)).andDo(documentPrettyPrint("lockExceptions/get")).andReturn();
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class LockExceptionControllerDocumentation method testAddLockException.
@Test
public void testAddLockException() throws Exception {
MockHttpSession session = getSession("ALL");
PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
manager.save(period);
OrganisationUnit orgUnit = createOrganisationUnit('B');
manager.save(orgUnit);
DataSet dataSet = createDataSet('A', periodType);
dataSet.addOrganisationUnit(orgUnit);
manager.save(dataSet);
String postUrl = "/lockExceptions?ou=" + orgUnit.getUid() + "&pe=201612&ds=" + dataSet.getUid();
mvc.perform(post(postUrl).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().is(201)).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("lockExceptions/add"));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class LockExceptionControllerDocumentation method testDeleteLockException.
@Test
public void testDeleteLockException() throws Exception {
MockHttpSession session = getSession("ALL");
PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
manager.save(period);
OrganisationUnit orgUnit = createOrganisationUnit('B');
manager.save(orgUnit);
DataSet dataSet = createDataSet('A', periodType);
dataSet.addOrganisationUnit(orgUnit);
manager.save(dataSet);
LockException lockException = new LockException(period, orgUnit, dataSet);
dataSetService.addLockException(lockException);
String deleteUrl = "/lockExceptions?ou=" + orgUnit.getUid() + "&pe=201612&ds=" + dataSet.getUid();
mvc.perform(delete(deleteUrl).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isNoContent()).andDo(documentPrettyPrint("lockExceptions/delete"));
}
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()]))));
}
Aggregations