2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.pap.xacml.rest.service;
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;
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;
36 public class ImportServiceTest {
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"));
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();
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);
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);
82 public static void tearDown(){
84 FileUtils.deleteDirectory(new File("ExtractDir"));
85 } catch (IOException e) {