@Test
 public void testBeanPattern() {
   Address address = new Address("Danmarksgade 2", "9000", "Aalborg", "dk");
   assertEquals("Danmarksgade 2", address.getStreet());
   assertEquals("9000", address.getPostalCode());
   assertEquals("Aalborg", address.getCity());
   assertEquals("dk", address.getCountryCode());
 }
Beispiel #2
0
 @Test
 public void testScriptSig() throws Exception {
   byte[] sigProgBytes = Hex.decode(sigProg);
   Script script = new Script(sigProgBytes);
   // Test we can extract the from address.
   byte[] hash160 = Utils.sha256hash160(script.getPubKey());
   Address a = new Address(params, hash160);
   assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", a.toString());
 }
Beispiel #3
0
 @Test
 public void markAsUsed() throws Exception {
   Address addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   Address addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertEquals(addr1, addr2);
   group.markPubKeyHashAsUsed(addr1.getHash160());
   Address addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertNotEquals(addr2, addr3);
 }
  @Test
  public void testGetOpenTransactionOutputs() throws Exception {
    final int UNDOABLE_BLOCKS_STORED = 10;
    store = createStore(params, UNDOABLE_BLOCKS_STORED);
    chain = new FullPrunedBlockChain(params, store);

    // Check that we aren't accidentally leaving any references
    // to the full StoredUndoableBlock's lying around (ie memory leaks)
    ECKey outKey = new ECKey();
    int height = 1;

    // Build some blocks on genesis block to create a spendable output
    Block rollingBlock =
        params
            .getGenesisBlock()
            .createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
    chain.add(rollingBlock);
    Transaction transaction = rollingBlock.getTransactions().get(0);
    TransactionOutPoint spendableOutput = new TransactionOutPoint(params, 0, transaction.getHash());
    byte[] spendableOutputScriptPubKey = transaction.getOutputs().get(0).getScriptBytes();
    for (int i = 1; i < params.getSpendableCoinbaseDepth(); i++) {
      rollingBlock =
          rollingBlock.createNextBlockWithCoinbase(
              Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
      chain.add(rollingBlock);
    }
    rollingBlock = rollingBlock.createNextBlock(null);

    // Create bitcoin spend of 1 BTC.
    ECKey toKey = new ECKey();
    Coin amount = Coin.valueOf(100000000);
    Address address = new Address(params, toKey.getPubKeyHash());
    Coin totalAmount = Coin.ZERO;

    Transaction t = new Transaction(params);
    t.addOutput(new TransactionOutput(params, t, amount, toKey));
    t.addSignedInput(spendableOutput, new Script(spendableOutputScriptPubKey), outKey);
    rollingBlock.addTransaction(t);
    rollingBlock.solve();
    chain.add(rollingBlock);
    totalAmount = totalAmount.add(amount);

    List<UTXO> outputs = store.getOpenTransactionOutputs(Lists.newArrayList(address));
    assertNotNull(outputs);
    assertEquals("Wrong Number of Outputs", 1, outputs.size());
    UTXO output = outputs.get(0);
    assertEquals("The address is not equal", address.toString(), output.getAddress());
    assertEquals("The amount is not equal", totalAmount, output.getValue());

    outputs = null;
    output = null;
    try {
      store.close();
    } catch (Exception e) {
    }
  }
 private boolean isValuePartOfAddressList(List<Address> list, String formated) {
   if (list != null) {
     for (Address actAttribute : list) {
       if (actAttribute.getFormatted().equals(formated)) {
         return true;
       }
     }
   }
   return false;
 }
Beispiel #6
0
 @Test
 public void currentP2SHAddress() throws Exception {
   group = createMarriedKeyChainGroup();
   Address a1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertTrue(a1.isP2SHAddress());
   Address a2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertEquals(a1, a2);
   Address a3 = group.currentAddress(KeyChain.KeyPurpose.CHANGE);
   assertNotEquals(a2, a3);
 }
Beispiel #7
0
 @Test
 public void testScriptPubKey() throws Exception {
   // Check we can extract the to address
   byte[] pubkeyBytes = Hex.decode(pubkeyProg);
   Script pubkey = new Script(pubkeyBytes);
   assertEquals(
       "DUP HASH160 [33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG",
       pubkey.toString());
   Address toAddr = new Address(params, pubkey.getPubKeyHash());
   assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString());
 }
  @Test
  public void convertsAddressCorrectly() {

    Address address = new Address();
    address.city = "New York";
    address.street = "Broadway";

    DBObject dbObject = new BasicDBObject();

    converter.write(address, dbObject);

    assertThat(dbObject.get("city").toString(), is("New York"));
    assertThat(dbObject.get("street").toString(), is("Broadway"));
  }
Beispiel #9
0
  @Test
  public void findRedeemData() throws Exception {
    group = createMarriedKeyChainGroup();

    // test script hash that we don't have
    assertNull(group.findRedeemDataFromScriptHash(new ECKey().getPubKey()));

    // test our script hash
    Address address = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    RedeemData redeemData = group.findRedeemDataFromScriptHash(address.getHash160());
    assertNotNull(redeemData);
    assertNotNull(redeemData.redeemScript);
    assertEquals(2, redeemData.keys.size());
  }
 private Address getAddress(List<Address> addresses, String formatted) {
   Address returnAddress = null;
   if (addresses != null) {
     for (Address actAddress : addresses) {
       if (actAddress.getFormatted().equals(formatted)) {
         returnAddress = actAddress;
         break;
       }
     }
   }
   if (returnAddress == null) {
     fail("The address with the formatted part of " + formatted + " could not be found");
   }
   return returnAddress;
 }
Beispiel #11
0
  @Test
  public void freshAddress() throws Exception {
    group = createMarriedKeyChainGroup();
    Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertTrue(a1.isP2SHAddress());
    assertNotEquals(a1, a2);
    group.getBloomFilterElementCount();
    assertEquals(
        ((group.getLookaheadSize() + group.getLookaheadThreshold())
                * 2) // * 2 because of internal/external
            + (2 - group.getLookaheadThreshold()) // keys issued
            + 4 /* master, account, int, ext */,
        group.numKeys());

    Address a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertEquals(a2, a3);
  }
Beispiel #12
0
 @Test
 public void findRedeemScriptFromPubHash() throws Exception {
   group = createMarriedKeyChainGroup();
   Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertTrue(group.findRedeemDataFromScriptHash(address.getHash160()) != null);
   group.getBloomFilterElementCount();
   KeyChainGroup group2 = createMarriedKeyChainGroup();
   group2.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   group2.getBloomFilterElementCount(); // Force lookahead.
   // test address from lookahead zone and lookahead threshold zone
   for (int i = 0; i < group.getLookaheadSize() + group.getLookaheadThreshold(); i++) {
     address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
     assertTrue(group2.findRedeemDataFromScriptHash(address.getHash160()) != null);
   }
   assertFalse(
       group2.findRedeemDataFromScriptHash(
               group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160())
           != null);
 }
Beispiel #13
0
  @Test
  public void bloomFilterForMarriedChains() throws Exception {
    group = createMarriedKeyChainGroup();
    int bufferSize = group.getLookaheadSize() + group.getLookaheadThreshold();
    int expected = bufferSize * 2 /* chains */ * 2 /* elements */;
    assertEquals(expected, group.getBloomFilterElementCount());
    Address address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertEquals(expected, group.getBloomFilterElementCount());
    BloomFilter filter =
        group.getBloomFilter(expected + 2, 0.001, (long) (Math.random() * Long.MAX_VALUE));
    assertTrue(filter.contains(address1.getHash160()));

    Address address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE);
    assertTrue(filter.contains(address2.getHash160()));

    // Check that the filter contains the lookahead buffer.
    for (int i = 0; i < bufferSize - 1 /* issued address */; i++) {
      Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
      assertTrue("key " + i, filter.contains(address.getHash160()));
    }
    // We ran ahead of the lookahead buffer.
    assertFalse(
        filter.contains(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160()));
  }
  @Test
  public void testExampleJson() throws Exception {
    String json =
        FileUtil.readFileFromClasspath("json-examples/invoicing-rule-updated-example.json");
    JsonMessage jsonMessage = new JsonMessage(json);
    ServiceResult serviceResult = new ServiceResult();
    serviceResult.setRawData(jsonMessage);

    ServiceResult result = (ServiceResult) transformer.doTransform(serviceResult, "UTF-8");
    InvoicingRuleUpdated invoicingRuleCreated =
        (InvoicingRuleUpdated) result.getIntegrationMessage().getDomainObject();

    MetaData metaData = invoicingRuleCreated.getMetaData();

    InvoicingRule invoicingRule = invoicingRuleCreated.getInvoicingRule();

    List<InvoiceRecipient> invoiceRecipients = invoicingRule.getInvoiceRecipients();
    collector.checkThat(invoiceRecipients.size(), is(3));

    InvoiceRecipient invoiceRecipient = invoiceRecipients.get(0);

    Address registeredAddressInvoiceRecipient = invoiceRecipient.getRegisteredAddress();

    List<SplittingRule> splittingRules = invoiceRecipients.get(2).getSplittingRules();
    collector.checkThat(splittingRules.size(), is(3));
    SplittingRule splittingRule = splittingRules.get(0);

    List<PurchaseOrder> purchaseOrders = invoicingRule.getPurchaseOrders();
    collector.checkThat(purchaseOrders.size(), is(3));
    PurchaseOrder purchaseOrder = purchaseOrders.get(0);

    List<InvoicingRuleMessageRule> invoiceMessageRules = invoicingRule.getInvoiceMessageRules();
    collector.checkThat(invoiceMessageRules.size(), is(1));
    InvoicingRuleMessageRule invoiceMessageRule = invoiceMessageRules.get(0);

    collector.checkThat(metaData.getMessageType(), is("UpdateInvoicingRule"));
    collector.checkThat(
        metaData.getMessageId().getGuid(), is("28b62635-15a0-b15e-c5f4-5442b66d1059"));
    collector.checkThat(
        metaData.getCreationTime().getTimestamp(), is("2012-07-05T13:21:00.000+02:00"));
    collector.checkThat(metaData.getVersion(), is("1.0"));
    collector.checkThat(metaData.getSourceSystem(), is("CRM"));

    collector.checkThat(invoicingRule.getClientId(), is("TELIA"));
    collector.checkThat(invoicingRule.getMarketId().getOrganizationId(), is(51));
    collector.checkThat(
        invoicingRule.getInvoicingRuleId().getGuid(), is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(invoicingRule.getInvoicingRuleName(), is("Volvo - do not edit"));
    collector.checkThat(invoicingRule.getDescription(), is("Used in unit tests - do not edit"));
    collector.checkThat(invoicingRule.getIssuerReference(), is("Maria Lind"));
    collector.checkThat(invoicingRule.getClientReference(), is("Lasse Volvosson"));
    collector.checkThat(invoicingRule.getCurrencyCode().getCurrencyCode(), is("EUR"));
    collector.checkThat(invoicingRule.getDistributionMode().getValue(), is(1));
    collector.checkThat(invoicingRule.getTermsOfPayment().getDays(), is(30));
    collector.checkThat(invoicingRule.getPostingProfile().getValue(), is(1));
    collector.checkThat(invoicingRule.isDisplayTradeDoublerCommission(), is(true));
    collector.checkThat(invoicingRule.getRevenueType().getValue(), is(1));
    collector.checkThat(invoicingRule.getPaymentMethod().getValue(), is(2));
    collector.checkThat(invoicingRule.isDeviatingExchangeRate(), is(false));

    collector.checkThat(
        invoiceRecipient.getInvoiceRecipientId().getGuid(),
        is("703b123f-6329-4d79-bfaa-60762a5f6cf4"));
    collector.checkThat(
        invoiceRecipient.getInvoicingRuleId().getGuid(),
        is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(invoiceRecipient.getAttentionRow1(), is("Attention of default recipient!"));
    collector.checkThat(invoiceRecipient.getAttentionRow2(), nullValue());
    collector.checkThat(invoiceRecipient.getEmailAddress(), nullValue());
    collector.checkThat(invoiceRecipient.isDefaultRecipient(), is(true));

    collector.checkThat(registeredAddressInvoiceRecipient.getLine1(), is("AVD. 50090 HB3S"));
    collector.checkThat(registeredAddressInvoiceRecipient.getLine2(), nullValue());
    collector.checkThat(registeredAddressInvoiceRecipient.getCity(), is("Göteborg"));
    collector.checkThat(registeredAddressInvoiceRecipient.getCounty(), nullValue());
    collector.checkThat(registeredAddressInvoiceRecipient.getPostalCode(), is("40531"));
    collector.checkThat(registeredAddressInvoiceRecipient.getCountryCode().getValue(), is("SE"));
    collector.checkThat(registeredAddressInvoiceRecipient.getAddressType().getValue(), is(1));

    collector.checkThat(
        splittingRule.getSplittingRuleId().getGuid(), is("8f756919-c9ed-e111-8b5b-005056b45da6"));
    collector.checkThat(
        splittingRule.getInvoiceRecipientId().getGuid(),
        is("3ac9520d-c9ed-e111-8b5b-005056b45da6"));
    collector.checkThat(splittingRule.getSplitter(), is("kjhh567855"));

    collector.checkThat(
        purchaseOrder.getInvoicingRuleId().getGuid(), is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(purchaseOrder.getPoNumber(), is("234 - do not edit"));
    collector.checkThat(
        purchaseOrder.getPurchaseOrderId().getGuid(), is("00000000-0000-0000-4000-100000000001"));
    collector.checkThat(
        purchaseOrder.getValidFrom().getTimestamp(), is("2012-08-15T00:00:00.000+02:00"));
    collector.checkThat(
        purchaseOrder.getValidTo().getTimestamp(), is("2012-08-17T00:00:00.000+02:00"));

    collector.checkThat(
        invoiceMessageRule.getInvoiceMessageRuleId().getGuid(),
        is("00000000-0000-0000-3000-100000000001"));
    collector.checkThat(
        invoiceMessageRule.getInvoicingRuleId().getGuid(),
        is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(
        invoiceMessageRule.getMessageText(),
        is("This is a text to be printed on all invoices for this invoicing rule"));
    collector.checkThat(
        invoiceMessageRule.getValidFrom().getTimestamp(), is("2012-08-13T00:00:00.000+02:00"));
    collector.checkThat(
        invoiceMessageRule.getValidTo().getTimestamp(), is("2012-08-30T00:00:00.000+02:00"));
  }
  @Test
  public void testBuildMessageFromMpiPatient_MultiAddress() {
    System.out.println("testBuildMessageFromMpiPatient_MultiAddress");
    II subjectId = new II();
    subjectId.setRoot("2.16.840.1.113883.3.200");
    subjectId.setExtension("1234");

    String firstExpectedName = "Joe";
    String lastExpectedName = "Smith";
    String middleExpectedName = "Middle";
    String expectedTitle = "Title";
    String expectedSuffix = "Suffix";

    PRPAIN201305UV02 query =
        TestHelper.build201305(
            firstExpectedName, lastExpectedName, "M", "March 1, 1956", subjectId);

    Identifier patId = new Identifier();
    patId.setId("1234");
    patId.setOrganizationId("2.16.840.1.113883.3.200");
    Patient patient =
        TestHelper.createMpiPatient(
            firstExpectedName, lastExpectedName, middleExpectedName, "M", "March 1, 1956", patId);

    patient.getName().setSuffix(expectedSuffix);
    patient.getName().setTitle(expectedTitle);

    Address add = new Address();
    add.setCity("Chantilly");
    add.setState("VA");
    add.setStreet1("5155 Parkstone Drive");
    add.setStreet2("Att:Developer");
    add.setZip("20151");

    Address add2 = new Address();
    add2.setCity("Melbourne");
    add2.setState("FL");
    add2.setStreet1("1025 West NASA Boulevard");
    add2.setStreet2("Att:Developer");
    add2.setZip("32919-0001");

    patient.getAddresses().add(add);
    patient.getAddresses().add(add2);
    PRPAIN201306UV02 result = HL7Parser201306.BuildMessageFromMpiPatient(patient, query);
    // TODO review the generated test code and remove the default call to fail.

    PRPAMT201310UV02Person person =
        result
            .getControlActProcess()
            .getSubject()
            .get(0)
            .getRegistrationEvent()
            .getSubject1()
            .getPatient()
            .getPatientPerson()
            .getValue();

    assertEquals(2, person.getAddr().size());
    assertEquals(5, person.getAddr().get(0).getContent().size());
    assertEquals(5, person.getAddr().get(1).getContent().size());
    // assertEquals("5155 Parkstone Drive", person.getAddr().get(0).getUse().get(0));
    // assertEquals("1025 West NASA Boulevard", person.getAddr().get(1).getUse().get(0));

  }
  @Test
  public void testAdd() {
    HibernateDatabaseUserManager userManager = HibernateDatabaseUserManager.getDefault();
    HibernateDatabaseAddressManager addrManager = HibernateDatabaseAddressManager.getDefault();
    HibernateDatabaseArenaManager arenaManager = HibernateDatabaseArenaManager.getDefault();
    HibernateDatabaseGameManager gameManager = HibernateDatabaseGameManager.getDefault();

    addrManager.setupTable();
    arenaManager.setupTable();
    gameManager.setupTable();
    userManager.setupTable();

    Address addr1 = new Address();
    addr1.setStreetAddress("2185 Arch St.");
    addr1.setCity("Ottawa");
    addr1.setPostalOrZipCode("K1G 2H5");
    addr1.setProvinceOrState("Ontario");
    addr1.setCountry("Canada");

    Arena arena1 = new Arena();
    arena1.setArenaName("Cantebury");
    arena1.setAddress(addr1);
    addr1.setArena(arena1);

    Game game1 = new Game();
    game1.setGameDay("Tuesday");
    game1.setGameTime("7:30 PM");

    arena1.addGame(game1);

    Address addr = new Address();
    addr.setStreetAddress("1264 Walkley Rd. ");
    addr.setCity("Ottawa");
    addr.setPostalOrZipCode("K1V 6P9");
    addr.setProvinceOrState("Ontario");
    addr.setCountry("Canada");

    Arena arena = new Arena();
    arena.setArenaName("Jim Durell");

    Game game = new Game();
    game.setGameDay("Monday");
    game.setGameTime("9:30 PM");

    Game game2 = new Game();
    game2.setGameDay("Wednesday");
    game2.setGameTime("10:30 PM");

    Address addr3 = new Address();
    addr3.setStreetAddress("210 Hopewell Ave.");
    addr3.setCity("Ottawa");
    addr3.setPostalOrZipCode("K1S 2Z5");
    addr3.setProvinceOrState("Ontario");
    addr3.setCountry("Canada");

    Arena arena3 = new Arena();
    arena3.setArenaName("Brewer");
    arena3.setAddress(addr3);
    addr3.setArena(arena3);

    Game game3 = new Game();
    game3.setGameDay("Friday");
    game3.setGameTime("10:30 PM");

    arena3.addGame(game3);

    arena.setAddress(addr);
    addr.setArena(arena);

    arena.addGame(game);
    arena.addGame(game2);

    arenaManager.add(arena);
    arenaManager.add(arena1);
    arenaManager.add(arena3);

    User client = new User();
    client.setFirstName("John");
    client.setLastName("Marsh");
    client.setEmailAddress("*****@*****.**");
    client.setPassword(BCrypt.hashpw("password", BCrypt.gensalt()));
    client.setCity("Ottawa");
    client.setCountry("Canada");
    client.setProvinceORstate("Ontario");
    client.setBirthdate(Timestamp.valueOf("1993-07-21 00:00:00"));

    User client2 = new User();
    client2.setFirstName("Dougall");
    client2.setLastName("Percival");
    client2.setEmailAddress("*****@*****.**");
    client2.setPassword(BCrypt.hashpw("password", BCrypt.gensalt()));
    client2.setCity("Ottawa");
    client2.setCountry("Canada");
    client2.setProvinceORstate("Ontario");
    client2.setBirthdate(Timestamp.valueOf("1993-12-21 00:00:00"));
    client2.addGame(game2);

    assertTrue(userManager.add(client));
    assertTrue(userManager.add(client2));

    userManager.update(client2);
    userManager.update(client);
  }