11package io .permit .sdk .endpoints ;
22
33import com .google .gson .Gson ;
4- import com .google .gson .internal .LinkedTreeMap ;
54import io .permit .sdk .Permit ;
65import io .permit .sdk .PermitE2ETestBase ;
76import io .permit .sdk .api .PermitApiError ;
1211import org .junit .jupiter .api .Test ;
1312
1413import java .io .IOException ;
15- import java .util .Arrays ;
16- import java .util .Collections ;
17- import java .util .HashMap ;
18- import java .util .List ;
14+ import java .util .*;
1915import java .util .stream .Collectors ;
2016
2117import static org .junit .jupiter .api .Assertions .*;
@@ -33,6 +29,40 @@ public class ConditionSetsE2ETest extends PermitE2ETestBase {
3329 private static ConditionSetCreate resourcesetData ;
3430 private static ConditionSetRuleCreate ruleData ;
3531
32+ private static HashMap <String , Object > getUsersetConditions () {
33+ HashMap <String , Integer > ageCondition = new HashMap <String , Integer >() {{
34+ put ("greater-than" , 30 );
35+ }};
36+
37+ HashMap <String , HashMap <String , Integer >> attributeRef = new HashMap <>();
38+ attributeRef .put ("user.age" , ageCondition );
39+
40+ List <HashMap <String , HashMap <String , Integer >>> andConditions = new ArrayList <>();
41+ andConditions .add (attributeRef );
42+
43+ HashMap <String , Object > conditions = new HashMap <>();
44+ conditions .put ("allOf" , andConditions );
45+
46+ return conditions ;
47+ }
48+
49+ private static HashMap <String , Object > getResourcesetConditions () {
50+ HashMap <String , Boolean > privateCondition = new HashMap <String , Boolean >() {{
51+ put ("equals" , false );
52+ }};
53+
54+ HashMap <String , HashMap <String , Boolean >> attributeRef = new HashMap <>();
55+ attributeRef .put ("resource.private" , privateCondition );
56+
57+ List <HashMap <String , HashMap <String , Boolean >>> andConditions = new ArrayList <>();
58+ andConditions .add (attributeRef );
59+
60+ HashMap <String , Object > conditions = new HashMap <>();
61+ conditions .put ("allOf" , andConditions );
62+
63+ return conditions ;
64+ }
65+
3666 @ BeforeAll
3767 static void setup () {
3868 // resource actions
@@ -64,38 +94,14 @@ static void setup() {
6494 new ConditionSetCreate (USERSET_KEY , "Users over 30" )
6595 )
6696 .withType (ConditionSetType .USERSET )
67- .withConditions (new HashMap <String , Object >() {{
68- put ("allOf" , Collections .singletonList (
69- new HashMap <String , List <HashMap <String , HashMap <String , Integer >>>>() {{
70- put ("allOf" , Collections .singletonList (
71- new HashMap <String , HashMap <String , Integer >>() {{
72- put ("user.age" , new HashMap <String , Integer >() {{
73- put ("greater-than" , 30 );
74- }});
75- }}
76- ));
77- }}
78- ));
79- }})
97+ .withConditions (getUsersetConditions ())
8098 );
8199
82100 resourcesetData = ((
83101 new ConditionSetCreate (RESOURCESET_KEY , "Private Docs" )
84102 )
85103 .withType (ConditionSetType .RESOURCESET )
86- .withConditions (new HashMap <String , Object >() {{
87- put ("allOf" , Collections .singletonList (
88- new HashMap <String , List <HashMap <String , HashMap <String , Boolean >>>>() {{
89- put ("allOf" , Collections .singletonList (
90- new HashMap <String , HashMap <String , Boolean >>() {{
91- put ("resource.private" , new HashMap <String , Boolean >() {{
92- put ("equals" , false );
93- }});
94- }}
95- ));
96- }}
97- ));
98- }})
104+ .withConditions (getResourcesetConditions ())
99105 );
100106
101107 ruleData = new ConditionSetRuleCreate (USERSET_KEY , DOCUMENT_KEY + ":sign" , RESOURCESET_KEY );
@@ -127,7 +133,7 @@ void cleanup() {
127133 }
128134
129135 @ Test
130- void testResourcesApi () {
136+ void testConditionSetsApi () {
131137 // init the client
132138 Permit permit = new Permit (this .config );
133139 Gson gson = new Gson ();
@@ -175,7 +181,7 @@ void testResourcesApi() {
175181 assertEquals (userset .name , usersetData .name );
176182 assertEquals (userset .description , usersetData .description );
177183
178- ConditionSetRead resourceset = permit .api .conditionSets .create (resourcesetData );
184+ ConditionSetRead resourceset = permit .api .conditionSets .create (resourcesetData . withResourceId ( document . id ) );
179185 assertNotNull (resourceset );
180186 assertNotNull (resourceset .id );
181187 assertEquals (resourceset .key , resourcesetData .key );
0 commit comments