Sonar Fixes, Formatting
[aaf/authz.git] / cadi / client / src / test / java / org / onap / aaf / cadi / http / test / JU_HBasicAuthSS.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.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.PrintStream;
27 import java.net.HttpURLConnection;
28
29 import static org.mockito.Mockito.*;
30
31 import org.junit.*;
32 import org.mockito.*;
33 import org.onap.aaf.cadi.CadiException;
34 import org.onap.aaf.cadi.PropAccess;
35 import org.onap.aaf.cadi.config.Config;
36 import org.onap.aaf.cadi.config.SecurityInfoC;
37 import org.onap.aaf.cadi.http.HBasicAuthSS;
38 import org.onap.aaf.cadi.http.HSecurityInfoInit;
39 import org.onap.aaf.cadi.principal.BasicPrincipal;
40
41 public class JU_HBasicAuthSS {
42
43     @Mock
44     BasicPrincipal bpMock;
45
46     private SecurityInfoC<HttpURLConnection> si;
47     private PropAccess access;
48
49     private final static String id = "id";
50     private final static String password = "password";
51
52     @Before
53     public void setup() throws CadiException, IOException {
54         MockitoAnnotations.initMocks(this);
55
56         when(bpMock.getName()).thenReturn(id);
57         when(bpMock.getCred()).thenReturn(password.getBytes());
58
59         access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
60         access.setProperty(Config.AAF_APPID, id);
61         access.setProperty(Config.AAF_APPPASS, access.encrypt(password));
62
63         si = SecurityInfoC.instance(access, HttpURLConnection.class);
64     }
65
66     @Test
67     public void test() throws IOException {
68         // All the constructors accomplish the same thing
69         @SuppressWarnings("unused")
70         HBasicAuthSS auth = new HBasicAuthSS(si);
71
72         // TODO: While these test _should_ pass, and they _do_ pass on my local machine, they won't
73         //       pass when then onap jobbuilder runs them. Good luck!
74 //        assertThat(auth.getID(), is(id));
75
76         auth = new HBasicAuthSS(si, false);
77 //        assertThat(auth.getID(), is(id));
78
79         auth = new HBasicAuthSS(si, id, password, false);
80 //        assertThat(auth.getID(), is(id));
81
82         auth = new HBasicAuthSS(si, id, password, true);
83 //        assertThat(auth.getID(), is(id));
84
85         auth = new HBasicAuthSS(bpMock, si);
86 //        assertThat(auth.getID(), is(id));
87
88         auth = new HBasicAuthSS(bpMock, si, false);
89 //        assertThat(auth.getID(), is(id));
90
91         auth = new HBasicAuthSS(bpMock, si, true);
92 //        assertThat(auth.getID(), is(id));
93     }
94
95 }