@Test
  public void testNestedCondition() throws IOException {
    try (GraphContext context = factory.create()) {
      ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class);
      pm.setName("Main Project");
      FileModel inputPath = context.getFramed().addVertex(null, FileModel.class);
      inputPath.setFilePath("src/test/resources/");

      Path outputPath =
          Paths.get(
              FileUtils.getTempDirectory().toString(), "windup_" + UUID.randomUUID().toString());
      FileUtils.deleteDirectory(outputPath.toFile());
      Files.createDirectories(outputPath);

      inputPath.setProjectModel(pm);
      pm.setRootFileModel(inputPath);

      WindupConfiguration windupConfiguration =
          new WindupConfiguration()
              .setRuleProviderFilter(
                  new NotPredicate(
                      new RuleProviderPhasePredicate(
                          MigrationRulesPhase.class, ReportGenerationPhase.class)))
              .setGraphContext(context);
      windupConfiguration.setInputPath(Paths.get(inputPath.getFilePath()));
      windupConfiguration.setOutputDirectory(outputPath);
      processor.execute(windupConfiguration);

      GraphService<ClassificationModel> classificationService =
          new GraphService<>(context, ClassificationModel.class);

      Assert.assertEquals(1, provider.getXmlFileMatches().size());
      List<ClassificationModel> classifications = Iterators.asList(classificationService.findAll());
      for (ClassificationModel model : classifications) {
        String classification = model.getClassification();
        String classificationString = classification.toString();
        Assert.assertEquals("Spring File", classificationString);
      }
      Assert.assertEquals(1, classifications.size());
      Iterator<FileModel> iterator = classifications.get(0).getFileModels().iterator();
      Assert.assertNotNull(iterator.next());
      Assert.assertNotNull(iterator.next());
      Assert.assertFalse(iterator.hasNext());
    }
  }
예제 #2
0
  @Test
  public void testJavaClassCondition()
      throws IOException, InstantiationException, IllegalAccessException {
    try (GraphContext context = factory.create(getDefaultPath())) {
      final String inputDir = "src/test/resources/org/jboss/windup/rules/java";

      final Path outputPath =
          Paths.get(
              FileUtils.getTempDirectory().toString(),
              "windup_" + RandomStringUtils.randomAlphanumeric(6));
      FileUtils.deleteDirectory(outputPath.toFile());
      Files.createDirectories(outputPath);

      // Fill the graph with test data.
      ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class);
      pm.setName("Main Project");

      // Create FileModel for $inputDir
      FileModel inputPathFrame = context.getFramed().addVertex(null, FileModel.class);
      inputPathFrame.setFilePath(inputDir);
      inputPathFrame.setProjectModel(pm);
      pm.addFileModel(inputPathFrame);

      // Set project.rootFileModel to inputPath
      pm.setRootFileModel(inputPathFrame);

      // Create FileModel for $inputDir/HintsClassificationsTest.java
      FileModel fileModel = context.getFramed().addVertex(null, FileModel.class);
      fileModel.setFilePath(inputDir + "/JavaHintsClassificationsTest.java");
      fileModel.setProjectModel(pm);
      pm.addFileModel(fileModel);

      // Create FileModel for $inputDir/JavaClassTest.java
      fileModel = context.getFramed().addVertex(null, FileModel.class);
      fileModel.setFilePath(inputDir + "/JavaClassTest.java");
      fileModel.setProjectModel(pm);
      pm.addFileModel(fileModel);

      context.getGraph().getBaseGraph().commit();

      final WindupConfiguration processorConfig =
          new WindupConfiguration().setOutputDirectory(outputPath);
      processorConfig.setRuleProviderFilter(
          new RuleProviderWithDependenciesPredicate(TestJavaClassTestRuleProvider.class));
      processorConfig
          .setGraphContext(context)
          .setRuleProviderFilter(
              new RuleProviderWithDependenciesPredicate(TestJavaClassTestRuleProvider.class));
      processorConfig.setInputPath(Paths.get(inputDir));
      processorConfig.setOutputDirectory(outputPath);
      processorConfig.setOptionValue(ScanPackagesOption.NAME, Collections.singletonList(""));

      processor.execute(processorConfig);

      GraphService<JavaTypeReferenceModel> typeRefService =
          new GraphService<>(context, JavaTypeReferenceModel.class);
      Iterable<JavaTypeReferenceModel> typeReferences = typeRefService.findAll();
      Assert.assertTrue(typeReferences.iterator().hasNext());

      Assert.assertEquals(3, provider.getFirstRuleMatchCount());
      Assert.assertEquals(1, provider.getSecondRuleMatchCount());
    }
  }