diff options
Diffstat (limited to 'vid-app-common/src/test')
9 files changed, 472 insertions, 10 deletions
diff --git a/vid-app-common/src/test/java/org/opencomp/vid/controller/VidControllerTest.java b/vid-app-common/src/test/java/org/opencomp/vid/controller/VidControllerTest.java new file mode 100644 index 000000000..05ca8c324 --- /dev/null +++ b/vid-app-common/src/test/java/org/opencomp/vid/controller/VidControllerTest.java @@ -0,0 +1,128 @@ +package org.opencomp.vid.controller; + +import net.javacrumbs.jsonunit.JsonAssert; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.AsdcClient; +import org.openecomp.vid.asdc.parser.ToscaParserImpl2; +import org.openecomp.vid.controller.WebConfig; +import org.openecomp.vid.model.*; +import org.openecomp.vid.properties.AsdcClientConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.Map; +import java.util.UUID; + +import static org.opencomp.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {WebConfig.class, AsdcClientConfiguration.class}) +public class VidControllerTest { + + @Autowired + private AsdcClient asdcClient; + + private String uuid = "f430728a-4530-42be-a577-1206b9484cef"; + //TODO: add as a test case. + private String vfFilePath = "vf-csar.JSON"; + private String vlFilePath = "vl-csar.JSON"; + + private ToscaParserImpl2 p2 = new ToscaParserImpl2(); + private ObjectMapper om = new ObjectMapper(); + final InputStream jsonFile = VidControllerTest.class.getClassLoader().getResourceAsStream(vfFilePath); + + + @Test + public void assertEqualsBetweenServices() throws Exception { + Service expectedService = getExpectedServiceModel().getService(); + Service actualService = p2.makeServiceModel(getCsarPath(), getServiceByUuid()).getService(); + JsonAssert.assertJsonEquals(expectedService, actualService); + } + + @Test + public void assertEqualBetweenObjects() throws Exception { + ServiceModel actualServiceModel = p2.makeServiceModel(getCsarPath(), getServiceByUuid()); + JsonAssert.assertJsonEquals(getExpectedServiceModel(), actualServiceModel); + } + + @Test + public void assertEqualsBetweenNetworkNodes() throws Exception { + Map<String, Network> expectedNetworksMap = getExpectedServiceModel().getNetworks(); + Map<String, Network> actualNetworksMap = p2.makeServiceModel(getCsarPath(), getServiceByUuid()).getNetworks(); + for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) { + Network expectedNetwork = entry.getValue(); + Network actualNetwork = actualNetworksMap.get(entry.getKey()); + Assert.assertEquals(expectedNetwork.getModelCustomizationName(), actualNetwork.getModelCustomizationName()); + verifyBaseNodeProperties(expectedNetwork, actualNetwork); + compareProperties(expectedNetwork.getProperties(), actualNetwork.getProperties()); + } + } + + //Because we are not supporting the old flow, the JSON are different by definition. + @Test + public void assertEqualsBetweenVnfsOfTosca() throws Exception { + Map<String, VNF> expectedVnfsMap = getExpectedServiceModel().getVnfs(); + Map<String, VNF> actualVnfsMap = p2.makeServiceModel(getCsarPath(), getServiceByUuid()).getVnfs(); + for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) { + VNF expectedVnf = entry.getValue(); + VNF actualVnf = actualVnfsMap.get(entry.getKey()); + verifyBaseNodeProperties(expectedVnf, actualVnf); + Assert.assertEquals(expectedVnf.getModelCustomizationName(), actualVnf.getModelCustomizationName()); + compareProperties(expectedVnf.getProperties(), actualVnf.getProperties()); + assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVnf), om.writeValueAsString(actualVnf)); + } + } + + @Test + public void assertEqualsBetweenVolumeGroups() throws Exception { + Map<String, VolumeGroup> actualVolumeGroups = p2.makeServiceModel(getCsarPath(), getServiceByUuid()).getVolumeGroups(); + Map<String, VolumeGroup> expectedVolumeGroups = getExpectedServiceModel().getVolumeGroups(); + JsonAssert.assertJsonEquals(actualVolumeGroups, expectedVolumeGroups); + } + + @Test + public void assertEqualsBetweenVfModules() throws Exception { + Map<String, VfModule> actualVfModules = p2.makeServiceModel(getCsarPath(), getServiceByUuid()).getVfModules(); + Map<String, VfModule> expectedVfModules = getExpectedServiceModel().getVfModules(); + JsonAssert.assertJsonEquals(actualVfModules, expectedVfModules); + } + + private void verifyBaseNodeProperties(Node expectedNode, Node actualNode) { + Assert.assertEquals(expectedNode.getName(), actualNode.getName()); + Assert.assertEquals(expectedNode.getCustomizationUuid(), actualNode.getCustomizationUuid()); + Assert.assertEquals(expectedNode.getDescription(), actualNode.getDescription()); + Assert.assertEquals(expectedNode.getInvariantUuid(), actualNode.getInvariantUuid()); + Assert.assertEquals(expectedNode.getUuid(), actualNode.getUuid()); + Assert.assertEquals(expectedNode.getVersion(), actualNode.getVersion()); + } + + private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) { + for (Map.Entry<String, String> property : expectedProperties.entrySet()) { + String expectedValue = property.getValue(); + String key = property.getKey(); + String actualValue = actualProperties.get(key); + Assert.assertEquals(expectedValue, actualValue); + } + } + + private NewServiceModel getExpectedServiceModel() throws IOException { + String expectedJsonAsString = IOUtils.toString(jsonFile).toString(); + return om.readValue(expectedJsonAsString,NewServiceModel.class); + } + + private Path getCsarPath() throws AsdcCatalogException { + return asdcClient.getServiceToscaModel(UUID.fromString(uuid)); + } + + private org.openecomp.vid.asdc.beans.Service getServiceByUuid() throws AsdcCatalogException { + return asdcClient.getService(UUID.fromString(uuid)); + } +}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/opencomp/vid/testUtils/TestUtils.java b/vid-app-common/src/test/java/org/opencomp/vid/testUtils/TestUtils.java new file mode 100644 index 000000000..29115e0aa --- /dev/null +++ b/vid-app-common/src/test/java/org/opencomp/vid/testUtils/TestUtils.java @@ -0,0 +1,65 @@ +package org.opencomp.vid.testUtils; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Assert; + +import java.util.Iterator; + +import static fj.parser.Parser.fail; + +/** + * Created by Oren on 6/7/17. + */ +public class TestUtils { + + /** + * The method compares between two jsons. the function assert that the actual object does not reduce or change the functionallity/parsing of the expected json. + * This means that if the expected JSON has a key which is null or the JSON doesn't have a key which contained in the expected JSON the assert will succeed and the will pass. + * For example : For JSON expected = {a:null} and actual {a:3} the test will pass + * Other example : For JSON expected = {a:3} and actual {a:null} the test will fail + * + * @param expected JSON + * @param actual JSON + */ + public static void assertJsonStringEqualsIgnoreNulls(String expected, String actual) { + if (expected == null || expected == JSONObject.NULL) {return;} + + JSONObject expectedJSON = new JSONObject(expected); + JSONObject actualJSON = new JSONObject(actual); + Iterator<?> keys = expectedJSON.keys(); + + while( keys.hasNext() ) { + String key = (String)keys.next(); + Object expectedValue = expectedJSON.get(key); + if (expectedValue == JSONObject.NULL){ + continue; + } + + Object actualValue = actualJSON.get(key); + + if (expectedValue instanceof JSONObject) { + String expectedVal = expectedValue.toString(); + String actualVal = actualValue.toString(); + assertJsonStringEqualsIgnoreNulls(expectedVal, actualVal); + } + else if (expectedValue instanceof JSONArray) { + if (actualValue instanceof JSONArray) { + JSONArray expectedJSONArray = (JSONArray)expectedValue; + JSONArray actualJSONArray = (JSONArray)expectedValue; + for (int i = 0; i < expectedJSONArray.length(); i++) { + String expectedItem = expectedJSONArray.getJSONObject(i).toString(); + String actualItem = actualJSONArray.getJSONObject(i).toString(); + assertJsonStringEqualsIgnoreNulls(expectedItem, actualItem); + } + } + else { + fail("expected: " + expectedValue + " got:" + actualValue); + } + } + else { + Assert.assertEquals(expectedValue, actualValue); + } + } + } +} diff --git a/vid-app-common/src/test/java/org/openecomp/ecomp/vid/selenium/LogOutLeftPane.java b/vid-app-common/src/test/java/org/openecomp/ecomp/vid/selenium/LogOutLeftPane.java index 66ea075e2..55aed8fb1 100755 --- a/vid-app-common/src/test/java/org/openecomp/ecomp/vid/selenium/LogOutLeftPane.java +++ b/vid-app-common/src/test/java/org/openecomp/ecomp/vid/selenium/LogOutLeftPane.java @@ -40,7 +40,7 @@ import org.testng.annotations.Test; /**
* The Class LogOutLeftPane.
*/
-@Test(enabled=true)
+@Test(enabled=false)
public class LogOutLeftPane {
/** The login button. */
diff --git a/vid-app-common/src/test/java/org/openecomp/fusion/core/MockApplicationContextTestSuite.java b/vid-app-common/src/test/java/org/openecomp/fusion/core/MockApplicationContextTestSuite.java index 64d72abef..2f5828b61 100755 --- a/vid-app-common/src/test/java/org/openecomp/fusion/core/MockApplicationContextTestSuite.java +++ b/vid-app-common/src/test/java/org/openecomp/fusion/core/MockApplicationContextTestSuite.java @@ -38,7 +38,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-
+import org.testng.annotations.Test;
import org.openecomp.portalsdk.core.conf.AppConfig;
import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
import org.openecomp.portalsdk.core.util.SystemProperties;
@@ -61,6 +61,7 @@ import org.openecomp.portalsdk.core.util.CacheManager; @WebAppConfiguration
@ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = {MockAppConfig.class})
@ActiveProfiles(value="test")
+@Test(enabled=false)
public class MockApplicationContextTestSuite {
/** The wac. */
diff --git a/vid-app-common/src/test/java/org/openecomp/fusionapp/service/ProfileServiceTest.java b/vid-app-common/src/test/java/org/openecomp/fusionapp/service/ProfileServiceTest.java index ce3e6ba5f..85c550d4c 100755 --- a/vid-app-common/src/test/java/org/openecomp/fusionapp/service/ProfileServiceTest.java +++ b/vid-app-common/src/test/java/org/openecomp/fusionapp/service/ProfileServiceTest.java @@ -36,6 +36,7 @@ import org.openecomp.portalsdk.core.service.UserProfileService; /**
* The Class ProfileServiceTest.
*/
+
public class ProfileServiceTest extends MockApplicationContextTestSuite {
/** The service. */
@@ -51,14 +52,13 @@ public class ProfileServiceTest extends MockApplicationContextTestSuite { */
@Test
public void testFindAll() {
-
- try {
- List<Profile> profiles = service.findAll();
- Assert.assertTrue(profiles.size() > 0);
- }
- catch (Exception e) {
- //TODO: this is only to make maven to not complaint
- return;
+
+ List<Profile> profiles;
+ try {
+ profiles = service.findAll();
+ Assert.assertTrue(profiles.size() > 0);
+ } catch (Exception e) {
+ Assert.assertTrue(false);
}
}
diff --git a/vid-app-common/src/test/resources/asdc.properties b/vid-app-common/src/test/resources/asdc.properties new file mode 100644 index 000000000..8352ff213 --- /dev/null +++ b/vid-app-common/src/test/resources/asdc.properties @@ -0,0 +1,6 @@ +asdc.client.type=REST + +asdc.client.rest.protocol=http +asdc.client.rest.host=c2.vm1.sdc.simpledemo.openecomp.org +asdc.client.rest.port=8080 +asdc.client.rest.auth=Basic dmlkOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU= diff --git a/vid-app-common/src/test/resources/sampleTosca.csar b/vid-app-common/src/test/resources/sampleTosca.csar Binary files differnew file mode 100644 index 000000000..d9c469a15 --- /dev/null +++ b/vid-app-common/src/test/resources/sampleTosca.csar diff --git a/vid-app-common/src/test/resources/vf-csar.JSON b/vid-app-common/src/test/resources/vf-csar.JSON new file mode 100644 index 000000000..bd1a01935 --- /dev/null +++ b/vid-app-common/src/test/resources/vf-csar.JSON @@ -0,0 +1,153 @@ +{ + "networks": { + }, + "service": { + "category": "Mobility", + "description": "Bla bla", + "inputs": { + "greatdefect0_availability_zone_max_count": { + "constraints": [ + ], + "default": 1, + "description": "", + "entry_schema": null, + "required": true, + "type": "integer" + }, + "greatdefect0_itc_name_0": { + "constraints": [ + ], + "default": "ab", + "description": "ixla itc instance name", + "entry_schema": null, + "required": true, + "type": "string" + }, + "greatdefect0_vf_module_id": { + "constraints": [ + ], + "default": "abc", + "description": "Unique ID for this VF Module instance", + "entry_schema": null, + "required": true, + "type": "string" + } + }, + "invariantUuid": "bd9bf71a-df22-4c95-8638-89f15d875395", + "name": "Moriya_new_test", + "serviceEcompNaming": "true", + "toscaModelURL": null, + "uuid": "48a52540-8772-4368-9cdb-1f124ea5c931", + "version": "1.0" + }, + "vfModules": { + "greatdefect0..Greatdefect..base_ixla..module-0": { + "commands": { + }, + "customizationUuid": "316e323d-611d-4007-a647-b1d2ecdaee9e", + "description": null, + "invariantUuid": "80ff85fb-cb11-42cb-9737-e47095d42756", + "modelCustomizationName": "Greatdefect..base_ixla..module-0", + "name": "Greatdefect..base_ixla..module-0", + "uuid": "01166434-ef34-4969-aaf2-626203d72e48", + "version": "3", + "volumeGroupAllowed": false + }, + "greatdefect0..Greatdefect..module_1_ixla..module-2": { + "commands": { + }, + "customizationUuid": "1106fca3-235a-4f92-8d5a-960a7336b32f", + "description": null, + "invariantUuid": "e0297a51-c670-452e-b31c-c5b37c6ad40f", + "modelCustomizationName": "Greatdefect..module_1_ixla..module-2", + "name": "Greatdefect..module_1_ixla..module-2", + "uuid": "6f09e053-56a6-4fbb-8299-e1de616825cc", + "version": "3", + "volumeGroupAllowed": false + }, + "greatdefect0..Greatdefect..module_2_ixla..module-1": { + "commands": { + }, + "customizationUuid": "b52c1fda-fbbf-4de3-ad9b-190d4a14990c", + "description": null, + "invariantUuid": "23befc6e-aa97-4004-b215-4979c3f84913", + "modelCustomizationName": "Greatdefect..module_2_ixla..module-1", + "name": "Greatdefect..module_2_ixla..module-1", + "uuid": "dea8e41f-c996-4557-b521-263210d96baa", + "version": "3", + "volumeGroupAllowed": false + } + }, + "vnfs": { + "greatdefect 0": { + "commands": { + "availability_zone_max_count": { + "command": "get_input", + "displayName": "availability_zone_max_count", + "inputName": "greatdefect0_availability_zone_max_count" + }, + "itc_name_0": { + "command": "get_input", + "displayName": "itc_name_0", + "inputName": "greatdefect0_itc_name_0" + }, + "vf_module_id": { + "command": "get_input", + "displayName": "vf_module_id", + "inputName": "greatdefect0_vf_module_id" + } + }, + "customizationUuid": "9123ced3-fbcd-42f7-b103-5965c54bbd66", + "description": "checl-IdanWithSecondFix", + "inputs": { + "availability_zone_max_count": { + "constraints": [ + ], + "default": 1, + "description": "", + "entry_schema": null, + "required": true, + "type": "integer" + }, + "itc_name_0": { + "constraints": [ + ], + "default": "ab", + "description": "ixla itc instance name", + "entry_schema": null, + "required": true, + "type": "string" + }, + "vf_module_id": { + "constraints": [ + ], + "default": "abc", + "description": "Unique ID for this VF Module instance", + "entry_schema": null, + "required": true, + "type": "string" + } + }, + "invariantUuid": "d149c45a-b42f-419a-9fac-f9c359fc2034", + "modelCustomizationName": "greatdefect 0", + "name": "greatdefect", + "properties": { + "availability_zone_max_count": "get_input:greatdefect0_availability_zone_max_count", + "itc_flavor_name": "nv.c8r24d160", + "itc_image_name": "NIMBUS_IXLA-ITC_8.20_EA_KVM_210117.qcow2", + "itc_name_0": "get_input:greatdefect0_itc_name_0", + "itm_flavor_name": "nv.c2r4d50", + "itm_image_name": "NIMBUS_IXLA-ITM_8.20.EA_KVM.qcow2", + "vf_module_id": "get_input:greatdefect0_vf_module_id" + }, + "uuid": "3b25707a-d345-4a80-8744-73adf8f2e67b", + "version": "3.0", + "vfModules": { + }, + "volumeGroups": { + } + } + }, + "volumeGroups": { + } +} diff --git a/vid-app-common/src/test/resources/vl-csar.JSON b/vid-app-common/src/test/resources/vl-csar.JSON new file mode 100644 index 000000000..ce1f1b79f --- /dev/null +++ b/vid-app-common/src/test/resources/vl-csar.JSON @@ -0,0 +1,109 @@ +{ + "networks": { + "ExtVL 0": { + "commands": { + "exVL_naming#naming_policy": { + "command": "get_input", + "displayName": "exVL_naming#naming_policy", + "inputName": "extvl0_exVL_naming_naming_policy" + }, + "network_role": { + "command": "get_input", + "displayName": "network_role", + "inputName": "extvl0_network_role" + }, + "network_scope": { + "command": "get_input", + "displayName": "network_scope", + "inputName": "extvl0_network_scope" + } + }, + "customizationUuid": "664f8aa7-3989-46ac-81c0-dd72a8a63f26", + "description": "ECOMP generic virtual link (network) base type for all other service-level and global networks", + "inputs": { + "exVL_naming#naming_policy": { + "constraints": [ + ], + "default": null, + "description": "Reference to naming policy that ECOMP will use when the name is auto-generated", + "entry_schema": null, + "required": true, + "type": "string" + }, + "network_role": { + "constraints": [ + ], + "default": null, + "description": "Reference to naming policy that ECOMP will use when the name is auto-generated", + "entry_schema": null, + "required": true, + "type": "string" + }, + "network_scope": { + "constraints": [ + ], + "default": null, + "description": "Reference to naming policy that ECOMP will use when the name is auto-generated", + "entry_schema": null, + "required": true, + "type": "string" + } + }, + "invariantUuid": "379f816b-a7aa-422f-be30-17114ff50b7c", + "modelCustomizationName": "ExtVL 0", + "name": "ExtVL", + "properties": { + "exVL_naming": "{naming_policy={get_input=extvl0_exVL_naming_naming_policy}}", + "network_role": "get_input:extvl0_network_role", + "network_scope": "get_input:extvl0_network_scope" + }, + "uuid": "af584529-d7f0-420e-a6f3-c38b689c030f", + "version": "4.0" + } + }, + "service": { + "category": "Network L1-3", + "description": "dsfg", + "inputs": { + "extvl0_exVL_naming_naming_policy": { + "constraints": [ + ], + "default": null, + "description": "Reference to naming policy that ECOMP will use when the name is auto-generated", + "entry_schema": null, + "required": true, + "type": "string" + }, + "extvl0_network_role": { + "constraints": [ + ], + "default": null, + "description": "Unique label that defines the role that this network performs. example: vce oam network, vnat sr-iov1 network\n", + "entry_schema": null, + "required": true, + "type": "string" + }, + "extvl0_network_scope": { + "constraints": [ + ], + "default": null, + "description": "Uniquely identifies the network scope. Valid values for the network scope includes: VF - VF-level network. Intra-VF network which connects the VFCs (VMs) inside the VF. SERVICE - Service-level network. Intra-Service network which connects the VFs within the service GLOBAL - Global network which can be shared by multiple services\n", + "entry_schema": null, + "required": true, + "type": "string" + } + }, + "invariantUuid": "d752a44c-ac7b-4bda-8111-fb52312d101e", + "name": "Macro_flow_test", + "serviceEcompNaming": "true", + "toscaModelURL": null, + "uuid": "68101369-6f08-4e99-9a28-fa6327d344f3", + "version": "1.0" + }, + "vfModules": { + }, + "vnfs": { + }, + "volumeGroups": { + } +} |