Skip to content

Commit 9dbea1a

Browse files
authored
Backport to branch(3): Add utility setter methods for ImmutableMap to AbacOperationAttributes (#2448) (#2460)
1 parent 2361f43 commit 9dbea1a

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

core/src/main/java/com/scalar/db/api/AbacOperationAttributes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.scalar.db.api;
22

3+
import com.google.common.collect.ImmutableMap;
34
import java.util.Map;
45
import java.util.Optional;
56

@@ -16,6 +17,11 @@ public static void setReadTag(Map<String, String> attributes, String policyName,
1617
attributes.put(READ_TAG_PREFIX + policyName, readTag);
1718
}
1819

20+
public static void setReadTag(
21+
ImmutableMap.Builder<String, String> attributesBuilder, String policyName, String readTag) {
22+
attributesBuilder.put(READ_TAG_PREFIX + policyName, readTag);
23+
}
24+
1925
public static void clearReadTag(Map<String, String> attributes, String policyName) {
2026
attributes.remove(READ_TAG_PREFIX + policyName);
2127
}
@@ -29,6 +35,11 @@ public static void setWriteTag(
2935
attributes.put(WRITE_TAG_PREFIX + policyName, writeTag);
3036
}
3137

38+
public static void setWriteTag(
39+
ImmutableMap.Builder<String, String> attributesBuilder, String policyName, String writeTag) {
40+
attributesBuilder.put(WRITE_TAG_PREFIX + policyName, writeTag);
41+
}
42+
3243
public static void clearWriteTag(Map<String, String> attributes, String policyName) {
3344
attributes.remove(WRITE_TAG_PREFIX + policyName);
3445
}

core/src/test/java/com/scalar/db/api/AbacOperationAttributesTest.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5+
import com.google.common.collect.ImmutableMap;
56
import com.scalar.db.io.Key;
67
import java.util.HashMap;
78
import java.util.Map;
@@ -11,7 +12,7 @@
1112
public class AbacOperationAttributesTest {
1213

1314
@Test
14-
public void setReadTag_ShouldSetReadTag() {
15+
public void setReadTag_MapGiven_ShouldSetReadTag() {
1516
// Arrange
1617
Map<String, String> attributes = new HashMap<>();
1718
String policyName = "policyName";
@@ -25,6 +26,21 @@ public void setReadTag_ShouldSetReadTag() {
2526
.containsEntry(AbacOperationAttributes.READ_TAG_PREFIX + policyName, readTag);
2627
}
2728

29+
@Test
30+
public void setReadTag_ImmutableMapBuilderGiven_ShouldSetReadTag() {
31+
// Arrange
32+
ImmutableMap.Builder<String, String> attributesBuilder = ImmutableMap.builder();
33+
String policyName = "policyName";
34+
String readTag = "readTag";
35+
36+
// Act
37+
AbacOperationAttributes.setReadTag(attributesBuilder, policyName, readTag);
38+
39+
// Assert
40+
assertThat(attributesBuilder.build())
41+
.containsEntry(AbacOperationAttributes.READ_TAG_PREFIX + policyName, readTag);
42+
}
43+
2844
@Test
2945
public void clearReadTag_ShouldClearReadTag() {
3046
// Arrange
@@ -60,7 +76,7 @@ public void clearReadTags_ShouldClearReadTags() {
6076
}
6177

6278
@Test
63-
public void setWriteTag_ShouldSetWriteTag() {
79+
public void setWriteTag_MapGiven_ShouldSetWriteTag() {
6480
// Arrange
6581
Map<String, String> attributes = new HashMap<>();
6682
String policyName = "policyName";
@@ -74,6 +90,21 @@ public void setWriteTag_ShouldSetWriteTag() {
7490
.containsEntry(AbacOperationAttributes.WRITE_TAG_PREFIX + policyName, writeTag);
7591
}
7692

93+
@Test
94+
public void setWriteTag_ImmutableMapBuilderGiven_ShouldSetWriteTag() {
95+
// Arrange
96+
ImmutableMap.Builder<String, String> attributesBuilder = ImmutableMap.builder();
97+
String policyName = "policyName";
98+
String writeTag = "writeTag";
99+
100+
// Act
101+
AbacOperationAttributes.setWriteTag(attributesBuilder, policyName, writeTag);
102+
103+
// Assert
104+
assertThat(attributesBuilder.build())
105+
.containsEntry(AbacOperationAttributes.WRITE_TAG_PREFIX + policyName, writeTag);
106+
}
107+
77108
@Test
78109
public void clearWriteTag_ShouldClearWriteTag() {
79110
// Arrange

0 commit comments

Comments
 (0)