75ca25cff8c666fa48f9fe11fd3ce8a754c6212b
[clamp.git] / src / test / java / org / onap / clamp / loop / deploy / BlueprintInputParametersTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Modifications copyright (c) 2019 Nokia
9  * Modifications Copyright (c) 2019 Samsung
10  * ================================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * ============LICENSE_END============================================
23  * ===================================================================
24  *
25  */
26
27 package org.onap.clamp.loop.deploy;
28
29 import com.google.gson.JsonObject;
30
31 import java.io.IOException;
32 import java.util.LinkedHashSet;
33
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
38 import org.onap.clamp.clds.util.JsonUtils;
39 import org.onap.clamp.clds.util.ResourceFileUtil;
40 import org.onap.clamp.loop.Loop;
41 import org.onap.clamp.policy.microservice.MicroServicePolicy;
42 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
43
44 public class BlueprintInputParametersTest {
45
46     private BlueprintArtifact buildFakeBuildprintArtifact(String blueprintFilePath) throws IOException {
47         BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class);
48         Mockito.when(blueprintArtifact.getDcaeBlueprint())
49                 .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath));
50         return blueprintArtifact;
51     }
52
53     private LinkedHashSet<BlueprintArtifact> buildFakeCsarHandler() throws IOException, SdcToscaParserException {
54
55         LinkedHashSet<BlueprintArtifact> blueprintSet = new LinkedHashSet<BlueprintArtifact>();
56
57         BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact("example/sdc/blueprint-dcae/tca.yaml");
58
59         blueprintSet.add(blueprintArtifact);
60         // Create fake blueprint artifact 2 on resource2
61         blueprintArtifact = buildFakeBuildprintArtifact("example/sdc/blueprint-dcae/tca_2.yaml");
62         blueprintSet.add(blueprintArtifact);
63
64         // Create fake blueprint artifact 3 on resource 1 so that it's possible to
65         // test multiple CL deployment per Service/vnf
66         blueprintArtifact = buildFakeBuildprintArtifact("example/sdc/blueprint-dcae/tca_3.yaml");
67         blueprintSet.add(blueprintArtifact);
68         return blueprintSet;
69     }
70
71     @Test
72     public void getDeploymentParametersinJsonTest() throws IOException, SdcToscaParserException {
73         Loop loop = Mockito.mock(Loop.class);
74         MicroServicePolicy umService = Mockito.mock(MicroServicePolicy.class);
75         LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>();
76         Mockito.when(umService.getName()).thenReturn("testName");
77         umServiceSet.add(umService);
78         Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
79
80         JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(buildFakeCsarHandler(), loop);
81
82         Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson), 
83             ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters.json"));
84     }
85 }