ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Give Your Business Logic a Framework with Drools
Pages: 1, 2, 3, 4, 5, 6, 7

This is a basic JUnit test, as we know that our (very simple!) system should buy all stocks with a price of less than 100 Euro. Obviously, this won't compile without our data holding class (StockOffer.java) and our business layer class (BusinessLayer.java). These are provided in the following listings.



/**
 * Facade for the Business Logic in our example.
 * 
 * In this simple example, all our business logic
 * is contained in this class but in reality it 
 * would delegate to other classes as required.
*/
public class BusinessLayer {
  /**
   * Evaluate whether or not it is a good idea
   * to purchase this stock.
   * @param stockToBuy
   * @return true if the recommendation is to buy 
   *   the stock, false if otherwise
   */
  public static void evaluateStockPurchase
    (StockOffer stockToBuy){
                return false;
  }
}

The StockOffer class looks like this:

/**
 * Simple JavaBean to hold StockOffer values.
 * A 'Stock offer' is an offer (from somebody else)
 * to sell us a Stock (or Company share).
 */
public class StockOffer {
        
  //constants
  public final static String YES="YES";
  public final static String NO="NO";
        
  //Internal Variables
  private String stockName =null;
  private int stockPrice=0;
  private int stockQuantity=0;
  private String recommendPurchase = null;
        
  /**
   * @return Returns the stockName.
   */
  public String getStockName() {
        return stockName;
  }
  /**
   * @param stockName The stockName to set.
   */
  public void setStockName(String stockName) {
        this.stockName = stockName;
  }
  /**
   * @return Returns the stockPrice.
   */
  public int getStockPrice() {
        return stockPrice;
  }
  /**
   * @param stockPrice The stockPrice to set.
   */
  public void setStockPrice(int stockPrice) {
        this.stockPrice = stockPrice;
  }
  /**
   * @return Returns the stockQuantity.
   */
  public int getStockQuantity() {
        return stockQuantity;
  }
  /**
   * @param stockQuantity to set.
   */
  public void setStockQuantity(int stockQuantity){
        this.stockQuantity = stockQuantity;
  }
  /**
   * @return Returns the recommendPurchase.
   */
  public String getRecommendPurchase() {
        return recommendPurchase;
  }
}

Pages: 1, 2, 3, 4, 5, 6, 7

Next Pagearrow