/
DomainCreatorImplTest.java
93 lines (78 loc) · 3.99 KB
/
DomainCreatorImplTest.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
/*******************************************************************************
* 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.domain.shiro;
import org.eclipse.kapua.model.domain.Actions;
import org.eclipse.kapua.qa.markers.junit.JUnitTests;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.HashSet;
import java.util.Set;
@Category(JUnitTests.class)
public class DomainCreatorImplTest {
@Test
public void domainCreatorImplTest() {
String[] names = {"", " na123)(&*^&NAME <>", "Na-,,..,,Me name ---", "-&^454536 na___,,12 NAME name ", "! 2#@ na meNEMA 2323", "12&^%4 ,,,. '|<>*(", " ,,123name;;'", "12#name--765 ,.aaa!!#$%^<> "};
for (String name : names) {
DomainCreatorImpl domainCreatorImpl = new DomainCreatorImpl(name);
Assert.assertNull("Null expected.", domainCreatorImpl.getScopeId());
Assert.assertEquals("Expected and actual values should be the same.", name, domainCreatorImpl.getName());
Assert.assertNull("Null expected.", domainCreatorImpl.getActions());
Assert.assertFalse("False expected.", domainCreatorImpl.getGroupable());
}
}
@Test
public void domainCreatorImplNullTest() {
DomainCreatorImpl domainCreatorImpl = new DomainCreatorImpl(null);
Assert.assertNull("Null expected.", domainCreatorImpl.getScopeId());
Assert.assertNull("Null expected.", domainCreatorImpl.getName());
Assert.assertNull("Null expected.", domainCreatorImpl.getActions());
Assert.assertFalse("False expected.", domainCreatorImpl.getGroupable());
}
@Test
public void setAndGetNameTest() {
String[] newNames = {"", " na123)(&*^&NAME NEWname <>", "newNa-,,..,,Me name NEW NEW---", "-&^454536 na___,,12 NAME New name ", "! 2#@ na meNewNAME 23NeW23", "12&^%4 ,,,. '|<new name>*(", " ,,123name;;'", "12#name-new-name765 ,.aaa!!#$%^<> "};
DomainCreatorImpl domainCreatorImpl = new DomainCreatorImpl("name");
for (String newName : newNames) {
domainCreatorImpl.setName(newName);
Assert.assertEquals("Expected and actual values should be the same.", newName, domainCreatorImpl.getName());
}
domainCreatorImpl.setName(null);
Assert.assertNull("Null expected.", domainCreatorImpl.getName());
}
@Test
public void setAndGetActionsTest() {
Set<Actions> actions = new HashSet<>();
DomainCreatorImpl domainCreatorImpl = new DomainCreatorImpl("name");
domainCreatorImpl.setActions(actions);
Assert.assertTrue("True expected", domainCreatorImpl.getActions().isEmpty());
actions.add(Actions.read);
actions.add(Actions.delete);
actions.add(Actions.connect);
actions.add(Actions.execute);
actions.add(Actions.write);
domainCreatorImpl.setActions(actions);
Assert.assertEquals("Expected and actual values should be the same.", 5, domainCreatorImpl.getActions().size());
domainCreatorImpl.setActions(null);
Assert.assertNull("Null expected.", domainCreatorImpl.getActions());
}
@Test
public void setAndGetGroupableTest() {
boolean[] groupables = {true, false};
DomainCreatorImpl domainCreatorImpl = new DomainCreatorImpl("name");
for (boolean groupable : groupables) {
domainCreatorImpl.setGroupable(groupable);
Assert.assertEquals("Expected and actual values should be the same.", groupable, domainCreatorImpl.getGroupable());
}
}
}