use of com.jayway.restassured.response.Response in project che by eclipse.
the class FactoryServiceTest method shouldNotThrowExceptionWhenRemoveNoExistingFactory.
@Test
public void shouldNotThrowExceptionWhenRemoveNoExistingFactory() throws Exception {
doNothing().when(factoryManager).removeFactory(FACTORY_ID);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).param("id", FACTORY_ID).when().delete(SERVICE_PATH + "/" + FACTORY_ID);
assertEquals(response.getStatusCode(), 204);
}
use of com.jayway.restassured.response.Response in project che by eclipse.
the class FactoryServiceTest method shouldReturnFactoryImageWithGivenName.
@Test
public void shouldReturnFactoryImageWithGivenName() throws Exception {
final byte[] imageContent = Files.readAllBytes(getImagePath());
final FactoryImage image = new FactoryImage(imageContent, FACTORY_IMAGE_MIME_TYPE, IMAGE_NAME);
when(factoryManager.getFactoryImages(FACTORY_ID, IMAGE_NAME)).thenReturn(ImmutableSet.of(image));
final Response response = given().when().expect().statusCode(200).get(SERVICE_PATH + "/" + FACTORY_ID + "/image?imgId=" + IMAGE_NAME);
assertEquals(response.getContentType(), FACTORY_IMAGE_MIME_TYPE);
assertEquals(response.getHeader("content-length"), String.valueOf(imageContent.length));
assertEquals(response.asByteArray(), imageContent);
}
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");
}
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);
}
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));
}
Aggregations