Пример #1
0
  @Override
  public boolean install() {
    FileResource<?> child =
        (FileResource<?>) project.getProjectRoot().getChild("mockFacet2.installed");

    return child.createNewFile();
  }
Пример #2
0
  /**
   * Initialize a new git repository.
   *
   * @param dir The directory in which to create a new .git/ folder and repository.
   */
  public static Git init(final DirectoryResource dir) throws IOException {
    FileResource<?> gitDir = dir.getChildDirectory(".git").reify(FileResource.class);
    gitDir.mkdirs();

    RepositoryBuilder db =
        new RepositoryBuilder().setGitDir(gitDir.getUnderlyingResourceObject()).setup();
    Git git = new Git(db.build());
    git.getRepository().create();
    return git;
  }
Пример #3
0
  @Override
  public FileResource<?> getConfigFile() {
    DirectoryResource webRoot = project.getFacet(WebResourceFacet.class).getWebRootDirectory();
    FileResource<?> child =
        (FileResource<?>) webRoot.getChild("WEB-INF" + File.separator + "faces-config.xml");

    if (!child.exists()) {
      return new UnknownFileResource(
          child.getResourceFactory(), child.getUnderlyingResourceObject()) {
        @Override
        public InputStream getResourceInputStream() {
          if (!exists()) {
            String projectName = project.getFacet(MetadataFacet.class).getProjectName();
            WebAppDescriptor unit =
                Descriptors.create(WebAppDescriptor.class)
                    .displayName(projectName)
                    .sessionTimeout(30);
            return Streams.fromString(unit.exportAsString());
          } else {
            return super.getResourceInputStream();
          }
        }

        @Override
        public UnknownFileResource setContents(InputStream data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }

        @Override
        public UnknownFileResource setContents(char[] data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }

        @Override
        public UnknownFileResource setContents(String data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }
      };
    }

    return (FileResource<?>) child;
  }
Пример #4
0
 @Test
 public void testFacesConfig() throws Exception {
   Project project = initializeJavaProject();
   queueInputLines("Y", "Y", "Y");
   getShell().execute("faces setup");
   getShell().execute("i18n setup");
   FileResource<?> configFile = project.getFacet(FacesFacet.class).getConfigFile();
   assertTrue(configFile.exists());
   Node facesConfig = XMLParser.parse(configFile.getResourceInputStream());
   assertEquals(
       "messages",
       facesConfig.getTextValueForPatternName("application/resource-bundle/base-name"));
   assertEquals("msg", facesConfig.getTextValueForPatternName("application/resource-bundle/var"));
 }
Пример #5
0
  @Test
  public void configureContainer() throws Exception {
    Project project = initializeJavaProject();

    MavenCoreFacet coreFacet = project.getFacet(MavenCoreFacet.class);

    List<Profile> profiles = coreFacet.getPOM().getProfiles();
    for (Profile profile : profiles) {
      System.out.println(profile.getId());
    }
    assertThat(profiles.size(), is(0));

    queueInputLines("JBOSS_AS_MANAGED_6.X", "", "19", "10", "", "", "", "8", "");
    getShell().execute("arquillian setup");

    queueInputLines("JBOSS_AS_MANAGED_6.X", "2", "8000");
    getShell().execute("arquillian configure-container");

    ResourceFacet facet = project.getFacet(ResourceFacet.class);
    FileResource<?> arquillianXML = facet.getTestResource("arquillian.xml");

    assertThat(arquillianXML, is(notNullValue()));
    assertThat(arquillianXML.exists(), is(true));
  }
Пример #6
0
  @Override
  public FileResource<?> promptFile(final String message, final FileResource<?> defaultIfEmpty) {
    FileResource<?> result = defaultIfEmpty;

    String query = " [ .../" + defaultIfEmpty.getName() + "] ";
    String path = promptWithCompleter(message + query, new FileNameCompleter());
    if ((path != null) && !path.trim().isEmpty()) {
      path = Files.canonicalize(path);
      Resource<File> resource = getResourceFactory().getResourceFrom(new File(path));

      if (resource instanceof FileResource) {
        result = (FileResource<?>) resource;
      } else {
        result = null;
      }
    }
    return result;
  }
  @Test
  public void testGenerate() throws Exception {
    Project current = getShell().getCurrentProject();
    final String targetDir = "petClinic";
    Project project = setupScaffoldProject(targetDir);

    queueInputLines("");
    getShell().execute("entity --named Owner");
    getShell().execute("field string --named firstName");
    getShell().execute("field string --named lastName");
    getShell().execute("field string --named address");
    getShell().execute("field string --named city");
    getShell().execute("field string --named telephone");
    getShell().execute("field string --named homePage");
    getShell().execute("field string --named email");
    getShell().execute("field temporal --type DATE --named birthday");
    getShell().execute("entity --named Vet");
    getShell().execute("field string --named firstName");
    getShell().execute("field string --named lastName");
    getShell().execute("field string --named address");
    getShell().execute("field string --named city");
    getShell().execute("field string --named telephone");
    getShell().execute("field string --named homePage");
    getShell().execute("field string --named email");
    getShell().execute("field temporal --type DATE --named birthday");
    getShell().execute("field temporal --type DATE --named employedSince");
    getShell().execute("field int --named specialty");
    getShell().execute("entity --named Pet");
    getShell().execute("field string --named name");
    getShell().execute("field int --named type");
    getShell().execute("field boolean --named sendReminders");
    getShell().execute("field manyToOne --named owner --fieldType com.test.model.Owner");
    getShell().execute("entity --named Visit");
    getShell().execute("field string --named description");
    getShell().execute("field temporal --type DATE --named visitDate");
    getShell().execute("field manyToOne --named pet --fieldType com.test.model.Pet");
    getShell().execute("field manyToOne --named vet --fieldType com.test.model.Vet");

    getShell().execute("cd ~~");
    queueInputLines("", "", "", "", "");
    getShell().execute("scaffold-x from src/main/java/com/test/model/*");

    WebResourceFacet web = project.getFacet(WebResourceFacet.class);

    // Check search screen has h:message

    FileResource<?> search = web.getWebResource(targetDir + "/pet/search.xhtml");
    Assert.assertTrue(search.exists());
    String contents = Streams.toString(search.getResourceInputStream());

    String metawidget =
        "\t\t\t\t\t\t<h:outputLabel for=\"petBeanExampleType\" value=\"Type:\"/>\r\n"
            + "\t\t\t\t\t\t<h:panelGroup>\r\n"
            + "\t\t\t\t\t\t\t<h:inputText id=\"petBeanExampleType\" value=\"#{petBean.example.type}\"/>\r\n"
            + "\t\t\t\t\t\t\t<h:message for=\"petBeanExampleType\" styleClass=\"error\"/>\r\n"
            + "\t\t\t\t\t\t</h:panelGroup>";

    Assert.assertTrue(contents.contains(metawidget));

    // Check search screen has boolean graphic

    metawidget = "\t\t\t\t\t<h:link outcome=\"/" + targetDir + "/pet/view\">\r\n";
    metawidget += "\t\t\t\t\t\t<f:param name=\"id\" value=\"#{_item.id}\"/>\r\n";
    metawidget +=
        "\t\t\t\t\t\t<h:outputText styleClass=\"#{_item.sendReminders ? 'boolean-true' : 'boolean-false'}\" value=\"\"/>\r\n";
    metawidget += "\t\t\t\t\t</h:link>\r\n";

    Assert.assertTrue(contents.contains(metawidget));

    metawidget = "\t\t\t\t\t<h:link outcome=\"/" + targetDir + "/pet/view\">\r\n";
    metawidget += "\t\t\t\t\t\t<f:param name=\"id\" value=\"#{_item.id}\"/>\r\n";
    metawidget += "\t\t\t\t\t\t<h:outputText id=\"itemOwner\" value=\"#{_item.owner}\"/>\r\n";
    metawidget += "\t\t\t\t\t</h:link>\r\n";

    Assert.assertTrue(contents.contains(metawidget));

    // Check create screen has h:selectBooleanCheckbox

    FileResource<?> create = web.getWebResource(targetDir + "/pet/create.xhtml");
    Assert.assertTrue(create.exists());
    contents = Streams.toString(create.getResourceInputStream());

    metawidget =
        "\t\t\t\t<h:outputLabel for=\"petBeanPetSendReminders\" value=\"Send Reminders:\"/>\r\n";
    metawidget += "\t\t\t\t<h:panelGroup>\r\n";
    metawidget +=
        "\t\t\t\t\t<h:selectBooleanCheckbox id=\"petBeanPetSendReminders\" value=\"#{petBean.pet.sendReminders}\"/>\r\n";
    metawidget += "\t\t\t\t\t<h:message for=\"petBeanPetSendReminders\" styleClass=\"error\"/>\r\n";
    metawidget += "\t\t\t\t</h:panelGroup>";

    Assert.assertTrue(contents.contains(metawidget));

    // Check view screen has boolean graphic

    FileResource<?> view = web.getWebResource(targetDir + "/pet/view.xhtml");
    Assert.assertTrue(view.exists());
    contents = Streams.toString(view.getResourceInputStream());

    metawidget = "\t\t\t<h:outputLabel value=\"Send Reminders:\"/>\r\n";
    metawidget +=
        "\t\t\t<h:outputText styleClass=\"#{petBean.pet.sendReminders ? 'boolean-true' : 'boolean-false'}\" value=\"\"/>";

    Assert.assertTrue(contents.contains(metawidget));

    // Deploy to a real container and test

    this.webTest.setup(project);
    JavaClass clazz = this.webTest.from(current, FacesScaffoldPetClinicClient.class);

    this.webTest.buildDefaultDeploymentMethod(
        project,
        clazz,
        Arrays.asList(
            ".addAsResource(\"META-INF/persistence.xml\", \"META-INF/persistence.xml\")"));
    this.webTest.addAsTestClass(project, clazz);
    try {
      getShell().execute("build");
    } catch (Exception e) {
      System.err.println(getOutput());
      throw e;
    }
  }
Пример #8
0
 @Override
 public FileResource<?> createTestResource(final char[] bytes, final String relativeFilename) {
   FileResource<?> file = (FileResource<?>) getTestResourceFolder().getChild(relativeFilename);
   file.setContents(bytes);
   return file;
 }