diff options
Diffstat (limited to 'adapters')
27 files changed, 1989 insertions, 1997 deletions
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 index 250211845f..045b62df85 100644 --- 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 @@ -26,6 +26,7 @@ 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;
@@ -35,125 +36,125 @@ 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 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 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 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 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();
- }
+ @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 index 73bd67723d..0316e4b74c 100644 --- 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 @@ -47,84 +47,82 @@ 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)); + 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); + @Test + public final void testKeystoneErrorToMsoException() { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); - MsoException me = super.keystoneErrorToMsoException (openStackConnectException,"ContextError"); + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1); - assertTrue(me instanceof MsoIOException); - assertTrue("connect".equals(me.getMessage())); + 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())); - } + 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); + @Test + public final void testHeatExceptionToMsoException() { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); - MsoException me = super.heatExceptionToMsoException (openStackConnectException,"ContextError"); + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1); - assertTrue(me instanceof MsoIOException); - assertTrue("connect".equals(me.getMessage())); + 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"); + MsoException me2 = super.heatExceptionToMsoException(openStackResponseException, "ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + } - OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); + @Test + public final void testNeutronExceptionToMsoException() { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); - MsoException me = super.neutronExceptionToMsoException (openStackConnectException,"ContextError"); + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1); - assertTrue(me instanceof MsoIOException); - assertTrue("connect".equals(me.getMessage())); + MsoException me = super.neutronExceptionToMsoException(openStackConnectException, "ContextError"); - MsoException me2 = super.neutronExceptionToMsoException (openStackResponseException,"ContextError"); - assertTrue(me2 instanceof MsoOpenstackException); - assertTrue("ContextError".equals(me2.getContext())); - assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); - } + assertTrue(me instanceof MsoIOException); + assertTrue("connect".equals(me.getMessage())); - @Test - public final void testRuntimeExceptionToMsoException () { - RuntimeException re = new RuntimeException ("runtime"); - MsoException me = super.runtimeExceptionToMsoException (re, "ContextError"); + MsoException me2 = super.neutronExceptionToMsoException(openStackResponseException, "ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + } - assertTrue (me instanceof MsoAdapterException); - assertTrue("ContextError".equals(me.getContext())); + @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 index c2d4f9ba60..84b3fb4f91 100644 --- 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 @@ -40,119 +40,117 @@ 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 { - ClassLoader classLoader = CloudConfigTest.class.getClassLoader(); - String config = classLoader.getResource("cloud_config.json").toString().substring(5); - cloudConfigFactory.initializeCloudConfig(config, 1); - 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 { - try { - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, - "environment"); - } catch (MsoIOException e) { - - } - - } - - @Test - public final void createStackSuccessWithFiles() throws MsoException { - try { - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, - "environment", new HashMap<>()); - } catch (MsoIOException e) { - - } - - } - - @Test - public final void createStackSuccessWithHeatFiles() throws MsoException { - try { - msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, - "environment", new HashMap<>(), new HashMap<>()); - } catch (MsoIOException e) { - - } - } - - @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(); - } + public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); + public static MsoHeatUtils msoHeatUtils; + + @BeforeClass + public static final void loadClasses() throws MsoCloudIdentityNotFound { + ClassLoader classLoader = CloudConfigTest.class.getClassLoader(); + String config = classLoader.getResource("cloud_config.json").toString().substring(5); + cloudConfigFactory.initializeCloudConfig(config, 1); + 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 { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, + "environment"); + } catch (MsoIOException e) { + + } + + } + + @Test + public final void createStackSuccessWithFiles() throws MsoException { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, + "environment", new HashMap<>()); + } catch (MsoIOException e) { + + } + + } + + @Test + public final void createStackSuccessWithHeatFiles() throws MsoException { + try { + msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<>(), Boolean.TRUE, 10, + "environment", new HashMap<>(), new HashMap<>()); + } catch (MsoIOException e) { + + } + } + + @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(); + } } 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/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java index 62043e83b8..47ffff8941 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/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java @@ -27,6 +27,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; + import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -50,86 +51,86 @@ 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(); - + public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); + @Mock CloudConfig cloudConfig; @InjectMocks - MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate("NO_PROP",msoPropertiesFactory,cloudConfigFactory); + MsoHeatUtilsWithUpdate util = new MsoHeatUtilsWithUpdate("NO_PROP", msoPropertiesFactory, cloudConfigFactory); private CloudSite cloudSite; @Before - public void init () { - cloudSite = new CloudSite (); - cloudSite.setId ("cloud"); - CloudIdentity cloudIdentity = new CloudIdentity (); + public void init() { + cloudSite = new CloudSite(); + cloudSite.setId("cloud"); + CloudIdentity cloudIdentity = new CloudIdentity(); cloudIdentity.setIdentityServerType(IdentityServerType.KEYSTONE); - cloudIdentity.setKeystoneUrl ("toto"); - cloudIdentity.setMsoPass (CloudIdentity.encryptPassword ("mockId")); - cloudSite.setIdentityService (cloudIdentity); - when(cloudConfig.getCloudSite("cloud")).thenReturn (Optional.of(cloudSite)); - when(cloudConfig.getCloudSite("none")).thenReturn (Optional.empty()); + cloudIdentity.setKeystoneUrl("toto"); + cloudIdentity.setMsoPass(CloudIdentity.encryptPassword("mockId")); + cloudSite.setIdentityService(cloudIdentity); + when(cloudConfig.getCloudSite("cloud")).thenReturn(Optional.of(cloudSite)); + when(cloudConfig.getCloudSite("none")).thenReturn(Optional.empty()); } @Test @Ignore - public void testUpdateStack () { + public void testUpdateStack() { // Heat heat = Mockito.mock (Heat.class); - Map <String, Object> stackInputs = new HashMap <> (); + Map<String, Object> stackInputs = new HashMap<>(); try { - util.updateStack ("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1); + util.updateStack("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1); } catch (MsoException e) { if (e instanceof MsoCloudSiteNotFound) { // Ok } else { - e.printStackTrace (); - fail ("Exception caught"); + e.printStackTrace(); + fail("Exception caught"); } } try { - util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1); + util.updateStack("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1); } catch (MsoException e) { - if (e instanceof MsoIOException && e.getCause () != null - && e.getCause () instanceof OpenStackConnectException) { + if (e instanceof MsoIOException && e.getCause() != null + && e.getCause() instanceof OpenStackConnectException) { // Ok, we were able to go up to the connection to OpenStack } else { - e.printStackTrace (); - fail ("Exception caught"); + e.printStackTrace(); + fail("Exception caught"); } } try { - util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment"); + util.updateStack("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment"); } catch (MsoException e) { - if (e instanceof MsoIOException && e.getCause () != null - && e.getCause () instanceof OpenStackConnectException) { + if (e instanceof MsoIOException && e.getCause() != null + && e.getCause() instanceof OpenStackConnectException) { // Ok, we were able to go up to the connection to OpenStack } else { - e.printStackTrace (); - fail ("Exception caught"); + e.printStackTrace(); + fail("Exception caught"); } } try { - util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null); + util.updateStack("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null); } catch (MsoException e) { - if (e instanceof MsoIOException && e.getCause () != null - && e.getCause () instanceof OpenStackConnectException) { + if (e instanceof MsoIOException && e.getCause() != null + && e.getCause() instanceof OpenStackConnectException) { // Ok, we were able to go up to the connection to OpenStack } else { - e.printStackTrace (); - fail ("Exception caught"); + e.printStackTrace(); + fail("Exception caught"); } } try { - util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null, null); + util.updateStack("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null, null); } catch (MsoException e) { - if (e instanceof MsoIOException && e.getCause () != null - && e.getCause () instanceof OpenStackConnectException) { + if (e instanceof MsoIOException && e.getCause() != null + && e.getCause() instanceof OpenStackConnectException) { // Ok, we were able to go up to the connection to OpenStack } else { - e.printStackTrace (); - fail ("Exception caught"); + e.printStackTrace(); + fail("Exception caught"); } } } 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 index 1c2501e8e4..b213bbd90b 100644 --- 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 @@ -27,10 +27,13 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.Optional; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; + import java.util.Map; + import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; public class CloudConfigTest { 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/openecomp/mso/cloud/CloudIdentityTest.java index eef45b7164..0033be80fd 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityTest.java @@ -29,36 +29,36 @@ import org.junit.Test; public class CloudIdentityTest { @Test - public final void testCloudIdentity () { - CloudIdentity id = new CloudIdentity (); - id.setAdminTenant ("AdminTenant"); - id.setId ("id"); + public final void testCloudIdentity() { + CloudIdentity id = new CloudIdentity(); + id.setAdminTenant("AdminTenant"); + id.setId("id"); // id.setKeystoneUrl ("keystone"); - id.setIdentityUrl ("keystone"); - id.setMemberRole ("member"); - id.setMsoId ("msoId"); - id.setMsoPass (CloudIdentity.encryptPassword ("password")); - id.setTenantMetadata (true); + id.setIdentityUrl("keystone"); + id.setMemberRole("member"); + id.setMsoId("msoId"); + id.setMsoPass(CloudIdentity.encryptPassword("password")); + id.setTenantMetadata(true); id.setIdentityServerType(null); id.setIdentityAuthenticationType(null); - - assertTrue (id.getAdminTenant ().equals ("AdminTenant")); - assertTrue (id.getId ().equals ("id")); + + assertTrue(id.getAdminTenant().equals("AdminTenant")); + assertTrue(id.getId().equals("id")); // assertTrue (id.getKeystoneUrl ().equals ("keystone")); - assertTrue (id.getMemberRole ().equals ("member")); - assertTrue (id.getMsoId ().equals ("msoId")); - assertTrue (id.getMsoPass ().equals ("password")); - assertTrue (id.hasTenantMetadata ()); + assertTrue(id.getMemberRole().equals("member")); + assertTrue(id.getMsoId().equals("msoId")); + assertTrue(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"); - assertTrue (encrypted != null); - assertTrue (!encrypted.equals ("password")); + public final void testEncryption() { + String encrypted = CloudIdentity.encryptPassword("password"); + assertTrue(encrypted != null); + assertTrue(!encrypted.equals("password")); } - + } 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 index b6c1c7373f..08a8c3b9cd 100644 --- 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 @@ -35,34 +35,33 @@ 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
- }
+ /**
+ *
+ */
+ 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 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()));
- }
+ @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/servertype/NewServerTypeUtils.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java index aaa732c9a3..94a224d5e3 100644 --- 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 @@ -31,14 +31,14 @@ import org.openecomp.mso.openstack.utils.MsoTenantUtils; public class NewServerTypeUtils extends MsoTenantUtils {
- /**
- * @param msoPropID
- */
- public NewServerTypeUtils(String msoPropID) {
- super(msoPropID);
- }
+ /**
+ * @param msoPropID
+ */
+ public NewServerTypeUtils(String msoPropID) {
+ super(msoPropID);
+ }
- @Override
+ @Override
public String createTenant(String tenantName, String cloudSiteId, Map<String, String> metadata, boolean backout)
throws MsoException {
// TODO Auto-generated method stub
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 index 4aaf379512..df853426ad 100644 --- 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 @@ -39,20 +39,20 @@ public class ServerTypeTest { 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 {
@@ -60,23 +60,25 @@ public class ServerTypeTest { 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");
+ 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"));
+ 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");
- }
+ 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/openstack/beans/NetworkInfoTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoTest.java index 0f357e5555..2f58f1d964 100644 --- 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 @@ -24,8 +24,10 @@ 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 { 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 index 9c7911ef89..f289f38843 100644 --- 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 @@ -23,7 +23,9 @@ 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; diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java index 9efaee921f..60026b0cd6 100644 --- a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java @@ -23,6 +23,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; + import org.junit.Test; import org.openecomp.mso.adapters.nwrest.ContrailNetwork; import org.openecomp.mso.adapters.nwrest.CreateNetworkError; @@ -76,377 +77,377 @@ import org.openecomp.mso.entity.MsoRequest; public class BeanTest { - // Test cases for code coverage - @Test - public void testCreateNetworkRequest() { - CreateNetworkRequest n = new CreateNetworkRequest(); - n.setBackout(true); - n.setCloudSiteId("test"); - ContrailNetwork contrailNetwork = new ContrailNetwork("shared", "external", new ArrayList<>(), - new ArrayList<>(), new ArrayList<>()); - contrailNetwork.setExternal("dgddb"); - contrailNetwork.setPolicyFqdns(new ArrayList<>()); - contrailNetwork.setRouteTableFqdns(new ArrayList<>()); - contrailNetwork.setRouteTargets(new ArrayList<>()); - contrailNetwork.setShared("test"); - n.setContrailNetwork(contrailNetwork); - n.setFailIfExists(true); - n.setMessageId("38829"); - n.setModelCustomizationUuid("4u838282"); - MsoRequest req = new MsoRequest(); - req.setRequestId("38849"); - req.setServiceInstanceId("3884839"); - n.setMsoRequest(req); - n.setNetworkId("478383"); - n.setNetworkName("tetet"); - n.setNetworkParams(new HashMap<>()); - n.setNetworkTechnology("VMWARE"); - n.setNetworkType("tete"); - n.setNetworkTypeVersion("v1"); - n.setNotificationUrl("test"); - ProviderVlanNetwork providerVlanNetwork = new ProviderVlanNetwork("test", new ArrayList<>()); - providerVlanNetwork.setPhysicalNetworkName("physicalNetworkName"); - providerVlanNetwork.setVlans(new ArrayList<>()); - n.setProviderVlanNetwork(providerVlanNetwork); - n.setSkipAAI(false); - n.setSubnets(new ArrayList<>()); - n.setTenantId("tenantId"); - n.getBackout(); - n.getCloudSiteId(); - ContrailNetwork cn = n.getContrailNetwork(); - cn.getExternal(); - cn.getPolicyFqdns(); - cn.getRouteTableFqdns(); - cn.getRouteTargets(); - cn.getShared(); - n.getFailIfExists(); - n.getMessageId(); - n.getModelCustomizationUuid(); - n.getMsoRequest(); - n.getNetworkId(); - n.getNetworkName(); - n.getNetworkParams(); - n.getNetworkTechnology(); - n.getNetworkType(); - n.getNetworkTypeVersion(); - n.getNotificationUrl(); - n.getProviderVlanNetwork(); - n.getSkipAAI(); - n.getSubnets(); - n.getTenantId(); - n.isContrailRequest(); - n.isSynchronous(); - n.toJsonString(); - n.toXmlString(); - } + // Test cases for code coverage + @Test + public void testCreateNetworkRequest() { + CreateNetworkRequest n = new CreateNetworkRequest(); + n.setBackout(true); + n.setCloudSiteId("test"); + ContrailNetwork contrailNetwork = new ContrailNetwork("shared", "external", new ArrayList<>(), + new ArrayList<>(), new ArrayList<>()); + contrailNetwork.setExternal("dgddb"); + contrailNetwork.setPolicyFqdns(new ArrayList<>()); + contrailNetwork.setRouteTableFqdns(new ArrayList<>()); + contrailNetwork.setRouteTargets(new ArrayList<>()); + contrailNetwork.setShared("test"); + n.setContrailNetwork(contrailNetwork); + n.setFailIfExists(true); + n.setMessageId("38829"); + n.setModelCustomizationUuid("4u838282"); + MsoRequest req = new MsoRequest(); + req.setRequestId("38849"); + req.setServiceInstanceId("3884839"); + n.setMsoRequest(req); + n.setNetworkId("478383"); + n.setNetworkName("tetet"); + n.setNetworkParams(new HashMap<>()); + n.setNetworkTechnology("VMWARE"); + n.setNetworkType("tete"); + n.setNetworkTypeVersion("v1"); + n.setNotificationUrl("test"); + ProviderVlanNetwork providerVlanNetwork = new ProviderVlanNetwork("test", new ArrayList<>()); + providerVlanNetwork.setPhysicalNetworkName("physicalNetworkName"); + providerVlanNetwork.setVlans(new ArrayList<>()); + n.setProviderVlanNetwork(providerVlanNetwork); + n.setSkipAAI(false); + n.setSubnets(new ArrayList<>()); + n.setTenantId("tenantId"); + n.getBackout(); + n.getCloudSiteId(); + ContrailNetwork cn = n.getContrailNetwork(); + cn.getExternal(); + cn.getPolicyFqdns(); + cn.getRouteTableFqdns(); + cn.getRouteTargets(); + cn.getShared(); + n.getFailIfExists(); + n.getMessageId(); + n.getModelCustomizationUuid(); + n.getMsoRequest(); + n.getNetworkId(); + n.getNetworkName(); + n.getNetworkParams(); + n.getNetworkTechnology(); + n.getNetworkType(); + n.getNetworkTypeVersion(); + n.getNotificationUrl(); + n.getProviderVlanNetwork(); + n.getSkipAAI(); + n.getSubnets(); + n.getTenantId(); + n.isContrailRequest(); + n.isSynchronous(); + n.toJsonString(); + n.toXmlString(); + } + + @Test + public void testDeleteNetworkRequest() { + DeleteNetworkRequest r = new DeleteNetworkRequest(); + r.setCloudSiteId("test"); + r.setMessageId("messageId"); + r.setModelCustomizationUuid("modelCustomizationUuid"); + r.setMsoRequest(null); + r.setNetworkId("networkId"); + r.setNetworkStackId("networkStackId"); + r.setNetworkType("networkType"); + r.setNotificationUrl("notificationUrl"); + r.setSkipAAI(true); + r.setTenantId("tenantId"); + r.getCloudSiteId(); + r.getMessageId(); + r.getModelCustomizationUuid(); + r.getMsoRequest(); + r.getNetworkId(); + r.getNetworkStackId(); + r.getNetworkType(); + r.getNotificationUrl(); + r.getSkipAAI(); + r.getTenantId(); + } - @Test - public void testDeleteNetworkRequest() { - DeleteNetworkRequest r = new DeleteNetworkRequest(); - r.setCloudSiteId("test"); - r.setMessageId("messageId"); - r.setModelCustomizationUuid("modelCustomizationUuid"); - r.setMsoRequest(null); - r.setNetworkId("networkId"); - r.setNetworkStackId("networkStackId"); - r.setNetworkType("networkType"); - r.setNotificationUrl("notificationUrl"); - r.setSkipAAI(true); - r.setTenantId("tenantId"); - r.getCloudSiteId(); - r.getMessageId(); - r.getModelCustomizationUuid(); - r.getMsoRequest(); - r.getNetworkId(); - r.getNetworkStackId(); - r.getNetworkType(); - r.getNotificationUrl(); - r.getSkipAAI(); - r.getTenantId(); - } + @Test + public void testCreateNetworkError() { + CreateNetworkError e = new CreateNetworkError("message"); + e = new CreateNetworkError("message", null, true, "messageid"); + DeleteNetworkError d = new DeleteNetworkError("message"); + d = new DeleteNetworkError("message", null, false, "29102"); + } - @Test - public void testCreateNetworkError() { - CreateNetworkError e = new CreateNetworkError("message"); - e = new CreateNetworkError("message", null, true, "messageid"); - DeleteNetworkError d = new DeleteNetworkError("message"); - d = new DeleteNetworkError("message", null, false, "29102"); - } + @Test + public void testCreatenetworkResponse() { + CreateNetworkResponse cnr = new CreateNetworkResponse("networkId", "neutronNetworkId", "networkStackId", + "networkFqdn", false, null, null, "messageId"); + cnr.setMessageId("messageId"); + cnr.setNetworkCreated(true); + cnr.setNetworkFqdn(null); + cnr.setNetworkStackId(null); + cnr.setNeutronNetworkId(null); + cnr.setRollback(null); + cnr.setNetworkStackId(null); + cnr.setSubnetMap(null); + cnr.getMessageId(); + cnr.getNetworkCreated(); + cnr.getNetworkFqdn(); + cnr.getNetworkId(); + cnr.getNetworkStackId(); + cnr.getNeutronNetworkId(); + cnr.getRollback(); + cnr.getSubnetMap(); - @Test - public void testCreatenetworkResponse() { - CreateNetworkResponse cnr = new CreateNetworkResponse("networkId", "neutronNetworkId", "networkStackId", - "networkFqdn", false, null, null, "messageId"); - cnr.setMessageId("messageId"); - cnr.setNetworkCreated(true); - cnr.setNetworkFqdn(null); - cnr.setNetworkStackId(null); - cnr.setNeutronNetworkId(null); - cnr.setRollback(null); - cnr.setNetworkStackId(null); - cnr.setSubnetMap(null); - cnr.getMessageId(); - cnr.getNetworkCreated(); - cnr.getNetworkFqdn(); - cnr.getNetworkId(); - cnr.getNetworkStackId(); - cnr.getNeutronNetworkId(); - cnr.getRollback(); - cnr.getSubnetMap(); + DeleteNetworkResponse dr = new DeleteNetworkResponse("networkId", true, "messageId"); + dr.setMessageId(null); + dr.setNetworkDeleted(null); + dr.setNetworkId(null); + dr.getMessageId(); + dr.getNetworkDeleted(); + dr.getNetworkId(); - DeleteNetworkResponse dr = new DeleteNetworkResponse("networkId", true, "messageId"); - dr.setMessageId(null); - dr.setNetworkDeleted(null); - dr.setNetworkId(null); - dr.getMessageId(); - dr.getNetworkDeleted(); - dr.getNetworkId(); + NetworkExceptionResponse ner = new NetworkExceptionResponse("message"); + ner = new NetworkExceptionResponse(null, null, false, null); + ner.setCategory(null); + ner.setMessage(null); + ner.setRolledBack(null); + ner.setMessageId(null); + ner.getCategory(); + ner.getMessage(); + ner.getMessageId(); + ner.getRolledBack(); - NetworkExceptionResponse ner = new NetworkExceptionResponse("message"); - ner = new NetworkExceptionResponse(null, null, false, null); - ner.setCategory(null); - ner.setMessage(null); - ner.setRolledBack(null); - ner.setMessageId(null); - ner.getCategory(); - ner.getMessage(); - ner.getMessageId(); - ner.getRolledBack(); + ner.toJsonString(); + ner.toXmlString(); + NetworkTechnology nt = NetworkTechnology.NEUTRON; + ProviderVlanNetwork pvn = new ProviderVlanNetwork(null, null); + pvn.setPhysicalNetworkName(null); + pvn.setVlans(null); + pvn.getPhysicalNetworkName(); + pvn.getVlans(); - ner.toJsonString(); - ner.toXmlString(); - NetworkTechnology nt = NetworkTechnology.NEUTRON; - ProviderVlanNetwork pvn = new ProviderVlanNetwork(null, null); - pvn.setPhysicalNetworkName(null); - pvn.setVlans(null); - pvn.getPhysicalNetworkName(); - pvn.getVlans(); + QueryNetworkResponse qnr = new QueryNetworkResponse(null, null, null, null, null); + qnr.setNetworkExists(null); + qnr.setNetworkId(null); + qnr.setNetworkOutputs(null); + qnr.setNetworkStackId(null); + qnr.setNetworkStatus(null); + qnr.setNeutronNetworkId(null); + qnr.setRouteTargets(null); + qnr.setSubnetIdMap(null); + qnr.setVlans(null); + qnr.getNetworkExists(); + qnr.getNetworkId(); + qnr.getNetworkOutputs(); + qnr.getNetworkStatus(); + qnr.getNeutronNetworkId(); + qnr.getRouteTargets(); + qnr.getSubnetIdMap(); + qnr.getVlans(); + qnr.toJsonString(); - QueryNetworkResponse qnr = new QueryNetworkResponse(null, null, null, null, null); - qnr.setNetworkExists(null); - qnr.setNetworkId(null); - qnr.setNetworkOutputs(null); - qnr.setNetworkStackId(null); - qnr.setNetworkStatus(null); - qnr.setNeutronNetworkId(null); - qnr.setRouteTargets(null); - qnr.setSubnetIdMap(null); - qnr.setVlans(null); - qnr.getNetworkExists(); - qnr.getNetworkId(); - qnr.getNetworkOutputs(); - qnr.getNetworkStatus(); - qnr.getNeutronNetworkId(); - qnr.getRouteTargets(); - qnr.getSubnetIdMap(); - qnr.getVlans(); - qnr.toJsonString(); + UpdateNetworkRequest unr = new UpdateNetworkRequest(); + unr.setBackout(null); + unr.setCloudSiteId(null); + unr.setContrailNetwork(null); + unr.setMessageId(null); + unr.setModelCustomizationUuid(null); + unr.setMsoRequest(null); + unr.setNetworkId(null); + unr.setNetworkName(null); + unr.setNetworkParams(null); + unr.setNetworkStackId(null); + unr.setNetworkTechnology("VMWARE"); + unr.setNetworkType(null); + unr.setNetworkTypeVersion(null); + unr.setNotificationUrl(null); + unr.setProviderVlanNetwork(null); + unr.setSkipAAI(null); + unr.setSubnets(null); + unr.setTenantId(null); + unr.getBackout(); + unr.getCloudSiteId(); + unr.getContrailNetwork(); + unr.getMessageId(); + unr.getModelCustomizationUuid(); + unr.getMsoRequest(); + unr.getNetworkId(); + unr.getNetworkName(); + unr.getNetworkParams(); + unr.getNetworkStackId(); + unr.getNetworkTechnology(); + unr.getNetworkType(); + unr.getNetworkTypeVersion(); + unr.getNotificationUrl(); + unr.getProviderVlanNetwork(); + unr.getSkipAAI(); + unr.getSubnets(); + unr.getTenantId(); + unr.isContrailRequest(); - UpdateNetworkRequest unr = new UpdateNetworkRequest(); - unr.setBackout(null); - unr.setCloudSiteId(null); - unr.setContrailNetwork(null); - unr.setMessageId(null); - unr.setModelCustomizationUuid(null); - unr.setMsoRequest(null); - unr.setNetworkId(null); - unr.setNetworkName(null); - unr.setNetworkParams(null); - unr.setNetworkStackId(null); - unr.setNetworkTechnology("VMWARE"); - unr.setNetworkType(null); - unr.setNetworkTypeVersion(null); - unr.setNotificationUrl(null); - unr.setProviderVlanNetwork(null); - unr.setSkipAAI(null); - unr.setSubnets(null); - unr.setTenantId(null); - unr.getBackout(); - unr.getCloudSiteId(); - unr.getContrailNetwork(); - unr.getMessageId(); - unr.getModelCustomizationUuid(); - unr.getMsoRequest(); - unr.getNetworkId(); - unr.getNetworkName(); - unr.getNetworkParams(); - unr.getNetworkStackId(); - unr.getNetworkTechnology(); - unr.getNetworkType(); - unr.getNetworkTypeVersion(); - unr.getNotificationUrl(); - unr.getProviderVlanNetwork(); - unr.getSkipAAI(); - unr.getSubnets(); - unr.getTenantId(); - unr.isContrailRequest(); + RollbackNetworkError err = new RollbackNetworkError("message"); + err = new RollbackNetworkError(null, null, false, null); + RollbackNetworkRequest req = new RollbackNetworkRequest(); + req.setNetworkRollback(null); + req.getNetworkRollback(); + req.setMessageId(null); + req.getMessageId(); + req.setNotificationUrl(null); + req.getNotificationUrl(); + req.setSkipAAI(null); + req.getSkipAAI(); - RollbackNetworkError err = new RollbackNetworkError("message"); - err = new RollbackNetworkError(null, null, false, null); - RollbackNetworkRequest req = new RollbackNetworkRequest(); - req.setNetworkRollback(null); - req.getNetworkRollback(); - req.setMessageId(null); - req.getMessageId(); - req.setNotificationUrl(null); - req.getNotificationUrl(); - req.setSkipAAI(null); - req.getSkipAAI(); + RollbackNetworkResponse rnr = new RollbackNetworkResponse(true, null); + rnr.setMessageId(null); + rnr.getMessageId(); + rnr.setNetworkRolledBack(null); + rnr.getNetworkRolledBack(); - RollbackNetworkResponse rnr = new RollbackNetworkResponse(true, null); - rnr.setMessageId(null); - rnr.getMessageId(); - rnr.setNetworkRolledBack(null); - rnr.getNetworkRolledBack(); + UpdateNetworkError error = new UpdateNetworkError(null); + error = new UpdateNetworkError("test", null, false, null); - UpdateNetworkError error = new UpdateNetworkError(null); - error = new UpdateNetworkError("test", null, false, null); + UpdateVfModuleRequest uvmr = new UpdateVfModuleRequest(); + uvmr.setBackout(null); + uvmr.setBaseVfModuleId(null); + uvmr.setBaseVfModuleStackId(null); + uvmr.setFailIfExists(null); + uvmr.setMessageId(null); + uvmr.setModelCustomizationUuid(null); + uvmr.setMsoRequest(null); + uvmr.setNotificationUrl(null); + uvmr.setRequestType(null); + uvmr.setSkipAAI(true); + uvmr.setTenantId(null); + uvmr.setVfModuleId(null); + uvmr.setVfModuleName(null); + uvmr.setVfModuleParams(null); + uvmr.setVfModuleStackId(null); + uvmr.setVfModuleType(null); + uvmr.setVnfId(null); + uvmr.setVnfType(null); + uvmr.setVnfVersion(null); + uvmr.setVolumeGroupId(null); + uvmr.setVolumeGroupStackId(null); + uvmr.getBackout(); + uvmr.getBaseVfModuleId(); + uvmr.getBaseVfModuleStackId(); + uvmr.getCloudSiteId(); + uvmr.getFailIfExists(); + uvmr.getMessageId(); + uvmr.getModelCustomizationUuid(); + uvmr.getMsoRequest(); + uvmr.getNotificationUrl(); + uvmr.getRequestType(); + uvmr.getSkipAAI(); + uvmr.getTenantId(); + uvmr.getVfModuleId(); + uvmr.getVfModuleName(); + uvmr.getVfModuleParams(); + uvmr.getVfModuleStackId(); + uvmr.getVfModuleType(); + uvmr.getVnfId(); + uvmr.getVnfType(); + uvmr.getVnfVersion(); + uvmr.getVolumeGroupId(); + uvmr.getVolumeGroupStackId(); + uvmr.setCloudSiteId(null); - UpdateVfModuleRequest uvmr = new UpdateVfModuleRequest(); - uvmr.setBackout(null); - uvmr.setBaseVfModuleId(null); - uvmr.setBaseVfModuleStackId(null); - uvmr.setFailIfExists(null); - uvmr.setMessageId(null); - uvmr.setModelCustomizationUuid(null); - uvmr.setMsoRequest(null); - uvmr.setNotificationUrl(null); - uvmr.setRequestType(null); - uvmr.setSkipAAI(true); - uvmr.setTenantId(null); - uvmr.setVfModuleId(null); - uvmr.setVfModuleName(null); - uvmr.setVfModuleParams(null); - uvmr.setVfModuleStackId(null); - uvmr.setVfModuleType(null); - uvmr.setVnfId(null); - uvmr.setVnfType(null); - uvmr.setVnfVersion(null); - uvmr.setVolumeGroupId(null); - uvmr.setVolumeGroupStackId(null); - uvmr.getBackout(); - uvmr.getBaseVfModuleId(); - uvmr.getBaseVfModuleStackId(); - uvmr.getCloudSiteId(); - uvmr.getFailIfExists(); - uvmr.getMessageId(); - uvmr.getModelCustomizationUuid(); - uvmr.getMsoRequest(); - uvmr.getNotificationUrl(); - uvmr.getRequestType(); - uvmr.getSkipAAI(); - uvmr.getTenantId(); - uvmr.getVfModuleId(); - uvmr.getVfModuleName(); - uvmr.getVfModuleParams(); - uvmr.getVfModuleStackId(); - uvmr.getVfModuleType(); - uvmr.getVnfId(); - uvmr.getVnfType(); - uvmr.getVnfVersion(); - uvmr.getVolumeGroupId(); - uvmr.getVolumeGroupStackId(); - uvmr.setCloudSiteId(null); + CreateVfModuleRequest cvmr = new CreateVfModuleRequest(); + cvmr.setBackout(null); + cvmr.setBaseVfModuleId(null); + cvmr.setBaseVfModuleStackId(null); + cvmr.setCloudSiteId(null); + cvmr.setFailIfExists(null); - CreateVfModuleRequest cvmr = new CreateVfModuleRequest(); - cvmr.setBackout(null); - cvmr.setBaseVfModuleId(null); - cvmr.setBaseVfModuleStackId(null); - cvmr.setCloudSiteId(null); - cvmr.setFailIfExists(null); + coverCode(CreateVfModuleRequest.class); + CreateVfModuleResponse resp = new CreateVfModuleResponse(null, null, null, true, null, null, null); + resp.toJsonString(); + resp.toXmlString(); + coverCode(CreateVfModuleResponse.class); - coverCode(CreateVfModuleRequest.class); - CreateVfModuleResponse resp = new CreateVfModuleResponse(null, null, null, true, null, null, null); - resp.toJsonString(); - resp.toXmlString(); - coverCode(CreateVfModuleResponse.class); + coverCode(CreateVolumeGroupRequest.class); - coverCode(CreateVolumeGroupRequest.class); + CreateVolumeGroupResponse cvgr = new CreateVolumeGroupResponse(null, null, true, null, null, null); + coverCode(CreateVolumeGroupResponse.class); + coverCode(DeleteVfModuleRequest.class); + coverCode(DeleteVfModuleResponse.class); + coverCode(DeleteVolumeGroupRequest.class); + coverCode(DeleteVolumeGroupResponse.class); + QueryVfModuleResponse vfmr = new QueryVfModuleResponse(null, null, null, null, null); + coverCode(QueryVfModuleResponse.class); + QueryVolumeGroupResponse qvgr = new QueryVolumeGroupResponse(null, null, null, null); + coverCode(QueryVolumeGroupResponse.class); + UpdateVfModuleResponse uvfmr = new UpdateVfModuleResponse(null, null, null, null, null); + coverCode(UpdateVfModuleResponse.class); + coverCode(UpdateVolumeGroupRequest.class); + UpdateVolumeGroupResponse uvgr = new UpdateVolumeGroupResponse(null, null, null, null); + coverCode(UpdateVolumeGroupResponse.class); + VfModuleExceptionResponse vfmer = new VfModuleExceptionResponse(null, null, false, null); + coverCode(VfModuleExceptionResponse.class); + //VfModuleRollback vfmrb = new VfModuleRollback(null, null, null, null); + VfModuleRollback vfmrb = new VfModuleRollback(null, null, null, false, null, null, null, null); + coverCode(VfModuleRollback.class); + //VolumeGroupRollback vgrback = new VolumeGroupRollback(null, null, null); + VolumeGroupRollback vgrback = new VolumeGroupRollback(null, null, false, null, null, null, null); + coverCode(VolumeGroupRollback.class); + RollbackVolumeGroupResponse rvgresp = new RollbackVolumeGroupResponse(null, null); + coverCode(RollbackVolumeGroupResponse.class); + } - CreateVolumeGroupResponse cvgr = new CreateVolumeGroupResponse(null, null, true, null, null, null); - coverCode(CreateVolumeGroupResponse.class); - coverCode(DeleteVfModuleRequest.class); - coverCode(DeleteVfModuleResponse.class); - coverCode(DeleteVolumeGroupRequest.class); - coverCode(DeleteVolumeGroupResponse.class); - QueryVfModuleResponse vfmr = new QueryVfModuleResponse(null, null, null, null, null); - coverCode(QueryVfModuleResponse.class); - QueryVolumeGroupResponse qvgr = new QueryVolumeGroupResponse(null, null, null, null); - coverCode(QueryVolumeGroupResponse.class); - UpdateVfModuleResponse uvfmr = new UpdateVfModuleResponse(null, null, null, null, null); - coverCode(UpdateVfModuleResponse.class); - coverCode(UpdateVolumeGroupRequest.class); - UpdateVolumeGroupResponse uvgr = new UpdateVolumeGroupResponse(null, null, null, null); - coverCode(UpdateVolumeGroupResponse.class); - VfModuleExceptionResponse vfmer = new VfModuleExceptionResponse(null, null, false, null); - coverCode(VfModuleExceptionResponse.class); - //VfModuleRollback vfmrb = new VfModuleRollback(null, null, null, null); - VfModuleRollback vfmrb = new VfModuleRollback(null, null, null, false, null, null, null, null); - coverCode(VfModuleRollback.class); - //VolumeGroupRollback vgrback = new VolumeGroupRollback(null, null, null); - VolumeGroupRollback vgrback = new VolumeGroupRollback(null, null, false, null, null, null, null); - coverCode(VolumeGroupRollback.class); - RollbackVolumeGroupResponse rvgresp = new RollbackVolumeGroupResponse(null, null); - coverCode(RollbackVolumeGroupResponse.class); - } - - @Test - public void testTenantRestPackage(){ - CreateTenantError cte = new CreateTenantError(null, null, false); - coverCode(CreateTenantError.class); - CreateTenantRequest ctreq = new CreateTenantRequest(); - ctreq.toJsonString(); - ctreq.toXmlString(); - ctreq.toString(); - coverCode(CreateTenantRequest.class); - CreateTenantResponse ctresp = new CreateTenantResponse(null, null, null, new TenantRollback()); - ctresp.toString(); - coverCode(CreateTenantResponse.class); - DeleteTenantError dterr = new DeleteTenantError(null, null, false); - coverCode(DeleteTenantError.class); - coverCode(DeleteTenantRequest.class); - coverCode(DeleteTenantResponse.class); - coverCode(HealthCheckHandler.class); - QueryTenantError qnerr = new QueryTenantError(null, null); - coverCode(QueryTenantError.class); - QueryTenantResponse qtresp = new QueryTenantResponse(null, null, null); - coverCode(QueryTenantResponse.class); - coverCode(RollbackTenantError.class); - RollbackTenantError rollTer = new RollbackTenantError(null, null, false); - coverCode(RollbackTenantRequest.class); - coverCode(RollbackTenantResponse.class); - TenantExceptionResponse resp = new TenantExceptionResponse(null, null, false); - coverCode(TenantExceptionResponse.class); - coverCode(TenantRollback.class); - } + @Test + public void testTenantRestPackage() { + CreateTenantError cte = new CreateTenantError(null, null, false); + coverCode(CreateTenantError.class); + CreateTenantRequest ctreq = new CreateTenantRequest(); + ctreq.toJsonString(); + ctreq.toXmlString(); + ctreq.toString(); + coverCode(CreateTenantRequest.class); + CreateTenantResponse ctresp = new CreateTenantResponse(null, null, null, new TenantRollback()); + ctresp.toString(); + coverCode(CreateTenantResponse.class); + DeleteTenantError dterr = new DeleteTenantError(null, null, false); + coverCode(DeleteTenantError.class); + coverCode(DeleteTenantRequest.class); + coverCode(DeleteTenantResponse.class); + coverCode(HealthCheckHandler.class); + QueryTenantError qnerr = new QueryTenantError(null, null); + coverCode(QueryTenantError.class); + QueryTenantResponse qtresp = new QueryTenantResponse(null, null, null); + coverCode(QueryTenantResponse.class); + coverCode(RollbackTenantError.class); + RollbackTenantError rollTer = new RollbackTenantError(null, null, false); + coverCode(RollbackTenantRequest.class); + coverCode(RollbackTenantResponse.class); + TenantExceptionResponse resp = new TenantExceptionResponse(null, null, false); + coverCode(TenantExceptionResponse.class); + coverCode(TenantRollback.class); + } - private void coverCode(Class cls) { - try { - Object obj = cls.newInstance(); - Method[] methods = cls.getDeclaredMethods(); - for (Method m : methods) { - try { - m.setAccessible(true); - Type[] types = m.getGenericParameterTypes(); - Object[] objs = { new Object(), new Object(), new Object(), new Object() }; - if (types.length < 1) { - m.invoke(obj); - } else if (types.length == 1) { - String type = types[0].getTypeName(); - if (type.contains("<")) { - type = type.substring(0, type.indexOf("<")); - } - Class paramCls = Class.forName(type); - Object paramobj = paramCls.newInstance(); - m.invoke(obj, paramobj); - } else if (types.length == 2) { - // m.invoke(obj,null,null); - } - } catch (Exception ex) { - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } + private void coverCode(Class cls) { + try { + Object obj = cls.newInstance(); + Method[] methods = cls.getDeclaredMethods(); + for (Method m : methods) { + try { + m.setAccessible(true); + Type[] types = m.getGenericParameterTypes(); + Object[] objs = {new Object(), new Object(), new Object(), new Object()}; + if (types.length < 1) { + m.invoke(obj); + } else if (types.length == 1) { + String type = types[0].getTypeName(); + if (type.contains("<")) { + type = type.substring(0, type.indexOf("<")); + } + Class paramCls = Class.forName(type); + Object paramobj = paramCls.newInstance(); + m.invoke(obj, paramobj); + } else if (types.length == 2) { + // m.invoke(obj,null,null); + } + } catch (Exception ex) { + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } } diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapDeserializerTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapDeserializerTest.java index 897c69d144..b3bf2b8c25 100644 --- a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapDeserializerTest.java +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapDeserializerTest.java @@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import java.util.Map; + import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.map.DeserializationContext; import org.codehaus.jackson.map.ObjectMapper; diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java index f903f21441..b97496d05b 100644 --- a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.verify; import java.util.HashMap; import java.util.Map; + import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.map.SerializerProvider; import org.junit.Test; diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java index 31594905fd..f3ee941641 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestClassTest.java @@ -29,7 +29,9 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; + import javax.json.*; + import org.junit.Test; import org.junit.runner.RunWith; import org.openecomp.mso.adapters.catalogdb.CatalogDbAdapterRest; @@ -55,50 +57,50 @@ import static org.hamcrest.CoreMatchers.instanceOf; public class CatalogDbAdapterRestClassTest { @Mock private static CatalogDatabase dbMock; - + private static List<VnfResourceCustomization> paramList; - + @Before - public void prepare () { - /* - * 1. for non routing related methods/classes, use mockito - * 2. for routing methods, use TJWSEmbeddedJaxrsServer - */ - - /* - * in the setup portion, create a mock db object - * - */ - // set up mock return value + public void prepare() { + /* + * 1. for non routing related methods/classes, use mockito + * 2. for routing methods, use TJWSEmbeddedJaxrsServer + */ + + /* + * in the setup portion, create a mock db object + * + */ + // set up mock return value paramList = new ArrayList<>(); VnfResourceCustomization d1 = new VnfResourceCustomization(); d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); d1.setModelInstanceName("ciVFOnboarded-FNAT-aab06c41 1"); paramList.add(d1); // end - - PowerMockito.mockStatic(CatalogDatabase.class); - dbMock = PowerMockito.mock(CatalogDatabase.class); - PowerMockito.when(CatalogDatabase.getInstance()).thenReturn(dbMock); - try { - - PowerMockito.whenNew(CatalogDatabase.class).withAnyArguments().thenReturn(dbMock); - PowerMockito.spy (dbMock); - - } catch (Exception e) { - e.printStackTrace(); - } + + PowerMockito.mockStatic(CatalogDatabase.class); + dbMock = PowerMockito.mock(CatalogDatabase.class); + PowerMockito.when(CatalogDatabase.getInstance()).thenReturn(dbMock); + try { + + PowerMockito.whenNew(CatalogDatabase.class).withAnyArguments().thenReturn(dbMock); + PowerMockito.spy(dbMock); + + } catch (Exception e) { + e.printStackTrace(); + } } - + @Test - public void respond_Test(){ - QueryServiceVnfs qryResp = new QueryServiceVnfs(paramList); - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter); - - Response resp = spyAdapter.respond("v1", HttpStatus.SC_OK, false, qryResp); - Mockito.verify(spyAdapter,Mockito.times(1)).respond("v1", HttpStatus.SC_OK, false, qryResp); - + public void respond_Test() { + QueryServiceVnfs qryResp = new QueryServiceVnfs(paramList); + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter); + + Response resp = spyAdapter.respond("v1", HttpStatus.SC_OK, false, qryResp); + Mockito.verify(spyAdapter, Mockito.times(1)).respond("v1", HttpStatus.SC_OK, false, qryResp); + String s = resp.getEntity().toString(); // System.out.println(s); @@ -108,225 +110,218 @@ public class CatalogDbAdapterRestClassTest { reader.close(); // end JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + } + + + @Test + public void serviceVnfsImpl_vnfUuid_ver_Test() { + PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn(paramList); + + try { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + + // Run + Response resp = adapter.serviceVnfsImpl("v1", true, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null, null); + String s = resp.getEntity().toString(); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + // end + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + // + Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByVnfModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void serviceVnfsImpl_smiUuid_NoVer_Test() { + PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString())).thenReturn(paramList); + + try { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + + // Run + Response resp = adapter.serviceVnfsImpl("v1", true, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null); + String s = resp.getEntity().toString(); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + // end + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelInvariantUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void serviceVnfsImpl_smUuid_ver_Test() { + PowerMockito.when(dbMock.getAllVnfsByServiceModelUuid(Mockito.anyString())).thenReturn(paramList); + + try { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + + // Run + Response resp = adapter.serviceVnfsImpl("v1", true, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null); + String s = resp.getEntity().toString(); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + // end + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void serviceVnfsImpl_smiUuid_ver_Test() { + PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString(), Mockito.anyString())).thenReturn(paramList); + + try { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + + // Run + Response resp = adapter.serviceVnfsImpl("v1", true, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", "v1", null); + String s = resp.getEntity().toString(); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + // end + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelInvariantUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391", "v1"); + + } catch (Exception e) { + e.printStackTrace(); + } } - - - @Test - public void serviceVnfsImpl_vnfUuid_ver_Test() - { - PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList); - - try { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - - // Run - Response resp = adapter.serviceVnfsImpl("v1", true, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null, null); - String s = resp.getEntity().toString(); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - // end - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - // - Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByVnfModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - - } catch (Exception e) { - e.printStackTrace(); - } + + @Test + public void serviceVnfsImpl_smName_ver_Test() { + PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString(), Mockito.anyString())).thenReturn(paramList); + + try { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + + // Run + Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, "v1", "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + String s = resp.getEntity().toString(); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + // end + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceName("16ea3e56-a8ce-4ad7-8edd-4d2eae095391", "v1"); + + } catch (Exception e) { + e.printStackTrace(); + } } - @Test - public void serviceVnfsImpl_smiUuid_NoVer_Test() - { - PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString())).thenReturn (paramList); - - try { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - - // Run - Response resp = adapter.serviceVnfsImpl("v1", true, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null); - String s = resp.getEntity().toString(); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - // end - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelInvariantUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void serviceVnfsImpl_smUuid_ver_Test() - { - PowerMockito.when(dbMock.getAllVnfsByServiceModelUuid(Mockito.anyString())).thenReturn (paramList); - - try { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - - // Run - Response resp = adapter.serviceVnfsImpl("v1", true, null,"16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null); - String s = resp.getEntity().toString(); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - // end - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void serviceVnfsImpl_smiUuid_ver_Test() - { - PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString(),Mockito.anyString())).thenReturn (paramList); - - try { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - - // Run - Response resp = adapter.serviceVnfsImpl("v1", true, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", "v1", null); - String s = resp.getEntity().toString(); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - // end - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceModelInvariantUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391","v1"); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void serviceVnfsImpl_smName_ver_Test() - { - PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString(),Mockito.anyString())).thenReturn (paramList); - - try { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - - // Run - Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, "v1", "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - String s = resp.getEntity().toString(); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - // end - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceName("16ea3e56-a8ce-4ad7-8edd-4d2eae095391","v1"); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void serviceVnfsImpl_smName_NoVer_Test() - { - PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString())).thenReturn (paramList); - - try { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - - // Run - Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - String s = resp.getEntity().toString(); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - // end - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceName("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void serviceVnfsImpl_Exception_Test() - { - PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString())).thenReturn (null); - - try { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - - // Run - Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, null, null); - - assertEquals(resp.getStatus(), HttpStatus.SC_INTERNAL_SERVER_ERROR); - assertThat(resp.getEntity(), instanceOf(CatalogQueryException.class)); - } catch (Exception e) { - e.printStackTrace(); - } - } - @Test - public void serviceNetworksImpl_nUuid_ver_Test(){ - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter); - - Response resp = Response - .status(HttpStatus.SC_OK) - .entity("{\"serviceVnfs\":[{\"version\":\"v1\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}") - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .build(); - - Mockito.doReturn(resp).when(spyAdapter).serviceNetworksImpl(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - - // Run - - Response ret = spyAdapter.serviceNetworksImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391",null, null, null, null); - Mockito.verify(spyAdapter).serviceNetworksImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null, null); - - assertTrue(ret.getStatus() == HttpStatus.SC_OK); + public void serviceVnfsImpl_smName_NoVer_Test() { + PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString())).thenReturn(paramList); + + try { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + + // Run + Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, null, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + String s = resp.getEntity().toString(); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + // end + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + Mockito.verify(dbMock, Mockito.times(1)).getAllVnfsByServiceName("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void serviceVnfsImpl_Exception_Test() { + PowerMockito.when(dbMock.getAllVnfsByServiceName(Mockito.anyString())).thenReturn(null); + + try { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + + // Run + Response resp = adapter.serviceVnfsImpl("v1", true, null, null, null, null, null); + + assertEquals(resp.getStatus(), HttpStatus.SC_INTERNAL_SERVER_ERROR); + assertThat(resp.getEntity(), instanceOf(CatalogQueryException.class)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void serviceNetworksImpl_nUuid_ver_Test() { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter); + + Response resp = Response + .status(HttpStatus.SC_OK) + .entity("{\"serviceVnfs\":[{\"version\":\"v1\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .build(); + + Mockito.doReturn(resp).when(spyAdapter).serviceNetworksImpl(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + + // Run + + Response ret = spyAdapter.serviceNetworksImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null, null); + Mockito.verify(spyAdapter).serviceNetworksImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null, null); + + assertTrue(ret.getStatus() == HttpStatus.SC_OK); String s = resp.getEntity().toString(); // prepare to inspect response @@ -335,33 +330,32 @@ public class CatalogDbAdapterRestClassTest { reader.close(); // end JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + } - + @Test - public void serviceAllottedResourcesImpl_Test() - { - CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); - CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter); - - Response resp = Response - .status(HttpStatus.SC_OK) - .entity("{\"serviceVnfs\":[{\"version\":\"v1\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}") - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .build(); - - Mockito.doReturn(resp).when(spyAdapter).serviceAllottedResourcesImpl(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - - // Run - - Response ret = spyAdapter.serviceAllottedResourcesImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391",null, null, null); - Mockito.verify(spyAdapter).serviceAllottedResourcesImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null); - - assertTrue(ret.getStatus() == HttpStatus.SC_OK); + public void serviceAllottedResourcesImpl_Test() { + CatalogDbAdapterRest adapter = new CatalogDbAdapterRest(); + CatalogDbAdapterRest spyAdapter = Mockito.spy(adapter); + + Response resp = Response + .status(HttpStatus.SC_OK) + .entity("{\"serviceVnfs\":[{\"version\":\"v1\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .build(); + + Mockito.doReturn(resp).when(spyAdapter).serviceAllottedResourcesImpl(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + + // Run + + Response ret = spyAdapter.serviceAllottedResourcesImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null); + Mockito.verify(spyAdapter).serviceAllottedResourcesImpl("v1", false, "16ea3e56-a8ce-4ad7-8edd-4d2eae095391", null, null, null); + + assertTrue(ret.getStatus() == HttpStatus.SC_OK); String s = resp.getEntity().toString(); // prepare to inspect response @@ -370,11 +364,11 @@ public class CatalogDbAdapterRestClassTest { reader.close(); // end JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - - assertEquals(resp.getStatus(), HttpStatus.SC_OK); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - + + assertEquals(resp.getStatus(), HttpStatus.SC_OK); + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + } - + } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java index ae5e663777..1f80227514 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRestHttpTest.java @@ -29,6 +29,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer; + import static org.junit.Assert.*; import java.io.StringReader; @@ -73,7 +74,7 @@ public class CatalogDbAdapterRestHttpTest { private static final int PORT = 3099; private static Registry registry; private static ResteasyProviderFactory factory; - + @BeforeClass public static void beforeClass() throws Exception { server = new TJWSEmbeddedJaxrsServer(); @@ -84,76 +85,75 @@ public class CatalogDbAdapterRestHttpTest { registry.addPerRequestResource(CatalogDbAdapterRest.class); factory.registerProvider(CatalogDbAdapterRest.class); } - + @Before - public void before(){ - PowerMockito.mockStatic(CatalogDatabase.class); - dbMock = PowerMockito.mock(CatalogDatabase.class); - PowerMockito.when(CatalogDatabase.getInstance()).thenReturn(dbMock); - - try { - PowerMockito.whenNew(CatalogDatabase.class).withAnyArguments().thenReturn(dbMock); - - } catch (Exception e) { - e.printStackTrace(); - } + public void before() { + PowerMockito.mockStatic(CatalogDatabase.class); + dbMock = PowerMockito.mock(CatalogDatabase.class); + PowerMockito.when(CatalogDatabase.getInstance()).thenReturn(dbMock); + + try { + PowerMockito.whenNew(CatalogDatabase.class).withAnyArguments().thenReturn(dbMock); + + } catch (Exception e) { + e.printStackTrace(); + } } - + @Test - public void healthCheck_Test(){ + public void healthCheck_Test() { ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyWebTarget target = client.target("http://localhost:3099/v1/healthcheck"); Response response = target.request().get(); String value = response.readEntity(String.class); assertTrue(value.contains("Application v1 ready")); } - + @Test - public void vnfResourcesUrl_Test() - { - try { - List<VnfResourceCustomization> paramList; - // set up mock return value + public void vnfResourcesUrl_Test() { + try { + List<VnfResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); VnfResourceCustomization d1 = new VnfResourceCustomization(); d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); d1.setModelInstanceName("RG_6-26_mog11 0"); d1.setVersion("v1"); paramList.add(d1); - PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList); + PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn(paramList); + // end + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/vnfResources/16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + assertTrue(jArray.size() == 1); + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String version = rec.getString("version"); + String uuid = rec.getString("modelCustomizationUuid"); + + assertTrue(version.equals("v1")); + assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391")); + } // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/vnfResources/16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - assertTrue(jArray.size() == 1); - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String version = rec.getString("version"); - String uuid = rec.getString("modelCustomizationUuid"); - - assertTrue(version.equals("v1")); - assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391")); - } - // end - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception e) { + e.printStackTrace(); + } } - + @Test - public void serviceVnfsUrl_smiUuid_smVer_Test(){ - try { - List<VnfResourceCustomization> paramList; - // set up mock return value + public void serviceVnfsUrl_smiUuid_smVer_Test() { + try { + List<VnfResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); VnfResourceCustomization d1 = new VnfResourceCustomization(); d1.setVnfResourceModelUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); @@ -161,330 +161,327 @@ public class CatalogDbAdapterRestHttpTest { d1.setVersion("v1"); d1.setMaxInstances(50); paramList.add(d1); - PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString(),Mockito.anyString())).thenReturn (paramList); + PowerMockito.when(dbMock.getAllVnfsByServiceModelInvariantUuid(Mockito.anyString(), Mockito.anyString())).thenReturn(paramList); // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceVnfs?serviceModelInvariantUuid=16ea3e56-a8ce-4ad7-8edd-4d2eae095391&serviceModelVersion=ver1"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - assertTrue(jArray.size() == 1); - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String version = rec.getString("version"); - String uuid = rec.getString("vnfResourceModelUuid"); - int maxInstance = rec.getInt("maxInstances"); - - assertTrue(version.equals("v1")); - assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391")); - assertTrue(maxInstance == 50); - } - // end - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceVnfs?serviceModelInvariantUuid=16ea3e56-a8ce-4ad7-8edd-4d2eae095391&serviceModelVersion=ver1"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + assertTrue(jArray.size() == 1); + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String version = rec.getString("version"); + String uuid = rec.getString("vnfResourceModelUuid"); + int maxInstance = rec.getInt("maxInstances"); + + assertTrue(version.equals("v1")); + assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391")); + assertTrue(maxInstance == 50); + } + // end + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } } - + @Test - public void serviceVnfsUrl_vnfUuid_Test(){ - try { - List<VnfResourceCustomization> paramList; - // set up mock return value + public void serviceVnfsUrl_vnfUuid_Test() { + try { + List<VnfResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); VnfResourceCustomization d1 = new VnfResourceCustomization(); d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); d1.setModelInstanceName("RG_6-26_mog11 0"); d1.setVersion("v1"); paramList.add(d1); - PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList); + PowerMockito.when(dbMock.getAllVnfsByVnfModelCustomizationUuid(Mockito.anyString())).thenReturn(paramList); + // end + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceVnfs?vnfModelCustomizationUuid=16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // System.out.println(value); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceVnfs"); + assertTrue(jArray.size() == 1); + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String version = rec.getString("version"); + String uuid = rec.getString("modelCustomizationUuid"); + + assertTrue(version.equals("v1")); + assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391")); + } // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceVnfs?vnfModelCustomizationUuid=16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // System.out.println(value); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - assertTrue(jArray.size() == 1); - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String version = rec.getString("version"); - String uuid = rec.getString("modelCustomizationUuid"); - - assertTrue(version.equals("v1")); - assertTrue(uuid.equals("16ea3e56-a8ce-4ad7-8edd-4d2eae095391")); - } - // end - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + @Test - public void networkResourcesUrl_nUuid_Ver_Test(){ - try { - List<NetworkResourceCustomization> paramList; - // set up mock return value + public void networkResourcesUrl_nUuid_Ver_Test() { + try { + List<NetworkResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); NetworkResourceCustomization d1 = new NetworkResourceCustomization(); d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); - PowerMockito.when(dbMock.getAllNetworksByNetworkModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList); + PowerMockito.when(dbMock.getAllNetworksByNetworkModelCustomizationUuid(Mockito.anyString())).thenReturn(paramList); + // end + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/networkResources/0cb9b26a-9820-48a7-86e5-16c510e993d9"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // System.out.println(value); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceNetworks"); + assertTrue(jArray.size() == 1); + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String uuid = rec.getString("networkResourceModelUuid"); + + assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + } // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/networkResources/0cb9b26a-9820-48a7-86e5-16c510e993d9"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // System.out.println(value); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceNetworks"); - assertTrue(jArray.size() == 1); - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String uuid = rec.getString("networkResourceModelUuid"); - - assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - } - // end - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } } - + @Test - public void serviceNetworksUrl_nType_Test(){ - try { - List<NetworkResourceCustomization> paramList; - // set up mock return value + public void serviceNetworksUrl_nType_Test() { + try { + List<NetworkResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); NetworkResourceCustomization d1 = new NetworkResourceCustomization(); d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); - PowerMockito.when(dbMock.getAllNetworksByNetworkType(Mockito.anyString())).thenReturn (paramList); + PowerMockito.when(dbMock.getAllNetworksByNetworkType(Mockito.anyString())).thenReturn(paramList); // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceNetworks?networkModelName=0cb9b26a-9820-48a7-86e5-16c510e993d9"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // System.out.println(value); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceNetworks"); - assertTrue(jArray.size() == 1); - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String uuid = rec.getString("networkResourceModelUuid"); - - assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - } - // end - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceNetworks?networkModelName=0cb9b26a-9820-48a7-86e5-16c510e993d9"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // System.out.println(value); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceNetworks"); + assertTrue(jArray.size() == 1); + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String uuid = rec.getString("networkResourceModelUuid"); + + assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + } + // end + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + @Test - public void serviceResourcesUrl_smiUuid_Ver_Test(){ - try { - ArrayList<NetworkResourceCustomization> paramList; - // set up mock return value + public void serviceResourcesUrl_smiUuid_Ver_Test() { + try { + ArrayList<NetworkResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); NetworkResourceCustomization d1 = new NetworkResourceCustomization(); d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); - ServiceMacroHolder ret = new ServiceMacroHolder(); - ret.setNetworkResourceCustomization(paramList); - PowerMockito.when(dbMock.getAllResourcesByServiceModelInvariantUuid(Mockito.anyString(),Mockito.anyString())).thenReturn (ret); + ServiceMacroHolder ret = new ServiceMacroHolder(); + ret.setNetworkResourceCustomization(paramList); + PowerMockito.when(dbMock.getAllResourcesByServiceModelInvariantUuid(Mockito.anyString(), Mockito.anyString())).thenReturn(ret); + // end + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceResources?serviceModelInvariantUuid=0cb9b26a-9820-48a7-86e5-16c510e993d9&serviceModelVersion=ver1"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // System.out.println(value); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonObject obj = respObj.getJsonObject("serviceResources"); + JsonArray jArray = obj.getJsonArray("networkResourceCustomization"); + assertTrue(jArray.size() == 1); + + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String uuid = rec.getString("networkResourceModelUuid"); + + assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + } // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceResources?serviceModelInvariantUuid=0cb9b26a-9820-48a7-86e5-16c510e993d9&serviceModelVersion=ver1"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // System.out.println(value); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonObject obj = respObj.getJsonObject("serviceResources"); - JsonArray jArray = obj.getJsonArray("networkResourceCustomization"); - assertTrue(jArray.size() == 1); - - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String uuid = rec.getString("networkResourceModelUuid"); - - assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - } - // end - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + @Test - public void allottedResourcesUrl_aUuid_Test() - { - try { - List<AllottedResourceCustomization> paramList; - // set up mock return value + public void allottedResourcesUrl_aUuid_Test() { + try { + List<AllottedResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); AllottedResourceCustomization d1 = new AllottedResourceCustomization(); d1.setArModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); - PowerMockito.when(dbMock.getAllAllottedResourcesByArModelCustomizationUuid(Mockito.anyString())).thenReturn (paramList); + PowerMockito.when(dbMock.getAllAllottedResourcesByArModelCustomizationUuid(Mockito.anyString())).thenReturn(paramList); + // end + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/allottedResources/0cb9b26a-9820-48a7-86e5-16c510e993d9"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // System.out.println(value); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceAllottedResources"); + assertTrue(jArray.size() == 1); + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String uuid = rec.getString("arModelUuid"); + + assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + } // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/allottedResources/0cb9b26a-9820-48a7-86e5-16c510e993d9"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // System.out.println(value); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceAllottedResources"); - assertTrue(jArray.size() == 1); - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String uuid = rec.getString("arModelUuid"); - - assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - } - // end - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } - + @Test - public void serviceAllottedResourcesUrl_smiUuid_Test() - { - try { - List<AllottedResourceCustomization> paramList; - // set up mock return value + public void serviceAllottedResourcesUrl_smiUuid_Test() { + try { + List<AllottedResourceCustomization> paramList; + // set up mock return value paramList = new ArrayList<>(); AllottedResourceCustomization d1 = new AllottedResourceCustomization(); d1.setArModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); - PowerMockito.when(dbMock.getAllAllottedResourcesByServiceModelInvariantUuid(Mockito.anyString(), Mockito.anyString())).thenReturn (paramList); + PowerMockito.when(dbMock.getAllAllottedResourcesByServiceModelInvariantUuid(Mockito.anyString(), Mockito.anyString())).thenReturn(paramList); // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceAllottedResources?serviceModelInvariantUuid=0cb9b26a-9820-48a7-86e5-16c510e993d9&serviceModelVersion=ver1"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // System.out.println(value); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonArray jArray = respObj.getJsonArray("serviceAllottedResources"); - assertTrue(jArray.size() == 1); - if(jArray.size() == 1){ - JsonObject rec = jArray.getJsonObject(0); - String uuid = rec.getString("arModelUuid"); - - assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - } - // end - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/serviceAllottedResources?serviceModelInvariantUuid=0cb9b26a-9820-48a7-86e5-16c510e993d9&serviceModelVersion=ver1"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // System.out.println(value); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonArray jArray = respObj.getJsonArray("serviceAllottedResources"); + assertTrue(jArray.size() == 1); + if (jArray.size() == 1) { + JsonObject rec = jArray.getJsonObject(0); + String uuid = rec.getString("arModelUuid"); + + assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + } + // end + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } } @Test - public void vfModulesUrl_modelName_Test() - { - try { - // set up mock return value - VfModule vfm = new VfModule(); - vfm.setModelName("test Model"); - vfm.setModelUUID("0cb9b26a-9820-48a7-86e5-16c510e993d9"); - - VfModuleCustomization ret = new VfModuleCustomization(); - ret.setVfModule(vfm); - PowerMockito.when(dbMock.getVfModuleCustomizationByModelName(Mockito.anyString())).thenReturn (ret); + public void vfModulesUrl_modelName_Test() { + try { + // set up mock return value + VfModule vfm = new VfModule(); + vfm.setModelName("test Model"); + vfm.setModelUUID("0cb9b26a-9820-48a7-86e5-16c510e993d9"); + + VfModuleCustomization ret = new VfModuleCustomization(); + ret.setVfModule(vfm); + PowerMockito.when(dbMock.getVfModuleCustomizationByModelName(Mockito.anyString())).thenReturn(ret); + // end + + // Run + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:3099/v1/vfModules?vfModuleModelName=0cb9b26a-9820-48a7-86e5-16c510e993d9"); + Response response = target.request().get(); + String value = response.readEntity(String.class); + + // System.out.println(value); + + // prepare to inspect response + JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); + JsonObject respObj = reader.readObject(); + reader.close(); + JsonObject jObj = respObj.getJsonObject("modelInfo"); + String uuid = jObj.getString("modelUuid"); + String name = jObj.getString("modelName"); + assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + assertTrue(name.equals("test Model")); // end - - // Run - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:3099/v1/vfModules?vfModuleModelName=0cb9b26a-9820-48a7-86e5-16c510e993d9"); - Response response = target.request().get(); - String value = response.readEntity(String.class); - - // System.out.println(value); - - // prepare to inspect response - JsonReader reader = Json.createReader(new StringReader(value.replaceAll("\r?\n", ""))); - JsonObject respObj = reader.readObject(); - reader.close(); - JsonObject jObj = respObj.getJsonObject("modelInfo"); - String uuid = jObj.getString("modelUuid"); - String name = jObj.getString("modelName"); - assertTrue(uuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - assertTrue(name.equals("test Model")); - // end - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + @AfterClass public static void afterClass() throws Exception { - server.stop(); + server.stop(); } } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java index ee2c8db577..a7ee7f5ac7 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java @@ -43,70 +43,68 @@ import static org.junit.Assert.*; @RunWith(MockitoJUnitRunner.class) public class CatalogQueryTest { - - @Test - public void catalogQuerySetTemplateImpl_Test(){ - CatalogQuery mockCatalogQuery = Mockito.mock(CatalogQuery.class); - Mockito.doCallRealMethod().when(mockCatalogQuery).setTemplate(Mockito.anyString(), Mockito.anyMapOf(String.class, String.class)); - - Map<String,String> valueMap = new HashMap<>(); - valueMap.put("somekey", "somevalue"); - - String ret = mockCatalogQuery.setTemplate("<somekey>", valueMap); - - assertTrue(ret.equalsIgnoreCase("somevalue")); - } - - @Test - public void smartToJson_Test() - { + + @Test + public void catalogQuerySetTemplateImpl_Test() { + CatalogQuery mockCatalogQuery = Mockito.mock(CatalogQuery.class); + Mockito.doCallRealMethod().when(mockCatalogQuery).setTemplate(Mockito.anyString(), Mockito.anyMapOf(String.class, String.class)); + + Map<String, String> valueMap = new HashMap<>(); + valueMap.put("somekey", "somevalue"); + + String ret = mockCatalogQuery.setTemplate("<somekey>", valueMap); + + assertTrue(ret.equalsIgnoreCase("somevalue")); + } + + @Test + public void smartToJson_Test() { List<VnfResourceCustomization> paramList = new ArrayList<>(); VnfResourceCustomization d1 = new VnfResourceCustomization(); d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); d1.setModelInstanceName("RG_6-26_mog11 0"); d1.setVersion("v1"); paramList.add(d1); - + QueryServiceVnfs qryResp = new QueryServiceVnfs(paramList); QueryServiceVnfs mockCatalogQuery = Mockito.spy(qryResp); Mockito.doCallRealMethod().when(mockCatalogQuery).smartToJSON(); - String ret = qryResp.smartToJSON(); - // System.out.println(ret); - + String ret = qryResp.smartToJSON(); + // System.out.println(ret); + JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", ""))); JsonObject respObj = reader.readObject(); reader.close(); JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - } - - @Test - public void toJsonString_Test() - { - CatalogQueryExtendedTest mockCatalogQuery = Mockito.mock(CatalogQueryExtendedTest.class); - Mockito.doCallRealMethod().when(mockCatalogQuery).JSON2(Mockito.anyBoolean(), Mockito.anyBoolean()); - String ret = mockCatalogQuery.JSON2(true, true); - - // System.out.println(ret); - + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + } + + @Test + public void toJsonString_Test() { + CatalogQueryExtendedTest mockCatalogQuery = Mockito.mock(CatalogQueryExtendedTest.class); + Mockito.doCallRealMethod().when(mockCatalogQuery).JSON2(Mockito.anyBoolean(), Mockito.anyBoolean()); + String ret = mockCatalogQuery.JSON2(true, true); + + // System.out.println(ret); + JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", ""))); JsonObject respObj = reader.readObject(); reader.close(); JsonArray jArray = respObj.getJsonArray("serviceVnfs"); - assertEquals(jArray.size(), 1); - assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - assertEquals(jArray.getJsonObject(0).getString("version"), "v2"); - } - - class CatalogQueryExtendedTest extends CatalogQuery{ - @Override - public String JSON2(boolean isArray, boolean isEmbed) { - return "{\"serviceVnfs\":[{\"version\":\"v2\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}"; - } - - } - + assertEquals(jArray.size(), 1); + assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + assertEquals(jArray.getJsonObject(0).getString("version"), "v2"); + } + + class CatalogQueryExtendedTest extends CatalogQuery { + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + return "{\"serviceVnfs\":[{\"version\":\"v2\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}"; + } + + } + } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java index 0d86a6cf10..fd9e23e9f0 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomizationTest.java @@ -39,29 +39,28 @@ import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization; @RunWith(MockitoJUnitRunner.class) public class QueryAllottedResourceCustomizationTest { - @Test - public void JSON2_Test() - { - List<AllottedResourceCustomization> paramList; + @Test + public void JSON2_Test() { + List<AllottedResourceCustomization> paramList; paramList = new ArrayList<>(); AllottedResourceCustomization d1 = new AllottedResourceCustomization(); d1.setModelInstanceName("0cb9b26a-9820-48a7-86e5-16c510e993d9"); d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); paramList.add(d1); - - QueryAllottedResourceCustomization qarcObj = new QueryAllottedResourceCustomization(paramList); - String ret = qarcObj.JSON2(true, true); - System.out.println(ret); - ret = "{" + ret + "}"; - + + QueryAllottedResourceCustomization qarcObj = new QueryAllottedResourceCustomization(paramList); + String ret = qarcObj.JSON2(true, true); + System.out.println(ret); + ret = "{" + ret + "}"; + JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", ""))); JsonObject respObj = reader.readObject(); reader.close(); JsonArray jArray = respObj.getJsonArray("serviceAllottedResources"); - assertEquals(jArray.size(), 1); - - assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelInstanceName"), "0cb9b26a-9820-48a7-86e5-16c510e993d9"); - assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); - } - + assertEquals(jArray.size(), 1); + + assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelInstanceName"), "0cb9b26a-9820-48a7-86e5-16c510e993d9"); + assertEquals(jArray.getJsonObject(0).getJsonObject("modelInfo").getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391"); + } + } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java index 3a767a8609..01bb570090 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMarcoHolderTest.java @@ -40,25 +40,24 @@ import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder; @RunWith(MockitoJUnitRunner.class) public class QueryServiceMarcoHolderTest { - @Test - public void JSON2_Test() - { - Service svc = new Service(); - svc.setModelUUID("0cb9b26a-9820-48a7-86e5-16c510e993d9"); - svc.setModelName("Testing Model One"); - ArrayList<NetworkResourceCustomization> paramList; + @Test + public void JSON2_Test() { + Service svc = new Service(); + svc.setModelUUID("0cb9b26a-9820-48a7-86e5-16c510e993d9"); + svc.setModelName("Testing Model One"); + ArrayList<NetworkResourceCustomization> paramList; paramList = new ArrayList<>(); NetworkResourceCustomization d1 = new NetworkResourceCustomization(); d1.setNetworkResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); - ServiceMacroHolder ret = new ServiceMacroHolder(svc); - ret.setNetworkResourceCustomization(paramList); - QueryServiceMacroHolder holder = new QueryServiceMacroHolder(ret); - String s = holder.JSON2(true, true); - - // System.out.println(s); + ServiceMacroHolder ret = new ServiceMacroHolder(svc); + ret.setNetworkResourceCustomization(paramList); + QueryServiceMacroHolder holder = new QueryServiceMacroHolder(ret); + String s = holder.JSON2(true, true); - // prepare to inspect response + // System.out.println(s); + + // prepare to inspect response JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); JsonObject respObj = reader.readObject(); reader.close(); @@ -66,9 +65,9 @@ public class QueryServiceMarcoHolderTest { JsonObject obj2 = obj.getJsonObject("modelInfo"); String modelName = obj2.getString("modelName"); String modelUuid = obj2.getString("modelUuid"); - - assertTrue(modelName.equals("Testing Model One")); - assertTrue(modelUuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - // end - } + + assertTrue(modelName.equals("Testing Model One")); + assertTrue(modelUuid.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + // end + } } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java index 1c855eaa72..0d4a4f9254 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworksTest.java @@ -40,33 +40,32 @@ import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder; @RunWith(MockitoJUnitRunner.class) public class QueryServiceNetworksTest { - - @Test - public void JSON2_Test() - { - ArrayList<NetworkResourceCustomization> paramList; + + @Test + public void JSON2_Test() { + ArrayList<NetworkResourceCustomization> paramList; paramList = new ArrayList<>(); NetworkResourceCustomization d1 = new NetworkResourceCustomization(); d1.setModelInstanceName("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); QueryServiceNetworks qsn = new QueryServiceNetworks(paramList); - - String s = qsn.JSON2(true, true); - s = "{" + s + "}"; - System.out.println(s); - - // prepare to inspect response + + String s = qsn.JSON2(true, true); + s = "{" + s + "}"; + System.out.println(s); + + // prepare to inspect response JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); JsonObject respObj = reader.readObject(); reader.close(); JsonArray objArr = respObj.getJsonArray("serviceNetworks"); - + assertTrue(objArr.size() == 1); - + JsonObject obj2 = objArr.getJsonObject(0).getJsonObject("modelInfo"); String modelName = obj2.getString("modelInstanceName"); - - assertTrue(modelName.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - // end - } + + assertTrue(modelName.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + // end + } } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java index 8c8fc967da..b48d8af66e 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfsTest.java @@ -40,34 +40,33 @@ import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization; @RunWith(MockitoJUnitRunner.class) public class QueryServiceVnfsTest { - @Test - public void JSON2_Test() - { - List<VnfResourceCustomization> paramList; + @Test + public void JSON2_Test() { + List<VnfResourceCustomization> paramList; paramList = new ArrayList<>(); VnfResourceCustomization d1 = new VnfResourceCustomization(); d1.setModelInstanceName("0cb9b26a-9820-48a7-86e5-16c510e993d9"); d1.setVnfResourceModelUuid("0cb9b26a-9820-48a7-86e5-16c510e993d9"); paramList.add(d1); QueryServiceVnfs qsn = new QueryServiceVnfs(paramList); - - String s = qsn.JSON2(true, true); - s = "{" + s + "}"; - System.out.println(s); - - // prepare to inspect response + + String s = qsn.JSON2(true, true); + s = "{" + s + "}"; + System.out.println(s); + + // prepare to inspect response JsonReader reader = Json.createReader(new StringReader(s.replaceAll("\r?\n", ""))); JsonObject respObj = reader.readObject(); reader.close(); JsonArray objArr = respObj.getJsonArray("serviceVnfs"); - + assertTrue(objArr.size() == 1); - + JsonObject obj2 = objArr.getJsonObject(0).getJsonObject("modelInfo"); String modelName = obj2.getString("modelInstanceName"); - - assertTrue(modelName.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); - // end - - } + + assertTrue(modelName.equals("0cb9b26a-9820-48a7-86e5-16c510e993d9")); + // end + + } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java index 5e3f79add6..8b64f9325e 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java @@ -43,45 +43,44 @@ public class ObjectFactoryTest { * Test method for {@link org.openecomp.mso.adapters.sdnc.ObjectFactory#createRequestHeader()}. */ @Test - public final void testCreateRequestHeader () { - ObjectFactory of = new ObjectFactory (); - RequestHeader rh = of.createRequestHeader (); - rh.setCallbackUrl ("callback"); - rh.setMsoAction ("action"); - rh.setRequestId ("reqid"); - rh.setSvcAction ("svcAction"); - rh.setSvcInstanceId ("svcId"); - rh.setSvcOperation ("op"); - + public final void testCreateRequestHeader() { + ObjectFactory of = new ObjectFactory(); + RequestHeader rh = of.createRequestHeader(); + rh.setCallbackUrl("callback"); + rh.setMsoAction("action"); + rh.setRequestId("reqid"); + rh.setSvcAction("svcAction"); + rh.setSvcInstanceId("svcId"); + rh.setSvcOperation("op"); + try { JAXBContext jaxbContext = JAXBContext.newInstance(RequestHeader.class); jaxbMarshaller = jaxbContext.createMarshaller(); - + JAXBContext jaxbContext2 = JAXBContext.newInstance(RequestHeader.class); jaxbUnmarshaller = jaxbContext2.createUnmarshaller(); - } - catch (JAXBException e) { - e.printStackTrace (); + } catch (JAXBException e) { + e.printStackTrace(); fail(); return; } StringWriter writer = new StringWriter(); try { - jaxbMarshaller.marshal (rh, writer); + jaxbMarshaller.marshal(rh, writer); } catch (JAXBException e) { e.printStackTrace(); - fail (); + fail(); } - String marshalled = writer.toString (); - assert(marshalled.contains ("<RequestId>reqid</RequestId>")); - + String marshalled = writer.toString(); + assert (marshalled.contains("<RequestId>reqid</RequestId>")); + InputStream inputStream = new ByteArrayInputStream(marshalled.getBytes(Charset.forName("UTF-8"))); try { - RequestHeader res2 = (RequestHeader) jaxbUnmarshaller.unmarshal (inputStream); - assert(res2.getCallbackUrl ().equals ("callback")); - assert(res2.getMsoAction ().equals ("action")); - assert(res2.getSvcOperation ().equals ("op")); + RequestHeader res2 = (RequestHeader) jaxbUnmarshaller.unmarshal(inputStream); + assert (res2.getCallbackUrl().equals("callback")); + assert (res2.getMsoAction().equals("action")); + assert (res2.getSvcOperation().equals("op")); } catch (JAXBException e) { e.printStackTrace(); fail(); @@ -92,9 +91,9 @@ public class ObjectFactoryTest { * Test method for {@link org.openecomp.mso.adapters.sdnc.ObjectFactory#createSDNCAdapterResponse()}. */ @Test - public final void testCreateSDNCAdapterResponse () { - ObjectFactory of = new ObjectFactory (); - SDNCAdapterResponse ar = of.createSDNCAdapterResponse (); + public final void testCreateSDNCAdapterResponse() { + ObjectFactory of = new ObjectFactory(); + SDNCAdapterResponse ar = of.createSDNCAdapterResponse(); assert (ar != null); } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java index fa96b7983e..5fd2c84f1c 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java @@ -29,26 +29,26 @@ import org.openecomp.mso.adapters.sdnc.RequestHeader; public class SDNCAdapterRequestTest { - static Object sd= new SDNCAdapterRequest(); - static RequestHeader rh=new RequestHeader(); - - @BeforeClass - public static final void RHeader() - { - rh.setCallbackUrl("callback"); - rh.setMsoAction ("action"); - rh.setRequestId ("reqid"); - rh.setSvcAction ("svcAction"); - rh.setSvcInstanceId ("svcId"); - rh.setSvcOperation ("op"); - } - @Test - public final void testtoString(){ - ((SDNCAdapterRequest) sd).setRequestData("data"); - ((SDNCAdapterRequest) sd).setRequestHeader(rh); - assert (((SDNCAdapterRequest) sd).getRequestData()!= null) ; - assert(((SDNCAdapterRequest) sd).getRequestData().equals("data")); - assert(((SDNCAdapterRequest) sd).getRequestHeader().equals(rh)); - } + static Object sd = new SDNCAdapterRequest(); + static RequestHeader rh = new RequestHeader(); + + @BeforeClass + public static final void RHeader() { + rh.setCallbackUrl("callback"); + rh.setMsoAction("action"); + rh.setRequestId("reqid"); + rh.setSvcAction("svcAction"); + rh.setSvcInstanceId("svcId"); + rh.setSvcOperation("op"); + } + + @Test + public final void testtoString() { + ((SDNCAdapterRequest) sd).setRequestData("data"); + ((SDNCAdapterRequest) sd).setRequestHeader(rh); + assert (((SDNCAdapterRequest) sd).getRequestData() != null); + assert (((SDNCAdapterRequest) sd).getRequestData().equals("data")); + assert (((SDNCAdapterRequest) sd).getRequestHeader().equals(rh)); + } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java index 63aa49cf54..cb64528e78 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java @@ -27,27 +27,25 @@ import org.openecomp.mso.adapters.sdnc.client.SDNCAdapterCallbackRequest; public class SDNCAdapterCallbackRequestTest { - static SDNCAdapterCallbackRequest sdc = new SDNCAdapterCallbackRequest(); - static CallbackHeader ch = new CallbackHeader("413658f4-7f42-482e-b834-23a5c15657da-1474471336781","200","OK"); - - @Test - public void testSDNCAdapterCallbackRequest() - { - sdc.setCallbackHeader(ch); - sdc.setRequestData("data"); - assert(sdc.getCallbackHeader()!=null); - assert(sdc.getRequestData()!=null); - assert(sdc.getCallbackHeader().equals(ch)); - assert(sdc.getRequestData().equals("data")); - - } - - @Test - public void testtoString() - { - assert(ch.toString()!=null); - } - + static SDNCAdapterCallbackRequest sdc = new SDNCAdapterCallbackRequest(); + static CallbackHeader ch = new CallbackHeader("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", "200", "OK"); + + @Test + public void testSDNCAdapterCallbackRequest() { + sdc.setCallbackHeader(ch); + sdc.setRequestData("data"); + assert (sdc.getCallbackHeader() != null); + assert (sdc.getRequestData() != null); + assert (sdc.getCallbackHeader().equals(ch)); + assert (sdc.getRequestData().equals("data")); + + } + + @Test + public void testtoString() { + assert (ch.toString() != null); + } + } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java index 55295fc3ea..0845315f67 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java @@ -33,20 +33,21 @@ import org.openecomp.mso.properties.MsoPropertiesFactory; public class RequestTunablesTest { - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - + public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + /** * This method is called before any test occurs. * It creates a fake tree from scratch - * @throws MsoPropertiesException + * + * @throws MsoPropertiesException */ @BeforeClass - public static final void prepare () throws MsoPropertiesException { - ClassLoader classLoader = RequestTunablesTest.class.getClassLoader (); - String path = classLoader.getResource ("mso.properties").toString ().substring (5); - + public static final void prepare() throws MsoPropertiesException { + ClassLoader classLoader = RequestTunablesTest.class.getClassLoader(); + String path = classLoader.getResource("mso.properties").toString().substring(5); + msoPropertiesFactory.initializeMsoProperties(RequestTunables.MSO_PROP_SDNC_ADAPTER, path); - + } /** @@ -55,20 +56,20 @@ public class RequestTunablesTest { * . */ @Test - public final void testRequestTunables () { - RequestTunables rt = new RequestTunables (null, null, "op", null,msoPropertiesFactory); - assert(rt.getReqId ().length ()==0); - rt = new RequestTunables ("reqId", "msoAction", null, "query",msoPropertiesFactory); - rt.setTunables (); - System.out.println(rt.toString ()); - // assert (rt.getReqMethod ().equals ("toto")); - assert (rt.getTimeout () != null); - assert (rt.getAction ().equals ("query")); - assert (rt.getMsoAction ().equals ("msoAction")); - assert (rt.getHeaderName ().equals ("sdnc-request-header")); - assert (rt.getOperation ().length () == 0); - assert (rt.getAsyncInd ().equals ("N")); - assert (rt.getReqId ().equals ("reqId")); + public final void testRequestTunables() { + RequestTunables rt = new RequestTunables(null, null, "op", null, msoPropertiesFactory); + assert (rt.getReqId().length() == 0); + rt = new RequestTunables("reqId", "msoAction", null, "query", msoPropertiesFactory); + rt.setTunables(); + System.out.println(rt.toString()); + // assert (rt.getReqMethod ().equals ("toto")); + assert (rt.getTimeout() != null); + assert (rt.getAction().equals("query")); + assert (rt.getMsoAction().equals("msoAction")); + assert (rt.getHeaderName().equals("sdnc-request-header")); + assert (rt.getOperation().length() == 0); + assert (rt.getAsyncInd().equals("N")); + assert (rt.getReqId().equals("reqId")); } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java index 1921a9961a..3b7eef5f42 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java @@ -39,439 +39,438 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; - /** * JSON object mapping tests. */ public class ObjectMappingTest { - private static final String EOL = "\n"; - - private final String SDNC_SERVICE_REQUEST = - "{" + EOL + - " \"SDNCServiceRequest\": {" + EOL + - " \"requestInformation\": {" + EOL + - " \"requestId\": \"413658f4-7f42-482e-b834-23a5c15657da\"," + EOL + - " \"source\": \"CCD\"," + EOL + - " \"notificationUrl\": \"https://ccd-host:8080/notifications\"" + EOL + - " }," + EOL + - " \"serviceInformation\": {" + EOL + - " \"serviceType\": \"vHNFaaS\"," + EOL + - " \"serviceInstanceId\": \"74e65b2b637441bca078e63e44bb511b\"," + EOL + - " \"subscriberName\": \"IST_SG_0902_3003\"," + EOL + - " \"subscriberGlobalId\": \"IST15_0902_3003\"" + EOL + - " }," + EOL + - " \"bpNotificationUrl\": \"http://localhost:8080/mso/SDNCAdapterCallbackService\"," + EOL + - "((BP-TIMEOUT))" + - " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL + - " \"sdncService\": \"vhnf\"," + EOL + - " \"sdncOperation\": \"service-topology-cust-assign-operation\"," + EOL + - " \"sdncServiceDataType\": \"XML\"," + EOL + - " \"sdncServiceData\": \"<vhnf-cust-stage-information><dhv-service-instance-id>c26dfed652164d60a17461734422b085</dhv-service-instance-id><hnportal-primary-vnf-host-name>HOSTNAME</hnportal-primary-vnf-host-name></vhnf-cust-stage-information>\"" + EOL + - " }" + EOL + - "}" + EOL; - - private final String SDNC_SERVICE_RESPONSE = - "{" + EOL + - " \"SDNCServiceResponse\": {" + EOL + - " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL + - " \"responseCode\": \"200\"," + EOL + - "((RESPONSE-MESSAGE))" + - " \"ackFinalIndicator\": \"Y\"" + EOL + - "((RESPONSE-PARAMS))" + - " }" + EOL + - "}" + EOL; - - private final String SDNC_SERVICE_ERROR = - "{" + EOL + - " \"SDNCServiceError\": {" + EOL + - " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL + - " \"responseCode\": \"500\"," + EOL + - "((RESPONSE-MESSAGE))" + - " \"ackFinalIndicator\": \"Y\"" + EOL + - " }" + EOL + - "}" + EOL; - - private final String SDNC_EVENT = - "{" + EOL + - " \"SDNCEvent\": {" + EOL + - " \"eventType\": \"ACTIVATION\"," + EOL + - " \"eventCorrelatorType\": \"HOST-NAME\"," + EOL + - " \"eventCorrelator\": \"USOSTCDALTX0101UJZZ31\"" + EOL + - "((EVENT-PARAMS))" + - " }" + EOL + - "}" + EOL; - - private final String PARAMS = - "{\"entry\":[{\"key\":\"P1\",\"value\":\"V1\"},{\"key\":\"P2\",\"value\":\"V2\"},{\"key\":\"P3\",\"value\":\"V3\"}]}"; - - @Test - public final void jsonToSDNCServiceRequest() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - String json = SDNC_SERVICE_REQUEST; - json = json.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL); - - SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId()); - assertEquals("CCD", object.getRequestInformation().getSource()); - assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl()); - assertEquals("vHNFaaS", object.getServiceInformation().getServiceType()); - assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId()); - assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName()); - assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId()); - assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl()); - assertEquals("PT5M", object.getBPTimeout()); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); - assertEquals("vhnf", object.getSDNCService()); - assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation()); - assertEquals("XML", object.getSDNCServiceDataType()); - assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>")); - } - - @Test - public final void jsonToSDNCServiceRequestWithoutOptionalFields() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // bpTimeout is optional. - String json = SDNC_SERVICE_REQUEST; - json = json.replace("((BP-TIMEOUT))", ""); - - SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId()); - assertEquals("CCD", object.getRequestInformation().getSource()); - assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl()); - assertEquals("vHNFaaS", object.getServiceInformation().getServiceType()); - assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId()); - assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName()); - assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId()); - assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl()); - assertNull(object.getBPTimeout()); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); - assertEquals("vhnf", object.getSDNCService()); - assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation()); - assertEquals("XML", object.getSDNCServiceDataType()); - assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>")); - } - - @Test - public final void jsonFromSDNCServiceRequest() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // Convert source json string to object. - String json1 = SDNC_SERVICE_REQUEST; - json1 = json1.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL); - SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class); - - // Convert resulting object back to json. - String json2 = object1.toJson(); - System.out.println("Generated JSON for " + object1.getClass().getSimpleName() - + ":" + System.lineSeparator() + json2); - assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceRequest\":{")); - - // Convert generated json string to another object. - SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class); - - // Compare the first object to the second object. - assertTrue(serializedEquals(object1, object2)); - } - - @Test - public final void jsonFromSDNCServiceRequestWithoutOptionalFields() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // Convert source json string to object. - String json1 = SDNC_SERVICE_REQUEST; - json1 = json1.replace("((BP-TIMEOUT))", ""); - SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class); - - // Convert resulting object back to json. - String json2 = object1.toJson(); - System.out.println("Generated JSON for " + object1.getClass().getSimpleName() - + ":" + System.lineSeparator() + json2); - assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceRequest\":{")); - - // Convert generated json string to another object. - SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class); - - // Compare the first object to the second object. - assertTrue(serializedEquals(object1, object2)); - } - - @Test - public final void jsonToSDNCServiceResponse() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - String json = SDNC_SERVICE_RESPONSE; - json = json.replace("((RESPONSE-MESSAGE))", " \"responseMessage\": \"" + "OK" + "\"," + EOL); - json = json.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); - - SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); - assertEquals("200", object.getResponseCode()); - assertEquals("OK", object.getResponseMessage()); - assertEquals("Y", object.getAckFinalIndicator()); - assertEquals("V1", object.getParams().get("P1")); - assertEquals("V2", object.getParams().get("P2")); - assertEquals("V3", object.getParams().get("P3")); - } - - @Test - public final void jsonToSDNCServiceResponseWithoutOptionalFields() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // responseMessage is optional. - String json = SDNC_SERVICE_RESPONSE; - json = json.replace("((RESPONSE-MESSAGE))", ""); - json = json.replace("((RESPONSE-PARAMS))", ""); - - SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); - assertEquals("200", object.getResponseCode()); - assertNull(object.getResponseMessage()); - assertEquals("Y", object.getAckFinalIndicator()); - assertNull(object.getParams()); - } - - @Test - public final void jsonFromSDNCServiceResponse() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // Convert source json string to object. - String json1 = SDNC_SERVICE_RESPONSE; - json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL); - json1 = json1.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); - SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class); - - // Convert resulting object back to json. - String json2 = object1.toJson(); - System.out.println("Generated JSON for " + object1.getClass().getSimpleName() - + ":" + System.lineSeparator() + json2); - assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceResponse\":{")); - - // Convert generated json string to another object. - SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class); - - // Compare the first object to the second object. - assertTrue(serializedEquals(object1, object2)); - } - - @Test - public final void jsonFromSDNCServiceResponseWithoutOptionalFields() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // Convert source json string to object. - String json1 = SDNC_SERVICE_RESPONSE; - json1 = json1.replace("((RESPONSE-MESSAGE))", ""); - json1 = json1.replace("((RESPONSE-PARAMS))", ""); - SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class); - - // Convert resulting object back to json. - String json2 = object1.toJson(); - System.out.println("Generated JSON for " + object1.getClass().getSimpleName() - + ":" + System.lineSeparator() + json2); - assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceResponse\":{")); - - // Convert generated json string to another object. - SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class); - - // Compare the first object to the second object. - assertTrue(serializedEquals(object1, object2)); - } - - @Test - public final void jsonToSDNCServiceError() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - String json = SDNC_SERVICE_ERROR; - json = json.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "SOMETHING BAD" + "\"," + EOL); - - SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); - assertEquals("500", object.getResponseCode()); - assertEquals("SOMETHING BAD", object.getResponseMessage()); - assertEquals("Y", object.getAckFinalIndicator()); - } - - @Test - public final void jsonToSDNCServiceErrorWithoutOptionalFields() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // responseMessage is optional. - String json = SDNC_SERVICE_ERROR; - json = json.replace("((RESPONSE-MESSAGE))", ""); - - SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); - assertEquals("500", object.getResponseCode()); - assertNull(object.getResponseMessage()); - assertEquals("Y", object.getAckFinalIndicator()); - } - - @Test - public final void jsonFromSDNCServiceError() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // Convert source json string to object. - String json1 = SDNC_SERVICE_ERROR; - json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL); - SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class); - - // Convert resulting object back to json. - String json2 = object1.toJson(); - System.out.println("Generated JSON for " + object1.getClass().getSimpleName() - + ":" + System.lineSeparator() + json2); - assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceError\":{")); - - // Convert generated json string to another object. - SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class); - - // Compare the first object to the second object. - assertTrue(serializedEquals(object1, object2)); - } - - @Test - public final void jsonFromSDNCServiceErrorWithoutOptionalFields() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // Convert source json string to object. - String json1 = SDNC_SERVICE_ERROR; - json1 = json1.replace("((RESPONSE-MESSAGE))", ""); - SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class); - - // Convert resulting object back to json. - String json2 = object1.toJson(); - System.out.println("Generated JSON for " + object1.getClass().getSimpleName() - + ":" + System.lineSeparator() + json2); - assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceError\":{")); - - // Convert generated json string to another object. - SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class); - - // Compare the first object to the second object. - assertTrue(serializedEquals(object1, object2)); - } - - @Test - public final void jsonToSDNCEvent() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - String json = SDNC_EVENT; - json = json.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); - - SDNCEvent object = mapper.readValue(json, SDNCEvent.class); - assertEquals("ACTIVATION", object.getEventType()); - assertEquals("HOST-NAME", object.getEventCorrelatorType()); - assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator()); - assertEquals("V1", object.getParams().get("P1")); - assertEquals("V2", object.getParams().get("P2")); - assertEquals("V3", object.getParams().get("P3")); - } - - @Test - public final void jsonToSDNCEventWithoutOptionalFields() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // params are optional. - String json = SDNC_EVENT; - json = json.replace("((EVENT-PARAMS))", ""); - - SDNCEvent object = mapper.readValue(json, SDNCEvent.class); - assertEquals("ACTIVATION", object.getEventType()); - assertEquals("HOST-NAME", object.getEventCorrelatorType()); - assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator()); - assertNull(object.getParams()); - } - - @Test - public final void jsonFromSDNCEvent() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - - // Convert source json string to object. - String json1 = SDNC_EVENT; - json1 = json1.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); - SDNCEvent object1 = mapper.readValue(json1, SDNCEvent.class); - - // Convert resulting object back to json. - String json2 = object1.toJson(); - System.out.println("Generated JSON for " + object1.getClass().getSimpleName() - + ":" + System.lineSeparator() + json2); - assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCEvent\":{")); - - // Convert generated json string to another object. - SDNCEvent object2 = mapper.readValue(json2, SDNCEvent.class); - - // Compare the first object to the second object. - assertTrue(serializedEquals(object1, object2)); - } - - /** - * Tests equality of two objects by comparing their serialized form. - * WARNING: this works pretty well as long as the objects don't contain - * collections like maps and sets that are semantically equal, but have - * different internal ordering of elements. - */ - private boolean serializedEquals(Serializable object1, Serializable object2) throws IOException { - ByteArrayOutputStream byteStream1 = new ByteArrayOutputStream(); - ObjectOutputStream objectStream1 = new ObjectOutputStream(byteStream1); - objectStream1.writeObject(object1); - objectStream1.close(); - - ByteArrayOutputStream byteStream2 = new ByteArrayOutputStream(); - ObjectOutputStream objectStream2 = new ObjectOutputStream(byteStream2); - objectStream2.writeObject(object2); - objectStream2.close(); - - return Arrays.equals(byteStream1.toByteArray(), byteStream2.toByteArray()); - } - - private void logTest() { - StackTraceElement[] st = Thread.currentThread().getStackTrace(); - String method = st[2].getMethodName(); - System.out.println("RUNNING TEST: " + method); - } + private static final String EOL = "\n"; + + private final String SDNC_SERVICE_REQUEST = + "{" + EOL + + " \"SDNCServiceRequest\": {" + EOL + + " \"requestInformation\": {" + EOL + + " \"requestId\": \"413658f4-7f42-482e-b834-23a5c15657da\"," + EOL + + " \"source\": \"CCD\"," + EOL + + " \"notificationUrl\": \"https://ccd-host:8080/notifications\"" + EOL + + " }," + EOL + + " \"serviceInformation\": {" + EOL + + " \"serviceType\": \"vHNFaaS\"," + EOL + + " \"serviceInstanceId\": \"74e65b2b637441bca078e63e44bb511b\"," + EOL + + " \"subscriberName\": \"IST_SG_0902_3003\"," + EOL + + " \"subscriberGlobalId\": \"IST15_0902_3003\"" + EOL + + " }," + EOL + + " \"bpNotificationUrl\": \"http://localhost:8080/mso/SDNCAdapterCallbackService\"," + EOL + + "((BP-TIMEOUT))" + + " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL + + " \"sdncService\": \"vhnf\"," + EOL + + " \"sdncOperation\": \"service-topology-cust-assign-operation\"," + EOL + + " \"sdncServiceDataType\": \"XML\"," + EOL + + " \"sdncServiceData\": \"<vhnf-cust-stage-information><dhv-service-instance-id>c26dfed652164d60a17461734422b085</dhv-service-instance-id><hnportal-primary-vnf-host-name>HOSTNAME</hnportal-primary-vnf-host-name></vhnf-cust-stage-information>\"" + EOL + + " }" + EOL + + "}" + EOL; + + private final String SDNC_SERVICE_RESPONSE = + "{" + EOL + + " \"SDNCServiceResponse\": {" + EOL + + " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL + + " \"responseCode\": \"200\"," + EOL + + "((RESPONSE-MESSAGE))" + + " \"ackFinalIndicator\": \"Y\"" + EOL + + "((RESPONSE-PARAMS))" + + " }" + EOL + + "}" + EOL; + + private final String SDNC_SERVICE_ERROR = + "{" + EOL + + " \"SDNCServiceError\": {" + EOL + + " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL + + " \"responseCode\": \"500\"," + EOL + + "((RESPONSE-MESSAGE))" + + " \"ackFinalIndicator\": \"Y\"" + EOL + + " }" + EOL + + "}" + EOL; + + private final String SDNC_EVENT = + "{" + EOL + + " \"SDNCEvent\": {" + EOL + + " \"eventType\": \"ACTIVATION\"," + EOL + + " \"eventCorrelatorType\": \"HOST-NAME\"," + EOL + + " \"eventCorrelator\": \"USOSTCDALTX0101UJZZ31\"" + EOL + + "((EVENT-PARAMS))" + + " }" + EOL + + "}" + EOL; + + private final String PARAMS = + "{\"entry\":[{\"key\":\"P1\",\"value\":\"V1\"},{\"key\":\"P2\",\"value\":\"V2\"},{\"key\":\"P3\",\"value\":\"V3\"}]}"; + + @Test + public final void jsonToSDNCServiceRequest() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + String json = SDNC_SERVICE_REQUEST; + json = json.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL); + + SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId()); + assertEquals("CCD", object.getRequestInformation().getSource()); + assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl()); + assertEquals("vHNFaaS", object.getServiceInformation().getServiceType()); + assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId()); + assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName()); + assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId()); + assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl()); + assertEquals("PT5M", object.getBPTimeout()); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); + assertEquals("vhnf", object.getSDNCService()); + assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation()); + assertEquals("XML", object.getSDNCServiceDataType()); + assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>")); + } + + @Test + public final void jsonToSDNCServiceRequestWithoutOptionalFields() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // bpTimeout is optional. + String json = SDNC_SERVICE_REQUEST; + json = json.replace("((BP-TIMEOUT))", ""); + + SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId()); + assertEquals("CCD", object.getRequestInformation().getSource()); + assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl()); + assertEquals("vHNFaaS", object.getServiceInformation().getServiceType()); + assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId()); + assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName()); + assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId()); + assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl()); + assertNull(object.getBPTimeout()); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); + assertEquals("vhnf", object.getSDNCService()); + assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation()); + assertEquals("XML", object.getSDNCServiceDataType()); + assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>")); + } + + @Test + public final void jsonFromSDNCServiceRequest() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // Convert source json string to object. + String json1 = SDNC_SERVICE_REQUEST; + json1 = json1.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL); + SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class); + + // Convert resulting object back to json. + String json2 = object1.toJson(); + System.out.println("Generated JSON for " + object1.getClass().getSimpleName() + + ":" + System.lineSeparator() + json2); + assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceRequest\":{")); + + // Convert generated json string to another object. + SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class); + + // Compare the first object to the second object. + assertTrue(serializedEquals(object1, object2)); + } + + @Test + public final void jsonFromSDNCServiceRequestWithoutOptionalFields() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // Convert source json string to object. + String json1 = SDNC_SERVICE_REQUEST; + json1 = json1.replace("((BP-TIMEOUT))", ""); + SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class); + + // Convert resulting object back to json. + String json2 = object1.toJson(); + System.out.println("Generated JSON for " + object1.getClass().getSimpleName() + + ":" + System.lineSeparator() + json2); + assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceRequest\":{")); + + // Convert generated json string to another object. + SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class); + + // Compare the first object to the second object. + assertTrue(serializedEquals(object1, object2)); + } + + @Test + public final void jsonToSDNCServiceResponse() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + String json = SDNC_SERVICE_RESPONSE; + json = json.replace("((RESPONSE-MESSAGE))", " \"responseMessage\": \"" + "OK" + "\"," + EOL); + json = json.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); + + SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); + assertEquals("200", object.getResponseCode()); + assertEquals("OK", object.getResponseMessage()); + assertEquals("Y", object.getAckFinalIndicator()); + assertEquals("V1", object.getParams().get("P1")); + assertEquals("V2", object.getParams().get("P2")); + assertEquals("V3", object.getParams().get("P3")); + } + + @Test + public final void jsonToSDNCServiceResponseWithoutOptionalFields() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // responseMessage is optional. + String json = SDNC_SERVICE_RESPONSE; + json = json.replace("((RESPONSE-MESSAGE))", ""); + json = json.replace("((RESPONSE-PARAMS))", ""); + + SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); + assertEquals("200", object.getResponseCode()); + assertNull(object.getResponseMessage()); + assertEquals("Y", object.getAckFinalIndicator()); + assertNull(object.getParams()); + } + + @Test + public final void jsonFromSDNCServiceResponse() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // Convert source json string to object. + String json1 = SDNC_SERVICE_RESPONSE; + json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL); + json1 = json1.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); + SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class); + + // Convert resulting object back to json. + String json2 = object1.toJson(); + System.out.println("Generated JSON for " + object1.getClass().getSimpleName() + + ":" + System.lineSeparator() + json2); + assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceResponse\":{")); + + // Convert generated json string to another object. + SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class); + + // Compare the first object to the second object. + assertTrue(serializedEquals(object1, object2)); + } + + @Test + public final void jsonFromSDNCServiceResponseWithoutOptionalFields() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // Convert source json string to object. + String json1 = SDNC_SERVICE_RESPONSE; + json1 = json1.replace("((RESPONSE-MESSAGE))", ""); + json1 = json1.replace("((RESPONSE-PARAMS))", ""); + SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class); + + // Convert resulting object back to json. + String json2 = object1.toJson(); + System.out.println("Generated JSON for " + object1.getClass().getSimpleName() + + ":" + System.lineSeparator() + json2); + assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceResponse\":{")); + + // Convert generated json string to another object. + SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class); + + // Compare the first object to the second object. + assertTrue(serializedEquals(object1, object2)); + } + + @Test + public final void jsonToSDNCServiceError() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + String json = SDNC_SERVICE_ERROR; + json = json.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "SOMETHING BAD" + "\"," + EOL); + + SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); + assertEquals("500", object.getResponseCode()); + assertEquals("SOMETHING BAD", object.getResponseMessage()); + assertEquals("Y", object.getAckFinalIndicator()); + } + + @Test + public final void jsonToSDNCServiceErrorWithoutOptionalFields() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // responseMessage is optional. + String json = SDNC_SERVICE_ERROR; + json = json.replace("((RESPONSE-MESSAGE))", ""); + + SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId()); + assertEquals("500", object.getResponseCode()); + assertNull(object.getResponseMessage()); + assertEquals("Y", object.getAckFinalIndicator()); + } + + @Test + public final void jsonFromSDNCServiceError() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // Convert source json string to object. + String json1 = SDNC_SERVICE_ERROR; + json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL); + SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class); + + // Convert resulting object back to json. + String json2 = object1.toJson(); + System.out.println("Generated JSON for " + object1.getClass().getSimpleName() + + ":" + System.lineSeparator() + json2); + assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceError\":{")); + + // Convert generated json string to another object. + SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class); + + // Compare the first object to the second object. + assertTrue(serializedEquals(object1, object2)); + } + + @Test + public final void jsonFromSDNCServiceErrorWithoutOptionalFields() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // Convert source json string to object. + String json1 = SDNC_SERVICE_ERROR; + json1 = json1.replace("((RESPONSE-MESSAGE))", ""); + SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class); + + // Convert resulting object back to json. + String json2 = object1.toJson(); + System.out.println("Generated JSON for " + object1.getClass().getSimpleName() + + ":" + System.lineSeparator() + json2); + assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceError\":{")); + + // Convert generated json string to another object. + SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class); + + // Compare the first object to the second object. + assertTrue(serializedEquals(object1, object2)); + } + + @Test + public final void jsonToSDNCEvent() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + String json = SDNC_EVENT; + json = json.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); + + SDNCEvent object = mapper.readValue(json, SDNCEvent.class); + assertEquals("ACTIVATION", object.getEventType()); + assertEquals("HOST-NAME", object.getEventCorrelatorType()); + assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator()); + assertEquals("V1", object.getParams().get("P1")); + assertEquals("V2", object.getParams().get("P2")); + assertEquals("V3", object.getParams().get("P3")); + } + + @Test + public final void jsonToSDNCEventWithoutOptionalFields() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // params are optional. + String json = SDNC_EVENT; + json = json.replace("((EVENT-PARAMS))", ""); + + SDNCEvent object = mapper.readValue(json, SDNCEvent.class); + assertEquals("ACTIVATION", object.getEventType()); + assertEquals("HOST-NAME", object.getEventCorrelatorType()); + assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator()); + assertNull(object.getParams()); + } + + @Test + public final void jsonFromSDNCEvent() throws Exception { + logTest(); + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + + // Convert source json string to object. + String json1 = SDNC_EVENT; + json1 = json1.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); + SDNCEvent object1 = mapper.readValue(json1, SDNCEvent.class); + + // Convert resulting object back to json. + String json2 = object1.toJson(); + System.out.println("Generated JSON for " + object1.getClass().getSimpleName() + + ":" + System.lineSeparator() + json2); + assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCEvent\":{")); + + // Convert generated json string to another object. + SDNCEvent object2 = mapper.readValue(json2, SDNCEvent.class); + + // Compare the first object to the second object. + assertTrue(serializedEquals(object1, object2)); + } + + /** + * Tests equality of two objects by comparing their serialized form. + * WARNING: this works pretty well as long as the objects don't contain + * collections like maps and sets that are semantically equal, but have + * different internal ordering of elements. + */ + private boolean serializedEquals(Serializable object1, Serializable object2) throws IOException { + ByteArrayOutputStream byteStream1 = new ByteArrayOutputStream(); + ObjectOutputStream objectStream1 = new ObjectOutputStream(byteStream1); + objectStream1.writeObject(object1); + objectStream1.close(); + + ByteArrayOutputStream byteStream2 = new ByteArrayOutputStream(); + ObjectOutputStream objectStream2 = new ObjectOutputStream(byteStream2); + objectStream2.writeObject(object2); + objectStream2.close(); + + return Arrays.equals(byteStream1.toByteArray(), byteStream2.toByteArray()); + } + + private void logTest() { + StackTraceElement[] st = Thread.currentThread().getStackTrace(); + String method = st[2].getMethodName(); + System.out.println("RUNNING TEST: " + method); + } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java index 275c2acd14..a4b4d891d4 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java @@ -21,6 +21,7 @@ package org.openecomp.mso.adapters.sdnc.util; import java.util.UUID; + import org.junit.Test; @@ -30,14 +31,14 @@ public class SDNCRequestIdUtilTest { * Test method for {@link org.openecomp.mso.adapters.sdnc.SDNCRequestIdUtil#getSDNCOriginalRequestId()}. */ @Test - public final void testGetSDNCOriginalRequestId () { - String originalRequestId = UUID.randomUUID().toString(); - String postfixedRequestId = originalRequestId + "-1466203712068"; - String postfixedRequestId2 = originalRequestId + "-1466203712068-2"; - - assert(SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId).equals(originalRequestId)); - assert(SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId2).equals(postfixedRequestId2)); - + public final void testGetSDNCOriginalRequestId() { + String originalRequestId = UUID.randomUUID().toString(); + String postfixedRequestId = originalRequestId + "-1466203712068"; + String postfixedRequestId2 = originalRequestId + "-1466203712068-2"; + + assert (SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId).equals(originalRequestId)); + assert (SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId2).equals(postfixedRequestId2)); + } } |