Search in sources :

Example 31 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class ApiVersionMethodTest method testMethodAll.

@Test
public void testMethodAll() throws Exception {
    MockHttpSession session = getSession("ALL");
    String endpoint = "/method/testAll";
    mvc.perform(get(endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/23" + endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/24" + endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/23" + endpoint + "/a").session(session)).andExpect(status().isOk());
    mvc.perform(get("/24" + endpoint + "/b").session(session)).andExpect(status().isOk());
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.Test)

Example 32 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class ApiVersionMethodTest method testMethodAllExcludeV23.

@Test
public void testMethodAllExcludeV23() throws Exception {
    MockHttpSession session = getSession("ALL");
    String endpoint = "/method/testAllExcludeV23";
    mvc.perform(get(endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/23" + endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/24" + endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/23" + endpoint + "/a").session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/23" + endpoint + "/b").session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/24" + endpoint + "/a").session(session)).andExpect(status().isOk());
    mvc.perform(get("/24" + endpoint + "/b").session(session)).andExpect(status().isOk());
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.Test)

Example 33 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class ApiVersionTypeTest method testTypeAnnotationDefault.

@Test
public void testTypeAnnotationDefault() throws Exception {
    MockHttpSession session = getSession("ALL");
    String endpoint = "/type/testDefault";
    mvc.perform(get(endpoint).session(session)).andExpect(status().isOk());
    mvc.perform(get("/23" + endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/24" + endpoint).session(session)).andExpect(status().isNotFound());
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.Test)

Example 34 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class ApiVersionTypeTest method testTypeAnnotationV23V24.

@Test
public void testTypeAnnotationV23V24() throws Exception {
    MockHttpSession session = getSession("ALL");
    String endpoint = "/type/testV23V24";
    mvc.perform(get(endpoint).session(session)).andExpect(status().isNotFound());
    mvc.perform(get("/23" + endpoint).session(session)).andExpect(status().isOk());
    mvc.perform(get("/24" + endpoint).session(session)).andExpect(status().isOk());
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.Test)

Example 35 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class ApiVersionTypeTest method testTypeAnnotationDefaultV23.

@Test
public void testTypeAnnotationDefaultV23() throws Exception {
    MockHttpSession session = getSession("ALL");
    String endpoint = "/type/testDefaultV23";
    mvc.perform(get(endpoint).session(session)).andExpect(status().isOk());
    mvc.perform(get("/23" + endpoint).session(session)).andExpect(status().isOk());
    mvc.perform(get("/24" + endpoint).session(session)).andExpect(status().isNotFound());
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.Test)

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