Skip to content

Commit

Permalink
Feature/add outlet controller tests (USACE#798)
Browse files Browse the repository at this point in the history
Adding outlet controller and virtual outlet controller integration tests
  • Loading branch information
RyanM-RMA authored Jul 24, 2024
1 parent 9b60d14 commit d209b68
Show file tree
Hide file tree
Showing 9 changed files with 777 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private Timer.Context markAndTime(String subject) {
},
description = "Create CWMS Outlet",
method = HttpMethod.POST,
tags = {OutletController.TAG},
tags = {TAG},
responses = {
@OpenApiResponse(status = STATUS_204, description = "Outlet successfully stored to CWMS.")
}
Expand Down Expand Up @@ -113,12 +113,12 @@ public void create(@NotNull Context ctx) {
})
},
description = "Returns matching CWMS Outlet Data for a Reservoir Project.",
tags = {OutletController.TAG}
tags = {TAG}
)
@Override
public void getAll(@NotNull Context ctx) {
String office = ctx.pathParam(OFFICE);
String projectId = ctx.pathParam(PROJECT_ID);
String office = requiredParam(ctx, OFFICE);
String projectId = requiredParam(ctx, PROJECT_ID);
try (Timer.Context ignored = markAndTime(GET_ALL)) {
DSLContext dsl = getDslContext(ctx);
OutletDao dao = new OutletDao(dsl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ public void handle(@NotNull Context ctx) throws Exception {
boolean failIfExists = queryParamAsClass(ctx, Boolean.class, true, FAIL_IF_EXISTS);
DSLContext dsl = getDslContext(ctx);
OutletDao dao = new OutletDao(dsl);

String officeId = virtualOutlet.getProjectId().getOfficeId();
String projectId = virtualOutlet.getProjectId().getName();
String virtualOutletId = virtualOutlet.getVirtualOutletId().getName();
dao.storeVirtualOutlet(officeId, projectId, virtualOutletId, virtualOutlet.getVirtualRecords(), failIfExists);
dao.storeVirtualOutlet(virtualOutlet, failIfExists);
ctx.status(HttpServletResponse.SC_CREATED).json("Created Outlet");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,24 @@ private VirtualOutlet retrieveVirtualOutlet(Configuration config, String virtual
.build();
}

public void storeVirtualOutlet(String officeId, String projectId, String virtualOutletId,
List<VirtualOutletRecord> records, boolean failIfExists) {
List<List<String>> virtualOutlets = records.stream()
.map(this::mapVirtualRecords)
.collect(Collectors.toList());
public void storeVirtualOutlet(VirtualOutlet outlet, boolean failIfExists) {
List<List<String>> virtualOutlets = outlet.getVirtualRecords()
.stream()
.map(this::mapVirtualRecords)
.collect(Collectors.toList());

STR_TAB_TAB_T outlets = new STR_TAB_TAB_T(
virtualOutlets.stream().map(STR_TAB_T::new).collect(Collectors.toList()));

CwmsId projectId = outlet.getProjectId();
CwmsId outletId = outlet.getVirtualOutletId();

connection(dsl, conn -> {
setOffice(conn, officeId);
CWMS_OUTLET_PACKAGE.call_STORE_COMPOUND_OUTLET(DSL.using(conn).configuration(), projectId, virtualOutletId,
outlets, OracleTypeMap.formatBool(failIfExists), officeId);
setOffice(conn, outlet.getProjectId().getOfficeId());
CWMS_OUTLET_PACKAGE.call_STORE_COMPOUND_OUTLET(DSL.using(conn).configuration(), projectId.getName(),
outletId.getName(), outlets,
OracleTypeMap.formatBool(failIfExists),
projectId.getOfficeId());
});
}

Expand Down
Loading

0 comments on commit d209b68

Please sign in to comment.