Exemplo n.º 1
0
  @Test
  public void testGetValidNetworkCountByStage() {
    init();

    List<Network> infosOfDB = readDBByUserId(_info.getUserId());
    int countOfDB = 0;
    for (int i = 0; i < infosOfDB.size(); i++) {
      if (infosOfDB.get(i).getStatus() == -1 || infosOfDB.get(i).getStatus() == 0) {
        countOfDB++;
      }
    }
    int countOfOrigin = 0;
    for (int i = 0; i < _infos.size(); i++) {
      if (_infos.get(i).getStatus() == -1 || _infos.get(i).getStatus() == 0) {
        countOfOrigin++;
      }
    }
    int countOfCache =
        AdapterFactory.getNetworkAdapter()
            .getValidNetworkCountByStage(_info.getUserId(), _info.getStage());
    int countOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getValidNetworkCountByStage(_info.getUserId(), _info.getStage());

    System.out.println(
        countOfOrigin + " " + countOfDB + " " + countOfCache + " " + countOfReaderCache);
    Assert.assertEquals(countOfOrigin, countOfDB);
    Assert.assertEquals(countOfOrigin, countOfCache);
    Assert.assertEquals(countOfOrigin, countOfReaderCache);
  }
Exemplo n.º 2
0
  @Test
  public void testRemoveNetworkByStage() {
    init();

    _infos.remove(_info);
    AdapterFactory.getNetworkAdapter().removeNetworkByStage(_info.getUserId(), _info.getStage());
    checkAll();

    // Writer
    init();

    _infos.remove(_info);
    AdapterFactory.getNetworkWriterAdapter()
        .removeNetworkByStage(_info.getUserId(), _info.getStage());
    checkAll();
  }
Exemplo n.º 3
0
  @Test
  public void testGetNetworkListByStage() {
    init();

    List<Network> infosOfDB = readDBByUserId(_info.getUserId());
    List<Network> infosOfCache =
        AdapterFactory.getNetworkAdapter()
            .getNetworkListByStage(_info.getUserId(), _info.getStage());
    List<Network> infosOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getNetworkListByStage(_info.getUserId(), _info.getStage());

    Assert.assertTrue(isEqual(infosOfDB, _infos));
    Assert.assertTrue(isEqual(infosOfCache, _infos));
    Assert.assertTrue(isEqual(infosOfReaderCache, _infos));
  }
Exemplo n.º 4
0
  @Test
  public void testGetNetworkCountByStage() {
    init();

    int countOfDB = readDBByUserId(_info.getUserId()).size();
    int countOfCache =
        AdapterFactory.getNetworkAdapter()
            .getNetworkCountByStage(_info.getUserId(), _info.getStage());
    int countOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getNetworkCountByStage(_info.getUserId(), _info.getStage());
    int countOfOrigin = _infos.size();

    Assert.assertEquals(countOfOrigin, countOfDB);
    Assert.assertEquals(countOfOrigin, countOfCache);
    Assert.assertEquals(countOfOrigin, countOfReaderCache);
  }
Exemplo n.º 5
0
  @Test
  public void testGetNetworkListByStageAndStatus() {
    init();
    Network info = genInfoCopy(1);
    int status[] = {_info.getStatus(), info.getStatus()};
    setDBAndInfos(info.getId(), info);
    AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());

    List<Network> infosOfDB = readDBByUserId(_info.getUserId());
    List<Network> infosOfCache =
        AdapterFactory.getNetworkAdapter()
            .getNetworkListByStageAndStatus(_info.getUserId(), _info.getStage(), status);
    List<Network> infosOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getNetworkListByStageAndStatus(_info.getUserId(), _info.getStage(), status);

    Assert.assertTrue(isEqual(infosOfDB, _infos));
    Assert.assertTrue(isEqual(infosOfCache, _infos));
    Assert.assertTrue(isEqual(infosOfReaderCache, _infos));
  }
Exemplo n.º 6
0
  /**
   * 获取一份新的数据
   *
   * @param idStep
   * @return
   */
  protected Network genInfoCopy(int idStep) {
    Network result = new Network();
    result.setId(_info.getId() + idStep);
    result.setUserId(_info.getUserId());
    result.setStage(_info.getStage());
    result.setNetworkId(_info.getNetworkId() + idStep);
    result.setNetworkName(_info.getNetworkName() + ".new");
    result.setInfoId(_info.getInfoId());
    result.setJoinTime(_info.getJoinTime());
    result.setStatus(_info.getStatus() + idStep);

    return result;
  }
Exemplo n.º 7
0
 protected void setDBAndInfos(int recordId, Network info) {
   String sql =
       "replace into network_history(id,userid,stage,network_id,network_name,info_id,join_time,status) values ("
           + recordId
           + ","
           + info.getUserId()
           + ","
           + info.getStage()
           + ","
           + info.getNetworkId()
           + ",'"
           + info.getNetworkName()
           + "',"
           + info.getInfoId()
           + ",'"
           + DateFormatter.format(info.getJoinTime())
           + "',"
           + info.getStatus()
           + ")";
   writeDB(sql);
   _infos.add(info);
 }