aboutsummaryrefslogtreecommitdiffstats
path: root/client/client-deployment/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-09-04 11:03:24 +0100
committerliamfallon <liam.fallon@est.tech>2020-09-04 11:24:29 +0100
commit25e3f7a0d6cd5e364e4fd69eef310fcdb8a58b55 (patch)
tree0bf44a0a6a7be18568e368c35f983e18a23fa42b /client/client-deployment/src/test
parent508bdbd4d17ebf3726d92553839cc4b3af922250 (diff)
Remove client code from apex-pdp
Removal of the deployment and monitoring client from the apex-pdp as the functionality is replaced by the Policy Framework deployment using PAP and the Policy Framework monitoring GUI. Code in the engine proper that was used to administer apex-pdp over the Web Socket port is also removed, as this code was only used by the apex-pdp legacy GUIs. Issue-ID: POLICY-2621 Change-Id: Ib9fc4a667a4bc79377bb7b82fae6a2bd520a3e3d Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'client/client-deployment/src/test')
-rw-r--r--client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentExceptionTest.java38
-rw-r--r--client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java215
-rw-r--r--client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestParameterTest.java39
-rw-r--r--client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/ParameterCheckTest.java189
-rw-r--r--client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/RestResourceTest.java176
5 files changed, 0 insertions, 657 deletions
diff --git a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentExceptionTest.java b/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentExceptionTest.java
deleted file mode 100644
index d89f1faa6..000000000
--- a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentExceptionTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.apex.client.deployment.rest;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-/**
- * Test the REST Deployment exception.
- *
- */
-public class DeploymentExceptionTest {
-
- @Test
- public void test() {
- ApexDeploymentRestParameterException ame = new ApexDeploymentRestParameterException("a message");
- assertEquals("a message", ame.getMessage());
- }
-}
diff --git a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java b/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java
deleted file mode 100644
index 1ab6cc1d9..000000000
--- a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestMainTest.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 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.apex.client.deployment.rest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.assertj.core.api.Assertions.catchThrowable;
-import static org.awaitility.Awaitility.await;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Test;
-
-/**
- * Test the periodic event manager utility.
- */
-public class DeploymentRestMainTest {
- private static InputStream systemInStream = System.in;
-
- @Test
- public void testDeploymentClientOk() {
- final String[] eventArgs = {"-t", "1", "-p", "1256"};
- assertThatCode(() -> ApexDeploymentRestMain.main(eventArgs)).doesNotThrowAnyException();
- }
-
- @Test
- public void testDeploymentClientNoOptions() {
- final String[] eventArgs = new String[] {};
- assertThat(testApexDeploymentRestMainConstructor(eventArgs)).isEqualTo("*** StdOut ***\n\n*** StdErr ***\n");
- }
-
- @Test
- public void testDeploymentClientBadOptions() {
- final String[] eventArgs = {"-zabbu"};
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class)
- .hasMessageContaining("Apex Services REST endpoint (ApexDeploymentRestMain: Config=[null], State=STOPPED) "
- + "parameter error, invalid command line arguments specified " + ": Unrecognized option: -zabbu");
- }
-
- @Test
- public void testDeploymentClientHelp() {
- final String[] eventArgs = {"-h"};
-
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class).hasMessageContaining(
- "usage: org.onap.policy.apex.client.deployment.rest.ApexDeploymentRestMain [options...]");
-
- }
-
- @Test
- public void testDeploymentClientPortBad() {
- final String[] eventArgs = {"-p", "hello"};
-
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class)
- .hasMessageContaining("Apex Services REST endpoint (ApexDeploymentRestMain: Config=[null], State=STOPPED) "
- + "parameter error, error parsing argument \"port\" :For input string: \"hello\"");
-
- }
-
- @Test
- public void testDeploymentClientPortNegative() {
- final String[] eventArgs = {"-p", "-1"};
-
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class).hasMessageContaining(
- "Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: "
- + "URI=http://localhost:-1/apexservices/, TTL=-1sec], State=STOPPED) parameters invalid, "
- + "port must be greater than 1023 and less than 65536");
-
- }
-
- @Test
- public void testDeploymentClientTtlTooSmall() {
- final String[] eventArgs = {"-t", "-2"};
-
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class).hasMessageContaining(
- "Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: "
- + "URI=http://localhost:18989/apexservices/, TTL=-2sec], State=STOPPED) parameters invalid, "
- + "time to live must be greater than -1 (set to -1 to wait forever)");
-
- }
-
- @Test
- public void testDeploymentClientTooManyPars() {
- final String[] eventArgs = {"-t", "10", "-p", "12344", "aaa", "bbb"};
-
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class)
- .hasMessageContaining("Apex Services REST endpoint (ApexDeploymentRestMain: Config=[null], State=STOPPED) "
- + "parameter error, too many command line arguments specified : [aaa, bbb]");
- }
-
- @Test
- public void testDeploymentClientDefaultPars() {
- assertThatCode(() -> {
- ApexDeploymentRest monRest = new ApexDeploymentRest();
- monRest.shutdown();
- }).doesNotThrowAnyException();
-
- }
-
- @Test
- public void testDeploymentClientTtlNotNumber() {
- final String[] eventArgs = {"-t", "timetolive"};
-
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class)
- .hasMessageContaining("Apex Services REST endpoint (ApexDeploymentRestMain: Config=[null], State=STOPPED) "
- + "parameter error, error parsing argument \"time-to-live\" :" + "For input string: \"timetolive\"");
-
- }
-
- @Test
- public void testDeploymentClientPortTooBig() {
- final String[] eventArgs = {"-p", "65536"};
-
- Throwable thrown = catchThrowable(() -> new ApexDeploymentRestMain(eventArgs, System.out));
-
- assertThat(thrown).isInstanceOf(Exception.class).hasMessageContaining(
- "Apex Services REST endpoint (ApexDeploymentRestMain: Config=[ApexDeploymentRestParameters: "
- + "URI=http://localhost:65536/apexservices/, TTL=-1sec], State=STOPPED) parameters invalid, "
- + "port must be greater than 1023 and less than 65536");
- }
-
- @Test
- public void testDeploymentOneSecStart() {
- final String[] eventArgs = {"-t", "1"};
-
- assertThatCode(() -> {
- ApexDeploymentRestMain monRestMain = new ApexDeploymentRestMain(eventArgs, System.out);
- monRestMain.init();
- monRestMain.shutdown();
- }).doesNotThrowAnyException();
-
- }
-
- @Test
- public void testDeploymentForeverStart() {
- final String[] eventArgs = {"-t", "-1"};
-
- ApexDeploymentRestMain monRestMain = new ApexDeploymentRestMain(eventArgs, System.out);
-
- Thread monThread = new Thread() {
- @Override
- public void run() {
- monRestMain.init();
- }
- };
-
- assertThatCode(() -> {
- monThread.start();
- await().atMost(2, TimeUnit.SECONDS)
- .until(() -> monRestMain.getState().equals(ApexDeploymentRestMain.ServicesState.RUNNING));
- monRestMain.shutdown();
- }).doesNotThrowAnyException();
- }
-
- @After
- public void cleanUpStreamSetting() {
- System.setIn(systemInStream);
- }
-
- /**
- * Run the application.
- *
- * @param eventArgs the command arguments
- * @return a string containing the command output
- */
- private String testApexDeploymentRestMainConstructor(final String[] eventArgs) {
- final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
- final ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
-
- new ApexDeploymentRestMain(eventArgs, new PrintStream(baosOut, true));
-
- InputStream testInput = new ByteArrayInputStream("Test Data for Input to WS".getBytes());
- System.setIn(testInput);
-
- String outString = baosOut.toString();
- String errString = baosErr.toString();
-
- return "*** StdOut ***\n" + outString + "\n*** StdErr ***\n" + errString;
- }
-}
diff --git a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestParameterTest.java b/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestParameterTest.java
deleted file mode 100644
index 16a7b2897..000000000
--- a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/DeploymentRestParameterTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.apex.client.deployment.rest;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-/**
- * Extra Deployment rest tests.
- *
- */
-public class DeploymentRestParameterTest {
-
- @Test
- public void test() {
- ApexDeploymentRestParameters parameters = new ApexDeploymentRestParameters();
- parameters.setRestPort(12345);
- assertEquals(12345, parameters.getRestPort());
- }
-}
diff --git a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/ParameterCheckTest.java b/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/ParameterCheckTest.java
deleted file mode 100644
index 9218347df..000000000
--- a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/ParameterCheckTest.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.apex.client.deployment.rest;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-
-/**
- * Test the parameter check class.
- *
- */
-public class ParameterCheckTest {
-
- @Test
- public void testStartStop() {
- assertEquals("START", ParameterCheck.StartStop.START.name());
- assertEquals("STOP", ParameterCheck.StartStop.STOP.name());
- }
-
- @Test
- public void testHostName() {
- assertNull(ParameterCheck.getHostName(null));
-
- Map<String, String[]> parameterMap = new LinkedHashMap<>();
- assertNull(ParameterCheck.getHostName(parameterMap));
- parameterMap.put("hostname", null);
- assertNull(ParameterCheck.getHostName(parameterMap));
-
- String[] hostnameBlankValue0 = {"", ""};
- parameterMap.put("hostname", hostnameBlankValue0);
- assertNull(ParameterCheck.getHostName(parameterMap));
-
- String[] hostnameBlankValue1 = {" ", " "};
- parameterMap.put("hostname", hostnameBlankValue1);
- assertNull(ParameterCheck.getHostName(parameterMap));
-
- String[] hostnameValue = {"hostname0", "hostname1"};
- parameterMap.put("hostname", hostnameValue);
- assertEquals("hostname0", ParameterCheck.getHostName(parameterMap));
- }
-
- @Test
- public void testPort() {
- assertEquals(-1, ParameterCheck.getPort(null));
-
- Map<String, String[]> parameterMap = new LinkedHashMap<>();
- assertEquals(-1, ParameterCheck.getPort(parameterMap));
-
- String[] portBlankValue0 = {"", ""};
- parameterMap.put("port", portBlankValue0);
- assertEquals(-1, ParameterCheck.getPort(parameterMap));
-
- String[] portBlankValue1 = {" ", " "};
- parameterMap.put("port", portBlankValue1);
- assertEquals(-1, ParameterCheck.getPort(parameterMap));
-
- String[] portValueBad = {"port", "value"};
- parameterMap.put("port", portValueBad);
- assertEquals(-1, ParameterCheck.getPort(parameterMap));
-
- String[] portValueRange0 = {"-1", "-1"};
- parameterMap.put("port", portValueRange0);
- assertEquals(-1, ParameterCheck.getPort(parameterMap));
-
- String[] portValueRange1 = {"65536", "65536"};
- parameterMap.put("port", portValueRange1);
- assertEquals(-1, ParameterCheck.getPort(parameterMap));
-
- String[] portValue = {"12344", "23221"};
- parameterMap.put("port", portValue);
- assertEquals(12344, ParameterCheck.getPort(parameterMap));
- }
-
- @Test
- public void testEngineKey() {
- assertEquals(null, ParameterCheck.getEngineKey(null));
-
- Map<String, String[]> parameterMap = new LinkedHashMap<>();
- parameterMap.put("Zooby", null);
- assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
-
- parameterMap.put("AxArtifactKey", null);
- assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
- parameterMap.remove("AxArtifactKey");
-
- parameterMap.put("AxArtifactKey#zooby", null);
- assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
- parameterMap.remove("AxArtifactKey#zooby");
-
- parameterMap.put("AxArtifactKey#zooby#looby", null);
- assertEquals(null, ParameterCheck.getEngineKey(parameterMap));
- parameterMap.remove("AxArtifactKey#zooby#looby");
-
- parameterMap.put("AxArtifactKey#Name:0.0.1", null);
- assertEquals(new AxArtifactKey("Name", "0.0.1"), ParameterCheck.getEngineKey(parameterMap));
- }
-
- @Test
- public void testStartStopValue() {
- assertEquals(null, ParameterCheck.getStartStop(null, null));
-
- Map<String, String[]> parameterMap = new LinkedHashMap<>();
- assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
-
- parameterMap.put("Zooby", null);
- assertEquals(null, ParameterCheck.getStartStop(parameterMap, null));
-
- AxArtifactKey engineKey = new AxArtifactKey("Engine", "0.0.1");
-
- parameterMap.put("Zooby", null);
- assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
-
- String key = "AxArtifactKey#" + engineKey.getId();
-
- parameterMap.put(key, null);
- assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
-
- String[] startStopBlankValue0 = {"", ""};
- parameterMap.put(key, startStopBlankValue0);
- assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
-
- String[] startStopBlankValue1 = {" ", " "};
- parameterMap.put(key, startStopBlankValue1);
- assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
-
- String[] startStopValueBad = {key, "value"};
- parameterMap.put(key, startStopValueBad);
- assertEquals(null, ParameterCheck.getStartStop(parameterMap, engineKey));
-
- String[] startValue = {"START", "STOP"};
- parameterMap.put(key, startValue);
- assertEquals(ParameterCheck.StartStop.START, ParameterCheck.getStartStop(parameterMap, engineKey));
-
- String[] stopValue = {"STOP", "START"};
- parameterMap.put(key, stopValue);
- assertEquals(ParameterCheck.StartStop.STOP, ParameterCheck.getStartStop(parameterMap, engineKey));
- }
-
- @Test
- public void testLong() {
- assertEquals(-1, ParameterCheck.getLong(null, null));
-
- Map<String, String[]> parameterMap = new LinkedHashMap<>();
- assertEquals(-1, ParameterCheck.getLong(parameterMap, null));
-
- parameterMap.put("long0", null);
- assertEquals(-1, ParameterCheck.getLong(parameterMap, "longx"));
- assertEquals(-1, ParameterCheck.getLong(parameterMap, "long0"));
-
- String[] longBlankValue0 = {"", ""};
- parameterMap.put("long1", longBlankValue0);
- assertEquals(-1, ParameterCheck.getLong(parameterMap, "long1"));
-
- String[] longBlankValue1 = {" ", " "};
- parameterMap.put("long2", longBlankValue1);
- assertEquals(-1, ParameterCheck.getLong(parameterMap, "long2"));
-
- String[] longValueBad = {"long", "value"};
- parameterMap.put("long3", longValueBad);
- assertEquals(-1, ParameterCheck.getLong(parameterMap, "long3"));
-
- String[] longValue = {"12345", "6789"};
- parameterMap.put("long4", longValue);
- assertEquals(12345, ParameterCheck.getLong(parameterMap, "long4"));
- }
-}
diff --git a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/RestResourceTest.java b/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/RestResourceTest.java
deleted file mode 100644
index 019ccc8cb..000000000
--- a/client/client-deployment/src/test/java/org/onap/policy/apex/client/deployment/rest/RestResourceTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.apex.client.deployment.rest;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import javax.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.policy.apex.core.deployment.ApexDeploymentException;
-import org.onap.policy.apex.core.deployment.EngineServiceFacade;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
-
-/**
- * Test the Deployment rest resource.
- */
-public class RestResourceTest {
- @Mock
- private EngineServiceFacade engineServiceFacadeMock;
- private ApexDeploymentRestResource restResource;
-
- /**
- * Set up mocking of the engine service facade.
- *
- * @throws ApexException on engine service facade setup errors
- */
- @Before
- public void initializeMocking() throws ApexException {
- MockitoAnnotations.initMocks(this);
-
- final AxArtifactKey engineServiceKey = new AxArtifactKey("EngineServiceKey", "0.0.1");
- final AxArtifactKey engineKey = new AxArtifactKey("Engine0", "0.0.1");
- final AxArtifactKey[] engineServiceKeyArray = {engineKey};
- final AxEngineModel engineModel = new AxEngineModel(engineServiceKeyArray[0]);
-
- restResource = Mockito.spy(new ApexDeploymentRestResource());
- Mockito.doReturn(engineServiceFacadeMock).when(restResource).getEngineServiceFacade("apexServer", 12345);
-
- Mockito.doReturn(engineServiceKey).when(engineServiceFacadeMock).getKey();
- Mockito.doReturn(engineServiceKeyArray).when(engineServiceFacadeMock).getEngineKeyArray();
- Mockito.doReturn(engineModel).when(engineServiceFacadeMock).getEngineStatus(engineKey);
- }
-
- @Test
- public void testRestResourceCreateSession() throws ApexException {
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testRestResourceCreateSessionWithApexModelKey() throws ApexException {
- Mockito.doReturn(new AxArtifactKey("ModelKey:0.0.1")).when(engineServiceFacadeMock).getApexModelKey();
-
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testRestResourceCreateSessionConnectException() throws ApexException {
- Mockito.doThrow(new ApexDeploymentException("Connection Failed")).when(engineServiceFacadeMock).init();
-
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(500, response.getStatus());
- assertTrue(((String) response.getEntity()).contains("Error connecting to Apex Engine Service"));
- }
-
- @Test
- public void testRestResourceCreateSessionGetException() throws ApexException {
- final AxArtifactKey engineKey = new AxArtifactKey("Engine0", "0.0.1");
- Mockito.doThrow(new ApexException("Exception on get")).when(engineServiceFacadeMock).getEngineStatus(engineKey);
-
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testRestResourceCreateSessionInfo() throws ApexException {
- final AxArtifactKey engineKey = new AxArtifactKey("Engine0", "0.0.1");
- Mockito.doReturn("{}").when(engineServiceFacadeMock).getEngineInfo(engineKey);
-
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testRestResourceCreateSessionNullInfo() throws ApexException {
- final AxArtifactKey engineKey = new AxArtifactKey("Engine0", "0.0.1");
- Mockito.doReturn(null).when(engineServiceFacadeMock).getEngineInfo(engineKey);
-
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testRestResourceCreateSessionEmptyInfo() throws ApexException {
- final AxArtifactKey engineKey = new AxArtifactKey("Engine0", "0.0.1");
- Mockito.doReturn(" ").when(engineServiceFacadeMock).getEngineInfo(engineKey);
-
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testRestResourceCreateSessionExceptionInfo() throws ApexException {
- final AxArtifactKey engineKey = new AxArtifactKey("Engine0", "0.0.1");
- Mockito.doThrow(new ApexException("Exception on info")).when(engineServiceFacadeMock).getEngineInfo(engineKey);
-
- Response response = restResource.createSession("apexServer", 12345);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void testRestResourcemodelUpload() throws ApexException {
- InputStream uploadedInputStream =
- new ByteArrayInputStream("src/test/resources/models/SmallModel.json".getBytes());
-
- Response response = restResource.modelUpload("apexServer", 12345,
- uploadedInputStream, "SmallModel.json", false, false);
- assertEquals(200, response.getStatus());
- assertTrue(((String) response.getEntity()).contains("SmallModel.json"));
- }
-
- @Test
- public void testRestResourcemodelUploadNoConnection() throws ApexException {
- Mockito.doThrow(new ApexDeploymentException("Connection Failed")).when(engineServiceFacadeMock).init();
-
- InputStream uploadedInputStream =
- new ByteArrayInputStream("src/test/resources/models/SmallModel.json".getBytes());
-
- Response response =
- restResource.modelUpload("apexServer", 12345, uploadedInputStream, "SmallModel.json", false, false);
- assertEquals(500, response.getStatus());
- }
-
- @Test
- public void testRestResourcemodelUploadDeploy() throws ApexException {
-
- InputStream uploadedInputStream =
- new ByteArrayInputStream("src/test/resources/models/SmallModel.json".getBytes());
-
- Mockito.doThrow(new ApexDeploymentException("Connection Failed")).when(engineServiceFacadeMock)
- .deployModel("SmallModel.json", uploadedInputStream, false, true);
-
-
- Response response =
- restResource.modelUpload("apexServer", 12345, uploadedInputStream, "SmallModel.json", false, true);
- assertEquals(500, response.getStatus());
- assertTrue(((String) response.getEntity()).contains("Error updating model on engine service"));
- }
-}