Sonar Fixes, Formatting
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / org / test / JU_Organization.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.auth.org.test;
24
25 import static org.mockito.Mockito.mock;
26
27 import java.util.ArrayList;
28 import java.util.GregorianCalendar;
29 import java.util.HashSet;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.aaf.auth.env.AuthzTrans;
34 import org.onap.aaf.auth.org.EmailWarnings;
35 import org.onap.aaf.auth.org.Organization;
36 import org.onap.aaf.auth.org.Organization.Expiration;
37 import org.onap.aaf.auth.org.Organization.Identity;
38 import org.onap.aaf.auth.org.Organization.Notify;
39 import org.onap.aaf.auth.org.Organization.Policy;
40 import org.onap.aaf.auth.org.Organization.Response;
41 import org.onap.aaf.auth.org.OrganizationException;
42
43 import junit.framework.Assert;
44
45 public class JU_Organization {
46
47     AuthzTrans trans;
48     GregorianCalendar gc;
49     @Before
50     public void setUp() {
51         gc = new GregorianCalendar(1900, 1, 1);
52         trans = mock(AuthzTrans.class);
53     }
54
55     @Test
56     public void test() throws OrganizationException {
57         //tests for Org null
58         Assert.assertEquals("n/a",Organization.NULL.getName());
59         Assert.assertEquals("n/a",Organization.NULL.getDomain());
60         Assert.assertEquals("n/a",Organization.NULL.getRealm());
61         Assert.assertTrue(Organization.NULL.getIdentity(trans, "test") instanceof Identity);
62         Assert.assertEquals("n/a",Organization.NULL.isValidID(trans, null));
63         Assert.assertEquals("n/a",Organization.NULL.isValidPassword(trans, null, null, null));
64         Assert.assertTrue(Organization.NULL.getIdentityTypes() instanceof HashSet);
65         Assert.assertTrue(Organization.NULL.notify(trans, Notify.PasswordExpiration, null, null, null, null, null) instanceof Response);
66         Assert.assertEquals(0,Organization.NULL.sendEmail(trans, null, null, null, null, null));
67         Assert.assertEquals(gc.getTime(),Organization.NULL.whenToValidate(null, null));
68         Assert.assertEquals(gc,Organization.NULL.expiration(gc, Expiration.Password));
69         Assert.assertTrue(Organization.NULL.getApprovers(trans, null) instanceof ArrayList);
70         Assert.assertEquals("",Organization.NULL.getApproverType());
71         Assert.assertEquals(0,Organization.NULL.startOfDay());
72         Assert.assertFalse(Organization.NULL.canHaveMultipleCreds(null));
73         Assert.assertFalse(Organization.NULL.isValidCred(trans, null));
74         Assert.assertEquals("Null Organization rejects all Policies",Organization.NULL.validate(trans, Policy.CHANGE_JOB, null, null));
75         Assert.assertFalse(Organization.NULL.isTestEnv());
76         Organization.NULL.setTestMode(true);
77
78         //tests for org emailWarnings
79         Assert.assertTrue(Organization.NULL.emailWarningPolicy() instanceof EmailWarnings);
80         Assert.assertEquals(604800000L, Organization.NULL.emailWarningPolicy().credEmailInterval());
81         Assert.assertEquals(604800000L, Organization.NULL.emailWarningPolicy().roleEmailInterval());
82         Assert.assertEquals(259200000L, Organization.NULL.emailWarningPolicy().apprEmailInterval());
83         Assert.assertEquals(2592000000L, Organization.NULL.emailWarningPolicy().credExpirationWarning());
84         Assert.assertEquals(2592000000L, Organization.NULL.emailWarningPolicy().roleExpirationWarning());
85         Assert.assertEquals(1209600000L, Organization.NULL.emailWarningPolicy().emailUrgentWarning());
86         Assert.assertTrue(Organization.NULL.getPasswordRules() instanceof String[]);
87
88     }
89 }