org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl Java Examples
The following examples show how to use
org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiuserJpaWorkspaceDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public Page<WorkspaceImpl> getWorkspaces(String userId, int maxItems, long skipCount) throws ServerException { try { final List<WorkspaceImpl> list = managerProvider .get() .createQuery(findByWorkerQuery, WorkspaceImpl.class) .setParameter("userId", userId) .setMaxResults(maxItems) .setFirstResult((int) skipCount) .getResultList(); final long count = managerProvider .get() .createQuery(findByWorkerCountQuery, Long.class) .setParameter("userId", userId) .getSingleResult(); return new Page<>(list, skipCount, maxItems, count); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
Example #2
Source File: ForwardActivityFilter.java From rh-che with Eclipse Public License 2.0 | 6 votes |
@Override public void onEvent(WorkspaceStatusEvent event) { String workspaceId = event.getWorkspaceId(); if (WorkspaceStatus.STOPPING.equals(event.getStatus())) { try { final WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); Runtime runtime = workspace.getRuntime(); if (runtime != null) { String userId = runtime.getOwner(); callWorkspaceAnalyticsEndpoint( userId, workspaceId, "/fabric8-che-analytics/stopped", "notify stop", workspace); } else { LOG.warn( "Received stopping event for workspace {}/{} with id {} but runtime is null", workspace.getNamespace(), workspace.getConfig().getName(), workspaceId); } } catch (NotFoundException | ServerException e) { LOG.warn("", e); return; } } }
Example #3
Source File: WorkspaceActivityDaoTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void createdTimeMustSetLastStopped() throws TckRepositoryException, ServerException { // given new workspace with created activity AccountImpl newAccount = new AccountImpl("new_account", "new_account", "test"); WorkspaceImpl workspace = createWorkspace("new_ws", newAccount, "new_ws"); accountTckRepository.createAll(singletonList(newAccount)); wsTckRepository.createAll(singletonList(workspace)); Page<String> stopped = workspaceActivityDao.findInStatusSince(Instant.now().toEpochMilli(), STOPPED, 100, 0); assertTrue(stopped.isEmpty()); // when created workspace activity workspaceActivityDao.setCreatedTime("new_ws", Instant.now().toEpochMilli()); // then find STOPPED must return it and activity must have set last_stopped timestamp stopped = workspaceActivityDao.findInStatusSince(Instant.now().toEpochMilli(), STOPPED, 100, 0); assertFalse(stopped.isEmpty()); assertEquals(stopped.getItemsCount(), 1); WorkspaceActivity activity = workspaceActivityDao.findActivity("new_ws"); assertNotNull(activity.getLastStopped()); }
Example #4
Source File: WorkspaceActivityCheckerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldContinueCheckActivitiesValidityIfExceptionOccurredOnRestoringOne() throws Exception { // given String id = "1"; WorkspaceActivity invalidActivity = new WorkspaceActivity(); invalidActivity.setWorkspaceId(id); when(workspaceRuntimes.getRunning()).thenReturn(ImmutableSet.of("problematic", id)); doThrow(new ServerException("error")) .when(workspaceActivityDao) .findActivity(eq("problematic")); doReturn(invalidActivity).when(workspaceActivityDao).findActivity(eq(id)); when(workspaceManager.getWorkspace(eq(id))) .thenReturn( WorkspaceImpl.builder() .setId(id) .setAttributes(ImmutableMap.of(Constants.CREATED_ATTRIBUTE_NAME, "15")) .build()); // when checker.cleanup(); // then verify(workspaceActivityDao).setCreatedTime(eq(id), eq(15L)); }
Example #5
Source File: WorkspaceDaoTest.java From che with Eclipse Public License 2.0 | 6 votes |
@BeforeMethod public void createEntities() throws TckRepositoryException { accounts = new AccountImpl[COUNT_OF_ACCOUNTS]; for (int i = 0; i < COUNT_OF_ACCOUNTS; i++) { accounts[i] = new AccountImpl("accountId" + i, "accountName" + i, "test"); } workspaces = new WorkspaceImpl[COUNT_OF_WORKSPACES]; for (int i = 0; i < COUNT_OF_WORKSPACES; i++) { // 2 workspaces share 1 namespace AccountImpl account = accounts[i / 2]; // Last one is made from devfile if (i < DEVFILE_WORKSPACE_INDEX) { workspaces[i] = createWorkspaceFromConfig("workspace-" + i, account, "name-" + i); } else { workspaces[i] = createWorkspaceFromDevfile("workspace-" + i, account, "name-" + i); } } accountRepo.createAll(Arrays.asList(accounts)); workspaceRepo.createAll(Stream.of(workspaces).map(WorkspaceImpl::new).collect(toList())); }
Example #6
Source File: WorkspaceDaoTest.java From che with Eclipse Public License 2.0 | 6 votes |
public static WorkspaceImpl createWorkspaceFromConfig( String id, AccountImpl account, String name) { final WorkspaceConfigImpl wCfg = createWorkspaceConfig(name); // Workspace final WorkspaceImpl workspace = new WorkspaceImpl(); workspace.setId(id); workspace.setAccount(account); wCfg.setName(name); workspace.setConfig(wCfg); workspace.setAttributes( new HashMap<>( ImmutableMap.of( "attr1", "value1", "attr2", "value2", "attr3", "value3"))); workspace.setConfig(wCfg); return workspace; }
Example #7
Source File: RemoveInvitesBeforeWorkspaceRemovedEventSubscriberTest.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Test public void shouldRemoveInvitesOnBeforeWorkspaceEvent() throws Exception { WorkspaceImpl toRemove = new WorkspaceImpl(WS_ID, null, null); InviteImpl invite1 = new InviteImpl( EMAIL_1, WorkspaceDomain.DOMAIN_ID, WS_ID, singletonList(WorkspaceDomain.DELETE)); InviteImpl invite2 = new InviteImpl( EMAIL_2, WorkspaceDomain.DOMAIN_ID, WS_ID, singletonList(WorkspaceDomain.CONFIGURE)); doReturn(new Page<>(singletonList(invite1), 0, 1, 2)) .doReturn(new Page<>(singletonList(invite2), 1, 1, 2)) .when(inviteManager) .getInvites(anyString(), anyString(), anyLong(), anyInt()); subscriber.onCascadeEvent(new BeforeWorkspaceRemovedEvent(toRemove)); verify(inviteManager, times(2)) .getInvites(eq(WorkspaceDomain.DOMAIN_ID), eq(WS_ID), anyLong(), anyInt()); verify(inviteManager).remove(WorkspaceDomain.DOMAIN_ID, WS_ID, EMAIL_1); verify(inviteManager).remove(WorkspaceDomain.DOMAIN_ID, WS_ID, EMAIL_2); }
Example #8
Source File: WorkspaceDaoTest.java From che with Eclipse Public License 2.0 | 6 votes |
public static WorkspaceImpl createWorkspaceFromDevfile( String id, AccountImpl account, String name) { final DevfileImpl devfile = createDevfile(name); // Workspace final WorkspaceImpl workspace = new WorkspaceImpl(); workspace.setId(id); workspace.setAccount(account); workspace.setDevfile(devfile); workspace.setAttributes( new HashMap<>( ImmutableMap.of( "attr1", "value1", "attr2", "value2", "attr3", "value3"))); return workspace; }
Example #9
Source File: InviteDaoTest.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@BeforeMethod private void setUp() throws TckRepositoryException { organization = new OrganizationImpl("org123", "test", null); workspace = new WorkspaceImpl("ws123", organization.getAccount(), null); invites = new InviteImpl[3]; invites[0] = new InviteImpl( EMAIL_1, OrganizationDomain.DOMAIN_ID, organization.getId(), asList("read", "delete")); invites[1] = new InviteImpl( EMAIL_1, WorkspaceDomain.DOMAIN_ID, workspace.getId(), asList("read", "update", "delete")); invites[2] = new InviteImpl( EMAIL_2, WorkspaceDomain.DOMAIN_ID, workspace.getId(), asList("read", "update")); organizationRepo.createAll(singletonList(organization)); workspaceRepo.createAll(singletonList(workspace)); inviteRepo.createAll(Stream.of(invites).map(InviteImpl::new).collect(Collectors.toList())); }
Example #10
Source File: JpaWorkspaceDaoTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test(expectedExceptions = IllegalStateException.class) public void shouldNotSaveDevfileWithEmptyMetadataName() { final AccountImpl account = new AccountImpl("accountId", "namespace", "test"); final WorkspaceImpl workspace = createWorkspaceFromDevfile("id", account, "name"); workspace.getDevfile().getMetadata().setName(""); try { // persist the workspace manager.getTransaction().begin(); manager.persist(account); manager.persist(workspace); manager.getTransaction().commit(); } finally { manager.getTransaction().rollback(); manager.clear(); } }
Example #11
Source File: PreviewUrlLinksVariableGeneratorTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldAppendPathWithQueryParamsWhenDefinedInPreviewUrl() { Map<String, String> commandAttrs = new HashMap<>(); commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host"); CommandImpl command = new CommandImpl( "run command", "a", "a", new PreviewUrlImpl(123, "/hello?a=b"), commandAttrs); WorkspaceImpl workspace = createWorkspaceWithCommands(singletonList(command)); Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(workspace, uriBuilder); assertTrue(linkMap.values().iterator().next().endsWith("preview_url_host")); String linkKey = linkMap.keySet().iterator().next(); assertEquals( workspace .getRuntime() .getCommands() .get(0) .getAttributes() .get(Command.PREVIEW_URL_ATTRIBUTE), "${" + linkKey + "}/hello?a=b"); }
Example #12
Source File: WorkspaceFsBackupSchedulerTest.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Test public void shouldNotBackupWSWithNonRunningStatus() throws Exception { // given WorkspaceImpl wsInSnapshottingState = addWorkspace("ws3"); when(workspaceManager.getWorkspace("ws3")).thenReturn(wsInSnapshottingState); when(wsInSnapshottingState.getStatus()).thenReturn(WorkspaceStatus.SNAPSHOTTING); WorkspaceImpl wsInStoppingState = addWorkspace("ws4"); when(workspaceManager.getWorkspace("ws4")).thenReturn(wsInStoppingState); when(wsInStoppingState.getStatus()).thenReturn(WorkspaceStatus.STOPPING); WorkspaceImpl wsInStartingState = addWorkspace("ws5"); when(workspaceManager.getWorkspace("ws5")).thenReturn(wsInStartingState); when(wsInStartingState.getStatus()).thenReturn(WorkspaceStatus.STARTING); // when scheduler.scheduleBackup(); // then // add this verification with timeout to ensure that thread executor had enough time before // verification of call verify(backupManager, timeout(2000)).backupWorkspace(WORKSPACE_ID_1); verify(backupManager, timeout(2000)).backupWorkspace(WORKSPACE_ID_2); verify(backupManager, after(2000).never()).backupWorkspace("ws3"); // previous verifying should wait enough, so no timeouts here verify(backupManager, never()).backupWorkspace("ws4"); verify(backupManager, never()).backupWorkspace("ws5"); }
Example #13
Source File: WorkspaceActivityCheckerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldRestoreCreatedTimeOnInvalidActivityRecord() throws Exception { // given String id = "1"; WorkspaceActivity invalidActivity = new WorkspaceActivity(); invalidActivity.setWorkspaceId(id); when(workspaceRuntimes.getRunning()).thenReturn(singleton(id)); when(workspaceActivityDao.findActivity(eq(id))).thenReturn(invalidActivity); when(workspaceManager.getWorkspace(eq(id))) .thenReturn( WorkspaceImpl.builder() .setId(id) .setAttributes(ImmutableMap.of(Constants.CREATED_ATTRIBUTE_NAME, "15")) .build()); // when checker.cleanup(); // then verify(workspaceActivityDao).setCreatedTime(eq(id), eq(15L)); }
Example #14
Source File: WorkspaceServiceTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldAddCommand() throws Exception { final WorkspaceImpl workspace = createWorkspace(createConfigDto()); when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace); when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace); final CommandDto commandDto = createCommandDto(); final int commandsSizeBefore = workspace.getConfig().getCommands().size(); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(commandDto) .when() .post(SECURE_PATH + "/workspace/" + workspace.getId() + "/command"); assertEquals(response.getStatusCode(), 200); assertEquals( new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT) .getConfig() .getCommands() .size(), commandsSizeBefore + 1); verify(wsManager).updateWorkspace(any(), any()); }
Example #15
Source File: WorkspaceRuntimesTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void runtimeIsRecoveredForWorkspaceWithConfig() throws Exception { RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace"); mockWorkspaceWithConfig(identity); RuntimeContext context = mockContext(identity); when(context.getRuntime()) .thenReturn(new TestInternalRuntime(context, emptyMap(), WorkspaceStatus.STARTING)); doReturn(context).when(infrastructure).prepare(eq(identity), any()); doReturn(mock(InternalEnvironment.class)).when(testEnvFactory).create(any()); when(statuses.get(anyString())).thenReturn(WorkspaceStatus.STARTING); // try recover runtimes.recoverOne(infrastructure, identity); WorkspaceImpl workspace = WorkspaceImpl.builder().setId(identity.getWorkspaceId()).build(); runtimes.injectRuntime(workspace); assertNotNull(workspace.getRuntime()); assertEquals(workspace.getStatus(), WorkspaceStatus.STARTING); }
Example #16
Source File: JpaWorkspaceDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public Page<WorkspaceImpl> getWorkspaces(String userId, int maxItems, long skipCount) throws ServerException { try { final List<WorkspaceImpl> list = managerProvider .get() .createNamedQuery("Workspace.getAll", WorkspaceImpl.class) .setMaxResults(maxItems) .setFirstResult((int) skipCount) .getResultList() .stream() .map(WorkspaceImpl::new) .collect(Collectors.toList()); final long count = managerProvider .get() .createNamedQuery("Workspace.getAllCount", Long.class) .getSingleResult(); return new Page<>(list, skipCount, maxItems, count); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
Example #17
Source File: WorkspaceManager.java From che with Eclipse Public License 2.0 | 6 votes |
/** * Asynchronously stops the workspace. * * @param workspaceId the id of the workspace to stop * @throws ServerException when any server error occurs * @throws NullPointerException when {@code workspaceId} is null * @throws NotFoundException when workspace {@code workspaceId} doesn't have runtime */ public void stopWorkspace(String workspaceId, Map<String, String> options) throws ServerException, NotFoundException, ConflictException { requireNonNull(workspaceId, "Required non-null workspace id"); final WorkspaceImpl workspace = normalizeState(workspaceDao.get(workspaceId), true); checkWorkspaceIsRunningOrStarting(workspace); if (!workspace.isTemporary()) { workspace.getAttributes().put(STOPPED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis())); workspace.getAttributes().put(STOPPED_ABNORMALLY_ATTRIBUTE_NAME, Boolean.toString(false)); workspaceDao.update(workspace); } runtimes .stopAsync(workspace, options) .whenComplete( (aVoid, throwable) -> { if (workspace.isTemporary()) { removeWorkspaceQuietly(workspace.getId()); } }); }
Example #18
Source File: WorkspaceManager.java From che with Eclipse Public License 2.0 | 6 votes |
private WorkspaceImpl getByKey(String key) throws NotFoundException, ServerException { int lastColonIndex = key.indexOf(":"); int lastSlashIndex = key.lastIndexOf("/"); if (lastSlashIndex == -1 && lastColonIndex == -1) { // key is id return workspaceDao.get(key); } final String namespace; final String wsName; if (lastColonIndex == 0) { // no namespace, use current user namespace namespace = EnvironmentContext.getCurrent().getSubject().getUserName(); wsName = key.substring(1); } else if (lastColonIndex > 0) { wsName = key.substring(lastColonIndex + 1); namespace = key.substring(0, lastColonIndex); } else { namespace = key.substring(0, lastSlashIndex); wsName = key.substring(lastSlashIndex + 1); } return workspaceDao.get(wsName, namespace); }
Example #19
Source File: JpaWorkspaceDao.java From che with Eclipse Public License 2.0 | 6 votes |
@Override @Transactional public WorkspaceImpl get(String name, String namespace) throws NotFoundException, ServerException { requireNonNull(name, "Required non-null name"); requireNonNull(namespace, "Required non-null namespace"); try { return new WorkspaceImpl( managerProvider .get() .createNamedQuery("Workspace.getByName", WorkspaceImpl.class) .setParameter("namespace", namespace) .setParameter("name", name) .getSingleResult()); } catch (NoResultException noResEx) { throw new NotFoundException( format("Workspace with name '%s' in namespace '%s' doesn't exist", name, namespace)); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
Example #20
Source File: WorkspaceServiceTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldUpdateTheWorkspace() throws Exception { final WorkspaceImpl workspace = createWorkspace(createConfigDto()); when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace); when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace); final WorkspaceDto workspaceDto = asDto(workspace); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(workspaceDto) .when() .put(SECURE_PATH + "/workspace/" + workspace.getId()); assertEquals(response.getStatusCode(), 200); assertEquals( new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace); }
Example #21
Source File: MultiuserJpaWorkspaceDaoTest.java From che with Eclipse Public License 2.0 | 6 votes |
@BeforeMethod public void setUp() throws Exception { manager.getTransaction().begin(); manager.persist(account); for (UserImpl user : users) { manager.persist(user); } for (WorkspaceImpl ws : workspaces) { manager.persist(ws); } for (WorkerImpl worker : workers) { manager.persist(worker); } manager.getTransaction().commit(); manager.clear(); }
Example #22
Source File: WorkspaceServiceTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldUpdateCommand() throws Exception { final WorkspaceImpl workspace = createWorkspace(createConfigDto()); when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace); when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace); final CommandDto commandDto = createCommandDto(); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(commandDto) .when() .put( SECURE_PATH + "/workspace/" + workspace.getId() + "/command/" + commandDto.getName()); assertEquals(response.getStatusCode(), 200); verify(wsManager).updateWorkspace(any(), any()); }
Example #23
Source File: WorkspaceServiceTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldRespond404WhenUpdatingCommandWhichDoesNotExist() throws Exception { final WorkspaceImpl workspace = createWorkspace(createConfigDto()); when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(createCommandDto()) .when() .put(SECURE_PATH + "/workspace/" + workspace.getId() + "/command/fake"); assertEquals(response.getStatusCode(), 404); assertEquals( unwrapError(response), "Workspace '" + workspace.getId() + "' doesn't contain command 'fake'"); verify(wsManager, never()).updateWorkspace(any(), any()); }
Example #24
Source File: WorkspacePermissionsFilterTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldCheckPermissionsOnGetWorkspaceByUserNameAndWorkspaceName() throws Exception { when(subject.hasPermission("workspace", "workspace123", "read")).thenReturn(true); User storedUser = mock(User.class); when(storedUser.getId()).thenReturn("user123"); WorkspaceImpl workspace = mock(WorkspaceImpl.class); when(workspace.getId()).thenReturn("workspace123"); when(workspaceManager.getWorkspace("myWorkspace", "userok")).thenReturn(workspace); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .pathParam("key", "userok:myWorkspace") .contentType("application/json") .when() .get(SECURE_PATH + "/workspace/{key}"); assertEquals(response.getStatusCode(), 204); verify(workspaceService).getByKey(eq("userok:myWorkspace"), eq("false")); verify(subject).hasPermission(eq("workspace"), eq("workspace123"), eq("read")); }
Example #25
Source File: WorkspaceRuntimesTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldNotInjectRuntimeIfExceptionOccurredOnRuntimeFetching() throws Exception { // given RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace"); mockWorkspaceWithConfig(identity); when(statuses.get("workspace123")).thenReturn(WorkspaceStatus.STARTING); RuntimeContext context = mockContext(identity); ImmutableMap<String, Machine> machines = ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING)); when(context.getRuntime()) .thenReturn(new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING)); doThrow(new InfrastructureException("error")).when(infrastructure).prepare(eq(identity), any()); // when WorkspaceImpl workspace = new WorkspaceImpl(); workspace.setId("workspace123"); runtimes.injectRuntime(workspace); // then assertEquals(workspace.getStatus(), WorkspaceStatus.STOPPED); assertNull(workspace.getRuntime()); }
Example #26
Source File: WorkspaceServiceTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldReturnBadRequestOnInvalidDevfile() throws Exception { final DevfileDto devfileDto = createDevfileDto(); final WorkspaceImpl workspace = createWorkspace(devfileDto); when(wsManager.createWorkspace(any(Devfile.class), anyString(), any(), any())) .thenThrow(new ValidationException("boom")); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(devfileDto) .when() .post( SECURE_PATH + "/workspace/devfile" + "?namespace=test" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value"); assertEquals(response.getStatusCode(), 400); String error = unwrapError(response); assertEquals(error, "boom"); }
Example #27
Source File: RamResourceUsageTrackerTest.java From che with Eclipse Public License 2.0 | 6 votes |
/** Creates users workspace object based on the status and machines RAM. */ private static WorkspaceImpl createWorkspace(WorkspaceStatus status, Integer... machineRams) { final Map<String, MachineImpl> machines = new HashMap<>(machineRams.length - 1); final Map<String, MachineConfigImpl> machineConfigs = new HashMap<>(machineRams.length - 1); byte i = 1; for (Integer machineRam : machineRams) { final String machineName = "machine_" + i++; machines.put(machineName, createMachine(machineRam)); machineConfigs.put(machineName, createMachineConfig(machineRam)); } return WorkspaceImpl.builder() .setConfig( WorkspaceConfigImpl.builder() .setEnvironments( ImmutableBiMap.of(ACTIVE_ENV_NAME, new EnvironmentImpl(null, machineConfigs))) .build()) .setRuntime(new RuntimeImpl(ACTIVE_ENV_NAME, machines, null)) .setStatus(status) .build(); }
Example #28
Source File: WorkspaceServiceTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldDeleteCommand() throws Exception { final WorkspaceImpl workspace = createWorkspace(createConfigDto()); when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace); final int commandsSizeBefore = workspace.getConfig().getCommands().size(); final CommandImpl firstCommand = workspace.getConfig().getCommands().iterator().next(); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .when() .delete( SECURE_PATH + "/workspace/" + workspace.getId() + "/command/" + firstCommand.getName()); assertEquals(response.getStatusCode(), 204); assertEquals(workspace.getConfig().getCommands().size(), commandsSizeBefore - 1); verify(wsManager).updateWorkspace(any(), any()); }
Example #29
Source File: PreviewUrlLinksVariableGeneratorTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldAppendQueryParamsWhenDefinedInPreviewUrl() { Map<String, String> commandAttrs = new HashMap<>(); commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host"); CommandImpl command = new CommandImpl("run command", "a", "a", new PreviewUrlImpl(123, "?a=b"), commandAttrs); WorkspaceImpl workspace = createWorkspaceWithCommands(singletonList(command)); Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(workspace, uriBuilder); assertTrue(linkMap.values().iterator().next().endsWith("preview_url_host")); String linkKey = linkMap.keySet().iterator().next(); assertEquals( workspace .getRuntime() .getCommands() .get(0) .getAttributes() .get(Command.PREVIEW_URL_ATTRIBUTE), "${" + linkKey + "}?a=b"); }
Example #30
Source File: WorkspaceDaoTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test(dependsOnMethods = "shouldGetWorkspaceById") public void shouldNotRemoveWorkspaceWhenSubscriberThrowsExceptionOnWorkspaceRemoving() throws Exception { final WorkspaceImpl workspace = workspaces[0]; CascadeEventSubscriber<BeforeWorkspaceRemovedEvent> subscriber = mockCascadeEventSubscriber(); doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any()); eventService.subscribe(subscriber, BeforeWorkspaceRemovedEvent.class); try { workspaceDao.remove(workspace.getId()); fail("WorkspaceDao#remove had to throw server exception"); } catch (ServerException ignored) { } assertEquals(workspaceDao.get(workspace.getId()), workspace); eventService.unsubscribe(subscriber, BeforeWorkspaceRemovedEvent.class); }