How to use ZooExecuteAction method of com.consol.citrus.zookeeper.actions.ZooExecuteAction class

Best Citrus code snippet using com.consol.citrus.zookeeper.actions.ZooExecuteAction.ZooExecuteAction

Source:ZooExecuteAction.java Github

copy

Full Screen

...43 *44 * @author Martin Maher45 * @since 2.546 */47public class ZooExecuteAction extends AbstractTestAction {48 @Autowired(required = false)49 @Qualifier("zookeeperClient")50 /** Zookeeper client instance */51 private ZooClient zookeeperClient = new ZooClient();52 /**53 * Zookeeper command to execute54 */55 private ZooCommand command;56 /**57 * Expected command result for validation58 */59 private String expectedCommandResult;60 @Autowired(required = false)61 @Qualifier("zookeeperCommandResultMapper")62 /** JSON data binding */63 private ObjectMapper jsonMapper = new ObjectMapper();64 @Autowired65 private JsonTextMessageValidator jsonTextMessageValidator = new JsonTextMessageValidator();66 @Autowired67 private JsonPathMessageValidator jsonPathMessageValidator = new JsonPathMessageValidator();68 /**69 * An optional validation contextst containing json path validators to validate the command result70 */71 private JsonPathMessageValidationContext jsonPathMessageValidationContext;72 /**73 * List of variable extractors responsible for creating variables from received message content74 */75 private List<VariableExtractor> variableExtractors = new ArrayList<VariableExtractor>();76 /**77 * Logger78 */79 private static Logger log = LoggerFactory.getLogger(ZooExecuteAction.class);80 /**81 * Default constructor.82 */83 public ZooExecuteAction() {84 setName("zookeeper-execute");85 }86 @Override87 public void doExecute(TestContext context) {88 try {89 if (log.isDebugEnabled()) {90 log.debug(String.format("Executing zookeeper command '%s'", command.getName()));91 }92 command.execute(zookeeperClient, context);93 validateCommandResult(command, context);94 log.info(String.format("Zookeeper command execution successful: '%s'", command.getName()));95 } catch (CitrusRuntimeException e) {96 throw e;97 } catch (Exception e) {98 throw new CitrusRuntimeException("Unable to perform zookeeper command", e);99 }100 }101 /**102 * Validate command results.103 *104 * @param command105 * @param context106 */107 private void validateCommandResult(ZooCommand command, TestContext context) {108 Message commandResult = getCommandResult(command);109 extractVariables(commandResult, context);110 if (log.isDebugEnabled()) {111 log.debug("Validating Zookeeper response");112 }113 if (StringUtils.hasText(expectedCommandResult)) {114 assertResultExists(commandResult);115 JsonMessageValidationContext validationContext = new JsonMessageValidationContext();116 jsonTextMessageValidator.validateMessage(commandResult, new DefaultMessage(expectedCommandResult), context, validationContext);117 }118 if (jsonPathMessageValidationContext != null) {119 assertResultExists(commandResult);120 jsonPathMessageValidator.validateMessage(commandResult, null, context, jsonPathMessageValidationContext);121 }122 log.info("Zookeeper command result validation successful - all values OK!");123 if (command.getResultCallback() != null) {124 command.getResultCallback().doWithCommandResult(command.getCommandResult(), context);125 }126 }127 private void assertResultExists(Message commandResult) {128 if (commandResult == null) {129 throw new ValidationException("Missing Zookeeper command result");130 }131 }132 private Message getCommandResult(ZooCommand command) {133 if (command.getCommandResult() == null) {134 return null;135 }136 try {137 Object commandResult = command.getCommandResult();138 String commandResultJson = jsonMapper.writeValueAsString(commandResult);139 return new DefaultMessage(commandResultJson);140 } catch (JsonProcessingException e) {141 throw new CitrusRuntimeException(e);142 }143 }144 private void extractVariables(Message commandResult, TestContext context) {145 if (log.isDebugEnabled()) {146 log.debug("Extracting variables from Zookeeper response");147 }148 for (VariableExtractor variableExtractor : variableExtractors) {149 variableExtractor.extractVariables(commandResult, context);150 }151 }152 /**153 * Gets the zookeeper command to execute.154 *155 * @return156 */157 public ZooCommand getCommand() {158 return command;159 }160 /**161 * Sets zookeeper command to execute.162 *163 * @param command164 * @return165 */166 public ZooExecuteAction setCommand(ZooCommand command) {167 this.command = command;168 return this;169 }170 /**171 * Gets the zookeeper client.172 *173 * @return174 */175 public ZooClient getZookeeperClient() {176 return zookeeperClient;177 }178 /**179 * Sets the zookeeper client.180 *181 * @param zookeeperClient182 */183 public ZooExecuteAction setZookeeperClient(ZooClient zookeeperClient) {184 this.zookeeperClient = zookeeperClient;185 return this;186 }187 /**188 * Gets the expected command result data.189 *190 * @return191 */192 public String getExpectedCommandResult() {193 return expectedCommandResult;194 }195 /**196 * Sets the expected command result data.197 *198 * @param expectedCommandResult199 */200 public ZooExecuteAction setExpectedCommandResult(String expectedCommandResult) {201 this.expectedCommandResult = expectedCommandResult;202 return this;203 }204 /**205 * Sets the JSON object mapper.206 *207 * @param jsonMapper208 */209 public ZooExecuteAction setJsonMapper(ObjectMapper jsonMapper) {210 this.jsonMapper = jsonMapper;211 return this;212 }213 /**214 * Adds a new variable extractor.215 *216 * @param variableExtractor the variableExtractor to add217 */218 public ZooExecuteAction addVariableExtractors(VariableExtractor variableExtractor) {219 this.variableExtractors.add(variableExtractor);220 return this;221 }222 /**223 * Set the list of variable extractors.224 *225 * @param variableExtractors the variableExtractors to set226 */227 public ZooExecuteAction setVariableExtractors(List<VariableExtractor> variableExtractors) {228 this.variableExtractors = variableExtractors;229 return this;230 }231 /**232 * Gets the variable extractors.233 *234 * @return the variableExtractors235 */236 public List<VariableExtractor> getVariableExtractors() {237 return variableExtractors;238 }239 /**240 * Sets the JsonPathMessageValidationContext for this action.241 *242 * @param jsonPathMessageValidationContext the json-path validation context243 */244 public ZooExecuteAction setJsonPathMessageValidationContext(JsonPathMessageValidationContext jsonPathMessageValidationContext) {245 this.jsonPathMessageValidationContext = jsonPathMessageValidationContext;246 return this;247 }248 /**249 * Gets the JsonPathMessageValidationContext.250 *251 * @return the validationContexts252 */253 public JsonPathMessageValidationContext getJsonPathMessageValidationContext() {254 return jsonPathMessageValidationContext;255 }256}...

Full Screen

Full Screen

Source:ZooTestRunnerTest.java Github

copy

Full Screen

...15 */16package com.consol.citrus.dsl.runner;17import com.consol.citrus.TestCase;18import com.consol.citrus.testng.AbstractTestNGUnitTest;19import com.consol.citrus.zookeeper.actions.ZooExecuteAction;20import com.consol.citrus.zookeeper.command.AbstractZooCommand;21import org.apache.zookeeper.*;22import org.apache.zookeeper.data.Stat;23import org.mockito.Mockito;24import org.testng.Assert;25import org.testng.annotations.Test;26import java.util.Arrays;27import java.util.List;28import static org.mockito.Matchers.any;29import static org.mockito.Mockito.*;30/**31 * @author Martin Maher32 * @since 2.533 */34public class ZooTestRunnerTest extends AbstractTestNGUnitTest {35 private ZooKeeper zookeeperClientMock = Mockito.mock(ZooKeeper.class);36 private Stat statMock = prepareStatMock();37 @Test38 public void testZookeeperBuilder() throws KeeperException, InterruptedException {39 final String pwd = "SomePwd";40 final String path = "my-node";41 final String data = "my-data";42 final List<String> children = Arrays.asList("child1", "child2");43 final String newPath = "the-created-node";44 reset(zookeeperClientMock);45 // prepare info46 when(zookeeperClientMock.getState()).thenReturn(ZooKeeper.States.CONNECTED);47 when(zookeeperClientMock.getSessionId()).thenReturn(100L);48 when(zookeeperClientMock.getSessionPasswd()).thenReturn(pwd.getBytes());49 when(zookeeperClientMock.getSessionTimeout()).thenReturn(200);50 // prepare create51 when(zookeeperClientMock.create(path, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL)).thenReturn(newPath);52 // prepare exists53 when(zookeeperClientMock.exists(path, false)).thenReturn(statMock);54 // prepare get-children55 when(zookeeperClientMock.getChildren(path, false)).thenReturn(children);56 // prepare get-data57 when(zookeeperClientMock.getData(path, false, null)).thenReturn(data.getBytes());58 // prepare set-data59 when(zookeeperClientMock.setData(path, data.getBytes(), 0)).thenReturn(statMock);60 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {61 @Override62 public void execute() {63 zookeeper(builder -> builder.client(new com.consol.citrus.zookeeper.client.ZooClient(zookeeperClientMock))64 .validate("$.responseData.state", ZooKeeper.States.CONNECTED.name())65 .extract("$.responseData.state","state")66 .extract("$.responseData.sessionId","sessionId")67 .extract("$.responseData.sessionPwd","sessionPwd")68 .extract("$.responseData.sessionTimeout","sessionTimeout")69 .info()70 .validateCommandResult((result, context) -> {71 Assert.assertNotNull(result);72 Assert.assertEquals(result.getResponseData().get("state"), ZooKeeper.States.CONNECTED.name());73 Assert.assertEquals(result.getResponseData().get("sessionId"), 100L);74 Assert.assertEquals(result.getResponseData().get("sessionPwd"), pwd.getBytes());75 Assert.assertEquals(result.getResponseData().get("sessionTimeout"), 200);76 }));77 zookeeper(builder -> builder.client(new com.consol.citrus.zookeeper.client.ZooClient(zookeeperClientMock))78 .create(path, data)79 .validateCommandResult((result, context) -> {80 Assert.assertNotNull(result);81 Assert.assertEquals(result.getResponseData().get(AbstractZooCommand.PATH), newPath);82 }));83 zookeeper(builder -> builder.client(new com.consol.citrus.zookeeper.client.ZooClient(zookeeperClientMock))84 .delete(path)85 .validateCommandResult((result, context) -> verify(zookeeperClientMock).delete(eq(path), eq(0), any(AsyncCallback.VoidCallback.class), isNull())));86 zookeeper(builder -> builder.client(new com.consol.citrus.zookeeper.client.ZooClient(zookeeperClientMock))87 .exists(path)88 .validateCommandResult((result, context) -> {89 Assert.assertNotNull(result);90 for (Object o : result.getResponseData().values()) {91 Assert.assertEquals(o.toString(), "1");92 }93 }));94 zookeeper(builder -> builder.client(new com.consol.citrus.zookeeper.client.ZooClient(zookeeperClientMock))95 .children(path)96 .validateCommandResult((result, context) -> {97 Assert.assertNotNull(result);98 Assert.assertEquals(result.getResponseData().get(AbstractZooCommand.CHILDREN), children);99 }));100 zookeeper(builder -> builder.client(new com.consol.citrus.zookeeper.client.ZooClient(zookeeperClientMock))101 .get(path)102 .validateCommandResult((result, context) -> {103 Assert.assertNotNull(result);104 Assert.assertEquals(result.getResponseData().get(AbstractZooCommand.DATA), data);105 }));106 zookeeper(builder -> builder.client(new com.consol.citrus.zookeeper.client.ZooClient(zookeeperClientMock))107 .set(path, data)108 .validateCommandResult((result, context) -> {109 Assert.assertNotNull(result);110 for (Object o : result.getResponseData().values()) {111 Assert.assertEquals(o.toString(), "1");112 }113 }));114 }115 };116 TestCase test = builder.getTestCase();117 Assert.assertEquals(test.getActionCount(), 7);118 Assert.assertEquals(test.getActions().get(0).getClass(), ZooExecuteAction.class);119 Assert.assertEquals(test.getActiveAction().getClass(), ZooExecuteAction.class);120 String actionName = "zookeeper-execute";121 ZooExecuteAction action = (ZooExecuteAction) test.getActions().get(0);122 Assert.assertEquals(action.getName(), actionName);123 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.Info.class);124 action = (ZooExecuteAction) test.getActions().get(1);125 Assert.assertEquals(action.getName(), actionName);126 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.Create.class);127 action = (ZooExecuteAction) test.getActions().get(2);128 Assert.assertEquals(action.getName(), actionName);129 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.Delete.class);130 action = (ZooExecuteAction) test.getActions().get(3);131 Assert.assertEquals(action.getName(), actionName);132 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.Exists.class);133 action = (ZooExecuteAction) test.getActions().get(4);134 Assert.assertEquals(action.getName(), actionName);135 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.GetChildren.class);136 action = (ZooExecuteAction) test.getActions().get(5);137 Assert.assertEquals(action.getName(), actionName);138 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.GetData.class);139 action = (ZooExecuteAction) test.getActions().get(6);140 Assert.assertEquals(action.getName(), actionName);141 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.SetData.class);142 }143 private Stat prepareStatMock() {144 Stat stat = Mockito.mock(Stat.class);145 when(stat.getAversion()).thenReturn(1);146 when(stat.getCtime()).thenReturn(1L);147 when(stat.getCversion()).thenReturn(1);148 when(stat.getCzxid()).thenReturn(1L);149 when(stat.getDataLength()).thenReturn(1);150 when(stat.getEphemeralOwner()).thenReturn(1L);151 when(stat.getMtime()).thenReturn(1L);152 when(stat.getMzxid()).thenReturn(1L);153 when(stat.getNumChildren()).thenReturn(1);...

Full Screen

Full Screen

Source:ZooTestDesignerTest.java Github

copy

Full Screen

...16package com.consol.citrus.dsl.design;17import com.consol.citrus.TestCase;18import com.consol.citrus.dsl.builder.ZooActionBuilder;19import com.consol.citrus.testng.AbstractTestNGUnitTest;20import com.consol.citrus.zookeeper.actions.ZooExecuteAction;21import com.consol.citrus.zookeeper.command.*;22import org.testng.Assert;23import org.testng.annotations.Test;24/**25 * @author Martin Maher26 * @since 2.527 */28public class ZooTestDesignerTest extends AbstractTestNGUnitTest {29 @Test30 public void testZooBuilder() {31 final String actionName = "zookeeper-execute";32 final String path = "my-node";33 final String data = "my-data";34 final String mode = "custom-mode";35 final String acl = "custom-acl";36 final int version = 10;37 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {38 @Override39 public void configure() {40 zookeeper().info().validateCommandResult((result, context) -> Assert.assertNotNull(result));41 zookeeper().create(path, data);42 zookeeper().create(path, data).mode(mode).acl(acl);43 zookeeper().delete(path);44 zookeeper().delete(path).version(version);45 zookeeper().exists(path);46 zookeeper().children(path);47 zookeeper().set(path, data);48 zookeeper().get(path);49 }50 };51 builder.configure();52 TestCase test = builder.getTestCase();53 Assert.assertEquals(test.getActionCount(), 9);54 Assert.assertEquals(test.getActions().get(0).getClass(), ZooExecuteAction.class);55 ZooExecuteAction action = (ZooExecuteAction) test.getActions().get(0);56 Assert.assertEquals(action.getName(), actionName);57 Assert.assertEquals(action.getCommand().getClass(), com.consol.citrus.zookeeper.command.Info.class);58 Assert.assertNotNull(action.getCommand().getResultCallback());59 action = (ZooExecuteAction) test.getActions().get(1);60 Assert.assertEquals(action.getName(), actionName);61 Assert.assertEquals(action.getCommand().getClass(), Create.class);62 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);63 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.DATA), data);64 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.ACL), ZooActionBuilder.DEFAULT_ACL);65 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.MODE), ZooActionBuilder.DEFAULT_MODE);66 action = (ZooExecuteAction) test.getActions().get(2);67 Assert.assertEquals(action.getName(), actionName);68 Assert.assertEquals(action.getCommand().getClass(), Create.class);69 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);70 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.DATA), data);71 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.ACL), acl);72 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.MODE), mode);73 action = (ZooExecuteAction) test.getActions().get(3);74 Assert.assertEquals(action.getName(), actionName);75 Assert.assertEquals(action.getCommand().getClass(), Delete.class);76 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);77 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.VERSION), ZooActionBuilder.DEFAULT_VERSION);78 action = (ZooExecuteAction) test.getActions().get(4);79 Assert.assertEquals(action.getName(), actionName);80 Assert.assertEquals(action.getCommand().getClass(), Delete.class);81 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);82 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.VERSION), version);83 action = (ZooExecuteAction) test.getActions().get(5);84 Assert.assertEquals(action.getName(), actionName);85 Assert.assertEquals(action.getCommand().getClass(), Exists.class);86 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);87 action = (ZooExecuteAction) test.getActions().get(6);88 Assert.assertEquals(action.getName(), actionName);89 Assert.assertEquals(action.getCommand().getClass(), GetChildren.class);90 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);91 action = (ZooExecuteAction) test.getActions().get(7);92 Assert.assertEquals(action.getName(), actionName);93 Assert.assertEquals(action.getCommand().getClass(), SetData.class);94 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);95 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.DATA), data);96 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.VERSION), ZooActionBuilder.DEFAULT_VERSION);97 action = (ZooExecuteAction) test.getActions().get(8);98 Assert.assertEquals(action.getName(), actionName);99 Assert.assertEquals(action.getCommand().getClass(), GetData.class);100 Assert.assertEquals(action.getCommand().getParameters().get(AbstractZooCommand.PATH), path);101 }102}...

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.testng.CitrusParameters;3import com.consol.citrus.zookeeper.actions.ZooExecuteAction;4import com.consol.citrus.zookeeper.client.ZooClient;5import com.consol.citrus.zookeeper.message.ZooMessage;6import com.consol.citrus.zookeeper.message.ZooMessageHeaders;7import com.consol.citrus.zookeeper.server.ZooServer;8import com.consol.citrus.zookeeper.server.ZooServerBuilder;9import org.apache.zookeeper.CreateMode;10import org.apache.zookeeper.ZooDefs;11import org.apache.zookeeper.ZooKeeper;12import org.apache.zookeeper.data.ACL;13import org.apache.zookeeper.data.Stat;14import org.springframework.context.annotation.Bean;15import org.springframework.context.annotation.Configuration;16import org.springframework.core.io.ClassPathResource;17import org.testng.annotations.Test;18import java.util.Collections;19import static com.consol.citrus.zookeeper.actions.ZooExecuteAction.Builder.zoo;20import static com.consol.citrus.zookeeper.actions.ZooExecuteAction.ZooAction.*;21import static com.consol.citrus.zookeeper.message.ZooMessageHeaders.*;22import static org.testng.Assert.assertEquals;23public class ZooExecuteActionJavaITest {24 @CitrusParameters({"zooServer", "zooClient"})25 public void testZooExecuteAction(ZooServer zooServer, ZooClient zooClient) {26 ZooExecuteAction.Builder builder = zoo();27 builder.server(zooServer);28 builder.client(zooClient);29 builder.action(SET_DATA);30 builder.path("/test");31 builder.data("test");32 builder.version(0);33 builder.acls(Collections.singletonList(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE)));34 builder.stat(new Stat());35 builder.message(new ZooMessage());36 builder.header(ZooMessageHeaders.ZOO_ACTION, ZooAction.SET_DATA);37 builder.header(ZooMessageHeaders.ZOO_PATH, "/test");38 builder.header(ZooMessageHeaders.ZOO_DATA, "test");39 builder.header(ZooMessageHeaders.ZOO_VERSION, 0);40 builder.header(ZooMessageHeaders.ZOO_ACLS, Collections.singletonList(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE)));41 builder.header(ZooMessageHeaders.ZOO_STAT, new Stat());42 builder.header(Z

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.testng.CitrusParameters;3import com.consol.citrus.zookeeper.actions.ZooExecuteAction;4import com.consol.citrus.zookeeper.message.ZooMessage;5import com.consol.citrus.zookeeper.server.ZooServer;6import com.consol.citrus.zookeeper.server.ZooServerBuilder;7import org.apache.curator.framework.CuratorFramework;8import org.apache.curator.framework.CuratorFrameworkFactory;9import org.apache.curator.retry.RetryNTimes;10import org.apache.zookeeper.CreateMode;11import org.apache.zookeeper.ZooDefs;12import org.apache.zookeeper.data.Stat;13import org.springframework.beans.factory.annotation.Autowired;14import org.springframework.context.annotation.Bean;15import org.springframework.context.annotation.Configuration;16import org.springframework.core.io.ClassPathResource;17import org.testng.annotations.Test;18import java.util.List;19import static org.testng.Assert.assertEquals;20import static org.testng.Assert.assertNotNull;21import static org.testng.Assert.assertTrue;22public class ZooExecuteActionJavaITest extends AbstractZooITest {23 private CuratorFramework client;24 @CitrusParameters("zooExecuteAction")25 public void zooExecuteAction(ZooExecuteAction action) {26 action.execute(context);27 }28 public static class Config {29 public ZooServer zooServer() {30 return new ZooServerBuilder().build();31 }32 public CuratorFramework client() {33 return CuratorFrameworkFactory.newClient("localhost:2181", new RetryNTimes(5, 1000));34 }35 }36}37import com.consol.citrus.annotations.CitrusTest;38import com.consol.citrus.zookeeper.actions.ZooExecuteAction;39import com.consol.citrus.zookeeper.message.ZooMessage;40import com.consol.citrus.zookeeper.server.ZooServer;41import com.consol.citrus.zookeeper.server.ZooServerBuilder;42import org.apache.curator.framework.CuratorFramework;43import org.apache.curator.framework.CuratorFrameworkFactory;44import org.apache.curator.retry.RetryNTimes;45import org.apache.zookeeper.CreateMode;46import org.apache.zookeeper.ZooDefs;47import org.apache

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.actions;2import com.consol.citrus.actions.AbstractTestAction;3import com.consol.citrus.context.TestContext;4import com.consol.citrus.exceptions.CitrusRuntimeException;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.zookeeper.client.ZooClient;7import com.consol.citrus.zookeeper.message.ZooMessage;8import com.consol.citrus.zookeeper.message.ZooMessageHeaders;9import org.apache.zookeeper.CreateMode;10import org.apache.zookeeper.KeeperException;11import org.apache.zookeeper.ZooDefs;12import org.springframework.util.StringUtils;13import java.util.List;14import java.util.concurrent.TimeUnit;15public class ZooExecuteAction extends AbstractTestAction {16 private final ZooClient client;17 private final ZooMessage message;18 public ZooExecuteAction(Builder builder) {19 super("zoo-execute", builder);20 this.client = builder.client;21 this.message = builder.message;22 }23 public void doExecute(TestContext context) {24 String path = context.replaceDynamicContentInString(message.getHeaders().get(ZooMessageHeaders.PATH));25 String data = context.replaceDynamicContentInString(message.getPayload(String.class));26 switch (message.getHeaders().getOperation()) {27 CreateMode createMode = message.getHeaders().getMode() != null ? message.getHeaders().getMode() : CreateMode.PERSISTENT;28 try {29 client.create(path, data, createMode);30 } catch (KeeperException | InterruptedException e) {31 throw new CitrusRuntimeException("Failed to create ZooKeeper node", e);32 }33 break;34 try {35 client.delete(path);36 } catch (KeeperException | InterruptedException e) {37 throw new CitrusRuntimeException("Failed to delete ZooKeeper node", e);38 }39 break;40 try {41 client.setData(path, data);42 } catch (KeeperException | InterruptedException e) {43 throw new CitrusRuntimeException("Failed to update ZooKeeper node", e);44 }

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.actions;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.exceptions.CitrusRuntimeException;4import com.consol.citrus.zookeeper.client.ZooClient;5import org.apache.curator.framework.CuratorFramework;6import org.apache.curator.framework.api.transaction.CuratorTransaction;7import org.apache.curator.framework.api.transaction.CuratorTransactionResult;8import org.apache.zookeeper.CreateMode;9import org.apache.zookeeper.data.Stat;10import org.slf4j.Logger;11import org.slf4j.LoggerFactory;12import org.springframework.util.CollectionUtils;13import java.util.List;14public class ZooExecuteAction extends AbstractZooExecuteAction<ZooExecuteAction> {15 private static final Logger LOG = LoggerFactory.getLogger(ZooExecuteAction.class);16 private final List<ZooExecuteAction.ZooOperation> operations;17 public ZooExecuteAction(Builder builder) {18 super("execute", builder);19 this.operations = builder.operations;20 }21 public void doExecute(ZooClient client, TestContext context) {22 CuratorFramework curatorFramework = client.getCuratorFramework();23 CuratorTransaction transaction = curatorFramework.inTransaction();24 for (ZooOperation operation : operations) {25 operation.apply(transaction, context);26 }27 try {28 List<CuratorTransactionResult> results = transaction.commit();29 if (!CollectionUtils.isEmpty(results)) {30 for (CuratorTransactionResult result : results) {31 LOG.info("ZooKeeper transaction result: {}", result);32 }33 }34 } catch (Exception e) {35 throw new CitrusRuntimeException("Failed to execute ZooKeeper transaction", e);36 }37 }38 public List<ZooOperation> getOperations() {39 return operations;40 }41 public static final class Builder extends AbstractZooExecuteAction.Builder<ZooExecuteAction, Builder> {42 private List<ZooOperation> operations;

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.actions;2import org.testng.annotations.Test;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.testng.CitrusParameters;5import com.consol.citrus.zookeeper.client.ZooClient;6import com.consol.citrus.zookeeper.message.ZooMessage;7import com.consol.citrus.zookeeper.server.ZooServer;8import com.consol.citrus.zookeeper.command.ZooCommand;9import com.consol.citrus.zookeeper.command.ZooCommandBuilder;10import com.consol.citrus.zookeeper.command.ZooCommandResult;11import org.apache.zookeeper.ZooDefs;12import org.apache.zookeeper.data.ACL;13import java.util.ArrayList;14import java.util.List;15import static org.testng.Assert.assertEquals;16public class ZooExecuteActionTest {17 @CitrusParameters({"zooServer", "zooClient"})18 public void testZooExecuteAction(ZooServer zooServer, ZooClient zooClient) {19 ZooCommandBuilder zooCommandBuilder = new ZooCommandBuilder();20 ZooCommand zooCommand = zooCommandBuilder.createCommand("create", "/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, 0);21 zooCommand.setZooClient(zooClient);22 ZooCommandResult zooCommandResult = zooCommand.execute();23 assertEquals(zooCommandResult.getResultCode(), 0);24 }25}26package com.consol.citrus.zookeeper.actions;27import org.testng.annotations.Test;28import com.consol.citrus.annotations.CitrusTest;29import com.consol.citrus.testng.CitrusParameters;30import com.consol.citrus.zookeeper.client.ZooClient;31import com.consol.citrus.zookeeper.message.ZooMessage;32import com.consol.citrus.zookeeper.command.ZooCommand;33import com.consol.citrus.zookeeper.command.ZooCommandBuilder;34import com.consol.citrus.zookeeper.command.ZooCommandResult;35import org.apache.zookeeper.ZooDefs;36import org.apache.zookeeper.data.ACL;37import java.util.ArrayList;38import java.util.List;39import static org.testng.Assert.assertEquals;40public class ZooExecuteActionTest {41 @CitrusParameters({"zooServer", "zooClient"})42 public void testZooExecuteAction(ZooServer zooServer, Zoo

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import com.consol.citrus.zookeeper.actions.ZooExecuteAction;4import com.consol.citrus.zookeeper.client.ZooClient;5import com.consol.citrus.zookeeper.command.ZooCommand;6import com.consol.citrus.zookeeper.command.ZooCommandBuilder;7import org.apache.zookeeper.CreateMode;8import org.apache.zookeeper.data.Stat;9import org.springframework.beans.factory.annotation.Autowired;10import org.testng.annotations.Test;11public class 4 extends TestNGCitrusTestDesigner {12 private ZooClient zooClient;13 public void 4() {14 description("Test to create a node in zookeeper");15 variable("path", "/citrus");16 variable("data", "Hello Citrus!");17 echo("Create node in zookeeper");18 zooExecute(new ZooCommandBuilder().create().withPath("${path}").withData("${data}").withMode(CreateMode.PERSISTENT).build());19 echo("Check if node exists");20 zooExecute(new ZooCommandBuilder().exists().withPath("${path}").withWatch(false).build(), new ZooExecuteAction.ZooCommandResultCallback() {21 public void doWithResult(ZooCommand command, Object result) {22 if (result instanceof Stat) {23 echo("Node exists");24 } else {25 echo("Node does not exist");26 }27 }28 });29 }30}31import com.consol.citrus.annotations.CitrusTest;32import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;33import com.consol.citrus.zookeeper.actions.ZooExecuteAction;34import com.consol.citrus.zookeeper.client.ZooClient;35import com.consol.citrus.zookeeper.command.ZooCommand;36import com.consol.citrus.zookeeper.command.ZooCommandBuilder;37import org.apache.zookeeper.CreateMode;38import org.apache.zookeeper.data.Stat;39import org.springframework.beans.factory.annotation.Autowired;40import org.testng.annotations.Test;41public class 5 extends TestNGCitrusTestDesigner {42 private ZooClient zooClient;

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.actions;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.testng.CitrusParameters;4import com.consol.citrus.zookeeper.message.ZooMessage;5import org.apache.zookeeper.CreateMode;6import org.testng.annotations.Test;7import java.util.Collections;8public class ZooExecuteActionJavaITest extends AbstractZooITest {9 @CitrusParameters("zooExecuteAction")10 public void zooExecuteAction() {11 variable("zooPath", "/path/to/node");12 variable("zooData", "some data");13 variable("zooAcl", "world:anyone:r");14 variable("zooMode", "PERSISTENT");15 variable("zooNode", "node");16 zooCreate()17 .path("${zooPath}")18 .data("${zooData}")19 .acl("${zooAcl}")20 .mode(CreateMode.valueOf("${zooMode}"))21 .build();22 zooExecute()23 .message(new ZooMessage()24 .path("${zooPath}")25 .data("${zooData}")26 .acl(Collections.singletonList("${zooAcl}"))27 .mode(CreateMode.valueOf("${zooMode}"))28 .node("${zooNode}"))29 .build();30 }31}32package com.consol.citrus.zookeeper.actions;33import com.consol.citrus.annotations.CitrusTest;34import com.consol.citrus.testng.CitrusParameters;35import org.testng.annotations.Test;36public class ZooExistsActionJavaITest extends AbstractZooITest {37 @CitrusParameters("zooExistsAction")38 public void zooExistsAction() {39 variable("zooPath", "/path/to/node");40 variable("zooData", "some data");41 variable("zooAcl", "world:anyone:r");42 variable("zooMode", "PERSISTENT");43 zooCreate()44 .path("${zooPath}")45 .data("${zooData}")46 .acl("${zooAcl}")47 .mode(CreateMode.valueOf("${zooMode}"))48 .build();

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.actions;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;4import org.testng.annotations.Test;5public class ZooExecuteActionJavaITest extends TestDesignerBeforeTestSupport {6 public void zooExecuteActionJavaITest() {7 variable("zookeeperUrl", "localhost:2181");8 variable("zookeeperPath", "/test");9 variable("zookeeperData", "test");10 variable("zookeeperVersion", "0");11 variable("zookeeperCreateMode", "PERSISTENT");12 variable("zookeeperStat", "test");13 $(zooExecuteAction()14 .server("zookeeperServer")15 .command("create")16 .url("${zookeeperUrl}")17 .path("${zookeeperPath}")18 .data("${zookeeperData}")19 .version("${zookeeperVersion}")20 .createMode("${zookeeperCreateMode}")21 .stat("${zookeeperStat}")22 );23 }24}25package com.consol.citrus.zookeeper.actions;26import com.consol.citrus.actions.AbstractTestActionBuilder;27import com.consol.citrus.context.TestContext;28import com.consol.citrus.zookeeper.client.ZooClient;29import com.consol.citrus.zookeeper.command.ZooExecuteCommand;30import org.apache.curator.framework.CuratorFramework;31import org.apache.zookeeper.CreateMode;32import org.apache.zookeeper.data.Stat;33public class ZooExecuteActionBuilder extends AbstractTestActionBuilder<ZooExecuteAction, ZooExecuteActionBuilder> {34 public ZooExecuteActionBuilder() {35 super(new ZooExecuteAction());36 }37 public ZooExecuteActionBuilder client(ZooClient zooClient) {38 action.setZooClient(zooClient);39 return this;40 }41 public ZooExecuteActionBuilder client(CuratorFramework zooClient) {42 action.setZooClient(new ZooClient(zooClient));

Full Screen

Full Screen

ZooExecuteAction

Using AI Code Generation

copy

Full Screen

1public class ZooExecuteAction extends AbstractTestAction {2 private ZooKeeperClient zooKeeperClient;3 private String command;4 public void doExecute(TestContext context) {5 try {6 zooKeeperClient.execute(command);7 } catch (Exception e) {8 throw new CitrusRuntimeException("Failed to execute command", e);9 }10 }11 public ZooKeeperClient getZooKeeperClient() {12 return zooKeeperClient;13 }14 public void setZooKeeperClient(ZooKeeperClient zooKeeperClient) {15 this.zooKeeperClient = zooKeeperClient;16 }17 public String getCommand() {18 return command;19 }20 public void setCommand(String command) {21 this.command = command;22 }23}24public class ZooExecuteAction extends AbstractTestAction {25 private ZooKeeperClient zooKeeperClient;26 private String command;27 public void doExecute(TestContext context) {28 try {29 zooKeeperClient.execute(command);30 } catch (Exception e) {31 throw new CitrusRuntimeException("Failed to execute command", e);32 }33 }

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful