CCM NG: Tests and fixed bugs found by tests
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3442 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
11fae39504
commit
0cd20cfaee
|
|
@ -88,7 +88,7 @@ public class GroupMembership implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof GroupMembership)) {
|
||||
return false;
|
||||
}
|
||||
final GroupMembership other = (GroupMembership) obj;
|
||||
|
|
|
|||
|
|
@ -56,12 +56,16 @@ public class Party extends CcmObject implements Serializable {
|
|||
|
||||
public Party() {
|
||||
super();
|
||||
|
||||
|
||||
grantedPermissions = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
public List<EmailAddress> getEmailAddresses() {
|
||||
return Collections.unmodifiableList(emailAddresses);
|
||||
if (emailAddresses == null) {
|
||||
return null;
|
||||
} else {
|
||||
return Collections.unmodifiableList(emailAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setEmailAddresses(final List<EmailAddress> eMailAddresses) {
|
||||
|
|
@ -80,14 +84,15 @@ public class Party extends CcmObject implements Serializable {
|
|||
return Collections.unmodifiableList(grantedPermissions);
|
||||
}
|
||||
|
||||
protected void setGrantedPermissions(final List<Permission> grantedPermissions) {
|
||||
protected void setGrantedPermissions(
|
||||
final List<Permission> grantedPermissions) {
|
||||
this.grantedPermissions = grantedPermissions;
|
||||
}
|
||||
|
||||
|
||||
protected void addGrantedPermission(final Permission permission) {
|
||||
grantedPermissions.add(permission);
|
||||
}
|
||||
|
||||
|
||||
protected void removeGrantedPermission(final Permission permission) {
|
||||
grantedPermissions.remove(permission);
|
||||
}
|
||||
|
|
@ -95,7 +100,7 @@ public class Party extends CcmObject implements Serializable {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
int hash = super.hashCode();
|
||||
hash = 41 * hash + Objects.hashCode(this.emailAddresses);
|
||||
hash = 41 * hash + Objects.hashCode(emailAddresses);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +113,7 @@ public class Party extends CcmObject implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof Party)) {
|
||||
return false;
|
||||
}
|
||||
final Party other = (Party) obj;
|
||||
|
|
@ -116,7 +121,7 @@ public class Party extends CcmObject implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(this.emailAddresses, other.getEmailAddresses());
|
||||
return Objects.equals(emailAddresses, other.getEmailAddresses());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -48,27 +48,27 @@ public class Permission implements Serializable {
|
|||
@Column(name = "permission_id")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long permissionId;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "grantee_id")
|
||||
private Party grantee;
|
||||
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "granted_privilege_id")
|
||||
private Privilege grantedPrivilege;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "object_id")
|
||||
private CcmObject object;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "creation_user_id")
|
||||
private User creationUser;
|
||||
|
||||
|
||||
@Column(name = "creation_date")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date creationDate;
|
||||
|
||||
|
||||
@Column(name = "creation_ip")
|
||||
private String creationIp;
|
||||
|
||||
|
|
@ -113,7 +113,11 @@ public class Permission implements Serializable {
|
|||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return new Date(creationDate.getTime());
|
||||
if (creationDate == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new Date(creationDate.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreationDate(final Date creationDate) {
|
||||
|
|
@ -132,7 +136,7 @@ public class Permission implements Serializable {
|
|||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash
|
||||
= 31 * hash + (int) (permissionId ^ (permissionId >>> 32));
|
||||
= 31 * hash + (int) (permissionId ^ (permissionId >>> 32));
|
||||
hash = 31 * hash + Objects.hashCode(grantee);
|
||||
hash = 31 * hash + Objects.hashCode(grantedPrivilege);
|
||||
hash = 31 * hash + Objects.hashCode(object);
|
||||
|
|
@ -147,15 +151,15 @@ public class Permission implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getClass() != obj.getClass()) {
|
||||
|
||||
if (!(obj instanceof Permission)) {
|
||||
return false;
|
||||
}
|
||||
final Permission other = (Permission) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (permissionId != other.getPermissionId()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -176,22 +180,22 @@ public class Permission implements Serializable {
|
|||
}
|
||||
return Objects.equals(creationIp, other.getCreationIp());
|
||||
}
|
||||
|
||||
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof Permission;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s{ "
|
||||
+ "permissionId = %d, "
|
||||
+ "grantee = %s, "
|
||||
+ "grantedPrivilege = %s, "
|
||||
+ "object = %s, "
|
||||
+ "creationUser = %s,"
|
||||
+ "creationDate = %tF %<tT, "
|
||||
+ "creationIp = %s"
|
||||
+ " }",
|
||||
+ "permissionId = %d, "
|
||||
+ "grantee = %s, "
|
||||
+ "grantedPrivilege = %s, "
|
||||
+ "object = %s, "
|
||||
+ "creationUser = %s,"
|
||||
+ "creationDate = %tF %<tT, "
|
||||
+ "creationIp = %s"
|
||||
+ " }",
|
||||
super.toString(),
|
||||
permissionId,
|
||||
Objects.toString(grantee),
|
||||
|
|
@ -201,4 +205,5 @@ public class Permission implements Serializable {
|
|||
creationDate,
|
||||
creationIp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public class PersonName implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof PersonName)) {
|
||||
return false;
|
||||
}
|
||||
final PersonName other = (PersonName) obj;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import javax.persistence.Table;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "privileges")
|
||||
@Table(name = "ccm_privileges")
|
||||
public class Privilege implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3986038536996049440L;
|
||||
|
|
@ -75,7 +75,7 @@ public class Privilege implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof Privilege)) {
|
||||
return false;
|
||||
}
|
||||
final Privilege other = (Privilege) obj;
|
||||
|
|
|
|||
|
|
@ -39,18 +39,18 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
|
||||
/**
|
||||
* The {@code Resource} class is a base class for several other classes, for
|
||||
* The {@code Resource} class is a base class for several other classes, for
|
||||
* example the {@link Application} class.
|
||||
*
|
||||
*
|
||||
* Resources can be nested, a resource can have multiple child resources.
|
||||
*
|
||||
* This class is an adopted variant of the class
|
||||
*
|
||||
* This class is an adopted variant of the class
|
||||
* {@code com.arsdigita.kernel.Resource} from the old structure. This class is
|
||||
* maybe removed in future releases. Therefore it is strictly recommend not to
|
||||
* use this class directly.
|
||||
*
|
||||
* use this class directly.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "resources")
|
||||
|
|
@ -69,7 +69,7 @@ public class Resource extends CcmObject implements Serializable {
|
|||
@JoinColumn(name = "object_id")}))
|
||||
private LocalizedString title;
|
||||
|
||||
/**
|
||||
/**
|
||||
* A localisable description for the {@code Resource}.
|
||||
*/
|
||||
@Embedded
|
||||
|
|
@ -102,7 +102,6 @@ public class Resource extends CcmObject implements Serializable {
|
|||
|
||||
// @Column(name = "resource_type")
|
||||
// private String resourceType;
|
||||
|
||||
public LocalizedString getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
|
@ -120,7 +119,11 @@ public class Resource extends CcmObject implements Serializable {
|
|||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return new Date(created.getTime());
|
||||
if (created == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new Date(created.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreated(final Date created) {
|
||||
|
|
@ -158,7 +161,6 @@ public class Resource extends CcmObject implements Serializable {
|
|||
// public void setResourceType(final String resourceType) {
|
||||
// this.resourceType = resourceType;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
|
|
@ -174,7 +176,7 @@ public class Resource extends CcmObject implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof Resource)) {
|
||||
return false;
|
||||
}
|
||||
final Resource other = (Resource) obj;
|
||||
|
|
@ -205,7 +207,7 @@ public class Resource extends CcmObject implements Serializable {
|
|||
return super.toString(
|
||||
String.format(", title = %s, "
|
||||
+ "created = %tF %<tT%s",
|
||||
title.toString(),
|
||||
Objects.toString(title),
|
||||
created,
|
||||
data));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public class Role implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof Role)) {
|
||||
return false;
|
||||
}
|
||||
final Role other = (Role) obj;
|
||||
|
|
@ -126,7 +126,7 @@ public class Role implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (this.roleId != other.roleId) {
|
||||
if (this.roleId != other.getRoleId()) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.name, other.getName())) {
|
||||
|
|
@ -144,20 +144,20 @@ public class Role implements Serializable {
|
|||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof Role;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s{ "
|
||||
+ "roleId = %d, "
|
||||
+ "name = \"%s\", "
|
||||
+ "sourceGroup = %s, "
|
||||
+ "implicitGroup = %s, "
|
||||
+ " }",
|
||||
+ "roleId = %d, "
|
||||
+ "name = \"%s\", "
|
||||
+ "sourceGroup = %s, "
|
||||
+ "implicitGroup = %s, "
|
||||
+ " }",
|
||||
super.toString(),
|
||||
roleId,
|
||||
name,
|
||||
sourceGroup.toString(),
|
||||
implicitGroup.toString());
|
||||
Objects.toString(sourceGroup),
|
||||
Objects.toString(implicitGroup));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ public class User extends Party implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof User)) {
|
||||
return false;
|
||||
}
|
||||
final User other = (User) obj;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class UserGroup extends Party implements Serializable {
|
|||
|
||||
@OneToMany(mappedBy = "sourceGroup")
|
||||
private List<Role> roles;
|
||||
|
||||
|
||||
@OneToMany(mappedBy = "group")
|
||||
private List<GroupMembership> members;
|
||||
|
||||
|
|
@ -66,7 +66,11 @@ public class UserGroup extends Party implements Serializable {
|
|||
}
|
||||
|
||||
public List<Role> getRoles() {
|
||||
return Collections.unmodifiableList(roles);
|
||||
if (roles == null) {
|
||||
return null;
|
||||
} else {
|
||||
return Collections.unmodifiableList(roles);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setRoles(final List<Role> roles) {
|
||||
|
|
@ -80,26 +84,30 @@ public class UserGroup extends Party implements Serializable {
|
|||
protected void removeRole(final Role role) {
|
||||
roles.remove(role);
|
||||
}
|
||||
|
||||
|
||||
public List<GroupMembership> getMembers() {
|
||||
return Collections.unmodifiableList(members);
|
||||
if (members == null) {
|
||||
return null;
|
||||
} else {
|
||||
return Collections.unmodifiableList(members);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setMembers(final List<GroupMembership> members) {
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
|
||||
protected void addMember(final GroupMembership member) {
|
||||
members.add(member);
|
||||
}
|
||||
|
||||
|
||||
protected void removeMember(final GroupMembership member) {
|
||||
members.remove(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
int hash = super.hashCode();
|
||||
hash = 83 * hash + Objects.hashCode(this.name);
|
||||
hash = 83 * hash + Objects.hashCode(this.roles);
|
||||
return hash;
|
||||
|
|
@ -114,7 +122,7 @@ public class UserGroup extends Party implements Serializable {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof UserGroup)) {
|
||||
return false;
|
||||
}
|
||||
final UserGroup other = (UserGroup) obj;
|
||||
|
|
@ -128,7 +136,8 @@ public class UserGroup extends Party implements Serializable {
|
|||
return Objects.equals(this.roles, other.getRoles());
|
||||
}
|
||||
|
||||
public boolean canEquals(final Object obj) {
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof UserGroup;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.categorization;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.jpautils.EqualsVerifier;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@org.junit.experimental.categories.Category(UnitTest.class)
|
||||
public class EqualsAndHashCodeTest extends EqualsVerifier {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
Categorization.class,
|
||||
org.libreccm.categorization.Category.class,
|
||||
Domain.class,
|
||||
DomainOwnership.class});
|
||||
}
|
||||
|
||||
public EqualsAndHashCodeTest(final Class<?> entitiesClass) {
|
||||
super(entitiesClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.categorization;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.jpautils.ToStringVerifier;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@org.junit.experimental.categories.Category(UnitTest.class)
|
||||
public class ToStringTest extends ToStringVerifier {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
Categorization.class,
|
||||
org.libreccm.categorization.Category.class,
|
||||
Domain.class,
|
||||
DomainOwnership.class});
|
||||
}
|
||||
|
||||
public ToStringTest(final Class<?> entitiesClass) {
|
||||
super(entitiesClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.libreccm.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.categorization.Categorization;
|
||||
import org.libreccm.categorization.Domain;
|
||||
import org.libreccm.categorization.DomainOwnership;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@Category(UnitTest.class)
|
||||
public class CategorizationEntitiesTest extends EntitiesTestCore {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
Categorization.class,
|
||||
org.libreccm.categorization.Category.class,
|
||||
Domain.class,
|
||||
DomainOwnership.class});
|
||||
}
|
||||
|
||||
public CategorizationEntitiesTest(final Class<?> entitiesClass) {
|
||||
super(entitiesClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.libreccm.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
/**
|
||||
* The tests in this class are used to verify the implementations of the
|
||||
* {@code equals}, {@code hashCode} and {@code toString} methods of the entities
|
||||
* in the {@code org.libreccm.core} package.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@Category(UnitTest.class)
|
||||
public class CcmCoreEntitiesTest extends EntitiesTestCore {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
CcmObject.class,
|
||||
EmailAddress.class,
|
||||
GroupMembership.class,
|
||||
Party.class,
|
||||
Permission.class,
|
||||
PersonName.class,
|
||||
Privilege.class,
|
||||
Resource.class,
|
||||
Role.class,
|
||||
User.class,
|
||||
UserGroup.class});
|
||||
}
|
||||
|
||||
public CcmCoreEntitiesTest(final Class<?> entityClass) {
|
||||
super(entityClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,15 +10,11 @@ import nl.jqno.equalsverifier.Warning;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
|
|
@ -38,6 +34,7 @@ public class EntitiesTestCore {
|
|||
EqualsVerifier
|
||||
.forClass(entityClass)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.suppress(Warning.NONFINAL_FIELDS)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
|
@ -49,18 +46,11 @@ public class EntitiesTestCore {
|
|||
IllegalArgumentException,
|
||||
InvocationTargetException {
|
||||
final Object obj = entityClass.newInstance();
|
||||
// final BeanInfo beanInfo = Introspector.getBeanInfo(entityClass);
|
||||
//
|
||||
// final PropertyDescriptor[] properties = beanInfo
|
||||
// .getPropertyDescriptors();
|
||||
// for (PropertyDescriptor property : properties) {
|
||||
// final Method setter = property.getWriteMethod();
|
||||
|
||||
// setter.invoke(obj, new Object[]{null});
|
||||
final Field[] fields = entityClass.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (!Modifier.isStatic(field.getModifiers())
|
||||
&& !field.getType().isPrimitive()) {
|
||||
&& !field.getType().isPrimitive()) {
|
||||
field.setAccessible(true);
|
||||
field.set(obj, null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.core;
|
||||
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.jpautils.EqualsVerifier;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@Category(UnitTest.class)
|
||||
public class EqualsAndHashCodeTest extends EqualsVerifier {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
CcmObject.class,
|
||||
EmailAddress.class,
|
||||
GroupMembership.class,
|
||||
Party.class,
|
||||
Permission.class,
|
||||
PersonName.class,
|
||||
Privilege.class,
|
||||
Role.class,
|
||||
User.class,
|
||||
UserGroup.class});
|
||||
}
|
||||
|
||||
public EqualsAndHashCodeTest(final Class<?> entityClass) {
|
||||
super(entityClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.core;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import nl.jqno.equalsverifier.Warning;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Category(UnitTest.class)
|
||||
public class EqualsTest {
|
||||
|
||||
public EqualsTest() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyCcmObject() {
|
||||
EqualsVerifier
|
||||
.forClass(CcmObject.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyEmailAddress() {
|
||||
EqualsVerifier
|
||||
.forClass(EmailAddress.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyGroupMembership() {
|
||||
EqualsVerifier
|
||||
.forClass(GroupMembership.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyParty() {
|
||||
EqualsVerifier
|
||||
.forClass(Party.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPermission() {
|
||||
EqualsVerifier
|
||||
.forClass(Permission.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPersonName() {
|
||||
EqualsVerifier
|
||||
.forClass(PersonName.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPrivilege() {
|
||||
EqualsVerifier
|
||||
.forClass(Privilege.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyResource() {
|
||||
EqualsVerifier
|
||||
.forClass(Resource.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyRole() {
|
||||
EqualsVerifier
|
||||
.forClass(Role.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyUser() {
|
||||
EqualsVerifier
|
||||
.forClass(User.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyUserGroup() {
|
||||
EqualsVerifier
|
||||
.forClass(UserGroup.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.core;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import nl.jqno.equalsverifier.Warning;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Category(UnitTest.class)
|
||||
public class ResourceEntityTest {
|
||||
|
||||
public ResourceEntityTest() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyEqualsAndHashCode() {
|
||||
final Resource resource1 = new Resource();
|
||||
final LocalizedString title1 = new LocalizedString();
|
||||
title1.addValue(Locale.ENGLISH, "Resource 1");
|
||||
resource1.setTitle(title1);
|
||||
|
||||
final Resource resource2 = new Resource();
|
||||
final LocalizedString title2 = new LocalizedString();
|
||||
title2.addValue(Locale.ENGLISH, "Resource 2");
|
||||
resource2.setTitle(title2);
|
||||
|
||||
EqualsVerifier
|
||||
.forClass(Resource.class)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.suppress(Warning.NONFINAL_FIELDS)
|
||||
.withPrefabValues(Resource.class, resource1, resource2)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.core;
|
||||
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.libreccm.jpautils.ToStringVerifier;
|
||||
import org.libreccm.tests.categories.UnitTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@Category(UnitTest.class)
|
||||
public class ToStringTest extends ToStringVerifier {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Collection<Class<?>> data() {
|
||||
return Arrays.asList(new Class<?>[]{
|
||||
CcmObject.class,
|
||||
EmailAddress.class,
|
||||
GroupMembership.class,
|
||||
Party.class,
|
||||
Permission.class,
|
||||
PersonName.class,
|
||||
Privilege.class,
|
||||
Resource.class,
|
||||
Role.class,
|
||||
User.class,
|
||||
UserGroup.class});
|
||||
}
|
||||
|
||||
public ToStringTest(final Class<?> entityClass) {
|
||||
super(entityClass);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.jpautils;
|
||||
|
||||
import nl.jqno.equalsverifier.Warning;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
/**
|
||||
* A base class for verifying the implementations of the {@code equals()}
|
||||
* and {@code hashCode} methods of an object using the {@link Parameterized}
|
||||
* test runner from JUnit.
|
||||
*
|
||||
* To use this class create a new JUnit test class which extends this class
|
||||
* and which uses the {@link Parameterized} test runner. The class must have a
|
||||
* static method which provides the classes to be tested. Example for testing
|
||||
* the classes {@code Foo} and {@code Bar} (imports have been omitted):
|
||||
*
|
||||
* <pre>
|
||||
* @RunWith(Parameterized.class)
|
||||
* @Category(UnitTest.class)
|
||||
* public class FooBarTest extends EqualsVerifier {
|
||||
*
|
||||
* @Parameterized.Parameters(name = "{0}")
|
||||
* public static Collection<Class<?>> data() {
|
||||
* return Arrays.asList(new Class<?>[] {
|
||||
* Foo.class,
|
||||
* Bar.class
|
||||
* });
|
||||
* }
|
||||
*
|
||||
* public FooBarTest(final Class<?> entityClass) {
|
||||
* super(entityClass);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class EqualsVerifier {
|
||||
|
||||
private final Class<?> entityClass;
|
||||
|
||||
public EqualsVerifier(final Class<?> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyEqualsAndHashCode() {
|
||||
nl.jqno.equalsverifier.EqualsVerifier
|
||||
.forClass(entityClass)
|
||||
.suppress(Warning.STRICT_INHERITANCE)
|
||||
.suppress(Warning.NONFINAL_FIELDS)
|
||||
.withRedefinedSuperclass()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.jpautils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* A base class for verifying the implementation of the {@code toString()}
|
||||
* method of an object using the {@link Parameterized}
|
||||
* test runner from JUnit.
|
||||
*
|
||||
* To use this class create a new JUnit test class which extends this class
|
||||
* and which uses the {@link Parameterized} test runner. The class must have a
|
||||
* static method which provides the classes to be tested. Example for testing
|
||||
* the classes {@code Foo} and {@code Bar} (imports have been omitted):
|
||||
*
|
||||
* <pre>
|
||||
* @RunWith(Parameterized.class)
|
||||
* @Category(UnitTest.class)
|
||||
* public class FooBarTest extends ToStringVerifier {
|
||||
*
|
||||
* @Parameterized.Parameters(name = "{0}")
|
||||
* public static Collection<Class<?>> data() {
|
||||
* return Arrays.asList(new Class<?>[] {
|
||||
* Foo.class,
|
||||
* Bar.class
|
||||
* });
|
||||
* }
|
||||
*
|
||||
* public FooBarTest(final Class<?> entityClass) {
|
||||
* super(entityClass);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ToStringVerifier {
|
||||
|
||||
private final Class<?> entityClass;
|
||||
|
||||
public ToStringVerifier(final Class<?> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyToString() throws IntrospectionException,
|
||||
InstantiationException,
|
||||
IllegalAccessException,
|
||||
IllegalArgumentException,
|
||||
InvocationTargetException {
|
||||
final Object obj = entityClass.newInstance();
|
||||
|
||||
final Field[] fields = entityClass.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (!Modifier.isStatic(field.getModifiers())
|
||||
&& !field.getType().isPrimitive()) {
|
||||
field.setAccessible(true);
|
||||
field.set(obj, null);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
obj.toString();
|
||||
} catch (NullPointerException ex) {
|
||||
final StringWriter strWriter = new StringWriter();
|
||||
final PrintWriter writer = new PrintWriter(strWriter);
|
||||
ex.printStackTrace(writer);
|
||||
Assert.fail(String.format(
|
||||
"toString() implemention of class \"%s\" "
|
||||
+ "is not null safe:\n %s",
|
||||
entityClass.getName(),
|
||||
strWriter.toString()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue