aboutsummaryrefslogtreecommitdiffstats
path: root/gui-editors/gui-editor-apex/src/test
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2022-01-28 11:41:38 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2022-02-23 09:50:14 +0000
commit4a50604b767176aa323acae366fa762015a7f9f6 (patch)
tree065f6be626573df3da5df23b3b2d2533cb9ed819 /gui-editors/gui-editor-apex/src/test
parent6e3d850c1b6efda12a70a111c8734972c99e3db5 (diff)
Apex Editor using Spring Boot
Changed Apex Editor to use Spring Boot (MVC) Changed all tests to use JUnit 5 Added more tests for policy upload feature Updated JS files to reflect JSON encoding change Added Apex Editor README Changed rest path to /policy/gui/v1/apex/editor Issue-ID: POLICY-3896 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I10f1ee3c40244a822a7032b4b24cb02060698fc3
Diffstat (limited to 'gui-editors/gui-editor-apex/src/test')
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/SpringContextTest.java (renamed from gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ExceptionsTest.java)26
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java42
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java360
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java131
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java1228
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java20
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionTest.java54
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtilsTest.java8
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeansTest.java14
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKeyTest.java52
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadDisabledTest.java80
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadEnabledTest.java101
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandlerTest.java159
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDtoTest.java14
14 files changed, 1040 insertions, 1249 deletions
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ExceptionsTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/SpringContextTest.java
index 9c83fdc..8422f82 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ExceptionsTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/SpringContextTest.java
@@ -1,7 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,25 +18,16 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.gui.editors.apex.rest;
+package org.onap.policy.gui.editors.apex;
-import static org.junit.Assert.assertNotNull;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
-import java.io.IOException;
-import org.junit.Test;
-
-/**
- * Test Apex Editor Exceptions.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class ExceptionsTest {
+@SpringBootTest(classes = ApexEditor.class)
+class SpringContextTest {
+ @SuppressWarnings("java:S2699")
@Test
- public void test() {
- assertNotNull(new ApexEditorException("Message"));
- assertNotNull(new ApexEditorException("Message", "Object of Exception"));
- assertNotNull(new ApexEditorException("Message", new IOException()));
- assertNotNull(new ApexEditorException("Message", new IOException(), "Object of Exception"));
+ void contextLoads() {
}
}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java
deleted file mode 100644
index 88e2707..0000000
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.gui.editors.apex.rest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Test;
-
-public class ApexEditorParametersTest {
-
- @Test
- public void validate() {
- final var apexEditorParameters = new ApexEditorParameters();
- apexEditorParameters.setTimeToLive(-3);
- apexEditorParameters.setRestPort(-3);
- apexEditorParameters.setUploadUrl("what://ever");
- final var actual = apexEditorParameters.validate();
- assertThat(actual).contains("upload-url parameter is an invalid")
- .contains("upload-userid parameter must be specified")
- .contains("port must be between")
- .contains("time to live must be greater than -1");
- }
-}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java
deleted file mode 100644
index 717da11..0000000
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java
+++ /dev/null
@@ -1,360 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.gui.editors.apex.rest;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.concurrent.TimeUnit;
-import org.junit.Test;
-import org.onap.policy.common.parameters.ParameterService;
-import org.onap.policy.gui.editors.apex.rest.ApexEditorMain.EditorState;
-
-/**
- * Test Apex Editor Startup.
- */
-public class ApexEditorStartupTest {
- // CHECKSTYLE:OFF: MagicNumber
-
- /**
- * Test no args.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testNoArgs() throws IOException, InterruptedException {
- final String[] args = new String[] {};
-
- final String outString = runEditor(args);
-
- assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain:"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("State=RUNNING) started"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("help=false"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("restPort=18989"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("timeToLive=-1"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("listenAddress=localhost"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("uploadUrl=null"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("uploadUserid=null"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith(" State=STOPPED) shut down "));
- }
-
- /**
- * Test bad arg 0.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadArg0() throws IOException, InterruptedException {
- final String[] args = new String[] { "12321" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("parameter error, too many command line arguments specified : [12321]");
- }
-
- /**
- * Test bad arg 1.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadArg1() throws IOException, InterruptedException {
- final String[] args = new String[] { "12321 12322 12323" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("parameter error, too many command line arguments specified : [12321 12322 12323]");
- }
-
- /**
- * Test bad arg 2.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadArg2() throws IOException, InterruptedException {
- final String[] args = new String[] { "-z" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class).hasMessageContaining(
- "parameter error, invalid command line arguments specified : Unrecognized option: -z");
- }
-
- /**
- * Test bad arg 3.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadArg3() throws IOException, InterruptedException {
- final String[] args = new String[] { "--hello" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class).hasMessageContaining(
- "parameter error, invalid command line arguments specified : Unrecognized option: --hello");
- }
-
- /**
- * Test bad arg 4.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadArg4() throws IOException, InterruptedException {
- final String[] args = new String[] { "-l", "+++++" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("parameters invalid, listen address is not valid. "
- + "Illegal character in hostname at index 7: http://+++++:18989/apexservices/");
- }
-
- /**
- * Test help 0.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testHelp0() throws IOException, InterruptedException {
- final String[] args = new String[] { "--help" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("usage: org.onap.policy.gui.editors.apex.rest.ApexEditorMain [options...]");
- }
-
- /**
- * Test help 1.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testHelp1() throws IOException, InterruptedException {
- final String[] args = new String[] { "-h" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("usage: org.onap.policy.gui.editors.apex.rest.ApexEditorMain [options...]");
- }
-
- /**
- * Test port arg.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testPortArgShJo() throws IOException, InterruptedException {
- final String[] args = new String[] { "-p12321" };
-
- final String outString = runEditor(args);
-
- assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain:"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("State=RUNNING) started"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("localhost:12321"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith(" State=STOPPED) shut down "));
- }
-
- /**
- * Test port arg.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testPortArgShSe() throws IOException, InterruptedException {
- final String[] args = new String[] { "-p", "12321" };
-
- final String outString = runEditor(args);
-
- assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain:"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("State=RUNNING) started"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("localhost:12321"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith(" State=STOPPED) shut down "));
- }
-
- /**
- * Test port arg.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testPortArgSpace() throws IOException, InterruptedException {
- final String[] args = new String[] { "-p 12321" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("parameter error, error parsing argument \"port\" :For input string: \" 12321\"");
- }
-
- /**
- * Test bad port arg 0.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadPortArgs0() throws IOException, InterruptedException {
- final String[] args = new String[] { "-p0" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("parameters invalid, port must be between 1024 and 65535");
- }
-
- /**
- * Test bad port arg 1023.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadPortArgs1023() throws IOException, InterruptedException {
- final String[] args = new String[] { "-p1023" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("parameters invalid, port must be between 1024 and 65535");
- }
-
- /**
- * Test bad port arg 65536.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testBadPortArgs65536() throws IOException, InterruptedException {
- final String[] args = new String[] { "-p65536" };
-
- assertThatThrownBy(() -> runEditor(args)).isInstanceOf(ApexEditorParameterException.class)
- .hasMessageContaining("parameters invalid, port must be between 1024 and 65535");
- }
-
- /**
- * Test TTL arg 0.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testTtlArg0() throws IOException, InterruptedException {
- final String[] args = new String[] { "-t10" };
-
- final String outString = runEditor(args);
-
- assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain:"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("State=RUNNING) started"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("timeToLive=10"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith(" State=STOPPED) shut down "));
- }
-
- /**
- * Test TTL arg 10.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testTtlArg1() throws IOException, InterruptedException {
- final String[] args = new String[] { "-t", "10", "-l", "localhost" };
-
- final String outString = runEditor(args);
-
- assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain:"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("State=RUNNING) started"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("timeToLive=10"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith(" State=STOPPED) shut down "));
- }
-
- /**
- * Test port TTL arg 0.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testPortTtlArg0() throws IOException, InterruptedException {
- final String[] args = new String[] { "-t", "10", "-p", "12321" };
-
- final String outString = runEditor(args);
-
- assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain:"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("State=RUNNING) started"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("timeToLive=10"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith(" State=STOPPED) shut down "));
- }
-
- /**
- * Test port TTL arg 10.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException if the test is interrupted
- */
- @Test
- public void testPortTtlArg1() throws IOException, InterruptedException {
- final String[] args = new String[] { "--time-to-live", "10", "--port", "12321", "--listen", "127.0.0.1" };
-
- final String outString = runEditor(args);
-
- assertTrue(outString.startsWith("Apex Editor REST endpoint (ApexEditorMain:"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("State=RUNNING) started"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").contains("timeToLive=10"));
- assertTrue(outString.replaceAll("[\\r?\\n]+", " ").endsWith(" State=STOPPED) shut down "));
- }
-
- /**
- * Run the editor for tests.
- *
- * @param args the args
- * @return the output string
- * @throws InterruptedException if the test is interrupted
- */
- private String runEditor(final String[] args) throws InterruptedException {
- ParameterService.clear();
- final var outBaStream = new ByteArrayOutputStream();
- final var outStream = new PrintStream(outBaStream);
-
- final var editorMain = new ApexEditorMain(args, outStream);
-
- // This test must be started in a thread because we want to intercept the output
- // in cases where the editor is
- // started infinitely
- final var testThread = new Runnable() {
- @Override
- public void run() {
- editorMain.init();
- }
- };
- new Thread(testThread).start();
- await().atMost(15000, TimeUnit.MILLISECONDS).until(() -> !(editorMain.getState().equals(EditorState.READY)
- || editorMain.getState().equals(EditorState.INITIALIZING)));
- editorMain.shutdown();
- final String outString = outBaStream.toString();
- System.out.println(outString);
- return outString;
- }
-}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java
index 3506dab..f97897a 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,111 +22,67 @@
package org.onap.policy.gui.editors.apex.rest;
-import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.concurrent.TimeUnit;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation.Builder;
-import javax.ws.rs.client.WebTarget;
-import javax.xml.bind.JAXBException;
-import org.eclipse.persistence.jpa.jpql.Assert;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+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.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
-import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.gui.editors.apex.rest.ApexEditorMain.EditorState;
+import org.onap.policy.gui.editors.apex.ApexEditor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
/**
* The RestInterface Test.
*/
-public class RestInterfaceTest {
- // CHECKSTYLE:OFF: MagicNumber
+@SpringBootTest(classes = ApexEditor.class)
+@AutoConfigureMockMvc
+class RestInterfaceTest {
- private static final String TESTMODELFILE = "models/PolicyModel.yaml";
- private static final String TESTPORTNUM = "18989";
- private static final long MAX_WAIT = 15000; // 15 sec
- private static final InputStream SYSIN = System.in;
- private static final String[] EDITOR_MAIN_ARGS = new String[] { "-p", TESTPORTNUM };
+ @Autowired
+ private MockMvc mvc;
- private static ApexEditorMain editorMain;
- private static WebTarget target;
+ private static final String TESTMODELFILE = "models/PolicyModel.yaml";
private static String localModelString = null;
/**
* Sets up the tests.
*
- * @throws Exception if an error happens
*/
- @BeforeClass
- public static void setUp() throws Exception {
- ParameterService.clear();
- // Start the editor
- editorMain = new ApexEditorMain(EDITOR_MAIN_ARGS, System.out);
- // prevent a stray stdin value from killing the editor
- final var input = new ByteArrayInputStream("".getBytes());
- System.setIn(input);
- // Init the editor in a separate thread
- final var testThread = new Runnable() {
- @Override
- public void run() {
- editorMain.init();
- }
- };
- new Thread(testThread).start();
- // wait until editorMain is in state RUNNING
- await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> !(editorMain.getState().equals(EditorState.READY)
- || editorMain.getState().equals(EditorState.INITIALIZING)));
-
- if (editorMain.getState().equals(EditorState.STOPPED)) {
- Assert.fail("Rest endpoint (" + editorMain + ") shut down before it could be used");
- }
-
- // create the client
- final Client c = ClientBuilder.newClient();
- // Create the web target
- target = c.target(new ApexEditorParameters().getBaseUri());
-
+ @BeforeAll
+ static void setUp() {
// load a test model locally
localModelString = ResourceUtils.getResourceAsString(TESTMODELFILE);
-
- // initialize a session ID
- createNewSession();
}
/**
- * Clean up streams.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws InterruptedException the interrupted exception
+ * Test to see that the message create Model with model id -1 .
*/
- @AfterClass
- public static void cleanUpStreams() throws IOException, InterruptedException {
- editorMain.shutdown();
- // wait until editorMain is in state STOPPED
- await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> editorMain.getState().equals(EditorState.STOPPED));
- System.setIn(SYSIN);
+ @Test
+ void createSession() throws Exception {
+ createNewSession();
}
/**
- * Test to see that the message create Model with model id -1 .
+ * Helper method to invoke rest call using mock mvc, and return ApexApiResult.
*/
- @Test
- public void createSession() {
- createNewSession();
+ private ApexApiResult apexRest(MockHttpServletRequestBuilder requestBuilder) throws Exception {
+ var response = mvc.perform(requestBuilder).andReturn().getResponse();
+ return new StandardCoder().decode(response.getContentAsString(), ApexApiResult.class);
}
/**
@@ -134,8 +90,8 @@ public class RestInterfaceTest {
*
* @return the session ID
*/
- private static int createNewSession() {
- final ApexApiResult responseMsg = target.path("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ private int createNewSession() throws Exception {
+ final ApexApiResult responseMsg = apexRest(get("/policy/gui/v1/apex/editor/-1/Session/Create"));
assertEquals(ApexApiResult.Result.SUCCESS, responseMsg.getResult());
assertEquals(1, responseMsg.getMessages().size());
return Integer.parseInt(responseMsg.getMessages().get(0));
@@ -147,28 +103,27 @@ public class RestInterfaceTest {
* @param sessionId the session ID
* @param modelAsJsonString the model as json string
*/
- private void uploadPolicy(final int sessionId, final String modelAsJsonString) {
- final Builder requestbuilder = target.path("editor/" + sessionId + "/Model/Load").request();
- final ApexApiResult responseMsg = requestbuilder.put(Entity.json(modelAsJsonString), ApexApiResult.class);
+ private void uploadPolicy(final int sessionId, final String modelAsJsonString) throws Exception {
+ final ApexApiResult responseMsg = apexRest(put("/policy/gui/v1/apex/editor/" + sessionId + "/Model/Load")
+ .content(modelAsJsonString).contentType(APPLICATION_JSON));
assertTrue(responseMsg.isOk());
}
/**
- * Create a new session, Upload a test policy model, then get a policy, parse it, and compare it to the same policy
+ * Create a new session, Upload a test policy model, then get a policy, parse it, and compare it to the same policy
* in the original model.
*
* @throws ApexException if there is an Apex Error
- * @throws JAXBException if there is a JaxB Error
**/
@Test
- public void testUploadThenGet() throws ApexException, JAXBException {
+ void testUploadThenGet() throws Exception {
final int sessionId = createNewSession();
uploadPolicy(sessionId, localModelString);
- final ApexApiResult responseMsg = target.path("editor/" + sessionId + "/Policy/Get")
- .queryParam("name", "policy").queryParam("version", "0.0.1").request().get(ApexApiResult.class);
+ final ApexApiResult responseMsg = apexRest(get("/policy/gui/v1/apex/editor/" + sessionId + "/Policy/Get")
+ .queryParam("name", "policy").queryParam("version", "0.0.1"));
assertTrue(responseMsg.isOk());
// The string in responseMsg.Messages[0] is a JSON representation of a AxPolicy
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java
index 359dbcc..e5f24ff 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,312 +21,364 @@
package org.onap.policy.gui.editors.apex.rest.handling;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.IOException;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.MediaType;
-import org.glassfish.jersey.media.multipart.MultiPartFeature;
-import org.glassfish.jersey.server.ResourceConfig;
-import org.glassfish.jersey.test.JerseyTest;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
+
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.gui.editors.apex.ApexEditor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
/**
* Test Apex Editor Rest Resource.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ApexEditorRestResourceTest extends JerseyTest {
- @Override
- protected Application configure() {
- return new ResourceConfig(ApexEditorRestResource.class).register(MultiPartFeature.class);
- }
+@SpringBootTest(classes = ApexEditor.class)
+@AutoConfigureMockMvc
+class ApexEditorRestResourceTest {
+
+ private static final String BASE_URL = "/policy/gui/v1/apex/editor/{sessionId}";
+
+ @Autowired
+ private MockMvc mvc;
+
+ @Autowired
+ private RestSessionHandler sessionHandler;
@Test
- public void testSessionCreate() {
- ApexApiResult result = target("editor/-2/Session/Create").request().get(ApexApiResult.class);
+ void testSessionCreate() throws Exception {
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -2));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Session/Create", -1));
assertEquals(Result.SUCCESS, result.getResult());
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Session/Create", -1));
assertEquals(Result.SUCCESS, result.getResult());
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ final int corruptSessionId = createCorruptSession();
- target("editor/" + corruptSessionId + "/Model/Analyse").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Model/Analyse", corruptSessionId));
- result = target("editor/" + sessionId + "/Model/Analyse").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Analyse", sessionId));
assertEquals(Result.SUCCESS, result.getResult());
- result = target("editor/-12345/Model/Analyse").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Analyse", -12345));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/12345/Model/Analyse").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Analyse", 12345));
assertEquals(Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Model/Validate").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Model/Validate", corruptSessionId));
- result = target("editor/" + sessionId + "/Model/Validate").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Validate", sessionId));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/-12345/Model/Validate").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Validate", -12345));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/12345/Model/Validate").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Validate", 12345));
assertEquals(Result.FAILED, result.getResult());
final String modelString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002699\","
+ "\"description\" : \"A description of the model\"" + "}";
- final Entity<String> csEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/Model/Create").request().post(csEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Model/Create", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/-12345/Model/Create").request().post(csEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Model/Create", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Model/Create").request().post(csEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Model/Create", 1234545)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Create").request().post(csEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Model/Create", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/Model/Create").request().post(csEntity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Model/Create", corruptSessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
- result = target("editor/-12345/Model/Update").request().put(csEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Update", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/-12345/Model/Update").request().put(csEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Update", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Model/Update").request().put(csEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Update", 1234545)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Update").request().put(csEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Update", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/Model/Update").request().put(csEntity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Model/Update", corruptSessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
- target("editor/" + corruptSessionId + "/Model/GetKey").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Model/GetKey", corruptSessionId));
- result = target("editor/" + sessionId + "/Model/GetKey").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/GetKey", sessionId));
assertEquals(Result.SUCCESS, result.getResult());
- result = target("editor/-12345/Model/GetKey").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/GetKey", -12345));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/12345/Model/GetKey").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/GetKey", 12345));
assertEquals(Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Model/Get").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Model/Get", corruptSessionId));
- result = target("editor/" + sessionId + "/Model/Get").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Get", sessionId));
assertEquals(Result.SUCCESS, result.getResult());
- result = target("editor/-12345/Model/Get").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Get", -12345));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/12345/Model/Get").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Get", 12345));
assertEquals(Result.FAILED, result.getResult());
- String resultString = target("editor/" + corruptSessionId + "/Model/Download").request().get(String.class);
+ String resultString = requestString(get(BASE_URL + "/Model/Download", corruptSessionId));
assertEquals("", resultString);
- resultString = target("editor/" + sessionId + "/Model/Download").request().get(String.class);
+ resultString = requestString(get(BASE_URL + "/Model/Download", sessionId));
assertNotNull(resultString);
}
@Test
- public void testSessionCreateExt() {
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ void testSessionCreateExt() throws Exception {
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- target("editor/-1/Session/Create").request().get(ApexApiResult.class);
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ apexRequest(get(BASE_URL + "/Session/Create", -1));
+ final int corruptSessionId = createCorruptSession();
- String resultString = target("editor/-12345/Model/Download").request().get(String.class);
+ String resultString = requestString(get(BASE_URL + "/Model/Download", -12345));
assertEquals("", resultString);
- resultString = target("editor/12345/Model/Download").request().get(String.class);
+ resultString = requestString(get(BASE_URL + "/Model/Download", 12345));
assertEquals("", resultString);
- target("editor/" + corruptSessionId + "/KeyInformation/Get").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/KeyInformation/Get", corruptSessionId));
- result = target("editor/" + sessionId + "/KeyInformation/Get").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/KeyInformation/Get", sessionId));
assertEquals(Result.SUCCESS, result.getResult());
- result = target("editor/-12345/KeyInformation/Get").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/KeyInformation/Get", -12345));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/12345/KeyInformation/Get").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/KeyInformation/Get", 12345));
assertEquals(Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Model/Delete").request().delete(ApexApiResult.class);
+ apexRequest(delete(BASE_URL + "/Model/Delete", corruptSessionId));
- result = target("editor/" + sessionId + "/Model/Delete").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Model/Delete", sessionId));
assertEquals(Result.SUCCESS, result.getResult());
- result = target("editor/-12345/Model/Delete").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Model/Delete", -12345));
assertEquals(Result.FAILED, result.getResult());
- result = target("editor/12345/Model/Delete").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Model/Delete", 12345));
assertEquals(Result.FAILED, result.getResult());
}
@Test
- public void testContextSchema() throws IOException {
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ void testContextSchema() throws Exception {
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
assertEquals(Result.SUCCESS, result.getResult());
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ final int corruptSessionId = createCorruptSession();
- result = target("editor/-12345/Validate/ContextSchema").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextSchema", -12345));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Validate/ContextSchema").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Validate/ContextSchema", corruptSessionId));
- result = target("editor/" + sessionId + "/Validate/ContextSchema").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextSchema", sessionId));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Validate/ContextSchema").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextSchema", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Validate/ContextSchema").queryParam("name", "%%%$£")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextSchema", sessionId)
+ .queryParam("name", "%%%$£")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
-
- Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
- result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ String modelString = "Somewhere over the rainbow";
+ result = apexRequest(put(BASE_URL + "/Model/Load", -12345)
+ .content(modelString)
+ .contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", 12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = "";
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/ContextSchema/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextSchema/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/ContextSchema/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/ContextSchema/Get", corruptSessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
String csString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"schemaFlavour\" : \"Java\"," + "\"schemaDefinition\" : \"java.lang.String\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> csEntity = Entity.entity(csString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/ContextSchema/Create").request().post(csEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/ContextSchema/Create", -12345)
+ .content(csString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/ContextSchema/Create").request().post(csEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/ContextSchema/Create", 1234545)
+ .content(csString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/ContextSchema/Create").request().post(csEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/ContextSchema/Create", sessionId)
+ .content(csString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/ContextSchema/Create").request().post(csEntity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/ContextSchema/Create", corruptSessionId)
+ .content(csString).contentType(APPLICATION_JSON));
csString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"schemaFlavour\" : \"Java\"," + "\"schemaDefinition\" : \"my.perfect.String\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- csEntity = Entity.entity(csString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/ContextSchema/Update").request().put(csEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/ContextSchema/Update", -12345)
+ .content(csString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/ContextSchema/Update").request().put(csEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/ContextSchema/Update", 1234545)
+ .content(csString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/ContextSchema/Update").request().put(csEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/ContextSchema/Update", sessionId)
+ .content(csString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/ContextSchema/Update").request().put(csEntity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/ContextSchema/Update", corruptSessionId)
+ .content(csString).contentType(APPLICATION_JSON));
- result = target("editor/" + sessionId + "/ContextSchema/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextSchema/Get", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/ContextSchema/Get").queryParam("name", "NonExistant")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextSchema/Get", sessionId)
+ .queryParam("name", "NonExistant")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/-123345/ContextSchema/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextSchema/Get", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/ContextSchema/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextSchema/Get", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/ContextSchema/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/ContextSchema/Get", corruptSessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
- result = target("editor/" + sessionId + "/Validate/ContextSchema").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextSchema", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/ContextSchema/Delete").queryParam("name", "Hello")
- .queryParam("version", "0.0.2").request().delete(ApexApiResult.class);
+ apexRequest(delete(BASE_URL + "/ContextSchema/Delete", corruptSessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", "0.0.2"));
- result = target("editor/-123345/ContextSchema/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/ContextSchema/Delete", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/ContextSchema/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/ContextSchema/Delete", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/ContextSchema/Delete").queryParam("name", "Hello")
- .queryParam("version", "0.0.2").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/ContextSchema/Delete", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", "0.0.2"));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
@Test
- public void testContextSchemaExt() throws IOException {
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ void testContextSchemaExt() throws Exception {
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
- Entity<String> modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
- target("editor/" + sessionId + "/ContextSchema/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
+ apexRequest(get(BASE_URL + "/ContextSchema/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
- result = target("editor/" + sessionId + "/ContextSchema/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/ContextSchema/Delete", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
@Test
- public void testContextAlbum() throws IOException {
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ void testContextAlbum() throws Exception {
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
assertEquals(Result.SUCCESS, result.getResult());
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ final int corruptSessionId = createCorruptSession();
- result = target("editor/-12345/Validate/ContextAlbum").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextAlbum", -12345));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Validate/ContextAlbum").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Validate/ContextAlbum", corruptSessionId));
- result = target("editor/" + sessionId + "/Validate/ContextAlbum").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextAlbum", sessionId));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Validate/ContextAlbum").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextAlbum", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Validate/ContextAlbum").queryParam("name", "%%%$£")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextAlbum", sessionId)
+ .queryParam("name", "%%%$£")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
-
- Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
- result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ String modelString = "Somewhere over the rainbow";
+ result = apexRequest(put(BASE_URL + "/Model/Load", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", 12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = "";
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/ContextAlbum/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextAlbum/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
String caString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
@@ -334,146 +386,173 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"itemSchema\" : {\"name\" : \"StringType\", \"version\" : \"0.0.1\"},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> caEntity = Entity.entity(caString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/ContextAlbum/Create").request().post(caEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/ContextAlbum/Create", -12345)
+ .content(caString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/ContextAlbum/Create").request().post(caEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/ContextAlbum/Create", 1234545)
+ .content(caString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/ContextAlbum/Create").request().post(caEntity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/ContextAlbum/Create", sessionId)
+ .content(caString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/ContextAlbum/Create").request().post(caEntity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/ContextAlbum/Create", corruptSessionId)
+ .content(caString).contentType(APPLICATION_JSON));
caString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"scope\" : \"Global\"," + "\"writeable\" : false,"
+ "\"itemSchema\" : {\"name\" : \"StringType\", \"version\" : \"0.0.1\"},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- caEntity = Entity.entity(caString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/ContextAlbum/Update").request().put(caEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/ContextAlbum/Update", -12345)
+ .content(caString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/ContextAlbum/Update").request().put(caEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/ContextAlbum/Update", 1234545)
+ .content(caString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/ContextAlbum/Update").request().put(caEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/ContextAlbum/Update", sessionId)
+ .content(caString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/ContextAlbum/Update").request().put(caEntity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/ContextAlbum/Update", corruptSessionId)
+ .content(caString).contentType(APPLICATION_JSON));
- target("editor/" + corruptSessionId + "/ContextAlbum/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/ContextAlbum/Get", corruptSessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
- result = target("editor/" + sessionId + "/ContextAlbum/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextAlbum/Get", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/ContextAlbum/Get").queryParam("name", "IDontExist")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextAlbum/Get", sessionId)
+ .queryParam("name", "IDontExist")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/-123345/ContextAlbum/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextAlbum/Get", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/ContextAlbum/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/ContextAlbum/Get", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Validate/ContextAlbum").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/ContextAlbum", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/ContextAlbum/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ apexRequest(delete(BASE_URL + "/ContextAlbum/Delete", corruptSessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
- result = target("editor/-123345/ContextAlbum/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/ContextAlbum/Delete", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/ContextAlbum/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/ContextAlbum/Delete", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/ContextAlbum/Delete").queryParam("name", "Hello")
- .queryParam("version", "0.0.2").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/ContextAlbum/Delete", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", "0.0.2"));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
@Test
- public void testContextAlbumExt() throws IOException {
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ void testContextAlbumExt() throws Exception {
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
- Entity<String> modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
- target("editor/" + sessionId + "/ContextAlbum/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
+ apexRequest(get(BASE_URL + "/ContextAlbum/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
@Test
- public void testEvent() throws IOException {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testEvent() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
assertEquals(Result.SUCCESS, result.getResult());
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- result = target("editor/-12345/Validate/Event").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", -12345));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Validate/Event").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", sessionId));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- target("editor/" + corruptSessionId + "/Validate/Event").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Validate/Event", corruptSessionId));
- result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", "%%%$£")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", sessionId)
+ .queryParam("name", "%%%$£")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.yaml");
-
- Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
- result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ String modelString = "Somewhere over the rainbow";
+ result = apexRequest(put(BASE_URL + "/Model/Load", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", 12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = "";
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.yaml");
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Event/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ "\"target\" : \"end\"," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", -12345)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", 1234545)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
- target("editor/" + corruptSessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Event/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : \"Hiya\"," + "\"version\" : \"0.0.2\","
+ "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ "\"target\" : \"end\"," + "\"parameters\" : {},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"HowsItGoing\"," + "\"version\" : \"0.0.2\","
@@ -483,8 +562,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"localName\" : \"Par0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hi\"," + "\"version\" : \"0.0.2\","
@@ -492,8 +571,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"target\" : \"end\"," + "\"parameters\" : {\"Par0\" : null},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"GoodDay\"," + "\"version\" : \"0.0.2\","
@@ -503,176 +582,204 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"localName\" : \"Par0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"namespace\" : \"somewhere.over.someone.elses.rainbow\"," + "\"source\" : \"start\","
+ "\"target\" : \"finish\"," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/Event/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Event/Update", -12345)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Event/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Event/Update", 1234545)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Event/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Event/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/Event/Update").request().put(entity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Event/Update", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : null," + "\"version\" : \"0.0.2\","
+ "\"namespace\" : \"somewhere.over.someone.elses.rainbow\"," + "\"source\" : \"start\","
+ "\"target\" : \"finish\"," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Event/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Event/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"NonExistantEvent\"," + "\"version\" : \"0.0.2\","
+ "\"namespace\" : \"somewhere.over.someone.elses.rainbow\"," + "\"source\" : \"start\","
+ "\"target\" : \"finish\"," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Event/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Event/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Event/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Event/Get", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
@Test
- public void testEventExt() {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testEventExt() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ "\"target\" : \"end\"," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : \"Hiya\"," + "\"version\" : \"0.0.2\","
+ "\"namespace\" : \"somewhere.over.the.rainbow\"," + "\"source\" : \"beginning\","
+ "\"target\" : \"end\"," + "\"parameters\" : {},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
- target("editor/" + corruptSessionId + "/Event/Create").request().post(entity, ApexApiResult.class);
- target("editor/" + sessionId + "/Event/Update").request().put(entity, ApexApiResult.class);
- result = target("editor/" + sessionId + "/Event/Get").queryParam("name", "IDontExist")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Event/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+ apexRequest(post(BASE_URL + "/Event/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+ apexRequest(put(BASE_URL + "/Event/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+ result = apexRequest(get(BASE_URL + "/Event/Get", sessionId)
+ .queryParam("name", "IDontExist")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/-123345/Event/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Event/Get", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/Event/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Event/Get", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Event/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Event/Get", corruptSessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
- result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/-12345/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", -12345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/12345/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", 12345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Event/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ apexRequest(delete(BASE_URL + "/Event/Delete", corruptSessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
- result = target("editor/-123345/Event/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Event/Delete", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/Event/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Event/Delete", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Event/Delete").queryParam("name", "Hello")
- .queryParam("version", "0.0.2").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Event/Delete", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", "0.0.2"));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Event/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Event/Delete", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
@Test
- public void testTask() throws IOException {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testTask() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
assertEquals(Result.SUCCESS, result.getResult());
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- result = target("editor/-12345/Validate/Task").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Task", -12345));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Validate/Task").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Task", sessionId));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
try {
- target("editor/" + corruptSessionId + "/Validate/Task").request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Validate/Task", corruptSessionId));
} catch (final Exception e) {
assertEquals("HTTP 500 Request failed.", e.getMessage());
}
- result = target("editor/" + sessionId + "/Validate/Task").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Task", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Validate/Task").queryParam("name", "%%%$£")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Task", sessionId)
+ .queryParam("name", "%%%$£")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
-
- Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
- result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ String modelString = "Somewhere over the rainbow";
+ result = apexRequest(put(BASE_URL + "/Model/Load", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", 12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = "";
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Event/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", -12345)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", 1234545)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
- target("editor/" + corruptSessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Task/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : \"Hiya\"," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"HowsItGoing\"," + "\"version\" : \"0.0.2\","
@@ -680,16 +787,16 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"localName\" : \"IField0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hi\"," + "\"version\" : \"0.0.2\","
+ "\"inputFields\" : {\"IField0\" : null},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"GoodDay\"," + "\"version\" : \"0.0.2\","
@@ -697,8 +804,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"localName\" : \"IField0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Howdy\"," + "\"version\" : \"0.0.2\","
@@ -706,8 +813,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"localName\" : \"NotIField0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"HowsItGoing2\"," + "\"version\" : \"0.0.2\","
@@ -715,16 +822,16 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"localName\" : \"OField0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hi2\"," + "\"version\" : \"0.0.2\","
+ "\"outputFields\" : {\"OField0\" : null},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"GoodDay2\"," + "\"version\" : \"0.0.2\","
@@ -732,8 +839,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"localName\" : \"OField0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Howdy2\"," + "\"version\" : \"0.0.2\","
@@ -741,45 +848,47 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"localName\" : \"NotOField0\", \"optional\" : false}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
}
@Test
- public void testTaskExt() throws IOException {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testTaskExt() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
- Entity<String> modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
- target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
+ apexRequest(get(BASE_URL + "/Event/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
- target("editor/" + corruptSessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+ apexRequest(post(BASE_URL + "/Task/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+
entityString = "{" + "\"name\" : \"HowsItGoing3\"," + "\"version\" : \"0.0.2\","
+ "\"taskLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : \"lots of lemons,"
+ " lots of lime\"}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
-
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hi3\"," + "\"version\" : \"0.0.2\","
+ "\"taskLogic\" : null," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"GoodDay3\"," + "\"version\" : \"0.0.2\","
@@ -788,16 +897,16 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"taskLogic\" : {\"logicFlavour\" : \"UNDEFINED\", \"logic\" : \"lots of lemons,"
+ " lots of lime\"}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Howdy3\"," + "\"version\" : \"0.0.2\","
+ "\"taskLogic\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : null},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"HowsItGoing4\"," + "\"version\" : \"0.0.2\","
@@ -805,199 +914,224 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"defaultValue\" : \"Parameter Defaultvalue\"}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hi4\"," + "\"version\" : \"0.0.2\","
+ "\"parameters\" : {\"Par0\" : null},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"GoodDay4\"," + "\"version\" : \"0.0.2\","
+ "\"parameters\" : {\"Par0\" : {\"parameterName\" : \"NotPar0\", \"defaultValue\" : "
+ "\"Parameter Defaultvalue\"}}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Howdy4\"," + "\"version\" : \"0.0.2\","
+ "\"parameters\" : {\"Par0\" : {\"parameterName\" : \"MyParameter\", \"defaultValue\" : null}},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"HowsItGoing5\"," + "\"version\" : \"0.0.2\","
+ "\"contexts\" : [{\"name\" : \"contextAlbum0\", \"version\" : \"0.0.1\"}],"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hi5\"," + "\"version\" : \"0.0.2\","
+ "\"contexts\" : []," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"GoodDay5\"," + "\"version\" : \"0.0.2\","
+ "\"contexts\" : [{\"name\" : \"NonExistantType\", \"version\" : \"0.0.1\"}],"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Howdy5\"," + "\"version\" : \"0.0.2\","
+ "\"contexts\" : [{\"name\" : null, \"version\" : \"0.0.1\"}],"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002799\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/Task/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Task/Update", -12345)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Task/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Task/Update", 1234545)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Task/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Task/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/Task/Update").request().put(entity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Task/Update", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : null," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Task/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"NonExistantEvent\"," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Task/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Task/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Task/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Task/Get", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Task/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Task/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Task/Get").queryParam("name", "IDontExist")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Task/Get", sessionId)
+ .queryParam("name", "IDontExist")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/-123345/Task/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Task/Get", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/Task/Get").queryParam("name", (String) null).queryParam("version", (String) null)
- .request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Task/Get", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Task/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Task/Get", corruptSessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
- result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/-12345/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", -12345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/12345/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", 12345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
}
@Test
- public void testTaskExt_2() throws IOException {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testTaskExt_2() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
- Entity<String> modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
- target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
+ apexRequest(get(BASE_URL + "/Event/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/1234545/Task/Create").request().post(entity, ApexApiResult.class);
- target("editor/" + sessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
- target("editor/" + corruptSessionId + "/Task/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Task/Create", 1234545)
+ .content(entityString).contentType(APPLICATION_JSON));
+ apexRequest(post(BASE_URL + "/Task/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+ apexRequest(post(BASE_URL + "/Task/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
- result = target("editor/-123345/Task/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Task/Delete", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/Task/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Task/Delete", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Task/Delete").queryParam("name", "Hello")
- .queryParam("version", "0.0.2").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Task/Delete", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", "0.0.2"));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Task/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Task/Delete", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
@Test
- public void testPolicy() throws IOException {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testPolicy() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
assertEquals(Result.SUCCESS, result.getResult());
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- result = target("editor/-12345/Model/Validate").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Validate", -12345));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Validate").request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Validate", sessionId));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Model/Validate").request().get(ApexApiResult.class);
- result = target("editor/" + sessionId + "/Model/Validate").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Model/Validate", corruptSessionId));
+ result = apexRequest(get(BASE_URL + "/Model/Validate", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Validate").queryParam("name", "%%%$£")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Model/Validate", sessionId)
+ .queryParam("name", "%%%$£")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
-
- Entity<String> modelEntity = Entity.entity("Somewhere over the rainbow", MediaType.APPLICATION_JSON);
- result = target("editor/" + -12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ String modelString = "Somewhere over the rainbow";
+ result = apexRequest(put(BASE_URL + "/Model/Load", -12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + 12345 + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", 12345)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity("", MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = "";
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ result = apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Event/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Event/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
@@ -1011,24 +1145,28 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", -12345)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", 1234545)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
- target("editor/" + corruptSessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Policy/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : \"GoodTaSeeYa\"," + "\"version\" : \"0.0.2\","
+ "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ "\"states\" : null," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"HelloAnother\"," + "\"version\" : \"0.0.2\","
@@ -1042,8 +1180,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hello2\"," + "\"version\" : \"0.0.2\","
@@ -1057,8 +1195,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello3\"," + "\"version\" : \"0.0.2\","
@@ -1072,8 +1210,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello4\"," + "\"version\" : \"0.0.2\","
@@ -1086,8 +1224,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello5\"," + "\"version\" : \"0.0.2\","
@@ -1099,8 +1237,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"nextState\" : null" + " }" + " }," + " \"tasks\" : null" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello6\"," + "\"version\" : \"0.0.2\","
@@ -1114,8 +1252,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Hello7\"," + "\"version\" : \"0.0.2\","
@@ -1123,8 +1261,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "\"states\" : {" + " \"state\" : null" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello8\"," + "\"version\" : \"0.0.2\","
@@ -1139,8 +1277,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Hello9\"," + "\"version\" : \"0.0.2\","
@@ -1154,23 +1292,23 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
System.err.println(result);
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
}
@Test
- public void testPolicyExt() throws IOException {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testPolicyExt() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
- Entity<String> modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
@@ -1183,10 +1321,11 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
- target("editor/" + corruptSessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+ apexRequest(post(BASE_URL + "/Policy/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : \"HelloAnother\"," + "\"version\" : \"0.0.2\","
+ "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
@@ -1199,8 +1338,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : \"Hello10\"," + "\"version\" : \"0.0.2\","
+ "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
@@ -1213,8 +1352,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Hello11\"," + "\"version\" : \"0.0.2\","
@@ -1227,8 +1366,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"task\" : null," + " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\""
+ " }" + " }" + " }" + "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello12\"," + "\"version\" : \"0.0.2\","
@@ -1245,8 +1384,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }"
+ "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hello13\"," + "\"version\" : \"0.0.2\","
@@ -1263,8 +1402,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }"
+ "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello14\"," + "\"version\" : \"0.0.2\","
@@ -1283,8 +1422,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }"
+ "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hello15\"," + "\"version\" : \"0.0.2\","
@@ -1302,8 +1441,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }"
+ "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
entityString = "{" + "\"name\" : \"Hello16\"," + "\"version\" : \"0.0.2\","
@@ -1321,8 +1460,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }"
+ "}," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello17\"," + "\"version\" : \"0.0.2\","
@@ -1344,8 +1483,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ "lots of lime\"}" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
entityString = "{" + "\"name\" : \"Hello18\"," + "\"version\" : \"0.0.2\","
@@ -1365,8 +1504,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"finalizers\" : {" + " \"sf0\" : null" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"Hello19\"," + "\"version\" : \"0.0.2\","
@@ -1387,8 +1526,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"sf0\" : {\"logicFlavour\" : \"LemonAndLime\", \"logic\" : null}" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ result = apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"HelloAnother\"," + "\"version\" : \"0.0.2\","
@@ -1402,19 +1541,23 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A better description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/-12345/Policy/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Policy/Update", -12345)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/1234545/Policy/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Policy/Update", 1234545)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Policy/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Update").queryParam("firstStatePeriodic", "true").request()
- .put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Policy/Update", sessionId)
+ .queryParam("firstStatePeriodic", "true")
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- target("editor/" + corruptSessionId + "/Policy/Update").request().put(entity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Policy/Update", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : null," + "\"version\" : \"0.0.2\","
+ "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
@@ -1427,8 +1570,8 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A better description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Policy/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
entityString = "{" + "\"name\" : \"IDontExist\"," + "\"version\" : \"0.0.2\","
@@ -1442,63 +1585,75 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A better description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- result = target("editor/" + sessionId + "/Policy/Update").request().put(entity, ApexApiResult.class);
+ result = apexRequest(put(BASE_URL + "/Policy/Update", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Policy/Get", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Get").queryParam("name", "IDontExist")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Policy/Get", sessionId)
+ .queryParam("name", "IDontExist")
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Policy/Get", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/-123345/Policy/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Policy/Get", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/123345/Policy/Get").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Policy/Get", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Policy/Get").queryParam("name", "Hello")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Policy/Get", corruptSessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", (String) null));
- result = target("editor/" + sessionId + "/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/-12345/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", -12345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/12345/Validate/Event").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ result = apexRequest(get(BASE_URL + "/Validate/Event", 12345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- target("editor/" + corruptSessionId + "/Policy/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ apexRequest(delete(BASE_URL + "/Policy/Delete", corruptSessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
- result = target("editor/-123345/Policy/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Policy/Delete", -123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
}
@Test
- public void testPolicyExt_2() throws IOException {
- final int corruptSessionId = ApexEditorRestResource.createCorruptSession();
+ void testPolicyExt_2() throws Exception {
+ final int corruptSessionId = createCorruptSession();
- ApexApiResult result = target("editor/-1/Session/Create").request().get(ApexApiResult.class);
+ ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
final int sessionId = Integer.parseInt(result.getMessages().get(0));
- target("editor/" + corruptSessionId + "/Model/Validate").request().get(ApexApiResult.class);
- target("editor/" + sessionId + "/Model/Validate").queryParam("name", "%%%$£")
- .queryParam("version", (String) null).request().get(ApexApiResult.class);
+ apexRequest(get(BASE_URL + "/Model/Validate", corruptSessionId));
+ apexRequest(get(BASE_URL + "/Model/Validate", sessionId)
+ .queryParam("name", "%%%$£")
+ .queryParam("version", (String) null));
final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
- Entity<String> modelEntity = Entity.entity(modelString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Model/Load").request().put(modelEntity, ApexApiResult.class);
+ apexRequest(put(BASE_URL + "/Model/Load", sessionId)
+ .content(modelString).contentType(APPLICATION_JSON));
String entityString = "{" + "\"name\" : \"Hello\"," + "\"version\" : \"0.0.2\","
+ "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
@@ -1511,26 +1666,55 @@ public class ApexEditorRestResourceTest extends JerseyTest {
+ " \"outputType\" : \"DIRECT\"," + " \"outputName\" : \"so0\"" + " }" + " }" + " }" + "},"
+ "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- Entity<String> entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
- target("editor/" + corruptSessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
+ apexRequest(post(BASE_URL + "/Policy/Create", corruptSessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
entityString = "{" + "\"name\" : \"GoodTaSeeYa\"," + "\"version\" : \"0.0.2\","
+ "\"template\" : \"somewhere.over.the.rainbow\"," + "\"firstState\" : \"state\","
+ "\"states\" : null," + "\"uuid\" : \"1fa2e430-f2b2-11e6-bc64-92361f002671\","
+ "\"description\" : \"A description of hello\"" + "}";
- entity = Entity.entity(entityString, MediaType.APPLICATION_JSON);
- target("editor/" + sessionId + "/Policy/Create").request().post(entity, ApexApiResult.class);
+ apexRequest(post(BASE_URL + "/Policy/Create", sessionId)
+ .content(entityString).contentType(APPLICATION_JSON));
- result = target("editor/123345/Policy/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Policy/Delete", 123345)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.FAILED, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Delete").queryParam("name", "Hello")
- .queryParam("version", "0.0.2").request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Policy/Delete", sessionId)
+ .queryParam("name", "Hello")
+ .queryParam("version", "0.0.2"));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
- result = target("editor/" + sessionId + "/Policy/Delete").queryParam("name", (String) null)
- .queryParam("version", (String) null).request().delete(ApexApiResult.class);
+ result = apexRequest(delete(BASE_URL + "/Policy/Delete", sessionId)
+ .queryParam("name", (String) null)
+ .queryParam("version", (String) null));
assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
}
+ /*
+ * Make a request using MockMvc and return the response body as a string.
+ */
+ private String requestString(MockHttpServletRequestBuilder requestBuilder) throws Exception {
+ return mvc.perform(requestBuilder).andReturn().getResponse().getContentAsString();
+ }
+
+ /*
+ * Make a request using MockMvc and return the decoded JSON response as an ApexApiResult.
+ */
+ private ApexApiResult apexRequest(MockHttpServletRequestBuilder requestBuilder) throws Exception {
+ String json = requestString(requestBuilder);
+ return new StandardCoder().decode(json, ApexApiResult.class);
+ }
+
+ /*
+ * This method is used only for testing and is used to cause an exception on calls from unit test to test exception
+ * handling.
+ */
+ private int createCorruptSession() throws Exception {
+ final ApexApiResult result = apexRequest(get(BASE_URL + "/Session/Create", -1));
+ final int corruptSessionId = Integer.parseInt(result.getMessages().get(0));
+ sessionHandler.setCorruptSession(corruptSessionId);
+ return corruptSessionId;
+ }
}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java
index 7d193ce..26f3090 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,23 +23,23 @@ package org.onap.policy.gui.editors.apex.rest.handling;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Random;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.modelapi.ApexModel;
-public class KeyInfoHandlerTest {
+class KeyInfoHandlerTest {
private final Random random = new Random();
private KeyInfoHandler handler;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
handler = new KeyInfoHandler();
}
@Test
- public void testExecuteRestCommand() {
+ void testExecuteRestCommand() {
final var sessionId = random.nextInt();
final var session = new RestSession(sessionId);
final var commandType = RestCommandType.EVENT;
@@ -54,7 +54,7 @@ public class KeyInfoHandlerTest {
}
@Test
- public void testExecuteRestCommandWithJsonString() {
+ void testExecuteRestCommandWithJsonString() {
final var sessionId = random.nextInt();
final var session = new RestSession(sessionId);
final var commandType = RestCommandType.EVENT;
@@ -70,7 +70,7 @@ public class KeyInfoHandlerTest {
}
@Test
- public void testExecuteRestCommandWithNameAndVersion() {
+ void testExecuteRestCommandWithNameAndVersion() {
final var sessionId = random.nextInt();
final var session = new RestSession(sessionId);
final var commandType = RestCommandType.EVENT;
@@ -87,7 +87,7 @@ public class KeyInfoHandlerTest {
}
@Test
- public void testExecuteRestCommandWithNameAndVersion2() {
+ void testExecuteRestCommandWithNameAndVersion2() {
final var session = Mockito.mock(RestSession.class);
final var commandType = RestCommandType.KEY_INFO;
final var command = RestCommand.LIST;
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionTest.java
index 121faa0..077deaf 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionTest.java
@@ -23,64 +23,51 @@ package org.onap.policy.gui.editors.apex.rest.handling;
import static org.assertj.core.api.Assertions.assertThat;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Random;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.gui.editors.apex.rest.ApexEditorMain;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class RestSessionTest {
+class RestSessionTest {
private int sessionId;
private RestSession restSession;
- @BeforeClass
- public static void beforeClass() {
- // Initialize ApexEditor
- final String[] args = {"--time-to-live", "10", "--port", "12321", "--listen", "127.0.0.1"};
- final var outBaStream = new ByteArrayOutputStream();
- final var outStream = new PrintStream(outBaStream);
- new ApexEditorMain(args, outStream);
- }
-
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
sessionId = new Random().nextInt();
restSession = new RestSession(sessionId);
}
@Test
- public void testGetSessionId() {
+ void testGetSessionId() {
final var actual = restSession.getSessionId();
assertThat(actual).isEqualTo(sessionId);
}
@Test
- public void testCommitChangesNoChanges() {
+ void testCommitChangesNoChanges() {
final var apexApiResult = restSession.commitChanges();
assertThat(apexApiResult.isNok()).isTrue();
}
@Test
- public void testCommitChanges() {
+ void testCommitChanges() {
restSession.editModel();
final var apexApiResult = restSession.commitChanges();
assertThat(apexApiResult.isOk()).isTrue();
}
@Test
- public void testDiscardChangesNotEdited() {
+ void testDiscardChangesNotEdited() {
final var apexApiResult = restSession.discardChanges();
assertThat(apexApiResult.isNok()).isTrue();
}
@Test
- public void testDiscardChanges() {
+ void testDiscardChanges() {
restSession.editModel();
final var apexApiResult = restSession.discardChanges();
assertThat(apexApiResult.isOk()).isTrue();
@@ -88,13 +75,13 @@ public class RestSessionTest {
}
@Test
- public void testDownloadModel() {
+ void testDownloadModel() {
final var actual = restSession.downloadModel();
assertThat(actual.isOk()).isTrue();
}
@Test
- public void testEditModel() {
+ void testEditModel() {
final var original = restSession.getApexModelEdited();
final var apexApiResult = restSession.editModel();
final var apexModelEdited = restSession.getApexModelEdited();
@@ -106,14 +93,14 @@ public class RestSessionTest {
}
@Test
- public void testEditModelAlreadyEdited() {
+ void testEditModelAlreadyEdited() {
restSession.editModel();
final var apexApiResult = restSession.editModel();
assertThat(apexApiResult.isNok()).isTrue();
}
@Test
- public void testLoadFromString() throws IOException {
+ void testLoadFromString() throws IOException {
restSession.editModel();
final var toscaPath = Path.of("src/test/resources/models/PolicyModel.yaml");
final var toscaString = Files.readString(toscaPath);
@@ -124,7 +111,7 @@ public class RestSessionTest {
}
@Test
- public void testLoadFromStringNoPolicies() throws IOException {
+ void testLoadFromStringNoPolicies() throws IOException {
restSession.editModel();
final var toscaPath = Path.of("src/test/resources/models/PolicyModelNoPolicies.yaml");
final var toscaString = Files.readString(toscaPath);
@@ -132,15 +119,4 @@ public class RestSessionTest {
assertThat(apexApiResult.isNok()).isTrue();
assertThat(apexApiResult.getMessage()).contains("no policies");
}
-
- @Test
- public void testUploadModel() throws IOException {
- restSession.editModel();
- final var toscaPath = Path.of("src/test/resources/models/PolicyModel.yaml");
- final var toscaString = Files.readString(toscaPath);
- restSession.loadFromString(toscaString);
- final var apexApiResult = restSession.uploadModel("");
- assertThat(apexApiResult.isNok()).isTrue();
- assertThat(apexApiResult.getMessage()).contains("Model upload is disabled");
- }
}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtilsTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtilsTest.java
index 84876d5..9706ad7 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtilsTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtilsTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,13 @@ package org.onap.policy.gui.editors.apex.rest.handling;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanModel;
-public class RestUtilsTest {
+class RestUtilsTest {
@Test
- public void getJsonParameters() {
+ void getJsonParameters() {
final var name = RandomStringUtils.randomAlphabetic(3);
final var uuid = RandomStringUtils.randomAlphabetic(4);
final var desc = RandomStringUtils.randomAlphabetic(5);
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeansTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeansTest.java
index c8c0971..fde130d 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeansTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeansTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,20 +22,20 @@
package org.onap.policy.gui.editors.apex.rest.handling.bean;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the beans.
- *
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class BeansTest {
+class BeansTest {
@Test
- public void testBeans() {
+ void testBeans() {
assertNotNull(new BeanEvent().toString());
assertNotNull(new BeanState().toString());
assertNotNull(new BeanContextAlbum().toString());
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKeyTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKeyTest.java
deleted file mode 100644
index 5d45db7..0000000
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKeyTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.gui.editors.apex.rest.handling.config;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Test;
-
-public class PolicyUploadPluginConfigKeyTest {
-
- @Test
- public void getKeyUrl() {
- final var actual = PolicyUploadPluginConfigKey.URL.getKey();
- assertThat(actual).isEqualTo("plugin.policy.upload.url");
- }
-
- @Test
- public void getTypeUrl() {
- final var actual = PolicyUploadPluginConfigKey.URL.getType();
- assertThat(actual).isEqualTo(String.class);
- }
-
- @Test
- public void getKeyEnable() {
- final var actual = PolicyUploadPluginConfigKey.ENABLE.getKey();
- assertThat(actual).isEqualTo("plugin.policy.upload.enable");
- }
-
- @Test
- public void getTypeEnable() {
- final var actual = PolicyUploadPluginConfigKey.ENABLE.getType();
- assertThat(actual).isEqualTo(Boolean.class);
- }
-}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadDisabledTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadDisabledTest.java
new file mode 100644
index 0000000..2388e8c
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadDisabledTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.plugin.upload;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.gui.editors.apex.ApexEditor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+
+@SpringBootTest(classes = ApexEditor.class,
+ properties = "apex-editor.upload-url=")
+@AutoConfigureMockMvc
+class PolicyUploadDisabledTest {
+
+ @Autowired
+ private MockMvc mvc;
+
+ private int sessionId;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ createSession();
+ loadModel();
+ }
+
+ @Test
+ void testModelUploadDisabled() throws Exception {
+ ApexApiResult result = apexRequest(get("/policy/gui/v1/apex/editor/" + sessionId + "/Model/Upload")
+ .queryParam("userId", "MyUser"));
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ assertThat(result.getMessage()).contains("Model upload is disabled");
+ }
+
+ private ApexApiResult apexRequest(MockHttpServletRequestBuilder requestBuilder) throws Exception {
+ var response = mvc.perform(requestBuilder).andReturn().getResponse();
+ return new StandardCoder().decode(response.getContentAsString(), ApexApiResult.class);
+ }
+
+ private void createSession() throws Exception {
+ ApexApiResult result = apexRequest(get("/policy/gui/v1/apex/editor/-1/Session/Create"));
+ sessionId = Integer.parseInt(result.getMessages().get(0));
+ }
+
+ private void loadModel() throws Exception {
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ apexRequest(put("/policy/gui/v1/apex/editor/" + sessionId + "/Model/Load")
+ .content(modelString).contentType(APPLICATION_JSON));
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadEnabledTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadEnabledTest.java
new file mode 100644
index 0000000..4f4694a
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadEnabledTest.java
@@ -0,0 +1,101 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.plugin.upload;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.gui.editors.apex.ApexEditor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.test.web.client.ExpectedCount;
+import org.springframework.test.web.client.MockRestServiceServer;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+import org.springframework.web.client.RestTemplate;
+
+@SpringBootTest(classes = ApexEditor.class,
+ properties = "apex-editor.upload-url=http://localhost:12345")
+@AutoConfigureMockMvc
+class PolicyUploadEnabledTest {
+
+ @Autowired
+ private MockMvc mvc;
+
+ @Autowired
+ private RestTemplate policyUploadRestTemplate;
+
+ private MockRestServiceServer mockServer;
+
+ private int sessionId;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ mockServer = MockRestServiceServer.createServer(policyUploadRestTemplate);
+ createSession();
+ loadModel();
+ }
+
+ @Test
+ void testModelUpload() throws Exception {
+ mockServer.expect(ExpectedCount.once(),
+ requestTo("http://localhost:12345"))
+ .andExpect(method(HttpMethod.POST))
+ .andExpect(content().contentType(APPLICATION_JSON))
+ .andRespond(withStatus(HttpStatus.CREATED));
+
+ ApexApiResult result = apexRequest(get("/policy/gui/v1/apex/editor/" + sessionId + "/Model/Upload")
+ .queryParam("userId", "MyUser"));
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ mockServer.verify();
+ }
+
+ private ApexApiResult apexRequest(MockHttpServletRequestBuilder requestBuilder) throws Exception {
+ var response = mvc.perform(requestBuilder).andReturn().getResponse();
+ return new StandardCoder().decode(response.getContentAsString(), ApexApiResult.class);
+ }
+
+ private void createSession() throws Exception {
+ ApexApiResult result = apexRequest(get("/policy/gui/v1/apex/editor/-1/Session/Create"));
+ sessionId = Integer.parseInt(result.getMessages().get(0));
+ }
+
+ private void loadModel() throws Exception {
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ apexRequest(put("/policy/gui/v1/apex/editor/" + sessionId + "/Model/Load")
+ .content(modelString).contentType(APPLICATION_JSON));
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandlerTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandlerTest.java
index 4525f42..df5452b 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandlerTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandlerTest.java
@@ -21,84 +21,77 @@
package org.onap.policy.gui.editors.apex.rest.handling.plugin.upload;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.ResponseProcessingException;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatchers;
-import org.mockito.MockedStatic;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.gui.editors.apex.rest.ApexEditorMain;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpStatus;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
-public class PolicyUploadHandlerTest {
+@ExtendWith(MockitoExtension.class)
+class PolicyUploadHandlerTest {
- private static final String CMDLINE_UPLOAD_USERID = "MyUser";
+ private static final String DEFAULT_UPLOAD_USER_ID = "MyUser";
+ private static final String UPLOAD_URL = "http://127.0.0.1";
+
+ @Mock
+ private RestTemplate policyUploadRestTemplate;
+
+ @InjectMocks
private PolicyUploadHandler uploadHandler;
+
+ @Captor
+ ArgumentCaptor<HttpEntity<UploadPolicyRequestDto>> dtoEntityCaptor;
+
private AxArtifactKey axArtifactKey;
private String toscaServiceTemplate;
- private MockedStatic<ClientBuilder> clientBuilderMockedStatic;
- private ArgumentCaptor<Entity<UploadPolicyRequestDto>> dtoEntityCaptor;
/**
* Prepares test environment.
*
* @throws IOException where there is problem with reading the file.
*/
- @Before
- public void setUp() throws IOException {
- uploadHandler = new PolicyUploadHandler();
+ @BeforeEach
+ void setUp() throws IOException {
final var name = "a" + RandomStringUtils.randomAlphabetic(5);
final var version = "0.0.1";
axArtifactKey = new AxArtifactKey(name, version);
final var path = Path.of("src/test/resources/models/", "PolicyModel.json");
toscaServiceTemplate = Files.readString(path);
- }
-
- /**
- * Cleaning up after the test.
- */
- @After
- public void tearDown() {
- if (clientBuilderMockedStatic != null) {
- clientBuilderMockedStatic.close();
- }
+ ReflectionTestUtils.setField(uploadHandler, "uploadUrl", UPLOAD_URL);
+ ReflectionTestUtils.setField(uploadHandler, "defaultUserId", DEFAULT_UPLOAD_USER_ID);
}
@Test
- public void testDoUploadNoUrl() {
- final String[] args = {"--upload-userid", CMDLINE_UPLOAD_USERID};
- final var outBaStream = new ByteArrayOutputStream();
- final var outStream = new PrintStream(outBaStream);
- new ApexEditorMain(args, outStream);
-
+ void testDoUploadNoUrl() {
+ ReflectionTestUtils.setField(uploadHandler, "uploadUrl", null);
final var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "", "");
assertThat(result.isNok()).isTrue();
- assertThat(result.getMessage()).contains("Model upload is disable");
+ assertThat(result.getMessage()).contains("Model upload is disabled");
}
@Test
- public void testDoUploadConnectionError() {
- final var response = Mockito.mock(Response.class);
- mockRsHttpClient(response);
- Mockito.doThrow(ResponseProcessingException.class).when(response).getStatus();
-
- prepareApexEditorMain();
+ void testDoUploadConnectionError() {
+ when(policyUploadRestTemplate.postForObject(eq(UPLOAD_URL), any(HttpEntity.class), eq(String.class)))
+ .thenThrow(new RestClientException("connection error"));
final var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "", "");
@@ -107,27 +100,16 @@ public class PolicyUploadHandlerTest {
}
@Test
- public void testDoResponse() {
- final var response = Mockito.mock(Response.class);
- mockRsHttpClient(response);
-
- Mockito.doReturn(201).when(response).getStatus();
-
- prepareApexEditorMain();
-
+ void testDoResponse() {
final var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "", "");
assertThat(result.isOk()).isTrue();
}
@Test
- public void testDoResponseErrorCode500() {
- final var response = Mockito.mock(Response.class);
- mockRsHttpClient(response);
-
- Mockito.doReturn(500).when(response).getStatus();
-
- prepareApexEditorMain();
+ void testDoResponseErrorCode500() {
+ when(policyUploadRestTemplate.postForObject(eq(UPLOAD_URL), any(HttpEntity.class), eq(String.class)))
+ .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR));
final var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "", "");
@@ -136,55 +118,32 @@ public class PolicyUploadHandlerTest {
}
@Test
- public void testDoUploadUserId() {
- final var response = Mockito.mock(Response.class);
- mockRsHttpClient(response);
-
- Mockito.doReturn(201).when(response).getStatus();
-
- prepareApexEditorMain();
-
+ void testDoUploadUserId() {
// If uploadUserId is specified, that value should be in DTO.
var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "",
"OverrideUser");
assertThat(result.isOk()).isTrue();
- var dto = dtoEntityCaptor.getValue().getEntity();
+ Mockito.verify(policyUploadRestTemplate)
+ .postForObject(eq(UPLOAD_URL), dtoEntityCaptor.capture(), eq(String.class));
+ var dto = dtoEntityCaptor.getValue().getBody();
assertThat(dto.getUserId()).isEqualTo("OverrideUser");
+ Mockito.reset(policyUploadRestTemplate);
- // If uploadUserId is blank, the value from command line parameter 'upload-userid' is used.
+ // If uploadUserId is blank, the value from Spring config parameter 'apex-editor.upload-userid' is used.
result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "", "");
assertThat(result.isOk()).isTrue();
- dto = dtoEntityCaptor.getValue().getEntity();
- assertThat(dto.getUserId()).isEqualTo(CMDLINE_UPLOAD_USERID);
+ Mockito.verify(policyUploadRestTemplate)
+ .postForObject(eq(UPLOAD_URL), dtoEntityCaptor.capture(), eq(String.class));
+ dto = dtoEntityCaptor.getValue().getBody();
+ assertThat(dto.getUserId()).isEqualTo(DEFAULT_UPLOAD_USER_ID);
+ Mockito.reset(policyUploadRestTemplate);
- // If uploadUserId is null, the value from command line parameter 'upload-userid' is used.
+ // If uploadUserId is null, the value from Spring config parameter 'apex-editor.upload-userid' is used.
result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "", null);
assertThat(result.isOk()).isTrue();
- dto = dtoEntityCaptor.getValue().getEntity();
- assertThat(dto.getUserId()).isEqualTo(CMDLINE_UPLOAD_USERID);
- }
-
- private void mockRsHttpClient(Response response) {
- final var webTarget = Mockito.mock(WebTarget.class);
- final var client = Mockito.mock(Client.class);
- final var invocationBuilder = Mockito.mock(Invocation.Builder.class);
-
-
- clientBuilderMockedStatic = Mockito.mockStatic(ClientBuilder.class);
-
- dtoEntityCaptor = ArgumentCaptor.forClass(Entity.class);
-
- Mockito.when(ClientBuilder.newClient()).thenReturn(client);
- Mockito.when(client.target(ArgumentMatchers.anyString())).thenReturn(webTarget);
- Mockito.when(webTarget.request(MediaType.APPLICATION_JSON)).thenReturn(invocationBuilder);
- Mockito.when(webTarget.request(MediaType.APPLICATION_JSON)).thenReturn(invocationBuilder);
- Mockito.when(invocationBuilder.post(dtoEntityCaptor.capture())).thenReturn(response);
- }
-
- private void prepareApexEditorMain() {
- final String[] args = {"--upload-userid", CMDLINE_UPLOAD_USERID, "--upload-url", "http://127.0.0.1"};
- final var outBaStream = new ByteArrayOutputStream();
- final var outStream = new PrintStream(outBaStream);
- new ApexEditorMain(args, outStream);
+ Mockito.verify(policyUploadRestTemplate)
+ .postForObject(eq(UPLOAD_URL), dtoEntityCaptor.capture(), eq(String.class));
+ dto = dtoEntityCaptor.getValue().getBody();
+ assertThat(dto.getUserId()).isEqualTo(DEFAULT_UPLOAD_USER_ID);
}
}
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDtoTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDtoTest.java
index cb363e3..57e590b 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDtoTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDtoTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,13 +24,13 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Random;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class UploadPolicyRequestDtoTest {
+class UploadPolicyRequestDtoTest {
private final Random random = new Random();
@Test
- public void testId() {
+ void testId() {
final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
final var id = random.nextLong();
uploadPolicyRequestDto.setId(id);
@@ -38,7 +38,7 @@ public class UploadPolicyRequestDtoTest {
}
@Test
- public void testUserId() {
+ void testUserId() {
final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
final var id = RandomStringUtils.randomAlphanumeric(5);
uploadPolicyRequestDto.setUserId(id);
@@ -46,7 +46,7 @@ public class UploadPolicyRequestDtoTest {
}
@Test
- public void testFileName() {
+ void testFileName() {
final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
final var filename = RandomStringUtils.randomAlphabetic(6);
uploadPolicyRequestDto.setFilename(filename);
@@ -54,7 +54,7 @@ public class UploadPolicyRequestDtoTest {
}
@Test
- public void testFileData() {
+ void testFileData() {
final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
final var fileData = RandomStringUtils.randomAlphabetic(6);
uploadPolicyRequestDto.setFileData(fileData);