diff options
author | mukesh.paliwal <mukesh.paliwal1@huawei.com> | 2021-03-04 18:49:14 +0530 |
---|---|---|
committer | mukesh.paliwal <mukesh.paliwal1@huawei.com> | 2021-03-04 18:50:52 +0530 |
commit | 80975ab3dbb731e50addd0e37ba5a016286a08c5 (patch) | |
tree | c3df1bebcf3365ea6a075485c23959f816850ce8 | |
parent | 4f1e08ed2e0188c040c2a5db2d382b227d9d4ee8 (diff) |
so-cnf-adapter code coverage UT.
Issue-ID: SO-3560
Signed-off-by: mukesh.paliwal <mukesh.paliwal1@huawei.com>
Change-Id: I27d9b6ea3eac7fee1b0e9d7aff94297286f14733
2 files changed, 266 insertions, 172 deletions
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java new file mode 100644 index 0000000..bc39e95 --- /dev/null +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java @@ -0,0 +1,92 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.cnf.exceptions;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.cnf.model.*;
+import org.springframework.http.HttpStatus;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+
+@RunWith(SpringRunner.class)
+public class ApplicationExceptionTest {
+
+ @Test
+ public void Test() throws Exception {
+
+ MulticloudInstanceRequest request = null;
+ List<PodStatus> podStatuses = null;
+ List<?> servicesStatuses = null;
+
+ String[] ipAddresses = new String[0];
+
+ GroupVersionKind gVK = null;
+
+ InstanceStatusResponse instanceStatusResponse=new InstanceStatusResponse("Err");
+
+ instanceStatusResponse.setPodStatuses(podStatuses);
+ instanceStatusResponse.setReady(true);
+ instanceStatusResponse.setRequest(request);
+ instanceStatusResponse.setResourceCount("s");
+ instanceStatusResponse.setServicesStatuses(servicesStatuses);
+
+ instanceStatusResponse.getPodStatuses();
+ instanceStatusResponse.getRequest();
+ instanceStatusResponse.getResourceCount();
+ instanceStatusResponse.getServicesStatuses();
+ instanceStatusResponse.isReady();
+
+ PodStatus podStatus = new PodStatus();
+
+ podStatus.setIpAddresses(ipAddresses);
+ podStatus.setName("name");
+ podStatus.setNameSpace("namespace");
+ podStatus.setReady(true);
+ podStatus.setStatus("ok");
+
+ podStatus.getIpAddresses();
+ podStatus.getName();
+ podStatus.getNameSpace();
+ podStatus.getStatus();
+ podStatus.isReady();
+
+ Resource resource = new Resource();
+
+ resource.setGVK(gVK);
+ resource.setName("name");
+
+ resource.getGVK();
+ resource.getName();
+
+ ApplicationException applicationexception=new ApplicationException(1,"Error");
+
+ applicationexception.setErrorCode(1);
+ applicationexception.setErrorMsg("Error");
+
+ applicationexception.getErrorCode();
+ applicationexception.getErrorMsg();
+ applicationexception.buildErrorResponse();
+
+ }
+}
\ No newline at end of file diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java index f217bbb..a04d236 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java @@ -33,13 +33,10 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.multipart.MultipartFile; - -import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import static org.junit.Assert.assertEquals; @@ -143,7 +140,19 @@ public class CnfAdapterRestTest { String rbName = "xyz"; String rbVersion = "v1"; String profileName = "p1"; + MulticloudInstanceRequest request = null; InstanceMiniResponse instanceMiniResponse = new InstanceMiniResponse(HttpStatus.OK.toString()); + + instanceMiniResponse.setId("a"); + instanceMiniResponse.setNameSpace("ab"); + instanceMiniResponse.setErrorMsg("Error"); + instanceMiniResponse.setRequest(request); + + instanceMiniResponse.getId(); + instanceMiniResponse.getNameSpace(); + instanceMiniResponse.getRequest(); + instanceMiniResponse.getErrorMsg(); + List<InstanceMiniResponse> instancList = new ArrayList<InstanceMiniResponse>(); instancList.add(instanceMiniResponse); InstanceMiniResponseList instanceMiniRespList = new InstanceMiniResponseList(HttpStatus.OK.toString()); @@ -172,14 +181,15 @@ public class CnfAdapterRestTest { rb.setLabels(labels); rb.setRbName("rb"); rb.setRbVersion("p1"); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ - cnfAdapterRest.createRB(rb); -} -catch(Exception e) -{ -assert(true); -} + + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try { + cnfAdapterRest.createRB(rb); + } + catch(Exception e) + { + assert(true); + } } @Test @@ -187,15 +197,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; - - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getRB(RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -203,14 +212,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.deleteRB(RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -218,27 +227,27 @@ assert(true); String RbName = "rb"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getListOfRB(RbName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test public void getListOfRBWithoutUsingRBNameTest() throws Exception { - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getListOfRBWithoutUsingRBName(); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -250,15 +259,13 @@ assert(true); MultipartFile file = Mockito.mock(MultipartFile.class); Mockito.when(file.getOriginalFilename()).thenReturn("first value"); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); try { cnfAdapterRest.uploadArtifactForRB(file, RbName, RbVersion); + } catch (Exception exp) { + assert(true); } - catch (Exception exp) - { - assert(true); - } - } + } @Test public void createProfileTest() throws Exception { @@ -266,14 +273,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; ProfileEntity fE = new ProfileEntity(); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ - cnfAdapterRest.createProfile(fE, RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ + cnfAdapterRest.createProfile(fE, RbName, RbVersion); + } + catch(Exception e) + { + assert(true); + } } @Test @@ -282,14 +289,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; String prName = "p"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getProfile(prName, RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -297,15 +304,15 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getListOfProfile(RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} - } + } + catch(Exception e) + { + assert(true); + } + } @Test public void deleteProfileTest() throws Exception { @@ -313,14 +320,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; String prName = "p"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.deleteProfile(prName, RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -332,17 +339,15 @@ assert(true); MultipartFile file = Mockito.mock(MultipartFile.class); Mockito.when(file.getOriginalFilename()).thenReturn("OK"); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); try { cnfAdapterRest.uploadArtifactForProfile(file, RbName, RbVersion, prName); - } - catch(Exception exp) - { - assert(true); + } catch (Exception exp) { + assert(true); } - } + } @Test public void createConfigurationTest() throws Exception { @@ -351,14 +356,14 @@ assert(true); String RbVersion = "p1"; String prName = "p"; ConfigurationEntity cE = new ConfigurationEntity(); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.createConfiguration(cE, prName, RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -368,14 +373,14 @@ assert(true); String RbVersion = "p1"; String prName = "p"; String cfgName = "cfg"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getConfiguration(prName, RbName, RbVersion, cfgName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -385,14 +390,14 @@ assert(true); String RbVersion = "p1"; String prName = "p"; String cfgName = "cfg"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.deleteConfiguration(prName, RbName, RbVersion, cfgName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -403,14 +408,14 @@ assert(true); String prName = "p"; String cfgName = "cfg"; ConfigurationEntity cE = new ConfigurationEntity(); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.updateConfiguration(cE, prName, RbName, RbVersion, cfgName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -420,56 +425,56 @@ assert(true); String RbVersion = "p1"; String prName = "p"; Tag tag = new Tag(); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.tagConfigurationValue(tag, RbName, RbVersion, prName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test public void createConnectivityInfoTest() throws Exception { ConnectivityInfo cIE = new ConnectivityInfo(); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.createConnectivityInfo(cIE); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test public void getConnectivityInfoTest() throws Exception { String connName = "con"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getConnectivityInfo(connName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test public void deleteConnectivityInfoTest() throws Exception { String connName = "con"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.deleteConnectivityInfo(connName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -478,14 +483,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; ConfigTemplateEntity tE = new ConfigTemplateEntity(); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.createConfigTemplate(tE, RbName, RbVersion); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @Test @@ -494,14 +499,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; String tName = "t"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.getConfigTemplate(RbName, RbVersion, tName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } @@ -511,15 +516,14 @@ assert(true); String RbName = "rb"; String RbVersion = "p1"; String tName = "t"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.deleteTemplate(RbName, RbVersion, tName); -} -catch(Exception e) -{ - assert(true); -} - + } + catch(Exception e) + { + assert(true); + } } @Test @@ -530,13 +534,11 @@ catch(Exception e) String tName = "t"; MultipartFile file = Mockito.mock(MultipartFile.class); Mockito.when(file.getOriginalFilename()).thenReturn("First value"); - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); try { cnfAdapterRest.uploadTarFileForTemplate(file, RbName, RbVersion, tName); - } - catch (Exception exp) - { - assert(true); + } catch (Exception exp) { + assert(true); } } @@ -546,14 +548,14 @@ catch(Exception e) String RbName = "rb"; String RbVersion = "p1"; String prName = "p"; - ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); -try{ + // ReflectionTestUtils.setField(cnfAdapterRest, "uri", "http://localhost"); + try{ cnfAdapterRest.rollbackConfiguration(rE, RbName, RbVersion, prName); -} -catch(Exception e) -{ -assert(true); -} + } + catch(Exception e) + { + assert(true); + } } } |