1 /*** 2 * IndexerOperatorTest.java 3 * 4 * $Author: mballesteros $ 5 * $Date: 2003/11/28 19:18:03 $ 6 * $Revision: 1.1 $ 7 */ 8 package net.sf.jec; 9 10 import java.util.HashMap; 11 12 import net.sf.jec.AccessorOperator; 13 import net.sf.jec.ConstantOperator; 14 import net.sf.jec.EvaluationException; 15 import net.sf.jec.IndexerOperator; 16 import net.sf.jec.InvertibleOperator; 17 import net.sf.jec.Operator; 18 19 import junit.framework.TestCase; 20 21 /*** 22 * @author mballesteros 23 */ 24 public class IndexerOperatorTest extends TestCase { 25 26 /*** 27 * Constructor for IndexerOperatorTest. 28 * @param arg0 29 */ 30 public IndexerOperatorTest(String arg0) { 31 super(arg0); 32 } 33 34 private HashMap ctx; 35 private Book book; 36 37 /* 38 * @see TestCase#setUp() 39 */ 40 protected void setUp() throws Exception { 41 super.setUp(); 42 book = Book.getExample(); 43 ctx = new HashMap(); 44 ctx.put("book", book); 45 ctx.put("intIndex", "0"); 46 ctx.put("strIndex", "1"); 47 } 48 49 public void testApplyInverse() throws EvaluationException { 50 Operator op; 51 op = new AccessorOperator("book", false); 52 op = new AccessorOperator("pages", op, false); 53 op = new IndexerOperator(new ConstantOperator(new Integer(0)), op, false); 54 op = new AccessorOperator("paragraphs", op, false); 55 op = new IndexerOperator(new ConstantOperator(new Integer(0)), op, false); 56 InvertibleOperator iop = new AccessorOperator("text", op, false); 57 iop.applyInverse(ctx, ctx, "Nuevo texto"); 58 assertEquals("Nuevo texto", iop.apply(ctx, ctx)); 59 iop.applyInverse(ctx, ctx, null); 60 assertEquals(null, iop.apply(ctx, ctx)); 61 } 62 63 public void testApply() throws EvaluationException { 64 // Probamos que obtenemos la primera página del libro 65 AccessorOperator bookAccessor = new AccessorOperator("book", false); 66 AccessorOperator pagesAccessor = new AccessorOperator("pages", bookAccessor, false); 67 IndexerOperator firstIndexer = new IndexerOperator(new ConstantOperator(new Integer(0)), pagesAccessor, false); 68 assertEquals(book.getPages().get(0), firstIndexer.apply(ctx, ctx)); 69 70 // Probamos que podemos anidar más allá del operador de indexación 71 AccessorOperator textAccessor = new AccessorOperator("text", firstIndexer, false); 72 assertEquals(textAccessor.apply(ctx, ctx), ((Page)book.getPages().get(0)).getText() ); 73 } 74 }

This page was automatically generated by Maven