use of org.eclipse.che.api.factory.shared.dto.IdeActionDto in project che by eclipse.
the class FactoryBaseValidatorTest method shouldNotValidateOpenfileActionIfInWrongSectionOnAppClosed.
@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateOpenfileActionIfInWrongSectionOnAppClosed() throws Exception {
//given
validator = new TesterFactoryBaseValidator();
List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("openFile"));
IdeDto ide = newDto(IdeDto.class).withOnAppClosed(newDto(OnAppClosedDto.class).withActions(actions));
FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
//when
validator.validateProjectActions(factoryWithAccountId);
}
use of org.eclipse.che.api.factory.shared.dto.IdeActionDto in project che by eclipse.
the class FactoryBaseValidatorTest method shouldNotValidateFindReplaceActionIfInWrongSectionOnAppLoaded.
@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateFindReplaceActionIfInWrongSectionOnAppLoaded() throws Exception {
//given
validator = new TesterFactoryBaseValidator();
List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("findReplace"));
IdeDto ide = newDto(IdeDto.class).withOnAppLoaded(newDto(OnAppLoadedDto.class).withActions(actions));
FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
//when
validator.validateProjectActions(factoryWithAccountId);
}
use of org.eclipse.che.api.factory.shared.dto.IdeActionDto in project che by eclipse.
the class FactoryBaseValidator method validateProjectActions.
/**
* Validates IDE actions
*
* @param factory
* factory to validate
* @throws BadRequestException
* when factory actions is invalid
*/
protected void validateProjectActions(FactoryDto factory) throws BadRequestException {
final IdeDto ide = factory.getIde();
if (ide == null) {
return;
}
final List<IdeActionDto> applicationActions = new ArrayList<>();
if (ide.getOnAppClosed() != null) {
applicationActions.addAll(ide.getOnAppClosed().getActions());
}
if (ide.getOnAppLoaded() != null) {
applicationActions.addAll(ide.getOnAppLoaded().getActions());
}
for (IdeActionDto applicationAction : applicationActions) {
String id = applicationAction.getId();
if ("openFile".equals(id) || "findReplace".equals(id) || "runCommand".equals(id) || "newTerminal".equals(id)) {
throw new BadRequestException(format(FactoryConstants.INVALID_ACTION_SECTION, id));
}
}
final OnAppLoadedDto onAppLoaded = ide.getOnAppLoaded();
if (onAppLoaded != null) {
for (IdeActionDto action : onAppLoaded.getActions()) {
final Map<String, String> properties = action.getProperties();
if ("openWelcomePage".equals(action.getId()) && isNullOrEmpty(properties.get("greetingContentUrl"))) {
throw new BadRequestException(FactoryConstants.INVALID_WELCOME_PAGE_ACTION);
}
}
}
final OnProjectsLoadedDto onLoaded = ide.getOnProjectsLoaded();
if (onLoaded != null) {
final List<IdeActionDto> onProjectOpenedActions = onLoaded.getActions();
for (IdeActionDto applicationAction : onProjectOpenedActions) {
final String id = applicationAction.getId();
final Map<String, String> properties = applicationAction.getProperties();
switch(id) {
case "openFile":
if (isNullOrEmpty(properties.get("file"))) {
throw new BadRequestException(FactoryConstants.INVALID_OPENFILE_ACTION);
}
break;
case "runCommand":
if (isNullOrEmpty(properties.get("name"))) {
throw new BadRequestException(FactoryConstants.INVALID_RUNCOMMAND_ACTION);
}
break;
case "findReplace":
if (isNullOrEmpty(properties.get("in")) || isNullOrEmpty(properties.get("find")) || isNullOrEmpty(properties.get("replace"))) {
throw new BadRequestException(FactoryConstants.INVALID_FIND_REPLACE_ACTION);
}
break;
}
}
}
}
use of org.eclipse.che.api.factory.shared.dto.IdeActionDto 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.IdeActionDto 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