-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement MockContentFragment_ContentElement_Structured getValue() me…
…thod
- Loading branch information
Koen Kicken
authored and
Koen Kicken
committed
Nov 20, 2023
1 parent
e18f0c7
commit 2d86a49
Showing
3 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/src/main/java/io/wcm/testing/mock/aem/MockDataType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.wcm.testing.mock.aem; | ||
|
||
import com.adobe.cq.dam.cfm.DataType; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MockDataType implements DataType { | ||
|
||
boolean isArray; | ||
|
||
public MockDataType(boolean isArray) { | ||
this.isArray = isArray; | ||
} | ||
|
||
@Override | ||
public @Nullable String getSemanticType() { | ||
return StringUtils.EMPTY; | ||
} | ||
|
||
@Override | ||
public boolean isMultiValue() { | ||
return isArray; | ||
} | ||
|
||
// --- unsupported operations --- | ||
|
||
@Override | ||
public @NotNull String getTypeString() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public @NotNull String getValueType() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
core/src/main/java/io/wcm/testing/mock/aem/MockFragmentData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.wcm.testing.mock.aem; | ||
|
||
import com.adobe.cq.dam.cfm.ContentFragmentException; | ||
import com.adobe.cq.dam.cfm.DataType; | ||
import com.adobe.cq.dam.cfm.FragmentData; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Calendar; | ||
|
||
public class MockFragmentData implements FragmentData { | ||
|
||
private Object value; | ||
private String contentType; | ||
private final MockDataType mockDataType; | ||
|
||
public MockFragmentData(Object value, boolean isArray) { | ||
this.value = value; | ||
this.mockDataType = new MockDataType(isArray); | ||
} | ||
|
||
@Override | ||
public @NotNull DataType getDataType() { | ||
return mockDataType; | ||
} | ||
|
||
@Override | ||
public <T> @Nullable T getValue(Class<T> type) { | ||
if (type.isInstance(value)) { | ||
return (T) value; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isTypeSupported(Class type) { | ||
return type.isInstance(value); | ||
} | ||
|
||
@Override | ||
public @Nullable Object getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void setValue(@Nullable Object value) throws ContentFragmentException { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public @Nullable String getContentType() { | ||
return contentType; | ||
} | ||
|
||
@Override | ||
public void setContentType(@Nullable String contentType) { | ||
this.contentType = contentType; | ||
} | ||
|
||
@Override | ||
public @Nullable Calendar getLastModified() { | ||
return null; | ||
} | ||
} |