2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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=========================================================
20 package com.onap.sdnc.vnfbackupservice.scheduler;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
25 import org.junit.Test;
26 import org.springframework.http.HttpEntity;
27 import org.springframework.http.HttpMethod;
28 import org.springframework.http.HttpStatus;
29 import org.springframework.http.ResponseEntity;
30 import org.springframework.web.client.RestClientException;
31 import org.springframework.web.client.RestTemplate;
37 public class VnfRestClientTest {
39 String url = "/restconf/config/VNF-API:vnfs";
40 String userName = "abc";
41 String password = "abc";
44 public void restClientTest() {
46 new MockUp<RestTemplate>() {
47 @SuppressWarnings("unchecked")
49 public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
50 Class<T> responseType, Object... uriVariables) throws RestClientException {
51 ResponseEntity<String> str = new ResponseEntity<String>(HttpStatus.ACCEPTED);
52 return (ResponseEntity<T>) str;
55 VnfRestClient vnfRestClientmock = mock(VnfRestClient.class);
56 when(vnfRestClientmock.vnfRestClient(url, userName, password)).thenReturn("successfully mocked");
58 VnfRestClient vnfRestClient =new VnfRestClient();
59 vnfRestClient.vnfRestClient(url, userName, password);