2222import static org .junit .jupiter .api .Assertions .assertNotNull ;
2323import static org .junit .jupiter .api .Assertions .assertThrows ;
2424
25- import io .restassured .builder .RequestSpecBuilder ;
26- import io .restassured .builder .ResponseSpecBuilder ;
27- import io .restassured .http .ContentType ;
28- import io .restassured .specification .RequestSpecification ;
29- import io .restassured .specification .ResponseSpecification ;
3025import org .apache .fineract .client .feign .util .CallFailedRuntimeException ;
3126import org .apache .fineract .client .models .GetOfficesResponse ;
3227import org .apache .fineract .client .models .PostClientsRequest ;
28+ import org .apache .fineract .client .util .Calls ;
3329import org .apache .fineract .integrationtests .common .ClientHelper ;
30+ import org .apache .fineract .integrationtests .common .FineractClientHelper ;
3431import org .apache .fineract .integrationtests .common .OfficeHelper ;
35- import org .apache .fineract .integrationtests .common .SchedulerJobHelper ;
36- import org .apache .fineract .integrationtests .common .Utils ;
3732import org .apache .fineract .integrationtests .support .instancemode .ConfigureInstanceMode ;
3833import org .apache .fineract .integrationtests .support .instancemode .InstanceModeSupportExtension ;
3934import org .junit .jupiter .api .BeforeEach ;
4338@ ExtendWith (InstanceModeSupportExtension .class )
4439public class InstanceModeIntegrationTest {
4540
46- private ResponseSpecification responseSpec200 ;
47- private ResponseSpecification responseSpec405 ;
48- private RequestSpecification requestSpec ;
49- private SchedulerJobHelper schedulerJobHelper ;
50- private int jobId ;
41+ private Long jobId ;
5142
5243 @ BeforeEach
5344 public void setup () throws InterruptedException {
54- Utils .initializeRESTAssured ();
55-
56- requestSpec = new RequestSpecBuilder ().setContentType (ContentType .JSON ).build ();
57- requestSpec .header ("Authorization" , "Basic " + Utils .loginIntoServerAndGetBase64EncodedAuthenticationKey ());
58- requestSpec .header ("Fineract-Platform-TenantId" , "default" );
59- responseSpec200 = new ResponseSpecBuilder ().expectStatusCode (200 ).build ();
60- responseSpec405 = new ResponseSpecBuilder ().expectStatusCode (405 ).build ();
61-
62- schedulerJobHelper = new SchedulerJobHelper (requestSpec );
63- // Apply Annual Fee For Savings"
64- jobId = schedulerJobHelper .getSchedulerJobIdByShortName ("SA_AANF" );
45+ // Apply Annual Fee For Savings
46+ jobId = Calls .ok (FineractClientHelper .getFineractClient ().jobs .retrieveByShortName ("SA_AANF" )).getJobId ();
6547 }
6648
6749 @ ConfigureInstanceMode (readEnabled = true , writeEnabled = false , batchWorkerEnabled = false , batchManagerEnabled = false )
@@ -99,9 +81,8 @@ public void testGetHeadOfficeDoesntWork_WhenInstanceModeIsBatchOnly() {
9981 public void testCreateClientDoesntWork_WhenReadOnly () {
10082 // given
10183 PostClientsRequest request = ClientHelper .defaultClientCreationRequest ();
102- // when
103- ClientHelper .createClient (requestSpec , responseSpec405 , request );
104- // then no exception thrown
84+ // when/then
85+ assertThrows (RuntimeException .class , () -> ClientHelper .createClient (request ));
10586 }
10687
10788 @ ConfigureInstanceMode (readEnabled = false , writeEnabled = true , batchWorkerEnabled = false , batchManagerEnabled = false )
@@ -110,7 +91,7 @@ public void testCreateClientWorks_WhenWriteOnly() {
11091 // given
11192 PostClientsRequest request = ClientHelper .defaultClientCreationRequest ();
11293 // when
113- Integer result = ClientHelper .createClient (requestSpec , responseSpec200 , request );
94+ var result = ClientHelper .createClient (request );
11495 // then
11596 assertNotNull (result );
11697 }
@@ -120,35 +101,29 @@ public void testCreateClientWorks_WhenWriteOnly() {
120101 public void testCreateClientDoesntWork_WhenBatchOnly () {
121102 // given
122103 PostClientsRequest request = ClientHelper .defaultClientCreationRequest ();
123- // when
124- ClientHelper .createClient (requestSpec , responseSpec405 , request );
125- // then no exception thrown
104+ // when/then
105+ assertThrows (RuntimeException .class , () -> ClientHelper .createClient (request ));
126106 }
127107
128108 @ ConfigureInstanceMode (readEnabled = true , writeEnabled = false , batchWorkerEnabled = false , batchManagerEnabled = false )
129109 @ Test
130110 public void testRunSchedulerJobDoesntWork_WhenReadOnly () {
131- // given
132- // when
133- schedulerJobHelper .runSchedulerJob (jobId , responseSpec405 );
134- // then no exception thrown
111+ // when/then
112+ assertThrows (RuntimeException .class , () -> Calls .ok (FineractClientHelper .getFineractClient ().jobs .executeJob (jobId , "executeJob" )));
135113 }
136114
137115 @ ConfigureInstanceMode (readEnabled = false , writeEnabled = true , batchWorkerEnabled = false , batchManagerEnabled = false )
138116 @ Test
139117 public void testRunSchedulerJobDoesntWork_WhenWriteOnly () {
140- // given
141- // when
142- schedulerJobHelper .runSchedulerJob (jobId , responseSpec405 );
143- // then no exception thrown
118+ // when/then
119+ assertThrows (RuntimeException .class , () -> Calls .ok (FineractClientHelper .getFineractClient ().jobs .executeJob (jobId , "executeJob" )));
144120 }
145121
146122 @ ConfigureInstanceMode (readEnabled = false , writeEnabled = false , batchWorkerEnabled = true , batchManagerEnabled = true )
147123 @ Test
148124 public void testRunSchedulerJobWorks_WhenBatchOnly () {
149- // given
150125 // when
151- schedulerJobHelper . runSchedulerJob ( jobId );
126+ Calls . ok ( FineractClientHelper . getFineractClient (). jobs . executeJob ( jobId , "executeJob" ) );
152127 // then no exception thrown
153128 }
154129}
0 commit comments