Пример #1
0
  @Before
  public void setup() throws Exception {
    AddonRegistry addonRegistry =
        SimpleContainer.getFurnace(getClass().getClassLoader()).getAddonRegistry();
    this.projectFactory = addonRegistry.getServices(ProjectFactory.class).get();
    this.testHarness = addonRegistry.getServices(UITestHarness.class).get();
    project = projectFactory.createTempProject();
    CommandController gitSetupCommandTester =
        testHarness.createCommandController(GitSetupCommand.class, project.getRoot());
    gitSetupCommandTester.initialize();
    gitSetupCommandTester.execute();

    CommandController gitIgnoreSetupTester =
        testHarness.createCommandController(GitIgnoreSetupCommand.class, project.getRoot());
    gitIgnoreSetupTester.initialize();
    gitIgnoreSetupTester.setValueFor("templateRepoDir", getCloneDir());
    gitIgnoreSetupTester.execute();

    Resource<?> cloneDir = getCloneDir();
    boolean templateFound = false;
    for (Resource<?> resource : cloneDir.listResources()) {
      if (resource.getName().endsWith(".gitignore")) {
        templateFound = true;
        break;
      }
    }
    assertTrue(templateFound);
  }
  @Test
  public void testCreateNewObserverMethodWithQualifiers() throws Exception {
    try (CommandController controller =
        uiTestHarness.createCommandController(CDINewBeanCommand.class, project.getRoot())) {
      controller.initialize();
      controller.setValueFor("named", "MyBean");
      controller.setValueFor("targetPackage", "org.jboss.forge.test.bean");
      assertTrue(controller.isValid());
      assertTrue(controller.canExecute());
      Result result = controller.execute();
      Assert.assertThat(result, is(not(instanceOf(Failed.class))));
    }

    try (CommandController controller =
        uiTestHarness.createCommandController(
            CDIAddObserverMethodCommand.class, project.getRoot())) {
      controller.initialize();
      controller.setValueFor("named", "observe");
      controller.setValueFor("targetClass", "org.jboss.forge.test.bean.MyBean");
      controller.setValueFor("eventType", "java.lang.String");
      controller.setValueFor(
          "qualifiers",
          Arrays.asList("javax.enterprise.inject.Default", "javax.enterprise.inject.Any"));
      assertTrue(controller.isValid());
      assertTrue(controller.canExecute());
      Result result = controller.execute();
      Assert.assertThat(result, is(not(instanceOf(Failed.class))));
    }

    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.bean.MyBean");
    Assert.assertNotNull(javaResource);
    Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaClass.class)));
    JavaClass<?> myBean = javaResource.getJavaType();
    Assert.assertEquals(1, myBean.getMethods().size());
    Assert.assertEquals(0, myBean.getInterfaces().size());
    Method<?, ?> method = myBean.getMethods().get(0);
    Assert.assertEquals("observe", method.getName());
    Assert.assertEquals(1, method.getParameters().size());
    Parameter<?> parameter = method.getParameters().get(0);
    Assert.assertTrue(parameter.hasAnnotation(Observes.class));
    Assert.assertEquals("java.lang.String", parameter.getType().getQualifiedName());
    Assert.assertEquals("event", parameter.getName());
    Assert.assertEquals(3, parameter.getAnnotations().size());
    Assert.assertTrue(parameter.hasAnnotation(Observes.class));
    Assert.assertTrue(parameter.hasAnnotation(Default.class));
    Assert.assertTrue(parameter.hasAnnotation(Any.class));
  }
Пример #3
0
 @Before
 public void setup() throws Exception {
   project = projectFactory.createTempProject();
   commandController =
       testHarness.createCommandController(GitSetupCommand.class, project.getRoot());
   commandController.initialize();
 }
  @Test
  public void testAddDependencyWithDifferentScopeThenManaged() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      installer.installManaged(project, DEPENDENCY);

      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));

      try (CommandController command =
          testHarness.createCommandController(AddDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", COORDINATES + ":test");
        command.execute();
      }
      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));

      Dependency dependency =
          project
              .getFacet(DependencyFacet.class)
              .getDirectDependency(DependencyBuilder.create(COORDINATES));
      Assert.assertEquals("test", dependency.getScopeType());
    } finally {
      project.getRoot().delete(true);
    }
  }
  @Test
  public void testHasManagedDependencyReturnFailureOnSomeFound() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      installer.installManaged(project, DEPENDENCY);

      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));

      try (CommandController command =
          testHarness.createCommandController(
              HasManagedDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", Arrays.asList(COORDINATES, COORDINATES2));
        Result result = command.execute();
        Assert.assertTrue(result instanceof Failed);
      }
    } finally {
      project.getRoot().delete(true);
    }
  }
Пример #6
0
 private void executeGitIgnoreCreate() throws Exception {
   CommandController gitIgnoreCreateTester =
       testHarness.createCommandController(GitIgnoreCreateCommand.class, project.getRoot());
   gitIgnoreCreateTester.initialize();
   gitIgnoreCreateTester.setValueFor("templates", "Eclipse Maven");
   gitIgnoreCreateTester.execute();
 }
Пример #7
0
  @Test
  public void testCreateEnum() throws Exception {
    Project project = projectFactory.createTempProject();
    facetFactory.install(project, JavaSourceFacet.class);
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    JavaEnumSource javaEnum =
        Roaster.parse(
            JavaEnumSource.class, "package org.jboss.forge.test; public enum CreditCardType{}");
    facet.saveJavaSource(javaEnum);

    JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
    Assert.assertNotNull(javaResource);
    Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaEnum.class)));

    CommandController controller =
        testHarness.createCommandController(JavaAddEnumConstantCommand.class, javaResource);
    controller.initialize();
    controller.setValueFor("named", "VISA");
    Assert.assertTrue(controller.isValid());
    Assert.assertTrue(controller.canExecute());
    Result result = controller.execute();
    Assert.assertThat(result, is(not(instanceOf(Failed.class))));

    javaResource = facet.getJavaResource("org.jboss.forge.test.CreditCardType");
    JavaEnumSource enumClass = javaResource.getJavaType();
    List<EnumConstantSource> enumConstants = enumClass.getEnumConstants();
    Assert.assertEquals(1, enumConstants.size());

    Assert.assertEquals("VISA", enumConstants.get(0).getName());
  }
Пример #8
0
 @Test
 public void testGitIgnoreUpdateRepo() throws Exception {
   CommandController gitIgnoreUpdateRepoTester =
       testHarness.createCommandController(GitIgnoreUpdateRepoCommand.class, project.getRoot());
   gitIgnoreUpdateRepoTester.initialize();
   Result result = gitIgnoreUpdateRepoTester.execute();
   assertTrue(result.getMessage().contains("Local gitignore repository updated"));
 }
Пример #9
0
 @Test
 public void testContextListenerIsSet() throws Exception {
   try (WizardCommandController tester = testHarness.createWizardController(MyFirstWizard.class)) {
     tester.initialize();
     Assert.assertTrue("Wizard is not on a valid state", tester.isValid());
     Assert.assertTrue("Listener is not set", listener.isContextInitialized());
     tester.execute();
   }
   Assert.assertFalse("Listener is still set", listener.isContextInitialized());
 }
Пример #10
0
  @Test
  public void testGitIgnoreListPatterns() throws Exception {
    executeGitIgnoreCreate();

    CommandController gitIgnoreListPatternsTester =
        testHarness.createCommandController(GitIgnoreListPatternsCommand.class, project.getRoot());
    gitIgnoreListPatternsTester.initialize();
    Result result = gitIgnoreListPatternsTester.execute();

    assertTrue(result.getMessage().contains("target/"));
    assertTrue(result.getMessage().contains(".settings/"));
  }
Пример #11
0
 @Test
 public void testGitIgnoreListTemplates() throws Exception {
   CommandController gitIgnoreListTemplatesTester =
       testHarness.createCommandController(GitIgnoreListTemplatesCommand.class, project.getRoot());
   gitIgnoreListTemplatesTester.initialize();
   Result result = gitIgnoreListTemplatesTester.execute();
   String listOutput = result.getMessage().substring(result.getMessage().indexOf("==="));
   assertFalse(listOutput.contains(".gitignore"));
   assertTrue(listOutput.contains("= Languages ="));
   assertTrue(listOutput.contains("= Globals ="));
   assertTrue(listOutput.contains("Java"));
   assertTrue(listOutput.contains("Eclipse"));
 }
Пример #12
0
  @Test
  public void testGitIgnoreAddPattern() throws Exception {
    executeGitIgnoreCreate();

    CommandController gitIgnoreAddPatternTester =
        testHarness.createCommandController(GitIgnoreAddPatternCommand.class, project.getRoot());
    gitIgnoreAddPatternTester.initialize();
    gitIgnoreAddPatternTester.setValueFor("pattern", "*.forge");
    gitIgnoreAddPatternTester.execute();

    GitIgnoreResource gitignore = gitIgnoreResource();
    String content = Streams.toString(gitignore.getResourceInputStream());
    assertTrue(content.contains("*.forge"));
  }
 @Test
 public void testProjectTypeWithNoBuildSystemRequirements() throws Exception {
   File tempDir = OperatingSystemUtils.createTempDir();
   try {
     WizardCommandController wizard = testHarness.createWizardController(NewProjectWizard.class);
     wizard.initialize();
     Assert.assertFalse(wizard.canMoveToNextStep());
     wizard.setValueFor("named", "test");
     wizard.setValueFor("targetLocation", tempDir);
     wizard.setValueFor("topLevelPackage", "org.example");
     wizard.setValueFor("type", "norequirements");
     Assert.assertEquals(
         "norequirements", InputComponents.getValueFor(wizard.getInputs().get("type")).toString());
   } finally {
     tempDir.delete();
   }
 }
 @Test
 public void checkCommandMetadata() throws Exception {
   try (CommandController controller =
       uiTestHarness.createCommandController(
           CDIAddObserverMethodCommand.class, project.getRoot())) {
     controller.initialize();
     // Checks the command metadata
     assertTrue(controller.getCommand() instanceof CDIAddObserverMethodCommand);
     UICommandMetadata metadata = controller.getMetadata();
     assertEquals("CDI: Add Observer Method", metadata.getName());
     assertEquals("Java EE", metadata.getCategory().getName());
     assertEquals("CDI", metadata.getCategory().getSubCategory().getName());
     assertEquals(4, controller.getInputs().size());
     assertTrue(controller.hasInput("named"));
     assertTrue(controller.hasInput("targetClass"));
     assertTrue(controller.hasInput("eventType"));
   }
 }
  @Test
  public void testRemoveManagedDependencies() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      installer.install(project, DEPENDENCY);
      installer.install(project, DEPENDENCY2);

      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));

      try (CommandController command =
          testHarness.createCommandController(
              RemoveManagedDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", Arrays.asList(DEPENDENCY, DEPENDENCY2));
        command.setValueFor("removeUnmanaged", "false");
        command.execute();
      }

      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));
    } finally {
      project.getRoot().delete(true);
    }
  }
  @Test
  public void testAddDependency() throws Exception {
    Project project = factory.createTempProject(build);
    try {
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));

      try (CommandController command =
          testHarness.createCommandController(AddDependenciesCommand.class, project.getRoot())) {
        command.initialize();
        command.setValueFor("arguments", COORDINATES);
        command.execute();
      }

      Assert.assertTrue(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY));
      Assert.assertTrue(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY));
      Assert.assertFalse(project.getFacet(DependencyFacet.class).hasDirectDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasDirectManagedDependency(DEPENDENCY2));
      Assert.assertFalse(
          project.getFacet(DependencyFacet.class).hasEffectiveManagedDependency(DEPENDENCY2));
    } finally {
      project.getRoot().delete(true);
    }
  }
Пример #17
0
 @Test
 public void checkCommandMetadata() throws Exception {
   try (CommandController controller =
       uiTestHarness.createCommandController(JPANewEntityCommand.class, project.getRoot())) {
     controller.initialize();
     // Checks the command metadata
     assertTrue(controller.getCommand() instanceof JPANewEntityCommand);
     UICommandMetadata metadata = controller.getMetadata();
     assertEquals("JPA: New Entity", metadata.getName());
     assertEquals("Java EE", metadata.getCategory().getName());
     assertEquals("JPA", metadata.getCategory().getSubCategory().getName());
     assertFalse(
         "Project is created, shouldn't have targetLocation",
         controller.hasInput("targetLocation"));
     assertEquals(5, controller.getInputs().size());
     assertTrue(controller.hasInput("named"));
     assertTrue(controller.hasInput("targetPackage"));
     assertTrue(controller.hasInput("idStrategy"));
     assertTrue(controller.hasInput("tableName"));
     assertTrue(controller.hasInput("overwrite"));
     assertTrue(
         controller.getValueFor("targetPackage").toString().endsWith(DEFAULT_ENTITY_PACKAGE));
   }
 }