|
| 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 | +} |
0 commit comments