Search in sources :

Example 6 with Response

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

the class FactoryServiceTest method shouldThrowBadRequestExceptionWhenInvalidFactorySectionProvided.

@Test
public void shouldThrowBadRequestExceptionWhenInvalidFactorySectionProvided() throws Exception {
    doThrow(new JsonSyntaxException("Invalid json")).when(factoryBuilderSpy).build(any(InputStream.class));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", "invalid content", FACTORY_IMAGE_MIME_TYPE).expect().statusCode(400).when().post(SERVICE_PATH);
    final ServiceError err = getFromResponse(response, ServiceError.class);
    assertEquals(err.getMessage(), "Invalid JSON value of the field 'factory' provided");
}
Also used : Response(com.jayway.restassured.response.Response) ServiceError(org.eclipse.che.api.core.rest.shared.dto.ServiceError) JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStream(java.io.InputStream) Test(org.testng.annotations.Test)

Example 7 with Response

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

the class FactoryServiceTest method shouldGenerateFactoryJsonIncludeGivenProjects.

@Test
public void shouldGenerateFactoryJsonIncludeGivenProjects() throws Exception {
    // given
    final String wsId = "workspace123234";
    WorkspaceImpl.WorkspaceImplBuilder ws = WorkspaceImpl.builder();
    WorkspaceConfigImpl.WorkspaceConfigImplBuilder wsConfig = WorkspaceConfigImpl.builder();
    ws.setId(wsId);
    wsConfig.setProjects(Arrays.asList(DTO.createDto(ProjectConfigDto.class).withPath("/proj1").withSource(DTO.createDto(SourceStorageDto.class).withType("git").withLocation("location")), DTO.createDto(ProjectConfigDto.class).withPath("/proj2").withSource(DTO.createDto(SourceStorageDto.class).withType("git").withLocation("location"))));
    wsConfig.setName("wsname");
    wsConfig.setEnvironments(singletonMap("env1", DTO.createDto(EnvironmentDto.class)));
    wsConfig.setDefaultEnv("env1");
    ws.setStatus(WorkspaceStatus.RUNNING);
    wsConfig.setCommands(singletonList(DTO.createDto(CommandDto.class).withName("MCI").withType("mvn").withCommandLine("clean install")));
    ws.setConfig(wsConfig.build());
    WorkspaceImpl usersWorkspace = ws.build();
    when(workspaceManager.getWorkspace(eq(wsId))).thenReturn(usersWorkspace);
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get("/private" + SERVICE_PATH + "/workspace/" + wsId);
    // then
    assertEquals(response.getStatusCode(), 200);
    FactoryDto result = DTO.createDtoFromJson(response.getBody().asString(), FactoryDto.class);
    assertEquals(result.getWorkspace().getProjects().size(), 2);
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 8 with Response

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

the class FactoryServiceTest method shouldBeAbleToUpdateFactory.

@Test
public void shouldBeAbleToUpdateFactory() throws Exception {
    final Factory existed = createFactory();
    final Factory update = createFactoryWithStorage(null, "git", "https://github.com/codenvy/platform-api1.git");
    when(factoryManager.getById(FACTORY_ID)).thenReturn(existed);
    when(factoryManager.updateFactory(any())).thenReturn(update);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(JsonHelper.toJson(asDto(existed, user))).when().expect().statusCode(200).put(SERVICE_PATH + "/" + FACTORY_ID);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    verify(factoryManager, times(1)).updateFactory(any());
    assertEquals(result.withLinks(emptyList()), asDto(update, user));
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 9 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 10 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)

Aggregations

Response (com.jayway.restassured.response.Response)169 Test (org.testng.annotations.Test)129 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)35 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)31 Test (org.junit.Test)31 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 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 InputStream (java.io.InputStream)6