Package org.springframework.batch.sample.domain.trade

Examples of org.springframework.batch.sample.domain.trade.Trade


    customers = Arrays.asList(new Customer("customer1", (credits.get("customer1") - 98.34)),
        new Customer("customer2", (credits.get("customer2") - 18.12 - 12.78)),
        new Customer("customer3", (credits.get("customer3") - 109.25)),
        new Customer("customer4", credits.get("customer4") - 123.39));

    trades = Arrays.asList(new Trade("UK21341EAH45", 978, new BigDecimal("98.34"), "customer1"),
        new Trade("UK21341EAH46", 112, new BigDecimal("18.12"), "customer2"),
        new Trade("UK21341EAH47", 245, new BigDecimal("12.78"), "customer2"),
        new Trade("UK21341EAH48", 108, new BigDecimal("109.25"), "customer3"),
        new Trade("UK21341EAH49", 854, new BigDecimal("123.39"), "customer4"));

        jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
      @Override
      public void processRow(ResultSet rs) throws SQLException {
        Trade trade = trades.get(activeRow++);

        assertTrue(trade.getIsin().equals(rs.getString(1)));
        assertTrue(trade.getQuantity() == rs.getLong(2));
        assertTrue(trade.getPrice().equals(rs.getBigDecimal(3)));
        assertTrue(trade.getCustomer().equals(rs.getString(4)));
      }
    });

    assertEquals(activeRow, trades.size());
View Full Code Here


  private static final long QUANTITY = 7;
  private static final String ISIN = "fj893gnsalX";

  @Override
  protected Object expectedDomainObject() {
    Trade trade = new Trade();
    trade.setIsin(ISIN);
    trade.setQuantity(QUANTITY);
    trade.setPrice(PRICE);
    trade.setCustomer(CUSTOMER);
    return trade;
  }
View Full Code Here

  @Override
  public Trade read() throws Exception {
    if (counter < limit) {
      counter++;
      return new Trade(
          "isin" + counter,
          counter,
          new BigDecimal(counter),
          "customer" + counter);
    }
View Full Code Here

  public static final int ID_COLUMN = 5;
  public static final int VERSION_COLUMN = 6;

  @Override
  public Trade mapRow(ResultSet rs, int rowNum) throws SQLException {
    Trade trade = new Trade(rs.getLong(ID_COLUMN));
   
    trade.setIsin(rs.getString(ISIN_COLUMN));
    trade.setQuantity(rs.getLong(QUANTITY_COLUMN));
    trade.setPrice(rs.getBigDecimal(PRICE_COLUMN));
    trade.setCustomer(rs.getString(CUSTOMER_COLUMN));
    trade.setVersion(rs.getInt(VERSION_COLUMN));
   
    return trade;
  }
View Full Code Here

  public static final int CUSTOMER_COLUMN = 3;
 
    @Override
  public Trade mapFieldSet(FieldSet fieldSet) {
     
      Trade trade = new Trade();
      trade.setIsin(fieldSet.readString(ISIN_COLUMN));
        trade.setQuantity(fieldSet.readLong(QUANTITY_COLUMN));
        trade.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN));
        trade.setCustomer(fieldSet.readString(CUSTOMER_COLUMN));
       
        return trade;
    }
View Full Code Here

        return clazz.equals(Trade.class);
    }

    @Override
    public void validate(Object target, Errors errors) {
        Trade trade = (Trade) target;

        if(trade.getIsin().length() >= 13) {
            errors.rejectValue("isin", "isin_length");
        }
    }
View Full Code Here

  private void checkOutputTable(int before) {
    @SuppressWarnings("serial")
    final List<Trade> trades = new ArrayList<Trade>() {
      {
        add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"));
        add(new Trade("UK21341EAH42", 212, new BigDecimal("32.11"), "customer2"));
        add(new Trade("UK21341EAH43", 213, new BigDecimal("33.11"), "customer3"));
        add(new Trade("UK21341EAH44", 214, new BigDecimal("34.11"), "customer4"));
        add(new Trade("UK21341EAH45", 215, new BigDecimal("35.11"), "customer5"));
      }
    };

    int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE", Integer.class);

    assertEquals(before + 5, after);

        jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
      private int activeRow = 0;

      @Override
      public void processRow(ResultSet rs) throws SQLException {
        Trade trade = trades.get(activeRow++);

        assertEquals(trade.getIsin(), rs.getString(1));
        assertEquals(trade.getQuantity(), rs.getLong(2));
        assertEquals(trade.getPrice(), rs.getBigDecimal(3));
        assertEquals(trade.getCustomer(), rs.getString(4));
      }
    });

  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testWrite() throws Exception {
    assertEquals(0, writer.getItems().size());
    Trade a = new Trade("a", 0, null, null);
    Trade b = new Trade("b", 0, null, null);
    Trade c = new Trade("c", 0, null, null);
    writer.write(Arrays.asList(a, b, c));
    assertEquals(3, writer.getItems().size());
  }
View Full Code Here

  @Test
  public void testWriteFailure() throws Exception {
    writer.setWriteFailureISIN("c");
    try {
      Trade a = new Trade("a", 0, null, null);
      Trade b = new Trade("b", 0, null, null);
      Trade c = new Trade("c", 0, null, null);
      writer.write(Arrays.asList(a, b, c));
      fail("Expected Write Failure Exception");
    }
    catch (IOException e) {
      // expected
    }
    // the failed item is removed
    assertEquals(0, writer.getItems().size());

    Trade e = new Trade("e", 0, null, null);
    Trade f = new Trade("f", 0, null, null);
    Trade g = new Trade("g", 0, null, null);
    writer.write(Arrays.asList(e, f, g));
    assertEquals(3, writer.getItems().size());
  }
View Full Code Here

    processor.setDao(writer);
  }
   
  @Test
  public void testProcess() {
    Trade trade = new Trade();

    writer.writeTrade(trade);
   
    processor.write(Collections.singletonList(trade));
  }
View Full Code Here

TOP

Related Classes of org.springframework.batch.sample.domain.trade.Trade

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.