-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 deletions.
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
44 changes: 44 additions & 0 deletions
44
server/src/main/java/com/adobe/testing/s3mock/store/S3ObjectVersions.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,44 @@ | ||
/************************************************************************* | ||
* ADOBE CONFIDENTIAL | ||
* ___________________ | ||
* | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
**************************************************************************/ | ||
|
||
package com.adobe.testing.s3mock.store; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public record S3ObjectVersions( | ||
UUID id, | ||
Map<Integer, String> versions, | ||
AtomicInteger latestVersionPointer | ||
) { | ||
|
||
public S3ObjectVersions(UUID id) { | ||
this(id, new HashMap<>(), new AtomicInteger(0)); | ||
} | ||
|
||
public String createVersion() { | ||
String versionId = UUID.randomUUID().toString(); | ||
versions.put(latestVersionPointer.incrementAndGet(), versionId); | ||
return versionId; | ||
} | ||
|
||
public String getLatestVersion() { | ||
return versions.get(latestVersionPointer.get()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
server/src/test/kotlin/com/adobe/testing/s3mock/store/S3ObjectVersionsTest.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,21 @@ | ||
package com.adobe.testing.s3mock.store; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.UUID; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class S3ObjectVersionsTest { | ||
|
||
@Test | ||
void testVersions() { | ||
var iut = new S3ObjectVersions(UUID.randomUUID()); | ||
assertThat(iut.getLatestVersion()).isNull(); | ||
assertThat(iut.latestVersionPointer().get()).isZero(); | ||
|
||
var version = iut.createVersion(); | ||
assertThat(version).isNotBlank(); | ||
assertThat(iut.latestVersionPointer().get()).isOne(); | ||
assertThat(iut.getLatestVersion()).isEqualTo(version); | ||
} | ||
} |