diff --git a/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/opendcs_dep/TestDecoder.java b/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/opendcs_dep/TestDecoder.java index 57a73ad16..389261ba8 100644 --- a/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/opendcs_dep/TestDecoder.java +++ b/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/opendcs_dep/TestDecoder.java @@ -43,6 +43,7 @@ import decodes.decoder.DecodedSample; import decodes.sql.DbKey; import decodes.tsdb.DbIoException; +import decodes.tsdb.TimeSeriesDb; import ilex.util.Logger; import ilex.var.TimedVariable; import opendcs.dai.DataTypeDAI; @@ -359,10 +360,9 @@ private static synchronized void initDecodes(OpenDcsDatabase db) if (decodes.db.Database.getDb() == null) decodes.db.Database.setDb(new decodes.db.Database()); - try (DataTypeDAI dtDAO = db.getDao(DataTypeDAI.class) - .orElseThrow(() -> new UnsupportedOperationException("TestDecodes is not supported")); - EnumDAI enumDAO = db.getDao(EnumDAI.class) - .orElseThrow(() -> new UnsupportedOperationException("TestDecodes is not supported"))) + try (DataTypeDAI dtDAO = db.getLegacyDatabase(TimeSeriesDb.class) + .orElseThrow(() -> new UnsupportedOperationException("TestDecodes is not supported")).makeDataTypeDAO(); + EnumDAI enumDAO = db.getLegacyDatabase(TimeSeriesDb.class).orElseThrow(() -> new UnsupportedOperationException("TestDecodes is not supported")).makeEnumDAO()) { enumDAO.readEnumList(decodes.db.Database.getDb().enumList); dtDAO.readDataTypeSet(decodes.db.Database.getDb().dataTypeSet); diff --git a/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/res/PlatformResources.java b/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/res/PlatformResources.java index d8c236f19..7b974fdde 100644 --- a/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/res/PlatformResources.java +++ b/opendcs-rest-api/src/main/java/org/opendcs/odcsapi/res/PlatformResources.java @@ -15,11 +15,17 @@ package org.opendcs.odcsapi.res; -import java.sql.SQLException; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; -import java.util.logging.Logger; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Vector; + import javax.annotation.security.RolesAllowed; +import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -32,18 +38,35 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import decodes.db.DatabaseException; +import decodes.db.DatabaseIO; +import decodes.db.Platform; +import decodes.db.PlatformConfig; +import decodes.db.PlatformList; +import decodes.db.PlatformSensor; +import decodes.db.PlatformStatus; +import decodes.db.RoutingSpec; +import decodes.db.ScheduleEntry; +import decodes.db.Site; +import decodes.db.TransportMedium; +import decodes.db.ValueNotFoundException; +import decodes.sql.DbKey; +import decodes.tsdb.DbIoException; +import opendcs.dai.PlatformStatusDAI; +import opendcs.dai.ScheduleEntryDAI; import org.opendcs.odcsapi.beans.ApiPlatform; import org.opendcs.odcsapi.beans.ApiPlatformRef; -import org.opendcs.odcsapi.dao.ApiPlatformDAO; +import org.opendcs.odcsapi.beans.ApiPlatformSensor; +import org.opendcs.odcsapi.beans.ApiPlatformStatus; +import org.opendcs.odcsapi.beans.ApiTransportMedium; import org.opendcs.odcsapi.dao.DbException; -import org.opendcs.odcsapi.errorhandling.ErrorCodes; +import org.opendcs.odcsapi.errorhandling.DatabaseItemNotFoundException; +import org.opendcs.odcsapi.errorhandling.MissingParameterException; import org.opendcs.odcsapi.errorhandling.WebAppException; -import org.opendcs.odcsapi.hydrojson.DbInterface; import org.opendcs.odcsapi.util.ApiConstants; -import org.opendcs.odcsapi.util.ApiHttpUtil; @Path("/") -public class PlatformResources +public final class PlatformResources extends OpenDcsResource { @Context HttpHeaders httpHeaders; @@ -51,93 +74,442 @@ public class PlatformResources @Path("platformrefs") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({ApiConstants.ODCS_API_GUEST}) - public Response gePlatformRefs(@QueryParam("tmtype") String tmtype) - throws DbException, SQLException + public Response getPlatformRefs(@QueryParam("tmtype") String tmtype) + throws DbException { - HashMap ret = new HashMap<>(); - Logger.getLogger(ApiConstants.loggerName).fine("getPlatforms, tmtype=" + tmtype); - try (DbInterface dbi = new DbInterface(); - ApiPlatformDAO platformDAO = new ApiPlatformDAO(dbi)) + DatabaseIO dbIo = getLegacyDatabase(); + Map ret = new HashMap<>(); + try { - ArrayList platSpecs = platformDAO.getPlatformRefs(tmtype); + + PlatformList platformList = new PlatformList(); + platformList = dbIo.readPlatformList(platformList, tmtype); + List platSpecs = map(platformList); for(ApiPlatformRef ps : platSpecs) + { ret.put(ps.getName(), ps); + } + return Response.status(HttpServletResponse.SC_OK).entity(ret).build(); + } + catch (DatabaseException ex) + { + throw new DbException("Unable to retrieve platform list", ex); + } + finally + { + dbIo.close(); } - Logger.getLogger(ApiConstants.loggerName).fine("getPlatforms returning " + ret.size() + " objects."); - return ApiHttpUtil.createResponse(ret); } - + + static List map(PlatformList platformList) + { + List ret = new ArrayList<>(); + Iterator platform = platformList.iterator(); + while (platform.hasNext()) + { + ApiPlatformRef ref = new ApiPlatformRef(); + Platform plat = platform.next(); + ref.setName(plat.getDisplayName()); + if (plat.getId() != null) + { + ref.setPlatformId(plat.getId().getValue()); + } + else + { + ref.setPlatformId(DbKey.NullKey.getValue()); + } + ref.setAgency(plat.getAgency()); + ref.setConfig(plat.getConfigName()); + ref.setDescription(plat.getDescription()); + if (plat.getConfig() != null && plat.getConfig().getId() != null) + { + ref.setConfigId(plat.getConfig().getId().getValue()); + } + else + { + ref.setConfigId(DbKey.NullKey.getValue()); + } + if (plat.getSite() != null) + { + ref.setSiteId(plat.getSite().getId().getValue()); + } + else + { + ref.setSiteId(DbKey.NullKey.getValue()); + } + ref.setName(plat.getSiteName(false)); + ref.setTransportMedia(plat.getProperties()); + ref.setDesignator(plat.getPlatformDesignator()); + ret.add(ref); + } + return ret; + } + @GET @Path("platform") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({ApiConstants.ODCS_API_GUEST}) public Response getPlatform(@QueryParam("platformid") Long platformId) - throws WebAppException, DbException, SQLException + throws WebAppException, DbException { if (platformId == null) - throw new WebAppException(ErrorCodes.MISSING_ID, - "Missing required platformid parameter."); - - Logger.getLogger(ApiConstants.loggerName).fine("getPlatform id=" + platformId); - try (DbInterface dbi = new DbInterface(); - ApiPlatformDAO dao = new ApiPlatformDAO(dbi)) { - return ApiHttpUtil.createResponse(dao.readPlatform(platformId)); + throw new MissingParameterException("Missing required platformid parameter."); + } + + DatabaseIO dbIo = getLegacyDatabase(); + try + { + Platform platform = new Platform(); + platform.setId(DbKey.createDbKey(platformId)); + platform = dbIo.readPlatform(platform); + return Response.status(HttpServletResponse.SC_OK).entity(map(platform)).build(); + } + catch (DatabaseException ex) + { + if (ex.getCause() instanceof ValueNotFoundException) + { + throw new DatabaseItemNotFoundException("Platform with ID " + platformId + " not found."); + } + throw new DbException("Unable to retrieve platform", ex); + } + finally + { + dbIo.close(); } } - + + static ApiPlatform map(Platform platform) + { + ApiPlatform ret = new ApiPlatform(); + if (platform.getId() != null) + { + ret.setPlatformId(platform.getId().getValue()); + } + else + { + ret.setPlatformId(DbKey.NullKey.getValue()); + } + ret.setAgency(platform.getAgency()); + ret.setDescription(platform.getDescription()); + ret.setDesignator(platform.getPlatformDesignator()); + if (platform.getConfig() != null && platform.getConfig().getId() != null) + { + ret.setConfigId(platform.getConfig().getId().getValue()); + } + else + { + ret.setConfigId(DbKey.NullKey.getValue()); + } + ret.setProduction(platform.isProduction); + if (platform.getSite() != null && platform.getSite().getId() != null) + { + ret.setSiteId(platform.getSite().getId().getValue()); + } + else + { + ret.setSiteId(DbKey.NullKey.getValue()); + } + ret.setName(platform.getSiteName(false)); + ret.setTransportMedia(map(platform.getTransportMedia())); + return ret; + } + + static ArrayList map(Iterator transportMedium) + { + ArrayList transportMedia = new ArrayList<>(); + while (transportMedium.hasNext()) + { + TransportMedium tm = transportMedium.next(); + ApiTransportMedium apiTm = new ApiTransportMedium(); + apiTm.setMediumId(tm.getMediumId()); + apiTm.setMediumType(tm.getMediumType()); + apiTm.setBaud(tm.getBaud()); + apiTm.setAssignedTime(tm.assignedTime); + apiTm.setChannelNum(tm.channelNum); + apiTm.setDataBits(tm.getDataBits()); + apiTm.setTimezone(tm.getTimeZone()); + apiTm.setStopBits(tm.getStopBits()); + apiTm.setParity(String.valueOf(tm.getParity())); + apiTm.setDoLogin(tm.isDoLogin()); + apiTm.setPassword(tm.getPassword()); + apiTm.setUsername(tm.getUsername()); + apiTm.setScriptName(tm.scriptName); + apiTm.setTransportInterval(tm.transmitInterval); + apiTm.setTransportWindow(tm.transmitWindow); + + transportMedia.add(apiTm); + } + return transportMedia; + } + @POST @Path("platform") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({ApiConstants.ODCS_API_ADMIN, ApiConstants.ODCS_API_USER}) public Response postPlatform(ApiPlatform platform) - throws WebAppException, DbException, SQLException + throws DbException + { + DatabaseIO dbIo = getLegacyDatabase(); + try + { + Platform plat = map(platform); + dbIo.writePlatform(plat); + return Response.status(HttpServletResponse.SC_CREATED) + .entity(map(plat)) + .build(); + } + catch (DatabaseException ex) + { + throw new DbException(String.format("Unable to store platform with name: %s", platform.getName()), ex); + } + finally + { + dbIo.close(); + } + } + + static Platform map(ApiPlatform platform) throws DatabaseException { - Logger.getLogger(ApiConstants.loggerName) - .fine("post platform received platformId=" + platform.getPlatformId()); - - try (DbInterface dbi = new DbInterface(); - ApiPlatformDAO dao = new ApiPlatformDAO(dbi)) + Platform ret = new Platform(); + if (platform.getPlatformId() != null) + { + ret.setId(DbKey.createDbKey(platform.getPlatformId())); + } + else + { + ret.setId(DbKey.NullKey); + } + ret.setAgency(platform.getAgency()); + ret.setDescription(platform.getDescription()); + ret.setPlatformDesignator(platform.getDesignator()); + ret.lastModifyTime = new Date(); + ret.platformSensors = platMap(platform.getPlatformSensors()); + if (platform.getConfigId() != null) { - dao.writePlatform(platform); - return ApiHttpUtil.createResponse(platform); + PlatformConfig config = new PlatformConfig(); + config.setId(DbKey.createDbKey(platform.getConfigId())); + ret.setConfig(config); } + ret.isProduction = platform.isProduction(); + if (platform.getSiteId() != null) + { + Site site = new Site(); + site.setId(DbKey.createDbKey(platform.getSiteId())); + site.setPublicName(platform.getName()); + ret.setSite(site); + } + ret.transportMedia = map(platform.getTransportMedia()); + return ret; } - + + static Vector platMap(List platformSensors) throws DatabaseException + { + Vector ret = new Vector<>(); + for (ApiPlatformSensor sensor: platformSensors) + { + PlatformSensor ps = new PlatformSensor(); + ps.sensorNumber = sensor.getSensorNum(); + if (sensor.getActualSiteId() != null) + { + Site site = new Site(); + site.setId(DbKey.createDbKey(sensor.getActualSiteId())); + ps.site = site; + } + ps.setUsgsDdno(sensor.getUsgsDdno()); + Properties props = sensor.getSensorProps(); + for (String name : props.stringPropertyNames()) + { + ps.setProperty(name, props.getProperty(name)); + } + ret.add(ps); + } + return ret; + } + + static Vector map(List transportMedium) + { + Vector ret = new Vector<>(); + for (ApiTransportMedium tm : transportMedium) + { + Platform platform = new Platform(); + TransportMedium t = new TransportMedium(platform); + if (tm.getMediumId() != null) + { + t.setMediumId(tm.getMediumId()); + } + t.setMediumType(tm.getMediumType()); + t.setBaud(tm.getBaud()); + if (tm.getAssignedTime() != null) + { + t.assignedTime = tm.getAssignedTime(); + } + if (tm.getChannelNum() != null) + { + t.channelNum = tm.getChannelNum(); + } + if (tm.getDataBits() != null) + { + t.setDataBits(tm.getDataBits()); + } + t.setTimeZone(tm.getTimezone()); + if (tm.getStopBits() != null) + { + t.setStopBits(tm.getStopBits()); + } + t.setParity(tm.getParity().charAt(0)); + t.setDoLogin(tm.getDoLogin()); + t.setPassword(tm.getPassword()); + t.setUsername(tm.getUsername()); + t.scriptName = tm.getScriptName(); + if (tm.getTransportInterval() != null) + { + t.transmitInterval = tm.getTransportInterval(); + } + if (tm.getTransportWindow() != null) + { + t.transmitWindow = tm.getTransportWindow(); + } + if (tm.getChannelNum() != null) + { + t.channelNum = tm.getChannelNum(); + } + ret.add(t); + } + return ret; + } + @DELETE @Path("platform") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({ApiConstants.ODCS_API_ADMIN, ApiConstants.ODCS_API_USER}) public Response deletePlatform(@QueryParam("platformid") Long platformId) - throws WebAppException, DbException + throws DbException, WebAppException { - Logger.getLogger(ApiConstants.loggerName) - .fine("DELETE platform received id=" + platformId); - - // Use username and password to attempt to connect to the database - try (DbInterface dbi = new DbInterface(); - ApiPlatformDAO platDao = new ApiPlatformDAO(dbi)) + if (platformId == null) { - platDao.deletePlatform(platformId); - return ApiHttpUtil.createResponse("Platform with ID " + platformId + " deleted"); + throw new MissingParameterException("Missing required platformid parameter."); + } + + DatabaseIO dbIo = getLegacyDatabase(); + try + { + Platform plat = new Platform(); + plat.setId(DbKey.createDbKey(platformId)); + dbIo.deletePlatform(plat); + return Response.status(HttpServletResponse.SC_NO_CONTENT) + .entity("Platform with ID " + platformId + " deleted") + .build(); + } + catch (DatabaseException ex) + { + throw new DbException(String.format("Unable to delete platform with ID: %s", platformId), ex); + } + finally + { + dbIo.close(); } } - + @GET @Path("platformstat") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed({ApiConstants.ODCS_API_GUEST}) - public Response gePlatformStats(@QueryParam("netlistid") Long netlistId) - throws DbException, SQLException + public Response getPlatformStats(@QueryParam("netlistid") Long netlistId) + throws DbException, WebAppException + { + if (netlistId == null) + { + throw new MissingParameterException("Missing required netlistid parameter."); + } + + DatabaseIO dbIo = getLegacyDatabase(); + try (PlatformStatusDAI dao = dbIo.makePlatformStatusDAO()) + { + List statuses = dao.readPlatformStatusList(DbKey.createDbKey(netlistId)); + return Response.status(HttpServletResponse.SC_OK).entity(statusListMap(dbIo, statuses)).build(); + } + catch (DbIoException | DatabaseException ex) + { + throw new DbException(String.format("Unable to retrieve platform status with ID: %s", netlistId), ex); + } + finally + { + dbIo.close(); + } + } + + static List statusListMap(DatabaseIO dbIo, List statuses) throws DatabaseException { - Logger.getLogger(ApiConstants.loggerName).fine("gePlatformStats, netlistid=" + netlistId); - try (DbInterface dbi = new DbInterface(); - ApiPlatformDAO platformDAO = new ApiPlatformDAO(dbi)) + if(statuses == null) + { + return new ArrayList<>(); + } + List ret = new ArrayList<>(); + for(PlatformStatus status : statuses) { - return ApiHttpUtil.createResponse(platformDAO.getPlatformStatus(netlistId)); + ApiPlatformStatus ps = new ApiPlatformStatus(); + if(status.getPlatformId() != null) + { + ps.setPlatformId(status.getPlatformId().getValue()); + } + else + { + ps.setPlatformId(DbKey.NullKey.getValue()); + } + ps.setAnnotation(status.getAnnotation()); + ps.setLastContact(status.getLastContactTime()); + ps.setLastError(status.getLastErrorTime()); + ps.setLastMessage(status.getLastMessageTime()); + if (!status.getLastScheduleEntryStatusId().isNull() + && (status.getLastRoutingSpecName() == null || status.getLastRoutingSpecName().isEmpty())) + { + try (ScheduleEntryDAI dai = dbIo.makeScheduleEntryDAO()) + { + ScheduleEntry scheduleEntry = dai.readScheduleEntry(status.getLastScheduleEntryStatusId()); + long routingId = scheduleEntry.getRoutingSpecId().getValue(); + RoutingSpec rs = new RoutingSpec(); + rs.setId(DbKey.createDbKey(routingId)); + dbIo.readRoutingSpec(rs); + ps.setRoutingSpecName(rs.getName()); + } + catch (DbIoException ex) + { + throw new DatabaseException("Unable to retrieve routing spec for platform status", ex); + } + } + else + { + ps.setRoutingSpecName(status.getLastRoutingSpecName()); + } + ps.setLastRoutingExecId(status.getLastScheduleEntryStatusId().getValue()); + if (status.getPlatformId() != null) + { + Platform pl = new Platform(); + pl.setId(status.getPlatformId()); + dbIo.readPlatform(pl); + if (pl.getSite() != null && pl.getSite().getId() != null) + { + ps.setSiteId(pl.getSite().getId().getValue()); + } + if (pl.getSite() != null && pl.getSite().getUniqueName() != null + && !pl.getSite().getUniqueName().isEmpty()) + { + if (status.getDesignator() != null && !status.getDesignator().isEmpty()) + { + ps.setPlatformName(pl.getSite().getUniqueName() + "-" + status.getDesignator()); + } + else + { + ps.setPlatformName(pl.getSite().getUniqueName()); + } + } + } + ret.add(ps); } + return ret; } -} +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/fixtures/DatabaseSetupExtension.java b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/fixtures/DatabaseSetupExtension.java index ecd40b414..374f5ac70 100644 --- a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/fixtures/DatabaseSetupExtension.java +++ b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/fixtures/DatabaseSetupExtension.java @@ -21,6 +21,8 @@ import java.sql.SQLException; import javax.servlet.http.HttpServletResponse; +import decodes.db.PlatformStatus; +import decodes.db.ScheduleEntryStatus; import io.restassured.RestAssured; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; @@ -40,6 +42,7 @@ public class DatabaseSetupExtension implements BeforeEachCallback { private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseSetupExtension.class); private static DbType currentDbType; + private static Configuration currentConfig; private static TomcatServer currentTomcat; private final Configuration config; private final DbType dbType; @@ -49,6 +52,7 @@ public DatabaseSetupExtension(Configuration config, DbType dbType) { this.config = config; this.dbType = dbType; + currentConfig = config; } public static DbType getCurrentDbType() @@ -150,6 +154,29 @@ private static void healthCheck() throws InterruptedException } } + public static void loadXMLDataIntoDb(String[] files) throws Exception + { + String[] filePaths = new String[files.length]; + for (int i = 0; i < files.length; i++) + { + filePaths[i] = String.format("%s%s%s", + System.getProperty("user.dir"), + "/src/test/resources/org/opendcs/odcsapi/res/it/", + files[i]); + } + currentConfig.loadXMLData(filePaths, new SystemExit(), new SystemProperties()); + } + + public static void storeScheduleEntryStatus(ScheduleEntryStatus status) throws Exception + { + currentConfig.storeScheduleEntryStatus(status); + } + + public static void storePlatformStatus(PlatformStatus status) throws Exception + { + currentConfig.storePlatformStatus(status); + } + private void setupClientUser() { if(dbType == DbType.CWMS) diff --git a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/PlatformResourcesTest.java b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/PlatformResourcesTest.java new file mode 100644 index 000000000..769c61256 --- /dev/null +++ b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/PlatformResourcesTest.java @@ -0,0 +1,514 @@ +package org.opendcs.odcsapi.res; + +import java.sql.Date; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Vector; + +import decodes.db.DatabaseIO; +import decodes.db.DecodesScript; +import decodes.db.EquipmentModel; +import decodes.db.Platform; +import decodes.db.PlatformConfig; +import decodes.db.PlatformList; +import decodes.db.PlatformSensor; +import decodes.db.PlatformStatus; +import decodes.db.RoutingSpec; +import decodes.db.ScheduleEntry; +import decodes.db.ScriptSensor; +import decodes.db.Site; +import decodes.db.SiteName; +import decodes.db.TransportMedium; +import decodes.sql.DbKey; +import decodes.xml.DecodesScriptParser; +import opendcs.dao.ScheduleEntryDAO; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.opendcs.odcsapi.beans.ApiPlatform; +import org.opendcs.odcsapi.beans.ApiPlatformRef; +import org.opendcs.odcsapi.beans.ApiPlatformSensor; +import org.opendcs.odcsapi.beans.ApiPlatformStatus; +import org.opendcs.odcsapi.beans.ApiTransportMedium; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; +import static org.opendcs.odcsapi.res.PlatformResources.map; +import static org.opendcs.odcsapi.res.PlatformResources.statusListMap; + +@ExtendWith(MockitoExtension.class) +final class PlatformResourcesTest +{ + @Mock + DatabaseIO dbIo; + + @Mock + ScheduleEntryDAO scheduleEntryDAO; + + @Test + void testPlatformRefMap() throws Exception + { + DbKey platId1 = DbKey.createDbKey(556774L); + DbKey platId2 = DbKey.createDbKey(557774L); + PlatformList platformList = new PlatformList(); + Platform plat1 = new Platform(); + plat1.setAgency("USGS"); + plat1.setDescription("Platform 1"); + plat1.setPlatformDesignator("Platform Designator"); + plat1.setConfigName("Platform Configuration"); + plat1.setIsComplete(true); + plat1.setId(platId1); + PlatformConfig config = new PlatformConfig(); + config.setId(DbKey.createDbKey(33565L)); + config.configName = "Platform Configuration"; + config.numPlatformsUsing = 11; + config.description = "A configuration for a platform"; + EquipmentModel model = new EquipmentModel(); + model.model = "Model 1"; + model.description = "An equipment model"; + model.setId(DbKey.createDbKey(555584L)); + model.name = "Equipped model"; + model.company = "RMA"; + Properties properties = new Properties(); + properties.setProperty("prop1", "value1"); + model.properties = properties; + config.equipmentModel = model; + Vector scripts = new Vector<>(); + DecodesScript script = new DecodesScript + .DecodesScriptBuilder(new DecodesScriptParser()).platformConfig(config) + .scriptName("Testing Script").build(); + ScriptSensor sensor = new ScriptSensor(script, 22); + script.addScriptSensor(sensor); + scripts.add(script); + config.decodesScripts = scripts; + plat1.setConfig(config); + Platform plat2 = new Platform(); + plat2.setAgency("USBR"); + plat2.setDescription("USBR Platform"); + plat2.setPlatformDesignator("Platform Designator 2"); + plat2.setConfigName("Platform Configuration 2"); + plat2.setIsComplete(true); + plat2.setId(platId2); + PlatformConfig config2 = new PlatformConfig(); + config2.setId(DbKey.createDbKey(34565L)); + config2.configName = plat2.getConfigName(); + config2.numPlatformsUsing = 34; + config2.description = "Configuration data for a platform"; + EquipmentModel model2 = new EquipmentModel(); + model2.model = "Model 2"; + model2.description = "An equipment model"; + model2.setId(DbKey.createDbKey(565584L)); + model2.name = "Equipment model 2"; + model2.company = "GEI"; + Properties properties2 = new Properties(); + properties2.setProperty("prop2", "value2"); + model2.properties = properties2; + config2.equipmentModel = model; + Vector scripts2 = new Vector<>(); + DecodesScript script2 = new DecodesScript + .DecodesScriptBuilder(new DecodesScriptParser()).platformConfig(config2) + .scriptName("Testing Script 2").build(); + ScriptSensor sensor2 = new ScriptSensor(script2, 22); + script2.addScriptSensor(sensor2); + scripts2.add(script2); + config2.decodesScripts = scripts2; + plat2.setConfig(config2); + platformList.add(plat1); + platformList.add(plat2); + + List platRefs = map(platformList); + + assertNotNull(platRefs); + assertFalse(platRefs.isEmpty()); + assertEquals(2, platRefs.size()); + Platform plat1Ref = platformList.getById(platId1); + Platform plat2Ref = platformList.getById(platId2); + assertNotNull(plat1Ref); + assertNotNull(plat2Ref); + + assertEquals(plat1.getAgency(), plat1Ref.getAgency()); + assertEquals(plat1.getDescription(), plat1Ref.getDescription()); + assertEquals(plat1.getPlatformDesignator(), plat1Ref.getPlatformDesignator()); + assertEquals(plat1.getConfigName(), plat1Ref.getConfigName()); + assertEquals(plat1.getId().getValue(), plat1Ref.getId().getValue()); + assertEquals(plat1.getConfig().getId().getValue(), plat1Ref.getConfig().getId().getValue()); + assertEquals(plat1.getConfig().getEquipmentModel().getId().getValue(), plat1Ref.getConfig().getEquipmentModel().getId().getValue()); + assertEquals(plat1.getConfig().getEquipmentModel().getName(), plat1Ref.getConfig().getEquipmentModel().getName()); + assertPlatMatchIterators(plat1.getPlatformSensors(), plat1Ref.getPlatformSensors()); + assertTransportMatch(plat1.getTransportMedia(), plat1Ref.getTransportMedia()); + assertEquals(plat1.getProperties(), plat1Ref.getProperties()); + assertEquals(plat1.getBriefDescription(), plat1Ref.getBriefDescription()); + assertEquals(plat1.getDisplayName(), plat1Ref.getDisplayName()); + if (plat1.getSite() != null && plat1Ref.getSite() != null) + { + assertEquals(plat1.getSite().getId().getValue(), plat1Ref.getSite().getId().getValue()); + assertEquals(plat1.getSite().getDisplayName(), plat1Ref.getSiteName()); + } + else + { + assertNull(plat1.getSite()); + assertNull(plat1Ref.getSite()); + } + assertEquals(plat2.getAgency(), plat2Ref.getAgency()); + assertEquals(plat2.getDescription(), plat2Ref.getDescription()); + assertEquals(plat2.getPlatformDesignator(), plat2Ref.getPlatformDesignator()); + assertEquals(plat2.getConfigName(), plat2Ref.getConfigName()); + assertEquals(plat2.getId().getValue(), plat2Ref.getId().getValue()); + assertEquals(plat2.getConfig().getId().getValue(), plat2Ref.getConfig().getId().getValue()); + assertEquals(plat2.getConfig().getEquipmentModel().getId().getValue(), plat2Ref.getConfig().getEquipmentModel().getId().getValue()); + assertEquals(plat2.getConfig().getEquipmentModel().getName(), plat2Ref.getConfig().getEquipmentModel().getName()); + assertPlatMatchIterators(plat2.getPlatformSensors(), plat2Ref.getPlatformSensors()); + assertTransportMatch(plat2.getTransportMedia(), plat2Ref.getTransportMedia()); + assertEquals(plat2.getProperties(), plat2Ref.getProperties()); + assertEquals(plat2.getBriefDescription(), plat2Ref.getBriefDescription()); + assertEquals(plat2.getDisplayName(), plat2Ref.getDisplayName()); + if (plat2.getSite() != null && plat2Ref.getSite() != null) + { + assertEquals(plat2.getSite().getId().getValue(), plat2Ref.getSite().getId().getValue()); + assertEquals(plat2.getSite().getDisplayName(), plat2Ref.getSiteName()); + } + else + { + assertNull(plat2.getSite()); + assertNull(plat2Ref.getSite()); + } + } + + @Test + void testPlatformMap() throws Exception + { + DbKey platId1 = DbKey.createDbKey(556774L); + Platform plat1 = new Platform(); + plat1.setAgency("USGS"); + plat1.setDescription("Platform 1"); + plat1.setPlatformDesignator("Platform Designator"); + plat1.setConfigName("Platform Configuration"); + plat1.setIsComplete(true); + plat1.setId(platId1); + Site site = new Site(); + site.setId(DbKey.createDbKey(1234L)); + plat1.setSite(site); + PlatformConfig config = new PlatformConfig(); + config.setId(DbKey.createDbKey(33565L)); + config.configName = plat1.getConfigName(); + config.numPlatformsUsing = 11; + config.description = "Platform configuration data"; + EquipmentModel model = new EquipmentModel(); + model.model = "Model 1"; + model.description = "Equipment model 1"; + model.setId(DbKey.createDbKey(555584L)); + model.name = "New Model"; + model.company = "RMA"; + Properties properties = new Properties(); + properties.setProperty("prop1", "value1"); + model.properties = properties; + config.equipmentModel = model; + Vector scripts = new Vector<>(); + DecodesScript script = new DecodesScript + .DecodesScriptBuilder(new DecodesScriptParser()).platformConfig(config) + .scriptName("Integration Testing Script").build(); + ScriptSensor sensor = new ScriptSensor(script, 22); + script.addScriptSensor(sensor); + scripts.add(script); + config.decodesScripts = scripts; + plat1.setConfig(config); + + ApiPlatform plat = map(plat1); + assertNotNull(plat); + + assertEquals(plat1.getAgency(), plat.getAgency()); + assertEquals(plat1.getDescription(), plat.getDescription()); + assertEquals(plat1.getPlatformDesignator(), plat.getDesignator()); + assertEquals(plat1.getId().getValue(), plat.getPlatformId()); + assertEquals(plat1.getConfig().getId().getValue(), plat.getConfigId()); + assertMatch(plat.getPlatformSensors(), plat1.getPlatformSensors()); + assertMatchMedium(plat.getTransportMedia(), plat1.getTransportMedia()); + assertEquals(plat1.getProperties(), plat.getProperties()); + assertEquals(plat1.getSite().getId().getValue(), plat.getSiteId()); + assertPlatMatch(plat1.getPlatformSensors(), plat.getPlatformSensors()); + assertMatch(plat1.getTransportMedia(), plat.getTransportMedia()); + } + + private void assertPlatMatch(Iterator platSensors, List apiPlatSensors) + { + assertEquals(apiPlatSensors.size(), iterSize(platSensors)); + int i = 0; + while (platSensors.hasNext()) + { + PlatformSensor platSensor = platSensors.next(); + ApiPlatformSensor apiSensor = apiPlatSensors.get(i); + + assertEquals(platSensor.sensorNumber, apiSensor.getSensorNum()); + assertEquals(platSensor.site.getId().getValue(), apiSensor.getActualSiteId()); + assertEquals(platSensor.getProperties(), apiSensor.getSensorProps()); + assertEquals(platSensor.getUsgsDdno(), apiSensor.getUsgsDdno()); + + i++; + } + } + + private void assertPlatMatchIterators(Iterator platSensors, Iterator otherPlatSensors) + { + assertEquals(iterSize(platSensors), iterSize(otherPlatSensors)); + + while (platSensors.hasNext()) + { + PlatformSensor sensorA = platSensors.next(); + PlatformSensor sensorB = otherPlatSensors.next(); + assertEquals(sensorA.sensorNumber, sensorB.sensorNumber); + assertEquals(sensorA.site.getId().getValue(), sensorB.site.getId().getValue()); + assertEquals(sensorA.getProperties(), sensorB.getProperties()); + assertEquals(sensorA.getUsgsDdno(), sensorB.getUsgsDdno()); + } + } + + private void assertTransportMatch(Iterator expectedTransportMedium, Iterator transportMedium) + { + assertEquals(iterSize(expectedTransportMedium), iterSize(transportMedium)); + + while (expectedTransportMedium.hasNext()) + { + TransportMedium expected = expectedTransportMedium.next(); + TransportMedium actual = transportMedium.next(); + assertEquals(expected.getMediumType(), actual.getMediumType()); + assertEquals(expected.getMediumId(), actual.getMediumId()); + assertEquals(expected.scriptName, actual.scriptName); + assertEquals(expected.channelNum, actual.channelNum); + assertEquals(expected.assignedTime, actual.assignedTime); + assertEquals(expected.transmitWindow, actual.transmitWindow); + assertEquals(expected.transmitInterval, actual.transmitInterval); + assertEquals(expected.getTimeZone(), actual.getTimeZone()); + assertEquals(expected.getBaud(), actual.getBaud()); + assertEquals(expected.getStopBits(), actual.getStopBits()); + assertEquals(expected.getDataBits(), actual.getDataBits()); + assertEquals(expected.getParity(), actual.getParity()); + assertEquals(expected.getUsername(), actual.getUsername()); + assertEquals(expected.getPassword(), actual.getPassword()); + assertEquals(expected.isDoLogin(), actual.isDoLogin()); + } + } + + private void assertMatch(Iterator transportMed, List apiTransportMed) + { + assertEquals(apiTransportMed.size(), iterSize(transportMed)); + int i = 0; + while (transportMed.hasNext()) + { + TransportMedium transportMedium = transportMed.next(); + ApiTransportMedium apiTransportMedium = apiTransportMed.get(i); + + assertEquals(transportMedium.getMediumType(), apiTransportMedium.getMediumType()); + assertEquals(transportMedium.getMediumId(), apiTransportMedium.getMediumId()); + assertEquals(transportMedium.scriptName, apiTransportMedium.getScriptName()); + assertEquals(transportMedium.channelNum, apiTransportMedium.getChannelNum()); + assertEquals(transportMedium.assignedTime, apiTransportMedium.getAssignedTime()); + assertEquals(transportMedium.transmitWindow, apiTransportMedium.getTransportWindow()); + assertEquals(transportMedium.transmitInterval, apiTransportMedium.getTransportInterval()); + assertEquals(transportMedium.getTimeZone(), apiTransportMedium.getTimezone()); + assertEquals(transportMedium.getBaud(), apiTransportMedium.getBaud()); + assertEquals(transportMedium.getStopBits(), apiTransportMedium.getStopBits()); + assertEquals(transportMedium.getDataBits(), apiTransportMedium.getDataBits()); + assertEquals(transportMedium.getParity(), apiTransportMedium.getParity().charAt(0)); + assertEquals(transportMedium.getUsername(), apiTransportMedium.getUsername()); + assertEquals(transportMedium.getPassword(), apiTransportMedium.getPassword()); + assertEquals(transportMedium.isDoLogin(), apiTransportMedium.getDoLogin()); + + i++; + } + } + + @Test + void testApiPlatformMap() throws Exception + { + ApiPlatform plat = new ApiPlatform(); + plat.setAgency("USGS"); + plat.setDescription("Platform 10"); + plat.setDesignator("Platform Designator"); + plat.setConfigId(33565L); + plat.setPlatformId(556774L); + ArrayList platSensors = new ArrayList<>(); + ApiPlatformSensor ps = new ApiPlatformSensor(); + ps.setMax(100.0); + ps.setMin(0.0); + ps.setSensorNum(22); + ps.setActualSiteId(1234L); + ps.setUsgsDdno(1534); + Properties props = new Properties(); + props.setProperty("prop1", "value1"); + ps.setSensorProps(props); + platSensors.add(ps); + plat.setPlatformSensors(platSensors); + plat.setSiteId(1234L); + plat.setLastModified(Date.from(Instant.parse("2021-07-01T12:00:00Z"))); + plat.setProduction(true); + + Platform result = map(plat); + + assertNotNull(result); + assertEquals(plat.getAgency(), result.getAgency()); + assertEquals(plat.getDescription(), result.getDescription()); + assertEquals(plat.getDesignator(), result.getPlatformDesignator()); + assertEquals(plat.getPlatformId(), result.getId().getValue()); + assertEquals(plat.getConfigId(), result.getConfig().getId().getValue()); + assertMatch(plat.getPlatformSensors(), result.getPlatformSensors()); + assertMatchMedium(plat.getTransportMedia(), result.getTransportMedia()); + assertEquals(plat.getProperties(), result.getProperties()); + } + + private static void assertMatch(List apiPlatformSensors, Iterator platformSensors) + { + assertEquals(apiPlatformSensors.size(), iterSize(platformSensors)); + int i = 0; + while (platformSensors.hasNext()) + { + PlatformSensor platformSensor = platformSensors.next(); + ApiPlatformSensor apiPlatformSensor = apiPlatformSensors.get(i); + + assertEquals(platformSensor.sensorNumber, apiPlatformSensor.getSensorNum()); + assertEquals(platformSensor.site.getId().getValue(), apiPlatformSensor.getActualSiteId()); + assertEquals(platformSensor.getProperties(), apiPlatformSensor.getSensorProps()); + assertEquals(platformSensor.getUsgsDdno(), apiPlatformSensor.getUsgsDdno()); + + i++; + } + } + + private static void assertMatchMedium(List apiTransportMedium, Iterator transportMedium) + { + assertEquals(apiTransportMedium.size(), iterSize(transportMedium)); + int i = 0; + while (transportMedium.hasNext()) + { + TransportMedium tm = transportMedium.next(); + ApiTransportMedium atm = apiTransportMedium.get(i); + + assertEquals(tm.getMediumType(), atm.getMediumType()); + assertEquals(tm.getMediumId(), atm.getMediumId()); + assertEquals(tm.scriptName, atm.getScriptName()); + assertEquals(tm.channelNum, atm.getChannelNum()); + assertEquals(tm.assignedTime, atm.getAssignedTime()); + assertEquals(tm.transmitWindow, atm.getTransportWindow()); + assertEquals(tm.transmitInterval, atm.getTransportInterval()); + assertEquals(tm.getTimeZone(), atm.getTimezone()); + assertEquals(tm.getBaud(), atm.getBaud()); + assertEquals(tm.getStopBits(), atm.getStopBits()); + assertEquals(tm.getDataBits(), atm.getDataBits()); + assertEquals(tm.getParity(), atm.getParity().charAt(0)); + assertEquals(tm.getUsername(), atm.getUsername()); + assertEquals(tm.getPassword(), atm.getPassword()); + assertEquals(tm.isDoLogin(), atm.getDoLogin()); + } + } + + @Test + void testPlatformStatusMap() throws Exception + { + String siteName = "Platform location"; + String routingSpecName = "Routing Spec 1"; + + DbKey scheduleEntryStatusId = DbKey.createDbKey(9987501L); + DbKey routingSpecId = DbKey.createDbKey(9987502L); + DbKey platformId = DbKey.createDbKey(9989900L); + DbKey siteId = DbKey.createDbKey(9987504L); + + Site site = new Site(); + site.setId(siteId); + SiteName sn = new SiteName(site, "site"); + sn.setNameValue(siteName); + site.addName(sn); + + ScheduleEntry entry = new ScheduleEntry("Test Entry"); + entry.setRoutingSpecId(routingSpecId); + + doAnswer(invocation -> { + Platform p = invocation.getArgument(0); + assertEquals(platformId, p.getId()); + p.setSite(site); + return null; + }).when(dbIo).readPlatform(any(Platform.class)); + + List statuses = new ArrayList<>(); + PlatformStatus status = new PlatformStatus(platformId); + status.setDesignator("Platform Designator"); + status.setAnnotation("Platform Annotation"); + status.setChecked(true); + status.setLastContactTime(Date.from(Instant.parse("2021-07-02T12:00:00Z"))); + status.setSiteName(siteName); + status.setLastFailureCodes("System Failure 2"); + status.setLastErrorTime(Date.from(Instant.parse("2021-07-01T12:00:00Z"))); + status.setLastRoutingSpecName(routingSpecName); + status.setLastScheduleEntryStatusId(scheduleEntryStatusId); + + statuses.add(status); + + List apiStatus = statusListMap(dbIo, statuses); + + assertNotNull(apiStatus); + assertFalse(apiStatus.isEmpty()); + assertEquals(1, apiStatus.size()); + ApiPlatformStatus apiStat = apiStatus.get(0); + assertEquals(status.getAnnotation(), apiStat.getAnnotation()); + assertEquals(status.getLastContactTime(), apiStat.getLastContact()); + assertEquals(status.getPlatformId().getValue(), apiStat.getPlatformId()); + assertEquals(status.getLastRoutingSpecName(), apiStat.getRoutingSpecName()); + assertEquals(status.getLastScheduleEntryStatusId().getValue(), apiStat.getLastRoutingExecId()); + + // Test with dbIo mocked to return a ScheduleEntry + when(dbIo.makeScheduleEntryDAO()).thenReturn(scheduleEntryDAO); + when(scheduleEntryDAO.readScheduleEntry(scheduleEntryStatusId)).thenReturn(entry); + doAnswer(invocation -> { + RoutingSpec rs = invocation.getArgument(0); + assertEquals(routingSpecId, rs.getId()); + rs.setName(routingSpecName); + return null; + }).when(dbIo).readRoutingSpec(any(RoutingSpec.class)); + + statuses = new ArrayList<>(); + status = new PlatformStatus(platformId); + status.setDesignator("Platform Designator"); + status.setAnnotation("Platform Annotation"); + status.setChecked(true); + status.setLastContactTime(Date.from(Instant.parse("2021-07-02T12:00:00Z"))); + status.setSiteName(siteName); + status.setLastFailureCodes("System Failure 2"); + status.setLastErrorTime(Date.from(Instant.parse("2021-07-01T12:00:00Z"))); + status.setLastScheduleEntryStatusId(scheduleEntryStatusId); + + statuses.add(status); + + apiStatus = statusListMap(dbIo, statuses); + + assertNotNull(apiStatus); + assertFalse(apiStatus.isEmpty()); + assertEquals(1, apiStatus.size()); + apiStat = apiStatus.get(0); + assertEquals(status.getAnnotation(), apiStat.getAnnotation()); + assertEquals(status.getLastContactTime(), apiStat.getLastContact()); + assertEquals(status.getPlatformId().getValue(), apiStat.getPlatformId()); + assertEquals(routingSpecName, apiStat.getRoutingSpecName()); + assertEquals(status.getLastScheduleEntryStatusId().getValue(), apiStat.getLastRoutingExecId()); + assertEquals(status.getPlatformName(), apiStat.getPlatformName()); + assertEquals(status.getPlatformId().getValue(), apiStat.getPlatformId()); + assertEquals(siteId.getValue(), apiStat.getSiteId()); + } + + private static int iterSize(Iterator it) + { + int n = 0; + while(it.hasNext()) + { + it.next(); + n++; + } + return n; + } +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/NetlistResourcesIT.java b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/NetlistResourcesIT.java index af4b3e882..1d540b666 100644 --- a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/NetlistResourcesIT.java +++ b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/NetlistResourcesIT.java @@ -65,7 +65,7 @@ void setUp() throws Exception .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)) + .statusCode(is(HttpServletResponse.SC_CREATED)) .extract() ; @@ -133,7 +133,7 @@ void tearDown() .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)) + .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) .extract() ; diff --git a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/OdcsapiResourceIT.java b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/OdcsapiResourceIT.java index 41ecc648f..fdc44fde6 100644 --- a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/OdcsapiResourceIT.java +++ b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/OdcsapiResourceIT.java @@ -249,11 +249,29 @@ private Long storePlatform() throws Exception .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)) + .statusCode(is(HttpServletResponse.SC_CREATED)) .extract() ; - return response.body().jsonPath().getLong("platformId"); + Long platformId = response.body().jsonPath().getLong("platformId"); + + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .queryParam("platformid", platformId) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + ; + + return platformId; } private void deletePlatform(Long platformId) @@ -271,7 +289,7 @@ private void deletePlatform(Long platformId) .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)) + .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) ; } diff --git a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/PlatformResourcesIT.java b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/PlatformResourcesIT.java new file mode 100644 index 000000000..70ddbc3ef --- /dev/null +++ b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/PlatformResourcesIT.java @@ -0,0 +1,522 @@ +package org.opendcs.odcsapi.res.it; + +import java.time.Instant; +import java.util.Date; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.MediaType; + +import decodes.db.PlatformStatus; +import decodes.db.ScheduleEntryStatus; +import decodes.sql.DbKey; +import io.restassured.filter.log.LogDetail; +import io.restassured.filter.session.SessionFilter; +import io.restassured.path.json.JsonPath; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; +import org.opendcs.odcsapi.fixtures.DatabaseContextProvider; +import org.opendcs.odcsapi.fixtures.DatabaseSetupExtension; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Tag("integration-opentsdb-only") +@ExtendWith(DatabaseContextProvider.class) +final class PlatformResourcesIT extends BaseIT +{ + private static SessionFilter sessionFilter; + private static Long platformId; + private static Long siteId; + private static Long netListId; + private static Boolean dataLoaded; + + @BeforeEach + void setUp() throws Exception + { + setUpCreds(); + sessionFilter = new SessionFilter(); + authenticate(sessionFilter); + + long scheduleId = DbKey.NullKey.getValue(); + + if (dataLoaded == null || !dataLoaded) + { + String[] files = new String[]{ + "OPEN_TSDB/platform_netlist_insert.xml", + "OPEN_TSDB/platform_datasource_insert.xml", + "OPEN_TSDB/platform_routingspec_insert.xml", + "OPEN_TSDB/platform_schedule_entry_insert.xml", + }; + DatabaseSetupExtension.loadXMLDataIntoDb(files); + + // get netlistId + ExtractableResponse resp = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("netlistrefs") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract(); + + JsonPath jsonPath = resp.body().jsonPath(); + + List> netLists = jsonPath.getList(""); + assertFalse(netLists.isEmpty()); + boolean found = false; + for(Map entry : netLists) + { + if(entry.get("name").equals("PlatformTest")) + { + netListId = Long.parseLong(entry.get("netlistId").toString()); + found = true; + break; + } + } + assertTrue(found); + + // get schedule entry id + resp = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("schedulerefs") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract() + ; + + jsonPath = resp.body().jsonPath(); + assertNotNull(jsonPath); + List> scheduleEntries = jsonPath.getList(""); + assertNotNull(scheduleEntries); + scheduleId = DbKey.NullKey.getValue(); + + ScheduleEntryStatus scheduleEntryStatus = new ScheduleEntryStatus(DbKey.NullKey); + scheduleEntryStatus.setHostname("localhost"); + scheduleEntryStatus.setLastMessageTime(Date.from(Instant.parse("2021-01-02T00:00:00Z"))); + scheduleEntryStatus.setScheduleEntryName("Test Schedule Entry"); + scheduleEntryStatus.setNumMessages(12); + scheduleEntryStatus.setRunStart(Date.from(Instant.parse("2021-01-01T00:00:00Z"))); + scheduleEntryStatus.setRunStop(Date.from(Instant.parse("2021-01-02T00:00:00Z"))); + scheduleEntryStatus.setRunStatus("Test Status"); + scheduleEntryStatus.setLastModified(Date.from(Instant.parse("2021-01-03T00:00:00Z"))); + + for(Map entry : scheduleEntries) + { + if(entry.get("name").equals(scheduleEntryStatus.getScheduleEntryName())) + { + scheduleId = Long.parseLong(entry.get("schedEntryId").toString()); + break; + } + } + + scheduleEntryStatus.setScheduleEntryId(DbKey.createDbKey(scheduleId)); + + // Store schedule entry status via extension, since no endpoint for this exists + // and the DbImport class does not accept the ScheduleEntryStatus object + DatabaseSetupExtension.storeScheduleEntryStatus(scheduleEntryStatus); + } + + String siteJson = getJsonFromResource("platform_insert_data.json"); + assertNotNull(siteJson); + + siteId = storeSite("platform_site_data.json"); + assertNotNull(siteId); + + String platformJson = siteJson.replace("\"[SITE_ID]\"", siteId.toString()); + + ExtractableResponse response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .contentType(MediaType.APPLICATION_JSON) + .filter(sessionFilter) + .body(platformJson) + .when() + .redirects().follow(true) + .redirects().max(3) + .post("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_CREATED)) + .extract() + ; + + platformId = response.body().jsonPath().getLong("platformId"); + + if (dataLoaded == null || !dataLoaded) + { + PlatformStatus status = new PlatformStatus(DbKey.createDbKey(platformId)); + status.setSiteName("Platform 10"); + status.setLastRoutingSpecName("TestRoutingSpec"); + status.setLastScheduleEntryStatusId(DbKey.createDbKey(scheduleId)); + status.setLastErrorTime(Date.from(Instant.parse("2021-01-03T00:00:00Z"))); + status.setLastMessageTime(Date.from(Instant.parse("2021-01-02T00:00:00Z"))); + status.setAnnotation("Test Annotation"); + status.setLastContactTime(Date.from(Instant.parse("2021-01-01T00:00:00Z"))); + status.setLastMessageTime(Date.from(Instant.parse("2021-01-02T00:00:00Z"))); + + DatabaseSetupExtension.storePlatformStatus(status); + dataLoaded = true; + } + } + + @AfterEach + void tearDown() + { + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .queryParam("platformid", platformId) + .filter(sessionFilter) + .when() + .redirects().follow(true) + .redirects().max(3) + .delete("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + ; + + tearDownSite(siteId); + + logout(sessionFilter); + } + + @TestTemplate + void testGetPlatFormRefs() + { + JsonPath expected = getJsonPathFromResource("platform_get_refs_expected.json"); + + // Retrieve all platforms + ExtractableResponse response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platformrefs") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract() + ; + + JsonPath actual = response.body().jsonPath(); + assertNotNull(actual); + Map actualMap = actual.getMap(""); + actualMap = (Map) actualMap.get(expected.getString("name")); // Name of platform is not stored in Platform object, could cause issues with collision + assertEquals(expected.get("description"), actualMap.get("description")); + assertEquals(expected.get("agency"), actualMap.get("agency")); + assertEquals(expected.get("designator"), actualMap.get("designator")); + assertEquals(expected.get("production"), actualMap.get("production")); + assertEquals(expected.get("configId"), actualMap.get("configId")); + + // Retrieve with a tmtype filter + response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .queryParam("tmtype", "goes") + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platformrefs") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract() + ; + + actual = response.body().jsonPath(); + actualMap = actual.getMap(""); + actualMap = (Map) actualMap.get(expected.getString("name")); // Name of platform is not stored in Platform object, could cause issues with collision + assertEquals(expected.get("description"), actualMap.get("description")); + assertEquals(expected.get("agency"), actualMap.get("agency")); + assertEquals(expected.get("designator"), actualMap.get("designator")); + assertEquals(expected.get("production"), actualMap.get("production")); + assertEquals(expected.get("configId"), actualMap.get("configId")); + + // Retrieve with an invalid tmtype to check filtering + response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .queryParam("tmtype", "NOT_VALID") + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platformrefs") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract() + ; + + actual = response.body().jsonPath(); + assertNotNull(actual); + assertEquals(0, ((Map) actual.get("")).size()); + } + + @TestTemplate + void testGetPlatform() + { + JsonPath expected = getJsonPathFromResource("platform_get_expected.json"); + + ExtractableResponse response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .queryParam("platformid", platformId) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract() + ; + + JsonPath actual = response.body().jsonPath(); + assertNotNull(actual.getString("")); + assertEquals(expected.getString("name"), actual.getString("name")); + assertEquals(expected.getString("description"), actual.getString("description")); + assertEquals(expected.getString("agency"), actual.getString("agency")); + assertEquals(expected.getString("designator"), actual.getString("designator")); + assertEquals(expected.getString("production"), actual.getString("production")); + assertEquals(expected.getString("properties"), actual.getString("properties")); + } + + @TestTemplate + void testPostAndDeletePlatform() throws Exception + { + String platformJson = getJsonFromResource("platform_post_delete_insert_data.json"); + Long newSiteId = storeSite("platform_site_post_delete_data.json"); + assertNotNull(newSiteId); + platformJson = platformJson.replace("\"[SITE_ID]\"", newSiteId.toString()); + + // Create a new platform + ExtractableResponse response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .contentType(MediaType.APPLICATION_JSON) + .filter(sessionFilter) + .body(platformJson) + .when() + .redirects().follow(true) + .redirects().max(3) + .post("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_CREATED)) + .extract() + ; + + // Get platform ID and load expected JSON + Long newPlatformId = response.body().jsonPath().getLong("platformId"); + JsonPath expected = getJsonPathFromResource("platform_post_delete_expected.json"); + + // Get the platform and assert it matches expected JSON values + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .queryParam("platformid", newPlatformId) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .body("name", equalTo(expected.get("name"))) + .body("description", equalTo(expected.get("description"))) + .body("agency", equalTo(expected.get("agency"))) + .body("platformType", equalTo(expected.get("platformType"))) + .body("designator", equalTo(expected.get("designator"))) + .body("production", equalTo(expected.get("production"))) + .body("properties", equalTo(expected.get("properties"))) + ; + + // Delete the platform + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .queryParam("platformid", newPlatformId) + .filter(sessionFilter) + .when() + .redirects().follow(true) + .redirects().max(3) + .delete("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + ; + + // Assert the platform no longer exists + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .queryParam("platformid", newPlatformId) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platform") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_NOT_FOUND)) + ; + } + + @TestTemplate + void testGetPlatformStats() + { + JsonPath expected = getJsonPathFromResource("platform_get_stats_expected.json"); + assertNotNull(expected.getString("")); + + ExtractableResponse response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .filter(sessionFilter) + .queryParam("netlistid", netListId) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("platformstat") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract() + ; + + JsonPath actual = response.body().jsonPath(); + List> actualList = actual.getList(""); + List> expectedList = expected.getList(""); + Map expectedItem = expectedList.get(0); + assertNotNull(actualList); + boolean found = false; + for (Map entry : actualList) + { + if (entry.get("platformName").equals(expectedItem.get("platformName"))) + { + assertEquals(expectedItem.get("routingSpecName"), entry.get("routingSpecName")); + assertEquals(expectedItem.get("lastError"), entry.get("lastError")); + assertEquals(expectedItem.get("lastMessage"), entry.get("lastMessage")); + assertEquals(expectedItem.get("annotation"), entry.get("annotation")); + assertEquals(expectedItem.get("lastContact"), entry.get("lastContact")); + found = true; + } + } + assertTrue(found); + } + + private Long storeSite(String jsonPath) throws Exception + { + assertNotNull(jsonPath); + String siteJson = getJsonFromResource(jsonPath); + assertNotNull(siteJson); + + ExtractableResponse response = given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .contentType(MediaType.APPLICATION_JSON) + .filter(sessionFilter) + .body(siteJson) + .when() + .redirects().follow(true) + .redirects().max(3) + .post("site") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .extract() + ; + + return response.body().jsonPath().getLong("siteId"); + } + + private void tearDownSite(Long siteId) + { + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .queryParam("siteid", siteId) + .filter(sessionFilter) + .when() + .redirects().follow(true) + .redirects().max(3) + .delete("site") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + ; + + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(MediaType.APPLICATION_JSON) + .header("Authorization", authHeader) + .queryParam("siteid", siteId) + .filter(sessionFilter) + .when() + .redirects().follow(true) + .redirects().max(3) + .get("site") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_NOT_FOUND)) + ; + } +} diff --git a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/SiteResourcesIT.java b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/SiteResourcesIT.java index c0fb86e15..d5e44e307 100644 --- a/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/SiteResourcesIT.java +++ b/opendcs-rest-api/src/test/java/org/opendcs/odcsapi/res/it/SiteResourcesIT.java @@ -15,6 +15,7 @@ package org.opendcs.odcsapi.res.it; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.core.MediaType; @@ -35,12 +36,12 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@Tag("integration") +@Tag("integration-opentsdb-only") @ExtendWith(DatabaseContextProvider.class) final class SiteResourcesIT extends BaseIT { @@ -106,7 +107,7 @@ void testGetSiteRefs() { JsonPath expected = getJsonPathFromResource("site_get_refs_expected.json"); - given() + ExtractableResponse response = given() .log().ifValidationFails(LogDetail.ALL, true) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) @@ -120,11 +121,22 @@ void testGetSiteRefs() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_OK)) - .body("size()", greaterThan(0)) - .body("sitenames", equalTo(expected.get("sitenames"))) - .body("public-name", equalTo(expected.get("public-name"))) - .body("description", equalTo(expected.get("description"))) - ; + .extract(); + + JsonPath actual = response.body().jsonPath(); + List> actualSites = actual.getList(""); + + boolean found = false; + for (Map site : actualSites) + { + if (site.get("publicName").equals(expected.get("publicName"))) + { + assertEquals(expected.get("sitenames"), site.get("sitenames")); + assertEquals(expected.get("description"), site.get("description")); + found = true; + } + } + assertTrue(found); } @TestTemplate diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/netlist_platform_insert_data.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/netlist_platform_insert_data.json index 4ddfe7264..5c2d838f9 100644 --- a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/netlist_platform_insert_data.json +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/netlist_platform_insert_data.json @@ -2,11 +2,11 @@ "platformId" : null, "name" : "Stream Platform", "siteId" : null, - "agency" : null, + "agency" : "USACE", "configId" : null, "description" : "Test Platform Description", - "designator" : null, - "lastModified" : null, + "designator" : "Platform", + "lastModified" : 1738362018, "production" : false, "properties" : { }, "platformSensors" : [ ], diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/odcsapi_platform_dto.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/odcsapi_platform_dto.json index f4b32b0c2..622f2885c 100644 --- a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/odcsapi_platform_dto.json +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/odcsapi_platform_dto.json @@ -2,11 +2,11 @@ "platformId" : null, "name" : "Platform1", "siteId" : null, - "agency" : null, + "agency" : "USACE", "configId" : null, "description" : "A test platform", - "designator" : null, - "lastModified" : null, + "designator" : "Plat", + "lastModified" : 1625140800000, "production" : false, "properties" : { }, "platformSensors" : [ ], @@ -15,9 +15,9 @@ "mediumId" : "15823", "scriptName" : "script1", "channelNum" : 142, - "assignedTime" : null, - "transportWindow" : null, - "transportInterval" : null, + "assignedTime" : 1738355857, + "transportWindow" : 400, + "transportInterval" : 20, "timeAdjustment" : 0, "timezone" : "UTC", "loggerType" : "Simple", diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_datasource_insert.xml b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_datasource_insert.xml new file mode 100644 index 000000000..cb6560d56 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_datasource_insert.xml @@ -0,0 +1,3 @@ + + TestDataSourceArg + \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_expected.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_expected.json new file mode 100644 index 000000000..8930313d7 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_expected.json @@ -0,0 +1,14 @@ +{ + "platformId": 4, + "name": "Platform 10", + "siteId": -1, + "agency": "USGS", + "configId": 33565, + "description": "Platform 10 description", + "designator": "Platform Designator", + "lastModified": 1625140800000, + "production": true, + "properties": {}, + "platformSensors": [], + "transportMedia": [] +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_refs_expected.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_refs_expected.json new file mode 100644 index 000000000..1ab1694c3 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_refs_expected.json @@ -0,0 +1,11 @@ +{ + "platformId" : null, + "name" : "Platform 10", + "siteId" : "[SITE_ID]", + "agency" : "USGS", + "configId" : -1, + "config": null, + "description" : "Platform 10 description", + "designator" : "Platform Designator", + "transportMedia" : [ ] +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_stats_expected.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_stats_expected.json new file mode 100644 index 000000000..5ab67155e --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_get_stats_expected.json @@ -0,0 +1,14 @@ +[ + { + "platformId": 1, + "platformName": "Platform 10", + "siteId": 1, + "lastContact": "2021-01-01T00:00:00.000Z[UTC]", + "lastMessage": "2021-01-02T00:00:00.000Z[UTC]", + "lastError": "2021-01-03T00:00:00.000Z[UTC]", + "lastMsgQuality": null, + "annotation": "Test Annotation", + "lastRoutingExecId": 1, + "routingSpecName": "TestRoutingSpec" + } +] \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_insert_data.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_insert_data.json new file mode 100644 index 000000000..fb4de6420 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_insert_data.json @@ -0,0 +1,32 @@ +{ + "platformId" : null, + "name" : "Platform 10", + "siteId" : "[SITE_ID]", + "agency" : "USGS", + "configId" : null, + "description" : "Platform 10 description", + "designator" : "Platform Designator", + "lastModified" : 1625140800000, + "production" : true, + "properties" : { }, + "platformSensors" : [ ], + "transportMedia" : [ { + "mediumType" : "goes", + "mediumId" : "Ident", + "scriptName" : "Script", + "channelNum" : 1, + "assignedTime" : 123456789, + "transportWindow" : 2, + "transportInterval" : 1, + "timeAdjustment" : 0, + "timezone" : "UTC", + "loggerType" : null, + "baud" : 9600, + "stopBits" : 1, + "parity" : "None", + "dataBits" : 8, + "doLogin" : false, + "username" : "User", + "password" : "Pass" + } ] +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_netlist_insert.xml b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_netlist_insert.xml new file mode 100644 index 000000000..8c5f60fa4 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_netlist_insert.xml @@ -0,0 +1,8 @@ + + GOES + TEST + + Platform 10 + Platform 10 description + + \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_post_delete_expected.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_post_delete_expected.json new file mode 100644 index 000000000..5b1c22a2b --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_post_delete_expected.json @@ -0,0 +1,14 @@ +{ + "platformId": 2, + "name": "Platform 20", + "siteId": null, + "agency": "USGS", + "configId": 816816, + "description": "Platform 20", + "designator": "Platform Designator", + "lastModified": 1625141800000, + "production": true, + "properties": {}, + "platformSensors": [], + "transportMedia": [] +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_post_delete_insert_data.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_post_delete_insert_data.json new file mode 100644 index 000000000..56944875c --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_post_delete_insert_data.json @@ -0,0 +1,14 @@ +{ + "platformId" : null, + "name" : "Platform 20", + "siteId" : "[SITE_ID]", + "agency" : "USGS", + "configId" : null, + "description" : "Platform 20", + "designator" : "Platform Designator", + "lastModified" : 1625141800000, + "production" : true, + "properties" : { }, + "platformSensors" : [ ], + "transportMedia" : [ ] +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_routingspec_insert.xml b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_routingspec_insert.xml new file mode 100644 index 000000000..1c7b72795 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_routingspec_insert.xml @@ -0,0 +1,12 @@ + + false + + TestDataSourceArg + + false + false + UTC + file + 2024-08-09T12:45:00Z + 2024-08-10T12:45:00Z + \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_schedule_entry_insert.xml b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_schedule_entry_insert.xml new file mode 100644 index 000000000..7dfc96486 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_schedule_entry_insert.xml @@ -0,0 +1,6 @@ + + TestRoutingSpec + true + UTC + 01/28/2025 01:01:58 + diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_site_data.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_site_data.json new file mode 100644 index 000000000..1e7da6ed9 --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_site_data.json @@ -0,0 +1,23 @@ +{ + "siteId": null, + "description": "a platform site", + "latitude": "38.0", + "longitude": "-121.0", + "elevation": 100.0, + "elevUnits": "m", + "state": "CA", + "country": "USA", + "nearestCity": "Sacramento", + "timezone": "PST", + "region": "Yolo County", + "active": true, + "properties": { + "prop1": "value1" + }, + "publicName": "Platform 10", + "locationType": "stream", + "lastModified": 1625140800000, + "sitenames": { + "stream": "Platform 10" + } +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_site_post_delete_data.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_site_post_delete_data.json new file mode 100644 index 000000000..f5b5ef91a --- /dev/null +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/platform_site_post_delete_data.json @@ -0,0 +1,23 @@ +{ + "siteId": null, + "description": "Platform 20 location", + "latitude": "39.0", + "longitude": "-122.0", + "elevation": 200.0, + "elevUnits": "m", + "state": "CA", + "country": "USA", + "nearestCity": "Sacramento", + "timezone": "PST", + "region": "Yolo County", + "active": true, + "properties": { + "prop2": "value2" + }, + "publicName": "Platform 20", + "locationType": "river", + "lastModified": 1625141800000, + "sitenames": { + "stream": "Platform 20" + } +} \ No newline at end of file diff --git a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/site_get_refs_expected.json b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/site_get_refs_expected.json index 7ce5472db..f98d22993 100644 --- a/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/site_get_refs_expected.json +++ b/opendcs-rest-api/src/test/resources/org/opendcs/odcsapi/res/it/OPEN_TSDB/site_get_refs_expected.json @@ -1,11 +1,9 @@ -[ +{ + "siteId": 4, + "sitenames": { - "siteId": 4, - "sitenames": - { - "PUMP": "Pump Site" - }, - "publicName": "Pump Site", - "description": "Pump located in NM, USA" - } -] \ No newline at end of file + "PUMP": "Pump Site" + }, + "publicName": "Pump Site", + "description": "Pump located in NM, USA" +} \ No newline at end of file