Search in sources :

Example 1 with IdeActionDto

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);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 2 with IdeActionDto

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);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 3 with IdeActionDto

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;
            }
        }
    }
}
Also used : OnAppLoadedDto(org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) ArrayList(java.util.ArrayList) BadRequestException(org.eclipse.che.api.core.BadRequestException) OnProjectsLoadedDto(org.eclipse.che.api.factory.shared.dto.OnProjectsLoadedDto)

Example 4 with IdeActionDto

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);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) HashMap(java.util.HashMap) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 5 with IdeActionDto

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);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Aggregations

IdeActionDto (org.eclipse.che.api.factory.shared.dto.IdeActionDto)9 IdeDto (org.eclipse.che.api.factory.shared.dto.IdeDto)9 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)8 Test (org.testng.annotations.Test)8 HashMap (java.util.HashMap)3 OnAppLoadedDto (org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto)2 ArrayList (java.util.ArrayList)1 BadRequestException (org.eclipse.che.api.core.BadRequestException)1 OnProjectsLoadedDto (org.eclipse.che.api.factory.shared.dto.OnProjectsLoadedDto)1