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;
36 import java.io.FileInputStream;
37 import java.io.InputStream;
38 import java.nio.file.Files;
39 import java.nio.file.Path;
40 import java.nio.file.Paths;
41 import javax.transaction.Transactional;
42 import org.apache.commons.io.IOUtils;
43 import org.apache.http.HttpEntity;
44 import org.apache.http.HttpResponse;
45 import org.apache.http.ProtocolVersion;
46 import org.apache.http.client.HttpClient;
47 import org.apache.http.client.methods.HttpPost;
48 import org.apache.http.message.BasicHttpResponse;
49 import org.apache.http.message.BasicStatusLine;
50 import org.junit.AfterClass;
51 import org.junit.Before;
52 import org.junit.Rule;
53 import org.junit.Test;
54 import org.junit.rules.TemporaryFolder;
57 public class BpmnInstallerTest {
59 private BpmnInstaller bpmnInstaller = new BpmnInstaller();
61 private static final String TEST_CSAR = "src/test/resources/resource-examples/WorkflowBpmn/service-CxSvc-csar.csar";
62 private Path tempDirectoryPath;
65 public TemporaryFolder folder = new TemporaryFolder();
68 public void init() throws Exception {
69 System.setProperty("mso.config.path", folder.getRoot().toString());
70 // we need to have this directory created for InstallBPMN test success
71 tempDirectoryPath = Paths.get(folder.getRoot().toString(), "ASDC");
72 Files.createDirectories(tempDirectoryPath);
76 public static void cleanup() {
77 System.clearProperty("mso.config.path");
81 public void buildMimeMultiPart_Test() throws Exception {
82 Path tempFilePath = Paths.get(tempDirectoryPath.toAbsolutePath().toString(), "TestBB.bpmn");
83 Files.createFile(tempFilePath);
84 HttpEntity entity = bpmnInstaller.buildMimeMultipart("TestBB.bpmn");
85 String mimeMultipartBodyFilePath = "src/test/resources" + "/mime-multipart-body.txt";
87 File mimeMultipartBody = new File(mimeMultipartBodyFilePath);
88 InputStream expectedContent = new FileInputStream(mimeMultipartBody);
90 assertThat(IOUtils.contentEquals(expectedContent, entity.getContent()));
92 IOUtils.closeQuietly(expectedContent);
96 public void installBpmn_Test() throws Exception {
97 BpmnInstaller bpmnInstallerSpy = spy(bpmnInstaller);
98 HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
99 HttpClient httpClient = mock(HttpClient.class);
100 doReturn(response).when(httpClient).execute(any(HttpPost.class));
101 bpmnInstallerSpy.installBpmn(TEST_CSAR);
102 verify(bpmnInstallerSpy, times(1)).sendDeploymentRequest(anyString());
106 public void containsWorkflowsSuccess() {
107 boolean result = bpmnInstaller.containsWorkflows(TEST_CSAR);
112 public void containsWorkflowsFailure() {
113 boolean result = bpmnInstaller.containsWorkflows("DOESNOTEXIST.csar");