Skip to content

Commit

Permalink
Merge branch 'SDK-92'
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Sampaio committed Aug 26, 2016
2 parents 0195202 + 9f07a1e commit 3054262
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To get started add our SDK as a dependency in your **pom.xml**:
<dependency>
<groupId>com.konduto.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>2.6.0</version>
<version>2.7.0</version>
</dependency>
```

Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ artifacts {
archives sourcesJar
}

signing {
sign configurations.archives
}
signing {
required { gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

uploadArchives {
repositories {
Expand Down Expand Up @@ -99,4 +100,4 @@ uploadArchives {
}
}
}
}
}
2 changes: 1 addition & 1 deletion konduto.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 2.6.0
version = 2.7.0
9 changes: 8 additions & 1 deletion src/main/java/com/konduto/sdk/models/KondutoCustomer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class KondutoCustomer extends KondutoModel {
@SerializedName("new") private Boolean isNew;

private Date created_at;
private Date dob;

/* Constructors */

Expand Down Expand Up @@ -64,7 +65,9 @@ public boolean equals(Object o) {
if (!nullSafeAreDatesEqual(created_at, that.created_at)){
return false;
}

if (!nullSafeAreDatesEqual(dob, that.dob)){
return false;
}

return true;
}
Expand Down Expand Up @@ -138,4 +141,8 @@ public void setIsNew(Boolean isNew) {
public Date getCreated_at() { return created_at; }

public void setCreated_at(Date created_at) { this.created_at = created_at; }

public Date getDOB() { return dob; }

public void setDOB(Date dob) { this.dob = dob; }
}
12 changes: 12 additions & 0 deletions src/main/java/com/konduto/sdk/models/KondutoFlightTravelLeg.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.konduto.sdk.models;

import com.konduto.sdk.Konduto;
import com.konduto.sdk.annotations.Required;
import com.konduto.sdk.annotations.ValidateFormat;

Expand All @@ -19,6 +20,17 @@ public class KondutoFlightTravelLeg extends KondutoTravelLeg {
private String originCity;
private String destinationCity;

/**
* Fluent constructor
* @param attributeName the attribute name (e.g totalAmount)
* @param attributeValue the attribute value (e.g 123.2)
* @return a new instance
*/
@Override
public KondutoFlightTravelLeg with(String attributeName, Object attributeValue) {
return (KondutoFlightTravelLeg) super.with(attributeName, attributeValue);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/konduto/sdk/models/KondutoModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import com.konduto.sdk.annotations.ValidateFormat;
import com.konduto.sdk.exceptions.KondutoInvalidEntityException;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.*;
import java.util.*;

/**
Expand Down Expand Up @@ -132,7 +129,8 @@ void addIsInvalidError(String errors) {
public boolean isValid() {
errors.clear();
Object value;
for(Field f : this.getClass().getDeclaredFields()) {

for(Field f : getAllFields(new LinkedList<Field>(), this.getClass())) {
if (!f.isSynthetic()) {
try {
f.setAccessible(true);
Expand Down Expand Up @@ -181,6 +179,15 @@ public boolean isValid() {

}

public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
fields.addAll(Arrays.asList(type.getDeclaredFields()));

if (type.getSuperclass() != null) {
fields = getAllFields(fields, type.getSuperclass());
}

return fields;
}

/**
* Enables Map-based construction in KondutoModel children.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/konduto/sdk/models/KondutoSeller.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public KondutoSeller() { }
* @return a new instance
*/
@Override
public KondutoCustomer with(String attributeName, Object attributeValue) {
return (KondutoCustomer) super.with(attributeName, attributeValue);
public KondutoSeller with(String attributeName, Object attributeValue) {
return (KondutoSeller) super.with(attributeName, attributeValue);
}

/* Equals */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.konduto.sdk.models.KondutoCustomer;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
Expand All @@ -16,14 +20,19 @@ public static KondutoCustomer basicCustomer(){
return customer;
}

public static KondutoCustomer completeCustomer() {
public static KondutoCustomer completeCustomer() throws ParseException {
KondutoCustomer customer = basicCustomer();
customer.setIsNew(false);
customer.setIsVip(false);
customer.setPhone1("11987654321");
customer.setPhone2("1133333333");
customer.setTaxId("01234567890");
customer.setCreated_at(new Date(1433818800000L));

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date dob = sdf.parse("27/12/1989");
customer.setDOB(dob);

return customer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

/**
Expand All @@ -27,4 +29,16 @@ public void serializeTest(){

assertEquals("deserialization failed", creditCardPayment, creditCardPaymentDeserialized);
}

@Test
public void invalidCardTypeTest(){
KondutoPayment creditCardPayment = KondutoPaymentFactory.getCreditCardPayment();
creditCardPayment.type = null;

assertFalse(creditCardPayment.isValid());

creditCardPayment.type = KondutoPaymentType.CREDIT;

assertTrue(creditCardPayment.isValid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.konduto.sdk.utils.TestUtils;
import org.junit.Test;

import java.text.ParseException;

import static org.junit.Assert.*;

/**
Expand All @@ -25,7 +27,7 @@ public void isValidTest() {
}

@Test
public void serializationTest(){
public void serializationTest() throws ParseException {
KondutoCustomer customer = KondutoCustomerFactory.completeCustomer();
JsonObject customerJSON = (JsonObject) TestUtils.readJSONFromFile("customer.json");
try {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/konduto/sdk/models/KondutoOrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import com.konduto.sdk.exceptions.KondutoInvalidEntityException;
import com.konduto.sdk.factories.KondutoCustomerFactory;
import com.konduto.sdk.factories.KondutoOrderFactory;
import com.konduto.sdk.factories.KondutoPaymentFactory;
import com.konduto.sdk.utils.TestUtils;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

import static org.junit.Assert.*;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/customer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"phone2":"1133333333",
"vip":false,
"new":false,
"created_at":"2015-06-09"
"created_at":"2015-06-09",
"dob": "1989-12-27"
}
3 changes: 2 additions & 1 deletion src/test/resources/order.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"phone2":"1133333333",
"vip":false,
"new":false,
"created_at": "2015-06-09"
"created_at": "2015-06-09",
"dob": "1989-12-27"
},
"recommendation":"approve",
"geolocation":{
Expand Down

0 comments on commit 3054262

Please sign in to comment.