@Test
  public void testGetFolder() throws MessagingException {
    Properties props;
    Session session;
    Folder folder;
    props = new Properties();

    props.put("mail.host", "pop.gmail.com");
    props.put("mail.store.protocol", "pop3s");
    props.put("mail.pop3s.auth", "true");
    props.put("mail.pop3s.port", 995);

    session = Session.getInstance(props, null);
    Store instance;

    // with wrong param
    instance = session.getStore();
    instance.connect("*****@*****.**", "spamreturn");
    try {
      folder = instance.getFolder("");
    } catch (MessagingException ex) {
      assertTrue(true);
    }

    // with valid param
    try {
      folder = instance.getFolder("INBOX");
      assertTrue(true);
    } catch (MessagingException ex) {
      fail("Should not throw MessagingException");
    }
  }
Exemplo n.º 2
0
  @Test
  public void failedTransaction2() throws ExecutionException, InterruptedException {
    Stage stage = createStage();
    Bank bank = Actor.getReference(Bank.class, "jimmy");
    Inventory inventory = Actor.getReference(Inventory.class, "jimmy");
    Store store = Actor.getReference(Store.class, "all");
    bank.increment(15).join();

    fakeSync.put("proceed", "ok");

    // this item is invalid but the bank balance is decreased first.
    store.buyItem(bank, inventory, "candy", 10).join();
    store.buyItem(bank, inventory, "chocolate", 1).join();
    try {
      store.buyItem(bank, inventory, "ice cream", 50).join();
      fail("expecting an exception");
    } catch (CompletionException ex) {
      System.out.println(ex.getCause().getMessage());
    }

    // the bank credits must be restored.
    eventually(() -> assertEquals((Integer) 4, bank.getBalance().join()));
    // no items were given
    eventually(() -> assertEquals(2, inventory.getItems().join().size()));
    dumpMessages();
  }
Exemplo n.º 3
0
  @Before
  public void setUp() throws Exception {
    Store store = new Store();
    store.setDbName("gwdp");
    store.setCollectionName("files_done");

    s = store;

    fr = new FileRecorder(store);
  }
Exemplo n.º 4
0
  @Test
  public void successfulTransaction() throws ExecutionException, InterruptedException {
    Stage stage = createStage();
    Bank bank = Actor.getReference(Bank.class, "jimmy");
    Inventory inventory = Actor.getReference(Inventory.class, "jimmy");
    Store store = Actor.getReference(Store.class, "all");
    bank.increment(15).join();

    // this allows the store to proceed without blocking
    fakeSync.put("proceed", "ok");
    store.buyItem(bank, inventory, "candy", 10).join();
    // the balance was decreased
    assertEquals((Integer) 5, bank.getBalance().join());
    // got the item
    assertTrue(inventory.getItems().join().get(0).startsWith("candy:"));
    Thread.sleep(1000);
    dumpMessages();
  }
Exemplo n.º 5
0
  @Test
  public void failedTransaction() throws ExecutionException, InterruptedException {
    Stage stage = createStage();
    Bank bank = Actor.getReference(Bank.class, "jimmy");
    Inventory inventory = Actor.getReference(Inventory.class, "jimmy");
    Store store = Actor.getReference(Store.class, "all");
    bank.increment(15).join();

    fakeSync.put("proceed", "fail");

    // this item is invalid but the bank balance is decreased first.
    expectException(() -> store.buyItem(bank, inventory, "ice cream", 10).join());

    // the bank credits must be restored.
    eventually(() -> assertEquals((Integer) 15, bank.getBalance().join()));
    // no items were given
    assertEquals(0, inventory.getItems().join().size());
    dumpMessages();
  }
  @Test
  public void testConnect() throws MessagingException {
    Properties props;
    Session session;
    Folder folder;
    props = new Properties();

    props.put("mail.host", "smtp.unice.fr");
    props.put("mail.store.protocol", "pop3s");
    props.put("mail.pop3s.auth", "true");
    props.put("mail.pop3s.port", 25);

    session = Session.getInstance(props, null);
    Store instance;
    try {
      instance = session.getStore();
      instance.connect(null, null);
      fail("Should throw MessagingException : params are null.");
    } catch (NoSuchProviderException ex) {
      throw ex; // this exception should not be thrown to test connect method
    } catch (MessagingException ex) {
      assertTrue(true);
    }
  }