CommandConverter { public CommandImpl toDevfileCommand( org.eclipse.che.api.workspace.server.model.impl.CommandImpl command) throws WorkspaceExportException { String componentName = command.getAttributes().remove(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE); if (componentName == null) { throw new WorkspaceExportException( format( "Command `%s` has no specified component where it should be run", command.getName())); } CommandImpl devCommand = new CommandImpl(); devCommand.setName(command.getName()); ActionImpl action = new ActionImpl(); action.setCommand(command.getCommandLine()); action.setType(command.getType()); action.setWorkdir(command.getAttributes().remove(WORKING_DIRECTORY_ATTRIBUTE)); action.setComponent(componentName); action.setType(Constants.EXEC_ACTION_TYPE); devCommand.getActions().add(action); devCommand.setAttributes(command.getAttributes()); return devCommand; }  CommandImpl toDevfileCommand(
      org.eclipse.che.api.workspace.server.model.impl.CommandImpl command); org.eclipse.che.api.workspace.server.model.impl.CommandImpl toWorkspaceCommand(
      Command devfileCommand, FileContentProvider fileContentProvider);  }
@Test public void shouldConvertWorkspaceCommandToDevfileCommand() throws Exception { 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"); CommandImpl devfileCommand = commandConverter.toDevfileCommand(workspaceCommand); 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); }
@Test( expectedExceptions = WorkspaceExportException.class, expectedExceptionsMessageRegExp = "Command `build` has no specified component where it should be run") public void shouldThrowAnExceptionIfWorkspaceCommandDoesNotHaveComponentNameAttribute() throws Exception { 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"); commandConverter.toDevfileCommand(workspaceCommand); }