Exemple #1
0
  @Test
  public void test() {
    final TestSvc test = (TestSvc) context.getBean("testSvc");

    // *AssignCache assignments are not very dynamic by their very nature.
    // Take care to invalidate the caches before each of the *AssignCache tests
    test.invalidateL2AssignIndia(System.currentTimeMillis());

    // Set the first cached datum
    final String orig = test.getL2AssignGolf(999L, RandomStringUtils.randomAlphabetic(4) + "-");

    // Make sure the value is definitely in there
    for (int ix = 0; ix < 3; ix++) {
      assertEquals(
          orig,
          test.getL2AssignGolf(1000L + ix, RandomStringUtils.randomAlphanumeric(4 + ix) + "-"));
    }

    // Force the update to happen.
    final String renew =
        test.getL2AssignHotel(
            System.currentTimeMillis(), RandomStringUtils.randomAlphanumeric(8) + "-");
    assertFalse(orig.equals(renew));

    // Make sure the NEW value is definitely in there
    for (int ix = 0; ix < 3; ix++) {
      assertEquals(
          renew,
          test.getL2AssignGolf(1000L + ix, RandomStringUtils.randomAlphanumeric(8 + ix) + "-"));
    }
  }
  @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());
    }
  }
 private Path getDefaultPath() {
   return FileUtils.getTempDirectory()
       .toPath()
       .resolve("Windup")
       .resolve("windupgraph_javaclasstest_" + RandomStringUtils.randomAlphanumeric(6));
 }