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 --- .../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 +- 7 files changed, 232 insertions(+), 146 deletions(-) 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 (limited to 'openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api') 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. -- cgit 1.2.3-korg