diff --git a/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java
index 1e3dfb277..b36c608c7 100644
--- a/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java
+++ b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java
@@ -33,8 +33,6 @@ import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -46,7 +44,6 @@ import org.libreccm.core.CcmObjectRepository;
import org.libreccm.security.Shiro;
import org.libreccm.tests.categories.IntegrationTest;
-import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -58,9 +55,11 @@ import javax.persistence.TypedQuery;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+
import static org.libreccm.testutils.DependenciesHelpers.*;
/**
+ * Tests for the {@link CategoryManager}.
*
* @author Jens Pelzetter
*/
@@ -116,18 +115,6 @@ public class CategoryManagerTest {
@Deployment
public static WebArchive createDeployment() {
-// final PomEquippedResolveStage pom = Maven
-// .resolver()
-// .loadPomFromFile("pom.xml");
-// final PomEquippedResolveStage dependencies = pom
-// .importCompileAndRuntimeDependencies();
-// final File[] libs = dependencies.resolve().withTransitivity().asFile();
-//
-// for (File lib : libs) {
-// System.err.printf("Adding file '%s' to test archive...%n",
-// lib.getName());
-// }
-
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.libreccm.categorization.CategoryManagerTest.war")
@@ -160,18 +147,27 @@ public class CategoryManagerTest {
.addAsWebInfResource("META-INF/beans.xml", "beans.xml");
}
+ /**
+ * Verifies that a {@link CategoryManager} instance is injected.
+ */
@Test
@InSequence(1)
public void managerIsInjected() {
assertThat(categoryManager, is(not(nullValue())));
}
+ /**
+ * Verifies that an {@link EntityManager} instance is injected.
+ */
@Test
@InSequence(2)
public void entityManagerIsInjected() {
assertThat(entityManager, is(not((nullValue()))));
}
+ /**
+ * Verifies that basic dataset for this test is loadable.
+ */
@Test
@UsingDataSet(
"datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
@@ -180,6 +176,9 @@ public class CategoryManagerTest {
System.out.println("Dataset loaded successfully.");
}
+ /**
+ * Verifies that Shiro is setup properly.
+ */
@Test
@InSequence(20)
public void checkShiro() {
@@ -187,9 +186,14 @@ public class CategoryManagerTest {
assertThat(shiro.getSystemUser(), is(not(nullValue())));
}
+ /**
+ * Verifies that
+ * {@link CategoryManager#addObjectToCategory(org.libreccm.core.CcmObject, org.libreccm.categorization.Category)}
+ * adds an object to a category.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
+ "after-add-obj-to-category.yml",
@@ -206,9 +210,13 @@ public class CategoryManagerTest {
object2, foo));
}
+ /**
+ * Verifies that the authorisation and permission inheritance from the
+ * domain to the categories works.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
+ "after-add-obj-to-category.yml",
@@ -231,9 +239,13 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Verifies that the authorisation and permission inheritance works for
+ * categories.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
+ "after-add-obj-to-category.yml",
@@ -256,9 +268,13 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Verifies that the authorisation and permission inheritance works for
+ * categories, this time with an unauthorised access.
+ */
@Test(expected = UnauthorizedException.class)
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldThrowException(UnauthorizedException.class)
@InSequence(1400)
public void addObjectToCategoryNotAuthorized() {
@@ -271,6 +287,14 @@ public class CategoryManagerTest {
categoryManager.addObjectToCategory(object2, foo);
}
+ /**
+ * Tries to remove an object from a category by using
+ * {@link CategoryManager#removeObjectFromCategory(org.libreccm.core.CcmObject, org.libreccm.categorization.Category)}
+ *
+ * The operation is executed in the system users context.
+ *
+ * @throws ObjectNotAssignedToCategoryException
+ */
@Test
@UsingDataSet(
"datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
@@ -294,9 +318,19 @@ public class CategoryManagerTest {
});
}
+ /**
+ * Tries to remove an object from a category by using
+ * {@link CategoryManager#removeObjectFromCategory(org.libreccm.core.CcmObject, org.libreccm.categorization.Category)}
+ *
+ * This time we are using an author which has been authorised to do so for
+ * the category by a permission set on the {@link Domain} to which the
+ * category belongs.
+ *
+ * @throws ObjectNotAssignedToCategoryException
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
+ "after-remove-obj-from-category.yml",
@@ -321,9 +355,18 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Tries to remove an object from a category by using
+ * {@link CategoryManager#removeObjectFromCategory(org.libreccm.core.CcmObject, org.libreccm.categorization.Category)}
+ *
+ * This time we are using an author which has been authorised to do so for
+ * the category by a permission set on the {@link Category} itself.
+ *
+ * @throws ObjectNotAssignedToCategoryException
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
+ "after-remove-obj-from-category.yml",
@@ -348,9 +391,16 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Tries to remove an object from a category and verifies that a
+ * {@link UnauthorizedException} is thrown if the current user is not
+ * authorised for the operation.
+ *
+ * @throws ObjectNotAssignedToCategoryException
+ */
@Test(expected = UnauthorizedException.class)
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldThrowException(UnauthorizedException.class)
@InSequence(2300)
public void removeObjectFromCategoryNotAuthorized()
@@ -365,9 +415,12 @@ public class CategoryManagerTest {
categoryManager.removeObjectFromCategory(object1, foo);
}
+ /**
+ * Tries to add a sub category to another category.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/"
+ "CategoryManagerTest/after-add-subcategory.yml",
@@ -392,9 +445,13 @@ public class CategoryManagerTest {
() -> categoryManager.addSubCategoryToCategory(sub, foo));
}
+ /**
+ * Tries to add a subcategory to category with authorisation by a permission
+ * set of the {@link Domain} to which the category belongs.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/"
+ "CategoryManagerTest/after-add-subcategory.yml",
@@ -425,9 +482,13 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Tries to add a subcategory to category with authorisation by a permission
+ * set of the category.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/"
+ "CategoryManagerTest/after-add-subcategory.yml",
@@ -458,9 +519,15 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Tries to add a subcategory to a category and verifies that
+ * {@link CategoryManager#addSubCategoryToCategory(org.libreccm.categorization.Category, org.libreccm.categorization.Category)}
+ * throws an {@link UnauthorizedException} if the current user is not
+ * authorised to do that.
+ */
@Test(expected = UnauthorizedException.class)
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldThrowException(UnauthorizedException.class)
@InSequence(3000)
public void addSubCategoryToCategoryNotAuthorized() {
@@ -481,9 +548,13 @@ public class CategoryManagerTest {
categoryManager.addSubCategoryToCategory(sub, foo);
}
+ /**
+ * Tries to remove a subcategory from a category by using
+ * {@link CategoryManager#removeSubCategoryFromCategory(org.libreccm.categorization.Category, org.libreccm.categorization.Category)}.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/"
+ "CategoryManagerTest/after-remove-subcategory.yml",
@@ -497,9 +568,14 @@ public class CategoryManagerTest {
() -> categoryManager.removeSubCategoryFromCategory(bar, foo));
}
+ /**
+ * Tries to remove a subcategory from a category. The user is authorised to
+ * do by a permission set on the {@link Domain} to which the category
+ * belongs.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/"
+ "CategoryManagerTest/after-remove-subcategory.yml",
@@ -519,9 +595,13 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Tries to remove a subcategory from a category. The user is authorised to
+ * do by a permission set on the category.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/"
+ "CategoryManagerTest/after-remove-subcategory.yml",
@@ -541,9 +621,15 @@ public class CategoryManagerTest {
subject.logout();
}
+ /**
+ * Verifies that
+ * {@link CategoryManager#removeSubCategoryFromCategory(org.libreccm.categorization.Category, org.libreccm.categorization.Category)}
+ * throws an {@link UnauthorizedException} if the current user does not have
+ * sufficient permissions to execute the operation.
+ */
@Test(expected = UnauthorizedException.class)
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldThrowException(UnauthorizedException.class)
@InSequence(4000)
public void removeSubCategoryFromCategoryNotAuthorized() {
@@ -553,9 +639,13 @@ public class CategoryManagerTest {
categoryManager.removeSubCategoryFromCategory(bar, foo);
}
+ /**
+ * Verifies that multiple categories (a complete category hierarchy) can be
+ * created without saving each category after the creation of each category.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
+ "after-create-multiple-categories.yml",
@@ -597,9 +687,14 @@ public class CategoryManagerTest {
});
}
+ /**
+ * Verifies that
+ * {@link CategoryManager#hasIndexObject(org.libreccm.categorization.Category)}
+ * returns the expected value.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/categorization/CategoryManagerTest/"
+ + "data.yml")
@InSequence(6000)
public void hasIndexObject() {
final Category category1 = categoryRepo.findById(-2100L);
@@ -609,6 +704,11 @@ public class CategoryManagerTest {
assertThat(categoryManager.hasIndexObject(category2), is(true));
}
+ /**
+ * Tries to retrieve the index object from several categories and verifies
+ * that the expected object is returned by
+ * {@link CategoryManager#getIndexObject(org.libreccm.categorization.Category).
+ */
@Test
@UsingDataSet(
"datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
diff --git a/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java
index 2d0259c19..f537d8f61 100644
--- a/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java
@@ -52,7 +52,7 @@ import static org.junit.Assert.*;
import static org.libreccm.testutils.DependenciesHelpers.*;
/**
- *
+ *
* @author Jens Pelzetter
*/
@org.junit.experimental.categories.Category(IntegrationTest.class)
diff --git a/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java b/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java
index 9e4aab77c..eedb0642e 100644
--- a/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java
+++ b/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java
@@ -20,7 +20,6 @@ package org.libreccm.configuration;
import com.example.TestConfiguration;
-import java.io.File;
import java.math.BigDecimal;
import javax.inject.Inject;
@@ -36,8 +35,6 @@ import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -50,9 +47,11 @@ import org.libreccm.tests.categories.IntegrationTest;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+
import static org.libreccm.testutils.DependenciesHelpers.*;
/**
+ * Tests for the {@link ConfigurationManager}.
*
* @author Jens Pelzetter
*/
@@ -91,18 +90,6 @@ public class ConfigurationManagerTest {
@Deployment
public static WebArchive createDeployment() {
-// final PomEquippedResolveStage pom = Maven
-// .resolver()
-// .loadPomFromFile("pom.xml");
-// final PomEquippedResolveStage dependencies = pom
-// .importCompileAndRuntimeDependencies();
-// final File[] libs = dependencies.resolve().withTransitivity().asFile();
-//
-// for (File lib : libs) {
-// System.err.printf("Adding file '%s' to test archive...%n",
-// lib.getName());
-// }
-
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.libreccm.configuration."
@@ -141,12 +128,18 @@ public class ConfigurationManagerTest {
.addAsWebInfResource("META-INF/beans.xml", "beans.xml");
}
+ /**
+ * Verifies that a {@link ConfigurationManager} instance is injected.
+ */
@Test
@InSequence(1)
public void managerIsInjected() {
assertThat(configurationManager, is(not(nullValue())));
}
+ /**
+ * Verifies if the dataset for this can be loaded.
+ */
@Test
@UsingDataSet(
"datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml")
@@ -155,9 +148,15 @@ public class ConfigurationManagerTest {
System.out.println("Dataset loaded successfully.");
}
+ /**
+ * Tries to load a configuration from the database using the
+ * {@link ConfigurationManager#findConfiguration(java.lang.Class)} method
+ * and verifies that the properties of the configuration class have the
+ * expected values.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/configuration/"
+ + "ConfigurationManagerTest/data.yml")
@InSequence(1100)
public void loadConfiguration() {
final TestExampleConfiguration configuration = configurationManager
@@ -176,12 +175,17 @@ public class ConfigurationManagerTest {
assertThat(configuration.getLanguages(), hasItem("en"));
}
+ /**
+ * Loads a configuration using
+ * {@link ConfigurationManager#findConfiguration(java.lang.Class)} changes
+ * some of the properties and writes the changes back to the database using
+ * {@link ConfigurationManager#saveConfiguration(java.lang.Object)}.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml")
- @ShouldMatchDataSet(
- "datasets/org/libreccm/configuration/ConfigurationManagerTest/"
- + "after-save-changed.yml")
+ @UsingDataSet("datasets/org/libreccm/configuration/"
+ + "ConfigurationManagerTest/data.yml")
+ @ShouldMatchDataSet("datasets/org/libreccm/configuration/"
+ + "ConfigurationManagerTest/after-save-changed.yml")
@InSequence(1200)
public void saveConfiguration() {
final TestExampleConfiguration configuration = configurationManager
@@ -195,9 +199,13 @@ public class ConfigurationManagerTest {
() -> configurationManager.saveConfiguration(configuration));
}
+ /**
+ * Loads a configuration which is not yet in the database an verifies that
+ * all properties of the configuration class have their defaults values.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/configuration/"
+ + "ConfigurationManagerTest/data.yml")
@InSequence(2100)
public void loadNewConfiguration() {
final TestConfiguration configuration = configurationManager
@@ -208,9 +216,13 @@ public class ConfigurationManagerTest {
assertThat(configuration.getItemsPerPage(), is(40L));
}
+ /**
+ * Loads a configuration which is not yet in the database and saves this
+ * configuration to the database.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/configuration/"
+ + "ConfigurationManagerTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/configuration/"
+ "ConfigurationManagerTest/after-save-new.yml",
diff --git a/ccm-core/src/test/java/org/libreccm/configuration/DatasetsTest.java b/ccm-core/src/test/java/org/libreccm/configuration/DatasetsTest.java
index afab984f4..d788721b4 100644
--- a/ccm-core/src/test/java/org/libreccm/configuration/DatasetsTest.java
+++ b/ccm-core/src/test/java/org/libreccm/configuration/DatasetsTest.java
@@ -34,20 +34,20 @@ import org.libreccm.testutils.DatasetsVerifier;
import static org.libreccm.testutils.DatasetType.*;
/**
+ * Ensures that all datasets used by the tests in this package are valid.
*
* @author Jens Pelzetter
*/
@RunWith(Parameterized.class)
@Category(UnitTest.class)
public class DatasetsTest extends DatasetsVerifier {
-
+
@Parameterized.Parameters(name = "Dataset {0}")
public static Collection data() {
return Arrays.asList(new String[]{
"/datasets/org/libreccm/configuration/ConfigurationManagerTest/after-save-changed.yml",
"/datasets/org/libreccm/configuration/ConfigurationManagerTest/after-save-new.yml",
- "/datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml",
- });
+ "/datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml",});
}
public DatasetsTest(final String datasetPath) {
@@ -79,5 +79,5 @@ public class DatasetsTest extends DatasetsVerifier {
@After
public void tearDown() {
}
-
+
}
diff --git a/ccm-core/src/test/java/org/libreccm/configuration/EqualsAndHashCodeTest.java b/ccm-core/src/test/java/org/libreccm/configuration/EqualsAndHashCodeTest.java
index 00bacf2a3..2c4bd15d9 100644
--- a/ccm-core/src/test/java/org/libreccm/configuration/EqualsAndHashCodeTest.java
+++ b/ccm-core/src/test/java/org/libreccm/configuration/EqualsAndHashCodeTest.java
@@ -27,7 +27,9 @@ import org.libreccm.tests.categories.UnitTest;
import org.libreccm.testutils.EqualsVerifier;
/**
- *
+ * Verifies the implementations of the {@code equals} and {@code hashCode}
+ * methods of several classes in this package.
+ *
* @author Jens Pelzetter
*/
@RunWith(Parameterized.class)
diff --git a/ccm-core/src/test/java/org/libreccm/configuration/TestExampleConfiguration.java b/ccm-core/src/test/java/org/libreccm/configuration/TestExampleConfiguration.java
index 4d0c76b7b..efaa52fd6 100644
--- a/ccm-core/src/test/java/org/libreccm/configuration/TestExampleConfiguration.java
+++ b/ccm-core/src/test/java/org/libreccm/configuration/TestExampleConfiguration.java
@@ -23,7 +23,8 @@ import java.util.Collections;
import java.util.Set;
/**
- *
+ * An example configuration used by {@link ConfigurationManagerTest}.
+ *
* @author Jens Pelzetter
*/
@Configuration
diff --git a/ccm-core/src/test/java/org/libreccm/configuration/ToStringTest.java b/ccm-core/src/test/java/org/libreccm/configuration/ToStringTest.java
index 47a2d41a7..4f92ca584 100644
--- a/ccm-core/src/test/java/org/libreccm/configuration/ToStringTest.java
+++ b/ccm-core/src/test/java/org/libreccm/configuration/ToStringTest.java
@@ -18,17 +18,9 @@
*/
package org.libreccm.configuration;
-import org.libreccm.configuration.StringSetting;
-import org.libreccm.configuration.LocalizedStringSetting;
-import org.libreccm.configuration.ConfigurationInfo;
-import org.libreccm.configuration.EnumSetting;
-import org.libreccm.configuration.DoubleSetting;
-import org.libreccm.configuration.BigDecimalSetting;
-import org.libreccm.configuration.LongSetting;
-import org.libreccm.configuration.SettingInfo;
-import org.libreccm.configuration.BooleanSetting;
import java.util.Arrays;
import java.util.Collection;
+
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -36,7 +28,9 @@ import org.libreccm.tests.categories.UnitTest;
import org.libreccm.testutils.ToStringVerifier;
/**
- *
+ * Checks the implementation of the {@code toString} method of several classes
+ * in this package for {@link NullPointerException} and similar errors.
+ *
* @author Jens Pelzetter
*/
@RunWith(Parameterized.class)
diff --git a/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
index 3bc070e5d..efb67b76d 100644
--- a/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
@@ -33,8 +33,6 @@ import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -44,7 +42,6 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.libreccm.tests.categories.IntegrationTest;
-import java.io.File;
import java.util.List;
import javax.inject.Inject;
@@ -52,9 +49,12 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import static org.junit.Assert.*;
+
import static org.libreccm.testutils.DependenciesHelpers.*;
/**
+ * Tests for the {@link CcmObjectRepository} which is the foundation for many
+ * other repositories in LibreCCM.
*
* @author Jens Pelzetter
*/
@@ -120,37 +120,53 @@ public class CcmObjectRepositoryTest {
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
}
+ /**
+ * Verify that an {@link CcmObjectRepository} instance is injected.
+ */
@Test
@InSequence(1)
public void repoIsInjected() {
assertThat(ccmObjectRepository, is(not((nullValue()))));
}
+ /**
+ * Verify that an {@link EntityManager} is injected.
+ */
@Test
@InSequence(2)
public void entityManagerIsInjected() {
assertThat(entityManager, is(not((nullValue()))));
}
+ /**
+ * Verify that the basic dataset loads successfully.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@InSequence(3)
public void datasetOnly() {
System.out.println("Dataset loaded successfully.");
}
+ /**
+ * Verify that the {@code after-save-changed.yml} dataset loads
+ * successfully.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-changed.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/"
+ + "after-save-changed.yml")
@InSequence(4)
public void datasetOnly2() {
System.out.println("Dataset loaded successfully.");
}
+ /**
+ * Tries to find several objects by using
+ * {@link EntityManager#find(java.lang.Class, java.lang.Object)} with a
+ * value of type {@code long}.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@InSequence(5)
public void entityManagerFindCcmObjectByLongPrimitive() {
final CcmObject obj1 = entityManager.find(CcmObject.class, -10L);
@@ -173,19 +189,24 @@ public class CcmObjectRepositoryTest {
assertThat(none, is(nullValue()));
}
+ /**
+ * Tries to find several objects by using
+ * {@link EntityManager#find(java.lang.Class, java.lang.Object)} with a
+ * value of type {@link Long}.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@InSequence(6)
public void entityManagerFindCcmObjectByLongClass() {
- final CcmObject obj1 = entityManager.find(CcmObject.class,
- new Long(-10L));
- final CcmObject obj2 = entityManager.find(CcmObject.class,
- new Long(-20L));
- final CcmObject obj3 = entityManager.find(CcmObject.class,
- new Long(-30L));
- final CcmObject none = entityManager.find(CcmObject.class, new Long(
- -999L));
+ final Long id1 = -10L;
+ final Long id2 = -20L;
+ final Long id3 = -30L;
+ final Long id4 = -999L;
+
+ final CcmObject obj1 = entityManager.find(CcmObject.class, id1);
+ final CcmObject obj2 = entityManager.find(CcmObject.class, id2);
+ final CcmObject obj3 = entityManager.find(CcmObject.class, id3);
+ final CcmObject none = entityManager.find(CcmObject.class, id4);
assertThat(obj1, is(not(nullValue())));
assertThat(obj1.getObjectId(), is(-10L));
@@ -203,8 +224,7 @@ public class CcmObjectRepositoryTest {
}
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@InSequence(10)
public void findCcmObjectById() {
final CcmObject obj1 = ccmObjectRepository.findById(-10L);
@@ -227,9 +247,12 @@ public class CcmObjectRepositoryTest {
assertThat(none, is(nullValue()));
}
+ /**
+ * Tries to find all {@link CcmObject}s in the test database by using
+ * {@link CcmObjectRepository#findAll()}.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@InSequence(10)
public void findAllCcmObjects() {
final List objects = ccmObjectRepository.findAll();
@@ -237,9 +260,13 @@ public class CcmObjectRepositoryTest {
assertThat(objects.size(), is(3));
}
+ /**
+ * Tries to save a new {@link CcmObject} using
+ * {@link CcmObjectRepository#save(java.lang.Object)} and verifes that it is
+ * saved to the * database.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
+ "after-save-new.yml",
@@ -252,9 +279,14 @@ public class CcmObjectRepositoryTest {
ccmObjectRepository.save(obj);
}
+ /**
+ * Changes some values of one of the {@link CcmObject}s in the test
+ * database, saves the changes to the database by using
+ * {@link CcmObjectRepository#save(java.lang.Object)} and verifies that the
+ * changes have been written to the database.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
+ "after-save-changed.yml",
@@ -267,6 +299,11 @@ public class CcmObjectRepositoryTest {
ccmObjectRepository.save(obj);
}
+ /**
+ * Verifies that {@link CcmObjectRepository#save(java.lang.Object)} throws a
+ * {@link IllegalArgumentException} if called with {@code null} as the
+ * object to save.
+ */
@Test(expected = IllegalArgumentException.class)
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(500)
@@ -274,9 +311,13 @@ public class CcmObjectRepositoryTest {
ccmObjectRepository.save(null);
}
+ /**
+ * Deletes one of the {@link CcmObject}s in the database by using
+ * {@link CcmObjectRepository#delete(java.lang.Object)} and verifies that
+ * the object has been removed from the test database.
+ */
@Test
- @UsingDataSet(
- "datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
+ @UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/core/CcmObjectRepositoryTest/"
+ "after-delete.yml",
@@ -288,6 +329,11 @@ public class CcmObjectRepositoryTest {
ccmObjectRepository.delete(obj);
}
+ /**
+ * Verifies that {@link CcmObjectRepository#delete(java.lang.Object)} throws
+ * a {@link IllegalArgumentException} if called with {@link null} for the
+ * object to delete.
+ */
@Test(expected = IllegalArgumentException.class)
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(700)
diff --git a/ccm-core/src/test/java/org/libreccm/core/DatasetsTest.java b/ccm-core/src/test/java/org/libreccm/core/DatasetsTest.java
index 44ea7a767..914d84527 100644
--- a/ccm-core/src/test/java/org/libreccm/core/DatasetsTest.java
+++ b/ccm-core/src/test/java/org/libreccm/core/DatasetsTest.java
@@ -32,7 +32,8 @@ import java.util.Arrays;
import java.util.Collection;
/**
- *
+ * Verifies that datasets used by the tests in this package.
+ *
* @author Jens Pelzetter
*/
@RunWith(Parameterized.class)
diff --git a/ccm-core/src/test/java/org/libreccm/core/EntitiesTestCore.java b/ccm-core/src/test/java/org/libreccm/core/EntitiesTestCore.java
index b8ed303b3..10e553ad1 100644
--- a/ccm-core/src/test/java/org/libreccm/core/EntitiesTestCore.java
+++ b/ccm-core/src/test/java/org/libreccm/core/EntitiesTestCore.java
@@ -18,6 +18,8 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
/**
+ * Verifies the implementions of {@code hashCode}, {@code equals} and
+ * {@code toString}.
*
* @author Jens Pelzetter
*/
diff --git a/ccm-core/src/test/java/org/libreccm/core/EqualsAndHashCodeTest.java b/ccm-core/src/test/java/org/libreccm/core/EqualsAndHashCodeTest.java
index b5bb0a891..13dce05d7 100644
--- a/ccm-core/src/test/java/org/libreccm/core/EqualsAndHashCodeTest.java
+++ b/ccm-core/src/test/java/org/libreccm/core/EqualsAndHashCodeTest.java
@@ -32,6 +32,8 @@ import org.libreccm.security.User;
import org.libreccm.testutils.EqualsVerifier;
/**
+ * Verifies implementions of {@code equals} and {@code hashCode} for the
+ * entities in the {@code org.libreccm.core} package.
*
* @author Jens Pelzetter
*/
diff --git a/ccm-core/src/test/java/org/libreccm/core/ResourceEntityTest.java b/ccm-core/src/test/java/org/libreccm/core/ResourceEntityTest.java
index cb528874a..7e6bcb611 100644
--- a/ccm-core/src/test/java/org/libreccm/core/ResourceEntityTest.java
+++ b/ccm-core/src/test/java/org/libreccm/core/ResourceEntityTest.java
@@ -18,12 +18,6 @@
*/
package org.libreccm.core;
-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.runner.RunWith;
import org.junit.runners.Parameterized;
import org.libreccm.categorization.Category;
@@ -39,6 +33,10 @@ import java.util.Collection;
import java.util.Locale;
/**
+ * Verifies the implementation {@code equals} and {@code hashCode} of the
+ * {@link Resource} class. Separated from the tests in
+ * {@link EqualsAndHashCodeTest} because we need another setup in {@link #addPrefabValues(nl.jqno.equalsverifier.EqualsVerifier)
+ * for testing {@link Resource}.
*
* @author Jens Pelzetter
*/
diff --git a/ccm-core/src/test/java/org/libreccm/core/ToStringTest.java b/ccm-core/src/test/java/org/libreccm/core/ToStringTest.java
index 6e5c0c4cf..4f6a7b06d 100644
--- a/ccm-core/src/test/java/org/libreccm/core/ToStringTest.java
+++ b/ccm-core/src/test/java/org/libreccm/core/ToStringTest.java
@@ -28,34 +28,34 @@ import java.util.Arrays;
import java.util.Collection;
/**
+ * Checks the implemention of the {@code toString} method of the entities in
+ * this package for {@link NullPointerException}.
*
* @author Jens Pelzetter
*/
@RunWith(Parameterized.class)
@Category(UnitTest.class)
public class ToStringTest extends ToStringVerifier {
-
+
@Parameterized.Parameters(name = "{0}")
public static Collection> data() {
return Arrays.asList(new Class>[]{
CcmObject.class,
EmailAddress.class,
-// GroupMembership.class,
-// Subject.class,
-// Permission.class,
-// PersonName.class,
-// Privilege.class,
+ // GroupMembership.class,
+ // Subject.class,
+ // Permission.class,
+ // PersonName.class,
+ // Privilege.class,
Resource.class,
- ResourceType.class,
-// Role.class,
-// User.class,
-// Group.class
+ ResourceType.class, // Role.class,
+ // User.class,
+ // Group.class
});
}
public ToStringTest(final Class> entityClass) {
super(entityClass);
}
-
}