11package com .contentstack .cms .stack ;
22
3+ import com .contentstack .cms .Contentstack ;
34import com .contentstack .cms .TestClient ;
5+ import com .contentstack .cms .Utils ;
46import com .contentstack .cms .core .Util ;
7+ import com .google .gson .JsonObject ;
8+
59import okhttp3 .Request ;
610import okhttp3 .ResponseBody ;
711import org .json .simple .JSONObject ;
812import org .junit .jupiter .api .*;
13+
14+ import retrofit2 .Call ;
915import retrofit2 .Response ;
1016
1117import java .io .IOException ;
18+ import java .util .HashMap ;
1219
1320@ Tag ("api" )
1421@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
@@ -19,15 +26,22 @@ class RoleAPITest {
1926 protected static String _uid = TestClient .AUTHTOKEN ;
2027 protected static String MANAGEMENT_TOKEN = TestClient .MANAGEMENT_TOKEN ;
2128 protected static Roles roles ;
22- static Stack stack ;
29+ protected static String Taxonomy_uid = "sample_two" ;
30+ protected static Taxonomy taxonomy ;
31+ protected static Terms term ;
32+ protected static Stack stack ;
2333
2434
2535 @ BeforeAll
2636 static void setup () {
27- stack = TestClient .getStack ();
28- stack .addHeader (Util .API_KEY , API_KEY );
29- stack .addHeader (Util .AUTHORIZATION , MANAGEMENT_TOKEN );
37+ final String AUTHTOKEN = TestClient .AUTHTOKEN ;
38+ HashMap <String , Object > headers = new HashMap <>();
39+ headers .put (Util .API_KEY , API_KEY );
40+ headers .put (Util .AUTHORIZATION , MANAGEMENT_TOKEN );
41+ stack = new Contentstack .Builder ().setAuthtoken (AUTHTOKEN ).build ().stack (headers );
3042 roles = stack .roles (_uid );
43+ taxonomy = stack .taxonomy ();
44+ term = stack .taxonomy (Taxonomy_uid ).terms ();
3145 }
3246
3347 @ Test
@@ -111,5 +125,33 @@ void deleteRole() {
111125 Assertions .assertNull (request .url ().encodedQuery ());
112126 Assertions .assertEquals ("https://api.contentstack.io/v3/roles/" + _uid , request .url ().toString ());
113127 }
128+ @ Test
129+ void createRoleWithRule1 () throws IOException {
130+ JSONObject requestTaxonomy = Utils .readJson ("mocktaxonomy/create.json" );
131+ taxonomy .addHeader (Util .API_KEY , API_KEY );
132+ taxonomy .addHeader (Util .AUTHORIZATION , MANAGEMENT_TOKEN );
133+ Call <ResponseBody > responseTaxonomy = taxonomy .create (requestTaxonomy );
134+ Response <ResponseBody > response1 = responseTaxonomy .execute ();
135+ System .out .println ("Taxonomy created" + response1 .body ().string ());
136+
137+ }
138+ @ Test
139+ void createRoleWithRule2 () throws IOException {
140+ JSONObject requestTerm = Utils .readJson ("mocktaxonomy/createTerm.json" );
141+
142+ Response <ResponseBody > response2 = term .create (requestTerm ).execute ();
143+ System .out .println ("Term created" + response2 .toString ());
144+
145+ }
146+ @ Test
147+ void createRoleWithTaxonomy () throws IOException {
148+ JSONObject requestBody = Utils .readJson ("mockrole/createRole.json" );
149+
150+ Call <ResponseBody > responseCall = roles .create (requestBody );
151+ Response <ResponseBody > response = responseCall .execute ();
152+ System .out .println ("Role created" + response .body ().string ());
153+
154+
155+ }
114156
115157}
0 commit comments