org.apache.sling.api.wrappers.ModifiableValueMapDecorator Java Examples

The following examples show how to use org.apache.sling.api.wrappers.ModifiableValueMapDecorator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphqlProductViewHandlerTest.java    From commerce-cif-connector with Apache License 2.0 6 votes vote down vote up
@Test
public void testCategoryConstraintSearchQuery() throws RepositoryException {
    Mockito.when(servletRequest.getHeader("Referer")).thenReturn("editor.html/test/page.html");
    PageManager pageManager = Mockito.mock(PageManager.class);
    Mockito.when(resourceResolver.adaptTo(PageManager.class)).thenReturn(pageManager);
    Page page = Mockito.mock(Page.class);
    Mockito.when(pageManager.getContainingPage("/test/page")).thenReturn(page);
    Resource contentResource = Mockito.mock(Resource.class);
    Mockito.when(page.getContentResource()).thenReturn(contentResource);
    ModifiableValueMapDecorator valueMap = new ModifiableValueMapDecorator(new HashMap<>());
    Mockito.when(contentResource.getValueMap()).thenReturn(valueMap);
    valueMap.put(PN_CATALOG_PATH, "/catalog/path");
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resourceResolver.getResource("/catalog/path")).thenReturn(resource);
    ModifiableValueMapDecorator properties = new ModifiableValueMapDecorator(new HashMap<>());
    Mockito.when(resource.getValueMap()).thenReturn(properties);
    properties.put("cq:commerceType", "category");
    properties.put("cifId", "1");

    ViewQuery viewQuery = viewHandler.createQuery(servletRequest, null, "query=trail");
    PredicateGroup predicateGroup = ((GraphqlProductViewHandler.GQLViewQuery) viewQuery).predicateGroup;
    Assert.assertNotNull(predicateGroup.getByName("3_" + CATEGORY_ID_PARAMETER));
    Assert.assertEquals(predicateGroup.getByName("3_" + CATEGORY_ID_PARAMETER).get(CATEGORY_ID_PARAMETER), "1");
    Assert.assertNotNull(predicateGroup.getByName("4_" + CATEGORY_PATH_PARAMETER));
    Assert.assertEquals(predicateGroup.getByName("4_" + CATEGORY_PATH_PARAMETER).get(CATEGORY_PATH_PARAMETER), "/catalog/path");
}
 
Example #2
Source File: FieldInitializerTest.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    SlingScriptHelper sling = mock(SlingScriptHelper.class);
    bindings.put(SlingBindings.SLING, sling);
    ExpressionResolver expressionResolver = mock(ExpressionResolver.class);
    when(expressionResolver.resolve(anyString(), any(), any(), (SlingHttpServletRequest) any())).thenAnswer(
        invocationOnMock -> invocationOnMock.getArguments()[0]);
    when(sling.getService(ExpressionResolver.class)).thenReturn(expressionResolver);
    CommerceBasePathsService pathService = mock(CommerceBasePathsService.class);
    when(pathService.getProductsBasePath()).thenReturn(PRODUCTS_BASE_PATH);
    when(sling.getService(CommerceBasePathsService.class)).thenReturn(pathService);
    doAnswer(invocationOnMock -> {
        includedResourceSample = (Resource) invocationOnMock.getArguments()[0];
        return null;
    }).when(sling).include(any(Resource.class));
    request = mock(SlingHttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("some_request_uri");
    bindings.put(SlingBindings.REQUEST, request);
    requestPathInfo = mock(RequestPathInfo.class);
    when(request.getRequestPathInfo()).thenReturn(requestPathInfo);
    valueMap = new ModifiableValueMapDecorator(new HashMap<>());
    bindings.put(WCMBindingsConstants.NAME_PROPERTIES, valueMap);

    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    when(request.getResourceResolver()).thenReturn(resourceResolver);
    PageManager pageManager = mock(PageManager.class);
    when(resourceResolver.adaptTo(PageManager.class)).thenReturn(pageManager);
    Page page = mock(Page.class);
    when(pageManager.getContainingPage(anyString())).thenReturn(page);
    contentResource = mock(Resource.class);
    contentResourceProperties = new ModifiableValueMapDecorator(new HashMap<>());
    when(contentResource.getValueMap()).thenReturn(contentResourceProperties);
    when(page.getContentResource()).thenReturn(contentResource);
}
 
Example #3
Source File: PageTypeRenderConditionServletTest.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    request = new MockSlingHttpServletRequest(context.resourceResolver());
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resource.getPath()).thenReturn("/here");
    Mockito.when(resource.getResourceResolver()).thenReturn(context.resourceResolver());
    Mockito.when(resource.getValueMap()).thenReturn(new ModifiableValueMapDecorator(new HashMap<>()));
    request.setResource(resource);
    servlet = new PageTypeRenderConditionServlet();
}