PathMetadataDynamoDBTranslation { static Item pathMetadataToItem(DDBPathMetadata meta) { Preconditions.checkNotNull(meta); final S3AFileStatus status = meta.getFileStatus(); final Item item = new Item().withPrimaryKey(pathToKey(status.getPath())); if (status.isDirectory()) { item.withBoolean(IS_DIR, true); if (!IGNORED_FIELDS.contains(IS_AUTHORITATIVE)) { item.withBoolean(IS_AUTHORITATIVE, meta.isAuthoritativeDir()); } } else { item.withLong(FILE_LENGTH, status.getLen()) .withLong(MOD_TIME, status.getModificationTime()) .withLong(BLOCK_SIZE, status.getBlockSize()); if (status.getETag() != null) { item.withString(ETAG, status.getETag()); } if (status.getVersionId() != null) { item.withString(VERSION_ID, status.getVersionId()); } } item.withBoolean(IS_DELETED, meta.isDeleted()); if(!IGNORED_FIELDS.contains(LAST_UPDATED)) { item.withLong(LAST_UPDATED, meta.getLastUpdated()); } return item; } private  PathMetadataDynamoDBTranslation(); @VisibleForTesting static String pathToParentKey(Path path);  }
@Test public void testPathMetadataToItem() { verify(pathMetadataToItem(testDirPathMetadata), testDirPathMetadata); verify(pathMetadataToItem(testFilePathMetadata), testFilePathMetadata); }
@Test public void testIsAuthoritativeCompatibilityPathMetadataToItem() { DDBPathMetadata meta = Mockito.spy(testFilePathMetadata); meta.setAuthoritativeDir(true); PathMetadataDynamoDBTranslation.IGNORED_FIELDS.add(IS_AUTHORITATIVE); Item item = pathMetadataToItem(meta); Mockito.verify(meta, never()).isAuthoritativeDir(); assertFalse(item.hasAttribute(IS_AUTHORITATIVE)); }
@Test public void testIsLastUpdatedCompatibilityPathMetadataToItem() { DDBPathMetadata meta = Mockito.spy(testFilePathMetadata); meta.setLastUpdated(100); PathMetadataDynamoDBTranslation.IGNORED_FIELDS.add(LAST_UPDATED); Item item = pathMetadataToItem(meta); Mockito.verify(meta, never()).getLastUpdated(); assertFalse(item.hasAttribute(LAST_UPDATED)); }