fcb25d4edf060226fa2650ffa3b1bc0d899228a9
[aaf/authz.git] / cadi / client / src / test / java / org / onap / aaf / cadi / http / test / JU_HTransferSS.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.cadi.http.test;
23
24 import java.io.IOException;
25 import java.net.HttpURLConnection;
26
27 import javax.net.ssl.HttpsURLConnection;
28
29 import static org.junit.Assert.*;
30 import static org.mockito.Mockito.*;
31 import static org.hamcrest.CoreMatchers.*;
32
33 import org.junit.*;
34 import org.mockito.*;
35
36 import org.onap.aaf.cadi.CadiException;
37 import org.onap.aaf.cadi.SecuritySetter;
38 import org.onap.aaf.cadi.config.SecurityInfoC;
39
40 import org.onap.aaf.cadi.http.HTransferSS;
41 import org.onap.aaf.cadi.principal.TaggedPrincipal;
42
43 public class JU_HTransferSS {
44         
45         @Mock
46         TaggedPrincipal princMock;
47         
48         @Mock
49         HttpURLConnection hucMock;
50
51         @Mock
52         HttpsURLConnection hucsMock;
53
54         @Mock
55         SecurityInfoC<HttpURLConnection> siMock;
56         
57         @Mock
58         SecurityInfoC<HttpURLConnection> siMockNoDefSS;
59
60         @Mock
61         SecuritySetter<HttpURLConnection> ssMock;
62         
63         private static final String princName = "name";
64         
65         @Before
66         public void setup() {
67                 MockitoAnnotations.initMocks(this);
68                 when(princMock.getName()).thenReturn(princName);
69                 siMock.defSS = ssMock;
70         }
71
72         @Test
73         public void test() throws IOException, CadiException {
74                 HTransferSS transfer = new HTransferSS(princMock, "string1");
75                 assertThat(transfer.setLastResponse(0), is(0));
76                 
77                 transfer = new HTransferSS(princMock, "string1", siMock);
78                 transfer.setSecurity(hucsMock);
79                 assertThat(transfer.getID(), is(princName));
80
81                 transfer = new HTransferSS(null, "string1", siMock);
82                 transfer.setSecurity(hucsMock);
83                 assertThat(transfer.getID(), is(""));
84         }
85
86         @Test(expected = CadiException.class)
87         public void testThrows() throws CadiException {
88                 HTransferSS transfer = new HTransferSS(princMock, "string1", siMockNoDefSS);
89                 transfer.setSecurity(hucMock);
90         }
91
92 }