use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.
the class FactoryServiceTest method shouldReturnFactoryByIdentifierWithoutValidation.
@Test
public void shouldReturnFactoryByIdentifierWithoutValidation() throws Exception {
final Factory factory = createFactory();
final FactoryDto factoryDto = asDto(factory, user);
when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
when(factoryManager.getFactoryImages(FACTORY_ID)).thenReturn(emptySet());
final Response response = given().when().expect().statusCode(200).get(SERVICE_PATH + "/" + FACTORY_ID);
assertEquals(getFromResponse(response, FactoryDto.class).withLinks(emptyList()), factoryDto);
}
use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.
the class FactoryServiceTest method shouldThrowNotFoundExceptionWhenUpdatingNonExistingFactory.
@Test
public void shouldThrowNotFoundExceptionWhenUpdatingNonExistingFactory() throws Exception {
final Factory factory = createFactoryWithStorage(FACTORY_NAME, "git", "https://github.com/codenvy/platform-api.git");
doThrow(new NotFoundException(format("Factory with id %s is not found.", FACTORY_ID))).when(factoryManager).getById(anyString());
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(JsonHelper.toJson(factory)).when().put(SERVICE_PATH + "/" + FACTORY_ID);
assertEquals(response.getStatusCode(), 404);
assertEquals(DTO.createDtoFromJson(response.getBody().asString(), ServiceError.class).getMessage(), format("Factory with id %s is not found.", FACTORY_ID));
}
use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.
the class FactoryServiceTest method shouldSaveFactoryFromFormDataWithoutImages.
@Test
public void shouldSaveFactoryFromFormDataWithoutImages() throws Exception {
final Factory factory = createFactory();
final FactoryDto factoryDto = asDto(factory, user);
when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
doReturn(factoryDto).when(factoryBuilderSpy).build(any(InputStream.class));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", JsonHelper.toJson(factoryDto), APPLICATION_JSON).expect().statusCode(200).when().post(SERVICE_PATH);
final FactoryDto result = getFromResponse(response, FactoryDto.class);
factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
assertEquals(result, factoryDto);
}
use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.
the class FactoryServiceTest method shouldReturnFactoryListByCreatorAttribute.
@Test
public void shouldReturnFactoryListByCreatorAttribute() throws Exception {
final Factory factory1 = createNamedFactory("factory1");
final Factory factory2 = createNamedFactory("factory2");
when(factoryManager.getByAttribute(2, 0, ImmutableList.of(Pair.of("factory.creator.name", user.getName())))).thenReturn(ImmutableList.of(factory1, factory2));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).when().expect().statusCode(200).get(SERVICE_PATH + "/find?maxItems=2&skipCount=0&factory.creator.name=" + user.getName());
final Set<FactoryDto> res = unwrapDtoList(response, FactoryDto.class).stream().map(f -> f.withLinks(emptyList())).collect(toSet());
assertEquals(res.size(), 2);
assertTrue(res.containsAll(ImmutableList.of(asDto(factory1, user), asDto(factory2, user))));
}
use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.
the class FactoryServiceTest method shouldBeAbleToRemoveFactory.
/**
* Checks that the user can remove an existing factory
*/
@Test
public void shouldBeAbleToRemoveFactory() throws Exception {
final Factory factory = createFactory();
when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
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);
// check there was a call on the remove operation with expected ID
verify(factoryManager).removeFactory(FACTORY_ID);
}
Aggregations