2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 huawei. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.examples.bbs;
23 import java.io.ByteArrayInputStream;
24 import java.io.InputStream;
25 import javax.net.ssl.HttpsURLConnection;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mockito;
29 import static org.junit.Assert.*;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
33 public class WebClientTest {
34 HttpsURLConnection mockedHttpsURLConnection;
35 String sampleString = "Response Code :200";
37 * Set up the mocked REST manager.
40 public void setupMockedRest() {
41 mockedHttpsURLConnection = mock(HttpsURLConnection.class);
42 InputStream iStream = new ByteArrayInputStream(sampleString.getBytes());
44 when(mockedHttpsURLConnection.getInputStream()).thenReturn(iStream);
45 Mockito.doNothing().when(mockedHttpsURLConnection).connect();
46 }catch (Exception e) {
52 public void httpsRequest() {
53 WebClient cl = new WebClient();
54 String result = cl.httpsRequest("https://some.random.url/data", "POST", null,
55 "admin", "admin", "application/json",true, true);
60 public void httpRequest() {
61 WebClient cl = new WebClient();
62 String result = cl.httpRequest("http://some.random.url/data", "GET", null,
63 "admin", "admin", "application/json",true, true);
68 public void toPrettyString() {
69 String xmlSample = "<input xmlns=\"org:onap:sdnc:northbound:generic-resource\">" +
70 "<sdnc-request-header> <svc-action>update</svc-action> </sdnc-request-header></input>";
71 WebClient cl = new WebClient();
72 cl.toPrettyString(xmlSample, 4);