Browse Source

Fixed tests by adding context configuration, swapping @MockitoSpyBean for @MockitoBean and adding missing dependencies.

Signed-off-by: Oleksandra Matviienko <al.zzzeebra@gmail.com>
pull/15487/head
Oleksandra Matviienko 4 months ago
parent
commit
e31d04956c
  1. 17
      application/src/test/java/org/thingsboard/server/service/device/provision/DeviceProvisionServiceTest.java
  2. 19
      application/src/test/java/org/thingsboard/server/service/queue/DefaultTbClusterServiceTest.java
  3. 24
      application/src/test/java/org/thingsboard/server/service/transport/DefaultTransportApiServiceTest.java

17
application/src/test/java/org/thingsboard/server/service/device/provision/DeviceProvisionServiceTest.java

@ -73,9 +73,24 @@ import static org.mockito.Mockito.when;
@Slf4j
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = DeviceProvisionServiceImpl.class)
@ContextConfiguration(classes = DeviceProvisionServiceTest.ContextConfiguration.class)
public class DeviceProvisionServiceTest {
@org.springframework.context.annotation.Configuration
static class ContextConfiguration {
@org.springframework.context.annotation.Bean
public DeviceProvisionServiceImpl deviceProvisionService(TbQueueProducerProvider producerProvider,
DeviceProfileService deviceProfileService,
DeviceService deviceService,
DeviceCredentialsService deviceCredentialsService,
AttributesService attributesService,
AuditLogService auditLogService,
PartitionService partitionService) {
return new DeviceProvisionServiceImpl(producerProvider, deviceProfileService, deviceService,
deviceCredentialsService, attributesService, auditLogService, partitionService);
}
}
@MockitoBean
protected TbQueueProducerProvider producerProvider;
@MockitoBean

19
application/src/test/java/org/thingsboard/server/service/queue/DefaultTbClusterServiceTest.java

@ -56,6 +56,7 @@ import org.thingsboard.server.queue.discovery.PartitionService;
import org.thingsboard.server.queue.discovery.TopicService;
import org.thingsboard.server.queue.provider.TbQueueProducerProvider;
import org.thingsboard.server.service.gateway_device.GatewayNotificationsService;
import org.thingsboard.server.service.ota.OtaPackageStateService;
import org.thingsboard.server.service.profile.TbAssetProfileCache;
import org.thingsboard.server.service.profile.TbDeviceProfileCache;
@ -67,6 +68,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@ -106,11 +108,26 @@ public class DefaultTbClusterServiceTest {
@MockitoBean
protected CalculatedFieldService calculatedFieldService;
@MockitoSpyBean
@MockitoBean
protected TopicService topicService;
@MockitoBean
protected OtaPackageStateService otaPackageStateService;
@MockitoSpyBean
protected TbClusterService clusterService;
@org.junit.Before
public void setUp() {
lenient().when(topicService.getNotificationsTopic(any(), any())).thenAnswer(invocation -> {
ServiceType serviceType = invocation.getArgument(0);
String serviceId = invocation.getArgument(1);
return new TopicPartitionInfo(serviceType.name().toLowerCase() + ".notifications." + serviceId, null, null, false);
});
lenient().when(topicService.getCalculatedFieldNotificationsTopic(any())).thenAnswer(invocation -> {
String serviceId = invocation.getArgument(0);
return new TopicPartitionInfo("calculated_field.notifications." + serviceId, null, null, false);
});
}
@Test
public void testOnQueueChangeSingleMonolith() {
when(partitionService.getAllServiceIds(ServiceType.TB_RULE_ENGINE)).thenReturn(Sets.newHashSet(MONOLITH));

24
application/src/test/java/org/thingsboard/server/service/transport/DefaultTransportApiServiceTest.java

@ -69,9 +69,31 @@ import static org.mockito.Mockito.when;
@Slf4j
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = DefaultTransportApiService.class)
@ContextConfiguration(classes = DefaultTransportApiServiceTest.ContextConfiguration.class)
public class DefaultTransportApiServiceTest {
@org.springframework.context.annotation.Configuration
static class ContextConfiguration {
@org.springframework.context.annotation.Bean
public DefaultTransportApiService defaultTransportApiService(TbDeviceProfileCache deviceProfileCache,
TbTenantProfileCache tenantProfileCache,
TbApiUsageStateService apiUsageStateService,
DeviceService deviceService,
DeviceProfileService deviceProfileService,
RelationService relationService,
DeviceCredentialsService deviceCredentialsService,
TbClusterService tbClusterService,
DeviceProvisionService deviceProvisionService,
ResourceService resourceService,
OtaPackageService otaPackageService,
OtaPackageDataCache otaPackageDataCache,
QueueService queueService) {
return new DefaultTransportApiService(deviceProfileCache, tenantProfileCache, apiUsageStateService,
deviceService, deviceProfileService, relationService, deviceCredentialsService, tbClusterService,
deviceProvisionService, resourceService, otaPackageService, otaPackageDataCache, queueService);
}
}
@MockitoBean
protected TbDeviceProfileCache deviceProfileCache;
@MockitoBean

Loading…
Cancel
Save