use of org.eclipse.che.api.core.notification.EventService in project che by eclipse.
the class CheEnvironmentEngineTest method machineStopShouldFireEvents.
@Test
public void machineStopShouldFireEvents() throws Exception {
// given
List<Instance> instances = startEnv();
Optional<Instance> instanceOpt = instances.stream().filter(machine -> !machine.getConfig().isDev()).findAny();
assertTrue(instanceOpt.isPresent(), "Required for test non-dev machine is not found");
Instance instance = instanceOpt.get();
// when
engine.stopMachine(instance.getWorkspaceId(), instance.getId());
// then
verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.CREATING).withDev(instance.getConfig().isDev()).withMachineName(instance.getConfig().getName()).withMachineId(instance.getId()).withWorkspaceId(instance.getWorkspaceId()));
verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withDev(instance.getConfig().isDev()).withMachineName(instance.getConfig().getName()).withMachineId(instance.getId()).withWorkspaceId(instance.getWorkspaceId()));
}
use of org.eclipse.che.api.core.notification.EventService in project che by eclipse.
the class BaseTest method initProjectApi.
@BeforeClass
protected void initProjectApi() throws Exception {
JavaPlugin javaPlugin = new JavaPlugin(wsPath + "/set", null, null);
EventService eventService = new EventService();
TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder();
if (root == null)
root = new File(wsPath);
if (root.exists()) {
IoUtil.deleteRecursive(root);
}
root.mkdir();
File indexDir = new File(INDEX_PATH);
if (indexDir.exists()) {
IoUtil.deleteRecursive(indexDir);
}
indexDir.mkdir();
Set<PathMatcher> filters = new HashSet<>();
filters.add(path -> true);
FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory()));
projectTypeRegistry.registerProjectType(new PlainJavaProjectType(new PlainJavaValueProviderFactory()));
ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
projectRegistry.initProjects();
ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
projectManager = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, new TestWorkspaceHolder(new ArrayList<>()), mock(FileWatcherManager.class));
ResourcesPlugin plugin = new ResourcesPlugin("target/index", wsPath, () -> projectRegistry, () -> projectManager);
plugin.start();
javaPlugin.start();
}
use of org.eclipse.che.api.core.notification.EventService in project che by eclipse.
the class WsAgentTestBase method setUp.
public void setUp() throws Exception {
if (workspaceHolder == null)
workspaceHolder = new TestWorkspaceHolder();
if (root == null)
root = new File(FS_PATH);
if (root.exists()) {
IoUtil.deleteRecursive(root);
}
root.mkdir();
File indexDir = new File(INDEX_PATH);
if (indexDir.exists()) {
IoUtil.deleteRecursive(indexDir);
}
indexDir.mkdir();
Set<PathMatcher> filters = new HashSet<>();
filters.add(path -> true);
FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
projectTypeRegistry.registerProjectType(new PT1());
projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
this.eventService = new EventService();
projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
projectRegistry.initProjects();
this.importerRegistry = new ProjectImporterRegistry(new HashSet<>());
fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
fileWatcherManager = mock(FileWatcherManager.class);
TestWorkspaceHolder wsHolder = new TestWorkspaceHolder();
pm = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, wsHolder, fileWatcherManager);
pm.initWatcher();
}
use of org.eclipse.che.api.core.notification.EventService in project che by eclipse.
the class ProjectServiceTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
WorkspaceProjectsSyncer workspaceHolder = new WsAgentTestBase.TestWorkspaceHolder();
File root = new File(FS_PATH);
if (root.exists()) {
IoUtil.deleteRecursive(root);
}
root.mkdir();
File indexDir = new File(INDEX_PATH);
if (indexDir.exists()) {
IoUtil.deleteRecursive(indexDir);
}
indexDir.mkdir();
Set<PathMatcher> filters = new HashSet<>();
filters.add(path -> {
for (java.nio.file.Path pathElement : path) {
if (pathElement == null || EXCLUDE_SEARCH_PATH.equals(pathElement.toString())) {
return true;
}
}
return false;
});
FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
final EventService eventService = new EventService();
// PTs for test
ProjectTypeDef chuck = new ProjectTypeDef("chuck_project_type", "chuck_project_type", true, false) {
{
addConstantDefinition("x", "attr description", new AttributeValue(Arrays.asList("a", "b")));
}
};
Set<ProjectTypeDef> projectTypes = new HashSet<>();
final LocalProjectType myProjectType = new LocalProjectType("my_project_type", "my project type");
projectTypes.add(myProjectType);
projectTypes.add(new LocalProjectType("module_type", "module type"));
projectTypes.add(chuck);
ptRegistry = new ProjectTypeRegistry(projectTypes);
phRegistry = new ProjectHandlerRegistry(new HashSet<>());
importerRegistry = new ProjectImporterRegistry(Collections.<ProjectImporter>emptySet());
projectServiceLinksInjector = new ProjectServiceLinksInjector();
projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, ptRegistry, phRegistry, eventService);
projectRegistry.initProjects();
FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
pm = new ProjectManager(vfsProvider, ptRegistry, projectRegistry, phRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
pm.initWatcher();
HttpJsonRequest httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
//List<ProjectConfigDto> modules = new ArrayList<>();
projects = new ArrayList<>();
addMockedProjectConfigDto(myProjectType, "my_project");
when(httpJsonRequestFactory.fromLink(any())).thenReturn(httpJsonRequest);
when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
when(workspaceConfigMock.getProjects()).thenReturn(projects);
// verify(httpJsonRequestFactory).fromLink(eq(DtoFactory.newDto(Link.class)
// .withHref(apiEndpoint + "/workspace/" + workspace + "/project")
// .withMethod(PUT)));
DependencySupplierImpl dependencies = new DependencySupplierImpl();
dependencies.addInstance(ProjectTypeRegistry.class, ptRegistry);
dependencies.addInstance(UserDao.class, userDao);
dependencies.addInstance(ProjectManager.class, pm);
dependencies.addInstance(ProjectImporterRegistry.class, importerRegistry);
dependencies.addInstance(ProjectHandlerRegistry.class, phRegistry);
dependencies.addInstance(EventService.class, eventService);
dependencies.addInstance(ProjectServiceLinksInjector.class, projectServiceLinksInjector);
ResourceBinder resources = new ResourceBinderImpl();
ProviderBinder providers = ProviderBinder.getInstance();
EverrestProcessor processor = new EverrestProcessor(new EverrestConfiguration(), dependencies, new RequestHandlerImpl(new RequestDispatcher(resources), providers), null);
launcher = new ResourceLauncher(processor);
processor.addApplication(new Application() {
@Override
public Set<Class<?>> getClasses() {
return java.util.Collections.<Class<?>>singleton(ProjectService.class);
}
@Override
public Set<Object> getSingletons() {
return new HashSet<>(Arrays.asList(new ApiExceptionMapper()));
}
});
ApplicationContext.setCurrent(anApplicationContext().withProviders(providers).build());
env = org.eclipse.che.commons.env.EnvironmentContext.getCurrent();
}
use of org.eclipse.che.api.core.notification.EventService in project che by eclipse.
the class MachineProcessManagerTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
final EventService eventService = mock(EventService.class);
final String machineLogsDir = targetDir().resolve("logs-dir").toString();
IoUtil.deleteRecursive(new File(machineLogsDir));
manager = spy(new MachineProcessManager(machineLogsDir, eventService, environmentEngine));
EnvironmentContext envCont = new EnvironmentContext();
envCont.setSubject(CREATOR);
EnvironmentContext.setCurrent(envCont);
doReturn(logConsumer).when(manager).getProcessLogger(MACHINE_ID, 111, "outputChannel");
when(command.getCommandLine()).thenReturn("CommandLine");
when(command.getName()).thenReturn("CommandName");
when(command.getType()).thenReturn("CommandType");
when(instance.createProcess(command, "outputChannel")).thenReturn(instanceProcess);
when(instanceProcess.getPid()).thenReturn(111);
when(environmentEngine.getMachine(WORKSPACE_ID, MACHINE_ID)).thenReturn(instance);
}
Aggregations