File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed
main/java/com/amihaiemil/docker
test/java/com/amihaiemil/docker Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 25
25
*/
26
26
package com .amihaiemil .docker ;
27
27
28
+ import org .apache .http .client .HttpClient ;
29
+
28
30
import java .io .IOException ;
29
31
30
32
/**
@@ -79,4 +81,19 @@ public interface Docker {
79
81
* @return Swarm.
80
82
*/
81
83
Swarm swarm ();
84
+
85
+ /**
86
+ * The underlying, immutable, Apache HttpClient.<br><br>
87
+ *
88
+ * Use this method to fetch the underlying HttpClient and perform your own
89
+ * HTTP requests, in case the API is missing the desired method.<br><br>
90
+ *
91
+ * Usage in any other scenario is discouraged. Try to find the desired
92
+ * method before using this. Also, if the method is missing, open an
93
+ * Issue at https://www.github.com/amihaiemil/docker-java-api, maybe
94
+ * it can be implemented and released quickly.
95
+ *
96
+ * @return The underlying HttpClient.
97
+ */
98
+ HttpClient httpClient ();
82
99
}
Original file line number Diff line number Diff line change @@ -118,4 +118,9 @@ public final Swarm swarm() {
118
118
this
119
119
);
120
120
}
121
+
122
+ @ Override
123
+ public HttpClient httpClient () {
124
+ return this .client ;
125
+ }
121
126
}
Original file line number Diff line number Diff line change 27
27
28
28
import com .amihaiemil .docker .mock .AssertRequest ;
29
29
import com .amihaiemil .docker .mock .Response ;
30
+ import org .apache .http .client .HttpClient ;
30
31
import org .hamcrest .MatcherAssert ;
31
32
import org .hamcrest .Matchers ;
32
33
import org .junit .Test ;
@@ -126,4 +127,21 @@ public void returnsImages() {
126
127
Matchers .notNullValue ()
127
128
);
128
129
}
130
+
131
+ /**
132
+ * LocalDocker can return its HttpClient.
133
+ */
134
+ @ Test
135
+ public void returnsHttpClient () {
136
+ MatcherAssert .assertThat (
137
+ new LocalDocker (
138
+ new File ("/var/run/docker.sock" )
139
+ ).httpClient (),
140
+ Matchers .allOf (
141
+ Matchers .notNullValue (),
142
+ Matchers .instanceOf (HttpClient .class ),
143
+ Matchers .instanceOf (UnixHttpClient .class )
144
+ )
145
+ );
146
+ }
129
147
}
Original file line number Diff line number Diff line change 27
27
28
28
import com .amihaiemil .docker .mock .AssertRequest ;
29
29
import com .amihaiemil .docker .mock .Response ;
30
+
30
31
import java .net .URI ;
31
32
import org .apache .http .HttpStatus ;
32
33
import org .apache .http .client .HttpClient ;
@@ -121,4 +122,23 @@ public void returnsImages() {
121
122
Matchers .notNullValue ()
122
123
);
123
124
}
125
+
126
+ /**
127
+ * LocalDocker can return its HttpClient.
128
+ */
129
+ @ Test
130
+ public void returnsHttpClient () {
131
+ final HttpClient client = Mockito .mock (HttpClient .class );
132
+ MatcherAssert .assertThat (
133
+ new RemoteDocker (
134
+ client ,
135
+ URI .create ("http://localhost" )
136
+ ).httpClient (),
137
+ Matchers .allOf (
138
+ Matchers .notNullValue (),
139
+ Matchers .instanceOf (HttpClient .class ),
140
+ Matchers .sameInstance (client )
141
+ )
142
+ );
143
+ }
124
144
}
You can’t perform that action at this time.
0 commit comments