Skip to content

Commit

Permalink
Merge pull request #13 from processout/test-suite
Browse files Browse the repository at this point in the history
tests: add UI test suite
  • Loading branch information
jlejoux authored Oct 31, 2019
2 parents d246496 + e850963 commit 84bec91
Show file tree
Hide file tree
Showing 9 changed files with 715 additions and 205 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation project(':processout-sdk')
implementation 'com.google.code.gson:gson:2.8.2'
}

This file was deleted.

14 changes: 10 additions & 4 deletions processout-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

Expand All @@ -20,15 +20,21 @@ android {
}
}

packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'


implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.code.gson:gson:2.8.2'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.processout.processout_sdk;

import android.app.Activity;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.util.Log;

import com.android.volley.Request;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -15,160 +10,17 @@

import java.util.concurrent.CountDownLatch;

import androidx.test.core.app.ApplicationProvider;

import static org.junit.Assert.fail;


public class ProcessOutTest {

private String projectId = "test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x";
private String privateKey = "key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB";
final private ProcessOut p = new ProcessOut(InstrumentationRegistry.getContext(), projectId);
final private ProcessOut p = new ProcessOut(ApplicationProvider.getApplicationContext(), projectId);
private Gson gson = new GsonBuilder().disableHtmlEscaping().create();
final Context withActivity = InstrumentationRegistry.getContext();

@Test
public void threeDS2Fingerprint() {
final CountDownLatch signal = new CountDownLatch(1);


Card c = new Card("4000000000003063", 10, 20, "737");
p.tokenize(c,null, new TokenCallback() {
@Override
public void onError(Exception error) {
fail("Could not tokenize the card");
}

@Override
public void onSuccess(final String token) {
Invoice invoice = new Invoice("test", "121.01", "EUR", new Device("android"));
try {
JSONObject body = new JSONObject(gson.toJson(invoice));
Network.getTestInstance(InstrumentationRegistry.getContext(), projectId, privateKey).CallProcessOut("/invoices", Request.Method.POST, body, new Network.NetworkResult() {
@Override
public void onError(Exception error) {
Log.e("PROCESSOUT", error.toString());
fail("Invoice creation failed");
}

@Override
public void onSuccess(JSONObject json) {
try {
Invoice invoiceResult = gson.fromJson(json.getJSONObject("invoice").toString(), Invoice.class);
p.makeCardPayment(invoiceResult.getId(), token, new ThreeDSHandler() {
@Override
public void doFingerprint(DirectoryServerData directoryServerData, DoFingerprintCallback callback) {
callback.continueCallback(
new ThreeDSFingerprintResponse(
"", "", new SDKEPhemPubKey("", "", "", ""),
"", ""));
}

@Override
public void doChallenge(AuthenticationChallengeData authData, final DoChallengeCallback callback) {
callback.success();
}

@Override
public void onSuccess(String invoiceId) {
signal.countDown();
}

@Override
public void onError(Exception error) {
fail("ThreeDS2 failed");
}
}, withActivity);
} catch (JSONException e) {
fail("Unhandled exception");
e.printStackTrace();
}
}
});
} catch (JSONException e) {
fail("Unhandled exception");
e.printStackTrace();
}
}
});

try {
signal.await();// wait for callback
} catch (InterruptedException e) {
e.printStackTrace();
fail("Could not run test");
}
}

@Test
public void threeDS2Challenge() {
final CountDownLatch signal = new CountDownLatch(1);

Card c = new Card("4000000000000101", 10, 20, "737");
p.tokenize(c,null, new TokenCallback() {
@Override
public void onError(Exception error) {
fail("Could not tokenize the card");
}

@Override
public void onSuccess(final String token) {
// Creation of the invoice
Invoice invoice = new Invoice("test", "121.01", "EUR", new Device("android"));
try {
JSONObject body = new JSONObject(gson.toJson(invoice));
Network.getTestInstance(InstrumentationRegistry.getContext(), projectId, privateKey).CallProcessOut("/invoices", Request.Method.POST, body, new Network.NetworkResult() {
@Override
public void onError(Exception error) {
fail("Invoice creation failed");
}

@Override
public void onSuccess(JSONObject json) {
try {
Invoice invoiceResult = gson.fromJson(json.getJSONObject("invoice").toString(), Invoice.class);
p.makeCardPayment(invoiceResult.getId(), token, new ThreeDSHandler() {
@Override
public void doFingerprint(DirectoryServerData directoryServerData, DoFingerprintCallback callback) {
callback.continueCallback(
new ThreeDSFingerprintResponse(
"", "", new SDKEPhemPubKey("", "", "", ""),
"", ""));
}

@Override
public void doChallenge(AuthenticationChallengeData authData, final DoChallengeCallback callback) {
callback.success();
}

@Override
public void onSuccess(String invoiceId) {
signal.countDown();
}

@Override
public void onError(Exception error) {
fail("ThreeDS2 failed" + error.toString());
}
}, withActivity);
} catch (JSONException e) {
fail("Unhandled exception");
e.printStackTrace();
}
}
});
} catch (JSONException e) {
fail("Unhandled exception");
e.printStackTrace();
}
}
});

try {
signal.await();// wait for callback
} catch (InterruptedException e) {
e.printStackTrace();
fail("Could not run test");
}
}

@Test
public void tokenize() {
Expand Down Expand Up @@ -203,7 +55,7 @@ public void listAlternativePaymentGateways() {
Invoice invoice = new Invoice("test", "123.0", "EUR", new Device("android"));
try {
JSONObject body = new JSONObject(gson.toJson(invoice));
Network.getTestInstance(InstrumentationRegistry.getContext(), projectId, privateKey).CallProcessOut("/invoices", Request.Method.POST, body, new Network.NetworkResult() {
Network.getTestInstance(ApplicationProvider.getApplicationContext(), projectId, privateKey).CallProcessOut("/invoices", Request.Method.POST, body, new Network.NetworkResult() {
@Override
public void onError(Exception error) {
fail(error.toString());
Expand Down
Loading

0 comments on commit 84bec91

Please sign in to comment.