Search in sources :

Example 11 with MockHttpServletRequest

use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.

the class HttpHeadersTest method testMultipleHeaders.

@Test
public void testMultipleHeaders() {
    final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
    headers.add("a", "b");
    headers.add("a", "c");
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/"), headers, null, null);
    final MinijaxHttpHeaders httpHeaders = new MinijaxHttpHeaders(request);
    assertEquals(Arrays.asList("b", "c"), httpHeaders.getRequestHeader("a"));
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) Test(org.junit.Test)

Example 12 with MockHttpServletRequest

use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.

the class HttpHeadersTest method testLanguageMissing.

@Test
public void testLanguageMissing() {
    final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/"), headers, null, null);
    final MinijaxHttpHeaders httpHeaders = new MinijaxHttpHeaders(request);
    assertNull(httpHeaders.getLanguage());
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) Test(org.junit.Test)

Example 13 with MockHttpServletRequest

use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.

the class HttpHeadersTest method testLanguage.

@Test
public void testLanguage() {
    final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
    headers.add("Content-Language", "en-US");
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", URI.create("/"), headers, null, null);
    final MinijaxHttpHeaders httpHeaders = new MinijaxHttpHeaders(request);
    assertEquals("en-US", httpHeaders.getLanguage().toLanguageTag());
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) Test(org.junit.Test)

Example 14 with MockHttpServletRequest

use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.

the class RequestScopedTest method testRequestScoped.

@Test
public void testRequestScoped() throws IOException {
    final Minijax container = new Minijax();
    final MinijaxApplication application = container.getDefaultApplication();
    final MockHttpServletRequest r1 = new MockHttpServletRequest("GET", URI.create("/"));
    A a1;
    A a2;
    try (MinijaxRequestContext context = new MinijaxRequestContext(application, r1, null)) {
        a1 = container.getResource(A.class);
        assertNotNull(a1);
        a2 = container.getResource(A.class);
        assertEquals(a1, a2);
        assertTrue(a1 == a2);
    }
    final MockHttpServletRequest r2 = new MockHttpServletRequest("GET", URI.create("/"));
    A a3;
    A a4;
    try (MinijaxRequestContext context = new MinijaxRequestContext(application, r2, null)) {
        a3 = container.getResource(A.class);
        assertNotNull(a3);
        a4 = container.getResource(A.class);
        assertEquals(a3, a4);
        assertTrue(a3 == a4);
    }
    assertNotEquals(a1, a3);
    assertTrue(a1 != a3);
    container.getInjector().close();
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication) MinijaxRequestContext(org.minijax.MinijaxRequestContext) Minijax(org.minijax.Minijax) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) Test(org.junit.Test)

Example 15 with MockHttpServletRequest

use of org.minijax.test.MockHttpServletRequest in project minijax by minijax.

the class UrlUtilsTest method testForwardedProtocol.

@Test
public void testForwardedProtocol() {
    final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
    headers.add("X-Forwarded-Proto", "https");
    final MockHttpServletRequest req = new MockHttpServletRequest(null, URI.create("http://www.example.com/"), headers, null, null);
    assertEquals("https://www.example.com/", UrlUtils.getFullRequestUrl(req).toString());
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MockHttpServletRequest(org.minijax.test.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 MockHttpServletRequest (org.minijax.test.MockHttpServletRequest)23 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)16 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Minijax (org.minijax.Minijax)3 MinijaxApplication (org.minijax.MinijaxApplication)3 MinijaxRequestContext (org.minijax.MinijaxRequestContext)3 MockHttpServletResponse (org.minijax.test.MockHttpServletResponse)3 Cookie (javax.servlet.http.Cookie)2 MinijaxTest (org.minijax.test.MinijaxTest)2 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 AnnotatedEndpoint (io.undertow.websockets.jsr.annotated.AnnotatedEndpoint)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)1 Cookie (javax.ws.rs.core.Cookie)1 MediaType (javax.ws.rs.core.MediaType)1 Widget (org.minijax.db.test.Widget)1