Skip to content

Commit 6c0f34d

Browse files
committed
amihaiemil#144 started FilteredImages
1 parent c30d31b commit 6c0f34d

File tree

4 files changed

+96
-31
lines changed

4 files changed

+96
-31
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright (c) 2018, Mihai Emil Andronache
3+
* All rights reserved.
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
* 1)Redistributions of source code must retain the above copyright notice,
7+
* this list of conditions and the following disclaimer.
8+
* 2)Redistributions in binary form must reproduce the above copyright notice,
9+
* this list of conditions and the following disclaimer in the documentation
10+
* and/or other materials provided with the distribution.
11+
* 3)Neither the name of docker-java-api nor the names of its
12+
* contributors may be used to endorse or promote products derived from
13+
* this software without specific prior written permission.
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
* POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
package com.amihaiemil.docker;
27+
28+
import org.apache.http.client.HttpClient;
29+
import org.apache.http.client.methods.HttpGet;
30+
import java.net.URI;
31+
import java.util.Iterator;
32+
33+
/**
34+
* These are some Images after applying a filter.
35+
* @author Mihai Andronache (amihaiemil@gmail.com)
36+
* @version $Id$
37+
* @since 0.0.3
38+
*/
39+
final class FilteredImages extends RtImages {
40+
41+
/**
42+
* Ctor.
43+
* @param client The http client.
44+
* @param uri The URI for this Images API.
45+
* @param dkr The docker entry point.
46+
* @checkstyle ParameterNumber (10 lines)
47+
*/
48+
FilteredImages(final HttpClient client, final URI uri, final Docker dkr) {
49+
super(client, uri, dkr);
50+
}
51+
52+
@Override
53+
public Iterator<Image> iterator() {
54+
return new ResourcesIterator<>(
55+
super.client(),
56+
new HttpGet(super.baseUri().toString().concat("/json")),
57+
img -> new RtImage(
58+
img,
59+
super.client(),
60+
URI.create(
61+
super.baseUri().toString() + "/" + img.getString("Id")
62+
),
63+
super.docker()
64+
)
65+
);
66+
}
67+
}

src/main/java/com/amihaiemil/docker/RtDocker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public final Containers containers() {
7979

8080
@Override
8181
public final Images images() {
82-
return new RtImages(
82+
return new FilteredImages(
8383
this.client,
8484
URI.create(this.baseUri.toString() + "/images"),
8585
this

src/main/java/com/amihaiemil/docker/RtImages.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
import java.io.IOException;
2929
import java.net.URI;
3030
import java.net.URL;
31-
import java.util.Iterator;
3231
import org.apache.http.HttpStatus;
3332
import org.apache.http.client.HttpClient;
34-
import org.apache.http.client.methods.HttpGet;
3533
import org.apache.http.client.methods.HttpPost;
3634

3735
import javax.json.Json;
@@ -42,14 +40,14 @@
4240
* @version $Id$
4341
* @since 0.0.1
4442
*/
45-
final class RtImages implements Images {
43+
abstract class RtImages implements Images {
4644
/**
4745
* Apache HttpClient which sends the requests.
4846
*/
4947
private final HttpClient client;
5048

5149
/**
52-
* Base URI.
50+
* Base URI for Images API.
5351
*/
5452
private final URI baseUri;
5553

@@ -63,6 +61,7 @@ final class RtImages implements Images {
6361
* @param client The http client.
6462
* @param uri The URI for this Images API.
6563
* @param dkr The docker entry point.
64+
* @checkstyle ParameterNumber (10 lines)
6665
*/
6766
RtImages(final HttpClient client, final URI uri, final Docker dkr) {
6867
this.client = client;
@@ -123,25 +122,24 @@ public void prune() throws IOException, UnexpectedResponseException {
123122
}
124123
}
125124

126-
@Override
127-
public Iterator<Image> iterator() {
128-
return new ResourcesIterator<>(
129-
this.client,
130-
new HttpGet(this.baseUri.toString().concat("/json")),
131-
json-> new RtImage(
132-
json,
133-
this.client,
134-
URI.create(
135-
this.baseUri.toString() + "/" + json.getString("Id")
136-
),
137-
this.docker
138-
)
139-
);
140-
}
141-
142125
@Override
143126
public Docker docker() {
144127
return this.docker;
145128
}
146-
129+
130+
/**
131+
* Get the (protected) HttpClient for subclasses.
132+
* @return HttpClient.
133+
*/
134+
HttpClient client() {
135+
return this.client;
136+
}
137+
138+
/**
139+
* Get the (protected) base URI for subclasses.
140+
* @return URI.
141+
*/
142+
URI baseUri() {
143+
return this.baseUri;
144+
}
147145
}

src/test/java/com/amihaiemil/docker/RtImagesTestCase.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final class RtImagesTestCase {
5757
@Test
5858
public void iteratesImages() {
5959
final AtomicInteger count = new AtomicInteger();
60-
new RtImages(
60+
new FilteredImages(
6161
new AssertRequest(
6262
new Response(
6363
HttpStatus.SC_OK,
@@ -87,7 +87,7 @@ public void iteratesImages() {
8787
@Test
8888
public void iteratesZeroImages() throws Exception {
8989
final AtomicInteger count = new AtomicInteger();
90-
new RtImages(
90+
new FilteredImages(
9191
new AssertRequest(
9292
new Response(
9393
HttpStatus.SC_OK,
@@ -109,7 +109,7 @@ public void iteratesZeroImages() throws Exception {
109109
*/
110110
@Test(expected = UnexpectedResponseException.class)
111111
public void iterateFailsIfResponseIs500() throws Exception {
112-
new RtImages(
112+
new FilteredImages(
113113
new AssertRequest(
114114
new Response(HttpStatus.SC_INTERNAL_SERVER_ERROR)
115115
),
@@ -127,7 +127,7 @@ public void iterateFailsIfResponseIs500() throws Exception {
127127
*/
128128
@Test
129129
public void createSetsGivenParameters() throws Exception {
130-
new RtImages(
130+
new FilteredImages(
131131
new AssertRequest(
132132
new Response(HttpStatus.SC_OK),
133133
new Condition(
@@ -154,7 +154,7 @@ public void createSetsGivenParameters() throws Exception {
154154
*/
155155
@Test(expected = UnexpectedResponseException.class)
156156
public void createErrorOnStatus404() throws Exception {
157-
new RtImages(
157+
new FilteredImages(
158158
new AssertRequest(
159159
new Response(HttpStatus.SC_NOT_FOUND)
160160
),
@@ -170,7 +170,7 @@ public void createErrorOnStatus404() throws Exception {
170170
*/
171171
@Test(expected = UnexpectedResponseException.class)
172172
public void createErrorOnStatus500() throws Exception {
173-
new RtImages(
173+
new FilteredImages(
174174
new AssertRequest(
175175
new Response(HttpStatus.SC_INTERNAL_SERVER_ERROR)
176176
),
@@ -186,7 +186,7 @@ public void createErrorOnStatus500() throws Exception {
186186
*/
187187
@Test
188188
public void prunesOk() throws Exception {
189-
new RtImages(
189+
new FilteredImages(
190190
new AssertRequest(
191191
new Response(HttpStatus.SC_OK),
192192
new Condition(
@@ -211,7 +211,7 @@ public void prunesOk() throws Exception {
211211
*/
212212
@Test(expected = UnexpectedResponseException.class)
213213
public void pruneThrowsErrorOnResponse500() throws Exception {
214-
new RtImages(
214+
new FilteredImages(
215215
new AssertRequest(
216216
new Response(HttpStatus.SC_INTERNAL_SERVER_ERROR)
217217
),
@@ -226,7 +226,7 @@ public void pruneThrowsErrorOnResponse500() throws Exception {
226226
@Test
227227
public void returnsDocker() {
228228
MatcherAssert.assertThat(
229-
new RtImages(
229+
new FilteredImages(
230230
new AssertRequest(
231231
new Response(
232232
HttpStatus.SC_OK,

0 commit comments

Comments
 (0)