Remove ECOMP in headers
[clamp.git] / src / test / java / org / onap / clamp / clds / it / SdcReqItCase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * 
22  */
23
24 package org.onap.clamp.clds.it;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import java.io.IOException;
31 import java.security.GeneralSecurityException;
32 import java.util.List;
33
34 import org.apache.commons.codec.DecoderException;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.onap.clamp.clds.client.req.sdc.SdcRequests;
39 import org.onap.clamp.clds.model.CldsEvent;
40 import org.onap.clamp.clds.model.properties.ModelProperties;
41 import org.onap.clamp.clds.util.ResourceFileUtil;
42 import org.skyscreamer.jsonassert.JSONAssert;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.boot.test.context.SpringBootTest;
45 import org.springframework.test.context.junit4.SpringRunner;
46
47 @RunWith(SpringRunner.class)
48 @SpringBootTest
49 public class SdcReqItCase {
50
51     @Autowired
52     private SdcRequests sdcReq;
53     private String modelBpmnProp;
54     private String modelBpmn;
55     private String modelName;
56     private String controlName;
57     private ModelProperties modelProperties;
58     private String jsonWithYamlInside;
59
60     /**
61      * Initialize Test.
62      */
63     @Before
64     public void setUp() throws IOException {
65         modelBpmnProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json");
66         modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json");
67         modelName = "example-model01";
68         controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf";
69         modelProperties = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmn,
70                 modelBpmnProp);
71         jsonWithYamlInside = ResourceFileUtil.getResourceAsString("example/tca-policy-req/prop-text.json");
72     }
73
74     @Test
75     public void formatBlueprintTest() throws IOException {
76         String blueprintFormatted = sdcReq.formatBlueprint(modelProperties, jsonWithYamlInside);
77         assertEquals(ResourceFileUtil.getResourceAsString("example/tca-policy-req/blueprint-expected.yaml"),
78                 blueprintFormatted);
79     }
80
81     @Test
82     public void formatSdcLocationsReqTest() {
83         String blueprintFormatted = sdcReq.formatSdcLocationsReq(modelProperties, "testos");
84         assertEquals(
85                 "{\"artifactName\":\"testos\",\"locations\":[\"SNDGCA64\",\"ALPRGAED\",\"LSLEILAA\",\"MDTWNJC1\"]}",
86                 blueprintFormatted);
87     }
88
89     @Test
90     public void formatSdcReqTest() {
91         String jsonResult = sdcReq.formatSdcReq("payload", "artifactName", "artifactLabel", "artifactType");
92         JSONAssert.assertEquals(
93                 "{\"payloadData\" : \"cGF5bG9hZA==\",\"artifactLabel\" : \"artifactLabel\",\"artifactName\" :\"artifactName\",\"artifactType\" : \"artifactType\","
94                         + "\"artifactGroupType\" : \"DEPLOYMENT\",\"description\" : \"from CLAMP Cockpit\"}",
95                 jsonResult, true);
96     }
97
98     @Test
99     public void getSdcReqUrlsListTest() throws GeneralSecurityException, DecoderException {
100         List<String> listUrls = sdcReq.getSdcReqUrlsList(modelProperties);
101         assertNotNull(listUrls);
102         assertTrue(listUrls.size() == 1);
103         assertTrue(listUrls.get(0).contains(
104                 "/sdc/v1/catalog/services/56441b4b-0467-41dc-9a0e-e68613838219/resourceInstances/vpacketgen0/artifacts"));
105     }
106 }