@Test
  public void testInstallAfterOtherServletMapping() throws Exception {
    Project project = getProject();

    assertFalse(project.hasFacet(RestFacet.class));

    queueInputLines("");
    getShell().execute("setup servlet");
    ServletFacet web = project.getFacet(ServletFacet.class);
    WebAppDescriptor config = web.getConfig();
    config.facesServlet();
    web.saveConfig(config);

    org.jboss.forge.parser.xml.Node webXml = XMLParser.parse(web.getConfig().exportAsString());
    assertEquals(1, webXml.get("servlet-mapping").size());

    assertTrue(config.exportAsString().contains("servlet-mapping"));

    setupRest();

    assertTrue(project.hasFacet(RestFacet.class));
    assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasEffectiveDependency(
                DependencyBuilder.create("org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_1.1_spec")));

    RestFacet restFacet = project.getFacet(RestFacet.class);
    assertEquals("/rest", restFacet.getApplicationPath());

    assertTrue(project.hasFacet(RestWebXmlFacet.class));
    RestWebXmlFacet restWebXmlFacet = project.getFacet(RestWebXmlFacet.class);
    assertEquals("/rest/*", restWebXmlFacet.getServletPath());

    webXml = XMLParser.parse(web.getConfig().exportAsString());
    assertEquals(2, webXml.get("servlet-mapping").size());
  }
Exemple #2
0
  @Override
  public boolean install() {
    if (!isInstalled()) {
      String projectName = project.getFacet(MetadataFacet.class).getProjectName();

      project.getFacet(DependencyFacet.class).addDependency(dep);

      DirectoryResource webRoot = project.getFacet(WebResourceFacet.class).getWebRootDirectory();
      if (!webRoot.exists()) {
        webRoot.mkdirs();
      }

      FileResource<?> descriptor = getConfigFile();
      if (!descriptor.exists()) {
        WebAppDescriptor unit =
            Descriptors.create(WebAppDescriptor.class)
                .displayName(projectName)
                .sessionTimeout(30)
                .welcomeFile("/index.html");

        descriptor.setContents(unit.exportAsString());
      }

      FileResource<?> welcomePage = (FileResource<?>) webRoot.getChild("index.html");
      welcomePage.setContents(
          "<html><head><title>Welcome to Seam Forge</title></head>"
              + "<body>"
              + "<h1> ["
              + projectName
              + "] is Online</h1>"
              + "Powered by <a href=\"http://bit.ly/seamforge\">Seam Forge</a>"
              + "</body>"
              + "</html>");
    }
    return true;
  }
Exemple #3
0
 public void saveConfig(final WebAppDescriptor descriptor) {
   String output = descriptor.exportAsString();
   getConfigFile().setContents(output);
 }