@Test public void testAddLoginConfigWithServlet30() throws Exception { ServletFacet_3_0 servletFacet = addLoginConfig("myRealm", "FORM", ServletFacet_3_0.class); org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXml = servletFacet.getConfig(); assertEquals(1, webXml.getAllLoginConfig().size()); LoginConfigType<org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor> loginConfig = webXml.getAllLoginConfig().get(0); assertEquals("FORM", loginConfig.getAuthMethod()); assertEquals("myRealm", loginConfig.getRealmName()); }
@Deployment public static PortletArchive createDeployment() { TestDeployment deployment = new TestDeployment(FaceletCompositionCustomTagTest.class, true); WebAppDescriptor webConfig = deployment.webXml(); webConfig .createContextParam() .paramName("facelets.LIBRARIES") .paramValue("/WEB-INF/pbr.taglib.xml"); deployment .archive() .createFacesPortlet( "FaceletCompositionCustomTag", "Facelet Composition Portlet", "main.xhtml") .addAsWebResource("pages/facelet/customTag/main.xhtml", "main.xhtml") .addAsWebResource("pages/facelet/customTag/button.xhtml", "button.xhtml") .addAsWebInfResource("pages/facelet/customTag/pbr.taglib.xml", "pbr.taglib.xml"); return deployment.getFinalArchive(); }
@Test public void testLoadOnStartupType() throws Exception { final WebAppDescriptor webApp = create().createServlet().loadOnStartup(1).up(); assertTrue(webApp.getAllServlet().get(0).getLoadOnStartup() == 1); webApp.exportAsString(); assertPresenceUsingXPath(webApp.exportAsString(), "/web-app/servlet/load-on-startup", "1"); webApp.getAllServlet().get(0).loadOnStartup(0); assertPresenceUsingXPath(webApp.exportAsString(), "/web-app/servlet/load-on-startup", "0"); webApp.getAllServlet().get(0).removeLoadOnStartup(); assertTrue(webApp.exportAsString().indexOf("load-on-startup") == -1); }
@Test public void testWebAppVersionType() throws Exception { final WebAppDescriptor webApp = create().version("3.0"); assertEquals(webApp.getVersionAsString(), "3.0"); assertPresenceUsingXPath(webApp.exportAsString(), "/web-app/@version", "3.0"); webApp.version("3.x"); assertEquals(webApp.getVersionAsString(), "3.x"); assertPresenceUsingXPath(webApp.exportAsString(), "/web-app/@version", "3.x"); }
@SuppressWarnings("rawtypes") protected List<Resource<?>> generateIndex(String targetDir, final Resource<?> template) { List<Resource<?>> result = new ArrayList<>(); WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class); ServletFacet servlet = this.project.getFacet(ServletFacet.class); if (servlet instanceof ServletFacet_3_0) { WebAppDescriptor servletConfig = (WebAppDescriptor) servlet.getConfig(); servletConfig.getOrCreateWelcomeFileList().welcomeFile(INDEX_HTML); } else if (servlet instanceof ServletFacet_3_1) { org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor servletConfig = (org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) servlet.getConfig(); servletConfig.getOrCreateWelcomeFileList().welcomeFile(INDEX_HTML); } loadTemplates(); generateTemplates(targetDir); HashMap<Object, Object> context = getTemplateContext(targetDir, template); // Basic pages result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(targetDir + INDEX_HTML), FreemarkerTemplateProcessor.processTemplate(context, indexWelcomeTemplate))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(targetDir + INDEX_XHTML), FreemarkerTemplateProcessor.processTemplate(context, indexTemplate))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(ERROR_XHTML), FreemarkerTemplateProcessor.processTemplate(context, errorTemplate))); // Static resources result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(ADD_PNG), getClass().getResourceAsStream(SCAFFOLD_ADD_PNG))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(BOOTSTRAP_CSS), getClass().getResourceAsStream(SCAFFOLD_BOOTSTRAP_CSS))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(FALSE_PNG), getClass().getResourceAsStream(SCAFFOLD_FALSE_PNG))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(FAVICON_ICO), getClass().getResourceAsStream(SCAFFOLD_FAVICON_ICO))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(FORGE_LOGO_PNG), getClass().getResourceAsStream(SCAFFOLD_FORGE_LOGO_PNG))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(FORGE_STYLE_CSS), getClass().getResourceAsStream(SCAFFOLD_FORGE_STYLE_CSS))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(REMOVE_PNG), getClass().getResourceAsStream(SCAFFOLD_REMOVE_PNG))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(SEARCH_PNG), getClass().getResourceAsStream(SCAFFOLD_SEARCH_PNG))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(TRUE_PNG), getClass().getResourceAsStream(SCAFFOLD_TRUE_PNG))); result.add( ScaffoldUtil.createOrOverwrite( web.getWebResource(JBOSS_COMMUNITY_PNG), getClass().getResourceAsStream(SCAFFOLD_JBOSS_COMMUNITY_PNG))); return result; }
@SuppressWarnings("rawtypes") @Override public boolean isSetup(ScaffoldSetupContext setupContext) { Project project = setupContext.getProject(); setProject(project); String targetDir = setupContext.getTargetDirectory(); targetDir = targetDir == null ? "" : targetDir; if (project.hasAllFacets( Arrays.asList( WebResourcesFacet.class, DependencyFacet.class, JPAFacet.class, EJBFacet.class, CDIFacet.class, ServletFacet.class, FacesFacet.class))) { WebResourcesFacet web = project.getFacet(WebResourcesFacet.class); boolean areResourcesInstalled = web.getWebResource(targetDir + INDEX_HTML).exists() && web.getWebResource(targetDir + INDEX_XHTML).exists() && web.getWebResource(ERROR_XHTML).exists() && web.getWebResource(ADD_PNG).exists() && web.getWebResource(BOOTSTRAP_CSS).exists() && web.getWebResource(FALSE_PNG).exists() && web.getWebResource(FAVICON_ICO).exists() && web.getWebResource(FORGE_LOGO_PNG).exists() && web.getWebResource(FORGE_STYLE_CSS).exists() && web.getWebResource(REMOVE_PNG).exists() && web.getWebResource(SEARCH_PNG).exists() && web.getWebResource(TRUE_PNG).exists() && web.getWebResource(JBOSS_COMMUNITY_PNG).exists() && web.getWebResource(PAGINATOR).exists() && getTemplateStrategy().getDefaultTemplate().exists(); ServletFacet servlet = project.getFacet(ServletFacet.class); boolean isWelcomeFileListed = false; if (servlet instanceof ServletFacet_3_0) { WebAppDescriptor servletConfig = (WebAppDescriptor) servlet.getConfig(); for (WelcomeFileListType<WebAppDescriptor> welcomeFileList : servletConfig.getAllWelcomeFileList()) { for (String welcomeFile : welcomeFileList.getAllWelcomeFile()) { if (welcomeFile.equals(INDEX_HTML)) { isWelcomeFileListed = true; break; } } } } else if (servlet instanceof ServletFacet_3_1) { org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor servletConfig = (org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) servlet.getConfig(); for (org.jboss.shrinkwrap.descriptor.api.webcommon31.WelcomeFileListType< org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor> welcomeFileList : servletConfig.getAllWelcomeFileList()) { for (String welcomeFile : welcomeFileList.getAllWelcomeFile()) { if (welcomeFile.equals(INDEX_HTML)) { isWelcomeFileListed = true; break; } } } } return areResourcesInstalled && isWelcomeFileListed; } return false; }