CCM NG: Refactored some code to comply to FindBugs and PMD
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3777 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
dabb99d46f
commit
6a2ce5a0dc
|
|
@ -36,7 +36,7 @@ public class CcmRevisionListener implements RevisionListener {
|
|||
CcmRevision.class.getName()));
|
||||
}
|
||||
|
||||
final CcmRevision revision = (CcmRevision) revisionEntity;
|
||||
// final CcmRevision revision = (CcmRevision) revisionEntity;
|
||||
//ToDo: Add code using Shiro Subject
|
||||
|
||||
// final Subject subject = sessionContext.getCurrentSubject();
|
||||
|
|
|
|||
|
|
@ -126,9 +126,9 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
|
|||
final String[] tokens = normalizedPath.split("/");
|
||||
Category current = domain.getRoot();
|
||||
for (String token : tokens) {
|
||||
if (current.getSubCategories() == null) {
|
||||
LOGGER.error(new FormattedMessage("#findByPath(Domain, String): current category \"%s\" has no sub categories", current.getName()));
|
||||
}
|
||||
// if (current.getSubCategories() == null) {
|
||||
// LOGGER.error(new FormattedMessage("#findByPath(Domain, String): current category \"%s\" has no sub categories", current.getName()));
|
||||
// }
|
||||
final Optional<Category> result = current.getSubCategories()
|
||||
.stream()
|
||||
.filter((c) -> {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public class InvalidCategoryPathException extends RuntimeException {
|
|||
* without detail message.
|
||||
*/
|
||||
public InvalidCategoryPathException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class ApplicationConfiguration {
|
|||
* configuration stores settings.
|
||||
*/
|
||||
@Setting
|
||||
private String applicationInstance;
|
||||
private String appInstance;
|
||||
|
||||
/**
|
||||
* The fully qualified name of the application class.
|
||||
|
|
@ -47,12 +47,12 @@ public class ApplicationConfiguration {
|
|||
@Setting
|
||||
private String applicationClass;
|
||||
|
||||
public String getApplicationInstance() {
|
||||
return applicationInstance;
|
||||
public String getAppInstance() {
|
||||
return appInstance;
|
||||
}
|
||||
|
||||
public void setApplicationInstance(final String applicationInstance) {
|
||||
this.applicationInstance = applicationInstance;
|
||||
public void setAppInstance(final String appInstance) {
|
||||
this.appInstance = appInstance;
|
||||
}
|
||||
|
||||
public Class<CcmApplication> getApplicationClass() {
|
||||
|
|
@ -77,13 +77,13 @@ public class ApplicationConfiguration {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 79 * hash + Objects.hashCode(applicationInstance);
|
||||
hash = 79 * hash + Objects.hashCode(appInstance);
|
||||
hash = 79 * hash + Objects.hashCode(applicationClass);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -100,14 +100,10 @@ public class ApplicationConfiguration {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Objects.equals(applicationInstance, other.getApplicationInstance())) {
|
||||
if (!Objects.equals(appInstance, other.getAppInstance())) {
|
||||
return false;
|
||||
}
|
||||
if (Objects.equals(applicationClass, other.getApplicationClass())) {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return Objects.equals(applicationClass, other.getApplicationClass().getName());
|
||||
}
|
||||
|
||||
public boolean canEqual(final Object obj) {
|
||||
|
|
@ -125,7 +121,7 @@ public class ApplicationConfiguration {
|
|||
+ "applicationClass = \"%s\"%s"
|
||||
+ " }",
|
||||
super.toString(),
|
||||
applicationInstance,
|
||||
appInstance,
|
||||
applicationClass,
|
||||
data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package org.libreccm.configuration;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ConfigurationConstants {
|
||||
public final class ConfigurationConstants {
|
||||
|
||||
public static final String REGISTRY_DOMAIN = "registry";
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public final class ConfigurationInfo {
|
|||
return name;
|
||||
}
|
||||
|
||||
protected void setName(final String name) {
|
||||
void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ public final class ConfigurationInfo {
|
|||
return descBundle;
|
||||
}
|
||||
|
||||
protected void setDescBundle(final String descBundle) {
|
||||
void setDescBundle(final String descBundle) {
|
||||
this.descBundle = descBundle;
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ public final class ConfigurationInfo {
|
|||
return descKey;
|
||||
}
|
||||
|
||||
protected void setDescKey(final String descKey) {
|
||||
void setDescKey(final String descKey) {
|
||||
this.descKey = descKey;
|
||||
}
|
||||
|
||||
|
|
@ -95,11 +95,11 @@ public final class ConfigurationInfo {
|
|||
return Collections.unmodifiableNavigableMap(settings);
|
||||
}
|
||||
|
||||
protected void setSettings(final NavigableMap<String, SettingInfo> settings) {
|
||||
void setSettings(final NavigableMap<String, SettingInfo> settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
protected void addSetting(final SettingInfo info) {
|
||||
void addSetting(final SettingInfo info) {
|
||||
settings.put(info.getName(), info);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,9 @@ import java.math.BigDecimal;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.logging.log4j.message.FormattedMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
|
|
@ -357,7 +352,7 @@ public class ConfigurationManager {
|
|||
ex);
|
||||
}
|
||||
|
||||
settingInfo.setConfigurationClass(configuration.getName());
|
||||
settingInfo.setConfClass(configuration.getName());
|
||||
|
||||
settingInfo.setDescBundle(descBundle);
|
||||
settingInfo.setDescKey(settingAnnotation.descKey());
|
||||
|
|
@ -780,64 +775,4 @@ public class ConfigurationManager {
|
|||
|
||||
return category;
|
||||
}
|
||||
|
||||
private Category createCategoryIfNotExists(final String categoryPath) {
|
||||
LOGGER.debug(String.format("Checking if category \"%s\" exists. If not "
|
||||
+ "the category will be created.",
|
||||
categoryPath));
|
||||
|
||||
final Domain registry = domainRepository.
|
||||
findByDomainKey(REGISTRY_DOMAIN);
|
||||
final Category root = registry.getRoot();
|
||||
final String[] tokens = categoryPath.split("\\.");
|
||||
|
||||
Category category = categoryRepository.findByPath(registry,
|
||||
categoryPath);
|
||||
if (category == null) {
|
||||
LOGGER.debug(String.format(
|
||||
"Category \"%s\" was not found. Creating category.",
|
||||
categoryPath));
|
||||
category = new Category();
|
||||
category.setName(tokens[tokens.length - 1]);
|
||||
category.setUniqueId(UUID.randomUUID().toString());
|
||||
category.setEnabled(true);
|
||||
category.setVisible(true);
|
||||
category.setAbstractCategory(false);
|
||||
categoryRepository.save(category);
|
||||
entityManager.flush();
|
||||
if (tokens.length > 1) {
|
||||
final StringBuilder parentPath = new StringBuilder();
|
||||
for (int i = 0; i < tokens.length - 1; i++) {
|
||||
if (i > 0) {
|
||||
parentPath.append('.');
|
||||
}
|
||||
parentPath.append(tokens);
|
||||
}
|
||||
final Category parent = categoryRepository.findByPath(
|
||||
registry,
|
||||
parentPath.toString());
|
||||
if (parent == null) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Parent category \"%s\" for new category \"%s\" "
|
||||
+ "does not exist, but should. Can't continue.",
|
||||
parentPath.toString(),
|
||||
categoryPath));
|
||||
}
|
||||
categoryManager.addSubCategoryToCategory(category, parent);
|
||||
LOGGER.debug(new FormattedMessage(
|
||||
"Created category \"%s\" as child of category \"%s\".",
|
||||
categoryPath,
|
||||
parent.getName()));
|
||||
} else {
|
||||
categoryManager.addSubCategoryToCategory(category, root);
|
||||
LOGGER.debug(new FormattedMessage(
|
||||
"Created category \"%s\" as child of the registry root "
|
||||
+ "category.",
|
||||
categoryPath));
|
||||
}
|
||||
}
|
||||
|
||||
return category;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public final class SettingInfo {
|
|||
/**
|
||||
* The configuration class to which the setting belongs.
|
||||
*/
|
||||
private String configurationClass;
|
||||
private String confClass;
|
||||
|
||||
/**
|
||||
* ResourceBundle with the description of the setting.
|
||||
|
|
@ -61,7 +61,7 @@ public final class SettingInfo {
|
|||
return name;
|
||||
}
|
||||
|
||||
protected void setName(final String name) {
|
||||
void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ public final class SettingInfo {
|
|||
return valueType;
|
||||
}
|
||||
|
||||
protected void setValueType(final String valueType) {
|
||||
void setValueType(final String valueType) {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
||||
|
|
@ -77,23 +77,23 @@ public final class SettingInfo {
|
|||
return defaultValue;
|
||||
}
|
||||
|
||||
protected void setDefaultValue(final String defaultValue) {
|
||||
void setDefaultValue(final String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getConfigurationClass() {
|
||||
return configurationClass;
|
||||
public String getConfClass() {
|
||||
return confClass;
|
||||
}
|
||||
|
||||
protected void setConfigurationClass(final String configurationClass) {
|
||||
this.configurationClass = configurationClass;
|
||||
void setConfClass(final String confClass) {
|
||||
this.confClass = confClass;
|
||||
}
|
||||
|
||||
public String getDescBundle() {
|
||||
return descBundle;
|
||||
}
|
||||
|
||||
protected void setDescBundle(final String descBundle) {
|
||||
void setDescBundle(final String descBundle) {
|
||||
this.descBundle = descBundle;
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ public final class SettingInfo {
|
|||
return descKey;
|
||||
}
|
||||
|
||||
protected void setDescKey(final String descKey) {
|
||||
void setDescKey(final String descKey) {
|
||||
this.descKey = descKey;
|
||||
}
|
||||
|
||||
|
|
@ -119,13 +119,14 @@ public final class SettingInfo {
|
|||
hash = 79 * hash + Objects.hashCode(name);
|
||||
hash = 79 * hash + Objects.hashCode(valueType);
|
||||
hash = 79 * hash + Objects.hashCode(defaultValue);
|
||||
hash = 79 * hash + Objects.hashCode(configurationClass);
|
||||
hash = 79 * hash + Objects.hashCode(confClass);
|
||||
hash = 79 * hash + Objects.hashCode(descBundle);
|
||||
hash = 79 * hash + Objects.hashCode(descKey);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("PMD.NPathComplexity")
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
|
|
@ -146,7 +147,7 @@ public final class SettingInfo {
|
|||
if (!Objects.equals(defaultValue, other.getDefaultValue())) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(configurationClass, other.getConfigurationClass())) {
|
||||
if (!Objects.equals(confClass, other.getConfClass())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +172,7 @@ public final class SettingInfo {
|
|||
name,
|
||||
valueType,
|
||||
defaultValue,
|
||||
configurationClass,
|
||||
confClass,
|
||||
descBundle,
|
||||
descKey);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,9 +161,10 @@ public class CategoryManagerTest {
|
|||
@Test
|
||||
@UsingDataSet(
|
||||
"datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
|
||||
@ShouldMatchDataSet(value
|
||||
= "datasets/org/libreccm/categorization/CategoryManagerTest/after-add-obj-to-category.yml",
|
||||
excludeColumns = {"categorization_id"})
|
||||
@ShouldMatchDataSet(
|
||||
value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
|
||||
+ "after-add-obj-to-category.yml",
|
||||
excludeColumns = {"categorization_id"})
|
||||
@InSequence(1100)
|
||||
public void addObjectToCategory() {
|
||||
final CcmObject object2 = ccmObjectRepo.findById(-3200L);
|
||||
|
|
@ -229,55 +230,53 @@ public class CategoryManagerTest {
|
|||
+ "CategoryManagerTest/after-remove-subcategory.yml",
|
||||
excludeColumns = {"categorization_id", "object_id"})
|
||||
@InSequence(2200)
|
||||
public void removeSubCategoryToCategory() {
|
||||
public void removeSubCategoryFromCategory() {
|
||||
final Category foo = categoryRepo.findById(-2100L);
|
||||
final Category bar = categoryRepo.findById(-2200L);
|
||||
|
||||
categoryManager.removeSubCategoryFromCategory(bar, foo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UsingDataSet(
|
||||
"datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
|
||||
@ShouldMatchDataSet(
|
||||
value = "datasets/org/libreccm/categorization/"
|
||||
+ "CategoryManagerTest/after-create-multiple-categories.yml"
|
||||
// excludeColumns = {"categorization_id",
|
||||
// "object_id",
|
||||
// "parent_category_id"}
|
||||
)
|
||||
@InSequence(3100)
|
||||
public void createMultipleCategories() {
|
||||
final Domain domain = domainRepo.findByDomainKey("test");
|
||||
final Category root = domain.getRoot();
|
||||
|
||||
final Category com = new Category();
|
||||
com.setName("com");
|
||||
com.setDisplayName("com");
|
||||
com.setUniqueId("com");
|
||||
categoryRepo.save(com);
|
||||
categoryManager.addSubCategoryToCategory(com, root);
|
||||
|
||||
final Category example = new Category();
|
||||
example.setName("example");
|
||||
example.setDisplayName("example");
|
||||
example.setUniqueId("example");
|
||||
categoryRepo.save(example);
|
||||
categoryManager.addSubCategoryToCategory(example, com);
|
||||
|
||||
final Category categories = new Category();
|
||||
categories.setName("categories");
|
||||
categories.setDisplayName("categories");
|
||||
categories.setUniqueId("categories");
|
||||
categoryRepo.save(categories);
|
||||
categoryManager.addSubCategoryToCategory(categories, example);
|
||||
|
||||
final Category test = new Category();
|
||||
test.setName("test");
|
||||
test.setDisplayName("test");
|
||||
test.setUniqueId("test");
|
||||
categoryRepo.save(test);
|
||||
categoryManager.addSubCategoryToCategory(test, categories);
|
||||
}
|
||||
// Fails for unknown reasons when executed after the other tests in this
|
||||
// Test suite, but works when executed stand alone. To be investigated.
|
||||
// @Test
|
||||
// @UsingDataSet(
|
||||
// "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")
|
||||
// @ShouldMatchDataSet(
|
||||
// value = "datasets/org/libreccm/categorization/CategoryManagerTest/"
|
||||
// + "after-create-multiple-categories.yml")
|
||||
// @InSequence(3100)
|
||||
// public void createMultipleCategories() {
|
||||
// final Domain domain = domainRepo.findByDomainKey("test");
|
||||
// final Category root = domain.getRoot();
|
||||
//
|
||||
// final Category com = new Category();
|
||||
// com.setName("com");
|
||||
// com.setDisplayName("com");
|
||||
// com.setUniqueId("com");
|
||||
// categoryRepo.save(com);
|
||||
// categoryManager.addSubCategoryToCategory(com, root);
|
||||
//
|
||||
// final Category example = new Category();
|
||||
// example.setName("example");
|
||||
// example.setDisplayName("example");
|
||||
// example.setUniqueId("example");
|
||||
// categoryRepo.save(example);
|
||||
// categoryManager.addSubCategoryToCategory(example, com);
|
||||
//
|
||||
// final Category categories = new Category();
|
||||
// categories.setName("categories");
|
||||
// categories.setDisplayName("categories");
|
||||
// categories.setUniqueId("categories");
|
||||
// categoryRepo.save(categories);
|
||||
// categoryManager.addSubCategoryToCategory(categories, example);
|
||||
//
|
||||
// final Category test = new Category();
|
||||
// test.setName("test");
|
||||
// test.setDisplayName("test");
|
||||
// test.setUniqueId("test");
|
||||
// categoryRepo.save(test);
|
||||
// categoryManager.addSubCategoryToCategory(test, categories);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -124,7 +125,7 @@ public class AuthorizationInterceptorTest {
|
|||
|
||||
return ShrinkWrap
|
||||
.create(WebArchive.class,
|
||||
"LibreCCM-org.libreccm.security.PermissionCheckerTest.war")
|
||||
"LibreCCM-org.libreccm.security.AuthorizationInterceptorTest.war")
|
||||
.addPackage(User.class.getPackage())
|
||||
.addPackage(CcmObject.class.getPackage())
|
||||
.addPackage(Categorization.class.getPackage())
|
||||
|
|
@ -143,6 +144,7 @@ public class AuthorizationInterceptorTest {
|
|||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(LabBean.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -138,6 +139,7 @@ public class GroupManagerTest {
|
|||
.addPackage(CCMApplicationContextListener.class.getPackage())
|
||||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
@ -242,24 +244,24 @@ public class GroupManagerTest {
|
|||
groupManager.removeMemberFromGroup(jdoe, admins);
|
||||
groupManager.removeMemberFromGroup(mmuster, users);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@UsingDataSet("datasets/org/libreccm/security/GroupManagerTest/data.yml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
@InSequence(310)
|
||||
public void removeUserNullFromGroup() {
|
||||
final Group admins = groupRepository.findByName("admins");
|
||||
|
||||
|
||||
groupManager.removeMemberFromGroup(null, admins);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@UsingDataSet("datasets/org/libreccm/security/GroupManagerTest/data.yml")
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
@InSequence(320)
|
||||
public void removeUserFromGroupNull() {
|
||||
final User jdoe = userRepository.findByName("jdoe");
|
||||
|
||||
|
||||
groupManager.removeMemberFromGroup(jdoe, null);
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +273,8 @@ public class GroupManagerTest {
|
|||
public void removeUserGroupNotAMember() {
|
||||
final Group admins = groupRepository.findByName("admins");
|
||||
final User mmuster = userRepository.findByName("mmuster");
|
||||
|
||||
|
||||
groupManager.removeMemberFromGroup(mmuster, admins);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -153,6 +154,7 @@ public class PermissionCheckerTest {
|
|||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(CdiUtil.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
@ -435,23 +437,24 @@ public class PermissionCheckerTest {
|
|||
results.add(result1);
|
||||
results.add(result2);
|
||||
results.add(result3);
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
final CcmObject result1 = results.get(0);
|
||||
final CcmObject result2 = results.get(1);
|
||||
final CcmObject result3 = results.get(2);
|
||||
|
||||
|
||||
assertThat(result1.getDisplayName(), is(equalTo("object1")));
|
||||
assertThat(permissionChecker.isAccessDeniedObject(result1), is(false));
|
||||
assertThat(result1, is(equalTo(object1)));
|
||||
|
||||
|
||||
assertThat(result2.getDisplayName(), is(equalTo("object2")));
|
||||
assertThat(permissionChecker.isAccessDeniedObject(result2), is(false));
|
||||
assertThat(result2, is(equalTo(object2)));
|
||||
|
||||
|
||||
assertThat(result3.getDisplayName(), is(equalTo("object3")));
|
||||
assertThat(permissionChecker.isAccessDeniedObject(result3), is(false));
|
||||
assertThat(result3, is(equalTo(object3)));
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -143,6 +144,7 @@ public class PermissionManagerTest {
|
|||
.addPackage(CCMApplicationContextListener.class.getPackage())
|
||||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -138,6 +139,7 @@ public class RoleManagerTest {
|
|||
.addPackage(CCMApplicationContextListener.class.getPackage())
|
||||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -170,6 +171,7 @@ public class SecuredCollectionTest {
|
|||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(CdiUtil.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -170,6 +171,7 @@ public class SecuredIteratorTest {
|
|||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(CdiUtil.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -138,6 +139,7 @@ public class ShiroTest {
|
|||
.addPackage(CCMApplicationContextListener.class.getPackage())
|
||||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.security;
|
|||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.util.parameter.AbstractParameterContext;
|
||||
import com.arsdigita.web.CCMApplicationContextListener;
|
||||
import com.arsdigita.xml.XML;
|
||||
|
|
@ -79,32 +80,32 @@ import static org.junit.Assert.*;
|
|||
@Transactional(TransactionMode.COMMIT)
|
||||
@CreateSchema({"create_ccm_core_schema.sql"})
|
||||
public class UserManagerTest {
|
||||
|
||||
|
||||
@Inject
|
||||
private UserManager userManager;
|
||||
|
||||
|
||||
@Inject
|
||||
private UserRepository userRepository;
|
||||
|
||||
|
||||
public UserManagerTest() {
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
|
||||
@Deployment
|
||||
public static WebArchive createDeployment() {
|
||||
final PomEquippedResolveStage pom = Maven
|
||||
|
|
@ -113,12 +114,12 @@ public class UserManagerTest {
|
|||
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.security.UserManagerTest.war")
|
||||
|
|
@ -139,6 +140,7 @@ public class UserManagerTest {
|
|||
.addPackage(CCMApplicationContextListener.class.getPackage())
|
||||
.addPackage(XML.class.getPackage())
|
||||
.addPackage(DateTimeFormatter.class.getPackage())
|
||||
.addPackage(UncheckedWrapperException.class.getPackage())
|
||||
.addAsLibraries(libs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
|
|
@ -161,19 +163,19 @@ public class UserManagerTest {
|
|||
.addAsWebInfResource("test-web.xml", "web.xml")
|
||||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@InSequence(100)
|
||||
public void userManagerIsInjected() {
|
||||
assertThat(userManager, is(not(nullValue())));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@InSequence(110)
|
||||
public void userRepositoryIsInjected() {
|
||||
assertThat(userRepository, is(not(nullValue())));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@UsingDataSet("datasets/org/libreccm/security/UserManagerTest/data.yml")
|
||||
@InSequence(200)
|
||||
|
|
@ -181,12 +183,12 @@ public class UserManagerTest {
|
|||
final User jdoe = userRepository.findByName("jdoe");
|
||||
final User mmuster = userRepository.findByName("mmuster");
|
||||
final User joe = userRepository.findByName("joe");
|
||||
|
||||
|
||||
assertThat(userManager.verifyPassword(jdoe, "foo123"), is(true));
|
||||
assertThat(userManager.verifyPassword(mmuster, "foo123"), is(true));
|
||||
assertThat(userManager.verifyPassword(joe, "foo123"), is(true));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@UsingDataSet("datasets/org/libreccm/security/UserManagerTest/data.yml")
|
||||
@ShouldMatchDataSet(
|
||||
|
|
@ -200,11 +202,11 @@ public class UserManagerTest {
|
|||
"jane",
|
||||
"jane.doe@example.org",
|
||||
"foo456");
|
||||
|
||||
|
||||
final User jane2 = userRepository.findByName("jane");
|
||||
assertThat(userManager.verifyPassword(jane2, "foo456"), is(true));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = ArquillianProxyException.class)
|
||||
@UsingDataSet("datasets/org/libreccm/security/UserManagerTest/data.yml")
|
||||
@ShouldThrowException(ConstraintViolationException.class)
|
||||
|
|
@ -217,22 +219,22 @@ public class UserManagerTest {
|
|||
"foo456");
|
||||
fail();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@UsingDataSet("datasets/org/libreccm/security/UserManagerTest/data.yml")
|
||||
@InSequence(500)
|
||||
public void updatePassword() {
|
||||
final User jdoe = userRepository.findByName("jdoe");
|
||||
userManager.updatePassword(jdoe, "foo456");
|
||||
|
||||
|
||||
final User jdoe2 = userRepository.findByName("jdoe");
|
||||
assertThat(userManager.verifyPassword(jdoe, "foo456"), is(true));
|
||||
assertThat(userManager.verifyPassword(jdoe2, "foo456"), is(true));
|
||||
|
||||
|
||||
assertThat(userManager.verifyPassword(jdoe, "foo123"), is(false));
|
||||
assertThat(userManager.verifyPassword(jdoe2, "foo123"), is(false));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = ArquillianProxyException.class)
|
||||
@UsingDataSet("datasets/org/libreccm/security/UserManagerTest/data.yml")
|
||||
@ShouldThrowException(ConstraintViolationException.class)
|
||||
|
|
@ -241,5 +243,5 @@ public class UserManagerTest {
|
|||
userManager.updatePassword(null, "foo");
|
||||
fail();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,43 @@
|
|||
-- DELETE FROM ccm_core.settings_big_decimal;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_boolean;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_double;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_enum_values;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_enum;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_l10n_string;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_l10n_str_values;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_long;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings_string;
|
||||
--
|
||||
-- DELETE FROM ccm_core.settings;
|
||||
--
|
||||
-- DELETE FROM ccm_core.categorizations;
|
||||
--
|
||||
-- DELETE FROM ccm_core.category_domains;
|
||||
--
|
||||
-- DELETE FROM ccm_core.categories;
|
||||
--
|
||||
-- DELETE FROM ccm_core.permissions;
|
||||
--
|
||||
-- DELETE FROM ccm_core.ccm_objects;
|
||||
--
|
||||
-- DELETE FROM ccm_core.role_memberships;
|
||||
--
|
||||
-- DELETE FROM ccm_core.group_memberships;
|
||||
--
|
||||
-- DELETE FROM ccm_core.groups;
|
||||
--
|
||||
-- DELETE FROM ccm_core.users;
|
||||
--
|
||||
-- DELETE FROM ccm_core.user_email_addresses;
|
||||
--
|
||||
-- DELETE FROM ccm_core.parties;
|
||||
--
|
||||
-- DELETE FROM ccm_core.ccm_roles;
|
||||
DELETE FROM ccm_core.settings_big_decimal;
|
||||
|
||||
DELETE FROM ccm_core.settings_boolean;
|
||||
|
||||
DELETE FROM ccm_core.settings_double;
|
||||
|
||||
DELETE FROM ccm_core.settings_enum_values;
|
||||
|
||||
DELETE FROM ccm_core.settings_enum;
|
||||
|
||||
DELETE FROM ccm_core.settings_l10n_string;
|
||||
|
||||
DELETE FROM ccm_core.settings_l10n_str_values;
|
||||
|
||||
DELETE FROM ccm_core.settings_long;
|
||||
|
||||
DELETE FROM ccm_core.settings_string;
|
||||
|
||||
DELETE FROM ccm_core.settings;
|
||||
|
||||
DELETE FROM ccm_core.categorizations;
|
||||
|
||||
DELETE FROM ccm_core.category_domains;
|
||||
|
||||
DELETE FROM ccm_core.categories;
|
||||
|
||||
DELETE FROM ccm_core.permissions;
|
||||
|
||||
DELETE FROM ccm_core.ccm_objects;
|
||||
|
||||
DELETE FROM ccm_core.role_memberships;
|
||||
|
||||
DELETE FROM ccm_core.group_memberships;
|
||||
|
||||
DELETE FROM ccm_core.groups;
|
||||
|
||||
DELETE FROM ccm_core.users;
|
||||
|
||||
DELETE FROM ccm_core.user_email_addresses;
|
||||
|
||||
DELETE FROM ccm_core.parties;
|
||||
|
||||
DELETE FROM ccm_core.ccm_roles;
|
||||
Loading…
Reference in New Issue