@Override public ExcelSink newOperator() { return new ExcelSink(this); }
@Override public void write(OutputStream output) throws IOException, WebApplicationException { byte[] data = Files.readAllBytes(excelSink.getFilePath()); output.write(data); output.flush(); } };
/** * Collects ALL the tuples to an in-memory list * also add all tuples into the excel file by calling this.getNextTuple * * @return a list of tuples * @throws TexeraException */ public List<Tuple> collectAllTuples() throws TexeraException { ArrayList<Tuple> results = new ArrayList<>(); Tuple tuple; while ((tuple = this.getNextTuple()) != null) { results.add(tuple); } return results; }
excelSink = new ExcelSink(new ExcelSinkPredicate()); excelSink.setInputOperator(inputOperator); excelSink.open(); excelSink.collectAllTuples(); excelSink.close(); Files.deleteIfExists(excelSink.getFilePath());
excelSink.setInputOperator(tupleSource); excelSink.open(); excelSink.collectAllTuples(); excelSink.close();
@Test public void testOpen() throws Exception { excelSink.open(); // // verify that inputOperator called open() method Mockito.verify(inputOperator).open(); // // assert that the tuple stream sink removes the _ID and PAYLOAD attribute Assert.assertEquals(new Schema(new Attribute("content", AttributeType.TEXT)), excelSink.getOutputSchema()); excelSink.close(); Files.deleteIfExists(excelSink.getFilePath()); }
@Test public void testClose() throws Exception { excelSink.open(); excelSink.close(); // verify that inputOperator called close() method Mockito.verify(inputOperator).close(); Files.deleteIfExists(excelSink.getFilePath()); }
@Before public void setUp() throws FileNotFoundException { inputOperator = Mockito.mock(IOperator.class); Mockito.when(inputOperator.getOutputSchema()).thenReturn(inputSchema); excelSink = new ExcelSink(new ExcelSinkPredicate()); excelSink.setInputOperator(inputOperator); }
writeCell(row.createCell(i), resultTuple.getField(outputSchema.getAttributeNames().get(i)));
Mockito.when(inputOperator.getNextTuple()).thenReturn(tuple1).thenReturn(tuple2).thenReturn(null); excelSink = new ExcelSink(new ExcelSinkPredicate()); excelSink.setInputOperator(inputOperator); excelSink.open(); excelSink.collectAllTuples(); excelSink.close(); Files.deleteIfExists(excelSink.getFilePath());