Skip to content

Commit

Permalink
add unit tests MockDataType and MockFragmentData
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Kicken authored and Koen Kicken committed Nov 29, 2023
1 parent 2d86a49 commit 50d55fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 0 additions & 2 deletions core/src/main/java/io/wcm/testing/mock/aem/MockDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public MockDataType(boolean isArray) {
this.isArray = isArray;
}

@Override
public @Nullable String getSemanticType() {
return StringUtils.EMPTY;
}
Expand All @@ -30,7 +29,6 @@ public boolean isMultiValue() {
throw new UnsupportedOperationException();
}

@Override
public @NotNull String getValueType() {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public void setContentType(@Nullable String contentType) {
this.contentType = contentType;
}

@Override
public @Nullable Calendar getLastModified() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.apache.commons.collections4.IteratorUtils;
import org.junit.Rule;
import org.junit.Test;
import static org.junit.Assert.assertFalse;

import com.adobe.cq.dam.cfm.ContentElement;
import com.adobe.cq.dam.cfm.ContentFragment;
import com.adobe.cq.dam.cfm.ContentVariation;
import com.adobe.cq.dam.cfm.DataType;
import com.adobe.cq.dam.cfm.FragmentData;
import com.adobe.cq.dam.cfm.VariationTemplate;
import org.apache.commons.collections4.IteratorUtils;
import org.junit.Rule;
import org.junit.Test;

import com.day.cq.dam.api.DamConstants;

import io.wcm.testing.mock.aem.context.TestAemContext;
Expand Down Expand Up @@ -66,6 +70,27 @@ public void testContentFragmentStructure() throws Exception {
assertEquals("true", cf.getElement("param3").getContent());
assertEquals("v1\nv2", cf.getElement("param4").getContent());

// get fragmentData and dataType
FragmentData fragmentData = cf.getElement("param1").getValue();
assertNotNull(fragmentData);
assertEquals("value1", fragmentData.getValue());
assertTrue(fragmentData.isTypeSupported(String.class));
assertEquals("value1", fragmentData.getValue(String.class));
assertFalse(fragmentData.isTypeSupported(Boolean.class));
assertNull(fragmentData.getValue(Boolean.class));

DataType dataType = fragmentData.getDataType();
assertNotNull(dataType);

assertFalse(dataType.isMultiValue());
assertTrue(cf.getElement("param4").getValue().getDataType().isMultiValue());

//update fragmentData value and contentType
fragmentData.setValue("newvalue");
fragmentData.setContentType("contentType");
assertEquals("newvalue", fragmentData.getValue());
assertEquals("contentType", fragmentData.getContentType());

// update data
ContentElement param1 = cf.getElement("param1");
param1.setContent("new_value", null);
Expand Down

0 comments on commit 50d55fd

Please sign in to comment.