コード例 #1
0
 private void createAccount(
     String transactionId, String accountId, double initialBalance, boolean independentTest)
     throws Throwable {
   if (independentTest) {
     this.host.testStart(1);
   }
   BankAccountServiceState initialState = new BankAccountServiceState();
   initialState.documentSelfLink = accountId;
   initialState.balance = initialBalance;
   Operation post =
       Operation.createPost(getAccountFactoryUri())
           .setBody(initialState)
           .setCompletion(
               (o, e) -> {
                 if (operationFailed(o, e)) {
                   this.host.failIteration(e);
                   return;
                 }
                 this.host.completeIteration();
               });
   if (transactionId != null) {
     post.setTransactionId(transactionId);
   }
   this.host.send(post);
   if (independentTest) {
     this.host.testWait();
   }
 }
コード例 #2
0
    void handlePatchForDeposit(Operation patch) {
      BankAccountServiceState currentState = getState(patch);
      BankAccountServiceRequest body = patch.getBody(BankAccountServiceRequest.class);

      currentState.balance += body.amount;

      setState(patch, currentState);
      patch.setBody(currentState);
      patch.complete();
    }
コード例 #3
0
    void handlePatchForWithdraw(Operation patch) {
      BankAccountServiceState currentState = getState(patch);
      BankAccountServiceRequest body = patch.getBody(BankAccountServiceRequest.class);

      if (body.amount > currentState.balance) {
        patch.fail(new IllegalArgumentException("Not enough funds to withdraw"));
        return;
      }
      currentState.balance -= body.amount;

      setState(patch, currentState);
      patch.setBody(currentState);
      patch.complete();
    }