1- package com .bunq .sdk . model . generated ;
1+ package com .bunq .sdk ;
22
33import com .bunq .sdk .context .ApiContext ;
44import com .bunq .sdk .context .ApiEnvironmentType ;
55import com .bunq .sdk .exception .ApiException ;
66import com .bunq .sdk .exception .BunqException ;
7+ import com .bunq .sdk .model .generated .User ;
78import java .util .Arrays ;
89import java .util .List ;
910import java .util .Properties ;
1011
1112/**
12- * Checks if the sessionToken stored in the conf file is still valid, if not it will generate a new
13- * one
13+ * Base class for the Bunq SDK tests.
1414 */
15- public class ApiContextHandler {
15+ public class BunqSdkTestBase {
1616
1717 /**
18- * Config fields
18+ * Description of the test device for Java SDK.
19+ */
20+ private static final String DEVICE_DESCRIPTION = "Java test device" ;
21+
22+ /**
23+ * Config fields.
1924 */
20- private static final String DEVICE_DESCRIPTION = "Java test case" ;
2125 private static final String FIELD_API_KEY = "API_KEY" ;
2226 private static final String FIELD_PERMITTED_IPS = "PERMITTED_IPS" ;
2327 private static final String FIELD_API_CONFIG_PATH = "API_CONFIG_PATH" ;
28+
29+ /**
30+ * Delimiter between the IP addresses in the PERMITTED_IPS field.
31+ */
2432 private static final String DELIMITER_IPS = ", " ;
33+
34+ /**
35+ * Properties for the tests.
36+ */
2537 private static Properties config = TestConfig .prop ();
2638
39+ /**
40+ * Individual properties.
41+ */
2742 private static String apiKey = config .getProperty (FIELD_API_KEY );
2843 private static String [] permittedIps = config .getProperty (FIELD_PERMITTED_IPS ).split (
2944 DELIMITER_IPS );
@@ -33,32 +48,20 @@ public class ApiContextHandler {
3348 * Based on the result of isSessionActive will create a new ApiContext or restore an old conf
3449 * file
3550 */
36- public static ApiContext getApiContext () {
51+ protected static ApiContext getApiContext () {
3752 ApiContext apiContext ;
3853
39- if ( isSessionActive ()) {
54+ try {
4055 apiContext = ApiContext .restore (apiConfigPath );
41- } else {
56+ User .list (apiContext );
57+ } catch (ApiException | BunqException exception ) {
4258 List <String > ips = Arrays .asList (permittedIps );
4359 apiContext = ApiContext .create (ApiEnvironmentType .SANDBOX , apiKey , DEVICE_DESCRIPTION , ips );
44- apiContext .save ();
4560 }
4661
47- return apiContext ;
48- }
49-
50- /**
51- * Checks if the session is active by making an API call and see if an Api/Bunq exception is
52- * thrown
53- */
54- private static boolean isSessionActive () {
55- try {
56- User .list (ApiContext .restore (apiConfigPath ));
62+ apiContext .save ();
5763
58- return true ;
59- } catch (ApiException |BunqException exception ) {
60- return false ;
61- }
64+ return apiContext ;
6265 }
6366
6467}
0 commit comments