Search in sources :

Example 16 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class BaseLibraryIndexingTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws IOException {
    if (!created) {
        final String repositoryName = getRepositoryName();
        final String path = createTempDirectory().getAbsolutePath();
        System.setProperty("org.uberfire.nio.git.dir", path);
        System.setProperty("org.uberfire.nio.git.daemon.enabled", "false");
        System.setProperty("org.uberfire.nio.git.ssh.enabled", "false");
        System.setProperty("org.uberfire.sys.repo.monitor.disabled", "true");
        System.setProperty(FileSystemUtils.SIMPLIFIED_MONITORING_ENABLED, "false");
        System.out.println(".niogit: " + path);
        final URI newRepo = URI.create("git://" + repositoryName);
        try {
            IOService ioService = ioService();
            ioService.newFileSystem(newRepo, new HashMap<>());
            // Don't ask, but we need to write a single file first in order for indexing to work
            basePath = getDirectoryPath().resolveSibling("someNewOtherPath");
            Path dummyFile = basePath.resolve("dummy");
            // Create directory instead of file so we don't add anything indexable.
            ioService.createDirectory(dummyFile);
        } catch (final Exception e) {
            e.printStackTrace();
            logger.warn("Failed to initialize IOService instance: " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
        } finally {
            created = true;
        }
        final Instance<NamedQuery> namedQueriesProducer = mock(Instance.class);
        when(namedQueriesProducer.iterator()).thenReturn(getQueries().iterator());
        service = new RefactoringQueryServiceImpl(config, new NamedQueries(namedQueriesProducer));
        service.init();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) IOService(org.uberfire.io.IOService) NamedQueries(org.kie.workbench.common.services.refactoring.backend.server.query.NamedQueries) NamedQuery(org.kie.workbench.common.services.refactoring.backend.server.query.NamedQuery) URI(java.net.URI) IOException(java.io.IOException) RefactoringQueryServiceImpl(org.kie.workbench.common.services.refactoring.backend.server.query.RefactoringQueryServiceImpl) Before(org.junit.Before)

Example 17 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class KieServiceTest method setUp.

@Before
public void setUp() throws Exception {
    fileSystemProvider = new SimpleFileSystemProvider();
    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.metadataService = KieServiceTest.this.metadataService;
            this.moduleService = KieServiceTest.this.moduleService;
            this.projectService = KieServiceTest.this.projectService;
            this.overviewLoader = new KieServiceOverviewLoader(metadataService, moduleService, projectService);
        }

        @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) IOService(org.uberfire.io.IOService) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Logger(org.slf4j.Logger) Before(org.junit.Before)

Example 18 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class DataModelServiceConstructorTest method testConstructor.

@Test
public void testConstructor() throws IllegalArgumentException, FileSystemNotFoundException, SecurityException, URISyntaxException {
    final URL packageUrl = this.getClass().getResource("/DataModelServiceConstructorTest/src/main/java/t1p1");
    final RenameService renameService = mock(RenameService.class);
    final SaveAndRenameServiceImpl saveAndRenameService = mock(SaveAndRenameServiceImpl.class);
    RepositoryService repoService = mock(RepositoryService.class);
    IOService ioService = new IOServiceDotFileImpl();
    Collection<Role> roles = new ArrayList<>();
    Collection<Group> groups = new ArrayList<>();
    User user = new UserImpl("admin", roles, groups);
    SessionInfo sessionInfo = new SessionInfoImpl("admin", user);
    Instance<User> userInstance = mock(Instance.class);
    when(userInstance.get()).thenReturn(user);
    ConfigIOServiceProducer cfiosProducer = new ConfigIOServiceProducer();
    cfiosProducer.setup();
    IOService configIOService = cfiosProducer.configIOService();
    MetadataService metadataService = new MetadataServiceImpl(ioService, configIOService, mock(CommentedOptionFactory.class), sessionInfo);
    POMContentHandler pomContentHandler = new POMContentHandler();
    M2RepoServiceImpl m2RepoService = new M2RepoServiceImpl();
    PomEnhancer pomEnhancer = new DefaultPomEnhancer();
    POMService pomService = new POMServiceImpl(ioService, pomContentHandler, m2RepoService, metadataService, new EventSourceMock<>(), mock(ModuleService.class), mock(CommentedOptionFactory.class), pomEnhancer);
    KModuleContentHandler moduleContentHandler = new KModuleContentHandler();
    CommentedOptionFactory commentedOptionFactory = new CommentedOptionFactoryImpl(sessionInfo);
    ProjectConfigurationContentHandler moduleConfigurationContentHandler = new ProjectConfigurationContentHandler();
    ProjectImportsService moduleImportsService = new ProjectImportsServiceImpl(ioService, moduleConfigurationContentHandler, renameService, saveAndRenameService);
    Event<NewModuleEvent> newModuleEvent = new EventSourceMock<>();
    Event<NewPackageEvent> newPackageEvent = new EventSourceMock<>();
    Event<InvalidateDMOModuleCacheEvent> invalidateDMOCache = new EventSourceMock<>();
    PermissionTypeRegistry permissionTypeRegistry = new DefaultPermissionTypeRegistry();
    DotNamedPermissionType permissionType = new DotNamedPermissionType(REPOSITORY_TYPE.getName());
    permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.READ, true);
    permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.CREATE, true);
    permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.UPDATE, true);
    permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.DELETE, true);
    permissionTypeRegistry.register(permissionType);
    ModuleRepositoryResolver repositoryResolver = new ModuleRepositoryResolverImpl(ioService, null, null);
    FileDiscoveryService fileDiscoveryService = new FileDiscoveryServiceImpl();
    HackedKieModuleServiceImpl moduleService = null;
    HackedKModuleServiceImpl kModuleService = new HackedKModuleServiceImpl(ioService, moduleService, metadataService, moduleContentHandler);
    KieResourceResolver resourceResolver = new KieResourceResolver(ioService, pomService, commentedOptionFactory, kModuleService, resourcePathResolversInstance);
    ModuleSaver moduleSaver = null;
    moduleService = new HackedKieModuleServiceImpl(ioService, moduleSaver, pomService, repoService, newModuleEvent, newPackageEvent, invalidateDMOCache, sessionInfo, commentedOptionFactory, mock(ModuleFinder.class), mock(PackageServiceLoader.class), resourceResolver, repositoryResolver);
    ModuleRepositoriesContentHandler contentHandler = new ModuleRepositoriesContentHandler();
    ModuleRepositoriesService moduleRepositoriesService = new KieModuleRepositoriesServiceImpl(ioService, repositoryResolver, resourceResolver, contentHandler, commentedOptionFactory);
    DependencyService dependencyService = new DependencyServiceImpl();
    PackageNameSearchProvider packageNameSearchProvider = new PackageNameSearchProvider(dependencyService);
    PackageNameAllowListLoader loader = new PackageNameAllowListLoader(packageNameSearchProvider, ioService);
    MetadataServerSideService serverSideMetdataService = new MetadataServiceImpl(ioService, configIOService, commentedOptionFactory, sessionInfo);
    PackageNameAllowListSaver saver = new PackageNameAllowListSaver(ioService, serverSideMetdataService, commentedOptionFactory);
    PackageNameAllowListService packageNameAllowListService = new PackageNameAllowListServiceImpl(ioService, moduleService, loader, saver);
    moduleSaver = new ModuleSaver(ioService, pomService, kModuleService, newModuleEvent, newPackageEvent, resourceResolver, moduleImportsService, moduleRepositoriesService, packageNameAllowListService, commentedOptionFactory, sessionInfo);
    moduleService.setModuleSaver(moduleSaver);
    kModuleService.setModuleService(moduleService);
    ProjectImportsService importsService = new ProjectImportsServiceImpl(ioService, moduleConfigurationContentHandler, renameService, saveAndRenameService);
    Instance<BuildValidationHelper> buildValidationHelperBeans = null;
    Instance<Predicate<String>> classFilterBeans = null;
    HackedLRUModuleDependenciesClassLoaderCache dependenciesClassLoaderCache = new HackedLRUModuleDependenciesClassLoaderCache();
    LRUPomModelCache pomModelCache = new LRUPomModelCache();
    LRUBuilderCache builderCache = new LRUBuilderCache(ioService, moduleService, importsService, buildValidationHelperBeans, dependenciesClassLoaderCache, pomModelCache, packageNameAllowListService, classFilterBeans);
    Instance<PostBuildHandler> handlerInstance = mock(Instance.class);
    Iterator<PostBuildHandler> mockIterator = mock(Iterator.class);
    when(handlerInstance.iterator()).thenReturn(mockIterator);
    when(mockIterator.hasNext()).thenReturn(false);
    DeploymentVerifier deploymentVerifier = new DeploymentVerifier(repositoryResolver, moduleRepositoriesService);
    BuildHelper buildHelper = new BuildHelper(pomService, m2RepoService, moduleService, deploymentVerifier, builderCache, handlerInstance, userInstance);
    PipelineRegistry pipelineRegistry = new InMemoryPipelineRegistry();
    BuildPipelineInitializer pipelineInitializer = new BuildPipelineInitializer(pipelineRegistry, getConfigExecutors(moduleService, buildHelper));
    BuildPipelineInvoker pipelineInvoker = new BuildPipelineInvoker(pipelineInitializer.getExecutor(), pipelineRegistry);
    BuildServiceHelper buildServiceHelper = new BuildServiceHelper(pipelineInvoker, deploymentVerifier);
    BuildService buildService = new BuildServiceImpl(moduleService, buildServiceHelper, builderCache);
    BuildInfoService buildInfoService = new BuildInfoService(buildService, builderCache);
    ModuleDataModelOracleBuilderProvider builderProvider = new ModuleDataModelOracleBuilderProvider(packageNameAllowListService, importsService);
    LRUModuleDataModelOracleCache cacheModules = new LRUModuleDataModelOracleCache(builderProvider, moduleService, buildInfoService);
    dependenciesClassLoaderCache.setBuildInfoService(buildInfoService);
    LRUDataModelOracleCache cachePackages = new LRUDataModelOracleCache(ioService, fileDiscoveryService, cacheModules, moduleService, buildInfoService, dataModelExtensionProvider, new RawMVELEvaluator());
    DataModelService dataModelService = new DataModelServiceImpl(cachePackages, cacheModules, moduleService);
    final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
    final Path packagePath = Paths.convert(nioPackagePath);
    final ModuleDataModelOracle oracle = dataModelService.getModuleDataModel(packagePath);
    assertNotNull(oracle);
    assertEquals(4, oracle.getModuleModelFields().size());
    assertContains("t1p1.Bean1", oracle.getModuleModelFields().keySet());
    assertContains("t1p1.DRLBean", oracle.getModuleModelFields().keySet());
    assertContains("t1p2.Bean2", oracle.getModuleModelFields().keySet());
    assertContains("java.lang.String", oracle.getModuleModelFields().keySet());
    assertEquals(TypeSource.JAVA_PROJECT, oracle.getModuleTypeSources().get("t1p1.Bean1"));
    assertEquals(TypeSource.DECLARED, oracle.getModuleTypeSources().get("t1p1.DRLBean"));
    assertEquals(TypeSource.JAVA_PROJECT, oracle.getModuleTypeSources().get("t1p2.Bean2"));
    assertEquals(TypeSource.JAVA_DEPENDENCY, oracle.getModuleTypeSources().get("java.lang.String"));
}
Also used : KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) ModuleService(org.guvnor.common.services.project.service.ModuleService) IOServiceDotFileImpl(org.uberfire.io.impl.IOServiceDotFileImpl) ProjectImportsService(org.kie.workbench.common.services.shared.project.ProjectImportsService) ArrayList(java.util.ArrayList) POMContentHandler(org.guvnor.common.services.project.backend.server.utils.POMContentHandler) KieResourceResolver(org.kie.workbench.common.services.backend.project.KieResourceResolver) PackageNameAllowListLoader(org.kie.workbench.common.services.backend.allowlist.PackageNameAllowListLoader) MetadataServerSideService(org.guvnor.common.services.backend.metadata.MetadataServerSideService) Predicate(java.util.function.Predicate) ProjectImportsServiceImpl(org.kie.workbench.common.services.backend.project.ProjectImportsServiceImpl) PackageNameSearchProvider(org.kie.workbench.common.services.backend.allowlist.PackageNameSearchProvider) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) ModuleDataModelOracleBuilderProvider(org.kie.workbench.common.services.datamodel.backend.server.cache.ModuleDataModelOracleBuilderProvider) DefaultPermissionTypeRegistry(org.uberfire.security.impl.authz.DefaultPermissionTypeRegistry) FileDiscoveryServiceImpl(org.guvnor.common.services.backend.file.FileDiscoveryServiceImpl) BuildPipelineInvoker(org.kie.workbench.common.services.backend.builder.ala.BuildPipelineInvoker) DefaultPomEnhancer(org.guvnor.common.services.project.backend.server.DefaultPomEnhancer) KieModuleRepositoriesServiceImpl(org.kie.workbench.common.services.backend.project.KieModuleRepositoriesServiceImpl) FileDiscoveryService(org.guvnor.common.services.backend.file.FileDiscoveryService) Role(org.jboss.errai.security.shared.api.Role) LRUPomModelCache(org.kie.workbench.common.services.backend.builder.core.LRUPomModelCache) BuildServiceHelper(org.kie.workbench.common.services.backend.builder.service.BuildServiceHelper) ModuleRepositoriesContentHandler(org.guvnor.common.services.project.backend.server.ModuleRepositoriesContentHandler) BuildHelper(org.kie.workbench.common.services.backend.builder.core.BuildHelper) DefaultPermissionTypeRegistry(org.uberfire.security.impl.authz.DefaultPermissionTypeRegistry) PermissionTypeRegistry(org.uberfire.security.authz.PermissionTypeRegistry) ModuleRepositoryResolverImpl(org.guvnor.common.services.project.backend.server.ModuleRepositoryResolverImpl) BuildServiceImpl(org.kie.workbench.common.services.backend.builder.service.BuildServiceImpl) BuildValidationHelper(org.guvnor.common.services.project.builder.service.BuildValidationHelper) Group(org.jboss.errai.security.shared.api.Group) CommentedOptionFactory(org.guvnor.common.services.backend.util.CommentedOptionFactory) User(org.jboss.errai.security.shared.api.identity.User) BuildService(org.guvnor.common.services.project.builder.service.BuildService) DefaultPomEnhancer(org.guvnor.common.services.project.backend.server.DefaultPomEnhancer) PomEnhancer(org.guvnor.common.services.project.backend.server.PomEnhancer) POMServiceImpl(org.guvnor.common.services.project.backend.server.POMServiceImpl) SessionInfo(org.uberfire.rpc.SessionInfo) PackageNameAllowListServiceImpl(org.kie.workbench.common.services.backend.allowlist.PackageNameAllowListServiceImpl) MetadataServiceImpl(org.guvnor.common.services.backend.metadata.MetadataServiceImpl) EventSourceMock(org.uberfire.mocks.EventSourceMock) ModuleRepositoriesService(org.guvnor.common.services.project.service.ModuleRepositoriesService) DependencyService(org.kie.workbench.common.services.shared.dependencies.DependencyService) BuildPipelineInitializer(org.kie.workbench.common.services.backend.builder.ala.BuildPipelineInitializer) URL(java.net.URL) SessionInfoImpl(org.uberfire.rpc.impl.SessionInfoImpl) MetadataService(org.guvnor.common.services.shared.metadata.MetadataService) InMemoryPipelineRegistry(org.guvnor.ala.registry.inmemory.InMemoryPipelineRegistry) PipelineRegistry(org.guvnor.ala.registry.PipelineRegistry) SaveAndRenameServiceImpl(org.uberfire.ext.editor.commons.backend.service.SaveAndRenameServiceImpl) IOService(org.uberfire.io.IOService) NewPackageEvent(org.guvnor.common.services.project.events.NewPackageEvent) PackageNameAllowListSaver(org.kie.workbench.common.services.backend.allowlist.PackageNameAllowListSaver) PackageNameAllowListService(org.kie.workbench.common.services.shared.allowlist.PackageNameAllowListService) BuildInfoService(org.kie.workbench.common.services.backend.builder.service.BuildInfoService) UserImpl(org.jboss.errai.security.shared.api.identity.UserImpl) DotNamedPermissionType(org.uberfire.security.impl.authz.DotNamedPermissionType) KModuleContentHandler(org.kie.workbench.common.services.backend.kmodule.KModuleContentHandler) PostBuildHandler(org.guvnor.common.services.project.builder.service.PostBuildHandler) RepositoryService(org.guvnor.structure.repositories.RepositoryService) LRUModuleDataModelOracleCache(org.kie.workbench.common.services.datamodel.backend.server.cache.LRUModuleDataModelOracleCache) Path(org.uberfire.backend.vfs.Path) InvalidateDMOModuleCacheEvent(org.guvnor.common.services.project.builder.events.InvalidateDMOModuleCacheEvent) LRUBuilderCache(org.kie.workbench.common.services.backend.builder.core.LRUBuilderCache) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModuleSaver(org.kie.workbench.common.services.backend.project.ModuleSaver) RenameService(org.uberfire.ext.editor.commons.service.RenameService) InMemoryPipelineRegistry(org.guvnor.ala.registry.inmemory.InMemoryPipelineRegistry) POMService(org.guvnor.common.services.project.service.POMService) ConfigIOServiceProducer(org.uberfire.backend.server.io.ConfigIOServiceProducer) NewModuleEvent(org.guvnor.common.services.project.events.NewModuleEvent) DeploymentVerifier(org.kie.workbench.common.services.backend.builder.core.DeploymentVerifier) LRUDataModelOracleCache(org.kie.workbench.common.services.datamodel.backend.server.cache.LRUDataModelOracleCache) M2RepoServiceImpl(org.guvnor.m2repo.backend.server.M2RepoServiceImpl) DependencyServiceImpl(org.kie.workbench.common.services.backend.dependencies.DependencyServiceImpl) ProjectConfigurationContentHandler(org.guvnor.common.services.project.backend.server.ProjectConfigurationContentHandler) ModuleRepositoryResolver(org.guvnor.common.services.project.service.ModuleRepositoryResolver) DataModelService(org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService) CommentedOptionFactoryImpl(org.guvnor.common.services.backend.util.CommentedOptionFactoryImpl) Test(org.junit.Test)

Example 19 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriverTest method updateAnnotationsTest.

@Test
public void updateAnnotationsTest() {
    try {
        // First read the AnnotationsUpdateTest
        Path annotationsUpdateTestFilePath = rootPath.resolve("package3").resolve("AnnotationsUpdateTest.java");
        String source = ioService.readAllString(annotationsUpdateTestFilePath);
        JavaClassSource annotationsUpdateTestJavaClassSource = (JavaClassSource) Roaster.parse(source);
        ClassLoader classLoader = getClass().getClassLoader();
        ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(annotationsUpdateTestJavaClassSource, classLoader);
        final SourceFilter pojo1Filter = javaType -> false;
        final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
        final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
        FilterHolder filterHolder = mock(FilterHolder.class);
        when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
        when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
        when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
        JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, classLoader, filterHolder);
        ModelDriverResult result = javaRoasterModelDriver.loadDataObject(source, annotationsUpdateTestFilePath);
        // 1) read the AnnotationsUpdateTest
        DataObject annotationsUpdateTest = result.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package3.AnnotationsUpdateTest");
        // 2) modify the AnnotationsUpdateTest according to the expected result, basically updating all the needed annotations.
        // update the AnnotationValuesAnnotation
        Annotation annotationValuesAnnotation = annotationsUpdateTest.getAnnotation(AnnotationValuesAnnotation.class.getName());
        // annotation.setValue( "primitivesParam", @PrimitivesAnnotation(stringParam="\"line1\" \n line2 \\ \n line3") );
        Annotation primitivesParamValue = createAnnotation(PrimitivesAnnotation.class);
        // construct the value -> "\"line1\" \n line2 \\ \n line3"
        StringBuilder stringParamBuilder = new StringBuilder();
        stringParamBuilder.append('"').append("line1").append('"').append(" ").append('\n');
        stringParamBuilder.append(" line2 ").append('\\').append(" ").append('\n');
        stringParamBuilder.append(" line3");
        primitivesParamValue.setValue("stringParam", stringParamBuilder.toString());
        annotationValuesAnnotation.setValue("primitivesParam", primitivesParamValue);
        // @PrimitivesAnnotation(intParam=1)
        Annotation primitiveValue1 = createAnnotation(PrimitivesAnnotation.class);
        primitiveValue1.setValue("intParam", 2);
        // @PrimitivesAnnotation(intParam=3)
        Annotation primitiveValue2 = createAnnotation(PrimitivesAnnotation.class);
        primitiveValue2.setValue("intParam", 3);
        List<Annotation> primitivesArrayParamValue = new ArrayList<Annotation>();
        primitivesArrayParamValue.add(primitiveValue1);
        primitivesArrayParamValue.add(primitiveValue2);
        // annotation.setValue( "primitivesArrayParam", "{@PrimitivesAnnotation(intParam=2),@PrimitivesAnnotation(intParam=3)}" );
        annotationValuesAnnotation.setValue("primitivesArrayParam", primitivesArrayParamValue);
        // annotation.setValue( "enumsParam", "@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE2)" );
        Annotation enumsParamValue = createAnnotation(EnumsAnnotation.class);
        enumsParamValue.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
        annotationValuesAnnotation.setValue("enumsParam", enumsParamValue);
        // annotation.setValue( "enumsArrayParam", "{@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE2),@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE3)}" );
        Annotation enumArrayParam1 = createAnnotation(EnumsAnnotation.class);
        enumArrayParam1.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
        Annotation enumArrayParam2 = createAnnotation(EnumsAnnotation.class);
        enumArrayParam2.setValue("enum1Param", TestEnums.ENUM1.VALUE3.toString());
        List<Annotation> enumVarrayValues = new ArrayList<Annotation>();
        enumVarrayValues.add(enumArrayParam1);
        enumVarrayValues.add(enumArrayParam2);
        annotationValuesAnnotation.setValue("enumsArrayParam", enumVarrayValues);
        // annotation.setValue( "classAnnotationParam", "@ClassAnnotation(classParam=Set.class)" );
        Annotation classAnnotationParamValue = createAnnotation(ClassAnnotation.class);
        classAnnotationParamValue.setValue("classParam", "Set.class");
        annotationValuesAnnotation.setValue("classAnnotationParam", classAnnotationParamValue);
        // annotation.setValue( "classAnnotationArrayParam", "{@ClassAnnotation(classParam=Set.class),@ClassAnnotation(classParam=Set.class)}" );
        Annotation classAnnotationArrayParamValue1 = createAnnotation(ClassAnnotation.class);
        classAnnotationArrayParamValue1.setValue("classParam", "Set.class");
        Annotation classAnnotationArrayParamValue2 = createAnnotation(ClassAnnotation.class);
        classAnnotationArrayParamValue2.setValue("classParam", "Set.class");
        List<Annotation> classAnnotationArrayParamValue = new ArrayList<Annotation>();
        classAnnotationArrayParamValue.add(classAnnotationArrayParamValue1);
        classAnnotationArrayParamValue.add(classAnnotationArrayParamValue2);
        annotationValuesAnnotation.setValue("classAnnotationArrayParam", classAnnotationArrayParamValue);
        // update the ClassAnnotation
        Annotation classAnnotation = createAnnotation(ClassAnnotation.class);
        classAnnotation.setValue("classParam", "java.util.Collection.class");
        classAnnotation.setValue("classArrayParam", createArrayParam("List.class"));
        annotationsUpdateTest.addAnnotation(classAnnotation);
        // update the EnumsAnnotation
        Annotation enumsAnnotation = createAnnotation(EnumsAnnotation.class);
        enumsAnnotation.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
        // enumsAnnotation.setValue( "enum1ArrayParam", "{TestEnums.ENUM1.VALUE3}" );
        enumsAnnotation.setValue("enum1ArrayParam", createEnumArrayParam(TestEnums.ENUM1.VALUE3));
        enumsAnnotation.setValue("enum2Param", TestEnums.ENUM2.VALUE2.toString());
        // enumsAnnotation.setValue( "enum2ArrayParam", "{TestEnums.ENUM2.VALUE3}" );
        enumsAnnotation.setValue("enum2ArrayParam", createEnumArrayParam(TestEnums.ENUM2.VALUE3));
        annotationsUpdateTest.addAnnotation(enumsAnnotation);
        // update the PrimitivesAnnotation
        Annotation primitivesAnnotation = createAnnotation(PrimitivesAnnotation.class);
        primitivesAnnotation.setValue("byteParam", new Byte("2"));
        // primitivesAnnotation.setValue( "byteArrayParam", "{3,4}" );
        primitivesAnnotation.setValue("byteArrayParam", createArrayParam((byte) 3, (byte) 4));
        primitivesAnnotation.setValue("shortParam", new Short("2"));
        // primitivesAnnotation.setValue( "shortArrayParam", "{3,4}" );
        primitivesAnnotation.setValue("shortArrayParam", createArrayParam((short) 3, (short) 4));
        primitivesAnnotation.setValue("stringParam", "2");
        primitivesAnnotation.setValue("stringArrayParam", createArrayParam("3", "4"));
        annotationsUpdateTest.addAnnotation(primitivesAnnotation);
        // add the MarkerAnnotation
        annotationsUpdateTest.addAnnotation(createMarkerAnnotation());
        annotationsUpdateTest.setName("AnnotationsUpdateTestResult");
        // 3) compare the modified data object with the expected data object.
        Path expectedFilePath = rootPath.resolve("package3").resolve("AnnotationsUpdateTestResult.java");
        String expectedSource = ioService.readAllString(expectedFilePath);
        JavaClassSource expectedJavaClassSource = (JavaClassSource) Roaster.parse(expectedSource);
        ModelDriverResult expectedResult = javaRoasterModelDriver.loadDataObject(expectedSource, expectedFilePath);
        DataObject annotationsUpdateTestResult = expectedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package3.AnnotationsUpdateTestResult");
        // First check, the modified data object in memory should be the same as the readed from the model.
        DataModelerAssert.assertEqualsDataObject(annotationsUpdateTestResult, annotationsUpdateTest);
        // Second check, update the JavaClassSource corresponding to the AnnotationsUpdateTest
        javaRoasterModelDriver.updateSource(annotationsUpdateTestJavaClassSource, annotationsUpdateTest, new UpdateInfo(), classTypeResolver);
        ModelDriverResult updatedResult = javaRoasterModelDriver.loadDataObject(annotationsUpdateTestJavaClassSource.toString(), annotationsUpdateTestFilePath);
        // and now compare the updatedResult with the expected value.
        DataModelerAssert.assertEqualsDataObject(annotationsUpdateTestResult, updatedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package3.AnnotationsUpdateTestResult"));
        logger.debug(annotationsUpdateTestJavaClassSource.toString());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Test failed: " + e.getMessage());
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) Description(org.kie.api.definition.type.Description) Arrays(java.util.Arrays) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Timestamp(org.kie.api.definition.type.Timestamp) Label(org.kie.api.definition.type.Label) TestAnnotation1(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation1) UpdateInfo(org.kie.workbench.common.services.datamodeller.driver.impl.UpdateInfo) LoggerFactory(org.slf4j.LoggerFactory) DataModelerAssert(org.kie.workbench.common.services.datamodeller.DataModelerAssert) Paths(org.uberfire.backend.server.util.Paths) Generated(javax.annotation.Generated) Matcher(java.util.regex.Matcher) Roaster(org.jboss.forge.roaster.Roaster) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) SequenceGenerator(javax.persistence.SequenceGenerator) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) URI(java.net.URI) Instance(javax.enterprise.inject.Instance) Entity(javax.persistence.Entity) ParameterImpl(org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl) UniqueConstraint(javax.persistence.UniqueConstraint) ClassReactive(org.kie.api.definition.type.ClassReactive) JavaTypeInfo(org.kie.workbench.common.services.datamodeller.core.JavaTypeInfo) ENUM3(org.kie.workbench.common.services.datamodeller.annotations.ENUM3) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) List(java.util.List) AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) Role(org.kie.api.definition.type.Role) JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Expires(org.kie.api.definition.type.Expires) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Parameter(org.kie.workbench.common.services.datamodeller.core.Parameter) Mock(org.mockito.Mock) Path(org.uberfire.java.nio.file.Path) RunWith(org.junit.runner.RunWith) DriverUtils(org.kie.workbench.common.services.datamodeller.util.DriverUtils) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) Type(org.kie.workbench.common.services.datamodeller.core.Type) ArrayList(java.util.ArrayList) Table(javax.persistence.Table) TypeSafe(org.kie.api.definition.type.TypeSafe) Duration(org.kie.api.definition.type.Duration) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Before(org.junit.Before) Logger(org.slf4j.Logger) JavaEnumImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaEnumImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) IOException(java.io.IOException) Test(org.junit.Test) Method(org.kie.workbench.common.services.datamodeller.core.Method) InputStreamReader(java.io.InputStreamReader) File(java.io.File) ImportImpl(org.kie.workbench.common.services.datamodeller.core.impl.ImportImpl) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) Mockito(org.mockito.Mockito) TestEnums(org.kie.workbench.common.services.datamodeller.annotations.TestEnums) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Position(org.kie.api.definition.type.Position) JavaClass(org.kie.workbench.common.services.datamodeller.core.JavaClass) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) IOService(org.uberfire.io.IOService) BufferedReader(java.io.BufferedReader) Key(org.kie.api.definition.type.Key) Assert(org.junit.Assert) Collections(java.util.Collections) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) IOException(java.io.IOException) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) UpdateInfo(org.kie.workbench.common.services.datamodeller.driver.impl.UpdateInfo) Test(org.junit.Test)

Example 20 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriverTest method modelVetoingTest.

@Test
public void modelVetoingTest() throws Exception {
    try {
        final SourceFilter pojo1Filter = javaType -> javaType.getName().equals("Pojo1");
        final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
        final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
        FilterHolder filterHolder = mock(FilterHolder.class);
        when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
        when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
        when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
        final JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, getClass().getClassLoader(), filterHolder);
        ModelDriverResult modelDriverResult = javaRoasterModelDriver.loadModel();
        DataModel dataModelOriginal = createModel();
        assertNotNull(modelDriverResult);
        assertNotNull(modelDriverResult.getDataModel());
        assertEquals(dataModelOriginal.getDataObjects().size() - 1, modelDriverResult.getDataModel().getDataObjects().size());
        for (DataObject dataObject : modelDriverResult.getDataModel().getDataObjects()) {
            if (!dataObject.getClassName().endsWith("Pojo1")) {
                DataModelerAssert.assertEqualsDataObject(dataObject, modelDriverResult.getDataModel().getDataObject(dataObject.getClassName()));
            } else {
                fail("Pojo1 should have been vetoed.");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Test failed: " + e.getMessage());
    }
}
Also used : Description(org.kie.api.definition.type.Description) Arrays(java.util.Arrays) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Timestamp(org.kie.api.definition.type.Timestamp) Label(org.kie.api.definition.type.Label) TestAnnotation1(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation1) UpdateInfo(org.kie.workbench.common.services.datamodeller.driver.impl.UpdateInfo) LoggerFactory(org.slf4j.LoggerFactory) DataModelerAssert(org.kie.workbench.common.services.datamodeller.DataModelerAssert) Paths(org.uberfire.backend.server.util.Paths) Generated(javax.annotation.Generated) Matcher(java.util.regex.Matcher) Roaster(org.jboss.forge.roaster.Roaster) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) SequenceGenerator(javax.persistence.SequenceGenerator) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) URI(java.net.URI) Instance(javax.enterprise.inject.Instance) Entity(javax.persistence.Entity) ParameterImpl(org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl) UniqueConstraint(javax.persistence.UniqueConstraint) ClassReactive(org.kie.api.definition.type.ClassReactive) JavaTypeInfo(org.kie.workbench.common.services.datamodeller.core.JavaTypeInfo) ENUM3(org.kie.workbench.common.services.datamodeller.annotations.ENUM3) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) List(java.util.List) AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) Role(org.kie.api.definition.type.Role) JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Expires(org.kie.api.definition.type.Expires) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Parameter(org.kie.workbench.common.services.datamodeller.core.Parameter) Mock(org.mockito.Mock) Path(org.uberfire.java.nio.file.Path) RunWith(org.junit.runner.RunWith) DriverUtils(org.kie.workbench.common.services.datamodeller.util.DriverUtils) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) Type(org.kie.workbench.common.services.datamodeller.core.Type) ArrayList(java.util.ArrayList) Table(javax.persistence.Table) TypeSafe(org.kie.api.definition.type.TypeSafe) Duration(org.kie.api.definition.type.Duration) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Before(org.junit.Before) Logger(org.slf4j.Logger) JavaEnumImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaEnumImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) IOException(java.io.IOException) Test(org.junit.Test) Method(org.kie.workbench.common.services.datamodeller.core.Method) InputStreamReader(java.io.InputStreamReader) File(java.io.File) ImportImpl(org.kie.workbench.common.services.datamodeller.core.impl.ImportImpl) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) Mockito(org.mockito.Mockito) TestEnums(org.kie.workbench.common.services.datamodeller.annotations.TestEnums) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Position(org.kie.api.definition.type.Position) JavaClass(org.kie.workbench.common.services.datamodeller.core.JavaClass) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) IOService(org.uberfire.io.IOService) BufferedReader(java.io.BufferedReader) Key(org.kie.api.definition.type.Key) Assert(org.junit.Assert) Collections(java.util.Collections) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility) InputStream(java.io.InputStream) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOService (org.uberfire.io.IOService)25 Before (org.junit.Before)18 Test (org.junit.Test)15 IOException (java.io.IOException)14 Mock (org.mockito.Mock)14 RunWith (org.junit.runner.RunWith)13 List (java.util.List)12 Paths (org.uberfire.backend.server.util.Paths)12 Mockito (org.mockito.Mockito)11 Path (org.uberfire.backend.vfs.Path)11 File (java.io.File)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 URI (java.net.URI)9 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)9 Logger (org.slf4j.Logger)9 Path (org.uberfire.java.nio.file.Path)9 Arrays (java.util.Arrays)8 LoggerFactory (org.slf4j.LoggerFactory)8