aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java
diff options
context:
space:
mode:
authorOfir Sonsino <os0695@att.com>2017-09-04 14:52:07 +0300
committerOfir Sonsino <os0695@att.com>2017-09-04 14:52:07 +0300
commitb35670742c728d7d85da2f9c856c51a5889449d6 (patch)
tree92e544b121b8a47230667f0e0078c188a47dd8eb /vid-app-common/src/test/java
parent49a483a9b40cb429717ccec69fa99e4908aadbb6 (diff)
[VID-55] Upgrade Tosca Parser (merge)
Change-Id: I5389f1641ef22df3ed569a154b3c367117c04d04 Signed-off-by: Ofir Sonsino <os0695@att.com>
Diffstat (limited to 'vid-app-common/src/test/java')
-rw-r--r--vid-app-common/src/test/java/org/opencomp/vid/controller/VidControllerTest.java128
-rw-r--r--vid-app-common/src/test/java/org/opencomp/vid/testUtils/TestUtils.java65
-rwxr-xr-xvid-app-common/src/test/java/org/openecomp/ecomp/vid/selenium/LogOutLeftPane.java2
-rwxr-xr-xvid-app-common/src/test/java/org/openecomp/fusion/core/MockApplicationContextTestSuite.java3
-rwxr-xr-xvid-app-common/src/test/java/org/openecomp/fusionapp/service/ProfileServiceTest.java16
5 files changed, 204 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);
}
}