2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.it;
26 import static org.junit.Assert.assertEquals;
28 import java.io.IOException;
30 import javax.ws.rs.NotFoundException;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.clamp.clds.AbstractItCase;
36 import org.onap.clamp.clds.dao.CldsDao;
37 import org.onap.clamp.clds.model.CldsEvent;
38 import org.onap.clamp.clds.model.CldsModel;
39 import org.onap.clamp.clds.model.CldsTemplate;
40 import org.onap.clamp.clds.util.ResourceFileUtil;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.boot.test.context.SpringBootTest;
43 import org.springframework.test.context.TestPropertySource;
44 import org.springframework.test.context.junit4.SpringRunner;
47 * Test CldsDAO calls through CldsModel and CldsEvent. This really test the DB
48 * and stored procedures.
50 @RunWith(SpringRunner.class)
52 @TestPropertySource(locations = "classpath:application-no-camunda.properties")
53 public class CldsDaoItCase extends AbstractItCase {
56 public CldsDao cldsDao;
58 private String bpmnText;
59 private String imageText;
60 private String bpmnPropText;
63 * Setup the variable before the tests execution.
66 * In case of issues when opening the files
69 public void setupBefore() throws IOException {
70 bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml");
71 imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
72 bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
76 public void testModelSave() throws IOException {
77 // Add the template first
78 CldsTemplate newTemplate = new CldsTemplate();
79 newTemplate.setName("test-template");
81 newTemplate.setBpmnText(bpmnText);
82 newTemplate.setImageText(imageText);
84 // Save the template in DB
85 cldsDao.setTemplate(newTemplate, "user");
86 // Test if it's well there
87 CldsTemplate newTemplateRead = cldsDao.getTemplate("test-template");
88 assertEquals(bpmnText, newTemplateRead.getBpmnText());
89 assertEquals(imageText, newTemplateRead.getImageText());
92 CldsModel newModel = new CldsModel();
93 newModel.setName("test-model");
95 newModel.setBpmnText(bpmnText);
96 newModel.setImageText(imageText);
97 newModel.setPropText(bpmnPropText);
98 newModel.setControlNamePrefix("ClosedLoop-");
99 newModel.setTemplateName("test-template");
100 newModel.setTemplateId(newTemplate.getId());
101 newModel.setDocText(newTemplate.getPropText());
102 newModel.setDocId(newTemplate.getPropId());
103 // Save the model in DB
104 cldsDao.setModel(newModel, "user");
105 // Test if the model can be retrieved
106 CldsModel newCldsModel = cldsDao.getModelTemplate("test-model");
107 assertEquals(bpmnText, newCldsModel.getBpmnText());
108 assertEquals(imageText, newCldsModel.getImageText());
109 assertEquals(bpmnPropText, newCldsModel.getPropText());
113 @Test(expected = NotFoundException.class)
114 public void testGetModelNotFound() {
115 CldsModel.retrieve(cldsDao, "test-model-not-found", false);
118 @Test(expected = NotFoundException.class)
119 public void testGetTemplateNotFound() {
120 CldsTemplate.retrieve(cldsDao, "test-template-not-found", false);
124 public void testInsEvent() {
125 // Add the template first
126 CldsTemplate newTemplate = new CldsTemplate();
127 newTemplate.setName("test-template-for-event");
129 newTemplate.setBpmnText(bpmnText);
130 newTemplate.setImageText(imageText);
132 newTemplate.save(cldsDao, "user");
134 // Test if it's well there
135 CldsTemplate newTemplateRead = CldsTemplate.retrieve(cldsDao, "test-template-for-event", false);
136 assertEquals(bpmnText, newTemplateRead.getBpmnText());
137 assertEquals(imageText, newTemplateRead.getImageText());
140 CldsModel newModel = new CldsModel();
141 newModel.setName("test-model-for-event");
143 newModel.setBpmnText(bpmnText);
144 newModel.setImageText(imageText);
145 newModel.setPropText(bpmnPropText);
146 newModel.setControlNamePrefix("ClosedLoop-");
147 newModel.setTemplateName("test-template-for-event");
148 newModel.setTemplateId(newTemplate.getId());
149 newModel.setDocText(newTemplate.getPropText());
150 newModel.setDocId(newTemplate.getPropId());
152 CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED,
153 "process-instance-id");