package org.jboss.resteasy.test.finegrain; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.net.URI; import javax.ws.rs.core.UriInfo; import org.jboss.resteasy.mock.MockHttpRequest; import org.junit.Before; import org.junit.Test; public class MockHttpRequestTest { private MockHttpRequest request1, request2; private UriInfo uri1, uri2; @Before public void setup() { request1 = MockHttpRequest.create("GET", URI.create("http://localhost:8080/res/a"), URI.create("http://localhost:8080")); request2 = MockHttpRequest.create("GET", URI.create("http://localhost:8080/test/rs/res/a?q=test"), URI.create("http://localhost:8080/test/rs")); uri1 = request1.getUri(); uri2 = request2.getUri(); } @Test public void testPreprocessedPath() { assertEquals("/res/a", request1.getPreprocessedPath()); assertEquals("/res/a", request2.getPreprocessedPath()); } @Test public void testRequestUri() { assertEquals("http://localhost:8080/res/a", uri1.getRequestUri().toString()); assertEquals("http://localhost:8080/test/rs/res/a?q=test", uri2.getRequestUri().toString()); } @Test public void testAbsolutePath() { assertEquals("http://localhost:8080/res/a", uri1.getAbsolutePath().toString()); assertEquals("http://localhost:8080/test/rs/res/a", uri2.getAbsolutePath().toString()); } @Test public void testBaseUri() { assertEquals("http://localhost:8080", uri1.getBaseUri().toString()); assertEquals("http://localhost:8080/test/rs", uri2.getBaseUri().toString()); } @Test public void testPath() { assertEquals("/res/a", uri1.getPath()); assertEquals("/res/a", uri2.getPath()); } @Test public void testPathSegments() { assertEquals("res", uri1.getPathSegments().get(0).toString()); assertEquals("a", uri1.getPathSegments().get(1).toString()); assertEquals("res", uri2.getPathSegments().get(0).toString()); assertEquals("a", uri2.getPathSegments().get(1).toString()); } @Test public void testQuery() { assertTrue(uri1.getQueryParameters().isEmpty()); assertEquals("test", uri2.getQueryParameters().get("q").get(0)); } }