Merge "Set localhost in config"
[clamp.git] / src / test / java / org / onap / clamp / clds / it / CldsDaoItCase.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.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;
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 CldsDaoItCase extends AbstractItCase {
54
55     @Autowired
56     public CldsDao cldsDao;
57
58     private String bpmnText;
59     private String imageText;
60     private String bpmnPropText;
61
62     /**
63      * Setup the variable before the tests execution.
64      * 
65      * @throws IOException
66      *             In case of issues when opening the files
67      */
68     @Before
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");
73     }
74
75     @Test
76     public void testModelSave() throws IOException {
77         // Add the template first
78         CldsTemplate newTemplate = new CldsTemplate();
79         newTemplate.setName("test-template");
80
81         newTemplate.setBpmnText(bpmnText);
82         newTemplate.setImageText(imageText);
83
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());
90
91         // Save the model
92         CldsModel newModel = new CldsModel();
93         newModel.setName("test-model");
94
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());
110
111     }
112
113     @Test(expected = NotFoundException.class)
114     public void testGetModelNotFound() {
115         CldsModel.retrieve(cldsDao, "test-model-not-found", false);
116     }
117
118     @Test(expected = NotFoundException.class)
119     public void testGetTemplateNotFound() {
120         CldsTemplate.retrieve(cldsDao, "test-template-not-found", false);
121     }
122
123     @Test
124     public void testInsEvent() {
125         // Add the template first
126         CldsTemplate newTemplate = new CldsTemplate();
127         newTemplate.setName("test-template-for-event");
128
129         newTemplate.setBpmnText(bpmnText);
130         newTemplate.setImageText(imageText);
131
132         newTemplate.save(cldsDao, "user");
133
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());
138
139         // Save the model
140         CldsModel newModel = new CldsModel();
141         newModel.setName("test-model-for-event");
142
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());
151
152         CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED,
153                 "process-instance-id");
154     }
155 }