1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 IBM Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2021 Orange.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 *******************************************************************************/
25 package org.onap.dmaap.mr.client.impl;
27 import org.glassfish.jersey.client.ClientConfig;
28 import org.glassfish.jersey.client.ClientProperties;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.MockitoAnnotations;
35 import javax.ws.rs.client.Invocation.Builder;
36 import javax.ws.rs.client.WebTarget;
37 import javax.ws.rs.core.Response;
38 import java.util.Properties;
40 import static org.junit.Assert.assertEquals;
41 import static org.mockito.Matchers.any;
42 import static org.mockito.Mockito.times;
43 import static org.mockito.Mockito.verify;
45 public class DMaapClientUtilTest {
52 private ClientConfig config = null;
56 MockitoAnnotations.initMocks(this);
60 public void testGetTarget() {
61 WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(), "testpath");
63 assertEquals("testpath", actual.getUri().getPath());
67 public void testGetTargetWithParams() {
68 WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(), "testpath", "testuser", "testpassword");
70 assertEquals("testpath", actual.getUri().getPath());
74 public void testGetResponsewtCambriaAuth() {
75 Mockito.when(target.request()).thenReturn(builder);
76 Mockito.when(builder.header("X-CambriaAuth", "testuser")).thenReturn(builder);
77 Mockito.when(builder.header("X-CambriaDate", "testpassword")).thenReturn(builder);
78 Mockito.when(builder.get()).thenReturn(response);
80 Response actual = DmaapClientUtil.getResponsewtCambriaAuth(target, "testuser", "testpassword");
82 assertEquals(response, actual);
83 verify(target).request();
84 verify(builder, times(2)).header((String) any(), any());
88 public void testSetHttpClientProperties() {
89 Properties properties = new Properties();
90 properties.setProperty(ClientProperties.PROXY_URI, "http://localhost:1234");
91 ClientConfig cConfig = DmaapClientUtil.getClientConfig(properties);
93 assertEquals("ApacheConnectorProvider", cConfig.getConnectorProvider().getClass().getSimpleName());
96 private ClientConfig getClientConfig() {
98 config = DmaapClientUtil.getClientConfig(null);