From 4fc2e746a0c79e6f81fd08241733b02b781dc5d0 Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Tue, 5 Feb 2019 13:59:47 +0000 Subject: Test coverage for AppcNetconfAdapterActivator Added 100% coverage for untested class. Moved other test file to correct package. Issue-ID: APPC-1389 Change-Id: I73e768f21d5cda8865f891c63b9ad3f3ea2cce80 Signed-off-by: Joss Armstrong --- .../netconf/AppcNetconfAdapterActivator.java | 6 +- .../test/java/OperationalStateValidatorTest.java | 199 --------------------- .../netconf/AppcNetconfAdapterActivatorTest.java | 42 +++++ .../netconf/OperationalStateValidatorTest.java | 199 +++++++++++++++++++++ 4 files changed, 245 insertions(+), 201 deletions(-) delete mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivatorTest.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/OperationalStateValidatorTest.java (limited to 'appc-adapters/appc-netconf-adapter') diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java index 2c44c69c3..f412223ec 100644 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,13 +63,13 @@ public class AppcNetconfAdapterActivator implements BundleActivator { /* * The reference to the actual implementation object that implements the services */ - NetconfClientFactory clientFactory = new NetconfClientFactory(); + NetconfClientFactory clientFactory = new NetconfClientFactory(); factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null); NetconfDataAccessService dataAccessService = new NetconfDataAccessServiceImpl(); //set dblib service ServiceReference sref = context.getServiceReference(DbLibService.class.getName()); dataAccessService.setDbLibService((DbLibService)context.getService(sref)); - /////////////////////////////////// + factoryRegistration = context.registerService(NetconfDataAccessService.class, dataAccessService, null); } } diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java deleted file mode 100644 index e3521910e..000000000 --- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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========================================================= - */ - -import org.onap.appc.exceptions.APPCException; -import org.junit.Test; -import org.onap.appc.adapter.netconf.OperationalStateValidator; -import org.onap.appc.adapter.netconf.OperationalStateValidatorFactory; -import org.onap.appc.adapter.netconf.VnfType; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - - -public class OperationalStateValidatorTest { - - @Test - public void testVNFValidResponse() { - String validResponse = "\n" + - "\n" + - " \n" + - " \n" + - " 1\n" + - " \n" + - " 1\n" + - " \n" + - " 1\n" + - " \n" + - " 1\n" + - " ENABLED\n" + - " \n" + - " processor_0_5\n" + - " ENABLED\n" + - " \n" + - " \n" + - " processor_0_7\n" + - " ENABLED\n" + - " \n" + - " \n" + - " \n" + - " SC-1\n" + - " ENABLED\n" + - " \n" + - " \n" + - " SC-2\n" + - " ENABLED\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; - OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); - assertValidResponse(validResponse, operationalStateValidator); - } - - void assertInvalidResponse(String response, OperationalStateValidator operationalStateValidator) { - try { - operationalStateValidator.validateResponse(response); - fail("invalid resposne passed without exception!!!"); - } catch (APPCException e) { - assertNotNull(e.getMessage()); - } - } - - @Test - public void testVNFInvalidResponses() { - - OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); - assertInvalidResponse(null, operationalStateValidator); - - assertInvalidResponse("", operationalStateValidator); - - String response = ""; - assertInvalidResponse(response, operationalStateValidator); - - response = "\n" + - "\n" + - ""; - assertInvalidResponse(response, operationalStateValidator); - - response = "\n" + - "\n" + - " \n" + - " \n" + - " 1\n" + - " \n" + - " 1\n" + - " \n" + - " 1\n" + - " \n" + - " 1\n" + - " ENABLED\n" + - " \n" + - " processor_0_5\n" + - " ENABLED\n" + - " \n" + - " \n" + - " processor_0_7\n" + - " ENABLED\n" + - " \n" + - " \n" + - " \n" + - " SC-1\n" + - " ENABLED\n" + - " \n" + - " \n" + - " SC-2\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; - assertInvalidResponse(response, operationalStateValidator); - } - - void assertValidResponse(String response, OperationalStateValidator operationalStateValidator) { - try { - operationalStateValidator.validateResponse(response); - } catch (APPCException e) { - fail("Got unexpected exception. Validation failed. " + e.getMessage()); - } - } - - @Test - public void testMockValidResponse() { - String response = "valid"; - OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator("mock"); - assertValidResponse(response, operationalStateValidator); - - response = ""; - assertValidResponse(response, operationalStateValidator); - - response = null; - assertValidResponse(response, operationalStateValidator); - } - - @Test - public void testMockInValidResponse() { - String response = "anything InValid anything.. "; - OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.MOCK); - assertInvalidResponse(response, operationalStateValidator); - } - - @Test - public void testGetOperationalStateValidatorForInValidVnfType() { - try{ - OperationalStateValidatorFactory.getOperationalStateValidator("wrongVnfType"); - fail("invalid vnfType without exception!!!"); - } catch (Exception e) { - assertNotNull(e.getMessage()); - } - } - - @Test - public void testGetOperationalStateValidatorForValidVnfType() { - String vnfType = VnfType.VNF.name().toLowerCase(); - assertGettingValidatorForValidVnf(vnfType); - - vnfType = VnfType.VNF.name().toUpperCase(); - assertGettingValidatorForValidVnf(vnfType); - - vnfType = VnfType.MOCK.name().toLowerCase(); - assertGettingValidatorForValidVnf(vnfType); - - vnfType = VnfType.MOCK.name().toUpperCase(); - assertGettingValidatorForValidVnf(vnfType); - } - - void assertGettingValidatorForValidVnf(String vnfType) { - try{ - OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(vnfType); - assertNotNull(operationalStateValidator); - } catch (Exception e) { - fail("valid vnfType throw exception!!!"); - } - } -} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivatorTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivatorTest.java new file mode 100644 index 000000000..c1321ec10 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivatorTest.java @@ -0,0 +1,42 @@ +package org.onap.appc.adapter.netconf; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.powermock.reflect.Whitebox; + +public class AppcNetconfAdapterActivatorTest { + + private BundleContext bundle; + + @Before + public void setup() { + bundle = Mockito.mock(BundleContext.class); + } + + @Test + public void testStart() throws Exception { + AppcNetconfAdapterActivator activator = new AppcNetconfAdapterActivator(); + activator.start(bundle); + Mockito.verify(bundle, Mockito.times(2)).registerService(Mockito.any(Class.class), + Mockito.any(NetconfDataAccessServiceImpl.class), Mockito.any()); + } + + @Test + public void testStop() throws Exception { + AppcNetconfAdapterActivator activator = Mockito.spy(new AppcNetconfAdapterActivator()); + ServiceRegistration registration = Mockito.mock(ServiceRegistration.class); + ServiceRegistration reporterRegistration = Mockito.mock(ServiceRegistration.class); + ServiceRegistration factoryRegistration = Mockito.mock(ServiceRegistration.class); + ServiceRegistration dbRegistration = Mockito.mock(ServiceRegistration.class); + Whitebox.setInternalState(activator, "registration", registration); + Whitebox.setInternalState(activator, "reporterRegistration", reporterRegistration); + Whitebox.setInternalState(activator, "factoryRegistration", factoryRegistration); + Whitebox.setInternalState(activator, "dbRegistration", dbRegistration); + activator.stop(bundle); + Mockito.verify(dbRegistration).unregister(); + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/OperationalStateValidatorTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/OperationalStateValidatorTest.java new file mode 100644 index 000000000..5fe7c79c5 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/OperationalStateValidatorTest.java @@ -0,0 +1,199 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson + * ============================================================================= + * 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.appc.adapter.netconf; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import org.junit.Test; +import org.onap.appc.exceptions.APPCException; + + +public class OperationalStateValidatorTest { + + @Test + public void testVNFValidResponse() { + String validResponse = "\n" + + "\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " ENABLED\n" + + " \n" + + " processor_0_5\n" + + " ENABLED\n" + + " \n" + + " \n" + + " processor_0_7\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " SC-1\n" + + " ENABLED\n" + + " \n" + + " \n" + + " SC-2\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); + assertValidResponse(validResponse, operationalStateValidator); + } + + void assertInvalidResponse(String response, OperationalStateValidator operationalStateValidator) { + try { + operationalStateValidator.validateResponse(response); + fail("invalid resposne passed without exception!!!"); + } catch (APPCException e) { + assertNotNull(e.getMessage()); + } + } + + @Test + public void testVNFInvalidResponses() { + + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); + assertInvalidResponse(null, operationalStateValidator); + + assertInvalidResponse("", operationalStateValidator); + + String response = ""; + assertInvalidResponse(response, operationalStateValidator); + + response = "\n" + + "\n" + + ""; + assertInvalidResponse(response, operationalStateValidator); + + response = "\n" + + "\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " ENABLED\n" + + " \n" + + " processor_0_5\n" + + " ENABLED\n" + + " \n" + + " \n" + + " processor_0_7\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " SC-1\n" + + " ENABLED\n" + + " \n" + + " \n" + + " SC-2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + assertInvalidResponse(response, operationalStateValidator); + } + + void assertValidResponse(String response, OperationalStateValidator operationalStateValidator) { + try { + operationalStateValidator.validateResponse(response); + } catch (APPCException e) { + fail("Got unexpected exception. Validation failed. " + e.getMessage()); + } + } + + @Test + public void testMockValidResponse() { + String response = "valid"; + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator("mock"); + assertValidResponse(response, operationalStateValidator); + + response = ""; + assertValidResponse(response, operationalStateValidator); + + response = null; + assertValidResponse(response, operationalStateValidator); + } + + @Test + public void testMockInValidResponse() { + String response = "anything InValid anything.. "; + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.MOCK); + assertInvalidResponse(response, operationalStateValidator); + } + + @Test + public void testGetOperationalStateValidatorForInValidVnfType() { + try{ + OperationalStateValidatorFactory.getOperationalStateValidator("wrongVnfType"); + fail("invalid vnfType without exception!!!"); + } catch (Exception e) { + assertNotNull(e.getMessage()); + } + } + + @Test + public void testGetOperationalStateValidatorForValidVnfType() { + String vnfType = VnfType.VNF.name().toLowerCase(); + assertGettingValidatorForValidVnf(vnfType); + + vnfType = VnfType.VNF.name().toUpperCase(); + assertGettingValidatorForValidVnf(vnfType); + + vnfType = VnfType.MOCK.name().toLowerCase(); + assertGettingValidatorForValidVnf(vnfType); + + vnfType = VnfType.MOCK.name().toUpperCase(); + assertGettingValidatorForValidVnf(vnfType); + } + + void assertGettingValidatorForValidVnf(String vnfType) { + try{ + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(vnfType); + assertNotNull(operationalStateValidator); + } catch (Exception e) { + fail("valid vnfType throw exception!!!"); + } + } +} -- cgit 1.2.3-korg