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

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

Source:ContainerCreate.java Github

copy

Full Screen

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

Full Screen

Full Screen

getCapabilities

Using AI Code Generation

copy

Full Screen

1public class DockerJavaIT extends AbstractTestNGCitrusTest {2 public void dockerCreateContainer() {3 variable("containerId", "citrus:randomNumber(5)");4 variable("imageName", "citrusframework/citrus-docker-java");5 variable("imageTag", "latest");6 variable("containerName", "citrus:concat('citrus_', citrus:randomNumber(5))");7 variable("containerPort", "8080");8 echo("Docker create container");9 docker().createContainer()10 .withContainerId("${containerId}")11 .withImage("${imageName}:${imageTag}")12 .withName("${containerName}")13 .withExposedPorts("${containerPort}/tcp")14 .withPortBindings("8080:8080/tcp")15 .withLabels("citrus=true")16 .withCommand("tail -f /dev/null")17 .withLogDriver("json-file")18 .withLogDriverOpts("max-size=50m")19 .withLogDriverOpts("max-file=10")20 .withLogDriverOpts("labels=citrus")21 .withLogDriverOpts("env=TEST")22 .withLogDriverOpts("env=DEV")23 .withLogDriverOpts("env=PROD")24 .withLogDriverOpts("env=UAT")25 .withLogDriverOpts("env=QA")26 .withLogDriverOpts("env=STAGING")27 .withLogDriverOpts("env=DEMO")28 .withLogDriverOpts("env=SANDBO

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