diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java index 8ac4bc2a3a378ed660e4f39f3ae82b5f17e65092..9dbfc60604e9f28e711b1c55c4949633bc91d603 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java @@ -89,10 +89,8 @@ public class RecordSteps extends TestsBase { public void i_ingest_records_with_the_for_a_given(String record, String dataGroup, String kind) { String actualKind = generateActualName(kind, timeStamp); - File resourcesDirectory = new File("src/test/resources"); try { - String fileContent = FileHandler.readFile( - String.format("%s/testData/%s", resourcesDirectory.getAbsolutePath(), String.format("%s.%s", record, "json"))); + String fileContent = FileHandler.readFile(String.format("%s.%s", record, "json")); records = new Gson().fromJson(fileContent, new TypeToken<List<Map<String, Object>>>() {}.getType()); for (Map<String, Object> testRecord : records) { diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java index 7eb53519b98d0926f2ace54c62fec6a485fbed34..00ac7b1c9bd2fe9780c5d2f40baf761e8aa429c5 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java @@ -13,7 +13,6 @@ import org.opengroup.osdu.util.ElasticUtils; import org.opengroup.osdu.util.FileHandler; import org.opengroup.osdu.util.HTTPClient; -import java.io.File; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -84,10 +83,8 @@ public class TestIndex { } private List<Map<String, Object>> getRecordsFromTestFile() { - File resourcesDirectory = new File("src/test/resources"); - try { - String fileContent = FileHandler.readFile( - String.format("%s/testData/%s", resourcesDirectory.getAbsolutePath(), getRecordFile())); + try { + String fileContent = FileHandler.readFile(getRecordFile()); List<Map<String, Object>> records = new Gson().fromJson( fileContent, new TypeToken<List<Map<String,Object>>>() {}.getType()); @@ -105,10 +102,8 @@ public class TestIndex { } private String getIndexMappingFromJson() { - File resourcesDirectory = new File("src/test/resources"); try { - String fileContent = FileHandler.readFile( - String.format("%s/testData/%s", resourcesDirectory.getAbsolutePath(), getMappingFile())); + String fileContent = FileHandler.readFile(getMappingFile()); JsonElement json = gson.fromJson(fileContent, JsonElement.class); return gson.toJson(json); } catch (Exception e) { @@ -117,10 +112,8 @@ public class TestIndex { } private String getStorageSchemaFromJson() { - File resourcesDirectory = new File("src/test/resources"); try { - String fileContent = FileHandler.readFile( - String.format("%s/testData/%s", resourcesDirectory.getAbsolutePath(), getSchemaFile())); + String fileContent = FileHandler.readFile(getSchemaFile()); fileContent = fileContent.replaceAll("KIND_VAL", this.kind); JsonElement json = gson.fromJson(fileContent, JsonElement.class); return gson.toJson(json); diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/FileHandler.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/FileHandler.java index a9aa4fe89349565742387f26e3de16c0837a8ec1..678cb91204d3f786437090737dc9a29d1e1acfc7 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/FileHandler.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/FileHandler.java @@ -1,22 +1,24 @@ package org.opengroup.osdu.util; -import java.io.File; +import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.Scanner; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; public class FileHandler { - public static String readFile(String pathname) throws IOException { - - File file = new File(pathname); - StringBuilder fileContents = new StringBuilder((int) file.length()); - String lineSeparator = System.getProperty("line.separator"); - - try (Scanner scanner = new Scanner(file)) { - while (scanner.hasNextLine()) { - fileContents.append(scanner.nextLine()).append(lineSeparator); - } - return fileContents.toString(); + public static String readFile(String fileName) throws IOException { + InputStream inputStream = FileHandler.class.getClass().getResourceAsStream(String.format("/testData/%s",fileName)); + if(inputStream == null) { + throw new IOException(); + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, length); } + return outputStream.toString(StandardCharsets.UTF_8.toString()); } + } diff --git a/testing/indexer-test-gcp/src/test/resources/features/delete/Delete.feature b/testing/indexer-test-core/src/main/resources/features/delete/Delete.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/delete/Delete.feature rename to testing/indexer-test-core/src/main/resources/features/delete/Delete.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/indexrecord/IndexRecord.feature b/testing/indexer-test-core/src/main/resources/features/indexrecord/IndexRecord.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/indexrecord/IndexRecord.feature rename to testing/indexer-test-core/src/main/resources/features/indexrecord/IndexRecord.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/kindschema/KindSchema.feature b/testing/indexer-test-core/src/main/resources/features/kindschema/KindSchema.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/kindschema/KindSchema.feature rename to testing/indexer-test-core/src/main/resources/features/kindschema/KindSchema.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/query/crosscluster/Query.feature b/testing/indexer-test-core/src/main/resources/features/query/crosscluster/Query.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/query/crosscluster/Query.feature rename to testing/indexer-test-core/src/main/resources/features/query/crosscluster/Query.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/query/singlecluster/Query.feature b/testing/indexer-test-core/src/main/resources/features/query/singlecluster/Query.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/query/singlecluster/Query.feature rename to testing/indexer-test-core/src/main/resources/features/query/singlecluster/Query.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/querybycursor/crosscluster/QueryByCursor.feature b/testing/indexer-test-core/src/main/resources/features/querybycursor/crosscluster/QueryByCursor.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/querybycursor/crosscluster/QueryByCursor.feature rename to testing/indexer-test-core/src/main/resources/features/querybycursor/crosscluster/QueryByCursor.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/querybycursor/singlecluster/QueryByCursor.feature b/testing/indexer-test-core/src/main/resources/features/querybycursor/singlecluster/QueryByCursor.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/querybycursor/singlecluster/QueryByCursor.feature rename to testing/indexer-test-core/src/main/resources/features/querybycursor/singlecluster/QueryByCursor.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/smart/parser/SmartParser.feature b/testing/indexer-test-core/src/main/resources/features/smart/parser/SmartParser.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/smart/parser/SmartParser.feature rename to testing/indexer-test-core/src/main/resources/features/smart/parser/SmartParser.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/smart/search/Smart.feature b/testing/indexer-test-core/src/main/resources/features/smart/search/Smart.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/smart/search/Smart.feature rename to testing/indexer-test-core/src/main/resources/features/smart/search/Smart.feature diff --git a/testing/indexer-test-gcp/src/test/resources/features/updateindex/UpdateIndexMapping.feature b/testing/indexer-test-core/src/main/resources/features/updateindex/UpdateIndexMapping.feature similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/features/updateindex/UpdateIndexMapping.feature rename to testing/indexer-test-core/src/main/resources/features/updateindex/UpdateIndexMapping.feature diff --git a/testing/indexer-test-gcp/src/test/resources/testData/index_records_1.json b/testing/indexer-test-core/src/main/resources/testData/index_records_1.json similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/index_records_1.json rename to testing/indexer-test-core/src/main/resources/testData/index_records_1.json diff --git a/testing/indexer-test-gcp/src/test/resources/testData/index_records_1.schema b/testing/indexer-test-core/src/main/resources/testData/index_records_1.schema similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/index_records_1.schema rename to testing/indexer-test-core/src/main/resources/testData/index_records_1.schema diff --git a/testing/indexer-test-gcp/src/test/resources/testData/index_records_2.json b/testing/indexer-test-core/src/main/resources/testData/index_records_2.json similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/index_records_2.json rename to testing/indexer-test-core/src/main/resources/testData/index_records_2.json diff --git a/testing/indexer-test-gcp/src/test/resources/testData/index_records_2.schema b/testing/indexer-test-core/src/main/resources/testData/index_records_2.schema similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/index_records_2.schema rename to testing/indexer-test-core/src/main/resources/testData/index_records_2.schema diff --git a/testing/indexer-test-gcp/src/test/resources/testData/records_1.json b/testing/indexer-test-core/src/main/resources/testData/records_1.json similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/records_1.json rename to testing/indexer-test-core/src/main/resources/testData/records_1.json diff --git a/testing/indexer-test-gcp/src/test/resources/testData/records_1.mapping b/testing/indexer-test-core/src/main/resources/testData/records_1.mapping similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/records_1.mapping rename to testing/indexer-test-core/src/main/resources/testData/records_1.mapping diff --git a/testing/indexer-test-gcp/src/test/resources/testData/records_2.json b/testing/indexer-test-core/src/main/resources/testData/records_2.json similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/records_2.json rename to testing/indexer-test-core/src/main/resources/testData/records_2.json diff --git a/testing/indexer-test-gcp/src/test/resources/testData/records_2.mapping b/testing/indexer-test-core/src/main/resources/testData/records_2.mapping similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/records_2.mapping rename to testing/indexer-test-core/src/main/resources/testData/records_2.mapping diff --git a/testing/indexer-test-gcp/src/test/resources/testData/records_3.json b/testing/indexer-test-core/src/main/resources/testData/records_3.json similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/records_3.json rename to testing/indexer-test-core/src/main/resources/testData/records_3.json diff --git a/testing/indexer-test-gcp/src/test/resources/testData/records_3.mapping b/testing/indexer-test-core/src/main/resources/testData/records_3.mapping similarity index 100% rename from testing/indexer-test-gcp/src/test/resources/testData/records_3.mapping rename to testing/indexer-test-core/src/main/resources/testData/records_3.mapping diff --git a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/deleteschema/RunTest.java b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/deleteschema/RunTest.java index 55dbb6bf06ff23f0f433dfa0c8609972d9b53a8f..b04eb1b3079df08037ce32ada4f8f007c941e410 100644 --- a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/deleteschema/RunTest.java +++ b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/deleteschema/RunTest.java @@ -6,7 +6,7 @@ import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( - features = "src/test/resources/features/delete/Delete.feature", + features = "classpath:features/delete/Delete.feature", glue={"classpath:org.opengroup.osdu.step_definitions/index/deleteschema"}, format = {"pretty", "junit:target/cucumber-reports/TEST-deleteschema.xml"}) public class RunTest { diff --git a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/getschema/RunTest.java b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/getschema/RunTest.java index b6c70e297122c166fd751bf90fbc522f1c94db80..b60b4a1c581517f89f6e0b447738847cb2f75872 100644 --- a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/getschema/RunTest.java +++ b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/getschema/RunTest.java @@ -7,7 +7,7 @@ import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( - features = "src/test/resources/features/kindschema/KindSchema.feature", + features = "classpath:features/kindschema/KindSchema.feature", glue = {"classpath:org.opengroup.osdu.step_definitions/index/getschema"}, format = {"pretty", "junit:target/cucumber-reports/TEST-getschema.xml"}) public class RunTest { diff --git a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/RunTest.java b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/RunTest.java index dc9fbcd3af4da3b8babd3beb58a0f0fd4c04cb4f..4978ddfccad197628432d4ccb8b5985b4af5017e 100644 --- a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/RunTest.java +++ b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/RunTest.java @@ -6,7 +6,7 @@ import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( - features = "src/test/resources/features/indexrecord/IndexRecord.feature", + features = "classpath:features/indexrecord/IndexRecord.feature", glue = {"classpath:org.opengroup.osdu.step_definitions/index/record"}, plugin = {"pretty", "junit:target/cucumber-reports/TEST-indexrecord.xml"}) public class RunTest {