Test & clean

TODO : end WalletImplementationTest
This commit is contained in:
GME 2019-04-03 19:53:12 +02:00
parent ef9863a8be
commit 86f6abfce5
13 changed files with 112 additions and 84 deletions

View file

@ -1,8 +1,8 @@
-- SEQUENCE: public."T_TRANSACTION_transactionId_seq"
-- SEQUENCE: public.t_transaction_id_seq"
-- DROP SEQUENCE public."T_TRANSACTION_transactionId_seq";
-- DROP SEQUENCE public."t_transaction_id_seq";
CREATE SEQUENCE public."T_TRANSACTION_transactionId_seq";
CREATE SEQUENCE public."t_transaction_id_seq";
ALTER SEQUENCE public."T_TRANSACTION_transactionId_seq"
ALTER SEQUENCE public."t_transaction_id_seq"
OWNER TO monnethicadmin;

View file

@ -4,14 +4,14 @@
CREATE TABLE public."T_TRANSACTION"
(
"transactionId" integer NOT NULL DEFAULT nextval('"T_TRANSACTION_transactionId_seq"'::regclass),
"transactionDate" bigint NOT NULL,
"transactionFrom" character varying(255) COLLATE pg_catalog."default" NOT NULL,
"transactionTo" character varying(255) COLLATE pg_catalog."default" NOT NULL,
"transactionHash" character varying(255) COLLATE pg_catalog."default" NOT NULL,
"transactionAmount" numeric(255,5) NOT NULL,
"transactionUnit" character varying(255) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "T_TRANSACTION_pkey" PRIMARY KEY ("transactionId")
"transaction_id" integer NOT NULL DEFAULT nextval('"t_transaction_id_seq"'::regclass),
"transaction_date" bigint NOT NULL,
"transaction_from" character varying(255) COLLATE pg_catalog."default" NOT NULL,
"transaction_to" character varying(255) COLLATE pg_catalog."default" NOT NULL,
"transaction_hash" character varying(255) COLLATE pg_catalog."default" NOT NULL,
"transaction_amount" numeric(255,5) NOT NULL,
"transaction_unit" character varying(255) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "T_TRANSACTION_pkey" PRIMARY KEY ("transaction_id")
)
WITH (
OIDS = FALSE

View file

@ -38,7 +38,7 @@ public class Config {
//public static final String CHAINCODE_NAME = "mycc";
public static final String CHAINCODE_NAME = "monnethic_2";
//public static final String CHAINCODE_NAME = "monnethic-dev-4";
public static final String CHAINCODE_PROD = "monnethic-prod";
//public static final String CHAINCODE_PROD = "monnethic-prod";
//PEER 0
public static final String ORG1_PEER_0 = "peer0.org1.example.com";

View file

@ -65,7 +65,7 @@ public class WalletDao {
updateBuilder.updateColumnValue("user_hash",newUserHash);
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
updateBuilder.where().eq("walletHash",walletHash).and().eq("is_active",true);
updateBuilder.where().eq("wallet_hash",walletHash).and().eq("is_active",true);
updateBuilder.update();
}

View file

@ -6,100 +6,99 @@ import com.j256.ormlite.table.DatabaseTable;
@DatabaseTable(tableName = "T_TRANSACTION")
public class Transaction {
@DatabaseField(generatedId = true)
private int transactionId;
private int transaction_id;
@DatabaseField(canBeNull = false)
private long transactionDate;
private long transaction_date;
@DatabaseField(canBeNull = false)
private String transactionFrom;
private String transaction_from;
@DatabaseField(canBeNull = false)
private String transactionTo;
private String transaction_to;
@DatabaseField(canBeNull = false)
private String transactionHash;
private String transaction_hash;
@DatabaseField(canBeNull = false)
private Double transactionAmount;
private double transaction_amount;
@DatabaseField(canBeNull = false)
private String transactionUnit;
private String transaction_unit;
public Transaction() {
}
public Transaction(long transactionDate, String transactionFrom, String transactionTo, String transactionHash, Double transactionAmount, String transactionUnit) {
super();
this.transactionDate = transactionDate;
this.transactionFrom = transactionFrom;
this.transactionTo = transactionTo;
this.transactionHash = transactionHash;
this.transactionAmount = transactionAmount;
this.transactionUnit = transactionUnit;
public Transaction(int transaction_id, long transaction_date, String transaction_from, String transaction_to, String transaction_hash, double transaction_amount, String transaction_unit) {
this.transaction_id = transaction_id;
this.transaction_date = transaction_date;
this.transaction_from = transaction_from;
this.transaction_to = transaction_to;
this.transaction_hash = transaction_hash;
this.transaction_amount = transaction_amount;
this.transaction_unit = transaction_unit;
}
public String getTransactionFrom() {
return transactionFrom;
public int getTransaction_id() {
return transaction_id;
}
public void setTransactionFrom(String transactionFrom) {
this.transactionFrom = transactionFrom;
public void setTransaction_id(int transaction_id) {
this.transaction_id = transaction_id;
}
public String getTransactionTo() {
return transactionTo;
public long getTransaction_date() {
return transaction_date;
}
public void setTransactionTo(String transactionTo) {
this.transactionTo = transactionTo;
public void setTransaction_date(long transaction_date) {
this.transaction_date = transaction_date;
}
public String getTransactionHash() {
return transactionHash;
public String getTransaction_from() {
return transaction_from;
}
public void setTransactionHash(String transactionHash) {
this.transactionHash = transactionHash;
public void setTransaction_from(String transaction_from) {
this.transaction_from = transaction_from;
}
public Double getTransactionAmount() {
return transactionAmount;
public String getTransaction_to() {
return transaction_to;
}
public void setTransactionAmount(Double transactionAmount) {
this.transactionAmount = transactionAmount;
public void setTransaction_to(String transaction_to) {
this.transaction_to = transaction_to;
}
public int getTransactionId() {
return transactionId;
public String getTransaction_hash() {
return transaction_hash;
}
public void setTransactionId(int id) {
this.transactionId = transactionId;
public void setTransaction_hash(String transaction_hash) {
this.transaction_hash = transaction_hash;
}
public long getTransactionDate() {
return transactionDate;
public double getTransaction_amount() {
return transaction_amount;
}
public void setTransactionDate(long transactionDate) {
this.transactionDate = transactionDate;
public void setTransaction_amount(double transaction_amount) {
this.transaction_amount = transaction_amount;
}
public String getTransactionUnit() {
return transactionUnit;
public String getTransaction_unit() {
return transaction_unit;
}
public void setTransactionUnit(String transactionUnit) {
this.transactionUnit = transactionUnit;
public void setTransaction_unit(String transaction_unit) {
this.transaction_unit = transaction_unit;
}
@Override
public String toString() {
return "Transaction{" +
"transactionId=" + transactionId +
", transactionDate=" + transactionDate +
", transactionFrom='" + transactionFrom + '\'' +
", transactionTo='" + transactionTo + '\'' +
", transactionHash='" + transactionHash + '\'' +
", transactionAmount=" + transactionAmount +
", transactionUnit='" + transactionUnit + '\'' +
"transaction_id=" + transaction_id +
", transaction_date=" + transaction_date +
", transaction_from='" + transaction_from + '\'' +
", transaction_to='" + transaction_to + '\'' +
", transaction_hash='" + transaction_hash + '\'' +
", transaction_amount=" + transaction_amount +
", transaction_unit='" + transaction_unit + '\'' +
'}';
}
}

View file

@ -29,8 +29,8 @@ public class TransactionDao {
public List<Transaction> getUserTransactions(String userHash)throws Exception{
transactionDao = createTransactionDaoConnection();
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
queryBuilder.where().eq("transactionFrom",userHash).or().eq("transactionTo",userHash);
queryBuilder.orderBy("transactionDate",false);
queryBuilder.where().eq("transaction_from",userHash).or().eq("transaction_to",userHash);
queryBuilder.orderBy("transaction_date",false);
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
return transactionDao.query(preparedQuery);
}
@ -38,9 +38,9 @@ public class TransactionDao {
public List<Transaction> getTenLastUserTransactions(String userHash)throws Exception{
transactionDao = createTransactionDaoConnection();
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
queryBuilder.where().eq("transactionFrom",userHash).or().eq("transactionTo",userHash);
queryBuilder.where().eq("transaction_from",userHash).or().eq("transaction_to",userHash);
queryBuilder.limit(new Long(10));
queryBuilder.orderBy("transactionDate",false);
queryBuilder.orderBy("transaction_date",false);
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
return transactionDao.query(preparedQuery);
}
@ -48,7 +48,7 @@ public class TransactionDao {
public Transaction getTransaction(String userHash, String transactionHash)throws Exception{
transactionDao = createTransactionDaoConnection();
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
queryBuilder.where().eq("transactionTo",userHash).or().eq("transactionFrom",userHash).and().eq("transactionHash",transactionHash);
queryBuilder.where().eq("transaction_to",userHash).or().eq("transaction_from",userHash).and().eq("transaction_hash",transactionHash);
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
return transactionDao.queryForFirst(preparedQuery);
}
@ -56,8 +56,8 @@ public class TransactionDao {
public List<Transaction> getUserSentTransaction(String userHash)throws Exception{
transactionDao = createTransactionDaoConnection();
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
queryBuilder.where().eq("transactionFrom",userHash);
queryBuilder.orderBy("transactionDate",false);
queryBuilder.where().eq("transaction_from",userHash);
queryBuilder.orderBy("transaction_date",false);
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
return transactionDao.query(preparedQuery);
}
@ -65,8 +65,8 @@ public class TransactionDao {
public List<Transaction> getUserReceivedTransaction(String userHash)throws Exception{
transactionDao = createTransactionDaoConnection();
QueryBuilder<Transaction, String> queryBuilder = transactionDao.queryBuilder();
queryBuilder.where().eq("transactionTo",userHash);
queryBuilder.orderBy("transactionDate",false);
queryBuilder.where().eq("transaction_to",userHash);
queryBuilder.orderBy("transaction_date",false);
PreparedQuery<Transaction> preparedQuery = queryBuilder.prepare();
return transactionDao.query(preparedQuery);
}

View file

@ -40,12 +40,12 @@ public class TransactionImplementation {
Transaction transaction = new Transaction();
long now = Instant.now().toEpochMilli();
transaction.setTransactionDate(now);
transaction.setTransactionFrom(sourceWalletHash);
transaction.setTransactionTo(destinationWalletHash);
transaction.setTransactionAmount(amount);
transaction.setTransactionHash(txID);
transaction.setTransactionUnit(transactionUnit);
transaction.setTransaction_date(now);
transaction.setTransaction_from(sourceWalletHash);
transaction.setTransaction_to(destinationWalletHash);
transaction.setTransaction_amount(amount);
transaction.setTransaction_hash(txID);
transaction.setTransaction_unit(transactionUnit);
TransactionDao transactionDao = new TransactionDao();

View file

@ -82,6 +82,8 @@ public class WalletImplementation {
public void setBalanceToWallet(String walletHash, double amount) throws Exception {
double newBalance = 0.0;
TransactionWrapper transactionWrapper = new TransactionWrapper();
System.out.println("String.valueOf(amount) : "+String.valueOf(amount));
System.out.println("walletHash : "+walletHash);
transactionWrapper.sendTransaction("setSoldOnWallet",new String[]{walletHash,String.valueOf(amount)});

View file

@ -19,7 +19,7 @@ public class TransactionResource {
public ResponseEntity saveTransaction(@Valid @RequestBody Transaction transaction){
TransactionImplementation transactionImplementation = new TransactionImplementation();
try{
HashMap mapResponse = transactionImplementation.sendTransaction(transaction.getTransactionFrom(),transaction.getTransactionTo(),transaction.getTransactionAmount(),transaction.getTransactionUnit());
HashMap mapResponse = transactionImplementation.sendTransaction(transaction.getTransaction_from(),transaction.getTransaction_to(),transaction.getTransaction_amount(),transaction.getTransaction_unit());
if(Boolean.parseBoolean(mapResponse.get("success").toString())){
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\""+mapResponse.get("message")+"\"}");

View file

@ -71,6 +71,7 @@ public class WalletResource {
}
@RequestMapping(value = "/setBalance", method = RequestMethod.POST,produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity setBalance(@RequestBody Wallet wallet){
@ -85,6 +86,7 @@ public class WalletResource {
}
@RequestMapping(value = "/transfer", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity transferWallet(@RequestBody Wallet wallet){

View file

@ -24,7 +24,8 @@ public class QueryWalletByOwnerTest {
try{
QueryWrapper queryWrapper = new QueryWrapper();
String functionName = "queryWalletsByOwner";
String[] args = new String[]{"$2a$10$tdkMwJ7BQSOXO2uofu/fEOlncUfuX7SsjB.2N9KVsXJUQiarAQzpG"};
//String[] args = new String[]{"$2a$10$tdkMwJ7BQSOXO2uofu/fEOlncUfuX7SsjB.2N9KVsXJUQiarAQzpG"};
String[] args = new String[]{"chef"};
String response = queryWrapper.sendQuery(functionName,args);
logger.info("response : "+response);

View file

@ -24,7 +24,7 @@ public class ReadWalletTest {
try{
QueryWrapper queryWrapper = new QueryWrapper();
String functionName = "readWallet";
String[] args = new String[]{"$2a$10$PuJBO70uMfzUwbQ/Qz9kTe7JYJppwetyLyP0e6JAITr3B6pQf0cbe"};
String[] args = new String[]{"$2a$10$B2bESpzYaYlGtuf69Y8HIu1.libPO5NGKRnatvd2R7K/vciTAj/DS"};
String response = queryWrapper.sendQuery(functionName,args);
if(response!=null){

View file

@ -115,12 +115,35 @@ public class WalletImplementationTest {
@Test
public void TestSetBalance(){ //TODO
BasicConfigurator.configure();
WalletImplementation walletImplementation = new WalletImplementation();
try{
walletImplementation.setBalanceToWallet("$2a$10$PuJBO70uMfzUwbQ/Qz9kTe7JYJppwetyLyP0e6JAITr3B6pQf0cbe",20.0);
walletImplementation.setBalanceToWallet("$2a$10$B2bESpzYaYlGtuf69Y8HIu1.libPO5NGKRnatvd2R7K/vciTAj/DS",20.0);
} catch (Exception e){
logger.warn("Error: "+e.getMessage());
}
}
@Test
public void TestTransferWalelt(){ //TODO
BasicConfigurator.configure();
WalletImplementation walletImplementation = new WalletImplementation();
try{
walletImplementation.transferWallet("$2a$10$PuJBO70uMfzUwbQ/Qz9kTe7JYJppwetyLyP0e6JAITr3B6pQf0cbe","$2a$10$tdkMwJ7BQSOXO2uofu/fEOlncUfuX7SsjB.2N9KVsXJUQiarAQzpG");
} catch (Exception e){
logger.warn("Error: "+e.getMessage());
}
}
@Test
public void TestGetUserWallet(){ //TODO
BasicConfigurator.configure();
WalletImplementation walletImplementation = new WalletImplementation();
try{
walletImplementation.getAllUserWallets("$2a$10$tdkMwJ7BQSOXO2uofu/fEOlncUfuX7SsjB.2N9KVsXJUQiarAQzpG");
} catch (Exception e){
logger.warn("Error: "+e.getMessage());
}
@ -129,4 +152,5 @@ public class WalletImplementationTest {
}