This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch feature/SLING-12360-parent-60 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-caconfig.git
commit e0d1a9b628f89ebc5a4376924f6248100cddebf3 Author: Stefan Seifert <stefanseif...@users.noreply.github.com> AuthorDate: Mon Jun 24 14:51:52 2024 +0200 SLING-12360 apply spotless code formatting --- pom.xml | 30 +++--- .../annotations/ContextAwareConfiguration.java | 39 ++++---- .../models/caconfig/annotations/package-info.java | 2 +- .../ContextAwareConfigurationInjector.java | 78 ++++++++------- .../ContextAwareConfigurationProcessor.java | 1 - .../caconfig/example/caconfig/ListConfig.java | 1 - .../caconfig/example/caconfig/SingleConfig.java | 1 - .../caconfig/model/ConfigurationValuesModel.java | 8 +- .../invalidmodel/InvalidAnnotationListModel.java | 3 +- .../invalidmodel/InvalidAnnotationModel.java | 3 +- .../example/invalidmodel/InvalidInjectModel.java | 3 +- .../example/invalidmodel/InvalidSetModel.java | 3 +- .../example/model/ListConfigAdaptModel.java | 3 +- .../caconfig/example/model/ListConfigModel.java | 3 +- .../example/model/ListConfigValueMapModel.java | 3 +- .../example/model/SingleConfigAdaptModel.java | 3 +- .../caconfig/example/model/SingleConfigModel.java | 3 +- .../example/model/SingleConfigValueMapModel.java | 3 +- .../example/testhelper/ListConfigGetter.java | 1 - .../example/testhelper/SingleConfigGetter.java | 1 - .../ContextAwareConfigurationInjectorTest.java | 108 ++++++++++++--------- 21 files changed, 157 insertions(+), 143 deletions(-) diff --git a/pom.xml b/pom.xml index 2c10f2a..c4245e0 100644 --- a/pom.xml +++ b/pom.xml @@ -36,14 +36,26 @@ <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-caconfig.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-caconfig.git</developerConnection> + <tag>HEAD</tag> <url>https://github.com/apache/sling-org-apache-sling-models-caconfig.git</url> - <tag>HEAD</tag> - </scm> + </scm> <properties> <project.build.outputTimestamp>2022-08-08T14:03:16Z</project.build.outputTimestamp> </properties> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.junit</groupId> + <artifactId>junit-bom</artifactId> + <version>5.8.2</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> <dependency> @@ -153,21 +165,9 @@ </dependencies> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.junit</groupId> - <artifactId>junit-bom</artifactId> - <version>5.8.2</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - <build> <plugins> - + <plugin> <groupId>biz.aQute.bnd</groupId> <artifactId>bnd-baseline-maven-plugin</artifactId> diff --git a/src/main/java/org/apache/sling/models/caconfig/annotations/ContextAwareConfiguration.java b/src/main/java/org/apache/sling/models/caconfig/annotations/ContextAwareConfiguration.java index 0c527b5..59df346 100644 --- a/src/main/java/org/apache/sling/models/caconfig/annotations/ContextAwareConfiguration.java +++ b/src/main/java/org/apache/sling/models/caconfig/annotations/ContextAwareConfiguration.java @@ -1,26 +1,23 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.models.caconfig.annotations; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -28,12 +25,17 @@ import org.apache.sling.models.annotations.Source; import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; import org.apache.sling.models.spi.injectorspecific.InjectAnnotation; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + /** * Annotation to be used on either methods, fields or constructor parameters to let Sling Models inject a context-aware configuration. * The annotation supports the same features and semantics as {@link org.apache.sling.caconfig.ConfigurationBuilder}. * For configuration collections, you can use arrays, {@link java.util.List} or {@link java.util.Collection} variables. */ -@Target({ METHOD, FIELD, PARAMETER }) +@Target({METHOD, FIELD, PARAMETER}) @Retention(RUNTIME) @InjectAnnotation @Source("caconfig") @@ -53,5 +55,4 @@ public @interface ContextAwareConfiguration { * Default value = DEFAULT. */ public InjectionStrategy injectionStrategy() default InjectionStrategy.DEFAULT; - } diff --git a/src/main/java/org/apache/sling/models/caconfig/annotations/package-info.java b/src/main/java/org/apache/sling/models/caconfig/annotations/package-info.java index 35cfc58..abd3645 100644 --- a/src/main/java/org/apache/sling/models/caconfig/annotations/package-info.java +++ b/src/main/java/org/apache/sling/models/caconfig/annotations/package-info.java @@ -20,4 +20,4 @@ @Version("1.0.0") package org.apache.sling.models.caconfig.annotations; -import org.osgi.annotation.versioning.Version; \ No newline at end of file +import org.osgi.annotation.versioning.Version; diff --git a/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjector.java b/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjector.java index 73aaca0..726fb3e 100644 --- a/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjector.java +++ b/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjector.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.models.caconfig.impl.injectors; @@ -48,16 +50,19 @@ import org.osgi.service.component.propertytypes.ServiceRanking; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Component(service = { Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class }) +@Component(service = {Injector.class, StaticInjectAnnotationProcessorFactory.class, AcceptsNullName.class}) @ServiceRanking(6000) -public class ContextAwareConfigurationInjector implements Injector, StaticInjectAnnotationProcessorFactory, AcceptsNullName { +public class ContextAwareConfigurationInjector + implements Injector, StaticInjectAnnotationProcessorFactory, AcceptsNullName { private static final Logger log = LoggerFactory.getLogger(ContextAwareConfigurationInjector.class); @Reference private ConfigurationResolver configurationResolver; + @Reference - private ConfigurationInjectResourceDetectionStrategyMultiplexer configurationInjectResourceDetectionStrategyMultiplexer; + private ConfigurationInjectResourceDetectionStrategyMultiplexer + configurationInjectResourceDetectionStrategyMultiplexer; @Override public @NotNull String getName() { @@ -75,8 +80,11 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject } @Override - public Object getValue(@NotNull Object adaptable, String name, - @NotNull Type declaredType, @NotNull AnnotatedElement element, + public Object getValue( + @NotNull Object adaptable, + String name, + @NotNull Type declaredType, + @NotNull AnnotatedElement element, @NotNull DisposalCallbackRegistry callbackRegistry) { ContextAwareConfiguration annotation = getAnnotation(element); @@ -99,9 +107,10 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject configurationBuilder = configurationBuilder.name(annotation.name()); } - // detect from declared type if a single configuration or configuration collection is requested and return the configuration + // detect from declared type if a single configuration or configuration collection is requested and return the + // configuration if (declaredType instanceof Class) { - Class<?> clazz = (Class<?>)declaredType; + Class<?> clazz = (Class<?>) declaredType; if (clazz.isArray()) { Collection<?> result = getConfigurationCollection(configurationBuilder, clazz.getComponentType()); Object array = Array.newInstance(clazz.getComponentType(), result.size()); @@ -111,13 +120,11 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject Array.set(array, i++, resultIterator.next()); } return array; - } - else { + } else { return getConfiguration(configurationBuilder, clazz); } - } - else if (declaredType instanceof ParameterizedType) { - ParameterizedType parameterizedType = (ParameterizedType)declaredType; + } else if (declaredType instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) declaredType; if (parameterizedType.getActualTypeArguments().length != 1) { return null; } @@ -129,12 +136,10 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject Collection<?> result = getConfigurationCollection(configurationBuilder, clazz); if (collectionType.equals(List.class)) { return new ArrayList<>(result); - } - else { + } else { return result; } - } - else { + } else { log.warn("Cannot handle type {}", declaredType); return null; } @@ -146,10 +151,10 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject private @Nullable Resource getResource(@NotNull Object adaptable) { if (adaptable instanceof Resource) { - return (Resource)adaptable; + return (Resource) adaptable; } if (adaptable instanceof SlingHttpServletRequest) { - SlingHttpServletRequest request = (SlingHttpServletRequest)adaptable; + SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable; Resource resource = configurationInjectResourceDetectionStrategyMultiplexer.detectResource(request); if (resource == null) { resource = request.getResource(); @@ -159,7 +164,8 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject return null; } - private @Nullable Object getConfiguration(@NotNull ConfigurationBuilder configurationBuilder, @NotNull Class<?> clazz) { + private @Nullable Object getConfiguration( + @NotNull ConfigurationBuilder configurationBuilder, @NotNull Class<?> clazz) { try { if (clazz.equals(ValueMap.class)) { return configurationBuilder.asValueMap(); @@ -168,13 +174,13 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject return configurationBuilder.as(clazz); } return configurationBuilder.asAdaptable(clazz); - } - catch (ConfigurationResolveException ex) { + } catch (ConfigurationResolveException ex) { throw new ConfigurationResolveException("Class " + clazz.getName() + ": " + ex.getMessage(), ex); } } - private @NotNull Collection<?> getConfigurationCollection(@NotNull ConfigurationBuilder configurationBuilder, @NotNull Class<?> clazz) { + private @NotNull Collection<?> getConfigurationCollection( + @NotNull ConfigurationBuilder configurationBuilder, @NotNull Class<?> clazz) { try { if (clazz.equals(ValueMap.class)) { return configurationBuilder.asValueMapCollection(); @@ -183,8 +189,7 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject return configurationBuilder.asCollection(clazz); } return configurationBuilder.asAdaptableCollection(clazz); - } - catch (ConfigurationResolveException ex) { + } catch (ConfigurationResolveException ex) { throw new ConfigurationResolveException("Class " + clazz.getName() + ": " + ex.getMessage(), ex); } } @@ -192,5 +197,4 @@ public class ContextAwareConfigurationInjector implements Injector, StaticInject private boolean isContextAwareConfigAnnotationClass(Class<?> clazz) { return clazz.isAnnotation() && clazz.isAnnotationPresent(Configuration.class); } - } diff --git a/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationProcessor.java b/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationProcessor.java index 30bcec4..1f89dae 100644 --- a/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationProcessor.java +++ b/src/main/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationProcessor.java @@ -34,5 +34,4 @@ class ContextAwareConfigurationProcessor extends AbstractInjectAnnotationProcess public InjectionStrategy getInjectionStrategy() { return annotation.injectionStrategy(); } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/caconfig/ListConfig.java b/src/test/java/org/apache/sling/models/caconfig/example/caconfig/ListConfig.java index 104419d..4675113 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/caconfig/ListConfig.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/caconfig/ListConfig.java @@ -28,5 +28,4 @@ public @interface ListConfig { int intParam() default 5; boolean boolParam(); - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/caconfig/SingleConfig.java b/src/test/java/org/apache/sling/models/caconfig/example/caconfig/SingleConfig.java index 61ee707..b2eb604 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/caconfig/SingleConfig.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/caconfig/SingleConfig.java @@ -28,5 +28,4 @@ public @interface SingleConfig { int intParam() default 5; boolean boolParam(); - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/caconfig/model/ConfigurationValuesModel.java b/src/test/java/org/apache/sling/models/caconfig/example/caconfig/model/ConfigurationValuesModel.java index 664463d..e0767b0 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/caconfig/model/ConfigurationValuesModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/caconfig/model/ConfigurationValuesModel.java @@ -31,28 +31,34 @@ public class ConfigurationValuesModel { @ValueMapValue private String stringParam; + @ValueMapValue private int intParam; + @ValueMapValue private boolean boolParam; public String getStringParam() { return stringParam; } + public void setStringParam(String stringParam) { this.stringParam = stringParam; } + public int getIntParam() { return intParam; } + public void setIntParam(int intParam) { this.intParam = intParam; } + public boolean isBoolParam() { return boolParam; } + public void setBoolParam(boolean boolParam) { this.boolParam = boolParam; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationListModel.java b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationListModel.java index 4187fe6..d6f0662 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationListModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationListModel.java @@ -25,7 +25,7 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class InvalidAnnotationListModel { // "Model" is not a valid caconfig annotation @@ -35,5 +35,4 @@ public class InvalidAnnotationListModel { public List<Model> getConfigList() { return configList; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationModel.java b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationModel.java index 21a0fdb..383d683 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidAnnotationModel.java @@ -23,7 +23,7 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class InvalidAnnotationModel { // "Model" is not a valid caconfig annotation @@ -33,5 +33,4 @@ public class InvalidAnnotationModel { public Model getConfig() { return config; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidInjectModel.java b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidInjectModel.java index 5c7e832..d33994d 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidInjectModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidInjectModel.java @@ -26,7 +26,7 @@ import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.Source; import org.apache.sling.models.caconfig.example.caconfig.SingleConfig; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class InvalidInjectModel { // only injection with explicit annotation @ContextAwareConfiguration is supported @@ -37,5 +37,4 @@ public class InvalidInjectModel { public SingleConfig getConfig() { return config; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidSetModel.java b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidSetModel.java index 28232dc..d026f4a 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidSetModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/invalidmodel/InvalidSetModel.java @@ -26,7 +26,7 @@ import org.apache.sling.models.annotations.Model; import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; import org.apache.sling.models.caconfig.example.caconfig.ListConfig; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class InvalidSetModel { // Set is not supported as collection type @@ -36,5 +36,4 @@ public class InvalidSetModel { public Set<ListConfig> getConfigList() { return configList; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigAdaptModel.java b/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigAdaptModel.java index a872973..223899e 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigAdaptModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigAdaptModel.java @@ -28,7 +28,7 @@ import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; import org.apache.sling.models.caconfig.example.caconfig.model.ConfigurationValuesModel; import org.apache.sling.models.caconfig.example.testhelper.ListConfigGetter; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class ListConfigAdaptModel implements ListConfigGetter<ConfigurationValuesModel> { @ContextAwareConfiguration(name = "org.apache.sling.models.caconfig.example.caconfig.ListConfig") @@ -54,5 +54,4 @@ public class ListConfigAdaptModel implements ListConfigGetter<ConfigurationValue public ConfigurationValuesModel[] getConfigArray() { return configArray; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigModel.java b/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigModel.java index e8315e5..4383879 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigModel.java @@ -28,7 +28,7 @@ import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; import org.apache.sling.models.caconfig.example.caconfig.ListConfig; import org.apache.sling.models.caconfig.example.testhelper.ListConfigGetter; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class ListConfigModel implements ListConfigGetter<ListConfig> { @ContextAwareConfiguration @@ -54,5 +54,4 @@ public class ListConfigModel implements ListConfigGetter<ListConfig> { public ListConfig[] getConfigArray() { return configArray; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigValueMapModel.java b/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigValueMapModel.java index e092a0e..167b31a 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigValueMapModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/model/ListConfigValueMapModel.java @@ -28,7 +28,7 @@ import org.apache.sling.models.annotations.Model; import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; import org.apache.sling.models.caconfig.example.testhelper.ListConfigGetter; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class ListConfigValueMapModel implements ListConfigGetter<ValueMap> { @ContextAwareConfiguration(name = "org.apache.sling.models.caconfig.example.caconfig.ListConfig") @@ -54,5 +54,4 @@ public class ListConfigValueMapModel implements ListConfigGetter<ValueMap> { public ValueMap[] getConfigArray() { return configArray; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigAdaptModel.java b/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigAdaptModel.java index 504d93a..329c25a 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigAdaptModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigAdaptModel.java @@ -25,7 +25,7 @@ import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; import org.apache.sling.models.caconfig.example.caconfig.model.ConfigurationValuesModel; import org.apache.sling.models.caconfig.example.testhelper.SingleConfigGetter; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class SingleConfigAdaptModel implements SingleConfigGetter<ConfigurationValuesModel> { @ContextAwareConfiguration(name = "testSingleConfig") @@ -35,5 +35,4 @@ public class SingleConfigAdaptModel implements SingleConfigGetter<ConfigurationV public ConfigurationValuesModel getConfig() { return config; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigModel.java b/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigModel.java index 62cb6ab..c42b47a 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigModel.java @@ -26,7 +26,7 @@ import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; import org.apache.sling.models.caconfig.example.caconfig.SingleConfig; import org.apache.sling.models.caconfig.example.testhelper.SingleConfigGetter; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class, ResourceResolver.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class, ResourceResolver.class}) public class SingleConfigModel implements SingleConfigGetter<SingleConfig> { @ContextAwareConfiguration @@ -36,5 +36,4 @@ public class SingleConfigModel implements SingleConfigGetter<SingleConfig> { public SingleConfig getConfig() { return config; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigValueMapModel.java b/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigValueMapModel.java index 0c814e3..b81bda3 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigValueMapModel.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/model/SingleConfigValueMapModel.java @@ -25,7 +25,7 @@ import org.apache.sling.models.annotations.Model; import org.apache.sling.models.caconfig.annotations.ContextAwareConfiguration; import org.apache.sling.models.caconfig.example.testhelper.SingleConfigGetter; -@Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) +@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}) public class SingleConfigValueMapModel implements SingleConfigGetter<ValueMap> { @ContextAwareConfiguration(name = "testSingleConfig") @@ -35,5 +35,4 @@ public class SingleConfigValueMapModel implements SingleConfigGetter<ValueMap> { public ValueMap getConfig() { return config; } - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/testhelper/ListConfigGetter.java b/src/test/java/org/apache/sling/models/caconfig/example/testhelper/ListConfigGetter.java index 56ef1fa..1a1e379 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/testhelper/ListConfigGetter.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/testhelper/ListConfigGetter.java @@ -28,5 +28,4 @@ public interface ListConfigGetter<T> { Collection<T> getConfigCollection(); T[] getConfigArray(); - } diff --git a/src/test/java/org/apache/sling/models/caconfig/example/testhelper/SingleConfigGetter.java b/src/test/java/org/apache/sling/models/caconfig/example/testhelper/SingleConfigGetter.java index 7aaa6a8..16e574b 100644 --- a/src/test/java/org/apache/sling/models/caconfig/example/testhelper/SingleConfigGetter.java +++ b/src/test/java/org/apache/sling/models/caconfig/example/testhelper/SingleConfigGetter.java @@ -21,5 +21,4 @@ package org.apache.sling.models.caconfig.example.testhelper; public interface SingleConfigGetter<T> { T getConfig(); - } diff --git a/src/test/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjectorTest.java b/src/test/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjectorTest.java index b7e0da6..4cc148e 100644 --- a/src/test/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjectorTest.java +++ b/src/test/java/org/apache/sling/models/caconfig/impl/injectors/ContextAwareConfigurationInjectorTest.java @@ -18,14 +18,11 @@ */ package org.apache.sling.models.caconfig.impl.injectors; -import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - import java.util.List; import java.util.function.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.adapter.Adaptable; @@ -58,32 +55,36 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.osgi.framework.Constants; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; @ExtendWith(SlingContextExtension.class) class ContextAwareConfigurationInjectorTest { - private final SlingContext context = new SlingContextBuilder() - .plugin(CACONFIG) - .build(); + private final SlingContext context = + new SlingContextBuilder().plugin(CACONFIG).build(); @BeforeEach void setUp() { MockContextAwareConfig.registerAnnotationPackages(context, "org.apache.sling.models.caconfig.example.caconfig"); context.addModelsForPackage("org.apache.sling.models.caconfig.example.model"); - context.create().resource("/content/region/site", - "sling:configRef", "/conf/region/site"); + context.create().resource("/content/region/site", "sling:configRef", "/conf/region/site"); context.currentResource(context.create().resource("/content/region/site/en")); - MockContextAwareConfig.writeConfiguration(context, "/content/region/site", SingleConfig.class, - "stringParam", "value1"); + MockContextAwareConfig.writeConfiguration( + context, "/content/region/site", SingleConfig.class, "stringParam", "value1"); - MockContextAwareConfig.writeConfigurationCollection(context, "/content/region/site", ListConfig.class, ImmutableList.of( - ImmutableMap.<String,Object>of("stringParam", "item1"), - ImmutableMap.<String,Object>of("stringParam", "item2"))); + MockContextAwareConfig.writeConfigurationCollection( + context, + "/content/region/site", + ListConfig.class, + ImmutableList.of( + ImmutableMap.<String, Object>of("stringParam", "item1"), + ImmutableMap.<String, Object>of("stringParam", "item2"))); } @Test @@ -94,31 +95,40 @@ class ContextAwareConfigurationInjectorTest { @Test void testSingleConfigModel_Request_WithConfigurationInjectResourceDetectionStrategy() { // set another resource as current resource which has not caconfig applied - Resource otherCurrentResource = context.currentResource(context.create().resource("/content/region2/site2/en2")); - // register a custom ConfigurationInjectResourceDetectionStrategy which redirects to a resource with caconfig available - context.registerService(ConfigurationInjectResourceDetectionStrategy.class, new ConfigurationInjectResourceDetectionStrategy() { - @Override - @SuppressWarnings("null") - public @Nullable Resource detectResource(@NotNull SlingHttpServletRequest request) { - if (StringUtils.equals(request.getResource().getPath(), otherCurrentResource.getPath())) { - return context.resourceResolver().getResource("/content/region/site/en"); - } - return null; - } - }, Constants.SERVICE_RANKING, 100); + Resource otherCurrentResource = + context.currentResource(context.create().resource("/content/region2/site2/en2")); + // register a custom ConfigurationInjectResourceDetectionStrategy which redirects to a resource with caconfig + // available + context.registerService( + ConfigurationInjectResourceDetectionStrategy.class, + new ConfigurationInjectResourceDetectionStrategy() { + @Override + @SuppressWarnings("null") + public @Nullable Resource detectResource(@NotNull SlingHttpServletRequest request) { + if (StringUtils.equals(request.getResource().getPath(), otherCurrentResource.getPath())) { + return context.resourceResolver().getResource("/content/region/site/en"); + } + return null; + } + }, + Constants.SERVICE_RANKING, + 100); assertSingleConfig(SingleConfigModel.class, context.request(), SingleConfig::stringParam); } @Test void testSingleConfigModel_Request_WithConfigurationInjectResourceDetectionStrategy_NoStrategies() { // simulate no registered strategies - context.registerService(ConfigurationInjectResourceDetectionStrategyMultiplexer.class, new ConfigurationInjectResourceDetectionStrategyMultiplexer() { - @Override - public @Nullable Resource detectResource(@NotNull SlingHttpServletRequest request) { - return null; - } - - }, Constants.SERVICE_RANKING, 100); + context.registerService( + ConfigurationInjectResourceDetectionStrategyMultiplexer.class, + new ConfigurationInjectResourceDetectionStrategyMultiplexer() { + @Override + public @Nullable Resource detectResource(@NotNull SlingHttpServletRequest request) { + return null; + } + }, + Constants.SERVICE_RANKING, + 100); assertSingleConfig(SingleConfigModel.class, context.request(), SingleConfig::stringParam); } @@ -129,12 +139,16 @@ class ContextAwareConfigurationInjectorTest { @Test void testSingleConfigValueMapModel_Request() { - assertSingleConfig(SingleConfigValueMapModel.class, context.request(), map -> map.get("stringParam", String.class)); + assertSingleConfig( + SingleConfigValueMapModel.class, context.request(), map -> map.get("stringParam", String.class)); } @Test void testSingleConfigValueMapModel_Resource() { - assertSingleConfig(SingleConfigValueMapModel.class, context.currentResource(), map -> map.get("stringParam", String.class)); + assertSingleConfig( + SingleConfigValueMapModel.class, + context.currentResource(), + map -> map.get("stringParam", String.class)); } @Test @@ -144,7 +158,8 @@ class ContextAwareConfigurationInjectorTest { @Test void testSingleConfigAdaptModel_Resource() { - assertSingleConfig(SingleConfigAdaptModel.class, context.currentResource(), ConfigurationValuesModel::getStringParam); + assertSingleConfig( + SingleConfigAdaptModel.class, context.currentResource(), ConfigurationValuesModel::getStringParam); } @Test @@ -164,7 +179,8 @@ class ContextAwareConfigurationInjectorTest { @Test void testListConfigValueMapModel_Resource() { - assertListConfig(ListConfigValueMapModel.class, context.currentResource(), map -> map.get("stringParam", String.class)); + assertListConfig( + ListConfigValueMapModel.class, context.currentResource(), map -> map.get("stringParam", String.class)); } @Test @@ -174,10 +190,12 @@ class ContextAwareConfigurationInjectorTest { @Test void testListConfigAdaptModel_Resource() { - assertListConfig(ListConfigAdaptModel.class, context.currentResource(), ConfigurationValuesModel::getStringParam); + assertListConfig( + ListConfigAdaptModel.class, context.currentResource(), ConfigurationValuesModel::getStringParam); } - private <T> void assertSingleConfig(Class<? extends SingleConfigGetter<T>> modelClass, Adaptable adaptable, Function<T,String> extractor) { + private <T> void assertSingleConfig( + Class<? extends SingleConfigGetter<T>> modelClass, Adaptable adaptable, Function<T, String> extractor) { context.registerInjectActivateService(ContextAwareConfigurationInjector.class); SingleConfigGetter<T> model = adaptable.adaptTo(modelClass); assertNotNull(model); @@ -185,7 +203,8 @@ class ContextAwareConfigurationInjectorTest { assertEquals("value1", extractor.apply(config)); } - private <T> void assertListConfig(Class<? extends ListConfigGetter<T>> modelClass, Adaptable adaptable, Function<T,String> extractor) { + private <T> void assertListConfig( + Class<? extends ListConfigGetter<T>> modelClass, Adaptable adaptable, Function<T, String> extractor) { context.registerInjectActivateService(ContextAwareConfigurationInjector.class); ListConfigGetter<T> model = adaptable.adaptTo(modelClass); assertNotNull(model); @@ -194,7 +213,7 @@ class ContextAwareConfigurationInjectorTest { assertListValues(ImmutableList.copyOf(model.getConfigArray()), extractor); } - private <T> void assertListValues(List<T> configList, Function<T,String> extractor) { + private <T> void assertListValues(List<T> configList, Function<T, String> extractor) { assertNotNull(configList); assertEquals(2, configList.size()); assertEquals("item1", extractor.apply(configList.get(0))); @@ -239,5 +258,4 @@ class ContextAwareConfigurationInjectorTest { InvalidSetModel model = context.request().adaptTo(InvalidSetModel.class); assertNull(model); } - }