Skip to content

Commit b92a97d

Browse files
committed
Adds more test coverage
Signed-off-by: Patrick Reinhart <patrick@reini.net>
1 parent 29fe721 commit b92a97d

File tree

9 files changed

+426
-16
lines changed

9 files changed

+426
-16
lines changed

src/main/java/org/xmldb/api/base/ResourceType.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,22 @@ private ResourceType(String name) {
5353
this.name = name;
5454
}
5555

56+
/**
57+
* Returns the old style resource type name from XML:DB API version 1.0 constant.
58+
*
59+
* @return the classic type name
60+
*/
61+
public String typeName() {
62+
return name;
63+
}
64+
65+
/**
66+
* Returns the old style resource type name from XML:DB API version 1.0 constant.
67+
*
68+
* @return the classic type name
69+
*/
5670
@Override
5771
public String toString() {
58-
return name;
72+
return typeName();
5973
}
6074
}

src/main/java/org/xmldb/api/security/AclEntry.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import java.util.Collections;
4747
import java.util.EnumSet;
48+
import java.util.Objects;
4849
import java.util.Set;
4950

5051
/**
@@ -89,11 +90,10 @@ public static final class Builder {
8990

9091
private Builder(AclEntryType type, UserPrincipal principal, Set<AclEntryPermission> permissions,
9192
Set<AclEntryFlag> flags) {
92-
assert permissions != null && flags != null;
9393
this.type = type;
9494
this.principal = principal;
95-
this.permissions = permissions;
96-
this.flags = flags;
95+
this.permissions = Objects.requireNonNull(permissions);
96+
this.flags = Objects.requireNonNull(flags);
9797
}
9898

9999
/**
@@ -119,9 +119,7 @@ public AclEntry build() {
119119
* @return this builder
120120
*/
121121
public Builder setType(AclEntryType type) {
122-
if (type == null)
123-
throw new NullPointerException();
124-
this.type = type;
122+
this.type = Objects.requireNonNull(type);
125123
return this;
126124
}
127125

@@ -132,18 +130,14 @@ public Builder setType(AclEntryType type) {
132130
* @return this builder
133131
*/
134132
public Builder setPrincipal(UserPrincipal principal) {
135-
if (principal == null)
136-
throw new NullPointerException();
137-
this.principal = principal;
133+
this.principal = Objects.requireNonNull(principal);
138134
return this;
139135
}
140136

141137
// check set only contains elements of the given type
142138
private static void checkSet(Set<?> set, Class<?> type) {
143139
for (Object e : set) {
144-
if (e == null) {
145-
throw new NullPointerException();
146-
} else if (!type.isInstance(e)) {
140+
if (!type.isInstance(e)) {
147141
throw new IllegalArgumentException(
148142
e.getClass().getName() + " is not an instance of " + type.getName());
149143
}
@@ -210,7 +204,6 @@ public Builder setFlags(Set<AclEntryFlag> flags) {
210204
flags = EnumSet.copyOf(flags);
211205
checkSet(flags, AclEntryFlag.class);
212206
}
213-
214207
this.flags = flags;
215208
return this;
216209
}
@@ -332,6 +325,6 @@ public int hashCode() {
332325
*/
333326
@Override
334327
public String toString() {
335-
return format("%s(%s)", super.toString(), principal);
328+
return format("%s(%s)", getClass().getName(), principal);
336329
}
337330
}

src/main/java/org/xmldb/api/security/AclEntryFlag.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,28 @@
4545
* @since 2.0
4646
*/
4747
public enum AclEntryFlag {
48+
/**
49+
* Can be placed on a collection and indicates that the ACL entry should be added to each new
50+
* resource created.
51+
*/
52+
RESOURCE_INHERIT,
53+
54+
/**
55+
* Can be placed on a collection and indicates that the ACL entry should be added to each new
56+
* collection created.
57+
*/
58+
COLLECTION_INHERIT,
59+
60+
/**
61+
* Can be placed on a collection to indicate that the ACL entry should not be placed on the newly
62+
* created collection which is inheritable by sub collections of the created collection.
63+
*/
64+
NO_PROPAGATE_INHERIT,
65+
66+
/**
67+
* Can be placed on a collection but does not apply to the collection, only to newly created
68+
* resources/collections as specified by the {@link #RESOURCE_INHERIT} and
69+
* {@link #COLLECTION_INHERIT} flags.
70+
*/
71+
INHERIT_ONLY;
4872
}

src/main/java/org/xmldb/api/security/AclEntryPermission.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
*/
4040
package org.xmldb.api.security;
4141

42+
/**
43+
* A typesafe enumeration of the access entry permission types.
44+
*
45+
* @since 2.0
46+
*/
4247
public enum AclEntryPermission {
43-
READ, WRITE, EXECUTE;
48+
/**
49+
* Permission to read the data of the collection / resource.
50+
*/
51+
READ,
52+
/**
53+
* Permission to modify the collection / resource data.
54+
*/
55+
WRITE,
56+
/**
57+
* Permission to list a execute a resource.
58+
*/
59+
EXECUTE;
4460
}

src/test/java/org/xmldb/api/base/ResourceTypeTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ void testValidValues() {
5353

5454
@Test
5555
void testToString() {
56+
assertThat(BINARY_RESOURCE.typeName()).isEqualTo("BinaryResource");
5657
assertThat(BINARY_RESOURCE).hasToString("BinaryResource");
58+
assertThat(XML_RESOURCE.typeName()).isEqualTo("XMLResource");
5759
assertThat(XML_RESOURCE).hasToString("XMLResource");
5860
}
5961
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* The XML:DB Initiative Software License, Version 1.0
3+
*
4+
* Copyright (c) 2000-2022 The XML:DB Initiative. All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification, are permitted
7+
* provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
10+
* and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
* conditions and the following disclaimer in the documentation and/or other materials provided with
14+
* the distribution.
15+
*
16+
* 3. The end-user documentation included with the redistribution, if any, must include the
17+
* following acknowledgment: "This product includes software developed by the XML:DB Initiative
18+
* (http://www.xmldb.org/)." Alternately, this acknowledgment may appear in the software itself, if
19+
* and wherever such third-party acknowledgments normally appear.
20+
*
21+
* 4. The name "XML:DB Initiative" must not be used to endorse or promote products derived from this
22+
* software without prior written permission. For written permission, please contact info@xmldb.org.
23+
*
24+
* 5. Products derived from this software may not be called "XML:DB", nor may "XML:DB" appear in
25+
* their name, without prior written permission of the XML:DB Initiative.
26+
*
27+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29+
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR
30+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
* =================================================================================================
36+
* This software consists of voluntary contributions made by many individuals on behalf of the
37+
* XML:DB Initiative. For more information on the XML:DB Initiative, please see
38+
* <https://github.com/xmldb-org/>
39+
*/
40+
package org.xmldb.api.security;
41+
42+
import static org.assertj.core.api.Assertions.assertThat;
43+
import static org.xmldb.api.security.AclEntryFlag.COLLECTION_INHERIT;
44+
import static org.xmldb.api.security.AclEntryFlag.INHERIT_ONLY;
45+
import static org.xmldb.api.security.AclEntryFlag.NO_PROPAGATE_INHERIT;
46+
import static org.xmldb.api.security.AclEntryFlag.RESOURCE_INHERIT;
47+
48+
import org.junit.jupiter.api.Test;
49+
50+
class AclEntryFlagTest {
51+
@Test
52+
void testValidValues() {
53+
assertThat(AclEntryFlag.values()).containsExactly(RESOURCE_INHERIT, COLLECTION_INHERIT,
54+
NO_PROPAGATE_INHERIT, INHERIT_ONLY);
55+
}
56+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* The XML:DB Initiative Software License, Version 1.0
3+
*
4+
* Copyright (c) 2000-2022 The XML:DB Initiative. All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification, are permitted
7+
* provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
10+
* and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
* conditions and the following disclaimer in the documentation and/or other materials provided with
14+
* the distribution.
15+
*
16+
* 3. The end-user documentation included with the redistribution, if any, must include the
17+
* following acknowledgment: "This product includes software developed by the XML:DB Initiative
18+
* (http://www.xmldb.org/)." Alternately, this acknowledgment may appear in the software itself, if
19+
* and wherever such third-party acknowledgments normally appear.
20+
*
21+
* 4. The name "XML:DB Initiative" must not be used to endorse or promote products derived from this
22+
* software without prior written permission. For written permission, please contact info@xmldb.org.
23+
*
24+
* 5. Products derived from this software may not be called "XML:DB", nor may "XML:DB" appear in
25+
* their name, without prior written permission of the XML:DB Initiative.
26+
*
27+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29+
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR
30+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
* =================================================================================================
36+
* This software consists of voluntary contributions made by many individuals on behalf of the
37+
* XML:DB Initiative. For more information on the XML:DB Initiative, please see
38+
* <https://github.com/xmldb-org/>
39+
*/
40+
package org.xmldb.api.security;
41+
42+
import static org.assertj.core.api.Assertions.assertThat;
43+
import static org.xmldb.api.security.AclEntryPermission.EXECUTE;
44+
import static org.xmldb.api.security.AclEntryPermission.READ;
45+
import static org.xmldb.api.security.AclEntryPermission.WRITE;
46+
47+
import org.junit.jupiter.api.Test;
48+
49+
class AclEntryPermissionTest {
50+
@Test
51+
void testValidValues() {
52+
assertThat(AclEntryPermission.values()).containsExactly(READ, WRITE, EXECUTE);
53+
}
54+
}

0 commit comments

Comments
 (0)