/
GroupFactoryImplTest.java
145 lines (126 loc) · 6.21 KB
/
GroupFactoryImplTest.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
* 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.group.shiro;
import org.eclipse.kapua.KapuaEntityCloneException;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.qa.markers.junit.JUnitTests;
import org.eclipse.kapua.service.authorization.group.Group;
import org.eclipse.kapua.service.authorization.group.GroupCreator;
import org.eclipse.kapua.service.authorization.group.GroupListResult;
import org.eclipse.kapua.service.authorization.group.GroupQuery;
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 GroupFactoryImplTest {
GroupFactoryImpl groupFactoryImpl;
KapuaId scopeId;
String[] names;
Group group;
Date createdOn, modifiedOn;
@Before
public void initialize() {
groupFactoryImpl = new GroupFactoryImpl();
scopeId = KapuaId.ONE;
names = new String[]{"", " na123)(&*^&NAME <>", "Na-,,..,,Me name ---", "-&^454536 na___,,12 NAME name ", "! 2#@ na meNEMA 2323", "12&^%4 ,,,. '|<>*(", " ,,123name;;'", "12#name--765 ,.aaa!!#$%^<> "};
group = Mockito.mock(Group.class);
createdOn = new Date();
modifiedOn = new Date();
Mockito.when(group.getName()).thenReturn("group name");
Mockito.when(group.getDescription()).thenReturn("description");
Mockito.when(group.getId()).thenReturn(KapuaId.ONE);
Mockito.when(group.getScopeId()).thenReturn(KapuaId.ANY);
Mockito.when(group.getCreatedBy()).thenReturn(KapuaId.ONE);
Mockito.when(group.getCreatedOn()).thenReturn(createdOn);
Mockito.when(group.getModifiedBy()).thenReturn(KapuaId.ANY);
Mockito.when(group.getModifiedOn()).thenReturn(modifiedOn);
Mockito.when(group.getOptlock()).thenReturn(11);
}
@Test
public void newCreatorScopeIdNameParametersTest() {
for (String name : names) {
GroupCreator groupCreator = groupFactoryImpl.newCreator(scopeId, name);
Assert.assertEquals("Expected and actual values should be the same.", name, groupCreator.getName());
Assert.assertEquals("Expected and actual values should be the same.", scopeId, groupCreator.getScopeId());
}
}
@Test
public void newCreatorNullScopeIdNameParametersTest() {
for (String name : names) {
GroupCreator groupCreator = groupFactoryImpl.newCreator(null, name);
Assert.assertEquals("Expected and actual values should be the same.", name, groupCreator.getName());
Assert.assertNull("Null expected.", groupCreator.getScopeId());
}
}
@Test
public void newCreatorScopeIdNullNameParametersTest() {
GroupCreator groupCreator = groupFactoryImpl.newCreator(scopeId, null);
Assert.assertNull("Null expected.", groupCreator.getName());
Assert.assertEquals("Expected and actual values should be the same.", scopeId, groupCreator.getScopeId());
}
@Test
public void newEntityTest() {
Group group = groupFactoryImpl.newEntity(scopeId);
Assert.assertEquals("Expected and actual values should be the same.", scopeId, group.getScopeId());
}
@Test
public void newEntityNullTest() {
Group group = groupFactoryImpl.newEntity(null);
Assert.assertNull("Null expected.", group.getScopeId());
}
@Test
public void newListResultTest() {
GroupListResult groupListResult = groupFactoryImpl.newListResult();
Assert.assertTrue("True expected.", groupListResult.isEmpty());
}
@Test
public void newQueryTest() {
GroupQuery groupQuery = groupFactoryImpl.newQuery(scopeId);
Assert.assertEquals("Expected and actual values should be the same.", scopeId, groupQuery.getScopeId());
}
@Test
public void newQueryNullTest() {
GroupQuery groupQuery = groupFactoryImpl.newQuery(null);
Assert.assertNull("Null expected.", groupQuery.getScopeId());
}
@Test
public void newCreatorTest() {
GroupCreator groupCreator = groupFactoryImpl.newCreator(scopeId);
Assert.assertEquals("Expected and actual values should be the same.", scopeId, groupCreator.getScopeId());
}
@Test
public void newCreatorNullTest() {
GroupCreator groupCreator = groupFactoryImpl.newCreator(null);
Assert.assertNull("Null expected.", groupCreator.getScopeId());
}
@Test
public void cloneTest() {
Group resultGroup = groupFactoryImpl.clone(group);
Assert.assertEquals("Expected and actual values should be the same.", "group name", resultGroup.getName());
Assert.assertEquals("Expected and actual values should be the same.", "description", resultGroup.getDescription());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, resultGroup.getId());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ANY, resultGroup.getScopeId());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ONE, resultGroup.getCreatedBy());
Assert.assertEquals("Expected and actual values should be the same.", createdOn, resultGroup.getCreatedOn());
Assert.assertEquals("Expected and actual values should be the same.", KapuaId.ANY, resultGroup.getModifiedBy());
Assert.assertEquals("Expected and actual values should be the same.", modifiedOn, resultGroup.getModifiedOn());
Assert.assertEquals("Expected and actual values should be the same.", 11, resultGroup.getOptlock());
}
@Test(expected = KapuaEntityCloneException.class)
public void cloneNullTest() {
groupFactoryImpl.clone(null);
}
}