@@ -15,14 +15,14 @@ public class Test {
15
15
public static void main (String [] args ) throws Exception {
16
16
try {
17
17
test_1 ();
18
-
18
+ test_2 ();
19
19
} catch (Exception e ) {
20
20
e .printStackTrace ();
21
21
}
22
22
}
23
23
24
24
public static void test_1 () throws Exception {
25
-
25
+ System . out . println ( "test_1 START" );
26
26
// Calling Our PID and Key
27
27
String public_PID ;
28
28
String private_KEY ;
@@ -40,24 +40,16 @@ public static void test_1() throws Exception {
40
40
throw new Exception ("Missing PID and/or KEY values" );
41
41
}
42
42
43
- // Listing all Appointment types categories
44
43
String s = Client .get_appointment_types (public_PID );
45
- // System.out.println(s);
46
44
JSONArray jsonarray = new JSONArray (s );
47
45
JSONObject jsonobject = jsonarray .getJSONObject (0 );
48
46
String appointment_types_id = jsonobject .getString ("id" );
49
- assert jsonarray .length () == 3 ; // default 3
47
+ assert jsonarray .length () >= 1 ; // default 3
50
48
51
49
Date date = new Date ();
52
50
DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
53
51
String strDate = dateFormat .format (date );
54
- // List of available days for appointment from a given date
55
- String s1 = Client .get_days_available (public_PID ,
56
- appointment_types_id ,
57
- strDate ,
58
- null ,
59
- null );
60
- // System.out.println(s1);
52
+ String s1 = Client .get_days_available (public_PID , appointment_types_id , strDate , null , null );
61
53
JSONObject obj_2 = new JSONObject (s1 );
62
54
JSONArray json_arr = obj_2 .getJSONArray ("days_available" );
63
55
assert json_arr .length () > 1 ;
@@ -66,50 +58,75 @@ public static void test_1() throws Exception {
66
58
Calendar c = Calendar .getInstance ();
67
59
c .add (Calendar .DATE , 10 ); // number of days to add
68
60
String end_date = (String )(dateFormat .format (c .getTime ()));
69
-
70
- // List of all slot available for appointment between start_date and end_date
71
- String s2 = Client .get_slots_available (public_PID ,
72
- appointment_types_id ,
73
- start_date ,
74
- end_date ,
75
- null );
76
- // System.out.println(s2);
61
+ String s2 = Client .get_slots_available (public_PID , appointment_types_id , start_date , end_date , null );
77
62
78
63
JSONObject obj = new JSONObject (s2 );
79
64
JSONArray arr = obj .getJSONArray ("slots_available" );
80
65
assert arr .length () > 10 ;
81
66
82
67
String date_available = arr .getJSONObject (0 ).getString ("date" );
83
- // Complete Booking of available slot
84
- String s3 = Client .complete_booking (public_PID ,
85
- appointment_types_id ,
86
- date_available , // must be available timeslot from API
87
- null ,
88
- "Shubhanshu" , "Arya" , "shubhanshuarya@example.com" ,
89
- null , "Secure Videochat" );
90
- // System.out.println(s3);
68
+ String s3 = Client .complete_booking (public_PID , appointment_types_id , date_available , null , "Shubhanshu" , "Arya" , "shubhanshuarya@example.com" , null , "Secure Videochat" , null );
91
69
JSONObject obj_3 = new JSONObject (s3 );
92
70
assert obj_3 .has ("appointment" );
93
71
94
- // List of all appointments available
95
72
String s4 = Client .list_appointments (private_KEY , null , null , public_PID );
96
- // System.out.println(s4);
97
-
98
73
JSONObject jsonObj = new JSONObject (s4 );
99
74
assert jsonObj .has ("data" );
100
75
JSONArray arr_value = jsonObj .getJSONObject ("data" ).getJSONArray ("appointments" );
101
- assert arr_value .length () > 1 ;
76
+ assert arr_value .length () >= 1 ;
102
77
String appointment_id = arr_value .getJSONObject (0 ).getString ("id" );
103
- // System.out.println(appointment_id);
104
78
105
- // deleting the appointment
106
79
String s5 = Client .delete_appointment (private_KEY , appointment_id );
107
- // System.out.println(s5);
108
80
JSONObject json_Obj = new JSONObject (s5 );
109
81
assert jsonObj .has ("data" );
110
82
JSONObject json_Obj_2 = json_Obj .getJSONObject ("data" );
111
83
assert json_Obj_2 .has ("appointment" );
112
84
String json_Obj_3 = json_Obj .getJSONObject ("data" ).getJSONObject ("appointment" ).getString ("id" );
113
85
assert json_Obj_3 .equals (appointment_id );
86
+
87
+ System .out .println ("test_1 END" );
88
+ }
89
+ public static void test_2 () throws Exception {
90
+ System .out .println ("test_2 START" );
91
+ // Calling Our PID and Key
92
+ String public_PID ;
93
+ String private_KEY ;
94
+
95
+ if (System .getenv ("SPURWING_PID" ) != null && System .getenv ("SPURWING_KEY" ) != null ) {
96
+ public_PID = System .getenv ("SPURWING_PID" );
97
+ private_KEY = System .getenv ("SPURWING_KEY" );
98
+ }else {
99
+ Credentials private_details = new Credentials ();
100
+ public_PID = private_details .getPID ();
101
+ private_KEY = private_details .getKEY ();
102
+ }
103
+
104
+ if ((public_PID == null || public_PID .trim ().isEmpty ()) || (private_KEY == null || private_KEY .trim ().isEmpty ())){
105
+ throw new Exception ("Missing PID and/or KEY values" );
106
+ }
107
+
108
+ String s = Client .get_appointment_types (public_PID );
109
+ JSONArray jsonarray = new JSONArray (s );
110
+ JSONObject jsonobject = jsonarray .getJSONObject (3 ); // let 4th apt be of group type
111
+ String appointment_type_id = jsonobject .getString ("id" );
112
+ assert jsonarray .length () >= 4 ;
113
+
114
+ DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
115
+ Calendar c = Calendar .getInstance ();
116
+ c .add (Calendar .DATE , 1 ); // number of days to add
117
+ String end_date = (String )(dateFormat .format (c .getTime ()));
118
+ s = Client .create_group_appointment (private_KEY , public_PID , appointment_type_id , end_date );
119
+ jsonobject = new JSONObject (s );
120
+ jsonobject = jsonobject .getJSONObject ("data" ).getJSONObject ("appointment" );
121
+ String apid = jsonobject .getString ("id" );
122
+
123
+ s = Client .complete_booking (public_PID , appointment_type_id , null , null , "John" , "G" , "john@nevolin.be" , null , "java unit test" , apid );
124
+ assert ((new JSONObject (s )).has ("appointment" ));
125
+ s = Client .complete_booking (public_PID , appointment_type_id , null , null , "Bill" , "H" , "bill@nevolin.be" , null , "java unit test" , apid );
126
+ assert ((new JSONObject (s )).has ("appointment" ));
127
+
128
+ s = Client .delete_appointment (private_KEY , apid );
129
+ assert ((new JSONObject (s )).getJSONObject ("data" ).getJSONObject ("appointment" ).has ("id" ));
130
+ System .out .println ("test_2 END" );
114
131
}
115
132
}
0 commit comments