Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3023ff83fa915745d8aebed288d81ee1c85c9d37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*******************************************************************************
 * Copyright (c) 2012 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ats.core.users;

import java.util.HashMap;
import org.eclipse.osee.ats.api.user.IAtsUser;
import org.eclipse.osee.framework.core.enums.SystemUser;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.junit.Assert;
import org.junit.Test;

/**
 * Test case for {@link SystemUser}<br/>
 * Test case for {@link Anonymous}<br/>
 * Test case for {@link UnAssigned}<br/>
 * Test case for {@link AtsUser}
 *
 * @author Donald G. Dunne
 */
public class CoreAtsUsersTest {

   @Test
   public void testGetDescription() {
      Assert.assertEquals(SystemUser.OseeSystem.getName(), AtsCoreUsers.SYSTEM_USER.getDescription());
      Assert.assertEquals(SystemUser.Anonymous.getName(), AtsCoreUsers.ANONYMOUS_USER.getDescription());
      Assert.assertEquals(SystemUser.UnAssigned.getName(), AtsCoreUsers.UNASSIGNED_USER.getDescription());
   }

   @Test
   public void testIsActive() {
      AtsCoreUsers.SYSTEM_USER.isActive();
      AtsCoreUsers.ANONYMOUS_USER.isActive();
      AtsCoreUsers.UNASSIGNED_USER.isActive();
      new TestUser().isActive();
   }

   @Test
   public void testGetName() {
      Assert.assertEquals(SystemUser.OseeSystem.getName(), AtsCoreUsers.SYSTEM_USER.getName());
      Assert.assertEquals(SystemUser.Anonymous.getName(), AtsCoreUsers.ANONYMOUS_USER.getName());
      Assert.assertEquals(SystemUser.UnAssigned.getName(), AtsCoreUsers.UNASSIGNED_USER.getName());
   }

   @Test
   public void testGetUuid() {
      Assert.assertEquals(SystemUser.OseeSystem.getId(), AtsCoreUsers.SYSTEM_USER.getId());
      Assert.assertEquals(SystemUser.Anonymous.getId(), AtsCoreUsers.ANONYMOUS_USER.getId());
   }

   @Test
   public void testGetUserId() {
      Assert.assertEquals(SystemUser.OseeSystem.getUserId(), AtsCoreUsers.SYSTEM_USER.getUserId());
      Assert.assertEquals(SystemUser.Anonymous.getUserId(), AtsCoreUsers.ANONYMOUS_USER.getUserId());
      Assert.assertEquals(SystemUser.UnAssigned.getUserId(), AtsCoreUsers.UNASSIGNED_USER.getUserId());
   }

   @Test
   public void testSetUserId() {
      TestUser user = new TestUser();
      user.setUserId("asdf");
      Assert.assertEquals("asdf", user.getUserId());
   }

   @Test
   public void testGetEmail() {
      Assert.assertEquals("", AtsCoreUsers.SYSTEM_USER.getEmail());
      Assert.assertEquals("", AtsCoreUsers.ANONYMOUS_USER.getEmail());
      Assert.assertEquals("", AtsCoreUsers.UNASSIGNED_USER.getEmail());
   }

   @Test
   public void testToString() {
      Assert.assertEquals("User [Anonymous - 99999998 - ]", AtsCoreUsers.ANONYMOUS_USER.toString());
   }

   @Test
   public void testHashCode() {
      TestUser user = new TestUser();
      user.setUserId(null);
      Assert.assertEquals(user.hashCode(), 31);
      user.setUserId("99999998");
      Assert.assertEquals(user.hashCode(), 31 * 1 + user.getUserId().hashCode());
   }

   @Test
   public void testEqualsObject() {
      TestUser user = new TestUser();
      user.setUserId("99999999");
      Assert.assertTrue(AtsCoreUsers.SYSTEM_USER.equals(user));
      user.setUserId("234");
      Assert.assertFalse(AtsCoreUsers.SYSTEM_USER.equals(user));
      Assert.assertFalse(AtsCoreUsers.SYSTEM_USER.equals("asfd"));
      Assert.assertFalse(AtsCoreUsers.SYSTEM_USER.equals(null));
      Assert.assertTrue(AtsCoreUsers.SYSTEM_USER.equals(AtsCoreUsers.SYSTEM_USER));
      user.setUserId(null);
      Assert.assertFalse(user.equals(AtsCoreUsers.SYSTEM_USER));

      TestUser user2 = new TestUser();
      user2.setUserId(null);
      Assert.assertTrue(user.equals(user2));
   }

   @org.junit.Test
   public void testHashCorrectness() {
      TestUser user = new TestUser();
      user.setUserId("234");

      TestUser user1 = new TestUser();
      user1.setUserId("234");

      TestUser user2 = new TestUser();
      user2.setUserId(SystemUser.OseeSystem.getUserId());

      IAtsUser mapToPi = AtsCoreUsers.SYSTEM_USER;
      IAtsUser alsoMapToPi = user2;

      IAtsUser mapToE = user1;
      IAtsUser alsoMapToE = user1;

      HashMap<IAtsUser, Double> hash = new HashMap<>();
      hash.put(mapToPi, Math.PI);
      hash.put(mapToE, Math.E);

      Assert.assertTrue(hash.get(mapToPi).equals(Math.PI));
      Assert.assertTrue(hash.get(mapToE).equals(Math.E));
      Assert.assertTrue(hash.get(alsoMapToPi).equals(Math.PI));
      Assert.assertTrue(hash.get(alsoMapToE).equals(Math.E));
      Assert.assertFalse(hash.get(mapToPi).equals(Math.E));
      Assert.assertFalse(hash.get(mapToE).equals(Math.PI));
      Assert.assertFalse(mapToPi.equals(mapToE));
      Assert.assertTrue(mapToPi.equals(mapToPi));
   }

   @Test
   public void testEqualsObjectWithException() {
      TestUser user2 = new TestUser();
      user2.setUserId(null);
      ExceptionUser exceptionUser = new ExceptionUser();
      Assert.assertFalse(user2.equals(exceptionUser));
   }

   private class TestUser extends AtsUser {
      public TestUser() {
         super(999994L, "Test User", "999994");
      }
   };

   private class ExceptionUser extends AtsUser {
      public ExceptionUser() {
         super(0L, "Exception User", null);
      }

      @Override
      public String getUserId() throws OseeCoreException {
         throw new OseeStateException("this is the exception under test");
      }
   };
}

Back to the top