How to use Info class of com.consol.citrus.zookeeper.command package

Best Citrus code snippet using com.consol.citrus.zookeeper.command.Info

Source:ZooExecuteAction.java Github

copy

Full Screen

1/*2 * Copyright 2006-2015 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.zookeeper.actions;17import com.consol.citrus.actions.AbstractTestAction;18import com.consol.citrus.context.TestContext;19import com.consol.citrus.exceptions.CitrusRuntimeException;20import com.consol.citrus.exceptions.ValidationException;21import com.consol.citrus.message.DefaultMessage;22import com.consol.citrus.message.Message;23import com.consol.citrus.validation.context.ValidationContext;24import com.consol.citrus.validation.json.JsonMessageValidationContext;25import com.consol.citrus.validation.json.JsonPathMessageValidationContext;26import com.consol.citrus.validation.json.JsonPathMessageValidator;27import com.consol.citrus.validation.json.JsonTextMessageValidator;28import com.consol.citrus.variable.VariableExtractor;29import com.consol.citrus.zookeeper.client.ZooClient;30import com.consol.citrus.zookeeper.command.ZooCommand;31import com.fasterxml.jackson.core.JsonProcessingException;32import com.fasterxml.jackson.databind.ObjectMapper;33import org.slf4j.Logger;34import org.slf4j.LoggerFactory;35import org.springframework.beans.factory.annotation.Autowired;36import org.springframework.beans.factory.annotation.Qualifier;37import org.springframework.util.CollectionUtils;38import org.springframework.util.StringUtils;39import java.util.ArrayList;40import java.util.List;41/**42 * Executes zookeeper command with given zookeeper client implementation. Possible command result is stored within command object.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

...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);...

Full Screen

Full Screen

Source:ZooExecuteActionParserTest.java Github

copy

Full Screen

...17import com.consol.citrus.testng.AbstractActionParserTest;18import com.consol.citrus.zookeeper.actions.ZooExecuteAction;19import com.consol.citrus.zookeeper.client.ZooClient;20import com.consol.citrus.zookeeper.command.Create;21import com.consol.citrus.zookeeper.command.Info;22import org.springframework.beans.factory.BeanCreationException;23import org.testng.Assert;24import org.testng.annotations.Test;25import java.util.Map;26public class ZooExecuteActionParserTest extends AbstractActionParserTest<ZooExecuteAction> {27 @Test28 public void testZookeeperExecuteActionParser() {29 assertActionCount(2);30 assertActionClassAndName(ZooExecuteAction.class, "zookeeper-execute");31 ZooExecuteAction action = getNextTestActionFromTest();32 Assert.assertNotNull(action.getCommand());33 Assert.assertEquals(action.getCommand().getClass(), Info.class);34 Assert.assertEquals(action.getZookeeperClient(), beanDefinitionContext.getBean("myZookeeperClient", ZooClient.class));35 Assert.assertEquals(action.getCommand().getParameters().size(), 0);36 Assert.assertEquals(action.getExpectedCommandResult(), "{a:\"some thing\"}");37 action = getNextTestActionFromTest();38 Assert.assertNotNull(action.getCommand());39 Assert.assertEquals(action.getCommand().getClass(), Create.class);40 Assert.assertEquals(action.getZookeeperClient(), beanDefinitionContext.getBean("myZookeeperClient", ZooClient.class));41 Assert.assertEquals(action.getCommand().getParameters().size(), 4);42 assertParametersContainValue(action.getCommand().getParameters(), "path", "/some-path");43 assertParametersContainValue(action.getCommand().getParameters(), "mode", "PERSISTENT");44 assertParametersContainValue(action.getCommand().getParameters(), "acl", "OPEN_ACL_UNSAFE");45 assertParametersContainValue(action.getCommand().getParameters(), "data", "more data");46 Assert.assertEquals(action.getExpectedCommandResult(), "{b:\"some thing\"}");47 }...

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.command;2import org.apache.zookeeper.ZooKeeper;3import org.apache.zookeeper.data.Stat;4import org.testng.Assert;5import org.testng.annotations.Test;6public class InfoTest {7 public void testExecute() throws Exception {8 ZooKeeper zooKeeper = new ZooKeeper("localhost:2181", 10000, null);9 Info info = new Info();10 info.setPath("/test");11 info.setZooKeeper(zooKeeper);12 info.setStat(new Stat());13 info.execute();14 Assert.assertEquals(info.getStat().getAversion(), 0);15 }16}17package com.consol.citrus.zookeeper.command;18import org.apache.zookeeper.ZooKeeper;19import org.apache.zookeeper.data.Stat;20import org.testng.Assert;21import org.testng.annotations.Test;22public class SetDataTest {23 public void testExecute() throws Exception {24 ZooKeeper zooKeeper = new ZooKeeper("localhost:2181", 10000, null);25 SetData setData = new SetData();26 setData.setPath("/test");27 setData.setData("test".getBytes());28 setData.setZooKeeper(zooKeeper);29 setData.setStat(new Stat());30 setData.execute();31 Assert.assertEquals(setData.getStat().getAversion(), 0);32 }33}34package com.consol.citrus.zookeeper.command;35import org.apache.zookeeper.ZooKeeper;36import org.apache.zookeeper.data.Stat;37import org.testng.Assert;38import org.testng.annotations.Test;39public class SetACLTest {40 public void testExecute() throws Exception {41 ZooKeeper zooKeeper = new ZooKeeper("localhost:2181", 10000, null);42 SetACL setACL = new SetACL();43 setACL.setPath("/test");44 setACL.setZooKeeper(zooKeeper);45 setACL.setStat(new Stat());46 setACL.execute();47 Assert.assertEquals(setACL.getStat().getAversion(), 0);48 }49}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.command;2import org.apache.zookeeper.data.Stat;3import org.testng.Assert;4import org.testng.annotations.Test;5public class InfoTest {6 public void testInfo() {7 Info info = new Info("/path");8 info.setStat(new Stat());9 info.setVersion(1);10 Assert.assertEquals(info.getPath(), "/path");11 Assert.assertNotNull(info.getStat());12 Assert.assertEquals(info.getVersion(), 1);13 }14}15package com.consol.citrus.zookeeper.command;16import org.testng.Assert;17import org.testng.annotations.Test;18public class SetDataTest {19 public void testSetData() {20 SetData setData = new SetData("/path", "data".getBytes());21 setData.setVersion(1);22 Assert.assertEquals(setData.getPath(), "/path");23 Assert.assertEquals(setData.getData(), "data".getBytes());24 Assert.assertEquals(setData.getVersion(), 1);25 }26}27package com.consol.citrus.zookeeper.command;28import org.apache.zookeeper.data.ACL;29import org.testng.Assert;30import org.testng.annotations.Test;31import java.util.List;32public class SetAclTest {33 public void testSetAcl() {34 SetAcl setAcl = new SetAcl("/path", null);35 setAcl.setVersion(1);36 Assert.assertEquals(setAcl.getPath(), "/path");37 Assert.assertNull(setAcl.getAcl());38 Assert.assertEquals(setAcl.getVersion(), 1);39 }40}41package com.consol.citrus.zookeeper.command;42import org.testng.Assert;43import org.testng.annotations.Test;44public class SyncTest {45 public void testSync() {46 Sync sync = new Sync("/path");47 Assert.assertEquals(sync.getPath(), "/path");48 }49}50package com.consol.citrus.zookeeper.command;51import org.testng.Assert;52import org.testng.annotations

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.command;2import org.apache.zookeeper.data.Stat;3public class Info {4 private String path;5 private Stat stat;6 public Info(String path, Stat stat) {7 this.path = path;8 this.stat = stat;9 }10 public String getPath() {11 return path;12 }13 public Stat getStat() {14 return stat;15 }16}17package com.consol.citrus.zookeeper.command;18import org.apache.zookeeper.ZooKeeper;19import org.apache.zookeeper.data.Stat;20public class Info extends AbstractZooCommand<Info> {21 private final String path;22 public Info(String path) {23 this.path = path;24 }25 public Info execute(ZooKeeper zookeeper) throws Exception {26 Stat stat = new Stat();27 zookeeper.getData(path, false, stat);28 return new Info(path, stat);29 }30}31package com.consol.citrus.zookeeper.command;32import org.apache.zookeeper.ZooKeeper;33public abstract class AbstractZooCommand<T extends AbstractZooCommand<?>> {34 public abstract T execute(ZooKeeper zookeeper) throws Exception;35}36package com.consol.citrus.zookeeper.command;37import org.apache.zookeeper.ZooKeeper;38public interface ZooCommand<T extends ZooCommand<?>> {39 T execute(ZooKeeper zookeeper) throws Exception;40}41package com.consol.citrus.zookeeper.command;42public class InfoTest {43 public void infoTest() {44 Info info = new Info("/path");45 info.execute(null);46 }47}48package com.consol.citrus.zookeeper.command;49import org.apache.zookeeper.ZooKeeper;50import org.apache.zookeeper.data.Stat;51public class Info extends AbstractZooCommand<Info> {52 private final String path;53 public Info(String path

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.zookeeper.command.Info;2import com.consol.citrus.zookeeper.command.InfoResult;3import com.consol.citrus.zookeeper.client.ZooClient;4import org.testng.Assert;5import org.testng.annotations.Test;6import java.util.List;7public class ZookeeperTest {8 public void zookeeperTest() {9 ZooClient zooClient = new ZooClient();10 zooClient.setConnectString("localhost:2181");11 zooClient.setSessionTimeout(30000);12 zooClient.init();13 zooClient.create("/my-node", "my-node-value".getBytes(), false, true, true);14 byte[] data = zooClient.getData("/my-node", true, null);15 Assert.assertEquals(new String(data), "my-node-value");16 Info info = new Info();17 info.setPath("/my-node");18 InfoResult infoResult = zooClient.info(info);19 Assert.assertEquals(infoResult.getCzxid(), 0);20 List<String> children = zooClient.getChildren("/my-node", true, null);21 Assert.assertEquals(children.size(), 0);22 zooClient.delete("/my-node", 0);23 }24}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.command;2import org.apache.zookeeper.data.Stat;3import java.util.List;4public class Info {5 private String path;6 private Stat stat;7 private List<String> children;8 public Info(String path, Stat stat, List<String> children) {9 this.path = path;10 this.stat = stat;11 this.children = children;12 }13 public String getPath() {14 return path;15 }16 public Stat getStat() {17 return stat;18 }19 public List<String> getChildren() {20 return children;21 }22}23package com.consol.citrus.zookeeper.command;24public class Create {25 private String path;26 private String data;27 private String mode;28 private boolean ephemeral;29 public Create(String path, String data) {30 this.path = path;31 this.data = data;32 }33 public Create(String path, String data, String mode, boolean ephemeral) {34 this.path = path;35 this.data = data;36 this.mode = mode;37 this.ephemeral = ephemeral;38 }39 public String getPath() {40 return path;41 }42 public String getData() {43 return data;44 }45 public String getMode() {46 return mode;47 }48 public boolean isEphemeral() {49 return ephemeral;50 }51}52package com.consol.citrus.zookeeper.command;53public class Delete {54 private String path;55 private int version;56 public Delete(String path) {57 this.path = path;58 }59 public Delete(String path, int version) {60 this.path = path;61 this.version = version;62 }63 public String getPath() {64 return path;65 }66 public int getVersion() {67 return version;68 }69}70package com.consol.citrus.zookeeper.command;71public class SetData {72 private String path;73 private String data;74 private int version;75 public SetData(String path, String data) {76 this.path = path;

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.zookeeper.command;2import org.apache.zookeeper.KeeperException;3import org.apache.zookeeper.ZooKeeper;4public class Info implements Command {5private String path;6public Info(String path) {7this.path = path;8}9public void execute(ZooKeeper zooKeeper) throws KeeperException, InterruptedException {10System.out.println(zooKeeper.exists(path, null));11}12}13package com.consol.citrus.zookeeper.command;14import org.apache.zookeeper.KeeperException;15import org.apache.zookeeper.ZooKeeper;16public class Info implements Command {17private String path;18public Info(String path) {19this.path = path;20}21public void execute(ZooKeeper zooKeeper) throws KeeperException, InterruptedException {22System.out.println(zooKeeper.exists(path, null));23}24}25package com.consol.citrus.zookeeper.command;26import org.apache.zookeeper.KeeperException;27import org.apache.zookeeper.ZooKeeper;28public class Info implements Command {29private String path;30public Info(String path) {31this.path = path;32}33public void execute(ZooKeeper zooKeeper) throws KeeperException, InterruptedException {34System.out.println(zooKeeper.exists(path, null));35}36}37package com.consol.citrus.zookeeper.command;38import org.apache.zookeeper.KeeperException;39import org.apache.zookeeper.ZooKeeper;40public class Info implements Command {41private String path;42public Info(String path) {43this.path = path;44}45public void execute(ZooKeeper zooKeeper) throws KeeperException, InterruptedException {46System.out.println(zooKeeper.exists(path, null));47}48}49package com.consol.citrus.zookeeper.command;50import org.apache.zookeeper.KeeperException;51import org.apache.zookeeper.ZooKeeper;52public class Info implements Command {53private String path;54public Info(String path) {55this.path = path;56}

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 Citrus automation tests on LambdaTest cloud grid

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

Most used methods in Info

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