Skip to content

Commit 021a50b

Browse files
committed
Fix syntax errors
Signed-off-by: christian.lutnik <[email protected]>
1 parent 525a2f1 commit 021a50b

File tree

7 files changed

+29
-31
lines changed

7 files changed

+29
-31
lines changed

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/Fractional.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public String key() {
1818
return "fractional";
1919
}
2020

21-
public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationException {
21+
public Object evaluate(List arguments, Object data, String jsonPath) throws JsonLogicEvaluationException {
2222
if (arguments.size() < 2) {
2323
return null;
2424
}
@@ -53,7 +53,7 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx
5353

5454
try {
5555
for (Object dist : distibutions) {
56-
FractionProperty fractionProperty = new FractionProperty(dist);
56+
FractionProperty fractionProperty = new FractionProperty(dist, jsonPath);
5757
propertyList.add(fractionProperty);
5858
totalWeight += fractionProperty.getWeight();
5959
}
@@ -63,11 +63,11 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx
6363
}
6464

6565
// find distribution
66-
return distributeValue(bucketBy, propertyList, totalWeight);
66+
return distributeValue(bucketBy, propertyList, totalWeight, jsonPath);
6767
}
6868

6969
private static String distributeValue(
70-
final String hashKey, final List<FractionProperty> propertyList, int totalWeight)
70+
final String hashKey, final List<FractionProperty> propertyList, int totalWeight, String jsonPath)
7171
throws JsonLogicEvaluationException {
7272
byte[] bytes = hashKey.getBytes(StandardCharsets.UTF_8);
7373
int mmrHash = MurmurHash3.hash32x86(bytes, 0, bytes.length, 0);
@@ -83,7 +83,7 @@ private static String distributeValue(
8383
}
8484

8585
// this shall not be reached
86-
throw new JsonLogicEvaluationException("Unable to find a correct bucket");
86+
throw new JsonLogicEvaluationException("Unable to find a correct bucket", jsonPath);
8787
}
8888

8989
@Getter
@@ -96,27 +96,28 @@ protected final void finalize() {
9696
// DO NOT REMOVE, spotbugs: CT_CONSTRUCTOR_THROW
9797
}
9898

99-
FractionProperty(final Object from) throws JsonLogicException {
99+
FractionProperty(final Object from, String jsonPath) throws JsonLogicException {
100100
if (!(from instanceof List<?>)) {
101-
throw new JsonLogicException("Property is not an array");
101+
throw new JsonLogicException("Property is not an array", jsonPath);
102102
}
103103

104104
final List<?> array = (List) from;
105105

106106
if (array.isEmpty()) {
107-
throw new JsonLogicException("Fraction property needs at least one element");
107+
throw new JsonLogicException("Fraction property needs at least one element", jsonPath);
108108
}
109109

110110
// first must be a string
111111
if (!(array.get(0) instanceof String)) {
112-
throw new JsonLogicException("First element of the fraction property is not a string variant");
112+
throw new JsonLogicException("First element of the fraction property is not a string variant",
113+
jsonPath);
113114
}
114115

115116
variant = (String) array.get(0);
116117
if (array.size() >= 2) {
117118
// second element must be a number
118119
if (!(array.get(1) instanceof Number)) {
119-
throw new JsonLogicException("Second element of the fraction property is not a number");
120+
throw new JsonLogicException("Second element of the fraction property is not a number", jsonPath);
120121
}
121122
weight = ((Number) array.get(1)).intValue();
122123
} else {

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/SemVer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String key() {
3737
return "sem_ver";
3838
}
3939

40-
public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationException {
40+
public Object evaluate(List arguments, Object data, String jsonPath) throws JsonLogicEvaluationException {
4141

4242
if (arguments.size() != 3) {
4343
log.debug("Incorrect number of arguments for sem_ver operator");
@@ -75,10 +75,10 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx
7575
return null;
7676
}
7777

78-
return compare(arg2Parsed, arg1Parsed, arg3Parsed);
78+
return compare(arg2Parsed, arg1Parsed, arg3Parsed, jsonPath);
7979
}
8080

81-
private static boolean compare(final String operator, final Semver arg1, final Semver arg2)
81+
private static boolean compare(final String operator, final Semver arg1, final Semver arg2, final String jsonPath)
8282
throws JsonLogicEvaluationException {
8383

8484
int comp = arg1.compareTo(arg2);
@@ -102,7 +102,7 @@ private static boolean compare(final String operator, final Semver arg1, final S
102102
return arg1.getMinor() == arg2.getMinor() && arg1.getMajor() == arg2.getMajor();
103103
default:
104104
throw new JsonLogicEvaluationException(
105-
String.format("Unsupported operator received. Operator: %s", operator));
105+
String.format("Unsupported operator received. Operator: %s", operator), jsonPath);
106106
}
107107
}
108108
}

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/StringComp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public String key() {
1717
return type.key;
1818
}
1919

20-
public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationException {
20+
public Object evaluate(List arguments, Object data, String jsonPath) throws JsonLogicEvaluationException {
2121
if (arguments.size() != 2) {
2222
log.debug("Incorrect number of arguments for String comparison operator");
2323
return null;

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/connector/sync/SyncStreamQueueSourceTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.concurrent.TimeUnit;
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
30-
import org.mockito.invocation.InvocationOnMock;
3130
import org.mockito.stubbing.Answer;
3231

3332
class SyncStreamQueueSourceTest {
@@ -48,13 +47,11 @@ public void init() throws Exception {
4847

4948
stub = mock(FlagSyncServiceStub.class);
5049
when(stub.withDeadlineAfter(anyLong(), any())).thenReturn(stub);
51-
doAnswer(new Answer<Void>() {
52-
public Void answer(InvocationOnMock invocation) {
53-
latch.countDown();
54-
Object[] args = invocation.getArguments();
55-
observer = (QueueingStreamObserver<SyncFlagsResponse>) args[1];
56-
return null;
57-
}
50+
doAnswer((Answer<Void>) invocation -> {
51+
Object[] args = invocation.getArguments();
52+
observer = (QueueingStreamObserver<SyncFlagsResponse>) args[1];
53+
latch.countDown();
54+
return null;
5855
})
5956
.when(stub)
6057
.syncFlags(any(SyncFlagsRequest.class), any(QueueingStreamObserver.class)); // Mock the initialize

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/FractionalTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void validate_emptyJson_targetingReturned(@ConvertWith(FileContentConverter.clas
4141
data.put(FLAGD_PROPS_KEY, flagdProperties);
4242

4343
// when
44-
Object evaluate = fractional.evaluate(testData.rule, data);
44+
Object evaluate = fractional.evaluate(testData.rule, data, "path");
4545

4646
// then
4747
assertEquals(testData.result, evaluate);

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/SemVerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void testValidCases(List<String> args) throws JsonLogicEvaluationException {
3333
final SemVer semVer = new SemVer();
3434

3535
// when
36-
Object result = semVer.evaluate(args, new Object());
36+
Object result = semVer.evaluate(args, new Object(), "jsonPath");
3737

3838
// then
3939
if (!(result instanceof Boolean)) {
@@ -58,6 +58,6 @@ void testInvalidCases(List args) throws JsonLogicEvaluationException {
5858
final SemVer semVer = new SemVer();
5959

6060
// then
61-
assertNull(semVer.evaluate(args, new Object()));
61+
assertNull(semVer.evaluate(args, new Object(), "jsonPath"));
6262
}
6363
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/StringCompTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void startsWithEvaluation() throws JsonLogicEvaluationException {
1515
final StringComp startsWith = new StringComp(StringComp.Type.STARTS_WITH);
1616

1717
// when
18-
Object result = startsWith.evaluate(Arrays.asList("[email protected]", "abc"), new Object());
18+
Object result = startsWith.evaluate(Arrays.asList("[email protected]", "abc"), new Object(), "jsonPath");
1919

2020
// then
2121
if (!(result instanceof Boolean)) {
@@ -31,7 +31,7 @@ public void endsWithEvaluation() throws JsonLogicEvaluationException {
3131
final StringComp endsWith = new StringComp(StringComp.Type.ENDS_WITH);
3232

3333
// when
34-
Object result = endsWith.evaluate(Arrays.asList("[email protected]", "123.com"), new Object());
34+
Object result = endsWith.evaluate(Arrays.asList("[email protected]", "123.com"), new Object(), "jsonPath");
3535

3636
// then
3737
if (!(result instanceof Boolean)) {
@@ -47,7 +47,7 @@ public void invalidTypeCheckArg1() throws JsonLogicEvaluationException {
4747
final StringComp operator = new StringComp(StringComp.Type.STARTS_WITH);
4848

4949
// when
50-
Object result = operator.evaluate(Arrays.asList(1230, "12"), new Object());
50+
Object result = operator.evaluate(Arrays.asList(1230, "12"), new Object(), "jsonPath");
5151

5252
// then
5353
assertThat(result).isNull();
@@ -59,7 +59,7 @@ public void invalidTypeCheckArg2() throws JsonLogicEvaluationException {
5959
final StringComp operator = new StringComp(StringComp.Type.STARTS_WITH);
6060

6161
// when
62-
Object result = operator.evaluate(Arrays.asList("[email protected]", 123), new Object());
62+
Object result = operator.evaluate(Arrays.asList("[email protected]", 123), new Object(), "jsonPath");
6363

6464
// then
6565
assertThat(result).isNull();
@@ -71,7 +71,7 @@ public void invalidNumberOfArgs() throws JsonLogicEvaluationException {
7171
final StringComp operator = new StringComp(StringComp.Type.STARTS_WITH);
7272

7373
// when
74-
Object result = operator.evaluate(Arrays.asList("123", "12", "1"), new Object());
74+
Object result = operator.evaluate(Arrays.asList("123", "12", "1"), new Object(), "jsonPath");
7575

7676
// then
7777
assertThat(result).isNull();

0 commit comments

Comments
 (0)