2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
27 package org.onap.clamp.loop.deploy;
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.ResourceFileUtils;
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;
43 public class BlueprintInputParametersTest {
46 * getDeploymentParametersinJsonMultiBlueprintsTest.
48 * @throws IOException in case of failure
49 * @throws SdcToscaParserException in case of failure
52 public void getDeploymentParametersinJsonMultiBlueprintsTest() throws IOException, SdcToscaParserException {
55 MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
56 Mockito.when(umService1.getName()).thenReturn("testName1");
58 LoopElementModel loopElement = Mockito.mock(LoopElementModel.class);
59 String blueprint1 = ResourceFileUtils.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
60 Mockito.when(loopElement.getBlueprint()).thenReturn(blueprint1);
61 Mockito.when(umService1.getLoopElementModel()).thenReturn(loopElement);
63 MicroServicePolicy umService2 = Mockito.mock(MicroServicePolicy.class);
64 Mockito.when(umService2.getName()).thenReturn("testName2");
66 LoopElementModel loopElement2 = Mockito.mock(LoopElementModel.class);
67 String blueprint2 = ResourceFileUtils.getResourceAsString("example/sdc/blueprint-dcae/tca_2.yaml");
68 Mockito.when(loopElement2.getBlueprint()).thenReturn(blueprint2);
69 Mockito.when(umService2.getLoopElementModel()).thenReturn(loopElement2);
71 MicroServicePolicy umService3 = Mockito.mock(MicroServicePolicy.class);
72 Mockito.when(umService3.getName()).thenReturn("testName3");
74 LoopElementModel loopElement3 = Mockito.mock(LoopElementModel.class);
75 String blueprint3 = ResourceFileUtils.getResourceAsString("example/sdc/blueprint-dcae/tca_3.yaml");
76 Mockito.when(loopElement3.getBlueprint()).thenReturn(blueprint3);
77 Mockito.when(umService3.getLoopElementModel()).thenReturn(loopElement3);
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);
86 LoopTemplate template = Mockito.mock(LoopTemplate.class);
87 Mockito.when(template.getUniqueBlueprint()).thenReturn(false);
88 Mockito.when(loop.getLoopTemplate()).thenReturn(template);
90 JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
92 Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
93 ResourceFileUtils.getResourceAsString(
94 "example/sdc/expected-result/deployment-parameters-multi-blueprints.json"));
98 * getDeploymentParametersInJsonSingleBlueprintTest.
100 * @throws IOException In case of failure
101 * @throws SdcToscaParserException In case of failure
104 public void getDeploymentParametersInJsonSingleBlueprintTest() throws IOException, SdcToscaParserException {
105 Loop loop = Mockito.mock(Loop.class);
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);
113 LoopTemplate template = Mockito.mock(LoopTemplate.class);
114 Mockito.when(template.getUniqueBlueprint()).thenReturn(true);
115 String blueprint = ResourceFileUtils.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
116 Mockito.when(template.getBlueprint()).thenReturn(blueprint);
117 Mockito.when(loop.getLoopTemplate()).thenReturn(template);
119 JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
121 Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
122 ResourceFileUtils.getResourceAsString(
123 "example/sdc/expected-result/deployment-parameters-single-blueprint.json"));