Skip to content

Commit 74f226a

Browse files
authored
Merge pull request #232 from RachelTucker/fix-display-get-object-versions
Fix swapped Bucket Id and Version Id columns in get_object_versions.
2 parents 5b52c1a + 46848e4 commit 74f226a

5 files changed

Lines changed: 107 additions & 7 deletions

File tree

ds3-cli-integration/src/test/java/com/spectralogic/ds3cli/integration/FeatureIntegration_Test.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,4 +1311,51 @@ public void testResettingDeadJobTimerWithModifyJob() throws Exception {
13111311
Util.deleteBucket(client, bucketName);
13121312
}
13131313
}
1314+
1315+
@Test
1316+
public void getObjectVersions() throws Exception {
1317+
final String bucketName = "test_get_object_versions";
1318+
final String objectName = "beowulf.txt";
1319+
try {
1320+
Util.createBucket(client, bucketName);
1321+
Util.loadBookTestData(client, bucketName);
1322+
1323+
final GetBucketSpectraS3Response bucketResponse = client.getBucketSpectraS3(new GetBucketSpectraS3Request(bucketName));
1324+
final String bucketId = bucketResponse.getBucketResult().getId().toString();
1325+
1326+
final GetObjectDetailsSpectraS3Response objectResponse = client.getObjectDetailsSpectraS3(new GetObjectDetailsSpectraS3Request(objectName, bucketName));
1327+
final String versionId = objectResponse.getS3ObjectResult().getId().toString();
1328+
1329+
final Arguments args = new Arguments(new String[]{"--http", "-c", "get_object_versions", "-b", bucketName, "-o", objectName});
1330+
final CommandResponse response = Util.command(client, args);
1331+
1332+
final String message = response.getMessage();
1333+
1334+
final String[] lines = message.split("\n");
1335+
boolean foundHeader = false;
1336+
boolean foundData = false;
1337+
1338+
for (final String line : lines) {
1339+
if (line.contains("Bucket Id") && line.contains("Version Id")) {
1340+
foundHeader = true;
1341+
final String[] headerParts = line.split("\\|");
1342+
assertTrue("Bucket Id header should be in first column", headerParts[1].contains("Bucket Id"));
1343+
assertTrue("Name header should be in second column", headerParts[2].contains("Name"));
1344+
assertTrue("Version Id header should be in fifth column", headerParts[5].contains("Version Id"));
1345+
}
1346+
if (line.contains(objectName)) {
1347+
foundData = true;
1348+
final String[] dataParts = line.split("\\|");
1349+
assertEquals("Bucket ID should be in the first column", bucketId, dataParts[1].trim());
1350+
assertEquals("Object name should be in the second column", objectName, dataParts[2].trim());
1351+
assertEquals("Version ID should be in the fifth column", versionId, dataParts[5].trim());
1352+
}
1353+
}
1354+
assertTrue("Should have found header in output", foundHeader);
1355+
assertTrue("Should have found object in output", foundData);
1356+
1357+
} finally {
1358+
Util.deleteBucket(client, bucketName);
1359+
}
1360+
}
13141361
}

ds3_java_cli/src/main/java/com/spectralogic/ds3cli/metadata/PosixFileMetadata.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.nio.file.attribute.FileTime;
2626
import java.nio.file.attribute.UserPrincipalLookupService;
2727
import java.time.Instant;
28-
import java.time.LocalDateTime;
28+
import java.time.OffsetDateTime;
2929
import java.time.ZoneId;
3030
import java.time.ZoneOffset;
3131
import java.time.format.DateTimeFormatter;
@@ -49,9 +49,7 @@ public class PosixFileMetadata implements FileMetadata {
4949
}
5050

5151
private static FileTime makeLocalFileTime(final String metadataValue) {
52-
final Instant timeReadBack = LocalDateTime.parse(metadataValue, DATE_TIME_FORMATTER).toInstant(ZoneOffset.UTC);
53-
final LocalDateTime localDateTime = LocalDateTime.ofInstant(timeReadBack, ZoneId.systemDefault());
54-
return FileTime.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
52+
return FileTime.from(OffsetDateTime.parse(metadataValue, DATE_TIME_FORMATTER).toInstant());
5553
}
5654

5755
private static UserPrincipalLookupService userPrincipalLookupService(final Path filePath) {

ds3_java_cli/src/main/java/com/spectralogic/ds3cli/views/cli/GetObjectVersionsView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ protected String[][] formatTableContents() {
5151

5252
for (final S3Object version : versions) {
5353
final String[] arrayEntry = new String[this.columnCount];
54-
arrayEntry[0] = nullGuard(version.getId());
54+
arrayEntry[0] = nullGuard(version.getBucketId());
5555
arrayEntry[1] = nullGuard(version.getName());
5656
arrayEntry[2] = nullGuardFromDate(version.getCreationDate(), DATE_FORMAT);
5757
arrayEntry[3] = nullGuard(version.getLatest());
58-
arrayEntry[4] = nullGuard(version.getBucketId());
58+
arrayEntry[4] = nullGuard(version.getId());
5959
contents.add(arrayEntry);
6060
}
6161

ds3_java_cli/src/test/java/com/spectralogic/ds3cli/metadata/PosixFileMetadata_Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static java.nio.file.Files.readAllBytes;
2828
import static java.nio.file.Files.write;
2929
import static org.hamcrest.Matchers.greaterThan;
30+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3031
import static org.junit.Assert.*;
3132

3233
import java.nio.file.Files;
@@ -157,7 +158,7 @@ public void testFileCreatedTime() throws Exception {
157158
assertEquals(lastModified, lastModifiedAfterRestore);
158159

159160
final FileTime createdTimeAfterRestore = Files.readAttributes(fileNamePathTuple.filePath(), BasicFileAttributes.class).creationTime();
160-
assertThat(createdAfterDeletion.compareTo(createdTimeAfterRestore), greaterThan(0));
161+
assertThat(createdAfterDeletion.compareTo(createdTimeAfterRestore), greaterThanOrEqualTo(0));
161162

162163
}
163164

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.spectralogic.ds3cli.views.cli;
2+
3+
import com.google.common.collect.ImmutableList;
4+
import com.spectralogic.ds3cli.models.GetObjectVersionsResult;
5+
import com.spectralogic.ds3client.models.S3Object;
6+
import org.junit.Test;
7+
import java.util.UUID;
8+
import static org.hamcrest.CoreMatchers.containsString;
9+
import static org.junit.Assert.assertTrue;
10+
import static org.mockito.Mockito.mock;
11+
import static org.mockito.Mockito.when;
12+
13+
public class GetObjectVersionsView_Test {
14+
15+
@Test
16+
public void testRender() {
17+
final String versionId = UUID.randomUUID().toString();
18+
final String bucketId = UUID.randomUUID().toString();
19+
20+
final S3Object version = mock(S3Object.class);
21+
when(version.getId()).thenReturn(UUID.fromString(versionId));
22+
when(version.getName()).thenReturn("test-object");
23+
when(version.getLatest()).thenReturn(true);
24+
when(version.getBucketId()).thenReturn(UUID.fromString(bucketId));
25+
26+
final GetObjectVersionsResult result = new GetObjectVersionsResult(ImmutableList.of(version));
27+
final GetObjectVersionsView view = new GetObjectVersionsView();
28+
final String rendered = view.render(result);
29+
30+
final String[] lines = rendered.split("\n");
31+
boolean foundHeader = false;
32+
boolean foundDataLine = false;
33+
for (final String line : lines) {
34+
if (line.contains("Bucket Id") && line.contains("Version Id")) {
35+
foundHeader = true;
36+
final String[] headerParts = line.split("\\|");
37+
assertTrue("Bucket Id header should be in first column", headerParts[1].contains("Bucket Id"));
38+
assertTrue("Version Id header should be in fifth column", headerParts[5].contains("Version Id"));
39+
}
40+
if (line.contains("test-object")) {
41+
foundDataLine = true;
42+
final String[] dataParts = line.split("\\|");
43+
44+
// Assert that they are in the CORRECT columns.
45+
// Index 1 is Bucket Id, Index 5 is Version Id (split starts from before the first |)
46+
47+
assertTrue("Bucket ID should be in the first column", dataParts[1].trim().equals(bucketId));
48+
assertTrue("Version ID should be in the fifth column", dataParts[5].trim().equals(versionId));
49+
}
50+
}
51+
assertTrue("Should have found header", foundHeader);
52+
assertTrue("Should have found data line", foundDataLine);
53+
}
54+
}

0 commit comments

Comments
 (0)