2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.asdc.installer.bpmn;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
28 import static org.mockito.ArgumentMatchers.any;
29 import static org.mockito.ArgumentMatchers.anyString;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.spy;
33 import static org.mockito.Mockito.times;
34 import static org.mockito.Mockito.verify;
37 import java.io.FileInputStream;
38 import java.io.InputStream;
39 import java.nio.file.Files;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
42 import javax.transaction.Transactional;
43 import org.apache.commons.io.IOUtils;
44 import org.apache.http.HttpEntity;
45 import org.apache.http.HttpResponse;
46 import org.apache.http.ProtocolVersion;
47 import org.apache.http.client.HttpClient;
48 import org.apache.http.client.methods.HttpPost;
49 import org.apache.http.message.BasicHttpResponse;
50 import org.apache.http.message.BasicStatusLine;
51 import org.junit.AfterClass;
52 import org.junit.Before;
53 import org.junit.Rule;
54 import org.junit.Test;
55 import org.junit.rules.TemporaryFolder;
58 public class BpmnInstallerTest {
60 private BpmnInstaller bpmnInstaller = new BpmnInstaller();
62 private static final String TEST_CSAR = "src/test/resources/resource-examples/WorkflowBpmn/service-CxSvc-csar.csar";
63 private Path tempDirectoryPath;
66 public TemporaryFolder folder = new TemporaryFolder();
69 public void init() throws Exception {
70 System.setProperty("mso.config.path", folder.getRoot().toString());
71 // we need to have this directory created for InstallBPMN test success
72 tempDirectoryPath = Paths.get(folder.getRoot().toString(), "ASDC");
73 Files.createDirectories(tempDirectoryPath);
77 public static void cleanup() {
78 System.clearProperty("mso.config.path");
82 public void buildMimeMultiPart_Test() throws Exception {
83 Path tempFilePath = Paths.get(tempDirectoryPath.toAbsolutePath().toString(), "TestBB.bpmn");
84 Files.createFile(tempFilePath);
85 HttpEntity entity = bpmnInstaller.buildMimeMultipart("TestBB.bpmn");
86 String mimeMultipartBodyFilePath = "src/test/resources" + "/mime-multipart-body.txt";
88 File mimeMultipartBody = new File(mimeMultipartBodyFilePath);
89 InputStream expectedContent = new FileInputStream(mimeMultipartBody);
91 assertThat(IOUtils.contentEquals(expectedContent, entity.getContent()));
93 IOUtils.closeQuietly(expectedContent);
97 public void installBpmn_Test() throws Exception {
98 BpmnInstaller bpmnInstallerSpy = spy(bpmnInstaller);
99 HttpResponse response = new BasicHttpResponse(
100 new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
101 HttpClient httpClient = mock(HttpClient.class);
102 doReturn(response).when(httpClient).execute(any(HttpPost.class));
103 bpmnInstallerSpy.installBpmn(TEST_CSAR);
104 verify(bpmnInstallerSpy, times(1)).sendDeploymentRequest(anyString());
108 public void containsWorkflowsSuccess() {
109 boolean result = bpmnInstaller.containsWorkflows(TEST_CSAR);
114 public void containsWorkflowsFailure() {
115 boolean result = bpmnInstaller.containsWorkflows("DOESNOTEXIST.csar");