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