Merge "Set localhost in config"
[clamp.git] / src / test / java / org / onap / clamp / clds / it / CldsDaoIT.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
22  */
23
24 package org.onap.clamp.clds.it;
25
26 import static org.junit.Assert.assertEquals;
27
28 import java.io.IOException;
29
30 import javax.ws.rs.NotFoundException;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.clamp.clds.AbstractIT;
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;
45
46 /**
47  * Test CldsDAO calls through CldsModel and CldsEvent. This really test the DB
48  * and stored procedures.
49  */
50 @RunWith(SpringRunner.class)
51 @SpringBootTest
52 @TestPropertySource(locations = "classpath:application-no-camunda.properties")
53 public class CldsDaoIT extends AbstractIT {
54
55     @Autowired
56     public CldsDao cldsDao;
57
58     private String bpmnText;
59     private String imageText;
60     private String bpmnPropText;
61
62     @Before
63     public void setupBefore() throws IOException {
64         bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml");
65         imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
66         bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
67     }
68
69     @Test
70     public void testModelSave() throws IOException {
71         // Add the template first
72         CldsTemplate newTemplate = new CldsTemplate();
73         newTemplate.setName("test-template");
74
75         newTemplate.setBpmnText(bpmnText);
76         newTemplate.setImageText(imageText);
77
78         // Save the template in DB
79         cldsDao.setTemplate(newTemplate, "user");
80         // Test if it's well there
81         CldsTemplate newTemplateRead = cldsDao.getTemplate("test-template");
82         assertEquals(bpmnText, newTemplateRead.getBpmnText());
83         assertEquals(imageText, newTemplateRead.getImageText());
84
85         // Save the model
86         CldsModel newModel = new CldsModel();
87         newModel.setName("test-model");
88
89         newModel.setBpmnText(bpmnText);
90         newModel.setImageText(imageText);
91         newModel.setPropText(bpmnPropText);
92         newModel.setControlNamePrefix("ClosedLoop-");
93         newModel.setTemplateName("test-template");
94         newModel.setTemplateId(newTemplate.getId());
95         newModel.setDocText(newTemplate.getPropText());
96         newModel.setDocId(newTemplate.getPropId());
97         // Save the model in DB
98         cldsDao.setModel(newModel, "user");
99         // Test if the model can be retrieved
100         CldsModel newCldsModel = cldsDao.getModelTemplate("test-model");
101         assertEquals(bpmnText, newCldsModel.getBpmnText());
102         assertEquals(imageText, newCldsModel.getImageText());
103         assertEquals(bpmnPropText, newCldsModel.getPropText());
104
105     }
106
107     @Test(expected = NotFoundException.class)
108     public void testGetModelNotFound() {
109         CldsModel.retrieve(cldsDao, "test-model-not-found", false);
110     }
111
112     @Test(expected = NotFoundException.class)
113     public void testGetTemplateNotFound() {
114         CldsTemplate.retrieve(cldsDao, "test-template-not-found", false);
115     }
116
117     @Test
118     public void testInsEvent() {
119         // Add the template first
120         CldsTemplate newTemplate = new CldsTemplate();
121         newTemplate.setName("test-template-for-event");
122
123         newTemplate.setBpmnText(bpmnText);
124         newTemplate.setImageText(imageText);
125
126         newTemplate.save(cldsDao, "user");
127
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());
132
133         // Save the model
134         CldsModel newModel = new CldsModel();
135         newModel.setName("test-model-for-event");
136
137         newModel.setBpmnText(bpmnText);
138         newModel.setImageText(imageText);
139         newModel.setPropText(bpmnPropText);
140         newModel.setControlNamePrefix("ClosedLoop-");
141         newModel.setTemplateName("test-template-for-event");
142         newModel.setTemplateId(newTemplate.getId());
143         newModel.setDocText(newTemplate.getPropText());
144         newModel.setDocId(newTemplate.getPropId());
145
146         CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED,
147                 "process-instance-id");
148     }
149 }