2 * Copyright 2016-2017, Nokia Corporation
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 com.nokia.vfcadaptor.http.client;
19 import java.io.IOException;
20 import java.io.UnsupportedEncodingException;
21 import java.security.KeyManagementException;
22 import java.security.KeyStoreException;
23 import java.security.NoSuchAlgorithmException;
25 import org.apache.http.client.ClientProtocolException;
26 import org.apache.http.impl.client.HttpClientBuilder;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.http.MediaType;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
34 import org.springframework.test.context.web.WebAppConfiguration;
35 import org.springframework.test.web.servlet.MockMvc;
36 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
37 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
38 import org.springframework.web.bind.annotation.RequestMethod;
39 import org.springframework.web.context.WebApplicationContext;
41 import com.google.gson.Gson;
42 import com.nokia.vfcadaptor.vnfmdriver.bo.InstantiateVnfRequest;
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/mvc-servlet.xml"})
47 public class HttpRequestProcessorTest {
49 private String basicUrl="http://localhost:8080/NvfmDriver/api/nokiavnfm/v1";
50 private String funcPath;
52 private Gson gson = new Gson();
55 private WebApplicationContext wac;
56 private MockMvc mockMvc;
59 this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); //¹¹ÔìMockMvc
65 String message = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}";
66 InstantiateVnfRequest request = gson.fromJson(message, InstantiateVnfRequest.class);
68 System.out.println("vnfInstanceName = " + request.getVnfInstanceName());
72 result = mockMvc.perform(MockMvcRequestBuilders.post("/nokiavnfm/v1/vnfmId_001/vnfs")
73 .contentType(MediaType.APPLICATION_JSON).content(message)
74 .accept(MediaType.APPLICATION_JSON)) //Ö´ÐÐÇëÇó
75 .andReturn().getResponse().getContentAsString();
76 System.out.println("result = " + result);
77 } catch (UnsupportedEncodingException e) {
78 // TODO Auto-generated catch block
80 } catch (Exception e) {
81 // TODO Auto-generated catch block
89 // public void testProcess() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, IOException
91 // funcPath = "/vnfmId_001/vnfs";
92 // url = basicUrl + funcPath;
93 // String message = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}";
95 // HttpClientBuilder httpClientBuilder = HttpClientUtils.createHttpClientBuilder();
96 // HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.POST);
97 // processor.addPostEntity(message);
98 // String result = processor.process(url);
100 // System.out.println(result);
104 // public void testHttps() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, IOException
106 // url = "https://www.baidu.com";
107 // HttpClientBuilder httpClientBuilder = HttpClientUtils.createHttpClientBuilder();
108 // HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
110 // String result = processor.process(url);
112 // System.out.println("The result is :" + result);
115 // public void testHome() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, IOException
117 // url = "http://172.24.208.168/";
118 // HttpClientBuilder httpClientBuilder = HttpClientUtils.createHttpClientBuilder();
119 // HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
121 // String result = processor.process(url);
123 // System.out.println("The result is :" + result);