SLING-12284 apply spotless code formatting
diff --git a/pom.xml b/pom.xml
index 4d98322..42d9301 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,34 +28,21 @@
</parent>
<artifactId>org.apache.sling.testing.caconfig-mock-plugin</artifactId>
- <packaging>jar</packaging>
<version>1.6.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
<name>Apache Sling Context-Aware Configuration Mock Plugin</name>
<description>Mock Context Plugin for Apache Sling Context-Aware Configuration</description>
- <properties>
- <project.build.outputTimestamp>2023-12-11T14:53:01Z</project.build.outputTimestamp>
- </properties>
-
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-caconfig-mock-plugin.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-caconfig-mock-plugin.git</developerConnection>
- <url>https://github.com/apache/sling-org-apache-sling-testing-caconfig-mock-plugin.git</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/sling-org-apache-sling-testing-caconfig-mock-plugin.git</url>
</scm>
- <build>
- <plugins>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-baseline-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
+ <properties>
+ <project.build.outputTimestamp>2023-12-11T14:53:01Z</project.build.outputTimestamp>
+ </properties>
<dependencies>
<dependency>
@@ -118,6 +105,19 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-baseline-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
<profiles>
<!-- Test with Sling CAConfig Impl/SPI 1.2 -->
diff --git a/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationDataParts.java b/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationDataParts.java
index 080492d..4e77081 100644
--- a/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationDataParts.java
+++ b/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationDataParts.java
@@ -27,22 +27,20 @@
*/
class ConfigurationDataParts {
- private final Map<String,Object> values = new TreeMap<>();
- private final Map<String,Map<String,Object>> maps = new TreeMap<>();
- private final Map<String,Collection<Map<String,Object>>> collections = new TreeMap<>();
+ private final Map<String, Object> values = new TreeMap<>();
+ private final Map<String, Map<String, Object>> maps = new TreeMap<>();
+ private final Map<String, Collection<Map<String, Object>>> collections = new TreeMap<>();
@SuppressWarnings("unchecked")
- ConfigurationDataParts(Map<String,Object> input) {
+ ConfigurationDataParts(Map<String, Object> input) {
for (Map.Entry<String, Object> entry : input.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map) {
- maps.put(key, (Map)value);
- }
- else if (value instanceof Collection) {
- collections.put(key, (Collection)value);
- }
- else {
+ maps.put(key, (Map) value);
+ } else if (value instanceof Collection) {
+ collections.put(key, (Collection) value);
+ } else {
values.put(key, value);
}
}
@@ -59,5 +57,4 @@
Map<String, Collection<Map<String, Object>>> getCollections() {
return collections;
}
-
}
diff --git a/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationMetadataUtil.java b/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationMetadataUtil.java
index 0fdaa57..b5e65df 100644
--- a/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationMetadataUtil.java
+++ b/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationMetadataUtil.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.testing.mock.caconfig;
-import static org.apache.sling.caconfig.impl.ConfigurationNameConstants.CONFIGURATION_CLASSES_HEADER;
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -49,6 +47,8 @@
import org.osgi.framework.Version;
import org.reflections.Reflections;
+import static org.apache.sling.caconfig.impl.ConfigurationNameConstants.CONFIGURATION_CLASSES_HEADER;
+
/**
* Helper methods for registering Configuration annotation classes from the classpath.
*/
@@ -56,7 +56,8 @@
final class ConfigurationMetadataUtil {
private static final @NotNull String @NotNull [] CONFIGURATION_CLASSES_FROM_MANIFEST;
- private static final @NotNull ConcurrentMap<String, List<Class>> CONFIGURATION_CLASSES_FOR_PACKAGES = new ConcurrentHashMap<>();
+ private static final @NotNull ConcurrentMap<String, List<Class>> CONFIGURATION_CLASSES_FOR_PACKAGES =
+ new ConcurrentHashMap<>();
static {
// scan classpath for configuration classes bundle header entries only once
@@ -76,7 +77,8 @@
* @param bundleContext Bundle context
* @param classNames Java class names
*/
- public static void registerAnnotationClasses(@NotNull BundleContext bundleContext, @NotNull String @NotNull ... classNames) {
+ public static void registerAnnotationClasses(
+ @NotNull BundleContext bundleContext, @NotNull String @NotNull ... classNames) {
Bundle bundle = new RegisterConfigurationMetadataBundle(bundleContext, Bundle.ACTIVE, classNames);
BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle);
MockOsgi.sendBundleEvent(bundleContext, event);
@@ -87,7 +89,8 @@
* @param bundleContext Bundle context
* @param classNames Java class names
*/
- public static void registerAnnotationClasses(@NotNull BundleContext bundleContext, @NotNull Class @NotNull ... classes) {
+ public static void registerAnnotationClasses(
+ @NotNull BundleContext bundleContext, @NotNull Class @NotNull ... classes) {
String[] classNames = new String[classes.length];
for (int i = 0; i < classes.length; i++) {
classNames[i] = classes[i].getName();
@@ -127,7 +130,6 @@
return classes;
}
-
private static class RegisterConfigurationMetadataBundle implements Bundle {
private final BundleContext bundleContext;
@@ -153,7 +155,7 @@
}
@Override
- public Dictionary<String,String> getHeaders() {
+ public Dictionary<String, String> getHeaders() {
Dictionary<String, String> headers = new Hashtable<>();
headers.put(CONFIGURATION_CLASSES_HEADER, classNames);
return headers;
@@ -240,7 +242,7 @@
}
@Override
- public Dictionary<String,String> getHeaders(String locale) {
+ public Dictionary<String, String> getHeaders(String locale) {
return null;
}
@@ -293,7 +295,5 @@
public File getDataFile(String filename) {
return null;
}
-
}
-
}
diff --git a/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationPersistHelper.java b/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationPersistHelper.java
index 988d33e..c980cb3 100644
--- a/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationPersistHelper.java
+++ b/src/main/java/org/apache/sling/testing/mock/caconfig/ConfigurationPersistHelper.java
@@ -64,14 +64,17 @@
void writeConfiguration(@NotNull String configName, @NotNull Map<String, Object> values) {
// write properties of main configuration
ConfigurationDataParts parts = new ConfigurationDataParts(values);
- configManager.persistConfiguration(contextResource, configName, new ConfigurationPersistData(parts.getValues()));
+ configManager.persistConfiguration(
+ contextResource, configName, new ConfigurationPersistData(parts.getValues()));
// write nested configuration and nested configuration collections
- for (Map.Entry<String,Map<String,Object>> nestedMap : parts.getMaps().entrySet()) {
+ for (Map.Entry<String, Map<String, Object>> nestedMap : parts.getMaps().entrySet()) {
writeConfiguration(getNestedConfigName(configName, nestedMap.getKey()), nestedMap.getValue());
}
- for (Map.Entry<String,Collection<Map<String,Object>>> nestedCollection : parts.getCollections().entrySet()) {
- writeConfigurationCollection(getNestedConfigName(configName, nestedCollection.getKey()), nestedCollection.getValue());
+ for (Map.Entry<String, Collection<Map<String, Object>>> nestedCollection :
+ parts.getCollections().entrySet()) {
+ writeConfigurationCollection(
+ getNestedConfigName(configName, nestedCollection.getKey()), nestedCollection.getValue());
}
}
@@ -80,7 +83,8 @@
* @param configName Config name
* @param values Configuration values
*/
- void writeConfigurationCollection(@NotNull String configName, @NotNull Collection<@NotNull Map<String, Object>> values) {
+ void writeConfigurationCollection(
+ @NotNull String configName, @NotNull Collection<@NotNull Map<String, Object>> values) {
// split each collection item map in it's parts
Map<String, ConfigurationDataParts> partsCollection = new LinkedHashMap<>();
int index = 0;
@@ -90,20 +94,27 @@
// write properties of main configuration collection
List<ConfigurationPersistData> items = partsCollection.entrySet().stream()
- .map(entry -> new ConfigurationPersistData(entry.getValue().getValues()).collectionItemName(entry.getKey()))
+ .map(entry ->
+ new ConfigurationPersistData(entry.getValue().getValues()).collectionItemName(entry.getKey()))
.collect(Collectors.toList());
- configManager.persistConfigurationCollection(contextResource, configName,
- new ConfigurationCollectionPersistData(items));
+ configManager.persistConfigurationCollection(
+ contextResource, configName, new ConfigurationCollectionPersistData(items));
// write nested configuration and nested configuration collections
for (Map.Entry<String, ConfigurationDataParts> entry : partsCollection.entrySet()) {
String itemName = entry.getKey();
ConfigurationDataParts parts = entry.getValue();
- for (Map.Entry<String,Map<String,Object>> nestedMap : parts.getMaps().entrySet()) {
- writeConfiguration(getNestedCollectionItemConfigName(configName, itemName, nestedMap.getKey()), nestedMap.getValue());
+ for (Map.Entry<String, Map<String, Object>> nestedMap :
+ parts.getMaps().entrySet()) {
+ writeConfiguration(
+ getNestedCollectionItemConfigName(configName, itemName, nestedMap.getKey()),
+ nestedMap.getValue());
}
- for (Map.Entry<String,Collection<Map<String,Object>>> nestedCollection : parts.getCollections().entrySet()) {
- writeConfigurationCollection(getNestedCollectionItemConfigName(configName, itemName, nestedCollection.getKey()), nestedCollection.getValue());
+ for (Map.Entry<String, Collection<Map<String, Object>>> nestedCollection :
+ parts.getCollections().entrySet()) {
+ writeConfigurationCollection(
+ getNestedCollectionItemConfigName(configName, itemName, nestedCollection.getKey()),
+ nestedCollection.getValue());
}
}
}
@@ -113,19 +124,21 @@
}
private String getCollectionParentConfigName(@NotNull String configName) {
- return StringUtils.defaultString(configurationPersistenceStrategy.getCollectionParentConfigName(configName, null), configName);
+ return StringUtils.defaultString(
+ configurationPersistenceStrategy.getCollectionParentConfigName(configName, null), configName);
}
private String getCollectionItemConfigName(@NotNull String configName) {
- return StringUtils.defaultString(configurationPersistenceStrategy.getCollectionItemConfigName(configName, null), configName);
+ return StringUtils.defaultString(
+ configurationPersistenceStrategy.getCollectionItemConfigName(configName, null), configName);
}
private String getNestedConfigName(@NotNull String configName, @NotNull String key) {
return getConfigName(configName) + "/" + key;
}
- private String getNestedCollectionItemConfigName(@NotNull String configName, @NotNull String itemName, @NotNull String key) {
+ private String getNestedCollectionItemConfigName(
+ @NotNull String configName, @NotNull String itemName, @NotNull String key) {
return getCollectionItemConfigName(getCollectionParentConfigName(configName) + "/" + itemName) + "/" + key;
}
-
}
diff --git a/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java b/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java
index 01f2752..7958c31 100644
--- a/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java
+++ b/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java
@@ -47,38 +47,42 @@
/**
* Context plugin for Sling Context-Aware Configuration.
*/
- public static final @NotNull ContextPlugin<? extends SlingContextImpl> CACONFIG = new AbstractContextPlugin<SlingContextImpl>() {
- @Override
- public void beforeSetUp(@NotNull SlingContextImpl context) throws Exception {
- // register models injector and it's dependencies before setup, to ensure it is present
- // before sling models are auto-detected from classpath
- registerConfigurationResourceResolver(context);
- registerConfigurationResolver(context);
- registerConfigurationManagement(context);
- registerModelsInjector(context);
- }
- @Override
- public void afterSetUp(@NotNull SlingContextImpl context) throws Exception {
- registerConfigurationResourceResolverDefaultImpl(context);
- registerConfigurationResolverDefaultImpl(context);
+ public static final @NotNull ContextPlugin<? extends SlingContextImpl> CACONFIG =
+ new AbstractContextPlugin<SlingContextImpl>() {
+ @Override
+ public void beforeSetUp(@NotNull SlingContextImpl context) throws Exception {
+ // register models injector and it's dependencies before setup, to ensure it is present
+ // before sling models are auto-detected from classpath
+ registerConfigurationResourceResolver(context);
+ registerConfigurationResolver(context);
+ registerConfigurationManagement(context);
+ registerModelsInjector(context);
+ }
- // Scan MANIFEST.MF in the classpath and automatically register all Configuration annotation classes found.
- ConfigurationMetadataUtil.addAnnotationClassesForManifestEntries(context.bundleContext());
- }
- };
+ @Override
+ public void afterSetUp(@NotNull SlingContextImpl context) throws Exception {
+ registerConfigurationResourceResolverDefaultImpl(context);
+ registerConfigurationResolverDefaultImpl(context);
+
+ // Scan MANIFEST.MF in the classpath and automatically register all Configuration annotation classes
+ // found.
+ ConfigurationMetadataUtil.addAnnotationClassesForManifestEntries(context.bundleContext());
+ }
+ };
/**
* Context plugin for Sling Context-Aware Configuration (without the default implementations).
*/
- public static final @NotNull ContextPlugin<? extends SlingContextImpl> CACONFIG_NODEF = new AbstractContextPlugin<SlingContextImpl>() {
- @Override
- public void afterSetUp(@NotNull SlingContextImpl context) throws Exception {
- registerConfigurationResourceResolver(context);
- registerConfigurationResolver(context);
- registerConfigurationManagement(context);
- registerModelsInjector(context);
- }
- };
+ public static final @NotNull ContextPlugin<? extends SlingContextImpl> CACONFIG_NODEF =
+ new AbstractContextPlugin<SlingContextImpl>() {
+ @Override
+ public void afterSetUp(@NotNull SlingContextImpl context) throws Exception {
+ registerConfigurationResourceResolver(context);
+ registerConfigurationResolver(context);
+ registerConfigurationManagement(context);
+ registerModelsInjector(context);
+ }
+ };
/**
* Register all services for ConfigurationResourceResolver (without the default implementations).
@@ -88,9 +92,13 @@
context.registerInjectActivateService(new ContextPathStrategyMultiplexerImpl());
- if (!registerByClassName(context, "org.apache.sling.caconfig.resource.impl.ConfigurationResourceResolvingStrategyMultiplexerImpl")) {
+ if (!registerByClassName(
+ context,
+ "org.apache.sling.caconfig.resource.impl.ConfigurationResourceResolvingStrategyMultiplexerImpl")) {
// fallback to impl 1.2
- registerByClassName(context, "org.apache.sling.caconfig.resource.impl.ConfigurationResourceResolvingStrategyMultiplexer");
+ registerByClassName(
+ context,
+ "org.apache.sling.caconfig.resource.impl.ConfigurationResourceResolvingStrategyMultiplexer");
}
context.registerInjectActivateService(new ConfigurationResourceResolverImpl());
@@ -112,25 +120,31 @@
private static void registerConfigurationResolver(SlingContextImpl context) {
registerByClassName(context, "org.apache.sling.caconfig.management.impl.ConfigurationManagementSettingsImpl");
- if (!registerByClassName(context, "org.apache.sling.caconfig.management.impl.ConfigurationPersistenceStrategyMultiplexerImpl")) {
+ if (!registerByClassName(
+ context, "org.apache.sling.caconfig.management.impl.ConfigurationPersistenceStrategyMultiplexerImpl")) {
// fallback to impl 1.2
- registerByClassName(context, "org.apache.sling.caconfig.management.impl.ConfigurationPersistenceStrategyMultiplexer");
+ registerByClassName(
+ context, "org.apache.sling.caconfig.management.impl.ConfigurationPersistenceStrategyMultiplexer");
}
// only required for impl 1.3+
registerByClassName(context, "org.apache.sling.caconfig.impl.ConfigurationPersistenceStrategyBridge");
- if (!registerByClassName(context, "org.apache.sling.caconfig.impl.metadata.ConfigurationMetadataProviderMultiplexerImpl")) {
+ if (!registerByClassName(
+ context, "org.apache.sling.caconfig.impl.metadata.ConfigurationMetadataProviderMultiplexerImpl")) {
// fallback to impl 1.2
- registerByClassName(context, "org.apache.sling.caconfig.impl.metadata.ConfigurationMetadataProviderMultiplexer");
+ registerByClassName(
+ context, "org.apache.sling.caconfig.impl.metadata.ConfigurationMetadataProviderMultiplexer");
}
- if (!registerByClassName(context, "org.apache.sling.caconfig.impl.ConfigurationInheritanceStrategyMultiplexerImpl")) {
+ if (!registerByClassName(
+ context, "org.apache.sling.caconfig.impl.ConfigurationInheritanceStrategyMultiplexerImpl")) {
// fallback to impl 1.2 (not existing in 1.1 or below)
registerByClassName(context, "org.apache.sling.caconfig.impl.ConfigurationInheritanceStrategyMultiplexer");
}
- if (!registerByClassName(context, "org.apache.sling.caconfig.impl.override.ConfigurationOverrideMultiplexerImpl")) {
+ if (!registerByClassName(
+ context, "org.apache.sling.caconfig.impl.override.ConfigurationOverrideMultiplexerImpl")) {
// fallback to impl 1.2 (not existing in 1.1 or below)
registerByClassName(context, "org.apache.sling.caconfig.impl.override.ConfigurationOverrideManager");
}
@@ -147,10 +161,11 @@
context.registerInjectActivateService(new DefaultConfigurationPersistenceStrategy());
// only required for impl 1.2+
- registerByClassName(context,"org.apache.sling.caconfig.impl.def.DefaultConfigurationInheritanceStrategy");
+ registerByClassName(context, "org.apache.sling.caconfig.impl.def.DefaultConfigurationInheritanceStrategy");
// required for impl 1.6+
- registerByClassName(context, "org.apache.sling.caconfig.impl.def.DefaultConfigurationInjectResourceDetectionStrategy");
+ registerByClassName(
+ context, "org.apache.sling.caconfig.impl.def.DefaultConfigurationInjectResourceDetectionStrategy");
}
private static void registerConfigurationManagement(SlingContextImpl context) {
@@ -158,12 +173,14 @@
context.registerInjectActivateService(new AnnotationClassConfigurationMetadataProvider());
// required for impl 1.6
- registerByClassName(context, "org.apache.sling.caconfig.impl.ConfigurationInjectResourceDetectionStrategyMultiplexerImpl");
+ registerByClassName(
+ context, "org.apache.sling.caconfig.impl.ConfigurationInjectResourceDetectionStrategyMultiplexerImpl");
}
private static void registerModelsInjector(SlingContextImpl context) {
// required for impl 1.6
- registerByClassName(context, "org.apache.sling.models.caconfig.impl.injectors.ContextAwareConfigurationInjector");
+ registerByClassName(
+ context, "org.apache.sling.models.caconfig.impl.injectors.ContextAwareConfigurationInjector");
}
@SuppressWarnings("null")
@@ -172,17 +189,12 @@
Class<?> clazz = Class.forName(className);
context.registerInjectActivateService(clazz.newInstance());
return true;
- }
- catch (ClassNotFoundException ex) {
+ } catch (ClassNotFoundException ex) {
return false;
- }
- catch (InstantiationException ex) {
+ } catch (InstantiationException ex) {
+ throw new RuntimeException(ex);
+ } catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
}
- catch (IllegalAccessException ex) {
- throw new RuntimeException(ex);
- }
-
}
-
}
diff --git a/src/main/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig.java b/src/main/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig.java
index 7ffaf71..ea085ec 100644
--- a/src/main/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig.java
+++ b/src/main/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig.java
@@ -43,7 +43,8 @@
* @param context Sling context
* @param classNames Java class names
*/
- public static void registerAnnotationClasses(@NotNull SlingContextImpl context, @NotNull String @NotNull ... classNames) {
+ public static void registerAnnotationClasses(
+ @NotNull SlingContextImpl context, @NotNull String @NotNull ... classNames) {
ConfigurationMetadataUtil.registerAnnotationClasses(context.bundleContext(), classNames);
}
@@ -52,7 +53,8 @@
* @param context Sling context
* @param classes Java classes
*/
- public static void registerAnnotationClasses(@NotNull SlingContextImpl context, @NotNull Class @NotNull ... classes) {
+ public static void registerAnnotationClasses(
+ @NotNull SlingContextImpl context, @NotNull Class @NotNull ... classes) {
ConfigurationMetadataUtil.registerAnnotationClasses(context.bundleContext(), classes);
}
@@ -61,8 +63,10 @@
* @param context Sling context
* @param packageNames Java package names
*/
- public static void registerAnnotationPackages(@NotNull SlingContextImpl context, @NotNull String @NotNull ... packageNames) {
- Collection<Class> classes = ConfigurationMetadataUtil.getConfigurationClassesForPackages(StringUtils.join(packageNames, ","));
+ public static void registerAnnotationPackages(
+ @NotNull SlingContextImpl context, @NotNull String @NotNull ... packageNames) {
+ Collection<Class> classes =
+ ConfigurationMetadataUtil.getConfigurationClassesForPackages(StringUtils.join(packageNames, ","));
registerAnnotationClasses(context, classes.toArray(new Class[classes.size()]));
}
@@ -74,7 +78,10 @@
* @param configClass Configuration class
* @param values Configuration values
*/
- public static void writeConfiguration(@NotNull SlingContextImpl context, @NotNull String contextPath, @NotNull Class<?> configClass,
+ public static void writeConfiguration(
+ @NotNull SlingContextImpl context,
+ @NotNull String contextPath,
+ @NotNull Class<?> configClass,
@NotNull Map<String, Object> values) {
writeConfiguration(context, contextPath, getConfigurationName(configClass), values);
}
@@ -87,7 +94,10 @@
* @param configName Config name
* @param values Configuration values
*/
- public static void writeConfiguration(@NotNull SlingContextImpl context, @NotNull String contextPath, @NotNull String configName,
+ public static void writeConfiguration(
+ @NotNull SlingContextImpl context,
+ @NotNull String contextPath,
+ @NotNull String configName,
@NotNull Map<String, Object> values) {
ConfigurationPersistHelper helper = new ConfigurationPersistHelper(context, contextPath);
helper.writeConfiguration(configName, values);
@@ -101,7 +111,11 @@
* @param configClass Configuration class
* @param values Configuration values
*/
- public static void writeConfiguration(@NotNull SlingContextImpl context, @NotNull String contextPath, Class<?> configClass, @NotNull Object @NotNull ... values) {
+ public static void writeConfiguration(
+ @NotNull SlingContextImpl context,
+ @NotNull String contextPath,
+ Class<?> configClass,
+ @NotNull Object @NotNull ... values) {
writeConfiguration(context, contextPath, getConfigurationName(configClass), values);
}
@@ -113,7 +127,11 @@
* @param configName Config name
* @param values Configuration values
*/
- public static void writeConfiguration(@NotNull SlingContextImpl context, @NotNull String contextPath, @NotNull String configName, @NotNull Object @NotNull ... values) {
+ public static void writeConfiguration(
+ @NotNull SlingContextImpl context,
+ @NotNull String contextPath,
+ @NotNull String configName,
+ @NotNull Object @NotNull ... values) {
writeConfiguration(context, contextPath, configName, MapUtil.toMap(values));
}
@@ -125,7 +143,10 @@
* @param configClass Configuration class
* @param values Configuration values
*/
- public static void writeConfigurationCollection(@NotNull SlingContextImpl context, @NotNull String contextPath, @NotNull Class<?> configClass,
+ public static void writeConfigurationCollection(
+ @NotNull SlingContextImpl context,
+ @NotNull String contextPath,
+ @NotNull Class<?> configClass,
@NotNull Collection<@NotNull Map<String, Object>> values) {
writeConfigurationCollection(context, contextPath, getConfigurationName(configClass), values);
}
@@ -138,7 +159,10 @@
* @param configName Config name
* @param values Configuration values
*/
- public static void writeConfigurationCollection(@NotNull SlingContextImpl context, @NotNull String contextPath, @NotNull String configName,
+ public static void writeConfigurationCollection(
+ @NotNull SlingContextImpl context,
+ @NotNull String contextPath,
+ @NotNull String configName,
@NotNull Collection<@NotNull Map<String, Object>> values) {
ConfigurationPersistHelper helper = new ConfigurationPersistHelper(context, contextPath);
helper.writeConfigurationCollection(configName, values);
@@ -152,5 +176,4 @@
}
return configClass.getName();
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java b/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java
index 11e7ba1..aeeb157 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.testing.mock.caconfig;
-import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.caconfig.ConfigurationBuilder;
@@ -32,15 +28,17 @@
import org.junit.Rule;
import org.junit.Test;
+import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
@SuppressWarnings("null")
public class ContextPluginsTest {
private static final String CONFIG_NAME = "testConfig";
@Rule
- public SlingContext context = new SlingContextBuilder()
- .plugin(CACONFIG)
- .build();
+ public SlingContext context = new SlingContextBuilder().plugin(CACONFIG).build();
private Resource contextResource;
@@ -53,28 +51,37 @@
MockContextAwareConfig.registerAnnotationClasses(context, SimpleConfig.class);
// write config
- MockContextAwareConfig.writeConfiguration(context, contextResource.getPath(), SimpleConfig.class,
- "stringParam", "value1",
- "intParam", 123,
- "boolParam", true);
+ MockContextAwareConfig.writeConfiguration(
+ context,
+ contextResource.getPath(),
+ SimpleConfig.class,
+ "stringParam",
+ "value1",
+ "intParam",
+ 123,
+ "boolParam",
+ true);
}
@Test
public void testValueMap() {
// read config
- ValueMap props = contextResource.adaptTo(ConfigurationBuilder.class).name(CONFIG_NAME).asValueMap();
+ ValueMap props = contextResource
+ .adaptTo(ConfigurationBuilder.class)
+ .name(CONFIG_NAME)
+ .asValueMap();
assertEquals("value1", props.get("stringParam", String.class));
- assertEquals((Integer)123, props.get("intParam", Integer.class));
+ assertEquals((Integer) 123, props.get("intParam", Integer.class));
assertTrue(props.get("boolParam", Boolean.class));
}
@Test
public void testAnnotationClass() {
// read config
- SimpleConfig config = contextResource.adaptTo(ConfigurationBuilder.class).as(SimpleConfig.class);
+ SimpleConfig config =
+ contextResource.adaptTo(ConfigurationBuilder.class).as(SimpleConfig.class);
assertEquals("value1", config.stringParam());
assertEquals(123, config.intParam());
assertTrue(config.boolParam());
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfigTest.java b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfigTest.java
index 92de0c9..bef9eb7 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfigTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfigTest.java
@@ -18,11 +18,6 @@
*/
package org.apache.sling.testing.mock.caconfig;
-import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -44,12 +39,15 @@
import org.junit.Rule;
import org.junit.Test;
+import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
public class MockContextAwareConfigTest {
@Rule
- public SlingContext context = new SlingContextBuilder()
- .plugin(CACONFIG)
- .build();
+ public SlingContext context = new SlingContextBuilder().plugin(CACONFIG).build();
@Before
public void setUp() {
@@ -62,8 +60,8 @@
@Test
public void testSingletonConfig() {
- MockContextAwareConfig.writeConfiguration(context, "/content/region/site", SimpleConfig.class,
- "stringParam", "value1");
+ MockContextAwareConfig.writeConfiguration(
+ context, "/content/region/site", SimpleConfig.class, "stringParam", "value1");
SimpleConfig config = getConfig(SimpleConfig.class);
assertEquals("value1", config.stringParam());
@@ -72,9 +70,11 @@
@Test
public void testCollectionConfig() {
- MockContextAwareConfig.writeConfigurationCollection(context, "/content/region/site", ListConfig.class, List.of(
- Map.of("stringParam", "value1"),
- Map.of("stringParam", "value2")));
+ MockContextAwareConfig.writeConfigurationCollection(
+ context,
+ "/content/region/site",
+ ListConfig.class,
+ List.of(Map.of("stringParam", "value1"), Map.of("stringParam", "value2")));
Collection<ListConfig> config = getConfigCollection(ListConfig.class);
assertEquals(2, config.size());
@@ -91,10 +91,14 @@
@Test
public void testCollectionConfig_DifferentOrder() {
- MockContextAwareConfig.writeConfigurationCollection(context, "/content/region/site", ListConfig.class, List.of(
- Map.of("stringParam", "value2"),
- Map.of("stringParam", "value3"),
- Map.of("stringParam", "value1")));
+ MockContextAwareConfig.writeConfigurationCollection(
+ context,
+ "/content/region/site",
+ ListConfig.class,
+ List.of(
+ Map.of("stringParam", "value2"),
+ Map.of("stringParam", "value3"),
+ Map.of("stringParam", "value1")));
Collection<ListConfig> config = getConfigCollection(ListConfig.class);
assertEquals(3, config.size());
@@ -115,17 +119,23 @@
@Test
public void testNestedSingletonConfig() {
- MockContextAwareConfig.writeConfiguration(context, "/content/region/site", NestedConfig.class,
- "stringParam", "value1",
- "sub", List.of(
- Map.of("subStringParam", "v1", "intParam", 5, "stringArrayParam", new String[] {"v1a","v1b"}),
+ MockContextAwareConfig.writeConfiguration(
+ context,
+ "/content/region/site",
+ NestedConfig.class,
+ "stringParam",
+ "value1",
+ "sub",
+ List.of(
+ Map.of("subStringParam", "v1", "intParam", 5, "stringArrayParam", new String[] {"v1a", "v1b"}),
Map.of("subStringParam", "v2")),
- "sub2", Map.of(
+ "sub2",
+ Map.of(
"sub2StringParam", "v3",
"sub", Map.of("subStringParam", "v4"),
- "subList", List.of(Map.of("subStringParam", "v5a"),Map.of("subStringParam", "v5b"))),
- "sub2List", List.of(
- Map.of("sub2StringParam", "v6")));
+ "subList", List.of(Map.of("subStringParam", "v5a"), Map.of("subStringParam", "v5b"))),
+ "sub2List",
+ List.of(Map.of("sub2StringParam", "v6")));
NestedConfig config = getConfig(NestedConfig.class);
assertEquals("value1", config.stringParam());
@@ -134,7 +144,7 @@
assertEquals(2, sub.length);
assertEquals("v1", sub[0].subStringParam());
assertEquals(5, sub[0].intParam());
- assertArrayEquals(new String[] {"v1a","v1b"}, sub[0].stringArrayParam());
+ assertArrayEquals(new String[] {"v1a", "v1b"}, sub[0].stringArrayParam());
assertEquals("v2", sub[1].subStringParam());
NestedConfigSub2 sub2 = config.sub2();
@@ -152,18 +162,31 @@
@Test
public void testNestedCollectionConfig() {
- MockContextAwareConfig.writeConfigurationCollection(context, "/content/region/site", NestedListConfig.class, List.of(
- Map.of("stringParam", "value1",
- "sub", List.of(
- Map.of("subStringParam", "v1", "intParam", 5, "stringArrayParam", new String[] {"v1a","v1b"}),
- Map.of("subStringParam", "v2")),
- "sub2", Map.of(
- "sub2StringParam", "v3",
- "sub", Map.of("subStringParam", "v4"),
- "subList", List.of(Map.of("subStringParam", "v5a"),Map.of("subStringParam", "v5b"))),
- "sub2List", List.of(
- Map.of("sub2StringParam", "v6"))),
- Map.of("stringParam", "value2")));
+ MockContextAwareConfig.writeConfigurationCollection(
+ context,
+ "/content/region/site",
+ NestedListConfig.class,
+ List.of(
+ Map.of(
+ "stringParam",
+ "value1",
+ "sub",
+ List.of(
+ Map.of("subStringParam", "v1", "intParam", 5, "stringArrayParam", new String[] {
+ "v1a", "v1b"
+ }),
+ Map.of("subStringParam", "v2")),
+ "sub2",
+ Map.of(
+ "sub2StringParam", "v3",
+ "sub", Map.of("subStringParam", "v4"),
+ "subList",
+ List.of(
+ Map.of("subStringParam", "v5a"),
+ Map.of("subStringParam", "v5b"))),
+ "sub2List",
+ List.of(Map.of("sub2StringParam", "v6"))),
+ Map.of("stringParam", "value2")));
Collection<NestedListConfig> config = getConfigCollection(NestedListConfig.class);
assertEquals(2, config.size());
@@ -176,7 +199,7 @@
assertEquals(2, sub.length);
assertEquals("v1", sub[0].subStringParam());
assertEquals(5, sub[0].intParam());
- assertArrayEquals(new String[] {"v1a","v1b"}, sub[0].stringArrayParam());
+ assertArrayEquals(new String[] {"v1a", "v1b"}, sub[0].stringArrayParam());
assertEquals("v2", sub[1].subStringParam());
NestedConfigSub2 sub2 = item1.sub2();
@@ -206,9 +229,9 @@
@SuppressWarnings("null")
private <T> @NotNull Collection<@Nullable T> getConfigCollection(@NotNull Class<T> configClass) {
Resource resource = context.request().getResource();
- Collection<@Nullable T> result = resource.adaptTo(ConfigurationBuilder.class).asCollection(configClass);
+ Collection<@Nullable T> result =
+ resource.adaptTo(ConfigurationBuilder.class).asCollection(configClass);
assertNotNull(result);
return result;
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence2Test.java b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence2Test.java
index 77ae670..502aebf 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence2Test.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence2Test.java
@@ -28,10 +28,12 @@
@Override
@Before
public void setUp() {
- context.registerService(ConfigurationPersistenceStrategy2.class, new CustomConfigurationPersistenceStrategy2(),
- Constants.SERVICE_RANKING, 2000);
+ context.registerService(
+ ConfigurationPersistenceStrategy2.class,
+ new CustomConfigurationPersistenceStrategy2(),
+ Constants.SERVICE_RANKING,
+ 2000);
super.setUp();
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence3Test.java b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence3Test.java
index 4fabda3..dfe683b 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence3Test.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistence3Test.java
@@ -28,10 +28,12 @@
@Override
@Before
public void setUp() {
- context.registerService(ConfigurationPersistenceStrategy2.class, new CustomConfigurationPersistenceStrategy3(),
- Constants.SERVICE_RANKING, 2000);
+ context.registerService(
+ ConfigurationPersistenceStrategy2.class,
+ new CustomConfigurationPersistenceStrategy3(),
+ Constants.SERVICE_RANKING,
+ 2000);
super.setUp();
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistenceTest.java b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistenceTest.java
index 5278ad5..e6c872b 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistenceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/MockContextAwareConfig_CustomPersistenceTest.java
@@ -28,10 +28,12 @@
@Override
@Before
public void setUp() {
- context.registerService(ConfigurationPersistenceStrategy2.class, new CustomConfigurationPersistenceStrategy(),
- Constants.SERVICE_RANKING, 2000);
+ context.registerService(
+ ConfigurationPersistenceStrategy2.class,
+ new CustomConfigurationPersistenceStrategy(),
+ Constants.SERVICE_RANKING,
+ 2000);
super.setUp();
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/example/ListConfig.java b/src/test/java/org/apache/sling/testing/mock/caconfig/example/ListConfig.java
index 4f7c701..e6f3738 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/example/ListConfig.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/example/ListConfig.java
@@ -28,5 +28,4 @@
int intParam() default 5;
boolean boolParam();
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfig.java b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfig.java
index 80fd4aa..b146f5a 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfig.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfig.java
@@ -26,12 +26,11 @@
@Configuration
public @interface NestedConfig {
- String stringParam();
+ String stringParam();
- NestedConfigSub[] sub();
+ NestedConfigSub[] sub();
- NestedConfigSub2 sub2();
+ NestedConfigSub2 sub2();
- NestedConfigSub2[] sub2List();
-
+ NestedConfigSub2[] sub2List();
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub.java b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub.java
index 8714c9e..07ec767 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub.java
@@ -23,12 +23,9 @@
*/
public @interface NestedConfigSub {
- String subStringParam();
+ String subStringParam();
- int intParam();
+ int intParam();
- String[] stringArrayParam() default {
- "value1", "value2"
- };
-
+ String[] stringArrayParam() default {"value1", "value2"};
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub2.java b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub2.java
index c640056..f9caacf 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub2.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedConfigSub2.java
@@ -23,10 +23,9 @@
*/
public @interface NestedConfigSub2 {
- String sub2StringParam();
+ String sub2StringParam();
- NestedConfigSub sub();
+ NestedConfigSub sub();
- NestedConfigSub[] subList();
-
+ NestedConfigSub[] subList();
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedListConfig.java b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedListConfig.java
index 28e7c27..ff0daee 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedListConfig.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/example/NestedListConfig.java
@@ -26,12 +26,11 @@
@Configuration(collection = true)
public @interface NestedListConfig {
- String stringParam();
+ String stringParam();
- NestedConfigSub[] sub();
+ NestedConfigSub[] sub();
- NestedConfigSub2 sub2();
+ NestedConfigSub2 sub2();
- NestedConfigSub2[] sub2List();
-
+ NestedConfigSub2[] sub2List();
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/example/SimpleConfig.java b/src/test/java/org/apache/sling/testing/mock/caconfig/example/SimpleConfig.java
index 53ab6ec..26bb48f 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/example/SimpleConfig.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/example/SimpleConfig.java
@@ -28,5 +28,4 @@
int intParam() default 5;
boolean boolParam();
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy.java b/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy.java
index 6d76318..e73aecc 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.testing.mock.caconfig.persistence;
-import static org.junit.Assert.assertNotNull;
-
import java.util.HashSet;
import java.util.Map;
@@ -38,6 +36,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import static org.junit.Assert.assertNotNull;
+
/**
* This is a variant of {@link org.apache.sling.caconfig.impl.def.DefaultConfigurationPersistenceStrategy}
* which reads and stores data from a sub-resources named "jcr:content".
@@ -102,7 +102,9 @@
}
@Override
- public boolean persistConfiguration(@NotNull ResourceResolver resourceResolver, @NotNull String configResourcePath,
+ public boolean persistConfiguration(
+ @NotNull ResourceResolver resourceResolver,
+ @NotNull String configResourcePath,
@NotNull ConfigurationPersistData data) {
getOrCreateResource(resourceResolver, configResourcePath + "/" + CHILD_NODE_NAME, data.getProperties());
commit(resourceResolver);
@@ -110,9 +112,12 @@
}
@Override
- public boolean persistConfigurationCollection(@NotNull ResourceResolver resourceResolver, @NotNull String configResourceCollectionParentPath,
+ public boolean persistConfigurationCollection(
+ @NotNull ResourceResolver resourceResolver,
+ @NotNull String configResourceCollectionParentPath,
@NotNull ConfigurationCollectionPersistData data) {
- Resource configResourceParent = getOrCreateResource(resourceResolver, configResourceCollectionParentPath, ValueMap.EMPTY);
+ Resource configResourceParent =
+ getOrCreateResource(resourceResolver, configResourceCollectionParentPath, ValueMap.EMPTY);
// delete existing children and create new ones
deleteChildren(configResourceParent);
@@ -136,22 +141,23 @@
if (resource != null) {
try {
resourceResolver.delete(resource);
- }
- catch (PersistenceException ex) {
- throw new ConfigurationPersistenceException("Unable to delete configuration at " + configResourcePath, ex);
+ } catch (PersistenceException ex) {
+ throw new ConfigurationPersistenceException(
+ "Unable to delete configuration at " + configResourcePath, ex);
}
}
commit(resourceResolver);
return true;
}
- private Resource getOrCreateResource(ResourceResolver resourceResolver, String path, Map<String,Object> properties) {
+ private Resource getOrCreateResource(
+ ResourceResolver resourceResolver, String path, Map<String, Object> properties) {
try {
- Resource resource = ResourceUtil.getOrCreateResource(resourceResolver, path, DEFAULT_RESOURCE_TYPE, DEFAULT_RESOURCE_TYPE, false);
+ Resource resource = ResourceUtil.getOrCreateResource(
+ resourceResolver, path, DEFAULT_RESOURCE_TYPE, DEFAULT_RESOURCE_TYPE, false);
replaceProperties(resource, properties);
return resource;
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to persist configuration to " + path, ex);
}
}
@@ -162,14 +168,13 @@
for (Resource child : resource.getChildren()) {
resourceResolver.delete(child);
}
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to remove children from " + resource.getPath(), ex);
}
}
@SuppressWarnings("null")
- private void replaceProperties(Resource resource, Map<String,Object> properties) {
+ private void replaceProperties(Resource resource, Map<String, Object> properties) {
ModifiableValueMap modValueMap = resource.adaptTo(ModifiableValueMap.class);
// remove all existing properties that do not have jcr: namespace
for (String propertyName : new HashSet<>(modValueMap.keySet())) {
@@ -184,10 +189,8 @@
private void commit(ResourceResolver resourceResolver) {
try {
resourceResolver.commit();
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to save configuration: " + ex.getMessage(), ex);
}
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy2.java b/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy2.java
index 1f9cb38..c4d6c92 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy2.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy2.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.testing.mock.caconfig.persistence;
-import static org.junit.Assert.assertNotNull;
-
import java.util.HashSet;
import java.util.Map;
import java.util.regex.Pattern;
@@ -39,6 +37,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import static org.junit.Assert.assertNotNull;
+
/**
* This is a variant of {@link org.apache.sling.caconfig.impl.def.DefaultConfigurationPersistenceStrategy}
* which reads and stores data from a sub-resources named "jcr:content".
@@ -51,15 +51,15 @@
private static final String DEFAULT_RESOURCE_TYPE = JcrConstants.NT_UNSTRUCTURED;
private static final String CHILD_NODE_NAME = JcrConstants.JCR_CONTENT;
- private static final Pattern JCR_CONTENT_PATTERN = Pattern.compile("(.*/)?" + Pattern.quote(CHILD_NODE_NAME) + "(/.*)?");
+ private static final Pattern JCR_CONTENT_PATTERN =
+ Pattern.compile("(.*/)?" + Pattern.quote(CHILD_NODE_NAME) + "(/.*)?");
@Override
public Resource getResource(@NotNull Resource resource) {
assertNotNull(resource);
if (containsJcrContent(resource.getPath())) {
return resource;
- }
- else {
+ } else {
return resource.getChild(CHILD_NODE_NAME);
}
}
@@ -69,8 +69,7 @@
assertNotNull(resource);
if (containsJcrContent(resource.getPath())) {
return resource;
- }
- else {
+ } else {
return resource.getChild(CHILD_NODE_NAME);
}
}
@@ -86,8 +85,7 @@
assertNotNull(resourcePath);
if (containsJcrContent(resourcePath)) {
return resourcePath;
- }
- else {
+ } else {
return resourcePath + "/" + CHILD_NODE_NAME;
}
}
@@ -97,8 +95,7 @@
assertNotNull(resourcePath);
if (containsJcrContent(resourcePath)) {
return resourcePath;
- }
- else {
+ } else {
return resourcePath + "/" + CHILD_NODE_NAME;
}
}
@@ -114,8 +111,7 @@
assertNotNull(configName);
if (containsJcrContent(configName)) {
return configName;
- }
- else {
+ } else {
return configName + "/" + CHILD_NODE_NAME;
}
}
@@ -125,8 +121,7 @@
assertNotNull(configName);
if (containsJcrContent(configName)) {
return configName;
- }
- else {
+ } else {
return configName + "/" + CHILD_NODE_NAME;
}
}
@@ -138,7 +133,9 @@
}
@Override
- public boolean persistConfiguration(@NotNull ResourceResolver resourceResolver, @NotNull String configResourcePath,
+ public boolean persistConfiguration(
+ @NotNull ResourceResolver resourceResolver,
+ @NotNull String configResourcePath,
@NotNull ConfigurationPersistData data) {
getOrCreateResource(resourceResolver, getResourcePath(configResourcePath), data.getProperties());
commit(resourceResolver);
@@ -146,7 +143,9 @@
}
@Override
- public boolean persistConfigurationCollection(@NotNull ResourceResolver resourceResolver, @NotNull String configResourceCollectionParentPath,
+ public boolean persistConfigurationCollection(
+ @NotNull ResourceResolver resourceResolver,
+ @NotNull String configResourceCollectionParentPath,
@NotNull ConfigurationCollectionPersistData data) {
String parentPath = getCollectionParentResourcePath(configResourceCollectionParentPath);
Resource configResourceParent = getOrCreateResource(resourceResolver, parentPath, ValueMap.EMPTY);
@@ -154,13 +153,15 @@
// delete existing children and create new ones
deleteChildren(configResourceParent);
for (ConfigurationPersistData item : data.getItems()) {
- String path = getCollectionItemResourcePath(configResourceParent.getPath() + "/" + item.getCollectionItemName());
+ String path =
+ getCollectionItemResourcePath(configResourceParent.getPath() + "/" + item.getCollectionItemName());
getOrCreateResource(resourceResolver, path, item.getProperties());
}
// if resource collection parent properties are given replace them as well
if (data.getProperties() != null) {
- Resource propsResource = getOrCreateResource(resourceResolver, parentPath + "/colPropsResource", ValueMap.EMPTY);
+ Resource propsResource =
+ getOrCreateResource(resourceResolver, parentPath + "/colPropsResource", ValueMap.EMPTY);
replaceProperties(propsResource, data.getProperties());
}
@@ -174,22 +175,23 @@
if (resource != null) {
try {
resourceResolver.delete(resource);
- }
- catch (PersistenceException ex) {
- throw new ConfigurationPersistenceException("Unable to delete configuration at " + configResourcePath, ex);
+ } catch (PersistenceException ex) {
+ throw new ConfigurationPersistenceException(
+ "Unable to delete configuration at " + configResourcePath, ex);
}
}
commit(resourceResolver);
return true;
}
- private Resource getOrCreateResource(ResourceResolver resourceResolver, String path, Map<String,Object> properties) {
+ private Resource getOrCreateResource(
+ ResourceResolver resourceResolver, String path, Map<String, Object> properties) {
try {
- Resource resource = ResourceUtil.getOrCreateResource(resourceResolver, path, DEFAULT_RESOURCE_TYPE, DEFAULT_RESOURCE_TYPE, false);
+ Resource resource = ResourceUtil.getOrCreateResource(
+ resourceResolver, path, DEFAULT_RESOURCE_TYPE, DEFAULT_RESOURCE_TYPE, false);
replaceProperties(resource, properties);
return resource;
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to persist configuration to " + path, ex);
}
}
@@ -200,14 +202,13 @@
for (Resource child : resource.getChildren()) {
resourceResolver.delete(child);
}
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to remove children from " + resource.getPath(), ex);
}
}
@SuppressWarnings("null")
- private void replaceProperties(Resource resource, Map<String,Object> properties) {
+ private void replaceProperties(Resource resource, Map<String, Object> properties) {
ModifiableValueMap modValueMap = resource.adaptTo(ModifiableValueMap.class);
// remove all existing properties that do not have jcr: namespace
for (String propertyName : new HashSet<>(modValueMap.keySet())) {
@@ -222,8 +223,7 @@
private void commit(ResourceResolver resourceResolver) {
try {
resourceResolver.commit();
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to save configuration: " + ex.getMessage(), ex);
}
}
@@ -231,5 +231,4 @@
static boolean containsJcrContent(String path) {
return JCR_CONTENT_PATTERN.matcher(path).matches();
}
-
}
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy3.java b/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy3.java
index 3641adb..4a8092a 100644
--- a/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy3.java
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/persistence/CustomConfigurationPersistenceStrategy3.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.testing.mock.caconfig.persistence;
-import static org.junit.Assert.assertNotNull;
-
import java.util.HashSet;
import java.util.Map;
import java.util.regex.Pattern;
@@ -39,6 +37,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import static org.junit.Assert.assertNotNull;
+
/**
* This is a variant of {@link org.apache.sling.caconfig.impl.def.DefaultConfigurationPersistenceStrategy}
* which reads and stores data from a sub-resources named "jcr:content".
@@ -51,7 +51,8 @@
private static final String DEFAULT_RESOURCE_TYPE = JcrConstants.NT_UNSTRUCTURED;
private static final String CHILD_NODE_NAME = JcrConstants.JCR_CONTENT;
- private static final Pattern JCR_CONTENT_PATTERN = Pattern.compile("(.*/)?" + Pattern.quote(CHILD_NODE_NAME) + "(/.*)?");
+ private static final Pattern JCR_CONTENT_PATTERN =
+ Pattern.compile("(.*/)?" + Pattern.quote(CHILD_NODE_NAME) + "(/.*)?");
@Override
public Resource getResource(@NotNull Resource resource) {
@@ -114,7 +115,9 @@
}
@Override
- public boolean persistConfiguration(@NotNull ResourceResolver resourceResolver, @NotNull String configResourcePath,
+ public boolean persistConfiguration(
+ @NotNull ResourceResolver resourceResolver,
+ @NotNull String configResourcePath,
@NotNull ConfigurationPersistData data) {
getOrCreateResource(resourceResolver, getResourcePath(configResourcePath), data.getProperties());
commit(resourceResolver);
@@ -122,7 +125,9 @@
}
@Override
- public boolean persistConfigurationCollection(@NotNull ResourceResolver resourceResolver, @NotNull String configResourceCollectionParentPath,
+ public boolean persistConfigurationCollection(
+ @NotNull ResourceResolver resourceResolver,
+ @NotNull String configResourceCollectionParentPath,
@NotNull ConfigurationCollectionPersistData data) {
String parentPath = getCollectionParentResourcePath(configResourceCollectionParentPath);
Resource configResourceParent = getOrCreateResource(resourceResolver, parentPath, ValueMap.EMPTY);
@@ -130,13 +135,15 @@
// delete existing children and create new ones
deleteChildren(configResourceParent);
for (ConfigurationPersistData item : data.getItems()) {
- String path = getCollectionItemResourcePath(configResourceParent.getPath() + "/" + item.getCollectionItemName());
+ String path =
+ getCollectionItemResourcePath(configResourceParent.getPath() + "/" + item.getCollectionItemName());
getOrCreateResource(resourceResolver, path, item.getProperties());
}
// if resource collection parent properties are given replace them as well
if (data.getProperties() != null) {
- Resource propsResource = getOrCreateResource(resourceResolver, parentPath + "/colPropsResource", ValueMap.EMPTY);
+ Resource propsResource =
+ getOrCreateResource(resourceResolver, parentPath + "/colPropsResource", ValueMap.EMPTY);
replaceProperties(propsResource, data.getProperties());
}
@@ -150,22 +157,23 @@
if (resource != null) {
try {
resourceResolver.delete(resource);
- }
- catch (PersistenceException ex) {
- throw new ConfigurationPersistenceException("Unable to delete configuration at " + configResourcePath, ex);
+ } catch (PersistenceException ex) {
+ throw new ConfigurationPersistenceException(
+ "Unable to delete configuration at " + configResourcePath, ex);
}
}
commit(resourceResolver);
return true;
}
- private Resource getOrCreateResource(ResourceResolver resourceResolver, String path, Map<String,Object> properties) {
+ private Resource getOrCreateResource(
+ ResourceResolver resourceResolver, String path, Map<String, Object> properties) {
try {
- Resource resource = ResourceUtil.getOrCreateResource(resourceResolver, path, DEFAULT_RESOURCE_TYPE, DEFAULT_RESOURCE_TYPE, false);
+ Resource resource = ResourceUtil.getOrCreateResource(
+ resourceResolver, path, DEFAULT_RESOURCE_TYPE, DEFAULT_RESOURCE_TYPE, false);
replaceProperties(resource, properties);
return resource;
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to persist configuration to " + path, ex);
}
}
@@ -176,14 +184,13 @@
for (Resource child : resource.getChildren()) {
resourceResolver.delete(child);
}
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to remove children from " + resource.getPath(), ex);
}
}
@SuppressWarnings("null")
- private void replaceProperties(Resource resource, Map<String,Object> properties) {
+ private void replaceProperties(Resource resource, Map<String, Object> properties) {
ModifiableValueMap modValueMap = resource.adaptTo(ModifiableValueMap.class);
// remove all existing properties that do not have jcr: namespace
for (String propertyName : new HashSet<>(modValueMap.keySet())) {
@@ -198,8 +205,7 @@
private void commit(ResourceResolver resourceResolver) {
try {
resourceResolver.commit();
- }
- catch (PersistenceException ex) {
+ } catch (PersistenceException ex) {
throw new ConfigurationPersistenceException("Unable to save configuration: " + ex.getMessage(), ex);
}
}
@@ -207,5 +213,4 @@
static boolean containsJcrContent(String path) {
return JCR_CONTENT_PATTERN.matcher(path).matches();
}
-
}