/
RoleFactoryImplTest.java
128 lines (110 loc) · 5.54 KB
/
RoleFactoryImplTest.java
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
/*******************************************************************************
* Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.authorization.role.shiro;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.qa.markers.junit.JUnitTests;
import org.eclipse.kapua.service.authorization.role.Role;
import org.eclipse.kapua.service.authorization.role.RoleCreator;
import org.eclipse.kapua.service.authorization.role.RoleQuery;
import org.eclipse.kapua.service.authorization.role.RoleListResult;
import org.eclipse.kapua.service.authorization.role.RolePermission;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
import java.util.Date;
@Category(JUnitTests.class)
public class RoleFactoryImplTest {
RoleFactoryImpl roleFactoryImpl;
KapuaId scopeId;
Role role;
Date createdOn, modifiedOn;
@Before
public void initialize() {
roleFactoryImpl = new RoleFactoryImpl();
scopeId = KapuaId.ONE;
createdOn = new Date();
modifiedOn = new Date();
role = Mockito.mock(Role.class);
Mockito.when(role.getName()).thenReturn("role name");
Mockito.when(role.getDescription()).thenReturn("role description");
Mockito.when(role.getId()).thenReturn(KapuaId.ONE);
Mockito.when(role.getScopeId()).thenReturn(KapuaId.ANY);
Mockito.when(role.getCreatedBy()).thenReturn(KapuaId.ONE);
Mockito.when(role.getCreatedOn()).thenReturn(createdOn);
Mockito.when(role.getModifiedBy()).thenReturn(KapuaId.ANY);
Mockito.when(role.getModifiedOn()).thenReturn(modifiedOn);
Mockito.when(role.getOptlock()).thenReturn(11);
}
@Test
public void newEntityTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newEntity(scopeId) instanceof Role);
Assert.assertEquals("Expected and actual values should be the same.", scopeId, roleFactoryImpl.newEntity(scopeId).getScopeId());
}
@Test
public void newEntityNullTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newEntity(null) instanceof Role);
Assert.assertNull("Null expected.", roleFactoryImpl.newEntity(null).getScopeId());
}
@Test
public void newCreatorTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newCreator(scopeId) instanceof RoleCreator);
Assert.assertEquals("Expected and actual values should be the same.", scopeId, roleFactoryImpl.newCreator(scopeId).getScopeId());
}
@Test
public void newCreatorNullTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newCreator(null) instanceof RoleCreator);
Assert.assertNull("Null expected.", roleFactoryImpl.newCreator(null).getScopeId());
}
@Test
public void newQueryTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newQuery(scopeId) instanceof RoleQuery);
Assert.assertEquals("Expected and actual values should be the same.", scopeId, roleFactoryImpl.newQuery(scopeId).getScopeId());
}
@Test
public void newQueryNullTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newQuery(null) instanceof RoleQuery);
Assert.assertNull("Null expected.", roleFactoryImpl.newQuery(null).getScopeId());
}
@Test
public void newListResultTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newListResult() instanceof RoleListResult);
Assert.assertTrue("True expected.", roleFactoryImpl.newListResult().isEmpty());
}
@Test
public void newRolePermissionTest() {
Assert.assertTrue("True expected.", roleFactoryImpl.newRolePermission() instanceof RolePermission);
}
@Test
public void cloneTest() {
Role resultRole = roleFactoryImpl.clone(role);
Assert.assertEquals("Expected and actual values should be the same.", "role name", resultRole.getName());
Assert.assertEquals("Expected and actual values should be the same.", "role description", resultRole.getDescription());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, resultRole.getId());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ANY, resultRole.getScopeId());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, resultRole.getCreatedBy());
Assert.assertEquals("Expected and actual values should be the same.", createdOn, resultRole.getCreatedOn());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ANY, resultRole.getModifiedBy());
Assert.assertEquals("Expected and actual values should be the same.", modifiedOn, resultRole.getModifiedOn());
Assert.assertEquals("Expected and actual values should be the same.", 11, resultRole.getOptlock());
}
@Test
public void cloneNullTest() {
try {
roleFactoryImpl.clone(null);
} catch (Exception e) {
Assert.assertEquals("Expected and actual values should be the same", "org.eclipse.kapua.KapuaEntityCloneException: Severe error while cloning: role", e.toString());
}
}
}