WordCloudSink extends VisualizationOperator { @Override public void open() throws TexeraException { if (cursor != CLOSED) { return; } if (inputOperator == null) { throw new TexeraException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED); } inputOperator.open(); this.addPayload = ! inputOperator.getOutputSchema().containsAttribute(SchemaConstants.PAYLOAD); Schema schema = inputOperator.getOutputSchema(); Attribute textColumn = schema.getAttribute(predicate.getAttribute()); AttributeType nameColumnType = textColumn.getType(); if (!nameColumnType.equals(AttributeType.TEXT)) { throw new DataflowException("Type of name column should be text."); } outputSchema = new Schema.Builder().add(new Attribute("word", AttributeType.STRING), new Attribute("count", AttributeType.INTEGER)) .build(); cursor = OPENED; } WordCloudSink(WordCloudSinkPredicate predicate); @Override void open(); List<Map.Entry<String, Integer>> wordCount(); @Override void processTuples();  }
@Test public void test1() { TupleSourceOperator tupleSource = new TupleSourceOperator(WordCloudSinkTestConstants.getTuples(), WordCloudSinkTestConstants.WORD_CLOUD_SCHEMA); WordCloudSink wordCloudSink = new WordCloudSink(new WordCloudSinkPredicate(WordCloudSinkTestConstants.ATTRIBUTE_NAME_ONE, WordCloudSinkTestConstants.ANALYZER_TYPE)); wordCloudSink.setInputOperator(tupleSource); wordCloudSink.open(); List<Tuple> resultTuples = wordCloudSink.collectAllTuples(); assertTrue(TestUtils.equals(WordCloudSinkTestConstants.getResultTuples(), resultTuples)); }
@Test(expected = TexeraException.class) public void test2() { TupleSourceOperator tupleSource = new TupleSourceOperator(WordCloudSinkTestConstants.getTuples(), WordCloudSinkTestConstants.WORD_CLOUD_SCHEMA); WordCloudSink wordCloudSink = new WordCloudSink(new WordCloudSinkPredicate("w", WordCloudSinkTestConstants.ANALYZER_TYPE)); wordCloudSink.setInputOperator(tupleSource); wordCloudSink.open(); List<Tuple> resultTuples = wordCloudSink.collectAllTuples(); assertTrue(TestUtils.equals(WordCloudSinkTestConstants.getResultTuples(), resultTuples)); }
@Test(expected = TexeraException.class) public void test3() { TupleSourceOperator tupleSource = new TupleSourceOperator(WordCloudSinkTestConstants.getTuples(), WordCloudSinkTestConstants.WORD_CLOUD_SCHEMA); WordCloudSink wordCloudSink = new WordCloudSink(new WordCloudSinkPredicate("count", WordCloudSinkTestConstants.ANALYZER_TYPE)); wordCloudSink.setInputOperator(tupleSource); wordCloudSink.open(); List<Tuple> resultTuples = wordCloudSink.collectAllTuples(); TestUtils.equals(BarChartSinkTestConstants.getResultTuples(), resultTuples); }