2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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====================================================
22 package org.onap.aaf.cadi.http.test;
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
26 import static org.mockito.Mockito.*;
28 import java.io.ByteArrayOutputStream;
29 import java.io.PrintStream;
30 import java.net.HttpURLConnection;
32 import java.net.URISyntaxException;
36 import org.onap.aaf.cadi.CadiException;
37 import org.onap.aaf.cadi.Locator;
38 import org.onap.aaf.cadi.Locator.Item;
39 import org.onap.aaf.cadi.LocatorException;
40 import org.onap.aaf.cadi.PropAccess;
41 import org.onap.aaf.cadi.SecuritySetter;
42 import org.onap.aaf.cadi.client.EClient;
43 import org.onap.aaf.cadi.http.HMangr;
44 import org.onap.aaf.cadi.http.HRcli;
46 public class JU_HRcli {
49 SecuritySetter<HttpURLConnection> ssMock;
55 Locator.Item itemMock;
58 private PropAccess access;
59 private static URI uri;
61 private static final String uriString = "example.com";
64 public void setup() throws LocatorException, URISyntaxException {
65 MockitoAnnotations.initMocks(this);
67 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
68 hman = new HMangr(access, locMock);
69 uri = new URI(uriString);
71 when(locMock.get(itemMock)).thenReturn(uri);
74 @Test(expected = CadiException.class)
75 public void publicInterfaceTest() throws URISyntaxException, LocatorException, CadiException {
76 HRcli hrcli = new HRcli(hman, itemMock, ssMock);
77 assertThat(hrcli.setManager(hman), is(hrcli));
78 assertThat(hrcli.toString(), is(uriString));
80 hrcli.setSecuritySetter(ssMock);
81 assertThat(hrcli.getSecuritySetter(), is(ssMock));
86 doThrow(CadiException.class).when(locMock).invalidate(itemMock);
90 @Test(expected = CadiException.class)
91 public void protectedInterfaceTest() throws CadiException, LocatorException {
92 HRcliStub hrcli = new HRcliStub(hman, uri, itemMock, ssMock);
93 HRcli clone = hrcli.clone(uri, ssMock);
94 assertThat(clone.toString(), is(hrcli.toString()));
96 EClient<HttpURLConnection> eclient = hrcli.client();
97 assertThat(eclient, is(not(nullValue())));
99 hrcli = new HRcliStub(hman, null, itemMock, ssMock);
100 when(locMock.best()).thenReturn(itemMock);
101 eclient = hrcli.client();
102 assertThat(eclient, is(not(nullValue())));
104 hrcli = new HRcliStub(hman, null, itemMock, ssMock);
105 when(locMock.best()).thenReturn(null);
106 eclient = hrcli.client();
109 private class HRcliStub extends HRcli {
110 public HRcliStub(HMangr hman, URI uri, Item locItem, SecuritySetter<HttpURLConnection> secSet) {
111 super(hman, uri, locItem, secSet);
113 public HRcli clone(URI uri, SecuritySetter<HttpURLConnection> ss) {
114 return super.clone(uri, ss);
116 public EClient<HttpURLConnection> client() throws CadiException {
117 return super.client();