Migrate TestNG to Junit5
[sdc/sdc-tosca.git] / sdc-tosca / src / test / java / org / onap / sdc / impl / ToscaParserGroupTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc-tosca
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
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 package org.onap.sdc.impl;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertNotNull;
25 import static org.junit.jupiter.api.Assertions.assertNull;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
31 import org.onap.sdc.toscaparser.api.Group;
32 import org.onap.sdc.toscaparser.api.elements.Metadata;
33
34 import java.util.List;
35
36 @ExtendWith({SdcToscaParserBasicTest.class})
37  class ToscaParserGroupTest extends SdcToscaParserBasicTest{
38
39     //region getVfModulesByVf
40     @Test
41     public void testVfModulesFromVf(){
42         List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
43         assertEquals(2, vfModulesByVf.size());
44         for (Group group : vfModulesByVf){
45             assertTrue(group.getName().startsWith("fdnt1"));
46             assertNotNull(group.getMetadata());
47             assertNotNull(group.getMetadata().getValue("vfModuleModelCustomizationUUID"));
48         }
49     }
50
51     @Test
52     public void testGetGroupMetadata(){
53         List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
54         boolean found = false;
55         for (Group group : vfModulesByVf){
56             if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){
57                 found = true;
58                 Metadata metadata = group.getMetadata();
59                 assertNotNull(metadata);
60                 assertEquals("b458f4ef-ede2-403d-9605-d08c9398b6ee", metadata.getValue("vfModuleModelCustomizationUUID"));
61             }
62         }
63         assertTrue(found);
64     }
65
66     @Test
67     public void testGetGroupEmptyMetadata(){
68         List<Group> vfModulesByVf = rainyCsarHelperMultiVfs.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
69         boolean found = false;
70         for (Group group : vfModulesByVf){
71             if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){
72                 found = true;
73                 Metadata metadata = group.getMetadata();
74                 assertNull(metadata);
75             }
76         }
77         assertTrue(found);
78     }
79
80     @Test
81     public void testGetVfModuleNonExisitingVf() {
82         List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf("dummy");
83         assertNotNull(vfModulesByVf);
84         assertEquals(0, vfModulesByVf.size());
85     }
86
87     @Test
88     public void testGetVfModuleNullVf() {
89         List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf(null);
90         assertNotNull(vfModulesByVf);
91         assertEquals(0, vfModulesByVf.size());
92     }
93     //endregion
94
95     //region getGroupPropertyLeafValue
96     @Test
97     public void testGroupFlatProperty() throws SdcToscaParserException {
98         List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
99         String volumeGroup = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group");
100         assertEquals("false", volumeGroup);
101     }
102
103 //    @Test
104 //    public void testGroupFlatGetInputProperty() throws SdcToscaParserException {
105 //        List<Group> vfModulesByVf = fdntCsarHelperWithInputs.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
106 //        String volumeGroup = fdntCsarHelperWithInputs.getGroupPropertyLeafValue(vfModulesByVf.get(1), "volume_group");
107 //        assertEquals("false", volumeGroup);
108 //    }
109
110     @Test
111     public void testGroupPropertyLeafValueByNullProperty() {
112         List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
113         String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), null);
114         assertNull(groupProperty);
115     }
116
117     @Test
118     public void testGroupPropertyLeafValueByDummyProperty() {
119         List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
120         String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX");
121         assertNull(groupProperty);
122     }
123
124     @Test
125     public void testGroupPropertyLeafValueByNullGroup() {
126         String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(null, "volume_group");
127         assertNull(groupProperty);
128     }
129     //endregion
130
131     //region getGroupPropertyAsObject
132     @Test
133     public void testGetGroupPropertyAsObject() {
134         List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
135         Object volumeGroup = fdntCsarHelper.getGroupPropertyAsObject(vfModulesByVf.get(0), "volume_group");
136         assertEquals(false, volumeGroup);
137     }
138     //getGroupPropertyAsObject
139
140 }