예제 #1
0
  public void testShutDownManager() throws Exception {
    String strLastDate = AppConfig.dateCORPACTIONDOWNLOADMANAGER.Value;
    String strInCompleteList = AppConfig.corpActionDownloadErrorList.Value;
    Hashtable<PMDate, Vector<CompanyActionVO>> htConsidated =
        new Hashtable<PMDate, Vector<CompanyActionVO>>();
    final Mock compayDAOMock = new Mock(CompanyDAO.class);
    compayDAOMock.expects(once()).method("writeConsolidatedActionData").with(eq(htConsidated));

    final Mock synchronizerMock = new Mock(CorpActionSynchronizer.class);
    synchronizerMock.expects(once()).method("applyCorpAction").withNoArguments();

    CorpActionDownloadManager manager =
        new CorpActionDownloadManager(null) {
          {
            inCompleteList = new Vector<String>();
            inCompleteList.add(STOCKCODE1);
          }

          @Override
          CompanyDAO getCompanyDAO() {
            return (CompanyDAO) compayDAOMock.proxy();
          }

          CorpActionSynchronizer getSynchronizer() {
            return (CorpActionSynchronizer) synchronizerMock.proxy();
          }
        };
    manager.shutDownManager();
    assertTrue(
        PMDateFormatter.formatYYYYMMDD(new PMDate())
            .equals(AppConfig.dateCORPACTIONDOWNLOADMANAGER.Value));
    assertTrue(STOCKCODE1.equals(AppConfig.corpActionDownloadErrorList.Value));

    AppConfig.dateCORPACTIONDOWNLOADMANAGER.Value = strLastDate;
    AppConfig.corpActionDownloadErrorList.Value = strInCompleteList;
    AppConfig.saveConfigDetails();
    compayDAOMock.verify();
    synchronizerMock.verify();
  }
예제 #2
0
  public void testRunToIgnoreStoredConsolidatedDataWhenUsingCompleteList()
      throws InterruptedException {
    int maxThreadCount = 2;
    ThreadPoolExecutor executor =
        new ThreadPoolExecutor(
            maxThreadCount,
            maxThreadCount,
            0L,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>());
    final Vector<Boolean> callList = new Vector<Boolean>();
    final Hashtable<PMDate, Vector<CompanyActionVO>> storedData =
        new Hashtable<PMDate, Vector<CompanyActionVO>>();
    final Vector<String> storedInCompleteList = new Vector<String>();
    final Mock synchronizerMock = new Mock(CorpActionSynchronizer.class);
    synchronizerMock.expects(once()).method("applyCorpAction").withNoArguments();

    CorpActionDownloadManager manager =
        new CorpActionDownloadManager(executor) {
          @Override
          CompanyDAO getCompanyDAO() {
            return new CompanyDAO() {
              @Override
              public Hashtable<PMDate, Vector<CompanyActionVO>> getConsolidatedActionData() {
                Hashtable<PMDate, Vector<CompanyActionVO>> retVal =
                    new Hashtable<PMDate, Vector<CompanyActionVO>>();
                Vector<CompanyActionVO> vector = new Vector<CompanyActionVO>();
                try {
                  vector.add(new CompanyActionVO("20050101,STOCK,1,10,Split,false,"));
                } catch (Exception e) {
                }
                retVal.put(new PMDate(1, 1, 2005), vector);
                return retVal;
              }

              @Override
              public boolean writeConsolidatedActionData(
                  Hashtable<PMDate, Vector<CompanyActionVO>> consolidatedData) {
                storedData.putAll(consolidatedData);
                return true;
              }
            };
          }

          CorpActionSynchronizer getSynchronizer() {
            return (CorpActionSynchronizer) synchronizerMock.proxy();
          }

          @Override
          CorpActionDownloader createDownloader(String stockCode) {
            CorpActionDownloader corpActionDownloader;
            if (stockCode.equals(STOCKCODE1)) {
              corpActionDownloader =
                  new CorpActionDownloader(stockCode, this) {
                    @Override
                    protected void performTask() {}

                    @Override
                    public Vector<CompanyActionVO> getCorpActions() {
                      Vector<CompanyActionVO> vector = new Vector<CompanyActionVO>();
                      try {
                        vector.add(new CompanyActionVO("20050102,STOCK1,1,10,Split,false,"));
                      } catch (Exception e) {
                      }
                      return vector;
                    }
                  };

            } else {
              corpActionDownloader =
                  new CorpActionDownloader(stockCode, this) {
                    @Override
                    protected void performTask() {}

                    @Override
                    public boolean isCompleted() {
                      return false;
                    }
                  };
            }
            return corpActionDownloader;
          }

          @Override
          protected void storeIncompleteList() {
            storedInCompleteList.addAll(inCompleteList);
          }

          @Override
          protected void saveStatus() {}

          @Override
          void shutDownManager() {
            super.shutDownManager();
            callList.add(true);
          }

          @Override
          protected Vector<String> getCompleteList() {
            flagCompleteListLoaded = true;
            Vector<String> completeList = new Vector<String>();
            completeList.add(STOCKCODE1);
            completeList.add(STOCKCODE2);
            completeList.add(STOCKCODE3);
            return completeList;
          }
        };

    AppConfig.corpActionDownloadErrorList.Value = STOCKCODE1 + "," + STOCKCODE2;
    AppConfig.dateCORPACTIONDOWNLOADMANAGER.Value = "20010101";

    manager.run();
    executor.awaitTermination(1, TimeUnit.SECONDS);
    assertEquals(1, callList.size());
    assertTrue(callList.firstElement());

    assertEquals(1, storedData.size());
    assertEquals(1, storedData.elements().nextElement().size());
    assertEquals("STOCK1", storedData.values().iterator().next().firstElement().getStockCode());

    assertEquals(2, storedInCompleteList.size());
    assertTrue(storedInCompleteList.contains(STOCKCODE2));
    assertTrue(storedInCompleteList.contains(STOCKCODE3));
  }