コード例 #1
1
  @Test
  public void createTransactionFromTransparentRedirectSpecifyingLevel2Attributes() {
    TransactionRequest request =
        new TransactionRequest()
            .amount(TransactionAmount.AUTHORIZE.amount)
            .creditCard()
            .number(CreditCardNumber.VISA.number)
            .expirationDate("05/2009")
            .done();

    TransactionRequest trParams =
        new TransactionRequest()
            .type(Transaction.Type.SALE)
            .taxAmount(new BigDecimal("10.00"))
            .taxExempt(true)
            .purchaseOrderNumber("12345");

    String queryString =
        TestHelper.simulateFormPostForTR(
            gateway, trParams, request, gateway.transparentRedirect().url());
    Result<Transaction> result = gateway.transparentRedirect().confirmTransaction(queryString);

    assertTrue(result.isSuccess());
    Transaction transaction = result.getTarget();
    assertEquals(new BigDecimal("10.00"), transaction.getTaxAmount());
    assertTrue(transaction.isTaxExempt());
    assertEquals("12345", transaction.getPurchaseOrderNumber());
  }
コード例 #2
0
  @Test
  public void createTransactionFromTransparentRedirectSpecifyingDescriptor() {
    TransactionRequest request =
        new TransactionRequest()
            .amount(TransactionAmount.AUTHORIZE.amount)
            .creditCard()
            .number(CreditCardNumber.VISA.number)
            .expirationDate("05/2009")
            .done();

    TransactionRequest trParams =
        new TransactionRequest()
            .type(Transaction.Type.SALE)
            .descriptor()
            .name("123*123456789012345678")
            .phone("3334445555")
            .done();

    String queryString =
        TestHelper.simulateFormPostForTR(
            gateway, trParams, request, gateway.transparentRedirect().url());
    Result<Transaction> result = gateway.transparentRedirect().confirmTransaction(queryString);

    assertTrue(result.isSuccess());
    Transaction transaction = result.getTarget();
    assertEquals("123*123456789012345678", transaction.getDescriptor().getName());
    assertEquals("3334445555", transaction.getDescriptor().getPhone());
  }
コード例 #3
0
  @Test
  public void testCreateRelationship() {
    Node n1 = restAPI.createNode(map("name", "newnode1"));
    final Transaction tx = restAPI.beginTx();

    Node n2 = restAPI.createNode(map("name", "newnode2"));
    RestRelationship rel = restAPI.createRelationship(n1, n2, Type.TEST, map("name", "rel"));
    Iterable<Relationship> allRelationships = n1.getRelationships();

    tx.success();
    tx.finish();
    Relationship foundRelationship =
        TestHelper.firstRelationshipBetween(
            n1.getRelationships(Type.TEST, Direction.OUTGOING), n1, n2);
    Assert.assertNotNull("found relationship", foundRelationship);
    assertEquals("same relationship", rel, foundRelationship);
    assertEquals("rel", rel.getProperty("name"));

    assertThat(
        n1.getRelationships(Type.TEST, Direction.OUTGOING),
        new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Direction.OUTGOING), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Direction.BOTH), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Type.TEST), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(allRelationships, new IsRelationshipToNodeMatcher(n1, n2));
  }
コード例 #4
0
  @Test
  public void testAddToIndex() {
    final MatrixDataGraph matrixDataGraph = new MatrixDataGraph(getGraphDatabase());
    matrixDataGraph.createNodespace();
    final RestNode neoNode = restAPI.getNodeById(matrixDataGraph.getNeoNode().getId());

    final Transaction tx = restAPI.beginTx();
    restAPI.index().forNodes("heroes").add(neoNode, "indexname", "Neo2");
    Node n1 = restAPI.createNode(map("name", "Apoc"));
    final Index<Node> index = restAPI.index().forNodes("heroes");
    index.add(n1, "indexname", "Apoc");
    final Node indexResult =
        getGraphDatabase().index().forNodes("heroes").get("indexname", "Neo2").getSingle();
    assertNull(indexResult);
    final IndexHits<Node> heroes = index.query("indexname:Apoc");
    tx.success();
    tx.finish();
    assertEquals("1 hero", 1, heroes.size());
    IndexManager realIndex = getGraphDatabase().index();
    Index<Node> goodGuys = realIndex.forNodes("heroes");
    IndexHits<Node> hits = goodGuys.get("indexname", "Apoc");
    Node apoc = hits.getSingle();

    assertEquals("Apoc indexed", apoc, heroes.iterator().next());
  }
コード例 #5
0
ファイル: PeerTest.java プロジェクト: Bushstar/bitcoinj
  @Test
  public void getLargeBlock() throws Exception {
    connect();

    Block b1 = createFakeBlock(blockStore).block;
    blockChain.add(b1);
    Block b2 = makeSolvedTestBlock(b1);
    Transaction t = new Transaction(unitTestParams);
    t.addInput(b1.getTransactions().get(0).getOutput(0));
    t.addOutput(
        new TransactionOutput(
            unitTestParams, t, BigInteger.ZERO, new byte[Block.MAX_BLOCK_SIZE - 1000]));
    b2.addTransaction(t);

    // Request the block.
    Future<Block> resultFuture = peer.getBlock(b2.getHash());
    assertFalse(resultFuture.isDone());
    // Peer asks for it.
    GetDataMessage message = (GetDataMessage) outbound(writeTarget);
    assertEquals(message.getItems().get(0).hash, b2.getHash());
    assertFalse(resultFuture.isDone());
    // Peer receives it.
    inbound(writeTarget, b2);
    Block b = resultFuture.get();
    assertEquals(b, b2);
  }
コード例 #6
0
ファイル: PeerTest.java プロジェクト: Bushstar/bitcoinj
  @Test
  public void invDownloadTxMultiPeer() throws Exception {
    // Check co-ordination of which peer to download via the memory pool.
    VersionMessage ver = new VersionMessage(unitTestParams, 100);
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4242);
    Peer peer2 = new Peer(unitTestParams, ver, new PeerAddress(address), blockChain, memoryPool);
    peer2.addWallet(wallet);
    VersionMessage peerVersion = new VersionMessage(unitTestParams, OTHER_PEER_CHAIN_HEIGHT);
    peerVersion.clientVersion = 70001;
    peerVersion.localServices = VersionMessage.NODE_NETWORK;

    connect();
    InboundMessageQueuer writeTarget2 = connect(peer2, peerVersion);

    // Make a tx and advertise it to one of the peers.
    BigInteger value = Utils.toNanoCoins(1, 0);
    Transaction tx = createFakeTx(unitTestParams, value, this.address);
    InventoryMessage inv = new InventoryMessage(unitTestParams);
    InventoryItem item = new InventoryItem(InventoryItem.Type.Transaction, tx.getHash());
    inv.addItem(item);

    inbound(writeTarget, inv);

    // We got a getdata message.
    GetDataMessage message = (GetDataMessage) outbound(writeTarget);
    assertEquals(1, message.getItems().size());
    assertEquals(tx.getHash(), message.getItems().get(0).hash);
    assertTrue(memoryPool.maybeWasSeen(tx.getHash()));

    // Advertising to peer2 results in no getdata message.
    inbound(writeTarget2, inv);
    pingAndWait(writeTarget2);
    assertNull(outbound(writeTarget2));
  }
コード例 #7
0
ファイル: LabelScanStoreIT.java プロジェクト: Analect/neo4j
 private Node createLabeledNode(Label... labels) {
   try (Transaction tx = dbRule.getGraphDatabaseService().beginTx()) {
     Node node = dbRule.getGraphDatabaseService().createNode(labels);
     tx.success();
     return node;
   }
 }
コード例 #8
0
  @Test
  public void canVaultOnTransactionCreate() {
    TransactionRequest request =
        new TransactionRequest()
            .amount(TransactionAmount.AUTHORIZE.amount)
            .paymentMethodNonce(Nonce.Coinbase)
            .options()
            .submitForSettlement(true)
            .storeInVaultOnSuccess(true)
            .done();

    Result<Transaction> authResult = gateway.transaction().sale(request);
    assertTrue(authResult.isSuccess());

    Transaction transaction = authResult.getTarget();
    assertNotNull(transaction);
    CoinbaseDetails details = transaction.getCoinbaseDetails();
    assertNotNull(details);
    String token = details.getToken();
    assertNotNull(token);

    PaymentMethod account = gateway.paymentMethod().find(token);
    assertTrue(account instanceof CoinbaseAccount);
    assertNotNull(account);
  }
コード例 #9
0
 @Test
 public void shouldRollbackViaStatus() throws Exception {
   new TransactionTemplate(neo4jTransactionManager)
       .execute(
           new TransactionCallbackWithoutResult() {
             @Override
             protected void doInTransactionWithoutResult(final TransactionStatus status) {
               neo4jTemplate.exec(
                   new GraphCallback.WithoutResult() {
                     @Override
                     public void doWithGraphWithoutResult(GraphDatabase graph) throws Exception {
                       graph
                           .getReferenceNode()
                           .setProperty("test", "shouldRollbackTransactionOnException");
                       status.setRollbackOnly();
                     }
                   });
             }
           });
   Transaction tx = graphDatabase.beginTx();
   try {
     Assert.assertThat(
         (String) graphDatabase.getReferenceNode().getProperty("test", "not set"),
         not("shouldRollbackTransactionOnException"));
   } finally {
     tx.success();
     tx.finish();
   }
 }
コード例 #10
0
 @Test
 public void listing3_4_create_realationships_between_users() {
   usersAndMovies.createSimpleRelationshipsBetweenUsers();
   try (Transaction tx = graphDb.beginTx()) {
     assertTrue(usersAndMovies.user1.hasRelationship(MyRelationshipTypes.IS_FRIEND_OF));
     tx.success();
   }
 }
コード例 #11
0
 @Test
 public void testEnableBatchTransactions() throws Exception {
   System.setProperty(Config.CONFIG_BATCH_TRANSACTION, "true");
   Transaction tx = restAPI.beginTx();
   tx.failure();
   tx.finish();
   assertTrue(tx instanceof BatchTransaction);
 }
コード例 #12
0
  @AfterClass
  public static void tearDownAfterClass() throws Exception {
    final Transaction transaction = session.getTransaction();

    if (transaction.isActive()) transaction.commit();

    if (session != null) session.close();
  }
コード例 #13
0
 @Test
 public void listing3_2_create_single_user() {
   usersAndMovies.createSingleUser();
   try (Transaction tx = graphDb.beginTx()) {
     assertNotNull(graphDb.getNodeById(0));
     tx.success();
   }
 }
コード例 #14
0
ファイル: LabelScanStoreIT.java プロジェクト: Analect/neo4j
 private void addLabels(Node node, Label... labels) {
   try (Transaction tx = dbRule.getGraphDatabaseService().beginTx()) {
     for (Label label : labels) {
       node.addLabel(label);
     }
     tx.success();
   }
 }
コード例 #15
0
 @Test
 public void listing3_3_create_multiple_users() {
   usersAndMovies.createMultipleUsersInSingleTransaction();
   try (Transaction tx = graphDb.beginTx()) {
     assertNotNull(graphDb.getNodeById(1));
     assertNotNull(graphDb.getNodeById(2));
     tx.success();
   }
 }
コード例 #16
0
 @Test
 public void listing3_5_add_properties_to_user_nodes() {
   usersAndMovies.addPropertiesToUserNodes();
   try (Transaction tx = graphDb.beginTx()) {
     assertTrue(usersAndMovies.user1.hasProperty("name"));
     assertEquals("John Johnson", usersAndMovies.user1.getProperty("name"));
     tx.success();
   }
 }
コード例 #17
0
  public static boolean includesStatus(ResourceCollection<Transaction> collection, Status status) {
    for (Transaction transaction : collection) {
      if (transaction.getStatus().equals(status)) {
        return true;
      }
    }

    return false;
  }
コード例 #18
0
 @Test
 public void listing3_7_create_movies() {
   try (Transaction tx = graphDb.beginTx()) {
     assertNotNull(graphDb.getNodeById(3));
     assertNotNull(graphDb.getNodeById(4));
     assertNotNull(graphDb.getNodeById(5));
     tx.success();
   }
 }
コード例 #19
0
 @Test
 public void listing3_6_add_more_properties_to_user_nodes() {
   usersAndMovies.addMorePropertiesToUsers();
   try (Transaction tx = graphDb.beginTx()) {
     assertTrue(usersAndMovies.user1.hasProperty("year_of_birth"));
     assertEquals(1982, usersAndMovies.user1.getProperty("year_of_birth"));
     tx.success();
   }
 }
コード例 #20
0
 @Test
 public void listing3_8_add_type_properties_to_all_nodes() {
   usersAndMovies.addTypePropertiesToNodes();
   try (Transaction tx = graphDb.beginTx()) {
     assertEquals("User", usersAndMovies.user1.getProperty("type"));
     assertEquals("Movie", usersAndMovies.movie1.getProperty("type"));
     tx.success();
   }
 }
コード例 #21
0
 @Test
 public void listing3_10_node_labels() {
   usersAndMovies.addLabelToMovies();
   try (Transaction tx = graphDb.beginTx()) {
     ResourceIterable<Node> movies =
         GlobalGraphOperations.at(graphDb).getAllNodesWithLabel(DynamicLabel.label("MOVIES"));
     assertEquals(3, IteratorUtil.count(movies));
     tx.success();
   }
 }
コード例 #22
0
 @Test(expected = org.neo4j.graphdb.NotFoundException.class)
 public void testDeleteNode() {
   final Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "node1"));
   n1.delete();
   Node n2 = restAPI.createNode(map("name", "node2"));
   tx.success();
   tx.finish();
   loadRealNode(n1);
 }
コード例 #23
0
ファイル: Btransferpair.java プロジェクト: MOhannadAbdo15/Q-A
  // Test the change plan when trying to change a student plan
  @Test
  public void transferpairtest() {
    Backend b = new Backend();
    String[] args = new String[1];
    args[0] = "MasterBankAccounts.txt";

    tlist.clear();

    Transaction t = new Transaction();
    t.setCode("10");
    t.setMisc("A");
    t.setName("");

    Transaction t2 = new Transaction();
    t2.setCode("02");
    t2.setNum("00005");

    Transaction t3 = new Transaction();
    t3.setCode("00");

    tlist.add(t);
    tlist.add(t2);
    tlist.add(t3);

    b.load(args);
    b.setTransactions(tlist);
    b.handletransactions();
    assertEquals("Transfer transactions must come in pairs\n", outContent.toString());
  }
コード例 #24
0
 @Test
 public void raiseFeeTx() throws Exception {
   // Check basic tx serialization.
   Coin v1 = COIN;
   Transaction t1 = createFakeTx(params, v1, myAddress);
   t1.setPurpose(Purpose.RAISE_FEE);
   myWallet.receivePending(t1, null);
   Wallet wallet1 = roundTrip(myWallet);
   Transaction t1copy = wallet1.getTransaction(t1.getHash());
   assertEquals(Purpose.RAISE_FEE, t1copy.getPurpose());
 }
コード例 #25
0
 @Test
 public void listing3_9_add_properties_to_relationships() {
   usersAndMovies.addPropertiesToRelationships();
   try (Transaction tx = graphDb.beginTx()) {
     Relationship hasSeen =
         usersAndMovies.user1.getSingleRelationship(
             MyRelationshipTypes.HAS_SEEN, Direction.OUTGOING);
     assertEquals(5, hasSeen.getProperty("stars"));
     tx.success();
   }
 }
コード例 #26
0
 @Test(expected = UnsupportedOperationException.class)
 public void testRemoveEntryFromIndexWithGivenNodeAndKeyAndValue() {
   final Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "node1"));
   final Index<Node> index = restAPI.index().forNodes("testIndex");
   index.add(n1, "indexname", "Node1");
   index.remove(n1, "indexname", "Node1");
   tx.success();
   tx.finish();
   assertNull(index.get("indexname", "Node1").getSingle());
 }
コード例 #27
0
 @Test
 public void testRemoveEntryFromIndexWithGivenNode() {
   Node n1 = restAPI.createNode(map("name", "node1"));
   final Index<Node> index = restAPI.index().forNodes("testIndex");
   index.add(n1, "indexname", "Node1");
   final Transaction tx = restAPI.beginTx();
   index.remove(n1);
   tx.success();
   tx.finish();
   assertNull(index.get("indexname", "Node1").getSingle());
 }
コード例 #28
0
 @Test
 public void testDeleteIndex() {
   final MatrixDataGraph matrixDataGraph = new MatrixDataGraph(getGraphDatabase());
   matrixDataGraph.createNodespace();
   final Transaction tx = restAPI.beginTx();
   final Index<Node> heroes = restAPI.index().forNodes("heroes");
   heroes.delete();
   tx.success();
   tx.finish();
   Assert.assertFalse(getGraphDatabase().index().existsForNodes("heroes"));
 }
コード例 #29
0
  @Test(expected = RestResultException.class)
  public void testFailingDoubleDelete() throws Exception {
    final Transaction tx = restAPI.beginTx();

    Node n1 = restAPI.createNode(map());
    n1.delete();
    n1.delete();

    tx.success();
    tx.finish();
  }
コード例 #30
0
 @Test
 public void testQueryIndex() {
   final MatrixDataGraph matrixDataGraph = new MatrixDataGraph(getGraphDatabase());
   matrixDataGraph.createNodespace();
   final Transaction tx = restAPI.beginTx();
   final Index<Node> index = restAPI.index().forNodes("heroes");
   final IndexHits<Node> heroes = index.query("name:Neo");
   tx.success();
   tx.finish();
   assertEquals("1 hero", 1, heroes.size());
   assertEquals("Neo indexed", matrixDataGraph.getNeoNode(), heroes.iterator().next());
 }