use of org.apache.sling.testing.resourceresolver.MockValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class DownloadImplTest method testDownloadWithHiddenTitleLink.
@Test
void testDownloadWithHiddenTitleLink() {
Resource mockResource = mock(Resource.class);
MockValueMap mockValueMap = new MockValueMap(mockResource);
mockValueMap.put(Download.PN_HIDE_TITLE_LINK, true);
Style mockStyle = new MockStyle(mockResource, mockValueMap);
Download download = getDownloadUnderTest(DOWNLOAD_1, mockStyle);
assertTrue(download.hideTitleLink(), "Expected title link to be hidden");
}
use of org.apache.sling.testing.resourceresolver.MockValueMap 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 org.apache.sling.testing.resourceresolver.MockValueMap 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());
}
Aggregations