Skip to content

Commit

Permalink
Minor fixes + split up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koen-serry committed Jul 17, 2021
1 parent 4a80494 commit 61841ae
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 125 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ jobs:
with:
distribution: 'adopt'
java-version: ${{ matrix.java-version }}
server-id: ossrh
server-username: MAVEN_USERNAME # env variable for username in deploy
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Cache Maven packages
uses: actions/cache@v1
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.twikey</groupId>
<artifactId>twikey-api-java</artifactId>
<packaging>jar</packaging>
<version>0.1.1</version>
<version>0.1.2</version>
<name>Twikey Api</name>
<url>http://maven.apache.org</url>
<description>Official wrapper around the Twikey.com rest api</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/twikey/InvoiceGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public JSONObject create(long ct, Customer customer, Map<String, String> invoice
JSONObject invoice = new JSONObject()
.put("customer", customerAsJson)
.put("date", invoiceDetails.getOrDefault("date", LocalDate.now().toString()))
.put("duedate", invoiceDetails.getOrDefault("date", LocalDate.now().plusMonths(1).toString()))
.put("duedate", invoiceDetails.getOrDefault("duedate", LocalDate.now().plusMonths(1).toString()))
.put("ct", ct);

for (Map.Entry<String, String> entry : invoiceDetails.entrySet()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/twikey/PaylinkGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void feed(PaylinkCallback callback) throws IOException, TwikeyClient.User
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
JSONObject json = new JSONObject(new JSONTokener(br));

JSONArray messagesArr = json.getJSONArray("Messages");
JSONArray messagesArr = json.getJSONArray("Links");
isEmpty = messagesArr.isEmpty();
if (!isEmpty) {
for (int i = 0; i < messagesArr.length(); i++) {
Expand Down
79 changes: 79 additions & 0 deletions src/test/java/com/twikey/DocumentGatewayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.twikey;

import com.twikey.callback.DocumentCallback;
import com.twikey.modal.Customer;
import org.json.JSONObject;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;

import static org.junit.Assert.assertNotNull;

public class DocumentGatewayTest {

private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api

private final String ct = System.getenv("CT"); // found @ https://www.twikey.com/r/admin#/c/template

private Customer customer;

private TwikeyClient api;

@Before
public void createCustomer(){
customer = new Customer()
.setNumber("customerNum123")
.setEmail("no-reply@example.com")
.setFirstname("Twikey")
.setLastname("Support")
.setStreet("Derbystraat 43")
.setCity("Gent")
.setZip("9000")
.setCountry("BE")
.setLang("nl")
.setMobile("32498665995");

api = new TwikeyClient(apiKey,true)
.withUserAgent("twikey-api-java/junit");
}

@Test
public void testInviteMandateWithoutCustomerDetails() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey);
JSONObject response = api.document().create(Long.parseLong(ct), null, new HashMap<>());
assertNotNull("Invite URL",response.getString("url"));
assertNotNull("Document Reference",response.getString("mndtId"));
}

@Test
public void testInviteMandateCustomerDetails() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey);
JSONObject response = api.document().create(Long.parseLong(ct), customer, new HashMap<>());
assertNotNull("Invite URL",response.getString("url"));
assertNotNull("Document Reference",response.getString("mndtId"));
}

@Test
public void getMandatesAndDetails() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey);
api.document().feed(new DocumentCallback() {
@Override
public void newDocument(JSONObject newMandate) {
System.out.println("New mandate: "+newMandate);
}

@Override
public void updatedDocument(JSONObject updatedMandate) {
System.out.println("Updated mandate: "+updatedMandate);
}

@Override
public void cancelledDocument(JSONObject cancelledMandate) {
System.out.println("Cancelled mandate: "+cancelledMandate);
}
});
}
}
66 changes: 66 additions & 0 deletions src/test/java/com/twikey/InvoiceGatewayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.twikey;

import com.twikey.modal.Customer;
import junit.framework.TestCase;
import org.json.JSONObject;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertNotNull;

public class InvoiceGatewayTest {

private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api

private final String ct = System.getenv("CT"); // found @ https://www.twikey.com/r/admin#/c/template

private Customer customer;

private TwikeyClient api;

@Before
public void createCustomer() {
customer = new Customer()
.setNumber("customerNum123")
.setEmail("no-reply@example.com")
.setFirstname("Twikey")
.setLastname("Support")
.setStreet("Derbystraat 43")
.setCity("Gent")
.setZip("9000")
.setCountry("BE")
.setLang("nl")
.setMobile("32498665995");

api = new TwikeyClient(apiKey, true)
.withUserAgent("twikey-api-java/junit");
}

@Test
public void testCreateInvoice() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey, ct);
Map<String, String> invoiceDetails = new HashMap<>();
invoiceDetails.put("number", "Invss123");
invoiceDetails.put("title", "Invoice April");
invoiceDetails.put("remittance", "123456789123");
invoiceDetails.put("amount", "10.90");
invoiceDetails.put("date", "2020-03-20");
invoiceDetails.put("duedate", "2020-04-28");
JSONObject invoiceResponse = api.invoice().create(Long.parseLong(ct), customer, invoiceDetails);
assertNotNull("Payment URL", invoiceResponse.getString("url"));
assertNotNull("Invoice Id", invoiceResponse.getString("id"));
}


@Test
public void getInvoicesAndDetails() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey);
api.invoice().feed(updatedInvoice -> System.out.println("Updated invoice: " + updatedInvoice));
}

}
61 changes: 61 additions & 0 deletions src/test/java/com/twikey/PaylinkGatewayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.twikey;

import com.twikey.modal.Customer;
import org.json.JSONObject;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;

public class PaylinkGatewayTest {

private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api

private final String ct = System.getenv("CT"); // found @ https://www.twikey.com/r/admin#/c/template

private Customer customer;

private TwikeyClient api;

@Before
public void createCustomer() {
customer = new Customer()
.setNumber("customerNum123")
.setEmail("no-reply@example.com")
.setFirstname("Twikey")
.setLastname("Support")
.setStreet("Derbystraat 43")
.setCity("Gent")
.setZip("9000")
.setCountry("BE")
.setLang("nl")
.setMobile("32498665995");

api = new TwikeyClient(apiKey, true)
.withUserAgent("twikey-api-java/junit");
}

@Test
public void testCreate() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey, ct);
Map<String, String> extra = new HashMap<>();
extra.put("message", "Test Link");
extra.put("amount", "10.00");
JSONObject linkResponse = api.paylink().create(Long.parseLong(ct), customer, extra);
assertNotNull("Payment URL", linkResponse.getString("url"));
assertNotEquals(0, linkResponse.getLong("id"));

}

@Test
public void testFeed() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey);
api.paylink().feed(updatedLink -> System.out.println("Updated link: " + updatedLink));
}
}
46 changes: 46 additions & 0 deletions src/test/java/com/twikey/TransactionGatewayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.twikey;

import org.json.JSONObject;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertNotNull;

public class TransactionGatewayTest {

private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api

private final String mandateNumber = System.getenv("mndtNumber");

private TwikeyClient api;

@Before
public void prepClient() {
api = new TwikeyClient(apiKey, true)
.withUserAgent("twikey-api-java/junit");
}

@Test
public void testCreate() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey,mandateNumber);
Map<String, String> extra = new HashMap<>();
extra.put("message", "Test Message");
extra.put("amount", "10.00");
JSONObject linkResponse = api.transaction().create(mandateNumber, extra);
System.out.println(linkResponse);
assertNotNull("Payment URL", linkResponse.getString("url"));
assertNotNull("Invoice Id", linkResponse.getString("id"));
}

@Test
public void testFeed() throws IOException, TwikeyClient.UserException {
Assume.assumeNotNull(apiKey);
api.transaction().feed(updatedTransaction -> System.out.println("Updated transaction: " + updatedTransaction));
}

}
Loading

0 comments on commit 61841ae

Please sign in to comment.