From ddb67dc3cbb04f4857f2cf24221b306fa2bab052 Mon Sep 17 00:00:00 2001 From: James Guistwite Date: Wed, 1 May 2019 09:24:06 -0400 Subject: Improved test coverage. Reorganized some of the tests due to comments Issue-ID: SDC-2238 Change-Id: I6b3bcc674c792f3c5c06e851a2cfe2d92eead07c Signed-off-by: James Guistwite --- .../externaltesting/rest/services/ApiTest.java | 260 +++++++++++++ .../externaltesting/rest/services/ApiTests.java | 207 ---------- .../src/test/data/failedexecution.json | 6 + .../externaltesting/api/ConfigurationTest.java | 66 ++++ .../core/externaltesting/api/ErrorBodyTest.java | 42 ++ .../core/externaltesting/api/ErrorBodyTests.java | 42 -- .../externaltesting/api/ExecutionRequestTest.java | 115 ++++++ .../externaltesting/api/ExecutionRequestTests.java | 102 ----- .../api/ExternalTestingApiTests.java | 5 +- .../externaltesting/impl/ConfigurationTests.java | 80 ---- .../impl/ExternalTestingManagerImplTest.java | 422 +++++++++++++++++++++ .../impl/ExternalTestingManagerImplTests.java | 422 --------------------- .../impl/ExternalTestingTestSuite.java | 4 +- .../impl/TestingAccessConfigTest.java | 42 ++ 14 files changed, 958 insertions(+), 857 deletions(-) create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java delete mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java create mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/data/failedexecution.json create mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ConfigurationTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTest.java delete mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTests.java create mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTest.java delete mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTests.java delete mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ConfigurationTests.java create mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java delete mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTests.java create mode 100644 openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/TestingAccessConfigTest.java diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java new file mode 100644 index 0000000000..5f302bebc6 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTest.java @@ -0,0 +1,260 @@ +/* + * Copyright © 2019 iconectiv + * + * 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. + */ + +package org.openecomp.sdcrests.externaltesting.rest.services; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.core.externaltesting.api.*; +import org.openecomp.core.externaltesting.errors.ExternalTestingException; + +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ApiTest { + + private static final String EP = "ep"; + private static final String EXEC = "exec"; + private static final String SC = "sc"; + private static final String TS = "ts"; + private static final String TC = "tc"; + private static final String EXPECTED = "Expected"; + + + @Mock + private ExternalTestingManager testingManager; + + /** + * At the API level, test that the code does not throw + * exceptions but there's not much to test. + */ + @Test + public void testApi() { + MockitoAnnotations.initMocks(this); + + ExternalTestingImpl testing = new ExternalTestingImpl(testingManager); + Assert.assertNotNull(testing.getConfig()); + Assert.assertNotNull(testing.getEndpoints()); + Assert.assertNotNull(testing.getExecution(EP, EXEC)); + Assert.assertNotNull(testing.getScenarios(EP)); + Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC)); + Assert.assertNotNull(testing.getTestcases(EP, SC)); + Assert.assertNotNull(testing.getTestsuites(EP, SC)); + Assert.assertNotNull(testing.getTestCasesAsTree()); + + List requests = + Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); + Assert.assertNotNull(testing.execute(requests, "requestId")); + + + ClientConfiguration cc = new ClientConfiguration(); + Assert.assertNotNull(testing.setConfig(cc)); + + ArrayList lst = new ArrayList<>(); + Assert.assertNotNull(testing.setEndpoints(lst)); + } + + class ApiTestExternalTestingManager implements ExternalTestingManager { + @Override + public ClientConfiguration getConfig() { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public ClientConfiguration setConfig(ClientConfiguration config) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public List setEndpoints(List endpoints) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public TestTreeNode getTestCasesAsTree() { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public List getEndpoints() { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public List getScenarios(String endpoint) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public List getTestSuites(String endpoint, String scenario) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public List getTestCases(String endpoint, String scenario) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public List execute(List requests, String requestId) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + + @Override + public VtpTestExecutionResponse getExecution(String endpoint, String executionId) { + throw new ExternalTestingException(EXPECTED, 500, EXPECTED); + } + } + + /** + * Test the exception handler logic for configuration get/set. + */ + @Test() + public void testConfigExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + Response getResponse = testingF.getConfig(); + Assert.assertEquals(500, getResponse.getStatus()); + + Response setResponse = testingF.setConfig(new ClientConfiguration()); + Assert.assertEquals(500, setResponse.getStatus()); + } + + /** + * Test the exception handler logic for endpoint get/set. + */ + @Test() + public void testEndpointExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + Response getResponse = testingF.getEndpoints(); + Assert.assertEquals(500, getResponse.getStatus()); + + Response setResponse = testingF.setEndpoints(new ArrayList<>()); + Assert.assertEquals(500, setResponse.getStatus()); + } + + /** + * Test the exception handler logic for executions (invocation and query). + */ + @Test() + public void testExecutionExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + List requests = + Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); + + Response invokeResponse = testingF.execute(requests, null); + Assert.assertEquals(500, invokeResponse.getStatus()); + + Response getResponse = testingF.getExecution(EP, EXEC); + Assert.assertEquals(500, getResponse.getStatus()); + } + + + /** + * Test the exception handler logic for the cases when the + * testing manager throws an accessing the scenarios. + */ + @Test() + public void testScenarioExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + Response response = testingF.getScenarios(EP); + Assert.assertEquals(500, response.getStatus()); + } + + /** + * Test the exception handler logic for the cases when the + * testing manager throws an accessing a test case. + */ + @Test() + public void testTestCaseExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + Response response = testingF.getTestcase(EP, SC, TS, TC); + Assert.assertEquals(500, response.getStatus()); + } + + /** + * Test the exception handler logic for the cases when the + * testing manager throws an accessing the test cases. + */ + @Test() + public void testTestCasesExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + Response response = testingF.getTestcases(EP, SC); + Assert.assertEquals(500, response.getStatus()); + } + + /** + * Test the exception handler logic for the cases when the + * testing manager throws an accessing the test suites. + */ + @Test() + public void testTestSuitesExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + Response response = testingF.getTestsuites(EP, SC); + Assert.assertEquals(500, response.getStatus()); + } + + /** + * Test the exception handler logic for the cases when the + * testing manager throws an accessing the test tree. + */ + @Test() + public void testTreeExceptions() { + MockitoAnnotations.initMocks(this); + + ExternalTestingManager m = new ApiTestExternalTestingManager(); + ExternalTestingImpl testingF = new ExternalTestingImpl(m); + + Response response = testingF.getTestCasesAsTree(); + Assert.assertEquals(500, response.getStatus()); + } +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java b/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java deleted file mode 100644 index 411be2f150..0000000000 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/externaltesting-rest/externaltesting-rest-services/src/test/java/org/openecomp/sdcrests/externaltesting/rest/services/ApiTests.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright © 2019 iconectiv - * - * 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. - */ - -package org.openecomp.sdcrests.externaltesting.rest.services; - -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.core.externaltesting.api.*; -import org.openecomp.core.externaltesting.errors.ExternalTestingException; - -import java.util.Arrays; -import java.util.List; - -public class ApiTests { - - private static final String EP = "ep"; - private static final String EXEC = "exec"; - private static final String SC = "sc"; - private static final String TS = "ts"; - private static final String TC = "tc"; - private static final String EXPECTED = "Expected"; - - - @Mock - private ExternalTestingManager testingManager; - - /** - * At the API level, test that the code does not throw - * exceptions but there's not much to test. - */ - @Test - public void testApi() { - MockitoAnnotations.initMocks(this); - - ExternalTestingImpl testing = new ExternalTestingImpl(testingManager); - Assert.assertNotNull(testing.getConfig()); - Assert.assertNotNull(testing.getEndpoints()); - Assert.assertNotNull(testing.getExecution(EP, EXEC)); - Assert.assertNotNull(testing.getScenarios(EP)); - Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC)); - Assert.assertNotNull(testing.getTestcases(EP, SC)); - Assert.assertNotNull(testing.getTestsuites(EP, SC)); - Assert.assertNotNull(testing.getTestCasesAsTree()); - - List requests = - Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); - Assert.assertNotNull(testing.execute(requests, "requestId")); - } - - class ApiTestExternalTestingManager implements ExternalTestingManager { - @Override - public ClientConfiguration getConfig() { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public ClientConfiguration setConfig(ClientConfiguration config) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public List setEndpoints(List endpoints) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public TestTreeNode getTestCasesAsTree() { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public List getEndpoints() { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public List getScenarios(String endpoint) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public List getTestSuites(String endpoint, String scenario) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public List getTestCases(String endpoint, String scenario) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public List execute(List requests, String requestId) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - - @Override - public VtpTestExecutionResponse getExecution(String endpoint, String executionId) { - throw new ExternalTestingException(EXPECTED, 500, EXPECTED); - } - } - - /** - * Test the exception handler logic for the cases when the - * testing manager throws an exception. - */ - @Test - public void testExceptions() { - MockitoAnnotations.initMocks(this); - - ExternalTestingManager m = new ApiTestExternalTestingManager(); - ExternalTestingImpl testingF = new ExternalTestingImpl(m); - - try { - testingF.getConfig(); - } - catch (Exception ex) { - // expected. - } - - - try { - testingF.getEndpoints(); - } - catch (ExternalTestingException e) { - // expected. - } - - try { - testingF.getExecution(EP, EXEC); - } - catch (ExternalTestingException e) { - // expected. - } - try { - testingF.getScenarios(EP); - } - catch (ExternalTestingException e) { - // expected. - } - - try { - testingF.getTestcase(EP, SC, TS, TC); - } - catch (ExternalTestingException e) { - // expected. - } - - try { - testingF.getTestcases(EP, SC); - } - catch (ExternalTestingException e) { - // expected. - } - - try { - testingF.getTestsuites(EP, SC); - } - catch (ExternalTestingException e) { - // expected. - } - - try { - testingF.getTestCasesAsTree(); - } - catch (ExternalTestingException e) { - // expected. - } - - List requestsF = - Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest()); - - try { - testingF.execute(requestsF, null); - } - catch (ExternalTestingException e) { - // expected. - } - - - try { - testingF.execute(requestsF, null); - } - catch (ExternalTestingException e) { - // expected. - } - } -} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/data/failedexecution.json b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/data/failedexecution.json new file mode 100644 index 0000000000..089c3c16f0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/data/failedexecution.json @@ -0,0 +1,6 @@ +{ + "code": "F-1131", + "message": "Failure reason", + "httpStatus": 500, + "status": "FAILED" +} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ConfigurationTest.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ConfigurationTest.java new file mode 100644 index 0000000000..f637632835 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ConfigurationTest.java @@ -0,0 +1,66 @@ +/* + * Copyright © 2019 iconectiv + * + * 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. + */ + +package org.openecomp.core.externaltesting.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Assert; +import org.junit.Test; +import org.onap.sdc.tosca.services.YamlUtil; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +public class ConfigurationTest { + + @Test + public void testClientConfig() { + // a brain dead test of the setter and getter. + // future tests for more complex config to come. + ClientConfiguration cc = new ClientConfiguration(); + cc.setEnabled(true); + Assert.assertTrue("client configuration setter", cc.isEnabled()); + cc.setEnabled(false); + Assert.assertFalse("client configuration setter", cc.isEnabled()); + } + + @Test + public void testEndpointDefinition() { + RemoteTestingEndpointDefinition def = new RemoteTestingEndpointDefinition(); + def.setId("vtp"); + def.setEnabled(true); + def.setTitle("VTP"); + def.setApiKey("FOOBARBAZ"); + def.setUrl("http://example.com/vtptesting"); + def.setScenarioFilter("c.*"); + def.setConfig("vtp,VTP,true,http://example.com/vtptesting,c.*,FOO"); + + Assert.assertEquals("code", "VTP", def.getTitle()); + Assert.assertEquals("API keys equals", "FOOBARBAZ", def.getApiKey()); + Assert.assertEquals("code equals", "VTP", def.getTitle()); + Assert.assertEquals("url equals", "http://example.com/vtptesting", def.getUrl()); + Assert.assertEquals("filter equals", "c.*", def.getScenarioFilter()); + Assert.assertTrue("enabled", def.isEnabled()); + Assert.assertEquals("id equals", "vtp", def.getId()); + Assert.assertNotNull("config has val", def.getConfig()); + + + boolean matches = def.getScenarioFilterPattern().matcher("certification").matches(); + Assert.assertTrue("pattern", matches); + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTest.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTest.java new file mode 100644 index 0000000000..788e5d6cf3 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTest.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2019 iconectiv + * + * 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. + */ + +package org.openecomp.core.externaltesting.api; + +import org.junit.Assert; +import org.junit.Test; + +public class ErrorBodyTest { + + @Test + public void testErrorBody() { + TestErrorBody b = new TestErrorBody(); + b.setHttpStatus(404); + b.setMessage("message"); + b.setCode("code"); + + Assert.assertEquals("code match", new Integer(404), b.getHttpStatus()); + Assert.assertEquals("code message", "message", b.getMessage()); + Assert.assertEquals("code code", "code", b.getCode()); + + TestErrorBody b2 = new TestErrorBody("code", 404, "message"); + + Assert.assertEquals("code match", new Integer(404), b2.getHttpStatus()); + Assert.assertEquals("code message", "message", b2.getMessage()); + Assert.assertEquals("code code", "code", b2.getCode()); + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTests.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTests.java deleted file mode 100644 index 216ff3599f..0000000000 --- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ErrorBodyTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2019 iconectiv - * - * 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. - */ - -package org.openecomp.core.externaltesting.api; - -import org.junit.Assert; -import org.junit.Test; - -public class ErrorBodyTests { - - @Test - public void testErrorBody() { - TestErrorBody b = new TestErrorBody(); - b.setHttpStatus(404); - b.setMessage("message"); - b.setCode("code"); - - Assert.assertEquals("code match", new Integer(404), b.getHttpStatus()); - Assert.assertEquals("code message", "message", b.getMessage()); - Assert.assertEquals("code code", "code", b.getCode()); - - TestErrorBody b2 = new TestErrorBody("code", 404, "message"); - - Assert.assertEquals("code match", new Integer(404), b2.getHttpStatus()); - Assert.assertEquals("code message", "message", b2.getMessage()); - Assert.assertEquals("code code", "code", b2.getCode()); - - } -} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTest.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTest.java new file mode 100644 index 0000000000..541f636841 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTest.java @@ -0,0 +1,115 @@ +/* + * Copyright © 2019 iconectiv + * + * 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. + */ + +package org.openecomp.core.externaltesting.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.UUID; + +public class ExecutionRequestTest { + + @Test + public void testTestCase() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + VtpTestCase req = mapper.readValue(new File("src/test/data/testcase.json"), VtpTestCase.class); + + Assert.assertEquals("Scenario must match", "compliance", req.getScenario()); + Assert.assertEquals("Suite name must match", "compliancetests", req.getTestSuiteName()); + Assert.assertEquals("Test case name must match", "sriov", req.getTestCaseName()); + Assert.assertEquals("Description must match", "SR-IOV Test", req.getDescription()); + Assert.assertEquals("Author must match", "Jim", req.getAuthor()); + Assert.assertEquals("Endpoint must match", "vtp", req.getEndpoint()); + Assert.assertEquals("Test must contain two inputs", 3, req.getInputs().size()); + Assert.assertEquals("Test must contain one outputs", 1, req.getOutputs().size()); + + VtpTestCaseInput input1 = req.getInputs().get(0); + Assert.assertEquals("Name match", "vspId", input1.getName()); + Assert.assertEquals("Description match", "VSP ID", input1.getDescription()); + Assert.assertEquals("Input type match", "text", input1.getType()); + Assert.assertEquals("Input default match", "", input1.getDefaultValue()); + Assert.assertFalse("Input optional match", input1.getIsOptional()); + + VtpTestCaseOutput output1 = req.getOutputs().get(0); + Assert.assertEquals("Name match", "something", output1.getName()); + Assert.assertEquals("Description match", "is produced", output1.getDescription()); + Assert.assertEquals("Output type match", "integer", output1.getType()); + + + Map meta = input1.getMetadata(); + Assert.assertEquals("Metadata count", 3, meta.size()); + + VtpTestCase req2 = mapper.readValue(new File("src/test/data/testcase.json"), VtpTestCase.class); + + Assert.assertEquals("test equality", req, req2); + + } + + @Test + public void testExecutionRequest() throws IOException { + ObjectMapper mapper = new ObjectMapper(); + VtpTestExecutionRequest req = mapper.readValue(new File("src/test/data/executionrequest.json"), VtpTestExecutionRequest.class); + Assert.assertEquals("compliance", req.getScenario()); + Assert.assertEquals("compliance", req.getProfile()); + Assert.assertEquals("sriov", req.getTestCaseName()); + Assert.assertEquals("compliancetests", req.getTestSuiteName()); + Assert.assertEquals("repository", req.getEndpoint()); + + Assert.assertEquals(3, req.getParameters().size()); + } + + @Test + public void testExecutionResponse() throws IOException { + ObjectMapper mapper = new ObjectMapper(); + VtpTestExecutionResponse rsp = mapper.readValue(new File("src/test/data/priorexecution.json"), VtpTestExecutionResponse.class); + Assert.assertEquals("compliance", rsp.getScenario()); + Assert.assertEquals("computeflavors", rsp.getTestCaseName()); + Assert.assertEquals("compliancetests", rsp.getTestSuiteName()); + Assert.assertTrue(UUID.fromString(rsp.getExecutionId()).getLeastSignificantBits() != 0); + Assert.assertEquals("parameters", 6, rsp.getParameters().size()); + Assert.assertNotNull(rsp.getResults()); + Assert.assertEquals("COMPLETED", rsp.getStatus()); + Assert.assertNotNull(rsp.getStartTime()); + Assert.assertNotNull(rsp.getEndTime()); + + rsp = mapper.readValue(new File("src/test/data/failedexecution.json"), VtpTestExecutionResponse.class); + Assert.assertEquals("F-1131", rsp.getCode()); + Assert.assertEquals("Failure reason", rsp.getMessage()); + Assert.assertEquals(500, rsp.getHttpStatus().intValue()); + } + + @Test + public void testTreeConstructor() { + // test constructor. + TestTreeNode tree = new TestTreeNode("root", "Root"); + Assert.assertEquals("root", tree.getName()); + Assert.assertEquals("Root", tree.getDescription()); + } + + @Test + public void testTree() throws IOException { + ObjectMapper mapper = new ObjectMapper(); + TestTreeNode tree = mapper.readValue(new File("src/test/data/testtree.json"), TestTreeNode.class); + + Assert.assertEquals(2, tree.getChildren().size()); + Assert.assertEquals(0, tree.getTests().size()); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTests.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTests.java deleted file mode 100644 index bfa07ecc0c..0000000000 --- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTests.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2019 iconectiv - * - * 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. - */ - -package org.openecomp.core.externaltesting.api; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.util.Map; -import java.util.UUID; - -public class ExecutionRequestTests { - - @Test - public void testTestCase() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - VtpTestCase req = mapper.readValue(new File("src/test/data/testcase.json"), VtpTestCase.class); - - Assert.assertEquals("Scenario must match", "compliance", req.getScenario()); - Assert.assertEquals("Suite name must match", "compliancetests", req.getTestSuiteName()); - Assert.assertEquals("Test case name must match", "sriov", req.getTestCaseName()); - Assert.assertEquals("Description must match", "SR-IOV Test", req.getDescription()); - Assert.assertEquals("Author must match", "Jim", req.getAuthor()); - Assert.assertEquals("Endpoint must match", "vtp", req.getEndpoint()); - Assert.assertEquals("Test must contain two inputs", 3, req.getInputs().size()); - Assert.assertEquals("Test must contain one outputs", 1, req.getOutputs().size()); - - VtpTestCaseInput input1 = req.getInputs().get(0); - Assert.assertEquals("Name match", "vspId", input1.getName()); - Assert.assertEquals("Description match", "VSP ID", input1.getDescription()); - Assert.assertEquals("Input type match", "text", input1.getType()); - Assert.assertEquals("Input default match", "", input1.getDefaultValue()); - Assert.assertFalse("Input optional match", input1.getIsOptional()); - - VtpTestCaseOutput output1 = req.getOutputs().get(0); - Assert.assertEquals("Name match", "something", output1.getName()); - Assert.assertEquals("Description match", "is produced", output1.getDescription()); - Assert.assertEquals("Output type match", "integer", output1.getType()); - - - Map meta = input1.getMetadata(); - Assert.assertEquals("Metadata count", 3, meta.size()); - - VtpTestCase req2 = mapper.readValue(new File("src/test/data/testcase.json"), VtpTestCase.class); - - Assert.assertEquals("test equality", req, req2); - - } - - @Test - public void testExecutionRequest() throws IOException { - ObjectMapper mapper = new ObjectMapper(); - VtpTestExecutionRequest req = mapper.readValue(new File("src/test/data/executionrequest.json"), VtpTestExecutionRequest.class); - Assert.assertEquals("compliance", req.getScenario()); - Assert.assertEquals("compliance", req.getProfile()); - Assert.assertEquals("sriov", req.getTestCaseName()); - Assert.assertEquals("compliancetests", req.getTestSuiteName()); - Assert.assertEquals("repository", req.getEndpoint()); - - Assert.assertEquals(3, req.getParameters().size()); - } - - @Test - public void testExecutionResponse() throws IOException { - ObjectMapper mapper = new ObjectMapper(); - VtpTestExecutionResponse rsp = mapper.readValue(new File("src/test/data/priorexecution.json"), VtpTestExecutionResponse.class); - Assert.assertEquals("compliance", rsp.getScenario()); - Assert.assertEquals("computeflavors", rsp.getTestCaseName()); - Assert.assertEquals("compliancetests", rsp.getTestSuiteName()); - Assert.assertTrue(UUID.fromString(rsp.getExecutionId()).getLeastSignificantBits() != 0); - Assert.assertEquals("parameters", 6, rsp.getParameters().size()); - Assert.assertNotNull(rsp.getResults()); - Assert.assertEquals("COMPLETED", rsp.getStatus()); - Assert.assertNotNull(rsp.getStartTime()); - Assert.assertNotNull(rsp.getEndTime()); - } - - @Test - public void testTree() throws IOException { - ObjectMapper mapper = new ObjectMapper(); - TestTreeNode tree = mapper.readValue(new File("src/test/data/testtree.json"), TestTreeNode.class); - - Assert.assertEquals(2, tree.getChildren().size()); - Assert.assertEquals(0, tree.getTests().size()); - } -} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExternalTestingApiTests.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExternalTestingApiTests.java index 62b129c7c0..67cf71702d 100644 --- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExternalTestingApiTests.java +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExternalTestingApiTests.java @@ -21,8 +21,9 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ - ExecutionRequestTests.class, - ErrorBodyTests.class + ConfigurationTest.class, + ExecutionRequestTest.class, + ErrorBodyTest.class }) public class ExternalTestingApiTests { // nothing to do - just a placeholder. diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ConfigurationTests.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ConfigurationTests.java deleted file mode 100644 index 05fc9e3938..0000000000 --- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ConfigurationTests.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright © 2019 iconectiv - * - * 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. - */ - -package org.openecomp.core.externaltesting.impl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; -import org.onap.sdc.tosca.services.YamlUtil; -import org.openecomp.core.externaltesting.api.ClientConfiguration; -import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; - -public class ConfigurationTests { - - @Test - public void testClientConfig() { - // a brain dead test of the setter and getter. - // future tests for more complex config to come. - ClientConfiguration cc = new ClientConfiguration(); - cc.setEnabled(true); - Assert.assertTrue("client configuration setter", cc.isEnabled()); - cc.setEnabled(false); - Assert.assertFalse("client configuration setter", cc.isEnabled()); - } - - @Test - public void testConfig() throws Exception { - try (InputStream fileInput = new FileInputStream(new File("src/test/data/externaltesting-configuration.yaml"))) { - YamlUtil yamlUtil = new YamlUtil(); - Object raw = yamlUtil.yamlToMap(fileInput); - TestingAccessConfig accessConfig = new ObjectMapper().convertValue(raw, TestingAccessConfig.class); - Assert.assertNotNull("client config available", accessConfig.getClient()); - } - } - - @Test - public void testEndpointDefinition() { - RemoteTestingEndpointDefinition def = new RemoteTestingEndpointDefinition(); - def.setId("vtp"); - def.setEnabled(true); - def.setTitle("VTP"); - def.setApiKey("FOOBARBAZ"); - def.setUrl("http://example.com/vtptesting"); - def.setScenarioFilter("c.*"); - - RemoteTestingEndpointDefinition def2 = new RemoteTestingEndpointDefinition(); - def2.setId("vtp"); - def2.setEnabled(true); - def2.setTitle("VTP"); - def2.setUrl("http://example.com/vtptesting"); - def2.setApiKey("FOOBARBAZ"); - def2.setScenarioFilter("c.*"); - - Assert.assertEquals("code", "VTP", def.getTitle()); - Assert.assertEquals("API keys equals", def.getApiKey(), def2.getApiKey()); - Assert.assertEquals("code equals", def.getTitle(), def2.getTitle()); - Assert.assertEquals("url equals", def.getUrl(), def2.getUrl()); - - boolean matches = def.getScenarioFilterPattern().matcher("certification").matches(); - Assert.assertTrue("pattern", matches); - - } -} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java new file mode 100644 index 0000000000..04ddf6e2d4 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTest.java @@ -0,0 +1,422 @@ +/* + * Copyright © 2019 iconectiv + * + * 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. + */ + +package org.openecomp.core.externaltesting.impl; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.*; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.core.externaltesting.api.*; +import org.openecomp.core.externaltesting.errors.ExternalTestingException; +import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; +import org.openecomp.sdc.versioning.VersioningManager; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.*; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.HttpStatusCodeException; +import org.springframework.web.client.ResourceAccessException; +import org.springframework.web.client.RestTemplate; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.*; + +@RunWith(MockitoJUnitRunner.class) +public class ExternalTestingManagerImplTest { + + @Mock + private RestTemplate restTemplate; + + @Mock + private VersioningManager versioningManager; + + @Mock + private VendorSoftwareProductManager vendorSoftwareProductManager; + + @Mock + private OrchestrationTemplateCandidateManager candidateManager; + + @InjectMocks + private ExternalTestingManagerImpl mgr = new ExternalTestingManagerImpl(); + + @SuppressWarnings("unchecked") + private ExternalTestingManagerImpl configTestManager(boolean loadConfig) throws IOException { + + MockitoAnnotations.initMocks(this); + + if (loadConfig) { + mgr.init(); + } + + ObjectMapper mapper = new ObjectMapper(); + + // read mock data for API calls. + + File scenarioFile = new File("src/test/data/scenarios.json"); + TypeReference> typ = new TypeReference>(){}; + List scenarios = mapper.readValue(scenarioFile, typ); + + File testSuitesFile = new File("src/test/data/testsuites.json"); + List testSuites = mapper.readValue(testSuitesFile, new TypeReference>(){}); + + File testCasesFile = new File("src/test/data/testcases.json"); + List testCases = mapper.readValue(testCasesFile, new TypeReference>(){}); + + File testCaseFile = new File("src/test/data/testcase-sriov.json"); + VtpTestCase testCase = mapper.readValue(testCaseFile, VtpTestCase.class); + + File runResultFile = new File("src/test/data/runresult.json"); + List runResults = mapper.readValue(runResultFile, new TypeReference>(){}); + + File priorExecutionFile = new File("src/test/data/priorexecution.json"); + VtpTestExecutionResponse priorExecution = mapper.readValue(priorExecutionFile, VtpTestExecutionResponse.class); + + // create an error response as well + String notFound = FileUtils.readFileToString(new File("src/test/data/notfound.json"), "UTF-8"); + + ParameterizedTypeReference> listOfPairType = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> listOfCasesType = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference caseType = new ParameterizedTypeReference() {}; + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.parseMediaType("application/problem+json")); + + byte[] csar = IOUtils.toByteArray(new FileInputStream("src/test/data/csar.zip")); + byte[] heat = IOUtils.toByteArray(new FileInputStream("src/test/data/heat.zip")); + + List versionList = new ArrayList<>(); + versionList.add(new Version(UUID.randomUUID().toString())); + + Mockito + .when(candidateManager.get( + ArgumentMatchers.contains("csar"), + ArgumentMatchers.any())) + .thenReturn(Optional.of(Pair.of("Processed.zip", csar))); + + Mockito + .when(candidateManager.get( + ArgumentMatchers.contains("heat"), + ArgumentMatchers.any())) + .thenReturn(Optional.empty()); + + Mockito + .when(vendorSoftwareProductManager.get( + ArgumentMatchers.contains("heat"), + ArgumentMatchers.any())) + .thenReturn(Optional.of(Pair.of("Processed.zip", heat))); + + + + Mockito + .when(vendorSoftwareProductManager.get( + ArgumentMatchers.contains("missing"), + ArgumentMatchers.any())) + .thenReturn(Optional.empty()); + + Mockito + .when(candidateManager.get( + ArgumentMatchers.contains("missing"), + ArgumentMatchers.any())) + .thenReturn(Optional.empty()); + + + Mockito + .when(versioningManager.list( + ArgumentMatchers.contains("missing"))) + .thenReturn(versionList); + + + + + + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.endsWith("/scenarios"), + ArgumentMatchers.eq(HttpMethod.GET), + ArgumentMatchers.any(), + ArgumentMatchers.eq(listOfPairType))) + .thenReturn(new ResponseEntity(scenarios, HttpStatus.OK)); + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.endsWith("/testsuites"), + ArgumentMatchers.eq(HttpMethod.GET), + ArgumentMatchers.any(), + ArgumentMatchers.eq(listOfPairType))) + .thenReturn(new ResponseEntity(testSuites, HttpStatus.OK)); + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.endsWith("/testcases"), + ArgumentMatchers.eq(HttpMethod.GET), + ArgumentMatchers.any(), + ArgumentMatchers.eq(listOfCasesType))) + .thenReturn(new ResponseEntity(testCases, HttpStatus.OK)); + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.endsWith("/sriov"), + ArgumentMatchers.eq(HttpMethod.GET), + ArgumentMatchers.any(), + ArgumentMatchers.eq(caseType))) + .thenReturn(new ResponseEntity(testCase, HttpStatus.OK)); + + + // POST for execution + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.contains("executions"), + ArgumentMatchers.eq(HttpMethod.POST), + ArgumentMatchers.any(), + ArgumentMatchers.eq(new ParameterizedTypeReference>() {}))) + .thenReturn(new ResponseEntity(runResults, HttpStatus.OK)); + + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.contains("/executions/"), + ArgumentMatchers.eq(HttpMethod.GET), + ArgumentMatchers.any(), + ArgumentMatchers.eq(new ParameterizedTypeReference() {}))) + .thenReturn(new ResponseEntity(priorExecution, HttpStatus.OK)); + + + HttpStatusCodeException missingException = new HttpServerErrorException(HttpStatus.NOT_FOUND, "Not Found", headers, notFound.getBytes(), Charset.defaultCharset()); + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.endsWith("/missing"), + ArgumentMatchers.eq(HttpMethod.GET), + ArgumentMatchers.any(), + ArgumentMatchers.eq(caseType))) + .thenThrow(missingException); + + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.endsWith("/sitedown"), + ArgumentMatchers.eq(HttpMethod.GET), + ArgumentMatchers.any(), + ArgumentMatchers.eq(caseType))) + .thenThrow(new ResourceAccessException("Remote site is down")); + + Mockito + .when(restTemplate.exchange( + ArgumentMatchers.endsWith("throwexception"), + ArgumentMatchers.eq(HttpMethod.POST), + ArgumentMatchers.any(), + ArgumentMatchers.eq(new ParameterizedTypeReference>() {}))) + .thenThrow(missingException); + + + return mgr; + } + + @Before + public void setConfigLocation() { + System.setProperty("config.location", "src/test/data"); + } + + @Test + public void testManager() throws IOException { + ExternalTestingManager m = configTestManager(true); + + ClientConfiguration config = m.getConfig(); + Assert.assertNotNull(config); + + List endpoints = m.getEndpoints(); + Assert.assertEquals("two endpoints", 2, endpoints.size()); + + + // this will exercise the internal APIs as well. + TestTreeNode root = m.getTestCasesAsTree(); + Assert.assertEquals("two scenarios", 2, root.getChildren().size()); + + + // handle case where remote endpoint is down. + try { + m.getTestCase("repository", "scen", "suite", "sitedown"); + Assert.fail("not expected to retrieve sitedown test case"); + } + catch (ExternalTestingException e) { + // expecting this exception. + Assert.assertNotNull(e.getDetail()); + Assert.assertNotEquals(0, e.getHttpStatus()); + Assert.assertNotNull(e.getMessageCode()); + } + + // get a particular test case + try { + m.getTestCase("repository", "scen", "suite", "missing"); + Assert.fail("not expected to retrieve missing test case"); + } + catch (ExternalTestingException e) { + // expecting this exception. + Assert.assertNotNull(e.getDetail()); + Assert.assertNotEquals(0, e.getHttpStatus()); + Assert.assertNotNull(e.getMessageCode()); + } + } + + @Test + public void testManagerExecution() throws IOException { + ExternalTestingManager m = configTestManager(true); + + // execute a test. + List requests = new ArrayList<>(); + VtpTestExecutionRequest req = new VtpTestExecutionRequest(); + req.setEndpoint("repository"); + requests.add(req); + + // send a request with the endpoint defined. + List responses = m.execute(requests, "rid"); + Assert.assertEquals(1, responses.size()); + + // send a request for a prior execution. + VtpTestExecutionResponse execRsp = m.getExecution("repository", "execId"); + Assert.assertEquals("COMPLETED", execRsp.getStatus()); + } + + @Test + public void testMissingConfig() throws IOException { + // directory exists but no config file should be found here. + System.setProperty("config.location", "src/test"); + ExternalTestingManager m = configTestManager(true); + Assert.assertFalse("missing config client enabled false", m.getConfig().isEnabled()); + Assert.assertEquals("missing config no endpoints", 0, m.getEndpoints().size()); + } + + @Test + public void testMissingEndpoint() throws IOException { + ExternalTestingManager m = configTestManager(true); + + // execute a test. + List requests = new ArrayList<>(); + VtpTestExecutionRequest req = new VtpTestExecutionRequest(); + req.setEndpoint("repository"); + requests.add(req); + + // send a request with the endpoint defined. + try { + m.execute(requests, "throwexception"); + } + catch (ExternalTestingException e) { + // expected. + } + } + + + @Test + public void testManagerConfigOverrides() throws IOException { + ExternalTestingManager m = configTestManager(false); + + ClientConfiguration cc = new ClientConfiguration(); + cc.setEnabled(true); + m.setConfig(cc); + Assert.assertTrue(m.getConfig().isEnabled()); + + List lst = new ArrayList<>(); + lst.add(new RemoteTestingEndpointDefinition()); + lst.get(0).setEnabled(true); + m.setEndpoints(lst); + Assert.assertEquals(1,m.getEndpoints().size()); + } + + @Test + public void testManagerErrorCases() throws IOException { + ExternalTestingManager m = configTestManager(false); + ClientConfiguration emptyConfig = m.getConfig(); + Assert.assertFalse("empty configuration should have client enabled of false", emptyConfig.isEnabled()); + + try { + m.getEndpoints(); + Assert.assertTrue("should have exception here", true); + } + catch (ExternalTestingException e) { + // eat the exception cause this is what should happen. + } + } + + @Test + public void testExecutionDistribution() throws IOException { + ExternalTestingManager m = configTestManager(true); + + VtpTestExecutionRequest r1 = new VtpTestExecutionRequest(); + r1.setScenario("scenario1"); + r1.setEndpoint("vtp"); + + VtpTestExecutionRequest r2 = new VtpTestExecutionRequest(); + r2.setScenario("scenario2"); + r2.setEndpoint("vtp"); + + VtpTestExecutionRequest r3 = new VtpTestExecutionRequest(); + r3.setScenario("scenario3"); + r3.setEndpoint("repository"); + + List results = m.execute(Arrays.asList(r1,r2,r3), "rid"); + Assert.assertEquals("three in two out merged", 2, results.size()); + } + + @Test + public void testArchiveProcessing() throws IOException { + ExternalTestingManagerImpl m = configTestManager(true); + VtpTestExecutionRequest r1 = new VtpTestExecutionRequest(); + r1.setScenario("scenario1"); + r1.setEndpoint("vtp"); + r1.setParameters(new HashMap<>()); + r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.csar.content"); + r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString()); + + LinkedMultiValueMap body = new LinkedMultiValueMap<>(); + m.attachArchiveContent(r1, body); + + r1.setParameters(new HashMap<>()); + r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.heat.content"); + r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString()); + + LinkedMultiValueMap body2 = new LinkedMultiValueMap<>(); + m.attachArchiveContent(r1, body2); + + // now, let's handle a missing archive. + r1.setParameters(new HashMap<>()); + r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.missing.content"); + r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString()); + + LinkedMultiValueMap body3 = new LinkedMultiValueMap<>(); + try { + m.attachArchiveContent(r1, body3); + Assert.fail("expected to receive an exception here"); + } + catch (ExternalTestingException ex) { + Assert.assertEquals(500, ex.getHttpStatus()); + } + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTests.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTests.java deleted file mode 100644 index 2233f85ccf..0000000000 --- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImplTests.java +++ /dev/null @@ -1,422 +0,0 @@ -/* - * Copyright © 2019 iconectiv - * - * 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. - */ - -package org.openecomp.core.externaltesting.impl; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.*; -import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.core.externaltesting.api.*; -import org.openecomp.core.externaltesting.errors.ExternalTestingException; -import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; -import org.openecomp.sdc.versioning.VersioningManager; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.*; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.HttpStatusCodeException; -import org.springframework.web.client.ResourceAccessException; -import org.springframework.web.client.RestTemplate; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.*; - -@RunWith(MockitoJUnitRunner.class) -public class ExternalTestingManagerImplTests { - - @Mock - private RestTemplate restTemplate; - - @Mock - private VersioningManager versioningManager; - - @Mock - private VendorSoftwareProductManager vendorSoftwareProductManager; - - @Mock - private OrchestrationTemplateCandidateManager candidateManager; - - @InjectMocks - private ExternalTestingManagerImpl mgr = new ExternalTestingManagerImpl(); - - @SuppressWarnings("unchecked") - private ExternalTestingManagerImpl configTestManager(boolean loadConfig) throws IOException { - - MockitoAnnotations.initMocks(this); - - if (loadConfig) { - mgr.init(); - } - - ObjectMapper mapper = new ObjectMapper(); - - // read mock data for API calls. - - File scenarioFile = new File("src/test/data/scenarios.json"); - TypeReference> typ = new TypeReference>(){}; - List scenarios = mapper.readValue(scenarioFile, typ); - - File testSuitesFile = new File("src/test/data/testsuites.json"); - List testSuites = mapper.readValue(testSuitesFile, new TypeReference>(){}); - - File testCasesFile = new File("src/test/data/testcases.json"); - List testCases = mapper.readValue(testCasesFile, new TypeReference>(){}); - - File testCaseFile = new File("src/test/data/testcase-sriov.json"); - VtpTestCase testCase = mapper.readValue(testCaseFile, VtpTestCase.class); - - File runResultFile = new File("src/test/data/runresult.json"); - List runResults = mapper.readValue(runResultFile, new TypeReference>(){}); - - File priorExecutionFile = new File("src/test/data/priorexecution.json"); - VtpTestExecutionResponse priorExecution = mapper.readValue(priorExecutionFile, VtpTestExecutionResponse.class); - - // create an error response as well - String notFound = FileUtils.readFileToString(new File("src/test/data/notfound.json"), "UTF-8"); - - ParameterizedTypeReference> listOfPairType = new ParameterizedTypeReference>() {}; - ParameterizedTypeReference> listOfCasesType = new ParameterizedTypeReference>() {}; - ParameterizedTypeReference caseType = new ParameterizedTypeReference() {}; - - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.parseMediaType("application/problem+json")); - - byte[] csar = IOUtils.toByteArray(new FileInputStream("src/test/data/csar.zip")); - byte[] heat = IOUtils.toByteArray(new FileInputStream("src/test/data/heat.zip")); - - List versionList = new ArrayList<>(); - versionList.add(new Version(UUID.randomUUID().toString())); - - Mockito - .when(candidateManager.get( - ArgumentMatchers.contains("csar"), - ArgumentMatchers.any())) - .thenReturn(Optional.of(Pair.of("Processed.zip", csar))); - - Mockito - .when(candidateManager.get( - ArgumentMatchers.contains("heat"), - ArgumentMatchers.any())) - .thenReturn(Optional.empty()); - - Mockito - .when(vendorSoftwareProductManager.get( - ArgumentMatchers.contains("heat"), - ArgumentMatchers.any())) - .thenReturn(Optional.of(Pair.of("Processed.zip", heat))); - - - - Mockito - .when(vendorSoftwareProductManager.get( - ArgumentMatchers.contains("missing"), - ArgumentMatchers.any())) - .thenReturn(Optional.empty()); - - Mockito - .when(candidateManager.get( - ArgumentMatchers.contains("missing"), - ArgumentMatchers.any())) - .thenReturn(Optional.empty()); - - - Mockito - .when(versioningManager.list( - ArgumentMatchers.contains("missing"))) - .thenReturn(versionList); - - - - - - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.endsWith("/scenarios"), - ArgumentMatchers.eq(HttpMethod.GET), - ArgumentMatchers.any(), - ArgumentMatchers.eq(listOfPairType))) - .thenReturn(new ResponseEntity(scenarios, HttpStatus.OK)); - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.endsWith("/testsuites"), - ArgumentMatchers.eq(HttpMethod.GET), - ArgumentMatchers.any(), - ArgumentMatchers.eq(listOfPairType))) - .thenReturn(new ResponseEntity(testSuites, HttpStatus.OK)); - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.endsWith("/testcases"), - ArgumentMatchers.eq(HttpMethod.GET), - ArgumentMatchers.any(), - ArgumentMatchers.eq(listOfCasesType))) - .thenReturn(new ResponseEntity(testCases, HttpStatus.OK)); - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.endsWith("/sriov"), - ArgumentMatchers.eq(HttpMethod.GET), - ArgumentMatchers.any(), - ArgumentMatchers.eq(caseType))) - .thenReturn(new ResponseEntity(testCase, HttpStatus.OK)); - - - // POST for execution - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.contains("executions"), - ArgumentMatchers.eq(HttpMethod.POST), - ArgumentMatchers.any(), - ArgumentMatchers.eq(new ParameterizedTypeReference>() {}))) - .thenReturn(new ResponseEntity(runResults, HttpStatus.OK)); - - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.contains("/executions/"), - ArgumentMatchers.eq(HttpMethod.GET), - ArgumentMatchers.any(), - ArgumentMatchers.eq(new ParameterizedTypeReference() {}))) - .thenReturn(new ResponseEntity(priorExecution, HttpStatus.OK)); - - - HttpStatusCodeException missingException = new HttpServerErrorException(HttpStatus.NOT_FOUND, "Not Found", headers, notFound.getBytes(), Charset.defaultCharset()); - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.endsWith("/missing"), - ArgumentMatchers.eq(HttpMethod.GET), - ArgumentMatchers.any(), - ArgumentMatchers.eq(caseType))) - .thenThrow(missingException); - - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.endsWith("/sitedown"), - ArgumentMatchers.eq(HttpMethod.GET), - ArgumentMatchers.any(), - ArgumentMatchers.eq(caseType))) - .thenThrow(new ResourceAccessException("Remote site is down")); - - Mockito - .when(restTemplate.exchange( - ArgumentMatchers.endsWith("throwexception"), - ArgumentMatchers.eq(HttpMethod.POST), - ArgumentMatchers.any(), - ArgumentMatchers.eq(new ParameterizedTypeReference>() {}))) - .thenThrow(missingException); - - - return mgr; - } - - @Before - public void setConfigLocation() { - System.setProperty("config.location", "src/test/data"); - } - - @Test - public void testManager() throws IOException { - ExternalTestingManager m = configTestManager(true); - - ClientConfiguration config = m.getConfig(); - Assert.assertNotNull(config); - - List endpoints = m.getEndpoints(); - Assert.assertEquals("two endpoints", 2, endpoints.size()); - - - // this will exercise the internal APIs as well. - TestTreeNode root = m.getTestCasesAsTree(); - Assert.assertEquals("two scenarios", 2, root.getChildren().size()); - - - // handle case where remote endpoint is down. - try { - m.getTestCase("repository", "scen", "suite", "sitedown"); - Assert.fail("not expected to retrieve sitedown test case"); - } - catch (ExternalTestingException e) { - // expecting this exception. - Assert.assertNotNull(e.getDetail()); - Assert.assertNotEquals(0, e.getHttpStatus()); - Assert.assertNotNull(e.getMessageCode()); - } - - // get a particular test case - try { - m.getTestCase("repository", "scen", "suite", "missing"); - Assert.fail("not expected to retrieve missing test case"); - } - catch (ExternalTestingException e) { - // expecting this exception. - Assert.assertNotNull(e.getDetail()); - Assert.assertNotEquals(0, e.getHttpStatus()); - Assert.assertNotNull(e.getMessageCode()); - } - } - - @Test - public void testManagerExecution() throws IOException { - ExternalTestingManager m = configTestManager(true); - - // execute a test. - List requests = new ArrayList<>(); - VtpTestExecutionRequest req = new VtpTestExecutionRequest(); - req.setEndpoint("repository"); - requests.add(req); - - // send a request with the endpoint defined. - List responses = m.execute(requests, "rid"); - Assert.assertEquals(1, responses.size()); - - // send a request for a prior execution. - VtpTestExecutionResponse execRsp = m.getExecution("repository", "execId"); - Assert.assertEquals("COMPLETED", execRsp.getStatus()); - } - - @Test - public void testMissingConfig() throws IOException { - // directory exists but no config file should be found here. - System.setProperty("config.location", "src/test"); - ExternalTestingManager m = configTestManager(true); - Assert.assertFalse("missing config client enabled false", m.getConfig().isEnabled()); - Assert.assertEquals("missing config no endpoints", 0, m.getEndpoints().size()); - } - - @Test - public void testMissingEndpoint() throws IOException { - ExternalTestingManager m = configTestManager(true); - - // execute a test. - List requests = new ArrayList<>(); - VtpTestExecutionRequest req = new VtpTestExecutionRequest(); - req.setEndpoint("repository"); - requests.add(req); - - // send a request with the endpoint defined. - try { - m.execute(requests, "throwexception"); - } - catch (ExternalTestingException e) { - // expected. - } - } - - - @Test - public void testManagerConfigOverrides() throws IOException { - ExternalTestingManager m = configTestManager(false); - - ClientConfiguration cc = new ClientConfiguration(); - cc.setEnabled(true); - m.setConfig(cc); - Assert.assertTrue(m.getConfig().isEnabled()); - - List lst = new ArrayList<>(); - lst.add(new RemoteTestingEndpointDefinition()); - lst.get(0).setEnabled(true); - m.setEndpoints(lst); - Assert.assertEquals(1,m.getEndpoints().size()); - } - - @Test - public void testManagerErrorCases() throws IOException { - ExternalTestingManager m = configTestManager(false); - ClientConfiguration emptyConfig = m.getConfig(); - Assert.assertFalse("empty configuration should have client enabled of false", emptyConfig.isEnabled()); - - try { - m.getEndpoints(); - Assert.assertTrue("should have exception here", true); - } - catch (ExternalTestingException e) { - // eat the exception cause this is what should happen. - } - } - - @Test - public void testExecutionDistribution() throws IOException { - ExternalTestingManager m = configTestManager(true); - - VtpTestExecutionRequest r1 = new VtpTestExecutionRequest(); - r1.setScenario("scenario1"); - r1.setEndpoint("vtp"); - - VtpTestExecutionRequest r2 = new VtpTestExecutionRequest(); - r2.setScenario("scenario2"); - r2.setEndpoint("vtp"); - - VtpTestExecutionRequest r3 = new VtpTestExecutionRequest(); - r3.setScenario("scenario3"); - r3.setEndpoint("repository"); - - List results = m.execute(Arrays.asList(r1,r2,r3), "rid"); - Assert.assertEquals("three in two out merged", 2, results.size()); - } - - @Test - public void testArchiveProcessing() throws IOException { - ExternalTestingManagerImpl m = configTestManager(true); - VtpTestExecutionRequest r1 = new VtpTestExecutionRequest(); - r1.setScenario("scenario1"); - r1.setEndpoint("vtp"); - r1.setParameters(new HashMap<>()); - r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.csar.content"); - r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString()); - - LinkedMultiValueMap body = new LinkedMultiValueMap<>(); - m.attachArchiveContent(r1, body); - - r1.setParameters(new HashMap<>()); - r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.heat.content"); - r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString()); - - LinkedMultiValueMap body2 = new LinkedMultiValueMap<>(); - m.attachArchiveContent(r1, body2); - - // now, let's handle a missing archive. - r1.setParameters(new HashMap<>()); - r1.getParameters().put(ExternalTestingManagerImpl.VSP_ID, "something.with.missing.content"); - r1.getParameters().put(ExternalTestingManagerImpl.VSP_VERSION, UUID.randomUUID().toString()); - - LinkedMultiValueMap body3 = new LinkedMultiValueMap<>(); - try { - m.attachArchiveContent(r1, body3); - Assert.fail("expected to receive an exception here"); - } - catch (ExternalTestingException ex) { - Assert.assertEquals(500, ex.getHttpStatus()); - } - - } -} diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingTestSuite.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingTestSuite.java index d9e4612774..6d464522b7 100644 --- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingTestSuite.java +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/ExternalTestingTestSuite.java @@ -21,8 +21,8 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ - ExternalTestingManagerImplTests.class, - ConfigurationTests.class + ExternalTestingManagerImplTest.class, + TestingAccessConfigTest.class }) public class ExternalTestingTestSuite { // nothing to do - just a placeholder. diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/TestingAccessConfigTest.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/TestingAccessConfigTest.java new file mode 100644 index 0000000000..698133b08e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/test/java/org/openecomp/core/externaltesting/impl/TestingAccessConfigTest.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2019 iconectiv + * + * 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. + */ + +package org.openecomp.core.externaltesting.impl; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Assert; +import org.junit.Test; +import org.onap.sdc.tosca.services.YamlUtil; +import org.openecomp.core.externaltesting.api.ClientConfiguration; +import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +public class TestingAccessConfigTest { + + @Test + public void testConfig() throws Exception { + try (InputStream fileInput = new FileInputStream(new File("src/test/data/externaltesting-configuration.yaml"))) { + YamlUtil yamlUtil = new YamlUtil(); + Object raw = yamlUtil.yamlToMap(fileInput); + TestingAccessConfig accessConfig = new ObjectMapper().convertValue(raw, TestingAccessConfig.class); + Assert.assertNotNull("client config available", accessConfig.getClient()); + } + } + +} -- cgit 1.2.3-korg