Fix tests
This commit is contained in:
parent
c577b50e9d
commit
f69d1147a6
@ -15,16 +15,23 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.rules.flow;
|
package org.thingsboard.server.rules.flow;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.thingsboard.rule.engine.metadata.TbGetAttributesNodeConfiguration;
|
import org.thingsboard.rule.engine.metadata.TbGetAttributesNodeConfiguration;
|
||||||
import org.thingsboard.server.actors.ActorSystemContext;
|
import org.thingsboard.server.actors.ActorSystemContext;
|
||||||
import org.thingsboard.server.common.data.*;
|
import org.thingsboard.server.common.data.DataConstants;
|
||||||
|
import org.thingsboard.server.common.data.Device;
|
||||||
|
import org.thingsboard.server.common.data.Event;
|
||||||
|
import org.thingsboard.server.common.data.Tenant;
|
||||||
|
import org.thingsboard.server.common.data.User;
|
||||||
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry;
|
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry;
|
||||||
import org.thingsboard.server.common.data.kv.StringDataEntry;
|
import org.thingsboard.server.common.data.kv.StringDataEntry;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
@ -38,12 +45,14 @@ import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg;
|
|||||||
import org.thingsboard.server.common.msg.queue.TbMsgCallback;
|
import org.thingsboard.server.common.msg.queue.TbMsgCallback;
|
||||||
import org.thingsboard.server.controller.AbstractRuleEngineControllerTest;
|
import org.thingsboard.server.controller.AbstractRuleEngineControllerTest;
|
||||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
import org.thingsboard.server.dao.attributes.AttributesService;
|
||||||
|
import org.thingsboard.server.dao.event.EventService;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,8 +70,26 @@ public abstract class AbstractRuleEngineFlowIntegrationTest extends AbstractRule
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected AttributesService attributesService;
|
protected AttributesService attributesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected EventService eventService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void beforeTest() throws Exception {
|
public void beforeTest() throws Exception {
|
||||||
|
|
||||||
|
EventService spyEventService = spy(eventService);
|
||||||
|
|
||||||
|
Mockito.doAnswer((Answer<ListenableFuture<Void>>) invocation -> {
|
||||||
|
Object[] args = invocation.getArguments();
|
||||||
|
Event event = (Event) args[0];
|
||||||
|
ListenableFuture<Void> future = eventService.saveAsync(event);
|
||||||
|
try {
|
||||||
|
future.get();
|
||||||
|
} catch (Exception e) {}
|
||||||
|
return future;
|
||||||
|
}).when(spyEventService).saveAsync(Mockito.any(Event.class));
|
||||||
|
|
||||||
|
ReflectionTestUtils.setField(actorSystem, "eventService", spyEventService);
|
||||||
|
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
|
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
|
|||||||
@ -15,13 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.rules.lifecycle;
|
package org.thingsboard.server.rules.lifecycle;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.thingsboard.rule.engine.metadata.TbGetAttributesNodeConfiguration;
|
import org.thingsboard.rule.engine.metadata.TbGetAttributesNodeConfiguration;
|
||||||
import org.thingsboard.server.actors.ActorSystemContext;
|
import org.thingsboard.server.actors.ActorSystemContext;
|
||||||
import org.thingsboard.server.common.data.DataConstants;
|
import org.thingsboard.server.common.data.DataConstants;
|
||||||
@ -42,6 +45,7 @@ import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg;
|
|||||||
import org.thingsboard.server.common.msg.queue.TbMsgCallback;
|
import org.thingsboard.server.common.msg.queue.TbMsgCallback;
|
||||||
import org.thingsboard.server.controller.AbstractRuleEngineControllerTest;
|
import org.thingsboard.server.controller.AbstractRuleEngineControllerTest;
|
||||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
import org.thingsboard.server.dao.attributes.AttributesService;
|
||||||
|
import org.thingsboard.server.dao.event.EventService;
|
||||||
import org.thingsboard.server.queue.memory.InMemoryStorage;
|
import org.thingsboard.server.queue.memory.InMemoryStorage;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -50,6 +54,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.awaitility.Awaitility.await;
|
import static org.awaitility.Awaitility.await;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,8 +72,26 @@ public abstract class AbstractRuleEngineLifecycleIntegrationTest extends Abstrac
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected AttributesService attributesService;
|
protected AttributesService attributesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected EventService eventService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void beforeTest() throws Exception {
|
public void beforeTest() throws Exception {
|
||||||
|
|
||||||
|
EventService spyEventService = spy(eventService);
|
||||||
|
|
||||||
|
Mockito.doAnswer((Answer<ListenableFuture<Void>>) invocation -> {
|
||||||
|
Object[] args = invocation.getArguments();
|
||||||
|
Event event = (Event) args[0];
|
||||||
|
ListenableFuture<Void> future = eventService.saveAsync(event);
|
||||||
|
try {
|
||||||
|
future.get();
|
||||||
|
} catch (Exception e) {}
|
||||||
|
return future;
|
||||||
|
}).when(spyEventService).saveAsync(Mockito.any(Event.class));
|
||||||
|
|
||||||
|
ReflectionTestUtils.setField(actorSystem, "eventService", spyEventService);
|
||||||
|
|
||||||
loginSysAdmin();
|
loginSysAdmin();
|
||||||
|
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user