use of cwms.radar.api.RatingController in project cwms-radar-api by USACE.
the class ApiServlet method configureRoutes.
protected void configureRoutes() {
RouteRole[] requiredRoles = { new Role(CWMS_USERS_ROLE) };
get("/", ctx -> ctx.result("Welcome to the CWMS REST API").contentType(Formats.PLAIN));
radarCrud("/location/category/{category-id}", new LocationCategoryController(metrics), requiredRoles);
radarCrud("/location/group/{group-id}", new LocationGroupController(metrics), requiredRoles);
radarCrud("/locations/{location_code}", new LocationController(metrics), requiredRoles);
radarCrud("/offices/{office}", new OfficeController(metrics), requiredRoles);
radarCrud("/units/{unit_name}", new UnitsController(metrics), requiredRoles);
radarCrud("/parameters/{param_name}", new ParametersController(metrics), requiredRoles);
radarCrud("/timezones/{zone}", new TimeZoneController(metrics), requiredRoles);
radarCrud("/levels/{location}", new LevelsController(metrics), requiredRoles);
TimeSeriesController tsController = new TimeSeriesController(metrics);
get("/timeseries/recent/{group-id}", tsController::getRecent);
radarCrud("/timeseries/category/{category-id}", new TimeSeriesCategoryController(metrics), requiredRoles);
radarCrud("/timeseries/group/{group-id}", new TimeSeriesGroupController(metrics), requiredRoles);
radarCrud("/timeseries/{timeseries}", tsController, requiredRoles);
radarCrud("/ratings/{rating}", new RatingController(metrics), requiredRoles);
radarCrud("/catalog/{dataSet}", new CatalogController(metrics), requiredRoles);
radarCrud("/basins/{basin-id}", new BasinController(metrics), requiredRoles);
radarCrud("/blobs/{blob-id}", new BlobController(metrics), requiredRoles);
radarCrud("/clobs/{clob-id}", new ClobController(metrics), requiredRoles);
radarCrud("/pools/{pool-id}", new PoolController(metrics), requiredRoles);
}
use of cwms.radar.api.RatingController in project cwms-radar-api by USACE.
the class RatingsControllerTest method post_to_create_passed_to_deserializeXml.
// This is only supposed to test that when XML data is posted to create,
// that data is forward to the method deserializeFromXml
@Test
void post_to_create_passed_to_deserializeXml() throws Exception {
final String testBody = "could be anything";
RatingController controller = spy(new RatingController(new MetricRegistry()));
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
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));
// Context context = new Context(request,response, attributes);
Context context = ContextUtil.init(request, response, "*", new HashMap<String, String>(), HandlerType.POST, attributes);
context.attribute("database", this.conn);
when(request.getContentLength()).thenReturn(testBody.length());
when(request.getAttribute("database")).thenReturn(this.conn);
assertNotNull(context.attribute("database"), "could not get the connection back as an attribute");
when(request.getHeader(Header.ACCEPT)).thenReturn(Formats.XMLV2);
when(request.getContentType()).thenReturn(Formats.XMLV2);
controller.create(context);
// For this test, it's ok that the server throws a RatingException
// Only want to check that the controller accessed our mock dao in the expected way
// Curious that it is XML and not XMLv2
verify(controller, times(1)).deserializeRatingSet(testBody, Formats.XML);
}
Aggregations