Search in sources :

Example 31 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class OAuthAuthenticationServiceTest method shouldThrowExceptionIfNoSuchProviderFound.

@Test
public void shouldThrowExceptionIfNoSuchProviderFound() throws Exception {
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().queryParam("oauth_provider", "unknown").get(SECURE_PATH + "/oauth/token");
    assertEquals(response.getStatusCode(), 400);
    assertEquals(DtoFactory.getInstance().createDtoFromJson(response.getBody().asInputStream(), ServiceError.class).getMessage(), "Unsupported OAuth provider unknown");
}
Also used : Response(com.jayway.restassured.response.Response) Test(org.testng.annotations.Test)

Example 32 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class OAuthAuthenticationServiceTest method shouldBeAbleToGetUserToken.

@Test
public void shouldBeAbleToGetUserToken() throws Exception {
    String provider = "myprovider";
    String token = "token123";
    OAuthAuthenticator authenticator = mock(OAuthAuthenticator.class);
    when(providers.getAuthenticator(eq(provider))).thenReturn(authenticator);
    when(authenticator.getToken(anyString())).thenReturn(newDto(OAuthToken.class).withToken(token));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().queryParam("oauth_provider", provider).get(SECURE_PATH + "/oauth/token");
    assertEquals(response.getStatusCode(), 200);
    assertEquals(DtoFactory.getInstance().createDtoFromJson(response.getBody().asInputStream(), OAuthToken.class).getToken(), token);
}
Also used : Response(com.jayway.restassured.response.Response) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 33 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class WorkspaceServiceTest method shouldNotRestoreWorkspace.

@Test
public void shouldNotRestoreWorkspace() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.startWorkspace(any(), any(), any())).thenReturn(workspace);
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().post(SECURE_PATH + "/workspace/" + workspace.getId() + "/runtime" + "?environment=" + workspace.getConfig().getDefaultEnv() + "&restore=false");
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
    verify(wsManager).startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 34 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class WorkspaceServiceTest method shouldUpdateProject.

@Test
public void shouldUpdateProject() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
    final ProjectConfigDto projectDto = createProjectDto();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(projectDto).when().put(SECURE_PATH + "/workspace/" + workspace.getId() + "/project" + projectDto.getPath());
    assertEquals(response.getStatusCode(), 200);
    verify(validator).validateConfig(workspace.getConfig());
    verify(wsManager).updateWorkspace(any(), any());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Test(org.testng.annotations.Test)

Example 35 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class WorkspaceServiceTest method shouldRelativizeLinksOnCreateWorkspace.

@Test
public void shouldRelativizeLinksOnCreateWorkspace() throws Exception {
    final String initialLocation = "http://localhost:8080/api/recipe/idrecipe123456789/script";
    final WorkspaceConfigDto configDto = createConfigDto();
    configDto.getEnvironments().get(configDto.getDefaultEnv()).getRecipe().withLocation(initialLocation).withType("dockerfile");
    ArgumentCaptor<WorkspaceConfigDto> captor = ArgumentCaptor.forClass(WorkspaceConfigDto.class);
    when(wsManager.createWorkspace(captor.capture(), any(), any())).thenAnswer(invocation -> createWorkspace(captor.getValue()));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(configDto).when().post(SECURE_PATH + "/workspace" + "?namespace=test" + "&attribute=stackId:stack123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 201);
    String savedLocation = unwrapDto(response, WorkspaceDto.class).getConfig().getEnvironments().get(configDto.getDefaultEnv()).getRecipe().getLocation();
    assertEquals(savedLocation, initialLocation.substring(API_ENDPOINT.length()));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Aggregations

Response (com.jayway.restassured.response.Response)214 Test (org.testng.annotations.Test)129 Test (org.junit.Test)73 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)35 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)31 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)27 Matchers.anyString (org.mockito.Matchers.anyString)21 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)19 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)15 IOException (java.io.IOException)14 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 XPathExpressionException (javax.xml.xpath.XPathExpressionException)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Factory (org.eclipse.che.api.core.model.factory.Factory)11 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)11 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)11 DtoFactory (org.eclipse.che.dto.server.DtoFactory)11 Matchers.containsString (org.hamcrest.Matchers.containsString)10 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)9