diff --git a/build.gradle b/build.gradle index 68d2fd5..1136efb 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,8 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.6.3' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } @@ -18,4 +20,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/rxp-hpp-android/build.gradle b/rxp-hpp-android/build.gradle index 7ab9b1c..b541335 100644 --- a/rxp-hpp-android/build.gradle +++ b/rxp-hpp-android/build.gradle @@ -1,4 +1,37 @@ apply plugin: 'com.android.library' +apply plugin: 'com.jfrog.bintray' +apply plugin: 'com.github.dcendents.android-maven' + +ext { + bintrayRepo = 'maven' + bintrayName = 'rxp-hpp-android' + bintrayUser = System.getenv('BINTRAY_USER') + bintrayKey = System.getenv('BINTRAY_KEY') + bintrayGPGPassphrase = System.getenv('BINTRAY_GPG_PASSPHRASE') + + publishedGroupId = 'com.realexpayments.hpp.sdk' + libraryName = 'rxp-hpp-android' + artifact = 'rxp-hpp-android' + + libraryDescription = 'The official Realex Payments Android SDK for HPP and Remote API.' + + siteUrl = 'https://developer.realexpayments.com' + gitUrl = 'https://github.com/realexpayments/rxp-android.git' + + libraryVersion = '2.0' + + developerId = 'realexpayments' + developerName = 'Realex Payments' + developerEmail = 'developers@realexpayments.com' + + licenseName = 'The MIT License (MIT)' + licenseUrl = 'https://opensource.org/licenses/MIT' + allLicenses = ["MIT"] +} + +// Maven Group ID for the artifact +group = publishedGroupId +version = libraryVersion android { compileSdkVersion 29 @@ -8,7 +41,7 @@ android { minSdkVersion 19 targetSdkVersion 29 versionCode 3 - versionName "2.0" + versionName libraryVersion } buildTypes { release { @@ -24,4 +57,107 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'com.squareup.retrofit:retrofit:1.7.1' implementation 'org.apache.httpcomponents:httpcore:4.4.10' + testImplementation 'junit:junit:4.12' +} + +task printBintrayEnv() { + println "bintrayUser: " + bintrayUser + println "bintrayKey: " + bintrayKey + println "bintrayGPGPassphrase: " + bintrayGPGPassphrase +} + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + archiveClassifier.convention('sources') + archiveClassifier.set('sources') +} + +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + options.encoding = 'UTF-8' + options.addStringOption('Xdoclint:none', '-quiet') +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + archiveClassifier.convention('javadoc') + archiveClassifier.set('javadoc') + from javadoc.destinationDir } + +artifacts { + archives javadocJar + archives sourcesJar +} + +install { + repositories.mavenInstaller { + // This generates POM.xml with proper parameters + pom { + project { + packaging 'aar' + groupId publishedGroupId + artifactId artifact + + // description + name libraryName + description libraryDescription + url siteUrl + + // Set your license + licenses { + license { + name licenseName + url licenseUrl + } + } + + developers { + developer { + id developerId + name developerName + email developerEmail + } + } + scm { + connection gitUrl + developerConnection gitUrl + url siteUrl + + } + } + } + } +} + +// Bintray +bintray { + user = bintrayUser + key = bintrayKey + + configurations = ['archives'] + pkg { + repo = bintrayRepo + name = bintrayName + desc = libraryDescription + publish = true + publicDownloadNumbers = true + + licenses = allLicenses + vcsUrl = gitUrl + websiteUrl = siteUrl + + version { + name = libraryVersion + desc = libraryDescription + released = new Date() + vcsTag = libraryVersion + desc = libraryDescription + // Optional. The passphrase for GPG signing' + gpg { + sign = true //Determines whether to GPG sign the files. The default is false + passphrase = bintrayGPGPassphrase + } + } + } +} \ No newline at end of file diff --git a/rxp-hpp-android/src/androidTest/java/com/realexpayments/hpp/ApplicationTest.java b/rxp-hpp-android/src/androidTest/java/com/realexpayments/hpp/ApplicationTest.java deleted file mode 100644 index b7f99af..0000000 --- a/rxp-hpp-android/src/androidTest/java/com/realexpayments/hpp/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.realexpayments.hpp; - -import android.app.Application; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends Application{ - - public ApplicationTest() { - super(); - } -} \ No newline at end of file diff --git a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java index 1a97254..ec1b0bb 100644 --- a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java +++ b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java @@ -19,14 +19,14 @@ class ApiAdapter { public static final String RETROFIT_TAG = "HPPRetrofit"; public static IHPPServerAPI getAdapter(String endpoint, Map headers) { - RestAdapter restAdapter = new RestAdapter.Builder() + return new RestAdapter.Builder() .setEndpoint(endpoint) .setLogLevel(RestAdapter.LogLevel.FULL) .setLog(new AndroidLog(RETROFIT_TAG)) .setConverter(new GsonConverter(getGson())) .setRequestInterceptor(getRequestInterceptor(headers)) - .build(); - return restAdapter.create(IHPPServerAPI.class); + .build() + .create(IHPPServerAPI.class); } public static Gson getGson() { diff --git a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java index 7bae4d3..7a13354 100644 --- a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java +++ b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java @@ -1,15 +1,12 @@ package com.realexpayments.hpp; import android.annotation.SuppressLint; -import android.annotation.TargetApi; -import android.app.Activity; +import android.content.Context; import android.net.Uri; import android.net.http.SslError; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; -import android.util.Base64; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -25,6 +22,7 @@ import android.webkit.WebView; import android.webkit.WebViewClient; +import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import com.google.gson.Gson; @@ -43,10 +41,13 @@ import static com.realexpayments.hpp.Constants.HTML_MIME_TYPE; import static com.realexpayments.hpp.Constants.HTTP_SCHEME_ENDING; import static com.realexpayments.hpp.Constants.JS_WEBVIEW_OBJECT_NAME; -import static com.realexpayments.hpp.Constants.SLASH; import static com.realexpayments.hpp.Constants.UTF_8; import static com.realexpayments.hpp.HPPResponse.HPP_POST_RESPONSE; import static com.realexpayments.hpp.HPPResponse.HPP_VERSION; +import static com.realexpayments.hpp.Utils.collectValidMapValues; +import static com.realexpayments.hpp.Utils.decode; +import static com.realexpayments.hpp.Utils.getHostPath; +import static com.realexpayments.hpp.Utils.getRelativePathEncoded; /** * Payment form fragment. @@ -56,116 +57,75 @@ * getFragmentManager()
.beginTransaction().add(R.id.container,hppManagerFrament)
.commit(); **/ -public class HPPManagerFragment extends Fragment implements Callback { - +public class HPPManagerFragment extends Fragment { private HPPManagerListener mListener; - private View root; private HPPManager hppManager; private boolean isResultReceived = false; - public HPPManagerFragment() { - } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments() != null) { - hppManager = HPPManager.createFromBundle(getArguments()); - } + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.hppmanager_fragment, container, false); } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - root = inflater.inflate(R.layout.hppmanager_fragment, container, false); - return root; - } + public void onAttach(@NonNull Context context) { + super.onAttach(context); - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); try { - mListener = (HPPManagerListener) activity; - - if (getArguments() != null) { - hppManager = HPPManager.createFromBundle(getArguments()); - - HashMap parameters = hppManager.getMap(); - - ApiAdapter.getAdapter(getHostPath(hppManager.getHppRequestProducerURL()), getRequestHeaders()) - .getHPPRequest( - getRelativePathEncoded(hppManager.getHppRequestProducerURL()), - parameters, - this - ); - - } else { + mListener = (HPPManagerListener) context; + Bundle arguments = getArguments(); + if (arguments == null) { mListener.hppManagerFailedWithError(new HPPError("Invalid arguments", null)); + } else { + hppManager = HPPManager.createFromBundle(arguments); + getHPPRequest(); } } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + throw new ClassCastException(requireActivity().toString() + " must implement HPPManagerListener"); } } - private Map getRequestHeaders() { - HashMap headersMap = new HashMap<>(); - HashMap additionalHeaders = hppManager.getAdditionalHeaders(); - - if (additionalHeaders != null && !additionalHeaders.isEmpty()) { - for (String headerName : additionalHeaders.keySet()) { - String headerValue = additionalHeaders.get(headerName); - - if (!TextUtils.isEmpty(headerName) && !TextUtils.isEmpty(headerValue)) { - headersMap.put(headerName, headerValue); - } - } - } + private void getHPPRequest() { + String hppRequestProducerURL = hppManager.getHppRequestProducerURL(); - return headersMap; - } - - private String getHostPath(String urlString) { - return urlString.substring(0, urlString.lastIndexOf(getRelativePath(urlString)) - 1); - } - - private String getRelativePath(String urlString) { - Uri uri = Uri.parse(urlString); - String path = uri.getPath(); - return (path.startsWith(SLASH)) ? path.substring(1) : path; - } + ApiAdapter.getAdapter(getHostPath(hppRequestProducerURL), getRequestHeaders()) + .getHPPRequest( + getRelativePathEncoded(hppRequestProducerURL), + hppManager.getMap(), + new Callback() { + @Override + public void success(Response hppResponse, Response response) { + String resp = new String(((TypedByteArray) response.getBody()).getBytes()); + Type mapType = new TypeToken>() { + }.getType(); + Map consumerResponseParams = new Gson().fromJson(resp, mapType); + postHPPData(buildWebView(), getHPPPostData(consumerResponseParams)); + } - private String getRelativePathEncoded(String urlString) { - Uri uri = Uri.parse(urlString); - String encodedPath = uri.getEncodedPath(); - return (encodedPath.startsWith(SLASH)) ? encodedPath.substring(1) : encodedPath; + @Override + public void failure(RetrofitError error) { + HPPError hppError = new HPPError(error.getMessage(), error, error.getUrl()); + mListener.hppManagerFailedWithError(hppError); + } + } + ); } - @Override - public void onDestroy() { - if (!isResultReceived) { - mListener.hppManagerCancelled(); - isResultReceived = true; - } - mListener = null; - - super.onDestroy(); + private Map getRequestHeaders() { + return collectValidMapValues(hppManager.getAdditionalHeaders()); } - @SuppressLint("SetJavaScriptEnabled") - @TargetApi(Build.VERSION_CODES.KITKAT) - @Override - public void success(Response hppResponse, Response response) { - final WebView webView = root.findViewById(R.id.hpp_web_view); + private WebView buildWebView() { + final WebView webView = requireView().findViewById(R.id.hpp_web_view); webView.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(this, JS_WEBVIEW_OBJECT_NAME); WebView.setWebContentsDebuggingEnabled(true); webView.setOnKeyListener(new View.OnKeyListener() { - @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { @@ -182,7 +142,6 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { }); webView.setWebChromeClient(new WebChromeClient() { - @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { if (consoleMessage.message().startsWith(HPPManager.RESULT_MESSAGE)) { @@ -192,81 +151,76 @@ public boolean onConsoleMessage(ConsoleMessage consoleMessage) { } return super.onConsoleMessage(consoleMessage); - } }); - webView.setWebViewClient(new WebViewClient() { - - Handler handler = new Handler(); - String url; - - @TargetApi(Build.VERSION_CODES.KITKAT) - @Override - public void onLoadResource(final WebView view, String url) { - this.url = url; - if (url.endsWith("api/auth")) { - checkResult(view); - } - - super.onLoadResource(view, url); - } - - private void checkResult(final WebView view) { - handler.postDelayed(new Runnable() { - @Override - public void run() { - view.evaluateJavascript("javascript:console.log('" + HPPManager.RESULT_MESSAGE + "'+document.getElementById('result-message').innerHTML);", new ValueCallback() { - @Override - public void onReceiveValue(String value) { - if (!isResultReceived) { - checkResult(view); - } - } - }); - - } - }, 100); - } - - @SuppressLint("NewApi") - @Override - public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { - super.onReceivedHttpError(view, request, errorResponse); - - if (this.url.equals(hppManager.getHppURL())) { - - isResultReceived = true; - mListener.hppManagerFailedWithError(new HPPError(errorResponse.getReasonPhrase(), hppManager.getHppURL())); - } - - } - - @SuppressLint("NewApi") - @Override - public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { - super.onReceivedError(view, request, error); - - isResultReceived = true; - mListener.hppManagerFailedWithError(new HPPError(error.getDescription().toString(), hppManager.getHppURL())); - - } - - @Override - public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { - super.onReceivedSslError(view, handler, error); - isResultReceived = true; - mListener.hppManagerFailedWithError(new HPPError(error.toString(), hppManager.getHppURL())); - - } - } - ); - - String resp = new String(((TypedByteArray) response.getBody()).getBytes()); - Type mapType = new TypeToken>() { - }.getType(); - Map consumerResponseParams = new Gson().fromJson(resp, mapType); - postHPPData(webView, getHPPPostData(consumerResponseParams)); + webView.setWebViewClient(buildWebViewClient()); + return webView; + } + + private WebViewClient buildWebViewClient() { + return new WebViewClient() { + Handler handler = new Handler(); + String url; + + @Override + public void onLoadResource(final WebView view, String url) { + this.url = url; + if (url.endsWith("api/auth")) { + checkResult(view, handler); + } + + super.onLoadResource(view, url); + } + + @SuppressLint("NewApi") + @Override + public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { + super.onReceivedHttpError(view, request, errorResponse); + if (this.url.equals(hppManager.getHppURL())) { + isResultReceived = true; + HPPError hppError = new HPPError(errorResponse.getReasonPhrase(), hppManager.getHppURL()); + mListener.hppManagerFailedWithError(hppError); + } + } + + @SuppressLint("NewApi") + @Override + public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { + super.onReceivedError(view, request, error); + isResultReceived = true; + HPPError hppError = new HPPError(error.getDescription().toString(), hppManager.getHppURL()); + mListener.hppManagerFailedWithError(hppError); + } + + @Override + public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { + super.onReceivedSslError(view, handler, error); + isResultReceived = true; + HPPError hppError = new HPPError(error.toString(), hppManager.getHppURL()); + mListener.hppManagerFailedWithError(hppError); + } + }; + } + + private void checkResult(final WebView view, final Handler handler) { + handler.postDelayed(new Runnable() { + @Override + public void run() { + String script = "javascript:console.log('" + HPPManager.RESULT_MESSAGE + + "'+document.getElementById('result-message').innerHTML);"; + + view.evaluateJavascript(script, new ValueCallback() { + @Override + public void onReceiveValue(String value) { + if (!isResultReceived) { + checkResult(view, handler); + } + } + }); + + } + }, 100); } private HashMap getHPPPostData(Map params) { @@ -284,14 +238,8 @@ private HashMap getHPPPostData(Map params) { String paramValue = params.get(key); if (!TextUtils.isEmpty(paramValue)) { - if (HPPManager.isEncoded()) { - byte[] decodedValue = Base64.decode(paramValue, Base64.DEFAULT); - String decodedString = new String(decodedValue); - map.put(key, decodedString); - } else { - map.put(key, paramValue); - } - + String finalParamValue = HPPManager.isEncoded() ? decode(paramValue) : paramValue; + map.put(key, finalParamValue); } } @@ -299,18 +247,21 @@ private HashMap getHPPPostData(Map params) { } private void postHPPData(final WebView webView, HashMap postData) { - ApiAdapter.getAdapter(getHostPath(hppManager.getHppURL()), getRequestHeaders()) - .getHPP(getRelativePathEncoded(hppManager.getHppURL()), postData, + final String hppURL = hppManager.getHppURL(); + + ApiAdapter.getAdapter(getHostPath(hppURL), getRequestHeaders()) + .getHPP(getRelativePathEncoded(hppURL), postData, new Callback() { @Override public void success(Response s, Response response) { String htmlString = new String(((TypedByteArray) response.getBody()).getBytes()); - loadWebView(webView, hppManager.getHppURL(), htmlString); + loadWebView(webView, hppURL, htmlString); } @Override public void failure(RetrofitError error) { - mListener.hppManagerFailedWithError(new HPPError(error.getMessage(), error, error.getUrl())); + HPPError hppError = new HPPError(error.getMessage(), error, error.getUrl()); + mListener.hppManagerFailedWithError(hppError); } } ); @@ -330,37 +281,23 @@ public void run() { public void callbackHandler(String data, String url) { if (!isResultReceived && data.length() > 0) { isResultReceived = true; + String hppResponseConsumerURL = hppManager.getHppResponseConsumerURL(); - ApiAdapter.getAdapter(getHostPath(hppManager.getHppResponseConsumerURL()), getRequestHeaders()) + ApiAdapter.getAdapter(getHostPath(hppResponseConsumerURL), getRequestHeaders()) .getConsumerRequest( - getRelativePathEncoded(hppManager.getHppResponseConsumerURL()), + getRelativePathEncoded(hppResponseConsumerURL), data, new Callback() { @Override public void success(Response s, Response response) { - String msg = new String(((TypedByteArray) response.getBody()).getBytes()); - - Method[] methods = mListener.getClass().getDeclaredMethods(); - - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(HPPManagerListener.HPP_MANAGER_COMPLETED_WITH_RESULT)) { - Method method = methods[i]; - - try { - mListener.hppManagerCompletedWithResult(ApiAdapter.getGson().fromJson(msg, method.getParameterTypes()[0])); - } catch (Exception error) { - mListener.hppManagerFailedWithError(new HPPError(msg, error, hppManager.getHppResponseConsumerURL())); - } - break; - } - } - + handleConsumerResponse(msg); } @Override public void failure(RetrofitError error) { - mListener.hppManagerFailedWithError(new HPPError(error.getMessage(), error, error.getUrl())); + HPPError hppError = new HPPError(error.getMessage(), error, error.getUrl()); + mListener.hppManagerFailedWithError(hppError); } } ); @@ -368,9 +305,30 @@ public void failure(RetrofitError error) { } } + private void handleConsumerResponse(String msg) { + Method[] methods = mListener.getClass().getDeclaredMethods(); + + for (Method method : methods) { + if (method.getName().equals(HPPManagerListener.HPP_MANAGER_COMPLETED_WITH_RESULT)) { + try { + mListener.hppManagerCompletedWithResult(ApiAdapter.getGson().fromJson(msg, method.getParameterTypes()[0])); + } catch (Exception error) { + mListener.hppManagerFailedWithError(new HPPError(msg, error, hppManager.getHppResponseConsumerURL())); + } + break; + } + } + } + @Override - public void failure(RetrofitError error) { - mListener.hppManagerFailedWithError(new HPPError(error.getMessage(), error, error.getUrl())); + public void onDestroy() { + if (!isResultReceived) { + mListener.hppManagerCancelled(); + isResultReceived = true; + } + + mListener = null; + super.onDestroy(); } } diff --git a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/Utils.java b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/Utils.java new file mode 100644 index 0000000..c88f808 --- /dev/null +++ b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/Utils.java @@ -0,0 +1,51 @@ +package com.realexpayments.hpp; + +import android.net.Uri; +import android.text.TextUtils; +import android.util.Base64; + +import java.util.HashMap; +import java.util.Map; + +import static com.realexpayments.hpp.Constants.SLASH; + +public class Utils { + + public static String getHostPath(String urlString) { + return urlString.substring(0, urlString.lastIndexOf(getRelativePath(urlString)) - 1); + } + + public static String getRelativePath(String urlString) { + Uri uri = Uri.parse(urlString); + String path = uri.getPath(); + return (path.startsWith(SLASH)) ? path.substring(1) : path; + } + + public static String getRelativePathEncoded(String urlString) { + Uri uri = Uri.parse(urlString); + String encodedPath = uri.getEncodedPath(); + return (encodedPath.startsWith(SLASH)) ? encodedPath.substring(1) : encodedPath; + } + + public static String decode(String encodedValue) { + byte[] decodedValue = Base64.decode(encodedValue, Base64.DEFAULT); + return new String(decodedValue); + } + + public static Map collectValidMapValues(Map inputMap) { + HashMap outputMap = new HashMap<>(); + + if (inputMap != null && !inputMap.isEmpty()) { + for (String key : inputMap.keySet()) { + String value = inputMap.get(key); + + if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) { + outputMap.put(key, value); + } + } + } + + return outputMap; + } + +} diff --git a/rxp-hpp-android/src/test/java/com/realexpayments/hpp/HPPManagerTest.java b/rxp-hpp-android/src/test/java/com/realexpayments/hpp/HPPManagerTest.java new file mode 100644 index 0000000..9d2e5ff --- /dev/null +++ b/rxp-hpp-android/src/test/java/com/realexpayments/hpp/HPPManagerTest.java @@ -0,0 +1,128 @@ +package com.realexpayments.hpp; + +import org.junit.Test; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Objects; + +import static com.realexpayments.hpp.HPPResponse.ACCOUNT; +import static com.realexpayments.hpp.HPPResponse.AMOUNT; +import static com.realexpayments.hpp.HPPResponse.AUTO_SETTLE_FLAG; +import static com.realexpayments.hpp.HPPResponse.BILLING_CO; +import static com.realexpayments.hpp.HPPResponse.BILLING_CODE; +import static com.realexpayments.hpp.HPPResponse.CARD_PAYMENT_BUTTON; +import static com.realexpayments.hpp.HPPResponse.CARD_STORAGE_ENABLE; +import static com.realexpayments.hpp.HPPResponse.COMMENT1; +import static com.realexpayments.hpp.HPPResponse.COMMENT2; +import static com.realexpayments.hpp.HPPResponse.CURRENCY; +import static com.realexpayments.hpp.HPPResponse.CUST_NUM; +import static com.realexpayments.hpp.HPPResponse.DCC_ENABLE; +import static com.realexpayments.hpp.HPPResponse.HPP_LANG; +import static com.realexpayments.hpp.HPPResponse.HPP_ORIGIN; +import static com.realexpayments.hpp.HPPResponse.HPP_POST_RESPONSE; +import static com.realexpayments.hpp.HPPResponse.HPP_TEMPLATE_TYPE; +import static com.realexpayments.hpp.HPPResponse.HPP_VERSION; +import static com.realexpayments.hpp.HPPResponse.MERCHANT_ID; +import static com.realexpayments.hpp.HPPResponse.OFFER_SAVE_CARD; +import static com.realexpayments.hpp.HPPResponse.ORDER_ID; +import static com.realexpayments.hpp.HPPResponse.PAYER_EXIST; +import static com.realexpayments.hpp.HPPResponse.PAYER_REF; +import static com.realexpayments.hpp.HPPResponse.PMT_REF; +import static com.realexpayments.hpp.HPPResponse.PROD_ID; +import static com.realexpayments.hpp.HPPResponse.RETURN_TSS; +import static com.realexpayments.hpp.HPPResponse.SHA1_HASH; +import static com.realexpayments.hpp.HPPResponse.SHIPPING_CO; +import static com.realexpayments.hpp.HPPResponse.SHIPPING_CODE; +import static com.realexpayments.hpp.HPPResponse.TIMESTAMP; +import static com.realexpayments.hpp.HPPResponse.VALIDATE_CARD_ONLY; +import static com.realexpayments.hpp.HPPResponse.VAR_REF; +import static junit.framework.TestCase.assertEquals; + +public class HPPManagerTest { + + @Test + public void testGetDataMap() { + HPPManager hppManager = new HPPManager(); + hppManager.setSupplementaryData("SupplementaryDataKey", "SupplementaryDataValue"); + hppManager.setMerchantId("merchantId"); + hppManager.setAccount("account"); + hppManager.setOrderId("orderId"); + hppManager.setAmount("amount"); + hppManager.setCurrency("currency"); + hppManager.setTimeStamp("timestamp"); + hppManager.setAutoSettleFlag("autoSettleFlag"); + hppManager.setCommentOne("commentOne"); + hppManager.setCommentTwo("commentTwo"); + hppManager.setReturnTss("returnTss"); + hppManager.setShippingCode("shippingCode"); + hppManager.setShippingCountry("shippingCountry"); + hppManager.setBillingCode("billingCode"); + hppManager.setBillingCountry("billingCountry"); + hppManager.setCustomerNumber("customerNumber"); + hppManager.setVariableReference("variableReference"); + hppManager.setProductId("productId"); + hppManager.setLanguage("language"); + hppManager.setCardPaymentButtonText("cardPaymentButtonText"); + hppManager.setCardStorageEnable("cardStorageEnable"); + hppManager.setOfferSaveCard("offerSaveCard"); + hppManager.setPayerReference("payerReference"); + hppManager.setPaymentReference("paymentReference"); + hppManager.setPayerExists("payerExists"); + hppManager.setValidateCardOnly("validateCardOnly"); + hppManager.setDccEnable("dccEnable"); + hppManager.setHash("sha1Hash"); + hppManager.setTemplateType("templateType"); + hppManager.setOrigin("origin"); + setValue(HPPManager.class, "hppVersion", hppManager, "hppVersion"); + setValue(HPPManager.class, "hppPostResponse", hppManager, "hppPostResponse"); + + HashMap actualResult = hppManager.getMap(); + + HashMap expectedResult = new HashMap<>(); + expectedResult.put(MERCHANT_ID, "merchantId"); + expectedResult.put(ACCOUNT, "account"); + expectedResult.put(ORDER_ID, "orderId"); + expectedResult.put(AMOUNT, "amount"); + expectedResult.put(CURRENCY, "currency"); + expectedResult.put(TIMESTAMP, "timestamp"); + expectedResult.put(AUTO_SETTLE_FLAG, "autoSettleFlag"); + expectedResult.put(COMMENT1, "commentOne"); + expectedResult.put(COMMENT2, "commentTwo"); + expectedResult.put(RETURN_TSS, "returnTss"); + expectedResult.put(SHIPPING_CODE, "shippingCode"); + expectedResult.put(SHIPPING_CO, "shippingCountry"); + expectedResult.put(BILLING_CODE, "billingCode"); + expectedResult.put(BILLING_CO, "billingCountry"); + expectedResult.put(CUST_NUM, "customerNumber"); + expectedResult.put(VAR_REF, "variableReference"); + expectedResult.put(PROD_ID, "productId"); + expectedResult.put(HPP_LANG, "language"); + expectedResult.put(CARD_PAYMENT_BUTTON, "cardPaymentButtonText"); + expectedResult.put(CARD_STORAGE_ENABLE, "cardStorageEnable"); + expectedResult.put(OFFER_SAVE_CARD, "offerSaveCard"); + expectedResult.put(PAYER_REF, "payerReference"); + expectedResult.put(PMT_REF, "paymentReference"); + expectedResult.put(PAYER_EXIST, "payerExists"); + expectedResult.put(VALIDATE_CARD_ONLY, "validateCardOnly"); + expectedResult.put(DCC_ENABLE, "dccEnable"); + expectedResult.put(SHA1_HASH, "sha1Hash"); + expectedResult.put(HPP_TEMPLATE_TYPE, "templateType"); + expectedResult.put(HPP_ORIGIN, "origin"); + expectedResult.put(HPP_VERSION, "hppVersion"); + expectedResult.put(HPP_POST_RESPONSE, "hppPostResponse"); + expectedResult.put("SupplementaryDataKey", "SupplementaryDataValue"); + + assertEquals(expectedResult, actualResult); + } + + private void setValue(Class clazz, String fieldName, Object obj, Object value) { + try { + Field field = Objects.requireNonNull(clazz.getSuperclass()).getDeclaredField(fieldName); + field.setAccessible(true); + field.set(obj, value); + } catch (NoSuchFieldException | IllegalAccessException var3) { + //ignore + } + } +} diff --git a/rxp-remote-android/build.gradle b/rxp-remote-android/build.gradle index 8eadb8a..15d5bfc 100644 --- a/rxp-remote-android/build.gradle +++ b/rxp-remote-android/build.gradle @@ -1,14 +1,47 @@ apply plugin: 'com.android.library' +apply plugin: 'com.jfrog.bintray' +apply plugin: 'com.github.dcendents.android-maven' + +ext { + bintrayRepo = 'maven' + bintrayName = 'rxp-remote-android' + bintrayUser = System.getenv('BINTRAY_USER') + bintrayKey = System.getenv('BINTRAY_KEY') + bintrayGPGPassphrase = System.getenv('BINTRAY_GPG_PASSPHRASE') + + publishedGroupId = 'com.realexpayments.remote.sdk' + libraryName = 'rxp-remote-android' + artifact = 'rxp-remote-android' + + libraryDescription = 'The official Realex Payments Android SDK for HPP and Remote API.' + + siteUrl = 'https://developer.realexpayments.com' + gitUrl = 'https://github.com/realexpayments/rxp-android.git' + + libraryVersion = '2.0' + + developerId = 'realexpayments' + developerName = 'Realex Payments' + developerEmail = 'developers@realexpayments.com' + + licenseName = 'The MIT License (MIT)' + licenseUrl = 'https://opensource.org/licenses/MIT' + allLicenses = ["MIT"] +} + +// Maven Group ID for the artifact +group = publishedGroupId +version = libraryVersion android { compileSdkVersion 29 - buildToolsVersion "29.0.0" + buildToolsVersion "29.0.2" defaultConfig { minSdkVersion 19 targetSdkVersion 29 - versionCode 2 - versionName "2.0" + versionCode 3 + versionName libraryVersion } buildTypes { release { @@ -20,8 +53,109 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - testImplementation 'junit:junit:4.12' implementation 'androidx.appcompat:appcompat:1.1.0' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'com.android.support.test:rules:1.0.2' + testImplementation 'junit:junit:4.12' +} + +task printBintrayEnv() { + println "bintrayUser: " + bintrayUser + println "bintrayKey: " + bintrayKey + println "bintrayGPGPassphrase: " + bintrayGPGPassphrase +} + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + archiveClassifier.convention('sources') + archiveClassifier.set('sources') +} + +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + options.encoding = 'UTF-8' + options.addStringOption('Xdoclint:none', '-quiet') +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + archiveClassifier.convention('javadoc') + archiveClassifier.set('javadoc') + from javadoc.destinationDir +} + +artifacts { + archives javadocJar + archives sourcesJar +} + +install { + repositories.mavenInstaller { + // This generates POM.xml with proper parameters + pom { + project { + packaging 'aar' + groupId publishedGroupId + artifactId artifact + + // description + name libraryName + description libraryDescription + url siteUrl + + + // Set your license + licenses { + license { + name licenseName + url licenseUrl + } + } + + developers { + developer { + id developerId + name developerName + email developerEmail + } + } + scm { + connection gitUrl + developerConnection gitUrl + url siteUrl + + } + } + } + } } + +// Bintray +bintray { + user = bintrayUser + key = bintrayKey + + configurations = ['archives'] + pkg { + repo = bintrayRepo + name = bintrayName + desc = libraryDescription + publish = true + publicDownloadNumbers = true + + licenses = allLicenses + vcsUrl = gitUrl + websiteUrl = siteUrl + + version { + name = libraryVersion + desc = libraryDescription + released = new Date() + vcsTag = libraryVersion + desc = libraryDescription + // Optional. The passphrase for GPG signing' + gpg { + sign = true //Determines whether to GPG sign the files. The default is false + passphrase = bintrayGPGPassphrase + } + } + } +} \ No newline at end of file diff --git a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateAmexCvnTest.java b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateAmexCvnTest.java similarity index 82% rename from rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateAmexCvnTest.java rename to rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateAmexCvnTest.java index 1912426..3f80f04 100644 --- a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateAmexCvnTest.java +++ b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateAmexCvnTest.java @@ -1,45 +1,44 @@ -package com.realexpayments.remote; - - -import androidx.test.filters.SmallTest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class ValidateAmexCvnTest { - - @SmallTest - public void testValidAmexCVN() { - assertTrue(RealexRemote.validateAmexCvn("1234")); - } - - @SmallTest - public void testEmptyCVN() { - assertFalse(RealexRemote.validateAmexCvn("")); - } - - @SmallTest - public void testUndefinedCVN() { - assertFalse(RealexRemote.validateAmexCvn(null)); - } - - @SmallTest - public void testWhiteSpaceOnly() { - assertFalse(RealexRemote.validateAmexCvn(" ")); - } - - @SmallTest - public void testAmexCVNof5Numbers() { - assertFalse(RealexRemote.validateAmexCvn("12345")); - } - - @SmallTest - public void testAmexCVNof3Numbers() { - assertFalse(RealexRemote.validateAmexCvn("123")); - } - - @SmallTest - public void testNonNumericAmexCVNof4Characters() { - assertFalse(RealexRemote.validateAmexCvn("123a")); - } +package com.realexpayments.remote; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ValidateAmexCvnTest { + + @Test + public void testValidAmexCVN() { + assertTrue(RealexRemote.validateAmexCvn("1234")); + } + + @Test + public void testEmptyCVN() { + assertFalse(RealexRemote.validateAmexCvn("")); + } + + @Test + public void testUndefinedCVN() { + assertFalse(RealexRemote.validateAmexCvn(null)); + } + + @Test + public void testWhiteSpaceOnly() { + assertFalse(RealexRemote.validateAmexCvn(" ")); + } + + @Test + public void testAmexCVNof5Numbers() { + assertFalse(RealexRemote.validateAmexCvn("12345")); + } + + @Test + public void testAmexCVNof3Numbers() { + assertFalse(RealexRemote.validateAmexCvn("123")); + } + + @Test + public void testNonNumericAmexCVNof4Characters() { + assertFalse(RealexRemote.validateAmexCvn("123a")); + } } \ No newline at end of file diff --git a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCardHolderNameTest.java b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCardHolderNameTest.java similarity index 82% rename from rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCardHolderNameTest.java rename to rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCardHolderNameTest.java index 86c9e35..f5233d0 100644 --- a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCardHolderNameTest.java +++ b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCardHolderNameTest.java @@ -1,73 +1,70 @@ -package com.realexpayments.remote; - -import android.app.Application; - -import androidx.test.filters.SmallTest; -import androidx.test.InstrumentationRegistry; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertFalse; - -/* -* Unit tests for validateCardHolderName -* card holder name validation (validateCardHolderName) -*/ - -public class ValidateCardHolderNameTest { - - @SmallTest - public void testValidName() { - assertTrue(RealexRemote.validateCardHolderName("Joe Smith")); - } - - @SmallTest - public void testEmptyName() { - assertFalse(RealexRemote.validateCardHolderName("")); - } - - @SmallTest - public void testUndefinedName() { - assertFalse(RealexRemote.validateCardHolderName(null)); - } - - @SmallTest - public void testWhiteSpaceOnly() { - assertFalse(RealexRemote.validateCardHolderName(" ")); - } - - @SmallTest - public void testNameOf100Characters() { - assertTrue(RealexRemote.validateCardHolderName("abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij")); - } - - @SmallTest - public void testNameOver100Characters() { - assertFalse(RealexRemote.validateCardHolderName("abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghija")); - } - - @SmallTest - public void testISO_IEC8859_1Characters1() { - assertTrue(RealexRemote.validateCardHolderName("!\" # $ % & \' ( ) * + - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R")); - } - - @SmallTest - public void testISO_IEC8859_1Characters2() { - assertTrue(RealexRemote.validateCardHolderName("S T U V W X Y Z [ \\ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ ¡ ¢ £ ¤ ¥")); - } - - @SmallTest - public void testISO_IEC8859_1Characters3() { - assertTrue(RealexRemote.validateCardHolderName("¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö")); - } - - @SmallTest - public void testISO_IEC8859_1Characters4() { - assertTrue(RealexRemote.validateCardHolderName("× Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ")); - } - - @SmallTest - public void testNonISO_IEC8859_1Characters() { - assertFalse(RealexRemote.validateCardHolderName("€")); - } - +package com.realexpayments.remote; + +import org.junit.Test; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; + +/* + * Unit tests for validateCardHolderName + * card holder name validation (validateCardHolderName) + */ + +public class ValidateCardHolderNameTest { + + @Test + public void testValidName() { + assertTrue(RealexRemote.validateCardHolderName("Joe Smith")); + } + + @Test + public void testEmptyName() { + assertFalse(RealexRemote.validateCardHolderName("")); + } + + @Test + public void testUndefinedName() { + assertFalse(RealexRemote.validateCardHolderName(null)); + } + + @Test + public void testWhiteSpaceOnly() { + assertFalse(RealexRemote.validateCardHolderName(" ")); + } + + @Test + public void testNameOf100Characters() { + assertTrue(RealexRemote.validateCardHolderName("abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij")); + } + + @Test + public void testNameOver100Characters() { + assertFalse(RealexRemote.validateCardHolderName("abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghija")); + } + + @Test + public void testISO_IEC8859_1Characters1() { + assertTrue(RealexRemote.validateCardHolderName("!\" # $ % & \' ( ) * + - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R")); + } + + @Test + public void testISO_IEC8859_1Characters2() { + assertTrue(RealexRemote.validateCardHolderName("S T U V W X Y Z [ \\ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ ¡ ¢ £ ¤ ¥")); + } + + @Test + public void testISO_IEC8859_1Characters3() { + assertTrue(RealexRemote.validateCardHolderName("¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö")); + } + + @Test + public void testISO_IEC8859_1Characters4() { + assertTrue(RealexRemote.validateCardHolderName("× Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ")); + } + + @Test + public void testNonISO_IEC8859_1Characters() { + assertFalse(RealexRemote.validateCardHolderName("€")); + } + } \ No newline at end of file diff --git a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCardNumberTest.java b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCardNumberTest.java similarity index 84% rename from rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCardNumberTest.java rename to rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCardNumberTest.java index b3a52d3..bde636d 100644 --- a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCardNumberTest.java +++ b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCardNumberTest.java @@ -1,72 +1,72 @@ -package com.realexpayments.remote; - -import androidx.test.filters.SmallTest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - - -/* - * Unit tests for validateCardNumber - */ - -public class ValidateCardNumberTest { - - @SmallTest - public void testValidCard() { - assertTrue(RealexRemote.validateCardNumber("424242424242424242")); - } - - @SmallTest - public void testNonNumericCard() { - assertFalse(RealexRemote.validateCardNumber("a24242424242424242")); - } - - @SmallTest - public void testCardWithSpaces() { - assertFalse(RealexRemote.validateCardNumber("4242 424242424242")); - } - - @SmallTest - public void testEmptyCard() { - assertFalse(RealexRemote.validateCardNumber("")); - } - - @SmallTest - public void testUndefinedCard() { - assertFalse(RealexRemote.validateCardNumber(null)); - } - - @SmallTest - public void testWhiteSpaceOnly() { - assertFalse(RealexRemote.validateCardNumber(" ")); - } - - @SmallTest - public void testLengthLt12() { - assertFalse(RealexRemote.validateCardNumber("42424242420")); - } - - @SmallTest - public void testLengthGt19() { - assertFalse(RealexRemote.validateCardNumber("42424242424242424242")); - } - - @SmallTest - public void testLengthEq12() - - { - assertTrue(RealexRemote.validateCardNumber("424242424242")); - } - - @SmallTest - public void testLengthEq19() { - assertTrue(RealexRemote.validateCardNumber("4242424242424242428")); - } - - @SmallTest - public void testLuhnCheck() { - assertFalse(RealexRemote.validateCardNumber("4242424242424242427")); - } - +package com.realexpayments.remote; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + + +/* + * Unit tests for validateCardNumber + */ + +public class ValidateCardNumberTest { + + @Test + public void testValidCard() { + assertTrue(RealexRemote.validateCardNumber("424242424242424242")); + } + + @Test + public void testNonNumericCard() { + assertFalse(RealexRemote.validateCardNumber("a24242424242424242")); + } + + @Test + public void testCardWithSpaces() { + assertFalse(RealexRemote.validateCardNumber("4242 424242424242")); + } + + @Test + public void testEmptyCard() { + assertFalse(RealexRemote.validateCardNumber("")); + } + + @Test + public void testUndefinedCard() { + assertFalse(RealexRemote.validateCardNumber(null)); + } + + @Test + public void testWhiteSpaceOnly() { + assertFalse(RealexRemote.validateCardNumber(" ")); + } + + @Test + public void testLengthLt12() { + assertFalse(RealexRemote.validateCardNumber("42424242420")); + } + + @Test + public void testLengthGt19() { + assertFalse(RealexRemote.validateCardNumber("42424242424242424242")); + } + + @Test + public void testLengthEq12() + + { + assertTrue(RealexRemote.validateCardNumber("424242424242")); + } + + @Test + public void testLengthEq19() { + assertTrue(RealexRemote.validateCardNumber("4242424242424242428")); + } + + @Test + public void testLuhnCheck() { + assertFalse(RealexRemote.validateCardNumber("4242424242424242427")); + } + } \ No newline at end of file diff --git a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCvnTest.java b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCvnTest.java similarity index 83% rename from rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCvnTest.java rename to rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCvnTest.java index f6b32a4..2c33203 100644 --- a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateCvnTest.java +++ b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateCvnTest.java @@ -1,49 +1,49 @@ -package com.realexpayments.remote; - -import androidx.test.filters.SmallTest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -/* - * Unit tests for validateCvn - * CVN non-Amex validation (validateCvn) - */ - -public class ValidateCvnTest { - - @SmallTest - public void testValidNonAmexCVN() { - assertTrue(RealexRemote.validateCvn("123")); - } - - @SmallTest - public void testEmptyCVN() { - assertFalse(RealexRemote.validateCvn("")); - } - - @SmallTest - public void testUndefinedCVN() { - assertFalse(RealexRemote.validateCvn(null)); - } - - @SmallTest - public void testWhiteSpaceOnly() { - assertFalse(RealexRemote.validateCvn(" ")); - } - - @SmallTest - public void testNonAmexCVNof4Numbers() { - assertFalse(RealexRemote.validateCvn("1234")); - } - - @SmallTest - public void testNonAmexCVNof2Numbers() { - assertFalse(RealexRemote.validateCvn("12")); - } - - @SmallTest - public void testNonNumericNonAmexCVNof3Characters() { - assertFalse(RealexRemote.validateCvn("12a")); - } - +package com.realexpayments.remote; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +/* + * Unit tests for validateCvn + * CVN non-Amex validation (validateCvn) + */ + +public class ValidateCvnTest { + + @Test + public void testValidNonAmexCVN() { + assertTrue(RealexRemote.validateCvn("123")); + } + + @Test + public void testEmptyCVN() { + assertFalse(RealexRemote.validateCvn("")); + } + + @Test + public void testUndefinedCVN() { + assertFalse(RealexRemote.validateCvn(null)); + } + + @Test + public void testWhiteSpaceOnly() { + assertFalse(RealexRemote.validateCvn(" ")); + } + + @Test + public void testNonAmexCVNof4Numbers() { + assertFalse(RealexRemote.validateCvn("1234")); + } + + @Test + public void testNonAmexCVNof2Numbers() { + assertFalse(RealexRemote.validateCvn("12")); + } + + @Test + public void testNonNumericNonAmexCVNof3Characters() { + assertFalse(RealexRemote.validateCvn("12a")); + } + } \ No newline at end of file diff --git a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateExpiryDateFormatTest.java b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateExpiryDateFormatTest.java similarity index 84% rename from rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateExpiryDateFormatTest.java rename to rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateExpiryDateFormatTest.java index 4972c17..c6c24a8 100644 --- a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateExpiryDateFormatTest.java +++ b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateExpiryDateFormatTest.java @@ -1,67 +1,67 @@ -package com.realexpayments.remote; - -import androidx.test.filters.SmallTest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -/* - * Expiry date format validation (validateExpiryDateFormat) - */ -public class ValidateExpiryDateFormatTest { - - @SmallTest - public void testValidDate1299() { - assertTrue(RealexRemote.validateExpiryDateFormat("1299")); - } - - @SmallTest - public void testValidDate0199() { - assertTrue(RealexRemote.validateExpiryDateFormat("0199")); - } - - @SmallTest - public void testNonNumericDate() { - assertFalse(RealexRemote.validateExpiryDateFormat("a199")); - } - - @SmallTest - public void testDateWithSpaces() { - assertFalse(RealexRemote.validateExpiryDateFormat("1 99")); - } - - @SmallTest - public void testEmptyDate() { - assertFalse(RealexRemote.validateExpiryDateFormat("")); - } - - @SmallTest - public void testUndefinedDate() { - assertFalse(RealexRemote.validateExpiryDateFormat(null)); - } - - @SmallTest - public void testWhiteSpaceOnly() { - assertFalse(RealexRemote.validateExpiryDateFormat(" ")); - } - - @SmallTest - public void testLengthGt4() { - assertFalse(RealexRemote.validateExpiryDateFormat("12099")); - } - - @SmallTest - public void testLengthLt4() { - assertFalse(RealexRemote.validateExpiryDateFormat("199")); - } - - @SmallTest - public void testInvalidMonth00() { - assertFalse(RealexRemote.validateExpiryDateFormat("0099")); - } - - @SmallTest - public void testInvalidMonth13() { - assertFalse(RealexRemote.validateExpiryDateFormat("1399")); - } - +package com.realexpayments.remote; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +/* + * Expiry date format validation (validateExpiryDateFormat) + */ +public class ValidateExpiryDateFormatTest { + + @Test + public void testValidDate1299() { + assertTrue(RealexRemote.validateExpiryDateFormat("1299")); + } + + @Test + public void testValidDate0199() { + assertTrue(RealexRemote.validateExpiryDateFormat("0199")); + } + + @Test + public void testNonNumericDate() { + assertFalse(RealexRemote.validateExpiryDateFormat("a199")); + } + + @Test + public void testDateWithSpaces() { + assertFalse(RealexRemote.validateExpiryDateFormat("1 99")); + } + + @Test + public void testEmptyDate() { + assertFalse(RealexRemote.validateExpiryDateFormat("")); + } + + @Test + public void testUndefinedDate() { + assertFalse(RealexRemote.validateExpiryDateFormat(null)); + } + + @Test + public void testWhiteSpaceOnly() { + assertFalse(RealexRemote.validateExpiryDateFormat(" ")); + } + + @Test + public void testLengthGt4() { + assertFalse(RealexRemote.validateExpiryDateFormat("12099")); + } + + @Test + public void testLengthLt4() { + assertFalse(RealexRemote.validateExpiryDateFormat("199")); + } + + @Test + public void testInvalidMonth00() { + assertFalse(RealexRemote.validateExpiryDateFormat("0099")); + } + + @Test + public void testInvalidMonth13() { + assertFalse(RealexRemote.validateExpiryDateFormat("1399")); + } + } \ No newline at end of file diff --git a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateExpiryDateNotInPastTest.java b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateExpiryDateNotInPastTest.java similarity index 86% rename from rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateExpiryDateNotInPastTest.java rename to rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateExpiryDateNotInPastTest.java index 61fd8e4..dcdfd77 100644 --- a/rxp-remote-android/src/androidTest/java/com/realexpayments/remote/ValidateExpiryDateNotInPastTest.java +++ b/rxp-remote-android/src/test/java/com/realexpayments/remote/ValidateExpiryDateNotInPastTest.java @@ -1,24 +1,24 @@ -package com.realexpayments.remote; - -import androidx.test.filters.SmallTest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import java.text.SimpleDateFormat; -import java.util.Calendar; - -public class ValidateExpiryDateNotInPastTest { - - @SmallTest - public void testDateInPast() { - assertFalse(RealexRemote.validateExpiryDateNotInPast("0615")); - } - - @SmallTest - public void testCurrentMonth() { - Calendar calendar = Calendar.getInstance(); - SimpleDateFormat format = new SimpleDateFormat("MMyy"); - assertTrue(RealexRemote.validateExpiryDateNotInPast(format.format(calendar.getTime()))); - } - +package com.realexpayments.remote; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +public class ValidateExpiryDateNotInPastTest { + + @Test + public void testDateInPast() { + assertFalse(RealexRemote.validateExpiryDateNotInPast("0615")); + } + + @Test + public void testCurrentMonth() { + Calendar calendar = Calendar.getInstance(); + SimpleDateFormat format = new SimpleDateFormat("MMyy"); + assertTrue(RealexRemote.validateExpiryDateNotInPast(format.format(calendar.getTime()))); + } + } \ No newline at end of file