Search in sources :

Example 1 with TestHttpServletResponse

use of fixtures.TestHttpServletResponse in project cwms-radar-api by USACE.

the class CatalogControllerTest method catalog_returns_only_original_ids_by_default.

@Test
public void catalog_returns_only_original_ids_by_default() throws Exception {
    CatalogController controller = new CatalogController(new MetricRegistry());
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = new TestHttpServletResponse();
    HashMap<String, Object> attributes = new HashMap<>();
    attributes.put(ContextUtil.maxRequestSizeKey, Integer.MAX_VALUE);
    attributes.put(JsonMapperKt.JSON_MAPPER_KEY, new JavalinJackson());
    attributes.put("PolicyFactory", this.sanitizer);
    when(request.getInputStream()).thenReturn(new TestServletInputStream(""));
    when(request.getAttribute("database")).thenReturn(this.conn);
    when(request.getRequestURI()).thenReturn("/catalog/TIMESERIES");
    when(request.getHeader(Header.ACCEPT)).thenReturn("application/json;version=2");
    Context context = ContextUtil.init(request, response, "*", new HashMap<String, String>(), HandlerType.GET, attributes);
    context.attribute("database", this.conn);
    controller.getOne(context, CatalogableEndpoint.TIMESERIES.getValue());
    assertEquals(HttpCode.OK.getStatus(), response.getStatus(), "200 OK was not returned");
    assertNotNull(response.getOutputStream(), "Output stream wasn't created");
}
Also used : Context(io.javalin.http.Context) HashMap(java.util.HashMap) MetricRegistry(com.codahale.metrics.MetricRegistry) TestHttpServletResponse(fixtures.TestHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TestHttpServletResponse(fixtures.TestHttpServletResponse) TestServletInputStream(fixtures.TestServletInputStream) HttpServletRequest(javax.servlet.http.HttpServletRequest) JavalinJackson(io.javalin.plugin.json.JavalinJackson) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TestHttpServletResponse

use of fixtures.TestHttpServletResponse in project cwms-radar-api by USACE.

the class LocationControllerTest method test_basic_operations.

/**
 * Test of getOne method, of class LocationController.
 */
@Test
public void test_basic_operations() throws Exception {
    final String testBody = "";
    LocationController instance = new LocationController(new MetricRegistry());
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = new TestHttpServletResponse();
    HashMap<String, Object> attributes = new HashMap<>();
    attributes.put(ContextUtil.maxRequestSizeKey, Integer.MAX_VALUE);
    attributes.put(JsonMapperKt.JSON_MAPPER_KEY, new JavalinJackson());
    when(request.getInputStream()).thenReturn(new TestServletInputStream(testBody));
    final Context context = ContextUtil.init(request, response, "*", new HashMap<String, String>(), HandlerType.GET, attributes);
    context.attribute("database", getTestConnection());
    when(request.getAttribute("database")).thenReturn(getTestConnection());
    assertNotNull(context.attribute("database"), "could not get the connection back as an attribute");
    String Location_id = "SimpleNoAlias";
    instance.getOne(context, Location_id);
    assertEquals(200, context.status(), "incorrect status code returned");
}
Also used : Context(io.javalin.http.Context) HashMap(java.util.HashMap) MetricRegistry(com.codahale.metrics.MetricRegistry) TestHttpServletResponse(fixtures.TestHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TestHttpServletResponse(fixtures.TestHttpServletResponse) TestServletInputStream(fixtures.TestServletInputStream) HttpServletRequest(javax.servlet.http.HttpServletRequest) JavalinJackson(io.javalin.plugin.json.JavalinJackson) Test(org.junit.jupiter.api.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)2 TestHttpServletResponse (fixtures.TestHttpServletResponse)2 TestServletInputStream (fixtures.TestServletInputStream)2 Context (io.javalin.http.Context)2 JavalinJackson (io.javalin.plugin.json.JavalinJackson)2 HashMap (java.util.HashMap)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1