CCM NG: First classes for org.libreccm.formbuilder, Test for equals and hashCode for Entities in org.libreccm.core

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3422 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-05-20 16:04:01 +00:00
parent 1835f40ccd
commit ae01470ca3
9 changed files with 778 additions and 4 deletions

View File

@ -64,6 +64,12 @@
<artifactId>hamcrest-library</artifactId> <artifactId>hamcrest-library</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -356,7 +356,8 @@ public class CcmObject implements Serializable {
public String toString(final String data) { public String toString(final String data) {
return String.format( return String.format(
"%s{ " "%s{ "
+ "objectId = %d; displayName = \"%s\"" + "objectId = %d, "
+ "displayName = \"%s\""
+ "%s" + "%s"
+ " }", + " }",
super.toString(), super.toString(),

View File

@ -22,6 +22,7 @@ import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
@ -71,6 +72,41 @@ public class EmailAddress implements Serializable {
this.verified = verified; this.verified = verified;
} }
@Override
public int hashCode() {
int hash = 5;
hash = 79 * hash + Objects.hashCode(eMailAddress);
hash = 79 * hash + (bouncing ? 1 : 0);
hash = 79 * hash + (verified ? 1 : 0);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final EmailAddress other = (EmailAddress) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(eMailAddress, other.getEmailAddress())) {
return false;
}
if (bouncing != other.isBouncing()) {
return false;
}
return verified == other.isVerified();
}
public boolean canEqual(final Object obj) {
return obj instanceof EmailAddress;
}
@Override @Override
public String toString() { public String toString() {
return String.format("%s{ " return String.format("%s{ "

View File

@ -96,13 +96,13 @@ public class GroupMembership implements Serializable {
return false; return false;
} }
if (this.membershipId != other.membershipId) { if (this.membershipId != other.getMembershipId()) {
return false; return false;
} }
if (!Objects.equals(this.group, other.group)) { if (!Objects.equals(this.group, other.getGroup())) {
return false; return false;
} }
return Objects.equals(this.user, other.user); return Objects.equals(this.user, other.getUser());
} }
public boolean canEqual(final Object obj) { public boolean canEqual(final Object obj) {

View File

@ -0,0 +1,217 @@
/*
* 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.formbuilder;
import org.libreccm.core.CcmObject;
import org.libreccm.l10n.LocalizedString;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.persistence.AssociationOverride;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Entity
@Table(name = "formbuilder_components")
public class Component extends CcmObject implements Serializable {
private static final long serialVersionUID = 1787173100367982069L;
@Column(name = "admin_name")
private String adminName;
@Embedded
@AssociationOverride(
name = "values",
joinTable = @JoinTable(name = "formbuilder_component_descriptions",
joinColumns = {
@JoinColumn(name = "component_id")}))
private LocalizedString description;
@Column(name = "attribute_string")
private String attributeString;
@Column(name = "active")
private boolean active;
@ManyToOne
private Component parentComponent;
@OneToMany(mappedBy = "parentComponent")
private List<Component> childComponents;
@Column(name = "component_order")
private long componentOrder;
@Column(name = "selected")
private boolean selected;
public String getAdminName() {
return adminName;
}
public void setAdminName(final String adminName) {
this.adminName = adminName;
}
public LocalizedString getDescription() {
return description;
}
public void setDescription(final LocalizedString description) {
this.description = description;
}
public String getAttributeString() {
return attributeString;
}
public void setAttributeString(final String attributeString) {
this.attributeString = attributeString;
}
public boolean isActive() {
return active;
}
public void setActive(final boolean active) {
this.active = active;
}
public Component getParentComponent() {
return parentComponent;
}
protected void setParentComponent(final Component parentComponent) {
this.parentComponent = parentComponent;
}
public List<Component> getChildComponents() {
return Collections.unmodifiableList(childComponents);
}
protected void setChildComponents(final List<Component> childComponents) {
this.childComponents = childComponents;
}
public long getComponentOrder() {
return componentOrder;
}
public void setComponentOrder(final long componentOrder) {
this.componentOrder = componentOrder;
}
public boolean isSelected() {
return selected;
}
public void setSelected(final boolean selected) {
this.selected = selected;
}
@Override
public int hashCode() {
int hash = super.hashCode();
hash = 53 * hash + Objects.hashCode(adminName);
hash = 53 * hash + Objects.hashCode(description);
hash = 53 * hash + Objects.hashCode(attributeString);
hash = 53 * hash + (active ? 1 : 0);
hash = 53 * hash + Objects.hashCode(parentComponent);
hash = 53 * hash + Objects.hashCode(childComponents);
hash = 53 * hash + (int) (componentOrder ^ (componentOrder >>> 32));
hash = 53 * hash + (selected ? 1 : 0);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Component other = (Component) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(adminName, other.getAdminName())) {
return false;
}
if (!Objects.equals(description, other.getDescription())) {
return false;
}
if (!Objects.equals(attributeString, other.getAttributeString())) {
return false;
}
if (active != other.isActive()) {
return false;
}
if (!Objects.equals(parentComponent, other.getParentComponent())) {
return false;
}
if (!Objects.equals(childComponents, other.getChildComponents())) {
return false;
}
if (componentOrder != other.getComponentOrder()) {
return false;
}
return selected == other.isSelected();
}
@Override
public boolean canEqual(final Object obj) {
return obj instanceof Component;
}
@Override
public String toString(final String data) {
return super.toString(String.format(", adminName = \"%s\", "
+ "description = %s, "
+ "attributeString = \"%s\", "
+ "active = %b, "
+ "parentComponent = %s, "
+ "componentOrder, "
+ "selected = %b%s",
adminName,
Objects.toString(description),
attributeString,
active,
Objects.toString(parentComponent),
componentOrder,
selected,
data));
}
}

View File

@ -0,0 +1,122 @@
/*
* 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.formbuilder;
import org.libreccm.core.CcmObject;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Entity
@Table(name = "formbuilder_listeners")
public class Listener extends CcmObject implements Serializable {
private static final long serialVersionUID = 9030104813240364500L;
@Column(name = "class_name")
private String className;
@Column(name = "attribute_string")
private String attributeString;
@ManyToOne
private Widget widget;
public String getClassName() {
return className;
}
public void setClassName(final String className) {
this.className = className;
}
public String getAttributeString() {
return attributeString;
}
public void setAttributeString(final String attributeString) {
this.attributeString = attributeString;
}
public Widget getWidget() {
return widget;
}
protected void setWidget(final Widget widget) {
this.widget = widget;
}
@Override
public int hashCode() {
int hash = super.hashCode();
hash = 59 * hash + Objects.hashCode(className);
hash = 59 * hash + Objects.hashCode(attributeString);
hash = 59 * hash + Objects.hashCode(widget);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Listener other = (Listener) obj;
if (other.canEqual(this)) {
return false;
}
if (!Objects.equals(className, other.getClassName())) {
return false;
}
if (!Objects.equals(attributeString, other.getAttributeString())) {
return false;
}
if (!Objects.equals(widget, other.getWidget())) {
return false;
}
return true;
}
@Override
public boolean canEqual(Object obj) {
return obj instanceof Listener;
}
@Override
public String toString(final String data) {
return super.toString(String.format(", className = \"%s\", "
+ "attributeString = \"%s\"%s",
className,
attributeString,
data));
}
}

View File

@ -0,0 +1,158 @@
/*
* 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.formbuilder;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Entity
@Table(name = "formbuilder_widgets")
public class Widget extends Component implements Serializable {
private static final long serialVersionUID = 1057792450655098288L;
@Column(name = "parameter_name")
private String parameterName;
@Column(name = "parameter_model")
private String parameterModel;
@Column(name = "default_value")
private String defaultValue;
@OneToOne
private WidgetLabel label;
@OneToMany(mappedBy = "widget")
private List<Listener> listeners;
public String getParameterName() {
return parameterName;
}
public void setParameterName(final String parameterName) {
this.parameterName = parameterName;
}
public String getParameterModel() {
return parameterModel;
}
public void setParameterModel(final String parameterModel) {
this.parameterModel = parameterModel;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(final String defaultValue) {
this.defaultValue = defaultValue;
}
public WidgetLabel getLabel() {
return label;
}
protected void setLabel(final WidgetLabel label) {
this.label = label;
}
public List<Listener> getListeners() {
return Collections.unmodifiableList(listeners);
}
protected void setListeners(final List<Listener> listeners) {
this.listeners = listeners;
}
protected void addListener(final Listener listener) {
listeners.add(listener);
}
protected void removeListener(final Listener listener) {
listeners.remove(listener);
}
@Override
public int hashCode() {
int hash = super.hashCode();
hash = 17 * hash + Objects.hashCode(parameterName);
hash = 17 * hash + Objects.hashCode(parameterModel);
hash = 17 * hash + Objects.hashCode(defaultValue);
hash = 17 * hash + Objects.hashCode(label);
hash = 17 * hash + Objects.hashCode(listeners);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Widget other = (Widget) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(parameterName, other.getParameterName())) {
return false;
}
if (!Objects.equals(parameterModel, other.getParameterModel())) {
return false;
}
if (!Objects.equals(defaultValue, other.getDefaultValue())) {
return false;
}
if (!Objects.equals(label, other.getLabel())) {
return false;
}
return Objects.equals(listeners, other.getListeners());
}
@Override
public String toString(final String data) {
return super.toString(String.format(", parameterName = \"%s\", "
+ "parameterModel = \"%s\", "
+ "defaultValue = \"%s\"%s",
parameterName,
parameterModel,
defaultValue,
data));
}
}

View File

@ -0,0 +1,78 @@
/*
* 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.formbuilder;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import javax.persistence.Table;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Entity
@Table(name = "formbuilder_widget_labels")
public class WidgetLabel extends Component implements Serializable {
private static final long serialVersionUID = -2939505715812565159L;
@OneToOne
private Widget widget;
public Widget getWidget() {
return widget;
}
protected void setWidget(final Widget widget) {
this.widget = widget;
}
@Override
public int hashCode() {
int hash = super.hashCode();
hash = 19 * hash + Objects.hashCode(widget);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final WidgetLabel other = (WidgetLabel) obj;
if (!other.canEqual(this)) {
return false;
}
return Objects.equals(widget, other.getWidget());
}
@Override
public boolean canEqual(final Object obj) {
return obj instanceof WidgetLabel;
}
}

View File

@ -0,0 +1,156 @@
/*
* 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();
}
}