ContentFragmentUtils { public static String getGridResourceType(Resource fragmentResource) { String gridResourceType = DEFAULT_GRID_TYPE; if (fragmentResource == null) { return gridResourceType; } ResourceResolver resourceResolver = fragmentResource.getResourceResolver(); ContentPolicyManager contentPolicyManager = resourceResolver.adaptTo(ContentPolicyManager.class); ContentPolicy fragmentContentPolicy = contentPolicyManager != null ? contentPolicyManager.getPolicy(fragmentResource) : null; if (fragmentContentPolicy != null) { ValueMap contentPolicyProperties = fragmentContentPolicy.getProperties(); gridResourceType = contentPolicyProperties.get(PN_CFM_GRID_TYPE, DEFAULT_GRID_TYPE); } return gridResourceType; } private  ContentFragmentUtils(); static String getType(ContentFragment contentFragment); static Iterator<ContentElement> filterElements(final ContentFragment contentFragment,
                                                          final String[] elementNames); static String getEditorJSON(final ContentFragment contentFragment,
                                       final String variationName,
                                       final String[] elementNames); static String getGridResourceType(Resource fragmentResource); static String[] getItemsOrder(Map<String, ?> itemsMap); static Map<String, ComponentExporter> getComponentExporters(Iterator<Resource> resourceIterator,
                                                                       ModelFactory modelFactory,
                                                                       SlingHttpServletRequest slingHttpServletRequest);  }
@Test public void getDefaultGridResourceType() { ResourceResolver resourceResolver = Mockito.mock(ResourceResolver.class); Resource resource = Mockito.mock(Resource.class); Mockito.when(resource.getResourceResolver()).thenReturn(resourceResolver); String defaultGridResourceType = ContentFragmentUtils.getGridResourceType(resource); Assertions.assertEquals(defaultGridResourceType, ContentFragmentUtils.DEFAULT_GRID_TYPE); }
@Test public void getGridTypeSetInFragmentPolicy() { ContentPolicyManager contentPolicyManager = Mockito.mock(ContentPolicyManager.class); ContentPolicy contentPolicy = Mockito.mock(ContentPolicy.class); ResourceResolver resourceResolver = Mockito.mock(ResourceResolver.class); Resource resource = Mockito.mock(Resource.class); ValueMap valueMap = new MockValueMap(resource); valueMap.put(PN_CFM_GRID_TYPE, "foobar"); Mockito.when(resource.getResourceResolver()).thenReturn(resourceResolver); Mockito.when(resourceResolver.adaptTo(Mockito.eq(ContentPolicyManager.class))).thenReturn(contentPolicyManager); Mockito.when(contentPolicyManager.getPolicy(Mockito.eq(resource))).thenReturn(contentPolicy); Mockito.when(contentPolicy.getProperties()).thenReturn(valueMap); String defaultGridResourceType = ContentFragmentUtils.getGridResourceType(resource); Assertions.assertEquals(defaultGridResourceType, "foobar"); }