Merge 1806 code of vid-common
[vid.git] / vid-app-common / src / test / java / org / onap / vid / controllers / VidControllerTest.java
1 package org.onap.vid.controllers;
2
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;
18 //
19 //import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls;
20 //
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;
26 //
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;
32 //
33 //@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
34 ////@RunWith(SpringJUnit4ClassRunner.class)
35 //@WebAppConfiguration
36 //
37 //public class VidControllerTest extends AbstractTestNGSpringContextTests {
38 //
39 //    @Autowired
40 //    MockServletContext context;
41 //    @Autowired
42 //    private AsdcClient asdcClient;
43 //    private ToscaParserImpl2 p2 = new ToscaParserImpl2();
44 //    private ObjectMapper om = new ObjectMapper();
45 //
46 //
47 //    @Test
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));
53 //        }
54 //    }
55 //
56 ////    @Test
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));
63 ////        }
64 ////    }
65 //
66 ////    @Test
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());
77 ////            }
78 ////        }
79 ////    }
80 //
81 //    //Because we are not supporting the old flow, the JSON are different by definition.
82 //    @Test
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));
95 //            }
96 //        }
97 //    }
98 //
99 //    @Test
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);
105 //        }
106 //    }
107 //
108 //    @Test
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);
115 //        }
116 //    }
117 //
118 //    /*@Test
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);
124 //        }
125 //    }*/
126 //
127 //    @Test
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);
133 //        }
134 //    }
135 //
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());
143 //    }
144 //
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);
151 //        }
152 //    }
153 //
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),
159 //        };
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);
165 //        }
166 //        return mockHelpers;
167 //    }
168 //
169 //    private Path getCsarPath(String uuid) throws AsdcCatalogException {
170 //        return asdcClient.getServiceToscaModel(UUID.fromString(uuid));
171 //    }
172 //
173 //    private org.onap.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException {
174 //        return asdcClient.getService(UUID.fromString(uuid));
175 //    }
176 //
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";
186 //
187 //    }
188 //
189 //}