Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1311,4 +1311,51 @@ public void testResettingDeadJobTimerWithModifyJob() throws Exception {
Util.deleteBucket(client, bucketName);
}
}

@Test
public void getObjectVersions() throws Exception {
final String bucketName = "test_get_object_versions";
final String objectName = "beowulf.txt";
try {
Util.createBucket(client, bucketName);
Util.loadBookTestData(client, bucketName);

final GetBucketSpectraS3Response bucketResponse = client.getBucketSpectraS3(new GetBucketSpectraS3Request(bucketName));
final String bucketId = bucketResponse.getBucketResult().getId().toString();

final GetObjectDetailsSpectraS3Response objectResponse = client.getObjectDetailsSpectraS3(new GetObjectDetailsSpectraS3Request(objectName, bucketName));
final String versionId = objectResponse.getS3ObjectResult().getId().toString();

final Arguments args = new Arguments(new String[]{"--http", "-c", "get_object_versions", "-b", bucketName, "-o", objectName});
final CommandResponse response = Util.command(client, args);

final String message = response.getMessage();

final String[] lines = message.split("\n");
boolean foundHeader = false;
boolean foundData = false;

for (final String line : lines) {
if (line.contains("Bucket Id") && line.contains("Version Id")) {
foundHeader = true;
final String[] headerParts = line.split("\\|");
assertTrue("Bucket Id header should be in first column", headerParts[1].contains("Bucket Id"));
assertTrue("Name header should be in second column", headerParts[2].contains("Name"));
assertTrue("Version Id header should be in fifth column", headerParts[5].contains("Version Id"));
}
if (line.contains(objectName)) {
foundData = true;
final String[] dataParts = line.split("\\|");
assertEquals("Bucket ID should be in the first column", bucketId, dataParts[1].trim());
assertEquals("Object name should be in the second column", objectName, dataParts[2].trim());
assertEquals("Version ID should be in the fifth column", versionId, dataParts[5].trim());
}
}
assertTrue("Should have found header in output", foundHeader);
assertTrue("Should have found object in output", foundData);

} finally {
Util.deleteBucket(client, bucketName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
Expand All @@ -49,9 +49,7 @@ public class PosixFileMetadata implements FileMetadata {
}

private static FileTime makeLocalFileTime(final String metadataValue) {
final Instant timeReadBack = LocalDateTime.parse(metadataValue, DATE_TIME_FORMATTER).toInstant(ZoneOffset.UTC);
final LocalDateTime localDateTime = LocalDateTime.ofInstant(timeReadBack, ZoneId.systemDefault());
return FileTime.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
return FileTime.from(OffsetDateTime.parse(metadataValue, DATE_TIME_FORMATTER).toInstant());
}

private static UserPrincipalLookupService userPrincipalLookupService(final Path filePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ protected String[][] formatTableContents() {

for (final S3Object version : versions) {
final String[] arrayEntry = new String[this.columnCount];
arrayEntry[0] = nullGuard(version.getId());
arrayEntry[0] = nullGuard(version.getBucketId());
arrayEntry[1] = nullGuard(version.getName());
arrayEntry[2] = nullGuardFromDate(version.getCreationDate(), DATE_FORMAT);
arrayEntry[3] = nullGuard(version.getLatest());
arrayEntry[4] = nullGuard(version.getBucketId());
arrayEntry[4] = nullGuard(version.getId());
contents.add(arrayEntry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static java.nio.file.Files.readAllBytes;
import static java.nio.file.Files.write;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.*;

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

final FileTime createdTimeAfterRestore = Files.readAttributes(fileNamePathTuple.filePath(), BasicFileAttributes.class).creationTime();
assertThat(createdAfterDeletion.compareTo(createdTimeAfterRestore), greaterThan(0));
assertThat(createdAfterDeletion.compareTo(createdTimeAfterRestore), greaterThanOrEqualTo(0));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.spectralogic.ds3cli.views.cli;

import com.google.common.collect.ImmutableList;
import com.spectralogic.ds3cli.models.GetObjectVersionsResult;
import com.spectralogic.ds3client.models.S3Object;
import org.junit.Test;
import java.util.UUID;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class GetObjectVersionsView_Test {

@Test
public void testRender() {
final String versionId = UUID.randomUUID().toString();
final String bucketId = UUID.randomUUID().toString();

final S3Object version = mock(S3Object.class);
when(version.getId()).thenReturn(UUID.fromString(versionId));
when(version.getName()).thenReturn("test-object");
when(version.getLatest()).thenReturn(true);
when(version.getBucketId()).thenReturn(UUID.fromString(bucketId));

final GetObjectVersionsResult result = new GetObjectVersionsResult(ImmutableList.of(version));
final GetObjectVersionsView view = new GetObjectVersionsView();
final String rendered = view.render(result);

final String[] lines = rendered.split("\n");
boolean foundHeader = false;
boolean foundDataLine = false;
for (final String line : lines) {
if (line.contains("Bucket Id") && line.contains("Version Id")) {
foundHeader = true;
final String[] headerParts = line.split("\\|");
assertTrue("Bucket Id header should be in first column", headerParts[1].contains("Bucket Id"));
assertTrue("Version Id header should be in fifth column", headerParts[5].contains("Version Id"));
}
if (line.contains("test-object")) {
foundDataLine = true;
final String[] dataParts = line.split("\\|");

// Assert that they are in the CORRECT columns.
// Index 1 is Bucket Id, Index 5 is Version Id (split starts from before the first |)

assertTrue("Bucket ID should be in the first column", dataParts[1].trim().equals(bucketId));
assertTrue("Version ID should be in the fifth column", dataParts[5].trim().equals(versionId));
}
}
assertTrue("Should have found header", foundHeader);
assertTrue("Should have found data line", foundDataLine);
}
}
Loading