Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / execute / imports / FilteredDataByParamsComponentServletTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.sdc.ci.tests.execute.imports;
22
23 import static org.testng.AssertJUnit.assertEquals;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.junit.rules.TestName;
29 import org.openecomp.sdc.be.model.ArtifactDefinition;
30 import org.openecomp.sdc.be.model.Resource;
31 import org.openecomp.sdc.be.model.User;
32 import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
33 import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer;
34 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
35 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
37 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
38 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
39 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
40 import org.testng.annotations.Test;
41
42
43
44 public class FilteredDataByParamsComponentServletTest extends ComponentBaseTest{
45
46         private static final String CSAR_NAME = "LDSA1_with_inputs.csar";
47         private static final String COMPONENT_INSTANCES = "include=componentInstances";
48         private static final String COMPONENT_INSTANCES_RELATIONS = "include=componentInstancesRelations";
49         private static final String DEPLOYMENT_ARTIFACTS = "include=deploymentArtifacts";
50         private static final String INFORMATIONAL_ARTIFACTS = "include=artifacts";
51         private static final String METADATA = "include=metadata";
52         public static TestName name = new TestName();
53
54
55         
56         protected User designerDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
57         
58         public FilteredDataByParamsComponentServletTest() {
59                 super(name, ImportCsarResourceTest.class.getName());
60         }
61
62         
63         @Test
64         public void getComponentInstancesAndComponentInstancesRelationsTest() throws Exception {
65                 Resource resource = ResourceRestUtils.importResourceFromCsar(CSAR_NAME);
66                 List<String> parameters = new ArrayList<>();
67                 parameters.add(COMPONENT_INSTANCES);
68                 parameters.add(COMPONENT_INSTANCES_RELATIONS);
69                 // create UiComponentDataTransfer and parse the ComponentInstancesRelations into it
70                 RestResponse resourceGetResponse = ResourceRestUtils.getResourceFilteredDataByParams(designerDetails, resource.getUniqueId() , parameters);
71                 UiComponentDataTransfer uiComponentWithComponentInstancesAndRelations = ResponseParser.parseToObjectUsingMapper(resourceGetResponse.getResponse() , UiComponentDataTransfer.class);
72                 
73                 uiComponentWithComponentInstancesAndRelations.getComponentInstances().stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
74                 resource.getComponentInstances().stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
75                 
76                 for (int i = 0 ; i <  resource.getComponentInstances().size() ; i++){
77                         assertEquals(uiComponentWithComponentInstancesAndRelations.getComponentInstances().get(i).getUniqueId() ,resource.getComponentInstances().get(i).getUniqueId());
78                 }
79                 assertEquals(uiComponentWithComponentInstancesAndRelations.getComponentInstancesRelations().size() , resource.getComponentInstancesRelations().size());
80         }
81
82         
83         @Test
84         public void getComponentDeploymentAndInformationalArtifacts() throws Exception {
85                 Resource resource = ResourceRestUtils.importResourceFromCsar(CSAR_NAME);
86                 List<String> parameters = new ArrayList<>();
87                 parameters.add(DEPLOYMENT_ARTIFACTS);
88                 parameters.add(INFORMATIONAL_ARTIFACTS);
89
90                 // create new UiComponentData transfer and parse the artifacts into it
91                 RestResponse resourceGetResponse = ResourceRestUtils.getResourceFilteredDataByParams(designerDetails, resource.getUniqueId() , parameters);
92                 UiComponentDataTransfer uiComponentWithArtifacts = ResponseParser.parseToObjectUsingMapper(resourceGetResponse.getResponse() , UiComponentDataTransfer.class);
93                 
94                 List<ArtifactDefinition> deploymentArtifactsFromResource = new ArrayList<ArtifactDefinition>(resource.getDeploymentArtifacts().values());
95                 List<ArtifactDefinition> deploymentArtifactsFromUiComponent = new ArrayList<ArtifactDefinition>(uiComponentWithArtifacts.getDeploymentArtifacts().values());
96                 List<ArtifactDefinition> informationalArtifactsFromResource = new ArrayList<ArtifactDefinition>(resource.getArtifacts().values());
97                 List<ArtifactDefinition> informationalArtifactsFromUiComponent = new ArrayList<ArtifactDefinition>(uiComponentWithArtifacts.getArtifacts().values());
98                 
99                 deploymentArtifactsFromResource.stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
100                 deploymentArtifactsFromUiComponent.stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
101                 informationalArtifactsFromResource.stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
102                 informationalArtifactsFromUiComponent.stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
103                 
104                 for (int i = 0 ; i <  deploymentArtifactsFromResource.size() ; i++){
105                         assertEquals(deploymentArtifactsFromResource.get(i).getUniqueId() , deploymentArtifactsFromUiComponent.get(i).getUniqueId());
106                 }
107                 
108                 for (int i = 0 ; i <  informationalArtifactsFromResource.size() ; i++){
109                         assertEquals(informationalArtifactsFromResource.get(i).getUniqueId() , informationalArtifactsFromUiComponent.get(i).getUniqueId());
110                 }
111         }
112         
113         
114         @Test
115         public void getComponentMetadataTest() throws Exception {
116                 
117                 Resource resource = ResourceRestUtils.importResourceFromCsar(CSAR_NAME);
118                 List<String> parameters = new ArrayList<>();
119                 parameters.add(METADATA);
120
121                 // create new UiResourceDataTransfer and parse the metadata into it
122                 RestResponse resourceGetResponse = ResourceRestUtils.getResourceFilteredDataByParams(designerDetails, resource.getUniqueId() , parameters);
123                 UiResourceDataTransfer uiResourceWithMetadata = ResponseParser.parseToObjectUsingMapper(resourceGetResponse.getResponse(), UiResourceDataTransfer.class);
124                 
125                 // assert that the metadata is equal
126                 assertEquals(uiResourceWithMetadata.getMetadata().getName(), resource.getName());
127                 assertEquals(uiResourceWithMetadata.getMetadata().getVersion() , resource.getVersion());
128                 assertEquals(uiResourceWithMetadata.getMetadata().getUniqueId() , resource.getUniqueId());
129                 assertEquals(uiResourceWithMetadata.getMetadata().getUUID(), resource.getUUID());
130         }
131         
132
133
134
135 }