Package rewards

Source Code of rewards.RewardNetworkPropagationTest

package rewards;

import static org.junit.Assert.*;

import javax.sql.DataSource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

/**
* A system test that demonstrates how propagation settings affect transactional execution.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:rewards/system-test-config.xml"})
public class RewardNetworkPropagationTest {

  /**
   * The object being tested.
   */
  @Autowired
  private RewardNetwork rewardNetwork;

  /**
   * A template to use for test verification
   */
  private SimpleJdbcTemplate template;

  /**
   * Manages transaction manually
   */
  private PlatformTransactionManager transactionManager;


  @Autowired
  public void setDataSource(DataSource dataSource) {
    this.template = new SimpleJdbcTemplate(dataSource);
  }

  @Autowired
  public void setTransactionManager(PlatformTransactionManager transactionManager) {
    this.transactionManager = transactionManager;
  }

  @Test
  public void testPropagation() {
    // Open a transaction for testing
    TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
    Dining dining = Dining.createDining("100.00", "1234123412341234", "1234567890");
    rewardNetwork.rewardAccountFor(dining);
    String sql = "select SAVINGS from T_ACCOUNT_BENEFICIARY where NAME = ?";

    // Rollback the transaction test transaction
    transactionManager.rollback(status);
    assertEquals(Double.valueOf(4.00), template.queryForObject(sql, Double.class, "Annabelle"));
    assertEquals(Double.valueOf(4.00), template.queryForObject(sql, Double.class, "Corgan"));

  }
}
TOP

Related Classes of rewards.RewardNetworkPropagationTest

TOP
Copyright © 2018 www.massapi.com. 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.