@Override public ExcelSink newOperator() { return new ExcelSink(this); }
/** * 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; }
@Override public void write(OutputStream output) throws IOException, WebApplicationException { byte[] data = Files.readAllBytes(excelSink.getFilePath()); output.write(data); output.flush(); } };
List<Tuple> tupleList = new ArrayList<Tuple>(); for(int i = 0; i < testSize; i++){ IField[] fields = { new StringField(getRandomString()), new StringField(getRandomString()), new IntegerField(rand.nextInt()), new DoubleField(rand.nextDouble()*rand.nextInt()), new DateField(getRandomDate()), new TextField(getRandomString())}; tupleList.add(new Tuple(new Schema(schemaAttributes), fields)); excelSink = new ExcelSink(new ExcelSinkPredicate()); excelSink.setInputOperator(inputOperator); excelSink.open(); excelSink.collectAllTuples(); excelSink.close(); Files.deleteIfExists(excelSink.getFilePath());
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());
ExcelSink excelSink = new ExcelSinkPredicate().newOperator(); 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()); }
@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); }
@Test public void testClose() throws Exception { excelSink.open(); excelSink.close(); // verify that inputOperator called close() method Mockito.verify(inputOperator).close(); Files.deleteIfExists(excelSink.getFilePath()); }
@Test public void testExcelSink() throws Exception { ExcelSinkPredicate excelSinkPredicate = new ExcelSinkPredicate(10, 10); testPredicate(excelSinkPredicate); }