- Fixed several issues reported by PMD
- Test for the UriConverter


git-svn-id: https://svn.libreccm.org/ccm/jpa@3369 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-05-01 15:48:55 +00:00
parent 5ac72c186c
commit ba2eea0ca8
11 changed files with 345 additions and 62 deletions

View File

@ -30,52 +30,6 @@
</license>
</licenses>
<repositories>
<repository>
<id>jp-digital-snapshots</id>
<url>http://archiva.jp-digital.de/repository/jp-digital-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jp-digital-releases</id>
<url>http://archiva.jp-digital.de/repository/jp-digital-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jp-digital-snapshots</id>
<url>http://archiva.jp-digital.de/repository/jp-digital-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>jp-digital-releases</id>
<url>http://archiva.jp-digital.de/repository/jp-digital-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>javax</groupId>
@ -127,7 +81,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<groups>de.jpdigital.research.accessibilitystudy.tests.UnitTest</groups>
<groups>org.libreccm.tests.categories.UnitTest</groups>
</configuration>
</plugin>
<plugin>

View File

@ -19,6 +19,7 @@
package org.libreccm.categorization;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@ -26,8 +27,11 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.libreccm.core.CcmObject;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -55,6 +59,109 @@ public class Categorization implements Serializable {
@Column(name = "object_order")
private long objectOrder;
public long getCategorizationId() {
return categorizationId;
}
public void setCategorizationId(final long categorizationId) {
this.categorizationId = categorizationId;
}
public Category getCategory() {
return category;
}
protected void setCategory(final Category category) {
this.category = category;
}
public CcmObject getCategorizedObject() {
return categorizedObject;
}
protected void setCategorizedObject(final CcmObject categorizedObject) {
this.categorizedObject = categorizedObject;
}
public long getCategoryOrder() {
return categoryOrder;
}
public void setCategoryOrder(final long categoryOrder) {
this.categoryOrder = categoryOrder;
}
public long getObjectOrder() {
return objectOrder;
}
public void setObjectOrder(final long objectOrder) {
this.objectOrder = objectOrder;
}
@Override
public int hashCode() {
int hash = 7;
hash
= 89 * hash + (int) (categorizationId ^ (categorizationId >>> 32));
hash = 89 * hash + Objects.hashCode(category);
hash = 89 * hash + Objects.hashCode(categorizedObject);
hash = 89 * hash + (int) (categoryOrder ^ (categoryOrder >>> 32));
hash = 89 * hash + (int) (objectOrder ^ (objectOrder >>> 32));
return hash;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Categorization other = (Categorization) obj;
if (categorizationId != other.getCategorizationId()) {
return false;
}
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(category, other.getCategory())) {
return false;
}
if (!Objects.equals(categorizedObject, other.getCategorizedObject())) {
return false;
}
if (categoryOrder != other.getCategoryOrder()) {
return false;
}
return objectOrder == other.getObjectOrder();
}
public boolean canEqual(final Object obj) {
return obj instanceof Categorization;
}
@Override
public String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "categorizationId = %d, "
+ "category = %s, "
+ "categorizedObject = %s, "
+ "categoryOrder = %d, "
+ "objectOrder = %d"
+ "%s }",
super.toString(),
categorizationId,
Objects.toString(category),
Objects.toString(categorizedObject),
categoryOrder,
objectOrder);
}
}

View File

@ -216,6 +216,10 @@ public class Category extends CcmObject implements Serializable {
}
@Override
@SuppressWarnings({"PMD.NPathComplexity",
"PMD.CyclomaticComplexity",
"PMD.StdCyclomaticComplexity",
"PMD.ModifiedCyclomaticComplexity"})
public boolean equals(final Object obj) {
if (obj == null) {
return false;

View File

@ -122,7 +122,7 @@ public class Domain extends CcmObject implements Serializable {
return version;
}
public void setVersion(String version) {
public void setVersion(final String version) {
this.version = version;
}
@ -172,7 +172,11 @@ public class Domain extends CcmObject implements Serializable {
}
@Override
public boolean equals(Object obj) {
@SuppressWarnings({"PMD.NPathComplexity",
"PMD.CyclomaticComplexity",
"PMD.StdCyclomaticComplexity",
"PMD.ModifiedCyclomaticComplexity"})
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}

View File

@ -120,6 +120,10 @@ public class DomainOwnership implements Serializable {
}
@Override
@SuppressWarnings({"PMD.NPathComplexity",
"PMD.CyclomaticComplexity",
"PMD.StdCyclomaticComplexity",
"PMD.ModifiedCyclomaticComplexity"})
public boolean equals(final Object obj) {
if (obj == null) {
return false;

View File

@ -81,7 +81,7 @@ public class Resource extends CcmObject implements Serializable {
return title;
}
public void setTitle(LocalizedString title) {
public void setTitle(final LocalizedString title) {
this.title = title;
}
@ -89,7 +89,7 @@ public class Resource extends CcmObject implements Serializable {
return description;
}
public void setDescription(LocalizedString description) {
public void setDescription(final LocalizedString description) {
this.description = description;
}
@ -121,7 +121,7 @@ public class Resource extends CcmObject implements Serializable {
return parent;
}
protected void setParent(Resource parent) {
protected void setParent(final Resource parent) {
this.parent = parent;
}

View File

@ -56,7 +56,7 @@ public class LocalizedString implements Serializable {
*/
@ElementCollection
@MapKeyColumn(name = "locale")
@Column(name = "value")
@Column(name = "localized_value")
@Lob
@XmlElementWrapper(name = "values")
@XmlElement(name = "value")

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/DECORATION/1.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.3.0
http://maven.apache.org/xsd/decoration-1.3.0.xsd">
<body>
<menu ref="reports"/>
</body>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.3.1</version>
</skin>
</project>

View File

@ -0,0 +1,146 @@
/*
* 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.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;
import java.net.URI;
import java.net.URISyntaxException;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
/**
* This test suite checks the functionality of the {@link UriConverter} class
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Category(UnitTest.class)
public class UriConverterTest {
private static final String WWW_EXAMPLE_ORG = "http://www.example.org";
private static final String WWW_EXAMPLE_COM = "http://www.example.com";
private static final String EXAMPLE_ORG_WITH_PATH2
= "http://example.org/some/path";
private static final String WWW_EXAMPLE_ORG_WITH_PATH
= "http://www.example.org/some/path";
private static final String WITH_USER_AND_PORT_AND_PATH
= "http://foo:bar@example.org/api/?query=foo";
private static final String FILE_PATH = "file:///home/foo/some/file";
private static final String HTTP = "http";
private static final String FILE = "file";
private transient UriConverter uriConverter;
public UriConverterTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
uriConverter = new UriConverter();
}
@After
public void tearDown() {
uriConverter = null;
}
/**
* Verifies that URI passed to
* {@link UriConverter#convertToDatabaseColumn(java.net.URI)} is converted
* to the expected string value.
*
* @throws URISyntaxException If one the test URIs could not be created
* (should never happen).
*/
@Test
public void verifyToDatabaseColumn() throws URISyntaxException {
final URI wwwExampleOrg = new URI(WWW_EXAMPLE_ORG);
final URI wwwExampleCom = new URI(WWW_EXAMPLE_COM);
final URI wwwExampleOrgWithPath = new URI(WWW_EXAMPLE_ORG_WITH_PATH);
final URI exampleOrgWithPath = new URI(EXAMPLE_ORG_WITH_PATH2);
final URI filePath = new URI(FILE_PATH);
final URI withUserAndPortAndPath = new URI(
WITH_USER_AND_PORT_AND_PATH);
assertThat(uriConverter.convertToDatabaseColumn(wwwExampleOrg),
is(equalTo(WWW_EXAMPLE_ORG)));
assertThat(uriConverter.convertToDatabaseColumn(wwwExampleCom),
is(equalTo(WWW_EXAMPLE_COM)));
assertThat(uriConverter.convertToDatabaseColumn(wwwExampleOrgWithPath),
is(equalTo(WWW_EXAMPLE_ORG_WITH_PATH)));
assertThat(uriConverter.convertToDatabaseColumn(exampleOrgWithPath),
is(equalTo(EXAMPLE_ORG_WITH_PATH2)));
assertThat(uriConverter.convertToDatabaseColumn(filePath),
is(equalTo(FILE_PATH)));
assertThat(uriConverter.convertToDatabaseColumn(withUserAndPortAndPath),
is(equalTo(WITH_USER_AND_PORT_AND_PATH)));
}
/**
* Verifies that
* {@link UriConverter#convertToEntityAttribute(java.lang.String)}
* returns the expected URI from the string passed to the method.
*/
@Test
public void verifyToEntityAttribute() {
final URI wwwExampleOrg = uriConverter.convertToEntityAttribute(
WWW_EXAMPLE_ORG);
assertThat(wwwExampleOrg, is(instanceOf(URI.class)));
assertThat(wwwExampleOrg.getScheme(), is(equalTo(HTTP)));
assertThat(wwwExampleOrg.getHost(), is(equalTo("www.example.org")));
final URI filePath = uriConverter.convertToEntityAttribute(FILE_PATH);
assertThat(filePath, is(instanceOf(URI.class)));
assertThat(filePath.getScheme(), is(equalTo(FILE)));
final URI withUserAndPortAndPath = uriConverter
.convertToEntityAttribute(WITH_USER_AND_PORT_AND_PATH);
assertThat(withUserAndPortAndPath, is(instanceOf(URI.class)));
assertThat(withUserAndPortAndPath.getScheme(), is(equalTo(HTTP)));
assertThat(withUserAndPortAndPath.getHost(), is(equalTo("example.org")));
assertThat(withUserAndPortAndPath.getUserInfo(), is(equalTo("foo:bar")));
assertThat(withUserAndPortAndPath.getPath(), is(equalTo("/api/")));
assertThat(withUserAndPortAndPath.getQuery(), is(equalTo("query=foo")));
}
/**
* Checks if
* {@link UriConverter#convertToEntityAttribute(java.lang.String)}
* throws an {@link IllegalArgumentException} for an invalid URI.
*/
@Test(expected = IllegalArgumentException.class)
public void invalidUriInDb() {
uriConverter.convertToEntityAttribute("file:///foo/b([[ar");
}
}

View File

@ -0,0 +1,31 @@
/*
* 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.tests.categories;
/**
* A marker interface for use with JUnit's {@link Category} annotation.
*
* Tests which are grouped into this category are used to test an
* individual class. All external dependencies should be mocked.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public interface UnitTest {
}

17
src/site/site.xml 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/DECORATION/1.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.3.0
http://maven.apache.org/xsd/decoration-1.3.0.xsd">
<body>
<menu ref="modules"/>
<menu ref="reports"/>
</body>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.3.1</version>
</skin>
</project>