WorkspaceNameEnvVarProvider implements EnvVarProvider { @Override public Pair<String, String> get(RuntimeIdentity runtimeIdentity) throws InfrastructureException { try { WorkspaceImpl workspace = workspaceDao.get(runtimeIdentity.getWorkspaceId()); return Pair.of(CHE_WORKSPACE_NAME, workspace.getName()); } catch (NotFoundException | ServerException e) { throw new InfrastructureException( "Not able to get workspace name for workspace with id " + runtimeIdentity.getWorkspaceId(), e); } } @Inject  WorkspaceNameEnvVarProvider(WorkspaceDao workspaceDao); @Override Pair<String, String> get(RuntimeIdentity runtimeIdentity); static final String CHE_WORKSPACE_NAME; }
@Test public void shouldReturnNameVar() throws NotFoundException, ServerException, InfrastructureException { when(runtimeIdentity.getWorkspaceId()).thenReturn("ws-id111"); doReturn(workspace).when(workspaceDao).get(Mockito.eq("ws-id111")); when(workspace.getName()).thenReturn("ws-name"); Pair<String, String> actual = provider.get(runtimeIdentity); assertEquals(actual.first, WorkspaceNameEnvVarProvider.CHE_WORKSPACE_NAME); assertEquals(actual.second, "ws-name"); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Not able to get workspace name for workspace with id ws-id111") public void shouldWrapNotFoundExceptionException() throws NotFoundException, ServerException, InfrastructureException { when(runtimeIdentity.getWorkspaceId()).thenReturn("ws-id111"); doThrow(new NotFoundException("Some message")).when(workspaceDao).get(Mockito.eq("ws-id111")); provider.get(runtimeIdentity); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Not able to get workspace name for workspace with id ws-id111") public void shouldWrapServerExceptionException() throws NotFoundException, ServerException, InfrastructureException { when(runtimeIdentity.getWorkspaceId()).thenReturn("ws-id111"); doThrow(new ServerException("Some message")).when(workspaceDao).get(Mockito.eq("ws-id111")); provider.get(runtimeIdentity); }