Search in sources :

Example 1 with RenderCondition

use of com.adobe.granite.ui.components.rendercondition.RenderCondition in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ImageDelegateRenderConditionTest method testDoGet.

@Test
public void testDoGet() throws Exception {
    ImageDelegateRenderCondition imageDelegateRenderCondition = new ImageDelegateRenderCondition();
    context.requestPathInfo().setSuffix(SUFFIX);
    imageDelegateRenderCondition.doGet(context.request(), context.response());
    RenderCondition renderCondition = (RenderCondition) context.request().getAttribute(RenderCondition.class.getName());
    assertNotNull(renderCondition);
    assertTrue(renderCondition.check());
    ExpressionCustomizer expressionCustomizer = (ExpressionCustomizer) context.request().getAttribute(ExpressionCustomizer.class.getName());
    assertNotNull(expressionCustomizer);
    assertTrue(expressionCustomizer.hasVariable(AbstractImageDelegatingModel.IMAGE_DELEGATE));
}
Also used : RenderCondition(com.adobe.granite.ui.components.rendercondition.RenderCondition) ExpressionCustomizer(com.adobe.granite.ui.components.ExpressionCustomizer) Test(org.junit.jupiter.api.Test)

Example 2 with RenderCondition

use of com.adobe.granite.ui.components.rendercondition.RenderCondition in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ElementNamesRenderConditionTest method testSingleTextDisplayMode.

@Test
void testSingleTextDisplayMode() throws ServletException, IOException {
    RenderCondition renderCondition = getRenderCondition(RC_SINGLE_TEXT);
    assertTrue(renderCondition.check(), "Invalid value of render condition");
}
Also used : RenderCondition(com.adobe.granite.ui.components.rendercondition.RenderCondition) Test(org.junit.jupiter.api.Test)

Example 3 with RenderCondition

use of com.adobe.granite.ui.components.rendercondition.RenderCondition in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ElementNamesRenderConditionTest method getRenderCondition.

/**
 * Calls the servlet with the specified render conditino resource and returns the resulting render condition.
 */
private RenderCondition getRenderCondition(String name) throws ServletException, IOException {
    // get render condition resource
    ResourceResolver resolver = context.resourceResolver();
    Resource renderCondition = resolver.getResource(RENDERCONDITIONS_PATH + "/" + name);
    // mock the request
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resolver, context.bundleContext());
    request.setResource(renderCondition);
    // call the servlet
    servlet.doGet(request, new MockSlingHttpServletResponse());
    // return the resulting render condition
    return (RenderCondition) request.getAttribute(RenderCondition.class.getName());
}
Also used : RenderCondition(com.adobe.granite.ui.components.rendercondition.RenderCondition) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.servlethelpers.MockSlingHttpServletResponse)

Example 4 with RenderCondition

use of com.adobe.granite.ui.components.rendercondition.RenderCondition in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ElementNamesRenderConditionTest method testMultipleElementsDisplayMode.

@Test
void testMultipleElementsDisplayMode() throws ServletException, IOException {
    RenderCondition renderCondition = getRenderCondition(RC_MULTI);
    assertFalse(renderCondition.check(), "Invalid value of render condition");
}
Also used : RenderCondition(com.adobe.granite.ui.components.rendercondition.RenderCondition) Test(org.junit.jupiter.api.Test)

Aggregations

RenderCondition (com.adobe.granite.ui.components.rendercondition.RenderCondition)4 Test (org.junit.jupiter.api.Test)3 ExpressionCustomizer (com.adobe.granite.ui.components.ExpressionCustomizer)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 MockSlingHttpServletResponse (org.apache.sling.servlethelpers.MockSlingHttpServletResponse)1 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)1