Skip to content

Commit d31db06

Browse files
committed
fix tests
1 parent 0b18509 commit d31db06

File tree

7 files changed

+175
-69
lines changed

7 files changed

+175
-69
lines changed

src/main/java/com/github/dockerjava/api/model/HostConfig.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ public class HostConfig implements Serializable {
242242
@JsonProperty("Isolation")
243243
private String isolation;
244244

245+
public static HostConfig newHostConfig() {
246+
return new HostConfig();
247+
}
248+
245249
@JsonIgnore
246250
public Bind[] getBinds() {
247251
return (binds == null) ? new Bind[0] : binds.getBinds();
@@ -531,6 +535,12 @@ public HostConfig withBinds(Binds binds) {
531535
return this;
532536
}
533537

538+
public HostConfig withBinds(Bind... binds) {
539+
checkNotNull(binds, "binds was not specified");
540+
setBinds(binds);
541+
return this;
542+
}
543+
534544
/**
535545
* @see #blkioDeviceReadBps
536546
*/
@@ -583,15 +593,15 @@ public HostConfig withBlkioWeightDevice(List<Object> blkioWeightDevice) {
583593
* Add linux <a href="http://man7.org/linux/man-pages/man7/capabilities.7.html">kernel capability</a> to the container. For example:
584594
* adding {@link Capability#MKNOD} allows the container to create special files using the 'mknod' command.
585595
*/
586-
public HostConfig withCapAdd(Capability[] capAdd) {
596+
public HostConfig withCapAdd(Capability... capAdd) {
587597
this.capAdd = capAdd;
588598
return this;
589599
}
590600

591601
/**
592602
* @see #capDrop
593603
*/
594-
public HostConfig withCapDrop(Capability[] capDrop) {
604+
public HostConfig withCapDrop(Capability... capDrop) {
595605
this.capDrop = capDrop;
596606
return this;
597607
}
@@ -660,7 +670,7 @@ public HostConfig withDevices(List<Device> devices) {
660670
/**
661671
* @see #devices
662672
*/
663-
public HostConfig withDevices(Device[] devices) {
673+
public HostConfig withDevices(Device... devices) {
664674
this.devices = devices;
665675
return this;
666676
}
@@ -676,7 +686,7 @@ public HostConfig withDiskQuota(Long diskQuota) {
676686
/**
677687
* @see #dns
678688
*/
679-
public HostConfig withDns(String[] dns) {
689+
public HostConfig withDns(String... dns) {
680690
this.dns = dns;
681691
return this;
682692
}
@@ -689,7 +699,7 @@ public HostConfig withDns(List<String> dns) {
689699
/**
690700
* @see #dnsSearch
691701
*/
692-
public HostConfig withDnsSearch(String[] dnsSearch) {
702+
public HostConfig withDnsSearch(String... dnsSearch) {
693703
this.dnsSearch = dnsSearch;
694704
return this;
695705
}
@@ -702,7 +712,7 @@ public HostConfig withDnsSearch(List<String> dnsSearch) {
702712
/**
703713
* @see #extraHosts
704714
*/
705-
public HostConfig withExtraHosts(String[] extraHosts) {
715+
public HostConfig withExtraHosts(String... extraHosts) {
706716
this.extraHosts = extraHosts;
707717
return this;
708718
}
@@ -734,6 +744,12 @@ public HostConfig withLinks(List<Link> links) {
734744
return this;
735745
}
736746

747+
public HostConfig withLinks(Link... links) {
748+
checkNotNull(links, "links was not specified");
749+
setLinks(links);
750+
return this;
751+
}
752+
737753
/**
738754
* @see #logConfig
739755
*/
@@ -993,8 +1009,6 @@ public HostConfig withIsolation(String isolation) {
9931009
return this;
9941010
}
9951011

996-
// end of auto-generated
997-
9981012
@Override
9991013
public String toString() {
10001014
return ToStringBuilder.reflectionToString(this);

src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java

+54-24
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
import static com.github.dockerjava.api.model.Capability.MKNOD;
5050
import static com.github.dockerjava.api.model.Capability.NET_ADMIN;
51+
import static com.github.dockerjava.api.model.HostConfig.newHostConfig;
5152
import static com.github.dockerjava.cmd.CmdIT.FactoryType.JERSEY;
5253
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23;
5354
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_24;
@@ -160,7 +161,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
160161
CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
161162
.withCmd("sleep", "9999")
162163
.withName(container1Name)
163-
.withBinds(bind1, bind2)
164+
.withHostConfig(newHostConfig()
165+
.withBinds(bind1, bind2))
164166
.exec();
165167

166168
LOG.info("Created container1 {}", container1.toString());
@@ -175,7 +177,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
175177
// create a second container with volumes from first container
176178
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
177179
.withCmd("sleep", "9999")
178-
.withVolumesFrom(new VolumesFrom(container1Name))
180+
.withHostConfig(newHostConfig()
181+
.withVolumesFrom(new VolumesFrom(container1Name)))
179182
.exec();
180183

181184
LOG.info("Created container2 {}", container2.toString());
@@ -285,7 +288,10 @@ public void createContainerWithLink() throws DockerException {
285288
assertThat(inspectContainerResponse1.getState().getRunning(), is(true));
286289

287290
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withName(containerName2)
288-
.withCmd("env").withLinks(new Link(containerName1, "container1Link")).exec();
291+
.withCmd("env")
292+
.withHostConfig(newHostConfig()
293+
.withLinks(new Link(containerName1, "container1Link")))
294+
.exec();
289295
LOG.info("Created container {}", container2.toString());
290296
assertThat(container2.getId(), not(isEmptyString()));
291297

@@ -299,7 +305,8 @@ public void createContainerWithLink() throws DockerException {
299305
public void createContainerWithMemorySwappiness() throws DockerException {
300306
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
301307
.withCmd("sleep", "9999")
302-
.withMemorySwappiness(42)
308+
.withHostConfig(newHostConfig()
309+
.withMemorySwappiness(42))
303310
.exec();
304311
assertThat(container.getId(), not(isEmptyString()));
305312
LOG.info("Created container {}", container.toString());
@@ -328,8 +335,9 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
328335
assertNotNull(createNetworkResponse.getId());
329336

330337
CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
331-
.withNetworkMode(networkName)
332338
.withCmd("sleep", "9999")
339+
.withHostConfig(newHostConfig()
340+
.withNetworkMode(networkName))
333341
.withName(containerName1)
334342
.exec();
335343

@@ -343,10 +351,12 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
343351
assertThat(inspectContainerResponse1.getState().getRunning(), is(true));
344352

345353
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
346-
.withNetworkMode(networkName)
354+
.withHostConfig(newHostConfig()
355+
.withNetworkMode(networkName)
356+
.withLinks(new Link(containerName1, containerName1 + "Link"))
357+
)
347358
.withName(containerName2)
348359
.withCmd("env")
349-
.withLinks(new Link(containerName1, containerName1 + "Link"))
350360
.exec();
351361

352362
LOG.info("Created container {}", container2.toString());
@@ -377,10 +387,11 @@ public void createContainerWithCustomIp() throws DockerException {
377387
assertNotNull(createNetworkResponse.getId());
378388

379389
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
380-
.withNetworkMode(networkName)
381390
.withCmd("sleep", "9999")
391+
.withHostConfig(newHostConfig()
392+
.withNetworkMode(networkName))
382393
.withName(containerName1)
383-
.withIpv4Address(subnetPrefix +".100")
394+
.withIpv4Address(subnetPrefix + ".100")
384395
.exec();
385396

386397
assertThat(container.getId(), not(isEmptyString()));
@@ -410,8 +421,9 @@ public void createContainerWithAlias() throws DockerException {
410421
assertNotNull(createNetworkResponse.getId());
411422

412423
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
413-
.withNetworkMode(networkName)
414424
.withCmd("sleep", "9999")
425+
.withHostConfig(newHostConfig()
426+
.withNetworkMode(networkName))
415427
.withName(containerName1)
416428
.withAliases("server" + dockerRule.getKind())
417429
.exec();
@@ -430,8 +442,11 @@ public void createContainerWithAlias() throws DockerException {
430442
@Test
431443
public void createContainerWithCapAddAndCapDrop() throws DockerException {
432444

433-
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCapAdd(NET_ADMIN)
434-
.withCapDrop(MKNOD).exec();
445+
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
446+
.withHostConfig(newHostConfig()
447+
.withCapAdd(NET_ADMIN)
448+
.withCapDrop(MKNOD))
449+
.exec();
435450

436451
LOG.info("Created container {}", container.toString());
437452

@@ -451,7 +466,9 @@ public void createContainerWithDns() throws DockerException {
451466
String anotherDnsServer = "8.8.4.4";
452467

453468
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
454-
.withDns(aDnsServer, anotherDnsServer).exec();
469+
.withHostConfig(newHostConfig()
470+
.withDns(aDnsServer, anotherDnsServer))
471+
.exec();
455472

456473
LOG.info("Created container {}", container.toString());
457474

@@ -487,7 +504,9 @@ public void createContainerWithExtraHosts() throws DockerException {
487504

488505
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
489506
.withName("containerextrahosts" + dockerRule.getKind())
490-
.withExtraHosts(extraHosts).exec();
507+
.withHostConfig(newHostConfig()
508+
.withExtraHosts(extraHosts))
509+
.exec();
491510

492511
LOG.info("Created container {}", container.toString());
493512

@@ -503,7 +522,8 @@ public void createContainerWithExtraHosts() throws DockerException {
503522
public void createContainerWithDevices() throws DockerException {
504523

505524
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
506-
.withDevices(new Device("rwm", "/dev/nulo", "/dev/zero")).exec();
525+
.withHostConfig(newHostConfig()
526+
.withDevices(new Device("rwm", "/dev/nulo", "/dev/zero"))).exec();
507527

508528
LOG.info("Created container {}", container.toString());
509529

@@ -517,7 +537,7 @@ public void createContainerWithDevices() throws DockerException {
517537

518538
@Test
519539
public void createContainerWithPortBindings() throws DockerException {
520-
int baseport = getFactoryType() == FactoryType.JERSEY? 11000: 12000;
540+
int baseport = getFactoryType() == FactoryType.JERSEY ? 11000 : 12000;
521541

522542
ExposedPort tcp22 = ExposedPort.tcp(22);
523543
ExposedPort tcp23 = ExposedPort.tcp(23);
@@ -528,7 +548,8 @@ public void createContainerWithPortBindings() throws DockerException {
528548
portBindings.bind(tcp23, Binding.bindPort(baseport + 24));
529549

530550
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
531-
.withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec();
551+
.withExposedPorts(tcp22, tcp23).withHostConfig(newHostConfig()
552+
.withPortBindings(portBindings)).exec();
532553

533554
LOG.info("Created container {}", container.toString());
534555

@@ -581,7 +602,8 @@ public void createContainerWithLinking() throws DockerException {
581602

582603
CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
583604
.withName(containerName2)
584-
.withLinks(new Link(containerName1, containerName1 + "Link")).exec();
605+
.withHostConfig(newHostConfig()
606+
.withLinks(new Link(containerName1, containerName1 + "Link"))).exec();
585607

586608
LOG.info("Created container2 {}", container2.toString());
587609
assertThat(container2.getId(), not(isEmptyString()));
@@ -608,7 +630,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
608630
RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5);
609631

610632
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
611-
.withRestartPolicy(restartPolicy).exec();
633+
.withHostConfig(newHostConfig()
634+
.withRestartPolicy(restartPolicy)).exec();
612635

613636
LOG.info("Created container {}", container.toString());
614637

@@ -623,7 +646,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
623646
public void createContainerWithPidMode() throws DockerException {
624647

625648
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
626-
.withPidMode("host").exec();
649+
.withHostConfig(newHostConfig()
650+
.withPidMode("host")).exec();
627651

628652
LOG.info("Created container {}", container.toString());
629653

@@ -644,7 +668,8 @@ public void createContainerWithPidMode() throws DockerException {
644668
public void createContainerWithNetworkMode() throws DockerException {
645669

646670
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true")
647-
.withNetworkMode("host").exec();
671+
.withHostConfig(newHostConfig()
672+
.withNetworkMode("host")).exec();
648673

649674
LOG.info("Created container {}", container.toString());
650675

@@ -677,7 +702,8 @@ public void createContainerWithULimits() throws DockerException {
677702

678703
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
679704
.withName(containerName)
680-
.withUlimits(ulimits).exec();
705+
.withHostConfig(newHostConfig()
706+
.withUlimits(ulimits)).exec();
681707

682708
LOG.info("Created container {}", container.toString());
683709

@@ -720,7 +746,10 @@ public void createContainerWithLabels() throws DockerException {
720746
public void createContainerWithLogConfig() throws DockerException {
721747

722748
LogConfig logConfig = new LogConfig(LogConfig.LoggingType.NONE, null);
723-
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withLogConfig(logConfig).exec();
749+
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
750+
.withHostConfig(newHostConfig()
751+
.withLogConfig(logConfig))
752+
.exec();
724753

725754
LOG.info("Created container {}", container.toString());
726755

@@ -789,7 +818,8 @@ public void onNext(Frame item) {
789818
@Test
790819
public void createContainerWithCgroupParent() throws DockerException {
791820
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
792-
.withCgroupParent("/parent").exec();
821+
.withHostConfig(newHostConfig()
822+
.withCgroupParent("/parent")).exec();
793823

794824
LOG.info("Created container {}", container.toString());
795825

src/test/java/com/github/dockerjava/cmd/DisconnectFromNetworkCmdIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.github.dockerjava.api.model.Network;
66
import org.junit.Test;
77

8+
import static com.github.dockerjava.api.model.HostConfig.newHostConfig;
89
import static com.github.dockerjava.junit.DockerAssume.assumeNotSwarm;
910
import static org.junit.Assert.assertFalse;
1011
import static org.junit.Assert.assertTrue;
@@ -40,8 +41,9 @@ public void forceDisconnectFromNetwork() throws InterruptedException {
4041
CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd().withName("testNetwork2" + dockerRule.getKind()).exec();
4142

4243
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
43-
.withNetworkMode("testNetwork2" + dockerRule.getKind())
4444
.withCmd("sleep", "9999")
45+
.withHostConfig(newHostConfig()
46+
.withNetworkMode("testNetwork2" + dockerRule.getKind()))
4547
.exec();
4648

4749
dockerRule.getClient().startContainerCmd(container.getId()).exec();

src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.dockerjava.api.command.InspectContainerResponse;
55
import com.github.dockerjava.api.model.Bind;
66
import com.github.dockerjava.api.model.Container;
7+
import com.github.dockerjava.api.model.HostConfig;
78
import com.github.dockerjava.api.model.Volume;
89
import com.github.dockerjava.core.command.PullImageResultCallback;
910
import com.github.dockerjava.core.command.WaitContainerResultCallback;
@@ -257,7 +258,9 @@ public void testVolumeFilter() throws Exception {
257258

258259
id = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
259260
.withLabels(testLabel)
260-
.withBinds(new Bind("TestFilterVolume", new Volume("/test")))
261+
.withHostConfig(HostConfig.newHostConfig()
262+
.withBinds(new Bind("TestFilterVolume", new Volume("/test")))
263+
)
261264
.exec()
262265
.getId();
263266

@@ -285,7 +288,9 @@ public void testNetworkFilter() throws Exception {
285288

286289
id = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
287290
.withLabels(testLabel)
288-
.withNetworkMode("TestFilterNetwork")
291+
.withHostConfig(HostConfig.newHostConfig()
292+
.withNetworkMode("TestFilterNetwork")
293+
)
289294
.exec()
290295
.getId();
291296

0 commit comments

Comments
 (0)