From 96848443622a42b65d7126480c29fa6b80427f64 Mon Sep 17 00:00:00 2001 From: Lars Johansson <lars.johansson@ess.eu> Date: Thu, 24 Feb 2022 16:19:50 +0100 Subject: [PATCH] Added docker integration tests for REST API endpoints - names, structures, healthcheck --- docker-compose-it-db-schema-migration.yml | 37 + ...pt_notes.txt => Schema_data_migration.txt} | 0 .../openepics/names/docker/HealthcheckIT.java | 65 + .../org/openepics/names/docker/ITUtil.java | 506 ++++ .../docker/ITUtilNameStructureElement.java | 726 ++++++ .../org/openepics/names/docker/NamesIT.java | 1119 +++++++++ .../names/docker/StructuresDeviceGroupIT.java | 2121 ++++++++++++++++ .../names/docker/StructuresDeviceTypeIT.java | 2129 ++++++++++++++++ .../names/docker/StructuresDisciplineIT.java | 2024 ++++++++++++++++ .../names/docker/StructuresSubsystemIT.java | 2145 +++++++++++++++++ .../names/docker/StructuresSystemGroupIT.java | 2070 ++++++++++++++++ .../names/docker/StructuresSystemIT.java | 2126 ++++++++++++++++ .../db/schema_migration/V1__Initial.sql | 378 +++ .../V2__Commit_Msg_to_Device.sql | 1 + .../V3__Notification_CC_List.sql | 6 + .../V4__Schema_data_migration.sql | 815 +++++++ 16 files changed, 16268 insertions(+) create mode 100644 docker-compose-it-db-schema-migration.yml rename docs/verification/{script_notes.txt => Schema_data_migration.txt} (100%) create mode 100644 src/test/java/org/openepics/names/docker/HealthcheckIT.java create mode 100644 src/test/java/org/openepics/names/docker/ITUtil.java create mode 100644 src/test/java/org/openepics/names/docker/ITUtilNameStructureElement.java create mode 100644 src/test/java/org/openepics/names/docker/NamesIT.java create mode 100644 src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java create mode 100644 src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java create mode 100644 src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java create mode 100644 src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java create mode 100644 src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java create mode 100644 src/test/java/org/openepics/names/docker/StructuresSystemIT.java create mode 100644 src/test/resources/db/schema_migration/V1__Initial.sql create mode 100644 src/test/resources/db/schema_migration/V2__Commit_Msg_to_Device.sql create mode 100644 src/test/resources/db/schema_migration/V3__Notification_CC_List.sql create mode 100644 src/test/resources/db/schema_migration/V4__Schema_data_migration.sql diff --git a/docker-compose-it-db-schema-migration.yml b/docker-compose-it-db-schema-migration.yml new file mode 100644 index 00000000..5cdaf326 --- /dev/null +++ b/docker-compose-it-db-schema-migration.yml @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------ +# Copyright (C) 2022 European Spallation Source ERIC. +# ------------------------------------------------------------------------------ + +version: '3.7' +services: + naming: + build: ./ + ports: + - "8080:8083" + depends_on: + postgres: + condition: service_healthy + command: "java -jar /naming/naming-backend-0.0.1-SNAPSHOT.jar" + + postgres: + image: "postgres:9.6.7" + ports: + - "5432:5432" + environment: + POSTGRES_DB: discs_names + POSTGRES_USER: discs_names + POSTGRES_PASSWORD: discs_names + PGDATA: /var/lib/postgresql/data/pgdata + healthcheck: + test: ["CMD-SHELL", "pg_isready -U discs_names"] + interval: 10s + timeout: 5s + retries: 10 + volumes: + - ./src/test/resources/db/schema_migration/V1__Initial.sql:/docker-entrypoint-initdb.d/V1__Initial.sql + - ./src/test/resources/db/schema_migration/V2__Commit_Msg_to_Device.sql:/docker-entrypoint-initdb.d/V2__Commit_Msg_to_Device.sql + - ./src/test/resources/db/schema_migration/V3__Notification_CC_List.sql:/docker-entrypoint-initdb.d/V3__Notification_CC_List.sql + - ./src/test/resources/db/schema_migration/V4__Schema_data_migration.sql:/docker-entrypoint-initdb.d/V4__Schema_data_migration.sql + +volumes: + naming-data: diff --git a/docs/verification/script_notes.txt b/docs/verification/Schema_data_migration.txt similarity index 100% rename from docs/verification/script_notes.txt rename to docs/verification/Schema_data_migration.txt diff --git a/src/test/java/org/openepics/names/docker/HealthcheckIT.java b/src/test/java/org/openepics/names/docker/HealthcheckIT.java new file mode 100644 index 00000000..868d3996 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/HealthcheckIT.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; + +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +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.yml / Dockerfile. + * + * <p> + * Focus of this class is Healthcheck endpoint. + * In practice, it means means to have Naming and PostgreSQL up and running. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class HealthcheckIT { + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + @Test + public void readHealthcheck() { + try { + String address = ITUtil.HTTP_IP_PORT_NAMING + "/healthcheck"; + int responseCode = ITUtil.doGet(address); + + assertEquals(HttpURLConnection.HTTP_OK, responseCode); + } catch (IOException e) { + fail(); + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/ITUtil.java b/src/test/java/org/openepics/names/docker/ITUtil.java new file mode 100644 index 00000000..3bc680f3 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/ITUtil.java @@ -0,0 +1,506 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; + +/** + * Utility class to help (Docker) integration tests for Naming and PostgreSQL. + * + * @author Lars Johansson + */ +public class ITUtil { + + static final String NAMING = "naming"; + + static final String AUTH_USER = "user:userPass"; + 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 IP_PORT_NAMING = "127.0.0.1:8080"; + + static final String API_V1_NAMES = "/api/v1/names"; + static final String API_V1_STRUCTURES = "/api/v1/structures"; + + static final String HTTP_IP_PORT_NAMING = ITUtil.HTTP + ITUtil.IP_PORT_NAMING; + + static final String HTTP_IP_PORT_NAMING_API_V1_NAMES = ITUtil.HTTP + ITUtil.IP_PORT_NAMING + API_V1_NAMES; + static final String HTTP_AUTH_USER_IP_PORT_NAMING_API_V1_NAMES = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_NAMING + API_V1_NAMES; + static final String HTTP_AUTH_ADMIN_IP_PORT_NAMING_API_V1_NAMES = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_NAMING + API_V1_NAMES; + + static final String HTTP_IP_PORT_NAMING_API_V1_STRUCTURES = ITUtil.HTTP + ITUtil.IP_PORT_NAMING + API_V1_STRUCTURES; + static final String HTTP_AUTH_USER_IP_PORT_NAMING_API_V1_STRUCTURES = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_NAMING + API_V1_STRUCTURES; + static final String HTTP_AUTH_ADMIN_IP_PORT_NAMING_API_V1_STRUCTURES = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_NAMING + API_V1_STRUCTURES; + + private static final String BRACKET_BEGIN = "["; + private static final String BRACKET_END = "]"; + private static final String CURLY_BRACE_BEGIN = "{"; + private static final String CURLY_BRACE_END = "}"; + private static final String HTTP_REPLY = "HTTP"; + + /** + * This class is not to be instantiated. + */ + private ITUtil() { + throw new IllegalStateException("Utility class"); + } + + /** + * Do GET request with given string as URL and return response code. + * + * @param spec string to parse as URL + * @return response code + * + * @throws IOException + */ + static int doGet(String spec) throws IOException { + URL url = new URL(spec); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + return con.getResponseCode(); + } + + /** + * Do GET request with given string as URL and return response with string array with response code and response string. + * + * @param spec string to parse as URL + * @return string array with response code and response string + * + * @throws IOException + */ + static String[] doGetJson(String spec) throws IOException { + URL url = new URL(spec); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + int responseCode = con.getResponseCode(); + + String line; + StringBuilder sb = new StringBuilder(); + try (BufferedReader br = responseCode == HttpURLConnection.HTTP_OK + ? new BufferedReader(new InputStreamReader(con.getInputStream())) + : new BufferedReader(new InputStreamReader(con.getErrorStream()))) { + while((line = br.readLine()) != null) { + sb.append(line); + } + } + + return new String[] {String.valueOf(responseCode), sb.toString().trim()}; + } + + /** + * Run a shell command and return response with string array with response code and response string. + * + * @param command shell command + * @return string array with response code and response string + * + * @throws IOException + * @throws InterruptedException + * @throws Exception + */ + static String[] runShellCommand(String command) throws IOException, InterruptedException, Exception { + // run shell command & return http response code if available + + final ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("bash", "-c", command); + + String responseCode = null; + String responseContent = null; + try { + final Process process = processBuilder.start(); + final BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream())); + final BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream())); + final boolean processFinished = process.waitFor(30, TimeUnit.SECONDS); + + String line = null; + while ((line = inputStream.readLine()) != null) { + if (line.startsWith(HTTP_REPLY)) { + // response code, e.g. "HTTP/1.1 200", "HTTP/1.1 401", "HTTP/1.1 500" + String[] s = line.trim().split(" "); + if (s != null && s.length == 2) { + responseCode = s[1]; + } + } else if ((line.startsWith(BRACKET_BEGIN) && line.endsWith(BRACKET_END)) + || (line.startsWith(CURLY_BRACE_BEGIN) && line.endsWith(CURLY_BRACE_END))) { + // response string, json + responseContent = line; + } + } + + if (!processFinished) { + throw new Exception("Timed out waiting to execute command: " + command); + } + if (process.exitValue() != 0) { + throw new Exception( + String.format("Shell command finished with status %d error: %s", + process.exitValue(), + errorStream.lines().collect(Collectors.joining()))); + } + } catch (IOException | InterruptedException e) { + throw e; + } + return new String[] {responseCode, responseContent}; + } + + // ---------------------------------------------------------------------------------------------------- + + /** + * Assert that response object is as expected, an array with 2 elements + * of which first contains response code OK (200). + * + * @param response string array with response of http request, response code and content + * + * @see HttpURLConnection#HTTP_OK + */ + static void assertResponseLength2CodeOK(String[] response) { + assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + } + + /** + * Assert that response object is as expected, an array with 2 elements + * of which first element contains given response code. + * + * @param response string array with response of http request, response code and content + * @param responseCode expected response code + * + * @see HttpURLConnection for available response codes + */ + static void assertResponseLength2Code(String[] response, int responseCode) { + assertNotNull(response); + assertEquals(2, response.length); + assertEquals(responseCode, Integer.parseInt(response[0])); + } + + /** + * Assert that response object is as expected, an array with 2 elements + * of which first element contains response code OK (200) and second element contains given response content. + * + * @param response string array with response of http request, response code and content + * @param responseContent expected response content + * + * @see HttpURLConnection#HTTP_OK + */ + static void assertResponseLength2CodeOKContent(String[] response, String responseContent) { + assertResponseLength2CodeContent(response, HttpURLConnection.HTTP_OK, responseContent); + } + + /** + * Assert that response object is as expected, an array with 2 elements + * of which first element contains given response code and second element contains given response content. + * + * @param response string array with response of http request, response code and content + * @param responseCode expected response code + * @param responseContent expected response content + * + * @see HttpURLConnection for available response codes + */ + static void assertResponseLength2CodeContent(String[] response, int responseCode, String responseContent) { + assertResponseLength2Code(response, responseCode); + assertEquals(responseContent, response[1]); + } + + // ---------------------------------------------------------------------------------------------------- + + /** + * Assert response available with empty message. + * + * @param actual response object + */ + static void assertMessageEmpty(Response actual) { + assertMessageEmpty(actual, Boolean.TRUE); + } + /** + * Assert response available with non-empty message. + * + * @param actual response object + */ + static void assertMessageNotEmpty(Response actual) { + assertMessageEmpty(actual, Boolean.FALSE); + } + /** + * Assert response available with empty message. + * + * @param actual response object + * @param expectedMessageEmpty expected message behavior + */ + private static void assertMessageEmpty(Response actual, Boolean expectedMessageEmpty) { + assertNotNull(actual); + assertEquals(StringUtils.isEmpty(actual.getMessage()), expectedMessageEmpty); + } + + /** + * Assert response boolean available with expected response. + * + * @param actual response boolean object + * @param expectedResponse expected response + */ + static void assertEqualsResponseBoolean(ResponseBoolean actual, Boolean expectedResponse) { + assertNotNull(actual); + assertEquals(expectedResponse, actual.getResponse()); + } + /** + * Assert response boolean available with empty message. + * + * @param actual response boolean object + * @param expectedResponse expected message behavior + */ + static void assertEqualsResponseBooleanMessageEmpty(ResponseBoolean actual, Boolean expectedResponse) { + assertEqualsResponseBooleanMessageEmpty(actual, expectedResponse, Boolean.TRUE); + } + /** + * Assert response boolean available with non-empty message. + * + * @param actual response boolean object + * @param expectedResponse expected message behavior + */ + static void assertEqualsResponseBooleanMessageNotEmpty(ResponseBoolean actual, Boolean expectedResponse) { + assertEqualsResponseBooleanMessageEmpty(actual, expectedResponse, Boolean.FALSE); + } + /** + * Assert response boolean available with expected response and expected message behavior. + * + * @param actual response boolean object + * @param expectedResponse expected response + * @param expectedMessageEmpty expected message behavior + */ + private static void assertEqualsResponseBooleanMessageEmpty(ResponseBoolean actual, Boolean expectedResponse, Boolean expectedMessageEmpty) { + assertEqualsResponseBoolean(actual, expectedResponse); + assertEquals(StringUtils.isEmpty(actual.getMessage()), expectedMessageEmpty); + } + + /** + * Assert response boolean list available with expected response. + * + * @param actual response boolean list object + * @param expectedResponse expected response + */ + static void assertEqualsResponseBoolean(ResponseBooleanList actual, Boolean expectedResponse) { + assertNotNull(actual); + assertEquals(expectedResponse, actual.getResponse()); + } + /** + * Assert response boolean list available with empty message. + * + * @param actual response boolean list object + * @param expectedResponse expected message behavior + */ + static void assertEqualsResponseBooleanMessageEmpty(ResponseBooleanList actual, Boolean expectedResponse) { + assertEqualsResponseBooleanMessageEmpty(actual, expectedResponse, Boolean.TRUE); + } + /** + * Assert response boolean list available with non-empty message. + * + * @param actual response boolean list object + * @param expectedResponse expected message behavior + */ + static void assertEqualsResponseBooleanMessageNotEmpty(ResponseBooleanList actual, Boolean expectedResponse) { + assertEqualsResponseBooleanMessageEmpty(actual, expectedResponse, Boolean.FALSE); + } + /** + * Assert response boolean list available with expected response and expected message behavior. + * + * @param actual response boolean list object + * @param expectedResponse expected response + * @param expectedMessageEmpty expected message behavior + */ + private static void assertEqualsResponseBooleanMessageEmpty(ResponseBooleanList actual, Boolean expectedResponse, Boolean expectedMessageEmpty) { + assertEqualsResponseBoolean(actual, expectedResponse); + assertEquals(StringUtils.isEmpty(actual.getMessage()), expectedMessageEmpty); + } + + // ---------------------------------------------------------------------------------------------------- + + // enum for http methods + static enum MethodChoice {POST, GET, PUT, DELETE, PATCH}; + + // enum for different authorizations + static enum AuthorizationChoice {NONE, USER, ADMIN}; + + // enum for different endpoints + static enum EndpointChoice {NAMES, STRUCTURES}; + + /** + * Utility method to return curl for POST (create information) with path and json. + * + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param json json data + * @return curl for POST property (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); + } + + /** + * Utility method to return curl for GET (get information) with path and json. + * + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param json json data + * @return curl for GET property (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); + } + + /** + * Utility method to return curl for PUT (update information) with path and json. + * + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param json json data + * @return curl for PUT property (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); + } + + /** + * Utility method to return curl for DELETE (delete information) with path and json + * + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param json json data + * @return curl for DELETE property (delete information) with path + */ + static String curlDeletePathJson(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { + return curlMethodAuthEndpointPathJson(MethodChoice.DELETE, authorizationChoice, endpointChoice, path, json); + } + + /** + * Utility method to return curl for PATCH (patch information) with path and json. + * + * @param authorizationChoice authorization choice + * @param endpointChoice endpoint choice + * @param path particular path + * @param json json data + * @return + */ + static String curlPatchPathJson(AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { + return curlMethodAuthEndpointPathJson(MethodChoice.PATCH, authorizationChoice, endpointChoice, path, json); + } + + /** + * Prepare curl command for test to run for contacting server. + * + * @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(MethodChoice methodChoice, AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) { + String pathstr = !StringUtils.isEmpty(path) + ? path + : ""; + + String data = !StringUtils.isEmpty(json) + ? " -d '" + json + "'" + : ""; + + return "curl" + + " -H " + ITUtil.HEADER_JSON + + " -X" + ITUtil.getMethodString(methodChoice) + + " -i " + + ITUtil.HTTP + + ITUtil.getAuthorizationString(authorizationChoice) + + ITUtil.IP_PORT_NAMING + + ITUtil.getEndpointString(endpointChoice) + + pathstr + + data; + } + + /** + * Utility method to return string for http method. To be used when constructing url to send query to server. + * + * @param methodChoice method choice, i.e. POST, GET, PUT, DELETE, PATCH + * @return string for http method + */ + private static String getMethodString(MethodChoice methodChoice) { + switch (methodChoice) { + case POST: + return "POST"; + case GET: + return "GET"; + case PUT: + return "PUT"; + case PATCH: + return "PATCH"; + case DELETE: + return "DELETE"; + default: + return "GET"; + } + } + + /** + * Utility method to return string for authorization. To be used when constructing url to send query to server. + * + * @param authorizationChoice authorization choice + * @return string for authorization + */ + private static String getAuthorizationString(AuthorizationChoice authorizationChoice) { + switch (authorizationChoice) { + case ADMIN: + return ITUtil.AUTH_ADMIN + "@"; + case USER: + return ITUtil.AUTH_USER + "@"; + case NONE: + return StringUtils.EMPTY; + default: + return StringUtils.EMPTY; + } + } + + /** + * Utility method to return string for endpoint. To be used when constructing url to send query to server. + * + * @param endpointChoice endpoint choice + * @return string for endpoint + */ + private static String getEndpointString(EndpointChoice endpointChoice) { + switch (endpointChoice) { + case NAMES: + return ITUtil.API_V1_NAMES; + case STRUCTURES: + return ITUtil.API_V1_STRUCTURES; + default: + return StringUtils.EMPTY; + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/ITUtilNameStructureElement.java b/src/test/java/org/openepics/names/docker/ITUtilNameStructureElement.java new file mode 100644 index 00000000..a51d9baa --- /dev/null +++ b/src/test/java/org/openepics/names/docker/ITUtilNameStructureElement.java @@ -0,0 +1,726 @@ +/* + * Copyright (C) 2022 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.assertEquals; +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 static org.junit.jupiter.api.Assertions.fail; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.util.UUID; + +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.NameElement; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.ResponseBooleanList; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Utility class to help (Docker) integration tests for Naming and PostgreSQL. + * + * @author Lars Johansson + */ +public class ITUtilNameStructureElement { + + /** + * This class is not to be instantiated. + */ + private ITUtilNameStructureElement() { + throw new IllegalStateException("Utility class"); + } + + /** + * Assert that array of structure elements has expected length. + * + * @param actual array of structure elements + * @param expectedLength expected length of array + */ + static void assertContentLength(StructureElement[] actual, int expectedLength) { + assertNotNull(actual); + assertEquals(expectedLength, actual.length); + } + + /** + * Assert that array of structure elements has length one and structure element is available. + * + * @param actual array of structure elements + * @return structure element + */ + static StructureElement assertContentLengthOne(StructureElement[] actual) { + assertContentLength(actual, 1); + assertNotNull(actual[0]); + return actual[0]; + } + + /** + * Assert content of structure element. + * + * @param actual structure element + * @param expectedType expected type + * @param expectedUuid expected uuid + * @param expectedParent expected parent + * @param expectedName expected name + * @param expectedMnemonic expected mnemonic + * @param expectedMnemonicpath expected mnemonic path + * @param expectedLevel expected level + * @param expectedDescription expected description + * @param expectedStatus expected status + * @param expectedIsLatest expected latest + * @param expectedIsDeleted expected deleted + * @param expectedWho expected who + * @param expectedComment expected comment + */ + static void assertContent(StructureElement actual, + Type expectedType, UUID expectedUuid, UUID expectedParent, + String expectedName, String expectedMnemonic, String expectedMnemonicpath, Integer expectedLevel, + String expectedDescription, Status expectedStatus, Boolean expectedIsLatest, Boolean expectedIsDeleted, + String expectedWho, String expectedComment) { + assertNotNull(actual); + assertEquals(expectedType, actual.getType()); + assertEquals(expectedUuid, actual.getUuid()); + assertEquals(expectedParent, actual.getParent()); + assertEquals(expectedName, actual.getName()); + assertEquals(expectedMnemonic, actual.getMnemonic()); + assertEquals(expectedMnemonicpath, actual.getMnemonicpath()); + assertEquals(expectedLevel, actual.getLevel()); + assertEquals(expectedDescription, actual.getDescription()); + assertEquals(expectedStatus, actual.getStatus()); + assertEquals(expectedIsLatest, actual.isLatest()); + assertEquals(expectedIsDeleted, actual.isDeleted()); + assertNotNull(actual.getWhen()); + assertEquals(expectedWho, actual.getWho()); + assertEquals(expectedComment, actual.getComment()); + } + + /** + * Assert that arrays are equal with same length and same content in each array position. + * + * @param actual actual array of structure elements + * @param expected expected arbitrary number of structure elements + */ + static void assertEqualsStructureElements(StructureElement[] actual, StructureElement... expected) { + if (expected != null) { + assertNotNull(actual); + assertEquals(expected.length, actual.length); + for (int i=0; i<expected.length; i++) { + assertTrue(expected[i].equals(actual[i])); + } + } else { + assertNull(actual); + } + } + + // ---------------------------------------------------------------------------------------------------- + + /** + * Assert that array of name elements has expected length. + * + * @param actual array of name elements + * @param expectedLength expected length of array + */ + static void assertContentLength(NameElement[] actual, int expectedLength) { + assertNotNull(actual); + assertEquals(expectedLength, actual.length); + } + + /** + * Assert that array of name elements has length one and name element is available. + * + * @param actual array of name elements + * @return name element + */ + static NameElement assertContentLengthOne(NameElement[] actual) { + assertContentLength(actual, 1); + assertNotNull(actual[0]); + return actual[0]; + } + + /** + * Assert content of name element. + * + * @param actual name element + * @param expectedUuid expected uuid + * @param expectedSystemgroup expected system group + * @param expectedSystem expected system + * @param expectedSubsystem expected subsystem + * @param expectedDevicetype expected device type + * @param expectedSystemstructure expected system structure + * @param expectedDevicestructure expected device structure + * @param expectedIndex expected index + * @param expectedName expected name + * @param expectedDescription expected description + * @param expectedStatus expected status + * @param expectedIsLatest expected latest + * @param expectedIsDeleted expected deleted + * @param expectedWho expected who + * @param expectedComment expected comment + */ + static void assertContent(NameElement actual, + UUID expectedUuid, UUID expectedSystemgroup, UUID expectedSystem, UUID expectedSubsystem, UUID expectedDevicetype, + String expectedSystemstructure, String expectedDevicestructure, + String expectedIndex, String expectedName, + String expectedDescription, Status expectedStatus, Boolean expectedIsLatest, Boolean expectedIsDeleted, + String expectedWho, String expectedComment) { + assertNotNull(actual); + assertEquals(expectedUuid, actual.getUuid()); + assertEquals(expectedSystemgroup, actual.getSystemgroup()); + assertEquals(expectedSystem, actual.getSystem()); + assertEquals(expectedSubsystem, actual.getSubsystem()); + assertEquals(expectedDevicetype, actual.getDevicetype()); + assertEquals(expectedSystemstructure, actual.getSystemstructure()); + assertEquals(expectedDevicestructure, actual.getDevicestructure()); + assertEquals(expectedIndex, actual.getIndex()); + assertEquals(expectedName, actual.getName()); + assertEquals(expectedDescription, actual.getDescription()); + assertEquals(expectedStatus, actual.getStatus()); + assertEquals(expectedIsLatest, actual.isLatest()); + assertEquals(expectedIsDeleted, actual.isDeleted()); + assertNotNull(actual.getWhen()); + assertEquals(expectedWho, actual.getWho()); + assertEquals(expectedComment, actual.getComment()); + } + + /** + * Assert that arrays are equal with same length and same content in each array position. + * + * @param actual actual array of name elements + * @param expected expected arbitrary number of name elements + */ + static void assertEqualsNameElements(NameElement[] actual, NameElement... expected) { + if (expected != null) { + assertNotNull(actual); + assertEquals(expected.length, actual.length); + for (int i=0; i<expected.length; i++) { + assertTrue(expected[i].equals(actual[i])); + } + } else { + assertNull(actual); + } + } + + // ---------------------------------------------------------------------------------------------------- + + /** + * Utility method to create a name element and assert result. + * + * @param nameElement name element + * @return created name element + */ + static NameElement assertCreate(NameElement nameElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + NameElement[] createdNameElements = null; + NameElement createdNameElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + createdNameElements = mapper.readValue(response[1], NameElement[].class); + createdNameElement = ITUtilNameStructureElement.assertContentLengthOne(createdNameElements); + assertNotNull(createdNameElement.getUuid()); + + uuid = createdNameElement.getUuid(); + nameElement.setUuid(uuid); + + ITUtilNameStructureElement.assertContent(createdNameElement, + uuid, nameElement.getSystemgroup(), nameElement.getSystem(), nameElement.getSubsystem(), nameElement.getDevicetype(), + nameElement.getSystemstructure(), nameElement.getDevicestructure(), + nameElement.getIndex(), nameElement.getName(), + nameElement.getDescription(), nameElement.getStatus(), Boolean.TRUE, Boolean.FALSE, + "test who", nameElement.getComment()); + assertNotNull(createdNameElement.getWhen()); + + return createdNameElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to update a name element and assert result. + * + * @param nameElement name element + * @return updated name element + */ + static NameElement assertUpdate(NameElement nameElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + NameElement[] updatedNameElements = null; + NameElement updatedNameElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlPutPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + updatedNameElements = mapper.readValue(response[1], NameElement[].class); + updatedNameElement = ITUtilNameStructureElement.assertContentLengthOne(updatedNameElements); + assertNotNull(updatedNameElement.getUuid()); + + uuid = updatedNameElement.getUuid(); + nameElement.setUuid(uuid); + + ITUtilNameStructureElement.assertContent(updatedNameElement, + uuid, nameElement.getSystemgroup(), nameElement.getSystem(), nameElement.getSubsystem(), nameElement.getDevicetype(), + nameElement.getSystemstructure(), nameElement.getDevicestructure(), + nameElement.getIndex(), nameElement.getName(), + nameElement.getDescription(), nameElement.getStatus(), Boolean.TRUE, Boolean.FALSE, + "test who", nameElement.getComment()); + assertNotNull(updatedNameElement.getWhen()); + + return updatedNameElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to delete a name element and assert result. + * + * @param nameElement name element + * @return deleted name element + */ + static NameElement assertDelete(NameElement nameElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + NameElement[] deletedNameElements = null; + NameElement deletedNameElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlDeletePathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + deletedNameElements = mapper.readValue(response[1], NameElement[].class); + deletedNameElement = ITUtilNameStructureElement.assertContentLengthOne(deletedNameElements); + assertNotNull(deletedNameElement.getUuid()); + + uuid = deletedNameElement.getUuid(); + nameElement.setUuid(uuid); + + ITUtilNameStructureElement.assertContent(deletedNameElement, + uuid, nameElement.getSystemgroup(), nameElement.getSystem(), nameElement.getSubsystem(), nameElement.getDevicetype(), + nameElement.getSystemstructure(), nameElement.getDevicestructure(), + nameElement.getIndex(), nameElement.getName(), + nameElement.getDescription(), nameElement.getStatus(), Boolean.TRUE, Boolean.TRUE, + "test who", nameElement.getComment()); + assertNotNull(deletedNameElement.getWhen()); + + return deletedNameElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + // ---------------------------------------------------------------------------------------------------- + + /** + * Utility method to create a structure element and assert result. + * + * @param structureElement structure element + * @return created structure element + */ + static StructureElement assertCreate(StructureElement structureElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement[] createdStructureElements = null; + StructureElement createdStructureElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + createdStructureElements = mapper.readValue(response[1], StructureElement[].class); + createdStructureElement = ITUtilNameStructureElement.assertContentLengthOne(createdStructureElements); + assertNotNull(createdStructureElement.getUuid()); + + uuid = createdStructureElement.getUuid(); + structureElement.setUuid(uuid); + + ITUtilNameStructureElement.assertContent(createdStructureElement, + structureElement.getType(), uuid, structureElement.getParent(), + structureElement.getName(), structureElement.getMnemonic(), structureElement.getMnemonicpath(), structureElement.getLevel(), + structureElement.getDescription(), Status.PENDING, Boolean.FALSE, Boolean.FALSE, + "test who", structureElement.getComment()); + assertNotNull(createdStructureElement.getWhen()); + + return createdStructureElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to update a structure element and assert result. + * + * @param structureElement structure element + * @return updated structure element + */ + static StructureElement assertUpdate(StructureElement structureElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement[] updatedStructureElements = null; + StructureElement updatedStructureElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlPutPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + updatedStructureElements = mapper.readValue(response[1], StructureElement[].class); + updatedStructureElement = ITUtilNameStructureElement.assertContentLengthOne(updatedStructureElements); + assertNotNull(updatedStructureElement.getUuid()); + + uuid = updatedStructureElement.getUuid(); + structureElement.setUuid(uuid); + + ITUtilNameStructureElement.assertContent(updatedStructureElement, + structureElement.getType(), uuid, structureElement.getParent(), + structureElement.getName(), structureElement.getMnemonic(), structureElement.getMnemonicpath(), structureElement.getLevel(), + structureElement.getDescription(), Status.PENDING, Boolean.FALSE, Boolean.FALSE, + "test who", structureElement.getComment()); + assertNotNull(updatedStructureElement.getWhen()); + + return updatedStructureElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to delete a structure element and assert result. + * + * @param structureElement structure element + * @return deleted structure element + */ + static StructureElement assertDelete(StructureElement structureElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement[] deletedStructureElements = null; + StructureElement deletedStructureElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlDeletePathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + deletedStructureElements = mapper.readValue(response[1], StructureElement[].class); + deletedStructureElement = ITUtilNameStructureElement.assertContentLengthOne(deletedStructureElements); + assertNotNull(deletedStructureElement.getUuid()); + + uuid = deletedStructureElement.getUuid(); + structureElement.setUuid(uuid); + + ITUtilNameStructureElement.assertContent(deletedStructureElement, + structureElement.getType(), uuid, structureElement.getParent(), + structureElement.getName(), structureElement.getMnemonic(), structureElement.getMnemonicpath(), structureElement.getLevel(), + structureElement.getDescription(), Status.PENDING, Boolean.FALSE, Boolean.TRUE, + "test who", structureElement.getComment()); + assertNotNull(deletedStructureElement.getWhen()); + + return deletedStructureElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to approve a structure element and assert result. + * + * @param structureElement structure element + * @return approved structure element + */ + static StructureElement assertApprove(StructureElement structureElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] approvedStructureElements = null; + StructureElement approvedStructureElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/approve", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + approvedStructureElements = mapper.readValue(response[1], StructureElement[].class); + approvedStructureElement = ITUtilNameStructureElement.assertContentLengthOne(approvedStructureElements); + ITUtilNameStructureElement.assertContent(approvedStructureElement, + structureElement.getType(), structureElement.getUuid(), structureElement.getParent(), + structureElement.getName(), structureElement.getMnemonic(), structureElement.getMnemonicpath(), structureElement.getLevel(), + structureElement.getDescription(), Status.APPROVED, Boolean.TRUE, structureElement.isDeleted(), + "test who", "test comment"); + assertNotNull(approvedStructureElement.getWhen()); + + return approvedStructureElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to cancel a structure element and assert result. + * + * @param structureElement structure element + * @return cancelled structure element + */ + static StructureElement assertCancel(StructureElement structureElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] cancelledStructureElements = null; + StructureElement cancelledStructureElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/cancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + cancelledStructureElements = mapper.readValue(response[1], StructureElement[].class); + cancelledStructureElement = ITUtilNameStructureElement.assertContentLengthOne(cancelledStructureElements); + ITUtilNameStructureElement.assertContent(cancelledStructureElement, + structureElement.getType(), structureElement.getUuid(), structureElement.getParent(), + structureElement.getName(), structureElement.getMnemonic(), structureElement.getMnemonicpath(), structureElement.getLevel(), + structureElement.getDescription(), Status.CANCELLED, Boolean.FALSE, structureElement.isDeleted(), + "test who", "test comment"); + assertNotNull(cancelledStructureElement.getWhen()); + + return cancelledStructureElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to reject a structure element and assert result. + * + * @param structureElement structure element + * @return rejected structure element + */ + static StructureElement assertReject(StructureElement structureElement) { + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] rejectedStructureElements = null; + StructureElement rejectedStructureElement = null; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/reject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + rejectedStructureElements = mapper.readValue(response[1], StructureElement[].class); + rejectedStructureElement = ITUtilNameStructureElement.assertContentLengthOne(rejectedStructureElements); + ITUtilNameStructureElement.assertContent(rejectedStructureElement, + structureElement.getType(), structureElement.getUuid(), structureElement.getParent(), + structureElement.getName(), structureElement.getMnemonic(), structureElement.getMnemonicpath(), structureElement.getLevel(), + structureElement.getDescription(), Status.REJECTED, Boolean.FALSE, structureElement.isDeleted(), + "test who", "test comment"); + assertNotNull(rejectedStructureElement.getWhen()); + + return rejectedStructureElement; + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + + return null; + } + + /** + * Utility method to create, approve a structure element and assert result. + * + * @param structureElement structure element + * @return approved structure element (after create) + */ + static StructureElement assertCreateApprove(StructureElement structureElement) { + return assertApprove(assertCreate(structureElement)); + } + + /** + * Utility method to create, cancel a structure element and assert result. + * + * @param structureElement structure element + * @return cancelled structure element (after create) + */ + static StructureElement assertCreateCancel(StructureElement structureElement) { + return assertCancel(assertCreate(structureElement)); + } + + /** + * Utility method to create, reject a structure element and assert result. + * + * @param structureElement structure element + * @return rejected structure element (after create) + */ + static StructureElement assertCreateReject(StructureElement structureElement) { + return assertReject(assertCreate(structureElement)); + } + + /** + * Utility method to update, approve a structure element and assert result. + * + * @param structureElement structure element + * @return approved structure element (after update) + */ + static StructureElement assertUpdateApprove(StructureElement structureElement) { + return assertApprove(assertUpdate(structureElement)); + } + + /** + * Utility method to update, cancel a structure element and assert result. + * + * @param structureElement structure element + * @return cancelled structure element (after update) + */ + static StructureElement assertUpdateCancel(StructureElement structureElement) { + return assertCancel(assertUpdate(structureElement)); + } + + /** + * Utility method to update, reject a structure element and assert result. + * + * @param structureElement structure element + * @return rejected structure element (after update) + */ + static StructureElement assertUpdateReject(StructureElement structureElement) { + return assertReject(assertUpdate(structureElement)); + } + + /** + * Utility method to delete, approve a structure element and assert result. + * + * @param structureElement structure element + * @return approved structure element (after delete) + */ + static StructureElement assertDeleteApprove(StructureElement structureElement) { + return assertApprove(assertDelete(structureElement)); + } + + /** + * Utility method to delete, cancel a structure element and assert result. + * + * @param structureElement structure element + * @return cancelled structure element (after delete) + */ + static StructureElement assertDeleteCancel(StructureElement structureElement) { + return assertCancel(assertDelete(structureElement)); + } + + /** + * Utility method to delete, reject a structure element and assert result. + * + * @param structureElement structure element + * @return rejected structure element (after delete) + */ + static StructureElement assertDeleteReject(StructureElement structureElement) { + return assertReject(assertDelete(structureElement)); + } + +} diff --git a/src/test/java/org/openepics/names/docker/NamesIT.java b/src/test/java/org/openepics/names/docker/NamesIT.java new file mode 100644 index 00000000..50b2a8f0 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/NamesIT.java @@ -0,0 +1,1119 @@ +/* + * Copyright (C) 2022 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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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.UUID; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.NameElement; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose.yml / Dockerfile. + * + * <p> + * Focus of this class is names endpoint. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class NamesIT { + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + private static UUID systemGroupAcc = null; + private static UUID systemRFQ = null; + private static UUID subsystem010PRL = null; + private static UUID subsystem010 = null; + private static UUID subsystemN1U1 = null; + + private static UUID disciplineEMR = null; + private static UUID deviceGroupEMR = null; + private static UUID deviceTypeFS = null; + private static UUID deviceTypeRFA = null; + private static UUID deviceTypeTT = null; + + @BeforeAll + public static void initAll() { + // init system group, system, subsystem, discipline, device group, device type + + StructureElement structureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "Accelerator", "Acc", "Acc", 1, + "The ESS Linear Accelerator", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "approved by alfio"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + systemGroupAcc = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupAcc, + "Radio Frequency Quadrupole", "RFQ", "Acc-RFQ", 2, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "empty"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + systemRFQ = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemRFQ, + "01 Phase Reference Line", "010PRL", "Acc-RFQ-010PRL", 3, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "Approved by Daniel Piso"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + subsystem010PRL = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemRFQ, + "RFQ-010", "010", "Acc-RFQ-010", 3, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "Approved by Daniel Piso"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + subsystem010 = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemRFQ, + "Power switch board 01", "N1U1", "Acc-RFQ-N1U1", 3, + "Electrical power cabinets", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "Approved by Daniel Piso"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + subsystemN1U1 = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "Electromagnetic Resonators", "EMR", "EMR", 1, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "empty"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + disciplineEMR = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineEMR, + "Control", null, "EMR", 2, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "These names are needed now, so I am approving, but please add a description to these later."); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + deviceGroupEMR = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupEMR, + "Flow Switch", "FS", "EMR-FS", 3, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "Approve names added from misc device group"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + deviceTypeFS = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupEMR, + "RF Antenna", "RFA", "EMR-RFA", 3, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "Approve names added from misc device group"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + deviceTypeRFA = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupEMR, + "Temperature Transmitter", "TT", "EMR-TT", 3, + "empty", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "Approve names added from misc device group"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + deviceTypeTT = approvedStructureElement.getUuid(); + } + + @Test + public void checkCreate() { + // purpose + // test conditions for create name + // not create itself + // + // what - combination of + // read exists name + // read is legacy name + // read is valid to create + // read validate create + + try { + ObjectMapper mapper = new ObjectMapper(); + NameElement nameElement = new NameElement(); + String[] response = null; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/exists/RFQ-010PRL:EMR-RFA-051"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/islegacy/RFQ-010PRL:EMR-RFA-051"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/isvalidtocreate/RFQ-010PRL:EMR-RFA-051"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + // validate create + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setSubsystem(subsystem010PRL); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setName("RFQ-010PRL"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // ---------- + + nameElement.setName("RFQ-010PRL:EMR-RFA-051"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setIndex("051"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setDevicetype(deviceTypeRFA); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // ---------- + + nameElement.setSubsystem(null); + nameElement.setName(null); + nameElement.setIndex(null); + nameElement.setDevicetype(null); + + // ---------- + + nameElement.setSystem(systemRFQ); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setName("RFQ"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // ---------- + + nameElement.setName("RFQ:EMR-RFA-051"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setIndex("051"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setDevicetype(deviceTypeRFA); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // ---------- + + nameElement.setSystem(null); + nameElement.setName(null); + nameElement.setIndex(null); + nameElement.setDevicetype(null); + + // ---------- + + nameElement.setSystemgroup(systemGroupAcc); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setName("Acc"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // ---------- + + nameElement.setName("Acc:EMR-RFA-051"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setIndex("051"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + nameElement.setDevicetype(deviceTypeTT); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setDevicetype(deviceTypeRFA); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void create() { + // purpose + // test create name + // + // what - combination of + // create create names + // read exists name + // read is legacy name + // read is valid to create + // read validate create + // + // note + // with and without index + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + NameElement nameElement = null; + NameElement nameElement2 = null; + NameElement createdNameElement = null; + + nameElement = new NameElement( + null, + null, null, subsystem010PRL, deviceTypeRFA, + "RFQ-010PRL", "EMR-RFA", + "052", "RFQ-010PRL:EMR-RFA-052", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + + nameElement2 = new NameElement( + null, + null, null, subsystem010PRL, deviceTypeRFA, + "RFQ-010PRL", "EMR-RFA", + "062", "RFQ-010PRL:EMR-RFA-061", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/exists/RFQ-010PRL:EMR-RFA-052"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/islegacy/RFQ-010PRL:EMR-RFA-052"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/isvalidtocreate/RFQ-010PRL:EMR-RFA-052"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + ","+mapper.writeValueAsString(nameElement2) +"]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // create + createdNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement = createdNameElement; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/exists/RFQ-010PRL:EMR-RFA-052"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/islegacy/RFQ-010PRL:EMR-RFA-052"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/isvalidtocreate/RFQ-010PRL:EMR-RFA-052"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatecreate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkUpdate() { + // purpose + // test conditions for update name + // not update + // + // what - combination of + // create create names + // read validate create + // read validate update + // + // note + // create in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + NameElement nameElement = null; + NameElement createdNameElement = null; + + nameElement = new NameElement( + null, + null, null, subsystem010PRL, deviceTypeRFA, + "RFQ-010PRL", "EMR-RFA", + "053", "RFQ-010PRL:EMR-RFA-053", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement = createdNameElement; + + // validate update + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setDescription("checkUpdate"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setComment("checkUpdate"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setSubsystem(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setSystemgroup(systemGroupAcc); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setSystemgroup(null); + nameElement.setSystem(systemRFQ); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setSystem(null); + nameElement.setSubsystem(subsystemN1U1); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setSubsystem(subsystem010PRL); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setDevicetype(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setDevicetype(deviceGroupEMR); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setDevicetype(deviceTypeFS); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setDevicetype(deviceTypeTT); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setDevicetype(deviceTypeRFA); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setName("RFQ-010PRL:EMR-RFA-053"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setIndex(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setIndex("053"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // system structure, device structure not used for validation + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void update() { + // purpose + // test update name + // + // what - combination of + // create create names + // read validate create + // read validate update + // update update names + // + // note + // create in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + NameElement nameElement = null; + NameElement createdNameElement = null; + NameElement updatedNameElement = null; + + nameElement = new NameElement( + null, + null, null, subsystem010PRL, deviceTypeRFA, + "RFQ-010PRL", "EMR-RFA", + "054", "RFQ-010PRL:EMR-RFA-054", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement = createdNameElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setDescription("updated description"); + nameElement.setComment("updated comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // update + updatedNameElement = ITUtilNameStructureElement.assertUpdate(nameElement); + nameElement = updatedNameElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validateupdate", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkDelete() { + // purpose + // test conditions for delete name + // not delete + // + // what - combination of + // create create names + // read validate create + // read validate delete + // + // note + // create in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + NameElement nameElement = null; + NameElement createdNameElement = null; + + nameElement = new NameElement( + null, + null, null, subsystem010PRL, deviceTypeRFA, + "RFQ-010PRL", "EMR-RFA", + "055", "RFQ-010PRL:EMR-RFA-055", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement = createdNameElement; + + // validate delete + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setDescription("checkDelete"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setComment("checkDelete"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setSystemgroup(systemGroupAcc); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setSystemgroup(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setSystem(systemRFQ); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setSystem(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setSubsystem(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + nameElement.setSubsystem(subsystem010PRL); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // device type not used for validation + + nameElement.setDevicetype(deviceTypeRFA); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // name, index not used for validation + + // system structure, device structure not used for validation + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void delete() { + // purpose + // test delete name + // + // what - combination of + // create create names + // read validate create + // read validate update + // delete delete names + // + // note + // create in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + NameElement nameElement = null; + NameElement createdNameElement = null; + NameElement deletedNameElement = null; + + nameElement = new NameElement( + null, + null, null, subsystem010PRL, deviceTypeRFA, + "RFQ-010PRL", "EMR-RFA", + "056", "RFQ-010PRL:EMR-RFA-056", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement = createdNameElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + nameElement.setDescription("deleted description"); + nameElement.setComment("deleted comment"); + nameElement.setDeleted(Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // delete + deletedNameElement = ITUtilNameStructureElement.assertDelete(nameElement); + nameElement = deletedNameElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.NAMES, "/validatedelete", "[" + mapper.writeValueAsString(nameElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryDeleted() { + // purpose + // test read names in various ways for create + // search + // ( latest ) + // history + // deleted + // + // note + // create (and more) to read (with content) + + NameElement nameElement = null; + NameElement responseNameElement = null; + UUID uuid, uuid2 = null; + + NameElement nameElement1, nameElement7, nameElement8 = null; + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "001", "RFQ-010:EMR-FS-001", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + + // create + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement1 = responseNameElement; + uuid = responseNameElement.getUuid(); + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "002", "RFQ-010:EMR-FS-002", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + uuid2 = responseNameElement.getUuid(); + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "003", "RFQ-010:EMR-FS-003", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "004", "RFQ-010:EMR-FS-004", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "005", "RFQ-010:EMR-FS-005", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "006", "RFQ-010:EMR-FS-006", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "007", "RFQ-010:EMR-FS-007", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement7 = responseNameElement; + + nameElement = new NameElement( + null, + null, null, subsystem010, deviceTypeFS, + "RFQ-010", "EMR-FS", + "008", "RFQ-010:EMR-FS-008", + "description", Status.APPROVED, Boolean.TRUE, Boolean.FALSE, + null, "test who", "comment"); + responseNameElement = ITUtilNameStructureElement.assertCreate(nameElement); + nameElement8 = responseNameElement; + + // update element 1 twice + nameElement = nameElement1; + nameElement.setDescription("updated description"); + nameElement.setComment("updated comment"); + + responseNameElement = ITUtilNameStructureElement.assertUpdate(nameElement); + nameElement = responseNameElement; + + nameElement.setDescription("updated description again"); + nameElement.setComment("updated comment again"); + + responseNameElement = ITUtilNameStructureElement.assertUpdate(nameElement); + nameElement = responseNameElement; + + // delete element 7, 8 + responseNameElement = ITUtilNameStructureElement.assertDelete(nameElement7); + responseNameElement = ITUtilNameStructureElement.assertDelete(nameElement8); + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + NameElement[] readNameElements = null; + + // read + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 8); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "?queryFields=UUID&queryValues=" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "?queryFields=NAMEEQUIVALENCE&queryValues=RFQ-10%25"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 8); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "?deleted=false"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 6); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "?deleted=true"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 2); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/RFQ-010:EMR-FS-005"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/RFQ-010:EMR-FS-0"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/RFQ-010:EMR-FS-0__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 6); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/RFQ-010:EMR-FS-0%25"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 6); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/systemstructure/RFQ-010"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 6); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/systemstructure/RFQ-0"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/systemstructure/RFQ-0__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 6); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/systemstructure/RFQ-N1U1"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/devicestructure/EMR-FS"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 6); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/devicestructure/EMR-F"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/devicestructure/EMR-F_"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + assertTrue(readNameElements.length >= 6); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/devicestructure/EMR-TT"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 0); + + // history + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/history/" + systemRFQ.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/history/" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 3); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/history/" + uuid2.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readNameElements = mapper.readValue(response[1], NameElement[].class); + ITUtilNameStructureElement.assertContentLength(readNameElements, 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void equivalenceName() { + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/equivalence/A2T-010PRL:RFS-PRLTap-054"); + ITUtil.assertResponseLength2CodeOKContent(response, "A2T-10PR1:RFS-PR1TAP-54"); + } catch (IOException e) { + fail(); + } + } + + @Test + public void existsName() { + ObjectMapper mapper = new ObjectMapper(); + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/exists/A2T-010PRL:RFS-PRLTap-054"); + ITUtil.assertResponseLength2CodeOK(response); + ResponseBoolean responseEntity = mapper.readValue(response[1], ResponseBoolean.class); + assertNotNull(responseEntity); + assertFalse(responseEntity.getResponse()); + } catch (IOException e) { + fail(); + } + } + + @Test + public void isLegacyName() { + ObjectMapper mapper = new ObjectMapper(); + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/islegacy/A2T-010PRL:RFS-PRLTap-054"); + ITUtil.assertResponseLength2CodeOK(response); + ResponseBoolean responseEntity = mapper.readValue(response[1], ResponseBoolean.class); + assertNotNull(responseEntity); + assertFalse(responseEntity.getResponse()); + } catch (IOException e) { + fail(); + } + } + + @Test + public void isValidToCreateName() { + ObjectMapper mapper = new ObjectMapper(); + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_NAMES + "/isvalidtocreate/A2T-010PRL:RFS-PRLTap-054"); + ITUtil.assertResponseLength2CodeOK(response); + ResponseBoolean responseEntity = mapper.readValue(response[1], ResponseBoolean.class); + assertNotNull(responseEntity); + assertFalse(responseEntity.getResponse()); + } catch (IOException e) { + fail(); + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java b/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java new file mode 100644 index 00000000..7055ffc5 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java @@ -0,0 +1,2121 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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.UUID; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose.yml / Dockerfile. + * + * <p> + * Focus of this class is structures endpoint and device group. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class StructuresDeviceGroupIT { + + // note + // StructureElement - when, who, comment - depend on requested or processed + // requested, requested by, requested comment + // processed, processed by, processed comment + // if less than a second between requested and processed, then considered one entry with processed + // history + // mnemonic path does not make same sense for history + // (very) tricky to find mnemonic path for uuid at proper time (history) + // therefore empty mnemonic path for history for structure + // one history entry if less than one second between requested and processed, otherwise two history entries + // attributes for entry for operations - create, update, delete, approve, cancel, reject + // some set client side, others set server side + // client side + // type, uuid, parent uuid, name, mnemonic, description, comment + // may be set client side for test purposes + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + private static UUID disciplineUuid = null; + private static UUID discipline2Uuid = null; + + @BeforeAll + public static void initAll() { + // init discipline + + StructureElement structureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Di", "Di", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + disciplineUuid = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Di2", "Di2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + discipline2Uuid = approvedStructureElement.getUuid(); + } + + @Test + public void checkCreate() { + // purpose + // test conditions for create device group + // not create itself + // + // what - combination of + // read exists in structure + // read is valid to create + // read validate create + + try { + ObjectMapper mapper = new ObjectMapper(); + StructureElement structureElement = new StructureElement(); + String[] response = null; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/exists/DEVICEGROUP/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/DEVICEGROUP/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setType(Type.DEVICEGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setParent(disciplineUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICEGROUP); + structureElement.setMnemonic("Cc"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createApprove() { + // purpose + // test create and approve system + // + // what - combination of + // create create structures + // read validate create + // read validate approve + // patch approve structures + // + // note + // create in order to approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createCancel() { + // purpose + // test create and cancel system + // + // what - combination of + // create create structures + // read validate create + // read validate cancel + // patch cancel structures + // + // note + // create in order to cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement cancelledStructureElement = null; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createReject() { + // purpose + // test create and reject system + // + // what - combination of + // create create structures + // read validate create + // read validate reject + // patch reject structures + // + // note + // create in order to reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement rejectedStructureElement = null; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkUpdate() { + // purpose + // test conditions for update device group + // not update + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // patch approve structures + // + // note + // create, approve in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate update + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICEGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(disciplineUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic("Cu"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateApprove() { + // purpose + // test update and approve device group + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // update update structures + // patch approve structures + // + // note + // create, approve in order to update, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateCancel() { + // purpose + // test update and cancel device group + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate cancel + // update update structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to update, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update cancel check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateReject() { + // purpose + // test update and reject device group + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate reject + // update update structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to update, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkDelete() { + // purpose + // test conditions for delete device group + // not delete + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // patch approve structures + // + // note + // create, approve in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate delete + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICEGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(disciplineUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic("Cd"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteApprove() { + // purpose + // test delete and approve device group + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // delete delete structures + // patch approve structures + // + // note + // create, approve in order to delete, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + structureElement.setDeleted(Boolean.TRUE); + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteCancel() { + // purpose + // test delete and cancel device group + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate cancel + // update delete structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to delete, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update delete check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteReject() { + // purpose + // test delete and reject device group + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate reject + // update delete structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to delete, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryApprove() { + // purpose + // test read system group in various ways for create, approve + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement approvedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?queryFields=UUID&queryValues=" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryCancel() { + // purpose + // test read system group in various ways for create, cancel + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement cancelledStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?queryFields=UUID&queryValues=" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryReject() { + // purpose + // test read system group in various ways for create, reject + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement rejectedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLengthOne(readStructureElements); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?queryFields=UUID&queryValues=" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchStatusDeletedChildren() { + // purpose + // test read system group in various ways + // status + // ( latest ) + // deleted + // children + // + // what + // entries with different statuses + // + // note + // create (and more) to read (with content) + // querying for Status.APPROVED means latest approved + + StructureElement structureElement = null; + StructureElement responseStructureElement = null; + UUID uuid = null; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + uuid = responseStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + String description2 = "some other description"; + String comment2 = "some other comment"; + String description3 = "more description"; + String comment3 = "more comment"; + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, discipline2Uuid, + "name", null, "Di2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + // 60 device group entries + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] readStructureElements = null; + + // from first structure element + assertNotNull(uuid); + + // 30, not 45 or 60 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + // 5, not 10 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + // 20, not 35 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=APPROVED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + // 0, not 5 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=CANCELLED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + // 5, not 10 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=REJECTED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + // 25, not 30 or 45 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?statuses=PENDING&statuses=APPROVED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 25); + + // 15, not 30 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=false&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + // 0, not 5 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=false&statuses=PENDING&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=false&statuses=APPROVED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + // 0, not 5 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=false&statuses=CANCELLED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + // 0, not 5 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=false&statuses=REJECTED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + // 15, not 20 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=false&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=true&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=true&statuses=PENDING&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=true&statuses=APPROVED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=true&statuses=CANCELLED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=true&statuses=REJECTED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICEGROUP?deleted=true&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONICPATH&queryValues=Di2"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/DEVICEGROUP/" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/DISCIPLINE/" + disciplineUuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void equivalenceMnemonic() { + // purpose + // test mnemonic equivalence + // + // what + // read equivalence mnemonic + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/equivalence/Dg"); + ITUtil.assertResponseLength2CodeOKContent(response, "DG"); + } catch (IOException e) { + fail(); + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java b/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java new file mode 100644 index 00000000..3f6891d2 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java @@ -0,0 +1,2129 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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.UUID; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose.yml / Dockerfile. + * + * <p> + * Focus of this class is structures endpoint and device type. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class StructuresDeviceTypeIT { + + // note + // StructureElement - when, who, comment - depend on requested or processed + // requested, requested by, requested comment + // processed, processed by, processed comment + // if less than a second between requested and processed, then considered one entry with processed + // history + // mnemonic path does not make same sense for history + // (very) tricky to find mnemonic path for uuid at proper time (history) + // therefore empty mnemonic path for history for structure + // one history entry if less than one second between requested and processed, otherwise two history entries + // attributes for entry for operations - create, update, delete, approve, cancel, reject + // some set client side, others set server side + // client side + // type, uuid, parent uuid, name, mnemonic, description, comment + // may be set client side for test purposes + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + private static UUID disciplineUuid = null; + private static UUID deviceGroupUuid = null; + + @BeforeAll + public static void initAll() { + // init discipline, device group + + StructureElement structureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Di", "Di", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + disciplineUuid = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DEVICEGROUP, null, disciplineUuid, + "name", null, "Di", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + deviceGroupUuid = approvedStructureElement.getUuid(); + } + + @Test + public void checkCreate() { + // purpose + // test conditions for create device type + // not create itself + // + // what - combination of + // read exists in structure + // read is valid to create + // read validate create + + try { + ObjectMapper mapper = new ObjectMapper(); + StructureElement structureElement = new StructureElement(); + String[] response = null; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/exists/DEVICETYPE/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/DEVICETYPE/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/DEVICETYPE/Db-Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/DEVICETYPE/Di-Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setType(Type.DEVICETYPE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setParent(deviceGroupUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setMnemonic("Cc"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createApprove() { + // purpose + // test create and approve system + // + // what - combination of + // create create structures + // read validate create + // read validate approve + // patch approve structures + // + // note + // create in order to approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Ca", "Di-Ca", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createCancel() { + // purpose + // test create and cancel system + // + // what - combination of + // create create structures + // read validate create + // read validate cancel + // patch cancel structures + // + // note + // create in order to cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement cancelledStructureElement = null; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Cc", "Di-Cc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createReject() { + // purpose + // test create and reject system + // + // what - combination of + // create create structures + // read validate create + // read validate reject + // patch reject structures + // + // note + // create in order to reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement rejectedStructureElement = null; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Cr", "Di-Cr", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkUpdate() { + // purpose + // test conditions for update device type + // not update + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // patch approve structures + // + // note + // create, approve in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Cu", "Di-Cu", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate update + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SUBSYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICETYPE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(deviceGroupUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cu"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateApprove() { + // purpose + // test update and approve device type + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // update update structures + // patch approve structures + // + // note + // create, approve in order to update, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Ua", "Di-Ua", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateCancel() { + // purpose + // test update and cancel device type + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate cancel + // update update structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to update, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Uc", "Di-Uc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update cancel check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateReject() { + // purpose + // test update and reject device type + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate reject + // update update structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to update, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Ur", "Di-Ur", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkDelete() { + // purpose + // test conditions for delete device type + // not delete + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // patch approve structures + // + // note + // create, approve in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Cd", "Di-Cd", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate delete + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SUBSYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICETYPE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(deviceGroupUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cd"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteApprove() { + // purpose + // test delete and approve device type + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // delete delete structures + // patch approve structures + // + // note + // create, approve in order to delete, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Da", "Di-Da", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + structureElement.setDeleted(Boolean.TRUE); + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteCancel() { + // purpose + // test delete and cancel device type + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate cancel + // update delete structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to delete, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Dc", "Di-Dc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update delete check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteReject() { + // purpose + // test delete and reject device type + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate reject + // update delete structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to delete, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Dr", "Di-Dr", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryApprove() { + // purpose + // test read system group in various ways for create, approve + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement approvedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Rsha", "Di-Rsha", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di-Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?queryFields=UUID&queryValues=" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di-Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryCancel() { + // purpose + // test read system group in various ways for create, cancel + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement cancelledStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Rshc", "Di-Rshc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di-Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?queryFields=UUID&queryValues=" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di-Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryReject() { + // purpose + // test read system group in various ways for create, reject + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement rejectedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "Rshr", "Di-Rshr", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLengthOne(readStructureElements); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di-Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?queryFields=UUID&queryValues=" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Di-Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchStatusDeletedChildren() { + // purpose + // test read system group in various ways + // status + // ( latest ) + // deleted + // children + // + // what + // entries with different statuses + // + // note + // create (and more) to read (with content) + // querying for Status.APPROVED means latest approved + + StructureElement structureElement = null; + StructureElement responseStructureElement = null; + UUID uuid = null; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AA1", "Di-AA1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + uuid = responseStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AA2", "Di-AA2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AA3", "Di-AA3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AA4", "Di-AA4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AA5", "Di-AA5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AB1", "Di-AB1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AB2", "Di-AB2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AB3", "Di-AB3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AB4", "Di-AB4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AB5", "Di-AB5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AC1", "Di-AC1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AC2", "Di-AC2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AC3", "Di-AC3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AC4", "Di-AC4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AC5", "Di-AC5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AD1", "Di-AD1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AD2", "Di-AD2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AD3", "Di-AD3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AD4", "Di-AD4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AD5", "Di-AD5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + String description2 = "some other description"; + String comment2 = "some other comment"; + String description3 = "more description"; + String comment3 = "more comment"; + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AE1", "Di-AE1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AE2", "Di-AE2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AE3", "Di-AE3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AE4", "Di-AE4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AE5", "Di-AE5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AF1", "Di-AF1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AF2", "Di-AF2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AF3", "Di-AF3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AF4", "Di-AF4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AF5", "Di-AF5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AG1", "Di-AG1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AG2", "Di-AG2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AG3", "Di-AG3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AG4", "Di-AG4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DEVICETYPE, null, deviceGroupUuid, + "name", "AG5", "Di-AG5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + // 60 device type entries + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] readStructureElements = null; + + // from first structure element + assertNotNull(uuid); + + // 45, not 60 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 45); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 20, not 35 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 30, not 45 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=false&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=false&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=false&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=false&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=false&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=false&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=true&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=true&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=true&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=true&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=true&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DEVICETYPE?deleted=true&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/DEVICETYPE/" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/DEVICEGROUP/" + deviceGroupUuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/DISCIPLINE/" + disciplineUuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void equivalenceMnemonic() { + // purpose + // test mnemonic equivalence + // + // what + // read equivalence mnemonic + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/equivalence/Dt"); + ITUtil.assertResponseLength2CodeOKContent(response, "DT"); + } catch (IOException e) { + fail(); + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java b/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java new file mode 100644 index 00000000..2d5c05d9 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java @@ -0,0 +1,2024 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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.UUID; + +import org.junit.jupiter.api.Test; +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose.yml / Dockerfile. + * + * <p> + * Focus of this class is structures endpoint and discipline. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class StructuresDisciplineIT { + + // note + // StructureElement - when, who, comment - depend on requested or processed + // requested, requested by, requested comment + // processed, processed by, processed comment + // if less than a second between requested and processed, then considered one entry with processed + // history + // mnemonic path does not make same sense for history + // (very) tricky to find mnemonic path for uuid at proper time (history) + // therefore empty mnemonic path for history for structure + // one history entry if less than one second between requested and processed, otherwise two history entries + // attributes for entry for operations - create, update, delete, approve, cancel, reject + // some set client side, others set server side + // client side + // type, uuid, parent uuid, name, mnemonic, description, comment + // may be set client side for test purposes + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + @Test + public void checkCreate() { + // purpose + // test conditions for create discipline + // not create itself + // + // what - combination of + // read exists in structure + // read is valid to create + // read validate create + + try { + ObjectMapper mapper = new ObjectMapper(); + StructureElement structureElement = new StructureElement(); + String[] response = null; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/exists/DISCIPLINE/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/DISCIPLINE/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setType(Type.DISCIPLINE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setMnemonic("Cc"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createApprove() { + // purpose + // test create and approve discipline + // + // what - combination of + // create create structures + // read validate create + // read validate approve + // patch approve structures + // + // note + // create in order to approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Ca", "Ca", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createCancel() { + // purpose + // test create and cancel discipline + // + // what - combination of + // create create structures + // read validate create + // read validate cancel + // patch cancel structures + // + // note + // create in order to cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement cancelledStructureElement = null; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Cc", "Cc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createReject() { + // purpose + // test create and reject discipline + // + // what - combination of + // create create structures + // read validate create + // read validate reject + // patch reject structures + // + // note + // create in order to reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement rejectedStructureElement = null; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Cr", "Cr", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkUpdate() { + // purpose + // test conditions for update discipline + // not update + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // patch approve structures + // + // note + // create, approve in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Cu", "Cu", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate update + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEMGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DISCIPLINE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cu"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateApprove() { + // purpose + // test update and approve discipline + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // update update structures + // patch approve structures + // + // note + // create, approve in order to update, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Ua", "Ua", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateCancel() { + // purpose + // test update and cancel discipline + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate cancel + // update update structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to update, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Uc", "Uc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update cancel check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateReject() { + // purpose + // test update and reject discipline + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate reject + // update update structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to update, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Ur", "Ur", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkDelete() { + // purpose + // test conditions for delete discipline + // not delete + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // patch approve structures + // + // note + // create, approve in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Cd", "Cd", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate delete + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEMGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DISCIPLINE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cd"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteApprove() { + // purpose + // test delete and approve discipline + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // delete delete structures + // patch approve structures + // + // note + // create, approve in order to delete, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Da", "Da", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + structureElement.setDeleted(Boolean.TRUE); + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteCancel() { + // purpose + // test delete and cancel discipline + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate cancel + // update delete structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to delete, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Dc", "Dc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update delete check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteReject() { + // purpose + // test delete and reject discipline + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate reject + // update delete structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to delete, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Dr", "Dr", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryApprove() { + // purpose + // test read discipline in various ways for create, approve + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement approvedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Rsha", "Rsha", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?queryFields=UUID&queryValues=" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryCancel() { + // purpose + // test read discipline in various ways for create, cancel + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement cancelledStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Rshc", "Rshc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?queryFields=UUID&queryValues=" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryReject() { + // purpose + // test read discipline in various ways for create, reject + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement rejectedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "Rshr", "Rshr", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLengthOne(readStructureElements); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?queryFields=UUID&queryValues=" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchStatusDeletedChildren() { + // purpose + // test read system group in various ways + // status + // ( latest ) + // deleted + // children + // + // what + // entries with different statuses + // + // note + // create (and more) to read (with content) + // querying for Status.APPROVED means latest approved + + StructureElement structureElement = null; + StructureElement responseStructureElement = null; + UUID uuid = null; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AA1", "AA1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + uuid = responseStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AA2", "AA2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AA3", "AA3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AA4", "AA4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AA5", "AA5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AB1", "AB1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AB2", "AB2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AB3", "AB3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AB4", "AB4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AB5", "AB5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AC1", "AC1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AC2", "AC2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AC3", "AC3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AC4", "AC4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AC5", "AC5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AD1", "AD1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AD2", "AD2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AD3", "AD3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AD4", "AD4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AD5", "AD5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + String description2 = "some other description"; + String comment2 = "some other comment"; + String description3 = "more description"; + String comment3 = "more comment"; + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AE1", "AE1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AE2", "AE2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AE3", "AE3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AE4", "AE4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AE5", "AE5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AF1", "AF1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AF2", "AF2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AF3", "AF3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AF4", "AF4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AF5", "AF5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AG1", "AG1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AG2", "AG2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AG3", "AG3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AG4", "AG4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.DISCIPLINE, null, null, + "name", "AG5", "AG5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + // 60 discipline entries + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] readStructureElements = null; + + // from first structure element + assertNotNull(uuid); + + // 45, not 60 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 45); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 20, not 35 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 30, not 45 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=false&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=false&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=false&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=false&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=false&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=false&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=true&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=true&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=true&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=true&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=true&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/DISCIPLINE?deleted=true&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/DISCIPLINE/" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void equivalenceMnemonic() { + // purpose + // test mnemonic equivalence + // + // what + // read equivalence mnemonic + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/equivalence/Di"); + ITUtil.assertResponseLength2CodeOKContent(response, "D1"); + } catch (IOException e) { + fail(); + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java b/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java new file mode 100644 index 00000000..a82133f2 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java @@ -0,0 +1,2145 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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.UUID; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose.yml / Dockerfile. + * + * <p> + * Focus of this class is structures endpoint and subsystem. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class StructuresSubsystemIT { + + // note + // StructureElement - when, who, comment - depend on requested or processed + // requested, requested by, requested comment + // processed, processed by, processed comment + // if less than a second between requested and processed, then considered one entry with processed + // history + // mnemonic path does not make same sense for history + // (very) tricky to find mnemonic path for uuid at proper time (history) + // therefore empty mnemonic path for history for structure + // one history entry if less than one second between requested and processed, otherwise two history entries + // attributes for entry for operations - create, update, delete, approve, cancel, reject + // some set client side, others set server side + // client side + // type, uuid, parent uuid, name, mnemonic, description, comment + // may be set client side for test purposes + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + private static UUID systemGroupUuid = null; + private static UUID systemUuid = null; + + @BeforeAll + public static void initAll() { + // init system group, system + + StructureElement structureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Sg", "Sg", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + systemGroupUuid = approvedStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Sys", "Sg-Sys", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + systemUuid = approvedStructureElement.getUuid(); + } + + @Test + public void checkCreate() { + // purpose + // test conditions for create subsystem + // not create itself + // + // what - combination of + // create create structures + // read exists in structure + // read is valid to create + // read validate create + // + // StructureElement attributes + // type, name, mnemonic, description, comment + + try { + ObjectMapper mapper = new ObjectMapper(); + StructureElement structureElement = new StructureElement(); + String[] response = null; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/exists/SUBSYSTEM/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SUBSYSTEM/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SUBSYSTEM/Sys-Sys"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SUBSYSTEM/Sys-Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SUBSYSTEM/Sg-Sys-Sg"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SUBSYSTEM/Sg-Sys-Sys"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SUBSYSTEM/Sg-Sys-Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setType(Type.SUBSYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setParent(systemUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setMnemonic("Cc"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createApprove() { + // purpose + // test create and approve subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate approve + // patch approve structures + // + // note + // create in order to approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Ca", "Sg-Sys-Ca", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createCancel() { + // purpose + // test create and cancel subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate cancel + // patch cancel structures + // + // note + // create in order to cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement cancelledStructureElement = null; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Cc", "Sg-Sys-Cc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createReject() { + // purpose + // test create and reject subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate reject + // patch reject structures + // + // note + // create in order to reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement rejectedStructureElement = null; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Cr", "Sg-Sys-Cr", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkUpdate() { + // purpose + // test conditions for update subsystem + // not update + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // patch approve structures + // + // note + // create, approve in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Cu", "Sg-Sys-Cu", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate update + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICETYPE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SUBSYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(systemUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cu"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateApprove() { + // purpose + // test update and approve subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // update update structures + // patch approve structures + // + // note + // create, approve in order to update, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Ua", "Sg-Sys-Ua", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateCancel() { + // purpose + // test update and cancel subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate cancel + // update update structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to update, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Uc", "Sg-Sys-Uc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update cancel check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateReject() { + // purpose + // test update and reject subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate reject + // update update structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to update, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Ur", "Sg-Sys-Ur", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkDelete() { + // purpose + // test conditions for delete subsystem + // not delete + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // patch approve structures + // + // note + // create, approve in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Cd", "Sg-Sys-Cd", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate delete + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICETYPE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SUBSYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(systemGroupUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cd"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteApprove() { + // purpose + // test delete and approve subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // delete delete structures + // patch approve structures + // + // note + // create, approve in order to delete, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Da", "Sg-Sys-Da", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + structureElement.setDeleted(Boolean.TRUE); + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteCancel() { + // purpose + // test delete and cancel subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate cancel + // update delete structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to delete, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Dc", "Sg-Sys-Dc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update delete check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteReject() { + // purpose + // test delete and reject subsystem + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate reject + // update delete structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to delete, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Dr", "Sg-Sys-Dr", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryApprove() { + // purpose + // test read system group in various ways for create, approve + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement approvedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Rsha", "Sg-Sys-Rsha", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Sys-Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?queryFields=UUID&queryValues=" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Sys-Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryCancel() { + // purpose + // test read system group in various ways for create, cancel + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement cancelledStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Rshc", "Sg-Sys-Rshc", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Sys-Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?queryFields=UUID&queryValues=" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Sys-Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryReject() { + // purpose + // test read system group in various ways for create, reject + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement rejectedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "Rshr", "Sg-Sys-Rshr", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLengthOne(readStructureElements); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Sys-Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?queryFields=UUID&queryValues=" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Sys-Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchStatusDeletedChildren() { + // purpose + // test read system group in various ways + // status + // ( latest ) + // deleted + // children + // + // what + // entries with different statuses + // + // note + // create (and more) to read (with content) + // querying for Status.APPROVED means latest approved + + StructureElement structureElement = null; + StructureElement responseStructureElement = null; + UUID uuid = null; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AA1", "Sg-Sys-AA1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + uuid = responseStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AA2", "Sg-Sys-AA2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AA3", "Sg-Sys-AA3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AA4", "Sg-Sys-AA4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AA5", "Sg-Sys-AA5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AB1", "Sg-Sys-AB1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AB2", "Sg-Sys-AB2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AB3", "Sg-Sys-AB3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AB4", "Sg-Sys-AB4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AB5", "Sg-Sys-AB5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AC1", "Sg-Sys-AC1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AC2", "Sg-Sys-AC2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AC3", "Sg-Sys-AC3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AC4", "Sg-Sys-AC4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AC5", "Sg-Sys-AC5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AD1", "Sg-Sys-AD1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AD2", "Sg-Sys-AD2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AD3", "Sg-Sys-AD3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AD4", "Sg-Sys-AD4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AD5", "Sg-Sys-AD5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + String description2 = "some other description"; + String comment2 = "some other comment"; + String description3 = "more description"; + String comment3 = "more comment"; + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AE1", "Sg-Sys-AE1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AE2", "Sg-Sys-AE2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AE3", "Sg-Sys-AE3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AE4", "Sg-Sys-AE4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AE5", "Sg-Sys-AE5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AF1", "Sg-Sys-AF1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AF2", "Sg-Sys-AF2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AF3", "Sg-Sys-AF3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AF4", "Sg-Sys-AF4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AF5", "Sg-Sys-AF5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AG1", "Sg-Sys-AG1", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AG2", "Sg-Sys-AG2", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AG3", "Sg-Sys-AG3", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AG4", "Sg-Sys-AG4", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SUBSYSTEM, null, systemUuid, + "name", "AG5", "Sg-Sys-AG5", 3, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + // 60 subsystem entries + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] readStructureElements = null; + + // from first structure element + assertNotNull(uuid); + + // 45, not 60 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 45); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 20, not 35 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 30, not 45 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=false&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=false&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=false&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=false&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=false&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=false&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=true&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=true&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=true&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=true&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=true&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SUBSYSTEM?deleted=true&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/SUBSYSTEM/" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/SYSTEM/" + systemUuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/SYSTEMGROUP/" + systemGroupUuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void equivalenceMnemonic() { + // purpose + // test mnemonic equivalence + // + // what + // read equivalence mnemonic + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/equivalence/Sub"); + ITUtil.assertResponseLength2CodeOKContent(response, "SUB"); + } catch (IOException e) { + fail(); + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java b/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java new file mode 100644 index 00000000..f836428a --- /dev/null +++ b/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java @@ -0,0 +1,2070 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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.UUID; + +import org.junit.jupiter.api.Test; +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose.yml / Dockerfile. + * + * <p> + * Focus of this class is structures endpoint and system group. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class StructuresSystemGroupIT { + + // note + // StructureElement - when, who, comment - depend on requested or processed + // requested, requested by, requested comment + // processed, processed by, processed comment + // if less than a second between requested and processed, then considered one entry with processed + // history + // mnemonic path does not make same sense for history + // (very) tricky to find mnemonic path for uuid at proper time (history) + // therefore empty mnemonic path for history for structure + // one history entry if less than one second between requested and processed, otherwise two history entries + // attributes for entry for operations - create, update, delete, approve, cancel, reject + // some set client side, others set server side + // client side + // type, uuid, parent uuid, name, mnemonic, description, comment + // may be set client side for test purposes + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + @Test + public void checkCreate() { + // purpose + // test conditions for create system group + // not create itself + // + // what - combination of + // read exists in structure + // read is valid to create + // read validate create + // + // note + // with and without mnemonic + + try { + ObjectMapper mapper = new ObjectMapper(); + StructureElement structureElement = new StructureElement(); + String[] response = null; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/exists/SYSTEMGROUP/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SYSTEMGROUP/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + // validate create + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setType(Type.SYSTEMGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setMnemonic("Cc"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(""); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createApprove() { + // purpose + // test create and approve system group + // + // what - combination of + // create create structures + // read validate create + // read validate approve + // patch approve structures + // + // note + // create in order to approve + // with and without mnemonic + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement approvedStructureElement = null; + UUID uuid, uuid2, uuid3 = null; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Ca", "Ca", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + uuid = createdStructureElement.getUuid(); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name2", null, null, 1, + "description2", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment2"); + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + uuid2 = createdStructureElement.getUuid(); + + // create + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name3", null, null, 1, + "description3", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment3"); + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + uuid3 = createdStructureElement.getUuid(); + + assertNotEquals(uuid, uuid2); + assertNotEquals(uuid, uuid3); + assertNotEquals(uuid2, uuid3); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createCancel() { + // purpose + // test create and cancel system group + // + // what - combination of + // create create structures + // read validate create + // read validate cancel + // patch cancel structures + // + // note + // create in order to cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement cancelledStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Cc", "Cc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createReject() { + // purpose + // test create and reject system group + // + // what - combination of + // create create structures + // read validate create + // read validate reject + // patch reject structures + // + // note + // create in order to reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement rejectedStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Cr", "Cr", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkUpdate() { + // purpose + // test conditions for update system group + // not update + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // patch approve structures + // + // note + // create, approve in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Cu", "Cu", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate update + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DISCIPLINE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEMGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic("Cu"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateApprove() { + // purpose + // test update and approve system group + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // update update structures + // patch approve structures + // + // note + // create, approve in order to update, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Ua", "Ua", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setDescription("description update approve check"); + structureElement.setComment("comment update approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateCancel() { + // purpose + // test update and cancel system group + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate cancel + // update update structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to update, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Uc", "Uc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setDescription("description update cancel check"); + structureElement.setComment("comment update cancel check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateReject() { + // purpose + // test update and reject system group + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate reject + // update update structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to update, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Ur", "Ur", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setDescription("description update reject check"); + structureElement.setComment("comment update reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkDelete() { + // purpose + // test conditions for delete system group + // not delete + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // patch approve structures + // + // note + // create, approve in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Cd", "Cd", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate delete + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DISCIPLINE); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEMGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic("Cd"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteApprove() { + // purpose + // test delete and approve system group + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // delete delete structures + // patch approve structures + // + // note + // create, approve in order to delete, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Da", "Da", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + structureElement.setDeleted(Boolean.TRUE); + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteCancel() { + // purpose + // test delete and cancel system group + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate cancel + // update delete structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to delete, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Dc", "Dc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update delete check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteReject() { + // purpose + // test delete and reject system group + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate reject + // update delete structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to delete, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Dr", "Dr", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryApprove() { + // purpose + // test read system group in various ways for create, approve + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement approvedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Rsha", "Rsha", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?queryFields=UUID&queryValues=" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryCancel() { + // purpose + // test read system group in various ways for create, cancel + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement cancelledStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Rshc", "Rshc", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?queryFields=UUID&queryValues=" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryReject() { + // purpose + // test read system group in various ways for create, reject + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement rejectedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Rshr", "Rshr", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLengthOne(readStructureElements); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?queryFields=UUID&queryValues=" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchStatusDeletedChildren() { + // purpose + // test read system group in various ways + // status + // ( latest ) + // deleted + // children + // + // what + // entries with different statuses + // + // note + // create (and more) to read (with content) + // querying for Status.APPROVED means latest approved + + StructureElement structureElement = null; + StructureElement responseStructureElement = null; + UUID uuid = null; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AA1", "AA1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + uuid = responseStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AA2", "AA2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AA3", "AA3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AA4", "AA4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AA5", "AA5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AB1", "AB1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AB2", "AB2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AB3", "AB3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AB4", "AB4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AB5", "AB5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AC1", "AC1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AC2", "AC2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AC3", "AC3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AC4", "AC4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AC5", "AC5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AD1", "AD1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AD2", "AD2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AD3", "AD3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AD4", "AD4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AD5", "AD5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + String description2 = "some other description"; + String comment2 = "some other comment"; + String description3 = "more description"; + String comment3 = "more comment"; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AE1", "AE1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AE2", "AE2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AE3", "AE3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AE4", "AE4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AE5", "AE5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AF1", "AF1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AF2", "AF2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AF3", "AF3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AF4", "AF4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AF5", "AF5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AG1", "AG1", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AG2", "AG2", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AG3", "AG3", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AG4", "AG4", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "AG5", "AG5", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + // 60 system group entries + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] readStructureElements = null; + + // from first structure element + assertNotNull(uuid); + + // 45, not 60 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 45); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 20, not 35 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 30, not 45 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=false&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=false&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=false&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=false&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=false&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=false&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=true&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=true&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=true&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=true&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=true&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEMGROUP?deleted=true&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/SYSTEMGROUP/" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void equivalenceMnemonic() { + // purpose + // test mnemonic equivalence + // + // what + // read equivalence mnemonic + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/equivalence/Sg"); + ITUtil.assertResponseLength2CodeOKContent(response, "SG"); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + +} diff --git a/src/test/java/org/openepics/names/docker/StructuresSystemIT.java b/src/test/java/org/openepics/names/docker/StructuresSystemIT.java new file mode 100644 index 00000000..2c16d0f0 --- /dev/null +++ b/src/test/java/org/openepics/names/docker/StructuresSystemIT.java @@ -0,0 +1,2126 @@ +/* + * Copyright (C) 2022 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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.UUID; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.openepics.names.docker.ITUtil.AuthorizationChoice; +import org.openepics.names.docker.ITUtil.EndpointChoice; +import org.openepics.names.rest.beans.Status; +import org.openepics.names.rest.beans.StructureElement; +import org.openepics.names.rest.beans.Type; +import org.openepics.names.util.response.Response; +import org.openepics.names.util.response.ResponseBoolean; +import org.openepics.names.util.response.ResponseBooleanList; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Integration tests for Naming and PostgreSQL that make use of existing dockerization + * with docker-compose.yml / Dockerfile. + * + * <p> + * Focus of this class is structures endpoint and system. + * </p> + * + * @author Lars Johansson + */ +@Testcontainers +public class StructuresSystemIT { + + // note + // StructureElement - when, who, comment - depend on requested or processed + // requested, requested by, requested comment + // processed, processed by, processed comment + // if less than a second between requested and processed, then considered one entry with processed + // history + // mnemonic path does not make same sense for history + // (very) tricky to find mnemonic path for uuid at proper time (history) + // therefore empty mnemonic path for history for structure + // one history entry if less than one second between requested and processed, otherwise two history entries + // attributes for entry for operations - create, update, delete, approve, cancel, reject + // some set client side, others set server side + // client side + // type, uuid, parent uuid, name, mnemonic, description, comment + // may be set client side for test purposes + + @Container + public static final DockerComposeContainer<?> ENVIRONMENT = + new DockerComposeContainer<>(new File("docker-compose-it-db-schema-migration.yml")) + .waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1)); + + private static UUID systemGroupUuid = null; + + @BeforeAll + public static void initAll() { + // init system group + + StructureElement structureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEMGROUP, null, null, + "name", "Sg", "Sg", 1, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + systemGroupUuid = approvedStructureElement.getUuid(); + } + + @Test + public void checkCreate() { + // purpose + // test conditions for create system + // not create itself + // + // what - combination of + // read exists in structure + // read is valid to create + // read validate create + // + // StructureElement attributes + // type, name, mnemonic, description, comment + + try { + ObjectMapper mapper = new ObjectMapper(); + StructureElement structureElement = new StructureElement(); + String[] response = null; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/exists/SYSTEM/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SYSTEM/Sg-Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SYSTEM/SG-Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SYSTEM/Sg-Sg"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SYSTEM/Sg-SG"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.FALSE); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/isvalidtocreate/SYSTEM/Cc"); + ITUtil.assertResponseLength2CodeOK(response); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBoolean.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[{asdf]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setType(Type.SYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setParent(systemGroupUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setMnemonic("Cc"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST); + ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecreate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createApprove() { + // purpose + // test create and approve system + // + // what - combination of + // create create structures + // read validate create + // read validate approve + // patch approve structures + // + // note + // create in order to approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement approvedStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Ca", "Sg-Ca", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createCancel() { + // purpose + // test create and cancel system + // + // what - combination of + // create create structures + // read validate create + // read validate cancel + // patch cancel structures + // + // note + // create in order to cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement cancelledStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Cc", "Sg-Cc", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void createReject() { + // purpose + // test create and reject system + // + // what - combination of + // create create structures + // read validate create + // read validate reject + // patch reject structures + // + // note + // create in order to reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement rejectedStructureElement = null; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Cr", "Sg-Cr", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkUpdate() { + // purpose + // test conditions for update system + // not update + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // patch approve structures + // + // note + // create, approve in order to update + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Cu", "Sg-Cu", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate update + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICEGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(systemGroupUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cu"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateApprove() { + // purpose + // test update and approve system + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // update update structures + // patch approve structures + // + // note + // create, approve in order to update, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Ua", "Sg-Ua", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateCancel() { + // purpose + // test update and cancel system + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate cancel + // update update structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to update, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Uc", "Sg-Uc", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update cancel check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void updateReject() { + // purpose + // test update and reject system + // + // what - combination of + // create create structures + // read validate create + // read validate update + // read validate approve + // read validate reject + // update update structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to update, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement updatedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Ur", "Sg-Ur", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // update + updatedStructureElement = ITUtilNameStructureElement.assertUpdate(structureElement); + structureElement = updatedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void checkDelete() { + // purpose + // test conditions for delete system + // not delete + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // patch approve structures + // + // note + // create, approve in order to delete + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + UUID uuid = null; + + StructureElement structureElement = new StructureElement(); + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Cd", "Sg-Cd", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + uuid = approvedStructureElement.getUuid(); + + // validate delete + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setType(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.DEVICEGROUP); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setType(Type.SYSTEM); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setUuid(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setUuid(uuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setParent(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setParent(systemGroupUuid); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setName(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setName("name"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setMnemonic(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setMnemonic("Cd"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setDescription(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setDescription("description"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + structureElement.setComment(null); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBooleanMessageNotEmpty(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + structureElement.setComment("comment"); + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteApprove() { + // purpose + // test delete and approve system + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // delete delete structures + // patch approve structures + // + // note + // create, approve in order to delete, approve + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Da", "Sg-Da", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete approve check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + structureElement.setDeleted(Boolean.TRUE); + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateapprove", "[" + mapper.writeValueAsString(approvedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteCancel() { + // purpose + // test delete and cancel system + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate cancel + // update delete structures + // patch approve structures + // patch cancel structures + // + // note + // create, approve in order to delete, cancel + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement cancelledStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Dc", "Sg-Dc", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment update delete check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatedelete", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatecancel", "[" + mapper.writeValueAsString(cancelledStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void deleteReject() { + // purpose + // test delete and reject system + // + // what - combination of + // create create structures + // read validate create + // read validate delete + // read validate approve + // read validate reject + // update delete structures + // patch approve structures + // patch reject structures + // + // note + // create, approve in order to delete, reject + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement deletedStructureElement = null; + StructureElement approvedStructureElement = null; + StructureElement rejectedStructureElement = null; + + // create, approve + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Dr", "Sg-Dr", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + approvedStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = approvedStructureElement; + + structureElement.setComment("comment delete reject check"); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validateupdate", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + // delete + deletedStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + structureElement = deletedStructureElement; + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(structureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + + response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(AuthorizationChoice.NONE, EndpointChoice.STRUCTURES, "/validatereject", "[" + mapper.writeValueAsString(rejectedStructureElement) + "]")); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.FALSE); + } catch (IOException e) { + fail(); + } catch (InterruptedException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryApprove() { + // purpose + // test read system group in various ways for create, approve + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement approvedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Rsha", "Sg-Rsha", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // approve + approvedStructureElement = ITUtilNameStructureElement.assertApprove(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?queryFields=UUID&queryValues=" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Rsha"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + approvedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryCancel() { + // purpose + // test read system group in various ways for create, cancel + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement cancelledStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Rshc", "Sg-Rshc", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // cancel + cancelledStructureElement = ITUtilNameStructureElement.assertCancel(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?queryFields=UUID&queryValues=" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Rshc"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + cancelledStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchHistoryReject() { + // purpose + // test read system group in various ways for create, reject + // search + // latest + // history + // + // note + // create (and more) to read (with content) + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement structureElement = null; + StructureElement createdStructureElement = null; + StructureElement[] readStructureElements = null; + StructureElement rejectedStructureElement = null; + int length = 0; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "Rshr", "Sg-Rshr", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "comment"); + + // create + createdStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + structureElement = createdStructureElement; + + // read (1) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + length = readStructureElements.length; + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?queryFields=UUID&queryValues=" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLengthOne(readStructureElements); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + createdStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + // reject + rejectedStructureElement = ITUtilNameStructureElement.assertReject(structureElement); + + // read (2) + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertNotNull(readStructureElements); + assertTrue(readStructureElements.length >= 1); + assertEquals(length, readStructureElements.length); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?queryFields=UUID&queryValues=" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 1); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonic/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/mnemonicpath/Sg-Rshr"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/history/" + rejectedStructureElement.getUuid().toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void readSearchStatusDeletedChildren() { + // purpose + // test read system group in various ways + // status + // ( latest ) + // deleted + // children + // + // what + // entries with different statuses + // + // note + // create (and more) to read (with content) + // querying for Status.APPROVED means latest approved + + StructureElement structureElement = null; + StructureElement responseStructureElement = null; + UUID uuid = null; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AA1", "Sg-AA1", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + uuid = responseStructureElement.getUuid(); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AA2", "Sg-AA2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AA3", "Sg-AA3", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AA4", "Sg-AA4", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AA5", "Sg-AA5", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AB1", "Sg-AB1", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AB2", "Sg-AB2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AB3", "Sg-AB3", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AB4", "Sg-AB4", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AB5", "Sg-AB5", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateCancel(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AC1", "Sg-AC1", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AC2", "Sg-AC2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AC3", "Sg-AC3", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AC4", "Sg-AC4", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AC5", "Sg-AC5", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AD1", "Sg-AD1", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AD2", "Sg-AD2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AD3", "Sg-AD3", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AD4", "Sg-AD4", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AD5", "Sg-AD5", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreate(structureElement); + + String description2 = "some other description"; + String comment2 = "some other comment"; + String description3 = "more description"; + String comment3 = "more comment"; + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AE1", "Sg-AE1", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AE2", "Sg-AE2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AE3", "Sg-AE3", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AE4", "Sg-AE4", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AE5", "Sg-AE5", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description2); + structureElement.setComment(comment2); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDescription(description3); + structureElement.setComment(comment3); + responseStructureElement = ITUtilNameStructureElement.assertUpdateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteReject(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AF1", "Sg-AF1", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AF2", "Sg-AF2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AF3", "Sg-AF3", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AF4", "Sg-AF4", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AF5", "Sg-AF5", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDeleteApprove(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AG1", "Sg-AG1", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AG2", "Sg-AG2", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AG3", "Sg-AG3", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AG4", "Sg-AG4", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + structureElement = new StructureElement( + Type.SYSTEM, null, systemGroupUuid, + "name", "AG5", "Sg-AG5", 2, + "description", Status.PENDING, Boolean.FALSE, Boolean.FALSE, + null, "test who", "test comment"); + responseStructureElement = ITUtilNameStructureElement.assertCreateApprove(structureElement); + structureElement = responseStructureElement; + structureElement.setDeleted(Boolean.FALSE); + responseStructureElement = ITUtilNameStructureElement.assertDelete(structureElement); + + // 60 system entries + + try { + ObjectMapper mapper = new ObjectMapper(); + String[] response = null; + + StructureElement[] readStructureElements = null; + + // from first structure element + assertNotNull(uuid); + + // 45, not 60 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 45); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 20, not 35 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + // 30, not 45 + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=false&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 30); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=false&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=false&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=false&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=false&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=false&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 20); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=true&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 15); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=true&statuses=PENDING&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=true&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=true&statuses=CANCELLED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=true&statuses=REJECTED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 5); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/SYSTEM?deleted=true&statuses=PENDING&statuses=APPROVED&queryFields=MNEMONIC&queryValues=A__"); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 10); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/SYSTEM/" + uuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + ITUtilNameStructureElement.assertContentLength(readStructureElements, 0); + + response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/children/SYSTEMGROUP/" + systemGroupUuid.toString()); + ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); + readStructureElements = mapper.readValue(response[1], StructureElement[].class); + assertTrue(readStructureElements.length >= 1); + } catch (IOException e) { + fail(); + } catch (Exception e) { + fail(); + } + } + + @Test + public void equivalenceMnemonic() { + // purpose + // test mnemonic equivalence + // + // what + // read equivalence mnemonic + + try { + String[] response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_NAMING_API_V1_STRUCTURES + "/equivalence/Sys"); + ITUtil.assertResponseLength2CodeOKContent(response, "SYS"); + } catch (IOException e) { + fail(); + } + } + +} diff --git a/src/test/resources/db/schema_migration/V1__Initial.sql b/src/test/resources/db/schema_migration/V1__Initial.sql new file mode 100644 index 00000000..cb960e1f --- /dev/null +++ b/src/test/resources/db/schema_migration/V1__Initial.sql @@ -0,0 +1,378 @@ +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; +SET search_path = public, pg_catalog; +SET default_tablespace = ''; +SET default_with_oids = false; + +-- +-- Name: appinfo; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE appinfo ( + id bigint NOT NULL, + version integer, + schemaversion integer NOT NULL +); + + +-- +-- Name: appinfo_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE appinfo_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: appinfo_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE appinfo_id_seq OWNED BY appinfo.id; + + +-- +-- Name: device; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE device ( + id bigint NOT NULL, + version integer, + uuid character varying(255) +); + + +-- +-- Name: device_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE device_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: device_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE device_id_seq OWNED BY device.id; + + +-- +-- Name: devicerevision; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE devicerevision ( + id bigint NOT NULL, + version integer, + additionalinfo character varying(255), + conventionname character varying(255), + conventionnameeqclass character varying(255), + deleted boolean NOT NULL, + instanceindex character varying(255), + requestdate timestamp without time zone, + device_id bigint, + devicetype_id bigint, + requestedby_id bigint, + section_id bigint +); + + +-- +-- Name: devicerevision_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE devicerevision_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: devicerevision_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE devicerevision_id_seq OWNED BY devicerevision.id; + + +-- +-- Name: namepart; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE namepart ( + id bigint NOT NULL, + version integer, + nameparttype character varying(255), + uuid character varying(255) +); + + +-- +-- Name: namepart_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE namepart_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: namepart_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE namepart_id_seq OWNED BY namepart.id; + + +-- +-- Name: namepartrevision; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE namepartrevision ( + id bigint NOT NULL, + version integer, + deleted boolean NOT NULL, + description character varying(255), + mnemonic character varying(255), + mnemoniceqclass character varying(255), + name character varying(255), + processdate timestamp without time zone, + processorcomment character varying(255), + requestdate timestamp without time zone, + requestercomment character varying(255), + status character varying(255), + namepart_id bigint, + parent_id bigint, + processedby_id bigint, + requestedby_id bigint +); + + +-- +-- Name: namepartrevision_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE namepartrevision_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: namepartrevision_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE namepartrevision_id_seq OWNED BY namepartrevision.id; + + +-- +-- Name: useraccount; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE useraccount ( + id bigint NOT NULL, + version integer, + role character varying(255), + username character varying(255) +); + + +-- +-- Name: useraccount_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE useraccount_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: useraccount_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE useraccount_id_seq OWNED BY useraccount.id; + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY appinfo ALTER COLUMN id SET DEFAULT nextval('appinfo_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY device ALTER COLUMN id SET DEFAULT nextval('device_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY devicerevision ALTER COLUMN id SET DEFAULT nextval('devicerevision_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY namepart ALTER COLUMN id SET DEFAULT nextval('namepart_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY namepartrevision ALTER COLUMN id SET DEFAULT nextval('namepartrevision_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY useraccount ALTER COLUMN id SET DEFAULT nextval('useraccount_id_seq'::regclass); + + +-- +-- Name: appinfo_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY appinfo + ADD CONSTRAINT appinfo_pkey PRIMARY KEY (id); + + +-- +-- Name: device_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY device + ADD CONSTRAINT device_pkey PRIMARY KEY (id); + + +-- +-- Name: devicerevision_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY devicerevision + ADD CONSTRAINT devicerevision_pkey PRIMARY KEY (id); + + +-- +-- Name: namepart_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY namepart + ADD CONSTRAINT namepart_pkey PRIMARY KEY (id); + + +-- +-- Name: namepartrevision_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY namepartrevision + ADD CONSTRAINT namepartrevision_pkey PRIMARY KEY (id); + + +-- +-- Name: useraccount_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY useraccount + ADD CONSTRAINT useraccount_pkey PRIMARY KEY (id); + + +-- +-- Name: fk_3f26vetemhujfdm9q74ecr2u5; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY namepartrevision + ADD CONSTRAINT fk_3f26vetemhujfdm9q74ecr2u5 FOREIGN KEY (namepart_id) REFERENCES namepart(id); + + +-- +-- Name: fk_4ucnoos7kd8s1gaqbpwm1xptq; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY devicerevision + ADD CONSTRAINT fk_4ucnoos7kd8s1gaqbpwm1xptq FOREIGN KEY (requestedby_id) REFERENCES useraccount(id); + + +-- +-- Name: fk_9vomfk9x1jow27ifx6xc62c5x; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY namepartrevision + ADD CONSTRAINT fk_9vomfk9x1jow27ifx6xc62c5x FOREIGN KEY (processedby_id) REFERENCES useraccount(id); + + +-- +-- Name: fk_9xs5oy86lf0j8ukpjokjipeke; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY namepartrevision + ADD CONSTRAINT fk_9xs5oy86lf0j8ukpjokjipeke FOREIGN KEY (requestedby_id) REFERENCES useraccount(id); + + +-- +-- Name: fk_d3ocbsb4tl4ttnusn98khq148; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY devicerevision + ADD CONSTRAINT fk_d3ocbsb4tl4ttnusn98khq148 FOREIGN KEY (devicetype_id) REFERENCES namepart(id); + + +-- +-- Name: fk_l7kklb4mxixjs27nsso6shone; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY devicerevision + ADD CONSTRAINT fk_l7kklb4mxixjs27nsso6shone FOREIGN KEY (section_id) REFERENCES namepart(id); + + +-- +-- Name: fk_l9r1givkfaiol5or2lnr324xp; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY devicerevision + ADD CONSTRAINT fk_l9r1givkfaiol5or2lnr324xp FOREIGN KEY (device_id) REFERENCES device(id); + + +-- +-- Name: fk_lufxqy46l9eiq55d445rbukag; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY namepartrevision + ADD CONSTRAINT fk_lufxqy46l9eiq55d445rbukag FOREIGN KEY (parent_id) REFERENCES namepart(id); + + +-- +-- Name: public; Type: ACL; Schema: -; Owner: - +-- + +REVOKE ALL ON SCHEMA public FROM PUBLIC; +REVOKE ALL ON SCHEMA public FROM postgres; +GRANT ALL ON SCHEMA public TO postgres; +GRANT ALL ON SCHEMA public TO PUBLIC; + + +INSERT INTO appinfo (version, schemaversion) VALUES (1,1); diff --git a/src/test/resources/db/schema_migration/V2__Commit_Msg_to_Device.sql b/src/test/resources/db/schema_migration/V2__Commit_Msg_to_Device.sql new file mode 100644 index 00000000..acbe8e16 --- /dev/null +++ b/src/test/resources/db/schema_migration/V2__Commit_Msg_to_Device.sql @@ -0,0 +1 @@ +ALTER TABLE devicerevision ADD processorcomment varchar(255) NULL; diff --git a/src/test/resources/db/schema_migration/V3__Notification_CC_List.sql b/src/test/resources/db/schema_migration/V3__Notification_CC_List.sql new file mode 100644 index 00000000..f694a061 --- /dev/null +++ b/src/test/resources/db/schema_migration/V3__Notification_CC_List.sql @@ -0,0 +1,6 @@ +CREATE TABLE user_notification ( + id bigserial NOT NULL, + notification_type varchar(32) NOT NULL, + user_login_name varchar(32) NOT NULL, + CONSTRAINT user_notification_pk PRIMARY KEY (id) +); \ No newline at end of file diff --git a/src/test/resources/db/schema_migration/V4__Schema_data_migration.sql b/src/test/resources/db/schema_migration/V4__Schema_data_migration.sql new file mode 100644 index 00000000..3110a96b --- /dev/null +++ b/src/test/resources/db/schema_migration/V4__Schema_data_migration.sql @@ -0,0 +1,815 @@ +-- -------------------------------------------------------------------------------- +-- About +-- migration script +-- postgresql 9.6.7 +-- Content +-- structures +-- name +-- data structures level 1 +-- data structures level 2 +-- data structures level 3 +-- data name level 1 +-- data name level 2 +-- data name level 3 +-- index +-- latest +-- foreign key +-- index +-- sequence +-- primary key +-- function +-- Note +-- order of items is important +-- -------------------------------------------------------------------------------- + +-- -------------------------------------------------------------------------------- +-- structures +-- -------------------------------------------------------------------------------- +CREATE TABLE systemgroup ( + id bigint NOT NULL, + version integer, + uuid character varying(255), + name character varying(255), + mnemonic character varying(255), + mnemonic_equivalence character varying(255), + description character varying(255), + status character varying(255), + latest boolean NOT NULL, + deleted boolean NOT NULL, + requested timestamp without time zone, + requested_by character varying(255), + requested_comment character varying(255), + processed timestamp without time zone, + processed_by character varying(255), + processed_comment character varying(255) +); +CREATE TABLE system ( + id bigint NOT NULL, + version integer, + uuid character varying(255), + parent_uuid character varying(255), + name character varying(255), + mnemonic character varying(255), + mnemonic_equivalence character varying(255), + description character varying(255), + status character varying(255), + latest boolean NOT NULL, + deleted boolean NOT NULL, + requested timestamp without time zone, + requested_by character varying(255), + requested_comment character varying(255), + processed timestamp without time zone, + processed_by character varying(255), + processed_comment character varying(255) +); + +CREATE TABLE subsystem ( + id bigint NOT NULL, + version integer, + uuid character varying(255), + parent_uuid character varying(255), + name character varying(255), + mnemonic character varying(255), + mnemonic_equivalence character varying(255), + description character varying(255), + status character varying(255), + latest boolean NOT NULL, + deleted boolean NOT NULL, + requested timestamp without time zone, + requested_by character varying(255), + requested_comment character varying(255), + processed timestamp without time zone, + processed_by character varying(255), + processed_comment character varying(255) +); +-- -------------------------------------------------------------------------------- +CREATE TABLE discipline ( + id bigint NOT NULL, + version integer, + uuid character varying(255), + name character varying(255), + mnemonic character varying(255), + mnemonic_equivalence character varying(255), + description character varying(255), + status character varying(255), + latest boolean NOT NULL, + deleted boolean NOT NULL, + requested timestamp without time zone, + requested_by character varying(255), + requested_comment character varying(255), + processed timestamp without time zone, + processed_by character varying(255), + processed_comment character varying(255) +); + +CREATE TABLE devicegroup ( + id bigint NOT NULL, + version integer, + uuid character varying(255), + parent_uuid character varying(255), + name character varying(255), + mnemonic character varying(255), + mnemonic_equivalence character varying(255), + description character varying(255), + status character varying(255), + latest boolean NOT NULL, + deleted boolean NOT NULL, + requested timestamp without time zone, + requested_by character varying(255), + requested_comment character varying(255), + processed timestamp without time zone, + processed_by character varying(255), + processed_comment character varying(255) +); + +CREATE TABLE devicetype ( + id bigint NOT NULL, + version integer, + uuid character varying(255), + parent_uuid character varying(255), + name character varying(255), + mnemonic character varying(255), + mnemonic_equivalence character varying(255), + description character varying(255), + status character varying(255), + latest boolean NOT NULL, + deleted boolean NOT NULL, + requested timestamp without time zone, + requested_by character varying(255), + requested_comment character varying(255), + processed timestamp without time zone, + processed_by character varying(255), + processed_comment character varying(255) +); + +-- -------------------------------------------------------------------------------- +-- name +-- -------------------------------------------------------------------------------- +CREATE TABLE name ( + id bigint NOT NULL, + version integer, + uuid character varying(255), + systemgroup_uuid character varying(255), + system_uuid character varying(255), + subsystem_uuid character varying(255), + devicetype_uuid character varying(255), + instance_index character varying(255), + convention_name character varying(255), + convention_name_equivalence character varying(255), + description character varying(255), + status character varying(255), + latest boolean NOT NULL, + deleted boolean NOT NULL, + requested timestamp without time zone, + requested_by character varying(255), + requested_comment character varying(255), + processed timestamp without time zone, + processed_by character varying(255), + processed_comment character varying(255) +); + +-- -------------------------------------------------------------------------------- +-- data structures level 1 +-- -------------------------------------------------------------------------------- +insert into systemgroup ( + id, + version, + uuid, + name, + mnemonic, + mnemonic_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select npr1.id, npr1."version", np1.uuid, npr1."name", npr1.mnemonic, npr1.mnemoniceqclass, npr1.description, npr1.status, false, npr1.deleted, +npr1.requestdate, ua_r.username as requestedBy, npr1.requestercomment, npr1.processdate, ua_p.username as processedBy, npr1.processorcomment +from namepartrevision npr1 +inner join namepart np1 on npr1.namepart_id = np1.id +left join useraccount ua_r on npr1.requestedby_id = ua_r.id +left join useraccount ua_p on npr1.processedby_id = ua_p.id +where np1.nameparttype = 'SECTION' and npr1.parent_id is null; + +insert into discipline ( + id, + version, + uuid, + name, + mnemonic, + mnemonic_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select npr1.id, npr1."version", np1.uuid, npr1."name", npr1.mnemonic, npr1.mnemoniceqclass, npr1.description, npr1.status, false, npr1.deleted, +npr1.requestdate, ua_r.username as requestedBy, npr1.requestercomment, npr1.processdate, ua_p.username as processedBy, npr1.processorcomment +from namepartrevision npr1 +inner join namepart np1 on npr1.namepart_id = np1.id +left join useraccount ua_r on npr1.requestedby_id = ua_r.id +left join useraccount ua_p on npr1.processedby_id = ua_p.id +where np1.nameparttype = 'DEVICE_TYPE' and npr1.parent_id is null; + +-- -------------------------------------------------------------------------------- +-- data structures level 2 +-- -------------------------------------------------------------------------------- +insert into system ( + id, + version, + uuid, + parent_uuid, + name, + mnemonic, + mnemonic_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select npr2.id, npr2."version", np2.uuid, np22.uuid, +npr2."name", npr2.mnemonic, npr2.mnemoniceqclass, npr2.description, +npr2.status, false, npr2.deleted, npr2.requestdate, ua_r.username as requestedBy, npr2.requestercomment, npr2.processdate, ua_p.username as processedBy, npr2.processorcomment +from namepartrevision npr2 +inner join namepart np2 on npr2.namepart_id = np2.id +inner join namepart np22 on npr2.parent_id = np22.id +left join useraccount ua_r on npr2.requestedby_id = ua_r.id +left join useraccount ua_p on npr2.processedby_id = ua_p.id +where np2.nameparttype = 'SECTION' and npr2.parent_id in +(select npr1.namepart_id from namepartrevision npr1, namepart np1 where npr1.namepart_id = np1.id and np1.nameparttype = 'SECTION' and npr1.parent_id is null); + +insert into devicegroup ( + id, + version, + uuid, + parent_uuid, + name, + mnemonic, + mnemonic_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select npr2.id, npr2."version", np2.uuid, np22.uuid, +npr2."name", npr2.mnemonic, npr2.mnemoniceqclass, npr2.description, +npr2.status, false, npr2.deleted, npr2.requestdate, ua_r.username as requestedBy, npr2.requestercomment, npr2.processdate, ua_p.username as processedBy, npr2.processorcomment +from namepartrevision npr2 +inner join namepart np2 on npr2.namepart_id = np2.id +inner join namepart np22 on npr2.parent_id = np22.id +left join useraccount ua_r on npr2.requestedby_id = ua_r.id +left join useraccount ua_p on npr2.processedby_id = ua_p.id +where np2.nameparttype = 'DEVICE_TYPE' and npr2.parent_id in +(select npr1.namepart_id from namepartrevision npr1, namepart np1 where npr1.namepart_id = np1.id and np1.nameparttype = 'DEVICE_TYPE' and npr1.parent_id is null); + +-- -------------------------------------------------------------------------------- +-- data structures level 3 +-- -------------------------------------------------------------------------------- +insert into subsystem ( + id, + version, + uuid, + parent_uuid, + name, + mnemonic, + mnemonic_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select npr3.id, npr3."version", np3.uuid, np32.uuid, +npr3."name", npr3.mnemonic, npr3.mnemoniceqclass, npr3.description, +npr3.status, false, npr3.deleted, npr3.requestdate, ua_r.username as requestedBy, npr3.requestercomment, npr3.processdate, ua_p.username as processedBy, npr3.processorcomment +from namepartrevision npr3 +inner join namepart np3 on npr3.namepart_id = np3.id +inner join namepart np32 on npr3.parent_id = np32.id +left join useraccount ua_r on npr3.requestedby_id = ua_r.id +left join useraccount ua_p on npr3.processedby_id = ua_p.id +where np3.nameparttype = 'SECTION' and npr3.parent_id in +( +select npr2.namepart_id from namepartrevision npr2, namepart np2 where npr2.namepart_id = np2.id and np2.nameparttype = 'SECTION' and npr2.parent_id in +(select npr1.namepart_id from namepartrevision npr1, namepart np1 where npr1.namepart_id = np1.id and np1.nameparttype = 'SECTION' and npr1.parent_id is null) +); + +insert into devicetype ( + id, + version, + uuid, + parent_uuid, + name, + mnemonic, + mnemonic_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select npr3.id, npr3."version", np3.uuid, np32.uuid, +npr3."name", npr3.mnemonic, npr3.mnemoniceqclass, npr3.description, +npr3.status, false, npr3.deleted, npr3.requestdate, ua_r.username as requestedBy, npr3.requestercomment, npr3.processdate, ua_p.username as processedBy, npr3.processorcomment +from namepartrevision npr3 +inner join namepart np3 on npr3.namepart_id = np3.id +inner join namepart np32 on npr3.parent_id = np32.id +left join useraccount ua_r on npr3.requestedby_id = ua_r.id +left join useraccount ua_p on npr3.processedby_id = ua_p.id +where np3.nameparttype = 'DEVICE_TYPE' and npr3.parent_id in +( +select npr2.namepart_id from namepartrevision npr2, namepart np2 where npr2.namepart_id = np2.id and np2.nameparttype = 'DEVICE_TYPE' and npr2.parent_id in +(select npr1.namepart_id from namepartrevision npr1, namepart np1 where npr1.namepart_id = np1.id and np1.nameparttype = 'DEVICE_TYPE' and npr1.parent_id is null) +); + +-- -------------------------------------------------------------------------------- +-- data name level 1 +-- -------------------------------------------------------------------------------- +insert into name ( + id, + version, + uuid, + systemgroup_uuid, + system_uuid, + subsystem_uuid, + devicetype_uuid, + instance_index, + convention_name, + convention_name_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select dr.id, dr.version, d.uuid, +np_s.uuid, +null, +null, +np_d.uuid, +dr.instanceindex, dr.conventionname, dr.conventionnameeqclass, dr.additionalinfo, null, false, dr.deleted, +dr.requestdate, ua_r.username as requestedBy, null, null, null, dr.processorComment +from devicerevision dr +inner join device d on dr.device_id = d.id +inner join namepart np_s on dr.section_id = np_s.id +left outer join namepart np_d on dr.devicetype_id = np_d.id +left join useraccount ua_r on dr.requestedby_id = ua_r.id +where dr.section_id in +( +select np.id from namepart np, namepartrevision npr where np.id = npr.namepart_id and npr.parent_id is null +); +-- -------------------------------------------------------------------------------- +-- data name level 2 +-- -------------------------------------------------------------------------------- +insert into name ( + id, + version, + uuid, + systemgroup_uuid, + system_uuid, + subsystem_uuid, + devicetype_uuid, + instance_index, + convention_name, + convention_name_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select dr.id, dr.version, d.uuid, +null, +np_s.uuid, +null, +np_d.uuid, +dr.instanceindex, dr.conventionname, dr.conventionnameeqclass, dr.additionalinfo, null, false, dr.deleted, +dr.requestdate, ua_r.username as requestedBy, null, null, null, dr.processorComment +from devicerevision dr +inner join device d on dr.device_id = d.id +inner join namepart np_s on dr.section_id = np_s.id +left outer join namepart np_d on dr.devicetype_id = np_d.id +left join useraccount ua_r on dr.requestedby_id = ua_r.id +where dr.section_id in +( +select np.id from namepart np, namepartrevision npr where np.id = npr.namepart_id and npr.parent_id in + ( + select np2.id from namepart np2, namepartrevision npr2 where np2.id = npr2.namepart_id and npr2.parent_id is null + ) +); + +-- -------------------------------------------------------------------------------- +-- data name level 3 +-- -------------------------------------------------------------------------------- +insert into name ( + id, + version, + uuid, + systemgroup_uuid, + system_uuid, + subsystem_uuid, + devicetype_uuid, + instance_index, + convention_name, + convention_name_equivalence, + description, + status, + latest, + deleted, + requested, + requested_by, + requested_comment, + processed, + processed_by, + processed_comment +) +select dr.id, dr.version, d.uuid, +null, +null, +np_s.uuid, +np_d.uuid, +dr.instanceindex, dr.conventionname, dr.conventionnameeqclass, dr.additionalinfo, null, false, dr.deleted, +dr.requestdate, ua_r.username as requestedBy, null, null, null, dr.processorComment +from devicerevision dr +inner join device d on dr.device_id = d.id +inner join namepart np_s on dr.section_id = np_s.id +left outer join namepart np_d on dr.devicetype_id = np_d.id +left join useraccount ua_r on dr.requestedby_id = ua_r.id +where dr.section_id in +( +select np.id from namepart np, namepartrevision npr where np.id = npr.namepart_id and npr.parent_id in + ( + select np2.id from namepart np2, namepartrevision npr2 where np2.id = npr2.namepart_id and npr2.parent_id in + ( + select np3.id from namepart np3, namepartrevision npr3 where np3.id = npr3.namepart_id and npr3.parent_id is null + ) + ) +); + +-- -------------------------------------------------------------------------------- +-- index +-- -------------------------------------------------------------------------------- +CREATE INDEX systemgroup_id_idx ON public.systemgroup (id); +CREATE INDEX systemgroup_uuid_idx ON public.systemgroup (uuid); +CREATE INDEX systemgroup_mnemonic_idx ON public.systemgroup (mnemonic); +CREATE INDEX systemgroup_status_idx ON public.systemgroup (status); +CREATE INDEX systemgroup_deleted_idx ON public.systemgroup (deleted); + +CREATE INDEX system_id_idx ON public.system (id); +CREATE INDEX system_uuid_idx ON public.system (uuid); +CREATE INDEX system_parent_uuid_idx ON public.system (parent_uuid); +CREATE INDEX system_mnemonic_idx ON public.system (mnemonic); +CREATE INDEX system_status_idx ON public.system (status); +CREATE INDEX system_deleted_idx ON public.system (deleted); + +CREATE INDEX subsystem_id_idx ON public.subsystem (id); +CREATE INDEX subsystem_uuid_idx ON public.subsystem (uuid); +CREATE INDEX subsystem_parent_uuid_idx ON public.subsystem (parent_uuid); +CREATE INDEX subsystem_mnemonic_idx ON public.subsystem (mnemonic); +CREATE INDEX subsystem_status_idx ON public.subsystem (status); +CREATE INDEX subsystem_deleted_idx ON public.subsystem (deleted); + +CREATE INDEX discipline_id_idx ON public.discipline (id); +CREATE INDEX discipline_uuid_idx ON public.discipline (uuid); +CREATE INDEX discipline_mnemonic_idx ON public.discipline (mnemonic); +CREATE INDEX discipline_status_idx ON public.discipline (status); +CREATE INDEX discipline_deleted_idx ON public.discipline (deleted); + +CREATE INDEX devicegroup_id_idx ON public.devicegroup (id); +CREATE INDEX devicegroup_uuid_idx ON public.devicegroup (uuid); +CREATE INDEX devicegroup_parent_uuid_idx ON public.devicegroup (parent_uuid); +CREATE INDEX devicegroup_mnemonic_idx ON public.devicegroup (mnemonic); +CREATE INDEX devicegroup_status_idx ON public.devicegroup (status); +CREATE INDEX devicegroup_deleted_idx ON public.devicegroup (deleted); + +CREATE INDEX devicetype_id_idx ON public.devicetype (id); +CREATE INDEX devicetype_uuid_idx ON public.devicetype (uuid); +CREATE INDEX devicetype_parent_uuid_idx ON public.devicetype (parent_uuid); +CREATE INDEX devicetype_mnemonic_idx ON public.devicetype (mnemonic); +CREATE INDEX devicetype_status_idx ON public.devicetype (status); +CREATE INDEX devicetype_deleted_idx ON public.devicetype (deleted); + +CREATE INDEX name_uuid_idx ON public.name (uuid); + +-- -------------------------------------------------------------------------------- +-- latest +-- -------------------------------------------------------------------------------- +update systemgroup sg set latest = true where sg.id = ( + select max(sg2.id) from systemgroup sg2 where sg2.uuid = sg.uuid and sg2.status = 'APPROVED' +); +update system sys set latest = true where sys.id = ( + select max(sys2.id) from system sys2 where sys2.uuid = sys.uuid and sys2.status = 'APPROVED' +); +update subsystem sub set latest = true where sub.id = ( + select max(sub2.id) from subsystem sub2 where sub2.uuid = sub.uuid and sub2.status = 'APPROVED' +); + +update discipline di set latest = true where di.id = ( + select max(di2.id) from discipline di2 where di2.uuid = di.uuid and di2.status = 'APPROVED' +); +update devicegroup dg set latest = true where dg.id = ( + select max(dg2.id) from devicegroup dg2 where dg2.uuid = dg.uuid and dg2.status = 'APPROVED' +); +update devicetype dt set latest = true where dt.id = ( + select max(dt2.id) from devicetype dt2 where dt2.uuid = dt.uuid and dt2.status = 'APPROVED' +); + +update name en set latest = true where en.id = ( + select max(en2.id) from name en2 where en2.uuid = en.uuid +); + +-- -------------------------------------------------------------------------------- +-- foreign key +-- -------------------------------------------------------------------------------- + +-- -------------------------------------------------------------------------------- +-- index +-- -------------------------------------------------------------------------------- +CREATE INDEX name_id_idx ON public.name (id); +CREATE INDEX name_namepartrevision_systemgroup_uuid_idx ON public.name (systemgroup_uuid); +CREATE INDEX name_namepartrevision_system_uuid_idx ON public.name (system_uuid); +CREATE INDEX name_namepartrevision_subsystem_uuid_idx ON public.name (subsystem_uuid); +CREATE INDEX name_namepartrevision_devicetype_uuid_idx ON public.name (devicetype_uuid); +CREATE INDEX name_convention_name_idx ON public.name (convention_name); +CREATE INDEX name_status_idx ON public.name (status); +CREATE INDEX name_deleted_idx ON public.name (deleted); + +CREATE INDEX systemgroup_latest_idx ON public.systemgroup (latest); +CREATE INDEX system_latest_idx ON public.system (latest); +CREATE INDEX subsystem_latest_idx ON public.subsystem (latest); + +CREATE INDEX discipline_latest_idx ON public.discipline (latest); +CREATE INDEX devicegroup_latest_idx ON public.devicegroup (latest); +CREATE INDEX devicetype_latest_idx ON public.devicetype (latest); + +CREATE INDEX name_latest_idx ON public.name (latest); + +-- -------------------------------------------------------------------------------- +-- sequence +-- -------------------------------------------------------------------------------- +CREATE SEQUENCE systemgroup_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +CREATE SEQUENCE system_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +CREATE SEQUENCE subsystem_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +CREATE SEQUENCE discipline_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +CREATE SEQUENCE devicegroup_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +CREATE SEQUENCE devicetype_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +CREATE SEQUENCE name_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +SELECT setval('systemgroup_id_seq', (select max(id) from systemgroup)); +SELECT setval('system_id_seq', (select max(id) from "system")); +SELECT setval('subsystem_id_seq', (select max(id) from "subsystem")); +SELECT setval('discipline_id_seq', (select max(id) from discipline)); +SELECT setval('devicegroup_id_seq', (select max(id) from devicegroup)); +SELECT setval('devicetype_id_seq', (select max(id) from devicetype)); +SELECT setval('name_id_seq', (select max(id) from "name")); + +ALTER SEQUENCE systemgroup_id_seq OWNED BY systemgroup.id; +ALTER SEQUENCE system_id_seq OWNED BY system.id; +ALTER SEQUENCE subsystem_id_seq OWNED BY subsystem.id; +ALTER SEQUENCE discipline_id_seq OWNED BY discipline.id; +ALTER SEQUENCE devicegroup_id_seq OWNED BY devicegroup.id; +ALTER SEQUENCE devicetype_id_seq OWNED BY devicetype.id; +ALTER SEQUENCE name_id_seq OWNED BY name.id; + +ALTER TABLE ONLY systemgroup ALTER COLUMN id SET DEFAULT nextval('systemgroup_id_seq'::regclass); +ALTER TABLE ONLY system ALTER COLUMN id SET DEFAULT nextval('system_id_seq'::regclass); +ALTER TABLE ONLY subsystem ALTER COLUMN id SET DEFAULT nextval('subsystem_id_seq'::regclass); +ALTER TABLE ONLY discipline ALTER COLUMN id SET DEFAULT nextval('discipline_id_seq'::regclass); +ALTER TABLE ONLY devicegroup ALTER COLUMN id SET DEFAULT nextval('devicegroup_id_seq'::regclass); +ALTER TABLE ONLY devicetype ALTER COLUMN id SET DEFAULT nextval('devicetype_id_seq'::regclass); +ALTER TABLE ONLY name ALTER COLUMN id SET DEFAULT nextval('name_id_seq'::regclass); + +-- -------------------------------------------------------------------------------- +-- primary key +-- -------------------------------------------------------------------------------- +ALTER TABLE public.systemgroup ADD CONSTRAINT systemgroup_pk PRIMARY KEY (id); +ALTER TABLE public.system ADD CONSTRAINT system_pk PRIMARY KEY (id); +ALTER TABLE public.subsystem ADD CONSTRAINT subsystem_pk PRIMARY KEY (id); + +ALTER TABLE public.discipline ADD CONSTRAINT discipline_pk PRIMARY KEY (id); +ALTER TABLE public.devicegroup ADD CONSTRAINT devicegroup_pk PRIMARY KEY (id); +ALTER TABLE public.devicetype ADD CONSTRAINT devicetype_pk PRIMARY KEY (id); + +ALTER TABLE public.name ADD CONSTRAINT name_pk PRIMARY KEY (id); +-- -------------------------------------------------------------------------------- + +-- -------------------------------------------------------------------------------- +-- function +-- -------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION get_mnemonic_path_system_structure(convention_name text) + RETURNS text + LANGUAGE plpgsql +AS +$$ +DECLARE + pos int; +BEGIN + pos = strpos(convention_name, ':'); + IF pos > 0 THEN + RETURN substr(convention_name, 1, pos-1); + END IF; + RETURN convention_name; +END; +$$; + +CREATE OR REPLACE FUNCTION get_mnemonic_path_device_structure(convention_name text) + RETURNS text + LANGUAGE plpgsql +AS +$$ +DECLARE + pos int; + mnemonic_path text; + nbr_delimiters int; +BEGIN + pos = strpos(convention_name, ':'); + IF pos > 0 THEN + mnemonic_path = substr(convention_name, pos+1); + nbr_delimiters = array_length(string_to_array(mnemonic_path, '-'), 1) - 1; + IF nbr_delimiters = 2 then + mnemonic_path = reverse(mnemonic_path); + mnemonic_path = substr(mnemonic_path, strpos(mnemonic_path, '-')+1); + RETURN reverse(mnemonic_path); + ELSIF nbr_delimiters = 1 then + return mnemonic_path; + ELSE + RETURN null; + END IF; + END IF; + RETURN null; +END; +$$; + +CREATE OR REPLACE FUNCTION get_mnemonic_path_system(system_uuid text) + RETURNS text + LANGUAGE plpgsql +AS +$$ +DECLARE + system_mnemonic text; + systemgroup_uuid text; + systemgroup_mnemonic text; +BEGIN + select parent_uuid, mnemonic into systemgroup_uuid, system_mnemonic from "system" where uuid = system_uuid and latest = true; + select mnemonic into systemgroup_mnemonic from systemgroup where uuid = systemgroup_uuid and latest = true; + + if systemgroup_mnemonic is not null and system_mnemonic is not null then + return concat(systemgroup_mnemonic, '-', system_mnemonic); + elsif system_mnemonic is not null then + return system_mnemonic; + else + return null; + end if; +END; +$$; + +CREATE OR REPLACE FUNCTION get_mnemonic_path_subsystem(subsystem_uuid text) + RETURNS text + LANGUAGE plpgsql +AS +$$ +DECLARE + subsystem_mnemonic text; + system_uuid text; + system_mnemonic text; + systemgroup_uuid text; + systemgroup_mnemonic text; +BEGIN + select parent_uuid, mnemonic into system_uuid, subsystem_mnemonic from subsystem where uuid = subsystem_uuid and latest = true; + select parent_uuid, mnemonic into systemgroup_uuid, system_mnemonic from "system" where uuid = system_uuid and latest = true; + select mnemonic into systemgroup_mnemonic from systemgroup where uuid = systemgroup_uuid and latest = true; + + if systemgroup_mnemonic is not null and system_mnemonic is not null and subsystem_mnemonic is not null then + return concat(systemgroup_mnemonic, '-', system_mnemonic, '-', subsystem_mnemonic); + elsif system_mnemonic is not null and subsystem_mnemonic is not null then + return concat(system_mnemonic, '-', subsystem_mnemonic); + elsif subsystem_mnemonic is not null then + return subsystem_mnemonic; + else + return null; + end if; +END; +$$; + +CREATE OR REPLACE FUNCTION get_mnemonic_path_devicegroup(devicegroup_uuid text) + RETURNS text + LANGUAGE plpgsql +AS +$$ +DECLARE + discipline_uuid text; + discipline_mnemonic text; +BEGIN + select parent_uuid into discipline_uuid from devicegroup where uuid = devicegroup_uuid and latest = true; + select mnemonic into discipline_mnemonic from discipline where uuid = discipline_uuid and latest = true; + + if discipline_mnemonic is not null then + return discipline_mnemonic; + else + return null; + end if; +END; +$$; + +CREATE OR REPLACE FUNCTION get_mnemonic_path_devicetype(devicetype_uuid text) + RETURNS text + LANGUAGE plpgsql +AS +$$ +DECLARE + devicetype_mnemonic text; + devicegroup_uuid text; + discipline_uuid text; + discipline_mnemonic text; +BEGIN + select parent_uuid, mnemonic into devicegroup_uuid, devicetype_mnemonic from devicetype where uuid = devicetype_uuid and latest = true; + select parent_uuid, mnemonic into discipline_uuid from devicegroup where uuid = devicegroup_uuid and latest = true; + select mnemonic into discipline_mnemonic from discipline where uuid = discipline_uuid and latest = true; + + if discipline_mnemonic is not null and devicetype_mnemonic is not null then + return concat(discipline_mnemonic, '-', devicetype_mnemonic); + elsif devicetype_mnemonic is not null then + return devicetype_mnemonic; + else + return null; + end if; +END; +$$; \ No newline at end of file -- GitLab