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 java.io.IOException;
25 import java.net.HttpURLConnection;
27 import javax.net.ssl.HttpsURLConnection;
29 import static org.junit.Assert.*;
30 import static org.mockito.Mockito.*;
31 import static org.hamcrest.CoreMatchers.*;
36 import org.onap.aaf.cadi.CadiException;
37 import org.onap.aaf.cadi.SecuritySetter;
38 import org.onap.aaf.cadi.config.SecurityInfoC;
40 import org.onap.aaf.cadi.http.HTransferSS;
41 import org.onap.aaf.cadi.principal.TaggedPrincipal;
43 public class JU_HTransferSS {
46 TaggedPrincipal princMock;
49 HttpURLConnection hucMock;
52 HttpsURLConnection hucsMock;
55 SecurityInfoC<HttpURLConnection> siMock;
58 SecurityInfoC<HttpURLConnection> siMockNoDefSS;
61 SecuritySetter<HttpURLConnection> ssMock;
63 private static final String princName = "name";
67 MockitoAnnotations.initMocks(this);
68 when(princMock.getName()).thenReturn(princName);
69 siMock.defSS = ssMock;
73 public void test() throws IOException, CadiException {
74 HTransferSS transfer = new HTransferSS(princMock, "string1");
75 assertThat(transfer.setLastResponse(0), is(0));
77 transfer = new HTransferSS(princMock, "string1", siMock);
78 transfer.setSecurity(hucsMock);
79 assertThat(transfer.getID(), is(princName));
81 transfer = new HTransferSS(null, "string1", siMock);
82 transfer.setSecurity(hucsMock);
83 assertThat(transfer.getID(), is(""));
86 @Test(expected = CadiException.class)
87 public void testThrows() throws CadiException {
88 HTransferSS transfer = new HTransferSS(princMock, "string1", siMockNoDefSS);
89 transfer.setSecurity(hucMock);