Search in sources :

Example 1 with EnvironmentContext

use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.

the class DashboardRedirectionFilterTest method shouldRedirectIfRequestWithoutNamespace.

@Test(dataProvider = "nonNamespacePathProvider")
public void shouldRedirectIfRequestWithoutNamespace(String uri, String url) throws Exception {
    //given
    when(request.getMethod()).thenReturn("GET");
    when(request.getRequestURI()).thenReturn(uri);
    when(request.getRequestURL()).thenReturn(new StringBuffer(url));
    EnvironmentContext context = new EnvironmentContext();
    context.setSubject(new SubjectImpl("id123", "name", "token123", false));
    EnvironmentContext.setCurrent(context);
    //when
    filter.doFilter(request, response, chain);
    //then
    verify(response).sendRedirect(eq("/dashboard/"));
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Test(org.testng.annotations.Test)

Example 2 with EnvironmentContext

use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.

the class DefaultHttpJsonRequestTest method shouldUseTokenFromCurrentContextForAuthorization.

@Test
public void shouldUseTokenFromCurrentContextForAuthorization(ITestContext ctx) throws Exception {
    final EnvironmentContext context = new EnvironmentContext();
    context.setSubject(TEST_SUBJECT);
    EnvironmentContext.setCurrent(context);
    new DefaultHttpJsonRequest(getUrl(ctx) + "/token").usePostMethod().request();
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) Test(org.testng.annotations.Test)

Example 3 with EnvironmentContext

use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.

the class MachineProviderImplTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    when(dockerConnectorConfiguration.getDockerHostIp()).thenReturn("123.123.123.123");
    provider = spy(new MachineProviderBuilder().build());
    EnvironmentContext envCont = new EnvironmentContext();
    envCont.setSubject(new SubjectImpl(USER_NAME, "userId", USER_TOKEN, false));
    EnvironmentContext.setCurrent(envCont);
    when(recipeRetriever.getRecipe(any(MachineConfig.class))).thenReturn(new RecipeImpl().withType(DOCKER_FILE_TYPE).withScript("FROM codenvy"));
    when(dockerMachineFactory.createNode(anyString(), anyString())).thenReturn(dockerNode);
    when(dockerConnector.createContainer(any(CreateContainerParams.class))).thenReturn(new ContainerCreated(CONTAINER_ID, new String[0]));
    when(dockerConnector.inspectContainer(any(InspectContainerParams.class))).thenReturn(containerInfo);
    when(containerInfo.getState()).thenReturn(containerState);
    when(containerState.isRunning()).thenReturn(false);
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ContainerCreated(org.eclipse.che.plugin.docker.client.json.ContainerCreated) InspectContainerParams(org.eclipse.che.plugin.docker.client.params.InspectContainerParams) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with EnvironmentContext

use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.

the class CompletionJavadocTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    EnvironmentContext customEnvironment = mock(EnvironmentContext.class);
    doReturn(new SubjectImpl(vfsUser, "", "", false)).when(customEnvironment).getSubject();
    EnvironmentContext.setCurrent(customEnvironment);
    fJProject1 = Java18ProjectTestSetup.getProject();
    fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Before(org.junit.Before)

Example 5 with EnvironmentContext

use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.

the class WorkspaceManagerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    workspaceManager = new WorkspaceManager(workspaceDao, runtimes, eventService, accountManager, false, false, snapshotDao, sharedPool);
    when(accountManager.getByName(NAMESPACE)).thenReturn(new AccountImpl("accountId", NAMESPACE, "test"));
    when(accountManager.getByName(NAMESPACE_2)).thenReturn(new AccountImpl("accountId2", NAMESPACE_2, "test"));
    when(workspaceDao.create(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    when(workspaceDao.update(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    EnvironmentContext.setCurrent(new EnvironmentContext() {

        @Override
        public Subject getSubject() {
            return new SubjectImpl(NAMESPACE, USER_ID, "token", false);
        }
    });
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)8 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)5 BeforeMethod (org.testng.annotations.BeforeMethod)3 Subject (org.eclipse.che.commons.subject.Subject)2 Test (org.testng.annotations.Test)2 File (java.io.File)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 AccountImpl (org.eclipse.che.account.spi.AccountImpl)1 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)1 EventService (org.eclipse.che.api.core.notification.EventService)1 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)1 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)1 ContainerCreated (org.eclipse.che.plugin.docker.client.json.ContainerCreated)1 CreateContainerParams (org.eclipse.che.plugin.docker.client.params.CreateContainerParams)1 InspectContainerParams (org.eclipse.che.plugin.docker.client.params.InspectContainerParams)1 WSConnection (org.everrest.websockets.WSConnection)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1