Github user JPercivall commented on a diff in the pull request:
https://github.com/apache/nifi/pull/237#discussion_r56237303
--- Diff:
nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-processors/src/test/java/org/apache/nifi/processors/cassandra/PutCassandraQLTest.java
---
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.cassandra;
+
+import com.datastax.driver.core.BoundStatement;
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Configuration;
+import com.datastax.driver.core.ConsistencyLevel;
+import com.datastax.driver.core.Metadata;
+import com.datastax.driver.core.PreparedStatement;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.ResultSetFuture;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.Statement;
+import com.datastax.driver.core.exceptions.InvalidQueryException;
+import com.datastax.driver.core.exceptions.NoHostAvailableException;
+import com.datastax.driver.core.exceptions.UnavailableException;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.net.ssl.SSLContext;
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Unit tests for the PutCassandraQL processor
+ */
+public class PutCassandraQLTest {
+
+ private TestRunner testRunner;
+ private MockPutCassandraQL processor;
+
+ @Before
+ public void setUp() throws Exception {
+ processor = new MockPutCassandraQL();
+ testRunner = TestRunners.newTestRunner(processor);
+ }
+
+ @Test
+ public void testProcessorConfigValidity() {
+ testRunner.setProperty(AbstractCassandraProcessor.CONTACT_POINTS,
"localhost:9042");
+ testRunner.assertValid();
+ testRunner.setProperty(AbstractCassandraProcessor.PASSWORD,
"password");
+ testRunner.assertNotValid();
+ testRunner.setProperty(AbstractCassandraProcessor.USERNAME,
"username");
+
testRunner.setProperty(AbstractCassandraProcessor.CONSISTENCY_LEVEL, "ONE");
+ testRunner.assertValid();
+ }
+
+ @Test
+ public void testProcessorHappyPath() {
+ setUpStandardTestConfig();
+
+ testRunner.run(1, true, true);
+
testRunner.assertAllFlowFilesTransferred(PutCassandraQL.REL_SUCCESS, 1);
+ testRunner.clearTransferState();
+ }
+
+ @Test
+ public void testProcessorInvalidQueryException() {
+ setUpStandardTestConfig();
+
+ // Test exceptions
+ processor.setExceptionToThrow(
+ new InvalidQueryException(new
InetSocketAddress("localhost", 9042), "invalid query"));
+ testRunner.enqueue("UPDATE users SET cities = [ 'New York', 'Los
Angeles' ] WHERE user_id = 'coast2coast';");
+ testRunner.run(1, true, true);
+
testRunner.assertAllFlowFilesTransferred(PutCassandraQL.REL_FAILURE, 1);
+ testRunner.clearTransferState();
+ }
+
+ @Test
+ public void testProcessorUnavailableException() {
+ setUpStandardTestConfig();
+
+ processor.setExceptionToThrow(
+ new UnavailableException(new
InetSocketAddress("localhost", 9042), ConsistencyLevel.ALL, 5, 2));
+ testRunner.enqueue("UPDATE users SET cities = [ 'New York', 'Los
Angeles' ] WHERE user_id = 'coast2coast';");
+ testRunner.run(1, true, true);
+ testRunner.assertAllFlowFilesTransferred(PutCassandraQL.REL_RETRY,
1);
+ }
+
+ @Test
+ public void testProcessorNoHostAvailableException() {
+ setUpStandardTestConfig();
+
+ processor.setExceptionToThrow(new NoHostAvailableException(new
HashMap<InetSocketAddress, Throwable>()));
+ testRunner.enqueue("UPDATE users SET cities = [ 'New York', 'Los
Angeles' ] WHERE user_id = 'coast2coast';");
+ testRunner.run(1, true, true);
+ testRunner.assertAllFlowFilesTransferred(PutCassandraQL.REL_RETRY,
1);
+ }
+
+ @Test
+ public void testProcessorProcessException() {
+ setUpStandardTestConfig();
+
+ processor.setExceptionToThrow(new ProcessException());
+ testRunner.enqueue("UPDATE users SET cities = [ 'New York', 'Los
Angeles' ] WHERE user_id = 'coast2coast';");
+ testRunner.run(1, true, true);
+
testRunner.assertAllFlowFilesTransferred(PutCassandraQL.REL_FAILURE, 1);
+ }
+
+ private void setUpStandardTestConfig() {
--- End diff --
In many tests "setUpStandardTestConfig" is used (enqueuing a flowfile),
then another flowfile is enqueued and then testRunner is only run once. The
second FlowFile is not needed.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---