Search in sources :

Example 11 with SimpleFileSystemProvider

use of org.uberfire.java.nio.fs.file.SimpleFileSystemProvider in project kie-wb-common by kiegroup.

the class BuilderTest method testBuilderKModuleHasDependency.

@Test
public void testBuilderKModuleHasDependency() throws Exception {
    URL url = this.getClass().getResource("/GuvnorM2RepoDependencyExample2");
    SimpleFileSystemProvider p = new SimpleFileSystemProvider();
    org.uberfire.java.nio.file.Path path = p.getPath(url.toURI());
    final Module module = moduleService.resolveModule(Paths.convert(path));
    final Builder builder = new Builder(module, ioService, moduleService, importsService, new ArrayList<>(), dependenciesClassLoaderCache, pomModelCache, getPackageNameWhiteListService(), alwaysTrue);
    final BuildResults results = builder.build();
    // Debug output
    if (!results.getMessages().isEmpty()) {
        for (BuildMessage m : results.getMessages()) {
            logger.debug(m.getText());
        }
    }
    assertTrue(results.getMessages().isEmpty());
}
Also used : SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) Module(org.guvnor.common.services.project.model.Module) URL(java.net.URL) Test(org.junit.Test)

Example 12 with SimpleFileSystemProvider

use of org.uberfire.java.nio.fs.file.SimpleFileSystemProvider in project kie-wb-common by kiegroup.

the class BuilderTest method testBuilderKModuleHasDependencyMetaData.

@Test
public void testBuilderKModuleHasDependencyMetaData() throws Exception {
    URL url = this.getClass().getResource("/GuvnorM2RepoDependencyExample2");
    SimpleFileSystemProvider p = new SimpleFileSystemProvider();
    org.uberfire.java.nio.file.Path path = p.getPath(url.toURI());
    final Module module = moduleService.resolveModule(Paths.convert(path));
    final Builder builder = new Builder(module, ioService, moduleService, importsService, new ArrayList<>(), dependenciesClassLoaderCache, pomModelCache, getPackageNameWhiteListService(), alwaysTrue);
    final BuildResults results = builder.build();
    // Debug output
    if (!results.getMessages().isEmpty()) {
        for (BuildMessage m : results.getMessages()) {
            logger.debug(m.getText());
        }
    }
    assertTrue(results.getMessages().isEmpty());
    final KieModuleMetaData metaData = KieModuleMetaData.Factory.newKieModuleMetaData(builder.getKieModule());
    // Check packages
    final Set<String> packageNames = new HashSet<>();
    final Iterator<String> packageNameIterator = metaData.getPackages().iterator();
    while (packageNameIterator.hasNext()) {
        packageNames.add(packageNameIterator.next());
    }
    assertEquals(2, packageNames.size());
    assertTrue(packageNames.contains("defaultpkg"));
    assertTrue(packageNames.contains("org.kie.workbench.common.services.builder.tests.test1"));
    // Check classes
    final String packageName = "org.kie.workbench.common.services.builder.tests.test1";
    assertEquals(1, metaData.getClasses(packageName).size());
    final String className = metaData.getClasses(packageName).iterator().next();
    assertEquals("Bean", className);
    // Check metadata
    final Class clazz = metaData.getClass(packageName, className);
    final TypeMetaInfo typeMetaInfo = metaData.getTypeMetaInfo(clazz);
    assertNotNull(typeMetaInfo);
    assertFalse(typeMetaInfo.isEvent());
}
Also used : BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) URL(java.net.URL) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) Module(org.guvnor.common.services.project.model.Module) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with SimpleFileSystemProvider

use of org.uberfire.java.nio.fs.file.SimpleFileSystemProvider in project kie-wb-common by kiegroup.

the class BuilderTest method testKModuleContainsXLS.

@Test
public void testKModuleContainsXLS() throws Exception {
    URL url = this.getClass().getResource("/ExampleWithExcel");
    SimpleFileSystemProvider p = new SimpleFileSystemProvider();
    org.uberfire.java.nio.file.Path path = p.getPath(url.toURI());
    final Module module = moduleService.resolveModule(Paths.convert(path));
    final Builder builder = new Builder(module, ioService, moduleService, importsService, new ArrayList<>(), dependenciesClassLoaderCache, pomModelCache, getPackageNameWhiteListService(), alwaysTrue);
    final BuildResults results = builder.build();
    // Debug output
    if (!results.getMessages().isEmpty()) {
        for (BuildMessage m : results.getMessages()) {
            logger.debug(m.getText());
        }
    }
    assertTrue(results.getMessages().isEmpty());
}
Also used : SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) Module(org.guvnor.common.services.project.model.Module) URL(java.net.URL) Test(org.junit.Test)

Example 14 with SimpleFileSystemProvider

use of org.uberfire.java.nio.fs.file.SimpleFileSystemProvider in project kie-wb-common by kiegroup.

the class ModuleSaverTest method setUp.

@Before
public void setUp() throws Exception {
    fs = new SimpleFileSystemProvider();
    super.startWeld();
    // Instantiate Paths used in tests for Path conversion
    final Bean pathsBean = (Bean) beanManager.getBeans(Paths.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(pathsBean);
    paths = (Paths) beanManager.getReference(pathsBean, Paths.class, cc);
    // Ensure URLs use the default:// scheme
    fs.forceAsDefault();
    final Event<NewModuleEvent> newModuleEvent = mock(Event.class);
    when(ioService.createDirectory(any(org.uberfire.java.nio.file.Path.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    doCallRealMethod().when(resourceResolver).getDefaultWorkspacePath(any());
    doCallRealMethod().when(resourceResolver).getLegalId(any());
    saver = new ModuleSaver(ioService, pomService, mock(KModuleService.class), newModuleEvent, newPackageEvent, resourceResolver, mock(ProjectImportsService.class), mock(ModuleRepositoriesService.class), mock(PackageNameWhiteListService.class), mock(CommentedOptionFactory.class), new SessionInfo() {

        @Override
        public String getId() {
            return "session";
        }

        @Override
        public User getIdentity() {
            return new UserImpl("testuser");
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) SessionInfo(org.uberfire.rpc.SessionInfo) Bean(javax.enterprise.inject.spi.Bean) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) CreationalContext(javax.enterprise.context.spi.CreationalContext) NewModuleEvent(org.guvnor.common.services.project.events.NewModuleEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UserImpl(org.jboss.errai.security.shared.api.identity.UserImpl) Paths(org.uberfire.backend.server.util.Paths) Before(org.junit.Before)

Example 15 with SimpleFileSystemProvider

use of org.uberfire.java.nio.fs.file.SimpleFileSystemProvider in project kie-wb-common by kiegroup.

the class KieServiceTest method setUp.

@Before
public void setUp() throws Exception {
    fileSystemProvider = new SimpleFileSystemProvider();
    // Ensure URLs use the default:// scheme
    fileSystemProvider.forceAsDefault();
    mainFilePath = fileSystemProvider.getPath(this.getClass().getResource("mymodel.model").toURI());
    dotFilePath = fileSystemProvider.getPath(this.getClass().getResource(".mymodel.model").toURI());
    orphanDotFilePath = fileSystemProvider.getPath(this.getClass().getResource(".mymodel").toURI());
    kieService = spy(new KieService<TestModel>() {

        {
            IOService mockIOService = mock(IOService.class);
            when(mockIOService.exists(mainFilePath)).thenReturn(true);
            when(mockIOService.exists(dotFilePath)).thenReturn(false);
            this.logger = mock(Logger.class);
            this.pathResolver = new PathResolverMock();
            this.ioService = mockIOService;
            this.moduleService = mock(KieModuleService.class);
            this.projectService = mock(WorkspaceProjectService.class);
            this.metadataService = KieServiceTest.this.metadataService;
        }

        @Override
        protected TestModel constructContent(Path path, Overview overview) {
            if (path.getFileName().toString().equals(mainFilePath.getFileName().toString())) {
                return new TestModel(overview);
            } else if (path.getFileName().toString().equals(orphanDotFilePath.getFileName().toString())) {
                return new TestModel(overview);
            } else {
                return null;
            }
        }
    });
}
Also used : SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) IOService(org.uberfire.io.IOService) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Logger(org.slf4j.Logger) Before(org.junit.Before)

Aggregations

SimpleFileSystemProvider (org.uberfire.java.nio.fs.file.SimpleFileSystemProvider)16 Before (org.junit.Before)9 Test (org.junit.Test)8 Module (org.guvnor.common.services.project.model.Module)7 URL (java.net.URL)6 Path (org.uberfire.backend.vfs.Path)5 BuildMessage (org.guvnor.common.services.project.builder.model.BuildMessage)4 BuildResults (org.guvnor.common.services.project.builder.model.BuildResults)4 Paths (org.uberfire.backend.server.util.Paths)3 CreationalContext (javax.enterprise.context.spi.CreationalContext)2 Bean (javax.enterprise.inject.spi.Bean)2 KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)2 IOService (org.uberfire.io.IOService)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1