diff --git a/README.md b/README.md index 7aa8fe5e84a6340adae0adb08d2e781fca2ea56e..52f57c3a2aec7cb931866ce37dcbb32ecc7a6698 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ See ``` postgres: volumes: - - ./src/test/resources/db/data/dump-discs_names_namesit.sql:/docker-entrypoint-initdb.d/dump-discs_names_namesit.sql + - ./src/test/resources/data/db/dump-discs_names_namesit.sql:/docker-entrypoint-initdb.d/dump-discs_names_namesit.sql ``` * Test diff --git a/docker-compose-demo.yml b/docker-compose-demo.yml index a11410aef4e66d8ec8a93db64c909b24feeb5627..8a1a1f732bbf53f43a6f154bcac661f47ce1c240 100644 --- a/docker-compose-demo.yml +++ b/docker-compose-demo.yml @@ -34,7 +34,7 @@ services: timeout: 5s retries: 10 volumes: - - ./src/test/resources/db/data/dump-discs_names_namesit.sql:/docker-entrypoint-initdb.d/dump-discs_names_namesit.sql + - ./src/test/resources/data/db/dump-discs_names_namesit.sql:/docker-entrypoint-initdb.d/dump-discs_names_namesit.sql volumes: naming-data: diff --git a/src/main/java/org/openepics/names/rest/api/v1/IConvert.java b/src/main/java/org/openepics/names/rest/api/v1/IConvert.java index f9ce6ef6ea52e4537f4345efab823fbcd06eb88d..7dc8c9e05d3361baea33d1960526e4a6f065fca0 100644 --- a/src/main/java/org/openepics/names/rest/api/v1/IConvert.java +++ b/src/main/java/org/openepics/names/rest/api/v1/IConvert.java @@ -49,7 +49,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; * @author Lars Johansson */ @Tag(name = "4. Convert", - description = "handle conversion of names and structure data from one format to another for Naming application") + description = "handle conversion of names and structures data from one format to another for Naming application") @RequestMapping("/api/v1/convert") public interface IConvert { diff --git a/src/test/java/org/openepics/names/docker/ConvertIT.java b/src/test/java/org/openepics/names/docker/ConvertIT.java new file mode 100644 index 0000000000000000000000000000000000000000..fcbbaf7f0724f64089ccceab18033e9d324a708d --- /dev/null +++ b/src/test/java/org/openepics/names/docker/ConvertIT.java @@ -0,0 +1,270 @@ +/* + * Copyright (C) 2024 European Spallation Source ERIC. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package org.openepics.names.docker; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; +import java.util.UUID; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.rest.beans.element.NameElement; +import org.openepics.names.rest.beans.element.NameElementCommandCreate; +import org.openepics.names.rest.beans.element.StructureElement; +import org.openepics.names.rest.beans.element.StructureElementCommandCreate; +import org.openepics.names.rest.beans.response.ResponsePageNameElements; +import org.openepics.names.rest.beans.response.ResponsePageStructureElements; +import org.testcontainers.containers.ComposeContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose-integrationtest.yml / Dockerfile.integrationtest. + * + * <p> + * Purpose of this class is to test conversion of names and structures data from one format to another. + * </p> + * + * @author Lars Johansson + * @see NamesIT + * @see NamesIT#readSearchHistoryDeleted() + */ +@Testcontainers +class ConvertIT { + + @Container + public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers(); + + private static UUID systemGroupAcc = null; + private static UUID systemRFQ = null; + private static UUID subsystem010 = null; + + private static UUID disciplineEMR = null; + private static UUID deviceGroupEMR = null; + private static UUID deviceTypeFS = null; + + @BeforeAll + public static void initAll() { + // init system group, system, subsystem, discipline, device group, device type + + StructureElementCommandCreate structureElementCommandCreate = null; + StructureElement approvedStructureElement = null; + NameElementCommandCreate nameElementCommandCreate = null; +// NameElement nameElement = null; + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.SYSTEMGROUP, null, + "Accelerator", "Acc", + "The ESS Linear Accelerator", "approved by alfio"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + systemGroupAcc = approvedStructureElement.getUuid(); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.SYSTEM, systemGroupAcc, + "Radio Frequency Quadrupole", "RFQ", + "empty", "empty"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + systemRFQ = approvedStructureElement.getUuid(); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.SUBSYSTEM, systemRFQ, + "01 Phase Reference Line", "010PRL", + "empty", "Approved by Daniel Piso"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.SUBSYSTEM, systemRFQ, + "RFQ-010", "010", + "empty", "Approved by Daniel Piso"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + subsystem010 = approvedStructureElement.getUuid(); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.SUBSYSTEM, systemRFQ, + "Power switch board 01", "N1U1", + "Electrical power cabinets", "Approved by Daniel Piso"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.DISCIPLINE, null, + "Electromagnetic Resonators", "EMR", + "empty", "empty"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + disciplineEMR = approvedStructureElement.getUuid(); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.DEVICEGROUP, disciplineEMR, + "Control", null, + "empty", "These names are needed now, so I am approving, but please add a description to these later."); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + deviceGroupEMR = approvedStructureElement.getUuid(); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.DEVICETYPE, deviceGroupEMR, + "Flow Switch", "FS", + "empty", "Approve names added from misc device group"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + deviceTypeFS = approvedStructureElement.getUuid(); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.DEVICETYPE, deviceGroupEMR, + "RF Antenna", "RFA", + "empty", "Approve names added from misc device group"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + + structureElementCommandCreate = new StructureElementCommandCreate( + Type.DEVICETYPE, deviceGroupEMR, + "Temperature Transmitter", "TT", + "empty", "Approve names added from misc device group"); + approvedStructureElement = ITUtilStructures.assertCreateApprove(structureElementCommandCreate); + + nameElementCommandCreate = new NameElementCommandCreate( + subsystem010, deviceTypeFS, "001", + "description", "comment"); + ITUtilNames.assertCreate(nameElementCommandCreate); + + nameElementCommandCreate = new NameElementCommandCreate( + subsystem010, deviceTypeFS, "002", + "description", "comment"); + ITUtilNames.assertCreate(nameElementCommandCreate); + + nameElementCommandCreate = new NameElementCommandCreate( + subsystem010, deviceTypeFS, "003", + "description", "comment"); + ITUtilNames.assertCreate(nameElementCommandCreate); + } + + @AfterAll + public static void extractJacocoReport() { + // extract jacoco report from container file system + ITUtil.extractJacocoReport(ENVIRONMENT, + ITUtil.JACOCO_TARGET_PREFIX + ConvertIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX); + } + + @Test + void json2ExcelStructure() { + // purpose + // test convert structures data in json, according to array of structure elements, to Excel file + // + // note + // response - no content (null) if response is not json + + ResponsePageStructureElements responsePage = ITUtilStructures.assertRead("/children/" + systemGroupAcc.toString(), 1); + String response = ITUtilStructures.assertConvertJson2Excel(responsePage.getList().stream().toArray(StructureElement[]::new)); + + assertNotNull(responsePage); + assertNull(response); + } + + @Test + void json2ExcelStructures() { + // purpose + // test convert structures data in json, according to array of structure elements, to Excel file + // + // note + // response - no content (null) if response is not json + + ResponsePageStructureElements responsePage = ITUtilStructures.assertRead("/children/" + systemRFQ.toString(), 3); + String response = ITUtilStructures.assertConvertJson2Excel(responsePage.getList().stream().toArray(StructureElement[]::new)); + + assertNotNull(responsePage); + assertNull(response); + } + + @Test + void json2ExcelName() { + // purpose + // test convert names data in json, according to array of structure elements, to Excel file + // + // note + // response - no content (null) if response is not json + + ResponsePageNameElements responsePage = ITUtilNames.assertRead("?index=001", 1); + String response = ITUtilNames.assertConvertJson2Excel(responsePage.getList().stream().toArray(NameElement[]::new)); + + assertNotNull(responsePage); + assertNull(response); + } + + @Test + void json2ExcelNames() { + // purpose + // test convert names data in json, according to array of structure elements, to Excel file + // + // note + // response - no content (null) if response is not json + + ResponsePageNameElements responsePage = ITUtilNames.assertRead("?index=00%", 3); + String response = ITUtilNames.assertConvertJson2Excel(responsePage.getList().stream().toArray(NameElement[]::new)); + + assertNotNull(responsePage); + assertNull(response); + } + + @Test + void excel2JsonStructure() { + // purpose + // test convert structures data in Excel file, according to template for structures, to json + + String json = ITUtilStructures.assertConvertExcel2Json(new File("src/test/resources/data/templates/StructureElementCommand_create_system.xlsx")); + + assertNotNull(json); + assertTrue(json.length() > 0); + } + + @Test + void excel2JsonStructures() { + // purpose + // test convert structures data in Excel file, according to template for structures, to json + + String json = ITUtilStructures.assertConvertExcel2Json(new File("src/test/resources/data/templates/StructureElementCommand_create_systems.xlsx")); + + assertNotNull(json); + assertTrue(json.length() > 0); + } + + @Test + void excel2JsonName() { + // purpose + // test convert names data in Excel file, according to template for structures, to json + + String json = ITUtilNames.assertConvertExcel2Json(new File("src/test/resources/data/templates/NameElementCommand_create_name.xlsx")); + + assertNotNull(json); + assertTrue(json.length() > 0); + } + + @Test + void excel2JsonNames() { + // purpose + // test convert names data in Excel file, according to template for structures, to json + + String json = ITUtilNames.assertConvertExcel2Json(new File("src/test/resources/data/templates/NameElementCommand_create_names.xlsx")); + + assertNotNull(json); + assertTrue(json.length() > 0); + } + +} diff --git a/src/test/java/org/openepics/names/docker/ITUtil.java b/src/test/java/org/openepics/names/docker/ITUtil.java index a5a39539690860a275fe731e8dfc2a83c779e932..a2e35219012dfa785f5a36059bc95fb031e99048 100644 --- a/src/test/java/org/openepics/names/docker/ITUtil.java +++ b/src/test/java/org/openepics/names/docker/ITUtil.java @@ -59,10 +59,15 @@ public class ITUtil { static final String AUTH_ADMIN = "admin:adminPass"; static final String EMPTY_JSON = "[]"; static final String HTTP = "http://"; - static final String HEADER_JSON = "'Content-Type: application/json'"; + + static final String HEADER_ACCEPT_APPLICATION_JSON = "'accept: application/json'"; + static final String HEADER_ACCEPT_APPLICATION_VND_MS_EXCEL = "'accept: application/vnd.ms-excel'"; + static final String HEADER_CONTENT_TYPE_APPLICATION_JSON = "'Content-Type: application/json'"; + static final String HEADER_CONTENT_TYPE_MULTIPART_FORM_DATA = "'Content-Type: multipart/form-data'"; static final String IP_PORT_NAMING = "127.0.0.1:8080"; + static final String API_V1_CONVERT = "/api/v1/convert"; static final String API_V1_HISTORY = "/api/v1/history"; static final String API_V1_NAMES = "/api/v1/names"; static final String API_V1_STRUCTURES = "/api/v1/structures"; @@ -418,7 +423,42 @@ public class ITUtil { static enum AuthorizationChoice {NONE, USER, ADMIN}; // enum for different endpoints - static enum EndpointChoice {NAMES, STRUCTURES}; + static enum EndpointChoice {NAMES, STRUCTURES, CONVERT}; + + /** + * Utility method to return curl for POST with path and json. + * + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param json json data + * @return curl for POST with path and json + */ + static String curlPostPathJson2Excel(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { + StringBuilder header = new StringBuilder(); + header.append(" -H " + HEADER_ACCEPT_APPLICATION_VND_MS_EXCEL); + header.append(" -H " + HEADER_CONTENT_TYPE_APPLICATION_JSON); + + return curlMethodAuthEndpointPathJson(header.toString(), MethodChoice.POST, authorizationChoice, endpointChoice, path, json); + } + + /** + * Utility method to return curl for POST with path. + * + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param file file + * @return curl for POST with path + */ + static String curlPostPathExcel2Json(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, File file) { + StringBuilder header = new StringBuilder(); + header.append(" -H " + HEADER_ACCEPT_APPLICATION_JSON); + header.append(" -H " + HEADER_CONTENT_TYPE_MULTIPART_FORM_DATA); + header.append(" -F 'file=@" + file.getPath() + ";type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'"); + + return curlMethodAuthEndpointPathJson(header.toString(), MethodChoice.POST, authorizationChoice, endpointChoice, path, null); + } /** * Utility method to return curl for POST (create information) with path and json. @@ -427,7 +467,7 @@ public class ITUtil { * @param endpointChoice endpoint choice * @param path particular path * @param json json data - * @return curl for POST property (create information) with path and json + * @return curl for POST (create information) with path and json */ static String curlPostPathJson(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { return curlMethodAuthEndpointPathJson(MethodChoice.POST, authorizationChoice, endpointChoice, path, json); @@ -440,7 +480,7 @@ public class ITUtil { * @param endpointChoice endpoint choice * @param path particular path * @param json json data - * @return curl for GET property (get information) with path and json + * @return curl for GET (get information) with path and json */ static String curlGetPathJson(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { return curlMethodAuthEndpointPathJson(MethodChoice.GET, authorizationChoice, endpointChoice, path, json); @@ -453,7 +493,7 @@ public class ITUtil { * @param endpointChoice endpoint choice * @param path particular path * @param json json data - * @return curl for PUT property (update information) with path and json + * @return curl for PUT (update information) with path and json */ static String curlPutPathJson(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { return curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, endpointChoice, path, json); @@ -466,7 +506,7 @@ public class ITUtil { * @param endpointChoice endpoint choice * @param path particular path * @param json json data - * @return curl for DELETE property (delete information) with path + * @return curl for DELETE (delete information) with path and json */ static String curlDeletePathJson(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { return curlMethodAuthEndpointPathJson(MethodChoice.DELETE, authorizationChoice, endpointChoice, path, json); @@ -479,7 +519,7 @@ public class ITUtil { * @param endpointChoice endpoint choice * @param path particular path * @param json json data - * @return + * @return curl for PATCH with path and json */ static String curlPatchPathJson(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { return curlMethodAuthEndpointPathJson(MethodChoice.PATCH, authorizationChoice, endpointChoice, path, json); @@ -496,6 +536,20 @@ public class ITUtil { * @return curl command to run */ private static String curlMethodAuthEndpointPathJson(MethodChoice methodChoice, AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { + return curlMethodAuthEndpointPathJson(null, methodChoice, authorizationChoice, endpointChoice, path, json); + } + /** + * Prepare curl command for test to run for contacting server. + * + * @param header header + * @param methodChoice method choice + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param json json data + * @return curl command to run + */ + private static String curlMethodAuthEndpointPathJson(String header, MethodChoice methodChoice, AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { String pathstr = !StringUtils.isEmpty(path) ? path : ""; @@ -504,10 +558,19 @@ public class ITUtil { ? " -d '" + json + "'" : ""; + String optionHeader = !StringUtils.isEmpty(header) + ? header + : !StringUtils.isEmpty(json) + ? " -H " + ITUtil.HEADER_CONTENT_TYPE_APPLICATION_JSON + : ""; + + String options = + optionHeader + + " -X" + ITUtil.getMethodString(methodChoice) + + " -i "; + return "curl" - + " -H " + ITUtil.HEADER_JSON - + " -X" + ITUtil.getMethodString(methodChoice) - + " -i " + + options + ITUtil.HTTP + ITUtil.getAuthorizationString(authorizationChoice) + ITUtil.IP_PORT_NAMING @@ -570,6 +633,8 @@ public class ITUtil { return ITUtil.API_V1_NAMES; case STRUCTURES: return ITUtil.API_V1_STRUCTURES; + case CONVERT: + return ITUtil.API_V1_CONVERT; default: return StringUtils.EMPTY; } diff --git a/src/test/java/org/openepics/names/docker/ITUtilNames.java b/src/test/java/org/openepics/names/docker/ITUtilNames.java index bbaa154699ea9ea60068805d0fcc7cb001c83b70..1df17ede1fe3746da5c0eb984c2bfe551d8cff00 100644 --- a/src/test/java/org/openepics/names/docker/ITUtilNames.java +++ b/src/test/java/org/openepics/names/docker/ITUtilNames.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.util.Map; @@ -67,6 +68,21 @@ public class ITUtilNames { // ---------------------------------------------------------------------------------------------------- + /** + * Return string for name element array. + * + * @param value name element array + * @return string for name element array + */ + static String object2Json(NameElement[] value) { + try { + return mapper.writeValueAsString(value); + } catch (JsonProcessingException e) { + fail(); + } + return null; + } + /** * Return string for name element command array. * @@ -81,6 +97,7 @@ public class ITUtilNames { } return null; } + /** * Return string for name element command array. * @@ -95,6 +112,7 @@ public class ITUtilNames { } return null; } + /** * Return string for name element command array. * @@ -240,6 +258,69 @@ public class ITUtilNames { // ---------------------------------------------------------------------------------------------------- + /** + * @see ITUtilNames#assertConvertExcel2Json(File, int) + */ + public static String assertConvertExcel2Json(File file) { + return assertConvertExcel2Json(file, HttpURLConnection.HTTP_OK); + } + /** + * Utility method to convert Excel to json and assert response code. + * + * @param file file + * @param expectedResponseCode expected response code + * @return json + */ + public static String assertConvertExcel2Json(File file, int expectedResponseCode) { + try { + String[] response = null; + + response = ITUtil.runShellCommand(ITUtil.curlPostPathExcel2Json(AuthorizationChoice.NONE, EndpointChoice.CONVERT, "/excel2Json/names", file)); + ITUtil.assertResponseLength2Code(response, expectedResponseCode); + + return response[1]; + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + return null; + } + + // ---------------------------------------------------------------------------------------------------- + + /** + * @see ITUtilNames#assertConvertJson2Excel(NameElement[], int) + */ + public static String assertConvertJson2Excel(NameElement[] nameElements) { + return assertConvertJson2Excel(nameElements, HttpURLConnection.HTTP_OK); + } + /** + * Utility method to convert json to Excel and assert response code. + * + * @param nameElements name elements + * @param expectedResponseCode expected response code + * @return response for Excel file + */ + public static String assertConvertJson2Excel(NameElement[] nameElements, int expectedResponseCode) { + try { + // response - no content (null) if response is not json + String[] response = null; + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson2Excel(AuthorizationChoice.NONE, EndpointChoice.CONVERT, "/json2Excel/names", object2Json(nameElements))); + ITUtil.assertResponseLength2Code(response, expectedResponseCode); + + return response[1]; + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + return null; + } + + // ---------------------------------------------------------------------------------------------------- + /** * @see ITUtilNames#assertFind(String, int) */ diff --git a/src/test/java/org/openepics/names/docker/ITUtilStructures.java b/src/test/java/org/openepics/names/docker/ITUtilStructures.java index b20a63bb187118825688e6f939a7ef6b7a0928d0..b5606bb9788fcebbc2af30dc715afbe43928eac0 100644 --- a/src/test/java/org/openepics/names/docker/ITUtilStructures.java +++ b/src/test/java/org/openepics/names/docker/ITUtilStructures.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.util.Map; @@ -68,6 +69,21 @@ public class ITUtilStructures { // ---------------------------------------------------------------------------------------------------- + /** + * Return string for structure element array. + * + * @param value structure element array + * @return string for structure element array + */ + static String object2Json(StructureElement[] value) { + try { + return mapper.writeValueAsString(value); + } catch (JsonProcessingException e) { + fail(); + } + return null; + } + /** * Return string for structure element command array. * @@ -243,6 +259,70 @@ public class ITUtilStructures { // ---------------------------------------------------------------------------------------------------- + + /** + * @see ITUtilStructures#assertConvertExcel2Json(File, int) + */ + public static String assertConvertExcel2Json(File file) { + return assertConvertExcel2Json(file, HttpURLConnection.HTTP_OK); + } + /** + * Utility method to convert Excel to json and assert response code. + * + * @param file file + * @param expectedResponseCode expected response code + * @return json + */ + public static String assertConvertExcel2Json(File file, int expectedResponseCode) { + try { + String[] response = null; + + response = ITUtil.runShellCommand(ITUtil.curlPostPathExcel2Json(AuthorizationChoice.NONE, EndpointChoice.CONVERT, "/excel2Json/structures", file)); + ITUtil.assertResponseLength2Code(response, expectedResponseCode); + + return response[1]; + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + return null; + } + + // ---------------------------------------------------------------------------------------------------- + + /** + * @see ITUtilStructures#assertConvertJson2Excel(StructureElement[], int) + */ + public static String assertConvertJson2Excel(StructureElement[] structureElements) { + return assertConvertJson2Excel(structureElements, HttpURLConnection.HTTP_OK); + } + /** + * Utility method to convert json to Excel and assert response code. + * + * @param structureElements structure elements + * @param expectedResponseCode expected response code + * @return response for Excel file + */ + public static String assertConvertJson2Excel(StructureElement[] structureElements, int expectedResponseCode) { + try { + // response - no content (null) if response is not json + String[] response = null; + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson2Excel(AuthorizationChoice.NONE, EndpointChoice.CONVERT, "/json2Excel/structures", object2Json(structureElements))); + ITUtil.assertResponseLength2Code(response, expectedResponseCode); + + return response[1]; + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + return null; + } + + // ---------------------------------------------------------------------------------------------------- + /** * @see ITUtilStructures#assertFind(String, int) */ diff --git a/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md b/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md index 60c6df181a596b5d6a0c037cf53e32ad094a3f92..f983761cdc7d858a7fcf21c8c2b1edb701403cd0 100644 --- a/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md +++ b/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md @@ -28,6 +28,7 @@ mvn failsafe:integration-test -DskipITs=false -DskipITCoverage=false To run individual integration tests (classes) via Maven. ``` +mvn test -Dtest=org.openepics.names.docker.ConvertIT mvn test -Dtest=org.openepics.names.docker.HealthcheckIT mvn test -Dtest=org.openepics.names.docker.NamesIT mvn test -Dtest=org.openepics.names.docker.ReportIT diff --git a/src/test/resources/db/data/README.txt b/src/test/resources/data/db/README.txt similarity index 94% rename from src/test/resources/db/data/README.txt rename to src/test/resources/data/db/README.txt index 5f132e02307f76ad972768c41dc524546789648d..0f1359dd3fd0bd9d8165b7982be646289babb5c6 100644 --- a/src/test/resources/db/data/README.txt +++ b/src/test/resources/data/db/README.txt @@ -18,7 +18,7 @@ Backup done with DBeaver tool Restore to be done with psql make sure database container is up and running e.g. - psql --host=localhost --port=5432 --dbname=discs_names --username=discs_names < ......../naming-backend/src/test/resources/db/data/dump-discs_names_subsystemit.sql + psql --host=localhost --port=5432 --dbname=discs_names --username=discs_names < ......../naming-backend/src/test/resources/data/db/dump-discs_names_subsystemit.sql DBeaver https://dbeaver.io/ diff --git a/src/test/resources/db/data/dump-discs_names_namesit.sql b/src/test/resources/data/db/dump-discs_names_namesit.sql similarity index 100% rename from src/test/resources/db/data/dump-discs_names_namesit.sql rename to src/test/resources/data/db/dump-discs_names_namesit.sql diff --git a/src/test/resources/db/data/dump-discs_names_subsystemit.sql b/src/test/resources/data/db/dump-discs_names_subsystemit.sql similarity index 100% rename from src/test/resources/db/data/dump-discs_names_subsystemit.sql rename to src/test/resources/data/db/dump-discs_names_subsystemit.sql diff --git a/src/test/resources/data/templates/NameElementCommand_create_name.xlsx b/src/test/resources/data/templates/NameElementCommand_create_name.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..daffac29e46d1ce4f9226a9104f68dc2f3919458 Binary files /dev/null and b/src/test/resources/data/templates/NameElementCommand_create_name.xlsx differ diff --git a/src/test/resources/data/templates/NameElementCommand_create_names.xlsx b/src/test/resources/data/templates/NameElementCommand_create_names.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..f6e39e10fb9b9ba01ef93d122d5c5181dee99dce Binary files /dev/null and b/src/test/resources/data/templates/NameElementCommand_create_names.xlsx differ diff --git a/src/test/resources/db/data/templates/StructureElementCommand_system_create.xlsx b/src/test/resources/data/templates/StructureElementCommand_create_system.xlsx similarity index 100% rename from src/test/resources/db/data/templates/StructureElementCommand_system_create.xlsx rename to src/test/resources/data/templates/StructureElementCommand_create_system.xlsx diff --git a/src/test/resources/data/templates/StructureElementCommand_create_systems.xlsx b/src/test/resources/data/templates/StructureElementCommand_create_systems.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..28c5063fd03e1a2477d1abf99c3a20a696fed681 Binary files /dev/null and b/src/test/resources/data/templates/StructureElementCommand_create_systems.xlsx differ diff --git a/src/test/resources/db/data/templates/NameElementCommand_name_create.xlsx b/src/test/resources/db/data/templates/NameElementCommand_name_create.xlsx deleted file mode 100644 index c9c341a2e84488af7e9877fa1b8afee23cae9f2e..0000000000000000000000000000000000000000 Binary files a/src/test/resources/db/data/templates/NameElementCommand_name_create.xlsx and /dev/null differ