Search in sources :

Example 1 with RatingController

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);
}
Also used : BlobController(cwms.radar.api.BlobController) LevelsController(cwms.radar.api.LevelsController) CatalogController(cwms.radar.api.CatalogController) PoolController(cwms.radar.api.PoolController) LocationController(cwms.radar.api.LocationController) TimeZoneController(cwms.radar.api.TimeZoneController) LocationGroupController(cwms.radar.api.LocationGroupController) TimeSeriesCategoryController(cwms.radar.api.TimeSeriesCategoryController) ClobController(cwms.radar.api.ClobController) RouteRole(io.javalin.core.security.RouteRole) RouteRole(io.javalin.core.security.RouteRole) Role(cwms.radar.security.Role) UnitsController(cwms.radar.api.UnitsController) OfficeController(cwms.radar.api.OfficeController) LocationCategoryController(cwms.radar.api.LocationCategoryController) UnitsController(cwms.radar.api.UnitsController) TimeSeriesGroupController(cwms.radar.api.TimeSeriesGroupController) RatingController(cwms.radar.api.RatingController) ParametersController(cwms.radar.api.ParametersController) BasinController(cwms.radar.api.BasinController) TimeSeriesController(cwms.radar.api.TimeSeriesController)

Example 2 with RatingController

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Context(io.javalin.http.Context) HashMap(java.util.HashMap) JavalinJackson(io.javalin.plugin.json.JavalinJackson) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpServletResponse(javax.servlet.http.HttpServletResponse) RatingController(cwms.radar.api.RatingController) TestServletInputStream(fixtures.TestServletInputStream) JsonRatingUtilsTest(cwms.radar.data.dao.JsonRatingUtilsTest) Test(org.junit.jupiter.api.Test) DaoTest(cwms.radar.data.dao.DaoTest)

Aggregations

RatingController (cwms.radar.api.RatingController)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 BasinController (cwms.radar.api.BasinController)1 BlobController (cwms.radar.api.BlobController)1 CatalogController (cwms.radar.api.CatalogController)1 ClobController (cwms.radar.api.ClobController)1 LevelsController (cwms.radar.api.LevelsController)1 LocationCategoryController (cwms.radar.api.LocationCategoryController)1 LocationController (cwms.radar.api.LocationController)1 LocationGroupController (cwms.radar.api.LocationGroupController)1 OfficeController (cwms.radar.api.OfficeController)1 ParametersController (cwms.radar.api.ParametersController)1 PoolController (cwms.radar.api.PoolController)1 TimeSeriesCategoryController (cwms.radar.api.TimeSeriesCategoryController)1 TimeSeriesController (cwms.radar.api.TimeSeriesController)1 TimeSeriesGroupController (cwms.radar.api.TimeSeriesGroupController)1 TimeZoneController (cwms.radar.api.TimeZoneController)1 UnitsController (cwms.radar.api.UnitsController)1 DaoTest (cwms.radar.data.dao.DaoTest)1 JsonRatingUtilsTest (cwms.radar.data.dao.JsonRatingUtilsTest)1