summaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-iaas-adapter
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-12 11:04:19 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-12 15:55:53 +0000
commitd2f77574cd61f5ceb2a03bfa2ae1c6d4e5913098 (patch)
treec1f836bda26ca44dd3addbffac8075f7c9644f6c /appc-adapters/appc-iaas-adapter
parentcc8ae79f1986f67b113aef27878d7f958d9e2d49 (diff)
Test coverage in ServiceCatalogV3
Increased coverage from 44% to 94% Issue-ID: APPC-1418 Change-Id: I0e534a5bc20caaae25b28902caa58f0c5d950c31 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java10
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java40
2 files changed, 48 insertions, 2 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java
index df307bcf8..970182245 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java
@@ -7,6 +7,8 @@
* Copyright (C) 2017 Amdocs
* =============================================================================
* Modifications Copyright © 2018 IBM.
+ * ================================================================================
+ * 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.
@@ -136,7 +138,7 @@ public class ServiceCatalogV3 extends ServiceCatalog {
logger.error("An error occurred when initializing ServiceCatalogV3", e);
return;
}
- Keystone keystone = new Keystone(identityURL, connector);
+ Keystone keystone = getKeystone(identityURL, connector);
String proxyHost = properties.getProperty(ContextFactory.PROPERTY_PROXY_HOST);
String proxyPort = properties.getProperty(ContextFactory.PROPERTY_PROXY_PORT);
@@ -401,7 +403,7 @@ public class ServiceCatalogV3 extends ServiceCatalog {
}
return now.getTime();
}
-
+
public Project getProject() {
Lock readLock = rwLock.readLock();
readLock.lock();
@@ -411,4 +413,8 @@ public class ServiceCatalogV3 extends ServiceCatalog {
readLock.unlock();
}
}
+
+ protected Keystone getKeystone(String identityURL, OpenStackClientConnector connector) {
+ return new Keystone(identityURL, connector);
+ }
} \ No newline at end of file
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java
index a5deb732a..f2ebf02d0 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.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.
@@ -29,6 +31,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -43,7 +46,15 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.appc.configuration.ConfigurationFactory;
+import org.powermock.reflect.Whitebox;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.ContextFactory;
import com.google.common.collect.ImmutableMap;
+import com.woorea.openstack.base.client.OpenStackClientConnector;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+import com.woorea.openstack.keystone.v3.Keystone;
+import com.woorea.openstack.keystone.v3.api.TokensResource;
import com.woorea.openstack.keystone.v3.model.Token;
import com.woorea.openstack.keystone.v3.model.Token.Service;
import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;
@@ -119,6 +130,8 @@ public class TestServiceCatalogV3 {
public void setup() {
URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
properties = new Properties();
+ properties.setProperty(ContextFactory.PROPERTY_PROXY_HOST, "PROXY_HOST");
+ properties.setProperty(ContextFactory.PROPERTY_PROXY_PORT, "PROXY_PORT");
catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
spyCatalog = Mockito.spy(catalog);
project.setId(TENANT_ID);
@@ -233,4 +246,31 @@ public class TestServiceCatalogV3 {
catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);
}
+
+ @Test
+ public void testInit() throws ZoneException, ClassNotFoundException, InstantiationException, IllegalAccessException, OpenStackConnectException, OpenStackResponseException {
+ ServiceCatalogV3 catalogSpy = Mockito.spy(catalog);
+ Class<?> connectorClass = Class.forName(ServiceCatalogV2.CLIENT_CONNECTOR_CLASS);
+ OpenStackClientConnector connector = (OpenStackClientConnector) connectorClass.newInstance();
+ Keystone keystone = Mockito.spy(new Keystone(IDENTITY_URL, connector));
+ TokensResource tokens = Mockito.mock(TokensResource.class);
+ TokensResource.Authenticate authenticate = Mockito.mock(TokensResource.Authenticate.class);
+ Mockito.when(keystone.tokens()).thenReturn(tokens);
+ Mockito.when(tokens.authenticate(Mockito.any())).thenReturn(authenticate);
+ Token token = Mockito.mock(Token.class);
+
+ Mockito.when(authenticate.execute()).thenReturn(token);
+ //Mockito.when(authenticate.withTenantName(Mockito.anyString())).thenReturn(authenticate);
+ Mockito.when(catalogSpy.getKeystone(Mockito.anyString(), Mockito.any())).thenReturn(keystone);
+ Endpoint endpoint = new Endpoint();
+ List<Endpoint> endpointList = new ArrayList<>();
+ endpointList.add(endpoint);
+ List<Token.Service> serviceList = new ArrayList<>();
+ Token.Service service = new Token.Service();
+ Whitebox.setInternalState(service, "endpoints", endpointList);
+ serviceList.add(service);
+ Mockito.when(token.getCatalog()).thenReturn(serviceList);
+ catalogSpy.init();
+ Mockito.verify(token).getCatalog();
+ }
}