2b3b48255f1016af03df7b3978002515ccfc3c73
[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 import java.io.IOException;
31 import java.util.LinkedHashSet;
32 import org.junit.Assert;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.onap.clamp.clds.util.JsonUtils;
36 import org.onap.clamp.clds.util.ResourceFileUtil;
37 import org.onap.clamp.loop.Loop;
38 import org.onap.clamp.loop.template.LoopElementModel;
39 import org.onap.clamp.loop.template.LoopTemplate;
40 import org.onap.clamp.policy.microservice.MicroServicePolicy;
41 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
42
43 public class BlueprintInputParametersTest {
44
45     /**
46      * getDeploymentParametersinJsonMultiBlueprintsTest.
47      *
48      * @throws IOException             in case of failure
49      * @throws SdcToscaParserException in case of failure
50      */
51     @Test
52     public void getDeploymentParametersinJsonMultiBlueprintsTest() throws IOException, SdcToscaParserException {
53
54
55         MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
56         Mockito.when(umService1.getName()).thenReturn("testName1");
57
58         LoopElementModel loopElement = Mockito.mock(LoopElementModel.class);
59         String blueprint1 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
60         Mockito.when(loopElement.getBlueprint()).thenReturn(blueprint1);
61         Mockito.when(umService1.getLoopElementModel()).thenReturn(loopElement);
62
63         MicroServicePolicy umService2 = Mockito.mock(MicroServicePolicy.class);
64         Mockito.when(umService2.getName()).thenReturn("testName2");
65
66         LoopElementModel loopElement2 = Mockito.mock(LoopElementModel.class);
67         String blueprint2 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca_2.yaml");
68         Mockito.when(loopElement2.getBlueprint()).thenReturn(blueprint2);
69         Mockito.when(umService2.getLoopElementModel()).thenReturn(loopElement2);
70
71         MicroServicePolicy umService3 = Mockito.mock(MicroServicePolicy.class);
72         Mockito.when(umService3.getName()).thenReturn("testName3");
73
74         LoopElementModel loopElement3 = Mockito.mock(LoopElementModel.class);
75         String blueprint3 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca_3.yaml");
76         Mockito.when(loopElement3.getBlueprint()).thenReturn(blueprint3);
77         Mockito.when(umService3.getLoopElementModel()).thenReturn(loopElement3);
78
79         LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<>();
80         umServiceSet.add(umService1);
81         umServiceSet.add(umService2);
82         umServiceSet.add(umService3);
83         Loop loop = Mockito.mock(Loop.class);
84         Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
85
86         LoopTemplate template = Mockito.mock(LoopTemplate.class);
87         Mockito.when(template.getUniqueBlueprint()).thenReturn(false);
88         Mockito.when(loop.getLoopTemplate()).thenReturn(template);
89
90         JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
91
92         Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
93                 ResourceFileUtil.getResourceAsString(
94                         "example/sdc/expected-result/deployment-parameters-multi-blueprints.json"));
95     }
96
97     /**
98      * getDeploymentParametersInJsonSingleBlueprintTest.
99      *
100      * @throws IOException In case of failure
101      * @throws SdcToscaParserException In case of failure
102      */
103     @Test
104     public void getDeploymentParametersInJsonSingleBlueprintTest() throws IOException, SdcToscaParserException {
105         Loop loop = Mockito.mock(Loop.class);
106
107         MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
108         Mockito.when(umService1.getName()).thenReturn("testName1");
109         LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>();
110         umServiceSet.add(umService1);
111         Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
112
113         LoopTemplate template = Mockito.mock(LoopTemplate.class);
114         Mockito.when(template.getUniqueBlueprint()).thenReturn(true);
115         String blueprint = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
116         Mockito.when(template.getBlueprint()).thenReturn(blueprint);
117         Mockito.when(loop.getLoopTemplate()).thenReturn(template);
118
119         JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
120
121         Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
122                 ResourceFileUtil.getResourceAsString(
123                         "example/sdc/expected-result/deployment-parameters-single-blueprint.json"));
124     }
125 }