--- /dev/null
+/*\r
+* ============LICENSE_START=======================================================\r
+* ONAP : SO\r
+* ================================================================================\r
+* Copyright 2018 TechMahindra\r
+*=================================================================================\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+* ============LICENSE_END=========================================================\r
+*/\r
+\r
+package org.openecomp.mso.openstack.utils;\r
+\r
+import static org.mockito.Mockito.mock;\r
+\r
+import org.junit.Test;\r
+\r
+public class MsoHeatEnvironmentParameterTest {\r
+\r
+ @Test\r
+ public void test() {\r
+ MsoHeatEnvironmentParameter hep=mock(MsoHeatEnvironmentParameter.class);\r
+ Object op=hep.getName();\r
+ MsoHeatEnvironmentParameter meo=new MsoHeatEnvironmentParameter();\r
+ MsoHeatEnvironmentParameter mea=new MsoHeatEnvironmentParameter("name");\r
+ MsoHeatEnvironmentParameter mep=new MsoHeatEnvironmentParameter("name"," value");\r
+ mea.setName("name");\r
+ mep.setValue("value");\r
+ assert(mea.getName().equals("name"));\r
+ assert(mep.getValue().equals("value"));\r
+ assert(meo.toString()!=null);\r
+ //assertTrue(op.equals(hep));\r
+ meo.equals(op);\r
+ meo.hashCode();\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+* ============LICENSE_START=======================================================\r
+* ONAP : SO\r
+* ================================================================================\r
+* Copyright 2018 TechMahindra\r
+*=================================================================================\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+* ============LICENSE_END=========================================================\r
+*/\r
+\r
+package org.openecomp.mso.openstack.utils;\r
+\r
+import org.junit.Test;\r
+\r
+\r
+public class MsoHeatEnvironmentResourceTest {\r
+\r
+ \r
+ @Test\r
+ public void test() {\r
+ Object op=true;\r
+ // MsoHeatEnvironmentResource mer=mock(MsoHeatEnvironmentResource.class);\r
+ // MsoHeatEnvironmentResource mrea=new MsoHeatEnvironmentResource();\r
+ MsoHeatEnvironmentResource mre=new MsoHeatEnvironmentResource("name");\r
+ MsoHeatEnvironmentResource mae=new MsoHeatEnvironmentResource("name", "value");\r
+ mre.setName("name");\r
+ mae.setValue("value");\r
+ assert(mre.getName().equals("name"));\r
+ assert(mae.getValue().equals("value"));\r
+ assert(mre.toString()!=null);\r
+ //assertFalse(mer.equals(op));\r
+ mae.equals(op);\r
+ mae.hashCode();\r
+ //when(mer.hashCode()).thenReturn(result);\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+* ============LICENSE_START=======================================================\r
+* ONAP : SO\r
+* ================================================================================\r
+* Copyright 2018 TechMahindra\r
+*=================================================================================\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+* ============LICENSE_END=========================================================\r
+*/\r
+\r
+package org.openecomp.mso.openstack.utils;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.doReturn;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.openecomp.mso.cloud.CloudIdentity;\r
+import org.openecomp.mso.cloud.CloudSite;\r
+import org.openecomp.mso.openstack.beans.MsoTenant;\r
+import org.openecomp.mso.openstack.exceptions.MsoException;\r
+import org.openecomp.mso.properties.MsoJavaProperties;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+\r
+import com.woorea.openstack.keystone.Keystone;\r
+import com.woorea.openstack.keystone.model.Tenant;\r
+\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({MsoKeystoneUtils.class,CloudSite.class,CloudIdentity.class,Tenant.class,Keystone.class,MsoTenant.class,MsoJavaProperties.class})\r
+public class MsoKeystoneUtilsTest {\r
+ \r
+ @Mock\r
+ Tenant tenant;\r
+\r
+ @Mock\r
+ Keystone adminClient;\r
+ \r
+ @Mock\r
+ MsoTenant mst;\r
+ \r
+ @Mock\r
+ CloudSite cs;\r
+ \r
+ @Mock\r
+ CloudIdentity cloudIdentity;\r
+ \r
+ @Mock\r
+ MsoJavaProperties msoProps;\r
+\r
+ @Test\r
+ public void testcreateTenant() throws MsoException{\r
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));\r
+ Map<String,String>metadata=new HashMap<>();\r
+ metadata.put("1", "value");\r
+ PowerMockito.when(tenant.getId ()).thenReturn("ID");\r
+ doReturn(tenant.getId ()).when(msk).createTenant("tenantName", "cloudSiteId", metadata, true);\r
+ PowerMockito.spy(tenant.getId ());\r
+ String Id = msk.createTenant("tenantName", "cloudSiteId", metadata, true);\r
+ Assert.assertEquals(tenant.getId (), Id);\r
+ assert(msk.createTenant("tenantName", "cloudSiteId", metadata, true)!=null);\r
+ }\r
+ @Test\r
+ public void testdeleteTenant() throws MsoException{\r
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));\r
+ doReturn(true).when(msk).deleteTenant("tenantId", "cloudSiteId");\r
+ assertTrue(msk.deleteTenant("tenantId", "cloudSiteId"));\r
+ }\r
+ @Test\r
+ public void testfindTenantByName() throws Exception{\r
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));\r
+ doReturn(null).when(msk).findTenantByName(adminClient, "tenantName");\r
+ assertNull(msk.findTenantByName(adminClient, "tenantName"));\r
+ }\r
+ @Test\r
+ public void testqueryTenant() throws MsoException{\r
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));\r
+ Map<String,String>metadata=new HashMap<>();\r
+ metadata.put("1", "value"); \r
+ PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");\r
+ PowerMockito.when(mst.getMetadata()).thenReturn(metadata);\r
+ PowerMockito.when(mst.getTenantName()).thenReturn("name");\r
+ doReturn(mst).when(msk).queryTenant ("tenantId", "cloudSiteId");\r
+ assertNotNull(msk.queryTenant("tenantId", "cloudSiteId")); \r
+ }\r
+ \r
+ @Test\r
+ public void testqueryTenantByName()throws MsoException {\r
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));\r
+ Map<String,String>metadata=new HashMap<>();\r
+ metadata.put("1", "value"); \r
+ PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");\r
+ PowerMockito.when(mst.getMetadata()).thenReturn(metadata);\r
+ PowerMockito.when(mst.getTenantName()).thenReturn("name");\r
+ doReturn(mst).when(msk).queryTenantByName ("tenantId", "cloudSiteId");\r
+ assertNotNull(msk.queryTenantByName("tenantId", "cloudSiteId")); \r
+ \r
+ }\r
+ \r
+ @Test\r
+ public void testgetKeystoneAdminClient() throws MsoException{\r
+ Keystone keystone = new Keystone (cloudIdentity.getKeystoneUrl ("region", "msoPropID"));\r
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));\r
+ doReturn(keystone).when(msk).getKeystoneAdminClient(cs);\r
+ assertNotNull(msk.getKeystoneAdminClient(cs));\r
+ }\r
+ \r
+ }\r
--- /dev/null
+/*\r
+* ============LICENSE_START=======================================================\r
+* ONAP : SO\r
+* ================================================================================\r
+* Copyright 2018 TechMahindra\r
+*=================================================================================\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+* ============LICENSE_END=========================================================\r
+*/\r
+\r
+package org.openecomp.mso.openstack.utils;\r
+\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.doReturn;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.openecomp.mso.cloud.CloudConfig;\r
+import org.openecomp.mso.cloud.CloudConfigFactory;\r
+import org.openecomp.mso.cloud.CloudSite;\r
+import org.openecomp.mso.openstack.beans.NetworkInfo;\r
+import org.openecomp.mso.openstack.exceptions.MsoException;\r
+import org.openecomp.mso.openstack.utils.MsoNeutronUtils.NetworkType;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+\r
+import com.woorea.openstack.quantum.Quantum;\r
+import com.woorea.openstack.quantum.model.Network;\r
+import com.woorea.openstack.quantum.model.Segment;\r
+\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({MsoNeutronUtils.class,MsoCommonUtils.class,NetworkInfo.class,CloudConfigFactory.class,CloudConfig.class,Segment.class,Network.class,Quantum.class})\r
+public class MsoNeutronUtilsTest{\r
+\r
+@Mock\r
+MsoCommonUtils utils;\r
+\r
+@Mock\r
+NetworkInfo net;\r
+\r
+@Mock\r
+CloudConfig cloudConfig;\r
+\r
+@Mock\r
+Segment segment;\r
+\r
+@Mock\r
+CloudConfigFactory cloudConfigFactory;\r
+\r
+@Mock\r
+Network network;\r
+\r
+@Mock\r
+NetworkInfo ninfo;\r
+\r
+@Mock\r
+Quantum neutronClient;\r
+\r
+@Mock\r
+CloudSite cloudSite;\r
+\r
+\r
+ @Test\r
+ public void testcreateNetwork() throws MsoException{\r
+ List<Integer> vlans=new ArrayList();\r
+ vlans.add(1);\r
+ MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));\r
+ NetworkType type=NetworkType.PROVIDER;\r
+ doReturn(ninfo).when(mnu).createNetwork("cloudSiteId", "tenantId", type, "networkName", "provider", vlans);\r
+ assert(mnu.createNetwork("cloudSiteId", "tenantId", type, "networkName", "provider", vlans)!=null);\r
+ \r
+ }\r
+ @Test\r
+ public void testqueryNetwork() throws MsoException{\r
+ MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));\r
+ doReturn(ninfo).when(mnu).queryNetwork("networkNameOrId", "tenantId", "cloudSiteId");\r
+ assert(mnu.queryNetwork("networkNameOrId", "tenantId", "cloudSiteId")!=null);\r
+ }\r
+ \r
+ @Test\r
+ public void testdeleteNetwork() throws MsoException{\r
+ MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));\r
+ doReturn(true).when(mnu).deleteNetwork("networkId", "tenantId", "cloudSiteId");\r
+ assertTrue(mnu.deleteNetwork("networkId", "tenantId", "cloudSiteId"));\r
+ \r
+ }\r
+ @Test\r
+ public void testupdateNetwork() throws MsoException{\r
+ List<Integer> vlans=new ArrayList();\r
+ vlans.add(1);\r
+ NetworkType type=NetworkType.PROVIDER;\r
+ MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));\r
+ doReturn(ninfo).when(mnu).updateNetwork("cloudSiteId", "tenantId", "Nid", type, "provider", vlans);\r
+ assert(mnu.updateNetwork("cloudSiteId", "tenantId", "Nid", type, "provider", vlans)!=null);\r
+ } \r
+ \r
+ }\r
+\r
+\r
--- /dev/null
+/*\r
+* ============LICENSE_START=======================================================\r
+* ONAP : SO\r
+* ================================================================================\r
+* Copyright 2018 TechMahindra\r
+*=================================================================================\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+* ============LICENSE_END=========================================================\r
+*/\r
+\r
+package org.openecomp.mso.openstack.utils;\r
+\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.when;\r
+\r
+import org.junit.Test;\r
+import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;\r
+\r
+public class MsoTenantUtilsFactoryTest {\r
+ \r
+ MsoTenantUtils tenantU = null;\r
+ \r
+ @Test\r
+ public void test() throws MsoCloudSiteNotFound {\r
+ tenantU = mock( MsoKeystoneUtils.class);\r
+ new MsoTenantUtilsFactory("ID");\r
+ MsoTenantUtilsFactory mti=mock(MsoTenantUtilsFactory.class);\r
+ mti.getTenantUtils("cloudSiteId");\r
+ when(mti.getTenantUtils("cloudSiteId")).thenReturn(tenantU);\r
+ mti.getTenantUtilsByServerType("type");\r
+ when(mti.getTenantUtilsByServerType("type")).thenReturn(tenantU);\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+* ============LICENSE_START=======================================================\r
+* ONAP : SO\r
+* ================================================================================\r
+* Copyright 2018 TechMahindra\r
+*=================================================================================\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+* ============LICENSE_END=========================================================\r
+*/\r
+\r
+package org.openecomp.mso.openstack.utils;\r
+\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.openecomp.mso.cloud.CloudIdentity;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class MsoTenantUtilsTest {\r
+\r
+ @Test\r
+ public void test()throws Exception {\r
+ MsoTenantUtils mtu =mock(MsoTenantUtils.class);\r
+ //MsoTenantUtils mki = null;\r
+ CloudIdentity cloudIdentity=mock(CloudIdentity.class);\r
+ Map <String, String> metadata=new HashMap<>();\r
+ mtu.createTenant("name", "id", metadata, true);\r
+ verify(mtu).createTenant("name", "id", metadata, true);\r
+ mtu.queryTenant("tenantId", "cloudSiteId");\r
+ verify(mtu).queryTenant("tenantId", "cloudSiteId");\r
+ mtu.deleteTenant("tenantId", "cloudSiteId");\r
+ verify(mtu).deleteTenant("tenantId", "cloudSiteId");\r
+ mtu.getKeystoneUrl("regionId", "msoPropID", cloudIdentity);\r
+ verify(mtu).getKeystoneUrl("regionId", "msoPropID", cloudIdentity);\r
+ mtu.queryTenantByName("tenantName", "cloudSiteId");\r
+ verify(mtu).queryTenantByName("tenantName", "cloudSiteId");\r
+\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+* ============LICENSE_START=======================================================\r
+* ONAP : SO\r
+* ================================================================================\r
+* Copyright 2018 TechMahindra\r
+*=================================================================================\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+* ============LICENSE_END=========================================================\r
+*/\r
+\r
+package org.openecomp.mso.openstack.utils;\r
+\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.when;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;\r
+import org.powermock.api.mockito.PowerMockito;\r
+\r
+public class MsoYamlEditorWithEnvtTest {\r
+ \r
+ @Mock\r
+ MsoHeatEnvironmentParameter mhep;\r
+ \r
+ @Mock\r
+ HeatTemplateParam hep;\r
+\r
+ @Test\r
+ public void testgetParameterList() {\r
+ Set<HeatTemplateParam> paramSet = new HashSet<>();\r
+ paramSet.add(hep);\r
+ mhep=PowerMockito.spy(new MsoHeatEnvironmentParameter());\r
+ MsoYamlEditorWithEnvt Mso=mock(MsoYamlEditorWithEnvt.class);\r
+ when(Mso.getParameterList()).thenReturn(paramSet);\r
+ assert(Mso.getParameterList()!=null);\r
+ }\r
+ \r
+ @Test\r
+ public void testgetResourceLisstFromEnvt() {\r
+ Set<MsoHeatEnvironmentParameter> paramSet = new HashSet<>();\r
+ paramSet.add(mhep);\r
+ new MsoHeatEnvironmentResource();;\r
+ mhep=PowerMockito.spy(new MsoHeatEnvironmentParameter());\r
+ MsoYamlEditorWithEnvt Mso=mock(MsoYamlEditorWithEnvt.class);\r
+ when(Mso.getParameterListFromEnvt()).thenReturn(paramSet);\r
+ }\r
+ \r
+ @Test\r
+ public void getParameterListFromEnvt() {\r
+ mhep=PowerMockito.spy(new MsoHeatEnvironmentParameter());\r
+ Set<MsoHeatEnvironmentParameter> paramSet = new HashSet<>();\r
+ paramSet.add(mhep);\r
+ new MsoHeatEnvironmentResource();;\r
+ MsoYamlEditorWithEnvt Mso=mock(MsoYamlEditorWithEnvt.class);\r
+ when(Mso.getParameterListFromEnvt()).thenReturn(paramSet);\r
+ }\r
+\r
+}\r