Few JUnit additions for PAP-REST
[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
27 import com.mockrunner.mock.web.MockHttpServletRequest;
28 import com.mockrunner.mock.web.MockHttpServletResponse;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import org.junit.Test;
32
33 public class ImportServiceTest {
34     @Test
35     public void testNegativeCases() {
36         ImportService service = new ImportService();
37         HttpServletRequest request = new MockHttpServletRequest();
38         HttpServletResponse response = new MockHttpServletResponse();
39         service.doImportMicroServicePut(request, response);
40         assertEquals("missing", response.getHeader("error"));
41     }
42
43     @Test
44     public void testImportBRMS() {
45         ImportService service = new ImportService();
46         MockHttpServletRequest request = new MockHttpServletRequest();
47         request.setupAddParameter("serviceName", "serviceName");
48         request.setupAddParameter("importService", "BRMSPARAM");
49         request.setBodyContent("foo");
50         HttpServletResponse response = new MockHttpServletResponse();
51         assertThatCode(() -> service.doImportMicroServicePut(request, response)).doesNotThrowAnyException();
52     }
53
54     @Test
55     public void testImportMS() {
56         ImportService service = new ImportService();
57         MockHttpServletRequest request = new MockHttpServletRequest();
58         request.setupAddParameter("serviceName", "serviceName");
59         request.setupAddParameter("importService", "MICROSERVICE");
60         request.setupAddParameter("fileName", "fileName");
61         request.setBodyContent("foo");
62         HttpServletResponse response = new MockHttpServletResponse();
63         assertThatThrownBy(() -> service.doImportMicroServicePut(request, response)).isInstanceOf(Exception.class);
64     }
65
66     @Test
67     public void testImportOpt() {
68         ImportService service = new ImportService();
69         MockHttpServletRequest request = new MockHttpServletRequest();
70         request.setupAddParameter("serviceName", "serviceName");
71         request.setupAddParameter("importService", "OPTIMIZATION");
72         request.setupAddParameter("fileName", "fileName");
73         request.setBodyContent("foo");
74         HttpServletResponse response = new MockHttpServletResponse();
75         assertThatThrownBy(() -> service.doImportMicroServicePut(request, response)).isInstanceOf(Exception.class);
76     }
77 }