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");
}
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");
}
Aggregations