2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END============================================
\r
20 * ===================================================================
\r
24 package org.onap.clamp.loop;
\r
26 import static org.assertj.core.api.Assertions.assertThat;
\r
27 import static org.junit.Assert.assertNotNull;
\r
28 import static org.junit.Assert.assertNull;
\r
29 import static org.junit.jupiter.api.Assertions.assertEquals;
\r
31 import java.util.List;
\r
32 import java.util.SortedSet;
\r
33 import javax.transaction.Transactional;
\r
34 import org.junit.Test;
\r
35 import org.junit.runner.RunWith;
\r
36 import org.onap.clamp.clds.Application;
\r
37 import org.onap.clamp.loop.template.LoopElementModel;
\r
38 import org.onap.clamp.loop.template.LoopTemplate;
\r
39 import org.onap.clamp.loop.template.LoopTemplateLoopElementModel;
\r
40 import org.onap.clamp.loop.template.LoopTemplatesService;
\r
41 import org.onap.clamp.loop.template.LoopType;
\r
42 import org.onap.clamp.loop.template.PolicyModel;
\r
43 import org.springframework.beans.factory.annotation.Autowired;
\r
44 import org.springframework.boot.test.context.SpringBootTest;
\r
45 import org.springframework.test.context.junit4.SpringRunner;
\r
47 @RunWith(SpringRunner.class)
\r
48 @SpringBootTest(classes = Application.class)
\r
49 public class LoopTemplatesServiceItCase {
\r
52 LoopTemplatesService loopTemplatesService;
\r
54 private static final String POLICY_MODEL_TYPE_1 = "org.onap.test";
\r
55 private static final String VERSION = "1.0.0";
\r
57 private LoopElementModel getLoopElementModel(String yaml, String name, String loopElementType,
\r
58 String createdBy, PolicyModel policyModel) {
\r
59 LoopElementModel model = new LoopElementModel(name, loopElementType, yaml);
\r
60 model.setBlueprint("");
\r
61 model.setDcaeBlueprintId("");
\r
62 model.addPolicyModel(policyModel);
\r
66 private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version,
\r
67 String policyAcronym, String createdBy) {
\r
68 return new PolicyModel(policyType, policyModelTosca, version, policyAcronym);
\r
71 private LoopTemplate getLoopTemplate(String name, String blueprint, String createdBy, Integer maxInstancesAllowed) {
\r
72 LoopTemplate template =
\r
73 new LoopTemplate(name, blueprint, maxInstancesAllowed, null);
\r
74 template.addLoopElementModel(getLoopElementModel("yaml", "microService1", "MicroService",
\r
75 createdBy, getPolicyModel(POLICY_MODEL_TYPE_1, "yaml", VERSION, "MS1", createdBy)));
\r
76 template.setAllowedLoopType(LoopType.OPEN);
\r
82 public void shouldSaveOrUpdateLoopTemplate() {
\r
83 LoopTemplate loopTemplate = getLoopTemplate("TemplateName", null, "xyz", -1);
\r
84 LoopTemplate actualLoopTemplate =
\r
85 loopTemplatesService.saveOrUpdateLoopTemplate(loopTemplate);
\r
87 assertNotNull(actualLoopTemplate);
\r
88 assertThat(loopTemplate.getName()).isEqualTo("TemplateName");
\r
89 assertThat(loopTemplate.getAllowedLoopType()).isEqualTo(LoopType.OPEN);
\r
94 public void shouldReturnAllLoopTemplates() {
\r
95 LoopTemplate loopTemplate = getLoopTemplate("TemplateName", null, "xyz", -1);
\r
96 loopTemplatesService.saveOrUpdateLoopTemplate(loopTemplate);
\r
97 List<LoopTemplate> loopTemplateList = loopTemplatesService.getAllLoopTemplates();
\r
99 assertNotNull(loopTemplateList);
\r
104 public void shouldReturnLoopTemplateNames() {
\r
105 LoopTemplate loopTemplate = getLoopTemplate("TemplateName", null, "xyz", -1);
\r
106 loopTemplatesService.saveOrUpdateLoopTemplate(loopTemplate);
\r
107 List<String> loopTemplateNames = loopTemplatesService.getLoopTemplateNames();
\r
109 assertNotNull(loopTemplateNames);
\r
110 assertEquals("TemplateName", loopTemplateNames.get(0));
\r
115 public void shouldReturnLoopTemplate() {
\r
116 LoopTemplate loopTemplate = getLoopTemplate("TemplateName", null, "xyz", -1);
\r
117 loopTemplatesService.saveOrUpdateLoopTemplate(loopTemplate);
\r
118 LoopTemplate actualLoopTemplate = loopTemplatesService.getLoopTemplate("TemplateName");
\r
120 assertNotNull(actualLoopTemplate);
\r
121 assertThat(loopTemplate).isEqualTo(actualLoopTemplate);
\r
122 assertThat(loopTemplate.getName()).isEqualTo(actualLoopTemplate.getName());
\r
123 assertThat(loopTemplate.getMaximumInstancesAllowed())
\r
124 .isEqualTo(actualLoopTemplate.getMaximumInstancesAllowed());
\r
125 SortedSet<LoopTemplateLoopElementModel> loopElementModelsUsed =
\r
126 loopTemplate.getLoopElementModelsUsed();
\r
127 LoopTemplateLoopElementModel loopTemplateLoopElementModel = loopElementModelsUsed.first();
\r
128 assertThat(loopTemplateLoopElementModel.getLoopElementModel().getName())
\r
129 .isEqualTo("microService1");
\r
130 assertThat(loopTemplateLoopElementModel.getLoopTemplate().getName())
\r
131 .isEqualTo("TemplateName");
\r
132 assertNull(actualLoopTemplate.getBlueprint());
\r
133 assertNull(actualLoopTemplate.getModelService());
\r
138 public void shouldDeleteLoopTemplate() {
\r
139 LoopTemplate loopTemplate = getLoopTemplate("TemplateName", null, "xyz", -1);
\r
140 loopTemplatesService.saveOrUpdateLoopTemplate(loopTemplate);
\r
141 loopTemplatesService.deleteLoopTemplate("TemplateName");
\r
142 LoopTemplate actualLoopTemplate = loopTemplatesService.getLoopTemplate("TemplateName");
\r
143 assertNull(actualLoopTemplate);
\r