Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 26, 2024
2 parents aed6835 + 4b96fed commit 86e12ea
Show file tree
Hide file tree
Showing 25 changed files with 566 additions and 73 deletions.
15 changes: 15 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="5.5.0" date="2024-01-26">
<action type="add" dev="sseifert" issue="30">
Add mock for AssetDelivery OSGi service for Web-Optimized Image Delivery (not registered by default).
</action>
<action type="add" dev="sseifert" issue="31">
Add mock for MockNextGenDynamicMediaConfig OSGi service (not registered by default).
</action>
<action type="update" dev="sseifert">
Update to latest JCR Mock, OSGI Mock, ResourceResolver Mock, Sling Mock.
</action>
<action type="update" dev="sseifert">
Switch to AEM 6.5.17 as minimum version.
</action>
</release>

<release version="5.4.4" date="2023-12-12">
<action type="update" dev="sseifert">
Update to latest Sling Mock.
Expand Down
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.4.4</version>
<version>5.5.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -210,20 +210,20 @@
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-tiff</artifactId>
<version>3.7.0</version>
<version>3.10.1</version>
<scope>test</scope>
</dependency>
<!-- Java ImageIO Support for SVG -->
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-batik</artifactId>
<version>3.7.0</version>
<version>3.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.9.1</version>
<version>1.17</version>
<scope>test</scope>
</dependency>

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/io/wcm/testing/mock/aem/MockComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package io.wcm.testing.mock.aem;

import static org.apache.sling.api.resource.ResourceResolver.PROPERTY_RESOURCE_TYPE;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -41,8 +43,6 @@
import com.day.cq.wcm.api.components.ComponentEditConfig;
import com.day.cq.wcm.api.components.VirtualComponent;

import static org.apache.sling.api.resource.ResourceResolver.PROPERTY_RESOURCE_TYPE;

/**
* Mock implementation of {@link Component}.
*/
Expand Down Expand Up @@ -261,12 +261,12 @@ private static class RemoveKeyPrefixMap extends ValueMapDecorator {
}

@Override
public <T> T get(String name, Class<T> type) {
public <T> T get(@NotNull String name, Class<T> type) {
return super.get(removeKeyPrefix(name), type);
}

@Override
public <T> T get(String name, T defaultValue) {
public <T> T get(@NotNull String name, T defaultValue) {
return super.get(removeKeyPrefix(name), defaultValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ public Resource getResource() {

@Override
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@SuppressWarnings("java:S2583") // null check
public Component getComponent() {
Resource currentResource = getResource();
if (currentResource == null) {
return null;
}
ComponentManager componentManager = currentResource.getResourceResolver().adaptTo(ComponentManager.class);
if (componentManager == null) {
throw new RuntimeException("No component manager.");
throw new IllegalStateException("No component manager.");
}
return componentManager.getComponentOfResource(currentResource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
/**
* Mock implementation of {@link ContentFragment}.
*/
class MockContentFragment extends MockContentFragment_Versionable implements ContentFragment {
final class MockContentFragment extends MockContentFragment_Versionable implements ContentFragment {

private final Resource assetResource;
private final Asset asset;
Expand Down Expand Up @@ -262,35 +262,41 @@ public void removeVariation(String variation) throws ContentFragmentException {
}

// latest AEM Cloud API
@Override
public @Nullable Calendar getLastModifiedDate() {
throw new UnsupportedOperationException();
}

// latest AEM Cloud API
@Override
@SuppressWarnings("unused")
public @NotNull Calendar getLastModifiedDeep() throws ContentFragmentException {
throw new UnsupportedOperationException();
}

// latest AEM Cloud API
@Override
@SuppressWarnings("unused")
public void setTags(@NotNull Tag[] tags) throws ContentFragmentException {
throw new UnsupportedOperationException();
}

// latest AEM Cloud API
@Override
@SuppressWarnings("unused")
public @NotNull Tag[] getTags() throws ContentFragmentException {
throw new UnsupportedOperationException();
}

// latest AEM Cloud API
@Override
@SuppressWarnings("unused")
public void setVariationTags(@NotNull Tag[] tags, @NotNull String variationName) throws ContentFragmentException {
throw new UnsupportedOperationException();
}

// latest AEM Cloud API
@Override
@SuppressWarnings("unused")
public @NotNull Tag[] getVariationTags(@NotNull String variationName) throws ContentFragmentException {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
public final class MockLanguageManager implements LanguageManager {

@Override
@Deprecated
@Deprecated(forRemoval = true)
public Map<Locale, Info> getAdjacentInfo(final ResourceResolver resourceResolver, final String path) {
return Optional.ofNullable(getAdjacentLanguageInfo(resourceResolver, path))
.map(Map::entrySet)
Expand All @@ -71,6 +71,7 @@ public Map<Locale, Info> getAdjacentInfo(final ResourceResolver resourceResolver
}

@Override
@SuppressWarnings("null")
public Map<Language, Info> getAdjacentLanguageInfo(final ResourceResolver resourceResolver, final String path) {
return Optional.ofNullable(LanguageUtil.getLanguageRoot(path))
.map(root -> path.substring(root.length()))
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/wcm/testing/mock/aem/MockTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.Queue;
import java.util.function.BinaryOperator;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.util.ISO9075;
import org.apache.sling.api.adapter.SlingAdaptable;
Expand All @@ -58,7 +58,7 @@
* Mock implementation of {@link Tag}.
*/
@SuppressWarnings("null")
class MockTag extends SlingAdaptable implements Tag, Comparable<Tag> {
final class MockTag extends SlingAdaptable implements Tag, Comparable<Tag> {

/** resource being represented as a Tag */
private final Resource resource;
Expand Down Expand Up @@ -349,7 +349,7 @@ public String getTitlePath(Locale locale) {

while (ancestor != null) {
Tag parent = ancestor.getParent();
if (ancestor != this) {
if (!ancestor.equals(this)) {
if (parent == null) {
if (DEFAULT_NAMESPACE.equals(ancestor.getName())) {
break;
Expand Down
26 changes: 13 additions & 13 deletions core/src/main/java/io/wcm/testing/mock/aem/MockTagManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static com.day.cq.tagging.TagConstants.TAG_ROOT_PATH;

import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
Expand All @@ -38,7 +37,7 @@

import javax.jcr.Session;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
Expand Down Expand Up @@ -149,13 +148,13 @@ public boolean canCreateTag(String tagID) throws InvalidTagFormatException {

@Override
public Tag createTag(String tagID, String title, String description)
throws AccessControlException, InvalidTagFormatException {
throws InvalidTagFormatException {
return createTag(tagID, title, description, true);
}

@Override
public Tag createTag(String tagID, String title, String description, boolean autoSave)
throws AccessControlException, InvalidTagFormatException {
throws InvalidTagFormatException {
String tagPath = getPathFromID(tagID);
if (!StringUtils.startsWith(tagPath, TAG_ROOT_PATH)) {
throw new InvalidTagFormatException("Tag path '" + tagPath + "' does not start with: " + TAG_ROOT_PATH);
Expand Down Expand Up @@ -196,17 +195,17 @@ public Tag createTag(String tagID, String title, String description, boolean aut
}

@Override
public Tag createTagByTitle(String titlePath) throws AccessControlException, InvalidTagFormatException {
public Tag createTagByTitle(String titlePath) throws InvalidTagFormatException {
return createTagByTitle(titlePath, true);
}

@Override
public void deleteTag(Tag tag) throws AccessControlException {
public void deleteTag(Tag tag) {
deleteTag(tag, true);
}

@Override
public void deleteTag(Tag tag, boolean autoSave) throws AccessControlException {
public void deleteTag(Tag tag, boolean autoSave) {
Resource tagResource = tag.adaptTo(Resource.class);
if (tagResource == null) {
return;
Expand Down Expand Up @@ -427,7 +426,7 @@ public void setTags(Resource resource, Tag[] tags) {
public void setTags(Resource resource, Tag[] tags, boolean autoSave) {
ModifiableValueMap props = resource.adaptTo(ModifiableValueMap.class);
if (props == null) {
throw new RuntimeException("Unable to get modifiable value map: " + resource.getPath());
throw new IllegalStateException("Unable to get modifiable value map: " + resource.getPath());
}
if (tags == null) {
props.remove(TagConstants.PN_TAGS);
Expand All @@ -444,7 +443,8 @@ public void setTags(Resource resource, Tag[] tags, boolean autoSave) {
if (autoSave) {
try {
resourceResolver.commit();
} catch (PersistenceException e) {
}
catch (PersistenceException e) {
log.error("failed to commit updates for setting tags", e);
}
}
Expand All @@ -470,12 +470,12 @@ public boolean canCreateTagByTitle(String tagTitlePath, Locale locale) throws In
}

@Override
public Tag createTagByTitle(String titlePath, boolean autoSave) throws AccessControlException, InvalidTagFormatException {
public Tag createTagByTitle(String titlePath, boolean autoSave) throws InvalidTagFormatException {
throw new UnsupportedOperationException();
}

@Override
public Tag createTagByTitle(String titlePath, Locale locale) throws AccessControlException, InvalidTagFormatException {
public Tag createTagByTitle(String titlePath, Locale locale) throws InvalidTagFormatException {
throw new UnsupportedOperationException();
}

Expand All @@ -490,12 +490,12 @@ public FindResults findByTitle(String title) {
}

@Override
public void mergeTag(Tag tag, Tag destination) throws AccessControlException, TagException {
public void mergeTag(Tag tag, Tag destination) throws TagException {
throw new UnsupportedOperationException();
}

@Override
public Tag moveTag(Tag tag, String destination) throws AccessControlException, InvalidTagFormatException, TagException {
public Tag moveTag(Tag tag, String destination) throws InvalidTagFormatException, TagException {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ private ContentFragment contentFragmentTextOrStructured(@NotNull String path,
resource(path + "/" + JcrConstants.JCR_CONTENT + "/" + DamConstants.METADATA_FOLDER, metadataProps);

// store text as original rendition
if (text != null) {
if (text != null && mimeType != null) {
try (InputStream is = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8))) {
ContentLoader contentLoader = new ContentLoader(resourceResolver);
contentLoader.binaryFile(is, renditionsPath + "/" + DamConstants.ORIGINAL_FILE, mimeType);
}
catch (IOException ex) {
throw new RuntimeException("Unable to create content fragment at " + path, ex);
throw new IllegalArgumentException("Unable to create content fragment at " + path, ex);
}

// create model/elements/main node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class MockAemBindingsValuesProvider implements BindingsValuesProvider {

static final String PROPERTY_CONTEXT = "context";

private volatile AemContextImpl context;
@SuppressWarnings("java:S1845") // naming
private AemContextImpl context;

@Activate
private void activate(Map<String, Object> config) {
Expand Down
Loading

0 comments on commit 86e12ea

Please sign in to comment.