2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.it;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.List;
36 import javax.ws.rs.NotFoundException;
38 import org.apache.commons.lang3.RandomStringUtils;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.onap.clamp.clds.dao.CldsDao;
43 import org.onap.clamp.clds.model.CldsEvent;
44 import org.onap.clamp.clds.model.CldsModel;
45 import org.onap.clamp.clds.model.CldsMonitoringDetails;
46 import org.onap.clamp.clds.model.CldsTemplate;
47 import org.onap.clamp.clds.util.ResourceFileUtil;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.boot.test.context.SpringBootTest;
50 import org.springframework.test.context.junit4.SpringRunner;
53 * Test CldsDAO calls through CldsModel and CldsEvent. This really test the DB
54 * and stored procedures.
56 @RunWith(SpringRunner.class)
58 public class CldsDaoItCase {
60 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDaoItCase.class);
62 public CldsDao cldsDao;
63 private String bpmnText;
64 private String imageText;
65 private String bpmnPropText;
68 * Setup the variable before the tests execution.
71 * In case of issues when opening the files
74 public void setupBefore() throws IOException {
75 bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml");
76 imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
77 bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
81 public void testModelSave() {
82 String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5);
83 // Add the template first
84 CldsTemplate newTemplate = new CldsTemplate();
85 newTemplate.setName(randomNameTemplate);
86 newTemplate.setBpmnText(bpmnText);
87 newTemplate.setImageText(imageText);
88 // Save the template in DB
89 cldsDao.setTemplate(newTemplate, "user");
90 // Test if it's well there
91 CldsTemplate newTemplateRead = cldsDao.getTemplate(randomNameTemplate);
92 assertEquals(bpmnText, newTemplateRead.getBpmnText());
93 assertEquals(imageText, newTemplateRead.getImageText());
95 CldsModel newModel = new CldsModel();
96 String randomNameModel = RandomStringUtils.randomAlphanumeric(5);
97 newModel.setName(randomNameModel);
98 newModel.setBpmnText(bpmnText);
99 newModel.setImageText(imageText);
100 newModel.setPropText(bpmnPropText);
101 newModel.setControlNamePrefix("ClosedLoop-");
102 newModel.setTemplateName(randomNameTemplate);
103 newModel.setTemplateId(newTemplate.getId());
104 newModel.setDocText(newTemplate.getPropText());
105 // Save the model in DB
106 cldsDao.setModel(newModel, "user");
107 // Test if the model can be retrieved
108 CldsModel newCldsModel = cldsDao.getModelTemplate(randomNameModel);
109 assertEquals(bpmnText, newCldsModel.getBpmnText());
110 assertEquals(imageText, newCldsModel.getImageText());
111 assertEquals(bpmnPropText, newCldsModel.getPropText());
114 @Test(expected = NotFoundException.class)
115 public void testGetModelNotFound() {
116 CldsModel.retrieve(cldsDao, "test-model-not-found", false);
119 @Test(expected = NotFoundException.class)
120 public void testGetTemplateNotFound() {
121 CldsTemplate.retrieve(cldsDao, "test-template-not-found", false);
125 public void testInsEvent() {
126 // Add the template first
127 CldsTemplate newTemplate = new CldsTemplate();
128 newTemplate.setName("test-template-for-event");
129 newTemplate.setBpmnText(bpmnText);
130 newTemplate.setImageText(imageText);
131 newTemplate.save(cldsDao, "user");
132 // Test if it's well there
133 CldsTemplate newTemplateRead = CldsTemplate.retrieve(cldsDao, "test-template-for-event", false);
134 assertEquals(bpmnText, newTemplateRead.getBpmnText());
135 assertEquals(imageText, newTemplateRead.getImageText());
137 CldsModel newModel = new CldsModel();
138 newModel.setName("test-model-for-event");
139 newModel.setBpmnText(bpmnText);
140 newModel.setImageText(imageText);
141 newModel.setPropText(bpmnPropText);
142 newModel.setControlNamePrefix("ClosedLoop-");
143 newModel.setTemplateName("test-template-for-event");
144 newModel.setTemplateId(newTemplate.getId());
145 newModel.setDocText(newTemplate.getPropText());
146 CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED,
147 "process-instance-id");
151 public void testGetCldsMonitoringDetails() {
152 List<CldsMonitoringDetails> cldsMonitoringDetailsList = new ArrayList<CldsMonitoringDetails>();
153 cldsMonitoringDetailsList = cldsDao.getCldsMonitoringDetails();
154 cldsMonitoringDetailsList.forEach(clName -> {
155 logger.info(clName.getCloseloopName());
156 assertNotNull(clName.getCloseloopName());