use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.
the class FactoryServiceTest method shouldSaveFactoryWithImagesFromFormData.
@Test
public void shouldSaveFactoryWithImagesFromFormData() throws Exception {
final Factory factory = createFactory();
final FactoryDto factoryDto = asDto(factory, user);
when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
when(factoryManager.getById(FACTORY_ID)).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).multiPart("image", getImagePath().toFile(), FACTORY_IMAGE_MIME_TYPE).expect().statusCode(200).when().post(SERVICE_PATH);
final FactoryDto result = getFromResponse(response, FactoryDto.class);
final boolean found = result.getLinks().stream().anyMatch(link -> link.getRel().equals("image") && link.getProduces().equals(FACTORY_IMAGE_MIME_TYPE) && !link.getHref().isEmpty());
factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
assertEquals(result, factoryDto);
assertTrue(found);
}
use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.
the class FactoryServiceTest method shouldSaveFactoryWithImagesWhenImagesWithoutContent.
@Test
public void shouldSaveFactoryWithImagesWhenImagesWithoutContent() throws Exception {
final Factory factory = createFactory();
when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
final FactoryDto factoryDto = asDto(factory, user);
doReturn(factoryDto).when(factoryBuilderSpy).build(any(InputStream.class));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", DTO.toJson(factoryDto), APPLICATION_JSON).multiPart("image", File.createTempFile("img", ".jpeg"), "image/jpeg").expect().statusCode(200).when().post(SERVICE_PATH);
final FactoryDto result = getFromResponse(response, FactoryDto.class);
verify(factoryManager).saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class));
factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
assertEquals(result, factoryDto);
}
use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.
the class FactoryBaseValidatorTest method shouldValidateTrackedParamsIfOrgIdIsMissingButOnPremisesTrue.
@Test
public void shouldValidateTrackedParamsIfOrgIdIsMissingButOnPremisesTrue() throws Exception {
final DtoFactory dtoFactory = getInstance();
FactoryDto factory = dtoFactory.createDto(FactoryDto.class);
factory.withV("4.0").withPolicies(dtoFactory.createDto(PoliciesDto.class).withSince(System.currentTimeMillis() + 1_000_000).withUntil(System.currentTimeMillis() + 10_000_000).withReferer("codenvy.com"));
validator = new TesterFactoryBaseValidator();
}
use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.
the class FactoryBaseValidatorTest method shouldValidateOpenfileAction.
@Test
public void shouldValidateOpenfileAction() throws Exception {
//given
validator = new TesterFactoryBaseValidator();
Map<String, String> params = new HashMap<>();
params.put("file", "pom.xml");
List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("openFile").withProperties(params));
IdeDto ide = newDto(IdeDto.class).withOnProjectsLoaded(newDto(OnProjectsLoadedDto.class).withActions(actions));
FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
//when
validator.validateProjectActions(factoryWithAccountId);
}
use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.
the class FactoryBaseValidatorTest method shouldNotValidateIfrunCommandActionInsufficientParams.
@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateIfrunCommandActionInsufficientParams() throws Exception {
//given
validator = new TesterFactoryBaseValidator();
List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("openFile"));
IdeDto ide = newDto(IdeDto.class).withOnProjectsLoaded(newDto(OnProjectsLoadedDto.class).withActions(actions));
FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
//when
validator.validateProjectActions(factoryWithAccountId);
}
Aggregations