@Test public void testPerRowAppendMapper() throws Exception { List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); data.add(Table.buildRow("foo", "bar")); // build a query that will just copy the PK field Query q2 = new AbstractQuery("idcopy", null) { @Override public void exec(RenderTask task) throws Exception { if (task instanceof RowRenderSubTask) { RowRenderSubTask subtask = (RowRenderSubTask) task; if (subtask.getRowIdx() >= 0) { task.add(Table.buildRow("idcopy", subtask.getParentRowKey())); } } } }; // regular three rows, but the second query is appended to each row ViewDef vd = new TestViewDef(); vd.addQuery(ViewDefSamples.sq1); vd.addQuery(new PerRowAppendMapper(new StaticQuery("foo", data))); vd.addQuery(new PerRowAppendMapper(q2)); // should append the queries to each other, totaling 3 rows with 7 columns apeice RenderTask q = runner.exec(vd).getAction(ViewRenderAction.class).getResults(); assertEquals(3, q.size()); assertEquals(7, q.getRowIdx(0).size()); assertEquals(7, q.getRowIdx(1).size()); assertEquals(7, q.getRowIdx(2).size()); // static data just gets added to each row assertEquals("bar", q.getCellIdx(0, "foo")); assertEquals("bar", q.getCellIdx(1, "foo")); assertEquals("bar", q.getCellIdx(2, "foo")); // q2 copies the PK assertEquals("1", q.getCellIdx(0, "idcopy")); assertEquals("2", q.getCellIdx(1, "idcopy")); assertEquals("3", q.getCellIdx(2, "idcopy")); }
@Test public void testNestedViewDefs() throws FrameInitException, FrameExecException { ViewDef def = new TestViewDef(); def.addQuery(new DataGeneratorQuery("id", "1st", 10, 5)); def.addQuery(new PerRowSubTableMapper("subview", vd)); // we expect the usual 10 rows // runner.setExecutor(null); FrameTask task = runner.exec(def); RenderTask results = task.getAction(ViewRenderAction.class).getResults(); assertEquals(10, results.size()); for (int i = 0; i < 10; i++) { // each one should have 1 column that can be verifyied as the standard results Map<String, Object> row = results.getRowIdx(i); assertTrue(row.containsKey("subview")); assertTrue(row.get("subview") instanceof RenderTask); RenderTask subview = (RenderTask) row.get("subview"); verify(subview); } }