11package io .opentdf .platform .sdk ;
22
3- import static org .assertj .core .api .Assertions .assertThat ;
4- import static org .assertj .core .api .Assertions .assertThatThrownBy ;
5- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
6- import static org .junit .jupiter .api .Assertions .assertEquals ;
7- import static org .junit .jupiter .api .Assertions .assertNotNull ;
8- import static org .mockito .ArgumentMatchers .any ;
9- import static org .mockito .Mockito .mock ;
10- import static org .mockito .Mockito .never ;
11- import static org .mockito .Mockito .verify ;
12- import static org .mockito .Mockito .when ;
13-
143import com .connectrpc .ResponseMessage ;
154import com .connectrpc .UnaryBlockingCall ;
165import io .opentdf .platform .policy .Algorithm ;
2918import io .opentdf .platform .policy .attributes .GetAttributeValuesByFqnsRequest ;
3019import io .opentdf .platform .policy .attributes .GetAttributeValuesByFqnsResponse ;
3120import io .opentdf .platform .sdk .Autoconfigure .AttributeValueFQN ;
21+ import io .opentdf .platform .sdk .Autoconfigure .Granter ;
3222import io .opentdf .platform .sdk .Autoconfigure .Granter .AttributeBooleanExpression ;
3323import io .opentdf .platform .sdk .Autoconfigure .Granter .BooleanKeyExpression ;
3424import io .opentdf .platform .sdk .Autoconfigure .KeySplitStep ;
35- import io .opentdf .platform .sdk .Autoconfigure .Granter ;
36-
3725import org .junit .jupiter .api .BeforeAll ;
3826import org .junit .jupiter .api .Test ;
3927import org .mockito .Mockito ;
4836import java .util .concurrent .atomic .AtomicInteger ;
4937import java .util .function .BiFunction ;
5038import java .util .function .Supplier ;
51- import java .util .stream .Collectors ;
5239import java .util .regex .Matcher ;
5340import java .util .regex .Pattern ;
41+ import java .util .stream .Collectors ;
42+
43+ import static org .assertj .core .api .Assertions .assertThat ;
44+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
45+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
46+ import static org .junit .jupiter .api .Assertions .assertEquals ;
47+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
48+ import static org .mockito .ArgumentMatchers .any ;
49+ import static org .mockito .Mockito .mock ;
50+ import static org .mockito .Mockito .never ;
51+ import static org .mockito .Mockito .verify ;
52+ import static org .mockito .Mockito .when ;
5453
5554public class AutoconfigureTest {
5655
@@ -514,7 +513,7 @@ public void testReasonerConstructAttributeBoolean() {
514513 var wrapper = new Object () {
515514 int i = 0 ;
516515 };
517- List <KeySplitStep > plan = reasoner .getSplits (tc .getDefaults (), () -> String .valueOf (wrapper .i ++ + 1 ), () -> Optional . empty () );
516+ List <KeySplitStep > plan = reasoner .getSplits (tc .getDefaults (), () -> String .valueOf (wrapper .i ++ + 1 ), Optional :: empty );
518517 assertThat (plan )
519518 .as (tc .name )
520519 .isEqualTo (tc .getPlan ());
@@ -525,7 +524,7 @@ public void testReasonerConstructAttributeBoolean() {
525524 void testUsingAttributeMappedAtNamespace () {
526525 Granter granter = Autoconfigure .newGranterFromAttributes (new KASKeyCache (), mockValueFor (mp2uns2uns ));
527526 var counter = new AtomicInteger (0 );
528- var splitPlan = granter .getSplits (Collections .emptyList (), () -> Integer .toString (counter .getAndIncrement ()), () -> Optional . empty () );
527+ var splitPlan = granter .getSplits (Collections .emptyList (), () -> Integer .toString (counter .getAndIncrement ()), Optional :: empty );
529528 assertThat (splitPlan ).isEqualTo (List .of (new KeySplitStep ("https://mapped.example.com" , "" , NAMESPACE_KAS_KEY .getPublicKey ().getKid ())));
530529 }
531530
@@ -534,7 +533,7 @@ void testUsingAttributeMappedAtMultiplePlaces() {
534533 var attributes = new Value []{mockValueFor (mp2uns2uns ), mockValueFor (mp2uns2mp )};
535534 Granter granter = Autoconfigure .newGranterFromAttributes (new KASKeyCache (), attributes );
536535 var counter = new AtomicInteger (0 );
537- var splitPlan = granter .getSplits (Collections .emptyList (), () -> Integer .toString (counter .getAndIncrement ()), () -> Optional . empty () );
536+ var splitPlan = granter .getSplits (Collections .emptyList (), () -> Integer .toString (counter .getAndIncrement ()), Optional :: empty );
538537 assertThat (splitPlan ).isEqualTo (List .of (
539538 new KeySplitStep (NAMESPACE_KAS_KEY .getKasUri (), "0" , NAMESPACE_KAS_KEY .getPublicKey ().getKid ()),
540539 new KeySplitStep (VALUE_KEY .getKasUri (), "0" , VALUE_KEY .getPublicKey ().getKid ())
@@ -1075,27 +1074,18 @@ void createsGranterFromService() {
10751074
10761075 // Mock the attribute service to return a response with the expected values
10771076 when (attributesServiceClient .getAttributeValuesByFqnsBlocking (any (), any ())).thenAnswer (invocation -> {
1078- return new UnaryBlockingCall <GetAttributeValuesByFqnsResponse >() {
1079- @ Override
1080- public ResponseMessage <GetAttributeValuesByFqnsResponse > execute () {
1081- GetAttributeValuesByFqnsResponse .Builder builder = GetAttributeValuesByFqnsResponse .newBuilder ();
1082- for (AttributeValueFQN fqn : policy ) {
1083- Value value = Value .newBuilder ()
1084- .setId (fqn .toString ())
1085- .setFqn (fqn .toString ())
1086- .build ();
1087- builder .putFqnAttributeValues (fqn .toString (),
1088- GetAttributeValuesByFqnsResponse .AttributeAndValue .newBuilder ()
1089- .setValue (value )
1090- .build ());
1091- }
1092- return new ResponseMessage .Success <>(builder .build (), Collections .emptyMap (), Collections .emptyMap ());
1093- }
1094-
1095- @ Override
1096- public void cancel () {
1097- }
1098- };
1077+ GetAttributeValuesByFqnsResponse .Builder builder = GetAttributeValuesByFqnsResponse .newBuilder ();
1078+ for (AttributeValueFQN fqn : policy ) {
1079+ Value value = Value .newBuilder ()
1080+ .setId (fqn .toString ())
1081+ .setFqn (fqn .toString ())
1082+ .build ();
1083+ builder .putFqnAttributeValues (fqn .toString (),
1084+ GetAttributeValuesByFqnsResponse .AttributeAndValue .newBuilder ()
1085+ .setValue (value )
1086+ .build ());
1087+ }
1088+ return TestUtil .successfulUnaryCall (builder .build ());
10991089 });
11001090
11011091 // Act
0 commit comments