Test coverage in ServiceCatalogV3
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / onap / appc / adapter / iaas / impl / TestServiceCatalogV3.java
index a5deb73..f2ebf02 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.\r
  * ================================================================================\r
  * Copyright (C) 2017 Amdocs\r
+ * ================================================================================\r
+ * Modifications Copyright (C) 2019 Ericsson\r
  * =============================================================================\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -29,6 +31,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;\r
 import static org.junit.Assert.assertTrue;\r
 import static org.mockito.Mockito.when;\r
+import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.HashSet;\r
 import java.util.List;\r
@@ -43,7 +46,15 @@ import org.junit.runner.RunWith;
 import org.mockito.Mockito;\r
 import org.mockito.runners.MockitoJUnitRunner;\r
 import org.onap.appc.configuration.ConfigurationFactory;\r
+import org.powermock.reflect.Whitebox;\r
+import com.att.cdp.exceptions.ZoneException;\r
+import com.att.cdp.zones.ContextFactory;\r
 import com.google.common.collect.ImmutableMap;\r
+import com.woorea.openstack.base.client.OpenStackClientConnector;\r
+import com.woorea.openstack.base.client.OpenStackConnectException;\r
+import com.woorea.openstack.base.client.OpenStackResponseException;\r
+import com.woorea.openstack.keystone.v3.Keystone;\r
+import com.woorea.openstack.keystone.v3.api.TokensResource;\r
 import com.woorea.openstack.keystone.v3.model.Token;\r
 import com.woorea.openstack.keystone.v3.model.Token.Service;\r
 import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;\r
@@ -119,6 +130,8 @@ public class TestServiceCatalogV3 {
     public void setup() {\r
         URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);\r
         properties = new Properties();\r
+        properties.setProperty(ContextFactory.PROPERTY_PROXY_HOST, "PROXY_HOST");\r
+        properties.setProperty(ContextFactory.PROPERTY_PROXY_PORT, "PROXY_PORT");\r
         catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);\r
         spyCatalog = Mockito.spy(catalog);\r
         project.setId(TENANT_ID);\r
@@ -233,4 +246,31 @@ public class TestServiceCatalogV3 {
 \r
         catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties);\r
     }\r
+\r
+    @Test\r
+    public void testInit() throws ZoneException, ClassNotFoundException, InstantiationException, IllegalAccessException, OpenStackConnectException, OpenStackResponseException {\r
+        ServiceCatalogV3 catalogSpy = Mockito.spy(catalog);\r
+        Class<?> connectorClass = Class.forName(ServiceCatalogV2.CLIENT_CONNECTOR_CLASS);\r
+        OpenStackClientConnector connector = (OpenStackClientConnector) connectorClass.newInstance();\r
+        Keystone keystone = Mockito.spy(new Keystone(IDENTITY_URL, connector));\r
+        TokensResource tokens = Mockito.mock(TokensResource.class);\r
+        TokensResource.Authenticate authenticate = Mockito.mock(TokensResource.Authenticate.class);\r
+        Mockito.when(keystone.tokens()).thenReturn(tokens);\r
+        Mockito.when(tokens.authenticate(Mockito.any())).thenReturn(authenticate);\r
+        Token token = Mockito.mock(Token.class);\r
+\r
+        Mockito.when(authenticate.execute()).thenReturn(token);\r
+        //Mockito.when(authenticate.withTenantName(Mockito.anyString())).thenReturn(authenticate);\r
+        Mockito.when(catalogSpy.getKeystone(Mockito.anyString(), Mockito.any())).thenReturn(keystone);\r
+        Endpoint endpoint = new Endpoint();\r
+        List<Endpoint> endpointList = new ArrayList<>();\r
+        endpointList.add(endpoint);\r
+        List<Token.Service> serviceList = new ArrayList<>();\r
+        Token.Service service = new Token.Service();\r
+        Whitebox.setInternalState(service, "endpoints", endpointList);\r
+        serviceList.add(service);\r
+        Mockito.when(token.getCatalog()).thenReturn(serviceList);\r
+        catalogSpy.init();\r
+        Mockito.verify(token).getCatalog();\r
+    }\r
 }\r