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