2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
33 import java.io.IOException;
34 import java.security.Principal;
35 import java.util.List;
37 import javax.ws.rs.core.SecurityContext;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.Mockito;
43 import org.onap.clamp.clds.dao.CldsDao;
44 import org.onap.clamp.clds.model.CldsTemplate;
45 import org.onap.clamp.clds.model.ValueItem;
46 import org.onap.clamp.clds.service.CldsTemplateService;
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.boot.test.context.SpringBootTest.WebEnvironment;
51 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
54 * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS.
56 @RunWith(SpringJUnit4ClassRunner.class)
57 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
58 public class CldsTemplateServiceItCase {
60 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsTemplateServiceItCase.class);
62 private CldsTemplateService cldsTemplateService;
64 private CldsDao cldsDao;
65 private String bpmnText;
66 private String imageText;
67 private String bpmnPropText;
68 private CldsTemplate cldsTemplate;
71 * Setup the variable before the tests execution.
74 * In case of issues when opening the files
77 public void setupBefore() throws IOException {
78 SecurityContext securityContext = Mockito.mock(SecurityContext.class);
79 Principal principal = Mockito.mock(Principal.class);
80 Mockito.when(principal.getName()).thenReturn("admin");
81 Mockito.when(securityContext.getUserPrincipal()).thenReturn(principal);
82 Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|read")).thenReturn(true);
83 Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|update")).thenReturn(true);
84 Mockito.when(securityContext.isUserInRole("permission-type-template|dev|read")).thenReturn(true);
85 Mockito.when(securityContext.isUserInRole("permission-type-template|dev|update")).thenReturn(true);
86 cldsTemplateService.setSecurityContext(securityContext);
87 bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml");
88 imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
89 bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
90 cldsTemplate = new CldsTemplate();
91 cldsTemplate.setName("testModel");
92 cldsTemplate.setBpmnText(bpmnText);
93 cldsTemplate.setImageText(imageText);
94 cldsTemplate.setPropText(bpmnPropText);
95 cldsTemplateService.putTemplate("testModel", cldsTemplate);
99 public void testPutTemplate() throws Exception {
100 CldsTemplate savedTemplate = CldsTemplate.retrieve(cldsDao, "testModel", false);
101 assertNotNull(savedTemplate);
102 logger.info("saved template bpmn text is:" + savedTemplate.getBpmnText());
103 assertEquals(bpmnText, savedTemplate.getBpmnText());
104 assertEquals(imageText, savedTemplate.getImageText());
105 assertEquals(bpmnPropText, savedTemplate.getPropText());
106 assertEquals("testModel", savedTemplate.getName());
110 public void testGetTemplate() throws Exception {
111 CldsTemplate getTemplate = cldsTemplateService.getTemplate("testModel");
112 assertNotNull(getTemplate);
113 assertEquals(bpmnText, getTemplate.getBpmnText());
114 assertEquals(imageText, getTemplate.getImageText());
115 assertEquals(bpmnPropText, getTemplate.getPropText());
116 assertEquals("testModel", getTemplate.getName());
120 public void testGetImageXml() throws Exception {
121 String imageXml = cldsTemplateService.getImageXml("testModel");
122 assertEquals(imageText, imageXml);
126 public void testGetBpmnTemplate() throws Exception {
127 String bpmnTemplate = cldsTemplateService.getBpmnTemplate("testModel");
128 assertEquals(bpmnText, bpmnTemplate);
132 public void testGetTemplateNames() throws Exception {
133 CldsTemplate cldsTemplateNew = new CldsTemplate();
134 cldsTemplateNew.setName("testModelNew");
135 cldsTemplateNew.setBpmnText(bpmnText);
136 cldsTemplateNew.setImageText(imageText);
137 cldsTemplateNew.setPropText(bpmnPropText);
138 cldsTemplateService.putTemplate("testModelNew", cldsTemplateNew);
139 List<ValueItem> templateNames = cldsTemplateService.getTemplateNames();
140 boolean testModel = false;
141 boolean testModelNew = false;
142 for (ValueItem item : templateNames) {
143 if (item.getValue().equals("testModel")) {
146 if (item.getValue().equals("testModelNew")) {
150 assertTrue(testModel || testModelNew);