large set of functional tests, passing all except the HandshakeAction
This commit is contained in:
@@ -43,13 +43,13 @@ public abstract class NoHandshakeAction extends NoSourcedAction {
|
||||
public void execute(NoAdapter adapter) {
|
||||
this.process();
|
||||
try {
|
||||
NoInfluence influence = this.generateTargetInfluence();
|
||||
NoInfluence influence = generateTargetInfluence();
|
||||
if (influence != null) {
|
||||
NoByteSet byteSet = influence.getByteSet(this.target);
|
||||
adapter.addNoByteSet(byteSet, this.target);
|
||||
}
|
||||
|
||||
NoInfluence result = this.generateReturnedInfluence();
|
||||
NoInfluence result = generateReturnedInfluence();
|
||||
if (result != null) {
|
||||
NoByteSet byteSet = result.getByteSet(this.source);
|
||||
adapter.addNoByteSet(byteSet, this.source);
|
||||
|
||||
@@ -2,6 +2,7 @@ package nodash.test.functional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.util.Arrays;
|
||||
|
||||
import nodash.core.NoAdapter;
|
||||
@@ -17,6 +18,13 @@ import nodash.exceptions.NoUserAlreadyOnlineException;
|
||||
import nodash.exceptions.NoUserNotValidException;
|
||||
import nodash.models.NoRegister;
|
||||
import nodash.models.NoUser;
|
||||
import nodash.test.functional.implementations.TestJustTouchStaticField;
|
||||
import nodash.test.functional.implementations.TestNoUser;
|
||||
import nodash.test.functional.implementations.TestRequestFunds;
|
||||
import nodash.test.functional.implementations.TestRequestRiskyFunds;
|
||||
import nodash.test.functional.implementations.TestSendFunds;
|
||||
import nodash.test.functional.implementations.TestSendFundsReceipted;
|
||||
import nodash.test.functional.implementations.TestSendFundsSourced;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -26,67 +34,291 @@ public class NoRoutineTest {
|
||||
return Arrays.copyOf(data, data.length);
|
||||
}
|
||||
|
||||
private byte[] registerAndConfirm(TestNoUser user, String password)
|
||||
throws NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException {
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
NoRegister registration = core.register(user, password.toCharArray());
|
||||
core.confirm(getCopy(registration.cookie), password.toCharArray(), getCopy(registration.data));
|
||||
return getCopy(registration.data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserChangeOwnData() throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoSessionNotAwaitingConfirmationException,
|
||||
NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException, NoAdapterException {
|
||||
final byte[] userFile = registerAndConfirm(new TestNoUser("username"), "password");
|
||||
|
||||
NoAdapter adapter = new NoDefaultAdapter();
|
||||
NoCore core = new NoCore(adapter);
|
||||
TestNoUser user = new TestNoUser("username");
|
||||
|
||||
NoRegister registration = core.register(user, "password".toCharArray());
|
||||
core.confirm(getCopy(registration.cookie), "password".toCharArray(), getCopy(registration.data));
|
||||
|
||||
byte[] cookie = core.login(getCopy(registration.data), "password".toCharArray());
|
||||
byte[] cookie = core.login(getCopy(userFile), "password".toCharArray());
|
||||
TestNoUser userRegistered = (TestNoUser) core.getNoUser(Arrays.copyOf(cookie, cookie.length));
|
||||
assertEquals(user, userRegistered);
|
||||
assertEquals("username", userRegistered.getUsername());
|
||||
|
||||
userRegistered.setUsername("newsername");
|
||||
byte[] data = core.save(getCopy(cookie), "password2".toCharArray());
|
||||
core.confirm(getCopy(cookie), "password2".toCharArray(), getCopy(data));
|
||||
|
||||
|
||||
try {
|
||||
core.login(getCopy(data), "password-bad".toCharArray());
|
||||
fail("Did not throw exception on login with bad password.");
|
||||
} catch (NoUserNotValidException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
|
||||
|
||||
cookie = core.login(getCopy(data), "password2".toCharArray());
|
||||
TestNoUser userChanged = (TestNoUser) core.getNoUser(getCopy(cookie));
|
||||
|
||||
|
||||
assertEquals("newsername", userChanged.getUsername());
|
||||
assertEquals(0, userChanged.getMoney());
|
||||
assertTrue(adapter.isOnline(userChanged.createHash()));
|
||||
|
||||
|
||||
core.shred(getCopy(cookie));
|
||||
assertFalse(adapter.isOnline(userChanged.createHash()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public static void testUserAction() {
|
||||
fail("Not yet implemented.");
|
||||
public void testUserAction() throws NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException,
|
||||
NoUserAlreadyOnlineException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException { // testing TestJustTouchStaticField
|
||||
byte[] userFile = registerAndConfirm(new TestNoUser("username"), "password");
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
|
||||
int touchCount = TestJustTouchStaticField.touchMe;
|
||||
|
||||
byte[] noSaveCookie = core.login(getCopy(userFile), "password".toCharArray());
|
||||
TestNoUser noSaveUser = (TestNoUser) core.getNoUser(getCopy(noSaveCookie));
|
||||
noSaveUser.addAction(new TestJustTouchStaticField());
|
||||
core.shred(noSaveCookie);
|
||||
// Assert action did not occur at shred.
|
||||
assertTrue(TestJustTouchStaticField.touchMe == touchCount);
|
||||
|
||||
byte[] noConfirmCookie = core.login(getCopy(userFile), "password".toCharArray());
|
||||
TestNoUser noConfirmUser = (TestNoUser) core.getNoUser(getCopy(noConfirmCookie));
|
||||
noConfirmUser.addAction(new TestJustTouchStaticField());
|
||||
core.save(getCopy(noConfirmCookie), "password".toCharArray());
|
||||
// Assert action did not occur at save
|
||||
assertTrue(TestJustTouchStaticField.touchMe == touchCount);
|
||||
core.shred(getCopy(noConfirmCookie));
|
||||
|
||||
byte[] confirmCookie = core.login(getCopy(userFile), "password".toCharArray());
|
||||
TestNoUser confirmUser = (TestNoUser) core.getNoUser(getCopy(confirmCookie));
|
||||
confirmUser.addAction(new TestJustTouchStaticField());
|
||||
byte[] saveConfirmFile = core.save(getCopy(confirmCookie), "password".toCharArray());
|
||||
core.confirm(getCopy(confirmCookie), "password".toCharArray(), getCopy(saveConfirmFile));
|
||||
// Assert action fired after confirm
|
||||
assertTrue(TestJustTouchStaticField.touchMe > touchCount);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public static void testUserSourcedAction() {
|
||||
fail("Not yet implemented.");
|
||||
public void testUserErrorableActionWithoutError() throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoSessionNotAwaitingConfirmationException,
|
||||
NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException { // testing TestRequestFunds
|
||||
byte[] requesterFile = registerAndConfirm(new TestNoUser("requester"), "password");
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
|
||||
byte[] requesterCookie = core.login(getCopy(requesterFile), "password".toCharArray());
|
||||
TestNoUser requester = (TestNoUser) core.getNoUser(getCopy(requesterCookie));
|
||||
requester.addAction(new TestRequestFunds(requester.getRsaPublicKey()));
|
||||
byte[] confirmFile = core.save(getCopy(requesterCookie), "password".toCharArray());
|
||||
core.confirm(getCopy(requesterCookie), "password".toCharArray(), getCopy(confirmFile));
|
||||
|
||||
requesterCookie = core.login(getCopy(confirmFile), "password".toCharArray());
|
||||
requester = (TestNoUser) core.getNoUser(getCopy(requesterCookie));
|
||||
assertTrue(requester.getMoney() == 100);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public static void testUserTargetedAction() {
|
||||
fail("Not yet implemented.");
|
||||
public void testUserErrorableActionWithError() throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoSessionNotAwaitingConfirmationException,
|
||||
NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException { // testing TestRequestFunds
|
||||
byte[] requesterFile = registerAndConfirm(new TestNoUser("requester"), "password");
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
|
||||
byte[] requesterCookie = core.login(getCopy(requesterFile), "password".toCharArray());
|
||||
TestNoUser requester = (TestNoUser) core.getNoUser(getCopy(requesterCookie));
|
||||
requester.addAction(new TestRequestRiskyFunds(requester.getRsaPublicKey()));
|
||||
byte[] confirmFile = core.save(getCopy(requesterCookie), "password".toCharArray());
|
||||
core.confirm(getCopy(requesterCookie), "password".toCharArray(), getCopy(confirmFile));
|
||||
assertTrue(requester.getMoney() == 0);
|
||||
assertTrue(requester.getReceipts().size() == 0);
|
||||
|
||||
requesterCookie = core.login(getCopy(confirmFile), "password".toCharArray());
|
||||
requester = (TestNoUser) core.getNoUser(getCopy(requesterCookie));
|
||||
assertTrue(requester.getMoney() == 0);
|
||||
assertTrue(requester.getReceipts().size() == 1);
|
||||
assertEquals(requester.getReceipts().get(0), "Could not request.");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public static void testUserHandshakeAction() {
|
||||
fail("Not yet implemented.");
|
||||
public void testUserTargetedAction() throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoSessionNotAwaitingConfirmationException,
|
||||
NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException { // testing TestSendFunds
|
||||
byte[] fundSenderFile = registerAndConfirm(new TestNoUser("fund-sender"), "password1");
|
||||
byte[] fundGetterFile = registerAndConfirm(new TestNoUser("fund-getter"), "password2");
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
|
||||
byte[] senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
TestNoUser sender = (TestNoUser) core.getNoUser(senderCookie);
|
||||
sender.setMoney(1000);
|
||||
fundSenderFile = core.save(getCopy(senderCookie), "password1".toCharArray());
|
||||
core.confirm(getCopy(senderCookie), "password1".toCharArray(), getCopy(fundSenderFile));
|
||||
sender = null;
|
||||
|
||||
byte[] getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
TestNoUser getter = (TestNoUser) core.getNoUser(getterCookie);
|
||||
PublicKey getterAddress = getter.getRsaPublicKey();
|
||||
core.shred(getterCookie);
|
||||
getter = null;
|
||||
|
||||
senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
sender = (TestNoUser) core.getNoUser(getCopy(senderCookie));
|
||||
sender.setMoney(500);
|
||||
sender.addAction(new TestSendFunds(getterAddress, 500));
|
||||
fundSenderFile = core.save(getCopy(senderCookie), "password1".toCharArray());
|
||||
core.confirm(getCopy(senderCookie), "password1".toCharArray(), getCopy(fundSenderFile));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
core.shred(getCopy(getterCookie));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
fundGetterFile = core.save(getCopy(getterCookie), "password2".toCharArray());
|
||||
core.confirm(getCopy(getterCookie), "password2".toCharArray(), getCopy(fundGetterFile));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
core.shred(getCopy(getterCookie));
|
||||
|
||||
senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
sender = (TestNoUser) core.getNoUser(getCopy(senderCookie));
|
||||
assertTrue(sender.getMoney() == 500);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public static void testUserErrorableAction() {
|
||||
fail("Not yet implemented.");
|
||||
public void testUserHandshakeAction() throws NoUserNotValidException,
|
||||
NoUserAlreadyOnlineException, NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException { // testing TestSendFundsReceipted
|
||||
byte[] fundSenderFile = registerAndConfirm(new TestNoUser("fund-sender"), "password1");
|
||||
byte[] fundGetterFile = registerAndConfirm(new TestNoUser("fund-getter"), "password2");
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
|
||||
byte[] senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
TestNoUser sender = (TestNoUser) core.getNoUser(senderCookie);
|
||||
sender.setMoney(1000);
|
||||
fundSenderFile = core.save(getCopy(senderCookie), "password1".toCharArray());
|
||||
core.confirm(getCopy(senderCookie), "password1".toCharArray(), getCopy(fundSenderFile));
|
||||
sender = null;
|
||||
|
||||
byte[] getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
TestNoUser getter = (TestNoUser) core.getNoUser(getterCookie);
|
||||
PublicKey getterAddress = getter.getRsaPublicKey();
|
||||
core.shred(getterCookie);
|
||||
getter = null;
|
||||
|
||||
senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
sender = (TestNoUser) core.getNoUser(getCopy(senderCookie));
|
||||
sender.setMoney(500);
|
||||
sender.addAction(new TestSendFundsReceipted(getterAddress, sender.getRsaPublicKey(), 500));
|
||||
fundSenderFile = core.save(getCopy(senderCookie), "password1".toCharArray());
|
||||
core.confirm(getCopy(senderCookie), "password1".toCharArray(), getCopy(fundSenderFile));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
assertTrue(getter.getNoActions().size() == 1);
|
||||
core.shred(getCopy(getterCookie));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
assertTrue(getter.getNoActions().size() == 1);
|
||||
fundGetterFile = core.save(getCopy(getterCookie), "password2".toCharArray());
|
||||
core.confirm(getCopy(getterCookie), "password2".toCharArray(), getCopy(fundGetterFile));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
assertTrue(getter.getNoActions().size() == 0);
|
||||
assertTrue(getter.getReceipts().size() == 0);
|
||||
core.shred(getCopy(getterCookie));
|
||||
|
||||
senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
sender = (TestNoUser) core.getNoUser(getCopy(senderCookie));
|
||||
assertTrue(sender.getMoney() == 500);
|
||||
assertTrue(sender.getReceipts().size() == 2);
|
||||
assertEquals(sender.getReceipts().get(0), "Sent funds to " + getterAddress.toString());
|
||||
assertEquals(sender.getReceipts().get(1), "Money received - fund-getter");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSourcedAction() throws NoSessionExpiredException,
|
||||
NoSessionConfirmedException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException, NoSessionNotAwaitingConfirmationException,
|
||||
NoUserNotValidException, NoUserAlreadyOnlineException { // testing TestSendFundsSourced
|
||||
byte[] fundSenderFile = registerAndConfirm(new TestNoUser("fund-sender"), "password1");
|
||||
byte[] fundGetterFile = registerAndConfirm(new TestNoUser("fund-getter"), "password2");
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
|
||||
byte[] senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
TestNoUser sender = (TestNoUser) core.getNoUser(senderCookie);
|
||||
sender.setMoney(1000);
|
||||
fundSenderFile = core.save(getCopy(senderCookie), "password1".toCharArray());
|
||||
core.confirm(getCopy(senderCookie), "password1".toCharArray(), getCopy(fundSenderFile));
|
||||
sender = null;
|
||||
|
||||
byte[] getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
TestNoUser getter = (TestNoUser) core.getNoUser(getterCookie);
|
||||
PublicKey getterAddress = getter.getRsaPublicKey();
|
||||
core.shred(getterCookie);
|
||||
getter = null;
|
||||
|
||||
senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
sender = (TestNoUser) core.getNoUser(getCopy(senderCookie));
|
||||
sender.setMoney(500);
|
||||
sender.addAction(new TestSendFundsSourced(getterAddress, sender.getRsaPublicKey(), 500));
|
||||
fundSenderFile = core.save(getCopy(senderCookie), "password1".toCharArray());
|
||||
core.confirm(getCopy(senderCookie), "password1".toCharArray(), getCopy(fundSenderFile));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
assertTrue(getter.getReceipts().size() == 1);
|
||||
assertEquals(getter.getReceipts().get(0), "Given money by " + sender.getRsaPublicKey().toString());
|
||||
assertTrue(getter.getNoActions().size() == 0);
|
||||
core.shred(getCopy(getterCookie));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
assertTrue(getter.getReceipts().size() == 1);
|
||||
assertEquals(getter.getReceipts().get(0), "Given money by " + sender.getRsaPublicKey().toString());
|
||||
assertTrue(getter.getNoActions().size() == 0);
|
||||
fundGetterFile = core.save(getCopy(getterCookie), "password2".toCharArray());
|
||||
core.confirm(getCopy(getterCookie), "password2".toCharArray(), getCopy(fundGetterFile));
|
||||
|
||||
getterCookie = core.login(getCopy(fundGetterFile), "password2".toCharArray());
|
||||
getter = (TestNoUser) core.getNoUser(getCopy(getterCookie));
|
||||
assertTrue(getter.getMoney() == 500);
|
||||
assertTrue(getter.getNoActions().size() == 0);
|
||||
assertTrue(getter.getReceipts().size() == 1);
|
||||
core.shred(getCopy(getterCookie));
|
||||
|
||||
senderCookie = core.login(getCopy(fundSenderFile), "password1".toCharArray());
|
||||
sender = (TestNoUser) core.getNoUser(getCopy(senderCookie));
|
||||
assertTrue(sender.getMoney() == 500);
|
||||
assertTrue(sender.getReceipts().size() == 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.NoUser;
|
||||
|
||||
public class TestAddReceipt extends NoInfluence {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String receipt;
|
||||
|
||||
public TestAddReceipt(String receipt) {
|
||||
this.receipt = receipt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(NoUser user) {
|
||||
TestNoUser test = (TestNoUser) user;
|
||||
System.out.println("Applying " + receipt + " to " + test.getUsername());
|
||||
test.addReceipt(receipt);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.NoUser;
|
||||
|
||||
public class TestIncreaseMoney extends NoInfluence {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int increaseBy;
|
||||
|
||||
public TestIncreaseMoney(int increaseBy) {
|
||||
this.increaseBy = increaseBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(NoUser user) {
|
||||
TestNoUser testUser = (TestNoUser) user;
|
||||
testUser.setMoney(testUser.getMoney() + increaseBy);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.NoUser;
|
||||
|
||||
public class TestIncreaseMoneyReceipted extends NoInfluence {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int increaseBy;
|
||||
private PublicKey receiptTarget;
|
||||
|
||||
public TestIncreaseMoneyReceipted(PublicKey receiptTarget, int increaseBy) {
|
||||
this.receiptTarget = receiptTarget;
|
||||
this.increaseBy = increaseBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(NoUser user) {
|
||||
TestNoUser testUser = (TestNoUser) user;
|
||||
testUser.setMoney(testUser.getMoney() + increaseBy);
|
||||
testUser.addAction(new TestSendReceipt(receiptTarget, "Money received - " + testUser.getUsername()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.NoUser;
|
||||
|
||||
public class TestIncreaseMoneySourced extends NoInfluence {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int increaseBy;
|
||||
private PublicKey source;
|
||||
|
||||
public TestIncreaseMoneySourced(PublicKey source, int increaseBy) {
|
||||
this.source = source;
|
||||
this.increaseBy = increaseBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(NoUser user) {
|
||||
TestNoUser testUser = (TestNoUser) user;
|
||||
testUser.setMoney(testUser.getMoney() + increaseBy);
|
||||
testUser.addReceipt("Given money by " + source.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import nodash.core.NoAdapter;
|
||||
import nodash.models.NoAction;
|
||||
|
||||
public class TestJustTouchStaticField extends NoAction {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static int touchMe = 0;
|
||||
|
||||
@Override
|
||||
public void process() {}
|
||||
|
||||
@Override
|
||||
public void execute(NoAdapter adapter) {
|
||||
TestJustTouchStaticField.touchMe++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purge() {}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
package nodash.test.functional;
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nodash.models.NoUser;
|
||||
|
||||
@@ -9,11 +12,13 @@ public class TestNoUser extends NoUser {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String username;
|
||||
private int money;
|
||||
private List<String> receipts;
|
||||
|
||||
public TestNoUser(String username) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.money = 0;
|
||||
this.receipts = new ArrayList<String>();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@@ -32,4 +37,12 @@ public class TestNoUser extends NoUser {
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
public void addReceipt(String receipt) {
|
||||
this.receipts.add(receipt);
|
||||
}
|
||||
|
||||
public List<String> getReceipts() {
|
||||
return receipts;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.exceptions.NoCannotGetInfluenceException;
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.noactiontypes.NoErrorableAction;
|
||||
import nodash.models.noactiontypes.NoSourcedAction;
|
||||
|
||||
public class TestRequestFunds extends NoErrorableAction {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TestRequestFunds(PublicKey source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NoInfluence generateTargetInfluence() throws NoCannotGetInfluenceException {
|
||||
return new TestIncreaseMoney(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.exceptions.NoCannotGetInfluenceException;
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.noactiontypes.NoErrorableAction;
|
||||
|
||||
public class TestRequestRiskyFunds extends NoErrorableAction {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TestRequestRiskyFunds(PublicKey source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NoInfluence generateTargetInfluence() throws NoCannotGetInfluenceException {
|
||||
throw new NoCannotGetInfluenceException(new TestAddReceipt("Could not request."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.noactiontypes.NoTargetedAction;
|
||||
|
||||
public class TestSendFunds extends NoTargetedAction {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int fundsToSend;
|
||||
|
||||
public TestSendFunds(PublicKey target, int fundsToSend) {
|
||||
super(target);
|
||||
this.fundsToSend = fundsToSend;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NoInfluence generateTargetInfluence() {
|
||||
return new TestIncreaseMoney(fundsToSend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.exceptions.NoCannotGetInfluenceException;
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.noactiontypes.NoHandshakeAction;
|
||||
|
||||
public class TestSendFundsReceipted extends NoHandshakeAction {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int fundsToSend;
|
||||
|
||||
public TestSendFundsReceipted(PublicKey target, PublicKey source, int fundsToSend) {
|
||||
super(target, source);
|
||||
this.fundsToSend = fundsToSend;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NoInfluence generateReturnedInfluence() {
|
||||
return new TestAddReceipt("Sent funds to " + target.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NoInfluence generateTargetInfluence() throws NoCannotGetInfluenceException {
|
||||
System.out.println("Added influence to source.");
|
||||
return new TestIncreaseMoneyReceipted(this.source, fundsToSend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.exceptions.NoCannotGetInfluenceException;
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.noactiontypes.NoSourcedAction;
|
||||
|
||||
public class TestSendFundsSourced extends NoSourcedAction {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int fundsToSend;
|
||||
|
||||
public TestSendFundsSourced(PublicKey target, PublicKey source, int fundsToSend) {
|
||||
super(target, source);
|
||||
this.fundsToSend = fundsToSend;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NoInfluence generateTargetInfluence() throws NoCannotGetInfluenceException {
|
||||
return new TestIncreaseMoneySourced(source, fundsToSend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package nodash.test.functional.implementations;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import nodash.exceptions.NoCannotGetInfluenceException;
|
||||
import nodash.models.NoInfluence;
|
||||
import nodash.models.noactiontypes.NoTargetedAction;
|
||||
|
||||
public class TestSendReceipt extends NoTargetedAction {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String receipt;
|
||||
|
||||
public TestSendReceipt(PublicKey target, String receipt) {
|
||||
super(target);
|
||||
this.receipt = receipt;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NoInfluence generateTargetInfluence() throws NoCannotGetInfluenceException {
|
||||
System.out.println("Adding receipt influence: " + receipt);
|
||||
return new TestAddReceipt(receipt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process() {}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user