How to use ContainerCreate class of com.consol.citrus.docker.command package

Best Citrus code snippet using com.consol.citrus.docker.command.ContainerCreate

Source:ContainerCreate.java Github

copy

Full Screen

...24/**25 * @author Christoph Deppisch26 * @since 2.427 */28public class ContainerCreate extends AbstractDockerCommand<CreateContainerResponse> {29 public static final String DELIMITER = ";";30 /**31 * Default constructor initializing the command name.32 */33 public ContainerCreate() {34 super("docker:container:create");35 }36 @Override37 public void execute(DockerClient dockerClient, TestContext context) {38 CreateContainerCmd command = dockerClient.getEndpointConfiguration().getDockerClient().createContainerCmd(getImageId(context));39 if (hasParameter("name")) {40 command.withName(getParameter("name", context));41 }42 if (hasParameter("attach-stderr")) {43 command.withAttachStderr(Boolean.valueOf(getParameter("attach-stderr", context)));44 }45 if (hasParameter("attach-stdin")) {46 command.withAttachStdin(Boolean.valueOf(getParameter("attach-stdin", context)));47 }48 if (hasParameter("attach-stdout")) {49 command.withAttachStdout(Boolean.valueOf(getParameter("attach-stdout", context)));50 }51 if (hasParameter("capability-add")) {52 if (getParameters().get("capability-add") instanceof Capability[]) {53 command.withCapAdd((Capability[]) getParameters().get("capability-add"));54 } else {55 command.withCapAdd(getCapabilities("capability-add", context));56 }57 }58 if (hasParameter("capability-drop")) {59 if (getParameters().get("capability-drop") instanceof Capability[]) {60 command.withCapAdd((Capability[]) getParameters().get("capability-drop"));61 } else {62 command.withCapDrop(getCapabilities("capability-drop", context));63 }64 }65 if (hasParameter("domain-name")) {66 command.withDomainName(getParameter("domain-name", context));67 }68 if (hasParameter("cmd")) {69 if (getParameters().get("cmd") instanceof Capability[]) {70 command.withCmd((String[]) getParameters().get("cmd"));71 } else {72 command.withCmd(StringUtils.delimitedListToStringArray(getParameter("cmd", context), DELIMITER));73 }74 }75 if (hasParameter("env")) {76 if (getParameters().get("env") instanceof Capability[]) {77 command.withEnv((String[]) getParameters().get("env"));78 } else {79 command.withEnv(StringUtils.delimitedListToStringArray(getParameter("env", context), DELIMITER));80 }81 }82 if (hasParameter("entrypoint")) {83 command.withEntrypoint(getParameter("entrypoint", context));84 }85 if (hasParameter("hostname")) {86 command.withHostName(getParameter("hostname", context));87 }88 if (hasParameter("port-specs")) {89 if (getParameters().get("port-specs") instanceof Capability[]) {90 command.withPortSpecs((String[]) getParameters().get("port-specs"));91 } else {92 command.withPortSpecs(StringUtils.delimitedListToStringArray(getParameter("port-specs", context), DELIMITER));93 }94 }95 ExposedPort[] exposedPorts = {};96 if (hasParameter("exposed-ports")) {97 if (getParameters().get("exposed-ports") instanceof ExposedPort[]) {98 exposedPorts = (ExposedPort[]) getParameters().get("exposed-ports");99 } else {100 exposedPorts = getExposedPorts(getParameter("exposed-ports", context), context);101 }102 command.withExposedPorts(exposedPorts);103 }104 if (hasParameter("port-bindings")) {105 if (getParameters().get("port-bindings") instanceof Ports) {106 command.withPortBindings((Ports) getParameters().get("port-bindings"));107 } if (getParameters().get("port-bindings") instanceof PortBinding[]) {108 command.withPortBindings((PortBinding[]) getParameters().get("port-bindings"));109 } else {110 command.withPortBindings(getPortBindings(getParameter("port-bindings", context), exposedPorts, context));111 }112 } else if (exposedPorts.length > 0) {113 command.withPortBindings(getPortBindings("", exposedPorts, context));114 }115 if (hasParameter("volumes")) {116 if (getParameters().get("volumes") instanceof ExposedPort[]) {117 command.withVolumes((Volume[]) getParameters().get("volumes"));118 } else {119 command.withVolumes(getVolumes(context));120 }121 }122 if (hasParameter("working-dir")) {123 command.withWorkingDir(getParameter("working-dir", context));124 }125 CreateContainerResponse response = command.exec();126 context.setVariable(DockerMessageHeaders.CONTAINER_ID, response.getId());127 setCommandResult(response);128 if (!hasParameter("name")) {129 InspectContainerCmd inspect = dockerClient.getEndpointConfiguration().getDockerClient().inspectContainerCmd(response.getId());130 InspectContainerResponse inspectResponse = inspect.exec();131 context.setVariable(DockerMessageHeaders.CONTAINER_NAME, inspectResponse.getName().substring(1));132 }133 }134 /**135 * Gets the volume specs from comma delimited string.136 * @return137 */138 private Volume[] getVolumes(TestContext context) {139 String[] volumes = StringUtils.commaDelimitedListToStringArray(getParameter("volumes", context));140 Volume[] volumeSpecs = new Volume[volumes.length];141 for (int i = 0; i < volumes.length; i++) {142 volumeSpecs[i] = new Volume(volumes[i]);143 }144 return volumeSpecs;145 }146 /**147 * Gets the capabilities added.148 * @return149 */150 private Capability[] getCapabilities(String addDrop, TestContext context) {151 String[] capabilities = StringUtils.commaDelimitedListToStringArray(getParameter(addDrop, context));152 Capability[] capAdd = new Capability[capabilities.length];153 for (int i = 0; i < capabilities.length; i++) {154 capAdd[i] = Capability.valueOf(capabilities[i]);155 }156 return capAdd;157 }158 /**159 * Construct set of exposed ports from comma delimited list of ports.160 * @param portSpecs161 * @param context162 * @return163 */164 private ExposedPort[] getExposedPorts(String portSpecs, TestContext context) {165 String[] ports = StringUtils.commaDelimitedListToStringArray(portSpecs);166 ExposedPort[] exposedPorts = new ExposedPort[ports.length];167 for (int i = 0; i < ports.length; i++) {168 String portSpec = context.replaceDynamicContentInString(ports[i]);169 if (portSpec.startsWith("udp:")) {170 exposedPorts[i] = ExposedPort.udp(Integer.valueOf(portSpec.substring("udp:".length())));171 } else if (portSpec.startsWith("tcp:")) {172 exposedPorts[i] = ExposedPort.tcp(Integer.valueOf(portSpec.substring("tcp:".length())));173 } else {174 exposedPorts[i] = ExposedPort.tcp(Integer.valueOf(portSpec));175 }176 }177 return exposedPorts;178 }179 /**180 * Construct set of port bindings from comma delimited list of ports.181 * @param portSpecs182 * @param exposedPorts183 * @param context184 * @return185 */186 private Ports getPortBindings(String portSpecs, ExposedPort[] exposedPorts, TestContext context) {187 String[] ports = StringUtils.commaDelimitedListToStringArray(portSpecs);188 Ports portsBindings = new Ports();189 for (String portSpec : ports) {190 String[] binding = context.replaceDynamicContentInString(portSpec).split(":");191 if (binding.length == 2) {192 Integer hostPort = Integer.valueOf(binding[0]);193 Integer port = Integer.valueOf(binding[1]);194 portsBindings.bind(Stream.of(exposedPorts).filter(exposed -> port.equals(exposed.getPort())).findAny().orElse(ExposedPort.tcp(port)), Ports.Binding.bindPort(hostPort));195 }196 }197 Stream.of(exposedPorts).filter(exposed -> !portsBindings.getBindings().keySet().contains(exposed)).forEach(exposed -> portsBindings.bind(exposed, Ports.Binding.empty()));198 return portsBindings;199 }200 /**201 * Sets the image id parameter.202 * @param id203 * @return204 */205 public ContainerCreate image(String id) {206 getParameters().put(IMAGE_ID, id);207 return this;208 }209 /**210 * Sets the image name parameter.211 * @param name212 * @return213 */214 public ContainerCreate name(String name) {215 getParameters().put("name", name);216 return this;217 }218 /**219 * Sets the attach-stderr parameter.220 * @param attachStderr221 * @return222 */223 public ContainerCreate attachStdErr(Boolean attachStderr) {224 getParameters().put("attach-stderr", attachStderr);225 return this;226 }227 /**228 * Sets the attach-stdin parameter.229 * @param attachStdin230 * @return231 */232 public ContainerCreate attachStdIn(Boolean attachStdin) {233 getParameters().put("attach-stdin", attachStdin);234 return this;235 }236 /**237 * Sets the attach-stdout parameter.238 * @param attachStdout239 * @return240 */241 public ContainerCreate attachStdOut(Boolean attachStdout) {242 getParameters().put("attach-stdout", attachStdout);243 return this;244 }245 /**246 * Adds capabilities as command parameter.247 * @param capabilities248 * @return249 */250 public ContainerCreate addCapability(Capability ... capabilities) {251 getParameters().put("capability-add", capabilities);252 return this;253 }254 /**255 * Drops capabilities as command parameter.256 * @param capabilities257 * @return258 */259 public ContainerCreate dropCapability(Capability ... capabilities) {260 getParameters().put("capability-drop", capabilities);261 return this;262 }263 /**264 * Sets the domain-name parameter.265 * @param domainName266 * @return267 */268 public ContainerCreate domainName(String domainName) {269 getParameters().put("domain-name", domainName);270 return this;271 }272 /**273 * Adds commands as command parameter.274 * @param commands275 * @return276 */277 public ContainerCreate cmd(String ... commands) {278 getParameters().put("cmd", commands);279 return this;280 }281 /**282 * Adds environment variables as command parameter.283 * @param envVars284 * @return285 */286 public ContainerCreate env(String ... envVars) {287 getParameters().put("env", envVars);288 return this;289 }290 /**291 * Sets the entrypoint parameter.292 * @param entrypoint293 * @return294 */295 public ContainerCreate entryPoint(String entrypoint) {296 getParameters().put("entrypoint", entrypoint);297 return this;298 }299 /**300 * Sets the hostname parameter.301 * @param hostname302 * @return303 */304 public ContainerCreate hostName(String hostname) {305 getParameters().put("hostname", hostname);306 return this;307 }308 /**309 * Adds port-specs variables as command parameter.310 * @param portSpecs311 * @return312 */313 public ContainerCreate portSpecs(String ... portSpecs) {314 getParameters().put("port-specs", portSpecs);315 return this;316 }317 /**318 * Adds exposed-ports variables as command parameter.319 * @param exposedPorts320 * @return321 */322 public ContainerCreate exposedPorts(ExposedPort ... exposedPorts) {323 getParameters().put("exposed-ports", exposedPorts);324 return this;325 }326 /**327 * Adds explicit port bindings as command parameter.328 * @param portBindings329 * @return330 */331 public ContainerCreate portBindings(Ports ... portBindings) {332 getParameters().put("port-bindings", portBindings);333 return this;334 }335 /**336 * Adds explicit port bindings as command parameter.337 * @param portBindings338 * @return339 */340 public ContainerCreate portBindings(PortBinding ... portBindings) {341 getParameters().put("port-bindings", portBindings);342 return this;343 }344 /**345 * Adds volumes variables as command parameter.346 * @param volumes347 * @return348 */349 public ContainerCreate volumes(Volume ... volumes) {350 getParameters().put("volumes", volumes);351 return this;352 }353 /**354 * Sets the working-dir parameter.355 * @param workingDir356 * @return357 */358 public ContainerCreate workingDir(String workingDir) {359 getParameters().put("working-dir", workingDir);360 return this;361 }362}...

Full Screen

Full Screen

Source:DockerExecuteActionBuilder.java Github

copy

Full Screen

...3import com.consol.citrus.docker.actions.DockerExecuteAction;4import com.consol.citrus.docker.client.DockerClient;5import com.consol.citrus.docker.command.AbstractDockerCommand;6import com.consol.citrus.docker.command.AbstractDockerCommandBuilder;7import com.consol.citrus.docker.command.ContainerCreate;8import com.consol.citrus.docker.command.ContainerInspect;9import com.consol.citrus.docker.command.ContainerStart;10import com.consol.citrus.docker.command.ContainerStop;11import com.consol.citrus.docker.command.ContainerWait;12import com.consol.citrus.docker.command.DockerCommand;13import com.consol.citrus.docker.command.ImageBuild;14import com.consol.citrus.docker.command.ImageInspect;15import com.consol.citrus.docker.command.ImagePull;16import com.consol.citrus.docker.command.ImageRemove;17import com.consol.citrus.docker.command.Info;18import com.consol.citrus.docker.command.Ping;19import com.consol.citrus.docker.command.Version;20import com.consol.citrus.validation.MessageValidator;21import com.consol.citrus.validation.context.ValidationContext;22import com.fasterxml.jackson.databind.ObjectMapper;23/**24 * @author Christoph Deppisch25 */26public class DockerExecuteActionBuilder extends AbstractTestActionBuilder<DockerExecuteAction, DockerExecuteActionBuilder> {27 private final DockerExecuteAction.Builder delegate = new DockerExecuteAction.Builder();28 /**29 * Use a custom docker client.30 */31 public DockerExecuteActionBuilder client(DockerClient dockerClient) {32 delegate.client(dockerClient);33 return this;34 }35 public DockerExecuteActionBuilder mapper(ObjectMapper jsonMapper) {36 delegate.mapper(jsonMapper);37 return this;38 }39 public DockerExecuteActionBuilder validator(MessageValidator<? extends ValidationContext> validator) {40 delegate.validator(validator);41 return this;42 }43 public <R, S extends AbstractDockerCommandBuilder<R, AbstractDockerCommand<R>, S>> DockerExecuteActionBuilder command(final DockerCommand<R> dockerCommand) {44 delegate.command(dockerCommand);45 return this;46 }47 public Info.Builder info() {48 return delegate.info();49 }50 public Ping.Builder ping() {51 return delegate.ping();52 }53 public Version.Builder version() {54 return delegate.version();55 }56 public ContainerCreate.Builder create(String imageId) {57 return delegate.create(imageId);58 }59 public ContainerStart.Builder start(String containerId) {60 return delegate.start(containerId);61 }62 public ContainerStop.Builder stop(String containerId) {63 return delegate.stop(containerId);64 }65 public ContainerWait.Builder wait(String containerId) {66 return delegate.wait(containerId);67 }68 public ContainerInspect.Builder inspectContainer(String containerId) {69 return delegate.inspectContainer(containerId);70 }...

Full Screen

Full Screen

Source:DockerActionBuilder.java Github

copy

Full Screen

...70 }71 /**72 * Adds a create command.73 */74 public ContainerCreate create(String imageId) {75 ContainerCreate command = new ContainerCreate();76 command.image(imageId);77 action.setCommand(command);78 return command;79 }80 /**81 * Adds a start command.82 */83 public ContainerStart start(String containerId) {84 ContainerStart command = new ContainerStart();85 command.container(containerId);86 action.setCommand(command);87 return command;88 }89 /**...

Full Screen

Full Screen

ContainerCreate

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.docker.command.ContainerCreate;2import com.consol.citrus.docker.command.ContainerStart;3import com.consol.citrus.docker.command.DockerClient;4import com.consol.citrus.docker.command.DockerClientBuilder;5import com.consol.citrus.docker.command.DockerCommand;6public class ContainerCreateTest {7 public static void main(String[] args) {8 DockerClient dockerClient = DockerClientBuilder.builder().build();9 DockerCommand dockerCommand = ContainerCreate.builder()10 .dockerClient(dockerClient)11 .image("nginx")12 .name("nginx")13 .build();14 dockerCommand.execute();15 }16}17import com.consol.citrus.docker.command.ContainerStart;18import com.consol.citrus.docker.command.DockerClient;19import com.consol.citrus.docker.command.DockerClientBuilder;20import com.consol.citrus.docker.command.DockerCommand;21public class ContainerStartTest {22 public static void main(String[] args) {23 DockerClient dockerClient = DockerClientBuilder.builder().build();24 DockerCommand dockerCommand = ContainerStart.builder()25 .dockerClient(dockerClient)26 .name("nginx")27 .build();28 dockerCommand.execute();29 }30}31import com.consol.citrus.docker.command.ContainerStop;32import com.consol.citrus.docker.command.DockerClient;33import com.consol.citrus.docker.command.DockerClientBuilder;34import com.consol.citrus.docker.command.DockerCommand;35public class ContainerStopTest {36 public static void main(String[] args) {37 DockerClient dockerClient = DockerClientBuilder.builder().build();38 DockerCommand dockerCommand = ContainerStop.builder()39 .dockerClient(dockerClient)40 .name("nginx")41 .build();42 dockerCommand.execute();43 }44}45import com.consol.citrus.docker.command.ContainerRemove;46import com.consol.citrus.docker.command.DockerClient;47import com.consol.citrus.docker.command.DockerClientBuilder;48import com.consol.citrus.docker.command.DockerCommand;

Full Screen

Full Screen

ContainerCreate

Using AI Code Generation

copy

Full Screen

1public class ContainerCreate {2 public static void main(String[] args) {3 DockerClient client = DefaultDockerClient.builder()4 .build();5 ContainerConfig config = ContainerConfig.builder()6 .image("busybox")7 .cmd("echo", "hello world")8 .build();9 ContainerCreation creation = client.createContainer(config);10 String id = creation.id();11 System.out.println(id);12 }13}

Full Screen

Full Screen

ContainerCreate

Using AI Code Generation

copy

Full Screen

1public class ContainerCreate extends AbstractDockerCommand {2 private String image;3 private String name;4 private String hostname;5 private String domainname;6 private String user;7 private String attachStdin;8 private String attachStdout;9 private String attachStderr;10 private String portSpecs;11 private String exposedPorts;12 private String tty;13 private String openStdin;14 private String stdinOnce;15 private String env;16 private String cmd;17 private String entrypoint;18 private String networkDisabled;19 private String macAddress;20 private String labels;21 private String volumes;22 private String volumesFrom;23 private String workingDir;24 private String networkMode;25 private String securityOpts;26 private String hostConfig;27 public ContainerCreate(Builder builder) {28 super("create", builder);29 this.image = builder.image;30 this.name = builder.name;31 this.hostname = builder.hostname;32 this.domainname = builder.domainname;33 this.user = builder.user;34 this.attachStdin = builder.attachStdin;35 this.attachStdout = builder.attachStdout;36 this.attachStderr = builder.attachStderr;37 this.portSpecs = builder.portSpecs;38 this.exposedPorts = builder.exposedPorts;39 this.tty = builder.tty;40 this.openStdin = builder.openStdin;41 this.stdinOnce = builder.stdinOnce;42 this.env = builder.env;43 this.cmd = builder.cmd;44 this.entrypoint = builder.entrypoint;45 this.networkDisabled = builder.networkDisabled;46 this.macAddress = builder.macAddress;47 this.labels = builder.labels;48 this.volumes = builder.volumes;49 this.volumesFrom = builder.volumesFrom;50 this.workingDir = builder.workingDir;51 this.networkMode = builder.networkMode;52 this.securityOpts = builder.securityOpts;53 this.hostConfig = builder.hostConfig;54 }55 public String getCommand() {56 return DockerClient.CMD_CREATE;57 }58 public static class Builder extends AbstractDockerCommand.Builder<Builder, ContainerCreate> {59 private String image;60 private String name;61 private String hostname;62 private String domainname;63 private String user;64 private String attachStdin;65 private String attachStdout;66 private String attachStderr;67 private String portSpecs;

Full Screen

Full Screen

ContainerCreate

Using AI Code Generation

copy

Full Screen

1public class ContainerCreate {2public static void main(String[] args) throws Exception {3 DockerClient dockerClient = DockerClientBuilder.getInstance().build();4 ContainerCreate containerCreate = new ContainerCreate();5 containerCreate.withName("test");6 containerCreate.withImage("ubuntu");7 containerCreate.withCmd(new String[] {"/bin/bash", "-c", "while true; do echo hello world; sleep 1; done"});8 containerCreate.withHostConfig(new HostConfig().withPortBindings(new PortBinding[] {new PortBinding().withHostPort("8080/tcp")}));9 CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd("ubuntu");10 createContainerCmd.withName("test");11 createContainerCmd.withImage("ubuntu");12 createContainerCmd.withCmd(new String[] {"/bin/bash", "-c", "while true; do echo hello world; sleep 1; done"});13 createContainerCmd.withHostConfig(new HostConfig().withPortBindings(new PortBinding[] {new PortBinding().withHostPort("8080/tcp")}));14 CreateContainerResponse response = createContainerCmd.exec();15 String containerId = response.getId();16 dockerClient.startContainerCmd(containerId).exec();17}18}19public class ContainerStart {20public static void main(String[] args) throws Exception {21 DockerClient dockerClient = DockerClientBuilder.getInstance().build();22 ContainerStart containerStart = new ContainerStart();23 containerStart.withName("test");24 containerStart.execute(dockerClient);25}26}

Full Screen

Full Screen

ContainerCreate

Using AI Code Generation

copy

Full Screen

1public class 3.java extends AbstractTestNGCitrusTest {2 private DockerClient dockerClient;3 private DockerEndpoint dockerEndpoint;4 public void test() {5 description("Test to create a container");6 variable("containerName", "testContainer");7 variable("image", "alpine");8 echo("Creating container ${containerName}");9 ContainerCreate containerCreate = new ContainerCreate.Builder()10 .containerName("${containerName}")11 .image("${image}")12 .build();13 send(dockerClient)14 .endpoint(dockerEndpoint)15 .message(containerCreate);16 }17}18public class 4.java extends AbstractTestNGCitrusTest {19 private DockerClient dockerClient;20 private DockerEndpoint dockerEndpoint;21 public void test() {22 description("Test to start a container");23 variable("containerName", "testContainer");24 echo("Starting container ${containerName}");25 ContainerStart containerStart = new ContainerStart.Builder()26 .containerName("${containerName}")27 .build();28 send(dockerClient)29 .endpoint(dockerEndpoint)30 .message(containerStart);31 }32}33public class 5.java extends AbstractTestNGCitrusTest {34 private DockerClient dockerClient;35 private DockerEndpoint dockerEndpoint;36 public void test() {37 description("Test to stop a container");38 variable("containerName", "testContainer");39 echo("Stopping container ${containerName}");40 ContainerStop containerStop = new ContainerStop.Builder()41 .containerName("${containerName}")42 .build();43 send(dockerClient)44 .endpoint(dockerEndpoint)45 .message(containerStop);46 }47}48public class 6.java extends AbstractTestNGCitrusTest {49 private DockerClient dockerClient;50 private DockerEndpoint dockerEndpoint;51 public void test() {52 description("Test to remove a container");53 variable("containerName", "testContainer");54 echo("Removing container ${

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.

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