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;
31 import java.io.IOException;
32 import java.util.LinkedHashSet;
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.onap.clamp.clds.util.JsonUtils;
38 import org.onap.clamp.clds.util.ResourceFileUtil;
39 import org.onap.clamp.loop.Loop;
40 import org.onap.clamp.loop.template.LoopElementModel;
41 import org.onap.clamp.loop.template.LoopTemplate;
42 import org.onap.clamp.policy.microservice.MicroServicePolicy;
43 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
45 public class BlueprintInputParametersTest {
48 public void getDeploymentParametersinJsonMultiBlueprintsTest() throws IOException, SdcToscaParserException {
49 Loop loop = Mockito.mock(Loop.class);
51 MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
52 Mockito.when(umService1.getName()).thenReturn("testName1");
54 LoopElementModel loopElement = Mockito.mock(LoopElementModel.class);
55 String blueprint1 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
56 Mockito.when(loopElement.getBlueprint()).thenReturn(blueprint1);
57 Mockito.when(umService1.getLoopElementModel()).thenReturn(loopElement);
59 MicroServicePolicy umService2 = Mockito.mock(MicroServicePolicy.class);
60 Mockito.when(umService2.getName()).thenReturn("testName2");
62 LoopElementModel loopElement2 = Mockito.mock(LoopElementModel.class);
63 String blueprint2 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca_2.yaml");
64 Mockito.when(loopElement2.getBlueprint()).thenReturn(blueprint2);
65 Mockito.when(umService2.getLoopElementModel()).thenReturn(loopElement2);
67 MicroServicePolicy umService3 = Mockito.mock(MicroServicePolicy.class);
68 Mockito.when(umService3.getName()).thenReturn("testName3");
70 LoopElementModel loopElement3 = Mockito.mock(LoopElementModel.class);
71 String blueprint3 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca_3.yaml");
72 Mockito.when(loopElement3.getBlueprint()).thenReturn(blueprint3);
73 Mockito.when(umService3.getLoopElementModel()).thenReturn(loopElement3);
75 LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>();
76 umServiceSet.add(umService1);
77 umServiceSet.add(umService2);
78 umServiceSet.add(umService3);
79 Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
81 LoopTemplate template = Mockito.mock(LoopTemplate.class);
82 Mockito.when(template.getUniqueBlueprint()).thenReturn(false);
83 Mockito.when(loop.getLoopTemplate()).thenReturn(template);
85 JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
87 Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
88 ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-multi-blueprints.json"));
92 public void getDeploymentParametersInJsonSingleBlueprintTest() throws IOException, SdcToscaParserException {
93 Loop loop = Mockito.mock(Loop.class);
95 MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
96 Mockito.when(umService1.getName()).thenReturn("testName1");
97 LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>();
98 umServiceSet.add(umService1);
99 Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
101 LoopTemplate template = Mockito.mock(LoopTemplate.class);
102 Mockito.when(template.getUniqueBlueprint()).thenReturn(true);
103 String blueprint = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
104 Mockito.when(template.getBlueprint()).thenReturn(blueprint);
105 Mockito.when(loop.getLoopTemplate()).thenReturn(template);
107 JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
109 Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
110 ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-single-blueprint.json"));