blob: 4b02752a1a6236d92c0d2a98a15cf7da0a4301bd [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21
22
23package org.onap.osam.controllers;
24
25//import com.fasterxml.jackson.databind.ObjectMapper;
26//import net.javacrumbs.jsonunit.JsonAssert;
27//import org.apache.commons.io.IOUtils;
28//import org.onap.vid.asdc.AsdcCatalogException;
29//import org.onap.vid.asdc.AsdcClient;
30//import org.onap.vid.asdc.parser.ToscaParserImpl2;
31//import org.onap.vid.model.*;
32//import org.onap.portalsdk.core.util.SystemProperties;
33//import org.springframework.beans.factory.annotation.Autowired;
34//import org.springframework.mock.web.MockServletContext;
35//import org.springframework.test.context.ContextConfiguration;
36//import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
37//import org.springframework.test.context.web.WebAppConfiguration;
38//import org.testng.Assert;
39//import org.testng.annotations.Test;
40//
41//import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls;
42//
43//import java.io.IOException;
44//import java.io.InputStream;
45//import java.nio.file.Path;
46//import java.util.Map;
47//import java.util.UUID;
48//
49////import org.junit.Assert;
50////import org.junit.Ignore;
51////import org.junit.Test;
52////import org.junit.runner.RunWith;
53////import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
54//
55//@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
56////@RunWith(SpringJUnit4ClassRunner.class)
57//@WebAppConfiguration
58//
59//public class VidControllerTest extends AbstractTestNGSpringContextTests {
60//
61// @Autowired
62// MockServletContext context;
63// @Autowired
64// private AsdcClient asdcClient;
65// private ToscaParserImpl2 p2 = new ToscaParserImpl2();
66// private ObjectMapper om = new ObjectMapper();
67//
68//
69// @Test
70// public void assertEqualsBetweenServices() throws Exception {
71// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
72// Service expectedService = mockHelper.getNewServiceModel().getService();
73// Service actualService = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getService();
74// assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedService), om.writeValueAsString(actualService));
75// }
76// }
77//
78//// @Test
79//// public void assertEqualBetweenObjects() throws Exception {
80//// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
81//// final Path csarPath = getCsarPath(mockHelper.getUuid());
82//// System.out.println("Comparing for csar " + csarPath);
83//// ServiceModel actualServiceModel = p2.makeServiceModel(csarPath, getServiceByUuid(mockHelper.getUuid()));
84//// assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(mockHelper.getNewServiceModel()), om.writeValueAsString(actualServiceModel));
85//// }
86//// }
87//
88//// @Test
89//// public void assertEqualsBetweenNetworkNodes() throws Exception {
90//// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
91//// Map<String, Network> expectedNetworksMap = mockHelper.getNewServiceModel().getNetworks();
92//// Map<String, Network> actualNetworksMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getNetworks();
93//// for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) {
94//// Network expectedNetwork = entry.getValue();
95//// Network actualNetwork = actualNetworksMap.get(entry.getKey());
96//// Assert.assertEquals(expectedNetwork.getModelCustomizationName(), actualNetwork.getModelCustomizationName());
97//// verifyBaseNodeProperties(expectedNetwork, actualNetwork);
98//// compareProperties(expectedNetwork.getProperties(), actualNetwork.getProperties());
99//// }
100//// }
101//// }
102//
103// //Because we are not supporting the old flow, the JSON are different by definition.
104// @Test
105// public void assertEqualsBetweenVnfsOfTosca() throws Exception {
106// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
107// Map<String, VNF> expectedVnfsMap = mockHelper.getNewServiceModel().getVnfs();
108// Map<String, VNF> actualVnfsMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfs();
109// for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) {
110// VNF expectedVnf = entry.getValue();
111// VNF actualVnf = actualVnfsMap.get(entry.getKey());
112// //need to uncomment these after 1806 merge
113// //verifyBaseNodeProperties(expectedVnf, actualVnf);
114// Assert.assertEquals(expectedVnf.getModelCustomizationName(), actualVnf.getModelCustomizationName());
115// //compareProperties(expectedVnf.getProperties(), actualVnf.getProperties());
116// //assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVnf), om.writeValueAsString(actualVnf));
117// }
118// }
119// }
120//
121// @Test
122// public void assertEqualsBetweenVolumeGroups() throws Exception {
123// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
124// Map<String, VolumeGroup> actualVolumeGroups = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVolumeGroups();
125// Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getNewServiceModel().getVolumeGroups();
126// JsonAssert.assertJsonEquals(actualVolumeGroups, expectedVolumeGroups);
127// }
128// }
129//
130// @Test
131// public void assertEqualsBetweenVfModules() throws Exception {
132// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
133// Map<String, VfModule> actualVfModules = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVfModules();
134// Map<String, VfModule> expectedVfModules = mockHelper.getNewServiceModel().getVfModules();
135// //need to uncomment after 1906 merge
136// //JsonAssert.assertJsonEquals(actualVfModules, expectedVfModules);
137// }
138// }
139//
140// /*@Test
141// public void assertEqualsBetweenPolicyConfigurationNodes() throws Exception {
142// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
143// Map<String, PortMirroringConfig> actualConfigurations = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations();
144// Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations();
145// JsonAssert.assertJsonEquals(actualConfigurations, expectedConfigurations);
146// }
147// }*/
148//
149// @Test
150// public void assertEqualsBetweenServiceProxyNodes() throws Exception {
151// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
152// Map<String, ServiceProxy> actualServiceProxies = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getServiceProxies();
153// Map<String, ServiceProxy> expectedServiceProxies = mockHelper.getNewServiceModel().getServiceProxies();
154// JsonAssert.assertJsonEquals(actualServiceProxies, expectedServiceProxies);
155// }
156// }
157//
158// private void verifyBaseNodeProperties(Node expectedNode, Node actualNode) {
159// Assert.assertEquals(expectedNode.getName(), actualNode.getName());
160// Assert.assertEquals(expectedNode.getCustomizationUuid(), actualNode.getCustomizationUuid());
161// Assert.assertEquals(expectedNode.getDescription(), actualNode.getDescription());
162// Assert.assertEquals(expectedNode.getInvariantUuid(), actualNode.getInvariantUuid());
163// Assert.assertEquals(expectedNode.getUuid(), actualNode.getUuid());
164// Assert.assertEquals(expectedNode.getVersion(), actualNode.getVersion());
165// }
166//
167// private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) {
168// for (Map.Entry<String, String> property : expectedProperties.entrySet()) {
169// String expectedValue = property.getValue();
170// String key = property.getKey();
171// String actualValue = actualProperties.get(key);
172// Assert.assertEquals(expectedValue, actualValue);
173// }
174// }
175//
176// private ToscaParserMockHelper[] getExpectedServiceModel() throws IOException {
177// ToscaParserMockHelper[] mockHelpers = {
178// new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath),
179// new ToscaParserMockHelper(Constants.vfUuid, Constants.vfFilePath),
180// new ToscaParserMockHelper(Constants.configurationUuid, Constants.configurationFilePath),
181// };
182// for (ToscaParserMockHelper mockHelper : mockHelpers) {
183// InputStream jsonFile = VidControllerTest.class.getClassLoader().getResourceAsStream(mockHelper.getFilePath());
184// String expectedJsonAsString = IOUtils.toString(jsonFile);
185// NewServiceModel newServiceModel1 = om.readValue(expectedJsonAsString, NewServiceModel.class);
186// mockHelper.setNewServiceModel(newServiceModel1);
187// }
188// return mockHelpers;
189// }
190//
191// private Path getCsarPath(String uuid) throws AsdcCatalogException {
192// return asdcClient.getServiceToscaModel(UUID.fromString(uuid));
193// }
194//
195// private org.onap.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException {
196// return asdcClient.getService(UUID.fromString(uuid));
197// }
198//
199// public class Constants {
200// public static final String configurationUuid = "ee6d61be-4841-4f98-8f23-5de9da846ca7";
201// public static final String configurationFilePath = "policy-configuration-csar.JSON";
202// static final String vfUuid = "48a52540-8772-4368-9cdb-1f124ea5c931";
203// static final String vlUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
204// // public static final String PNFUuid = "68101369-6f08-4e99-9a28-fa6327d344f3";
205// static final String vfFilePath = "vf-csar.JSON";
206// static final String vlFilePath = "vl-csar.JSON";
207//// public static final String PNFFilePath = "/Users/Oren/Git/Att/vid_internal/vid-app-common/src/main/resources/pnf.csar";
208//
209// }
210//
211//}