aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gui-editors/gui-editor-apex/pom.xml3
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java41
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java106
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionTest.java144
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtilsTest.java46
-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/PolicyUploadHandlerTest.java155
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDtoTest.java63
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/models/PolicyModelNoPolicies.yaml4
9 files changed, 613 insertions, 1 deletions
diff --git a/gui-editors/gui-editor-apex/pom.xml b/gui-editors/gui-editor-apex/pom.xml
index a87e0fd..2090e9e 100644
--- a/gui-editors/gui-editor-apex/pom.xml
+++ b/gui-editors/gui-editor-apex/pom.xml
@@ -122,7 +122,8 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
+ <artifactId>mockito-inline</artifactId>
+ <version>3.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
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
new file mode 100644
index 0000000..9201983
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParametersTest.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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;
+
+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");
+ assertThat(actual).contains("upload-userid parameter must be specified");
+ assertThat(actual).contains("port must be between");
+ assertThat(actual).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/handling/KeyInfoHandlerTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java
new file mode 100644
index 0000000..7d193ce
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandlerTest.java
@@ -0,0 +1,106 @@
+/*-
+ * ============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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Random;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+
+public class KeyInfoHandlerTest {
+ private final Random random = new Random();
+ private KeyInfoHandler handler;
+
+ @Before
+ public void setUp() {
+ handler = new KeyInfoHandler();
+ }
+
+ @Test
+ public void testExecuteRestCommand() {
+ final var sessionId = random.nextInt();
+ final var session = new RestSession(sessionId);
+ final var commandType = RestCommandType.EVENT;
+ final var command = RestCommand.ANALYSE;
+
+ final var actual = handler.executeRestCommand(session, commandType, command);
+
+ assertThat(actual.getResult()).isEqualTo(ApexApiResult.Result.FAILED);
+ assertThat(actual.getMessage()).contains(Integer.toString(sessionId));
+ assertThat(actual.getMessage()).contains(commandType.toString());
+ assertThat(actual.getMessage()).contains(command.toString());
+ }
+
+ @Test
+ public void testExecuteRestCommandWithJsonString() {
+ final var sessionId = random.nextInt();
+ final var session = new RestSession(sessionId);
+ final var commandType = RestCommandType.EVENT;
+ final var command = RestCommand.ANALYSE;
+ final var emptyString = "";
+
+ final var actual = handler.executeRestCommand(session, commandType, command, emptyString);
+
+ assertThat(actual.getResult()).isEqualTo(ApexApiResult.Result.FAILED);
+ assertThat(actual.getMessage()).contains(Integer.toString(sessionId));
+ assertThat(actual.getMessage()).contains(commandType.toString());
+ assertThat(actual.getMessage()).contains(command.toString());
+ }
+
+ @Test
+ public void testExecuteRestCommandWithNameAndVersion() {
+ final var sessionId = random.nextInt();
+ final var session = new RestSession(sessionId);
+ final var commandType = RestCommandType.EVENT;
+ final var command = RestCommand.ANALYSE;
+ final var name = "";
+ final var version = "";
+
+ final var actual = handler.executeRestCommand(session, commandType, command, name, version);
+
+ assertThat(actual.getResult()).isEqualTo(ApexApiResult.Result.FAILED);
+ assertThat(actual.getMessage()).contains(Integer.toString(sessionId));
+ assertThat(actual.getMessage()).contains(commandType.toString());
+ assertThat(actual.getMessage()).contains(command.toString());
+ }
+
+ @Test
+ public void testExecuteRestCommandWithNameAndVersion2() {
+ final var session = Mockito.mock(RestSession.class);
+ final var commandType = RestCommandType.KEY_INFO;
+ final var command = RestCommand.LIST;
+ final var name = "";
+ final var version = "version";
+ final var expected = new ApexApiResult();
+ final var apexModel = Mockito.mock(ApexModel.class);
+
+ Mockito.when(session.getApexModel()).thenReturn(apexModel);
+ Mockito.when(apexModel.listKeyInformation(null, version)).thenReturn(expected);
+
+ final var actual = handler.executeRestCommand(session, commandType, command, name, version);
+
+ assertThat(actual).isEqualTo(expected);
+ }
+}
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
new file mode 100644
index 0000000..8717198
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionTest.java
@@ -0,0 +1,144 @@
+/*-
+ * ============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;
+
+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;
+
+public 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() {
+ sessionId = new Random().nextInt();
+ restSession = new RestSession(sessionId);
+ }
+
+ @Test
+ public void testGetSessionId() {
+ final var actual = restSession.getSessionId();
+ assertThat(actual).isEqualTo(sessionId);
+ }
+
+ @Test
+ public void testCommitChangesNoChanges() {
+ final var apexApiResult = restSession.commitChanges();
+ assertThat(apexApiResult.isNok()).isTrue();
+ }
+
+ @Test
+ public void testCommitChanges() {
+ restSession.editModel();
+ final var apexApiResult = restSession.commitChanges();
+ assertThat(apexApiResult.isOk()).isTrue();
+ }
+
+ @Test
+ public void testDiscardChangesNotEdited() {
+ final var apexApiResult = restSession.discardChanges();
+ assertThat(apexApiResult.isNok()).isTrue();
+ }
+
+ @Test
+ public void testDiscardChanges() {
+ restSession.editModel();
+ final var apexApiResult = restSession.discardChanges();
+ assertThat(apexApiResult.isOk()).isTrue();
+ assertThat(restSession.getApexModelEdited()).isNull();
+ }
+
+ @Test
+ public void testDownloadModel() {
+ final var actual = restSession.downloadModel();
+ assertThat(actual.isOk()).isTrue();
+ }
+
+ @Test
+ public void testEditModel() {
+ final var original = restSession.getApexModelEdited();
+ final var apexApiResult = restSession.editModel();
+ final var apexModelEdited = restSession.getApexModelEdited();
+ final var apexModel = restSession.getApexModel();
+ assertThat(apexApiResult.isOk()).isTrue();
+ assertThat(original).isNull();
+ assertThat(apexModel).isNotNull();
+ }
+
+ @Test
+ public void testEditModelAlreadyEdited() {
+ restSession.editModel();
+ final var apexApiResult = restSession.editModel();
+ assertThat(apexApiResult.isNok()).isTrue();
+ }
+
+ @Test
+ public void testLoadFromString() throws IOException {
+ restSession.editModel();
+ final var toscaPath = Path.of("src/test/resources/models/PolicyModel.yaml");
+ final var toscaString = Files.readString(toscaPath);
+ final var apexApiResult = restSession.loadFromString(toscaString);
+ assertThat(apexApiResult.isOk()).isTrue();
+ final var apexModelEdited = restSession.getApexModelEdited();
+ assertThat(apexModelEdited).isNotNull();
+ }
+
+ @Test
+ public void testLoadFromStringNoPolicies() throws IOException {
+ restSession.editModel();
+ final var toscaPath = Path.of("src/test/resources/models/PolicyModelNoPolicies.yaml");
+ final var toscaString = Files.readString(toscaPath);
+ final var apexApiResult = restSession.loadFromString(toscaString);
+ 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
new file mode 100644
index 0000000..84876d5
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtilsTest.java
@@ -0,0 +1,46 @@
+/*-
+ * ============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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Test;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanModel;
+
+public class RestUtilsTest {
+
+ @Test
+ public void getJsonParameters() {
+ final var name = RandomStringUtils.randomAlphabetic(3);
+ final var uuid = RandomStringUtils.randomAlphabetic(4);
+ final var desc = RandomStringUtils.randomAlphabetic(5);
+ final var jsonString =
+ "{name: \"" + name + "\", version: \"\", uuid: \"" + uuid + "\", description: \"" + desc
+ + "\"}";
+ final var actual = RestUtils.getJsonParameters(jsonString, BeanModel.class);
+
+ assertThat(actual.getName()).isEqualTo(name);
+ assertThat(actual.getVersion()).isNull();
+ assertThat(actual.getUuid()).isEqualTo(uuid);
+ assertThat(actual.getDescription()).isEqualTo(desc);
+ }
+}
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
new file mode 100644
index 0000000..5d45db7
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKeyTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============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/PolicyUploadHandlerTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandlerTest.java
new file mode 100644
index 0000000..7c97734
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandlerTest.java
@@ -0,0 +1,155 @@
+/*-
+ * ============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.plugin.upload;
+
+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 javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+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.mockito.ArgumentMatchers;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.gui.editors.apex.rest.ApexEditorMain;
+
+public class PolicyUploadHandlerTest {
+
+ private PolicyUploadHandler uploadHandler;
+ private AxArtifactKey axArtifactKey;
+ private String toscaServiceTemplate;
+ private MockedStatic<ClientBuilder> clientBuilderMockedStatic;
+
+ /**
+ * Prepares test environment.
+ *
+ * @throws IOException where there is problem with reading the file.
+ */
+ @Before
+ public void setUp() throws IOException {
+ uploadHandler = new PolicyUploadHandler();
+ 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/converter/", "ToscaTemplate.json");
+ toscaServiceTemplate = Files.readString(path);
+ }
+
+ /**
+ * Cleaning up after the test.
+ */
+ @After
+ public void tearDown() {
+ if (clientBuilderMockedStatic != null) {
+ clientBuilderMockedStatic.close();
+ }
+ }
+
+ @Test
+ public void testDoUploadNoUrl() {
+ final String[] args = {"--upload-userid", "MyUser"};
+ final var outBaStream = new ByteArrayOutputStream();
+ final var outStream = new PrintStream(outBaStream);
+ new ApexEditorMain(args, outStream);
+
+ final var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "");
+ assertThat(result.isNok()).isTrue();
+ assertThat(result.getMessage()).contains("Model upload is disable");
+ }
+
+ @Test
+ public void testDoUploadConnectionError() {
+ final var response = Mockito.mock(Response.class);
+ mockRsHttpClient(response);
+ Mockito.doThrow(ResponseProcessingException.class).when(response).getStatus();
+
+ prepareApexEditorMain();
+
+ final var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "");
+
+ assertThat(result.isNok()).isTrue();
+ assertThat(result.getMessage()).contains("failed with error");
+ }
+
+ @Test
+ public void testDoResponse() {
+ final var response = Mockito.mock(Response.class);
+ mockRsHttpClient(response);
+
+ Mockito.doReturn(201).when(response).getStatus();
+
+ prepareApexEditorMain();
+
+ 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();
+
+ final var result = uploadHandler.doUpload(toscaServiceTemplate, axArtifactKey, "");
+
+ assertThat(result.isNok()).isTrue();
+ assertThat(result.getMessage()).contains("failed with status 500");
+ }
+
+ 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);
+
+ 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(ArgumentMatchers.any())).thenReturn(response);
+ }
+
+ private void prepareApexEditorMain() {
+ final String[] args = {"--upload-userid", "MyUser", "--upload-url", "http://127.0.0.1"};
+ final var outBaStream = new ByteArrayOutputStream();
+ final var outStream = new PrintStream(outBaStream);
+ new ApexEditorMain(args, outStream);
+ }
+}
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
new file mode 100644
index 0000000..cb363e3
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDtoTest.java
@@ -0,0 +1,63 @@
+/*-
+ * ============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.plugin.upload;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Random;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Test;
+
+public class UploadPolicyRequestDtoTest {
+ private final Random random = new Random();
+
+ @Test
+ public void testId() {
+ final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
+ final var id = random.nextLong();
+ uploadPolicyRequestDto.setId(id);
+ assertThat(uploadPolicyRequestDto.getId()).isEqualTo(id);
+ }
+
+ @Test
+ public void testUserId() {
+ final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
+ final var id = RandomStringUtils.randomAlphanumeric(5);
+ uploadPolicyRequestDto.setUserId(id);
+ assertThat(uploadPolicyRequestDto.getUserId()).isEqualTo(id);
+ }
+
+ @Test
+ public void testFileName() {
+ final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
+ final var filename = RandomStringUtils.randomAlphabetic(6);
+ uploadPolicyRequestDto.setFilename(filename);
+ assertThat(uploadPolicyRequestDto.getFilename()).isEqualTo(filename);
+ }
+
+ @Test
+ public void testFileData() {
+ final var uploadPolicyRequestDto = new UploadPolicyRequestDto();
+ final var fileData = RandomStringUtils.randomAlphabetic(6);
+ uploadPolicyRequestDto.setFileData(fileData);
+ assertThat(uploadPolicyRequestDto.getFileData()).isEqualTo(fileData);
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/test/resources/models/PolicyModelNoPolicies.yaml b/gui-editors/gui-editor-apex/src/test/resources/models/PolicyModelNoPolicies.yaml
new file mode 100644
index 0000000..1fd228a
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/models/PolicyModelNoPolicies.yaml
@@ -0,0 +1,4 @@
+---
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+topology_template:
+ policies: