2 * Copyright (c) 2016, Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openo.nfvo.jujuvnfmadapter.service.rest.fullstack;
20 import java.io.FileInputStream;
21 import java.io.FileNotFoundException;
22 import java.io.IOException;
23 import java.io.InputStream;
25 import org.apache.commons.io.IOUtils;
26 import org.openo.nfvo.jujuvnfmadapter.common.FileUtils;
27 import org.springframework.mock.web.MockHttpServletRequest;
34 * @author quanzhong@huawei.com
35 * @version NFVO 0.5 Nov 3, 2016
37 public class TestHelper {
39 @SuppressWarnings("deprecation")
40 public static MockHttpServletRequest buildMockRequest(File file) throws FileNotFoundException, IOException {
42 String contnet = IOUtils.toString(new FileInputStream(file));
43 byte[] content = contnet.getBytes();
44 MockHttpServletRequest context = new MockHttpServletRequest();
45 context.setContentType("application/json");
46 context.setContent(content);
50 public static MockHttpServletRequest buildMockRequest(String content) throws FileNotFoundException, IOException {
51 MockHttpServletRequest context = new MockHttpServletRequest();
52 context.setContentType("application/json");
53 context.setContent(content.getBytes());
57 public static MockHttpServletRequest buildDefaultRequest(String fileName)
58 throws FileNotFoundException, IOException {
59 MockHttpServletRequest context = new MockHttpServletRequest();
60 context.setContentType("application/json");
61 if(fileName != null) {
62 String file = FileUtils.getClassPath() + File.separator + fileName;
63 InputStream input = new FileInputStream(file);
64 @SuppressWarnings("deprecation")
65 String contnet = IOUtils.toString(input);
66 byte[] content = contnet.getBytes();
67 context.setContent(content);