Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# The following file will be copied to a unix Docker image and imported to InfluxDB data base. Therefore, the line
# ending plays a crucial role. This prevents the endings from being adjusted with 'core.autocrlf=true'
src/test/resources/testContainerFiles/influxDb/weather.txt eol=lf
src/test/resources/edu/ie3/datamodel/io/source/influxDb/weather/weather.txt eol=lf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package edu.ie3.datamodel.io.connectors

import edu.ie3.test.helper.TestContainerHelper
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.spock.Testcontainers
import org.testcontainers.utility.MountableFile
Expand All @@ -14,7 +15,7 @@ import spock.lang.Specification
import java.sql.SQLException

@Testcontainers
class SqlConnectorIT extends Specification {
class SqlConnectorIT extends Specification implements TestContainerHelper {
@Shared
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.9")

Expand All @@ -23,7 +24,7 @@ class SqlConnectorIT extends Specification {

def setupSpec() {
// Copy sql import script into docker
MountableFile sqlImportFile = MountableFile.forClasspathResource("/testcontainersFiles/sql/connector/connectorTest.sql")
MountableFile sqlImportFile = getMountableFile("sql/connectorTest.sql")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/connectorTest.sql")
// Execute import script
postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/connectorTest.sql")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
import edu.ie3.datamodel.models.value.WeatherValue
import edu.ie3.test.common.PsdmWeatherTestData
import edu.ie3.test.helper.TestContainerHelper
import edu.ie3.test.helper.WeatherSourceTestHelper
import edu.ie3.util.TimeUtil
import edu.ie3.util.interval.ClosedInterval
Expand All @@ -25,13 +26,14 @@ import spock.lang.Specification
import java.time.ZoneId

@Testcontainers
class CouchbaseWeatherSourcePsdmIT extends Specification implements WeatherSourceTestHelper {
class CouchbaseWeatherSourcePsdmIT extends Specification implements TestContainerHelper, WeatherSourceTestHelper {

@Shared
BucketDefinition bucketDefinition = new BucketDefinition("ie3_in")

@Shared
CouchbaseContainer couchbaseContainer = new CouchbaseContainer("couchbase/server:latest").withBucket(bucketDefinition)
CouchbaseContainer couchbaseContainer = new CouchbaseContainer("couchbase/server:latest")
.withBucket(bucketDefinition)
.withExposedPorts(8091, 8092, 8093, 8094, 11210)

@Shared
Expand All @@ -41,7 +43,7 @@ class CouchbaseWeatherSourcePsdmIT extends Specification implements WeatherSourc

def setupSpec() {
// Copy import file with json array of documents into docker
MountableFile couchbaseWeatherJsonsFile = MountableFile.forClasspathResource("/testcontainersFiles/couchbase/weather.json")
MountableFile couchbaseWeatherJsonsFile = getMountableFile("weather/weather.json")
couchbaseContainer.copyFileToContainer(couchbaseWeatherJsonsFile, "/home/weather.json")

// create an index for the document keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CosmoCsvIdCoordinateSourceIT extends Specification implements CsvTestDataM
CsvIdCoordinateSource source

def setupSpec() {
source = new CsvIdCoordinateSource(csvSep, coordinatesFolderPath + "_cosmo", fileNamingStrategy, new CosmoIdCoordinateFactory())
source = new CsvIdCoordinateSource(csvSep, coordinatesCosmoFolderPath, fileNamingStrategy, new CosmoIdCoordinateFactory())
}

def "The CsvCoordinateSource is able to create a valid stream from a coordinate file"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ class CsvDataSourceTest extends Specification {

@Shared
String csvSep = ","
String testBaseFolderPath = new File(getClass().getResource('/testGridFiles').toURI()).getAbsolutePath()
@Shared
String testBaseFolderPath = "testBaseFolderPath" // does not have to exist for this test
@Shared
FileNamingStrategy fileNamingStrategy = new FileNamingStrategy()

@Shared
DummyCsvSource dummyCsvSource = new DummyCsvSource(csvSep, testBaseFolderPath, fileNamingStrategy)

def "A csv data source is able to find the correct first entity by uuid"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CsvGraphicSourceTest extends Specification implements CsvTestDataMeta {
def "A CsvGraphicSource should provide an instance of GraphicElements based on valid input data correctly"() {
given:
def typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
def rawGridSource = new CsvRawGridSource(csvSep, gridFolderPath, fileNamingStrategy, typeSource)
def rawGridSource = new CsvRawGridSource(csvSep, gridDefaultFolderPath, fileNamingStrategy, typeSource)
def csvGraphicSource = new CsvGraphicSource(csvSep, graphicsFolderPath, fileNamingStrategy, typeSource, rawGridSource)

when:
Expand All @@ -40,7 +40,7 @@ class CsvGraphicSourceTest extends Specification implements CsvTestDataMeta {
given:
def typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
def rawGridSource =
new CsvRawGridSource(csvSep, gridFolderPath, fileNamingStrategy, typeSource) {
new CsvRawGridSource(csvSep, gridDefaultFolderPath, fileNamingStrategy, typeSource) {
@Override
Set<NodeInput> getNodes() {
return Collections.emptySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CsvRawGridSourceTest extends Specification implements CsvTestDataMeta {

def setupSpec() {
CsvTypeSource typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
source = new CsvRawGridSource(csvSep, gridFolderPath, fileNamingStrategy, typeSource)
source = new CsvRawGridSource(csvSep, gridDefaultFolderPath, fileNamingStrategy, typeSource)
}

def "The CsvRawGridSource is able to convert single valid AssetInputEntityData to ConnectorInputEntityData"() {
Expand Down Expand Up @@ -742,7 +742,7 @@ class CsvRawGridSourceTest extends Specification implements CsvTestDataMeta {
def "The CsvRawGridSource returns an empty Optional, if one mandatory element for the RawGridElements is missing"() {
given: "a source pointing to malformed grid data"
CsvTypeSource typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
source = new CsvRawGridSource(csvSep, gridFolderPath + "_malformed", fileNamingStrategy, typeSource)
source = new CsvRawGridSource(csvSep, gridMalformedFolderPath, fileNamingStrategy, typeSource)

when: "loading a total grid structure from file"
def actual = source.getGridData()
Expand All @@ -754,7 +754,7 @@ class CsvRawGridSourceTest extends Specification implements CsvTestDataMeta {
def "The CsvRawGridSource returns an empty Optional, if the RawGridElements contain no single element"() {
given: "a source pointing to malformed grid data"
CsvTypeSource typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
source = new CsvRawGridSource(csvSep, gridFolderPath + "_empty", fileNamingStrategy, typeSource)
source = new CsvRawGridSource(csvSep, gridEmptyFolderPath, fileNamingStrategy, typeSource)

when: "loading a total grid structure from file"
def actual = source.getGridData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
given:
def typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
def thermalSource = new CsvThermalSource(csvSep, participantsFolderPath, fileNamingStrategy, typeSource)
def rawGridSource = new CsvRawGridSource(csvSep, gridFolderPath, fileNamingStrategy, typeSource)
def rawGridSource = new CsvRawGridSource(csvSep, gridDefaultFolderPath, fileNamingStrategy, typeSource)
def csvSystemParticipantSource = new CsvSystemParticipantSource(csvSep,
participantsFolderPath, fileNamingStrategy, typeSource,
thermalSource, rawGridSource)
Expand Down Expand Up @@ -63,10 +63,10 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
def typeSource = new CsvTypeSource(csvSep, typeFolderPath, fileNamingStrategy)
def thermalSource = new CsvThermalSource(csvSep, participantsFolderPath, fileNamingStrategy, typeSource)
def rawGridSource = Spy(CsvRawGridSource, constructorArgs: [
csvSep,
gridFolderPath,
fileNamingStrategy,
typeSource
csvSep,
gridDefaultFolderPath,
fileNamingStrategy,
typeSource
]) {
// partly fake the return method of the csv raw grid source to always return empty node sets
// -> elements to build NodeGraphicInputs are missing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ package edu.ie3.datamodel.io.source.csv

import edu.ie3.datamodel.io.naming.FileNamingStrategy

import java.nio.file.Paths

/**
* Holds meta data for csv tests e.g. file and folder paths
*/
trait CsvTestDataMeta {

static String testParticipantsBaseFolderPath = new File(CsvTestDataMeta.getResource('/testGridFiles').toURI()).absolutePath
static String testTimeSeriesBaseFolderPath = new File(CsvTestDataMeta.getResource('/testTimeSeriesFiles').toURI()).absolutePath
static String graphicsFolderPath = testParticipantsBaseFolderPath.concat(File.separator).concat("graphics")
static String typeFolderPath = testParticipantsBaseFolderPath.concat(File.separator).concat("types")
static String gridFolderPath = testParticipantsBaseFolderPath.concat(File.separator).concat("grid")
static String participantsFolderPath = testParticipantsBaseFolderPath.concat(File.separator).concat("participants")
static String resultEntitiesFolderPath = testParticipantsBaseFolderPath.concat(File.separator).concat("results")
static String timeSeriesFolderPath = testTimeSeriesBaseFolderPath
static String thermalFolderPath = testParticipantsBaseFolderPath.concat(File.separator).concat("thermal")
static String coordinatesFolderPath = testParticipantsBaseFolderPath.concat(File.separator).concat("coordinates")
static String timeSeriesFolderPath = getResourceAbs("timeseries")
static String graphicsFolderPath = getResourceAbs("graphics")
static String typeFolderPath = getResourceAbs("types")
static String participantsFolderPath = getResourceAbs("participants")
static String resultEntitiesFolderPath = getResourceAbs("results")
static String thermalFolderPath = getResourceAbs("thermal")
static String coordinatesIconFolderPath = getResourceAbs("coordinates_icon")
static String coordinatesCosmoFolderPath = getResourceAbs("coordinates_cosmo")

static String gridDefaultFolderPath = getResourceAbs("grid/grid_default")
static String gridMalformedFolderPath = getResourceAbs("grid/grid_malformed")
static String gridEmptyFolderPath = getResourceAbs("grid/grid_empty")

static String csvSep = ","
static FileNamingStrategy fileNamingStrategy = new FileNamingStrategy()

static String getResourceAbs(String directory) {
return Paths.get(CsvTestDataMeta.getResource(directory).toURI()).toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CsvWeatherSourceIconTest extends Specification implements CsvTestDataMeta,
def setupSpec() {
coordinateSource = WeatherTestData.coordinateSource
def weatherFactory = new IconTimeBasedWeatherValueFactory()
folderPath = new File(getClass().getResource('/weather/icon').toURI()).absolutePath
folderPath = new File(getClass().getResource('weather/icon').toURI()).absolutePath
source = new CsvWeatherSource(",", folderPath, new FileNamingStrategy(), coordinateSource, weatherFactory)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IconCsvIdCoordinateSourceIT extends Specification implements CsvTestDataMe
CsvIdCoordinateSource source

def setupSpec() {
source = new CsvIdCoordinateSource(csvSep, coordinatesFolderPath + "_icon", fileNamingStrategy, new IconIdCoordinateFactory())
source = new CsvIdCoordinateSource(csvSep, coordinatesIconFolderPath, fileNamingStrategy, new IconIdCoordinateFactory())
}

def "The CsvCoordinateSource is able to create a valid stream from a coordinate file"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
import edu.ie3.datamodel.models.value.WeatherValue
import edu.ie3.test.common.PsdmWeatherTestData
import edu.ie3.test.helper.TestContainerHelper
import edu.ie3.test.helper.WeatherSourceTestHelper
import edu.ie3.util.geo.GeoUtils
import edu.ie3.util.interval.ClosedInterval
import org.locationtech.jts.geom.Point
import org.testcontainers.containers.InfluxDBContainer
import org.testcontainers.spock.Testcontainers
import org.testcontainers.utility.DockerImageName
import org.testcontainers.utility.MountableFile
import spock.lang.Shared
import spock.lang.Specification

@Testcontainers
class InfluxDbWeatherSourcePsdmIT extends Specification implements WeatherSourceTestHelper {
class InfluxDbWeatherSourcePsdmIT extends Specification implements TestContainerHelper, WeatherSourceTestHelper {

@Shared
InfluxDBContainer influxDbContainer = new InfluxDBContainer("1.8.4")
InfluxDBContainer influxDbContainer = new InfluxDBContainer(DockerImageName.parse("influxdb").withTag("1.8.4"))
.withAuthEnabled(false)
.withDatabase("test_weather")

Expand All @@ -35,7 +37,7 @@ class InfluxDbWeatherSourcePsdmIT extends Specification implements WeatherSource
def setupSpec() {
// Copy import file into docker and then import it via influx CLI
// more information on file format and usage here: https://docs.influxdata.com/influxdb/v1.7/tools/shell/#import-data-from-a-file-with-import
MountableFile influxWeatherImportFile = MountableFile.forClasspathResource("/testcontainersFiles/influxDb/weather.txt")
MountableFile influxWeatherImportFile = getMountableFile("weather/weather.txt")
influxDbContainer.copyFileToContainer(influxWeatherImportFile, "/home/weather.txt")
def execResult = influxDbContainer.execInContainer("influx", "-import", "-path=/home/weather.txt", "-precision=ms")
println "Command \"influx -import -path=/home/weather.txt -precision=ms\" returned:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ import edu.ie3.datamodel.io.connectors.SqlConnector
import edu.ie3.datamodel.io.csv.timeseries.ColumnScheme
import edu.ie3.datamodel.io.csv.timeseries.IndividualTimeSeriesMetaInformation
import edu.ie3.datamodel.io.naming.EntityPersistenceNamingStrategy
import edu.ie3.test.helper.TestContainerHelper
import org.testcontainers.containers.Container
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.spock.Testcontainers
import org.testcontainers.utility.MountableFile
import spock.lang.Shared
import spock.lang.Specification

import java.nio.file.Path
import java.nio.file.Paths

@Testcontainers
class SqlTimeSeriesMappingSourceIT extends Specification {
class SqlTimeSeriesMappingSourceIT extends Specification implements TestContainerHelper {

@Shared
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.14")
Expand All @@ -29,12 +27,8 @@ class SqlTimeSeriesMappingSourceIT extends Specification {
SqlTimeSeriesMappingSource source

def setupSpec() {
URL url = getClass().getResource("timeseries/")
assert url != null
Path path = Paths.get(url.toURI())

// Copy sql import script into docker
MountableFile sqlImportFile = MountableFile.forHostPath(path)
MountableFile sqlImportFile = getMountableFile("timeseries/")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/")

// Execute import script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package edu.ie3.datamodel.io.source.sql

import edu.ie3.test.helper.TestContainerHelper

import static edu.ie3.test.common.TimeSeriesSourceTestData.*

import edu.ie3.datamodel.exceptions.SourceException
Expand All @@ -20,11 +22,8 @@ import org.testcontainers.utility.MountableFile
import spock.lang.Shared
import spock.lang.Specification

import java.nio.file.Path
import java.nio.file.Paths

@Testcontainers
class SqlTimeSeriesSourceIT extends Specification {
class SqlTimeSeriesSourceIT extends Specification implements TestContainerHelper {

@Shared
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.14")
Expand All @@ -41,12 +40,8 @@ class SqlTimeSeriesSourceIT extends Specification {
static UUID timeSeriesUuid = UUID.fromString("9185b8c1-86ba-4a16-8dea-5ac898e8caa5")

def setupSpec() {
URL url = getClass().getResource("timeseries/")
assert url != null
Path path = Paths.get(url.toURI())

// Copy sql import scripts into docker
MountableFile sqlImportFile = MountableFile.forHostPath(path)
MountableFile sqlImportFile = getMountableFile("timeseries/")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/")

// Execute import script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
import edu.ie3.datamodel.models.value.WeatherValue
import edu.ie3.test.common.IconWeatherTestData
import edu.ie3.test.helper.TestContainerHelper
import edu.ie3.test.helper.WeatherSourceTestHelper
import edu.ie3.util.TimeUtil
import edu.ie3.util.interval.ClosedInterval
Expand All @@ -23,7 +24,7 @@ import spock.lang.Shared
import spock.lang.Specification

@Testcontainers
class SqlWeatherSourceIconIT extends Specification implements WeatherSourceTestHelper {
class SqlWeatherSourceIconIT extends Specification implements TestContainerHelper, WeatherSourceTestHelper {

@Shared
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.14")
Expand All @@ -36,10 +37,10 @@ class SqlWeatherSourceIconIT extends Specification implements WeatherSourceTestH

def setupSpec() {
// Copy sql import script into docker
MountableFile sqlImportFile = MountableFile.forClasspathResource("/testcontainersFiles/sql/icon/weather.sql")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/weather.sql")
MountableFile sqlImportFile = getMountableFile("weather/weather_icon.sql")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/weather_icon.sql")
// Execute import script
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather.sql")
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather_icon.sql")
assert res.stderr.empty

def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
import edu.ie3.datamodel.models.value.WeatherValue
import edu.ie3.test.common.PsdmWeatherTestData
import edu.ie3.test.helper.TestContainerHelper
import edu.ie3.test.helper.WeatherSourceTestHelper
import edu.ie3.util.TimeUtil
import edu.ie3.util.geo.GeoUtils
Expand All @@ -24,7 +25,7 @@ import spock.lang.Shared
import spock.lang.Specification

@Testcontainers
class SqlWeatherSourcePsdmIT extends Specification implements WeatherSourceTestHelper {
class SqlWeatherSourcePsdmIT extends Specification implements TestContainerHelper, WeatherSourceTestHelper {

@Shared
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.14")
Expand All @@ -37,10 +38,10 @@ class SqlWeatherSourcePsdmIT extends Specification implements WeatherSourceTestH

def setupSpec() {
// Copy sql import script into docker
MountableFile sqlImportFile = MountableFile.forClasspathResource("/testcontainersFiles/sql/psdm/weather.sql")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/weather.sql")
MountableFile sqlImportFile = getMountableFile("weather/weather_psdm.sql")
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/weather_psdm.sql")
// Execute import script
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather.sql")
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather_psdm.sql")
assert res.stderr.empty

def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
Expand Down
Loading