-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement MockContentFragment_ContentElement_Structured getValue() me… #26
base: develop
Are you sure you want to change the base?
Changes from all commits
2d86a49
50d55fd
d628bee
02fa944
bc81a66
7d746f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2023 wcm.io | ||
* %% | ||
* Licensed 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 | ||
* | ||
* 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. | ||
* #L% | ||
*/ | ||
package io.wcm.testing.mock.aem; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.adobe.cq.dam.cfm.DataType; | ||
|
||
class MockContentFragment_MockDataType implements DataType { | ||
|
||
private final boolean isArray; | ||
|
||
MockContentFragment_MockDataType(boolean isArray) { | ||
this.isArray = isArray; | ||
} | ||
|
||
public @Nullable String getSemanticType() { | ||
return StringUtils.EMPTY; | ||
} | ||
|
||
@Override | ||
public boolean isMultiValue() { | ||
return isArray; | ||
} | ||
|
||
// --- unsupported operations --- | ||
|
||
@Override | ||
public @NotNull String getTypeString() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
public @NotNull String getValueType() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2023 wcm.io | ||
* %% | ||
* Licensed 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 | ||
* | ||
* 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. | ||
* #L% | ||
*/ | ||
package io.wcm.testing.mock.aem; | ||
|
||
import java.util.Calendar; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.adobe.cq.dam.cfm.ContentFragmentException; | ||
import com.adobe.cq.dam.cfm.DataType; | ||
import com.adobe.cq.dam.cfm.FragmentData; | ||
|
||
class MockContentFragment_MockFragmentData implements FragmentData { | ||
|
||
private Object value; | ||
private String contentType; | ||
private final MockContentFragment_MockDataType mockDataType; | ||
|
||
MockContentFragment_MockFragmentData(Object value, boolean isArray) { | ||
this.value = value; | ||
this.mockDataType = new MockContentFragment_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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is too simplfied as well? following https://developer.adobe.com/experience-manager/reference-materials/cloud-service/javadoc/com/adobe/cq/dam/cfm/FragmentData.html#isTypeSupported(java.lang.Class) it should return true for any type supported to set as value (supported by the internal converters). it's not related to the value currently set. for sake of simplicity we could just return true here with a comment that this is simplified. |
||
} | ||
|
||
@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; | ||
} | ||
|
||
public @Nullable Calendar getLastModified() { | ||
return null; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is too simplified. according to https://developer.adobe.com/experience-manager/reference-materials/cloud-service/javadoc/com/adobe/cq/dam/cfm/FragmentData.html#getValue(java.lang.Class) this should support any conversion. what about using OSGi converter e.g.
probably also update the unit tests a bit to test one or two actual conversions.