-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for GetObjectAttributes API - WIP
- Loading branch information
Showing
9 changed files
with
387 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
server/src/main/java/com/adobe/testing/s3mock/dto/Checksum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2017-2022 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonRootName; | ||
|
||
/** | ||
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_Checksum.html">API Reference</a>. | ||
*/ | ||
@JsonRootName("Checksum") | ||
public class Checksum { | ||
|
||
@JsonProperty("ChecksumCRC32") | ||
private String checksumCRC32; | ||
|
||
@JsonProperty("ChecksumCRC32C") | ||
private String checksumCRC32C; | ||
|
||
@JsonProperty("ChecksumSHA1") | ||
private String checksumSHA1; | ||
|
||
@JsonProperty("ChecksumSHA256") | ||
private String checksumSHA256; | ||
|
||
public Checksum(String checksumCRC32, String checksumCRC32C, String checksumSHA1, | ||
String checksumSHA256) { | ||
this.checksumCRC32 = checksumCRC32; | ||
this.checksumCRC32C = checksumCRC32C; | ||
this.checksumSHA1 = checksumSHA1; | ||
this.checksumSHA256 = checksumSHA256; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
server/src/main/java/com/adobe/testing/s3mock/dto/GetObjectAttributesOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2017-2022 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.dto; | ||
|
||
import static com.adobe.testing.s3mock.util.EtagUtil.normalizeEtag; | ||
|
||
import com.adobe.testing.s3mock.store.S3ObjectMetadata; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonRootName; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import java.util.List; | ||
|
||
@JsonRootName("GetObjectAttributesOutput") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class GetObjectAttributesOutput { | ||
|
||
@JsonProperty("Checksum") | ||
private Checksum checksum; | ||
|
||
@JsonProperty("ETag") | ||
private String etag; | ||
|
||
@JsonProperty("ObjectParts") | ||
@JacksonXmlElementWrapper(useWrapping = false) | ||
private List<GetObjectAttributesParts> objectParts; | ||
|
||
@JsonProperty("ObjectSize") | ||
private Long objectSize; | ||
|
||
@JsonProperty("StorageClass") | ||
private StorageClass storageClass; | ||
|
||
public GetObjectAttributesOutput(Checksum checksum, String etag, | ||
List<GetObjectAttributesParts> objectParts, Long objectSize, StorageClass storageClass) { | ||
this.checksum = checksum; | ||
this.etag = normalizeEtag(etag); | ||
this.objectParts = objectParts; | ||
this.objectSize = objectSize; | ||
this.storageClass = storageClass; | ||
} | ||
|
||
GetObjectAttributesOutput from(S3ObjectMetadata metadata) { | ||
return new GetObjectAttributesOutput(null, | ||
metadata.getEtag(), | ||
null, | ||
Long.valueOf(metadata.getSize()), | ||
null); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
server/src/main/java/com/adobe/testing/s3mock/dto/GetObjectAttributesParts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2017-2022 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonRootName; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import java.util.List; | ||
|
||
/** | ||
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAttributesParts.html">API Reference</a>. | ||
*/ | ||
@JsonRootName("GetObjectAttributesParts") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class GetObjectAttributesParts { | ||
|
||
@JsonProperty("MaxParts") | ||
private int maxParts; | ||
|
||
@JsonProperty("IsTruncated") | ||
private boolean isTruncated; | ||
|
||
@JsonProperty("NextPartNumberMarker") | ||
private int nextPartNumberMarker; | ||
|
||
@JsonProperty("PartNumberMarker") | ||
private int partNumberMarker; | ||
|
||
@JsonProperty("TotalPartsCount") | ||
private int totalPartsCount; | ||
|
||
@JsonProperty("Parts") | ||
@JacksonXmlElementWrapper(useWrapping = false) | ||
private List<ObjectPart> parts; | ||
|
||
public GetObjectAttributesParts(int maxParts, boolean isTruncated, int nextPartNumberMarker, | ||
int partNumberMarker, int totalPartsCount, List<ObjectPart> parts) { | ||
this.maxParts = maxParts; | ||
this.isTruncated = isTruncated; | ||
this.nextPartNumberMarker = nextPartNumberMarker; | ||
this.partNumberMarker = partNumberMarker; | ||
this.totalPartsCount = totalPartsCount; | ||
this.parts = parts; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
server/src/main/java/com/adobe/testing/s3mock/dto/ObjectPart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2017-2022 Adobe. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.adobe.testing.s3mock.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonRootName; | ||
|
||
/** | ||
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_ObjectPart.html">API Reference</a>. | ||
*/ | ||
@JsonRootName("ObjectPart") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class ObjectPart { | ||
@JsonProperty("ChecksumCRC32") | ||
private String checksumCRC32; | ||
|
||
@JsonProperty("ChecksumCRC32C") | ||
private String checksumCRC32C; | ||
|
||
@JsonProperty("ChecksumSHA1") | ||
private String checksumSHA1; | ||
|
||
@JsonProperty("ChecksumSHA256") | ||
private String checksumSHA256; | ||
|
||
@JsonProperty("Size") | ||
private Long size; | ||
|
||
@JsonProperty("PartNumber") | ||
protected Integer partNumber; | ||
|
||
public ObjectPart(String checksumCRC32, String checksumCRC32C, String checksumSHA1, | ||
String checksumSHA256, Long size, Integer partNumber) { | ||
this.checksumCRC32 = checksumCRC32; | ||
this.checksumCRC32C = checksumCRC32C; | ||
this.checksumSHA1 = checksumSHA1; | ||
this.checksumSHA256 = checksumSHA256; | ||
this.size = size; | ||
this.partNumber = partNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
server/src/test/java/com/adobe/testing/s3mock/dto/GetObjectAttributesOutputTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.adobe.testing.s3mock.dto; | ||
|
||
import static com.adobe.testing.s3mock.dto.DtoTestUtil.serializeAndAssert; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
|
||
class GetObjectAttributesOutputTest { | ||
|
||
@Test | ||
void testSerialization_object(TestInfo testInfo) throws IOException { | ||
GetObjectAttributesOutput iut = new GetObjectAttributesOutput( | ||
null, | ||
"etag", | ||
null, | ||
1L, | ||
StorageClass.STANDARD | ||
); | ||
|
||
serializeAndAssert(iut, testInfo); | ||
} | ||
|
||
@Test | ||
void testSerialization_multiPart(TestInfo testInfo) throws IOException { | ||
ObjectPart part = new ObjectPart(null, | ||
null, | ||
null, | ||
null, | ||
1L, | ||
1); | ||
GetObjectAttributesParts getObjectAttributesParts = new GetObjectAttributesParts( | ||
1000, | ||
false, | ||
0, | ||
0, | ||
0, | ||
Collections.singletonList(part) | ||
); | ||
GetObjectAttributesOutput iut = new GetObjectAttributesOutput( | ||
null, | ||
"etag", | ||
Collections.singletonList(getObjectAttributesParts), | ||
1L, | ||
StorageClass.STANDARD | ||
); | ||
|
||
serializeAndAssert(iut, testInfo); | ||
} | ||
|
||
} |
Oops, something went wrong.