use of com.adobe.cq.dam.cfm.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContentFragmentUtilsTest method getTypeWhenTemplateResourceIsNotNull.
@Test
public void getTypeWhenTemplateResourceIsNotNull() {
// GIVEN
Resource fragmentResource = Mockito.mock(Resource.class);
Resource templateResource = Mockito.mock(Resource.class);
FragmentTemplate fragmentTemplate = Mockito.mock(FragmentTemplate.class);
ContentFragment contentFragment = Mockito.mock(ContentFragment.class);
Mockito.when(contentFragment.getTemplate()).thenReturn(fragmentTemplate);
Mockito.when(contentFragment.adaptTo(Mockito.eq(Resource.class))).thenReturn(fragmentResource);
Mockito.when(fragmentTemplate.adaptTo(Mockito.eq(Resource.class))).thenReturn(templateResource);
Mockito.when(templateResource.getPath()).thenReturn("/foo/bar/qux");
// WHEN
String type = ContentFragmentUtils.getType(contentFragment);
// THEN
Assertions.assertEquals(type, "/foo/bar/qux");
}
use of com.adobe.cq.dam.cfm.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContentFragmentUtilsTest method getTypeOfStructuredContentFragment.
@Test
public void getTypeOfStructuredContentFragment() {
// GIVEN
Resource fragmentResource = Mockito.mock(Resource.class);
Resource fragmentDataResource = Mockito.mock(Resource.class);
Resource templateResource = Mockito.mock(Resource.class);
FragmentTemplate fragmentTemplate = Mockito.mock(FragmentTemplate.class);
ContentFragment contentFragment = Mockito.mock(ContentFragment.class);
ValueMap valueMap = new MockValueMap(fragmentDataResource);
valueMap.put("cq:model", "foo.bar.QuxModel");
Mockito.when(contentFragment.getTemplate()).thenReturn(fragmentTemplate);
Mockito.when(contentFragment.adaptTo(Mockito.eq(Resource.class))).thenReturn(fragmentResource);
Mockito.when(fragmentResource.getChild(Mockito.eq(JCR_CONTENT + "/data"))).thenReturn(fragmentDataResource);
Mockito.when(fragmentDataResource.getValueMap()).thenReturn(valueMap);
Mockito.when(fragmentTemplate.adaptTo(Mockito.eq(Resource.class))).thenReturn(templateResource);
Mockito.when(templateResource.getPath()).thenReturn("/foo/bar/qux/quux/corge/grault/garply");
Mockito.when(templateResource.getName()).thenReturn("waldo");
// WHEN
String type = ContentFragmentUtils.getType(contentFragment);
// THEN
Assertions.assertEquals(type, "bar/models/waldo");
}
use of com.adobe.cq.dam.cfm.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContentFragmentUtilsTest method getEditorJsonOutputOfContentFragment.
@Test
public void getEditorJsonOutputOfContentFragment() {
// GIVEN
Resource contentFragmentResource = Mockito.mock(Resource.class);
ContentFragment contentFragment = Mockito.mock(ContentFragment.class);
Iterator<Resource> associatedContentResourceIterator = Mockito.mock(Iterator.class);
Resource firstAndOnlyAssociatedContent = Mockito.mock(Resource.class);
ValueMap associatedContentValueMap = new MockValueMap(firstAndOnlyAssociatedContent);
associatedContentValueMap.put(JCR_TITLE, "associatedContentTitle");
Mockito.when(contentFragment.getTitle()).thenReturn("titleOfTheContentFragment");
Mockito.when(contentFragment.getAssociatedContent()).thenReturn(associatedContentResourceIterator);
Mockito.when(contentFragment.adaptTo(Mockito.eq(Resource.class))).thenReturn(contentFragmentResource);
Mockito.when(contentFragmentResource.getPath()).thenReturn("/path/to/the/content/fragment");
Mockito.when(associatedContentResourceIterator.hasNext()).thenReturn(true, true, false);
Mockito.when(associatedContentResourceIterator.next()).thenReturn(firstAndOnlyAssociatedContent);
Mockito.when(firstAndOnlyAssociatedContent.getPath()).thenReturn("/path/to/the/associated/content");
Mockito.when(firstAndOnlyAssociatedContent.adaptTo(ValueMap.class)).thenReturn(associatedContentValueMap);
// WHEN
String json = ContentFragmentUtils.getEditorJSON(contentFragment, "slave", new String[] { "foo", "bar" });
// THEN
JsonReader expected = Json.createReader(this.getClass().getResourceAsStream("expectedJson.json"));
JsonReader actual = Json.createReader(new StringReader(json));
assertEquals(expected.read(), actual.read());
}
use of com.adobe.cq.dam.cfm.ContentFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContentFragmentUtilsTest method getTypeWhenResourceIsNull.
@Test
public void getTypeWhenResourceIsNull() {
// GIVEN
FragmentTemplate fragmentTemplate = Mockito.mock(FragmentTemplate.class);
ContentFragment contentFragment = Mockito.mock(ContentFragment.class);
Mockito.when(contentFragment.getTemplate()).thenReturn(fragmentTemplate);
Mockito.when(contentFragment.getName()).thenReturn("foobar");
// WHEN
String type = ContentFragmentUtils.getType(contentFragment);
// THEN
Assertions.assertEquals(type, "foobar");
}
Aggregations