I have been reading through the documentation and trying some of the tutorials and have a question about the no-loop attribute. <br><br>Not really relevant to the post, but I figured I would mention it, I have been following this post and updating it to use the current version of Drools. <a href="http://www.onjava.com/pub/a/onjava/2005/08/03/drools.html?page=7">http://www.onjava.com/pub/a/onjava/2005/08/03/drools.html?page=7</a> <br>
<br>I have written my rules as such:<br><br>package org.drools.examples<br><br>import org.drools.examples.StockOffer;<br><br>rule PriceBelow100<br>&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer( stockPrice &lt; 100 &amp;&amp; recommendPurchase == null )<br>
&nbsp;&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setRecommendPurchase(StockOffer.YES)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>end<br><br>rule NegativeStockPrice<br>&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>&nbsp;&nbsp;&nbsp; no-loop true<br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer( stockPrice &lt; 0 )<br>
&nbsp;&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setRecommendPurchase(StockOffer.NO)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>end&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br><br>rule DontBuyXYZStock<br>&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>&nbsp;&nbsp;&nbsp; no-loop true<br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer(stockName == &quot;XYZ&quot; &amp;&amp; stockPrice &lt; 10 )<br>
&nbsp;&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setRecommendPurchase(StockOffer.YES)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>end&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br><br>rule BuyXYZStock<br>&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>&nbsp;&nbsp;&nbsp; no-loop true<br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer(stockName == &quot;XYZ&quot; &amp;&amp; stockPrice &gt; 10 )<br>
&nbsp;&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setRecommendPurchase(StockOffer.NO)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>end&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br><br><br><br>My question is, why do I have to put no-loop on every rule (except for the first). After the first time through the rules, it shouldn&#39;t be modifying to where the rules would fire it again. Am I doing something wrong with how my rules are written? My sample data is this:<br>
<br>package org.drools.examples;<br><br>import org.drools.examples.BusinessLayer;<br>import org.drools.examples.StockOffer;<br><br>import junit.framework.TestCase;<br><br>/*<br>&nbsp;* JUnit test for the business rules in the <br>
&nbsp;* application.<br>&nbsp;* <br>&nbsp;* This also acts a &#39;simulator&#39; for the business <br>&nbsp;* rules - allowing us to specify the inputs,<br>&nbsp;* examine the outputs and see if they match our <br>&nbsp;* expectations before letting the code loose in&nbsp; <br>
&nbsp;* the real world.<br>&nbsp;*/<br>public class BusinessRuleTest extends TestCase {<br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; &nbsp;* Tests the purchase of a stock<br>&nbsp;&nbsp;&nbsp; &nbsp;*/<br>&nbsp;&nbsp;&nbsp; public void testStockBuy() throws Exception {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create a Stock with simulated values<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOffer = new StockOffer();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockName(&quot;MEGACORP&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockPrice(22);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockQuantity(1000);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Run the rules on it<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; BusinessLayer.evaluateStockPurchase(testOffer);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Is it what we expected?<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; assertTrue(testOffer.getRecommendPurchase() != null);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; assertTrue(&quot;YES&quot;.equals(testOffer.getRecommendPurchase()));<br>
&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; &nbsp;* Tests the purchase of a stock makes sure the system will not accept<br>&nbsp;&nbsp;&nbsp; &nbsp;* negative numbers.<br>&nbsp;&nbsp;&nbsp; &nbsp;*/<br>&nbsp;&nbsp;&nbsp; public void testNegativeStockBuy() throws Exception {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create a Stock with our simulated values<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOffer = new StockOffer();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockName(&quot;MEGACORP&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockPrice(-22);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockQuantity(1000);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Run the rules on it<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; BusinessLayer.evaluateStockPurchase(testOffer);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Is it what we expected?<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; assertTrue(&quot;NO&quot;.equals(testOffer.getRecommendPurchase()));<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; &nbsp;* Makes sure the system will buy stocks of XYZ corp only if it really cheap<br>
&nbsp;&nbsp;&nbsp; &nbsp;*/<br>&nbsp;&nbsp;&nbsp; public void testXYZStockBuy() throws Exception {<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create a Stock with our simulated values<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOfferLow = new StockOffer();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOfferHigh = new StockOffer();<br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferLow.setStockName(&quot;XYZ&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferLow.setStockPrice(9);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferLow.setStockQuantity(1000);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferHigh.setStockName(&quot;XYZ&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferHigh.setStockPrice(11);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferHigh.setStockQuantity(1000);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Run the rules on it and test<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; BusinessLayer.evaluateStockPurchase(testOfferLow);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; assertTrue(&quot;YES&quot;.equals(testOfferLow.getRecommendPurchase()));<br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; BusinessLayer.evaluateStockPurchase(testOfferHigh);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; assertTrue(&quot;NO&quot;.equals(testOfferHigh.getRecommendPurchase()));<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br><br>I can post up all the code if this isn&#39;t enough to answer the question.<br>
<br>Thanks!<br>