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.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;
44 public class BlueprintInputParametersTest {
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;
53 private LinkedHashSet<BlueprintArtifact> buildFakeCsarHandler() throws IOException, SdcToscaParserException {
55 LinkedHashSet<BlueprintArtifact> blueprintSet = new LinkedHashSet<BlueprintArtifact>();
57 BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact("example/sdc/blueprint-dcae/tca.yaml");
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);
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);
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);
80 JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(buildFakeCsarHandler(), loop);
82 Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
83 ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters.json"));