Sonar Fixes, Formatting
[aaf/authz.git] / auth / auth-deforg / src / test / java / org / onap / aaf / org / test / JU_DefaultOrgIdentity.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 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
23 package org.onap.aaf.org.test;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.aaf.auth.env.AuthzTrans;
34 import org.onap.aaf.auth.local.AbsData.Reuse;
35 import org.onap.aaf.auth.org.OrganizationException;
36 import org.onap.aaf.org.DefaultOrg;
37 import org.onap.aaf.org.DefaultOrgIdentity;
38 import org.onap.aaf.org.Identities;
39 import org.onap.aaf.org.Identities.Data;
40 import org.powermock.api.mockito.PowerMockito;
41 import org.powermock.modules.junit4.PowerMockRunner;
42 import static org.mockito.Mockito.*;
43 import java.io.IOException;
44
45 @RunWith(PowerMockRunner.class)
46 public class JU_DefaultOrgIdentity {
47
48     private DefaultOrg defaultOrgMock;
49
50     @Mock
51     private Reuse rMock;
52
53     @Mock
54     AuthzTrans authzTransMock;
55
56     @Mock
57     private Data dataMock;
58
59     @Mock
60     private DefaultOrgIdentity defaultOrgIdentity;
61
62     static String key = "iowna@deforg";
63     static String orgDomain = "@deforg";
64
65     @Before
66     public void setUp() throws IOException, OrganizationException {
67         MockitoAnnotations.initMocks(this);
68         defaultOrgMock = PowerMockito.mock(DefaultOrg.class);
69         defaultOrgMock.identities = mock(Identities.class);
70
71
72         authzTransMock = PowerMockito.mock(AuthzTrans.class);
73
74         when(defaultOrgMock.getDomain()).thenReturn(orgDomain);
75         when(defaultOrgMock.identities.reuse()).thenReturn(rMock);
76         when(defaultOrgMock.identities.find(eq(key),any(Reuse.class))).thenReturn(dataMock);
77
78         defaultOrgIdentity = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
79
80     }
81
82
83     @Test
84     public void testIdentify_returnIdentifiedEntity()  {
85
86         assertTrue(defaultOrgIdentity.id() != null);
87
88     }
89
90     @Test
91     public void testIdentify_returnIdentifiedEntityWithDataNull() throws IOException, OrganizationException {
92
93         when(defaultOrgMock.identities.find(eq(key),any(Reuse.class))).thenReturn(null);
94
95         DefaultOrgIdentity defaultOrgIdentityDataNull = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
96         assertTrue(defaultOrgIdentityDataNull.id() != null);
97
98     }
99
100     @Test(expected = OrganizationException.class)
101     public void testIdentify_returnThrowIOException() throws OrganizationException {
102
103         when(defaultOrgMock.getDomain()).thenReturn(orgDomain);
104         when(defaultOrgMock.identities.reuse()).thenThrow(IOException.class);
105         DefaultOrgIdentity defaultOrgIdentityException = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
106
107     }
108
109
110     @Test
111     public void testEquals_returnTrue() {
112
113         Object b = defaultOrgIdentity;
114         assertTrue(defaultOrgIdentity.equals(b) == true );
115     }
116
117     @Test
118     public void testStatus_returnUnknown() {
119
120         assertEquals(defaultOrgIdentity.type(), "Unknown");
121
122     }
123
124     @Test
125     public void testHash_returnHashCode() {
126
127         assertTrue(defaultOrgIdentity.hashCode() != 0 );
128
129     }
130
131     @Test
132     public void testFullId_returnFullId() throws IOException, OrganizationException{
133         String key="toto@deforg";
134         String orgDomain="@deforg";
135         when(defaultOrgMock.getDomain()).thenReturn(orgDomain);
136         when(defaultOrgMock.identities.reuse()).thenReturn(rMock);
137         when(defaultOrgMock.identities.find(eq(key),any(Reuse.class))).thenReturn(dataMock);
138         defaultOrgIdentity = new DefaultOrgIdentity(authzTransMock, key, defaultOrgMock);
139
140         assertTrue(defaultOrgIdentity.fullID().contains("@") );
141     }
142
143     @Test
144     public void testEmail_returnEmail() {
145
146         assertTrue(defaultOrgIdentity.email() != null  );
147     }
148
149
150     @Test
151     public void testFullName_returnFullName() {
152
153         assertTrue(defaultOrgIdentity.fullName() != null );
154     }
155
156
157     @Test
158     public void testFirstName_returnFirstName() {
159
160         assertTrue(defaultOrgIdentity.firstName() != null );
161     }
162
163
164
165
166 }