diff --git a/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_1_12_10.xml b/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_1_12_10.xml
new file mode 100644
index 0000000..b25c402
--- /dev/null
+++ b/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_1_12_10.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_assertj_assertj_core_3_23_1.xml b/.idea/libraries/Gradle__org_assertj_assertj_core_3_23_1.xml
new file mode 100644
index 0000000..6bcd7aa
--- /dev/null
+++ b/.idea/libraries/Gradle__org_assertj_assertj_core_3_23_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/lib/solussdk.lib.iml b/.idea/modules/lib/solussdk.lib.iml
new file mode 100644
index 0000000..0a126a9
--- /dev/null
+++ b/.idea/modules/lib/solussdk.lib.iml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/build.gradle b/lib/build.gradle
index 165f1d2..3e1776d 100644
--- a/lib/build.gradle
+++ b/lib/build.gradle
@@ -39,6 +39,7 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
+ testImplementation("org.assertj:assertj-core:3.23.1")
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
diff --git a/lib/src/main/java/com/tuti/Library.java b/lib/src/main/java/com/tuti/Library.java
index 14ba556..68fb35e 100644
--- a/lib/src/main/java/com/tuti/Library.java
+++ b/lib/src/main/java/com/tuti/Library.java
@@ -4,7 +4,8 @@
package com.tuti;
import com.tuti.api.TutiApiClient;
-import com.tuti.api.authentication.SignInInfo;
+import com.tuti.api.authentication.SignInRequest;
+import com.tuti.api.data.Card;
public class Library {
@@ -13,8 +14,8 @@ public static void main(String[] args) {
TutiApiClient client = new TutiApiClient(true);
client.setSingleThreaded(true);
- client.SignIn(new SignInInfo("adonese","12345678"),
- param -> {
+ client.SignIn(new SignInRequest("adonese","12345678"),
+ (param,response) -> {
jwt=param.getAuthorizationJWT();
System.out.println(jwt);
@@ -23,10 +24,16 @@ public static void main(String[] args) {
});
client.setAuthToken(jwt);
- client.getCards(param -> {
- System.out.println(param.getCards().get(0).getPAN());
- },(param, e,res) -> {
- System.out.println(param);
- });
+
+ Card card = new Card();
+ card.setName("JAVA SDK");
+ card.setExpiryDate("2020");
+ card.setPAN("1111222233334444");
+ client.addCard(card,(objectReceived, rawResponse) -> {
+ System.out.println(objectReceived);
+ } ,
+ (errorReceived, exception, rawResponse) -> {
+ System.out.println(errorReceived);
+ });
}
}
diff --git a/lib/src/main/java/com/tuti/api/TutiApiClient.java b/lib/src/main/java/com/tuti/api/TutiApiClient.java
index 44b4894..92ff299 100644
--- a/lib/src/main/java/com/tuti/api/TutiApiClient.java
+++ b/lib/src/main/java/com/tuti/api/TutiApiClient.java
@@ -2,11 +2,12 @@
import com.google.gson.Gson;
import com.tuti.api.authentication.SignInResponse;
-import com.tuti.api.authentication.SignUpInfo;
+import com.tuti.api.authentication.SignUpRequest;
import com.tuti.api.authentication.SignUpResponse;
-import com.tuti.api.authentication.SignInInfo;
+import com.tuti.api.authentication.SignInRequest;
import com.tuti.api.data.Card;
import com.tuti.api.data.Cards;
+import com.tuti.api.data.RequestMethods;
import com.tuti.api.ebs.EBSRequest;
import com.tuti.api.ebs.EBSResponse;
import com.tuti.model.Operations;
@@ -14,6 +15,7 @@
import java.io.IOException;
import java.lang.reflect.Type;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
public class TutiApiClient {
@@ -23,7 +25,7 @@ public class TutiApiClient {
private static volatile Gson gson = null;
private String serverURL;
private boolean isSingleThreaded = false;
- private String authToken = "";
+ private String authToken = null;
public String getAuthToken() {
return authToken;
@@ -64,26 +66,26 @@ private String getServerURL(boolean development) {
return development ? developmentHost : productionHost;
}
- public void SignIn(SignInInfo credentials,ResponseCallable onResponse,ErrorCallable onError){
- sendPostRequest(serverURL + Operations.SIGN_IN,credentials, SignInResponse.class,String.class,onResponse,onError);
+ public void SignIn(SignInRequest credentials, ResponseCallable onResponse, ErrorCallable onError){
+ sendRequest( RequestMethods.POST,serverURL + Operations.SIGN_IN,credentials, SignInResponse.class,String.class,onResponse,onError,null);
}
- public void Signup(SignUpInfo signUpInfo,ResponseCallable onResponse,ErrorCallable onError){
- sendPostRequest( serverURL + Operations.SIGN_UP,signUpInfo,SignUpResponse.class,String.class,onResponse,onError);
+ public void Signup(SignUpRequest signUpRequest, ResponseCallable onResponse, ErrorCallable onError){
+ sendRequest( RequestMethods.POST,serverURL + Operations.SIGN_UP, signUpRequest,SignUpResponse.class,String.class,onResponse,onError,null);
}
- public void sendEBSRequest(String URL,EBSRequest ebsRequest, ResponseCallable onResponse, ErrorCallable onError){
- sendPostRequest( URL,ebsRequest,EBSResponse.class,EBSResponse.class,onResponse,onError);
+ public void sendEBSRequest(String URL,EBSRequest ebsRequest, ResponseCallable onResponse, ErrorCallable onError){
+ sendRequest( RequestMethods.POST, URL,ebsRequest,EBSResponse.class,EBSResponse.class,onResponse,onError,null);
}
- public void getCards( ResponseCallable onResponse, ErrorCallable onError){
- sendGetRequest( serverURL + Operations.GET_CARDS, Cards.class,String.class,onResponse,onError);
+ public void getCards( ResponseCallable onResponse, ErrorCallable onError){
+ sendRequest( RequestMethods.GET,serverURL + Operations.GET_CARDS, null,Cards.class,String.class,onResponse,onError,null);
}
- public void addCard(Card card, ResponseCallable onResponse, ErrorCallable onError){
- sendPostRequest( serverURL + Operations.ADD_CARD,card,String.class,String.class,onResponse,onError);
+ public void addCard(Card card, ResponseCallable onResponse, ErrorCallable onError){
+ sendRequest( RequestMethods.POST,serverURL + Operations.ADD_CARD,card,String.class,String.class,onResponse,onError,null);
}
- public void sendPostRequest(String URL, Object requestToBeSent, Type ResponseType, Type ErrorType, ResponseCallable onResponse, ErrorCallable onError ){
+ public Thread sendRequest(RequestMethods method, String URL, Object requestToBeSent, Type ResponseType, Type ErrorType, ResponseCallable onResponse, ErrorCallable onError, Map headers){
// create a runnable to run it in a new thread (so main thread never hangs)
Runnable runnable = () ->{
@@ -93,91 +95,72 @@ public void sendPostRequest(String URL, Object requestToBeSent, Type ResponseTyp
RequestBody requestBody = RequestBody.create(gson.toJson(requestToBeSent),JSON);
+ Request.Builder requestBuilder = new Request.Builder().url(URL);
- Request request = new Request.Builder()
- .url(URL)
- .header("Authorization",authToken)
- .post(requestBody)
- .build();
+ if (authToken != null) requestBuilder.header("Authorization",authToken);
+
+ //add additional headers set by the user
+ if(headers != null){
+ for (String key : headers.keySet()){
+ requestBuilder.header(key, headers.get(key));
+ }
+ }
+
+ //check for http method set by the user
+ if (method == RequestMethods.POST){
+ requestBuilder.post(requestBody);
+ }else{
+ requestBuilder.get();
+ }
+
+ Request request = requestBuilder.build();
+
+ try (Response rawResponse = okHttpClient.newCall(request).execute()) {
- try (Response response = okHttpClient.newCall(request).execute()) {
// check for http errors
- if (response.code() >= 400 && response.code() < 600){
+ if (rawResponse.code() >= 400 && rawResponse.code() < 600){
// call onError if request has failed
- if(onError != null) { onError.call(processResponse(response,ErrorType),null,response.code()); }
+ if(onError != null) { onError.call(parseResponse(rawResponse,ErrorType),null,rawResponse); }
}else{
// call onResponse if request has succeeded
- if(onResponse != null) { onResponse.call(processResponse(response,ResponseType)); }
+ if(onResponse != null) { onResponse.call(parseResponse(rawResponse,ResponseType),rawResponse); }
}
}catch(Exception exception){
- onError.call(null,exception,-1);
+ exception.printStackTrace();
+ if(onError != null) onError.call(null,exception,null);
}
};
// unit testing concurrent code on multiple threads is hard
- if (isSingleThreaded){
- new Thread(runnable).run();
- }else {
- new Thread(runnable).start();
- }
- }
- public void sendGetRequest(String URL, Type ResponseType,Type ErrorType, ResponseCallable onResponse, ErrorCallable onError ){
+ Thread thread = new Thread(runnable);
- // create a runnable to run it in a new thread (so main thread never hangs)
- Runnable runnable = () ->{
- OkHttpClient okHttpClient = getOkHttpInstance();
- Gson gson = getGsonInstance();
-
- Request request = new Request.Builder()
- .url(URL)
- .header("Authorization",authToken)
- .get()
- .build();
-
- try (Response response = okHttpClient.newCall(request).execute()) {
- // check for http errors
- if (response.code() >= 400 && response.code() < 600){
- // call onError if request has failed
- if(onError != null) { onError.call(processResponse(response,ErrorType),null,response.code()); }
-
- }else{
- // call onResponse if request has succeeded
- if(onResponse != null) { onResponse.call(processResponse(response,ResponseType)); }
- }
+ if (isSingleThreaded) {
+ thread.run();
+ } else {
+ thread.start();
+ }
- }catch(Exception exception){
- exception.printStackTrace();
- // call on error in case of exception
- onError.call(null,exception,-1);
- }
- };
+ return thread;
+ }
- // unit testing concurrent code on multiple threads is hard
- if (isSingleThreaded){
- new Thread(runnable).run();
- }else {
- new Thread(runnable).start();
- }
+ private Object parseResponse(Response rawResponse, Type ResponseType) throws IOException {
+ Gson gson = getGsonInstance();
+ String responseAsString = rawResponse.body().string();
+ return isTypeStringOrNull(ResponseType) ? responseAsString : gson.fromJson(responseAsString, ResponseType);
}
- Object processResponse(Response response,Type ResponseType) throws IOException {
- Object finalResponse;
- if (ResponseType == String.class || ResponseType == null) {
- finalResponse = response.body().string();
- }else{
- finalResponse = gson.fromJson(response.body().string(), ResponseType);
- }
- return finalResponse;
+ private boolean isTypeStringOrNull(Type type){
+ return (type == String.class || type == null);
}
public interface ResponseCallable {
- void call(T param);
+ void call(T objectReceived,Response rawResponse);
}
public interface ErrorCallable {
- void call(T param,Exception exception,int responseCode);
+ void call(T errorReceived,Exception exception,Response rawResponse);
}
}
diff --git a/lib/src/main/java/com/tuti/api/authentication/SignInInfo.java b/lib/src/main/java/com/tuti/api/authentication/SignInRequest.java
similarity index 65%
rename from lib/src/main/java/com/tuti/api/authentication/SignInInfo.java
rename to lib/src/main/java/com/tuti/api/authentication/SignInRequest.java
index 2e4e241..4895e4e 100644
--- a/lib/src/main/java/com/tuti/api/authentication/SignInInfo.java
+++ b/lib/src/main/java/com/tuti/api/authentication/SignInRequest.java
@@ -1,6 +1,6 @@
package com.tuti.api.authentication;
-public class SignInInfo {
+public class SignInRequest {
private String username;
private String password;
@@ -8,12 +8,12 @@ public String getUsername() {
return username;
}
- public SignInInfo(String username, String password) {
+ public SignInRequest(String username, String password) {
this.username = username;
this.password = password;
}
- public SignInInfo setUsername(String username) {
+ public SignInRequest setUsername(String username) {
this.username = username;
return this;
}
@@ -22,7 +22,7 @@ public String getPassword() {
return password;
}
- public SignInInfo setPassword(String password) {
+ public SignInRequest setPassword(String password) {
this.password = password;
return this;
}
diff --git a/lib/src/main/java/com/tuti/api/authentication/SignUpInfo.java b/lib/src/main/java/com/tuti/api/authentication/SignUpRequest.java
similarity index 93%
rename from lib/src/main/java/com/tuti/api/authentication/SignUpInfo.java
rename to lib/src/main/java/com/tuti/api/authentication/SignUpRequest.java
index ae7d3ff..39ac958 100644
--- a/lib/src/main/java/com/tuti/api/authentication/SignUpInfo.java
+++ b/lib/src/main/java/com/tuti/api/authentication/SignUpRequest.java
@@ -2,7 +2,7 @@
import com.google.gson.annotations.SerializedName;
-public class SignUpInfo {
+public class SignUpRequest {
private String username;
private String password;
diff --git a/lib/src/main/java/com/tuti/api/authentication/User.java b/lib/src/main/java/com/tuti/api/authentication/User.java
index 7a9b1b3..673c62b 100644
--- a/lib/src/main/java/com/tuti/api/authentication/User.java
+++ b/lib/src/main/java/com/tuti/api/authentication/User.java
@@ -98,4 +98,19 @@ public void setIsMerchant(boolean isMerchant) {
this.isMerchant = isMerchant;
}
+ @Override
+ public String toString() {
+ return "User{" +
+ "id=" + id +
+ ", createdAt='" + createdAt + '\'' +
+ ", updateAt='" + updateAt + '\'' +
+ ", DeletedAt='" + DeletedAt + '\'' +
+ ", username='" + username + '\'' +
+ ", fullname='" + fullname + '\'' +
+ ", birthday='" + birthday + '\'' +
+ ", mobileNumber='" + mobileNumber + '\'' +
+ ", email='" + email + '\'' +
+ ", isMerchant=" + isMerchant +
+ '}';
+ }
}
diff --git a/lib/src/main/java/com/tuti/api/data/Card.java b/lib/src/main/java/com/tuti/api/data/Card.java
index edb9d1c..2ad8d85 100644
--- a/lib/src/main/java/com/tuti/api/data/Card.java
+++ b/lib/src/main/java/com/tuti/api/data/Card.java
@@ -32,4 +32,13 @@ public String getPAN() {
public void setPAN(String PAN) {
this.PAN = PAN;
}
+
+ @Override
+ public String toString() {
+ return "Card{" +
+ "name='" + name + '\'' +
+ ", expiryDate='" + expiryDate + '\'' +
+ ", PAN='" + PAN + '\'' +
+ '}';
+ }
}
diff --git a/lib/src/main/java/com/tuti/api/data/RequestMethods.java b/lib/src/main/java/com/tuti/api/data/RequestMethods.java
new file mode 100644
index 0000000..2381794
--- /dev/null
+++ b/lib/src/main/java/com/tuti/api/data/RequestMethods.java
@@ -0,0 +1,6 @@
+package com.tuti.api.data;
+
+public enum RequestMethods {
+ GET,
+ POST
+}
diff --git a/lib/src/main/java/com/tuti/main/SdkUtil.java b/lib/src/main/java/com/tuti/main/SdkUtil.java
deleted file mode 100644
index 0ffaa79..0000000
--- a/lib/src/main/java/com/tuti/main/SdkUtil.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.tuti.main;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.UUID;
-
-public class SdkUtil {
-
- public static String getDate(){
- DateFormat dateFormat = new SimpleDateFormat("ddMMyyHHmmss", Locale.US);
- Date date = new Date();
- String format = dateFormat.format(date);
- System.out.println(format);
- return format;
- }
-
-
- public static String getUuid() {
- String string = UUID.randomUUID().toString();
- //System.out.println(string);
- return string;
- }
-
-
-}
diff --git a/lib/src/main/java/com/tuti/model/IPIN.java b/lib/src/main/java/com/tuti/model/IPIN.java
index e20edce..96ab1f5 100644
--- a/lib/src/main/java/com/tuti/model/IPIN.java
+++ b/lib/src/main/java/com/tuti/model/IPIN.java
@@ -69,4 +69,10 @@ public static String getIPINBlock(String encryptedIPIN,
}
return encryptedIPIN;
}
+<<<<<<< HEAD
+
+
+
+=======
+>>>>>>> c4110956f3279116b914dceac561840ea4b49d79
}
diff --git a/lib/src/main/java/com/tuti/util/NamesForUnitTests.java b/lib/src/main/java/com/tuti/util/NamesForUnitTests.java
new file mode 100644
index 0000000..f96fdbe
--- /dev/null
+++ b/lib/src/main/java/com/tuti/util/NamesForUnitTests.java
@@ -0,0 +1,815 @@
+package com.tuti.util;
+
+public class NamesForUnitTests {
+ public static String[] names = {"Abbad",
+ "Abbas",
+ "Abd al-Uzza",
+ "Abdus Salam",
+ "Abd Manaf",
+ "Abd Rabbo",
+ "Abdel Fattah",
+ "Abdel Nour",
+ "Abdi",
+ "Abdolreza",
+ "Abdu",
+ "Abdul",
+ "Abdul Ahad",
+ "Abdul Ali",
+ "Abdul Alim",
+ "Abdul Azim",
+ "Abd al-Aziz",
+ "Abdul Baqi",
+ "Abdul Bari",
+ "Abdul Basir",
+ "Abdul Basit",
+ "Abdul Ghaffar",
+ "Abdul Ghani",
+ "Abdul Hadi",
+ "Abdul Hafiz",
+ "Abdul Hai",
+ "Abdul Hakim",
+ "Abdul Halim",
+ "Abdul Hamid",
+ "Abdul Haq",
+ "Abdul Hussein",
+ "Abdul Jabbar",
+ "Abdul Jalil",
+ "Abdul Jamil",
+ "Abdul Karim",
+ "Abdul Khaliq",
+ "Abdul Latif",
+ "Abdul Majid",
+ "Abdul Malik",
+ "Abdul Mannan",
+ "Abdul Monem",
+ "Abdul Muttalib",
+ "Abdul Qadir",
+ "Abdul Qayyum",
+ "Abdul Quddus",
+ "Abdul Rashid",
+ "Abdul Samad",
+ "Abdul Sattar",
+ "Abdul Wadud",
+ "Abdul Wahhab",
+ "Abdul Wahid",
+ "Abdul Zahir",
+ "Abdul Zahra",
+ "Abdullah",
+ "Abdur Rab",
+ "Abdur Rahim",
+ "Abd al-Rahman",
+ "Abdur Raqib",
+ "Abdur Rauf",
+ "Abdur Razzaq",
+ "Abdus Sabur",
+ "Abdus Shakur",
+ "Abid",
+ "Abidin",
+ "Abla",
+ "Abo",
+ "Ab",
+ "Abu Abdullah",
+ "Abu al-Qasim",
+ "Abu Bakr",
+ "Abu Hafs",
+ "Abu Hamza",
+ "Abu Nasir",
+ "Abu Nasr",
+ "Abu'l-Fadl",
+ "Adam",
+ "Adeel",
+ "Adeem",
+ "Adem",
+ "Aden",
+ "Adham",
+ "Adib",
+ "Adil",
+ "Adir",
+ "Adli",
+ "Adnan",
+ "Afif",
+ "Ahad",
+ "Ahmad",
+ "Ahmed Tijani",
+ "Ahsan",
+ "Akeem",
+ "Akif",
+ "Akram",
+ "Alaa",
+ "Aladdin",
+ "Ali",
+ "Ali Naqi",
+ "Ali Reza",
+ "Alim",
+ "Aman",
+ "Aman Ali",
+ "Amanullah",
+ "Amer",
+ "Amin",
+ "Amin al-Din",
+ "Aminullah",
+ "Amir",
+ "Amjad",
+ "Ammar",
+ "Amr",
+ "Anas",
+ "Anis",
+ "Anisur Rahman",
+ "Anjem",
+ "Anwar",
+ "Anwaruddin",
+ "Aqeel",
+ "Ari",
+ "Arif",
+ "Asad",
+ "Asadullah",
+ "Asem",
+ "Asghar",
+ "Ashraf",
+ "Asif",
+ "Asil",
+ "Islam",
+ "Ataullah",
+ "Atif",
+ "Atiq",
+ "Atiqullah",
+ "Awad",
+ "Ayad",
+ "Ayman",
+ "Ayub",
+ "Azem",
+ "Azeem",
+ "Azhar",
+ "Azim",
+ "Azimullah",
+ "Aziz",
+ "Azizullah",
+ "Azizur Rahman",
+ "Azmi",
+ "Azus",
+ "Abu Bakr",
+ "Badi",
+ "Badr al-Din",
+ "Bagher",
+ "Baha",
+ "Baha' al-Din",
+ "Bahri",
+ "Baki",
+ "Bakir",
+ "Bara",
+ "Barkat Ali",
+ "Barkatullah",
+ "Bashar",
+ "Bashir",
+ "Basri",
+ "Bilal",
+ "Bilel",
+ "Billah",
+ "Boualem",
+ "Boulos",
+ "Boutros",
+ "Brahim",
+ "Burhan",
+ "Burhan al-Din",
+ "Caden",
+ "Chadli",
+ "Daniel",
+ "Dastgir",
+ "Daud",
+ "Dawoud",
+ "Dhikrullah",
+ "Ehsanullah",
+ "Ekram",
+ "Fadel",
+ "Fahd",
+ "Faheem",
+ "Fahmi",
+ "Fahri",
+ "Faisal",
+ "Faiz",
+ "Faizan",
+ "Faizullah",
+ "Fakhr al-Din",
+ "Fakhraddin",
+ "Fakhruddin",
+ "Faqir",
+ "Faraj",
+ "Farhat",
+ "Farid",
+ "Fariduddin",
+ "Faris",
+ "Farooq",
+ "Fasih",
+ "Fathallah",
+ "Fathi",
+ "Fatin",
+ "Fawaz",
+ "Fawzi",
+ "Fayez",
+ "Fazel",
+ "Fazl",
+ "Fazl ur Rahman",
+ "Fazlallah",
+ "Fazli",
+ "Fazlul Haq",
+ "Fazlul Karim",
+ "Fikri",
+ "Fouzan",
+ "Fouad",
+ "Fuad",
+ "Furkan",
+ "Gaffar",
+ "Gamil",
+ "Ghanem",
+ "Ghassan",
+ "Ghiyath al-Din",
+ "Ghulam",
+ "Ghulam Faruq",
+ "Ghulam Mohiuddin",
+ "Gulzar",
+ "Habib",
+ "Habib ur Rahman",
+ "Habibullah",
+ "Hadem",
+ "Hadi",
+ "Hadid",
+ "Hafeez",
+ "Hafizullah",
+ "Haitham",
+ "Hajj",
+ "Hajji",
+ "Hakam",
+ "Hakim",
+ "Haldun",
+ "Halim",
+ "Halim",
+ "Hamdan",
+ "Hamdi",
+ "Hamid",
+ "Hamid al-Din",
+ "Hamidullah",
+ "Hamza",
+ "Hani",
+ "Harbi",
+ "Hanif",
+ "Harun",
+ "Hashem",
+ "Hashim",
+ "Hasib",
+ "Hassan",
+ "Hassim",
+ "Hatem",
+ "Hayatullah",
+ "Haydar",
+ "Hazem",
+ "Hibat Allah",
+ "Hichem",
+ "Hidayatullah",
+ "Hikmat",
+ "Hilmi",
+ "Hisham",
+ "Hisham ud-Din",
+ "Hossam",
+ "Hurairah",
+ "Husam ad-Din",
+ "Hussein",
+ "Ibrahim",
+ "Ibro",
+ "Idris",
+ "Idris",
+ "Ihab",
+ "Ihsan",
+ "Ikhtiyar al-Din",
+ "Ikramullah",
+ "Ikrimah",
+ "Ilyas",
+ "Imad",
+ "Imad al-Din",
+ "Imran",
+ "Imtiaz",
+ "Inaam",
+ "Inam-ul-Haq",
+ "Inayatullah",
+ "Iqbal",
+ "Irfan",
+ "Isa",
+ "Ishak",
+ "Issam",
+ "Ishtiaq",
+ "Iskandar",
+ "Ismail",
+ "Ismat ad-Din",
+ "Ismatullah",
+ "Izz al-Din",
+ "Izzat",
+ "Izzatullah",
+ "Ja'far",
+ "Jabal",
+ "Jaber",
+ "Jabir",
+ "Jabr",
+ "Jahid",
+ "Jalal",
+ "Jalal ad-Din",
+ "Jamal",
+ "Jamal ad-Din",
+ "Jameel",
+ "Jamil",
+ "Jarrah",
+ "Jasem",
+ "Jawad",
+ "Jawdat",
+ "Jihad",
+ "Jubayr",
+ "Junayd",
+ "Jurj",
+ "Min",
+ "Ka'b",
+ "Kadeem",
+ "Kadir",
+ "Kadri",
+ "Kafeel",
+ "Kamal ad-Din",
+ "Kamil",
+ "Karem",
+ "Karim",
+ "Kashif",
+ "Kazem",
+ "Khadem",
+ "Khair ad-Din",
+ "Khakim",
+ "Khalfan",
+ "Khalid",
+ "Khalifah",
+ "Khalil",
+ "Khalil-ur-Rehman",
+ "Khakim",
+ "Khamis",
+ "Kulthum",
+ "Labib",
+ "Lalji",
+ "Latif",
+ "Luay",
+ "Lutfullah",
+ "Lutfur Rahman",
+ "Mahalati",
+ "Mahbubur",
+ "Mahdi",
+ "Mahfuz",
+ "Mahir",
+ "Mahmud",
+ "Majid",
+ "Malik",
+ "Mamdouh",
+ "Mansur",
+ "Manzur",
+ "Marwan",
+ "Mashallah",
+ "Masih",
+ "Masoud",
+ "Maytham",
+ "Mehdi",
+ "Melhem",
+ "Michel",
+ "Midhat",
+ "Mizanur Rahman",
+ "Moatassem",
+ "Moeen",
+ "Moemen",
+ "Mohammad Taqi",
+ "Mohannad",
+ "Mohy al-Din",
+ "Moin",
+ "Moinuddin",
+ "Mojtaba",
+ "Moncef",
+ "Moneim",
+ "Mu'iz ad-Din",
+ "Mua'dh",
+ "Muammer",
+ "Mubarak",
+ "Muhammad",
+ "Muharrem",
+ "Muhibullah",
+ "Muhsin",
+ "Mukhtar",
+ "Mumtaz",
+ "Munib",
+ "Munif",
+ "Munir",
+ "Murad",
+ "Murtaza",
+ "Musa",
+ "Muslim",
+ "Mustafa",
+ "Muzaffar",
+ "Nabih",
+ "Nabil",
+ "Nadeem",
+ "Nader",
+ "Nadir",
+ "Nadur",
+ "Naguib",
+ "Nahyan",
+ "Naif",
+ "Naim",
+ "Naji",
+ "Najib",
+ "Najibullah",
+ "Najim",
+ "Najm",
+ "Najm al-Din",
+ "Naqibullah",
+ "Naseeb",
+ "Naseer",
+ "Nasim",
+ "Nasir",
+ "Nasir al-Din",
+ "Nasrallah",
+ "Nasri",
+ "Nasser",
+ "Nassif",
+ "Nasuh",
+ "Nawaf",
+ "Nawaz",
+ "Nowfal",
+ "Nazif",
+ "Nazim",
+ "Nazimuddin",
+ "Nazmi",
+ "Nihad",
+ "Nimatullah",
+ "Nizam al-Din",
+ "Nu'man",
+ "Numan",
+ "Nuh",
+ "Nur",
+ "Nur al-Din",
+ "Nuri",
+ "Nurullah",
+ "Nusrat",
+ "Omar",
+ "Osama",
+ "Othman",
+ "Qaid",
+ "Qamar ud-Din",
+ "Qasim",
+ "Qasymbek",
+ "Quddus",
+ "Qudratullah",
+ "Qusay",
+ "Qutb",
+ "Qutb ad-Din",
+ "Rabih",
+ "Raed",
+ "Rafiq",
+ "Rahim",
+ "Rahman",
+ "Rahmatullah",
+ "Rahmi",
+ "Rajab",
+ "Rajaei",
+ "Raji",
+ "Ramiz",
+ "Ramzan",
+ "Rakibul",
+ "Rakib",
+ "Ramzi",
+ "Rashad",
+ "Rashid",
+ "Rashid al-Din",
+ "Rasul",
+ "Rayan",
+ "Redouane",
+ "Reza",
+ "Riad",
+ "Riaz",
+ "Ridwan",
+ "Rifat",
+ "Rizqallah",
+ "Ruhi",
+ "Ruhullah",
+ "Rukn al-Din",
+ "Rushdi",
+ "Sa'd al-Din",
+ "Seif ilislam",
+ "Sa‘id",
+ "Saud",
+ "Saad",
+ "Saadallah",
+ "Sabri",
+ "Sabah ad-Din",
+ "Saddam",
+ "Sadik",
+ "Sadr al-Din",
+ "Safi",
+ "Safi al-Din",
+ "Safiullah",
+ "Sahir",
+ "Saif",
+ "Saifullah",
+ "Saifur Rahman",
+ "Sajid",
+ "Sajjad",
+ "Sakina",
+ "Salah",
+ "Salah ad-Din",
+ "Saleh",
+ "Salem",
+ "Salim",
+ "Salman",
+ "Samadu",
+ "Samee",
+ "Samer",
+ "Sami",
+ "Samir",
+ "Samirah",
+ "Samiullah",
+ "Sanaullah",
+ "Saqib",
+ "Sardar",
+ "Sarmad",
+ "Satam",
+ "Sattar",
+ "Sayf al-Din",
+ "Sayyid",
+ "Shaban",
+ "Shad",
+ "Shafiq ur Rahman",
+ "Shafiqullah",
+ "Shahid",
+ "Shahrukh",
+ "Shakeel",
+ "Shakir",
+ "Shams",
+ "Shams al-Din",
+ "Shamsur Rahman",
+ "Sharaf al-Din",
+ "Sharifullah",
+ "Shawkat",
+ "Shawki",
+ "Shiraz",
+ "Shihab al-Din",
+ "Shujauddin",
+ "Shukri",
+ "Sidique",
+ "Sidqi",
+ "Sirajuddin",
+ "Suhail",
+ "Suleiman",
+ "Sultan",
+ "Shaheed",
+ "Taha",
+ "Taher",
+ "Tahmid",
+ "Tahsin",
+ "Talal",
+ "Talat",
+ "Talat",
+ "Talhah",
+ "Talib",
+ "Taqi",
+ "Taqi al-Din",
+ "Tarazi",
+ "Tariq",
+ "Tawfik",
+ "Tayeb",
+ "Tayfur",
+ "Tufail",
+ "Turki",
+ "Ubay",
+ "Ubayd Allah",
+ "Uday",
+ "Uthman",
+ "Usama",
+ "Wadih",
+ "Wadud",
+ "Wael",
+ "Wafi",
+ "Wahed",
+ "Wahid",
+ "Wajdi",
+ "Wajid",
+ "Waleed",
+ "Waliullah",
+ "Wasim",
+ "Wazir",
+ "Wissem",
+ "Yacine",
+ "Yadollah",
+ "Yahya",
+ "Yakub",
+ "Yahir",
+ "Yasser",
+ "Yunus",
+ "Yusha",
+ "Yusuf",
+ "Yusuf Ali",
+ "Zafar",
+ "Zafarullah",
+ "Zafer",
+ "Zahed",
+ "Zahir",
+ "Zahir al-Din",
+ "Zaid",
+ "Zaim",
+ "Zainal",
+ "Zainal Abidin",
+ "Zakariya",
+ "Zaki",
+ "Zane",
+ "Zayn ad-Din",
+ "Zeeshan",
+ "Ziad",
+ "Ziauddin",
+ "Ziaur Rahman",
+ "Zubayr",
+ "Feminine",
+ "Contents: ",
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ "Abeer",
+ "Abiha",
+ "Adela",
+ "Afaf",
+ "Afreen",
+ "Aisha",
+ "Aliya",
+ "Alya",
+ "Amalia",
+ "Amina",
+ "Amira",
+ "Arwa",
+ "Ashraqat",
+ "Ashfa",
+ "Asma",
+ "Atikah",
+ "Aya",
+ "Azhar",
+ "Azra",
+ "Aziza",
+ "Boutheina",
+ "Bushra",
+ "Besma",
+ "Chaima",
+ "Dalal",
+ "Dalia",
+ "Danielle",
+ "Dana",
+ "Dareen",
+ "Dina",
+ "Eliana",
+ "Esma",
+ "Eva",
+ "Farah",
+ "Farida",
+ "Fatima",
+ "Feyrouz",
+ "Fouz",
+ "Habiba",
+ "Hafsa",
+ "Hajra",
+ "Hala",
+ "Halima",
+ "Hamida",
+ "Hana",
+ "Hanifa",
+ "Havva",
+ "Hawa",
+ "Hayat",
+ "Hessa",
+ "Huda",
+ "Ibtisam",
+ "Inaam",
+ "Ireen",
+ "Jamila",
+ "Jana",
+ "Jawahir",
+ "Jena",
+ "Jennifer",
+ "Jessica",
+ "Joelle",
+ "Joud",
+ "Jouri",
+ "Julia",
+ "Jumana",
+ "Kareena",
+ "Karima",
+ "Katya",
+ "Khadija",
+ "Khairunnisa",
+ "Khawlah",
+ "Lama",
+ "Lamia",
+ "Lana",
+ "Lara",
+ "Latifa",
+ "Layan",
+ "Leila",
+ "Lina",
+ "Lulwa",
+ "Madiha",
+ "Maha",
+ "Mahmuna",
+ "Mai",
+ "Malika",
+ "Maria",
+ "Marwa",
+ "Maryam",
+ "Maya",
+ "Maysoon",
+ "Melek",
+ "Melissa",
+ "Mila",
+ "Mira",
+ "Mirna",
+ "Mona",
+ "Munira",
+ "Nadia",
+ "Nadine",
+ "Nafisa",
+ "Nahla",
+ "Naila",
+ "Naima",
+ "Najat",
+ "Najma",
+ "Nalini",
+ "Nasim",
+ "Nasrin",
+ "Natasha",
+ "Nathalie",
+ "Nawal",
+ "Nayla",
+ "Naziha",
+ "Nazira",
+ "Nehal",
+ "Nejla",
+ "Nermin",
+ "Nezha",
+ "Nina",
+ "Qamar ud-Din",
+ "Qistina",
+ "Rabia",
+ "Rahima",
+ "Rana",
+ "Rania",
+ "Rashida",
+ "Reem",
+ "Riffat",
+ "Rimas",
+ "Rita",
+ "Ruqayya",
+ "Saadia",
+ "Sabah",
+ "Sabiha",
+ "Subiksha",
+ "Safaa",
+ "Safiya",
+ "Sahar",
+ "Saida",
+ "Saira",
+ "Sajida",
+ "Sakhra",
+ "Sakina",
+ "Salma",
+ "Samar",
+ "Samira",
+ "Samiya",
+ "Sandra",
+ "Sania",
+ "Sarah",
+ "Selma",
+ "Shahd",
+ "Shakira",
+ "Shams",
+ "Shatha",
+ "Sherine",
+ "Shumaila",
+ "Suha",
+ "Sumaya",
+ "Sonia",
+ "Soraida",
+ "Tahira",
+ "Tala",
+ "Tamara",
+ "Tanisha",
+ "Tanya",
+ "Tara",
+ "Taslima",
+ "Tina",
+ "Tuba",
+ "Umm Kulthum",
+ "Wafaa",
+ "Waliya",
+ "Wajahat",
+ "Wajhat",
+ "Yamina",
+ "Yara",
+ "Yasmin",
+ "Zahra",
+ "Zalayha",
+ "Zakiya",
+ "Zaynab",
+ "Zuhal",
+ "Zoraida"
+};
+}
diff --git a/lib/src/main/java/com/tuti/util/utils.java b/lib/src/main/java/com/tuti/util/utils.java
new file mode 100644
index 0000000..09b5a43
--- /dev/null
+++ b/lib/src/main/java/com/tuti/util/utils.java
@@ -0,0 +1,44 @@
+package com.tuti.util;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Random;
+import java.util.UUID;
+
+public class Utils {
+
+ public static String getDate(){
+ DateFormat dateFormat = new SimpleDateFormat("ddMMyyHHmmss", Locale.US);
+ Date date = new Date();
+ return dateFormat.format(date);
+ }
+
+ public static String getUuid() {
+ return UUID.randomUUID().toString();
+ }
+
+
+ static final String ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ static Random rnd = new Random();
+
+ public static String generateRandomStringFromAlphabet(String alphabet,int length){
+ StringBuilder sb = new StringBuilder(length);
+ for(int i = 0; i < length; i++)
+ sb.append(alphabet.charAt(rnd.nextInt(alphabet.length())));
+ return sb.toString();
+ }
+
+ public static String generateRandomAlphanumericString(int length){
+ return generateRandomStringFromAlphabet(ABC,length);
+ }
+
+ public static String generateRandomNumericString(int length){
+ return generateRandomStringFromAlphabet("0123456789",length);
+ }
+
+ public static String generateARandomName(){
+ return NamesForUnitTests.names[rnd.nextInt(NamesForUnitTests.names.length)];
+ }
+}
diff --git a/lib/src/test/java/com/tuti/ApiTest.java b/lib/src/test/java/com/tuti/ApiTest.java
index d3b6f40..3f08b1c 100644
--- a/lib/src/test/java/com/tuti/ApiTest.java
+++ b/lib/src/test/java/com/tuti/ApiTest.java
@@ -6,74 +6,142 @@
import com.tuti.api.TutiApiClient;
import com.tuti.api.authentication.*;
+import com.tuti.api.data.Card;
+import com.tuti.api.data.Cards;
+import com.tuti.model.IPIN;
+import com.tuti.util.Utils;
+import okhttp3.internal.Util;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import java.util.Random;
+import java.util.UUID;
+import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+@RunWith(JUnit4.class)
public class ApiTest {
static TutiApiClient client;
- @BeforeAll
- static void setup(){
+ @BeforeClass public static void setup(){
client = new TutiApiClient(true);
client.setSingleThreaded(true);
}
- @Test
- void testSignInApi(){
- SignInInfo credentials = new SignInInfo("adonese","12345678");
- client.SignIn(credentials,(SignInResponse response) -> {
- client.setAuthToken(response.getAuthorizationJWT());
- User user = response.getUser();
+ @Before public void signIn(){
+ SignInRequest credentials = new SignInRequest("0999999999","Testtest1234.");
+
+ client.SignIn(credentials,( signInResponse , rawResponse) -> {
+ client.setAuthToken(signInResponse.getAuthorizationJWT());
+ },(objectReceived, exception, rawResponse) -> {fail("sign in failed for @BeforeClass");});
+ }
+ @Test public void testSignInApi(){
+ SignInRequest credentials = new SignInRequest("adonese","12345678");
+ client.setAuthToken(null);
+
+ client.SignIn(credentials,( signInResponse , rawResponse) -> {
+ User user = signInResponse.getUser();
+
+ System.out.println("User information from sign in endpoint (adonese case):\n"+user);
assertEquals("adonese",user.getUsername());
assertEquals("Mohamed Yousif",user.getFullname());
assertEquals("mmbusif@gmail.com",user.getEmail());
assertEquals("0925343834",user.getMobileNumber());
assertEquals(true,user.getIsMerchant());
assertEquals(0,user.getId());
- },(String error,Exception e,int responseCode) -> {fail("sign in failed");});
-
-
- //
-
+ },( error, exception, rawResponse) -> {fail("sign in failed");});
+
+ credentials = new SignInRequest("non_existent_user" + Utils.generateRandomAlphanumericString(8),"asjfkdlj");
+ client.SignIn(credentials,( signInResponse , rawResponse) -> {
+ fail("sign in failed because the user is non existent");
+ },( error, exception, rawResponse) -> {
+ if (error != null) System.out.println("\nNon existent user case:\n"+error);
+ if (exception != null ) fail("exception in sign in");
+ });
}
- @Test void testSignUpApi(){
- SignUpInfo info = new SignUpInfo();
-
- info.setMobileNumber("0129751986");
- info.setPassword("Ramiimar1234.");
- info.setUsername("rami3sam");
- info.setFullname("Rami Essamedeen");
- info.setEmail("rami3sam@gmail.com");
- info.setMerchant(true);
-
- client.Signup(info,(SignUpResponse response) -> {
- User user = response.getUser();
- assertEquals("rami3sam",user.getUsername());
- assertEquals("Rami Essamedeen",user.getFullname());
- assertEquals("rami3sam@gmail.com",user.getEmail());
- assertEquals("0129751986",user.getMobileNumber());
- assertEquals(true,user.getIsMerchant());
- },(String error,Exception e, int responseCode ) -> {fail("sign up failed");} );
+ @Test public void testSignUpApi(){
+ SignUpRequest info = new SignUpRequest();
+
+ String tag = Utils.generateRandomNumericString(8);
+
+ String mobileNumber = "02" + Utils.generateRandomNumericString(8);
+ String username = "test_" + tag;
+ String email = "test_" + tag +"@test.com";
+ String fullname = Utils.generateARandomName() + " " + Utils.generateARandomName();
+ String password = Utils.generateRandomAlphanumericString(12)+"A1.";
+ boolean isMerchant = new Random().nextBoolean();
+ info.setMobileNumber(mobileNumber);
+ info.setPassword(password);
+ info.setUsername(username);
+ info.setFullname(fullname);
+ info.setEmail(email);
+ info.setMerchant(isMerchant);
+ client.Signup(info,( signUpResponse, rawResponse) -> {
+
+ User user = signUpResponse.getUser();
+ System.out.println("User information from signup endpoint:\n"+user);
+
+ assertEquals(username,user.getUsername());
+ assertEquals(fullname,user.getFullname());
+ assertEquals(email,user.getEmail());
+ assertEquals(mobileNumber,user.getMobileNumber());
+ assertEquals(isMerchant,user.getIsMerchant());
+
+ },( error, exception, rawResponse ) -> {
+ fail("sign up failed");} );
+
+ SignInRequest creds = new SignInRequest(username,password);
+ client.SignIn(creds , (objectReceived, rawResponse) -> {
+ User user = objectReceived.getUser();
+ System.out.println("User information from sign in endpoint:\n"+user);
+
+ assertEquals(username,user.getUsername());
+ assertEquals(fullname,user.getFullname());
+ assertEquals(email,user.getEmail());
+ assertEquals(mobileNumber,user.getMobileNumber());
+ assertEquals(isMerchant,user.getIsMerchant());
+
+ } ,
+ (errorReceived, exception, rawResponse) -> {fail("sign in failed!");} );
}
+ @Test public void testAddCardAndGetCard(){
+ String name = Utils.generateRandomAlphanumericString(16);
+ String PAN = Utils.generateRandomNumericString(16);
+ String expiryDate = Utils.generateRandomNumericString(4);
- @Test void testGetCards(){
- SignInInfo credentials = new SignInInfo("adonese","12345678");
+ Card cardToAdd = new Card();
+ cardToAdd.setName(name);
+ cardToAdd.setExpiryDate(expiryDate);
+ cardToAdd.setPAN(PAN);
- client.SignIn(credentials,(SignInResponse response) -> {
- client.setAuthToken(response.getAuthorizationJWT());
- },(param, exception, responseCode) -> {fail("Sign in failed");});
+ client.addCard(cardToAdd,(objectReceived, rawResponse) -> {},
+ (errorReceived, exception, rawResponse) -> {fail("adding a card failed");});
- client.getCards(cards -> {
- assertEquals("adonese",cards.getCards().get(0).getName());
- assertEquals("22222222222222222",cards.getCards().get(0).getPAN());
+ client.getCards((cards,response) -> {
+ outputCardsInfo(cards);
- } , (param, exception, responseCode) -> {fail();});
+ assertThat(cards.getCards()).extracting("name").contains(name);
+ assertThat(cards.getCards()).extracting("PAN").contains(PAN);
+ assertThat(cards.getCards()).extracting("expiryDate").contains(expiryDate);
+ } , (objectReceived, exception, rawResponse) -> {fail();});
+ }
+
+ public void outputCardsInfo(Cards cards){
+ System.out.println("Cards associated with the account");
+ for (Card card : cards.getCards()){
+ System.out.println(card);
+ }
+ }
+ @Test public void testIPINBlockGenerator(){
+ //System.out.println(new IPIN().getIPINBlock("0000","MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ4HwthfqXiK09AgShnnLqAqMyT5VUV0hvSdG+ySMx+a54Ui5EStkmO8iOdVG9DlWv55eLBoodjSfd0XRxN7an0CAwEAAQ==", UUID.randomUUID().toString()));
}
}