1 package org.onap.vid.controllers;
3 //import com.fasterxml.jackson.databind.ObjectMapper;
4 //import net.javacrumbs.jsonunit.JsonAssert;
5 //import org.apache.commons.io.IOUtils;
6 //import org.onap.vid.asdc.AsdcCatalogException;
7 //import org.onap.vid.asdc.AsdcClient;
8 //import org.onap.vid.asdc.parser.ToscaParserImpl2;
9 //import org.onap.vid.model.*;
10 //import org.onap.portalsdk.core.util.SystemProperties;
11 //import org.springframework.beans.factory.annotation.Autowired;
12 //import org.springframework.mock.web.MockServletContext;
13 //import org.springframework.test.context.ContextConfiguration;
14 //import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
15 //import org.springframework.test.context.web.WebAppConfiguration;
16 //import org.testng.Assert;
17 //import org.testng.annotations.Test;
19 //import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls;
21 //import java.io.IOException;
22 //import java.io.InputStream;
23 //import java.nio.file.Path;
24 //import java.util.Map;
25 //import java.util.UUID;
27 ////import org.junit.Assert;
28 ////import org.junit.Ignore;
29 ////import org.junit.Test;
30 ////import org.junit.runner.RunWith;
31 ////import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33 //@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
34 ////@RunWith(SpringJUnit4ClassRunner.class)
35 //@WebAppConfiguration
37 //public class VidControllerTest extends AbstractTestNGSpringContextTests {
40 // MockServletContext context;
42 // private AsdcClient asdcClient;
43 // private ToscaParserImpl2 p2 = new ToscaParserImpl2();
44 // private ObjectMapper om = new ObjectMapper();
48 // public void assertEqualsBetweenServices() throws Exception {
49 // for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
50 // Service expectedService = mockHelper.getNewServiceModel().getService();
51 // Service actualService = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getService();
52 // assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedService), om.writeValueAsString(actualService));
57 //// public void assertEqualBetweenObjects() throws Exception {
58 //// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
59 //// final Path csarPath = getCsarPath(mockHelper.getUuid());
60 //// System.out.println("Comparing for csar " + csarPath);
61 //// ServiceModel actualServiceModel = p2.makeServiceModel(csarPath, getServiceByUuid(mockHelper.getUuid()));
62 //// assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(mockHelper.getNewServiceModel()), om.writeValueAsString(actualServiceModel));
67 //// public void assertEqualsBetweenNetworkNodes() throws Exception {
68 //// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
69 //// Map<String, Network> expectedNetworksMap = mockHelper.getNewServiceModel().getNetworks();
70 //// Map<String, Network> actualNetworksMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getNetworks();
71 //// for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) {
72 //// Network expectedNetwork = entry.getValue();
73 //// Network actualNetwork = actualNetworksMap.get(entry.getKey());
74 //// Assert.assertEquals(expectedNetwork.getModelCustomizationName(), actualNetwork.getModelCustomizationName());
75 //// verifyBaseNodeProperties(expectedNetwork, actualNetwork);
76 //// compareProperties(expectedNetwork.getProperties(), actualNetwork.getProperties());
81 // //Because we are not supporting the old flow, the JSON are different by definition.
83 // public void assertEqualsBetweenVnfsOfTosca() throws Exception {
84 // for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
85 // Map<String, VNF> expectedVnfsMap = mockHelper.getNewServiceModel().getVnfs();
86 // Map<String, VNF> actualVnfsMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfs();
87 // for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) {
88 // VNF expectedVnf = entry.getValue();
89 // VNF actualVnf = actualVnfsMap.get(entry.getKey());
90 // //need to uncomment these after 1806 merge
91 // //verifyBaseNodeProperties(expectedVnf, actualVnf);
92 // Assert.assertEquals(expectedVnf.getModelCustomizationName(), actualVnf.getModelCustomizationName());
93 // //compareProperties(expectedVnf.getProperties(), actualVnf.getProperties());
94 // //assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVnf), om.writeValueAsString(actualVnf));
100 // public void assertEqualsBetweenVolumeGroups() throws Exception {
101 // for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
102 // Map<String, VolumeGroup> actualVolumeGroups = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVolumeGroups();
103 // Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getNewServiceModel().getVolumeGroups();
104 // JsonAssert.assertJsonEquals(actualVolumeGroups, expectedVolumeGroups);
109 // public void assertEqualsBetweenVfModules() throws Exception {
110 // for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
111 // Map<String, VfModule> actualVfModules = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVfModules();
112 // Map<String, VfModule> expectedVfModules = mockHelper.getNewServiceModel().getVfModules();
113 // //need to uncomment after 1906 merge
114 // //JsonAssert.assertJsonEquals(actualVfModules, expectedVfModules);
119 // public void assertEqualsBetweenPolicyConfigurationNodes() throws Exception {
120 // for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
121 // Map<String, PortMirroringConfig> actualConfigurations = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations();
122 // Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations();
123 // JsonAssert.assertJsonEquals(actualConfigurations, expectedConfigurations);
128 // public void assertEqualsBetweenServiceProxyNodes() throws Exception {
129 // for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
130 // Map<String, ServiceProxy> actualServiceProxies = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getServiceProxies();
131 // Map<String, ServiceProxy> expectedServiceProxies = mockHelper.getNewServiceModel().getServiceProxies();
132 // JsonAssert.assertJsonEquals(actualServiceProxies, expectedServiceProxies);
136 // private void verifyBaseNodeProperties(Node expectedNode, Node actualNode) {
137 // Assert.assertEquals(expectedNode.getName(), actualNode.getName());
138 // Assert.assertEquals(expectedNode.getCustomizationUuid(), actualNode.getCustomizationUuid());
139 // Assert.assertEquals(expectedNode.getDescription(), actualNode.getDescription());
140 // Assert.assertEquals(expectedNode.getInvariantUuid(), actualNode.getInvariantUuid());
141 // Assert.assertEquals(expectedNode.getUuid(), actualNode.getUuid());
142 // Assert.assertEquals(expectedNode.getVersion(), actualNode.getVersion());
145 // private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) {
146 // for (Map.Entry<String, String> property : expectedProperties.entrySet()) {
147 // String expectedValue = property.getValue();
148 // String key = property.getKey();
149 // String actualValue = actualProperties.get(key);
150 // Assert.assertEquals(expectedValue, actualValue);
154 // private ToscaParserMockHelper[] getExpectedServiceModel() throws IOException {
155 // ToscaParserMockHelper[] mockHelpers = {
156 // new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath),
157 // new ToscaParserMockHelper(Constants.vfUuid, Constants.vfFilePath),
158 // new ToscaParserMockHelper(Constants.configurationUuid, Constants.configurationFilePath),
160 // for (ToscaParserMockHelper mockHelper : mockHelpers) {
161 // InputStream jsonFile = VidControllerTest.class.getClassLoader().getResourceAsStream(mockHelper.getFilePath());
162 // String expectedJsonAsString = IOUtils.toString(jsonFile);
163 // NewServiceModel newServiceModel1 = om.readValue(expectedJsonAsString, NewServiceModel.class);
164 // mockHelper.setNewServiceModel(newServiceModel1);
166 // return mockHelpers;
169 // private Path getCsarPath(String uuid) throws AsdcCatalogException {
170 // return asdcClient.getServiceToscaModel(UUID.fromString(uuid));
173 // private org.onap.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException {
174 // return asdcClient.getService(UUID.fromString(uuid));
177 // public class Constants {
178 // public static final String configurationUuid = "ee6d61be-4841-4f98-8f23-5de9da846ca7";
179 // public static final String configurationFilePath = "policy-configuration-csar.JSON";
180 // static final String vfUuid = "48a52540-8772-4368-9cdb-1f124ea5c931";
181 // static final String vlUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
182 // // public static final String PNFUuid = "68101369-6f08-4e99-9a28-fa6327d344f3";
183 // static final String vfFilePath = "vf-csar.JSON";
184 // static final String vlFilePath = "vl-csar.JSON";
185 //// public static final String PNFFilePath = "/Users/Oren/Git/Att/vid_internal/vid-app-common/src/main/resources/pnf.csar";