Search in sources :

Example 11 with MockValueMap

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");
}
Also used : MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) MockStyle(com.adobe.cq.wcm.core.components.testing.MockStyle) Style(com.day.cq.wcm.api.designer.Style) Download(com.adobe.cq.wcm.core.components.models.Download) Test(org.junit.jupiter.api.Test)

Example 12 with MockValueMap

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");
}
Also used : ContentFragment(com.adobe.cq.dam.cfm.ContentFragment) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) FragmentTemplate(com.adobe.cq.dam.cfm.FragmentTemplate) ValueMap(org.apache.sling.api.resource.ValueMap) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.jupiter.api.Test)

Example 13 with MockValueMap

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());
}
Also used : ContentFragment(com.adobe.cq.dam.cfm.ContentFragment) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) ValueMap(org.apache.sling.api.resource.ValueMap) MockValueMap(org.apache.sling.testing.resourceresolver.MockValueMap) Resource(org.apache.sling.api.resource.Resource) StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) Test(org.junit.jupiter.api.Test)

Aggregations

MockValueMap (org.apache.sling.testing.resourceresolver.MockValueMap)13 Test (org.junit.jupiter.api.Test)11 Resource (org.apache.sling.api.resource.Resource)7 AbstractImageTest (com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)6 Asset (com.day.cq.dam.api.Asset)6 Rendition (com.day.cq.dam.api.Rendition)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 HashMap (java.util.HashMap)6 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)6 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)6 ValueMap (org.apache.sling.api.resource.ValueMap)5 BufferedImage (java.awt.image.BufferedImage)4 ContentFragment (com.adobe.cq.dam.cfm.ContentFragment)2 Download (com.adobe.cq.wcm.core.components.models.Download)2 MockStyle (com.adobe.cq.wcm.core.components.testing.MockStyle)2 Style (com.day.cq.wcm.api.designer.Style)2 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 ModifiableValueMapDecorator (org.apache.sling.api.wrappers.ModifiableValueMapDecorator)2 FragmentTemplate (com.adobe.cq.dam.cfm.FragmentTemplate)1 ContentPolicy (com.day.cq.wcm.api.policies.ContentPolicy)1