Skip to content

Commit

Permalink
Updated endpoint and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Nov 22, 2024
1 parent ba138a9 commit ac5245d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ private WaterPumpAccountingEndpointInput() {
throw new AssertionError("factory class");
}

public static GetAll getAll(String officeId, String projectId, String waterUserId, String waterContractName) {
return new GetAll(officeId, projectId, waterUserId, waterContractName);
public static GetAll getAll(String officeId, String projectId, String waterUserId, String waterContractName,
Instant startTime, Instant endTime) {
return new GetAll(officeId, projectId, waterUserId, waterContractName, startTime, endTime);
}

public static Post post(WaterSupplyAccounting waterSupplyAccounting) {
Expand All @@ -30,18 +31,21 @@ public static final class GetAll extends EndpointInput {
static final String END_INCLUSIVE_QUERY_PARAMETER = "end-time-inclusive";
static final String ASCENDING_QUERY_PARAMETER = "ascending";
static final String ROW_LIMIT_QUERY_PARAMETER = "row-limit";
static final String TIMEZONE_QUERY_PARAMETER = "timezone";
private final String waterUserId;
private final String waterContractName;
private final String projectId;
private final String officeId;
private Instant startTime = Instant.ofEpochSecond(-5364662400L);
private Instant endTime = Instant.ofEpochSecond(32503680000L);
private Instant startTime;
private Instant endTime;
private boolean startInclusive = true;
private boolean endInclusive = true;
private boolean ascending = true;
private int rowLimit = 0;
private String timeZone;

private GetAll(String officeId, String projectId, String waterUserId, String waterContractName) {
private GetAll(String officeId, String projectId, String waterUserId, String waterContractName,
Instant startTime, Instant endTime) {
this.officeId = Objects.requireNonNull(officeId, "Cannot access the water pump accounting GET "
+ "endpoint without providing office id");
this.projectId = Objects.requireNonNull(projectId, "Cannot access the water pump accounting GET "
Expand All @@ -50,16 +54,10 @@ private GetAll(String officeId, String projectId, String waterUserId, String wat
+ "GET endpoint without providing water user id");
this.waterContractName = Objects.requireNonNull(waterContractName, "Cannot access the water pump "
+ "accounting GET endpoint without providing water contract name");
}

public GetAll setStartTime(Instant startTime) {
this.startTime = Objects.requireNonNull(startTime, "Cannot set the start time to null");
return this;
}

public GetAll setEndTime(Instant endTime) {
this.endTime = Objects.requireNonNull(endTime, "Cannot set the end time to null");
return this;
this.startTime = Objects.requireNonNull(startTime, "Cannot access the water pump accounting GET "
+ "endpoint without providing start time");
this.endTime = Objects.requireNonNull(endTime, "Cannot access the water pump accounting GET "
+ "endpoint without providing end time");
}

public GetAll setStartInclusive(boolean startInclusive) {
Expand All @@ -82,6 +80,11 @@ public GetAll setRowLimit(int rowLimit) {
return this;
}

public GetAll setTimeZone(String timeZone) {
this.timeZone = timeZone;
return this;
}

public String getOfficeId() {
return officeId;
}
Expand Down Expand Up @@ -122,6 +125,10 @@ public int getRowLimit() {
return rowLimit;
}

public String getTimeZone() {
return timeZone;
}

@Override
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
return httpRequestBuilder.addQueryParameter(START_TIME_QUERY_PARAMETER, startTime.toString())
Expand All @@ -130,6 +137,7 @@ protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBu
.addQueryParameter(END_INCLUSIVE_QUERY_PARAMETER, endInclusive ? "true" : "false")
.addQueryParameter(ASCENDING_QUERY_PARAMETER, ascending ? "true" : "false")
.addQueryParameter(ROW_LIMIT_QUERY_PARAMETER, String.valueOf(rowLimit))
.addQueryParameter(TIMEZONE_QUERY_PARAMETER, timeZone)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ void testRetrieveAll() throws IOException {
String collect = readJsonFile("radar/v1/json/water_supply_accounting_list.json");
mockHttpServer.enqueue(collect);
mockHttpServer.start();
Instant startTime = Instant.ofEpochMilli(10000012648000L);
Instant endTime = Instant.ofEpochSecond(10000016484000L);
WaterPumpAccountingEndpointInput.GetAll input = WaterPumpAccountingEndpointInput
.getAll("SWT", "SACRAMENTO", "Test User", "TEST_CONTRACT");
.getAll("SWT", "SACRAMENTO", "Test User", "TEST_CONTRACT", startTime, endTime);
List<WaterSupplyAccounting> values = new WaterPumpAccountingController()
.retrieveWaterPumpAccounting(buildConnectionInfo(cookieJarSupplier), input);
assertFalse(values.isEmpty());
Expand All @@ -33,6 +35,7 @@ void testRetrieveAll() throws IOException {
assertEquals(1.0, value.getPumpAccounting().get(0).getFlow());
assertEquals(2.0, value.getPumpAccounting().get(1).getFlow());
assertEquals("Test Comment 2", value.getPumpAccounting().get(1).getComment());
assertEquals(Instant.ofEpochMilli(10000012648000L), value.getPumpAccounting().get(0).getTransferDate());
assertEquals(Instant.ofEpochMilli(10000016484000L), value.getPumpAccounting().get(1).getTransferDate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ void testGetAllQueryRequest() {
String projectId = "PROJECT";
String waterUserEntityName = "Test User";
String waterContractName = "TEST_CONTRACT";
GetAll input = WaterPumpAccountingEndpointInput.getAll(office, projectId, waterUserEntityName, waterContractName);
input.setStartTime(Instant.MIN);
input.setEndTime(Instant.MAX);
GetAll input = WaterPumpAccountingEndpointInput.getAll(office, projectId, waterUserEntityName,
waterContractName, Instant.MIN, Instant.MAX)
.setAscending(false)
.setRowLimit(100)
.setTimeZone("PST")
.setStartInclusive(false)
.setEndInclusive(false);
input.setStartInclusive(false);
input.setEndInclusive(false);
input.setAscending(false);
Expand All @@ -42,14 +46,16 @@ void testGetAllQueryRequest() {
assertFalse(input.isAscending());
assertFalse(input.isEndInclusive());
assertFalse(input.isStartInclusive());
assertEquals("PST", input.getTimeZone());
assertEquals(ACCEPT_HEADER_V1, mockHttpRequestBuilder.getQueryHeader(ACCEPT_QUERY_HEADER));
}

@Test
void testPostQueryRequest() throws IOException {
MockHttpRequestBuilder mockHttpRequestBuilder = new MockHttpRequestBuilder();
String collect = readJsonFile("radar/v1/json/water_supply_accounting.json");
WaterSupplyAccounting waterSupplyAccounting = RadarObjectMapper.mapJsonToObject(collect, WaterSupplyAccounting.class);
WaterSupplyAccounting waterSupplyAccounting = RadarObjectMapper
.mapJsonToObject(collect, WaterSupplyAccounting.class);
Post input = WaterPumpAccountingEndpointInput.post(waterSupplyAccounting);
input.addInputParameters(mockHttpRequestBuilder);
assertEquals(waterSupplyAccounting, input.getWaterSupplyAccounting());
Expand Down

0 comments on commit ac5245d

Please sign in to comment.