Generate API documents
[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.json.JSONException;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.onap.clamp.clds.client.req.sdc.SdcRequests;
40 import org.onap.clamp.clds.model.CldsEvent;
41 import org.onap.clamp.clds.model.properties.ModelProperties;
42 import org.onap.clamp.clds.util.ResourceFileUtil;
43 import org.skyscreamer.jsonassert.JSONAssert;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.boot.test.context.SpringBootTest;
46 import org.springframework.test.context.junit4.SpringRunner;
47
48 @RunWith(SpringRunner.class)
49 @SpringBootTest
50 public class SdcReqItCase {
51
52     @Autowired
53     private SdcRequests sdcReq;
54     private String modelBpmnProp;
55     private String modelBpmn;
56     private String modelName;
57     private String controlName;
58     private ModelProperties modelProperties;
59     private String jsonWithYamlInside;
60
61     /**
62      * Initialize Test.
63      */
64     @Before
65     public void setUp() throws IOException {
66         modelBpmnProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json");
67         modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json");
68         modelName = "example-model01";
69         controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf";
70         modelProperties = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmn,
71                 modelBpmnProp);
72         jsonWithYamlInside = ResourceFileUtil.getResourceAsString("example/tca-policy-req/prop-text.json");
73     }
74
75     @Test
76     public void formatBlueprintTest() throws IOException {
77         String blueprintFormatted = sdcReq.formatBlueprint(modelProperties, jsonWithYamlInside);
78         assertEquals(ResourceFileUtil.getResourceAsString("example/tca-policy-req/blueprint-expected.yaml"),
79                 blueprintFormatted);
80     }
81
82     @Test
83     public void formatSdcLocationsReqTest() {
84         String blueprintFormatted = sdcReq.formatSdcLocationsReq(modelProperties, "testos");
85         assertEquals(
86                 "{\"artifactName\":\"testos\",\"locations\":[\"SNDGCA64\",\"ALPRGAED\",\"LSLEILAA\",\"MDTWNJC1\"]}",
87                 blueprintFormatted);
88     }
89
90     @Test
91     public void formatSdcReqTest() throws JSONException {
92         String jsonResult = sdcReq.formatSdcReq("payload", "artifactName", "artifactLabel", "artifactType");
93         JSONAssert.assertEquals(
94                 "{\"payloadData\" : \"cGF5bG9hZA==\",\"artifactLabel\" : \"artifactLabel\",\"artifactName\" :\"artifactName\",\"artifactType\" : \"artifactType\","
95                         + "\"artifactGroupType\" : \"DEPLOYMENT\",\"description\" : \"from CLAMP Cockpit\"}",
96                 jsonResult, true);
97     }
98
99     @Test
100     public void getSdcReqUrlsListTest() throws GeneralSecurityException, DecoderException {
101         List<String> listUrls = sdcReq.getSdcReqUrlsList(modelProperties);
102         assertNotNull(listUrls);
103         assertTrue(listUrls.size() == 1);
104         assertTrue(listUrls.get(0).contains(
105                 "/sdc/v1/catalog/services/56441b4b-0467-41dc-9a0e-e68613838219/resourceInstances/vpacketgen0/artifacts"));
106     }
107 }