Sonar Fixes, Formatting
[aaf/authz.git] / cadi / client / src / test / java / org / onap / aaf / cadi / client / test / JU_AbsTransferSS.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.client.test;
23
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
26 import static org.mockito.Mockito.*;
27 import org.junit.*;
28 import org.mockito.*;
29 import org.onap.aaf.cadi.CadiException;
30 import org.onap.aaf.cadi.client.AbsTransferSS;
31 import org.onap.aaf.cadi.config.SecurityInfoC;
32 import org.onap.aaf.cadi.principal.TaggedPrincipal;
33
34 import java.net.HttpURLConnection;
35
36 public class JU_AbsTransferSS {
37
38     @Mock TaggedPrincipal princMock;
39     @Mock SecurityInfoC<HttpURLConnection> siMock;
40
41     private static final String princName = "name";
42     private static final String princTag = "tag";
43     private static final String app = "app";
44
45     @Before
46     public void setup() {
47         MockitoAnnotations.initMocks(this);
48
49         when(princMock.getName()).thenReturn(princName);
50         when(princMock.tag()).thenReturn(princTag);
51     }
52
53     @Test
54     public void test() {
55         TransferSSStub stub = new TransferSSStub(princMock, app);
56         assertThat(stub.getID(), is(princName));
57         assertThat(stub.getValue(), is(princName + ':' + app + ':' + princTag + ':' + "AS"));
58
59         stub = new TransferSSStub(null, app, siMock);
60         assertThat(stub.getID(), is(""));
61         assertThat(stub.getValue(), is(nullValue()));
62     }
63
64     private class TransferSSStub extends AbsTransferSS<HttpURLConnection> {
65         public TransferSSStub(TaggedPrincipal principal, String app) { super(principal, app); }
66         public TransferSSStub(TaggedPrincipal principal, String app, SecurityInfoC<HttpURLConnection> si) { super(principal, app, si); }
67         @Override public void setSecurity(HttpURLConnection client) throws CadiException { }
68         @Override public int setLastResponse(int respCode) { return 0; }
69         public String getValue() { return value; }
70     }
71
72 }