Search in sources :

Example 26 with CommandImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl in project devspaces-images by redhat-developer.

the class CommandConverterTest method shouldConvertWorkspaceCommandToDevfileCommand.

@Test
public void shouldConvertWorkspaceCommandToDevfileCommand() throws Exception {
    // given
    org.eclipse.che.api.workspace.server.model.impl.CommandImpl workspaceCommand = new org.eclipse.che.api.workspace.server.model.impl.CommandImpl("build", "mvn clean install", "custom");
    workspaceCommand.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "dockerimageComponent");
    workspaceCommand.getAttributes().put(WORKING_DIRECTORY_ATTRIBUTE, "/tmp");
    workspaceCommand.getAttributes().put("anotherAttribute", "value");
    // when
    CommandImpl devfileCommand = commandConverter.toDevfileCommand(workspaceCommand);
    // then
    assertEquals(devfileCommand.getName(), "build");
    assertEquals(devfileCommand.getActions().size(), 1);
    assertEquals(devfileCommand.getAttributes().size(), 1);
    assertEquals(devfileCommand.getAttributes().get("anotherAttribute"), "value");
    ActionImpl action = devfileCommand.getActions().get(0);
    assertEquals(action.getComponent(), "dockerimageComponent");
    assertEquals(action.getWorkdir(), "/tmp");
    assertEquals(action.getCommand(), "mvn clean install");
    assertEquals(action.getType(), EXEC_ACTION_TYPE);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) Test(org.testng.annotations.Test)

Example 27 with CommandImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl in project devspaces-images by redhat-developer.

the class CommandConverterTest method shouldAcceptActionWithReferenceContent.

@Test
public void shouldAcceptActionWithReferenceContent() throws Exception {
    // given
    CommandImpl devfileCommand = new CommandImpl();
    devfileCommand.setName("build");
    ActionImpl action = new ActionImpl();
    action.setType("exec");
    action.setReference("blah");
    action.setReferenceContent("content");
    devfileCommand.getActions().add(action);
    // when
    Command command = commandConverter.toWorkspaceCommand(devfileCommand, null);
    // 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));
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) Test(org.testng.annotations.Test)

Example 28 with CommandImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl in project devspaces-images by redhat-developer.

the class CommandConverterTest method shouldConvertDevfileCommandToWorkspaceCommands.

@Test
public void shouldConvertDevfileCommandToWorkspaceCommands() throws Exception {
    // given
    CommandImpl devfileCommand = new CommandImpl();
    devfileCommand.setName("build");
    devfileCommand.setAttributes(ImmutableMap.of("attr", "value"));
    ActionImpl action = new ActionImpl();
    action.setComponent("dockerimageComponent");
    action.setType(EXEC_ACTION_TYPE);
    action.setWorkdir("/tmp");
    action.setCommand("mvn clean install");
    devfileCommand.getActions().add(action);
    // when
    org.eclipse.che.api.workspace.server.model.impl.CommandImpl workspaceCommand = commandConverter.toWorkspaceCommand(devfileCommand, null);
    // then
    assertEquals(workspaceCommand.getName(), "build");
    assertEquals(workspaceCommand.getType(), EXEC_ACTION_TYPE);
    assertEquals(workspaceCommand.getAttributes().size(), 3);
    assertEquals(workspaceCommand.getAttributes().get("attr"), "value");
    assertEquals(workspaceCommand.getAttributes().get(WORKING_DIRECTORY_ATTRIBUTE), "/tmp");
    assertEquals(workspaceCommand.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE), "dockerimageComponent");
    assertEquals(workspaceCommand.getCommandLine(), "mvn clean install");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) Test(org.testng.annotations.Test)

Example 29 with CommandImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl in project devspaces-images by redhat-developer.

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));
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) Test(org.testng.annotations.Test)

Example 30 with CommandImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl in project devspaces-images by redhat-developer.

the class DevfileIntegrityValidatorTest method shouldThrowExceptionOnDuplicateCommandName.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate command name found:'build'")
public void shouldThrowExceptionOnDuplicateCommandName() throws Exception {
    DevfileImpl broken = new DevfileImpl(initialDevfile);
    CommandImpl command = new CommandImpl();
    command.setName(initialDevfile.getCommands().get(0).getName());
    broken.getCommands().add(command);
    // when
    integrityValidator.validateDevfile(broken);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Test(org.testng.annotations.Test)

Aggregations

CommandImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl)30 ActionImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl)26 Test (org.testng.annotations.Test)22 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)14 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)10 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)8 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)8 MetadataImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl)8 ProjectImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl)8 SourceImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.SourceImpl)8 Command (org.eclipse.che.api.core.model.workspace.config.Command)6 EntrypointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl)6 EnvImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl)6 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)2 WorkspaceExportException (org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException)2 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)2