-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/validation
# Conflicts: # backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/StubProjectionRunner.java # backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/StubHcsvProjectionEndpointTest.java
- Loading branch information
Showing
70 changed files
with
2,346 additions
and
3,649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
...src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/StubHcsvProjectionEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package ca.bc.gov.nrs.api.v1.endpoints; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import ca.bc.gov.nrs.api.helpers.TestHelper; | ||
import ca.bc.gov.nrs.vdyp.backend.v1.gen.api.ParameterNames; | ||
import ca.bc.gov.nrs.vdyp.backend.v1.gen.model.Parameters; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
@QuarkusTest | ||
class StubHcsvProjectionEndpointTest { | ||
|
||
private final TestHelper testHelper; | ||
|
||
@Inject | ||
StubHcsvProjectionEndpointTest(TestHelper testHelper) { | ||
this.testHelper = testHelper; | ||
} | ||
|
||
@BeforeEach | ||
void setup() { | ||
} | ||
|
||
@Test | ||
void testProjectionHscv_shouldReturnStatusOK() throws IOException { | ||
|
||
Path resourceFolderPath = Path.of("VDYP7Console-sample-files", "hcsv", "vdyp-240"); | ||
|
||
Parameters parameters = testHelper.addSelectedOptions( | ||
new Parameters(), // | ||
Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_DEBUG_LOGGING, | ||
Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_PROGRESS_LOGGING, | ||
Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_ERROR_LOGGING | ||
); | ||
|
||
// Included to generate JSON text of parameters as needed | ||
// ObjectMapper mapper = new ObjectMapper(); | ||
// String serializedParametersText = mapper.writeValueAsString(parameters); | ||
|
||
InputStream zipInputStream = given().basePath(TestHelper.ROOT_PATH).when() // | ||
.multiPart(ParameterNames.PROJECTION_PARAMETERS, parameters, MediaType.APPLICATION_JSON) // | ||
.multiPart( | ||
ParameterNames.POLYGON_INPUT_DATA, | ||
Files.readAllBytes(testHelper.getResourceFile(resourceFolderPath, "VDYP7_INPUT_POLY.csv")) | ||
) // | ||
.multiPart( | ||
ParameterNames.LAYERS_INPUT_DATA, | ||
Files.readAllBytes(testHelper.getResourceFile(resourceFolderPath, "VDYP7_INPUT_LAYER.csv")) | ||
) // | ||
.post("/projection/hcsv?trialRun=true") // | ||
.then().statusCode(201) // | ||
.and().contentType("application/octet-stream") // | ||
.and().header("content-disposition", Matchers.startsWith("attachment;filename=\"vdyp-output-")) // | ||
.extract().body().asInputStream(); | ||
|
||
ZipInputStream zipFile = new ZipInputStream(zipInputStream); | ||
ZipEntry entry1 = zipFile.getNextEntry(); | ||
assertEquals("YieldTable.csv", entry1.getName()); | ||
String entry1Content = new String(testHelper.readZipEntry(zipFile, entry1)); | ||
assertTrue(entry1Content.length() == 0); | ||
|
||
ZipEntry entry2 = zipFile.getNextEntry(); | ||
assertEquals("ProgressLog.txt", entry2.getName()); | ||
String entry2Content = new String(testHelper.readZipEntry(zipFile, entry2)); | ||
assertTrue(entry2Content.startsWith("Running Projection")); | ||
|
||
ZipEntry entry3 = zipFile.getNextEntry(); | ||
assertEquals("ErrorLog.txt", entry3.getName()); | ||
String entry3Content = new String(testHelper.readZipEntry(zipFile, entry3)); | ||
assertTrue(entry3Content.isBlank()); | ||
|
||
ZipEntry entry4 = zipFile.getNextEntry(); | ||
assertEquals("DebugLog.txt", entry4.getName()); | ||
String entry4Content = new String(testHelper.readZipEntry(zipFile, entry4)); | ||
assertTrue(entry4Content.startsWith(LocalDate.now().format(DateTimeFormatter.ISO_DATE))); | ||
} | ||
|
||
@Test | ||
void testProjectionHscv_testNoProgressLogging() throws IOException { | ||
|
||
Path resourceFolderPath = Path.of("VDYP7Console-sample-files", "hcsv", "vdyp-240"); | ||
|
||
Parameters parameters = new Parameters(); | ||
|
||
InputStream zipInputStream = given().basePath(TestHelper.ROOT_PATH).when() // | ||
.multiPart(ParameterNames.PROJECTION_PARAMETERS, parameters, MediaType.APPLICATION_JSON) // | ||
.multiPart( | ||
ParameterNames.POLYGON_INPUT_DATA, | ||
Files.readAllBytes(testHelper.getResourceFile(resourceFolderPath, "VDYP7_INPUT_POLY.csv")) | ||
) // | ||
.multiPart( | ||
ParameterNames.LAYERS_INPUT_DATA, | ||
Files.readAllBytes(testHelper.getResourceFile(resourceFolderPath, "VDYP7_INPUT_LAYER.csv")) | ||
) // | ||
.post("/projection/hcsv?trialRun=true") // | ||
.then().statusCode(201) // | ||
.and().contentType("application/octet-stream") // | ||
.and().header("content-disposition", Matchers.startsWith("attachment;filename=\"vdyp-output-")) // | ||
.extract().body().asInputStream(); | ||
|
||
ZipInputStream zipFile = new ZipInputStream(zipInputStream); | ||
ZipEntry entry1 = zipFile.getNextEntry(); | ||
assertEquals("YieldTable.csv", entry1.getName()); | ||
String entry1Content = new String(testHelper.readZipEntry(zipFile, entry1)); | ||
assertTrue(entry1Content.length() == 0); | ||
|
||
ZipEntry entry2 = zipFile.getNextEntry(); | ||
assertEquals("ProgressLog.txt", entry2.getName()); | ||
String entry2Content = new String(testHelper.readZipEntry(zipFile, entry2)); | ||
assertTrue(entry2Content.isBlank()); | ||
|
||
ZipEntry entry3 = zipFile.getNextEntry(); | ||
assertEquals("ErrorLog.txt", entry3.getName()); | ||
String entry3Content = new String(testHelper.readZipEntry(zipFile, entry3)); | ||
assertTrue(entry3Content.isBlank()); | ||
|
||
ZipEntry entry4 = zipFile.getNextEntry(); | ||
assertEquals("DebugLog.txt", entry4.getName()); | ||
String entry4Content = new String(testHelper.readZipEntry(zipFile, entry4)); | ||
assertTrue(entry4Content.isBlank()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.