Skip to content

Commit

Permalink
Added test for store
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan committed Jan 10, 2024
1 parent b1b7a2b commit d0eaffc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class StandardTimeSeriesTextDao extends JooqDao {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();

public static final String OFFICE_ID = "OFFICE_ID";

private static final String ATTRIBUTE = "ATTRIBUTE";
private static final String STD_TEXT_ID = "STD_TEXT_ID";
private static final String DATA_ENTRY_DATE = "DATA_ENTRY_DATE";
Expand All @@ -48,7 +47,6 @@ public class StandardTimeSeriesTextDao extends JooqDao {
private static final List<String> stdTextCatalogColumnsList;



static {
String[] array = new String[]{OFFICE_ID, STD_TEXT_ID, STD_TEXT};
Arrays.sort(array);
Expand Down Expand Up @@ -87,20 +85,18 @@ private static StandardTextCatalog buildCatalog(ResultSet rs) throws SQLExceptio
}

private static StandardTextValue buildStandardTextValue(String officeId, String txtId, String txt) {
StandardTextId id =
new StandardTextId.Builder()
StandardTextId id = new StandardTextId.Builder()
.withOfficeId(officeId)
.withId(txtId)
.build();
return new StandardTextValue.Builder()
return new StandardTextValue.Builder()
.withId(id)
.withStandardText(txt)
.build();
}


public StandardTextValue retrieve(StandardTextId standardTextId) {

return connectionResult(dsl, c -> retrieve(c, standardTextId));
}

Expand All @@ -119,11 +115,10 @@ private StandardTextValue retrieve(Connection c, StandardTextId standardTextId)

/**
* This is if you want to store a new standard text id -> value mapping.
* @param standardTextValue
* @param failIfExists
* @param standardTextValue The standard text value to store
* @param failIfExists true if the store should fail if the standard text id already exists
*/
public void store(StandardTextValue standardTextValue, boolean failIfExists) {

StandardTextId standardTextId = standardTextValue.getId();
String stdTextId = standardTextId.getId();
String stdText = standardTextValue.getStandardText();
Expand Down Expand Up @@ -217,8 +212,6 @@ public void delete(String officeId, String tsId,
}




public TextTimeSeries retrieveTextTimeSeries(
String officeId, String tsId, StandardTextId standardTextId,
Instant startTime, Instant endTime, Instant versionDate,
Expand All @@ -232,7 +225,6 @@ public TextTimeSeries retrieveTextTimeSeries(
stdTextIdMask = "*";
}
return retrieveTextTimeSeries(officeId, tsId, stdTextIdMask, startTime, endTime, versionDate, maxVersion, retrieveText, minAttribute, maxAttribute);

}

public TextTimeSeries retrieveTextTimeSeries(String officeId, String tsId, String stdTextIdMask, Instant startTime, Instant endTime, Instant versionDate, boolean maxVersion, boolean retrieveText, Long minAttribute, Long maxAttribute) {
Expand Down Expand Up @@ -280,7 +272,7 @@ private static StandardTextTimeSeriesRow buildRow(ResultSet rs, String officeId)

Calendar gmtCalendar = OracleTypeMap.getInstance().getGmtCalendar();
Timestamp tsDateTime = rs.getTimestamp(DATE_TIME, gmtCalendar);
Timestamp tsVersionDate = rs.getTimestamp(VERSION_DATE);
Timestamp tsVersionDate = rs.getTimestamp(VERSION_DATE, gmtCalendar);
Timestamp tsDataEntryDate = rs.getTimestamp(DATA_ENTRY_DATE, gmtCalendar);
String stdTextId = rs.getString(STD_TEXT_ID);
String clobString = rs.getString(STD_TEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,69 @@ private void testDelete(StandardTimeSeriesTextDao dao) {

}

@Test
void testStore() throws SQLException {
CwmsDatabaseContainer<?> databaseLink = CwmsDataApiSetupCallback.getDatabaseLink();
databaseLink.connection(c -> {//
DSLContext dsl = getDslContext(c, "SPK");
StandardTimeSeriesTextDao dao = new StandardTimeSeriesTextDao(dsl);
testStore(dao);
}
);
}

private void testStore(StandardTimeSeriesTextDao dao) {
String officeId = "SPK";
String tsId = "First519402.Flow.Inst.1Hour.0.1688755420497";

// Structure of the test is:
// 1) retrieve some data and verify its there
// 2) update it
// 3) retrieve it again and verify its updated

ZonedDateTime startZDT = ZonedDateTime.parse("2005-01-01T08:00:00-07:00[PST8PDT]");
ZonedDateTime endZDT = ZonedDateTime.parse("2005-02-03T08:00:00-07:00[PST8PDT]");
Instant startInstant = startZDT.toInstant();
Instant endInstant = endZDT.toInstant();
Instant versionInstant = null;

boolean maxVersion = false;
boolean retText = true;
Long minAttr = null;
Long maxAttr = null;

StandardTextId standardTextId = null;
TextTimeSeries tts = dao.retrieveTextTimeSeries(officeId, tsId, standardTextId,
startInstant, endInstant, versionInstant,
maxVersion, retText, minAttr, maxAttr);
assertNotNull(tts);

Collection<StandardTextTimeSeriesRow> stdRows = tts.getStandardTextValues();
assertNotNull(stdRows);
Assertions.assertFalse(stdRows.isEmpty());

StandardTextTimeSeriesRow first = stdRows.iterator().next();
assertNotNull(first);
assertEquals("E", first.getStandardTextId());

// Step 2: update it
String updatedId = "A";
StandardTextTimeSeriesRow row = new StandardTextTimeSeriesRow.Builder()
.from(first)
.withStandardTextId(updatedId)
.build();
dao.store(officeId, tsId, row, true, true);

// Step 3: retrieve it again and verify its updated
Assertions.assertNotNull(tts);
stdRows = tts.getStandardTextValues();
Assertions.assertNotNull(stdRows);
Assertions.assertFalse(stdRows.isEmpty());
first = stdRows.iterator().next();
Assertions.assertNotNull(first);

Assertions.assertEquals(updatedId, first.getTextValue());
}


}

0 comments on commit d0eaffc

Please sign in to comment.