Search in sources :

Example 1 with MavenRepository

use of org.appformer.maven.integration.MavenRepository in project drools by kiegroup.

the class KieModuleMavenTest method testKieContainerBeforeAndAfterDeployOfSnapshot.

@Test
public void testKieContainerBeforeAndAfterDeployOfSnapshot() throws Exception {
    // BZ-1007977
    KieServices ks = KieServices.Factory.get();
    String group = "org.kie.test";
    String artifact = "test-module";
    String version = "1.0.0-SNAPSHOT";
    ReleaseId releaseId = ks.newReleaseId(group, artifact, version);
    String prefix = new File(".").getAbsolutePath().contains("kie-ci") ? "" : "kie-ci/";
    File kjar = new File(prefix + "src/test/resources/kjar/kjar-module-before.jar");
    File pom = new File(prefix + "src/test/resources/kjar/pom-kjar.xml");
    MavenRepository repository = getMavenRepository();
    repository.installArtifact(releaseId, kjar, pom);
    KieContainer kContainer = ks.newKieContainer(releaseId);
    KieBase kbase = kContainer.getKieBase();
    assertNotNull(kbase);
    Collection<KiePackage> packages = kbase.getKiePackages();
    assertNotNull(packages);
    assertEquals(1, packages.size());
    Collection<Rule> rules = packages.iterator().next().getRules();
    assertEquals(2, rules.size());
    ks.getRepository().removeKieModule(releaseId);
    // deploy new version
    File kjar1 = new File(prefix + "src/test/resources/kjar/kjar-module-after.jar");
    File pom1 = new File(prefix + "src/test/resources/kjar/pom-kjar.xml");
    repository.installArtifact(releaseId, kjar1, pom1);
    KieContainer kContainer2 = ks.newKieContainer(releaseId);
    KieBase kbase2 = kContainer2.getKieBase();
    assertNotNull(kbase2);
    Collection<KiePackage> packages2 = kbase2.getKiePackages();
    assertNotNull(packages2);
    assertEquals(1, packages2.size());
    Collection<Rule> rules2 = packages2.iterator().next().getRules();
    assertEquals(4, rules2.size());
    ks.getRepository().removeKieModule(releaseId);
}
Also used : MavenRepository.getMavenRepository(org.appformer.maven.integration.MavenRepository.getMavenRepository) MavenRepository(org.appformer.maven.integration.MavenRepository) KiePackage(org.kie.api.definition.KiePackage) KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) Rule(org.kie.api.definition.rule.Rule) File(java.io.File) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 2 with MavenRepository

use of org.appformer.maven.integration.MavenRepository in project drools by kiegroup.

the class KieRepositoryScannerTest method testKieScannerScopesNotRequired.

@Test
public void testKieScannerScopesNotRequired() throws Exception {
    MavenRepository repository = getMavenRepository();
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseIdWithDep = ks.newReleaseId("org.kie", "test-with-dep", "1.0-SNAPSHOT");
    Dependency dep1 = dependencyWithScope("org.kie", "test-dep1-in-test-scope", "1.0-SNAPSHOT", "test");
    Dependency dep2 = dependencyWithScope("org.kie", "test-dep2-in-provided-scope", "1.0-SNAPSHOT", "provided");
    Dependency dep3 = dependencyWithScope("org.kie", "test-dep3-in-system-scope", "1.0-SNAPSHOT", "system");
    dep3.setSystemPath(fileManager.getRootDirectory().getAbsolutePath());
    // to ensure KieBuilder is able to build correctly:
    repository.installArtifact(ks.newReleaseId("org.kie", "test-dep3-in-system-scope", "1.0-SNAPSHOT"), new byte[] {}, new byte[] {});
    InternalKieModule kJar2 = createKieJarWithDependencies(ks, releaseIdWithDep, false, "rule1", dep1, dep2, dep3);
    KieContainer kieContainer = ks.newKieContainer(releaseIdWithDep);
    // DROOLS-1051 following should not throw NPE because dependencies are not in scope of scanner
    KieScanner scanner = ks.newKieScanner(kieContainer);
    assertNotNull(scanner);
}
Also used : MavenRepository.getMavenRepository(org.appformer.maven.integration.MavenRepository.getMavenRepository) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) MavenRepository(org.appformer.maven.integration.MavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) Dependency(org.apache.maven.model.Dependency) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 3 with MavenRepository

use of org.appformer.maven.integration.MavenRepository in project drools by kiegroup.

the class KieRepositoryScannerTest method testMissingDependency.

@Test
public void testMissingDependency() throws Exception {
    KieServices ks = KieServices.Factory.get();
    MavenRepository repository = getMavenRepository();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0");
    ReleaseId missingDep = ks.newReleaseId("org.kie", "missing-dep", "1.0");
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, false);
    kfs.writePomXML(getPom(releaseId, missingDep));
    kfs.write("src/main/resources/KBase1/rule1.drl", createDRLWithTypeDeclaration(1, 1));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    assertEquals(1, messages.size());
    assertTrue(messages.get(0).toString().contains("missing-dep"));
    ks.getRepository().removeKieModule(releaseId);
}
Also used : MavenRepository.getMavenRepository(org.appformer.maven.integration.MavenRepository.getMavenRepository) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) MavenRepository(org.appformer.maven.integration.MavenRepository) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Aggregations

MavenRepository (org.appformer.maven.integration.MavenRepository)3 MavenRepository.getMavenRepository (org.appformer.maven.integration.MavenRepository.getMavenRepository)3 Test (org.junit.Test)3 KieServices (org.kie.api.KieServices)3 ReleaseId (org.kie.api.builder.ReleaseId)3 KieContainer (org.kie.api.runtime.KieContainer)2 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)2 File (java.io.File)1 Dependency (org.apache.maven.model.Dependency)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)1 KieBase (org.kie.api.KieBase)1 KieBuilder (org.kie.api.builder.KieBuilder)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 KieScanner (org.kie.api.builder.KieScanner)1 Message (org.kie.api.builder.Message)1 KiePackage (org.kie.api.definition.KiePackage)1 Rule (org.kie.api.definition.rule.Rule)1