use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.
the class CommandConverterTest method shouldAcceptActionWithReference.
@Test
public void shouldAcceptActionWithReference() throws Exception {
// given
CommandImpl devfileCommand = new CommandImpl();
devfileCommand.setName("build");
ActionImpl action = new ActionImpl();
action.setType("exec");
action.setReference("blah");
devfileCommand.getActions().add(action);
// when
Command command = commandConverter.toWorkspaceCommand(devfileCommand, fileURL -> "content");
// then
assertNull(command.getCommandLine());
assertEquals("blah", command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_ATTRIBUTE));
assertEquals("content", command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_CONTENT_ATTRIBUTE));
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.
the class PreviewUrlLinksVariableGeneratorTest method shouldUpdateCommandAndReturnLinkMapWhenPreviewUrlFound.
@Test
public void shouldUpdateCommandAndReturnLinkMapWhenPreviewUrlFound() {
Map<String, String> commandAttrs = new HashMap<>();
commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host");
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(123, null), commandAttrs);
WorkspaceImpl w = createWorkspaceWithCommands(Arrays.asList(command, new CommandImpl("b", "b", "b")));
Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(w, uriBuilder);
assertEquals(linkMap.size(), 1);
assertEquals(linkMap.values().iterator().next(), "http://preview_url_host");
String varKey = linkMap.keySet().iterator().next();
assertTrue(varKey.startsWith("previewurl/"));
Command aCommand = w.getRuntime().getCommands().stream().filter(c -> c.getName().equals("a")).findFirst().get();
assertTrue(aCommand.getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE).contains(varKey));
assertEquals(aCommand.getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), "${" + varKey + "}");
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.
the class CommandConverterTest method shouldAcceptActionWithCommand.
@Test
public void shouldAcceptActionWithCommand() throws Exception {
// given
CommandImpl devfileCommand = new CommandImpl();
devfileCommand.setName("build");
ActionImpl action = new ActionImpl();
action.setType("exec");
action.setCommand("blah");
devfileCommand.getActions().add(action);
// when
Command command = commandConverter.toWorkspaceCommand(devfileCommand, null);
// then
assertEquals(command.getCommandLine(), "blah");
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.
the class PreviewUrlLinksVariableGeneratorTest method shouldUpdateCommandAndReturnLinkMapWhenPreviewUrlFound.
@Test
public void shouldUpdateCommandAndReturnLinkMapWhenPreviewUrlFound() {
Map<String, String> commandAttrs = new HashMap<>();
commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host");
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(123, null), commandAttrs);
WorkspaceImpl w = createWorkspaceWithCommands(Arrays.asList(command, new CommandImpl("b", "b", "b")));
Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(w, uriBuilder);
assertEquals(linkMap.size(), 1);
assertEquals(linkMap.values().iterator().next(), "http://preview_url_host");
String varKey = linkMap.keySet().iterator().next();
assertTrue(varKey.startsWith("previewurl/"));
Command aCommand = w.getRuntime().getCommands().stream().filter(c -> c.getName().equals("a")).findFirst().get();
assertTrue(aCommand.getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE).contains(varKey));
assertEquals(aCommand.getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), "${" + varKey + "}");
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.
the class WorkspaceValidator method validateConfig.
/**
* Checks whether given workspace configuration object is in application valid state, so it
* provides enough data to be processed by internal components, and the data it provides is valid
* so consistency is not violated.
*
* @param config configuration to validate
* @throws ValidationException if any of validation constraints is violated
* @throws ServerException when any other error occurs during environment validation
*/
public void validateConfig(WorkspaceConfig config) throws ValidationException, ServerException {
// configuration object properties
checkNotNull(config.getName(), "Workspace name required");
check(WS_NAME.matcher(config.getName()).matches(), "Incorrect workspace name, it must be between 3 and 100 characters and may contain digits, " + "latin letters, underscores, dots, dashes and must start and end only with digits, " + "latin letters or underscores");
validateEnvironments(config);
// commands
for (Command command : config.getCommands()) {
check(!isNullOrEmpty(command.getName()), "Workspace %s contains command with null or empty name", config.getName());
check(!isNullOrEmpty(command.getCommandLine()) || !isNullOrEmpty(command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_CONTENT_ATTRIBUTE)), "Command line or content required for command '%s' in workspace '%s'.", command.getName(), config.getName());
}
}
Aggregations