Skip to content

Commit 437414f

Browse files
committed
Merge branch 'pr-381' into upstream-master-381
2 parents 58d9407 + fb565f1 commit 437414f

File tree

8 files changed

+121
-10
lines changed

8 files changed

+121
-10
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
public class PullResponseItem extends ResponseItem {
1111

1212
private static final long serialVersionUID = -2575482839766823293L;
13+
private static final String LEGACY_REGISTRY = "this image was pulled from a legacy registry";
14+
private static final String DOWNLOADED_NEWER_IMAGE = "Downloaded newer image";
15+
private static final String IMAGE_UP_TO_DATE = "Image is up to date";
16+
private static final String DOWNLOAD_COMPLETE = "Download complete";
1317

1418
/**
1519
* Returns whether the status indicates a successful pull operation
@@ -22,8 +26,9 @@ public boolean isPullSuccessIndicated() {
2226
return false;
2327
}
2428

25-
return (getStatus().contains("Download complete") || getStatus().contains("Image is up to date") || getStatus()
26-
.contains("Downloaded newer image"));
29+
return (getStatus().contains(DOWNLOAD_COMPLETE) || getStatus().contains(IMAGE_UP_TO_DATE)
30+
|| getStatus().contains(DOWNLOADED_NEWER_IMAGE)
31+
|| getStatus().contains(LEGACY_REGISTRY));
2732
}
2833

2934
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2015, Zach Marshall.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.dockerjava.api.model;
17+
18+
import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
19+
import static org.testng.Assert.assertFalse;
20+
import static org.testng.Assert.assertTrue;
21+
22+
import java.io.IOException;
23+
24+
import org.testng.annotations.Test;
25+
26+
/**
27+
* Tests logic of PullResponseItem's error/success handling by simulating a JSON response.
28+
*
29+
* @author Zach Marshall
30+
*/
31+
public class PullResponseItemTest {
32+
@Test
33+
public void pullNewerImage() throws IOException {
34+
PullResponseItem response =
35+
testRoundTrip(PullResponseJSONSamples.pullImageResponse_newerImage, PullResponseItem.class);
36+
assertTrue(response.isPullSuccessIndicated());
37+
assertFalse(response.isErrorIndicated());
38+
}
39+
40+
@Test
41+
public void pullUpToDate() throws IOException {
42+
PullResponseItem response =
43+
testRoundTrip(PullResponseJSONSamples.pullImageResponse_upToDate, PullResponseItem.class);
44+
assertTrue(response.isPullSuccessIndicated());
45+
assertFalse(response.isErrorIndicated());
46+
}
47+
48+
@Test
49+
public void pullLegacyRegistry() throws IOException {
50+
PullResponseItem response =
51+
testRoundTrip(PullResponseJSONSamples.pullImageResponse_legacy, PullResponseItem.class);
52+
assertTrue(response.isPullSuccessIndicated());
53+
assertFalse(response.isErrorIndicated());
54+
}
55+
56+
@Test
57+
public void pullAndEncounterError() throws IOException {
58+
PullResponseItem response =
59+
testRoundTrip(PullResponseJSONSamples.pullImageResponse_error, PullResponseItem.class);
60+
assertFalse(response.isPullSuccessIndicated());
61+
assertTrue(response.isErrorIndicated());
62+
}
63+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2015 Zach Marshall.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.dockerjava.api.model;
17+
18+
import com.github.dockerjava.test.serdes.JSONResourceRef;
19+
20+
/**
21+
* Enumeration for the available pull response statuses.
22+
*
23+
* @author Zach Marshall
24+
*/
25+
public enum PullResponseJSONSamples implements JSONResourceRef {
26+
pullImageResponse_legacy, pullImageResponse_error, pullImageResponse_newerImage, pullImageResponse_upToDate;
27+
28+
@Override
29+
public String getFileName() {
30+
return this + ".json";
31+
}
32+
33+
@Override
34+
public Class<?> getResourceClass() {
35+
return PullResponseJSONSamples.class;
36+
}
37+
}

src/test/java/com/github/dockerjava/test/serdes/JSONTestHelper.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525

2626
import com.fasterxml.jackson.databind.JsonNode;
2727
import com.fasterxml.jackson.databind.ObjectMapper;
28-
import com.github.dockerjava.api.command.CommandJSONSamples;
2928

3029
/**
31-
* Provides helper methods for serialization-deserialization tests
32-
*
30+
* Provides helper methods for serialization-deserialization tests.
31+
*
32+
* <p><b>TODO</b>: Create helper that loads json files from simple folder
33+
* structure using a type, version number, and name.</p>
34+
*
3335
* @author Oleg Nenashev
34-
* @since TODO
3536
*/
3637
public class JSONTestHelper {
3738

@@ -45,11 +46,12 @@ public class JSONTestHelper {
4546
* JSON Conversion error
4647
*/
4748
public static String readString(JSONResourceRef resource) throws IOException {
48-
InputStream istream = CommandJSONSamples.class.getResourceAsStream(resource.getFileName());
49-
if (istream == null) {
50-
throw new IOException("Cannot retrieve resource " + resource.getFileName());
49+
try (InputStream istream = resource.getResourceClass().getResourceAsStream(resource.getFileName())) {
50+
if (istream == null) {
51+
throw new IOException("Cannot retrieve resource " + resource.getFileName());
52+
}
53+
return IOUtils.toString(istream, "UTF-8");
5154
}
52-
return IOUtils.toString(istream, "UTF-8");
5355
}
5456

5557
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"errorDetail":{"message":"Error: image cccxxx/xxxccc:latest not found"},"error":"Error: image cccxxx/xxxccc:latest not found"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status":"docker.com/xxxxcv/ccccxx: this image was pulled from a legacy registry. Important: This registry version will not be supported in future versions of docker."}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status":"Downloaded newer image for docker.com/xxxxcv/ccccxx"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status":"Image is up to date for docker.com/xxxxcv/ccccxx"}

0 commit comments

Comments
 (0)