Search in sources :

Example 6 with ContentFragment

use of com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentImplTest method textOnlyGetEditorJSON.

@Test
void textOnlyGetEditorJSON() {
    ContentFragment fragment = getModelInstanceUnderTest(CF_TEXT_ONLY_MULTIPLE_ELEMENTS);
    String expectedJSON = "{\"title\":\"Test Content Fragment\",\"path\":\"/content/dam/contentfragments/text-only\"" + ",\"elements\":[\"second\",\"non-existing\",\"main\"],\"associatedContent\":[{\"title\":\"Test Collection\"" + ",\"path\":\"/content/dam/collections/X/X7v6pJAcy5qtkUdXdIxR/test\"}]}";
    assertEquals(fragment.getEditorJSON(), expectedJSON);
}
Also used : DAMContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.DAMContentFragment) ContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment) Test(org.junit.jupiter.api.Test)

Example 7 with ContentFragment

use of com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentImplTest method testDataLayerJson.

@Test
void testDataLayerJson() {
    Utils.enableDataLayer(context, true);
    String expected = "{\"contentfragment-bb4058160c\":{\"@type\":\"core/wcm/components/contentfragment/v1/contentfragment\",\"dc:title\":\"Test Content Fragment\",\"elements\":[{\"xdm:text\":\"<p>Main content</p>\",\"xdm:title\":\"Main\"},{\"xdm:text\":\"Second content\",\"xdm:title\":\"Second\"}]}}";
    ContentFragment fragment = getModelInstanceUnderTest(CF_TEXT_ONLY);
    assertEquals(Json.createReader(new StringReader(expected)).read(), Json.createReader(new StringReader(fragment.getData().getJson())).read());
}
Also used : DAMContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.DAMContentFragment) ContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment) StringReader(java.io.StringReader) Test(org.junit.jupiter.api.Test)

Example 8 with ContentFragment

use of com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentImplTest method structuredNonExistingPath.

@Test
void structuredNonExistingPath() {
    ContentFragment fragment = getModelInstanceUnderTest(CF_STRUCTURED_NON_EXISTING_PATH);
    assertNotNull(fragment, "Model shouldn't be null when the path does not exist");
    assertNull(fragment.getTitle());
    assertNull(fragment.getDescription());
    assertNull(fragment.getType());
    assertNull(fragment.getElements());
    assertNull(fragment.getAssociatedContent());
    assertTrue(fragment.getExportedElements().isEmpty());
    assertEquals(0, fragment.getExportedElementsOrder().length);
}
Also used : DAMContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.DAMContentFragment) ContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment) Test(org.junit.jupiter.api.Test)

Example 9 with ContentFragment

use of com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentImplTest method getElementsType.

@Test
void getElementsType() {
    ContentFragment fragment = getModelInstanceUnderTest(CF_TEXT_ONLY);
    final Map<String, ? extends ComponentExporter> elements = fragment.getExportedElements();
    assertNotNull(elements);
    final ComponentExporter mainElement = elements.get("main");
    assertEquals("text/html", mainElement.getExportedType());
}
Also used : DAMContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.DAMContentFragment) ContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment) ComponentExporter(com.adobe.cq.export.json.ComponentExporter) Test(org.junit.jupiter.api.Test)

Example 10 with ContentFragment

use of com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ContentFragmentImplTest method textOnlyInvalidPath.

@Test
void textOnlyInvalidPath() {
    ContentFragment fragment = getModelInstanceUnderTest(CF_TEXT_ONLY_INVALID_PATH);
    assertNotNull(fragment, "Model shouldn't be null when the path is not a content fragment");
}
Also used : DAMContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.DAMContentFragment) ContentFragment(com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment) Test(org.junit.jupiter.api.Test)

Aggregations

ContentFragment (com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragment)26 DAMContentFragment (com.adobe.cq.wcm.core.components.models.contentfragment.DAMContentFragment)26 Test (org.junit.jupiter.api.Test)26 Resource (org.apache.sling.api.resource.Resource)3 ComponentExporter (com.adobe.cq.export.json.ComponentExporter)1 StringReader (java.io.StringReader)1