Add unit test for vfc-nfvo-wfengine
[vfc/nfvo/wfengine.git] / wfenginemgrservice / src / test / java / org / onap / workflow / common / RestClientUtilsTest.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.workflow.common;
18
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.InputStream;
22
23 import org.apache.http.HttpEntity;
24 import org.apache.http.entity.ContentType;
25 import org.junit.Assert;
26 import org.junit.Test;
27
28 /**
29  *
30  */
31 public class RestClientUtilsTest {
32
33   @Test
34   public void testbuildMultipartRequest() {
35     String filePath = System.getProperty("java.io.tmpdir");
36     String fileName = "testfile";
37     File file = new File(filePath + File.separator + fileName);
38     InputStream is = null;
39     try {
40       if (!file.exists()) {
41         file.createNewFile();
42       }
43       is = new FileInputStream(file);
44       HttpEntity httpentity = RestClientUtils.buildMultipartRequest(is, fileName);
45       Assert.assertTrue(httpentity.getContentType().getValue()
46           .indexOf(ContentType.MULTIPART_FORM_DATA.getMimeType()) > -1);
47     } catch (Exception e) {
48       assert (false);
49     } finally {
50       ToolUtil.closeInputStream(is);
51       if (file.exists()) {
52         file.delete();
53       }
54     }
55   }
56 }