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 com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils;
30 import java.io.IOException;
32 import javax.ws.rs.NotFoundException;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.onap.clamp.clds.AbstractItCase;
38 import org.onap.clamp.clds.dao.CldsDao;
39 import org.onap.clamp.clds.model.CldsEvent;
40 import org.onap.clamp.clds.model.CldsModel;
41 import org.onap.clamp.clds.model.CldsTemplate;
42 import org.onap.clamp.clds.util.ResourceFileUtil;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.boot.test.context.SpringBootTest;
45 import org.springframework.test.context.TestPropertySource;
46 import org.springframework.test.context.junit4.SpringRunner;
49 * Test CldsDAO calls through CldsModel and CldsEvent. This really test the DB
50 * and stored procedures.
52 @RunWith(SpringRunner.class)
54 @TestPropertySource(locations = "classpath:application-no-camunda.properties")
55 public class CldsDaoItCase extends AbstractItCase {
57 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 String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5);
78 String randomNameModel = RandomStringUtils.randomAlphanumeric(5);
79 // Add the template first
80 CldsTemplate newTemplate = new CldsTemplate();
81 newTemplate.setName(randomNameTemplate);
82 newTemplate.setBpmnText(bpmnText);
83 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(randomNameTemplate);
88 assertEquals(bpmnText, newTemplateRead.getBpmnText());
89 assertEquals(imageText, newTemplateRead.getImageText());
91 CldsModel newModel = new CldsModel();
92 newModel.setName(randomNameModel);
93 newModel.setBpmnText(bpmnText);
94 newModel.setImageText(imageText);
95 newModel.setPropText(bpmnPropText);
96 newModel.setControlNamePrefix("ClosedLoop-");
97 newModel.setTemplateName(randomNameTemplate);
98 newModel.setTemplateId(newTemplate.getId());
99 newModel.setDocText(newTemplate.getPropText());
100 newModel.setDocId(newTemplate.getPropId());
101 // Save the model in DB
102 cldsDao.setModel(newModel, "user");
103 // Test if the model can be retrieved
104 CldsModel newCldsModel = cldsDao.getModelTemplate(randomNameModel);
105 assertEquals(bpmnText, newCldsModel.getBpmnText());
106 assertEquals(imageText, newCldsModel.getImageText());
107 assertEquals(bpmnPropText, newCldsModel.getPropText());
110 @Test(expected = NotFoundException.class)
111 public void testGetModelNotFound() {
112 CldsModel.retrieve(cldsDao, "test-model-not-found", false);
115 @Test(expected = NotFoundException.class)
116 public void testGetTemplateNotFound() {
117 CldsTemplate.retrieve(cldsDao, "test-template-not-found", false);
121 public void testInsEvent() {
122 // Add the template first
123 CldsTemplate newTemplate = new CldsTemplate();
124 newTemplate.setName("test-template-for-event");
125 newTemplate.setBpmnText(bpmnText);
126 newTemplate.setImageText(imageText);
127 newTemplate.save(cldsDao, "user");
128 // Test if it's well there
129 CldsTemplate newTemplateRead = CldsTemplate.retrieve(cldsDao, "test-template-for-event", false);
130 assertEquals(bpmnText, newTemplateRead.getBpmnText());
131 assertEquals(imageText, newTemplateRead.getImageText());
133 CldsModel newModel = new CldsModel();
134 newModel.setName("test-model-for-event");
135 newModel.setBpmnText(bpmnText);
136 newModel.setImageText(imageText);
137 newModel.setPropText(bpmnPropText);
138 newModel.setControlNamePrefix("ClosedLoop-");
139 newModel.setTemplateName("test-template-for-event");
140 newModel.setTemplateId(newTemplate.getId());
141 newModel.setDocText(newTemplate.getPropText());
142 newModel.setDocId(newTemplate.getPropId());
143 CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED,
144 "process-instance-id");