Update css file name in conf.py
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / service / ImportServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.service;
22
23 import static org.assertj.core.api.Assertions.assertThatCode;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import com.mockrunner.mock.web.MockHttpServletRequest;
27 import com.mockrunner.mock.web.MockHttpServletResponse;
28 import java.io.File;
29 import java.io.IOException;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import org.apache.commons.io.FileUtils;
33 import org.junit.AfterClass;
34 import org.junit.Test;
35
36 public class ImportServiceTest {
37     @Test
38     public void testNegativeCases() {
39         ImportService service = new ImportService();
40         HttpServletRequest request = new MockHttpServletRequest();
41         HttpServletResponse response = new MockHttpServletResponse();
42         service.doImportMicroServicePut(request, response);
43         assertEquals("missing", response.getHeader("error"));
44     }
45
46     @Test
47     public void testImportBRMS() {
48         ImportService service = new ImportService();
49         MockHttpServletRequest request = new MockHttpServletRequest();
50         request.setupAddParameter("serviceName", "serviceName");
51         request.setupAddParameter("importService", "BRMSPARAM");
52         request.setBodyContent("foo");
53         HttpServletResponse response = new MockHttpServletResponse();
54         assertThatCode(() -> service.doImportMicroServicePut(request, response)).doesNotThrowAnyException();
55     }
56
57     @Test
58     public void testImportMS() {
59         ImportService service = new ImportService();
60         MockHttpServletRequest request = new MockHttpServletRequest();
61         request.setupAddParameter("serviceName", "serviceName");
62         request.setupAddParameter("importService", "MICROSERVICE");
63         request.setupAddParameter("fileName", "fileName");
64         request.setBodyContent("foo");
65         HttpServletResponse response = new MockHttpServletResponse();
66         assertThatThrownBy(() -> service.doImportMicroServicePut(request, response)).isInstanceOf(Exception.class);
67     }
68
69     @Test
70     public void testImportOpt() {
71         ImportService service = new ImportService();
72         MockHttpServletRequest request = new MockHttpServletRequest();
73         request.setupAddParameter("serviceName", "serviceName");
74         request.setupAddParameter("importService", "OPTIMIZATION");
75         request.setupAddParameter("fileName", "fileName");
76         request.setBodyContent("foo");
77         HttpServletResponse response = new MockHttpServletResponse();
78         assertThatThrownBy(() -> service.doImportMicroServicePut(request, response)).isInstanceOf(Exception.class);
79     }
80
81     @AfterClass
82     public static void tearDown(){
83         try {
84             FileUtils.deleteDirectory(new File("ExtractDir"));
85             } catch (IOException e) {
86                 e.printStackTrace();
87             }
88     }
89 }