1 package org.onap.vid.asdc.parser;
3 import com.fasterxml.jackson.core.JsonProcessingException;
4 import com.fasterxml.jackson.databind.SerializationFeature;
5 import com.google.common.collect.ImmutableList;
6 import org.apache.log4j.Logger;
7 import org.junit.Assert;
8 import org.onap.vid.controller.WebConfig;
9 import org.onap.vid.model.VfModule;
10 import org.onap.vid.model.VolumeGroup;
11 import org.onap.vid.properties.AsdcClientConfiguration;
12 import org.openecomp.portalsdk.core.util.SystemProperties;
13 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
14 import org.openecomp.sdc.toscaparser.api.Group;
15 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
16 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.test.context.ContextConfiguration;
18 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
19 import org.springframework.test.context.web.WebAppConfiguration;
20 import org.springframework.web.context.WebApplicationContext;
21 import org.testng.annotations.BeforeMethod;
22 import org.testng.annotations.Test;
24 import java.util.ArrayList;
25 import java.util.LinkedHashMap;
28 import static org.hamcrest.Matchers.*;
29 import static org.junit.Assert.assertThat;
30 import static org.mockito.Mockito.*;
33 @ContextConfiguration(classes = { WebConfig.class, AsdcClientConfiguration.class, SystemProperties.class })
35 public class ToscaParserImpl2Test extends AbstractTestNGSpringContextTests {
37 private final String myUUID = "myUUID";
38 private static final Logger log = Logger.getLogger(ToscaParserImpl2Test.class);
41 private ToscaParserImpl2 toscaParserImpl2;
44 private WebApplicationContext wac;
47 private void verifyWiring() {
48 Assert.assertNotNull(wac);
49 Assert.assertNotNull(toscaParserImpl2);
53 public void testGetNFModuleFromVf() throws Exception {
54 ISdcCsarHelper csarHelper = getMockedSdcCsarHelper();
56 Map<String, VfModule> vfModulesFromVF = toscaParserImpl2.getVfModulesFromVF(csarHelper, myUUID);
58 assertThat(vfModulesFromVF, allOf(
64 verify(csarHelper, only()).getVfModulesByVf(anyString());
68 public void testGetVolumeGroupsFromVF() throws Exception {
69 ISdcCsarHelper csarHelper = getMockedSdcCsarHelper();
71 Map<String, VolumeGroup> volumeGroupsFromVF = toscaParserImpl2.getVolumeGroupsFromVF(csarHelper, myUUID);
73 assertThat(volumeGroupsFromVF, allOf(
78 verify(csarHelper, only()).getVfModulesByVf(anyString());
81 private ISdcCsarHelper getMockedSdcCsarHelper() {
82 ISdcCsarHelper csarHelper = mock(ISdcCsarHelper.class);
84 // ThreadLocalsHolder.setCollector(new ExceptionCollector("c:\\temp\\foo"));
86 Group withVol = createMinimalGroup("withVol", true);
87 Group withoutVol = createMinimalGroup("withoutVol", false);
89 when(csarHelper.getVfModulesByVf(myUUID))
90 .thenReturn(ImmutableList.of(withVol, withoutVol));
95 private static Group createMinimalGroup(String name, boolean isVolumeGroup) {
96 LinkedHashMap<String, Object>
105 templates = new LinkedHashMap<>();
106 templates.put("type", "org.onap.groups.VfModule");
108 properties = addNewNamedMap(templates, "properties");
109 properties.put("volume_group", isVolumeGroup);
111 metadata = addNewNamedMap(templates, "metadata");
113 ArrayList<NodeTemplate> memberNodes = new ArrayList<>();
115 customDef = new LinkedHashMap<>();
116 vfModule = addNewNamedMap(customDef, "org.onap.groups.VfModule");
117 vfModuleProperties = addNewNamedMap(vfModule, "properties");
118 // vfModule.put("derived_from", "tosca.groups.Root");
119 // vfModule.put("description", "Grouped all heat resources which are in the same VF Module");
121 volumeGroup = addNewNamedMap(vfModuleProperties, "volume_group");
122 // volumeGroup.put("description", "volume_group");
123 volumeGroup.put("type", "boolean");
124 volumeGroup.put("default", false);
125 volumeGroup.put("required", true);
128 Group group = new Group(
136 log.info(String.format("Built a group: %s",
137 (new com.fasterxml.jackson.databind.ObjectMapper())
138 .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
139 .writeValueAsString(group)
141 } catch (JsonProcessingException e) {
142 throw new RuntimeException(e);
148 private static LinkedHashMap<String, Object> addNewNamedMap(LinkedHashMap<String, Object> root, String key) {
149 LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
150 root.put(key, properties);