How to use CerberusCommand class of org.cerberus.service.cerberuscommand.impl package

Best Cerberus-source code snippet using org.cerberus.service.cerberuscommand.impl.CerberusCommand

Source:CerberusCommand.java Github

copy

Full Screen

...27import org.cerberus.engine.entity.MessageEvent;28import org.cerberus.engine.gwt.impl.ActionService;29import org.cerberus.enums.MessageEventEnum;30import org.cerberus.exception.CerberusEventException;31import org.cerberus.service.cerberuscommand.ICerberusCommand;32import org.springframework.beans.factory.annotation.Autowired;33import org.springframework.stereotype.Service;34/**35 *36 * @author mlombard37 */38@Service("CerberusCommand")39public class CerberusCommand implements ICerberusCommand {40 /**41 * Associated {@link Logger} to this class42 */43 private static final org.apache.logging.log4j.Logger LOG = LogManager.getLogger(ActionService.class);44 private MessageEvent message;45 private String scriptPath;46 private String scriptUser;47 private String scriptPassword;48 private String newMessageDescription;49 private String messageDescriptionToReplace;50 private String[] commandToRun;51 private String command;52 @Autowired53 private IParameterService parameterService;54 /**55 * This method can be used in order to execute a script that is located on56 * the application server.57 *58 * @param command script file name (with extention)59 *60 * @return61 * @throws org.cerberus.exception.CerberusEventException62 */63 @Override64 public MessageEvent executeCerberusCommand(String command) throws CerberusEventException {65 this.command = command;66 try {67 checkCommandContent();68 checkOS();69 initializeParameters();70 checkPathParameterNotEmpty();71 checkPasswordParameterNotEmpty();72 checkUserParameterNotEmpty();73 checkCommandFirstCharacter();74 concatenateCommandToRun();75 executeProcessBuilder();76 } catch (CerberusEventException ex) {77 this.message = ex.getMessageError();78 checkNewMessageDescription();79 throw new CerberusEventException(this.message);80 }81 return this.message;82 }83 private void checkCommandContent() throws CerberusEventException {84 if (this.command.isEmpty()) {85 this.messageDescriptionToReplace = "%FIELD%";86 this.newMessageDescription = "Command";87 throw new CerberusEventException(new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND_MISSINGCOMMAND));88 }89 }90 private void checkOS() throws CerberusEventException {91 if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {92 this.messageDescriptionToReplace = "%OS%";93 this.newMessageDescription = System.getProperty("os.name");94 throw new CerberusEventException(new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND_NOTSUPPORTED_FOR_OS));95 }96 }97 private void initializeParameters() {98 this.scriptPath = parameterService.getParameterStringByKey("cerberus_executeCerberusCommand_path", "", "");99 this.scriptUser = parameterService.getParameterStringByKey("cerberus_executeCerberusCommand_user", "", "");100 this.scriptPassword = parameterService.getParameterStringByKey("cerberus_executeCerberusCommand_password", "", "");101 }102 private void checkPathParameterNotEmpty() throws CerberusEventException {103 if (this.scriptPath.isEmpty()) {104 this.messageDescriptionToReplace = "%PARAM%";105 this.newMessageDescription = "cerberus_executeCerberusCommand_path";106 throw new CerberusEventException(new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND_MISSINGPARAMETER));107 }108 }109 private void checkPasswordParameterNotEmpty() throws CerberusEventException {110 if (this.scriptPassword.isEmpty()) {111 this.messageDescriptionToReplace = "%PARAM%";112 this.newMessageDescription = "cerberus_executeCerberusCommand_password";113 throw new CerberusEventException(new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND_MISSINGPARAMETER));114 }115 }116 private void checkUserParameterNotEmpty() throws CerberusEventException {117 if (this.scriptUser.isEmpty()) {118 this.messageDescriptionToReplace = "%PARAM%";119 this.newMessageDescription = "cerberus_executeCerberusCommand_user";120 throw new CerberusEventException(new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND_MISSINGPARAMETER));121 }122 }123 private void checkCommandFirstCharacter() throws CerberusEventException {124 String firstChar = Character.toString(this.command.charAt(0));125 if (firstChar.equalsIgnoreCase("/")) {126 this.messageDescriptionToReplace = "%FIRST_CHAR%";127 this.newMessageDescription = firstChar;128 throw new CerberusEventException(new MessageEvent(MessageEventEnum.ACTION_FAILED_EXECUTECOMMAND_ILLEGALSTART));129 }130 }131 private void concatenateCommandToRun() {132 this.commandToRun = new String[]{"bash", "-c", "echo -n \""133 + this.scriptPassword...

Full Screen

Full Screen

CerberusCommand

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.cerberuscommand.impl.CerberusCommand;2import org.cerberus.service.cerberuscommand.impl.CerberusCommandService;3import org.cerberus.service.cerberuscommand.impl.CommandResult;4import org.cerberus.service.cerberuscommand.impl.CerberusCommandFactory;5import org.cerberus.service.cerberuscommand.impl.CerberusCommandFactoryService;6import org.cerberus.service.cerberuscommand.impl.CerberusCommandType;7import org.cerberus.service.cerberuscommand.impl.CerberusCommandTypeEnum;8import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroup;9import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupService;10import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupFactory;11import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupFactoryService;12import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupType;13import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupTypeEnum;14import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupList;15import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListService;16import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListFactory;17import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListFactoryService;18import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListType;19import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListTypeEnum;20import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListMap;21import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListMapService;22import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroupListMapFactory;23import org.cerberus.service.cerberuscommand.impl.CerberusCommandGroup

Full Screen

Full Screen

CerberusCommand

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.cerberuscommand.impl.CerberusCommand;2import org.cerberus.service.cerberuscommand.impl.CerberusCommandResult;3CerberusCommand cerberusCommand = new CerberusCommand();4CerberusCommandResult cerberusCommandResult = new CerberusCommandResult();5cerberusCommandResult = cerberusCommand.executeCommand("ls -l");6System.out.println(cerberusCommandResult.getOutput());7System.out.println(cerberusCommandResult.getError());8System.out.println(cerberusCommandResult.getReturnCode());9System.out.println(cerberusCommandResult.getExecutionTime());10System.out.println(cerberusCommandResult.getExecutionTimeInSeconds());11System.out.println(cerberusCommandResult.getExecutionTimeInMilliseconds());12System.out.println(cerberusCommandResult.getExecutionTimeInMicroseconds());13System.out.println(cerberusCommandResult.getExecutionTimeInNanoseconds());14System.out.println(cerberusCommandResult.getExecutionTimeInHours());15System.out.println(cerberusCommandResult.getExecutionTimeInMinutes());16System.out.println(cerberusCommandResult.getExecutionTimeInDays());17System.out.println(cerberusCommandResult.getExecutionTimeInWeeks());18System.out.println(cerberusCommandResult.getExecutionTimeInYears());19System.out.println(cerberusCommandResult.getExecutionTimeInDecades());20System.out.println(cerberusCommandResult.getExecutionTimeInCenturies());21System.out.println(cerberusCommandResult.getExecutionTimeInMillenia());

Full Screen

Full Screen

CerberusCommand

Using AI Code Generation

copy

Full Screen

1CerberusCommand cerberusCommand = new CerberusCommand();2cerberusCommand.setCommand("echo");3cerberusCommand.setArguments(new String[]{"Hello World"});4cerberusCommand.setCommandTimeout(10000);5cerberusCommand.setEnvironmentVariables(new String[]{"PATH=/bin:/usr/bin"});6cerberusCommand.setWorkingDirectory("/tmp");7cerberusCommand.setRedirectErrorStream(true);8cerberusCommand.setCharset("UTF-8");9cerberusCommand.execute();10String output = cerberusCommand.getOutput();11String errorOutput = cerberusCommand.getErrorOutput();12int exitValue = cerberusCommand.getExitValue();13boolean status = cerberusCommand.getStatus();14long executionTime = cerberusCommand.getExecutionTime();15Date executionDate = cerberusCommand.getExecutionDate();16Date executionDate = cerberusCommand.getExecutionDate();17String executionOutput = cerberusCommand.getExecutionOutput();18String executionErrorOutput = cerberusCommand.getExecutionErrorOutput();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful