use of org.uberfire.rpc.SessionInfo in project kie-wb-common by kiegroup.
the class WorkbenchPreferenceScopeTypesTest method setup.
@Before
public void setup() {
final SessionInfo sessionInfo = new SessionInfoMock();
final UsernameProvider usernameProvider = mock(UsernameProvider.class);
doReturn(sessionInfo.getIdentity().getIdentifier()).when(usernameProvider).get();
scopeTypes = new WorkbenchPreferenceScopeTypes(usernameProvider);
}
use of org.uberfire.rpc.SessionInfo in project kie-wb-common by kiegroup.
the class ModuleServiceImplNewModuleTest method testDeleteModuleObserverBridge.
@Test
public void testDeleteModuleObserverBridge() throws URISyntaxException {
final URI fs = new URI("git://test");
try {
FileSystems.getFileSystem(fs);
} catch (FileSystemNotFoundException e) {
FileSystems.newFileSystem(fs, new HashMap<String, Object>());
}
final Path path = mock(Path.class);
final org.uberfire.java.nio.file.Path nioPath = mock(org.uberfire.java.nio.file.Path.class);
when(path.getFileName()).thenReturn("pom.xml");
when(path.toURI()).thenReturn("git://test/p0/pom.xml");
when(nioPath.getParent()).thenReturn(nioPath);
when(nioPath.resolve(any(String.class))).thenReturn(nioPath);
when(nioPath.toUri()).thenReturn(URI.create("git://test/p0/pom.xml"));
when(nioPath.getFileSystem()).thenReturn(FileSystems.getFileSystem(fs));
when(ioService.get(any(URI.class))).thenReturn(nioPath);
final SessionInfo sessionInfo = mock(SessionInfo.class);
final Event<DeleteModuleEvent> deleteModuleEvent = mock(Event.class);
final AbstractModuleService moduleServiceSpy = spy(moduleService);
final DeleteKieModuleObserverBridge bridge = new DeleteKieModuleObserverBridge(ioService, deleteModuleEvent, moduleFactory);
bridge.onBatchResourceChanges(new ResourceDeletedEvent(path, "message", sessionInfo));
verify(deleteModuleEvent, times(1)).fire(any(DeleteModuleEvent.class));
verify(moduleServiceSpy, times(0)).newModule(any(Path.class), any(POM.class));
verify(moduleFactory, times(1)).simpleModuleInstance(any(org.uberfire.java.nio.file.Path.class));
}
use of org.uberfire.rpc.SessionInfo in project kie-wb-common by kiegroup.
the class SafeSessionInfoProvider method getSessionInfo.
@Override
public SessionInfo getSessionInfo() {
if (delegate.isUnsatisfied()) {
return createSessionInfo();
}
try {
SessionInfo sessionInfo = delegate.get();
sessionInfo.getId();
return sessionInfo;
} catch (Exception e) {
logger.debug("SessionInfo bean was available but could not be retrieved: " + e.getMessage(), e);
return createSessionInfo();
}
}
use of org.uberfire.rpc.SessionInfo 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"));
}
use of org.uberfire.rpc.SessionInfo in project kie-wb-common by kiegroup.
the class BuilderConcurrencyIntegrationTest method testBuilderConcurrency.
@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1145105
void testBuilderConcurrency() throws URISyntaxException {
final URL pomUrl = this.getClass().getResource("/BuilderConcurrencyRepo/pom.xml");
final org.uberfire.java.nio.file.Path nioPomPath = fs.getPath(pomUrl.toURI());
final Path pomPath = paths.convert(nioPomPath);
final URL resourceUrl = this.getClass().getResource("/BuilderConcurrencyRepo/src/main/resources/update.drl");
final org.uberfire.java.nio.file.Path nioResourcePath = fs.getPath(resourceUrl.toURI());
final Path resourcePath = paths.convert(nioResourcePath);
final SessionInfo sessionInfo = mock(SessionInfo.class);
// Force full build before attempting incremental changes
final KieModule project = moduleService.resolveModule(resourcePath);
final BuildResults buildResults = buildService.build(project);
assertNotNull(buildResults);
assertEquals(0, buildResults.getErrorMessages().size());
assertEquals(1, buildResults.getInformationMessages().size());
// Perform incremental build
final int THREADS = 200;
final Result result = new Result();
ExecutorService es = Executors.newCachedThreadPool();
for (int i = 0; i < THREADS; i++) {
switch(i % 3) {
case 0:
es.execute(new Runnable() {
@Override
public void run() {
try {
logger.debug("Thread " + Thread.currentThread().getName() + " has started: BuildService.build( project )");
buildService.build(project);
logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
} catch (Throwable e) {
result.setFailed(true);
result.setMessage(e.getMessage());
logger.debug(e.getMessage());
}
}
});
break;
case 1:
es.execute(new Runnable() {
@Override
public void run() {
try {
logger.debug("Thread " + Thread.currentThread().getName() + " has started: LRUModuleDataModelOracleCache.invalidateModuleCache(...)");
moduleDMOCache.invalidateModuleCache(new InvalidateDMOModuleCacheEvent(sessionInfo, project, pomPath));
logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
} catch (Throwable e) {
result.setFailed(true);
result.setMessage(e.getMessage());
logger.debug(e.getMessage());
}
}
});
break;
default:
es.execute(new Runnable() {
@Override
public void run() {
try {
logger.debug("Thread " + Thread.currentThread().getName() + " has started: LRUBuilderCache.assertBuilder( project ).getKieModuleIgnoringErrors();");
builderCache.assertBuilder(project).getKieModuleIgnoringErrors();
logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
} catch (Throwable e) {
result.setFailed(true);
result.setMessage(e.getMessage());
logger.debug(e.getMessage());
}
}
});
}
}
es.shutdown();
try {
es.awaitTermination(5, TimeUnit.MINUTES);
} catch (InterruptedException e) {
}
if (result.isFailed()) {
fail(result.getMessage());
}
}
Aggregations