AllowedEmbeddablesDataSourceServlet extends SlingSafeMethodsServlet { @Override protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) { SimpleDataSource allowedEmbeddablesDataSource = new SimpleDataSource(getAllowedEmbeddables(request).iterator()); request.setAttribute(DataSource.class.getName(), allowedEmbeddablesDataSource); }   static final String RESOURCE_TYPE_V1; }
@Test public void testAllowedEmbeddablesDataSourceServlet() { context.contentPolicyMapping("my-app/components/embed", Objects.requireNonNull(context.resourceResolver().getResource("/apps/conf/policy_1558011912823")) .getValueMap()); context.request().setAttribute(Value.CONTENTPATH_ATTRIBUTE, CURRENT_PATH); dataSourceServlet.doGet(context.request(), context.response()); DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName()); assertNotNull(dataSource); validateAllowedEmbeddables(dataSource, getExpectedAllowedEmbeddables(new String[][]{ {"Select", ""}, {"Chatbot", "/apps/my-app/chatbot"}, {"Social", "/apps/my-app/social"} })); }
@Test public void testAllowedEmbeddablesDesignDataSourceServlet() { Designer designer = mock(Designer.class); context.registerAdapter(ResourceResolver.class, Designer.class, (Function<ResourceResolver, Designer>) input -> designer); Resource styleResource = context.resourceResolver().getResource("/apps/etc/designs/embed"); MockStyle mockStyle = new MockStyle(styleResource, styleResource.getValueMap()); when(designer.getStyle(any(Resource.class))).thenReturn(mockStyle); context.request().setAttribute(Value.CONTENTPATH_ATTRIBUTE, CURRENT_PATH); dataSourceServlet.doGet(context.request(), context.response()); DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName()); assertNotNull(dataSource); validateAllowedEmbeddables(dataSource, getExpectedAllowedEmbeddables(new String[][]{ {"Select", ""}, {"Chatbot", "/apps/my-app/chatbot"}, {"Social", "/apps/my-app/social"} })); }