refactored tests
This commit is contained in:
parent
ada9f8b7eb
commit
00251f11b1
@ -25,6 +25,7 @@ import com.datastax.oss.driver.api.core.metadata.Node;
|
|||||||
import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry;
|
import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -95,10 +96,14 @@ public class TbSaveToCustomCassandraTableNodeTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Node nodeMock;
|
private Node nodeMock;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
node = spy(new TbSaveToCustomCassandraTableNode());
|
||||||
|
config = new TbSaveToCustomCassandraTableNodeConfiguration().defaultConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenCassandraClusterIsMissing_whenInit_thenThrowsException() {
|
void givenCassandraClusterIsMissing_whenInit_thenThrowsException() {
|
||||||
node = new TbSaveToCustomCassandraTableNode();
|
|
||||||
config = new TbSaveToCustomCassandraTableNodeConfiguration().defaultConfiguration();
|
|
||||||
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
||||||
assertThatThrownBy(() -> node.init(ctxMock, configuration))
|
assertThatThrownBy(() -> node.init(ctxMock, configuration))
|
||||||
.isInstanceOf(RuntimeException.class)
|
.isInstanceOf(RuntimeException.class)
|
||||||
@ -107,8 +112,6 @@ public class TbSaveToCustomCassandraTableNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenFieldsMapIsEmpty_whenInit_thenThrowsException() {
|
void givenFieldsMapIsEmpty_whenInit_thenThrowsException() {
|
||||||
node = new TbSaveToCustomCassandraTableNode();
|
|
||||||
config = new TbSaveToCustomCassandraTableNodeConfiguration().defaultConfiguration();
|
|
||||||
config.setFieldsMapping(emptyMap());
|
config.setFieldsMapping(emptyMap());
|
||||||
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
||||||
|
|
||||||
@ -121,8 +124,6 @@ public class TbSaveToCustomCassandraTableNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenInvalidMessageStructure_whenOnMsg_thenThrowsException() throws TbNodeException {
|
void givenInvalidMessageStructure_whenOnMsg_thenThrowsException() throws TbNodeException {
|
||||||
node = new TbSaveToCustomCassandraTableNode();
|
|
||||||
config = new TbSaveToCustomCassandraTableNodeConfiguration().defaultConfiguration();
|
|
||||||
config.setTableName("temperature_sensor");
|
config.setTableName("temperature_sensor");
|
||||||
config.setFieldsMapping(Map.of("temp", "temperature"));
|
config.setFieldsMapping(Map.of("temp", "temperature"));
|
||||||
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
||||||
@ -131,8 +132,7 @@ public class TbSaveToCustomCassandraTableNodeTest {
|
|||||||
|
|
||||||
node.init(ctxMock, configuration);
|
node.init(ctxMock, configuration);
|
||||||
|
|
||||||
String data = "";
|
TbMsg msg = TbMsg.newMsg(TbMsgType.POST_TELEMETRY_REQUEST, DEVICE_ID, TbMsgMetaData.EMPTY, TbMsg.EMPTY_STRING);
|
||||||
TbMsg msg = TbMsg.newMsg(TbMsgType.POST_TELEMETRY_REQUEST, DEVICE_ID, TbMsgMetaData.EMPTY, data);
|
|
||||||
|
|
||||||
assertThatThrownBy(() -> node.onMsg(ctxMock, msg))
|
assertThatThrownBy(() -> node.onMsg(ctxMock, msg))
|
||||||
.isInstanceOf(IllegalStateException.class)
|
.isInstanceOf(IllegalStateException.class)
|
||||||
@ -141,8 +141,6 @@ public class TbSaveToCustomCassandraTableNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenDataKeyIsMissingInMsg_whenOnMsg_thenThrowsException() throws TbNodeException {
|
void givenDataKeyIsMissingInMsg_whenOnMsg_thenThrowsException() throws TbNodeException {
|
||||||
node = new TbSaveToCustomCassandraTableNode();
|
|
||||||
config = new TbSaveToCustomCassandraTableNodeConfiguration().defaultConfiguration();
|
|
||||||
config.setTableName("temperature_sensor");
|
config.setTableName("temperature_sensor");
|
||||||
config.setFieldsMapping(Map.of("temp", "temperature"));
|
config.setFieldsMapping(Map.of("temp", "temperature"));
|
||||||
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
||||||
@ -171,8 +169,6 @@ public class TbSaveToCustomCassandraTableNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenUnsupportedData_whenOnMsg_thenThrowsException() throws TbNodeException {
|
void givenUnsupportedData_whenOnMsg_thenThrowsException() throws TbNodeException {
|
||||||
node = new TbSaveToCustomCassandraTableNode();
|
|
||||||
config = new TbSaveToCustomCassandraTableNodeConfiguration().defaultConfiguration();
|
|
||||||
config.setTableName("temperature_sensor");
|
config.setTableName("temperature_sensor");
|
||||||
config.setFieldsMapping(Map.of("temp", "temperature"));
|
config.setFieldsMapping(Map.of("temp", "temperature"));
|
||||||
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
||||||
@ -203,8 +199,6 @@ public class TbSaveToCustomCassandraTableNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenValidMsgStructure_whenOnMsg_thenOk() throws Exception {
|
void givenValidMsgStructure_whenOnMsg_thenOk() throws Exception {
|
||||||
node = spy(new TbSaveToCustomCassandraTableNode());
|
|
||||||
config = new TbSaveToCustomCassandraTableNodeConfiguration().defaultConfiguration();
|
|
||||||
config.setTableName("temperature_sensor");
|
config.setTableName("temperature_sensor");
|
||||||
config.setFieldsMapping(Map.of("temp", "temperature"));
|
config.setFieldsMapping(Map.of("temp", "temperature"));
|
||||||
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
var configuration = new TbNodeConfiguration(JacksonUtil.valueToTree(config));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user