diff --git a/server/src/main/java/com/adobe/testing/s3mock/store/ObjectStore.java b/server/src/main/java/com/adobe/testing/s3mock/store/ObjectStore.java index a22fe3980..323a3d9c6 100644 --- a/server/src/main/java/com/adobe/testing/s3mock/store/ObjectStore.java +++ b/server/src/main/java/com/adobe/testing/s3mock/store/ObjectStore.java @@ -54,6 +54,7 @@ public class ObjectStore extends StoreBase { private static final Logger LOG = LoggerFactory.getLogger(ObjectStore.class); private static final String META_FILE = "objectMetadata.json"; private static final String DATA_FILE = "binaryData"; + private static final String VERSIONS_FILE = "versions.json"; /** * This map stores one lock object per S3Object ID. @@ -480,11 +481,11 @@ private Path getObjectFolderPath(BucketMetadata bucket, UUID id) { } private Path getMetaFilePath(BucketMetadata bucket, UUID id) { - return Paths.get(getObjectFolderPath(bucket, id).toString(), META_FILE); + return getObjectFolderPath(bucket, id).resolve(META_FILE); } private Path getDataFilePath(BucketMetadata bucket, UUID id) { - return Paths.get(getObjectFolderPath(bucket, id).toString(), DATA_FILE); + return getObjectFolderPath(bucket, id).resolve(DATA_FILE); } private void writeMetafile(BucketMetadata bucket, S3ObjectMetadata s3ObjectMetadata) { diff --git a/server/src/main/java/com/adobe/testing/s3mock/store/S3ObjectVersions.java b/server/src/main/java/com/adobe/testing/s3mock/store/S3ObjectVersions.java new file mode 100644 index 000000000..a8483d650 --- /dev/null +++ b/server/src/main/java/com/adobe/testing/s3mock/store/S3ObjectVersions.java @@ -0,0 +1,43 @@ +/* + * Copyright 2017-2024 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.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 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()); + } +} diff --git a/server/src/test/kotlin/com/adobe/testing/s3mock/store/S3ObjectVersionsTest.kt b/server/src/test/kotlin/com/adobe/testing/s3mock/store/S3ObjectVersionsTest.kt new file mode 100644 index 000000000..393120d8a --- /dev/null +++ b/server/src/test/kotlin/com/adobe/testing/s3mock/store/S3ObjectVersionsTest.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2017-2024 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.store + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import java.util.UUID + +internal class S3ObjectVersionsTest { + @Test + fun testVersions() { + val iut = S3ObjectVersions(UUID.randomUUID()) + assertThat(iut.latestVersion).isNull() + assertThat(iut.latestVersionPointer.get()).isZero() + + val version = iut.createVersion() + assertThat(version).isNotBlank() + assertThat(iut.latestVersionPointer.get()).isOne() + assertThat(iut.latestVersion).isEqualTo(version) + } +}