diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src/test/java/org')
64 files changed, 2672 insertions, 3522 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java new file mode 100644 index 0000000000..36f82e15bd --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so; + + +import com.github.tomakehurst.wiremock.client.WireMock; +import org.junit.After; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +@AutoConfigureWireMock(port = 0) +public abstract class BaseTest extends TestDataSetup { + + @Value("${wiremock.server.port}") + protected int wireMockPort; + + @After + public void after() { + WireMock.reset(); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java new file mode 100644 index 0000000000..f5867befc0 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so; + +import org.apache.http.HttpStatus; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; + +public class StubOpenStack { + + public static void mockOpenStackResponseAccess(int port) throws IOException { + stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackDelete(String id) { + stubFor(delete(urlMatching("/mockPublicUrl/stacks/" + id)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } + + + public static void mockOpenStackPostStack_200(String filename) { + stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPostTenantWithBodyFile_200() throws IOException { + stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants")) + .willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetTenantByName(String tenantName) throws IOException { + stubFor(get(urlMatching("/mockPublicUrl/tenants/[?]name=" + tenantName)) + .willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetTenantById(String tenantId) throws IOException { + stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId")) + .willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackDeleteTenantById_200(String tenantId) { + stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetUserById(String user) { + stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetUserByName(String userName) { + stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetUserByName_500(String userName) { + stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse() + .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + } + + public static void mockOpenStackGetRoles_200(String roleFor) { + stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenstackPostNetwork(String responseFile) { + stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile(responseFile) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenstackPutNetwork(String responseFile, String networkId) { + stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile(responseFile) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetNeutronNetwork(String filename,String networkId) { + stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetNeutronNetwork_500(String networkId) { + stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId)) + .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + } + + public static void mockOpenStackDeleteNeutronNetwork(String networkId) { + stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)) + .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); + } + + private static String readFile(String fileName) throws IOException { + try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + return sb.toString(); + } + } + + public static String getBodyFromFile(String fileName, int port, String urlPath) throws IOException { + return readFile("src/test/resources/__files/" + fileName).replaceAll("port", "http://localhost:" + port + urlPath); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/TestApplication.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/TestApplication.java new file mode 100644 index 0000000000..479731c870 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/TestApplication.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 org.onap.so; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.Profile; + +@SpringBootApplication +@Profile("test") +@ComponentScan(basePackages = {"org.onap.so", "com.att"}, excludeFilters = { + @Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) +public class TestApplication { + public static void main(String... args) { + SpringApplication.run(TestApplication.class, args); + System.getProperties().setProperty("mso.db", "MARIADB"); + System.getProperties().setProperty("server.name", "Springboot"); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/TestDataSetup.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/TestDataSetup.java new file mode 100644 index 0000000000..21c4c225ba --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/TestDataSetup.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.ExpectedException; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class TestDataSetup { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + public static final String RESOURCE_PATH = "src/test/resources/__files/"; + public ObjectMapper mapper; + + @Before + public void testDataSetupBefore() { + mapper = new ObjectMapper(); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsRefactorTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsRefactorTest.java new file mode 100644 index 0000000000..539e7acef0 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsRefactorTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 org.onap.so.adapter_utils.tests; + + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.cloud.Application; +import org.onap.so.openstack.utils.MsoCommonUtils; +import org.onap.so.openstack.utils.MsoHeatUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.Assert.assertEquals; + +/** + * This class implements test methods of the MsoHeatUtils + * + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@ActiveProfiles("test") +public class MsoHeatUtilsRefactorTest extends MsoCommonUtils { + + @Autowired + private MsoHeatUtils msoHeatUtils; + + @Test + public final void testGetKeystoneUrl() { + try { + String keyUrl = msoHeatUtils.getCloudSiteKeystoneUrl("DAN"); + assertEquals("http://192.168.170.21:5000/v2.0",keyUrl); + } catch (Exception e) { + + } + } + + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsTest.java new file mode 100644 index 0000000000..c9a0a1d8c6 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsTest.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 org.onap.so.adapter_utils.tests; + +import java.util.HashMap; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.cloud.Application; +import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; +import org.onap.so.openstack.exceptions.MsoException; +import org.onap.so.openstack.exceptions.MsoIOException; +import org.onap.so.openstack.exceptions.MsoStackAlreadyExists; +import org.onap.so.openstack.exceptions.MsoTenantNotFound; +import org.onap.so.openstack.utils.MsoCommonUtils; +import org.onap.so.openstack.utils.MsoHeatUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import com.woorea.openstack.heat.model.CreateStackParam; + +/** + * This class implements test methods of the MsoHeatUtils + * + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@ActiveProfiles("test") +@Ignore +public class MsoHeatUtilsTest extends MsoCommonUtils { + @Autowired + private MsoHeatUtils msoHeatUtils; + + @Test + public final void testCreateStackBadCloudConfig() + throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { + try { + msoHeatUtils.createStack("DOESNOTEXIST", "test", "stackName", "test", new HashMap<String, Object>(), + Boolean.TRUE, 10); + } catch (MsoCloudSiteNotFound e) { + + } catch (java.lang.NullPointerException npe) { + + } + + } + + @Test + public final void testCreateStackFailedConnectionHeatClient() + throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, + 10); + } catch (MsoIOException e) { + + } + + } + + @Test + public final void testCreateStackFailedConnection() + throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, + 10); + } catch (MsoIOException e) { + + } + + } + + @Test + public final void createStackSuccessWithEnvironment() throws MsoException { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10, + "environment"); + } catch (MsoIOException e) { + + } + + } + + @Test + public final void createStackSuccessWithFiles() throws MsoException { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10, + "environment", new HashMap<String, Object>()); + } catch (MsoIOException e) { + + } + + } + + @Test + public final void createStackSuccessWithHeatFiles() throws MsoException { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10, + "environment", new HashMap<String, Object>(), new HashMap<String, Object>()); + } catch (MsoIOException e) { + + } + } + + @Test + public final void requestToStringBuilderTest() { + CreateStackParam param = new CreateStackParam(); + param.setDisableRollback(false); + param.setEnvironment("environment"); + param.setFiles(new HashMap<String, Object>()); + param.setParameters(new HashMap<>()); + param.setStackName("stackName"); + param.setTemplate("template"); + param.setTemplateUrl("http://templateUrl"); + param.setTimeoutMinutes(1); + + msoHeatUtils.requestToStringBuilder(param); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java index 62043e83b8..6d9687216d 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java @@ -18,11 +18,12 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.adapter_utils.tests; +package org.onap.so.adapter_utils.tests; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; +import java.security.GeneralSecurityException; import java.util.HashMap; import java.util.Map; @@ -34,40 +35,37 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import org.openecomp.mso.cloud.CloudConfig; -import org.openecomp.mso.cloud.CloudConfigFactory; -import org.openecomp.mso.cloud.CloudIdentity; -import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType; -import org.openecomp.mso.cloud.CloudSite; -import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; -import org.openecomp.mso.openstack.exceptions.MsoException; -import org.openecomp.mso.openstack.exceptions.MsoIOException; -import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate; -import org.openecomp.mso.properties.MsoPropertiesFactory; +import org.onap.so.cloud.CloudConfig; +import org.onap.so.cloud.CloudIdentity; +import org.onap.so.cloud.CloudSite; +import org.onap.so.cloud.ServerType; +import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; +import org.onap.so.openstack.exceptions.MsoException; +import org.onap.so.openstack.exceptions.MsoIOException; +import org.onap.so.openstack.utils.MsoHeatUtilsWithUpdate; +import org.onap.so.utils.CryptoUtils; import com.woorea.openstack.base.client.OpenStackConnectException; @RunWith(MockitoJUnitRunner.class) public class MsoHeatUtilsWithUpdateTest { - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); @Mock - CloudConfig cloudConfig; + private CloudConfig cloudConfig; @InjectMocks - MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate("NO_PROP",msoPropertiesFactory,cloudConfigFactory); + private MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate(); private CloudSite cloudSite; @Before public void init () { cloudSite = new CloudSite (); - cloudSite.setId ("cloud"); + cloudSite.setRegionId("cloud"); CloudIdentity cloudIdentity = new CloudIdentity (); - cloudIdentity.setIdentityServerType(IdentityServerType.KEYSTONE); - cloudIdentity.setKeystoneUrl ("toto"); - cloudIdentity.setMsoPass (CloudIdentity.encryptPassword ("mockId")); + cloudIdentity.setIdentityServerType(ServerType.KEYSTONE); + cloudIdentity.setIdentityUrl("toto"); + cloudIdentity.setMsoPass (CryptoUtils.encryptCloudConfigPassword("mockId")); cloudSite.setIdentityService (cloudIdentity); when(cloudConfig.getCloudSite("cloud")).thenReturn (Optional.of(cloudSite)); when(cloudConfig.getCloudSite("none")).thenReturn (Optional.empty()); diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudConfigTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudConfigTest.java new file mode 100644 index 0000000000..668b1806ac --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudConfigTest.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 org.onap.so.cloud; + +import static org.junit.Assert.*; + +import java.util.Map; +import java.util.Optional; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.BaseTest; +import org.onap.so.openstack.exceptions.MsoException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * This class implements test methods of the CloudConfig features. + * + * + */ +public class CloudConfigTest extends BaseTest { + + @Autowired + private CloudConfig con; + + /** + * This method implements a test for the getCloudSites method. + */ + @Test + public final void testGetCloudSites () { + Map<String,CloudSite> siteMap = con.getCloudSites(); + assertNotNull(siteMap); + + CloudSite site1 = siteMap.get("regionOne"); + + assertEquals ("regionOne", site1.getRegionId()); + assertEquals ("MT_KEYSTONE", site1.getIdentityServiceId()); + assertEquals ("MT2", site1.getClli()); + assertEquals ("2.5", site1.getAicVersion()); + } + + + /** + * This method implements a test for the getIdentityServices method. + * @throws MsoException + */ + @Test + public final void testGetIdentityServices () throws MsoException { + Map<String,CloudIdentity> identityMap = con.getIdentityServices (); + assertNotNull(identityMap); + + CloudIdentity identity1 = identityMap.get("MT_KEYSTONE"); + + assertEquals("john", identity1.getMsoId()); + assertEquals("313DECE408AF7759D442D7B06DD9A6AA", identity1.getMsoPass()); + assertEquals("admin", identity1.getAdminTenant()); + assertEquals("_member_", identity1.getMemberRole()); + assertEquals(false, identity1.hasTenantMetadata()); + assertEquals("http://localhost:"+wireMockPort+"/v2.0", identity1.getIdentityUrl()); + assertEquals(ServerType.KEYSTONE, identity1.getIdentityServerType()); + assertEquals(AuthenticationType.USERNAME_PASSWORD, identity1.getIdentityAuthenticationType()); + + } + + /** + * This method implements a test for the getCloudSite method. + */ + @Test + public final void testGetDefaultCloudSite () { + Optional<CloudSite> site = con.getCloudSite("NotThere"); + assertTrue(site.isPresent()); + CloudSite site1 = site.get(); + assertEquals ("NotThere", site1.getRegionId()); + assertEquals("MTN6", site1.getClli()); + assertEquals("NotThere", site1.getId()); + assertEquals ("ORDM3", site1.getIdentityServiceId()); + } + + @Test + public void testGetIdentityService() { + CloudIdentity identity = con.getIdentityService("MT_KEYSTONE"); + assertEquals("john", identity.getMsoId()); + assertEquals("MT_KEYSTONE", identity.getId()); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudIdentityTest.java index eef45b7164..db2ba05bf1 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudIdentityTest.java @@ -18,16 +18,28 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.cloud; +package org.onap.so.cloud; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Test; +import java.security.GeneralSecurityException; +import org.junit.Test; +import org.onap.so.utils.CryptoUtils; public class CloudIdentityTest { - + + private CloudIdentity cloudIdentity = new CloudIdentity(); + private static final String ID = "testId"; + private static final String IDENTITY_URL = "testIdentityUrl"; + private static final String MSO_ID = "testMsoId"; + private static final String MSO_PASS = "testMsoPassword"; + private static final String ADMIN_TENANT = "testAdminTenant"; + private static final String MEMBER_ROLE = "testMemberRole"; + private static final Boolean TENANT_METADATA = true; + @Test public final void testCloudIdentity () { CloudIdentity id = new CloudIdentity (); @@ -37,7 +49,7 @@ public class CloudIdentityTest { id.setIdentityUrl ("keystone"); id.setMemberRole ("member"); id.setMsoId ("msoId"); - id.setMsoPass (CloudIdentity.encryptPassword ("password")); + id.setMsoPass (CryptoUtils.encryptCloudConfigPassword("password")); id.setTenantMetadata (true); id.setIdentityServerType(null); id.setIdentityAuthenticationType(null); @@ -48,17 +60,41 @@ public class CloudIdentityTest { // assertTrue (id.getKeystoneUrl ().equals ("keystone")); assertTrue (id.getMemberRole ().equals ("member")); assertTrue (id.getMsoId ().equals ("msoId")); - assertTrue (id.getMsoPass ().equals ("password")); + assertTrue (CryptoUtils.decryptCloudConfigPassword(id.getMsoPass()).equals ("password")); assertTrue (id.hasTenantMetadata ()); // assertTrue (id.toString ().contains ("keystone")); assertTrue(id.toString().contains("null")); } @Test - public final void testEncryption () { - String encrypted = CloudIdentity.encryptPassword ("password"); + public final void testEncryption () throws GeneralSecurityException { + String encrypted = CryptoUtils.encryptCloudConfigPassword("password"); assertTrue (encrypted != null); assertTrue (!encrypted.equals ("password")); } + @Test + public void cloneTest() { + cloudIdentity = setupCloudIdentity(cloudIdentity, ID, IDENTITY_URL, MSO_ID, MSO_PASS, ADMIN_TENANT, + MEMBER_ROLE, TENANT_METADATA, ServerType.ORM, AuthenticationType.USERNAME_PASSWORD); + CloudIdentity cloudIdentity2 = cloudIdentity.clone(); + + assertEquals(cloudIdentity.getClass(), cloudIdentity2.getClass()); + } + + private CloudIdentity setupCloudIdentity(CloudIdentity obj, String id, String identityUrl, + String msoId, String msoPass, String adminTenant, String memberRole, Boolean tenantMetadata, + ServerType identityServerType, AuthenticationType identityAuthenticationType) { + obj.setId(id); + obj.setIdentityUrl(identityUrl); + obj.setMsoId(msoId); + obj.setMsoPass(msoPass); + obj.setAdminTenant(adminTenant); + obj.setMemberRole(memberRole); + obj.setTenantMetadata(tenantMetadata); + obj.setIdentityServerType(identityServerType); + obj.setIdentityAuthenticationType(identityAuthenticationType); + + return obj; + } } diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudPojoTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudPojoTest.java new file mode 100644 index 0000000000..89c15b0deb --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudPojoTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.cloud; + +import org.junit.Test; +import org.onap.so.openpojo.rules.EqualsAndHashCodeTester; +import org.onap.so.openpojo.rules.ToStringTester; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; +import com.openpojo.validation.rule.impl.NoPrimitivesRule; +import com.openpojo.validation.rule.impl.NoPublicFieldsRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class CloudPojoTest { + @Test + public void pojoStructure() { + test(PojoClassFactory.getPojoClass(CloudIdentity.class)); + test(PojoClassFactory.getPojoClass(CloudifyManager.class)); + test(PojoClassFactory.getPojoClass(CloudSite.class)); + test(PojoClassFactory.getPojoClass(CloudConfig.class)); + } + + private void test(PojoClass pojoClass) { + Validator validator = ValidatorBuilder.create() + .with(new EqualsAndHashCodeMatchRule()) + .with(new NoPrimitivesRule()) + .with(new NoPublicFieldsRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + .with(new EqualsAndHashCodeTester()) + .build(); + validator.validate(pojoClass); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudifyManagerTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudifyManagerTest.java new file mode 100644 index 0000000000..9a660b4d40 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/CloudifyManagerTest.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.cloud; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class CloudifyManagerTest { + + private CloudifyManager cloudifyManager = new CloudifyManager(); + private static final String ID = "testId"; + private static final String CLOUDIFY_URL = "testCloudifyUrl"; + private static final String USERNAME = "testUsername"; + private static final String PASSWORD = "testPassword"; + private static final String VERSION = "testVersion"; + + @Test + public void cloneTest() { + cloudifyManager.setId(ID); + cloudifyManager.setCloudifyUrl(CLOUDIFY_URL); + cloudifyManager.setUsername(USERNAME); + cloudifyManager.setPassword(PASSWORD); + cloudifyManager.setVersion(VERSION); + + CloudifyManager clone = cloudifyManager.clone(); + assertEquals(cloudifyManager, clone); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/AuthenticationMethodTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/AuthenticationMethodTest.java new file mode 100644 index 0000000000..e1c533757b --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/AuthenticationMethodTest.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 org.onap.so.cloud.authentication; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.cloud.Application; +import org.onap.so.cloud.AuthenticationType; +import org.onap.so.cloud.CloudIdentity; +import org.onap.so.cloud.authentication.models.RackspaceAuthentication; +import org.onap.so.openstack.exceptions.MsoException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import com.woorea.openstack.keystone.model.Authentication; +import com.woorea.openstack.keystone.model.authentication.UsernamePassword; + +/** + * A few JUnit tests to evaluate the new factory that manages authentication + * types and their associated wrapper classes. Here it is assumed that core types + * only are tested. + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@ActiveProfiles("test") +public class AuthenticationMethodTest { + + @Autowired + private AuthenticationMethodFactory authenticationMethodFactory; + /** + * + */ + public AuthenticationMethodTest() { + // TODO Auto-generated constructor stub + } + + @Test + public void testCustomRackspaceAuth() { + CloudIdentity ci = new CloudIdentity(); + ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY); + ci.setMsoPass("FD205490A48D48475607C36B9AD902BF"); + ci.setMsoId("test"); + + Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci); + assertTrue(RackspaceAuthentication.class.equals(auth.getClass())); + + } + + @Test + public void testCoreUsernamePasswordAuth() { + CloudIdentity ci = new CloudIdentity(); + ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD); + ci.setMsoPass("FD205490A48D48475607C36B9AD902BF"); + ci.setMsoId("someuser"); + + Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci); + assertTrue(UsernamePassword.class.equals(auth.getClass())); + + } + + @Test + public void testCustomRackspaceAuthFromCloudIdentity() { + CloudIdentity ci = new CloudIdentity(); + ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY); + ci.setMsoPass("FD205490A48D48475607C36B9AD902BF"); + ci.setMsoId("test"); + + Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci); + assertTrue(RackspaceAuthentication.class.equals(auth.getClass())); + } + + @Test + public void testCoreUsernamePasswordAuthFromCloudIdentity() { + CloudIdentity ci = new CloudIdentity(); + ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD); + ci.setMsoPass("FD205490A48D48475607C36B9AD902BF"); + ci.setMsoId("someuser"); + + Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci); + assertTrue(UsernamePassword.class.equals(auth.getClass())); + + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/beans/DeploymentInfoTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoTest.java index a8fef5db94..e200f9aa96 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/beans/DeploymentInfoTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoTest.java @@ -1,76 +1,76 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.cloudify.beans;
-
-import static org.mockito.Mockito.mock;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.openecomp.mso.cloudify.v3.model.Deployment;
-import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs;
-import org.openecomp.mso.cloudify.v3.model.Execution;
-import org.powermock.api.mockito.PowerMockito;
-
-public class DeploymentInfoTest {
-
- @Mock
- DeploymentStatus status;
-
- @Mock
- DeploymentOutputs out;
-
- @Mock
- Execution execution;
-
- @Mock
- Deployment deployment;
-
- @Test
- public void test() {
- Deployment deployment=mock(Deployment.class);
- Map<String,Object> dep=new HashMap();
- Map<String,Object> outputs = new HashMap<String,Object>();
- Map<String,Object> inputs = new HashMap<String,Object>();
- inputs.put("id",dep);
- status=DeploymentStatus.CREATED;
- outputs.put("id", out);
- dep.put("id", outputs);
- DeploymentInfo dinfo=new DeploymentInfo(deployment);
- DeploymentInfo dinfi=new DeploymentInfo("id");
- DeploymentInfo din=new DeploymentInfo("id",outputs);
- DeploymentInfo dfo=new DeploymentInfo("id", status);
- DeploymentInfo dfoi=new DeploymentInfo(deployment, out, execution);
- dinfo=PowerMockito.spy(new DeploymentInfo());
- dinfo.setId("id");
- dinfi.setInputs(inputs);
- din.setStatus(status);
- din.setOutputs(outputs);
- assert(din.toString()!=null);
- assert(din.getOutputs().equals(outputs));
- assert(din.getId().equals("id"));
- assert(din.getStatus().equals(status));
- din.getLastAction();
- din.getErrorMessage();
- din.getActionStatus();
- }
-
-}
+/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.cloudify.beans; + +import static org.mockito.Mockito.mock; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.so.cloudify.v3.model.Deployment; +import org.onap.so.cloudify.v3.model.DeploymentOutputs; +import org.onap.so.cloudify.v3.model.Execution; +import org.powermock.api.mockito.PowerMockito; + +public class DeploymentInfoTest { + + @Mock + DeploymentStatus status; + + @Mock + DeploymentOutputs out; + + @Mock + Execution execution; + + @Mock + Deployment deployment; + + @Test + public void test() { + Deployment deployment=mock(Deployment.class); + Map<String,Object> dep=new HashMap(); + Map<String,Object> outputs = new HashMap<String,Object>(); + Map<String,Object> inputs = new HashMap<String,Object>(); + inputs.put("id",dep); + status=DeploymentStatus.CREATED; + outputs.put("id", out); + dep.put("id", outputs); + DeploymentInfo dinfo=new DeploymentInfo(deployment); + DeploymentInfo dinfi=new DeploymentInfo("id"); + DeploymentInfo din=new DeploymentInfo("id",outputs); + DeploymentInfo dfo=new DeploymentInfo("id", status); + DeploymentInfo dfoi=new DeploymentInfo(deployment, out, execution); + dinfo=PowerMockito.spy(new DeploymentInfo()); + dinfo.setId("id"); + dinfi.setInputs(inputs); + din.setStatus(status); + din.setOutputs(outputs); + assert(din.toString()!=null); + assert(din.getOutputs().equals(outputs)); + assert(din.getId().equals("id")); + assert(din.getStatus().equals(status)); + din.getLastAction(); + din.getErrorMessage(); + din.getActionStatus(); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyExceptionTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyExceptionTest.java new file mode 100644 index 0000000000..4bf087b7a4 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyExceptionTest.java @@ -0,0 +1,39 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.cloudify.exceptions; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class MsoCloudifyExceptionTest { + + @Test + public void test() { + Exception e = null; + boolean pendingWorkflow=true; + MsoCloudifyException mce=new MsoCloudifyException(200, "message", "detail"); + MsoCloudifyException mcl=new MsoCloudifyException(200, "message", "detail", e); + mce.setPendingWorkflow(pendingWorkflow); + assert(mcl.toString()!=null); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTest.java new file mode 100644 index 0000000000..a1859e491a --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTest.java @@ -0,0 +1,35 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.cloudify.exceptions; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class MsoCloudifyTest { + + @Test + public void test() { + MsoBlueprintAlreadyExists mbae=new MsoBlueprintAlreadyExists("blueprintId", "cloud"); + MsoCloudifyManagerNotFound mcm=new MsoCloudifyManagerNotFound("cloudSiteId"); + MsoDeploymentAlreadyExists mdae=new MsoDeploymentAlreadyExists("deploymentId", "cloud"); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeoutTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeoutTest.java new file mode 100644 index 0000000000..21c625feb3 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeoutTest.java @@ -0,0 +1,38 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.cloudify.exceptions; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import org.junit.Test; +import org.onap.so.cloudify.v3.model.Execution; + +public class MsoCloudifyTimeoutTest { + + @Test + public void test() { + Execution execution=mock(Execution.class); + MsoCloudifyTimeout mct=new MsoCloudifyTimeout(execution); + mct.getExecution(); + assert(mct.toString()!=null); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java new file mode 100644 index 0000000000..68df574611 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java @@ -0,0 +1,36 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.cloudify.exceptions; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class MsoCloudifyWorkflowExceptionTest { + + @Test + public void test() { + MsoCloudifyWorkflowException mcw=new MsoCloudifyWorkflowException("message", "id", "workflowId", "workflowStatus"); + mcw.getWorkflowStatus(); + assertFalse(mcw.isWorkflowStillRunning()); + + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java index 05608b4d99..e75a4aecaf 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java @@ -1,254 +1,231 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.cloudify.utils;
-
-import static com.shazam.shazamcrest.MatcherAssert.assertThat;
-import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.openecomp.mso.adapters.vdu.CloudInfo;
-import org.openecomp.mso.adapters.vdu.PluginAction;
-import org.openecomp.mso.adapters.vdu.VduArtifact;
-import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;
-import org.openecomp.mso.adapters.vdu.VduInstance;
-import org.openecomp.mso.adapters.vdu.VduModelInfo;
-import org.openecomp.mso.adapters.vdu.VduStateType;
-import org.openecomp.mso.adapters.vdu.VduStatus;
-import org.openecomp.mso.cloud.CloudConfig;
-import org.openecomp.mso.cloud.CloudIdentity;
-import org.openecomp.mso.cloud.CloudSite;
-import org.openecomp.mso.cloudify.beans.DeploymentInfo;
-import org.openecomp.mso.cloudify.beans.DeploymentStatus;
-import org.openecomp.mso.cloudify.v3.client.Cloudify;
-import org.openecomp.mso.cloudify.v3.model.AzureConfig;
-import org.openecomp.mso.cloudify.v3.model.OpenstackConfig;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-
-public class MsoCloudifyUtilsTest2 {
-
- @Test
- public void instantiateVduTest() throws MsoException {
- VduInstance expected = new VduInstance();
- expected.setVduInstanceId("id");
- expected.setVduInstanceName("id");
- VduStatus status = new VduStatus();
- status.setState(VduStateType.INSTANTIATED);
- status.setLastAction(new PluginAction(null, null, null));
- expected.setStatus(status);
-
- MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class);
- CloudSite site = new CloudSite();
- Optional<CloudSite> opSite = Optional.ofNullable(site);
- CloudConfig config = Mockito.mock(CloudConfig.class);
- cloudify.cloudConfig = config;
- Cloudify cloudifyClient = new Cloudify("cloudSite");
- CloudInfo cloudInfo = new CloudInfo();
- cloudInfo.setCloudSiteId("cloudSiteId");
- cloudInfo.setTenantId("tenantId");
- VduModelInfo vduModel = new VduModelInfo();
- vduModel.setModelCustomizationUUID("blueprintId");
- vduModel.setTimeoutMinutes(1);
- VduArtifact artifact = new VduArtifact();
- artifact.setName("name");
- artifact.setType(ArtifactType.MAIN_TEMPLATE);
- byte[] content = new byte[1];
- artifact.setContent(content);
- List<VduArtifact> artifacts = new ArrayList<>();
- artifacts.add(artifact);
- vduModel.setArtifacts(artifacts);
- DeploymentInfo deployment = new DeploymentInfo();
- deployment.setId("id");
- deployment.setStatus(DeploymentStatus.INSTALLED);
- Map<String, byte[]> blueprintFiles = new HashMap<>();
- blueprintFiles.put(artifact.getName(), artifact.getContent());
- String instanceName = "instanceName";
- Map<String, Object> inputs = new HashMap<>();
- boolean rollbackOnFailure = true;
-
- when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite);
- doReturn(false).when(cloudify).isBlueprintLoaded(cloudInfo.getCloudSiteId(),
- vduModel.getModelCustomizationUUID());
- doReturn(cloudifyClient).when(cloudify).getCloudifyClient(site);
- doReturn(true).when(cloudify).uploadBlueprint(cloudifyClient, vduModel.getModelCustomizationUUID(),
- artifact.getName(), blueprintFiles);
- doReturn(deployment).when(cloudify).createAndInstallDeployment(cloudInfo.getCloudSiteId(),
- cloudInfo.getTenantId(), instanceName, vduModel.getModelCustomizationUUID(), inputs, true,
- vduModel.getTimeoutMinutes(), rollbackOnFailure);
-
- VduInstance actual = cloudify.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure);
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void queryVduTest() throws MsoException {
- VduInstance expected = new VduInstance();
- expected.setVduInstanceId("id");
- expected.setVduInstanceName("id");
- VduStatus status = new VduStatus();
- status.setState(VduStateType.INSTANTIATED);
- status.setLastAction(new PluginAction(null, null, null));
- expected.setStatus(status);
-
- CloudInfo cloudInfo = new CloudInfo();
- cloudInfo.setCloudSiteId("cloudSiteId");
- cloudInfo.setTenantId("tenantId");
- DeploymentInfo deployment = new DeploymentInfo();
- deployment.setId("id");
- deployment.setStatus(DeploymentStatus.INSTALLED);
- String instanceId = "instanceId";
-
- MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class);
-
- doReturn(deployment).when(cloudify).queryDeployment(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(),
- instanceId);
-
- VduInstance actual = cloudify.queryVdu(cloudInfo, instanceId);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void deleteVduTest() throws MsoException {
- VduInstance expected = new VduInstance();
- expected.setVduInstanceId("id");
- expected.setVduInstanceName("id");
- VduStatus status = new VduStatus();
- status.setState(VduStateType.DELETING);
- status.setLastAction(new PluginAction("deleting", null, null));
- expected.setStatus(status);
-
- CloudInfo cloudInfo = new CloudInfo();
- cloudInfo.setCloudSiteId("cloudSiteId");
- cloudInfo.setTenantId("tenantId");
- String instanceId = "instanceId";
- int timeoutMinutes = 1;
- DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class);
- deployment.setId("id");
- deployment.setStatus(DeploymentStatus.CREATED);
- when(deployment.getId()).thenReturn("id");
- when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED);
- when(deployment.getLastAction()).thenReturn("deleting");
- MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class);
- doReturn(deployment).when(cloudify).uninstallAndDeleteDeployment(cloudInfo.getCloudSiteId(),
- cloudInfo.getTenantId(), instanceId, timeoutMinutes);
-
- VduInstance actual = cloudify.deleteVdu(cloudInfo, instanceId, timeoutMinutes);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void deploymentInfoToVduInstanceTest() {
- VduInstance expected = new VduInstance();
- expected.setVduInstanceId("id");
- expected.setVduInstanceName("id");
- VduStatus status = new VduStatus();
- status.setState(VduStateType.DELETING);
- status.setLastAction(new PluginAction("deleting", null, null));
- expected.setStatus(status);
-
- DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class);
- deployment.setId("id");
- deployment.setStatus(DeploymentStatus.CREATED);
- when(deployment.getId()).thenReturn("id");
- when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED);
- when(deployment.getLastAction()).thenReturn("deleting");
-
- MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
-
- VduInstance actual = cloudify.deploymentInfoToVduInstance(deployment);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void deploymentStatusToVduStatusTest() {
- VduStatus expected = new VduStatus();
- expected.setState(VduStateType.DELETING);
- expected.setLastAction(new PluginAction("deleting", null, null));
-
- DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class);
- deployment.setId("id");
- deployment.setStatus(DeploymentStatus.CREATED);
- when(deployment.getId()).thenReturn("id");
- when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED);
- when(deployment.getLastAction()).thenReturn("deleting");
-
- MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
-
- VduStatus actual = cloudify.deploymentStatusToVduStatus(deployment);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void getOpenstackConfigTest() {
- OpenstackConfig expected = new OpenstackConfig();
- expected.setRegion("regionId");
- expected.setAuthUrl("identityUrl");
- expected.setUsername("msoId");
- expected.setPassword("msoPass");
- expected.setTenantName("tenantId");
-
- MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
- CloudSite cloudSite = Mockito.mock(CloudSite.class);
- CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class);
- when(cloudSite.getIdentityService()).thenReturn(cloudIdentity);
- when(cloudSite.getRegionId()).thenReturn("regionId");
- when(cloudIdentity.getIdentityUrl()).thenReturn("identityUrl");
- when(cloudIdentity.getMsoId()).thenReturn("msoId");
- when(cloudIdentity.getMsoPass()).thenReturn("msoPass");
- String tenantId = "tenantId";
- OpenstackConfig actual = cloudify.getOpenstackConfig(cloudSite, tenantId);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void getAzureConfigTest() {
- AzureConfig expected = new AzureConfig();
- expected.setSubscriptionId("subscriptionId");
- expected.setTenantId("tenantId");
- expected.setClientId("msoId");
- expected.setClientSecret("msoPass");
-
- MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
- CloudSite cloudSite = Mockito.mock(CloudSite.class);
- CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class);
- when(cloudSite.getIdentityService()).thenReturn(cloudIdentity);
- when(cloudIdentity.getAdminTenant()).thenReturn("subscriptionId");
- when(cloudIdentity.getMsoId()).thenReturn("msoId");
- when(cloudIdentity.getMsoPass()).thenReturn("msoPass");
- String tenantId = "tenantId";
- AzureConfig actual = cloudify.getAzureConfig(cloudSite, tenantId);
-
- assertThat(actual, sameBeanAs(expected));
- }
-}
+/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.cloudify.utils; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.so.adapters.vdu.CloudInfo; +import org.onap.so.adapters.vdu.PluginAction; +import org.onap.so.adapters.vdu.VduArtifact; +import org.onap.so.adapters.vdu.VduArtifact.ArtifactType; +import org.onap.so.adapters.vdu.VduInstance; +import org.onap.so.adapters.vdu.VduModelInfo; +import org.onap.so.adapters.vdu.VduStateType; +import org.onap.so.adapters.vdu.VduStatus; +import org.onap.so.cloud.CloudConfig; +import org.onap.so.cloud.CloudIdentity; +import org.onap.so.cloud.CloudSite; +import org.onap.so.cloudify.beans.DeploymentInfo; +import org.onap.so.cloudify.beans.DeploymentStatus; +import org.onap.so.cloudify.v3.client.Cloudify; +import org.onap.so.cloudify.v3.model.AzureConfig; +import org.onap.so.cloudify.v3.model.OpenstackConfig; +import org.onap.so.openstack.exceptions.MsoException; + +public class MsoCloudifyUtilsTest2 { + + @Test + public void instantiateVduTest() throws MsoException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction(new PluginAction(null, null, null)); + expected.setStatus(status); + + MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); + CloudSite site = new CloudSite(); + Optional<CloudSite> opSite = Optional.ofNullable(site); + CloudConfig config = Mockito.mock(CloudConfig.class); + cloudify.cloudConfig = config; + Cloudify cloudifyClient = new Cloudify("cloudSite"); + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + VduModelInfo vduModel = new VduModelInfo(); + vduModel.setModelCustomizationUUID("blueprintId"); + vduModel.setTimeoutMinutes(1); + VduArtifact artifact = new VduArtifact(); + artifact.setName("name"); + artifact.setType(ArtifactType.MAIN_TEMPLATE); + byte[] content = new byte[1]; + artifact.setContent(content); + List<VduArtifact> artifacts = new ArrayList<>(); + artifacts.add(artifact); + vduModel.setArtifacts(artifacts); + DeploymentInfo deployment = new DeploymentInfo(); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.INSTALLED); + Map<String, byte[]> blueprintFiles = new HashMap<>(); + blueprintFiles.put(artifact.getName(), artifact.getContent()); + String instanceName = "instanceName"; + Map<String, Object> inputs = new HashMap<>(); + boolean rollbackOnFailure = true; + + when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite); + doReturn(false).when(cloudify).isBlueprintLoaded(cloudInfo.getCloudSiteId(), + vduModel.getModelCustomizationUUID()); + doReturn(cloudifyClient).when(cloudify).getCloudifyClient(site); + doReturn(true).when(cloudify).uploadBlueprint(cloudifyClient, vduModel.getModelCustomizationUUID(), + artifact.getName(), blueprintFiles); + doReturn(deployment).when(cloudify).createAndInstallDeployment(cloudInfo.getCloudSiteId(), + cloudInfo.getTenantId(), instanceName, vduModel.getModelCustomizationUUID(), inputs, true, + vduModel.getTimeoutMinutes(), rollbackOnFailure); + + VduInstance actual = cloudify.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure); + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void queryVduTest() throws MsoException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction(new PluginAction(null, null, null)); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + DeploymentInfo deployment = new DeploymentInfo(); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.INSTALLED); + String instanceId = "instanceId"; + + MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); + + doReturn(deployment).when(cloudify).queryDeployment(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), + instanceId); + + VduInstance actual = cloudify.queryVdu(cloudInfo, instanceId); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deleteVduTest() throws MsoException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.DELETING); + status.setLastAction(new PluginAction("deleting", null, null)); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + String instanceId = "instanceId"; + int timeoutMinutes = 1; + DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.CREATED); + when(deployment.getId()).thenReturn("id"); + when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); + when(deployment.getLastAction()).thenReturn("deleting"); + MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); + doReturn(deployment).when(cloudify).uninstallAndDeleteDeployment(cloudInfo.getCloudSiteId(), + cloudInfo.getTenantId(), instanceId, timeoutMinutes); + + VduInstance actual = cloudify.deleteVdu(cloudInfo, instanceId, timeoutMinutes); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deploymentInfoToVduInstanceTest() { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.DELETING); + status.setLastAction(new PluginAction("deleting", null, null)); + expected.setStatus(status); + + DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.CREATED); + when(deployment.getId()).thenReturn("id"); + when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); + when(deployment.getLastAction()).thenReturn("deleting"); + + MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); + + VduInstance actual = cloudify.deploymentInfoToVduInstance(deployment); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deploymentStatusToVduStatusTest() { + VduStatus expected = new VduStatus(); + expected.setState(VduStateType.DELETING); + expected.setLastAction(new PluginAction("deleting", null, null)); + + DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.CREATED); + when(deployment.getId()).thenReturn("id"); + when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); + when(deployment.getLastAction()).thenReturn("deleting"); + + MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); + + VduStatus actual = cloudify.deploymentStatusToVduStatus(deployment); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void getAzureConfigTest() { + AzureConfig expected = new AzureConfig(); + expected.setSubscriptionId("subscriptionId"); + expected.setTenantId("tenantId"); + expected.setClientId("msoId"); + expected.setClientSecret("msoPass"); + + MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); + CloudSite cloudSite = Mockito.mock(CloudSite.class); + CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class); + when(cloudSite.getIdentityService()).thenReturn(cloudIdentity); + when(cloudIdentity.getAdminTenant()).thenReturn("subscriptionId"); + when(cloudIdentity.getMsoId()).thenReturn("msoId"); + when(cloudIdentity.getMsoPass()).thenReturn("msoPass"); + String tenantId = "tenantId"; + AzureConfig actual = cloudify.getAzureConfig(cloudSite, tenantId); + + assertThat(actual, sameBeanAs(expected)); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/config/PoConfigTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/config/PoConfigTest.java new file mode 100644 index 0000000000..d347dedb4f --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/config/PoConfigTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 org.onap.so.config; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.cloud.Application; +import org.onap.so.config.beans.PoConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@ActiveProfiles("test") +public class PoConfigTest { + + + @Autowired + private PoConfig poConfig; + + + @Test + public void tenantConfigValues() { + assertEquals("504", poConfig.getRetryCodes()); + assertEquals(5, poConfig.getRetryDelay()); + + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/HeatCacheEntryTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/HeatCacheEntryTest.java new file mode 100644 index 0000000000..4adf6bf5be --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/HeatCacheEntryTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.openstack.beans; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import org.junit.Test; +import org.onap.so.BaseTest; + +public class HeatCacheEntryTest extends BaseTest { + + private static final String HEAT_URL = "testHeatUrl"; + private static final String TOKEN = "testToken"; + + @Test + public void getHeatClientTest() { + Calendar expires = new GregorianCalendar(2013,0,31); + HeatCacheEntry heatCacheEntry = new HeatCacheEntry(HEAT_URL, TOKEN, expires); + assertNotNull(heatCacheEntry.getHeatClient()); + } + + @Test + public void isExpiredTrueTest() { + Calendar expires = new GregorianCalendar(2013,0,31); + HeatCacheEntry heatCacheEntry = new HeatCacheEntry(HEAT_URL, TOKEN, expires); + assertTrue(heatCacheEntry.isExpired()); + } + + @Test + public void isExpiredFalseTest() { + Calendar expires = new GregorianCalendar(2100,0,31); + HeatCacheEntry heatCacheEntry = new HeatCacheEntry(HEAT_URL, TOKEN, expires); + assertFalse(heatCacheEntry.isExpired()); + } + + @Test + public void isExpiredNullTest() { + Calendar expires = null; + HeatCacheEntry heatCacheEntry = new HeatCacheEntry(HEAT_URL, TOKEN, expires); + assertTrue(heatCacheEntry.isExpired()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/MsoTenantTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/MsoTenantTest.java new file mode 100644 index 0000000000..379501f206 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/MsoTenantTest.java @@ -0,0 +1,42 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.openstack.beans; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class MsoTenantTest { + MsoTenant ms = new MsoTenant(); + + @Test + public void test() { + Map<String, String> map = new HashMap<>(); + map.put("id","name"); + ms.setTenantId("tenantId"); + ms.setTenantName("tenantName"); + ms.setMetadata(map); + assert(ms.getMetadata().equals(map)); + assert(ms.getTenantId().equals("tenantId")); + assert(ms.getTenantName().equals("tenantName")); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/NetworkRollbackTest.java index d70c01d0d3..5a5e2bb75e 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/NetworkRollbackTest.java @@ -1,24 +1,24 @@ /* * ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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========================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.openecomp.mso.openstack.beans; +package org.onap.so.openstack.beans; import static org.junit.Assert.*; import java.util.ArrayList; @@ -26,7 +26,7 @@ import java.util.List; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.openecomp.mso.entity.MsoRequest; +import org.onap.so.entity.MsoRequest; public class NetworkRollbackTest { @Mock diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/NeutronCacheEntryTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/NeutronCacheEntryTest.java new file mode 100644 index 0000000000..3a652042b7 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/NeutronCacheEntryTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.openstack.beans; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import org.junit.Test; +import org.onap.so.BaseTest; + +public class NeutronCacheEntryTest extends BaseTest { + + private static final String NEUTRON_URL = "testNeutronUrl"; + private static final String TOKEN = "testToken"; + + @Test + public void isExpiredTrueTest() { + Calendar expires = new GregorianCalendar(2013,0,31); + NeutronCacheEntry neutronCacheEntry = new NeutronCacheEntry(NEUTRON_URL, TOKEN, expires); + assertTrue(neutronCacheEntry.isExpired()); + } + + @Test + public void isExpiredFalseTest() { + Calendar expires = new GregorianCalendar(2100,0,31); + NeutronCacheEntry neutronCacheEntry = new NeutronCacheEntry(NEUTRON_URL, TOKEN, expires); + assertFalse(neutronCacheEntry.isExpired()); + } + + @Test + public void isExpiredNullTest() { + Calendar expires = null; + NeutronCacheEntry neutronCacheEntry = new NeutronCacheEntry(NEUTRON_URL, TOKEN, expires); + assertTrue(neutronCacheEntry.isExpired()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/OpenstackBeansPojoTest.java index 1452c1569c..522a261fdd 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/OpenstackBeansPojoTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 - 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. @@ -18,39 +18,31 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.adapters.vdu; +package org.onap.so.openstack.beans; import org.junit.Test; +import org.onap.so.BaseTest; import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.reflection.impl.PojoClassFactory; import com.openpojo.validation.Validator; import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; import com.openpojo.validation.test.impl.GetterTester; import com.openpojo.validation.test.impl.SetterTester; -public class BeansTest { - - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - +public class OpenstackBeansPojoTest extends BaseTest { @Test public void pojoStructure() { - test("org.openecomp.mso.adapters.vdu"); + test(PojoClassFactory.getPojoClass(VnfRollback.class)); + test(PojoClassFactory.getPojoClass(NeutronCacheEntry.class)); + test(PojoClassFactory.getPojoClass(HeatCacheEntry.class)); } - - private void test(String pojoPackage) { + + private void test(PojoClass pojoClass) { Validator validator = ValidatorBuilder.create() - .with(new GetterMustExistRule()) .with(new SetterTester()) .with(new GetterTester()) .build(); - validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } + validator.validate(pojoClass); } } diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/VnfRollbackTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/VnfRollbackTest.java new file mode 100644 index 0000000000..163f141c5d --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/beans/VnfRollbackTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.openstack.beans; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.so.BaseTest; +import org.onap.so.entity.MsoRequest; +import org.springframework.beans.factory.annotation.Autowired; + +public class VnfRollbackTest extends BaseTest { + @Autowired + private VnfRollback vnfRollback; + + private String vnfId = "testVnfId"; + private String tenantId = "testTenantId"; + private String cloudSiteId = "testCloudSiteId"; + private boolean tenantCreated = true; + private boolean vnfCreated = true; + private MsoRequest msoRequest = new MsoRequest(); + private String volumeGroupName = "testVolumeGroupName"; + private String volumeGroupId = "testVolumeGroupId"; + private String requestType = "testRequestType"; + private String modelCustomizationUuid = "testModelCustimizationUuid"; + private String orchestrationMode = "testOrchestrationMode"; + private static final String VNF_ROLLBACK_STRING = "VnfRollback: cloud=testCloudSiteId, tenant=testTenantId, vnf=testVnfId, " + + "tenantCreated=true, vnfCreated=true, requestType = testRequestType, modelCustomizationUuid=testModelCustimizationUuid, mode=testOrchestrationMode"; + + @Test + public void VnfRollbackInstantiationTest() { + vnfRollback = new VnfRollback(vnfId, tenantId, cloudSiteId, tenantCreated, vnfCreated, + msoRequest, volumeGroupName, volumeGroupId, requestType, modelCustomizationUuid); + + assertEquals(vnfId, vnfRollback.getVnfId()); + assertEquals(tenantId, vnfRollback.getTenantId()); + assertEquals(cloudSiteId, vnfRollback.getCloudSiteId()); + assertEquals(tenantCreated, vnfRollback.getTenantCreated()); + assertEquals(vnfCreated, vnfRollback.getVnfCreated()); + assertEquals(msoRequest, vnfRollback.getMsoRequest()); + assertEquals(volumeGroupName, vnfRollback.getVolumeGroupName()); + assertEquals(volumeGroupId, vnfRollback.getVolumeGroupId()); + assertEquals(requestType, vnfRollback.getRequestType()); + assertEquals(modelCustomizationUuid, vnfRollback.getModelCustomizationUuid()); + } + + @Test + public void VnfRollbackInstantiationOrchestrationModeTest() { + vnfRollback = new VnfRollback(vnfId, tenantId, cloudSiteId, tenantCreated, vnfCreated, + msoRequest, volumeGroupName, volumeGroupId, requestType, modelCustomizationUuid, orchestrationMode); + + assertEquals(vnfId, vnfRollback.getVnfId()); + assertEquals(tenantId, vnfRollback.getTenantId()); + assertEquals(cloudSiteId, vnfRollback.getCloudSiteId()); + assertEquals(tenantCreated, vnfRollback.getTenantCreated()); + assertEquals(vnfCreated, vnfRollback.getVnfCreated()); + assertEquals(msoRequest, vnfRollback.getMsoRequest()); + assertEquals(volumeGroupName, vnfRollback.getVolumeGroupName()); + assertEquals(volumeGroupId, vnfRollback.getVolumeGroupId()); + assertEquals(requestType, vnfRollback.getRequestType()); + assertEquals(modelCustomizationUuid, vnfRollback.getModelCustomizationUuid()); + assertEquals(orchestrationMode, vnfRollback.getMode()); + } + + @Test + public void toStringTest() { + vnfRollback = new VnfRollback(vnfId, tenantId, cloudSiteId, tenantCreated, vnfCreated, + msoRequest, volumeGroupName, volumeGroupId, requestType, modelCustomizationUuid, orchestrationMode); + + assertEquals(VNF_ROLLBACK_STRING, vnfRollback.toString()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java new file mode 100644 index 0000000000..7ac92574a0 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 org.onap.so.openstack.utils; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.so.BaseTest; +import org.onap.so.openstack.exceptions.MsoAdapterException; +import org.onap.so.openstack.exceptions.MsoException; +import org.onap.so.openstack.exceptions.MsoExceptionCategory; +import org.onap.so.openstack.exceptions.MsoIOException; +import org.onap.so.openstack.exceptions.MsoOpenstackException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.woorea.openstack.base.client.OpenStackBaseException; +import com.woorea.openstack.base.client.OpenStackConnectException; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.base.client.OpenStackResponse; +import com.woorea.openstack.base.client.OpenStackResponseException; +import com.woorea.openstack.heat.model.Explanation; +import com.woorea.openstack.keystone.model.Error; +import com.woorea.openstack.quantum.model.NeutronError; + +/** + * This class implements test methods of the MsoCommonUtils + */ +public class MsoCommonUtilsTest extends BaseTest { + @Autowired + @Qualifier("CommonUtils") + private MsoCommonUtils commonUtils; + + @Mock + private OpenStackRequest openstackRequest; + + @Test + public final void testExecuteAndRecordOpenstackRequest() { + Mockito.when(openstackRequest.endpoint()).thenReturn("localhost"); + Mockito.when(openstackRequest.path()).thenReturn("/test"); + //TODO:Must try a real connection + assertNull(commonUtils.executeAndRecordOpenstackRequest (openstackRequest)); + } + + @Test + public void testexecuteAndRecordOpenstackRequestResponseException() { + expectedException.expect(OpenStackResponseException.class); + + doThrow(OpenStackResponseException.class).when(openstackRequest).execute(); + + commonUtils.executeAndRecordOpenstackRequest(openstackRequest); + } + + @Test + public void testexecuteAndRecordOpenstackRequestConnectException() { + expectedException.expect(OpenStackConnectException.class); + + doThrow(OpenStackConnectException.class).when(openstackRequest).execute(); + + commonUtils.executeAndRecordOpenstackRequest(openstackRequest); + } + + @Test + public final void testKeystoneErrorToMsoException() throws JsonParseException, JsonMappingException, IOException { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); + + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); + + MsoException me = commonUtils.keystoneErrorToMsoException(openStackConnectException,"ContextError"); + + assertTrue(me instanceof MsoIOException); + assertTrue("connect".equals(me.getMessage())); + + + MsoException me2 = commonUtils.keystoneErrorToMsoException(openStackResponseException,"ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + + + OpenStackResponse openStackResponse = Mockito.mock(OpenStackResponse.class); + Error error = mapper.readValue(new File(RESOURCE_PATH + "Error.json"), Error.class); + + doReturn(error).when(openStackResponse).getErrorEntity(eq(Error.class)); + + openStackResponseException = new OpenStackResponseException("response", 501, openStackResponse); + + MsoException me3 = commonUtils.keystoneErrorToMsoException(openStackResponseException,"ContextError"); + + assertTrue(me3 instanceof MsoOpenstackException); + assertEquals("1 title: message", me3.toString()); + } + + @Test + public final void testHeatExceptionToMsoException() throws JsonParseException, JsonMappingException, IOException { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); + + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); + + MsoException me = commonUtils.heatExceptionToMsoException(openStackConnectException,"ContextError"); + + assertTrue(me instanceof MsoIOException); + assertTrue("connect".equals(me.getMessage())); + + + MsoException me2 = commonUtils.heatExceptionToMsoException(openStackResponseException,"ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + + + OpenStackResponse openStackResponse = Mockito.mock(OpenStackResponse.class); + Explanation explanation = mapper.readValue(new File(RESOURCE_PATH + "Explanation.json"), Explanation.class); + + doReturn(explanation).when(openStackResponse).getErrorEntity(eq(Explanation.class)); + + openStackResponseException = new OpenStackResponseException("response", 501, openStackResponse); + + MsoException me3 = commonUtils.heatExceptionToMsoException(openStackResponseException,"ContextError"); + + assertTrue(me3 instanceof MsoOpenstackException); + assertEquals("1 title: explanation, error.type=null, error.message=null", me3.toString()); + } + + @Test + public final void testNeutronExceptionToMsoException() throws JsonParseException, JsonMappingException, IOException { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); + + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); + + MsoException me = commonUtils.neutronExceptionToMsoException(openStackConnectException,"ContextError"); + + assertTrue(me instanceof MsoIOException); + assertTrue("connect".equals(me.getMessage())); + + MsoException me2 = commonUtils.neutronExceptionToMsoException(openStackResponseException,"ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + + + OpenStackResponse openStackResponse = Mockito.mock(OpenStackResponse.class); + NeutronError explanation = mapper.readValue(new File(RESOURCE_PATH + "NeutronError.json"), NeutronError.class); + + doReturn(explanation).when(openStackResponse).getErrorEntity(eq(NeutronError.class)); + + openStackResponseException = new OpenStackResponseException("response", 501, openStackResponse); + + MsoException me3 = commonUtils.neutronExceptionToMsoException(openStackResponseException,"ContextError"); + + assertTrue(me3 instanceof MsoOpenstackException); + assertEquals("501 type: message", me3.toString()); + } + + @Test + public final void testRuntimeExceptionToMsoException() { + RuntimeException re = new RuntimeException("runtime"); + MsoException me = commonUtils.runtimeExceptionToMsoException(re, "ContextError"); + + assertTrue(me instanceof MsoAdapterException); + assertTrue("ContextError".equals(me.getContext())); + assertTrue(MsoExceptionCategory.INTERNAL.equals(me.getCategory())); + } + + @Test + public void testIoExceptionToMsoException() { + IOException exception = new IOException("IOExceptionTestMessage"); + + MsoException msoException = commonUtils.ioExceptionToMsoException(exception, "ContextError"); + + assertTrue(msoException instanceof MsoAdapterException); + assertEquals("ContextError", msoException.getContext()); + assertTrue(MsoExceptionCategory.INTERNAL.equals(msoException.getCategory())); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntryTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntryTest.java index 668bc68a3d..700d03dad3 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntryTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntryTest.java @@ -7,9 +7,9 @@ * 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. @@ -18,13 +18,27 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.openstack.utils; +package org.onap.so.openstack.utils; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; import org.junit.Test; +import org.onap.so.TestDataSetup; +import org.onap.so.db.catalog.beans.HeatTemplateParam; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; -public class MsoHeatEnvironmentEntryTest { +public class MsoHeatEnvironmentEntryTest extends TestDataSetup { private static final String PARAMETER_NAME = "keyTest"; private static final String VALUE_NAME = "valueTest"; @@ -43,13 +57,36 @@ public class MsoHeatEnvironmentEntryTest { } @Test - public void toFullString_ResourceRegistryNotPresentInRawEntry() { + public void toFullString_ResourceRegistryNotPresentInRawEntry() throws JsonParseException, JsonMappingException, IOException { StringBuilder sb = new StringBuilder(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY); + MsoHeatEnvironmentEntry testedObject = new MsoHeatEnvironmentEntry(sb); + + HeatTemplateParam heatTemplateParam = mapper.readValue(new File(RESOURCE_PATH + "HeatTemplateParam.json"), HeatTemplateParam.class); + assertThat(testedObject.getRawEntry()).isEqualTo(sb); assertThat(testedObject.isValid()).isTrue(); assertThat(testedObject.containsParameter(PARAMETER_NAME)).isTrue(); assertThat(testedObject.toString()).doesNotContain(RAW_ENTRY_WITH_RESOURCE_REGISTRY); + assertTrue(testedObject.containsParameter(PARAMETER_NAME, "dummyAlias")); + assertTrue(testedObject.containsParameter("dummyName", PARAMETER_NAME)); + assertFalse(testedObject.containsParameter("dummyName", "dummyAlias")); + assertEquals("parameters:\n " + PARAMETER_NAME + ": " + VALUE_NAME + "\n\n\n", testedObject.toFullString().toString()); + assertEquals("parameters:\n " + PARAMETER_NAME + ": " + VALUE_NAME + "\n\n\n", testedObject.toFullStringExcludeNonParams(new HashSet<HeatTemplateParam>(Arrays.asList(heatTemplateParam))).toString()); + assertEquals(1, testedObject.getNumberOfParameters()); + assertFalse(testedObject.hasResources()); + + MsoHeatEnvironmentResource heatResource = new MsoHeatEnvironmentResource("resourceName", "resourceValue"); + MsoHeatEnvironmentParameter heatParameter = new MsoHeatEnvironmentParameter("parameterName", "parameterValue"); + testedObject.addResource(heatResource); + testedObject.addParameter(heatParameter); + assertEquals(1, testedObject.getNumberOfResources()); + assertEquals(2, testedObject.getNumberOfParameters()); + + testedObject.setResources(null); + testedObject.setParameters(null); + assertNull(testedObject.getParameters()); + assertNull(testedObject.getResources()); } @Test diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentParameterTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentParameterTest.java new file mode 100644 index 0000000000..182a6d0e02 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentParameterTest.java @@ -0,0 +1,46 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.openstack.utils; + +import static org.mockito.Mockito.mock; + +import org.junit.Test; + +public class MsoHeatEnvironmentParameterTest { + + @Test + public void test() { + MsoHeatEnvironmentParameter hep=mock(MsoHeatEnvironmentParameter.class); + Object op=hep.getName(); + MsoHeatEnvironmentParameter meo=new MsoHeatEnvironmentParameter(); + MsoHeatEnvironmentParameter mea=new MsoHeatEnvironmentParameter("name"); + MsoHeatEnvironmentParameter mep=new MsoHeatEnvironmentParameter("name"," value"); + mea.setName("name"); + mep.setValue("value"); + assert(mea.getName().equals("name")); + assert(mep.getValue().equals("value")); + assert(meo.toString()!=null); + //assertTrue(op.equals(hep)); + meo.equals(op); + meo.hashCode(); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentResourceTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentResourceTest.java new file mode 100644 index 0000000000..934c149055 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatEnvironmentResourceTest.java @@ -0,0 +1,49 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.openstack.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class MsoHeatEnvironmentResourceTest { + @Test + public void test() { + Object op = true; + + MsoHeatEnvironmentResource mre = new MsoHeatEnvironmentResource("name"); + MsoHeatEnvironmentResource mae = new MsoHeatEnvironmentResource("name", "maeValue"); + MsoHeatEnvironmentResource msoHER = new MsoHeatEnvironmentResource(); + + msoHER.setName("msoHERName"); + msoHER.setValue("msoHERValue"); + + assertEquals("name", mre.getName()); + assertEquals("maeValue", mae.getValue()); + assertEquals("\"msoHERName\": msoHERValue", msoHER.toString()); + assertEquals("\"name\": maeValue", mae.toString()); + assertFalse(mae.equals(op)); + assertTrue(mae.equals(mre)); + assertEquals("name".hashCode(), mae.hashCode()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java new file mode 100644 index 0000000000..6bcb209125 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.openstack.utils; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.woorea.openstack.heat.model.CreateStackParam; +import org.apache.http.HttpStatus; +import org.junit.Assert; +import org.junit.Test; +import org.onap.so.BaseTest; +import org.onap.so.StubOpenStack; +import org.onap.so.adapters.vdu.CloudInfo; +import org.onap.so.adapters.vdu.PluginAction; +import org.onap.so.adapters.vdu.VduArtifact; +import org.onap.so.adapters.vdu.VduArtifact.ArtifactType; +import org.onap.so.adapters.vdu.VduInstance; +import org.onap.so.adapters.vdu.VduModelInfo; +import org.onap.so.adapters.vdu.VduStateType; +import org.onap.so.adapters.vdu.VduStatus; +import org.onap.so.openstack.exceptions.MsoException; + +import org.springframework.beans.factory.annotation.Autowired; + +public class MsoHeatUtilsTest extends BaseTest{ + + @Autowired + private MsoHeatUtils heatUtils; + + @Test + public void instantiateVduTest() throws MsoException, IOException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("name/da886914-efb2-4917-b335-c8381528d90b"); + expected.setVduInstanceName("name"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction((new PluginAction("create", "complete", null))); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("regionOne"); + cloudInfo.setTenantId("tenantId"); + VduModelInfo vduModel = new VduModelInfo(); + vduModel.setModelCustomizationUUID("blueprintId"); + vduModel.setTimeoutMinutes(1); + VduArtifact artifact = new VduArtifact(); + artifact.setName("name"); + artifact.setType(ArtifactType.MAIN_TEMPLATE); + byte[] content = new byte[1]; + artifact.setContent(content); + List<VduArtifact> artifacts = new ArrayList<>(); + artifacts.add(artifact); + vduModel.setArtifacts(artifacts); + Map<String, byte[]> blueprintFiles = new HashMap<>(); + blueprintFiles.put(artifact.getName(), artifact.getContent()); + String instanceName = "instanceName"; + Map<String, Object> inputs = new HashMap<>(); + boolean rollbackOnFailure = true; + + StubOpenStack.mockOpenStackResponseAccess(wireMockPort); + StubOpenStack.mockOpenStackPostStack_200("OpenstackResponse_Stack_Created.json"); + + stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceName/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_StackId.json") + .withStatus(HttpStatus.SC_OK))); + + VduInstance actual = heatUtils.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure); + + assertThat(actual, sameBeanAs(expected)); + } + + + @Test + public void queryVduTest() throws Exception { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("name/da886914-efb2-4917-b335-c8381528d90b"); + expected.setVduInstanceName("name"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction((new PluginAction("create", "complete",null))); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("regionOne"); + cloudInfo.setTenantId("tenantId"); + String instanceId = "instanceId"; + + StubOpenStack.mockOpenStackResponseAccess(wireMockPort); + StubOpenStack.mockOpenStackPostStack_200("OpenstackResponse_Stack_Created.json"); + + stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_StackId.json") + .withStatus(HttpStatus.SC_OK))); + + VduInstance actual = heatUtils.queryVdu(cloudInfo, instanceId); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deleteVduTest() throws Exception { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("instanceId"); + expected.setVduInstanceName("instanceId"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.DELETED); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("regionOne"); + cloudInfo.setTenantId("tenantId"); + String instanceId = "instanceId"; + + int timeoutInMinutes = 1; + + StubOpenStack.mockOpenStackResponseAccess(wireMockPort); + stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/instanceId")).willReturn(aResponse().withBodyFile("OpenstackResponse_StackId.json").withStatus(HttpStatus.SC_OK))); + StubOpenStack.mockOpenStackDelete("name/da886914-efb2-4917-b335-c8381528d90b"); + stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/name/da886914-efb2-4917-b335-c8381528d90b")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_DeleteComplete.json").withStatus(HttpStatus.SC_OK))); + + VduInstance actual = heatUtils.deleteVdu(cloudInfo, instanceId, timeoutInMinutes); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public final void requestToStringBuilderTest() { + CreateStackParam param = new CreateStackParam(); + param.setDisableRollback(false); + param.setEnvironment("environment"); + param.setFiles(new HashMap<String, Object>()); + param.setParameters(new HashMap<>()); + param.setStackName("stackName"); + param.setTemplate("template"); + param.setTemplateUrl("http://templateUrl"); + param.setTimeoutMinutes(1); + + StringBuilder stringBuilder = heatUtils.requestToStringBuilder(param); + + Assert.assertTrue(stringBuilder.toString().contains("StackName:")); + } + + @Test + public final void copyBaseOutputsToInputsTest() { + Map<String, Object> inputs = new HashMap<>(); + inputs.put("str1", "str"); + Map<String, Object> otherStackOutputs = new HashMap<>(); + otherStackOutputs.put("str", "str"); + List<String> paramNames = new ArrayList<>(); + Map<String, String> aliases = new HashMap<>(); + aliases.put("str", "str"); + heatUtils.copyBaseOutputsToInputs(inputs, otherStackOutputs, null, aliases); + Assert.assertEquals("str",otherStackOutputs.get("str")); + } + + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsWithUpdateTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsWithUpdateTest.java new file mode 100644 index 0000000000..c252f61e7f --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsWithUpdateTest.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.openstack.utils; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.TestDataSetup; +import org.onap.so.cloud.CloudConfig; +import org.onap.so.cloud.CloudSite; +import org.onap.so.openstack.beans.HeatStatus; +import org.onap.so.openstack.beans.StackInfo; +import org.onap.so.openstack.exceptions.MsoException; +import org.springframework.core.env.Environment; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.heat.Heat; +import com.woorea.openstack.heat.StackResource; +import com.woorea.openstack.heat.StackResource.UpdateStack; +import com.woorea.openstack.heat.model.Stack; +import com.woorea.openstack.heat.model.UpdateStackParam; + +@RunWith(MockitoJUnitRunner.class) +public class MsoHeatUtilsWithUpdateTest extends TestDataSetup { + @Mock + private CloudConfig cloudConfig; + + @Mock + private Environment environment; + + @Spy + @InjectMocks + private MsoHeatUtilsWithUpdate heatUtils; + + private String cloudSiteId; + private String tenantId; + private String stackName; + private String heatTemplate; + private Map<String, Object> stackInputs; + private boolean pollForCompletion; + private int timeoutMinutes; + + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + cloudSiteId = "cloudSiteId"; + tenantId = "tenantId"; + stackName = "stackName"; + heatTemplate = "heatTemplate"; + stackInputs = new HashMap<>(); + pollForCompletion = true; + timeoutMinutes = 0; + } + + @Test + public void updateStackTest() throws MsoException, JsonParseException, JsonMappingException, IOException { + CloudSite cloudSite = mapper.readValue(new File(RESOURCE_PATH + "CloudSite.json"), CloudSite.class); + Heat heatClient = new Heat("endpoint"); + Stack heatStack = mapper.readValue(new File(RESOURCE_PATH + "HeatStack.json"), Stack.class); + Stack updateStack = mapper.readValue(new File(RESOURCE_PATH + "UpdateStack.json"), Stack.class); + + StackInfo expectedStackInfo = new StackInfo("stackName", HeatStatus.UPDATED, "stackStatusReason", null); + expectedStackInfo.setCanonicalName("stackName/id"); + + doReturn(Optional.of(cloudSite)).when(cloudConfig).getCloudSite(isA(String.class)); + doReturn(heatClient).when(heatUtils).getHeatClient(isA(CloudSite.class), isA(String.class)); + doReturn(heatStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class)); + doReturn(null).when(heatUtils).executeAndRecordOpenstackRequest(isA(OpenStackRequest.class)); + doReturn("0").when(environment).getProperty(isA(String.class), isA(String.class)); + doReturn(updateStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class)); + + StackInfo actualStackInfo = heatUtils.updateStack(cloudSiteId, tenantId, stackName, + heatTemplate, stackInputs, pollForCompletion, timeoutMinutes); + + assertThat(actualStackInfo, sameBeanAs(expectedStackInfo)); + } + + @Test + public void updateStackWithEnvironmentTest() throws JsonParseException, JsonMappingException, IOException, MsoException { + String environmentString = "environmentString"; + + CloudSite cloudSite = mapper.readValue(new File(RESOURCE_PATH + "CloudSite.json"), CloudSite.class); + Heat heatClient = new Heat("endpoint"); + Stack heatStack = mapper.readValue(new File(RESOURCE_PATH + "HeatStack.json"), Stack.class); + Stack updateStack = mapper.readValue(new File(RESOURCE_PATH + "UpdateStack.json"), Stack.class); + + StackInfo expectedStackInfo = new StackInfo("stackName", HeatStatus.UPDATED, "stackStatusReason", null); + expectedStackInfo.setCanonicalName("stackName/id"); + + doReturn(Optional.of(cloudSite)).when(cloudConfig).getCloudSite(isA(String.class)); + doReturn(heatClient).when(heatUtils).getHeatClient(isA(CloudSite.class), isA(String.class)); + doReturn(heatStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class)); + doReturn(null).when(heatUtils).executeAndRecordOpenstackRequest(isA(OpenStackRequest.class)); + doReturn("0").when(environment).getProperty(isA(String.class), isA(String.class)); + doReturn(updateStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class)); + + StackInfo actualStackInfo = heatUtils.updateStack(cloudSiteId, tenantId, stackName, + heatTemplate, stackInputs, pollForCompletion, timeoutMinutes, environmentString); + + assertThat(actualStackInfo, sameBeanAs(expectedStackInfo)); + } + + @Test + public void updateStackWithFilesTest() throws MsoException, JsonParseException, JsonMappingException, IOException { + String environmentString = "environmentString"; + Map<String, Object> files = new HashMap<>(); + files.put("file1", new Object()); + + CloudSite cloudSite = mapper.readValue(new File(RESOURCE_PATH + "CloudSite.json"), CloudSite.class); + Heat heatClient = new Heat("endpoint"); + Stack heatStack = mapper.readValue(new File(RESOURCE_PATH + "HeatStack.json"), Stack.class); + Stack updateStack = mapper.readValue(new File(RESOURCE_PATH + "UpdateStack.json"), Stack.class); + + StackInfo expectedStackInfo = new StackInfo("stackName", HeatStatus.UPDATED, "stackStatusReason", null); + expectedStackInfo.setCanonicalName("stackName/id"); + + doReturn(Optional.of(cloudSite)).when(cloudConfig).getCloudSite(isA(String.class)); + doReturn(heatClient).when(heatUtils).getHeatClient(isA(CloudSite.class), isA(String.class)); + doReturn(heatStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class)); + doReturn(null).when(heatUtils).executeAndRecordOpenstackRequest(isA(OpenStackRequest.class)); + doReturn("0").when(environment).getProperty(isA(String.class), isA(String.class)); + doReturn(updateStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class)); + + StackInfo actualStackInfo = heatUtils.updateStack(cloudSiteId, tenantId, stackName, + heatTemplate, stackInputs, pollForCompletion, timeoutMinutes , environmentString, files); + + assertThat(actualStackInfo, sameBeanAs(expectedStackInfo)); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java new file mode 100644 index 0000000000..706427e985 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoKeystoneUtilsTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.openstack.utils; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.BaseTest; +import org.onap.so.StubOpenStack; +import org.onap.so.openstack.beans.MsoTenant; +import org.onap.so.openstack.exceptions.MsoException; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.IOException; +import java.util.HashMap; + +public class MsoKeystoneUtilsTest extends BaseTest { + + @Autowired + private MsoKeystoneUtils msoKeystoneUtils; + + @Before + public void before() throws IOException { + StubOpenStack.mockOpenStackResponseAccess(wireMockPort); + } + + @Test + public void createTenantTest() throws Exception { + StubOpenStack.mockOpenStackPostTenantWithBodyFile_200(); + + StubOpenStack.mockOpenStackGetUserById("john"); + StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM"); + String response = msoKeystoneUtils.createTenant("tenant", "regionOne", new HashMap<>(), true); + + Assert.assertEquals("tenantId", response); + } + + @Test + public void createTenantTest_FindUserByName() throws Exception { + StubOpenStack.mockOpenStackPostTenantWithBodyFile_200(); + + StubOpenStack.mockOpenStackGetUserByName("john"); + StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM"); + String response = msoKeystoneUtils.createTenant("tenant", "regionOne", new HashMap<>(), true); + Assert.assertEquals("tenantId", response); + + } + + @Test + public void createTenantTest_Exception() throws Exception { + expectedException.expect(MsoException.class); + StubOpenStack.mockOpenStackPostTenantWithBodyFile_200(); + StubOpenStack.mockOpenStackGetUserByName_500("john"); + StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM"); + msoKeystoneUtils.createTenant("tenant", "regionOne", new HashMap<>(), true); + } + + @Test + public void queryTenantTest() throws Exception { + StubOpenStack.mockOpenStackGetTenantById("tenantId"); + + MsoTenant msoTenant = msoKeystoneUtils.queryTenant("tenantId", "regionOne"); + + Assert.assertEquals("testingTenantName", msoTenant.getTenantName()); + } + + @Test + public void queryTenantByNameTest() throws Exception { + StubOpenStack.mockOpenStackGetTenantByName("tenant"); + + MsoTenant msoTenant = msoKeystoneUtils.queryTenantByName("tenant", "regionOne"); + + Assert.assertEquals("testingTenantName", msoTenant.getTenantName()); + } + + @Test + public void deleteTenantTest() throws Exception { + StubOpenStack.mockOpenStackGetTenantById("tenantId"); + StubOpenStack.mockOpenStackDeleteTenantById_200("tenantId"); + boolean result = msoKeystoneUtils.deleteTenant("tenantId", "regionOne"); + + Assert.assertTrue(result); + } + + @Test + public void deleteTenantByNameTest() throws Exception { + StubOpenStack.mockOpenStackGetTenantByName("tenant"); + StubOpenStack.mockOpenStackDeleteTenantById_200("tenantId"); + boolean result = msoKeystoneUtils.deleteTenantByName("tenant", "regionOne"); + + Assert.assertTrue(result); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java new file mode 100644 index 0000000000..9f8b51a3b7 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoNeutronUtilsTest.java @@ -0,0 +1,125 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.openstack.utils; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.BaseTest; +import org.onap.so.StubOpenStack; +import org.onap.so.openstack.beans.NetworkInfo; +import org.onap.so.openstack.exceptions.MsoException; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class MsoNeutronUtilsTest extends BaseTest{ + + @Autowired + private MsoNeutronUtils msoNeutronUtils; + + private List<Integer> vlans; + + @Before + public void before() throws IOException { + vlans = new ArrayList<>(); + vlans.add(3014); + StubOpenStack.mockOpenStackResponseAccess(wireMockPort); + } + + @Test + public void createNetworkTest_OpenStackBaseException() throws Exception { + expectedException.expect(MsoException.class); + msoNeutronUtils.createNetwork("regionOne", "tenantId", + MsoNeutronUtils.NetworkType.PROVIDER,"networkName", "PROVIDER", vlans); + } + + @Test + public void createNetworkTest_NetworkTypeAsMultiProvider() throws Exception { + StubOpenStack.mockOpenstackPostNetwork("OpenstackCreateNeutronNetworkResponse.json"); + NetworkInfo networkInfo = msoNeutronUtils.createNetwork("regionOne", "tenantId", + MsoNeutronUtils.NetworkType.MULTI_PROVIDER,"networkName","PROVIDER", vlans); + + Assert.assertEquals("2a4017ef-31ff-496a-9294-e96ecc3bc9c9",networkInfo.getId()); + } + + @Test + public void createNetworkTest() throws Exception { + StubOpenStack.mockOpenstackPostNetwork("OpenstackCreateNeutronNetworkResponse.json"); + NetworkInfo networkInfo = msoNeutronUtils.createNetwork("regionOne", "tenantId", + MsoNeutronUtils.NetworkType.PROVIDER,"networkName","PROVIDER", vlans); + + Assert.assertEquals("2a4017ef-31ff-496a-9294-e96ecc3bc9c9",networkInfo.getId()); + } + + @Test + public void queryNetworkTest() throws Exception { + StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + NetworkInfo networkInfo = msoNeutronUtils.queryNetwork("43173f6a-d699-414b-888f-ab243dda6dfe", "tenantId","regionOne"); + + Assert.assertEquals("net1",networkInfo.getName()); + } + + @Test + public void queryNetworkTest_404() throws Exception { + NetworkInfo networkInfo = msoNeutronUtils.queryNetwork("43173f6a-d699-414b-888f-ab243dda6dfe", "tenantId","regionOne"); + Assert.assertNull(networkInfo); + } + + @Test + public void queryNetworkTest_500() throws Exception { + expectedException.expect(MsoException.class); + StubOpenStack.mockOpenStackGetNeutronNetwork_500("43173f6a-d699-414b-888f-ab243dda6dfe"); + msoNeutronUtils.queryNetwork("43173f6a-d699-414b-888f-ab243dda6dfe", "tenantId","regionOne"); + + } + + @Test + public void deleteNetworkkTest() throws Exception { + StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + StubOpenStack.mockOpenStackDeleteNeutronNetwork("43173f6a-d699-414b-888f-ab243dda6dfe"); + Boolean result = msoNeutronUtils.deleteNetwork("43173f6a-d699-414b-888f-ab243dda6dfe", "tenantId","regionOne"); + + Assert.assertTrue(result); + } + + @Test + public void updateNetworkTest() throws Exception { + StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + StubOpenStack.mockOpenstackPutNetwork("OpenstackCreateNeutronNetworkResponse.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + NetworkInfo networkInfo = msoNeutronUtils.updateNetwork("regionOne", "tenantId", + "43173f6a-d699-414b-888f-ab243dda6dfe",MsoNeutronUtils.NetworkType.PROVIDER,"PROVIDER", vlans); + + Assert.assertEquals("2a4017ef-31ff-496a-9294-e96ecc3bc9c9",networkInfo.getId()); + } + + @Test + public void updateNetworkTest_NetworkTypeAsMultiProvider() throws Exception { + StubOpenStack.mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + StubOpenStack.mockOpenstackPutNetwork("OpenstackCreateNeutronNetworkResponse.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + NetworkInfo networkInfo = msoNeutronUtils.updateNetwork("regionOne", "tenantId", + "43173f6a-d699-414b-888f-ab243dda6dfe",MsoNeutronUtils.NetworkType.MULTI_PROVIDER,"PROVIDER", vlans); + + Assert.assertEquals("2a4017ef-31ff-496a-9294-e96ecc3bc9c9",networkInfo.getId()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoYamlEditorWithEnvtTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoYamlEditorWithEnvtTest.java new file mode 100644 index 0000000000..70b5f2699d --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoYamlEditorWithEnvtTest.java @@ -0,0 +1,95 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * 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.so.openstack.utils; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertNull; + +import java.io.File; +import java.io.IOException; +import java.util.Set; + +import org.junit.Test; +import org.onap.so.TestDataSetup; +import org.onap.so.db.catalog.beans.HeatTemplateParam; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + +public class MsoYamlEditorWithEnvtTest extends TestDataSetup { + private MsoYamlEditorWithEnvt yaml; + private static final String PARAMETER_NAME = "keyTest"; + private static final String PARAMETER_VALUE = "{type : paramType}"; + private static final String RESOURCE_NAME = "resourceKey"; + private static final String RESOURCE_VALUE = "resourceValue"; + private static final String RAW_ENTRY_WITH_RESOURCE_REGISTRY = "resource_registry: {" + RESOURCE_NAME + " : " + RESOURCE_VALUE + "}"; + private static final String RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY = "parameters: {" + + PARAMETER_NAME + ": " + PARAMETER_VALUE + "}"; + + @Test + public void getParameterListTest() throws JsonParseException, JsonMappingException, IOException { + yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY.getBytes()); + + MsoHeatEnvironmentParameter expectedHeatParam = mapper.readValue(new File(RESOURCE_PATH + "HeatEnvironmentParameter.json"), MsoHeatEnvironmentParameter.class); + + Set<MsoHeatEnvironmentParameter> heatEnvironmentSet = yaml.getParameterListFromEnvt(); + + for(MsoHeatEnvironmentParameter heatEnvironment : heatEnvironmentSet) { + assertThat(heatEnvironment, sameBeanAs(expectedHeatParam)); + } + } + + @Test + public void getResourceListFromEnvtTest() { + yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_RESOURCE_REGISTRY.getBytes()); + + MsoHeatEnvironmentResource expectedHeatResource = new MsoHeatEnvironmentResource(RESOURCE_NAME, RESOURCE_VALUE); + + Set<MsoHeatEnvironmentResource> heatResourceSet = yaml.getResourceListFromEnvt(); + + for(MsoHeatEnvironmentResource heatResource : heatResourceSet) { + assertThat(heatResource, sameBeanAs(expectedHeatResource)); + } + } + + @Test + public void getResourceListFromEnvtExceptionTest() { + yaml = new MsoYamlEditorWithEnvt(); + + Set<MsoHeatEnvironmentResource> heatResourceSet = yaml.getResourceListFromEnvt(); + + assertNull(heatResourceSet); + } + + @Test + public void getParameterListFromEnvtTest() throws JsonParseException, JsonMappingException, IOException { + yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY.getBytes()); + + HeatTemplateParam expectedHeatParam = mapper.readValue(new File(RESOURCE_PATH + "HeatTemplateParamExpected.json"), HeatTemplateParam.class); + + Set<HeatTemplateParam> heatParamSet = yaml.getParameterList(); + + for(HeatTemplateParam heatParam : heatParamSet) { + assertThat(heatParam, sameBeanAs(expectedHeatParam)); + } + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java deleted file mode 100644 index 250211845f..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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 org.openecomp.mso.adapter_utils.tests;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.junit.Test;
-import org.openecomp.mso.entity.MsoRequest;
-import org.openecomp.mso.openstack.beans.MsoTenant;
-import org.openecomp.mso.openstack.beans.NetworkRollback;
-import org.openecomp.mso.openstack.beans.Pool;
-import org.openecomp.mso.openstack.beans.Subnet;
-import org.openecomp.mso.openstack.beans.VnfRollback;
-
-public class AdapterBeansTest {
- @Test
- public final void msoTenantTest() {
- MsoTenant tenant = new MsoTenant();
- tenant.setTenantId("1");
- assertTrue(tenant.getTenantId().equalsIgnoreCase("1"));
- tenant.setTenantName("TenantName");
- assertTrue(tenant.getTenantName().equalsIgnoreCase("TenantName"));
- Map<String, String> hm = new HashMap<>();
- hm.put("Key1", "value1");
- tenant.setMetadata(hm);
- assertTrue(tenant.getMetadata() != null);
- new MsoTenant("1", "TenantName", hm);
- // assertTrue(tenant.toString() != null);
- }
-
- @Test
- public final void networkRollbackTest() {
- NetworkRollback networkRollback = new NetworkRollback();
- networkRollback.setCloudId("cloudId");
- assertTrue(networkRollback.getCloudId().equalsIgnoreCase("cloudId"));
- networkRollback.setModelCustomizationUuid("modelCustomizationUuid");
- assertTrue(networkRollback.getModelCustomizationUuid().equalsIgnoreCase("modelCustomizationUuid"));
- MsoRequest msoRequest = new MsoRequest();
- networkRollback.setMsoRequest(msoRequest);
- networkRollback.getMsoRequest();
- // assertTrue(networkRollback.getMsoRequest() == null);
- networkRollback.setNetworkCreated(Boolean.TRUE);
- assertTrue(networkRollback.getNetworkCreated());
- networkRollback.setNetworkId("networkId");
- assertTrue(networkRollback.getNetworkId().equalsIgnoreCase("networkId"));
- networkRollback.setNetworkName("networkName");
- assertTrue(networkRollback.getNetworkName().equalsIgnoreCase("networkName"));
- networkRollback.setNetworkStackId("networkStackId");
- assertTrue(networkRollback.getNetworkStackId().equalsIgnoreCase("networkStackId"));
- networkRollback.setNetworkType("networkType");
- assertTrue(networkRollback.getNetworkType().equalsIgnoreCase("networkType"));
- networkRollback.setNeutronNetworkId("neutronNetworkId");
- assertTrue(networkRollback.getNeutronNetworkId().equalsIgnoreCase("neutronNetworkId"));
- networkRollback.setPhysicalNetwork("physicalNetwork");
- assertTrue(networkRollback.getPhysicalNetwork().equalsIgnoreCase("physicalNetwork"));
- networkRollback.setTenantId("tenantId");
- assertTrue(networkRollback.getTenantId().equalsIgnoreCase("tenantId"));
- List<Integer> al = new ArrayList<>();
- al.add(1);
- al.add(2);
- networkRollback.setVlans(al);
- assertTrue(networkRollback.getVlans() != null);
- assertTrue(networkRollback.toString() != null);
- }
-
- @Test
- public final void poolTest() {
- Pool p = new Pool();
- p.setStart("start");
- p.getStart();
- p.setEnd("end");
- p.getEnd();
- p.toString();
- }
-
- @Test
- public final void subnetTest() {
- Subnet subnet = new Subnet();
- subnet.setAllocationPools(new ArrayList<>());
- subnet.getAllocationPools();
- subnet.setCidr("cidr");
- subnet.getCidr();
- subnet.setDnsNameServers(new ArrayList<>());
- subnet.getDnsNameServers();
- subnet.setEnableDHCP(true);
- subnet.getEnableDHCP();
- subnet.setGatewayIp("gatewayIp");
- subnet.getGatewayIp();
- subnet.setHostRoutes(new ArrayList<>());
- subnet.getHostRoutes();
- subnet.setIpVersion("ipVersion");
- subnet.getIpVersion();
- subnet.setNeutronId("neutronId");
- subnet.getNeutronId();
- subnet.setSubnetId("subnetId");
- subnet.getSubnetId();
- subnet.setSubnetName("subnetName");
- subnet.getSubnetName();
- subnet.toString();
- }
-
- @Test
- public final void vnfRollbackTest() {
- VnfRollback vnfRollback = new VnfRollback();
- new VnfRollback("vnfId", "tenantId", "cloudSiteId", true, true, new MsoRequest(), "volumeGroupName",
- "volumeGroupId", "requestType", "modelCustomizationUuid");
- vnfRollback.setBaseGroupHeatStackId("baseGroupHeatStackId");
- vnfRollback.getBaseGroupHeatStackId();
- vnfRollback.setCloudSiteId("cloudId");
- vnfRollback.getCloudSiteId();
- vnfRollback.setIsBase(false);
- vnfRollback.isBase();
- vnfRollback.setModelCustomizationUuid("modelCustomizationUuid");
- vnfRollback.getModelCustomizationUuid();
- vnfRollback.setMsoRequest(new MsoRequest());
- vnfRollback.getMsoRequest();
- vnfRollback.setRequestType("requestType");
- vnfRollback.getRequestType();
- vnfRollback.setTenantCreated(true);
- vnfRollback.getTenantCreated();
- vnfRollback.setTenantId("tenantId");
- vnfRollback.getTenantId();
- vnfRollback.setVfModuleStackId("vfModuleStackId");
- vnfRollback.getVfModuleStackId();
- vnfRollback.setVnfCreated(true);
- vnfRollback.getVnfCreated();
- vnfRollback.setVnfId("vnfId");
- vnfRollback.getVnfId();
- vnfRollback.setVolumeGroupHeatStackId("volumeGroupHeatStackId");
- vnfRollback.getVolumeGroupHeatStackId();
- vnfRollback.setVolumeGroupId("volumeGroupId");
- vnfRollback.getVolumeGroupId();
- vnfRollback.setVolumeGroupName("volumeGroupName");
- vnfRollback.getVolumeGroupName();
- vnfRollback.toString();
- }
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java deleted file mode 100644 index 73bd67723d..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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 org.openecomp.mso.adapter_utils.tests; - - -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.mockito.Mockito; - -import org.openecomp.mso.logger.MsoAlarmLogger; -import org.openecomp.mso.openstack.exceptions.MsoAdapterException; -import org.openecomp.mso.openstack.exceptions.MsoException; -import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory; -import org.openecomp.mso.openstack.exceptions.MsoIOException; -import org.openecomp.mso.openstack.exceptions.MsoOpenstackException; -import org.openecomp.mso.openstack.utils.MsoCommonUtils; -import org.openecomp.mso.properties.MsoJavaProperties; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.properties.MsoPropertiesFactory; -import com.woorea.openstack.base.client.OpenStackBaseException; -import com.woorea.openstack.base.client.OpenStackConnectException; -import com.woorea.openstack.base.client.OpenStackRequest; -import com.woorea.openstack.base.client.OpenStackResponseException; - - -/** - * This class implements test methods of the MsoCommonUtils - * - * - */ -public class MsoCommonUtilsTest extends MsoCommonUtils { - - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - - @Test - public final void testExecuteAndRecordOpenstackRequest () { - OpenStackRequest openstackRequest = Mockito.mock(OpenStackRequest.class); - Mockito.when(openstackRequest.endpoint()).thenReturn("localhost"); - Mockito.when(openstackRequest.path()).thenReturn("/test"); - //TODO:Must try a real connection - assertNull(super.executeAndRecordOpenstackRequest (openstackRequest)); - - } - - @Test - public final void testKeystoneErrorToMsoException () { - OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); - - OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); - - MsoException me = super.keystoneErrorToMsoException (openStackConnectException,"ContextError"); - - assertTrue(me instanceof MsoIOException); - assertTrue("connect".equals(me.getMessage())); - - - MsoException me2 = super.keystoneErrorToMsoException (openStackResponseException,"ContextError"); - assertTrue(me2 instanceof MsoOpenstackException); - assertTrue("ContextError".equals(me2.getContext())); - assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); - - } - - @Test - public final void testHeatExceptionToMsoException () { - OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); - - OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); - - MsoException me = super.heatExceptionToMsoException (openStackConnectException,"ContextError"); - - assertTrue(me instanceof MsoIOException); - assertTrue("connect".equals(me.getMessage())); - - - MsoException me2 = super.heatExceptionToMsoException (openStackResponseException,"ContextError"); - assertTrue(me2 instanceof MsoOpenstackException); - assertTrue("ContextError".equals(me2.getContext())); - assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); - } - - @Test - public final void testNeutronExceptionToMsoException () { - OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); - - OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); - - MsoException me = super.neutronExceptionToMsoException (openStackConnectException,"ContextError"); - - assertTrue(me instanceof MsoIOException); - assertTrue("connect".equals(me.getMessage())); - - MsoException me2 = super.neutronExceptionToMsoException (openStackResponseException,"ContextError"); - assertTrue(me2 instanceof MsoOpenstackException); - assertTrue("ContextError".equals(me2.getContext())); - assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); - } - - @Test - public final void testRuntimeExceptionToMsoException () { - RuntimeException re = new RuntimeException ("runtime"); - MsoException me = super.runtimeExceptionToMsoException (re, "ContextError"); - - assertTrue (me instanceof MsoAdapterException); - assertTrue("ContextError".equals(me.getContext())); - assertTrue(MsoExceptionCategory.INTERNAL.equals(me.getCategory())); - } -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java deleted file mode 100644 index 93afbcccaf..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java +++ /dev/null @@ -1,365 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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 org.openecomp.mso.adapter_utils.tests; - -import java.io.IOException; -import java.util.*; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.TextNode; -import com.woorea.openstack.base.client.HttpMethod; -import com.woorea.openstack.base.client.OpenStackRequest; -import com.woorea.openstack.heat.model.Stack; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.utils.KeystoneUtils; -import mockit.Deencapsulation; -import mockit.Invocation; -import mockit.Mock; -import mockit.MockUp; -import mockit.integration.junit4.JMockit; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openecomp.mso.cloud.CloudConfigFactory; -import org.openecomp.mso.cloud.CloudConfigTest; -import org.openecomp.mso.openstack.beans.StackInfo; -import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; -import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; -import org.openecomp.mso.openstack.exceptions.MsoException; -import org.openecomp.mso.openstack.exceptions.MsoIOException; -import org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists; -import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound; -import org.openecomp.mso.openstack.utils.MsoCommonUtils; -import org.openecomp.mso.openstack.utils.MsoHeatUtils; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.properties.MsoPropertiesFactory; - -import com.woorea.openstack.heat.model.CreateStackParam; - -/** - * This class implements test methods of the MsoHeatUtils - * - * - */ -public class MsoHeatUtilsTest extends MsoCommonUtils { - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); - public static MsoHeatUtils msoHeatUtils; - - @BeforeClass - public static final void loadClasses() throws MsoCloudIdentityNotFound, MsoPropertiesException { - ClassLoader classLoader = MsoHeatUtilsTest.class.getClassLoader(); - String cloudConfigJson = classLoader.getResource("cloud_config.json").getPath(); - cloudConfigFactory.initializeCloudConfig(cloudConfigJson, 1); - msoPropertiesFactory.initializeMsoProperties("NO_PROP", classLoader.getResource("mso.properties").getPath()); - msoHeatUtils = new MsoHeatUtils("NO_PROP", msoPropertiesFactory, cloudConfigFactory); - } - - @Test - public final void testCreateStackBadCloudConfig() - throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { - try { - msoHeatUtils.createStack("DOESNOTEXIST", "test", "stackName", "test", new HashMap<>(), - Boolean.TRUE, 10); - } catch (MsoCloudSiteNotFound e) { - - } catch (java.lang.NullPointerException npe) { - - } - - } - - @Test - public final void testCreateStackFailedConnectionHeatClient() - throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { - try { - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, - 10); - } catch (MsoIOException e) { - - } - - } - - @Test - public final void testCreateStackFailedConnection() - throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { - try { - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, - 10); - } catch (MsoIOException e) { - - } - - } - - @Test - public final void createStackSuccessWithEnvironment() throws MsoException { - final MockUp<OpenStackRequest<Access>> mockRequest = new MockUp<OpenStackRequest<Access>>() { - @Mock - public Object execute(Invocation invocation) { - final OpenStackRequest invokedInstance = invocation.getInvokedInstance(); - final Class<?> returnType = Deencapsulation.getField(invokedInstance, "returnType"); - - try { - if (returnType == Access.class) { - ObjectMapper mapper = new ObjectMapper(); - String json = "{\"token\":{\"id\":\"tokenId\",\"tenant\":{\"id\":\"tenantId\",\"name\":\"tenantName\"}},\"serviceCatalog\":[{\"type\":\"orchestration\",\"name\":\"orchestration\",\"endpoints\":[{\"region\":\"region1\",\"publicURL\":\"http://localhost:5000\",\"internalURL\":\"http://localhost:5000\",\"adminURL\":\"http://localhost:5000\"}]}]}"; - return mapper.readValue(json, Access.class); - } else if (returnType == Stack.class) { - final Stack stack = new Stack(); - stack.setId("stackId"); - stack.setStackName("stackName"); - stack.setStackStatus("CREATE_COMPLETE"); - return stack; - } - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }; - - final MockUp<KeystoneUtils> mockKeystone = new MockUp<KeystoneUtils>() { - @Mock - String findEndpointURL(List<Access.Service> serviceCatalog, String type, String region, String facing) { - return "http://localhost:5000"; - } - }; - - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, - "environment"); - - mockRequest.tearDown(); - mockKeystone.tearDown(); - } - - @Test - public final void createStackSuccessWithFiles() throws MsoException { - final MockUp<OpenStackRequest<Access>> mockRequest = new MockUp<OpenStackRequest<Access>>() { - @Mock - public Object execute(Invocation invocation) { - final OpenStackRequest invokedInstance = invocation.getInvokedInstance(); - final Class<?> returnType = Deencapsulation.getField(invokedInstance, "returnType"); - - try { - if (returnType == Access.class) { - ObjectMapper mapper = new ObjectMapper(); - String json = "{\"token\":{\"id\":\"tokenId\",\"tenant\":{\"id\":\"tenantId\",\"name\":\"tenantName\"}},\"serviceCatalog\":[{\"type\":\"orchestration\",\"name\":\"orchestration\",\"endpoints\":[{\"region\":\"region1\",\"publicURL\":\"http://localhost:5000\",\"internalURL\":\"http://localhost:5000\",\"adminURL\":\"http://localhost:5000\"}]}]}"; - return mapper.readValue(json, Access.class); - } else if (returnType == Stack.class) { - final Stack stack = new Stack(); - stack.setId("stackId"); - stack.setStackName("stackName"); - stack.setStackStatus("CREATE_COMPLETE"); - return stack; - } - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }; - - final MockUp<KeystoneUtils> mockKeystone = new MockUp<KeystoneUtils>() { - @Mock - String findEndpointURL(List<Access.Service> serviceCatalog, String type, String region, String facing) { - return "http://localhost:5000"; - } - }; - - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, - "environment", new HashMap<>()); - - mockRequest.tearDown(); - mockKeystone.tearDown(); - } - - @Test - public final void createStackSuccessWithHeatFiles() throws MsoException { - - final MockUp<OpenStackRequest<Access>> mockRequest = new MockUp<OpenStackRequest<Access>>() { - @Mock - public Object execute(Invocation invocation) { - final OpenStackRequest invokedInstance = invocation.getInvokedInstance(); - final Class<?> returnType = Deencapsulation.getField(invokedInstance, "returnType"); - - try { - if (returnType == Access.class) { - ObjectMapper mapper = new ObjectMapper(); - String json = "{\"token\":{\"id\":\"tokenId\",\"tenant\":{\"id\":\"tenantId\",\"name\":\"tenantName\"}},\"serviceCatalog\":[{\"type\":\"orchestration\",\"name\":\"orchestration\",\"endpoints\":[{\"region\":\"region1\",\"publicURL\":\"http://localhost:5000\",\"internalURL\":\"http://localhost:5000\",\"adminURL\":\"http://localhost:5000\"}]}]}"; - return mapper.readValue(json, Access.class); - } else if (returnType == Stack.class) { - final Stack stack = new Stack(); - stack.setId("stackId"); - stack.setStackName("stackName"); - stack.setStackStatus("CREATE_COMPLETE"); - return stack; - } - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }; - - final MockUp<KeystoneUtils> mockKeystone = new MockUp<KeystoneUtils>() { - @Mock - String findEndpointURL(List<Access.Service> serviceCatalog, String type, String region, String facing) { - return "http://localhost:5000"; - } - }; - - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, - "environment", new HashMap<>(), new HashMap<>()); - - mockRequest.tearDown(); - mockKeystone.tearDown(); - } - - @Test - public final void requestToStringBuilderTest() { - CreateStackParam param = new CreateStackParam(); - param.setDisableRollback(false); - param.setEnvironment("environment"); - param.setFiles(new HashMap<>()); - param.setParameters(new HashMap<>()); - param.setStackName("stackName"); - param.setTemplate("template"); - param.setTemplateUrl("http://templateUrl"); - param.setTimeoutMinutes(1); - - msoHeatUtils.requestToStringBuilder(param); - } - - @Test - public final void heatCacheResetTest() { - msoHeatUtils.heatCacheReset(); - } - - @Test - public final void expireHeatClientTest() { - msoHeatUtils.expireHeatClient("tenantId", "cloudId"); - } - - @Test - public final void heatCacheCleanupTest() { - msoHeatUtils.heatCacheCleanup(); - } - - @Test - public void queryStackTest() throws MsoException { - final MockUp<OpenStackRequest<Access>> mockRequest = new MockUp<OpenStackRequest<Access>>() { - @Mock - public Object execute(Invocation invocation) { - final OpenStackRequest invokedInstance = invocation.getInvokedInstance(); - final Class<?> returnType = Deencapsulation.getField(invokedInstance, "returnType"); - - try { - if (returnType == Access.class) { - ObjectMapper mapper = new ObjectMapper(); - String json = "{\"token\":{\"id\":\"tokenId\",\"tenant\":{\"id\":\"tenantId\",\"name\":\"tenantName\"}},\"serviceCatalog\":[{\"type\":\"orchestration\",\"name\":\"orchestration\",\"endpoints\":[{\"region\":\"region1\",\"publicURL\":\"http://localhost:5000\",\"internalURL\":\"http://localhost:5000\",\"adminURL\":\"http://localhost:5000\"}]}]}"; - return mapper.readValue(json, Access.class); - } else if (returnType == Stack.class) { - final Stack stack = new Stack(); - stack.setId("stackId"); - stack.setStackName("stackName"); - stack.setStackStatus("CREATE_COMPLETE"); - return stack; - } - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }; - - final MockUp<KeystoneUtils> mockKeystone = new MockUp<KeystoneUtils>() { - @Mock - String findEndpointURL(List<Access.Service> serviceCatalog, String type, String region, String facing) { - return "http://localhost:5000"; - } - }; - - final StackInfo stackInfo = msoHeatUtils.queryStack("MT", "test", "stackName"); - - mockRequest.tearDown(); - mockKeystone.tearDown(); - } - - @Test - public void deleteStack() throws MsoException { - final MockUp<OpenStackRequest<Access>> mockRequest = new MockUp<OpenStackRequest<Access>>() { - @Mock - public Object execute(Invocation invocation) { - final OpenStackRequest invokedInstance = invocation.getInvokedInstance(); - final Class<?> returnType = Deencapsulation.getField(invokedInstance, "returnType"); - final String path = Deencapsulation.getField(invokedInstance, "endpoint"); -// final String stackName = path.substring(path.lastIndexOf("/")); - - try { - if (returnType == Access.class) { - ObjectMapper mapper = new ObjectMapper(); - String json = "{\"token\":{\"id\":\"tokenId\",\"tenant\":{\"id\":\"tenantId\",\"name\":\"tenantName\"}},\"serviceCatalog\":[{\"type\":\"orchestration\",\"name\":\"orchestration\",\"endpoints\":[{\"region\":\"region1\",\"publicURL\":\"http://localhost:5000\",\"internalURL\":\"http://localhost:5000\",\"adminURL\":\"http://localhost:5000\"}]}]}"; - return mapper.readValue(json, Access.class); - } else if (returnType == Stack.class) { - final Stack stack = new Stack(); - stack.setId("stackId"); - stack.setStackName("stackName"); - final String status = "DELETE_COMPLETE"; - stack.setStackStatus(status); - return stack; - } - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }; - - final MockUp<KeystoneUtils> mockKeystone = new MockUp<KeystoneUtils>() { - @Mock - String findEndpointURL(List<Access.Service> serviceCatalog, String type, String region, String facing) { - return "http://localhost:5000"; - } - }; - - final StackInfo stackInfo = msoHeatUtils.deleteStack("test", "MT", "stackName", true); - - mockRequest.tearDown(); - mockKeystone.tearDown(); - } - - @Test - public void copyStringOutputsToInputsTest() { - Map<String, String> inputs = new HashMap<String, String>(){{put("key41", "value41");}}; - Map<String, Object> outputs = new HashMap<String, Object>(){{ - put("key2", "val2"); - put("key3", new TextNode("val3")); - put("key4", new LinkedHashMap<String, String>(){{put("key41", "value41");}}); - }}; - msoHeatUtils.copyStringOutputsToInputs(inputs, outputs, true); - } -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java deleted file mode 100644 index c6c6baf61b..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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 org.openecomp.mso.cloud; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import javax.ws.rs.core.Response; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; - -public class CloudConfigFactoryTest { - - private static final String CLOUD_CONFIG_FIELD_NAME = "cloudConfigCache"; - private static final int REFRESH_TIMER_VALUE = 1; - - private CloudConfigFactory testedObject; - private CloudConfig cloudConfigMock; - private CloudConfig savedCloudConfig; - - @Before - public void init() throws NoSuchFieldException, IllegalAccessException { - cloudConfigMock = mock(CloudConfig.class); - testedObject = new CloudConfigFactory(); - Field field = CloudConfigFactory.class.getDeclaredField(CLOUD_CONFIG_FIELD_NAME); - field.setAccessible(true); - savedCloudConfig = (CloudConfig) field.get(null); - field.set(null, cloudConfigMock); - } - - @After - public void reset() throws NoSuchFieldException, IllegalAccessException { - Field field = CloudConfigFactory.class.getDeclaredField(CLOUD_CONFIG_FIELD_NAME); - field.setAccessible(true); - field.set(null, savedCloudConfig); - } - - @Test - public void initializeCloudConfigSuccessful() throws MsoCloudIdentityNotFound, IOException { - ClassLoader classLoader = CloudConfigFactoryTest.class.getClassLoader(); - String cloudConfigJsonFilePath = classLoader.getResource("cloud_config.json").getPath(); - testedObject.initializeCloudConfig(cloudConfigJsonFilePath, REFRESH_TIMER_VALUE); - verify(cloudConfigMock).loadCloudConfig(cloudConfigJsonFilePath, REFRESH_TIMER_VALUE); - } - - @Test - public void getValidCloudConfig() { - when(cloudConfigMock.isValidCloudConfig()).thenReturn(true); - - testedObject.getCloudConfig(); - - verify(cloudConfigMock).clone(); - } - - @Test - public void reload_CloudConfigValid() throws IOException, MsoCloudIdentityNotFound { - when(cloudConfigMock.isValidCloudConfig()).thenReturn(true); - - testedObject.reloadCloudConfig(); - - verify(cloudConfigMock).clone(); - verify(cloudConfigMock).reloadPropertiesFile(); - } - - @Test - public void reload_CloudConfigNotValid() - throws IOException, MsoCloudIdentityNotFound { - when(cloudConfigMock.isValidCloudConfig()).thenReturn(false); - - testedObject.reloadCloudConfig(); - - verify(cloudConfigMock).reloadPropertiesFile(); - } - - @Test - public void showCloudConfig() throws NoSuchFieldException, IllegalAccessException { - when(cloudConfigMock.isValidCloudConfig()).thenReturn(true); - when(cloudConfigMock.clone()).thenReturn(createCloudConfig("IdTest576", "identityTest456")); - Response response = testedObject.showCloudConfig(); - - assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getEntity().toString()).containsPattern("CloudSite:.*IdTest576") - .containsPattern("Cloud Identity Service:.*identityTest456"); - - } - - @Test - public void resetClientCaches_Successful() { - Response response = testedObject.resetClientCaches(); - assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getEntity().toString()).isEqualTo("Client caches reset. All entries removed."); - } - - @Test - public void cleanUpClientCache_Successful() { - Response response = testedObject.cleanupClientCaches(); - assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getEntity().toString()).isEqualTo("Client caches cleaned up. All expired entries removed."); - } - - @Test - public void encryptPassword_Successful() { - Response response = testedObject.encryptPassword("passTest123"); - String expectedEncryptedPassword = CloudIdentity.encryptPassword("passTest123"); - assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getEntity().toString()).isEqualTo("Encrypted Password = "+expectedEncryptedPassword); - } - - private CloudConfig createCloudConfig(String cloudSiteId, String identityServiceId) - throws NoSuchFieldException, IllegalAccessException { - CloudConfig cloudConfig = new CloudConfig(); - Map<String, CloudSite> cloudSiteMap = new HashMap<>(); - CloudSite cs = new CloudSite(); - cs.setId(cloudSiteId); - cloudSiteMap.put("keyTest", cs); - Field cloudSitesField = cloudConfig.getClass().getDeclaredField("cloudSites"); - cloudSitesField.setAccessible(true); - cloudSitesField.set(cloudConfig, cloudSiteMap); - - Map<String, CloudIdentity> identityServicesMap = new HashMap<>(); - CloudIdentity cloudIdentity = new CloudIdentity(); - cloudIdentity.setId(identityServiceId); - identityServicesMap.put("identityKey", cloudIdentity); - - Field identityServicesField = cloudConfig.getClass().getDeclaredField("identityServices"); - identityServicesField.setAccessible(true); - identityServicesField.set(cloudConfig, identityServicesMap); - - return cloudConfig; - } - - private void setCloudConfig() - throws NoSuchFieldException, IllegalAccessException { - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java deleted file mode 100644 index a4859a11b2..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java +++ /dev/null @@ -1,244 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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 org.openecomp.mso.cloud; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; - -public class CloudConfigTest { - - private static final int NUMBER_OF_CLOUD_SITES_IN_JSON_FILE = 4; - private static final int NUMBER_OF_IDENTITY_SERVICES_IN_JSON_FILE = 4; - private static final String CLOUD_SITES_FIELD_NAME = "cloudSites"; - private static final String IDENTITY_SERVICE_FIELD_NAME = "identityServices"; - private static final String CLOUD_SITE_DEFAULT = "default"; - private static final String CLOUD_CONFIG_JSON_FILE_NAME = "cloud_config.json"; - private static final String CLOUD_CONFIG_INVALID_JSON_FILE_NAME = "cloud_config_bad.json"; - - private CloudConfig testedObject; - private CloudSite cloudSite; - private CloudSite cloudSiteDefault; - - @Before - public void init() { - testedObject = new CloudConfig(); - } - - @Test - public void cloudSite_returnEmptyOptionalIfIdIsNull() { - Optional<CloudSite> cloudConfigOpt = new CloudConfig().getCloudSite(null); - assertThat(cloudConfigOpt).isEmpty(); - } - - @Test - public void cloudSiteIsGotById_when_IdFound() throws NoSuchFieldException, IllegalAccessException { - setCloudSitesMap(); - Optional<CloudSite> cloudSiteOpt = testedObject.getCloudSite(cloudSite.getId()); - assertThat(cloudSiteOpt).isPresent(); - assertThat(cloudSiteOpt.get().getId()).isEqualTo(cloudSite.getId()); - assertThat(cloudSiteOpt.get().getClli()).isEqualTo(cloudSite.getClli()); - } - - @Test - @Ignore // 1802 merge - public void cloudSiteIsGotByClli_when_IdNotFound() throws NoSuchFieldException, IllegalAccessException { - setCloudSitesMap(); - Optional<CloudSite> cloudSiteOpt = testedObject.getCloudSite(cloudSite.getClli()); - assertTrue(cloudSiteOpt.isPresent()); - assertThat(cloudSiteOpt.get().getId()).isEqualTo(cloudSite.getId()); - assertThat(cloudSiteOpt.get().getClli()).isEqualTo(cloudSite.getClli()); - } - - @Test - @Ignore // 1802 merge - public void cloudSiteIsGotByDefault_when_IdAndClliNotFound() throws NoSuchFieldException, IllegalAccessException { - setCloudSitesMap(); - Optional<CloudSite> cloudSiteOpt = testedObject.getCloudSite("not_existing_id"); - assertTrue(cloudSiteOpt.isPresent()); - assertThat(cloudSiteOpt.get().getId()).isEqualTo("not_existing_id"); - assertThat(cloudSiteOpt.get().getClli()).isEqualTo(cloudSiteDefault.getClli()); - } - - @Test - @Ignore // 1802 merge - public void cloudSiteNotFound_returnNull() { - assertThat(testedObject.getCloudSite("not_existing_id")).isEmpty(); - } - - @Test - public void identityServiceFoundById() throws NoSuchFieldException, IllegalAccessException { - CloudIdentity cloudIdentity = createCloudIdentity(); - setIdentityServiceMap(); - CloudIdentity cloudIdentityResult = testedObject.getIdentityService(cloudIdentity.getId()); - - assertThat(cloudIdentityResult).isNotNull(); - assertThat(cloudIdentityResult.getId()).isEqualTo(cloudIdentity.getId()); - assertThat(cloudIdentityResult.getMsoId()).isEqualTo(cloudIdentity.getMsoId()); - } - - @Test - public void defaultClodeSiteNotFound_returnNull() { - assertThat(testedObject.getIdentityService("not_existing_id")).isNull(); - } - - @Test - public void loadCloudConfigSuccessful() throws IOException, MsoCloudIdentityNotFound { - ClassLoader classLoader = CloudConfigTest.class.getClassLoader(); - String cloudConfigJsonFilePath = classLoader.getResource(CLOUD_CONFIG_JSON_FILE_NAME).getPath(); - testedObject.loadCloudConfig(cloudConfigJsonFilePath, 1); - assertThat(testedObject.isValidCloudConfig()).isTrue(); - checkCloudSites(); - checkIdentityServices(); - } - - @Test - public void loadCloudConfig_cloudIdentityNotFound() { - ClassLoader classLoader = CloudConfigTest.class.getClassLoader(); - String cloudConfigInvalidJsonFilePath = classLoader.getResource(CLOUD_CONFIG_INVALID_JSON_FILE_NAME).getPath(); - assertThatThrownBy(() -> testedObject.loadCloudConfig(cloudConfigInvalidJsonFilePath, 1)) - .isInstanceOf(MsoCloudIdentityNotFound.class) - .hasMessage("Cloud Identity [MT Cloud site refers to a non-existing identity service: " - + "MT_KEYSTONE_NOT_EXISTING] not found"); - assertThat(testedObject.isValidCloudConfig()).isFalse(); - } - - private void checkCloudSites() { - Map<String, CloudSite> siteMap = testedObject.getCloudSites(); - assertThat(siteMap).isNotEmpty().hasSize(NUMBER_OF_CLOUD_SITES_IN_JSON_FILE); - CloudSite site1 = siteMap.get("MT"); - CloudSite site2 = siteMap.get("DAN"); - CloudSite site3 = siteMap.get("MTINJVCC101"); - CloudSite site4 = siteMap.get("MTSNJA4LCP1"); - - assertThat(site1.getId()).isEqualTo("MT"); - assertThat(site1.getRegionId()).isEqualTo("regionOne"); - assertThat(site1.getIdentityServiceId()).isEqualTo("MT_KEYSTONE"); - assertThat(site1.getIdentityService()).isNotNull(); - assertThat(site1.getIdentityService().getId()).isEqualTo(site1.getIdentityServiceId()); - - assertThat(site2.getId()).isEqualTo("DAN"); - assertThat(site2.getRegionId()).isEqualTo("RegionOne"); - assertThat(site2.getIdentityServiceId()).isEqualTo("DAN_KEYSTONE"); - assertThat(site2.getIdentityService()).isNotNull(); - assertThat(site2.getIdentityService().getId()).isEqualTo(site2.getIdentityServiceId()); - - assertThat(site3.getId()).isEqualTo("MTINJVCC101"); - assertThat(site3.getRegionId()).isEqualTo("regionTwo"); - assertThat(site3.getIdentityServiceId()).isEqualTo("MTINJVCC101_DCP"); - assertThat(site3.getIdentityService()).isNotNull(); - assertThat(site3.getIdentityService().getId()).isEqualTo(site3.getIdentityServiceId()); - - assertThat(site4.getId()).isEqualTo("MTSNJA4LCP1"); - assertThat(site4.getRegionId()).isEqualTo("mtsnjlcp1"); - assertThat(site4.getIdentityServiceId()).isEqualTo("MTSNJA3DCP1"); - assertThat(site4.getIdentityService()).isNotNull(); - assertThat(site4.getIdentityService().getId()).isEqualTo(site4.getIdentityServiceId()); - } - - private void checkIdentityServices() { - Map<String, CloudIdentity> identityMap = testedObject.getIdentityServices(); - assertThat(identityMap).isNotEmpty().hasSize(NUMBER_OF_IDENTITY_SERVICES_IN_JSON_FILE); - - CloudIdentity identity1 = identityMap.get("MT_KEYSTONE"); - CloudIdentity identity2 = identityMap.get("DAN_KEYSTONE"); - CloudIdentity identity3 = identityMap.get("MTINJVCC101_DCP"); - CloudIdentity identity4 = identityMap.get("MTSNJA3DCP1"); - - assertThat(identity1.getMsoId()).isEqualTo("john"); - assertThat(identity1.getMsoPass()).isEqualTo("changeme"); - assertThat(identity1.getAdminTenant()).isEqualTo("admin"); - assertThat(identity1.getMemberRole()).isEqualTo("_member_"); - assertThat(identity1.hasTenantMetadata()).isFalse(); - - assertThat(identity2.getMsoId()).isEqualTo("mockId"); - assertThat(identity2.getMsoPass()).isEqualTo("stack123"); - assertThat(identity2.getAdminTenant()).isEqualTo("service"); - assertThat(identity2.getMemberRole()).isEqualTo("_member_"); - assertThat(identity2.hasTenantMetadata()).isFalse(); - - assertThat(identity3.getMsoId()).isEqualTo("mockIdToo"); - assertThat(identity3.getMsoPass()).isEqualTo("AICG@mm@@2015"); - assertThat(identity3.getAdminTenant()).isEqualTo("service"); - assertThat(identity3.getMemberRole()).isEqualTo("admin"); - assertThat(identity3.hasTenantMetadata()).isTrue(); - - assertThat(identity4.getMsoId()).isEqualTo("mockIdToo"); - assertThat(identity4.getMsoPass()).isEqualTo("2315QRS2015srq"); - assertThat(identity4.getAdminTenant()).isEqualTo("service"); - assertThat(identity4.getMemberRole()).isEqualTo("admin"); - assertThat(identity4.hasTenantMetadata()).isTrue(); - } - - @Test - public void cloneSuccessful() throws NoSuchFieldException, IllegalAccessException { - setCloudSitesMap(); - setIdentityServiceMap(); - assertThat(testedObject.clone()).isEqualTo(testedObject); - } - - private void setCloudSitesMap() throws NoSuchFieldException, IllegalAccessException { - Field field = testedObject.getClass().getDeclaredField(CLOUD_SITES_FIELD_NAME); - field.setAccessible(true); - Map<String, CloudSite> cloudSites = new HashMap<>(); - cloudSite = createCloudSite("idTest1", "clliTest1"); - cloudSiteDefault = createCloudSite(CLOUD_SITE_DEFAULT, "clliTest2"); - cloudSites.put(cloudSite.getId(), cloudSite); - cloudSites.put(cloudSiteDefault.getId(), cloudSiteDefault); - field.set(testedObject, cloudSites); - } - - private void setIdentityServiceMap() throws NoSuchFieldException, IllegalAccessException { - Field field = testedObject.getClass().getDeclaredField(IDENTITY_SERVICE_FIELD_NAME); - field.setAccessible(true); - - Map<String, CloudIdentity> cloudIdentityMap = new HashMap<>(); - CloudIdentity cloudIdentity = createCloudIdentity(); - cloudIdentityMap.put(cloudIdentity.getId(), cloudIdentity); - field.set(testedObject, cloudIdentityMap); - } - - private CloudIdentity createCloudIdentity() { - CloudIdentity cloudIdentity = new CloudIdentity(); - cloudIdentity.setId("identityTestId"); - cloudIdentity.setMsoId("msoTestId"); - return cloudIdentity; - } - - private CloudSite createCloudSite(String id, String clli) { - CloudSite cloudSite = new CloudSite(); - cloudSite.setId(id); - cloudSite.setClli(clli); - cloudSite.setAic_version("2.5"); - cloudSite.setIdentityService(createCloudIdentity()); - return cloudSite; - } -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteTest.java deleted file mode 100644 index 4c5ceb238c..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.openecomp.mso.cloud; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -public class CloudSiteTest { - - @Mock - CloudIdentity ci= new CloudIdentity(); - - @InjectMocks - CloudSite cs = new CloudSite(); - - -@Before -public void init(){ - MockitoAnnotations.initMocks(this); - } - @Test - public void testCloudSite() { - cs.setAic_version("aic_version"); - cs.setClli("clli"); - cs.setId("id"); - cs.setIdentityService(ci); - cs.setRegionId("regionId"); - assert(cs.getAic_version().equals("aic_version")); - assert(cs.getClli().equals("clli")); - assert(cs.getId().equals("id")); - assert(cs.getIdentityService().equals(ci)); - assert(cs.getRegionId().equals("regionId")); - } - @Test - public void testtoStringmethod(){ - assert(cs.toString()!=null); - } - @Test - public void testhashCodemethod(){ - assert(cs.hashCode()!=0); - } - @Test - public void testclone(){ - assert(cs.clone()!=null); - } -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java deleted file mode 100644 index 2cfce276d8..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * ============LICENSE_START========================================== - * =================================================================== - * 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============================================ - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - * - */ - -package org.openecomp.mso.cloud.authentication; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.woorea.openstack.keystone.model.Authentication; -import org.junit.Test; -import org.openecomp.mso.cloud.CloudIdentity; -import org.openecomp.mso.cloud.CloudIdentity.IdentityAuthenticationType; -import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper; - -public class AuthenticationMethodFactoryTest { - - private static final Class WRAPPER_CLASS = RackspaceAPIKeyWrapper.class; - private static final String AUTHENTICATION_TYPE = "authenticationTest"; - - @Test - public void register_NoExceptionThrown() throws IllegalAccessException, InstantiationException { - AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, WRAPPER_CLASS); - } - - @Test - public void register_throwExceptionWhenAuthTypeIsNull() throws InstantiationException, IllegalAccessException { - try { - AuthenticationMethodFactory.register(null, WRAPPER_CLASS); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null " - + "or an empty name string"); - } - } - - @Test - public void register_throwExceptionWhenAuthTypeIsEmpty() throws InstantiationException, IllegalAccessException { - try { - AuthenticationMethodFactory.register("", WRAPPER_CLASS); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null " - + "or an empty name string"); - } - } - - @Test - public void register_throwExceptionWhenWrapperIsNull() throws IllegalAccessException, InstantiationException { - try { - AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, null); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isNotEmpty() - .contains("Wrapper Class to register for Authentication cannot be null"); - } - } - - @Test - public void getAuthentication_NoExceptionThrown() { - CloudIdentity cloudIdentity = new CloudIdentity(); - cloudIdentity.setIdentityAuthenticationType(IdentityAuthenticationType.RACKSPACE_APIKEY); - cloudIdentity.setMsoId("msoIdTest"); - cloudIdentity.setMsoPass("123"); - Authentication result = AuthenticationMethodFactory.getAuthenticationFor(cloudIdentity); - assertThat(result).isNotNull(); - } - - @Test - public void getAuthentication_ThrowExWhenCloudSiteIsNull() { - try { - AuthenticationMethodFactory.getAuthenticationFor(null); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isNotEmpty().contains("Cloud identity cannot be null"); - } - } - - @Test - public void getAuthentication_ThrowExWhenIdentityAuthenticationTypeIsNotSet() { - try { - AuthenticationMethodFactory.getAuthenticationFor(new CloudIdentity()); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isNotEmpty() - .contains("Cloud identity authentication type cannot be null or empty"); - } - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java deleted file mode 100644 index b6c1c7373f..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/*
- * ============LICENSE_START==========================================
- * ===================================================================
- * 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============================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- *
- */
-
-package org.openecomp.mso.cloud.authentication;
-
-import static org.junit.Assert.assertTrue;
-
-import com.woorea.openstack.keystone.model.Authentication;
-import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
-import org.junit.Test;
-import org.openecomp.mso.cloud.CloudIdentity;
-import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
-
-/**
- * A few JUnit tests to evaluate the new factory that manages authentication
- * types and their associated wrapper classes. Here it is assumed that core types
- * only are tested.
- *
- */
-public class AuthenticationMethodTest {
-
- /**
- *
- */
- public AuthenticationMethodTest() {
- // TODO Auto-generated constructor stub
- }
-
- @Test
- public void testCustomRackspaceAuthFromCloudIdentity() {
- CloudIdentity ci = new CloudIdentity();
- ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
- ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
- ci.setMsoId("test");
- Authentication auth = ci.getAuthentication();
- assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
- }
-
- @Test
- public void testCoreUsernamePasswordAuthFromCloudIdentity() {
- CloudIdentity ci = new CloudIdentity();
- ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
- ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
- ci.setMsoId("someuser");
- Authentication auth = ci.getAuthentication();
- assertTrue(UsernamePassword.class.equals(auth.getClass()));
- }
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java deleted file mode 100644 index 33f91c641e..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============LICENSE_START========================================== - * =================================================================== - * 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============================================ - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - * - */ - -package org.openecomp.mso.cloud.authentication.wrappers; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import com.woorea.openstack.keystone.model.Authentication; -import org.junit.Test; -import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication; - -public class RackspaceAPIKeyWrapperTest { - - @Test - public void getAuthenticationSuccessful() { - RackspaceAPIKeyWrapper testedObject = new RackspaceAPIKeyWrapper(); - Authentication authentication = testedObject.getAuthentication(WrapperTestUtility.createCloudIdentity()); - - assertThat(authentication).isInstanceOf(RackspaceAuthentication.class); - RackspaceAuthentication rackspaceAuthentication = (RackspaceAuthentication) authentication; - assertThat(rackspaceAuthentication.getToken().getUsername()) - .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_ID); - assertThat(rackspaceAuthentication.getToken().getApiKey()) - .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_PASS); - } - - @Test - public void getAuthenticationThrowsException() { - assertThatThrownBy(() -> new RackspaceAPIKeyWrapper().getAuthentication(null)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage(WrapperTestUtility.EXCEPTION_MESSAGE); - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java deleted file mode 100644 index 0cfe287dfe..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============LICENSE_START========================================== - * =================================================================== - * 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============================================ - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - * - */ - -package org.openecomp.mso.cloud.authentication.wrappers; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import com.woorea.openstack.keystone.model.Authentication; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import org.junit.Test; - -public class UsernamePasswordWrapperTest { - - @Test - public void getAuthenticationSuccessful() { - UsernamePasswordWrapper testedObject = new UsernamePasswordWrapper(); - Authentication authentication = testedObject.getAuthentication(WrapperTestUtility.createCloudIdentity()); - - assertThat(authentication).isInstanceOf(UsernamePassword.class); - UsernamePassword usernamePassword = (UsernamePassword) authentication; - assertThat(usernamePassword.getPasswordCredentials().getUsername()) - .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_ID); - assertThat(usernamePassword.getPasswordCredentials().getPassword()) - .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_PASS); - } - - @Test - public void getAuthenticationThrowsException() { - assertThatThrownBy(() -> new UsernamePasswordWrapper().getAuthentication(null)). - isInstanceOf(IllegalArgumentException.class). - hasMessage(WrapperTestUtility.EXCEPTION_MESSAGE); - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java deleted file mode 100644 index 3cbc48d090..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * ============LICENSE_START========================================== - * =================================================================== - * 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============================================ - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - * - */ - -package org.openecomp.mso.cloud.authentication.wrappers; - -import org.openecomp.mso.cloud.CloudIdentity; - -final class WrapperTestUtility { - - static final String CLOUD_IDENTITY_MSO_ID = "msoIdTest"; - static final String CLOUD_IDENTITY_MSO_PASS = "msoPassTest"; - static final String EXCEPTION_MESSAGE = "Provided cloud identity is null, cannot extract username and " - + "password"; - - private WrapperTestUtility() { - } - - static CloudIdentity createCloudIdentity() { - CloudIdentity cloudIdentity = new CloudIdentity(); - cloudIdentity.setMsoId(CLOUD_IDENTITY_MSO_ID); - cloudIdentity.setMsoPass(CloudIdentity.encryptPassword(CLOUD_IDENTITY_MSO_PASS)); - return cloudIdentity; - } -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java deleted file mode 100644 index 40108b3802..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java +++ /dev/null @@ -1,71 +0,0 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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 org.openecomp.mso.cloud.servertype;
-
-import java.util.Map;
-
-import org.openecomp.mso.cloud.CloudConfigFactory;
-import org.openecomp.mso.cloud.CloudIdentity;
-import org.openecomp.mso.openstack.beans.MsoTenant;
-import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-import org.openecomp.mso.openstack.utils.MsoTenantUtils;
-
-
-public class NewServerTypeUtils extends MsoTenantUtils {
-
- public NewServerTypeUtils(String msoPropID, CloudConfigFactory cloudConfigFactory) {
- super(msoPropID, cloudConfigFactory);
- }
-
- @Override
- public String createTenant(String tenantName, String cloudSiteId, Map<String, String> metadata, boolean backout)
- throws MsoException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public MsoTenant queryTenant(String tenantId, String cloudSiteId) throws MsoException, MsoCloudSiteNotFound {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public MsoTenant queryTenantByName(String tenantName, String cloudSiteId)
- throws MsoException, MsoCloudSiteNotFound {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean deleteTenant(String tenantId, String cloudSiteId) throws MsoException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public String getKeystoneUrl(String regionId, String msoPropID, CloudIdentity cloudIdentity)
- throws MsoException {
- return msoPropID + ":" + regionId + ":NewServerTypeKeystoneURL/" + cloudIdentity.getIdentityUrl();
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java deleted file mode 100644 index 69fab27f78..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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 org.openecomp.mso.cloud.servertype;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.openecomp.mso.cloud.CloudConfigFactory;
-import org.openecomp.mso.cloud.CloudIdentity;
-import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
-import org.openecomp.mso.cloud.IdentityServerTypeAbstract;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-import org.openecomp.mso.openstack.utils.MsoKeystoneUtilsTest;
-
-public class ServerTypeTest {
-
- @BeforeClass
- public static void init() throws Exception {
- String cloudConfigJson = ServerTypeTest.class.getClassLoader()
- .getResource("cloud_config.json").getPath();
- (new CloudConfigFactory()).initializeCloudConfig(cloudConfigJson, 0);
- }
-
- @Test
- @Ignore // IGNORED FOR 1710 MERGE TO ONAP
- public void testKeystoneServerType() {
- IdentityServerTypeAbstract keystoneServerType = IdentityServerType.valueOf("KEYSTONE");
- assertNotNull(keystoneServerType);
- }
-
- @Test
- public void testNewServerType() {
- IdentityServerTypeAbstract customServerType = null;
- try {
- customServerType = new IdentityServerType("NewServerType", NewServerTypeUtils.class);
-
- } catch (IllegalArgumentException e) {
- fail("An exception should not be raised when we register a new server type for the first time");
- } finally {
- System.out.println(IdentityServerType.values().toString());
- assertEquals(customServerType, IdentityServerType.valueOf("NewServerType"));
- }
-
- // Create it a second time
- IdentityServerTypeAbstract customServerType2 = null;
- try {
- customServerType2 = new IdentityServerType("NewServerType", NewServerTypeUtils.class);
- fail("An exception should be raised as server type does not exist");
- } catch (IllegalArgumentException e) {
- // Fail silently -- it simply indicates we already registered it
- customServerType2 = IdentityServerType.valueOf("NewServerType");
- } finally {
- System.out.println(IdentityServerType.values().toString());
- assertEquals(customServerType2, IdentityServerType.valueOf("NewServerType"));
- }
-
- // Check the KeystoneURL for this custom TenantUtils
- CloudIdentity cloudIdentity = new CloudIdentity();
- cloudIdentity.setIdentityUrl("LocalIdentity");
- cloudIdentity.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
- cloudIdentity.setIdentityServerType((CloudIdentity.IdentityServerType) CloudIdentity.IdentityServerType.valueOf("NewServerType"));
- String regionId = "RegionA";
- String msoPropID = "12345";
- try {
- assertEquals(cloudIdentity.getKeystoneUrl(regionId, msoPropID), msoPropID + ":" + regionId + ":NewServerTypeKeystoneURL/" + cloudIdentity.getIdentityUrl());
- } catch (MsoException e) {
- fail("No MSO Exception should have occured here");
- }
- }
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyExceptionTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyExceptionTest.java deleted file mode 100644 index 1521d11f31..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyExceptionTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.cloudify.exceptions;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class MsoCloudifyExceptionTest {
-
- @Test
- public void test() {
- Exception e = null;
- boolean pendingWorkflow=true;
- MsoCloudifyException mce=new MsoCloudifyException(200, "message", "detail");
- MsoCloudifyException mcl=new MsoCloudifyException(200, "message", "detail", e);
- mce.setPendingWorkflow(pendingWorkflow);
- assert(mcl.toString()!=null);
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTest.java deleted file mode 100644 index 1646f53022..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.cloudify.exceptions;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class MsoCloudifyTest {
-
- @Test
- public void test() {
- MsoBlueprintAlreadyExists mbae=new MsoBlueprintAlreadyExists("blueprintId", "cloud");
- MsoCloudifyManagerNotFound mcm=new MsoCloudifyManagerNotFound("cloudSiteId");
- MsoDeploymentAlreadyExists mdae=new MsoDeploymentAlreadyExists("deploymentId", "cloud");
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTimeoutTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTimeoutTest.java deleted file mode 100644 index f24db06389..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTimeoutTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.cloudify.exceptions;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-
-import org.junit.Test;
-import org.openecomp.mso.cloudify.v3.model.Execution;
-
-public class MsoCloudifyTimeoutTest {
-
- @Test
- public void test() {
- Execution execution=mock(Execution.class);
- MsoCloudifyTimeout mct=new MsoCloudifyTimeout(execution);
- mct.getExecution();
- assert(mct.toString()!=null);
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java deleted file mode 100644 index 985066cab1..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.cloudify.exceptions;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class MsoCloudifyWorkflowExceptionTest {
-
- @Test
- public void test() {
- MsoCloudifyWorkflowException mcw=new MsoCloudifyWorkflowException("message", "id", "workflowId", "workflowStatus");
- mcw.getWorkflowStatus();
- assertFalse(mcw.isWorkflowStillRunning());
-
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java deleted file mode 100644 index da4aebd3d9..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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 org.openecomp.mso.cloudify.utils; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.openecomp.mso.cloud.CloudConfigFactory; -import org.openecomp.mso.cloud.CloudSite; -import org.openecomp.mso.cloudify.beans.DeploymentInfo; -import org.openecomp.mso.cloudify.exceptions.MsoCloudifyManagerNotFound; -import org.openecomp.mso.cloudify.v3.client.Cloudify; -import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs; -import org.openecomp.mso.openstack.exceptions.MsoException; -import org.openecomp.mso.properties.MsoPropertiesFactory; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.HashMap; -import java.util.Map; -import static org.mockito.Mockito.mock; - -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doReturn; - -//@RunWith(PowerMockRunner.class) -@PrepareForTest({MsoCloudifyUtils.class}) - - -public class MsoCloudifyUtilsTest { - - - @Mock - MsoPropertiesFactory msoPropertiesFactory; - - @Mock - CloudConfigFactory cloudConfigFactory; - - @Mock - DeploymentInfo deploymentInfo; - - @Mock - Cloudify cloudify; - - @Mock - DeploymentOutputs deploymentOutputs; - - @Mock - CloudSite cloudSite; - - @Test(expected = NullPointerException.class) - public void testCreateandInstallDeployment() throws MsoException { - - MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); - Map<String, Object> inputs = new HashMap<>(); - inputs.put("1", "value"); - - mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId" - , inputs, true, 1, true); - - assert (mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId" - , inputs, true, 1, true) != null); - - - } - - @Test(expected = NullPointerException.class) - public void testDeploymentOutputs() throws MsoException { - - MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); - mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId"); - assert (mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId") != null); - } - - @Test(expected = NullPointerException.class) - public void testUninstallAndDeleteDeployment() throws MsoException { - - MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); - mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1); - assert (mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1) != null); - } - - @Test(expected = NullPointerException.class) - public void testIsBlueprintLoaded() throws MsoException { - - MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); - mcu.isBlueprintLoaded("cloudSiteId", "blueprintId"); - assertTrue(mcu.isBlueprintLoaded("cloudSiteId", "blueprintId")); - } - - @Test(expected = MsoCloudifyManagerNotFound.class) - public void testCloudifyClient() throws MsoException { - msoPropertiesFactory = mock(MsoPropertiesFactory.class); - cloudConfigFactory = mock(CloudConfigFactory.class); - cloudSite = mock(CloudSite.class); - MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); - mcu.getCloudifyClient(cloudSite); - assert (mcu.getCloudifyClient(cloudSite) != null); - - } - - @Test(expected = NullPointerException.class) - public void testuploadBlueprint() throws MsoException { - - MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); - - Map<String, byte[]> blueprintFiles = new HashMap<String, byte[]>(); - byte[] byteArray = new byte[]{8, 1, 2, 8}; - blueprintFiles.put("1", byteArray); - - mcu.uploadBlueprint("cloudSiteId", "blueprintId", "mainFileName", blueprintFiles, false); - - } - - @Test(expected = NullPointerException.class) - public void testqueryDeployment() throws MsoException { - - MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); - mcu.queryDeployment(cloudify, "deploymentId"); - assert (mcu.queryDeployment(cloudify, "deploymentId") != null); - - - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantTest.java deleted file mode 100644 index a1de54e231..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.openecomp.mso.openstack.beans; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - -public class MsoTenantTest { - MsoTenant ms = new MsoTenant(); - - @Test - public void test() { - Map<String, String> map = new HashMap<>(); - map.put("id","name"); - ms.setTenantId("tenantId"); - ms.setTenantName("tenantName"); - ms.setMetadata(map); - assert(ms.getMetadata().equals(map)); - assert(ms.getTenantId().equals("tenantId")); - assert(ms.getTenantName().equals("tenantName")); - } -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoTest.java deleted file mode 100644 index 0f357e5555..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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 org.openecomp.mso.openstack.beans; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.woorea.openstack.quantum.model.Network; -import com.woorea.openstack.quantum.model.Segment; -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; - -public class NetworkInfoTest { - - private static final String NETWORK_STATUS_ACTIVE = "ACTIVE"; - private static final String NETWORK_STATUS_ID = "networkIdTest"; - private static final String NETWORK_STATUS_NAME = "networkNameTest"; - private static final String SUBNET_NAME = "subnetTest"; - private static final String PROVIDER = "providerTest"; - private static final String PROVIDER_NETWORK_TYPE_VLAN = "vlan"; - private static final String PROVIDER_NETWORK_TYPE_OTHER = "providerTypeTest"; - private static final Integer PROVIDER_SEGMENTATION_ID = 777; - private static final String PROVIDER_FOR_SEGMENT = "providerSegmentTest"; - private static final Integer PROVIDER_SEGMENTATION_ID_FOR_SEGMENT = 123; - - @Test - public void networkStatusUnknownWhenIsNullInNetwork() { - NetworkInfo networkInfo = new NetworkInfo(prepareNetwork(null)); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.UNKNOWN); - checkCommonPartWhenProviderIsNotPresent(networkInfo); - } - - @Test - public void networkStatusUnknownWhenNotFoundInNetworkStatusMap() { - NetworkInfo networkInfo = new NetworkInfo(prepareNetwork("notExistingNetworkStatus")); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.UNKNOWN); - checkCommonPartWhenProviderIsNotPresent(networkInfo); - } - - @Test - public void setNetworkStatusWhenNetworkStatusFoundInNetworkStatusMap() { - NetworkInfo networkInfo = new NetworkInfo(prepareNetwork(NETWORK_STATUS_ACTIVE)); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.ACTIVE); - checkCommonPartWhenProviderIsNotPresent(networkInfo); - } - - @Test - public void setVLANProviderFromTheNetwork() { - NetworkInfo networkInfo = new NetworkInfo(prepareNetworkWithProvider(NETWORK_STATUS_ACTIVE, PROVIDER, - PROVIDER_NETWORK_TYPE_VLAN)); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.ACTIVE); - assertThat(networkInfo.getProvider()).isEqualTo(PROVIDER); - assertThat(networkInfo.getVlans()).hasSize(1).contains(PROVIDER_SEGMENTATION_ID); - checkCommonPart(networkInfo); - } - - @Test - public void setOtherProviderFromTheNetwork() { - NetworkInfo networkInfo = new NetworkInfo(prepareNetworkWithProvider(NETWORK_STATUS_ACTIVE, PROVIDER, - PROVIDER_NETWORK_TYPE_OTHER)); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.ACTIVE); - assertThat(networkInfo.getProvider()).isEqualTo(PROVIDER); - assertThat(networkInfo.getVlans()).isEmpty(); - checkCommonPart(networkInfo); - } - - @Test - public void setVLANProviderFromTheNetworkSegments() { - NetworkInfo networkInfo = new NetworkInfo(prepareNetworkWithSegments(NETWORK_STATUS_ACTIVE, - prepareSegment(PROVIDER_NETWORK_TYPE_VLAN))); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.ACTIVE); - assertThat(networkInfo.getProvider()).isEqualTo(PROVIDER_FOR_SEGMENT); - assertThat(networkInfo.getVlans()).hasSize(1).contains(PROVIDER_SEGMENTATION_ID_FOR_SEGMENT); - checkCommonPart(networkInfo); - } - - @Test - public void setOtherProviderFromTheNetworkSegments() { - NetworkInfo networkInfo = new NetworkInfo(prepareNetworkWithSegments(NETWORK_STATUS_ACTIVE, - prepareSegment(PROVIDER_NETWORK_TYPE_OTHER))); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.ACTIVE); - assertThat(networkInfo.getProvider()).isEqualTo(PROVIDER_FOR_SEGMENT); - assertThat(networkInfo.getVlans()).isEmpty(); - checkCommonPart(networkInfo); - } - - @Test - public void setNetworkStatusNotFoundWhenNetworkIsNull() { - NetworkInfo networkInfo = new NetworkInfo(null); - assertThat(networkInfo.getStatus()).isEqualTo(NetworkStatus.NOTFOUND); - } - - private void checkCommonPartWhenProviderIsNotPresent(NetworkInfo networkInfo) { - assertThat(networkInfo.getProvider()).isEmpty(); - assertThat(networkInfo.getVlans()).isEmpty(); - checkCommonPart(networkInfo); - } - - private void checkCommonPart(NetworkInfo networkInfo) { - assertThat(networkInfo.getId()).isEqualTo(NETWORK_STATUS_ID); - assertThat(networkInfo.getName()).isEqualTo(NETWORK_STATUS_NAME); - assertThat(networkInfo.getSubnets()).hasSize(1).contains(SUBNET_NAME); - } - - private Network prepareNetwork(String networkStatus) { - Network network = new Network(); - network.setId(NETWORK_STATUS_ID); - network.setName(NETWORK_STATUS_NAME); - network.setStatus(networkStatus); - List<String> subnets = new ArrayList<>(); - subnets.add(SUBNET_NAME); - network.setSubnets(subnets); - return network; - } - - private Network prepareNetworkWithProvider(String networkStatus, String providerPhysicalNetwork, String providerNetworkType) { - Network network = prepareNetwork(networkStatus); - network.setProviderPhysicalNetwork(providerPhysicalNetwork); - network.setProviderNetworkType(providerNetworkType); - network.setProviderSegmentationId(PROVIDER_SEGMENTATION_ID); - return network; - } - - private Network prepareNetworkWithSegments(String networkStatus, Segment segment) { - Network network = prepareNetwork(networkStatus); - List<Segment> segments = new ArrayList<>(); - segments.add(segment); - network.setSegments(segments); - return network; - } - - private Segment prepareSegment(String providerNetworkType) { - Segment segment = new Segment(); - segment.setProviderPhysicalNetwork(PROVIDER_FOR_SEGMENT); - segment.setProviderNetworkType(providerNetworkType); - segment.setProviderSegmentationId(PROVIDER_SEGMENTATION_ID_FOR_SEGMENT); - return segment; - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java deleted file mode 100644 index 9c7911ef89..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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 org.openecomp.mso.openstack.beans; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.woorea.openstack.heat.model.Stack; -import java.io.IOException; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Test; - -public class StackInfoTest { - - private static final String STACK_NAME = "stackNameTest"; - private static final String STACK_STATUS = "CREATE_COMPLETE"; - private static final String STACK_OUTPUT_KEY = "outputKeyTest"; - private static final String STACK_OUTPUT_VALUE = "outputValueTest"; - private static final String STACK_PARAM_KEY = "paramKeyTest"; - private static final String STACK_PARAM_VALUE = "paramValueTest"; - - @Test - public void setStatusNotFoundWhenStackIsNull() { - StackInfo stackInfo = new StackInfo(null); - assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.NOTFOUND); - assertThat(stackInfo.getOutputs()).isEmpty(); - assertThat(stackInfo.getParameters()).isEmpty(); - } - - @Test - public void createObjectWhenStackStatusIsNull() { - StackInfo stackInfo = new StackInfo(createStackWithStatus(null)); - assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); - assertThat(stackInfo.getOutputs()).isEmpty(); - assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.INIT); - assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); - } - - @Test - public void createObjectWhenStackStatusIsFound() { - StackInfo stackInfo = new StackInfo(createStackWithStatus(STACK_STATUS)); - assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); - assertThat(stackInfo.getOutputs()).isEmpty(); - assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.CREATED); - assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); - } - - @Test - public void createObjectWhenStackStatusIsUnknown() { - StackInfo stackInfo = new StackInfo(createStackWithStatus("unknownStatus")); - assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); - assertThat(stackInfo.getOutputs()).isEmpty(); - assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.UNKNOWN); - assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); - } - - @Test - public void createStackWhenOutputsListIsNotNull() throws IOException { - StackInfo stackInfo = new StackInfo(createStackWithOutputs()); - assertThat(stackInfo.getOutputs()).isNotEmpty().hasSize(1); - assertThat(stackInfo.getOutputs()).hasSize(1).containsEntry(STACK_OUTPUT_KEY, STACK_OUTPUT_VALUE); - } - - private Stack createStackWithStatus(String stackStatus) { - Stack stack = new Stack(); - stack.setStackName(STACK_NAME); - stack.setStackStatus(stackStatus); - stack.getParameters().put(STACK_PARAM_KEY, STACK_PARAM_VALUE); - return stack; - } - - private Stack createStackWithOutputs() throws IOException { - String json = "{\"outputs\":[{\"output_key\" : \"" + STACK_OUTPUT_KEY + "\", \"output_value\" : \"" - + STACK_OUTPUT_VALUE + "\" }]}"; - JsonNode node = new ObjectMapper().readTree(json); - Stack stack = new ObjectMapper().readValue(node, Stack.class); - return stack; - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterTest.java deleted file mode 100644 index 17a94840cf..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.openstack.utils;
-
-import static org.mockito.Mockito.mock;
-
-import org.junit.Test;
-
-public class MsoHeatEnvironmentParameterTest {
-
- @Test
- public void test() {
- MsoHeatEnvironmentParameter hep=mock(MsoHeatEnvironmentParameter.class);
- Object op=hep.getName();
- MsoHeatEnvironmentParameter meo=new MsoHeatEnvironmentParameter();
- MsoHeatEnvironmentParameter mea=new MsoHeatEnvironmentParameter("name");
- MsoHeatEnvironmentParameter mep=new MsoHeatEnvironmentParameter("name"," value");
- mea.setName("name");
- mep.setValue("value");
- assert(mea.getName().equals("name"));
- assert(mep.getValue().equals("value"));
- assert(meo.toString()!=null);
- //assertTrue(op.equals(hep));
- meo.equals(op);
- meo.hashCode();
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceTest.java deleted file mode 100644 index fb666ea5df..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.openstack.utils;
-
-import org.junit.Test;
-
-
-public class MsoHeatEnvironmentResourceTest {
-
-
- @Test
- public void test() {
- Object op=true;
- // MsoHeatEnvironmentResource mer=mock(MsoHeatEnvironmentResource.class);
- // MsoHeatEnvironmentResource mrea=new MsoHeatEnvironmentResource();
- MsoHeatEnvironmentResource mre=new MsoHeatEnvironmentResource("name");
- MsoHeatEnvironmentResource mae=new MsoHeatEnvironmentResource("name", "value");
- mre.setName("name");
- mae.setValue("value");
- assert(mre.getName().equals("name"));
- assert(mae.getValue().equals("value"));
- assert(mre.toString()!=null);
- //assertFalse(mer.equals(op));
- mae.equals(op);
- mae.hashCode();
- //when(mer.hashCode()).thenReturn(result);
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java deleted file mode 100644 index 9ba9b2f39d..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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 org.openecomp.mso.openstack.utils; - - -import com.woorea.openstack.heat.Heat; -import com.woorea.openstack.heat.model.Stack; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.openecomp.mso.cloud.CloudConfigFactory; -import org.openecomp.mso.cloud.CloudSite; -import org.openecomp.mso.openstack.beans.HeatStatus; -import org.openecomp.mso.openstack.beans.StackInfo; -import org.openecomp.mso.openstack.exceptions.MsoException; -import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound; -import org.openecomp.mso.properties.MsoPropertiesFactory; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.doReturn; - -//@RunWith(PowerMockRunner.class) -@PrepareForTest({MsoHeatUtils.class}) - - -public class MsoHeatUtilsTest { - - @Mock - StackInfo stackInfo; - - @Mock - MsoPropertiesFactory msoPropertiesFactory; - - @Mock - CloudConfigFactory cloudConfigFactory; - - @Mock - Heat heatClient; - - @Mock - CloudSite cloudSite; - - @Test(expected = NullPointerException.class) - public void testCreateStack() throws MsoException - { - - MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); - Map<String,String>metadata=new HashMap<>(); - metadata.put("1", "value"); - mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1); - doReturn(mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1, - null, null, - null, - true)); - - } - - @Test(expected = NullPointerException.class) - public void testCreateStackOne() throws MsoException - { - MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); - Map<String,String>metadata=new HashMap<>(); - metadata.put("1", "value"); - mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1, - "env"); - doReturn(mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1, - "env", null, - null, - true)); - } - - @Test(expected = NullPointerException.class) - public void testCreateStackTwo() throws MsoException - { - MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); - Map<String,String>metadata=new HashMap<>(); - metadata.put("1", "value"); - Map<String,Object>fileMap=new HashMap<>(); - fileMap.put("2", "value"); - mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1, - "env", - fileMap); - doReturn(mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1, - "env", fileMap, - null, - true)); - } - - @Test(expected = NullPointerException.class) - public void testCreateStackThree() throws MsoException - { - MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); - Map<String,String>metadata=new HashMap<>(); - metadata.put("1", "value"); - Map<String,Object>fileMap=new HashMap<>(); - fileMap.put("2", "value"); - Map<String,Object>heatFileMap=new HashMap<>(); - heatFileMap.put("3", "value"); - mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1, - "env", - fileMap, - heatFileMap); - doReturn(mht.createStack("cloudSiteId", - "tenantId", - "stackName", - "heatTemplate", - metadata, - true, - 1, - "env", fileMap, - heatFileMap, - true)); - } - - @Test(expected = NullPointerException.class) - - - public void testqueryStack() throws MsoException - { - MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); - - mht.queryStack("cloudSiteId","tenantId","stackName"); - - try { - heatClient = mht.getHeatClient (cloudSite, "tenantId"); - assertNotNull(heatClient); - - } catch (MsoTenantNotFound e) { - doReturn(new StackInfo ("stackName", HeatStatus.NOTFOUND)); - } catch (MsoException me) { - - me.addContext ("QueryStack"); - throw me; - } - - Stack heatStack = mht.queryHeatStack (heatClient, "stackName"); - - assertNull(heatStack); - StackInfo stackInfo = new StackInfo ("stackName", HeatStatus.NOTFOUND); - doReturn(stackInfo); - - assertNotNull(heatStack); - doReturn(new StackInfo (heatStack)); - - - - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java deleted file mode 100644 index 74d512c63e..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java +++ /dev/null @@ -1,172 +0,0 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.openstack.utils;
-
-import static com.shazam.shazamcrest.MatcherAssert.assertThat;
-import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.openecomp.mso.adapters.vdu.CloudInfo;
-import org.openecomp.mso.adapters.vdu.PluginAction;
-import org.openecomp.mso.adapters.vdu.VduArtifact;
-import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;
-import org.openecomp.mso.adapters.vdu.VduInstance;
-import org.openecomp.mso.adapters.vdu.VduModelInfo;
-import org.openecomp.mso.adapters.vdu.VduStateType;
-import org.openecomp.mso.adapters.vdu.VduStatus;
-import org.openecomp.mso.cloud.CloudConfig;
-import org.openecomp.mso.cloud.CloudConfigFactory;
-import org.openecomp.mso.cloud.CloudSite;
-import org.openecomp.mso.cloudify.beans.DeploymentInfo;
-import org.openecomp.mso.cloudify.beans.DeploymentStatus;
-import org.openecomp.mso.cloudify.utils.MsoCloudifyUtils;
-import org.openecomp.mso.openstack.beans.HeatStatus;
-import org.openecomp.mso.openstack.beans.StackInfo;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-
-public class MsoHeatUtilsTest2 {
-
- @Test
- public void instantiateVduTest() throws MsoException, JsonProcessingException {
- VduInstance expected = new VduInstance();
- expected.setVduInstanceId("canonicalName");
- expected.setVduInstanceName("name");
- VduStatus status = new VduStatus();
- status.setState(VduStateType.INSTANTIATED);
- status.setLastAction((new PluginAction("create", "complete", "")));
- expected.setStatus(status);
-
- MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
- CloudSite site = new CloudSite();
- Optional<CloudSite> opSite = Optional.ofNullable(site);
- CloudConfig config = Mockito.mock(CloudConfig.class);
- CloudConfigFactory cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
- when(cloudConfigFactory.getCloudConfig()).thenReturn(config);
- when(heatUtils.getCloudConfigFactory()).thenReturn(cloudConfigFactory);
- CloudInfo cloudInfo = new CloudInfo();
- cloudInfo.setCloudSiteId("cloudSiteId");
- cloudInfo.setTenantId("tenantId");
- VduModelInfo vduModel = new VduModelInfo();
- vduModel.setModelCustomizationUUID("blueprintId");
- vduModel.setTimeoutMinutes(1);
- VduArtifact artifact = new VduArtifact();
- artifact.setName("name");
- artifact.setType(ArtifactType.MAIN_TEMPLATE);
- byte[] content = new byte[1];
- artifact.setContent(content);
- List<VduArtifact> artifacts = new ArrayList<>();
- artifacts.add(artifact);
- vduModel.setArtifacts(artifacts);
- Map<String, byte[]> blueprintFiles = new HashMap<>();
- blueprintFiles.put(artifact.getName(), artifact.getContent());
- String instanceName = "instanceName";
- Map<String, Object> inputs = new HashMap<>();
- boolean rollbackOnFailure = true;
- String heatTemplate = new String(artifact.getContent());
- when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite);
- Map<String, Object> nestedTemplates = new HashMap<String, Object>();
- Map<String, Object> files = new HashMap<String, Object>();
-
- StackInfo stackInfo = new StackInfo();
- stackInfo.setCanonicalName("canonicalName");
- stackInfo.setName("name");
- stackInfo.setStatus(HeatStatus.CREATED);
-
- doReturn(stackInfo).when(heatUtils).createStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(),
- instanceName, heatTemplate, inputs, true, vduModel.getTimeoutMinutes(), null, nestedTemplates, files,
- rollbackOnFailure);
-
- VduInstance actual = heatUtils.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void queryVduTest() throws MsoException, JsonProcessingException {
- VduInstance expected = new VduInstance();
- expected.setVduInstanceId("canonicalName");
- expected.setVduInstanceName("name");
- VduStatus status = new VduStatus();
- status.setState(VduStateType.INSTANTIATED);
- status.setLastAction((new PluginAction("create", "complete", "")));
- expected.setStatus(status);
-
- CloudInfo cloudInfo = new CloudInfo();
- cloudInfo.setCloudSiteId("cloudSiteId");
- cloudInfo.setTenantId("tenantId");
- String instanceId = "instanceId";
-
- StackInfo stackInfo = new StackInfo();
- stackInfo.setCanonicalName("canonicalName");
- stackInfo.setName("name");
- stackInfo.setStatus(HeatStatus.CREATED);
-
- MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
-
- doReturn(stackInfo).when(heatUtils).queryStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), instanceId);
-
- VduInstance actual = heatUtils.queryVdu(cloudInfo, instanceId);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void deleteVduTest() throws MsoException {
- VduInstance expected = new VduInstance();
- expected.setVduInstanceId("canonicalName");
- expected.setVduInstanceName("name");
- VduStatus status = new VduStatus();
- status.setState(VduStateType.DELETED);
- expected.setStatus(status);
-
- CloudInfo cloudInfo = new CloudInfo();
- cloudInfo.setCloudSiteId("cloudSiteId");
- cloudInfo.setTenantId("tenantId");
- String instanceId = "instanceId";
-
- StackInfo stackInfo = new StackInfo();
- stackInfo.setCanonicalName("canonicalName");
- stackInfo.setName("name");
- stackInfo.setStatus(HeatStatus.NOTFOUND);
-
- int timeoutInMinutes = 1;
-
- MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
-
- doReturn(stackInfo).when(heatUtils).deleteStack( cloudInfo.getTenantId(), cloudInfo.getCloudSiteId(), instanceId, true);
-
- VduInstance actual = heatUtils.deleteVdu(cloudInfo, instanceId, timeoutInMinutes);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java deleted file mode 100644 index f2d14d8b22..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.openstack.utils;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.openecomp.mso.cloud.CloudConfig;
-import org.openecomp.mso.cloud.CloudConfigFactory;
-import org.openecomp.mso.cloud.CloudIdentity;
-import org.openecomp.mso.cloud.CloudSite;
-import org.openecomp.mso.openstack.beans.MsoTenant;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-import org.openecomp.mso.properties.MsoJavaProperties;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import com.woorea.openstack.keystone.Keystone;
-import com.woorea.openstack.keystone.model.Tenant;
-
-//@RunWith(PowerMockRunner.class)
-@PrepareForTest({MsoKeystoneUtils.class,CloudSite.class,CloudIdentity.class,Tenant.class,Keystone.class,MsoTenant.class,MsoJavaProperties.class})
-public class MsoKeystoneUtilsTest {
-
- @Mock
- Tenant tenant;
-
- @Mock
- Keystone adminClient;
-
- @Mock
- MsoTenant mst;
-
- @Mock
- CloudSite cs;
-
- @Mock
- CloudIdentity cloudIdentity;
-
- @Mock
- MsoJavaProperties msoProps;
-
- @Mock
- private static CloudConfigFactory cloudConfigFactory;
-
- @BeforeClass
- public static final void prepare () {
- cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
- CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
- Mockito.when(cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
- }
-
- @Test
- public void testcreateTenant() throws MsoException{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
- Map<String,String>metadata=new HashMap<>();
- metadata.put("1", "value");
- tenant = mock(Tenant.class);
- PowerMockito.when(tenant.getId ()).thenReturn("ID");
- doReturn(tenant.getId ()).when(msk).createTenant("tenantName", "cloudSiteId", metadata, true);
- PowerMockito.spy(tenant.getId ());
- String Id = msk.createTenant("tenantName", "cloudSiteId", metadata, true);
- Assert.assertEquals(tenant.getId (), Id);
- assert(msk.createTenant("tenantName", "cloudSiteId", metadata, true)!=null);
- }
- @Test
- public void testdeleteTenant() throws MsoException{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
- doReturn(true).when(msk).deleteTenant("tenantId", "cloudSiteId");
- assertTrue(msk.deleteTenant("tenantId", "cloudSiteId"));
- }
- @Test
- public void testfindTenantByName() throws Exception{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
- doReturn(null).when(msk).findTenantByName(adminClient, "tenantName");
- assertNull(msk.findTenantByName(adminClient, "tenantName"));
- }
- @Test
- public void testqueryTenant() throws MsoException{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
- Map<String,String>metadata=new HashMap<>();
- metadata.put("1", "value");
- mst = mock(MsoTenant.class);
- PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");
- PowerMockito.when(mst.getMetadata()).thenReturn(metadata);
- PowerMockito.when(mst.getTenantName()).thenReturn("name");
- doReturn(mst).when(msk).queryTenant ("tenantId", "cloudSiteId");
- assertNotNull(msk.queryTenant("tenantId", "cloudSiteId"));
- }
-
- @Test
- public void testqueryTenantByName()throws MsoException {
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
- Map<String,String>metadata=new HashMap<>();
- metadata.put("1", "value");
- mst = mock(MsoTenant.class);
- PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");
- PowerMockito.when(mst.getMetadata()).thenReturn(metadata);
- PowerMockito.when(mst.getTenantName()).thenReturn("name");
- doReturn(mst).when(msk).queryTenantByName ("tenantId", "cloudSiteId");
- assertNotNull(msk.queryTenantByName("tenantId", "cloudSiteId"));
-
- }
-
- @Test
- public void testgetKeystoneAdminClient() throws MsoException{
- cloudIdentity = mock(CloudIdentity.class);
- Keystone keystone = new Keystone (cloudIdentity.getKeystoneUrl ("region", "msoPropID"));
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
- doReturn(keystone).when(msk).getKeystoneAdminClient(cs);
- assertNotNull(msk.getKeystoneAdminClient(cs));
- }
-}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java deleted file mode 100644 index 839da370df..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.openstack.utils;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.openecomp.mso.cloud.CloudConfig;
-import org.openecomp.mso.cloud.CloudConfigFactory;
-import org.openecomp.mso.cloud.CloudSite;
-import org.openecomp.mso.openstack.beans.NetworkInfo;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-import org.openecomp.mso.openstack.utils.MsoNeutronUtils.NetworkType;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import com.woorea.openstack.quantum.Quantum;
-import com.woorea.openstack.quantum.model.Network;
-import com.woorea.openstack.quantum.model.Segment;
-
-
-//@RunWith(PowerMockRunner.class)
-@PrepareForTest({MsoNeutronUtils.class,MsoCommonUtils.class,NetworkInfo.class,CloudConfigFactory.class,CloudConfig.class,Segment.class,Network.class,Quantum.class})
-public class MsoNeutronUtilsTest{
-
-@Mock
-MsoCommonUtils utils;
-
-@Mock
-NetworkInfo net;
-
-@Mock
-CloudConfig cloudConfig;
-
-@Mock
-Segment segment;
-
-@Mock
-CloudConfigFactory cloudConfigFactory;
-
-@Mock
-Network network;
-
-@Mock
-NetworkInfo ninfo;
-
-@Mock
-Quantum neutronClient;
-
-@Mock
-CloudSite cloudSite;
-
-
- @Test
- public void testcreateNetwork() throws MsoException{
- List<Integer> vlans=new ArrayList();
- vlans.add(1);
- cloudConfigFactory = mock(CloudConfigFactory.class);
- ninfo = mock(NetworkInfo.class);
- MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
- NetworkType type=NetworkType.PROVIDER;
- doReturn(ninfo).when(mnu).createNetwork("cloudSiteId", "tenantId", type, "networkName", "provider", vlans);
- assert(mnu.createNetwork("cloudSiteId", "tenantId", type, "networkName", "provider", vlans)!=null);
-
- }
- @Test
- public void testqueryNetwork() throws MsoException{
- cloudConfigFactory = mock(CloudConfigFactory.class);
- ninfo = mock(NetworkInfo.class);
- MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
- doReturn(ninfo).when(mnu).queryNetwork("networkNameOrId", "tenantId", "cloudSiteId");
- NetworkInfo ni = mnu.queryNetwork("networkNameOrId", "tenantId", "cloudSiteId");
- assert(ni!=null);
- }
-
- @Test
- public void testdeleteNetwork() throws MsoException{
- cloudConfigFactory = mock(CloudConfigFactory.class);
- MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
- doReturn(true).when(mnu).deleteNetwork("networkId", "tenantId", "cloudSiteId");
- assertTrue(mnu.deleteNetwork("networkId", "tenantId", "cloudSiteId"));
-
- }
- @Test
- public void testupdateNetwork() throws MsoException{
- List<Integer> vlans=new ArrayList();
- vlans.add(1);
- NetworkType type=NetworkType.PROVIDER;
- cloudConfigFactory = mock(CloudConfigFactory.class);
- ninfo = mock(NetworkInfo.class);
- MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
- doReturn(ninfo).when(mnu).updateNetwork("cloudSiteId", "tenantId", "Nid", type, "provider", vlans);
- assert(mnu.updateNetwork("cloudSiteId", "tenantId", "Nid", type, "provider", vlans)!=null);
- }
-
- }
-
-
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactoryTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactoryTest.java deleted file mode 100644 index a759e0d1a6..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactoryTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.openstack.utils;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.junit.Test;
-import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
-
-public class MsoTenantUtilsFactoryTest {
-
- MsoTenantUtils tenantU = null;
-
- @Test
- public void test() throws MsoCloudSiteNotFound {
- tenantU = mock( MsoKeystoneUtils.class);
- new MsoTenantUtilsFactory("ID");
- MsoTenantUtilsFactory mti=mock(MsoTenantUtilsFactory.class);
- mti.getTenantUtils("cloudSiteId");
- when(mti.getTenantUtils("cloudSiteId")).thenReturn(tenantU);
- mti.getTenantUtilsByServerType("type");
- when(mti.getTenantUtilsByServerType("type")).thenReturn(tenantU);
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsTest.java deleted file mode 100644 index ffb1e3b787..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.openstack.utils;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.openecomp.mso.cloud.CloudIdentity;
-
-@RunWith(MockitoJUnitRunner.class)
-public class MsoTenantUtilsTest {
-
- @Test
- public void test()throws Exception {
- MsoTenantUtils mtu =mock(MsoTenantUtils.class);
- //MsoTenantUtils mki = null;
- CloudIdentity cloudIdentity=mock(CloudIdentity.class);
- Map <String, String> metadata=new HashMap<>();
- mtu.createTenant("name", "id", metadata, true);
- verify(mtu).createTenant("name", "id", metadata, true);
- mtu.queryTenant("tenantId", "cloudSiteId");
- verify(mtu).queryTenant("tenantId", "cloudSiteId");
- mtu.deleteTenant("tenantId", "cloudSiteId");
- verify(mtu).deleteTenant("tenantId", "cloudSiteId");
- mtu.getKeystoneUrl("regionId", "msoPropID", cloudIdentity);
- verify(mtu).getKeystoneUrl("regionId", "msoPropID", cloudIdentity);
- mtu.queryTenantByName("tenantName", "cloudSiteId");
- verify(mtu).queryTenantByName("tenantName", "cloudSiteId");
-
- }
-}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvtTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvtTest.java deleted file mode 100644 index 3dee177dee..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvtTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/*
-* ============LICENSE_START=======================================================
-* ONAP : SO
-* ================================================================================
-* Copyright 2018 TechMahindra
-*=================================================================================
-* 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.openecomp.mso.openstack.utils;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import java.util.HashSet;
-import java.util.Set;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
-import org.powermock.api.mockito.PowerMockito;
-
-public class MsoYamlEditorWithEnvtTest {
-
- @Mock
- MsoHeatEnvironmentParameter mhep;
-
- @Mock
- HeatTemplateParam hep;
-
- @Test
- public void testgetParameterList() {
- Set<HeatTemplateParam> paramSet = new HashSet<>();
- paramSet.add(hep);
- mhep=PowerMockito.spy(new MsoHeatEnvironmentParameter());
- MsoYamlEditorWithEnvt Mso=mock(MsoYamlEditorWithEnvt.class);
- when(Mso.getParameterList()).thenReturn(paramSet);
- assert(Mso.getParameterList()!=null);
- }
-
- @Test
- public void testgetResourceLisstFromEnvt() {
- Set<MsoHeatEnvironmentParameter> paramSet = new HashSet<>();
- paramSet.add(mhep);
- new MsoHeatEnvironmentResource();;
- mhep=PowerMockito.spy(new MsoHeatEnvironmentParameter());
- MsoYamlEditorWithEnvt Mso=mock(MsoYamlEditorWithEnvt.class);
- when(Mso.getParameterListFromEnvt()).thenReturn(paramSet);
- }
-
- @Test
- public void getParameterListFromEnvt() {
- mhep=PowerMockito.spy(new MsoHeatEnvironmentParameter());
- Set<MsoHeatEnvironmentParameter> paramSet = new HashSet<>();
- paramSet.add(mhep);
- new MsoHeatEnvironmentResource();;
- MsoYamlEditorWithEnvt Mso=mock(MsoYamlEditorWithEnvt.class);
- when(Mso.getParameterListFromEnvt()).thenReturn(paramSet);
- }
-
-}
|