1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.osaaf.defOrg;
\r
25 import static org.junit.Assert.assertNotNull;
\r
26 import static org.junit.Assert.assertTrue;
\r
28 import java.io.File;
\r
29 import java.util.Set;
\r
31 import org.junit.Before;
\r
32 import org.junit.Test;
\r
33 import org.junit.runner.RunWith;
\r
34 import org.mockito.Matchers;
\r
35 import org.mockito.Mock;
\r
36 import org.mockito.MockitoAnnotations;
\r
37 import org.onap.aaf.authz.env.AuthzEnv;
\r
38 import org.onap.aaf.authz.env.AuthzTrans;
\r
39 import org.onap.aaf.authz.org.OrganizationException;
\r
40 import org.powermock.api.mockito.PowerMockito;
\r
41 import org.powermock.modules.junit4.PowerMockRunner;
\r
43 @RunWith(PowerMockRunner.class)
\r
44 public class JU_DefaultOrg {
\r
46 DefaultOrg defaultOrg;
\r
47 //private DefaultOrg defaultOrgMock;
\r
49 AuthzEnv authzEnvMock;
\r
51 private static final String PROPERTY_IS_REQUIRED = " property is Required";
\r
52 private static final String DOMAIN = "osaaf.com";
\r
53 private static final String REALM = "com.osaaf";
\r
54 private static final String NAME = "Default Organization";
\r
55 private static final String NO_PASS = NAME + " does not support Passwords. Use AAF";
\r
56 String mailHost,mailFromUserId,supportAddress;
\r
57 private String SUFFIX;
\r
61 File fIdentitiesMock;
\r
65 public void setUp() throws OrganizationException{
\r
66 MockitoAnnotations.initMocks(this);
\r
67 PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".mailHost"), null)).thenReturn("hello");
\r
68 PowerMockito.when(authzEnvMock.getProperty(s=(REALM + ".supportEmail"), null)).thenReturn("notnull");
\r
69 PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn("src" + File.separator + "test" + File.separator + "resources" + File.separator + "test.txt");
\r
70 PowerMockito.when(fIdentitiesMock.exists()).thenReturn(true);
\r
71 //PowerMockito.when((fIdentitiesMock!=null && fIdentitiesMock.exists())).thenReturn(true);
\r
72 defaultOrg = new DefaultOrg(authzEnvMock);
\r
75 @Test //(expected=OrganizationException.class)
\r
76 public void test() throws OrganizationException{
\r
77 //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" ");
\r
78 //defaultOrg = new DefaultOrg(authzEnvMock);
\r
79 assertTrue(defaultOrg != null);
\r
83 @Test //(expected=OrganizationException.class)
\r
84 public void testMultipleCreds() throws OrganizationException{
\r
86 //PowerMockito.when(authzEnvMock.getProperty(Matchers.anyString())).thenReturn(" ");
\r
87 //defaultOrg = new DefaultOrg(authzEnvMock);
\r
88 boolean canHaveMultipleCreds;
\r
89 canHaveMultipleCreds = defaultOrg.canHaveMultipleCreds(id );
\r
90 System.out.println("value of canHaveMultipleCreds: " + canHaveMultipleCreds);
\r
91 assertTrue(canHaveMultipleCreds);
\r
96 public void testGetIdentityTypes() throws OrganizationException{
\r
97 Set<String> identityTypes = defaultOrg.getIdentityTypes();
\r
98 System.out.println("value of IdentityTypes: " + identityTypes);
\r
99 assertTrue(identityTypes.size() == 4);
\r
104 public void testGetRealm() throws OrganizationException{
\r
105 String realmTest = defaultOrg.getRealm();
\r
106 System.out.println("value of realm: " + realmTest);
\r
107 assertTrue(realmTest == REALM);
\r
111 public void testGetName() throws OrganizationException{
\r
112 String testName = defaultOrg.getName();
\r
113 System.out.println("value of name: " + testName);
\r
114 assertTrue(testName == NAME);
\r
119 public void testGetDomain() throws OrganizationException{
\r
120 String testDomain = defaultOrg.getDomain();
\r
121 System.out.println("value of domain: " + testDomain);
\r
122 assertTrue(testDomain == DOMAIN);
\r
128 public void testIsValidID(){
\r
129 String Result = defaultOrg.isValidID(Matchers.anyString());
\r
130 System.out.println("value of res " +Result);
\r
131 assertNotNull(Result);
\r
135 AuthzTrans authzTransMock;
\r