Keep only clean TestCases, remove 2 license issues
[aaf/authz.git] / auth / auth-deforg / src / test / java / org / onap / aaf / org / test / JU_DefaultOrg.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.*;
25
26 import java.io.File;
27 import java.util.Set;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Matchers;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.aaf.auth.env.AuthzEnv;
36 import org.onap.aaf.auth.env.AuthzTrans;
37 import org.onap.aaf.auth.org.OrganizationException;
38 import org.onap.aaf.org.DefaultOrg;
39 import org.powermock.api.mockito.PowerMockito;
40 import org.powermock.modules.junit4.PowerMockRunner;
41
42 @RunWith(PowerMockRunner.class)
43 public class JU_DefaultOrg {
44
45         DefaultOrg defaultOrg;
46         //private DefaultOrg defaultOrgMock;
47         @Mock
48         AuthzEnv authzEnvMock;
49
50         @Mock
51         AuthzTrans authzTransMock;
52
53         @Mock
54         File fIdentitiesMock;
55
56         private static final String PROPERTY_IS_REQUIRED = " property is Required";
57         private static final String DOMAIN = "osaaf.com";
58         private static final String REALM = "com.osaaf";
59         private static final String NAME = "Default Organization";
60         private static final String NO_PASS = NAME + " does not support Passwords.  Use AAF";
61         String mailHost,mailFromUserId,supportAddress;
62         private String SUFFIX;
63         String s;
64         String defFile;
65
66         //@Before
67         public void setUp() throws OrganizationException{
68                 MockitoAnnotations.initMocks(this);
69                 PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".mailHost"), null)).thenReturn("hello");
70                 PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".supportEmail"), null)).thenReturn("notnull");
71                 PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn("src" + File.separator + "test" + File.separator + "resources" + File.separator + "test.txt");
72                 PowerMockito.when(fIdentitiesMock.exists()).thenReturn(true);
73                 //PowerMockito.when((fIdentitiesMock!=null && fIdentitiesMock.exists())).thenReturn(true);
74                 defaultOrg = new DefaultOrg(authzEnvMock, REALM);
75         }
76
77         //@Test    //(expected=OrganizationException.class)
78         public void test() throws OrganizationException{
79                 //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" ");
80                 //defaultOrg = new DefaultOrg(authzEnvMock);
81                 assertTrue(defaultOrg != null);
82         }
83
84
85         //@Test    //(expected=OrganizationException.class)
86         public void testMultipleCreds() throws OrganizationException{
87                 String id = "test";
88                 //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" ");
89                 //defaultOrg = new DefaultOrg(authzEnvMock);
90                 boolean canHaveMultipleCreds;
91                 canHaveMultipleCreds = defaultOrg.canHaveMultipleCreds(id );
92                 System.out.println("value of canHaveMultipleCreds:  " + canHaveMultipleCreds);
93                 assertTrue(canHaveMultipleCreds);
94         }
95
96
97         //@Test   
98         public void testGetIdentityTypes() throws OrganizationException{
99                 Set<String> identityTypes = defaultOrg.getIdentityTypes();
100                 System.out.println("value of IdentityTypes:  " + identityTypes);
101                 assertTrue(identityTypes.size() == 4);
102         }
103
104
105         //@Test   
106         public void testGetRealm() throws OrganizationException{
107                 String realmTest = defaultOrg.getRealm();
108                 System.out.println("value of realm:  " + realmTest);
109                 assertTrue(realmTest == REALM);
110         }
111
112         //@Test   
113         public void testGetName() throws OrganizationException{
114                 String testName = defaultOrg.getName();
115                 System.out.println("value of name:  " + testName);
116                 assertTrue(testName == NAME);
117         }
118
119
120         //@Test   
121         public void testGetDomain() throws OrganizationException{
122                 String testDomain = defaultOrg.getDomain();
123                 System.out.println("value of domain:  " + testDomain);
124                 assertTrue(testDomain == DOMAIN);
125         }
126
127         // @Test
128         // public void testIsValidID(){ 
129         //      String Result = defaultOrg.isValidID(Matchers.anyString());
130         //      System.out.println("value of res " +Result);
131         //      assertNotNull(Result);  
132         // }
133
134         //@Test
135         public void notYetImplemented() {
136                 fail("Tests in this file should not be trusted");
137         }
138
139 }