summaryrefslogtreecommitdiffstats
path: root/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service
diff options
context:
space:
mode:
Diffstat (limited to 'SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service')
-rw-r--r--SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/CertificationClientServiceTest.java94
-rw-r--r--SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/LayerTestServiceImplTest.java84
-rw-r--r--SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/NetworkCertificationTest.java109
-rw-r--r--SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/ReportServiceImplTest.java127
4 files changed, 414 insertions, 0 deletions
diff --git a/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/CertificationClientServiceTest.java b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/CertificationClientServiceTest.java
new file mode 100644
index 00000000..6da3921b
--- /dev/null
+++ b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/CertificationClientServiceTest.java
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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 com.onap.sdnc.reports.service;
+
+import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.mockito.Mock;
+import com.onap.sdnc.reports.model.CertificationInputs;
+import com.onap.sdnc.reports.model.Input;
+import com.onap.sdnc.reports.model.Output;
+import com.onap.sdnc.reports.model.PreTestResponse;
+
+public class CertificationClientServiceTest {
+
+ @Mock
+ CertificationClientService cService;
+
+ private String hostname = "host";
+ private String ipaddress = "10.53.122.25";
+ private String statistics = "0% loss";
+ private String avgTime = "Minimum = 0ms";
+ private String testType = "network";
+
+ @Test(expected = NullPointerException.class)
+ public void TestRestClient() {
+
+ PreTestResponse pretestResponse = new PreTestResponse();
+ pretestResponse.setIpaddress(ipaddress);
+ pretestResponse.setAvgTime(avgTime);
+ pretestResponse.setHostname(hostname);
+ pretestResponse.setStatus("successs");
+ pretestResponse.setStatistics(statistics);
+ pretestResponse.setTesttype(testType);
+
+ List<PreTestResponse> preTestNew = new ArrayList<PreTestResponse>();
+ preTestNew.add(pretestResponse);
+
+ Input input = new Input();
+ input.setIpaddress(ipaddress);
+ input.setHostname(hostname);
+ input.setNetwork(testType);
+
+ CertificationInputs certificationInputs = new CertificationInputs();
+ certificationInputs.setInput(input);
+ CertificationClientService certificationClientservice = new CertificationClientService();
+ certificationClientservice.restClient(certificationInputs, preTestNew, testType);
+
+ }
+
+ @Test
+ public void pingServiceTest() {
+ CertificationInputs vnfinfo = new CertificationInputs();
+ Input input = new Input();
+ input.setIpaddress("10.53.122.25");
+ input.setHostname("hostname");
+ vnfinfo.setInput(input);
+ Output mockOutput = new Output();
+ mockOutput.setIpaddress("10.53.122.25");
+ Output output = CertificationClientService.pingTest(vnfinfo);
+ assertEquals(output.getIpaddress(), input.getIpaddress());
+ }
+
+ @Test
+ public void protocolTest() {
+ CertificationInputs vnfinfo = new CertificationInputs();
+ Input input = new Input();
+ input.setIpaddress(ipaddress);
+ input.setHostname("hostname");
+ vnfinfo.setInput(input);
+ Output mockOutput = new Output();
+ mockOutput.setIpaddress(ipaddress);
+ }
+}
diff --git a/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/LayerTestServiceImplTest.java b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/LayerTestServiceImplTest.java
new file mode 100644
index 00000000..c721401f
--- /dev/null
+++ b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/LayerTestServiceImplTest.java
@@ -0,0 +1,84 @@
+package com.onap.sdnc.reports.service;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import com.onap.sdnc.reports.model.CertificationInputs;
+import com.onap.sdnc.reports.model.Input;
+import com.onap.sdnc.reports.model.PreTestResponse;
+import com.onap.sdnc.reports.model.Request;
+import com.onap.sdnc.reports.model.Response;
+import com.onap.sdnc.reports.model.ValidationTestType;
+import com.onap.sdnc.reports.model.VnfList;
+
+public class LayerTestServiceImplTest {
+
+ @Mock
+ CertificationClientService cService;
+
+ @Mock
+ LayerTestServiceImpl layerTestServiceImpl;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void networkCertificationTest() {
+
+ Request restReq = new Request();
+ Input input = new Input();
+ CertificationInputs vnfinfo = new CertificationInputs();
+ ValidationTestType vType = new ValidationTestType();
+
+ List<ValidationTestType> lVtype = new ArrayList<ValidationTestType>();
+ vType.setTypeId("1");
+ vType.setValidationType("Network Layer");
+ lVtype.add(vType);
+
+ ValidationTestType[] validationTestType = new ValidationTestType[lVtype.size()];
+ lVtype.toArray(validationTestType);
+ restReq.setValidationTestType(validationTestType);
+
+ VnfList vnfList = new VnfList();
+ vnfList.setHostName("hostname");
+ vnfList.setIpAddress("0.0.0.0");
+ vnfList.setPortNo("0");
+
+ List<VnfList> vnfListArray = new ArrayList<VnfList>();
+ vnfListArray.add(vnfList);
+
+ VnfList[] vnfInputArray = new VnfList[vnfListArray.size()];
+ vnfListArray.toArray(vnfInputArray);
+ restReq.setVnfList(vnfInputArray);
+ input.setHostname("hostname");
+ input.setIpaddress("10.20.30.50");
+ input.setNetwork("network");
+ vnfinfo.setInput(input);
+
+ Response res = new Response();
+
+ PreTestResponse preTestRes = new PreTestResponse();
+ preTestRes.setIpaddress("0.0.0.0");
+
+ List<PreTestResponse> preList = new ArrayList<PreTestResponse>();
+ preList.add(preTestRes);
+
+ res.setPreTestResponse(preList);
+
+ Mockito.when(layerTestServiceImpl.networkCertification(restReq)).thenReturn(res);
+
+ Response actualRes = layerTestServiceImpl.networkCertification(restReq);
+
+ assertEquals(actualRes.getPreTestResponse().get(0).getIpaddress(), vnfList.getIpAddress());
+ }
+
+}
diff --git a/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/NetworkCertificationTest.java b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/NetworkCertificationTest.java
new file mode 100644
index 00000000..c21b6036
--- /dev/null
+++ b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/NetworkCertificationTest.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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 com.onap.sdnc.reports.service;
+import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+/*import com.onap.sdnc.testapi.model.ODLClientResponse;
+import com.onap.sdnc.testapi.model.PreTestResponse;
+import com.onap.sdnc.testapi.model.Request;
+import com.onap.sdnc.testapi.model.Response;
+import com.onap.sdnc.testapi.model.ValidationTestType;
+import com.onap.sdnc.testapi.model.Vnf;
+import com.onap.sdnc.testapi.model.VnfList;
+import com.onap.sdnc.testapi.service.LayerTestServiceImpl;*/
+
+import com.onap.sdnc.reports.model.ODLClientResponse;
+import com.onap.sdnc.reports.model.PreTestResponse;
+import com.onap.sdnc.reports.model.Request;
+import com.onap.sdnc.reports.model.Response;
+import com.onap.sdnc.reports.model.ValidationTestType;
+import com.onap.sdnc.reports.model.Vnf;
+import com.onap.sdnc.reports.model.VnfList;
+
+public class NetworkCertificationTest {
+
+ @Mock
+ LayerTestServiceImpl layerTestServiceImpl;
+
+ @Captor
+ ArgumentCaptor<LayerTestServiceImpl> captor;
+
+ private String hostname = "host";
+ private String ipaddress = "0.0.0.0";
+ private String network = "Network Layer";
+ private String statistics = "0% loss";
+ private String avgTime = "Minimum = 0ms";
+ private String testtype = "network";
+ private String typeId = "1";
+
+ Response response = new Response();
+ PreTestResponse preTestResponse = new PreTestResponse();
+ ODLClientResponse odlClientResponse = new ODLClientResponse();
+ Request restReq = new Request();
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void TestNetworkClient() {
+
+ preTestResponse.setAvgTime(avgTime);
+ preTestResponse.setIpaddress(ipaddress);
+ preTestResponse.setStatistics(statistics);
+ preTestResponse.setStatus("reachable");
+ preTestResponse.setTesttype(testtype);
+
+ List<PreTestResponse> listPreTestResponse = new ArrayList<PreTestResponse>();
+ listPreTestResponse.add(preTestResponse);
+ response.setPreTestResponse(listPreTestResponse);
+
+ ValidationTestType validationTestType = new ValidationTestType();
+ validationTestType.setTypeId(typeId);
+ validationTestType.setValidationType(network);
+
+ VnfList<List> vnflistt = new VnfList<List>();
+ vnflistt.setHostName(hostname);
+ vnflistt.setIpAddress(ipaddress);
+ vnflistt.setPortNo(null);
+
+ VnfList[] vnflist = restReq.getVnfList();
+ ValidationTestType[] validationTestTypee = restReq.getValidationTestType();
+
+ Vnf vnf = new Vnf();
+ vnf.setValidationTestType(validationTestTypee);
+ vnf.setVnfList(vnflist);
+ Mockito.when(layerTestServiceImpl.networkCertification(restReq)).thenReturn(response);
+ Response res = layerTestServiceImpl.networkCertification(restReq);
+
+ assertEquals(res.getPreTestResponse(), response.getPreTestResponse());
+ }
+}
diff --git a/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/ReportServiceImplTest.java b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/ReportServiceImplTest.java
new file mode 100644
index 00000000..27b88da3
--- /dev/null
+++ b/SdncReports/SdncReportsApi/src/test/java/com/onap/sdnc/reports/service/ReportServiceImplTest.java
@@ -0,0 +1,127 @@
+package com.onap.sdnc.reports.service;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.onap.sdnc.reports.Application;
+import com.onap.sdnc.reports.config.EmbeddedMariaDbConfig;
+import com.onap.sdnc.reports.model.DeviceConfig;
+import com.onap.sdnc.reports.model.PreTestConfig;
+import com.onap.sdnc.reports.repository.PreTestConfigRepository;
+import com.onap.sdnc.reports.rest.model.PreTestModel;
+
+import org.springframework.test.annotation.DirtiesContext;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = Application.class)
+@ContextConfiguration(classes = EmbeddedMariaDbConfig.class)
+@DataJpaTest
+@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
+public class ReportServiceImplTest {
+
+ private static final Logger logger = LogManager.getLogger(ReportServiceImplTest.class);
+
+ private Date startDate, endDate;
+
+ @TestConfiguration
+ static class ReportServiceImplTestContextConfiguration {
+ @Bean
+ public IReportService reportService() {
+ return new ReportServiceImpl();
+ }
+ }
+
+ @Autowired
+ private IReportService reportService;
+
+ @MockBean
+ private PreTestConfigRepository preTestConfigRepository;
+
+ @Test
+ public void reportServiceAutoWireTest() {
+ assertNotNull("Due to Application Context Fail", reportService);
+ }
+
+ @Test
+ public void preTestConfigRepositoryAutoWireTest() {
+ assertNotNull("Due to Application Context Fail", preTestConfigRepository);
+ }
+
+ @Before
+ public void setUp() {
+ DeviceConfig deviceConfig = new DeviceConfig();
+ deviceConfig.setDeviceIP("0.0.0.0");
+ deviceConfig.setPreTestConfig(null);
+ deviceConfig.setCreationDate(new Date().toLocaleString());
+
+ PreTestConfig obj = new PreTestConfig();
+ obj.setDevice(deviceConfig);
+ obj.setExecuationDetails("Ping Successful");
+ obj.setResult("Pass");
+
+ obj.setTestName("Network Layer");
+ obj.setTimestamp(new Date());
+
+ Calendar calendar = Calendar.getInstance();
+
+ calendar.add(Calendar.DATE, -7);
+ calendar.add(Calendar.HOUR_OF_DAY, 00);
+ calendar.add(Calendar.MINUTE, 00);
+ calendar.add(Calendar.SECOND, 00);
+ calendar.add(Calendar.MILLISECOND, 00);
+ startDate = calendar.getTime();
+
+ Calendar endDateCalendar = Calendar.getInstance();
+
+ endDateCalendar.add(Calendar.HOUR_OF_DAY, 23);
+ endDateCalendar.add(Calendar.MINUTE, 59);
+ calendar.add(Calendar.SECOND, 00);
+ endDateCalendar.add(Calendar.MILLISECOND, 00);
+ endDate = endDateCalendar.getTime();
+
+ System.out.println(
+ "Before Call : startDate " + startDate.toLocaleString() + " endDate : " + endDate.toLocaleString());
+ List<PreTestConfig> configList = new ArrayList<>();
+ configList.add(obj);
+ Mockito.when(preTestConfigRepository.findReportByDeviceIP(startDate, endDate, "0.0.0.0"))
+ .thenReturn(configList);
+ }
+
+ @Test
+ public void whenFindByDeviceName_thenReturPreTest() {
+ int expectedTestId = 0;
+ System.out.println(
+ "Test Call : startDate " + startDate.toLocaleString() + " endDate : " + endDate.toLocaleString());
+
+ List<PreTestModel> testList;
+ try {
+ testList = reportService.findReportByDeviceIP(startDate, endDate, "10.0.0.0");
+ assertThat(testList.get(0).getTestid()).isEqualTo(expectedTestId);
+ } catch (Exception e) {
+
+ e.printStackTrace();
+ }
+ }
+}