Skip to content

Commit 667226e

Browse files
committed
Updating head object response generation in java for 4.1 API
1 parent 974ef88 commit 667226e

File tree

6 files changed

+75
-27
lines changed

6 files changed

+75
-27
lines changed

ds3-autogen-java/src/main/java/com/spectralogic/ds3autogen/java/generators/responsemodels/HeadObjectResponseGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public ImmutableList<Arguments> toParamList(final ImmutableList<Ds3ResponseCode>
3636
final ImmutableList<Arguments> params = ImmutableList.of(
3737
new Arguments("Metadata", "Metadata"),
3838
new Arguments("long", "ObjectSize"),
39-
new Arguments("Status", "Status"));
39+
new Arguments("Status", "Status"),
40+
new Arguments("ChecksumType.Type", "BlobChecksumType"),
41+
new Arguments("ImmutableMap<Long, String>", "BlobChecksums"));
4042

4143
return ImmutableList.sortedCopyOf(new CustomArgumentComparator(), params);
4244
}
@@ -49,6 +51,7 @@ public ImmutableSet<String> getAllImports(final Ds3Request ds3Request) {
4951
return ImmutableSet.of(
5052
getParentImport(),
5153
"com.spectralogic.ds3client.networking.Metadata",
52-
"com.spectralogic.ds3client.models.ChecksumType");
54+
"com.spectralogic.ds3client.models.ChecksumType",
55+
"com.google.common.collect.ImmutableMap");
5356
}
5457
}

ds3-autogen-java/src/main/java/com/spectralogic/ds3autogen/java/generators/responseparser/HeadObjectParserGenerator.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.spectralogic.ds3autogen.java.models.ResponseCode;
2121

2222
import static com.spectralogic.ds3autogen.java.utils.ResponseAndParserUtils.getResponseCodes;
23+
import static com.spectralogic.ds3autogen.utils.Helper.indent;
2324

2425
/**
2526
* Response parser generator for Head Object command
@@ -42,17 +43,25 @@ public ImmutableList<ResponseCode> toResponseCodeList(
4243
throw new IllegalArgumentException("Does not contain expected response codes: " + EXPECTED_RESPONSE_CODES.toString());
4344
}
4445

45-
final ResponseCode code200 = new ResponseCode(200, toReturnCode(responseName, "EXISTS"));
46-
final ResponseCode code404 = new ResponseCode(404, toReturnCode(responseName, "DOESNTEXIST"));
46+
final ResponseCode code200 = new ResponseCode(200, toExistsReturnCode(responseName));
47+
final ResponseCode code404 = new ResponseCode(404, toDoesntExistReturnCode(responseName));
4748

4849
return ImmutableList.of(code200, code404);
4950
}
5051

5152
/**
52-
* Gets the java code for returning the response handler with the specified status,
53-
* metadata, and object size
53+
* Gets the java code for returning the response handler for an object that exists
5454
*/
55-
protected static String toReturnCode(final String responseName, final String status) {
56-
return "return new " + responseName + "(metadata, objectSize, " + responseName + ".Status." + status + ", this.getChecksum(), this.getChecksumType());\n";
55+
protected static String toExistsReturnCode(final String responseName) {
56+
return "final ChecksumType.Type blobChecksumType = getBlobChecksumType(response.getHeaders());\n" +
57+
indent(4) + "final ImmutableMap<Long, String> blobChecksumMap = getBlobChecksumMap(response.getHeaders());\n" +
58+
indent(4) + "return new " + responseName + "(blobChecksumMap, blobChecksumType, metadata, objectSize, " + responseName + ".Status.EXISTS, this.getChecksum(), this.getChecksumType());\n";
59+
}
60+
61+
/**
62+
* Gets the java code for returning the response handler for an object that does not exist
63+
*/
64+
protected static String toDoesntExistReturnCode(final String responseName) {
65+
return "return new " + responseName + "(ImmutableMap.of(), ChecksumType.Type.NONE, metadata, objectSize, " + responseName + ".Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());\n";
5766
}
5867
}

ds3-autogen-java/src/main/resources/tmpls/java/responseparser/head_object_parser.ftl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ package ${packageName};
44

55
import com.spectralogic.ds3client.commands.interfaces.MetadataImpl;
66
import com.spectralogic.ds3client.networking.Metadata;
7+
import com.google.common.collect.ImmutableMap;
8+
import com.spectralogic.ds3client.models.ChecksumType;
79
<#include "../imports.ftl"/>
810

9-
import static com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils.getSizeFromHeaders;
11+
import static com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils.*;
1012

1113
public class ${name} extends ${parentClass}<${responseName}> {
1214
private final int[] expectedStatusCodes = new int[]{${expectedStatusCodes}};

ds3-autogen-java/src/test/java/com/spectralogic/ds3autogen/java/JavaFunctionalTests.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
public class JavaFunctionalTests {
5858

5959
private static final Logger LOG = LoggerFactory.getLogger(JavaFunctionalTests.class);
60-
private final static GeneratedCodeLogger CODE_LOGGER = new GeneratedCodeLogger(FileTypeToLog.REQUEST, LOG);
60+
private final static GeneratedCodeLogger CODE_LOGGER = new GeneratedCodeLogger(FileTypeToLog.PARSER, LOG);
6161

6262
@Rule
6363
public TemporaryFolder tempFolder = new TemporaryFolder();
@@ -2034,10 +2034,13 @@ public void headObjectRequest() throws IOException, TemplateModelException {
20342034

20352035
assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.AbstractResponse", responseGeneratedCode));
20362036
assertTrue(hasImport("com.spectralogic.ds3client.networking.Metadata", responseGeneratedCode));
2037+
assertTrue(hasImport("com.google.common.collect.ImmutableMap", responseGeneratedCode));
20372038

20382039
assertTrue(isReqParamOfType("metadata", "Metadata", responseName, responseGeneratedCode, false));
20392040
assertTrue(isReqParamOfType("objectSize", "long", responseName, responseGeneratedCode, false));
20402041
assertTrue(isReqParamOfType("status", "Status", responseName, responseGeneratedCode, false));
2042+
assertTrue(isReqParamOfType("blobChecksumType", "ChecksumType.Type", responseName, responseGeneratedCode, false));
2043+
assertTrue(isReqParamOfType("blobChecksums", "ImmutableMap<Long, String>", responseName, responseGeneratedCode, false));
20412044

20422045
assertTrue(responseGeneratedCode.contains("public enum Status { EXISTS, DOESNTEXIST, UNKNOWN }"));
20432046

@@ -2063,10 +2066,19 @@ public void headObjectRequest() throws IOException, TemplateModelException {
20632066
assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils", responseParserCode));
20642067
assertTrue(hasImport("com.spectralogic.ds3client.commands.interfaces.MetadataImpl", responseParserCode));
20652068
assertTrue(hasImport("com.spectralogic.ds3client.networking.Metadata", responseParserCode));
2066-
assertTrue(responseParserCode.contains("import static com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils.getSizeFromHeaders;"));
2069+
assertTrue(hasImport("com.google.common.collect.ImmutableMap", responseParserCode));
2070+
assertTrue(hasImport("com.spectralogic.ds3client.models.ChecksumType", responseParserCode));
2071+
assertTrue(responseParserCode.contains("import static com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils.*;"));
2072+
assertFalse(responseParserCode.contains("import static com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils.getSizeFromHeaders;"));
2073+
2074+
// 200 response code
2075+
assertTrue(responseParserCode.contains("final ChecksumType.Type blobChecksumType = getBlobChecksumType(response.getHeaders());"));
2076+
assertTrue(responseParserCode.contains("final ImmutableMap<Long, String> blobChecksumMap = getBlobChecksumMap(response.getHeaders());"));
2077+
assertTrue(responseParserCode.contains("return new HeadObjectResponse(blobChecksumMap, blobChecksumType, metadata, objectSize, HeadObjectResponse.Status.EXISTS, this.getChecksum(), this.getChecksumType());"));
2078+
2079+
// 404 response code
2080+
assertTrue(responseParserCode.contains("return new HeadObjectResponse(ImmutableMap.of(), ChecksumType.Type.NONE, metadata, objectSize, HeadObjectResponse.Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());"));
20672081

2068-
assertTrue(responseParserCode.contains("return new HeadObjectResponse(metadata, objectSize, HeadObjectResponse.Status.EXISTS, this.getChecksum(), this.getChecksumType());"));
2069-
assertTrue(responseParserCode.contains("return new HeadObjectResponse(metadata, objectSize, HeadObjectResponse.Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());"));
20702082
assertTrue(responseParserCode.contains("private final int[] expectedStatusCodes = new int[]{200, 404};"));
20712083
}
20722084

ds3-autogen-java/src/test/java/com/spectralogic/ds3autogen/java/generators/responsemodels/HeadObjectResponseGenerator_Test.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,32 @@ public class HeadObjectResponseGenerator_Test {
3131
@Test
3232
public void getAllImports_Test() {
3333
final ImmutableSet<String> result = generator.getAllImports(null);
34-
assertThat(result.size(), is(3));
34+
assertThat(result.size(), is(4));
3535
assertThat(result, hasItem("com.spectralogic.ds3client.networking.Metadata"));
3636
assertThat(result, hasItem("com.spectralogic.ds3client.commands.interfaces.AbstractResponse"));
3737
assertThat(result, hasItem("com.spectralogic.ds3client.models.ChecksumType"));
38+
assertThat(result, hasItem("com.google.common.collect.ImmutableMap"));
3839
}
3940

4041
@Test
4142
public void toParamList_Test() {
4243
final ImmutableList<Arguments> result = generator.toParamList(null);
43-
assertThat(result.size(), is(3));
44-
assertThat(result.get(0).getName(), is("Metadata"));
45-
assertThat(result.get(0).getType(), is("Metadata"));
46-
assertThat(result.get(1).getName(), is("ObjectSize"));
47-
assertThat(result.get(1).getType(), is("long"));
48-
assertThat(result.get(2).getName(), is("Status"));
49-
assertThat(result.get(2).getType(), is("Status"));
44+
assertThat(result.size(), is(5));
45+
46+
// Verify that parameters were sorted alphabetically by name
47+
assertThat(result.get(0).getName(), is("BlobChecksums"));
48+
assertThat(result.get(0).getType(), is("ImmutableMap<Long, String>"));
49+
50+
assertThat(result.get(1).getName(), is("BlobChecksumType"));
51+
assertThat(result.get(1).getType(), is("ChecksumType.Type"));
52+
53+
assertThat(result.get(2).getName(), is("Metadata"));
54+
assertThat(result.get(2).getType(), is("Metadata"));
55+
56+
assertThat(result.get(3).getName(), is("ObjectSize"));
57+
assertThat(result.get(3).getType(), is("long"));
58+
59+
assertThat(result.get(4).getName(), is("Status"));
60+
assertThat(result.get(4).getType(), is("Status"));
5061
}
5162
}

ds3-autogen-java/src/test/java/com/spectralogic/ds3autogen/java/generators/responseparser/HeadObjectParserGenerator_Test.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import com.spectralogic.ds3autogen.java.models.ResponseCode;
2020
import org.junit.Test;
2121

22-
import static com.spectralogic.ds3autogen.java.generators.responseparser.HeadObjectParserGenerator.toReturnCode;
22+
import static com.spectralogic.ds3autogen.java.generators.responseparser.HeadObjectParserGenerator.toDoesntExistReturnCode;
23+
import static com.spectralogic.ds3autogen.java.generators.responseparser.HeadObjectParserGenerator.toExistsReturnCode;
2324
import static com.spectralogic.ds3autogen.testutil.Ds3ModelFixtures.getHeadBucketRequest;
2425
import static com.spectralogic.ds3autogen.testutil.Ds3ModelFixtures.getRequestDeleteNotification;
2526
import static org.hamcrest.CoreMatchers.is;
@@ -30,9 +31,17 @@ public class HeadObjectParserGenerator_Test {
3031
private final HeadObjectParserGenerator generator = new HeadObjectParserGenerator();
3132

3233
@Test
33-
public void toReturnCode_Test() {
34-
final String expected = "return new MyResponse(metadata, objectSize, MyResponse.Status.MyStatus, this.getChecksum(), this.getChecksumType());\n";
35-
assertThat(toReturnCode("MyResponse", "MyStatus"), is(expected));
34+
public void toExistsReturnCode_Test() {
35+
final String expected = "final ChecksumType.Type blobChecksumType = getBlobChecksumType(response.getHeaders());\n" +
36+
" final ImmutableMap<Long, String> blobChecksumMap = getBlobChecksumMap(response.getHeaders());\n" +
37+
" return new MyResponse(blobChecksumMap, blobChecksumType, metadata, objectSize, MyResponse.Status.EXISTS, this.getChecksum(), this.getChecksumType());\n";
38+
assertThat(toExistsReturnCode("MyResponse"), is(expected));
39+
}
40+
41+
@Test
42+
public void toDoesntExistReturnCode_Test() {
43+
final String expected = "return new MyResponse(ImmutableMap.of(), ChecksumType.Type.NONE, metadata, objectSize, MyResponse.Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());\n";
44+
assertThat(toDoesntExistReturnCode("MyResponse"), is(expected));
3645
}
3746

3847
@Test (expected = IllegalArgumentException.class)
@@ -51,10 +60,12 @@ public void toResponseCodeList_Test() {
5160

5261
assertThat(result.get(0).getCode(), is(200));
5362
assertThat(result.get(0).getProcessingCode(),
54-
is("return new TestResponse(metadata, objectSize, TestResponse.Status.EXISTS, this.getChecksum(), this.getChecksumType());\n"));
63+
is("final ChecksumType.Type blobChecksumType = getBlobChecksumType(response.getHeaders());\n" +
64+
" final ImmutableMap<Long, String> blobChecksumMap = getBlobChecksumMap(response.getHeaders());\n" +
65+
" return new TestResponse(blobChecksumMap, blobChecksumType, metadata, objectSize, TestResponse.Status.EXISTS, this.getChecksum(), this.getChecksumType());\n"));
5566

5667
assertThat(result.get(1).getCode(), is(404));
5768
assertThat(result.get(1).getProcessingCode(),
58-
is("return new TestResponse(metadata, objectSize, TestResponse.Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());\n"));
69+
is("return new TestResponse(ImmutableMap.of(), ChecksumType.Type.NONE, metadata, objectSize, TestResponse.Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());\n"));
5970
}
6071
}

0 commit comments

Comments
 (0)