Search in sources :

Example 91 with MockHttpSession

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"));
}
Also used : InputStream(java.io.InputStream) MockHttpSession(org.springframework.mock.web.MockHttpSession) MvcResult(org.springframework.test.web.servlet.MvcResult) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 92 with MockHttpSession

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();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) LockException(org.hisp.dhis.dataset.LockException) MockHttpSession(org.springframework.mock.web.MockHttpSession) Period(org.hisp.dhis.period.Period) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

Example 93 with MockHttpSession

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"));
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) MockHttpSession(org.springframework.mock.web.MockHttpSession) Period(org.hisp.dhis.period.Period) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

Example 94 with MockHttpSession

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"));
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) LockException(org.hisp.dhis.dataset.LockException) MockHttpSession(org.springframework.mock.web.MockHttpSession) Period(org.hisp.dhis.period.Period) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

Example 95 with MockHttpSession

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()]))));
}
Also used : ArrayList(java.util.ArrayList) MockHttpSession(org.springframework.mock.web.MockHttpSession) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Aggregations

MockHttpSession (org.springframework.mock.web.MockHttpSession)106 Test (org.junit.Test)84 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)44 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)34 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)23 HashMap (java.util.HashMap)13 AbstractWebApiTest (org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)13 MockFilterChain (org.springframework.mock.web.MockFilterChain)12 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)11 ModelAndView (org.springframework.web.servlet.ModelAndView)11 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)9 FilterChain (javax.servlet.FilterChain)8 MockServletContext (org.springframework.mock.web.MockServletContext)8 SessionRegistry (org.springframework.security.core.session.SessionRegistry)8 ConcurrentSessionFilter (org.springframework.security.web.session.ConcurrentSessionFilter)8 Principal (org.apereo.cas.authentication.principal.Principal)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 CasProfile (org.pac4j.cas.profile.CasProfile)7 InputStream (java.io.InputStream)6 Before (org.junit.Before)6