Exemplo n.º 1
0
  // Also 04.05.01
  public void test_04_01_01() {
    setUp2();
    // Test offer trade to friend
    User user = MyApplication.getLocalUser();
    Service newService = ServiceManager.sharedManager().newService();
    newService.setName("new service");
    user.addService(newService);

    user.addFriend(friend1);
    User myFriend = user.getFriends().get(0);

    // Create a new trade
    Trade newTrade = TradeManager.sharedManager().newTrade(myFriend, false);

    // Edit the trade
    newTrade.addBorrowerService(newService);
    newTrade.addOwnerService(service1);

    // Finalize it
    newTrade.commit();
    assertEquals(TradeManager.sharedManager().getTrades().size(), 1);
    assertEquals(user.getTrades().size(), 1);
    assertEquals(friend1.getTrades().size(), 1);

    TradeManager.sharedManager().clearCache();
    Trade oldTrade = TradeManager.sharedManager().getTrade(user.getTrades().get(0).getID());
    assertEquals(oldTrade.getID(), newTrade.getID());

    IOManager.sharedManager().deleteData(Constants.serverServiceExtension() + newService.getID());
    IOManager.sharedManager().deleteData(Constants.serverTradeExtension() + newTrade.getID());
    tearDown2();
  }
Exemplo n.º 2
0
  public void test_04_02_01() {
    setUp2();
    // Test get notified by a trade
    User user = MyApplication.getLocalUser();
    String tradeString =
        ""
            + "{"
            + "\"borrower\":\""
            + user.getEmail()
            + "\","
            + "\"borrowerServices\":[],"
            + "\"id\":\"0001\","
            + "\"lastUpdatedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"owner\":\"1\","
            + "\"ownerServices\":[],"
            + "\"proposedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"isCounterOffer\":false,"
            + "\"status\":0"
            + "}";
    Trade trade = (new Gson()).fromJson(tradeString, Trade.class);
    IOManager.sharedManager().storeData(trade, Constants.serverTradeExtension() + trade.getID());
    trade = TradeManager.sharedManager().getTrade(trade.getID());
    trade.commit();

    assertEquals(user.newTrades(), 1);

    IOManager.sharedManager().deleteData(Constants.serverTradeExtension() + trade.getID());
    tearDown2();
  }
Exemplo n.º 3
0
  @Override
  protected void tearDown2() {
    IOManager.sharedManager().deleteData(Constants.serverUserExtension() + friend1.getEmail());
    IOManager.sharedManager().deleteData(Constants.serverServiceExtension() + service1.getID());
    IOManager.sharedManager()
        .deleteData(Constants.serverUserExtension() + MyApplication.getLocalUser().getEmail());

    super.tearDown2();
  }
Exemplo n.º 4
0
  public void test_04_03_01() {
    setUp2();
    // Test accept and decline trades
    User user = MyApplication.getLocalUser();
    String trade1String =
        ""
            + "{"
            + "\"owner\":\""
            + user.getEmail()
            + "\","
            + "\"borrowerServices\":[],"
            + "\"id\":\"0001\","
            + "\"lastUpdatedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"borrower\":\"1\","
            + "\"ownerServices\":[],"
            + "\"proposedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"isCounterOffer\":false,"
            + "\"status\":0"
            + "}";
    String trade2String =
        ""
            + "{"
            + "\"owner\":\""
            + user.getEmail()
            + "\","
            + "\"borrowerServices\":[],"
            + "\"id\":\"0002\","
            + "\"lastUpdatedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"borrower\":\"1\","
            + "\"ownerServices\":[],"
            + "\"proposedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"isCounterOffer\":false,"
            + "\"status\":0"
            + "}";
    Trade trade1 = (new Gson()).fromJson(trade1String, Trade.class);
    Trade trade2 = (new Gson()).fromJson(trade2String, Trade.class);
    IOManager.sharedManager().storeData(trade1, Constants.serverTradeExtension() + trade1.getID());
    IOManager.sharedManager().storeData(trade2, Constants.serverTradeExtension() + trade2.getID());
    trade1 = TradeManager.sharedManager().getTrade(trade1.getID());
    trade2 = TradeManager.sharedManager().getTrade(trade2.getID());
    trade1.commit();
    trade2.commit();

    user.getTrades().get(0).accept();
    user.getTrades().get(1).decline();

    assertEquals(trade1.getState().getClass(), TradeStateAccepted.class);
    assertEquals(trade2.getState().getClass(), TradeStateDeclined.class);

    user.getTrades().get(0).complete();
    assertEquals(trade1.getState().getClass(), TradeStateComplete.class);

    IOManager.sharedManager().deleteData(Constants.serverTradeExtension() + trade1.getID());
    IOManager.sharedManager().deleteData(Constants.serverTradeExtension() + trade2.getID());
    tearDown2();
  }
Exemplo n.º 5
0
  // Also 04_09_01
  public void test_04_08_01() {
    setUp2();
    // Test browse past and current trades involving me
    User user = MyApplication.getLocalUser();
    String trade1String =
        ""
            + "{"
            + "\"borrower\":\""
            + user.getEmail()
            + "\","
            + "\"borrowerServices\":[],"
            + "\"id\":\"0001\","
            + "\"lastUpdatedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"owner\":\"1\","
            + "\"ownerServices\":[],"
            + "\"proposedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"isCounterOffer\":false,"
            + "\"status\":1"
            + "}";
    String trade2String =
        ""
            + "{"
            + "\"borrower\":\""
            + user.getEmail()
            + "\","
            + "\"borrowerServices\":[],"
            + "\"id\":\"0002\","
            + "\"lastUpdatedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"owner\":\"1\","
            + "\"ownerServices\":[],"
            + "\"proposedDate\":\"Nov 1, 2015 6:11:40 PM\","
            + "\"isCounterOffer\":false,"
            + "\"status\":0"
            + "}";
    Trade trade1 = (new Gson()).fromJson(trade1String, Trade.class);
    Trade trade2 = (new Gson()).fromJson(trade2String, Trade.class);
    IOManager.sharedManager().storeData(trade1, Constants.serverTradeExtension() + trade1.getID());
    IOManager.sharedManager().storeData(trade2, Constants.serverTradeExtension() + trade2.getID());
    trade1 = TradeManager.sharedManager().getTrade(trade1.getID());
    trade2 = TradeManager.sharedManager().getTrade(trade2.getID());
    trade1.commit();
    trade2.commit();

    assertEquals(user.getTrades().size(), 2);
    assertEquals(user.newTrades(), 1);

    IOManager.sharedManager().deleteData(Constants.serverTradeExtension() + trade1.getID());
    IOManager.sharedManager().deleteData(Constants.serverTradeExtension() + trade2.getID());
    tearDown2();
  }
Exemplo n.º 6
0
  @Override
  protected void setUp2() {
    super.setUp2();

    String friend1String =
        ""
            + "{"
            + "\"friends\":[],"
            + "\"email\":\"1\","
            + "\"location\":\"British\","
            + "\"name\":\"The Clown Guy\","
            + "\"services\":[1],"
            + "\"trades\":[]"
            + "}";
    String service1String =
        ""
            + "{"
            + "\"category\":"
            + "{"
            + "\"name\":\"OTHER\""
            + "}"
            + ","
            + "\"description\":\"\","
            + "\"id\":\"1\","
            + "\"name\":\"\","
            + "\"owner\":\"1\","
            + "\"pictures\":[],"
            + "\"shareable\":true"
            + "}";
    friend1 = (new Gson()).fromJson(friend1String, User.class);
    service1 = (new Gson()).fromJson(service1String, Service.class);
    IOManager.sharedManager()
        .storeData(friend1, Constants.serverUserExtension() + friend1.getEmail());
    IOManager.sharedManager()
        .storeData(service1, Constants.serverServiceExtension() + service1.getID());
    friend1 = UserManager.sharedManager().getUser(friend1.getEmail());
    service1 = ServiceManager.sharedManager().getService(service1.getID());
  }