2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.execute.imports;
23 import static org.testng.AssertJUnit.assertEquals;
25 import java.util.ArrayList;
26 import java.util.List;
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;
44 public class FilteredDataByParamsComponentServletTest extends ComponentBaseTest{
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();
56 protected User designerDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
58 public FilteredDataByParamsComponentServletTest() {
59 super(name, ImportCsarResourceTest.class.getName());
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);
73 uiComponentWithComponentInstancesAndRelations.getComponentInstances().stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
74 resource.getComponentInstances().stream().sorted((object1, object2) -> object1.getUniqueId().compareTo(object2.getUniqueId()));
76 for (int i = 0 ; i < resource.getComponentInstances().size() ; i++){
77 assertEquals(uiComponentWithComponentInstancesAndRelations.getComponentInstances().get(i).getUniqueId() ,resource.getComponentInstances().get(i).getUniqueId());
79 assertEquals(uiComponentWithComponentInstancesAndRelations.getComponentInstancesRelations().size() , resource.getComponentInstancesRelations().size());
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);
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);
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());
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()));
104 for (int i = 0 ; i < deploymentArtifactsFromResource.size() ; i++){
105 assertEquals(deploymentArtifactsFromResource.get(i).getUniqueId() , deploymentArtifactsFromUiComponent.get(i).getUniqueId());
108 for (int i = 0 ; i < informationalArtifactsFromResource.size() ; i++){
109 assertEquals(informationalArtifactsFromResource.get(i).getUniqueId() , informationalArtifactsFromUiComponent.get(i).getUniqueId());
115 public void getComponentMetadataTest() throws Exception {
117 Resource resource = ResourceRestUtils.importResourceFromCsar(CSAR_NAME);
118 List<String> parameters = new ArrayList<>();
119 parameters.add(METADATA);
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);
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());