Add mapping annotations to custom constructor (#1047) · kylechase/docker-java@70d9cab · GitHub
Skip to content

Commit 70d9cab

Browse files
Felix MaiKostyaSha
authored andcommitted
Add mapping annotations to custom constructor (docker-java#1047)
* Add mapping annotations to custom constructor * Annotate Volume's custom constructor * Add simple test and appropriate data * Fix docker-java#1046 * Add annotated factory method for inconsistent JSON * Enable to handle both JSON responses (w/ and w/o path key) * Add additional test case and data * Rename test data file due to alternative version * Add JavaDocs describing why we need both single-argument constructor and factory method * Fix docker-java#1046
1 parent 3993c60 commit 70d9cab

5 files changed

Lines changed: 400 additions & 1 deletion

File tree

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

Lines changed: 26 additions & 0 deletions

src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
*/
2525
public enum CommandJSONSamples implements JSONResourceRef {
2626

27-
inspectContainerResponse_full, inspectContainerResponse_full_1_21, inspectContainerResponse_empty;
27+
inspectContainerResponse_full,
28+
inspectContainerResponse_full_1_21,
29+
inspectContainerResponse_full_1_26a,
30+
inspectContainerResponse_full_1_26b,
31+
inspectContainerResponse_empty;
2832

2933
@Override
3034
public String getFileName() {

src/test/java/com/github/dockerjava/api/command/InspectContainerResponseTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
import com.fasterxml.jackson.databind.JavaType;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.github.dockerjava.api.model.Volume;
2021
import com.github.dockerjava.core.RemoteApiVersion;
2122
import org.junit.Test;
2223

2324
import java.io.IOException;
25+
import java.util.List;
2426

2527
import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip;
2628
import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
@@ -93,6 +95,38 @@ public void roundTrip_1_21_full() throws IOException {
9395
assertThat(state.getError(), isEmptyString());
9496
}
9597

98+
@Test
99+
public void roundTrip_1_26a_full() throws IOException {
100+
InspectContainerResponse[] responses = testRoundTrip(CommandJSONSamples.inspectContainerResponse_full_1_26a,
101+
InspectContainerResponse[].class);
102+
103+
assertEquals(1, responses.length);
104+
final InspectContainerResponse response = responses[0];
105+
106+
final List<InspectContainerResponse.Mount> mounts = response.getMounts();
107+
assertEquals(mounts.size(), 1);
108+
109+
final InspectContainerResponse.Mount mount = mounts.get(0);
110+
final Volume volume = mount.getDestination();
111+
assertEquals(volume.getPath(), "/var/lib/postgresql/data");
112+
}
113+
114+
@Test
115+
public void roundTrip_1_26b_full() throws IOException {
116+
InspectContainerResponse[] responses = testRoundTrip(CommandJSONSamples.inspectContainerResponse_full_1_26b,
117+
InspectContainerResponse[].class);
118+
119+
assertEquals(1, responses.length);
120+
final InspectContainerResponse response = responses[0];
121+
122+
final List<InspectContainerResponse.Mount> mounts = response.getMounts();
123+
assertEquals(mounts.size(), 1);
124+
125+
final InspectContainerResponse.Mount mount = mounts.get(0);
126+
final Volume volume = mount.getDestination();
127+
assertEquals(volume.getPath(), "/srv/test");
128+
}
129+
96130
@Test
97131
public void roundTrip_empty() throws IOException {
98132
testRoundTrip(CommandJSONSamples.inspectContainerResponse_empty, InspectContainerResponse[].class);
Lines changed: 155 additions & 0 deletions

0 commit comments

Comments
 (0)