diff options
Diffstat (limited to 'appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle')
4 files changed, 291 insertions, 194 deletions
diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/pom.xml b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/pom.xml index e65afa908..e38a803a0 100644 --- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/pom.xml +++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/pom.xml @@ -3,7 +3,7 @@ ============LICENSE_START======================================================= ONAP : APPC ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. ================================================================================ Copyright (C) 2017 Amdocs ============================================================================= @@ -23,186 +23,188 @@ ============LICENSE_END========================================================= --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onap.appc</groupId> - <artifactId>appc-ansible-adapter</artifactId> - <version>1.3.0-SNAPSHOT</version> - </parent> - - <artifactId>appc-ansible-adapter-bundle</artifactId> - <packaging>bundle</packaging> - <name>APPC Ansible Service Adapter - bundle</name> - - <dependencies> - <dependency> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - <version>1.9</version> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.2</version> - </dependency> - - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <version>4.5.2</version> - </dependency> - - <!-- http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --> - <dependency> - <groupId>org.onap.appc</groupId> - <artifactId>appc-common</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>javax</groupId> - <artifactId>javaee-api</artifactId> - <version>7.0</version> - </dependency> - - <!-- - ### DEPENDENCIES NOT REQUIRED + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.appc</groupId> + <artifactId>appc-ansible-adapter</artifactId> + <version>1.3.0-SNAPSHOT</version> + </parent> + + <artifactId>appc-ansible-adapter-bundle</artifactId> + <packaging>bundle</packaging> + <name>APPC Ansible Service Adapter - bundle</name> + + <dependencies> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.9</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.2</version> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.5.2</version> + </dependency> + + <!-- http://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --> + <dependency> + <groupId>org.onap.appc</groupId> + <artifactId>appc-common</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>javax</groupId> + <artifactId>javaee-api</artifactId> + <version>7.0</version> + </dependency> + + <!-- + ### DEPENDENCIES NOT REQUIRED <dependency> - <groupId>jce</groupId> - <artifactId>jce</artifactId> - <version>1_2-do</version> - <scope>compile</scope> - </dependency> - - - <dependency> - <groupId>javax.ws.rs</groupId> - <artifactId>javax.ws.rs-api</artifactId> - <version>2.0</version> - </dependency> - - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>2.2.3</version> - </dependency> - - <dependency> - <groupId>javax.xml</groupId> - <artifactId>jaxp-api</artifactId> - <version>1.4.2</version> - </dependency> - - ######### - --> - - <!-- Needed to run test cases --> - <dependency> - <groupId>org.glassfish.jersey.core</groupId> - <artifactId>jersey-common</artifactId> - <version>2.9.1</version> - </dependency> - - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-jaxrs</artifactId> - <version>1.9.12</version> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - - - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>sli-common</artifactId> - <scope>compile</scope> - <!-- Added exclusion to prevent missing dependency issue on dblib --> - <exclusions> - <exclusion> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>dblib-provider</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>sli-provider</artifactId> - <scope>compile</scope> - <!-- Added exclusion to prevent missing dependency issue on dblib --> - <exclusions> - <exclusion> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>dblib-provider</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>equinoxSDK381</groupId> - <artifactId>org.eclipse.osgi</artifactId> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - </dependency> - - <dependency> - <groupId>org.mariadb.jdbc</groupId> - <artifactId>mariadb-java-client</artifactId> - </dependency> - - <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - <version>20160212</version> - </dependency> + <groupId>jce</groupId> + <artifactId>jce</artifactId> + <version>1_2-do</version> + <scope>compile</scope> + </dependency> + + + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + <version>2.0</version> + </dependency> + + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>2.2.3</version> + </dependency> + + <dependency> + <groupId>javax.xml</groupId> + <artifactId>jaxp-api</artifactId> + <version>1.4.2</version> + </dependency> + + ######### + --> + + <!-- Needed to run test cases --> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-common</artifactId> + <version>2.9.1</version> + </dependency> + + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-jaxrs</artifactId> + <version>1.9.12</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-common</artifactId> + <scope>compile</scope> + <!-- Added exclusion to prevent missing dependency issue on dblib --> + <exclusions> + <exclusion> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>dblib-provider</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider</artifactId> + <scope>compile</scope> + <!-- Added exclusion to prevent missing dependency issue on dblib --> + <exclusions> + <exclusion> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>dblib-provider</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>equinoxSDK381</groupId> + <artifactId>org.eclipse.osgi</artifactId> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </dependency> + + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + </dependency> + + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20160212</version> + </dependency> <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>20.0</version> - </dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>20.0</version> + </dependency> <!-- <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.8.0</version> - </dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.0</version> + </dependency> --> - </dependencies> - - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-SymbolicName>appc-ansible-adapter</Bundle-SymbolicName> - <Bundle-Activator>org.onap.appc.adapter.ansible.AnsibleActivator</Bundle-Activator> - <Export-Package>org.onap.appc.adapter.ansible</Export-Package> - <Import-Package>org.onap.ccsdk.sli.core.sli.*,org.osgi.framework.*,org.slf4j.*, javax.net.*,javax.net.ssl.*,org.xml.sax.*,javax.xml.bind.*,javax.naming.*, javax.security.*</Import-Package> - <Embed-Dependency>*;scope=compile|runtime;artifactId=!sli-common|org.eclipse.osgi|slf4j-api|jcl-over-slf4j|mariadb-java-client|xml-apis</Embed-Dependency> - <Embed-Transitive>true</Embed-Transitive> - </instructions> - </configuration> - </plugin> - </plugins> - </build> + </dependencies> + + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>appc-ansible-adapter</Bundle-SymbolicName> + <Bundle-Activator>org.onap.appc.adapter.ansible.AnsibleActivator</Bundle-Activator> + <Export-Package>org.onap.appc.adapter.ansible</Export-Package> + <Import-Package>org.onap.ccsdk.sli.core.sli.*,org.osgi.framework.*,org.slf4j.*, javax.net.*,javax.net.ssl.*,org.xml.sax.*,javax.xml.bind.*,javax.naming.*, javax.security.*</Import-Package> + <Embed-Dependency>*;scope=compile|runtime;artifactId=!sli-common|org.eclipse.osgi|slf4j-api|jcl-over-slf4j|mariadb-java-client|xml-apis</Embed-Dependency> + <Embed-Transitive>true</Embed-Transitive> + </instructions> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java index 0e19384e6..5207df2c2 100644 --- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java +++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/model/AnsibleMessageParser.java @@ -116,21 +116,6 @@ public class AnsibleMessageParser { /** * Method that validates that the Map has enough information - * to query Ansible server for logs. If so, it populates the - * appropriate returns the appropriate url, else an empty string. - */ - public String reqUriOutput(Map<String, String> params) throws APPCException { - - final String[] mandatoryTestParams = {AGENT_URL_KEY, ID_KEY, USER_KEY, PASS_KEY}; - - for (String mandatoryParam : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, mandatoryParam); - } - return params.get(AGENT_URL_KEY) + "?Id=" + params.get(ID_KEY) + "&Type=GetOutput"; - } - - /** - * Method that validates that the Map has enough information * to query Ansible server for logs. If so, it populates the appropriate * returns the appropriate url, else an empty string. */ diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/AnsibleActivatorTest.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/AnsibleActivatorTest.java new file mode 100644 index 000000000..2eb1a781b --- /dev/null +++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/AnsibleActivatorTest.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.ansible; + +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.only; + +import java.util.Dictionary; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.appc.adapter.ansible.impl.AnsibleAdapterImpl; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +@RunWith(MockitoJUnitRunner.class) + +public class AnsibleActivatorTest { + + @Mock + private ServiceRegistration<AnsibleAdapter> serviceRegistration; + @Mock + private BundleContext bundleContext; + + private AnsibleActivator ansibleActivator = new AnsibleActivator(); + + @Before + public void setUp() { + given(bundleContext.registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull( + Dictionary.class))).willReturn(serviceRegistration); + } + + @Test + public void start_shouldRegisterService_whenRegistrationOccursForTheFirstTime() throws Exception { + registerService(); + + then(bundleContext).should(only()) + .registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull( + Dictionary.class)); + } + + @Test + public void start_shouldRegisterServiceOnlyOnce_whenServiceRegistrationIsNotNull() throws Exception { + // GIVEN + registerService(); + + // WHEN + registerService(); + + // THEN + then(bundleContext).should(only()).registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull( + Dictionary.class)); + } + + @Test + public void stop_shouldUnregisterService_whenServiceRegistrationObjectIsNotNull() throws Exception { + // GIVEN + registerService(); + + // WHEN + unregisterService(); + + // THEN + then(serviceRegistration).should().unregister(); + } + + @Test + public void stop_shouldNotAttemptToUnregisterService_whenServiceHasAlreadyBeenUnregistered() + throws Exception { + // GIVEN + registerService(); + unregisterService(); + + // WHEN + unregisterService(); + + // THEN + then(serviceRegistration).should(only()).unregister(); + } + + private void registerService() throws Exception { + ansibleActivator.start(bundleContext); + } + + private void unregisterService() throws Exception { + ansibleActivator.stop(bundleContext); + } +} diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleAdapter.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleAdapter.java index 9641d1986..34953d437 100644 --- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleAdapter.java +++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleAdapter.java @@ -42,13 +42,11 @@ public class TestAnsibleAdapter { @Test public void callPrivateConstructorsMethodsForCodeCoverage() throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { - /* test constructors */ Class<?>[] classesOne = {AnsibleMessageParser.class}; for(Class<?> clazz : classesOne) { Constructor<?> constructor = clazz.getDeclaredConstructor(); name = constructor.getName(); - System.out.println("the constructor name is" + name); constructor.setAccessible(true); assertNotNull(constructor.newInstance()); } @@ -56,7 +54,6 @@ public class TestAnsibleAdapter { for(Class<?> clazz : classesTwo) { Constructor<?> constructor = clazz.getDeclaredConstructor(); name = constructor.getName(); - System.out.println("the constructor name is" + name); constructor.setAccessible(true); assertNotNull(constructor.newInstance()); } @@ -64,17 +61,16 @@ public class TestAnsibleAdapter { for(Class<?> clazz : classesThree) { Constructor<?> constructor = clazz.getDeclaredConstructor(); name = constructor.getName(); - System.out.println("the constructor name is" + name); constructor.setAccessible(true); assertNotNull(constructor.newInstance()); } /* test methods */ - ansibleMessageParser = new AnsibleMessageParser(); + ansibleMessageParser = new AnsibleMessageParser(); parameterTypes = new Class[1]; parameterTypes[0] = java.lang.String.class; + m = ansibleMessageParser.getClass().getDeclaredMethod("getFilePayload", parameterTypes); - System.out.println("method name is getFilePayload"); m.setAccessible(true); assertNotNull(m.invoke(ansibleMessageParser,"{\"test\": test}")); |