Commit ddb5b2e7 by Juho Juopperi

Merge branch 'testfix2' into 'master'

Minor interface and enum renames and testcase fixing

Test cases need to be renamed consistently to be automatically included with maven testing framework. All unit test classes need to a) start with 'Test', b) end with 'Test' or c) end with 'TestCase' Test classes have been renamed to conform with this requirement.

Change names of Checkout parameter classes to be more descriptive what the classes really are for.

Includes also some unnecessary type checks from checkout QueryBuilder.

See merge request !258
2 parents d790c5ac 339a3404
...@@ -41,7 +41,6 @@ public class CheckoutBank { ...@@ -41,7 +41,6 @@ public class CheckoutBank {
throw new RuntimeException("Wrong type of node " + bank + " type " + bank.getNodeType()); throw new RuntimeException("Wrong type of node " + bank + " type " + bank.getNodeType());
} }
key = bank.getNodeName(); key = bank.getNodeName();
logger.info("Bank type {}", bank);
NamedNodeMap attrs = bank.getAttributes(); NamedNodeMap attrs = bank.getAttributes();
String iconval = null; String iconval = null;
String nameval = null; String nameval = null;
......
...@@ -18,18 +18,14 @@ ...@@ -18,18 +18,14 @@
*/ */
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -62,8 +58,8 @@ import org.w3c.dom.NodeList; ...@@ -62,8 +58,8 @@ import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import fi.codecrew.moya.checkoutfi.CheckoutFiCheckParam; import fi.codecrew.moya.checkoutfi.CheckoutFiCheckParam;
import fi.codecrew.moya.checkoutfi.CheckoutFiParam; import fi.codecrew.moya.checkoutfi.CheckoutFiPaymentParam;
import fi.codecrew.moya.checkoutfi.CheckoutQuery; import fi.codecrew.moya.checkoutfi.CheckoutQueryParam;
import fi.codecrew.moya.clientutils.BortalLocalContextHolder; import fi.codecrew.moya.clientutils.BortalLocalContextHolder;
import fi.codecrew.moya.enums.apps.BillPermission; import fi.codecrew.moya.enums.apps.BillPermission;
import fi.codecrew.moya.facade.BillFacade; import fi.codecrew.moya.facade.BillFacade;
...@@ -115,7 +111,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -115,7 +111,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
* *
*/ */
public boolean isBillPaid(Bill bill) { public boolean isBillPaid(Bill bill) {
QueryBuilder<CheckoutFiCheckParam> cb = initQuerybuilder(CheckoutFiCheckParam.class, CheckoutFiCheckParam.values()); QueryBuilder cb = initQuerybuilder(CheckoutFiCheckParam.values());
if (!cb.isCredentialsValid()) { if (!cb.isCredentialsValid()) {
throw new EJBException("Invalid Credentials"); throw new EJBException("Invalid Credentials");
...@@ -179,7 +175,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -179,7 +175,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
return ret; return ret;
} }
protected <T extends Enum<T>> QueryBuilder<T> initQuerybuilder(Class<T> clz, CheckoutQuery[] params) { protected QueryBuilder initQuerybuilder(CheckoutQueryParam[] params) {
final LanEventPrivateProperty expire = eventbean.getPrivateProperty(LanEventPrivatePropertyKey.CHECKOUT_FI_KEY_EXPIRE); final LanEventPrivateProperty expire = eventbean.getPrivateProperty(LanEventPrivatePropertyKey.CHECKOUT_FI_KEY_EXPIRE);
final String merchantid = eventbean.getPrivatePropertyString(LanEventPrivatePropertyKey.CHECKOUT_FI_MERCHANT_ID); final String merchantid = eventbean.getPrivatePropertyString(LanEventPrivatePropertyKey.CHECKOUT_FI_MERCHANT_ID);
...@@ -188,7 +184,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -188,7 +184,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
if (expire != null) { if (expire != null) {
date = expire.getDateValue(); date = expire.getDateValue();
} }
QueryBuilder<T> ret = new QueryBuilder<T>(clz, params, date, merchantid, merchantPassword); QueryBuilder ret = new QueryBuilder(params, date, merchantid, merchantPassword);
return ret; return ret;
} }
...@@ -200,7 +196,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -200,7 +196,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
if (bill.isFoowavePaymentOver()) { if (bill.isFoowavePaymentOver()) {
return null; return null;
} }
QueryBuilder<CheckoutFiParam> queryBuilder = initQuerybuilder(CheckoutFiParam.class, CheckoutFiParam.values()); QueryBuilder queryBuilder = initQuerybuilder(CheckoutFiPaymentParam.values());
if (!queryBuilder.isCredentialsValid()) { if (!queryBuilder.isCredentialsValid()) {
return null; return null;
...@@ -214,15 +210,15 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -214,15 +210,15 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
final String priceInCents = Integer.valueOf(bill.totalPrice().multiply(TO_CENTS).intValue()).toString(); final String priceInCents = Integer.valueOf(bill.totalPrice().multiply(TO_CENTS).intValue()).toString();
queryBuilder.addParam(CheckoutFiParam.STAMP, getStamp(bill)); queryBuilder.addParam(CheckoutFiPaymentParam.STAMP, getStamp(bill));
queryBuilder.addParam(CheckoutFiParam.AMOUNT, priceInCents); queryBuilder.addParam(CheckoutFiPaymentParam.AMOUNT, priceInCents);
queryBuilder.addParam(CheckoutFiParam.REFERENCE, bill.getReferenceNumber().toString()); queryBuilder.addParam(CheckoutFiPaymentParam.REFERENCE, bill.getReferenceNumber().toString());
queryBuilder.addParam(CheckoutFiParam.MERCHANT, queryBuilder.getMerchantId()); queryBuilder.addParam(CheckoutFiPaymentParam.MERCHANT, queryBuilder.getMerchantId());
queryBuilder.addParam(CheckoutFiParam.RETURN, returnUrl + "return.jsf"); queryBuilder.addParam(CheckoutFiPaymentParam.RETURN, returnUrl + "return.jsf");
queryBuilder.addParam(CheckoutFiParam.CANCEL, returnUrl + "cancel.jsf"); queryBuilder.addParam(CheckoutFiPaymentParam.CANCEL, returnUrl + "cancel.jsf");
queryBuilder.addParam(CheckoutFiParam.REJECT, returnUrl + "reject.jsf"); queryBuilder.addParam(CheckoutFiPaymentParam.REJECT, returnUrl + "reject.jsf");
queryBuilder.addParam(CheckoutFiParam.DELAYED, returnUrl + "delayed.jsf"); queryBuilder.addParam(CheckoutFiPaymentParam.DELAYED, returnUrl + "delayed.jsf");
queryBuilder.addParam(CheckoutFiParam.DELIVERY_DATE, new SimpleDateFormat(DATEFORMAT).format(new Date())); queryBuilder.addParam(CheckoutFiPaymentParam.DELIVERY_DATE, new SimpleDateFormat(DATEFORMAT).format(new Date()));
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
List<CheckoutBank> ret = null; List<CheckoutBank> ret = null;
...@@ -253,7 +249,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -253,7 +249,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
} }
private static CloseableHttpResponse sendQuery(QueryBuilder<?> queryBuilder) throws ClientProtocolException, IOException { private static CloseableHttpResponse sendQuery(QueryBuilder queryBuilder) throws ClientProtocolException, IOException {
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
final HttpPost postRequest = new HttpPost(REMOTE_URL); final HttpPost postRequest = new HttpPost(REMOTE_URL);
postRequest.setEntity(new UrlEncodedFormEntity(queryBuilder.getNameValuePairs())); postRequest.setEntity(new UrlEncodedFormEntity(queryBuilder.getNameValuePairs()));
...@@ -416,14 +412,14 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -416,14 +412,14 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
return ret; return ret;
} }
static class QueryBuilder<T extends Enum<T>> { static class QueryBuilder {
private final Map<CheckoutQuery, String> values = new HashMap<>();; private final Map<CheckoutQueryParam, String> values = new HashMap<>();;
private final Date expireDate; private final Date expireDate;
private final String merchantId; private final String merchantId;
private final String merchantPassword; private final String merchantPassword;
private final CheckoutQuery[] types; private final CheckoutQueryParam[] types;
QueryBuilder(Class<T> clz, CheckoutQuery[] types, Date expire, String merchantId, String merchantPassword) { QueryBuilder(CheckoutQueryParam[] types, Date expire, String merchantId, String merchantPassword) {
this.expireDate = expire; this.expireDate = expire;
this.merchantId = merchantId; this.merchantId = merchantId;
this.merchantPassword = merchantPassword; this.merchantPassword = merchantPassword;
...@@ -438,7 +434,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -438,7 +434,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
} }
public void addParam(CheckoutQuery key, String value) { public void addParam(CheckoutQueryParam key, String value) {
values.put(key, value); values.put(key, value);
} }
...@@ -447,14 +443,13 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -447,14 +443,13 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
StringBuilder mdString = new StringBuilder(); StringBuilder mdString = new StringBuilder();
for (CheckoutQuery v : types) { for (CheckoutQueryParam v : types) {
String value = null; String value = null;
if (values.containsKey(v)) { if (values.containsKey(v)) {
value = values.get(v); value = values.get(v);
} else { } else {
value = v.getDefaultValue(); value = v.getDefaultValue();
} }
logger.info("Add key {},value {}", v.name(), value);
if (value != null) { if (value != null) {
mdString.append(value); mdString.append(value);
nameValuePairs.add(new BasicNameValuePair(v.name(), value)); nameValuePairs.add(new BasicNameValuePair(v.name(), value));
...@@ -465,7 +460,6 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal { ...@@ -465,7 +460,6 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
mdString.append(merchantPassword); mdString.append(merchantPassword);
final String calculatedHash = PasswordFunctions.calculateMd5(mdString.toString()); final String calculatedHash = PasswordFunctions.calculateMd5(mdString.toString());
logger.info("Calculated checksum {} from {}", mdString.toString(), calculatedHash);
nameValuePairs.add(new BasicNameValuePair("MAC", calculatedHash)); nameValuePairs.add(new BasicNameValuePair("MAC", calculatedHash));
......
package fi.codecrew.moya.checkoutfi; package fi.codecrew.moya.checkoutfi;
public enum CheckoutFiCheckParam implements CheckoutQuery { public enum CheckoutFiCheckParam implements CheckoutQueryParam {
// DO NOT CHANGE THE ORDER OF THESE! // DO NOT CHANGE THE ORDER OF THESE!
// The md5 checksum is calculated from // The md5 checksum is calculated from
// these values... // these values...
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
package fi.codecrew.moya.checkoutfi; package fi.codecrew.moya.checkoutfi;
public enum CheckoutFiParam implements CheckoutQuery { public enum CheckoutFiPaymentParam implements CheckoutQueryParam {
// DO NOT CHANGE THE ORDER OF THESE! // DO NOT CHANGE THE ORDER OF THESE!
// The md5 checksum is calculated from // The md5 checksum is calculated from
...@@ -52,7 +52,7 @@ public enum CheckoutFiParam implements CheckoutQuery { ...@@ -52,7 +52,7 @@ public enum CheckoutFiParam implements CheckoutQuery {
private final String defaultValue; private final String defaultValue;
private CheckoutFiParam(String def) { private CheckoutFiPaymentParam(String def) {
defaultValue = def; defaultValue = def;
} }
......
package fi.codecrew.moya.checkoutfi; package fi.codecrew.moya.checkoutfi;
public interface CheckoutQuery { public interface CheckoutQueryParam {
public String name(); public String name();
......
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import org.testng.annotations.BeforeTest;
import javax.ejb.embeddable.EJBContainer; import javax.ejb.embeddable.EJBContainer;
import javax.naming.NamingException; import javax.naming.NamingException;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@Test
public abstract class AbstractEjbTest { public abstract class AbstractEjbTest {
@BeforeTest @BeforeTest
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test
public class BarcodeTests { public class BarcodeTest {
@Test @Test
public void tbd() { public void tbd() {
} }
......
...@@ -6,13 +6,13 @@ import org.testng.annotations.Test; ...@@ -6,13 +6,13 @@ import org.testng.annotations.Test;
@Test @Test
public class VipBeanTest { public class VipBeanTest {
private static final Logger log = LoggerFactory.getLogger(VipBeanTest.class); private static final Logger log = LoggerFactory.getLogger(VipBeanTest.class);
@Test @Test
public void testVip() { public void testVip() {
log.info("testVip"); log.info("testVip");
VipBean vipBean = new VipBean(); VipBean vipBean = new VipBean();
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!