Search in sources :

Example 1 with Container

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

the class ContainerImplTest method testFormWithoutCustomAttributesAndField.

@Test
public void testFormWithoutCustomAttributesAndField() {
    Resource resource = context.currentResource(FORM2_PATH);
    slingBindings.put(RESOURCE_PROPERTY, resource);
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    Container container = context.request().adaptTo(Container.class);
    assertEquals("multipart/form-data", container.getEnctype());
    assertEquals("POST", container.getMethod());
    assertEquals(CONTAINING_PAGE + ".html", container.getAction());
    assertEquals("core/wcm/components/form/container/v1/container/new", container.getResourceTypeForDropArea());
    assertNull(container.getRedirect());
}
Also used : Container(com.adobe.cq.wcm.core.components.models.form.Container) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 2 with Container

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

the class ContainerImplTest method testFormWithCustomAttributesAndFields.

@Test
public void testFormWithCustomAttributesAndFields() {
    Resource resource = context.currentResource(FORM1_PATH);
    when(formStructureHelperFactory.getFormStructureHelper(resource)).thenReturn(formStructureHelper);
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(RESOURCE_PROPERTY, resource);
    MockSlingHttpServletRequest request = context.request();
    request.setRequestDispatcherFactory(requestDispatcherFactory);
    when(requestDispatcherFactory.getRequestDispatcher((Resource) any(), (RequestDispatcherOptions) any())).thenReturn(requestDispatcher);
    Container container = request.adaptTo(Container.class);
    assertEquals("my-id", container.getId());
    assertEquals("my-id", container.getName());
    assertEquals("application/x-www-form-urlencoded", container.getEnctype());
    assertEquals("GET", container.getMethod());
    assertEquals(CONTAINING_PAGE + ".html", container.getAction());
    assertEquals("core/wcm/components/form/container/v1/container/new", container.getResourceTypeForDropArea());
    assertEquals("/content/we-retail/home", container.getRedirect());
}
Also used : Container(com.adobe.cq.wcm.core.components.models.form.Container) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 3 with Container

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

the class ContainerImplTest method testFormRedirectWithContextPath.

@Test
public void testFormRedirectWithContextPath() {
    Resource resource = context.currentResource(FORM1_PATH);
    slingBindings.put(RESOURCE_PROPERTY, resource);
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    context.request().setContextPath("/contextPath/test");
    when(formStructureHelperFactory.getFormStructureHelper(resource)).thenReturn(formStructureHelper);
    Container container = context.request().adaptTo(Container.class);
    assertEquals("/contextPath/test/content/we-retail/home", container.getRedirect());
}
Also used : Container(com.adobe.cq.wcm.core.components.models.form.Container) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

Container (com.adobe.cq.wcm.core.components.models.form.Container)3 Resource (org.apache.sling.api.resource.Resource)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 Test (org.junit.Test)3 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)1