mirror of
https://gitee.com/pnoker/iot-dc3.git
synced 2026-09-01 15:33:10 +08:00
test: align tests with enum rename and fix pre-existing failures
- Update test references to the renamed *TypeEnum/RuleStatusEnum. - Add the new builder/PermissionProvider constructor args to the affected service-impl test setups. - Fix pre-existing failures unrelated to this work: String-vs-Long assertions (DriverStatusServiceImplTest), save->saveBatch (EntityStateExpiryScannerTest), List.of(null) NPE (AlarmRulePipelineServiceImplTest), and the cache/batch refactor expectations (PointValueServiceImplTest).
This commit is contained in:
+2
-2
@@ -19,7 +19,7 @@ package io.github.pnoker.common.agentic.tools;
|
||||
import io.github.pnoker.common.agentic.entity.model.AgenticToolResult;
|
||||
import io.github.pnoker.common.constant.service.AgenticConstant;
|
||||
import io.github.pnoker.common.entity.common.RequestHeader;
|
||||
import io.github.pnoker.common.enums.DriverTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.DriverTypeEnum;
|
||||
import io.github.pnoker.common.enums.EnableFlagEnum;
|
||||
import io.github.pnoker.common.facade.api.DriverFacade;
|
||||
import io.github.pnoker.common.facade.api.StatusHealthFacade;
|
||||
@@ -116,7 +116,7 @@ class DriverToolTest {
|
||||
driver.setDriverCode("virtual-edge-acceptance-lab");
|
||||
driver.setServiceName("dc3-driver-virtual");
|
||||
driver.setServiceHost("dc3-driver-virtual.iot.svc");
|
||||
driver.setDriverTypeFlag(DriverTypeFlagEnum.DRIVER_CLIENT);
|
||||
driver.setDriverTypeFlag(DriverTypeEnum.DRIVER_CLIENT);
|
||||
driver.setEnableFlag(EnableFlagEnum.ENABLE);
|
||||
driver.setTenantId(11L);
|
||||
return driver;
|
||||
|
||||
+19
-19
@@ -51,37 +51,37 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class IndexedEnumContractTest {
|
||||
|
||||
private static final List<Class<? extends Enum<?>>> INDEXED_ENUMS = List.of(
|
||||
AccrueFlagEnum.class,
|
||||
AccrueTypeEnum.class,
|
||||
AgenticActionStatusEnum.class,
|
||||
AgenticMessageStatusEnum.class,
|
||||
AgenticModelProviderTypeEnum.class,
|
||||
AlarmMessageLevelFlagEnum.class,
|
||||
AlarmSourceFlagEnum.class,
|
||||
AlarmTargetTypeFlagEnum.class,
|
||||
AlarmTypeFlagEnum.class,
|
||||
ApiTypeFlagEnum.class,
|
||||
AttributeTypeFlagEnum.class,
|
||||
AlarmMessageLevelEnum.class,
|
||||
AlarmSourceTypeEnum.class,
|
||||
AlarmTargetTypeEnum.class,
|
||||
AlarmTypeEnum.class,
|
||||
ApiTypeEnum.class,
|
||||
AttributeTypeEnum.class,
|
||||
AutoConfirmFlagEnum.class,
|
||||
DefaultFlagEnum.class,
|
||||
PointCommandTypeEnum.class,
|
||||
EntityStatusEnum.class,
|
||||
DriverTypeFlagEnum.class,
|
||||
DriverTypeEnum.class,
|
||||
EnableFlagEnum.class,
|
||||
EntityTypeFlagEnum.class,
|
||||
ExpireFlagEnum.class,
|
||||
MenuLevelFlagEnum.class,
|
||||
EntityTypeEnum.class,
|
||||
ExpireTypeEnum.class,
|
||||
MenuLevelEnum.class,
|
||||
MenuTypeFlagEnum.class,
|
||||
MetadataOperateTypeEnum.class,
|
||||
MetadataTypeEnum.class,
|
||||
NotifyChannelTypeFlagEnum.class,
|
||||
NotifyChannelTypeEnum.class,
|
||||
NotifyHistoryStatusEnum.class,
|
||||
PointTypeFlagEnum.class,
|
||||
ProfileShareFlagEnum.class,
|
||||
ProfileTypeFlagEnum.class,
|
||||
ResourceScopeFlagEnum.class,
|
||||
ResourceTypeFlagEnum.class,
|
||||
RuleStateFlagEnum.class,
|
||||
RwFlagEnum.class);
|
||||
PointTypeEnum.class,
|
||||
ProfileShareTypeEnum.class,
|
||||
ProfileTypeEnum.class,
|
||||
ResourceScopeTypeEnum.class,
|
||||
ResourceTypeEnum.class,
|
||||
RuleStatusEnum.class,
|
||||
RwTypeEnum.class);
|
||||
|
||||
private static Method method(Class<?> type, String name, Class<?>... parameterTypes) {
|
||||
try {
|
||||
|
||||
+16
-16
@@ -17,7 +17,7 @@
|
||||
|
||||
package io.github.pnoker.common.data.biz.alarm;
|
||||
|
||||
import io.github.pnoker.common.enums.AlarmMessageLevelFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmMessageLevelEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -26,34 +26,34 @@ class AlarmLevelResolverTest {
|
||||
|
||||
@Test
|
||||
void resolvesUpperCaseSeverityName() {
|
||||
assertThat(AlarmLevelResolver.resolve("P0", AlarmMessageLevelFlagEnum.P2)).isEqualTo(AlarmMessageLevelFlagEnum.P0);
|
||||
assertThat(AlarmLevelResolver.resolve("P1", AlarmMessageLevelFlagEnum.P2)).isEqualTo(AlarmMessageLevelFlagEnum.P1);
|
||||
assertThat(AlarmLevelResolver.resolve("P2", AlarmMessageLevelFlagEnum.P2)).isEqualTo(AlarmMessageLevelFlagEnum.P2);
|
||||
assertThat(AlarmLevelResolver.resolve("P3", AlarmMessageLevelFlagEnum.P2)).isEqualTo(AlarmMessageLevelFlagEnum.P3);
|
||||
assertThat(AlarmLevelResolver.resolve("P0", AlarmMessageLevelEnum.P2)).isEqualTo(AlarmMessageLevelEnum.P0);
|
||||
assertThat(AlarmLevelResolver.resolve("P1", AlarmMessageLevelEnum.P2)).isEqualTo(AlarmMessageLevelEnum.P1);
|
||||
assertThat(AlarmLevelResolver.resolve("P2", AlarmMessageLevelEnum.P2)).isEqualTo(AlarmMessageLevelEnum.P2);
|
||||
assertThat(AlarmLevelResolver.resolve("P3", AlarmMessageLevelEnum.P2)).isEqualTo(AlarmMessageLevelEnum.P3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesLowerCaseSeverityCode() {
|
||||
assertThat(AlarmLevelResolver.resolve("p0", AlarmMessageLevelFlagEnum.P2)).isEqualTo(AlarmMessageLevelFlagEnum.P0);
|
||||
assertThat(AlarmLevelResolver.resolve("p3", AlarmMessageLevelFlagEnum.P2)).isEqualTo(AlarmMessageLevelFlagEnum.P3);
|
||||
assertThat(AlarmLevelResolver.resolve("p0", AlarmMessageLevelEnum.P2)).isEqualTo(AlarmMessageLevelEnum.P0);
|
||||
assertThat(AlarmLevelResolver.resolve("p3", AlarmMessageLevelEnum.P2)).isEqualTo(AlarmMessageLevelEnum.P3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalizesWhitespaceAndMixedCase() {
|
||||
assertThat(AlarmLevelResolver.resolve(" p1 ", AlarmMessageLevelFlagEnum.P2)).isEqualTo(AlarmMessageLevelFlagEnum.P1);
|
||||
assertThat(AlarmLevelResolver.resolve("Critical", AlarmMessageLevelFlagEnum.P2))
|
||||
assertThat(AlarmLevelResolver.resolve(" p1 ", AlarmMessageLevelEnum.P2)).isEqualTo(AlarmMessageLevelEnum.P1);
|
||||
assertThat(AlarmLevelResolver.resolve("Critical", AlarmMessageLevelEnum.P2))
|
||||
.as("unrecognized labels fall back to the supplied default")
|
||||
.isEqualTo(AlarmMessageLevelFlagEnum.P2);
|
||||
.isEqualTo(AlarmMessageLevelEnum.P2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void usesFallbackWhenSeverityIsBlankOrNull() {
|
||||
assertThat(AlarmLevelResolver.resolve(null, AlarmMessageLevelFlagEnum.P2))
|
||||
.isEqualTo(AlarmMessageLevelFlagEnum.P2);
|
||||
assertThat(AlarmLevelResolver.resolve("", AlarmMessageLevelFlagEnum.P3))
|
||||
.isEqualTo(AlarmMessageLevelFlagEnum.P3);
|
||||
assertThat(AlarmLevelResolver.resolve(" ", AlarmMessageLevelFlagEnum.P0))
|
||||
.isEqualTo(AlarmMessageLevelFlagEnum.P0);
|
||||
assertThat(AlarmLevelResolver.resolve(null, AlarmMessageLevelEnum.P2))
|
||||
.isEqualTo(AlarmMessageLevelEnum.P2);
|
||||
assertThat(AlarmLevelResolver.resolve("", AlarmMessageLevelEnum.P3))
|
||||
.isEqualTo(AlarmMessageLevelEnum.P3);
|
||||
assertThat(AlarmLevelResolver.resolve(" ", AlarmMessageLevelEnum.P0))
|
||||
.isEqualTo(AlarmMessageLevelEnum.P0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-13
@@ -19,7 +19,7 @@ package io.github.pnoker.common.data.biz.alarm;
|
||||
|
||||
import io.github.pnoker.common.data.entity.bo.NotifyHistoryBO;
|
||||
import io.github.pnoker.common.data.entity.bo.RuleBO;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -27,6 +27,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -55,7 +56,7 @@ class AlarmRulePipelineServiceImplTest {
|
||||
|
||||
// ---------- fixtures ----------
|
||||
|
||||
private static RuleFact fact(Long tenantId, AlarmTargetTypeFlagEnum targetType, Long entityId) {
|
||||
private static RuleFact fact(Long tenantId, AlarmTargetTypeEnum targetType, Long entityId) {
|
||||
return new RuleFact(tenantId, targetType, entityId, null,
|
||||
LocalDateTime.of(2026, 5, 21, 12, 0), Map.of("value", 100));
|
||||
}
|
||||
@@ -76,7 +77,7 @@ class AlarmRulePipelineServiceImplTest {
|
||||
|
||||
@Test
|
||||
void processEvaluatesRuleEngineAndNotifies() {
|
||||
RuleFact fact = fact(7L, AlarmTargetTypeFlagEnum.POINT, 11L);
|
||||
RuleFact fact = fact(7L, AlarmTargetTypeEnum.POINT, 11L);
|
||||
RuleMatch m = match(fact);
|
||||
when(ruleEngine.evaluate(fact)).thenReturn(List.of(m));
|
||||
when(ruleNotificationService.notify(m)).thenReturn(List.of(history(1L)));
|
||||
@@ -90,7 +91,7 @@ class AlarmRulePipelineServiceImplTest {
|
||||
|
||||
@Test
|
||||
void processReturnsEmptyWhenNoRulesMatch() {
|
||||
RuleFact fact = fact(7L, AlarmTargetTypeFlagEnum.POINT, 11L);
|
||||
RuleFact fact = fact(7L, AlarmTargetTypeEnum.POINT, 11L);
|
||||
when(ruleEngine.evaluate(fact)).thenReturn(List.of());
|
||||
|
||||
List<NotifyHistoryBO> result = service.process(fact);
|
||||
@@ -111,13 +112,13 @@ class AlarmRulePipelineServiceImplTest {
|
||||
|
||||
@Test
|
||||
void processBatchFiltersNullFactsAndFactsWithNullTenantIdOrTargetType() {
|
||||
List<RuleFact> facts = List.of(
|
||||
List<RuleFact> facts = Arrays.asList(
|
||||
null,
|
||||
fact(7L, (AlarmTargetTypeFlagEnum) null, 11L), // null target type
|
||||
fact(null, AlarmTargetTypeFlagEnum.POINT, 11L), // null tenantId
|
||||
fact(7L, AlarmTargetTypeFlagEnum.POINT, 11L)); // valid
|
||||
fact(7L, (AlarmTargetTypeEnum) null, 11L), // null target type
|
||||
fact(null, AlarmTargetTypeEnum.POINT, 11L), // null tenantId
|
||||
fact(7L, AlarmTargetTypeEnum.POINT, 11L)); // valid
|
||||
|
||||
RuleMatch m = match(fact(7L, AlarmTargetTypeFlagEnum.POINT, 11L));
|
||||
RuleMatch m = match(fact(7L, AlarmTargetTypeEnum.POINT, 11L));
|
||||
when(ruleEngine.evaluate(any())).thenReturn(List.of(m));
|
||||
when(ruleNotificationService.notifyBatch(anyList())).thenReturn(List.of(history(1L)));
|
||||
|
||||
@@ -133,9 +134,9 @@ class AlarmRulePipelineServiceImplTest {
|
||||
@Test
|
||||
void processBatchGroupsFactsByRuleCacheKeyAndCallsNotifyBatchOnce() {
|
||||
// 3 facts: two share the same group, one is in a different group
|
||||
RuleFact f1 = fact(7L, AlarmTargetTypeFlagEnum.POINT, 11L);
|
||||
RuleFact f2 = fact(7L, AlarmTargetTypeFlagEnum.POINT, 11L); // same group as f1
|
||||
RuleFact f3 = fact(7L, AlarmTargetTypeFlagEnum.POINT, 22L); // different entity
|
||||
RuleFact f1 = fact(7L, AlarmTargetTypeEnum.POINT, 11L);
|
||||
RuleFact f2 = fact(7L, AlarmTargetTypeEnum.POINT, 11L); // same group as f1
|
||||
RuleFact f3 = fact(7L, AlarmTargetTypeEnum.POINT, 22L); // different entity
|
||||
|
||||
RuleMatch m1 = match(f1);
|
||||
RuleMatch m2 = match(f2);
|
||||
@@ -158,7 +159,7 @@ class AlarmRulePipelineServiceImplTest {
|
||||
|
||||
@Test
|
||||
void processBatchReturnsEmptyWhenNoMatchesProduced() {
|
||||
RuleFact fact = fact(7L, AlarmTargetTypeFlagEnum.POINT, 11L);
|
||||
RuleFact fact = fact(7L, AlarmTargetTypeEnum.POINT, 11L);
|
||||
when(ruleEngine.evaluate(fact)).thenReturn(List.of());
|
||||
|
||||
List<NotifyHistoryBO> result = service.processBatch(List.of(fact));
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@ package io.github.pnoker.common.data.biz.alarm;
|
||||
|
||||
import io.github.pnoker.common.data.entity.bo.MessageBO;
|
||||
import io.github.pnoker.common.entity.ext.MessageExt;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -35,7 +35,7 @@ class MessageRenderServiceImplTest {
|
||||
void rendersStructuredTemplateForSelectedChannel() {
|
||||
MessageBO message = message();
|
||||
|
||||
MessagePayload payload = service.render(message, NotifyChannelTypeFlagEnum.FEISHU_BOT, Map.of(
|
||||
MessagePayload payload = service.render(message, NotifyChannelTypeEnum.FEISHU_BOT, Map.of(
|
||||
"severity", "P1",
|
||||
"deviceName", "Line A PLC",
|
||||
"value", 86.5,
|
||||
@@ -51,7 +51,7 @@ class MessageRenderServiceImplTest {
|
||||
void keepsUnknownPlaceholdersAndReportsMissingVariables() {
|
||||
MessageBO message = message();
|
||||
|
||||
MessagePayload payload = service.render(message, NotifyChannelTypeFlagEnum.FEISHU_BOT, Map.of(
|
||||
MessagePayload payload = service.render(message, NotifyChannelTypeEnum.FEISHU_BOT, Map.of(
|
||||
"severity", "P1",
|
||||
"deviceName", "Line A PLC"));
|
||||
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ import io.github.pnoker.common.data.entity.model.MessageDO;
|
||||
import io.github.pnoker.common.data.entity.model.NotifyChannelDO;
|
||||
import io.github.pnoker.common.data.entity.model.NotifyDO;
|
||||
import io.github.pnoker.common.data.entity.property.AlarmCacheProperties;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -127,7 +127,7 @@ class NotifyConfigCacheTest {
|
||||
when(notifyChannelManager.getById(3L)).thenReturn(entity);
|
||||
NotifyChannelBO bo = new NotifyChannelBO();
|
||||
bo.setTenantId(7L);
|
||||
bo.setChannelTypeFlag(NotifyChannelTypeFlagEnum.FEISHU_BOT);
|
||||
bo.setChannelTypeFlag(NotifyChannelTypeEnum.FEISHU_BOT);
|
||||
when(notifyChannelBuilder.buildBOByDO(entity)).thenReturn(bo);
|
||||
|
||||
// Same tenant id → return; different tenant id → null even on cache hit.
|
||||
|
||||
+13
-13
@@ -26,7 +26,7 @@ import io.github.pnoker.common.data.entity.model.NotifyChannelDO;
|
||||
import io.github.pnoker.common.data.entity.model.NotifyHistoryDO;
|
||||
import io.github.pnoker.common.entity.dto.NotifyTaskDTO;
|
||||
import io.github.pnoker.common.enums.EnableFlagEnum;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeEnum;
|
||||
import io.github.pnoker.common.enums.NotifyHistoryStatusEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -83,7 +83,7 @@ class NotifyWorkerTest {
|
||||
.notifyHistoryId(50L)
|
||||
.tenantId(7L)
|
||||
.channelId(2L)
|
||||
.channelTypeFlag(NotifyChannelTypeFlagEnum.WEBHOOK.getIndex())
|
||||
.channelTypeFlag(NotifyChannelTypeEnum.WEBHOOK.getIndex())
|
||||
.payloadType("webhook-json")
|
||||
.payload(Map.of("title", "test"))
|
||||
.retryCount(retry)
|
||||
@@ -97,7 +97,7 @@ class NotifyWorkerTest {
|
||||
message = new Message(new byte[0], props);
|
||||
}
|
||||
|
||||
private void stubChannel(boolean enabled, NotifyChannelTypeFlagEnum type) {
|
||||
private void stubChannel(boolean enabled, NotifyChannelTypeEnum type) {
|
||||
NotifyChannelDO entityDO = new NotifyChannelDO();
|
||||
entityDO.setId(2L);
|
||||
entityDO.setTenantId(7L);
|
||||
@@ -114,8 +114,8 @@ class NotifyWorkerTest {
|
||||
|
||||
@Test
|
||||
void marksHistorySuccessAndAcksOnSuccess() throws Exception {
|
||||
stubChannel(true, NotifyChannelTypeFlagEnum.WEBHOOK);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeFlagEnum.WEBHOOK)).thenReturn(Optional.of(adapter));
|
||||
stubChannel(true, NotifyChannelTypeEnum.WEBHOOK);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeEnum.WEBHOOK)).thenReturn(Optional.of(adapter));
|
||||
when(adapter.send(any(), any())).thenReturn(NotifySendResult.success("https://hook", 200, "OK", Map.of()));
|
||||
|
||||
worker.onNotifyTask(channel, message, task(0));
|
||||
@@ -130,8 +130,8 @@ class NotifyWorkerTest {
|
||||
|
||||
@Test
|
||||
void requeuesAsRetryingOnFirstFailure() throws Exception {
|
||||
stubChannel(true, NotifyChannelTypeFlagEnum.WEBHOOK);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeFlagEnum.WEBHOOK)).thenReturn(Optional.of(adapter));
|
||||
stubChannel(true, NotifyChannelTypeEnum.WEBHOOK);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeEnum.WEBHOOK)).thenReturn(Optional.of(adapter));
|
||||
when(adapter.send(any(), any())).thenReturn(NotifySendResult.failed("https://hook", "503"));
|
||||
|
||||
worker.onNotifyTask(channel, message, task(0));
|
||||
@@ -149,8 +149,8 @@ class NotifyWorkerTest {
|
||||
|
||||
@Test
|
||||
void terminatesAsFailedAfterMaxAttempts() throws Exception {
|
||||
stubChannel(true, NotifyChannelTypeFlagEnum.WEBHOOK);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeFlagEnum.WEBHOOK)).thenReturn(Optional.of(adapter));
|
||||
stubChannel(true, NotifyChannelTypeEnum.WEBHOOK);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeEnum.WEBHOOK)).thenReturn(Optional.of(adapter));
|
||||
when(adapter.send(any(), any())).thenReturn(NotifySendResult.failed("https://hook", "503"));
|
||||
|
||||
// retry already at MAX_ATTEMPTS - 1; one more failure should terminate.
|
||||
@@ -165,7 +165,7 @@ class NotifyWorkerTest {
|
||||
|
||||
@Test
|
||||
void marksHistorySkippedWhenChannelDisabled() throws Exception {
|
||||
stubChannel(false, NotifyChannelTypeFlagEnum.WEBHOOK);
|
||||
stubChannel(false, NotifyChannelTypeEnum.WEBHOOK);
|
||||
|
||||
worker.onNotifyTask(channel, message, task(0));
|
||||
|
||||
@@ -187,12 +187,12 @@ class NotifyWorkerTest {
|
||||
|
||||
@Test
|
||||
void marksHistoryFailedWhenAdapterMissing() throws Exception {
|
||||
stubChannel(true, NotifyChannelTypeFlagEnum.FEISHU_BOT);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeFlagEnum.FEISHU_BOT)).thenReturn(Optional.empty());
|
||||
stubChannel(true, NotifyChannelTypeEnum.FEISHU_BOT);
|
||||
when(notifyChannelAdapterRegistry.find(NotifyChannelTypeEnum.FEISHU_BOT)).thenReturn(Optional.empty());
|
||||
|
||||
worker.onNotifyTask(channel, message, NotifyTaskDTO.builder()
|
||||
.notifyHistoryId(50L).tenantId(7L).channelId(2L)
|
||||
.channelTypeFlag(NotifyChannelTypeFlagEnum.FEISHU_BOT.getIndex())
|
||||
.channelTypeFlag(NotifyChannelTypeEnum.FEISHU_BOT.getIndex())
|
||||
.build());
|
||||
|
||||
ArgumentCaptor<NotifyHistoryDO> captor = ArgumentCaptor.forClass(NotifyHistoryDO.class);
|
||||
|
||||
+7
-7
@@ -22,8 +22,8 @@ import io.github.pnoker.common.data.dal.EntityAlarmManager;
|
||||
import io.github.pnoker.common.data.entity.bo.RuleBO;
|
||||
import io.github.pnoker.common.data.entity.model.EntityAlarmDO;
|
||||
import io.github.pnoker.common.entity.ext.RuleExt;
|
||||
import io.github.pnoker.common.enums.AlarmMessageLevelFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmMessageLevelEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -60,7 +60,7 @@ class RuleAlarmPersistenceServiceImplTest {
|
||||
bo.setId(id);
|
||||
bo.setRuleCode("rule-" + id);
|
||||
bo.setRuleName("rule-" + id);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT);
|
||||
RuleExt ext = new RuleExt();
|
||||
RuleExt.Content content = new RuleExt.Content();
|
||||
content.setSeverity(severity);
|
||||
@@ -72,13 +72,13 @@ class RuleAlarmPersistenceServiceImplTest {
|
||||
}
|
||||
|
||||
private static RuleMatch firingMatch(String severity) {
|
||||
RuleFact fact = new RuleFact(7L, AlarmTargetTypeFlagEnum.POINT, 11L, null, LocalDateTime.now(),
|
||||
RuleFact fact = new RuleFact(7L, AlarmTargetTypeEnum.POINT, 11L, null, LocalDateTime.now(),
|
||||
Map.of("driverId", 3L, "deviceId", 5L));
|
||||
return RuleMatch.firing(rule(1L, severity), fact);
|
||||
}
|
||||
|
||||
private static RuleMatch recoveryMatch() {
|
||||
RuleFact fact = new RuleFact(7L, AlarmTargetTypeFlagEnum.POINT, 11L, null, LocalDateTime.now(), Map.of());
|
||||
RuleFact fact = new RuleFact(7L, AlarmTargetTypeEnum.POINT, 11L, null, LocalDateTime.now(), Map.of());
|
||||
return RuleMatch.recovery(rule(1L, "P1"), fact);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class RuleAlarmPersistenceServiceImplTest {
|
||||
verify(entityAlarmManager).save(captor.capture());
|
||||
EntityAlarmDO persisted = captor.getValue();
|
||||
// Severity P0 → alarm_level_flag index 0
|
||||
assertThat(persisted.getAlarmLevelFlag()).isEqualTo(AlarmMessageLevelFlagEnum.P0.getIndex());
|
||||
assertThat(persisted.getAlarmLevelFlag()).isEqualTo(AlarmMessageLevelEnum.P0.getIndex());
|
||||
assertThat(persisted.getRuleId()).isEqualTo(1L);
|
||||
assertThat(persisted.getTenantId()).isEqualTo(7L);
|
||||
// The fact gets the new alarm id back so downstream notification persists it
|
||||
@@ -119,7 +119,7 @@ class RuleAlarmPersistenceServiceImplTest {
|
||||
|
||||
ArgumentCaptor<EntityAlarmDO> captor = ArgumentCaptor.forClass(EntityAlarmDO.class);
|
||||
verify(entityAlarmManager).save(captor.capture());
|
||||
assertThat(captor.getValue().getAlarmLevelFlag()).isEqualTo(AlarmMessageLevelFlagEnum.P2.getIndex());
|
||||
assertThat(captor.getValue().getAlarmLevelFlag()).isEqualTo(AlarmMessageLevelEnum.P2.getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-5
@@ -20,7 +20,7 @@ package io.github.pnoker.common.data.biz.alarm;
|
||||
import io.github.pnoker.common.constant.service.AlarmConstant;
|
||||
import io.github.pnoker.common.data.entity.bo.RuleBO;
|
||||
import io.github.pnoker.common.entity.ext.RuleExt;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -59,7 +59,7 @@ class RuleEngineImplTest {
|
||||
RuleBO bo = new RuleBO();
|
||||
bo.setId(id);
|
||||
bo.setRuleCode("rule-" + id);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT);
|
||||
RuleExt ext = new RuleExt();
|
||||
RuleExt.Content content = new RuleExt.Content();
|
||||
content.setSeverity("P1");
|
||||
@@ -70,7 +70,7 @@ class RuleEngineImplTest {
|
||||
}
|
||||
|
||||
private static RuleFact fact() {
|
||||
return new RuleFact(7L, AlarmTargetTypeFlagEnum.POINT, 11L, null, LocalDateTime.now(), Map.of("value", 100));
|
||||
return new RuleFact(7L, AlarmTargetTypeEnum.POINT, 11L, null, LocalDateTime.now(), Map.of("value", 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,7 +80,7 @@ class RuleEngineImplTest {
|
||||
|
||||
@Test
|
||||
void returnsEmptyWhenTenantIdMissing() {
|
||||
RuleFact fact = new RuleFact(null, AlarmTargetTypeFlagEnum.POINT, 11L, null, LocalDateTime.now(), Map.of());
|
||||
RuleFact fact = new RuleFact(null, AlarmTargetTypeEnum.POINT, 11L, null, LocalDateTime.now(), Map.of());
|
||||
assertThat(engine.evaluate(fact)).isEmpty();
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class RuleEngineImplTest {
|
||||
when(ruleEvaluator.matches(eq(rule), any())).thenReturn(false);
|
||||
when(ruleEvaluator.recovers(eq(rule), any())).thenReturn(true);
|
||||
when(ruleStateLookup.hasFiringState(7L, 1L,
|
||||
AlarmTargetTypeFlagEnum.POINT.getIndex(), 11L)).thenReturn(true);
|
||||
AlarmTargetTypeEnum.POINT.getIndex(), 11L)).thenReturn(true);
|
||||
|
||||
List<RuleMatch> matches = engine.evaluate(fact());
|
||||
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package io.github.pnoker.common.data.biz.alarm;
|
||||
|
||||
import io.github.pnoker.common.data.entity.bo.RuleBO;
|
||||
import io.github.pnoker.common.entity.ext.RuleExt;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -146,7 +146,7 @@ class RuleEvaluatorImplTest {
|
||||
private RuleFact fact(Map<String, Object> values) {
|
||||
return new RuleFact(
|
||||
1L,
|
||||
AlarmTargetTypeFlagEnum.POINT,
|
||||
AlarmTargetTypeEnum.POINT,
|
||||
1001L,
|
||||
2001L,
|
||||
LocalDateTime.now(),
|
||||
|
||||
+25
-25
@@ -36,11 +36,11 @@ import io.github.pnoker.common.data.entity.model.RuleStateDO;
|
||||
import io.github.pnoker.common.entity.dto.NotifyTaskDTO;
|
||||
import io.github.pnoker.common.entity.ext.NotifyExt;
|
||||
import io.github.pnoker.common.entity.ext.RuleExt;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import io.github.pnoker.common.enums.EnableFlagEnum;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.NotifyChannelTypeEnum;
|
||||
import io.github.pnoker.common.enums.NotifyHistoryStatusEnum;
|
||||
import io.github.pnoker.common.enums.RuleStateFlagEnum;
|
||||
import io.github.pnoker.common.enums.RuleStatusEnum;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -108,7 +108,7 @@ class RuleNotificationServiceImplTest {
|
||||
bo.setId(1L);
|
||||
bo.setRuleCode("test-rule");
|
||||
bo.setRuleName("Test Rule");
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT);
|
||||
bo.setNotifyId(10L);
|
||||
bo.setMessageId(20L);
|
||||
RuleExt ext = new RuleExt();
|
||||
@@ -121,7 +121,7 @@ class RuleNotificationServiceImplTest {
|
||||
}
|
||||
|
||||
private static RuleFact fact() {
|
||||
return new RuleFact(7L, AlarmTargetTypeFlagEnum.POINT, 11L, null,
|
||||
return new RuleFact(7L, AlarmTargetTypeEnum.POINT, 11L, null,
|
||||
LocalDateTime.of(2026, 5, 21, 12, 0), Map.of("value", 100));
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class RuleNotificationServiceImplTest {
|
||||
NotifyChannelBO bo = new NotifyChannelBO();
|
||||
bo.setId(id);
|
||||
bo.setTenantId(tenantId);
|
||||
bo.setChannelTypeFlag(NotifyChannelTypeFlagEnum.WEBHOOK);
|
||||
bo.setChannelTypeFlag(NotifyChannelTypeEnum.WEBHOOK);
|
||||
bo.setEnableFlag(EnableFlagEnum.ENABLE);
|
||||
bo.setCredentialRef("secret:test:" + id);
|
||||
return bo;
|
||||
@@ -166,11 +166,11 @@ class RuleNotificationServiceImplTest {
|
||||
return bo;
|
||||
}
|
||||
|
||||
private static RuleStateBO state(long ruleId, long entityId, RuleStateFlagEnum flag) {
|
||||
private static RuleStateBO state(long ruleId, long entityId, RuleStatusEnum flag) {
|
||||
RuleStateBO bo = new RuleStateBO();
|
||||
bo.setId(1L);
|
||||
bo.setRuleId(ruleId);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT);
|
||||
bo.setEntityId(entityId);
|
||||
bo.setFingerprint("7:1:point:11");
|
||||
bo.setEntityStateFlag(flag);
|
||||
@@ -184,11 +184,11 @@ class RuleNotificationServiceImplTest {
|
||||
|
||||
// ---------- notify: firing path ----------
|
||||
|
||||
private static RuleStateDO stateDO(long id, RuleStateFlagEnum flag, long triggerCount) {
|
||||
private static RuleStateDO stateDO(long id, RuleStatusEnum flag, long triggerCount) {
|
||||
RuleStateDO entity = new RuleStateDO();
|
||||
entity.setId(id);
|
||||
entity.setRuleId(1L);
|
||||
entity.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT.getIndex());
|
||||
entity.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT.getIndex());
|
||||
entity.setEntityId(11L);
|
||||
entity.setFingerprint("7:1:point:11");
|
||||
entity.setEntityStateFlag(flag.getIndex());
|
||||
@@ -214,7 +214,7 @@ class RuleNotificationServiceImplTest {
|
||||
stubNotifyConfigLoaded(match);
|
||||
when(notifyPolicyEngine.decide(any(), any(), any(), any(), any())).thenReturn(NotifyDecision.send());
|
||||
when(messageRenderService.render(any(), any(), any()))
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeFlagEnum.WEBHOOK, "json", Map.of("title", "T"), List.of()));
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeEnum.WEBHOOK, "json", Map.of("title", "T"), List.of()));
|
||||
stubStateBuilder();
|
||||
stubHistoryBuilder();
|
||||
|
||||
@@ -229,7 +229,7 @@ class RuleNotificationServiceImplTest {
|
||||
// Verify rule_state save (new row)
|
||||
ArgumentCaptor<RuleStateDO> stateCaptor = ArgumentCaptor.forClass(RuleStateDO.class);
|
||||
verify(ruleStateManager).save(stateCaptor.capture());
|
||||
assertThat(stateCaptor.getValue().getEntityStateFlag()).isEqualTo(RuleStateFlagEnum.FIRING.getIndex());
|
||||
assertThat(stateCaptor.getValue().getEntityStateFlag()).isEqualTo(RuleStatusEnum.FIRING.getIndex());
|
||||
assertThat(stateCaptor.getValue().getTriggerCount()).isEqualTo(1L);
|
||||
// Verify PENDING history persisted
|
||||
ArgumentCaptor<NotifyHistoryDO> historyCaptor = ArgumentCaptor.forClass(NotifyHistoryDO.class);
|
||||
@@ -245,14 +245,14 @@ class RuleNotificationServiceImplTest {
|
||||
stubNotifyConfigLoaded(match);
|
||||
when(notifyPolicyEngine.decide(any(), any(), any(), any(), any())).thenReturn(NotifyDecision.send());
|
||||
when(messageRenderService.render(any(), any(), any()))
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeFlagEnum.WEBHOOK, "json", Map.of(), List.of()));
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeEnum.WEBHOOK, "json", Map.of(), List.of()));
|
||||
stubStateBuilder();
|
||||
stubHistoryBuilder();
|
||||
|
||||
// Existing FIRING row — subsequent fire
|
||||
RuleStateDO existingDO = stateDO(1L, RuleStateFlagEnum.FIRING, 5L);
|
||||
RuleStateDO existingDO = stateDO(1L, RuleStatusEnum.FIRING, 5L);
|
||||
when(ruleStateManager.getOne(any(LambdaQueryWrapper.class))).thenReturn(existingDO);
|
||||
RuleStateBO existingBO = state(1L, 11L, RuleStateFlagEnum.FIRING);
|
||||
RuleStateBO existingBO = state(1L, 11L, RuleStatusEnum.FIRING);
|
||||
existingBO.setTriggerCount(5L);
|
||||
when(ruleStateBuilder.buildBOByDO(existingDO)).thenReturn(existingBO);
|
||||
|
||||
@@ -277,14 +277,14 @@ class RuleNotificationServiceImplTest {
|
||||
stubNotifyConfigLoaded(match);
|
||||
when(notifyPolicyEngine.decide(any(), any(), any(), any(), any())).thenReturn(NotifyDecision.send());
|
||||
when(messageRenderService.render(any(), any(), any()))
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeFlagEnum.WEBHOOK, "json", Map.of(), List.of()));
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeEnum.WEBHOOK, "json", Map.of(), List.of()));
|
||||
stubStateBuilder();
|
||||
stubHistoryBuilder();
|
||||
|
||||
// Existing FIRING row — recovery gated
|
||||
RuleStateDO existingDO = stateDO(1L, RuleStateFlagEnum.FIRING, 3L);
|
||||
RuleStateDO existingDO = stateDO(1L, RuleStatusEnum.FIRING, 3L);
|
||||
when(ruleStateManager.getOne(any(LambdaQueryWrapper.class))).thenReturn(existingDO);
|
||||
RuleStateBO existingBO = state(1L, 11L, RuleStateFlagEnum.FIRING);
|
||||
RuleStateBO existingBO = state(1L, 11L, RuleStatusEnum.FIRING);
|
||||
when(ruleStateBuilder.buildBOByDO(existingDO)).thenReturn(existingBO);
|
||||
|
||||
when(ruleStateManager.update(any(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper.class)))
|
||||
@@ -412,7 +412,7 @@ class RuleNotificationServiceImplTest {
|
||||
when(notifyPolicyEngine.decide(any(), any(), any(), any(), any()))
|
||||
.thenReturn(NotifyDecision.send());
|
||||
when(messageRenderService.render(any(), any(), any()))
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeFlagEnum.WEBHOOK, "json", Map.of("title", "T"), List.of()));
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeEnum.WEBHOOK, "json", Map.of("title", "T"), List.of()));
|
||||
|
||||
List<NotifyHistoryBO> histories = service.notifyBatch(List.of(m1, m2));
|
||||
// Each match has 1 bind × 1 channel = 1 history; 2 matches = 2 histories
|
||||
@@ -443,9 +443,9 @@ class RuleNotificationServiceImplTest {
|
||||
when(notifyConfigCache.getChannel(30L, 7L)).thenReturn(channel);
|
||||
when(notifyPolicyEngine.decide(any(), any(), any(), any(), any())).thenReturn(NotifyDecision.send());
|
||||
when(messageRenderService.render(any(), any(), any()))
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeFlagEnum.WEBHOOK, "json", Map.of(), List.of()));
|
||||
.thenReturn(new MessagePayload(NotifyChannelTypeEnum.WEBHOOK, "json", Map.of(), List.of()));
|
||||
// First load: no existing state → will try insert. Reload after exception: now the row exists.
|
||||
RuleStateDO reloadedDO = stateDO(99L, RuleStateFlagEnum.FIRING, 1L);
|
||||
RuleStateDO reloadedDO = stateDO(99L, RuleStatusEnum.FIRING, 1L);
|
||||
when(ruleStateManager.getOne(any(LambdaQueryWrapper.class))).thenReturn(null, reloadedDO);
|
||||
// Insert throws DuplicateKeyException (another thread inserted first)
|
||||
when(ruleStateManager.save(any(RuleStateDO.class))).thenThrow(new DuplicateKeyException("duplicate"));
|
||||
@@ -502,10 +502,10 @@ class RuleNotificationServiceImplTest {
|
||||
RuleStateBO bo = new RuleStateBO();
|
||||
bo.setId(entity.getId());
|
||||
bo.setRuleId(entity.getRuleId());
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT);
|
||||
bo.setEntityId(entity.getEntityId());
|
||||
bo.setFingerprint(entity.getFingerprint());
|
||||
bo.setEntityStateFlag(RuleStateFlagEnum.ofIndex(entity.getEntityStateFlag()));
|
||||
bo.setEntityStateFlag(RuleStatusEnum.ofIndex(entity.getEntityStateFlag()));
|
||||
bo.setTriggerCount(entity.getTriggerCount());
|
||||
bo.setAlarmId(entity.getAlarmId());
|
||||
bo.setTenantId(entity.getTenantId());
|
||||
@@ -533,10 +533,10 @@ class RuleNotificationServiceImplTest {
|
||||
RuleStateBO bo = new RuleStateBO();
|
||||
bo.setId(entity.getId());
|
||||
bo.setRuleId(entity.getRuleId());
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT);
|
||||
bo.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT);
|
||||
bo.setEntityId(entity.getEntityId());
|
||||
bo.setFingerprint(entity.getFingerprint());
|
||||
bo.setEntityStateFlag(RuleStateFlagEnum.ofIndex(entity.getEntityStateFlag()));
|
||||
bo.setEntityStateFlag(RuleStatusEnum.ofIndex(entity.getEntityStateFlag()));
|
||||
bo.setTriggerCount(entity.getTriggerCount());
|
||||
bo.setAlarmId(entity.getAlarmId());
|
||||
bo.setTenantId(entity.getTenantId());
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ import io.github.pnoker.common.data.entity.bo.RuleBO;
|
||||
import io.github.pnoker.common.data.entity.builder.RuleBuilder;
|
||||
import io.github.pnoker.common.data.entity.model.RuleDO;
|
||||
import io.github.pnoker.common.data.entity.property.AlarmCacheProperties;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -50,7 +50,7 @@ class RuleRegistryTest {
|
||||
private RuleRegistry registry;
|
||||
|
||||
private static RuleFact fact(long tenantId, long entityId) {
|
||||
return new RuleFact(tenantId, AlarmTargetTypeFlagEnum.POINT, entityId, null, LocalDateTime.now(), Map.of());
|
||||
return new RuleFact(tenantId, AlarmTargetTypeEnum.POINT, entityId, null, LocalDateTime.now(), Map.of());
|
||||
}
|
||||
|
||||
private static RuleBO rule(long id) {
|
||||
@@ -124,7 +124,7 @@ class RuleRegistryTest {
|
||||
// not trip the underlying lookup either — the engine guards against
|
||||
// bad input upstream.
|
||||
assertThat(registry.findCandidates(null)).isEmpty();
|
||||
assertThat(registry.findCandidates(new RuleFact(null, AlarmTargetTypeFlagEnum.POINT, 11L,
|
||||
assertThat(registry.findCandidates(new RuleFact(null, AlarmTargetTypeEnum.POINT, 11L,
|
||||
null, LocalDateTime.now(), Map.of()))).isEmpty();
|
||||
verify(ruleCandidateLookup, times(0)).findCandidates(any());
|
||||
}
|
||||
|
||||
+4
-4
@@ -20,8 +20,8 @@ package io.github.pnoker.common.data.biz.alarm;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import io.github.pnoker.common.data.dal.RuleStateManager;
|
||||
import io.github.pnoker.common.data.entity.model.RuleStateDO;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.RuleStateFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import io.github.pnoker.common.enums.RuleStatusEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -40,7 +40,7 @@ class RuleStateLookupTest {
|
||||
|
||||
private static final long TENANT_ID = 7L;
|
||||
private static final long RULE_ID = 1L;
|
||||
private static final byte TARGET_TYPE = AlarmTargetTypeFlagEnum.POINT.getIndex();
|
||||
private static final byte TARGET_TYPE = AlarmTargetTypeEnum.POINT.getIndex();
|
||||
private static final long ENTITY_ID = 11L;
|
||||
@Mock
|
||||
private RuleStateManager ruleStateManager;
|
||||
@@ -63,7 +63,7 @@ class RuleStateLookupTest {
|
||||
verify(chainWrapper).eq(any(), eq(RULE_ID));
|
||||
verify(chainWrapper).eq(any(), eq(TARGET_TYPE));
|
||||
verify(chainWrapper).eq(any(), eq(ENTITY_ID));
|
||||
verify(chainWrapper).eq(any(), eq(RuleStateFlagEnum.FIRING.getIndex()));
|
||||
verify(chainWrapper).eq(any(), eq(RuleStatusEnum.FIRING.getIndex()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
package io.github.pnoker.common.data.biz.alarm;
|
||||
|
||||
import io.github.pnoker.common.data.entity.property.AlarmWindowProperties;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -30,8 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class WindowSampleBufferTest {
|
||||
|
||||
private static final WindowSampleKey KEY_A = new WindowSampleKey(7L, AlarmTargetTypeFlagEnum.POINT, 11L);
|
||||
private static final WindowSampleKey KEY_B = new WindowSampleKey(7L, AlarmTargetTypeFlagEnum.POINT, 12L);
|
||||
private static final WindowSampleKey KEY_A = new WindowSampleKey(7L, AlarmTargetTypeEnum.POINT, 11L);
|
||||
private static final WindowSampleKey KEY_B = new WindowSampleKey(7L, AlarmTargetTypeEnum.POINT, 12L);
|
||||
private AlarmWindowProperties properties;
|
||||
private WindowSampleBuffer buffer;
|
||||
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@ import io.github.pnoker.common.constant.service.AlarmConstant;
|
||||
import io.github.pnoker.common.data.entity.bo.RuleBO;
|
||||
import io.github.pnoker.common.data.entity.property.AlarmWindowProperties;
|
||||
import io.github.pnoker.common.entity.ext.RuleExt;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -80,7 +80,7 @@ class WindowedAlarmPipelineIntegrationTest {
|
||||
RuleBO rule = new RuleBO();
|
||||
rule.setId(1L);
|
||||
rule.setRuleCode("rule");
|
||||
rule.setAlarmTargetTypeFlag(AlarmTargetTypeFlagEnum.POINT);
|
||||
rule.setAlarmTargetTypeFlag(AlarmTargetTypeEnum.POINT);
|
||||
rule.setRuleExt(ext);
|
||||
return rule;
|
||||
}
|
||||
@@ -102,14 +102,14 @@ class WindowedAlarmPipelineIntegrationTest {
|
||||
private void feed(double value, String calValue) {
|
||||
LocalDateTime ts = LocalDateTime.now();
|
||||
buffer.append(
|
||||
WindowSampleKey.of(TENANT_ID, AlarmTargetTypeFlagEnum.POINT, POINT_ID),
|
||||
WindowSampleKey.of(TENANT_ID, AlarmTargetTypeEnum.POINT, POINT_ID),
|
||||
new WindowSample(value, calValue, ts));
|
||||
}
|
||||
|
||||
private RuleFact factOnPoint() {
|
||||
// Use a synthetic fact that arrives just after the most recently
|
||||
// appended sample, so the evaluator's window includes it.
|
||||
return new RuleFact(TENANT_ID, AlarmTargetTypeFlagEnum.POINT, POINT_ID, null,
|
||||
return new RuleFact(TENANT_ID, AlarmTargetTypeEnum.POINT, POINT_ID, null,
|
||||
LocalDateTime.now().plusNanos(1), Map.of("numValue", 0));
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ class WindowedAlarmPipelineIntegrationTest {
|
||||
assertThat(engine.evaluate(factOnPoint())).isEmpty();
|
||||
|
||||
// Build a fact that carries a numValue of 95
|
||||
RuleFact firingFact = new RuleFact(TENANT_ID, AlarmTargetTypeFlagEnum.POINT, POINT_ID, null,
|
||||
RuleFact firingFact = new RuleFact(TENANT_ID, AlarmTargetTypeEnum.POINT, POINT_ID, null,
|
||||
LocalDateTime.now(), Map.of("numValue", 95));
|
||||
assertThat(engine.evaluate(firingFact)).hasSize(1);
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package io.github.pnoker.common.data.biz.alarm;
|
||||
|
||||
import io.github.pnoker.common.data.entity.bo.RuleBO;
|
||||
import io.github.pnoker.common.entity.ext.RuleExt;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import io.github.pnoker.common.enums.WindowModeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -66,7 +66,7 @@ class WindowedRuleEvaluatorTest {
|
||||
}
|
||||
|
||||
private static RuleFact fact() {
|
||||
return new RuleFact(7L, AlarmTargetTypeFlagEnum.POINT, 11L, null, LocalDateTime.now(), Map.of());
|
||||
return new RuleFact(7L, AlarmTargetTypeEnum.POINT, 11L, null, LocalDateTime.now(), Map.of());
|
||||
}
|
||||
|
||||
private static WindowSpec spec(WindowModeEnum mode, int minSamples) {
|
||||
|
||||
+5
-1
@@ -20,6 +20,7 @@ package io.github.pnoker.common.data.biz.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.github.pnoker.common.constant.driver.RabbitConstant;
|
||||
import io.github.pnoker.common.data.dal.CommandHistoryManager;
|
||||
import io.github.pnoker.common.data.entity.builder.CommandHistoryBuilder;
|
||||
import io.github.pnoker.common.data.entity.model.CommandHistoryDO;
|
||||
import io.github.pnoker.common.data.entity.model.EntityStateDO;
|
||||
import io.github.pnoker.common.data.entity.vo.CommandCallVO;
|
||||
@@ -77,12 +78,15 @@ class CommandHistoryServiceImplTest {
|
||||
@Mock
|
||||
private EntityStateMapper entityStateMapper;
|
||||
|
||||
@Mock
|
||||
private CommandHistoryBuilder commandHistoryBuilder;
|
||||
|
||||
private CommandHistoryServiceImpl service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new CommandHistoryServiceImpl(deviceFacade, driverFacade, commandFacade, rabbitTemplate,
|
||||
commandHistoryManager, entityStateMapper);
|
||||
commandHistoryManager, commandHistoryBuilder, entityStateMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import io.github.pnoker.common.data.biz.alarm.AlarmRuleTriggerService;
|
||||
import io.github.pnoker.common.data.dal.EntityAlarmManager;
|
||||
import io.github.pnoker.common.data.entity.model.EntityAlarmDO;
|
||||
import io.github.pnoker.common.entity.dto.DeviceAlarmDTO;
|
||||
import io.github.pnoker.common.enums.AlarmMessageLevelFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmMessageLevelEnum;
|
||||
import io.github.pnoker.common.facade.api.DeviceFacade;
|
||||
import io.github.pnoker.common.facade.entity.bo.FacadeDeviceBO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -87,7 +87,7 @@ class DeviceAlarmServiceImplTest {
|
||||
assertThat(captor.getValue().getDeviceId()).isEqualTo(10L);
|
||||
// Device-reported alarms default to P2 — the rule pipeline writes a
|
||||
// separate row with the rule-derived severity if a matching rule fires.
|
||||
assertThat(captor.getValue().getAlarmLevelFlag()).isEqualTo(AlarmMessageLevelFlagEnum.P2.getIndex());
|
||||
assertThat(captor.getValue().getAlarmLevelFlag()).isEqualTo(AlarmMessageLevelEnum.P2.getIndex());
|
||||
verify(alarmRuleTriggerService).processDeviceAlarm(dto);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -22,8 +22,8 @@ import io.github.pnoker.common.data.entity.model.EntityStateDO;
|
||||
import io.github.pnoker.common.data.mapper.EntityStateMapper;
|
||||
import io.github.pnoker.common.entity.dto.DeviceStateDTO;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.TimeoutSourceFlagEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeEnum;
|
||||
import io.github.pnoker.common.enums.TimeoutSourceTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -69,7 +69,7 @@ class DeviceStateServiceImplTest {
|
||||
|
||||
private EntityStateDO persisted(byte stateFlag, byte lastStateFlag, long leaseVersion) {
|
||||
EntityStateDO state = new EntityStateDO();
|
||||
state.setEntityTypeFlag((byte) EntityTypeFlagEnum.DEVICE.getIndex());
|
||||
state.setEntityTypeFlag((byte) EntityTypeEnum.DEVICE.getIndex());
|
||||
state.setEntityId(10L);
|
||||
state.setParentEntityId(7L);
|
||||
state.setTenantId(100L);
|
||||
@@ -103,14 +103,14 @@ class DeviceStateServiceImplTest {
|
||||
|
||||
verify(entityStateMapper).upsertEntityState(anyLong(),
|
||||
eq(100L),
|
||||
eq((byte) EntityTypeFlagEnum.DEVICE.getIndex()),
|
||||
eq((byte) EntityTypeEnum.DEVICE.getIndex()),
|
||||
eq(10L),
|
||||
eq(7L),
|
||||
eq((byte) EntityStatusEnum.ONLINE.getIndex()),
|
||||
eq((byte) EntityStatusEnum.OFFLINE.getIndex()),
|
||||
any(LocalDateTime.class),
|
||||
eq(25),
|
||||
eq((byte) TimeoutSourceFlagEnum.DRIVER.getIndex()),
|
||||
eq((byte) TimeoutSourceTypeEnum.DRIVER.getIndex()),
|
||||
eq("device-heartbeat"),
|
||||
any());
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ import io.github.pnoker.common.data.dal.EntityStateManager;
|
||||
import io.github.pnoker.common.data.entity.model.EntityStateDO;
|
||||
import io.github.pnoker.common.data.entity.query.DeviceQuery;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeEnum;
|
||||
import io.github.pnoker.common.facade.api.DeviceFacade;
|
||||
import io.github.pnoker.common.facade.entity.bo.FacadeDeviceBO;
|
||||
import io.github.pnoker.common.facade.entity.common.FacadePage;
|
||||
@@ -62,7 +62,7 @@ class DeviceStatusServiceImplTest {
|
||||
|
||||
private EntityStateDO onlineState(Long entityId) {
|
||||
EntityStateDO state = new EntityStateDO();
|
||||
state.setEntityTypeFlag((byte) EntityTypeFlagEnum.DEVICE.getIndex());
|
||||
state.setEntityTypeFlag((byte) EntityTypeEnum.DEVICE.getIndex());
|
||||
state.setEntityId(entityId);
|
||||
state.setStateFlag((byte) EntityStatusEnum.ONLINE.getIndex());
|
||||
state.setExpireTime(LocalDateTime.now().plusSeconds(60));
|
||||
@@ -71,7 +71,7 @@ class DeviceStatusServiceImplTest {
|
||||
|
||||
private EntityStateDO expiredState(Long entityId) {
|
||||
EntityStateDO state = new EntityStateDO();
|
||||
state.setEntityTypeFlag((byte) EntityTypeFlagEnum.DEVICE.getIndex());
|
||||
state.setEntityTypeFlag((byte) EntityTypeEnum.DEVICE.getIndex());
|
||||
state.setEntityId(entityId);
|
||||
state.setStateFlag((byte) EntityStatusEnum.ONLINE.getIndex());
|
||||
state.setExpireTime(LocalDateTime.now().minusSeconds(10));
|
||||
|
||||
+5
-5
@@ -23,8 +23,8 @@ import io.github.pnoker.common.data.mapper.EntityStateMapper;
|
||||
import io.github.pnoker.common.entity.dto.DriverStateDTO;
|
||||
import io.github.pnoker.common.entity.dto.DriverTimeoutCheckDTO;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.TimeoutSourceFlagEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeEnum;
|
||||
import io.github.pnoker.common.enums.TimeoutSourceTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -72,7 +72,7 @@ class DriverStateServiceImplTest {
|
||||
|
||||
private EntityStateDO persisted(byte stateFlag, byte lastStateFlag, long leaseVersion) {
|
||||
EntityStateDO state = new EntityStateDO();
|
||||
state.setEntityTypeFlag((byte) EntityTypeFlagEnum.DRIVER.getIndex());
|
||||
state.setEntityTypeFlag((byte) EntityTypeEnum.DRIVER.getIndex());
|
||||
state.setEntityId(1L);
|
||||
state.setParentEntityId(0L);
|
||||
state.setTenantId(100L);
|
||||
@@ -117,14 +117,14 @@ class DriverStateServiceImplTest {
|
||||
|
||||
verify(entityStateMapper).upsertEntityState(anyLong(),
|
||||
eq(100L),
|
||||
eq((byte) EntityTypeFlagEnum.DRIVER.getIndex()),
|
||||
eq((byte) EntityTypeEnum.DRIVER.getIndex()),
|
||||
eq(1L),
|
||||
eq(0L),
|
||||
eq((byte) EntityStatusEnum.ONLINE.getIndex()),
|
||||
eq((byte) EntityStatusEnum.OFFLINE.getIndex()),
|
||||
any(LocalDateTime.class),
|
||||
eq(45),
|
||||
eq((byte) TimeoutSourceFlagEnum.SYSTEM.getIndex()),
|
||||
eq((byte) TimeoutSourceTypeEnum.SYSTEM.getIndex()),
|
||||
eq("driver-heartbeat"),
|
||||
any());
|
||||
|
||||
|
||||
+10
-10
@@ -22,7 +22,7 @@ import io.github.pnoker.common.data.dal.EntityStateManager;
|
||||
import io.github.pnoker.common.data.entity.model.EntityStateDO;
|
||||
import io.github.pnoker.common.data.entity.query.DriverQuery;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeEnum;
|
||||
import io.github.pnoker.common.facade.api.DeviceFacade;
|
||||
import io.github.pnoker.common.facade.api.DriverFacade;
|
||||
import io.github.pnoker.common.facade.entity.bo.FacadeDeviceBO;
|
||||
@@ -116,7 +116,7 @@ class DriverStatusServiceImplTest {
|
||||
when(driverFacade.listByPage(any())).thenReturn(page);
|
||||
when(entityStateManager.lambdaQuery()).thenReturn(queryWrapper);
|
||||
when(queryWrapper.eq(any(), any())).thenReturn(queryWrapper);
|
||||
when(queryWrapper.one()).thenReturn(onlineState(1L, EntityTypeFlagEnum.DRIVER.getIndex()));
|
||||
when(queryWrapper.one()).thenReturn(onlineState(1L, EntityTypeEnum.DRIVER.getIndex()));
|
||||
assertThat(service.getStatusByPage(new DriverQuery()))
|
||||
.containsEntry(1L, EntityStatusEnum.ONLINE.getCode());
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class DriverStatusServiceImplTest {
|
||||
when(driverFacade.listByPage(any())).thenReturn(page);
|
||||
when(entityStateManager.lambdaQuery()).thenReturn(queryWrapper);
|
||||
when(queryWrapper.eq(any(), any())).thenReturn(queryWrapper);
|
||||
when(queryWrapper.one()).thenReturn(expiredState(1L, EntityTypeFlagEnum.DRIVER.getIndex()));
|
||||
when(queryWrapper.one()).thenReturn(expiredState(1L, EntityTypeEnum.DRIVER.getIndex()));
|
||||
assertThat(service.getStatusByPage(new DriverQuery()))
|
||||
.containsEntry(1L, EntityStatusEnum.OFFLINE.getCode());
|
||||
}
|
||||
@@ -136,39 +136,39 @@ class DriverStatusServiceImplTest {
|
||||
@Test
|
||||
void getDeviceOnlineByDriverIdReturnsZeroWhenDriverMissing() {
|
||||
when(driverFacade.getById(1L, 7L)).thenReturn(null);
|
||||
assertThat(service.getDeviceOnlineByDriverId(1L, 7L)).isEqualTo("0");
|
||||
assertThat(service.getDeviceOnlineByDriverId(1L, 7L)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDeviceOnlineByDriverIdReturnsZeroWhenNoDevices() {
|
||||
when(driverFacade.getById(1L, 7L)).thenReturn(driver(7L));
|
||||
when(deviceFacade.listByDriverId(1L, 7L)).thenReturn(List.of());
|
||||
assertThat(service.getDeviceOnlineByDriverId(1L, 7L)).isEqualTo("0");
|
||||
assertThat(service.getDeviceOnlineByDriverId(1L, 7L)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDeviceOnlineByDriverIdCountsOnlineDevices() {
|
||||
when(driverFacade.getById(1L, 7L)).thenReturn(driver(7L));
|
||||
when(deviceFacade.listByDriverId(1L, 7L)).thenReturn(List.of(device(10L), device(11L)));
|
||||
EntityStateDO online10 = onlineState(10L, EntityTypeFlagEnum.DEVICE.getIndex());
|
||||
EntityStateDO online10 = onlineState(10L, EntityTypeEnum.DEVICE.getIndex());
|
||||
online10.setStateFlag((byte) EntityStatusEnum.ONLINE.getIndex());
|
||||
EntityStateDO expired11 = expiredState(11L, EntityTypeFlagEnum.DEVICE.getIndex());
|
||||
EntityStateDO expired11 = expiredState(11L, EntityTypeEnum.DEVICE.getIndex());
|
||||
expired11.setStateFlag((byte) EntityStatusEnum.ONLINE.getIndex());
|
||||
when(entityStateManager.lambdaQuery()).thenReturn(queryWrapper);
|
||||
when(queryWrapper.eq(any(), any())).thenReturn(queryWrapper);
|
||||
when(queryWrapper.one()).thenReturn(online10).thenReturn(expired11);
|
||||
assertThat(service.getDeviceOnlineByDriverId(1L, 7L)).isEqualTo("1");
|
||||
assertThat(service.getDeviceOnlineByDriverId(1L, 7L)).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDeviceOfflineByDriverIdCountsOfflineAndMissingDevices() {
|
||||
when(driverFacade.getById(1L, 7L)).thenReturn(driver(7L));
|
||||
when(deviceFacade.listByDriverId(1L, 7L)).thenReturn(List.of(device(10L), device(11L), device(12L)));
|
||||
EntityStateDO online10 = onlineState(10L, EntityTypeFlagEnum.DEVICE.getIndex());
|
||||
EntityStateDO online10 = onlineState(10L, EntityTypeEnum.DEVICE.getIndex());
|
||||
online10.setStateFlag((byte) EntityStatusEnum.ONLINE.getIndex());
|
||||
when(entityStateManager.lambdaQuery()).thenReturn(queryWrapper);
|
||||
when(queryWrapper.eq(any(), any())).thenReturn(queryWrapper);
|
||||
when(queryWrapper.one()).thenReturn(online10).thenReturn(null).thenReturn(null);
|
||||
assertThat(service.getDeviceOfflineByDriverId(1L, 7L)).isEqualTo("2");
|
||||
assertThat(service.getDeviceOfflineByDriverId(1L, 7L)).isEqualTo(2L);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -25,7 +25,7 @@ import io.github.pnoker.common.data.dal.EntityStateManager;
|
||||
import io.github.pnoker.common.data.entity.model.EntityStateDO;
|
||||
import io.github.pnoker.common.data.mapper.EntityStateMapper;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -78,7 +78,7 @@ class EntityStateExpiryScannerTest {
|
||||
|
||||
private EntityStateDO deviceState(Long deviceId, Long driverId, byte statusFlag, long leaseVersion, LocalDateTime expireTime) {
|
||||
EntityStateDO state = new EntityStateDO();
|
||||
state.setEntityTypeFlag((byte) EntityTypeFlagEnum.DEVICE.getIndex());
|
||||
state.setEntityTypeFlag((byte) EntityTypeEnum.DEVICE.getIndex());
|
||||
state.setEntityId(deviceId);
|
||||
state.setParentEntityId(driverId);
|
||||
state.setStateFlag(statusFlag);
|
||||
@@ -125,7 +125,7 @@ class EntityStateExpiryScannerTest {
|
||||
scanner.onScanTick(channel, mockMessage(1L));
|
||||
|
||||
verify(entityStateMapper).claimExpiredDevices(
|
||||
eq((byte) EntityTypeFlagEnum.DEVICE.getIndex()),
|
||||
eq((byte) EntityTypeEnum.DEVICE.getIndex()),
|
||||
eq((byte) EntityStatusEnum.ONLINE.getIndex()),
|
||||
eq((byte) EntityStatusEnum.MAINTAIN.getIndex()),
|
||||
eq((byte) EntityStatusEnum.FAULT.getIndex()),
|
||||
@@ -145,11 +145,11 @@ class EntityStateExpiryScannerTest {
|
||||
|
||||
stubClaimedDevices(List.of(expired));
|
||||
stubLastAlarmUpdate();
|
||||
when(entityAlarmManager.save(any())).thenReturn(true);
|
||||
when(entityAlarmManager.saveBatch(any())).thenReturn(true);
|
||||
|
||||
scanner.onScanTick(channel, mockMessage(1L));
|
||||
|
||||
verify(entityAlarmManager).save(any());
|
||||
verify(entityAlarmManager).saveBatch(any());
|
||||
verify(alarmRuleTriggerService).processDeviceAlarm(any());
|
||||
verify(rabbitTemplate).convertAndSend(anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
+7
-3
@@ -19,10 +19,11 @@ package io.github.pnoker.common.data.biz.impl;
|
||||
|
||||
import io.github.pnoker.common.data.biz.alarm.AlarmRuleTriggerService;
|
||||
import io.github.pnoker.common.data.dal.EventHistoryManager;
|
||||
import io.github.pnoker.common.data.entity.builder.EventHistoryBuilder;
|
||||
import io.github.pnoker.common.data.entity.model.EventHistoryDO;
|
||||
import io.github.pnoker.common.data.entity.vo.EventReportVO;
|
||||
import io.github.pnoker.common.enums.EnableFlagEnum;
|
||||
import io.github.pnoker.common.enums.EventLevelFlagEnum;
|
||||
import io.github.pnoker.common.enums.EventLevelEnum;
|
||||
import io.github.pnoker.common.enums.EventTypeFlagEnum;
|
||||
import io.github.pnoker.common.facade.api.DeviceFacade;
|
||||
import io.github.pnoker.common.facade.api.EventFacade;
|
||||
@@ -60,11 +61,14 @@ class EventHistoryServiceImplTest {
|
||||
@Mock
|
||||
private EventHistoryManager eventHistoryManager;
|
||||
|
||||
@Mock
|
||||
private EventHistoryBuilder eventHistoryBuilder;
|
||||
|
||||
private EventHistoryServiceImpl service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new EventHistoryServiceImpl(deviceFacade, eventFacade, alarmRuleTriggerService, eventHistoryManager);
|
||||
service = new EventHistoryServiceImpl(deviceFacade, eventFacade, alarmRuleTriggerService, eventHistoryManager, eventHistoryBuilder);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +89,7 @@ class EventHistoryServiceImplTest {
|
||||
event.setProfileId(30L);
|
||||
event.setEventCode("overheat");
|
||||
event.setEventTypeFlag(EventTypeFlagEnum.ALERT);
|
||||
event.setEventLevelFlag(EventLevelFlagEnum.HIGH);
|
||||
event.setEventLevelFlag(EventLevelEnum.HIGH);
|
||||
event.setEnableFlag(EnableFlagEnum.ENABLE);
|
||||
|
||||
EventReportVO report = new EventReportVO();
|
||||
|
||||
+7
-3
@@ -19,6 +19,7 @@ package io.github.pnoker.common.data.biz.impl;
|
||||
|
||||
import io.github.pnoker.common.constant.driver.RabbitConstant;
|
||||
import io.github.pnoker.common.data.dal.PointCommandHistoryManager;
|
||||
import io.github.pnoker.common.data.entity.builder.PointCommandHistoryBuilder;
|
||||
import io.github.pnoker.common.data.entity.model.EntityStateDO;
|
||||
import io.github.pnoker.common.data.entity.vo.PointCommandReadVO;
|
||||
import io.github.pnoker.common.data.entity.vo.PointCommandWriteVO;
|
||||
@@ -26,7 +27,7 @@ import io.github.pnoker.common.data.mapper.EntityStateMapper;
|
||||
import io.github.pnoker.common.data.validator.PointCommandValidator;
|
||||
import io.github.pnoker.common.enums.EnableFlagEnum;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.RwFlagEnum;
|
||||
import io.github.pnoker.common.enums.RwTypeEnum;
|
||||
import io.github.pnoker.common.exception.NotFoundException;
|
||||
import io.github.pnoker.common.exception.ServiceException;
|
||||
import io.github.pnoker.common.exception.UnAuthorizedException;
|
||||
@@ -69,6 +70,9 @@ class PointCommandServiceImplTest {
|
||||
@Mock
|
||||
private PointCommandHistoryManager pointCommandHistoryManager;
|
||||
|
||||
@Mock
|
||||
private PointCommandHistoryBuilder pointCommandHistoryBuilder;
|
||||
|
||||
@Mock
|
||||
private EntityStateMapper entityStateMapper;
|
||||
|
||||
@@ -90,7 +94,7 @@ class PointCommandServiceImplTest {
|
||||
point = new FacadePointBO();
|
||||
point.setProfileId(5L);
|
||||
point.setEnableFlag(EnableFlagEnum.ENABLE);
|
||||
point.setRwFlag(RwFlagEnum.READ_WRITE);
|
||||
point.setRwFlag(RwTypeEnum.READ_WRITE);
|
||||
driver = new FacadeDriverBO();
|
||||
driver.setId(30L);
|
||||
driver.setServiceName("dc3-driver-modbus-tcp");
|
||||
@@ -264,7 +268,7 @@ class PointCommandServiceImplTest {
|
||||
FacadePointBO readOnlyPoint = new FacadePointBO();
|
||||
readOnlyPoint.setProfileId(5L);
|
||||
readOnlyPoint.setEnableFlag(EnableFlagEnum.ENABLE);
|
||||
readOnlyPoint.setRwFlag(RwFlagEnum.READ_ONLY);
|
||||
readOnlyPoint.setRwFlag(RwTypeEnum.READ_ONLY);
|
||||
when(deviceFacade.getById(1L, 10L)).thenReturn(device);
|
||||
when(pointFacade.getById(1L, 20L)).thenReturn(readOnlyPoint);
|
||||
|
||||
|
||||
+8
-2
@@ -288,6 +288,10 @@ class PointValueServiceImplTest {
|
||||
List.of(pointWithValue, pointWithoutValue)));
|
||||
when(pointValueLocalCacheService.selectLatestPointValue(1L, 10L, List.of(20L, 21L)))
|
||||
.thenReturn(Map.of(20L, cached));
|
||||
// Point 21 is not in the local cache, so it is batch-queried from the repository,
|
||||
// which returns nothing -> point 21 becomes a placeholder.
|
||||
when(repositoryService.listLatestPointValues(1L, 10L, List.of(21L)))
|
||||
.thenReturn(List.of());
|
||||
|
||||
try (MockedStatic<RepositoryStrategyFactory> factory =
|
||||
Mockito.mockStatic(RepositoryStrategyFactory.class)) {
|
||||
@@ -310,8 +314,10 @@ class PointValueServiceImplTest {
|
||||
assertThat(placeholder.getOperateTime()).isNull();
|
||||
}
|
||||
|
||||
verify(repositoryService, never()).selectLatestPointValue(1L, 10L, 20L);
|
||||
verify(repositoryService).selectLatestPointValue(1L, 10L, 21L);
|
||||
// Only the cache-missing point (21) is batch-queried from the repository;
|
||||
// the cached point (20) is never queried.
|
||||
verify(repositoryService).listLatestPointValues(1L, 10L, List.of(21L));
|
||||
verify(repositoryService, never()).listLatestPointValues(1L, 10L, List.of(20L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import io.github.pnoker.common.data.entity.model.EntityAlarmDO;
|
||||
import io.github.pnoker.common.data.entity.model.EntityStateDO;
|
||||
import io.github.pnoker.common.entity.dto.DriverTimeoutCheckDTO;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.EntityTypeEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -94,7 +94,7 @@ class DriverTimeoutCheckReceiverTest {
|
||||
EntityStateDO state = new EntityStateDO();
|
||||
state.setId(9L);
|
||||
state.setTenantId(100L);
|
||||
state.setEntityTypeFlag((byte) EntityTypeFlagEnum.DRIVER.getIndex());
|
||||
state.setEntityTypeFlag((byte) EntityTypeEnum.DRIVER.getIndex());
|
||||
state.setEntityId(7L);
|
||||
state.setParentEntityId(0L);
|
||||
state.setStateFlag(statusFlag);
|
||||
|
||||
+6
-6
@@ -18,7 +18,7 @@ package io.github.pnoker.common.driver.entity.bean;
|
||||
|
||||
import io.github.pnoker.common.driver.entity.bo.DeviceBO;
|
||||
import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -48,7 +48,7 @@ class PointValueTest {
|
||||
|
||||
@Test
|
||||
void numericTypePopulatesNumValue() {
|
||||
point.setPointTypeFlag(PointTypeFlagEnum.DOUBLE);
|
||||
point.setPointTypeFlag(PointTypeEnum.DOUBLE);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "42.5");
|
||||
PointValue pv = new PointValue(readPointValue);
|
||||
|
||||
@@ -61,7 +61,7 @@ class PointValueTest {
|
||||
|
||||
@Test
|
||||
void stringTypeLeavesNumValueNull() {
|
||||
point.setPointTypeFlag(PointTypeFlagEnum.STRING);
|
||||
point.setPointTypeFlag(PointTypeEnum.STRING);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "hello");
|
||||
PointValue pv = new PointValue(readPointValue);
|
||||
|
||||
@@ -71,7 +71,7 @@ class PointValueTest {
|
||||
|
||||
@Test
|
||||
void booleanTrueMapsNumValueToOne() {
|
||||
point.setPointTypeFlag(PointTypeFlagEnum.BOOLEAN);
|
||||
point.setPointTypeFlag(PointTypeEnum.BOOLEAN);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "true");
|
||||
PointValue pv = new PointValue(readPointValue);
|
||||
|
||||
@@ -81,7 +81,7 @@ class PointValueTest {
|
||||
|
||||
@Test
|
||||
void booleanFalseMapsNumValueToZero() {
|
||||
point.setPointTypeFlag(PointTypeFlagEnum.BOOLEAN);
|
||||
point.setPointTypeFlag(PointTypeEnum.BOOLEAN);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "false");
|
||||
PointValue pv = new PointValue(readPointValue);
|
||||
|
||||
@@ -91,7 +91,7 @@ class PointValueTest {
|
||||
|
||||
@Test
|
||||
void intTypePopulatesNumValue() {
|
||||
point.setPointTypeFlag(PointTypeFlagEnum.INT);
|
||||
point.setPointTypeFlag(PointTypeEnum.INT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "100");
|
||||
PointValue pv = new PointValue(readPointValue);
|
||||
|
||||
|
||||
+26
-26
@@ -18,7 +18,7 @@ package io.github.pnoker.common.driver.entity.bean;
|
||||
|
||||
import io.github.pnoker.common.driver.entity.bo.DeviceBO;
|
||||
import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.common.exception.EmptyException;
|
||||
import io.github.pnoker.common.exception.OutRangeException;
|
||||
import io.github.pnoker.common.exception.TypeException;
|
||||
@@ -48,7 +48,7 @@ class ReadPointValueTest {
|
||||
point.setId(10L);
|
||||
}
|
||||
|
||||
private PointBO pointWithType(PointTypeFlagEnum type) {
|
||||
private PointBO pointWithType(PointTypeEnum type) {
|
||||
point.setPointTypeFlag(type);
|
||||
point.setBaseValue(BigDecimal.ZERO);
|
||||
point.setMultiple(BigDecimal.ONE);
|
||||
@@ -56,7 +56,7 @@ class ReadPointValueTest {
|
||||
return point;
|
||||
}
|
||||
|
||||
private PointBO pointWithTypeAndScale(PointTypeFlagEnum type, BigDecimal base, BigDecimal multiple, byte decimal) {
|
||||
private PointBO pointWithTypeAndScale(PointTypeEnum type, BigDecimal base, BigDecimal multiple, byte decimal) {
|
||||
point.setPointTypeFlag(type);
|
||||
point.setBaseValue(base);
|
||||
point.setMultiple(multiple);
|
||||
@@ -69,7 +69,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void stringValueReturnsRawInput() {
|
||||
pointWithType(PointTypeFlagEnum.STRING);
|
||||
pointWithType(PointTypeEnum.STRING);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "hello world");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("hello world");
|
||||
@@ -78,7 +78,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void stringNumericTextStillNull() {
|
||||
pointWithType(PointTypeFlagEnum.STRING);
|
||||
pointWithType(PointTypeEnum.STRING);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "42");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("42");
|
||||
@@ -102,7 +102,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void byteType() {
|
||||
pointWithType(PointTypeFlagEnum.BYTE);
|
||||
pointWithType(PointTypeEnum.BYTE);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "100");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("100");
|
||||
@@ -111,7 +111,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void shortType() {
|
||||
pointWithType(PointTypeFlagEnum.SHORT);
|
||||
pointWithType(PointTypeEnum.SHORT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "1000");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("1000");
|
||||
@@ -120,7 +120,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void intType() {
|
||||
pointWithType(PointTypeFlagEnum.INT);
|
||||
pointWithType(PointTypeEnum.INT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "42");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("42");
|
||||
@@ -129,7 +129,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void longType() {
|
||||
pointWithType(PointTypeFlagEnum.LONG);
|
||||
pointWithType(PointTypeEnum.LONG);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "9999999999");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("9999999999");
|
||||
@@ -138,7 +138,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void floatType() {
|
||||
pointWithType(PointTypeFlagEnum.FLOAT);
|
||||
pointWithType(PointTypeEnum.FLOAT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "3.14");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("3.14");
|
||||
@@ -147,7 +147,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void doubleType() {
|
||||
pointWithType(PointTypeFlagEnum.DOUBLE);
|
||||
pointWithType(PointTypeEnum.DOUBLE);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "2.718281828");
|
||||
|
||||
// ArithmeticUtil.round with decimal=6 rounds to 6 decimal places
|
||||
@@ -157,7 +157,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void negativeDouble() {
|
||||
pointWithType(PointTypeFlagEnum.DOUBLE);
|
||||
pointWithType(PointTypeEnum.DOUBLE);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "-42.5");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("-42.5");
|
||||
@@ -166,7 +166,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void zero() {
|
||||
pointWithType(PointTypeFlagEnum.INT);
|
||||
pointWithType(PointTypeEnum.INT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "0");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("0");
|
||||
@@ -179,7 +179,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void trueMapsToOne() {
|
||||
pointWithType(PointTypeFlagEnum.BOOLEAN);
|
||||
pointWithType(PointTypeEnum.BOOLEAN);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "true");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("true");
|
||||
@@ -188,7 +188,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void falseMapsToZero() {
|
||||
pointWithType(PointTypeFlagEnum.BOOLEAN);
|
||||
pointWithType(PointTypeEnum.BOOLEAN);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "false");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("false");
|
||||
@@ -197,7 +197,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void oneMapsToTrue() {
|
||||
pointWithType(PointTypeFlagEnum.BOOLEAN);
|
||||
pointWithType(PointTypeEnum.BOOLEAN);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "1");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("true");
|
||||
@@ -206,7 +206,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void invalidBooleanThrowsTypeException() {
|
||||
pointWithType(PointTypeFlagEnum.BOOLEAN);
|
||||
pointWithType(PointTypeEnum.BOOLEAN);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "yes");
|
||||
|
||||
assertThatThrownBy(readPointValue::getFinalValue).isInstanceOf(TypeException.class);
|
||||
@@ -218,7 +218,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void offsetApplied() {
|
||||
pointWithTypeAndScale(PointTypeFlagEnum.INT, new BigDecimal("10"), BigDecimal.ONE, (byte) 0);
|
||||
pointWithTypeAndScale(PointTypeEnum.INT, new BigDecimal("10"), BigDecimal.ONE, (byte) 0);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "5");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("15");
|
||||
@@ -227,7 +227,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void multiplierApplied() {
|
||||
pointWithTypeAndScale(PointTypeFlagEnum.DOUBLE, BigDecimal.ZERO, new BigDecimal("2.5"), (byte) 2);
|
||||
pointWithTypeAndScale(PointTypeEnum.DOUBLE, BigDecimal.ZERO, new BigDecimal("2.5"), (byte) 2);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "10");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("25.0");
|
||||
@@ -236,7 +236,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void linearTransformApplied() {
|
||||
pointWithTypeAndScale(PointTypeFlagEnum.DOUBLE, new BigDecimal("32"), new BigDecimal("1.8"), (byte) 2);
|
||||
pointWithTypeAndScale(PointTypeEnum.DOUBLE, new BigDecimal("32"), new BigDecimal("1.8"), (byte) 2);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "100");
|
||||
|
||||
assertThat(readPointValue.getFinalValue()).isEqualTo("212.0");
|
||||
@@ -256,7 +256,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void outOfRangeByteThrows() {
|
||||
pointWithType(PointTypeFlagEnum.BYTE);
|
||||
pointWithType(PointTypeEnum.BYTE);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "200");
|
||||
|
||||
assertThatThrownBy(readPointValue::getFinalValue).isInstanceOf(OutRangeException.class);
|
||||
@@ -264,7 +264,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void outOfRangeShortThrows() {
|
||||
pointWithType(PointTypeFlagEnum.SHORT);
|
||||
pointWithType(PointTypeEnum.SHORT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "100000");
|
||||
|
||||
assertThatThrownBy(readPointValue::getFinalValue).isInstanceOf(OutRangeException.class);
|
||||
@@ -272,7 +272,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void invalidNumberForIntThrows() {
|
||||
pointWithType(PointTypeFlagEnum.INT);
|
||||
pointWithType(PointTypeEnum.INT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "not-a-number");
|
||||
|
||||
assertThatThrownBy(readPointValue::getFinalValue).isInstanceOf(TypeException.class);
|
||||
@@ -284,7 +284,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void numericValueIsAvailableBeforeGetFinalValue() {
|
||||
pointWithType(PointTypeFlagEnum.DOUBLE);
|
||||
pointWithType(PointTypeEnum.DOUBLE);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "3.14");
|
||||
|
||||
assertThat(readPointValue.getNumericValue()).isCloseTo(3.14, org.assertj.core.data.Offset.offset(0.001));
|
||||
@@ -294,7 +294,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void builderValueCalculatesNumericValueWithoutCallOrderDependency() {
|
||||
pointWithType(PointTypeFlagEnum.DOUBLE);
|
||||
pointWithType(PointTypeEnum.DOUBLE);
|
||||
ReadPointValue readPointValue = ReadPointValue.builder().device(device).point(point).value("3.14").build();
|
||||
|
||||
assertThat(readPointValue.getNumericValue()).isCloseTo(3.14, org.assertj.core.data.Offset.offset(0.001));
|
||||
@@ -303,7 +303,7 @@ class ReadPointValueTest {
|
||||
|
||||
@Test
|
||||
void calculateReturnsBothValuesAtOnce() {
|
||||
pointWithType(PointTypeFlagEnum.INT);
|
||||
pointWithType(PointTypeEnum.INT);
|
||||
ReadPointValue readPointValue = new ReadPointValue(device, point, "7");
|
||||
|
||||
CalculatedPointValue calculated = readPointValue.calculate();
|
||||
|
||||
+18
-18
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
package io.github.pnoker.common.driver.entity.bean;
|
||||
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.common.exception.EmptyException;
|
||||
import io.github.pnoker.common.exception.OutRangeException;
|
||||
import io.github.pnoker.common.exception.TypeException;
|
||||
@@ -33,62 +33,62 @@ class WritePointValueTest {
|
||||
|
||||
@Test
|
||||
void convertsExactIntegerTypes() {
|
||||
assertThat(writePointValue("12", PointTypeFlagEnum.BYTE).getValue(Byte.class)).isEqualTo((byte) 12);
|
||||
assertThat(writePointValue("1024", PointTypeFlagEnum.SHORT).getValue(Short.class)).isEqualTo((short) 1024);
|
||||
assertThat(writePointValue("42.0", PointTypeFlagEnum.INT).getValue(Integer.class)).isEqualTo(42);
|
||||
assertThat(writePointValue("9999999999", PointTypeFlagEnum.LONG).getValue(Long.class)).isEqualTo(9999999999L);
|
||||
assertThat(writePointValue("12", PointTypeEnum.BYTE).getValue(Byte.class)).isEqualTo((byte) 12);
|
||||
assertThat(writePointValue("1024", PointTypeEnum.SHORT).getValue(Short.class)).isEqualTo((short) 1024);
|
||||
assertThat(writePointValue("42.0", PointTypeEnum.INT).getValue(Integer.class)).isEqualTo(42);
|
||||
assertThat(writePointValue("9999999999", PointTypeEnum.LONG).getValue(Long.class)).isEqualTo(9999999999L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsPrimitiveTargetClasses() {
|
||||
assertThat(writePointValue("42", PointTypeFlagEnum.INT).getValue(Integer.TYPE)).isEqualTo(42);
|
||||
assertThat(writePointValue("true", PointTypeFlagEnum.BOOLEAN).getValue(Boolean.TYPE)).isEqualTo(true);
|
||||
assertThat(writePointValue("42", PointTypeEnum.INT).getValue(Integer.TYPE)).isEqualTo(42);
|
||||
assertThat(writePointValue("true", PointTypeEnum.BOOLEAN).getValue(Boolean.TYPE)).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void convertsFloatingPointTypes() {
|
||||
assertThat(writePointValue("3.14", PointTypeFlagEnum.FLOAT).getValue(Float.class)).isEqualTo(3.14f);
|
||||
assertThat(writePointValue("2.718281828", PointTypeFlagEnum.DOUBLE).getValue(Double.class)).isEqualTo(2.718281828d);
|
||||
assertThat(writePointValue("3.14", PointTypeEnum.FLOAT).getValue(Float.class)).isEqualTo(3.14f);
|
||||
assertThat(writePointValue("2.718281828", PointTypeEnum.DOUBLE).getValue(Double.class)).isEqualTo(2.718281828d);
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsEmptyStringForStringPoint() {
|
||||
assertThat(writePointValue("", PointTypeFlagEnum.STRING).getValue(String.class)).isEmpty();
|
||||
assertThat(writePointValue("", PointTypeEnum.STRING).getValue(String.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void strictBooleanSupportsTrueFalseAndOneZero() {
|
||||
assertThat(writePointValue("true", PointTypeFlagEnum.BOOLEAN).getValue(Boolean.class)).isTrue();
|
||||
assertThat(writePointValue("0", PointTypeFlagEnum.BOOLEAN).getValue(Boolean.class)).isFalse();
|
||||
assertThat(writePointValue("true", PointTypeEnum.BOOLEAN).getValue(Boolean.class)).isTrue();
|
||||
assertThat(writePointValue("0", PointTypeEnum.BOOLEAN).getValue(Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidBooleanThrowsTypeException() {
|
||||
assertThatThrownBy(() -> writePointValue("yes", PointTypeFlagEnum.BOOLEAN).getValue(Boolean.class))
|
||||
assertThatThrownBy(() -> writePointValue("yes", PointTypeEnum.BOOLEAN).getValue(Boolean.class))
|
||||
.isInstanceOf(TypeException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongTargetTypeThrowsTypeException() {
|
||||
assertThatThrownBy(() -> writePointValue("1", PointTypeFlagEnum.INT).getValue(Long.class))
|
||||
assertThatThrownBy(() -> writePointValue("1", PointTypeEnum.INT).getValue(Long.class))
|
||||
.isInstanceOf(TypeException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyNumericValueThrowsEmptyException() {
|
||||
assertThatThrownBy(() -> writePointValue("", PointTypeFlagEnum.INT).getValue(Integer.class))
|
||||
assertThatThrownBy(() -> writePointValue("", PointTypeEnum.INT).getValue(Integer.class))
|
||||
.isInstanceOf(EmptyException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidNumberThrowsTypeException() {
|
||||
assertThatThrownBy(() -> writePointValue("abc", PointTypeFlagEnum.INT).getValue(Integer.class))
|
||||
assertThatThrownBy(() -> writePointValue("abc", PointTypeEnum.INT).getValue(Integer.class))
|
||||
.isInstanceOf(TypeException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void outOfRangeThrowsOutRangeException() {
|
||||
assertThatThrownBy(() -> writePointValue("200", PointTypeFlagEnum.BYTE).getValue(Byte.class))
|
||||
assertThatThrownBy(() -> writePointValue("200", PointTypeEnum.BYTE).getValue(Byte.class))
|
||||
.isInstanceOf(OutRangeException.class);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class WritePointValueTest {
|
||||
.isInstanceOf(UnSupportException.class);
|
||||
}
|
||||
|
||||
private WritePointValue writePointValue(String value, PointTypeFlagEnum type) {
|
||||
private WritePointValue writePointValue(String value, PointTypeEnum type) {
|
||||
return WritePointValue.builder().value(value).type(type).build();
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
package io.github.pnoker.common.driver.entity.bo;
|
||||
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.exception.TypeException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -30,29 +30,29 @@ class AttributeBOTest {
|
||||
|
||||
@Test
|
||||
void convertsConfiguredAttributeTypes() {
|
||||
assertThat(attribute("driver-1", AttributeTypeFlagEnum.STRING).getValue(String.class)).isEqualTo("driver-1");
|
||||
assertThat(attribute("9400", AttributeTypeFlagEnum.INT).getValue(Integer.class)).isEqualTo(9400);
|
||||
assertThat(attribute("true", AttributeTypeFlagEnum.BOOLEAN).getValue(Boolean.class)).isTrue();
|
||||
assertThat(attribute("driver-1", AttributeTypeEnum.STRING).getValue(String.class)).isEqualTo("driver-1");
|
||||
assertThat(attribute("9400", AttributeTypeEnum.INT).getValue(Integer.class)).isEqualTo(9400);
|
||||
assertThat(attribute("true", AttributeTypeEnum.BOOLEAN).getValue(Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsPrimitiveTargetClasses() {
|
||||
assertThat(attribute("9400", AttributeTypeFlagEnum.INT).getValue(Integer.TYPE)).isEqualTo(9400);
|
||||
assertThat(attribute("1", AttributeTypeFlagEnum.BOOLEAN).getValue(Boolean.TYPE)).isEqualTo(true);
|
||||
assertThat(attribute("9400", AttributeTypeEnum.INT).getValue(Integer.TYPE)).isEqualTo(9400);
|
||||
assertThat(attribute("1", AttributeTypeEnum.BOOLEAN).getValue(Boolean.TYPE)).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void strictBooleanRejectsAmbiguousValues() {
|
||||
assertThatThrownBy(() -> attribute("enabled", AttributeTypeFlagEnum.BOOLEAN).getValue(Boolean.class))
|
||||
assertThatThrownBy(() -> attribute("enabled", AttributeTypeEnum.BOOLEAN).getValue(Boolean.class))
|
||||
.isInstanceOf(TypeException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyStringAttributeIsAllowedForStringType() {
|
||||
assertThat(attribute("", AttributeTypeFlagEnum.STRING).getValue(String.class)).isEmpty();
|
||||
assertThat(attribute("", AttributeTypeEnum.STRING).getValue(String.class)).isEmpty();
|
||||
}
|
||||
|
||||
private AttributeBO attribute(String value, AttributeTypeFlagEnum type) {
|
||||
private AttributeBO attribute(String value, AttributeTypeEnum type) {
|
||||
return AttributeBO.builder().value(value).type(type).build();
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ import io.github.pnoker.common.driver.entity.bo.DriverBO;
|
||||
import io.github.pnoker.common.driver.entity.bo.RegisterBO;
|
||||
import io.github.pnoker.common.driver.entity.property.DriverProperties;
|
||||
import io.github.pnoker.common.driver.grpc.client.DriverClient;
|
||||
import io.github.pnoker.common.enums.DriverTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.DriverTypeEnum;
|
||||
import io.github.pnoker.common.exception.ServiceException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -58,7 +58,7 @@ class DriverRegisterServiceImplTest {
|
||||
properties.setTenant("default");
|
||||
properties.setClient("client-1");
|
||||
properties.setRemark("integration");
|
||||
properties.setType(DriverTypeFlagEnum.DRIVER_CLIENT);
|
||||
properties.setType(DriverTypeEnum.DRIVER_CLIENT);
|
||||
service = new DriverRegisterServiceImpl(properties, driverClient);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class DriverRegisterServiceImplTest {
|
||||
assertThat(driver.getDriverCode()).isEqualTo("modbus-tcp");
|
||||
assertThat(driver.getServiceName()).isEqualTo("dc3-driver-modbus-tcp");
|
||||
assertThat(driver.getServiceHost()).isEqualTo("127.0.0.1");
|
||||
assertThat(driver.getDriverTypeFlag()).isEqualTo(DriverTypeFlagEnum.DRIVER_CLIENT);
|
||||
assertThat(driver.getDriverTypeFlag()).isEqualTo(DriverTypeEnum.DRIVER_CLIENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -260,6 +260,6 @@ class ProfileServiceImplTest {
|
||||
when(profileManager.getOne(any(LambdaQueryWrapper.class))).thenReturn(doRow);
|
||||
when(profileBuilder.buildBOByDO(doRow)).thenReturn(bo);
|
||||
assertThat(service.getByNameAndType(100L, "DefaultProfile",
|
||||
io.github.pnoker.common.enums.ProfileTypeFlagEnum.SYSTEM)).isSameAs(bo);
|
||||
io.github.pnoker.common.enums.ProfileTypeEnum.SYSTEM)).isSameAs(bo);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@
|
||||
|
||||
package io.github.pnoker.common.entity.ext;
|
||||
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AlarmTargetTypeEnum;
|
||||
import io.github.pnoker.common.utils.JsonUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -128,7 +128,7 @@ class AlarmExtContractTest {
|
||||
1L,
|
||||
"temperature-high",
|
||||
"Temperature High",
|
||||
AlarmTargetTypeFlagEnum.POINT,
|
||||
AlarmTargetTypeEnum.POINT,
|
||||
1001L,
|
||||
"P1",
|
||||
"temperature_high",
|
||||
@@ -139,7 +139,7 @@ class AlarmExtContractTest {
|
||||
JsonUtil.toJsonString(content), RuleAlarmEventExt.Content.class);
|
||||
|
||||
assertThat(parsed.getRuleCode()).isEqualTo("temperature-high");
|
||||
assertThat(parsed.getTargetType()).isEqualTo(AlarmTargetTypeFlagEnum.POINT);
|
||||
assertThat(parsed.getTargetType()).isEqualTo(AlarmTargetTypeEnum.POINT);
|
||||
assertThat(parsed.getValues()).containsEntry("deviceId", 10);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -21,7 +21,7 @@ import io.github.pnoker.common.driver.entity.bean.DriverHealthState;
|
||||
import io.github.pnoker.common.driver.entity.bo.AttributeBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -47,14 +47,14 @@ class BleDriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> driverConfig(String deviceAddress) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("deviceAddress", AttributeBO.builder().value(deviceAddress).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("deviceAddress", AttributeBO.builder().value(deviceAddress).type(AttributeTypeEnum.STRING).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(String serviceUuid, String characteristicUuid) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("serviceUuid", AttributeBO.builder().value(serviceUuid).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("characteristicUuid", AttributeBO.builder().value(characteristicUuid).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("serviceUuid", AttributeBO.builder().value(serviceUuid).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("characteristicUuid", AttributeBO.builder().value(characteristicUuid).type(AttributeTypeEnum.STRING).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
+19
-19
@@ -25,10 +25,10 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.driver.coap.client.CoapClientManager;
|
||||
import io.github.pnoker.driver.coap.entity.CoapResult;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -110,12 +110,12 @@ class CoapDriverCustomServiceImplTest {
|
||||
void deviceDeleteReleasesRememberedClient() {
|
||||
Map<String, AttributeBO> driverConfig = new HashMap<>();
|
||||
driverConfig.put("deviceHost",
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeEnum.STRING).build());
|
||||
driverConfig.put("devicePort",
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeEnum.INT).build());
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("readPath",
|
||||
AttributeBO.builder().value("/sensors/temp").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("/sensors/temp").type(AttributeTypeEnum.STRING).build());
|
||||
when(coapClientManager.get(anyString(), anyString())).thenReturn(null);
|
||||
service.read(driverConfig, pointConfig, device(1L), point(1L));
|
||||
|
||||
@@ -128,13 +128,13 @@ class CoapDriverCustomServiceImplTest {
|
||||
void readReturnsValueFromCoapGet() {
|
||||
Map<String, AttributeBO> driverConfig = new HashMap<>();
|
||||
driverConfig.put("deviceHost",
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeEnum.STRING).build());
|
||||
driverConfig.put("devicePort",
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeEnum.INT).build());
|
||||
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("readPath",
|
||||
AttributeBO.builder().value("/sensors/temp").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("/sensors/temp").type(AttributeTypeEnum.STRING).build());
|
||||
|
||||
CoapResult mockResponse = CoapResult.builder()
|
||||
.statusCode(69)
|
||||
@@ -153,13 +153,13 @@ class CoapDriverCustomServiceImplTest {
|
||||
void readReturnsNullWhenCoapGetFails() {
|
||||
Map<String, AttributeBO> driverConfig = new HashMap<>();
|
||||
driverConfig.put("deviceHost",
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeEnum.STRING).build());
|
||||
driverConfig.put("devicePort",
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeEnum.INT).build());
|
||||
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("readPath",
|
||||
AttributeBO.builder().value("/sensors/temp").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("/sensors/temp").type(AttributeTypeEnum.STRING).build());
|
||||
|
||||
when(coapClientManager.get(anyString(), anyString())).thenReturn(null);
|
||||
|
||||
@@ -189,13 +189,13 @@ class CoapDriverCustomServiceImplTest {
|
||||
void writeSendsCoapPutAndReturnsTrueOnSuccess() {
|
||||
Map<String, AttributeBO> driverConfig = new HashMap<>();
|
||||
driverConfig.put("deviceHost",
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeEnum.STRING).build());
|
||||
driverConfig.put("devicePort",
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeEnum.INT).build());
|
||||
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("writePath",
|
||||
AttributeBO.builder().value("/actuators/relay").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("/actuators/relay").type(AttributeTypeEnum.STRING).build());
|
||||
|
||||
CoapResult mockResponse = CoapResult.builder()
|
||||
.statusCode(68)
|
||||
@@ -204,7 +204,7 @@ class CoapDriverCustomServiceImplTest {
|
||||
when(coapClientManager.put("coap://192.168.1.10:5683", "/actuators/relay", "ON")).thenReturn(mockResponse);
|
||||
|
||||
Boolean result = service.write(driverConfig, pointConfig, device(1L), point(1L),
|
||||
WritePointValue.builder().value("ON").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("ON").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
@@ -213,18 +213,18 @@ class CoapDriverCustomServiceImplTest {
|
||||
void writeReturnsFalseWhenCoapPutFails() {
|
||||
Map<String, AttributeBO> driverConfig = new HashMap<>();
|
||||
driverConfig.put("deviceHost",
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("192.168.1.10").type(AttributeTypeEnum.STRING).build());
|
||||
driverConfig.put("devicePort",
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value("5683").type(AttributeTypeEnum.INT).build());
|
||||
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("writePath",
|
||||
AttributeBO.builder().value("/actuators/relay").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("/actuators/relay").type(AttributeTypeEnum.STRING).build());
|
||||
|
||||
when(coapClientManager.put(anyString(), anyString(), anyString())).thenReturn(null);
|
||||
|
||||
Boolean result = service.write(driverConfig, pointConfig, device(1L), point(1L),
|
||||
WritePointValue.builder().value("ON").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("ON").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
+4
-4
@@ -25,7 +25,7 @@ import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.driver.service.netty.tcp.NettyTcpServer;
|
||||
import io.github.pnoker.driver.service.netty.udp.NettyUdpServer;
|
||||
import io.netty.channel.Channel;
|
||||
@@ -157,7 +157,7 @@ class ListeningVirtualDriverCustomServiceImplTest {
|
||||
NettyTcpServer.registerDeviceChannel(900L, channel);
|
||||
|
||||
Boolean ok = service.write(null, null, device, point,
|
||||
WritePointValue.builder().value("hello").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("hello").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(channel).writeAndFlush(any(byte[].class));
|
||||
@@ -176,7 +176,7 @@ class ListeningVirtualDriverCustomServiceImplTest {
|
||||
NettyTcpServer.registerDeviceChannel(902L, channel);
|
||||
|
||||
Boolean ok = service.write(null, null, device, point,
|
||||
WritePointValue.builder().value("hello").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("hello").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(ok).isFalse();
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class ListeningVirtualDriverCustomServiceImplTest {
|
||||
PointBO point = point(2L);
|
||||
|
||||
Boolean ok = service.write(null, null, device, point,
|
||||
WritePointValue.builder().value("hello").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("hello").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(ok).isFalse();
|
||||
// No channel was registered, so nothing was flushed.
|
||||
|
||||
+6
-6
@@ -24,7 +24,7 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DeviceMetadata;
|
||||
import io.github.pnoker.common.driver.metadata.PointMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -76,9 +76,9 @@ class NettyServerHandlerTest {
|
||||
device.setId(123L);
|
||||
when(deviceMetadata.getCache(123L)).thenReturn(device);
|
||||
when(deviceMetadata.getPointConfig(123L)).thenReturn(Map.of(1L, Map.of(
|
||||
"key", AttributeBO.builder().value("62").type(AttributeTypeFlagEnum.STRING).build(),
|
||||
"start", AttributeBO.builder().value("23").type(AttributeTypeFlagEnum.INT).build(),
|
||||
"end", AttributeBO.builder().value("28").type(AttributeTypeFlagEnum.INT).build()
|
||||
"key", AttributeBO.builder().value("62").type(AttributeTypeEnum.STRING).build(),
|
||||
"start", AttributeBO.builder().value("23").type(AttributeTypeEnum.INT).build(),
|
||||
"end", AttributeBO.builder().value("28").type(AttributeTypeEnum.INT).build()
|
||||
)));
|
||||
PointBO point = new PointBO();
|
||||
point.setId(1L);
|
||||
@@ -107,8 +107,8 @@ class NettyServerHandlerTest {
|
||||
device.setId(123L);
|
||||
when(deviceMetadata.getCache(123L)).thenReturn(device);
|
||||
when(deviceMetadata.getPointConfig(123L)).thenReturn(Map.of(1L, Map.of(
|
||||
"key", AttributeBO.builder().value("62").type(AttributeTypeFlagEnum.STRING).build(),
|
||||
"start", AttributeBO.builder().value("23").type(AttributeTypeFlagEnum.INT).build()
|
||||
"key", AttributeBO.builder().value("62").type(AttributeTypeEnum.STRING).build(),
|
||||
"start", AttributeBO.builder().value("23").type(AttributeTypeEnum.INT).build()
|
||||
)));
|
||||
PointBO point = new PointBO();
|
||||
point.setId(1L);
|
||||
|
||||
+14
-14
@@ -26,10 +26,10 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.driver.bean.MelsecPointVariable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -67,16 +67,16 @@ class MelsecDriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> driverConfig() {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("host", AttributeBO.builder().value("127.0.0.1").type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value("5000").type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("series", AttributeBO.builder().value("QnA").type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("host", AttributeBO.builder().value("127.0.0.1").type(AttributeTypeEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value("5000").type(AttributeTypeEnum.INT).build());
|
||||
m.put("series", AttributeBO.builder().value("QnA").type(AttributeTypeEnum.STRING).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(String address, int length) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("address", AttributeBO.builder().value(address).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("length", AttributeBO.builder().value(String.valueOf(length)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("address", AttributeBO.builder().value(address).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("length", AttributeBO.builder().value(String.valueOf(length)).type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class MelsecDriverCustomServiceImplTest {
|
||||
return device;
|
||||
}
|
||||
|
||||
private static PointBO point(PointTypeFlagEnum type) {
|
||||
private static PointBO point(PointTypeEnum type) {
|
||||
PointBO point = new PointBO();
|
||||
point.setId(1L);
|
||||
point.setPointTypeFlag(type);
|
||||
@@ -132,7 +132,7 @@ class MelsecDriverCustomServiceImplTest {
|
||||
when(plc.readInt32("D100")).thenReturn(42);
|
||||
|
||||
ReadPointValue value = service.read(driverConfig(), pointConfig("D100", 0),
|
||||
device(11L), point(PointTypeFlagEnum.INT));
|
||||
device(11L), point(PointTypeEnum.INT));
|
||||
|
||||
assertThat(value.getValue()).isEqualTo("42");
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class MelsecDriverCustomServiceImplTest {
|
||||
when(plc.readInt32(anyString())).thenThrow(new RuntimeException("plc offline"));
|
||||
|
||||
ReadPointValue value = service.read(driverConfig(), pointConfig("D100", 0),
|
||||
device(12L), point(PointTypeFlagEnum.INT));
|
||||
device(12L), point(PointTypeEnum.INT));
|
||||
|
||||
assertThat(value).isNull();
|
||||
assertThat(connectionMap()).doesNotContainKey(12L);
|
||||
@@ -155,8 +155,8 @@ class MelsecDriverCustomServiceImplTest {
|
||||
primeCachedPLC(13L);
|
||||
|
||||
Boolean ok = service.write(driverConfig(), pointConfig("D100", 0),
|
||||
device(13L), point(PointTypeFlagEnum.INT),
|
||||
WritePointValue.builder().value("7").type(PointTypeFlagEnum.INT).build());
|
||||
device(13L), point(PointTypeEnum.INT),
|
||||
WritePointValue.builder().value("7").type(PointTypeEnum.INT).build());
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(plc).writeInt32("D100", 7);
|
||||
@@ -168,8 +168,8 @@ class MelsecDriverCustomServiceImplTest {
|
||||
doThrow(new RuntimeException("plc offline")).when(plc).writeInt32(anyString(), org.mockito.ArgumentMatchers.anyInt());
|
||||
|
||||
Boolean ok = service.write(driverConfig(), pointConfig("D100", 0),
|
||||
device(14L), point(PointTypeFlagEnum.INT),
|
||||
WritePointValue.builder().value("7").type(PointTypeFlagEnum.INT).build());
|
||||
device(14L), point(PointTypeEnum.INT),
|
||||
WritePointValue.builder().value("7").type(PointTypeEnum.INT).build());
|
||||
|
||||
assertThat(ok).isFalse();
|
||||
assertThat(connectionMap()).doesNotContainKey(14L);
|
||||
|
||||
+18
-18
@@ -28,10 +28,10 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.common.exception.ConnectorException;
|
||||
import io.github.pnoker.common.exception.ReadPointException;
|
||||
import io.github.pnoker.common.exception.UnSupportException;
|
||||
@@ -83,19 +83,19 @@ class ModbusRtuDriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> driverConfig() {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("port", AttributeBO.builder().value("/dev/ttyS0").type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("baudRate", AttributeBO.builder().value("9600").type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("dataBits", AttributeBO.builder().value("8").type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("stopBits", AttributeBO.builder().value("1").type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("parity", AttributeBO.builder().value("0").type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("port", AttributeBO.builder().value("/dev/ttyS0").type(AttributeTypeEnum.STRING).build());
|
||||
m.put("baudRate", AttributeBO.builder().value("9600").type(AttributeTypeEnum.INT).build());
|
||||
m.put("dataBits", AttributeBO.builder().value("8").type(AttributeTypeEnum.INT).build());
|
||||
m.put("stopBits", AttributeBO.builder().value("1").type(AttributeTypeEnum.INT).build());
|
||||
m.put("parity", AttributeBO.builder().value("0").type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(int slaveId, int functionCode, int offset) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("slaveId", AttributeBO.builder().value(String.valueOf(slaveId)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("functionCode", AttributeBO.builder().value(String.valueOf(functionCode)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("offset", AttributeBO.builder().value(String.valueOf(offset)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("slaveId", AttributeBO.builder().value(String.valueOf(slaveId)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("functionCode", AttributeBO.builder().value(String.valueOf(functionCode)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("offset", AttributeBO.builder().value(String.valueOf(offset)).type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class ModbusRtuDriverCustomServiceImplTest {
|
||||
return device;
|
||||
}
|
||||
|
||||
private static PointBO point(PointTypeFlagEnum type) {
|
||||
private static PointBO point(PointTypeEnum type) {
|
||||
PointBO point = new PointBO();
|
||||
point.setId(1L);
|
||||
point.setPointTypeFlag(type);
|
||||
@@ -138,9 +138,9 @@ class ModbusRtuDriverCustomServiceImplTest {
|
||||
when(modbusMaster.getValue(any(BaseLocator.class))).thenReturn(true, 42);
|
||||
|
||||
assertThat(service.read(driverConfig(), pointConfig(1, 1, 0), device(10L),
|
||||
point(PointTypeFlagEnum.BOOLEAN)).getValue()).isEqualTo("true");
|
||||
point(PointTypeEnum.BOOLEAN)).getValue()).isEqualTo("true");
|
||||
assertThat(service.read(driverConfig(), pointConfig(1, 3, 0), device(10L),
|
||||
point(PointTypeFlagEnum.INT)).getValue()).isEqualTo("42");
|
||||
point(PointTypeEnum.INT)).getValue()).isEqualTo("42");
|
||||
|
||||
verify(modbusFactory, times(1)).createRtuMaster(any(JSerialCommWrapper.class));
|
||||
}
|
||||
@@ -150,7 +150,7 @@ class ModbusRtuDriverCustomServiceImplTest {
|
||||
when(modbusFactory.createRtuMaster(any(JSerialCommWrapper.class))).thenReturn(modbusMaster);
|
||||
|
||||
assertThatThrownBy(() -> service.read(driverConfig(), pointConfig(1, 99, 0), device(10L),
|
||||
point(PointTypeFlagEnum.INT))).isInstanceOf(UnSupportException.class);
|
||||
point(PointTypeEnum.INT))).isInstanceOf(UnSupportException.class);
|
||||
verify(modbusMaster, never()).getValue(any(BaseLocator.class));
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ class ModbusRtuDriverCustomServiceImplTest {
|
||||
when(modbusMaster.getValue(any(BaseLocator.class))).thenThrow(new ModbusTransportException("serial down"));
|
||||
|
||||
assertThatThrownBy(() -> service.read(driverConfig(), pointConfig(1, 3, 0), device(20L),
|
||||
point(PointTypeFlagEnum.INT))).isInstanceOf(ReadPointException.class)
|
||||
point(PointTypeEnum.INT))).isInstanceOf(ReadPointException.class)
|
||||
.hasMessageContaining("serial down");
|
||||
verify(modbusMaster).destroy();
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class ModbusRtuDriverCustomServiceImplTest {
|
||||
doThrow(new ModbusInitException("offline")).when(modbusMaster).init();
|
||||
|
||||
assertThatThrownBy(() -> service.read(driverConfig(), pointConfig(1, 1, 0), device(10L),
|
||||
point(PointTypeFlagEnum.INT))).isInstanceOf(ConnectorException.class)
|
||||
point(PointTypeEnum.INT))).isInstanceOf(ConnectorException.class)
|
||||
.hasMessageContaining("offline");
|
||||
verify(modbusMaster).destroy();
|
||||
}
|
||||
@@ -181,9 +181,9 @@ class ModbusRtuDriverCustomServiceImplTest {
|
||||
when(modbusFactory.createRtuMaster(any(JSerialCommWrapper.class))).thenReturn(modbusMaster);
|
||||
when(modbusMaster.getValue(any(BaseLocator.class))).thenReturn(true);
|
||||
|
||||
service.read(driverConfig(), pointConfig(1, 1, 0), device(30L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig(), pointConfig(1, 1, 0), device(30L), point(PointTypeEnum.BOOLEAN));
|
||||
service.event(metadataEvent(MetadataTypeEnum.DEVICE, MetadataOperateTypeEnum.UPDATE, 30L));
|
||||
service.read(driverConfig(), pointConfig(1, 1, 0), device(30L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig(), pointConfig(1, 1, 0), device(30L), point(PointTypeEnum.BOOLEAN));
|
||||
|
||||
verify(modbusFactory, times(2)).createRtuMaster(any(JSerialCommWrapper.class));
|
||||
verify(modbusMaster).destroy();
|
||||
|
||||
+34
-34
@@ -34,11 +34,11 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.common.exception.ConnectorException;
|
||||
import io.github.pnoker.common.exception.ReadPointException;
|
||||
import io.github.pnoker.common.exception.UnSupportException;
|
||||
@@ -95,18 +95,18 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> driverConfig(String host, int port) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("host", AttributeBO.builder().value(host).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value(String.valueOf(port)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("host", AttributeBO.builder().value(host).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value(String.valueOf(port)).type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(int slaveId, int functionCode, int offset) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("slaveId",
|
||||
AttributeBO.builder().value(String.valueOf(slaveId)).type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value(String.valueOf(slaveId)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("functionCode",
|
||||
AttributeBO.builder().value(String.valueOf(functionCode)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("offset", AttributeBO.builder().value(String.valueOf(offset)).type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value(String.valueOf(functionCode)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("offset", AttributeBO.builder().value(String.valueOf(offset)).type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -116,14 +116,14 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
return device;
|
||||
}
|
||||
|
||||
private static PointBO point(PointTypeFlagEnum type) {
|
||||
private static PointBO point(PointTypeEnum type) {
|
||||
PointBO point = new PointBO();
|
||||
point.setId(1L);
|
||||
point.setPointTypeFlag(type);
|
||||
return point;
|
||||
}
|
||||
|
||||
private static WritePointValue writePointValue(String value, PointTypeFlagEnum type) {
|
||||
private static WritePointValue writePointValue(String value, PointTypeEnum type) {
|
||||
return WritePointValue.builder().value(value).type(type).build();
|
||||
}
|
||||
|
||||
@@ -177,27 +177,27 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
@Test
|
||||
void deviceUpdateInvalidatesCachedConnection() throws Exception {
|
||||
when(modbusFactory.createTcpMaster(any(IpParameters.class), eq(true))).thenReturn(modbusMaster);
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(123L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(123L), point(PointTypeEnum.BOOLEAN));
|
||||
service.event(metadataEvent(MetadataTypeEnum.DEVICE, MetadataOperateTypeEnum.UPDATE, 123L));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(123L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(123L), point(PointTypeEnum.BOOLEAN));
|
||||
verify(modbusFactory, times(2)).createTcpMaster(any(IpParameters.class), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deviceDeleteInvalidatesCachedConnection() throws Exception {
|
||||
when(modbusFactory.createTcpMaster(any(IpParameters.class), eq(true))).thenReturn(modbusMaster);
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(456L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(456L), point(PointTypeEnum.BOOLEAN));
|
||||
service.event(metadataEvent(MetadataTypeEnum.DEVICE, MetadataOperateTypeEnum.DELETE, 456L));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(456L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(456L), point(PointTypeEnum.BOOLEAN));
|
||||
verify(modbusFactory, times(2)).createTcpMaster(any(IpParameters.class), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pointEventDoesNotTouchConnectionMap() throws Exception {
|
||||
when(modbusFactory.createTcpMaster(any(IpParameters.class), eq(true))).thenReturn(modbusMaster);
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(789L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(789L), point(PointTypeEnum.BOOLEAN));
|
||||
service.event(metadataEvent(MetadataTypeEnum.POINT, MetadataOperateTypeEnum.UPDATE, 999L));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(789L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("h", 502), pointConfig(1, 1, 0), device(789L), point(PointTypeEnum.BOOLEAN));
|
||||
verify(modbusFactory, times(1)).createTcpMaster(any(IpParameters.class), eq(true));
|
||||
}
|
||||
|
||||
@@ -206,8 +206,8 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusFactory.createTcpMaster(any(IpParameters.class), eq(true))).thenReturn(modbusMaster);
|
||||
when(modbusMaster.getValue(any(BaseLocator.class))).thenReturn(true);
|
||||
|
||||
service.read(driverConfig("host", 1502), pointConfig(1, 1, 0), device(1L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("host", 1502), pointConfig(1, 1, 0), device(1L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
service.read(driverConfig("host", 1502), pointConfig(1, 1, 0), device(1L), point(PointTypeEnum.BOOLEAN));
|
||||
service.read(driverConfig("host", 1502), pointConfig(1, 1, 0), device(1L), point(PointTypeEnum.BOOLEAN));
|
||||
|
||||
verify(modbusFactory, times(1)).createTcpMaster(any(IpParameters.class), eq(true));
|
||||
verify(modbusMaster, times(1)).init();
|
||||
@@ -219,7 +219,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
doThrow(new ModbusInitException("offline")).when(modbusMaster).init();
|
||||
|
||||
assertThatThrownBy(() -> service.read(driverConfig("host", 1502), pointConfig(1, 1, 0), device(7L),
|
||||
point(PointTypeFlagEnum.INT))).isInstanceOf(ConnectorException.class)
|
||||
point(PointTypeEnum.INT))).isInstanceOf(ConnectorException.class)
|
||||
.hasMessageContaining("offline");
|
||||
verify(modbusMaster).destroy();
|
||||
}
|
||||
@@ -230,16 +230,16 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusMaster.getValue(any(BaseLocator.class))).thenReturn(true, false, 42, 7);
|
||||
|
||||
assertThat(
|
||||
service.read(driverConfig("h", 1), pointConfig(1, 1, 0), device(2L), point(PointTypeFlagEnum.BOOLEAN))
|
||||
service.read(driverConfig("h", 1), pointConfig(1, 1, 0), device(2L), point(PointTypeEnum.BOOLEAN))
|
||||
.getValue())
|
||||
.isEqualTo("true");
|
||||
assertThat(
|
||||
service.read(driverConfig("h", 1), pointConfig(1, 2, 0), device(2L), point(PointTypeFlagEnum.BOOLEAN))
|
||||
service.read(driverConfig("h", 1), pointConfig(1, 2, 0), device(2L), point(PointTypeEnum.BOOLEAN))
|
||||
.getValue())
|
||||
.isEqualTo("false");
|
||||
assertThat(service.read(driverConfig("h", 1), pointConfig(1, 3, 0), device(2L), point(PointTypeFlagEnum.INT))
|
||||
assertThat(service.read(driverConfig("h", 1), pointConfig(1, 3, 0), device(2L), point(PointTypeEnum.INT))
|
||||
.getValue()).isEqualTo("42");
|
||||
assertThat(service.read(driverConfig("h", 1), pointConfig(1, 4, 0), device(2L), point(PointTypeFlagEnum.INT))
|
||||
assertThat(service.read(driverConfig("h", 1), pointConfig(1, 4, 0), device(2L), point(PointTypeEnum.INT))
|
||||
.getValue()).isEqualTo("7");
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusFactory.createTcpMaster(any(IpParameters.class), eq(true))).thenReturn(modbusMaster);
|
||||
// Function code 99 is not handled.
|
||||
assertThatThrownBy(() -> service.read(driverConfig("h", 1), pointConfig(1, 99, 0),
|
||||
device(2L), point(PointTypeFlagEnum.INT))).isInstanceOf(UnSupportException.class)
|
||||
device(2L), point(PointTypeEnum.INT))).isInstanceOf(UnSupportException.class)
|
||||
.hasMessageContaining("function code");
|
||||
verify(modbusMaster, never()).getValue(any(BaseLocator.class));
|
||||
}
|
||||
@@ -259,7 +259,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusMaster.getValue(any(BaseLocator.class))).thenThrow(new ModbusTransportException("rs485 down"));
|
||||
|
||||
assertThatThrownBy(() -> service.read(driverConfig("h", 1), pointConfig(1, 3, 0), device(3L),
|
||||
point(PointTypeFlagEnum.INT))).isInstanceOf(ReadPointException.class)
|
||||
point(PointTypeEnum.INT))).isInstanceOf(ReadPointException.class)
|
||||
.hasMessageContaining("rs485 down");
|
||||
verify(modbusMaster).destroy();
|
||||
}
|
||||
@@ -273,7 +273,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusMaster.getValue(any(BaseLocator.class))).thenThrow(new ErrorResponseException(null, errorResponse));
|
||||
|
||||
assertThatThrownBy(() -> service.read(driverConfig("h", 1), pointConfig(1, 4, 0), device(3L),
|
||||
point(PointTypeFlagEnum.INT))).isInstanceOf(ReadPointException.class)
|
||||
point(PointTypeEnum.INT))).isInstanceOf(ReadPointException.class)
|
||||
.hasMessageContaining("illegal data address");
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusMaster.send(any(com.serotonin.modbus4j.msg.WriteCoilRequest.class))).thenReturn(response);
|
||||
|
||||
Boolean ok = service.write(driverConfig("h", 1), pointConfig(1, 1, 0), device(7L),
|
||||
point(PointTypeFlagEnum.BOOLEAN), writePointValue("true", PointTypeFlagEnum.BOOLEAN));
|
||||
point(PointTypeEnum.BOOLEAN), writePointValue("true", PointTypeEnum.BOOLEAN));
|
||||
assertThat(ok).isTrue();
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusMaster.send(any(com.serotonin.modbus4j.msg.WriteCoilRequest.class))).thenReturn(response);
|
||||
|
||||
Boolean ok = service.write(driverConfig("h", 1), pointConfig(1, 1, 0), device(7L),
|
||||
point(PointTypeFlagEnum.BOOLEAN), writePointValue("false", PointTypeFlagEnum.BOOLEAN));
|
||||
point(PointTypeEnum.BOOLEAN), writePointValue("false", PointTypeEnum.BOOLEAN));
|
||||
assertThat(ok).isFalse();
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
.thenThrow(new ModbusTransportException("transport reset"));
|
||||
|
||||
assertThatThrownBy(() -> service.write(driverConfig("h", 1), pointConfig(1, 1, 0), device(7L),
|
||||
point(PointTypeFlagEnum.BOOLEAN), writePointValue("true", PointTypeFlagEnum.BOOLEAN)))
|
||||
point(PointTypeEnum.BOOLEAN), writePointValue("true", PointTypeEnum.BOOLEAN)))
|
||||
.isInstanceOf(WritePointException.class)
|
||||
.hasMessageContaining("transport reset");
|
||||
verify(modbusMaster).destroy();
|
||||
@@ -319,7 +319,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
when(modbusFactory.createTcpMaster(any(IpParameters.class), eq(true))).thenReturn(modbusMaster);
|
||||
|
||||
Boolean ok = service.write(driverConfig("h", 1), pointConfig(1, 3, 0), device(8L),
|
||||
point(PointTypeFlagEnum.FLOAT), writePointValue("3.14", PointTypeFlagEnum.FLOAT));
|
||||
point(PointTypeEnum.FLOAT), writePointValue("3.14", PointTypeEnum.FLOAT));
|
||||
assertThat(ok).isTrue();
|
||||
verify(modbusMaster).setValue(any(BaseLocator.class), any());
|
||||
}
|
||||
@@ -330,7 +330,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
doThrow(new ModbusTransportException("offline")).when(modbusMaster).setValue(any(BaseLocator.class), any());
|
||||
|
||||
assertThatThrownBy(() -> service.write(driverConfig("h", 1), pointConfig(1, 3, 0), device(8L),
|
||||
point(PointTypeFlagEnum.FLOAT), writePointValue("1.0", PointTypeFlagEnum.FLOAT)))
|
||||
point(PointTypeEnum.FLOAT), writePointValue("1.0", PointTypeEnum.FLOAT)))
|
||||
.isInstanceOf(WritePointException.class)
|
||||
.hasMessageContaining("offline");
|
||||
}
|
||||
@@ -367,7 +367,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
void validatePointReportsMissingAttributes() {
|
||||
Map<String, AttributeBO> empty = Map.of();
|
||||
ValidationReport report = service.validatePoint(empty,
|
||||
point(PointTypeFlagEnum.INT));
|
||||
point(PointTypeEnum.INT));
|
||||
assertThat(report.isPassed()).isFalse();
|
||||
assertThat(report.getIssues()).hasSize(3);
|
||||
assertThat(report.getIssues()).extracting("attributeCode")
|
||||
@@ -378,7 +378,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
void validatePointReportsInvalidFunctionCode() {
|
||||
Map<String, AttributeBO> config = pointConfig(1, 99, 0);
|
||||
ValidationReport report = service.validatePoint(config,
|
||||
point(PointTypeFlagEnum.INT));
|
||||
point(PointTypeEnum.INT));
|
||||
assertThat(report.isPassed()).isFalse();
|
||||
assertThat(report.getIssues()).extracting("attributeCode")
|
||||
.contains("functionCode");
|
||||
@@ -388,7 +388,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
void validatePointPassesWithValidConfig() {
|
||||
Map<String, AttributeBO> config = pointConfig(1, 3, 100);
|
||||
ValidationReport report = service.validatePoint(config,
|
||||
point(PointTypeFlagEnum.INT));
|
||||
point(PointTypeEnum.INT));
|
||||
assertThat(report.isPassed()).isTrue();
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ class ModbusTcpDriverCustomServiceImplTest {
|
||||
void writeUnsupportedFunctionCodeReturnsFalse() throws Exception {
|
||||
when(modbusFactory.createTcpMaster(any(IpParameters.class), eq(true))).thenReturn(modbusMaster);
|
||||
Boolean ok = service.write(driverConfig("h", 1), pointConfig(1, 4, 0), device(8L),
|
||||
point(PointTypeFlagEnum.INT), writePointValue("1", PointTypeFlagEnum.INT));
|
||||
point(PointTypeEnum.INT), writePointValue("1", PointTypeEnum.INT));
|
||||
assertThat(ok).isFalse();
|
||||
verify(modbusMaster, never()).setValue(any(BaseLocator.class), any());
|
||||
verify(modbusMaster, never()).send(any(com.serotonin.modbus4j.msg.WriteCoilRequest.class));
|
||||
|
||||
+5
-5
@@ -27,9 +27,9 @@ import io.github.pnoker.common.driver.metadata.DeviceMetadata;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.EventReportDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.EnableFlagEnum;
|
||||
import io.github.pnoker.common.enums.EventLevelFlagEnum;
|
||||
import io.github.pnoker.common.enums.EventLevelEnum;
|
||||
import io.github.pnoker.common.enums.EventTypeFlagEnum;
|
||||
import io.github.pnoker.common.facade.api.EventFacade;
|
||||
import io.github.pnoker.common.facade.entity.bo.FacadeEventBO;
|
||||
@@ -79,7 +79,7 @@ class MqttReceiveServiceImplTest {
|
||||
EventAttributeDTO attribute = new EventAttributeDTO();
|
||||
attribute.setId(id);
|
||||
attribute.setAttributeCode(code);
|
||||
attribute.setAttributeTypeFlag(AttributeTypeFlagEnum.STRING);
|
||||
attribute.setAttributeTypeFlag(AttributeTypeEnum.STRING);
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ class MqttReceiveServiceImplTest {
|
||||
event.setTenantId(1L);
|
||||
event.setEventCode("alarm");
|
||||
event.setEventTypeFlag(EventTypeFlagEnum.ALERT);
|
||||
event.setEventLevelFlag(EventLevelFlagEnum.HIGH);
|
||||
event.setEventLevelFlag(EventLevelEnum.HIGH);
|
||||
event.setEnableFlag(EnableFlagEnum.ENABLE);
|
||||
when(eventFacade.getById(1L, 20L)).thenReturn(event);
|
||||
|
||||
@@ -215,7 +215,7 @@ class MqttReceiveServiceImplTest {
|
||||
event.setTenantId(1L);
|
||||
event.setEventCode("alarm");
|
||||
event.setEventTypeFlag(EventTypeFlagEnum.ALERT);
|
||||
event.setEventLevelFlag(EventLevelFlagEnum.HIGH);
|
||||
event.setEventLevelFlag(EventLevelEnum.HIGH);
|
||||
event.setEnableFlag(EnableFlagEnum.ENABLE);
|
||||
when(eventFacade.getById(1L, 20L)).thenReturn(event);
|
||||
|
||||
|
||||
+10
-10
@@ -24,10 +24,10 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.driver.service.MqttSendService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -114,11 +114,11 @@ class MqttDriverCustomServiceImplTest {
|
||||
void writePublishesWithConfiguredQosWhenAvailable() {
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("commandTopic",
|
||||
AttributeBO.builder().value("dc3/cmd/temp").type(AttributeTypeFlagEnum.STRING).build());
|
||||
pointConfig.put("commandQos", AttributeBO.builder().value("1").type(AttributeTypeFlagEnum.INT).build());
|
||||
AttributeBO.builder().value("dc3/cmd/temp").type(AttributeTypeEnum.STRING).build());
|
||||
pointConfig.put("commandQos", AttributeBO.builder().value("1").type(AttributeTypeEnum.INT).build());
|
||||
|
||||
Boolean ok = service.write(null, pointConfig, device(1L), point(1L),
|
||||
WritePointValue.builder().value("23.5").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("23.5").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(mqttSendService).sendToMqtt("dc3/cmd/temp", 1, "23.5");
|
||||
@@ -129,11 +129,11 @@ class MqttDriverCustomServiceImplTest {
|
||||
void writeFallsBackToDefaultQosWhenLookupFails() {
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("commandTopic",
|
||||
AttributeBO.builder().value("dc3/cmd/temp").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("dc3/cmd/temp").type(AttributeTypeEnum.STRING).build());
|
||||
// commandQos missing entirely → service catches NPE and falls back
|
||||
|
||||
Boolean ok = service.write(null, pointConfig, device(1L), point(1L),
|
||||
WritePointValue.builder().value("23.5").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("23.5").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(mqttSendService).sendToMqtt("dc3/cmd/temp", "23.5");
|
||||
@@ -143,14 +143,14 @@ class MqttDriverCustomServiceImplTest {
|
||||
void writeFallsBackToDefaultQosWhenQosTypeIsWrong() {
|
||||
Map<String, AttributeBO> pointConfig = new HashMap<>();
|
||||
pointConfig.put("commandTopic",
|
||||
AttributeBO.builder().value("dc3/cmd/temp").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("dc3/cmd/temp").type(AttributeTypeEnum.STRING).build());
|
||||
// commandQos present but as STRING -> AttributeBO.getValue(Integer.class) throws
|
||||
// TypeException, service catches and falls back to default-QoS overload.
|
||||
pointConfig.put("commandQos",
|
||||
AttributeBO.builder().value("not-a-number").type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value("not-a-number").type(AttributeTypeEnum.STRING).build());
|
||||
|
||||
Boolean ok = service.write(null, pointConfig, device(1L), point(1L),
|
||||
WritePointValue.builder().value("23.5").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("23.5").type(PointTypeEnum.STRING).build());
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(mqttSendService).sendToMqtt("dc3/cmd/temp", "23.5");
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ import io.github.pnoker.common.driver.entity.bo.AttributeBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import org.jinterop.dcom.core.JIVariant;
|
||||
@@ -64,8 +64,8 @@ class OpcDaDriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(String group, String tag) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("group", AttributeBO.builder().value(group).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("tag", AttributeBO.builder().value(tag).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("group", AttributeBO.builder().value(group).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("tag", AttributeBO.builder().value(tag).type(AttributeTypeEnum.STRING).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -24,10 +24,10 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.common.exception.ConnectorException;
|
||||
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
|
||||
import org.eclipse.milo.opcua.stack.core.UaException;
|
||||
@@ -72,17 +72,17 @@ class OpcUaDriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> driverConfig(String host, int port, String path) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("host", AttributeBO.builder().value(host).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value(String.valueOf(port)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("path", AttributeBO.builder().value(path).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("host", AttributeBO.builder().value(host).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value(String.valueOf(port)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("path", AttributeBO.builder().value(path).type(AttributeTypeEnum.STRING).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(int namespace, String tag) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("namespace",
|
||||
AttributeBO.builder().value(String.valueOf(namespace)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("tag", AttributeBO.builder().value(tag).type(AttributeTypeFlagEnum.STRING).build());
|
||||
AttributeBO.builder().value(String.valueOf(namespace)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("tag", AttributeBO.builder().value(tag).type(AttributeTypeEnum.STRING).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class OpcUaDriverCustomServiceImplTest {
|
||||
return device;
|
||||
}
|
||||
|
||||
private static PointBO point(PointTypeFlagEnum type) {
|
||||
private static PointBO point(PointTypeEnum type) {
|
||||
PointBO point = new PointBO();
|
||||
point.setId(1L);
|
||||
point.setPointTypeFlag(type);
|
||||
@@ -183,7 +183,7 @@ class OpcUaDriverCustomServiceImplTest {
|
||||
any(Function.class))).thenThrow(new UaException(0L, "endpoint refused"));
|
||||
|
||||
assertThatThrownBy(() -> service.read(driverConfig("h", 4840, "/"), pointConfig(2, "tag.x"),
|
||||
device(1L), point(PointTypeFlagEnum.STRING))).isInstanceOf(ConnectorException.class)
|
||||
device(1L), point(PointTypeEnum.STRING))).isInstanceOf(ConnectorException.class)
|
||||
.hasMessageContaining("endpoint refused");
|
||||
assertThat(connectionMap()).doesNotContainKey(1L);
|
||||
}
|
||||
@@ -220,7 +220,7 @@ class OpcUaDriverCustomServiceImplTest {
|
||||
method.setAccessible(true);
|
||||
|
||||
Boolean ok = (Boolean) method.invoke(service, client, new NodeId(2, "tag.x"),
|
||||
WritePointValue.builder().value("7").type(PointTypeFlagEnum.INT).build());
|
||||
WritePointValue.builder().value("7").type(PointTypeEnum.INT).build());
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
}
|
||||
|
||||
+22
-22
@@ -26,10 +26,10 @@ import io.github.pnoker.common.driver.entity.bo.PointBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import io.github.pnoker.driver.bean.PlcS7PointVariable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -68,17 +68,17 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> driverConfig(String host, int port) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("host", AttributeBO.builder().value(host).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value(String.valueOf(port)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("plcType", AttributeBO.builder().value("S1200").type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("host", AttributeBO.builder().value(host).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("port", AttributeBO.builder().value(String.valueOf(port)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("plcType", AttributeBO.builder().value("S1200").type(AttributeTypeEnum.STRING).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(int dbNum, int byteOffset, int bitOffset) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("dbNum", AttributeBO.builder().value(String.valueOf(dbNum)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("byteOffset", AttributeBO.builder().value(String.valueOf(byteOffset)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("bitOffset", AttributeBO.builder().value(String.valueOf(bitOffset)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("dbNum", AttributeBO.builder().value(String.valueOf(dbNum)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("byteOffset", AttributeBO.builder().value(String.valueOf(byteOffset)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("bitOffset", AttributeBO.builder().value(String.valueOf(bitOffset)).type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -88,14 +88,14 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
return d;
|
||||
}
|
||||
|
||||
private static PointBO point(PointTypeFlagEnum type) {
|
||||
private static PointBO point(PointTypeEnum type) {
|
||||
PointBO p = new PointBO();
|
||||
p.setId(1L);
|
||||
p.setPointTypeFlag(type);
|
||||
return p;
|
||||
}
|
||||
|
||||
private static WritePointValue writePointValue(String value, PointTypeFlagEnum type) {
|
||||
private static WritePointValue writePointValue(String value, PointTypeEnum type) {
|
||||
return WritePointValue.builder().value(value).type(type).build();
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
when(plc.readInt32("DB1.0")).thenReturn(42);
|
||||
|
||||
ReadPointValue r = service.read(driverConfig("h", 102), pointConfig(1, 0, 0),
|
||||
device(10L), point(PointTypeFlagEnum.INT));
|
||||
device(10L), point(PointTypeEnum.INT));
|
||||
|
||||
assertThat(r.getValue()).isEqualTo("42");
|
||||
verify(plc, times(1)).readInt32("DB1.0");
|
||||
@@ -187,7 +187,7 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
when(plc.readBoolean("DB2.3.5")).thenReturn(true);
|
||||
|
||||
ReadPointValue r = service.read(driverConfig("h", 102), pointConfig(2, 3, 5),
|
||||
device(11L), point(PointTypeFlagEnum.BOOLEAN));
|
||||
device(11L), point(PointTypeEnum.BOOLEAN));
|
||||
|
||||
assertThat(r.getValue()).isEqualTo("true");
|
||||
verify(plc, times(1)).readBoolean("DB2.3.5");
|
||||
@@ -199,7 +199,7 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
when(plc.readFloat32("DB5.10")).thenReturn(3.14f);
|
||||
|
||||
ReadPointValue r = service.read(driverConfig("h", 102), pointConfig(5, 10, 0),
|
||||
device(12L), point(PointTypeFlagEnum.FLOAT));
|
||||
device(12L), point(PointTypeEnum.FLOAT));
|
||||
|
||||
assertThat(r.getValue()).isEqualTo("3.14");
|
||||
verify(plc, times(1)).readFloat32("DB5.10");
|
||||
@@ -211,7 +211,7 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
when(plc.readInt32(anyString())).thenThrow(new RuntimeException("plc offline"));
|
||||
|
||||
ReadPointValue r = service.read(driverConfig("h", 102), pointConfig(1, 0, 0),
|
||||
device(13L), point(PointTypeFlagEnum.INT));
|
||||
device(13L), point(PointTypeEnum.INT));
|
||||
|
||||
assertThat(r).isNull();
|
||||
assertThat(connectionMap()).doesNotContainKey(13L);
|
||||
@@ -227,8 +227,8 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
primeCachedPLC(20L);
|
||||
|
||||
Boolean ok = service.write(driverConfig("h", 102), pointConfig(1, 4, 0),
|
||||
device(20L), point(PointTypeFlagEnum.INT),
|
||||
writePointValue("123", PointTypeFlagEnum.INT));
|
||||
device(20L), point(PointTypeEnum.INT),
|
||||
writePointValue("123", PointTypeEnum.INT));
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(plc).writeInt32("DB1.4", 123);
|
||||
@@ -239,8 +239,8 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
primeCachedPLC(21L);
|
||||
|
||||
Boolean ok = service.write(driverConfig("h", 102), pointConfig(3, 8, 0),
|
||||
device(21L), point(PointTypeFlagEnum.FLOAT),
|
||||
writePointValue("2.5", PointTypeFlagEnum.FLOAT));
|
||||
device(21L), point(PointTypeEnum.FLOAT),
|
||||
writePointValue("2.5", PointTypeEnum.FLOAT));
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(plc).writeFloat32("DB3.8", 2.5f);
|
||||
@@ -251,8 +251,8 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
primeCachedPLC(22L);
|
||||
|
||||
Boolean ok = service.write(driverConfig("h", 102), pointConfig(1, 0, 3),
|
||||
device(22L), point(PointTypeFlagEnum.BOOLEAN),
|
||||
writePointValue("true", PointTypeFlagEnum.BOOLEAN));
|
||||
device(22L), point(PointTypeEnum.BOOLEAN),
|
||||
writePointValue("true", PointTypeEnum.BOOLEAN));
|
||||
|
||||
assertThat(ok).isTrue();
|
||||
verify(plc).writeBoolean("DB1.0.3", true);
|
||||
@@ -264,8 +264,8 @@ class PlcS7DriverCustomServiceImplTest {
|
||||
doThrow(new RuntimeException("plc offline")).when(plc).writeInt32(anyString(), org.mockito.ArgumentMatchers.anyInt());
|
||||
|
||||
Boolean ok = service.write(driverConfig("h", 102), pointConfig(1, 0, 0),
|
||||
device(23L), point(PointTypeFlagEnum.INT),
|
||||
writePointValue("1", PointTypeFlagEnum.INT));
|
||||
device(23L), point(PointTypeEnum.INT),
|
||||
writePointValue("1", PointTypeEnum.INT));
|
||||
|
||||
assertThat(ok).isFalse();
|
||||
assertThat(connectionMap()).doesNotContainKey(23L);
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import io.github.pnoker.common.driver.metadata.DeviceMetadata;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.metadata.PointMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -69,7 +69,7 @@ class Sl651DriverCustomServiceImplTest {
|
||||
device.setDeviceCode("01020304");
|
||||
when(deviceMetadata.getCache(10L)).thenReturn(device);
|
||||
when(deviceMetadata.getPointConfig(10L)).thenReturn(Map.of(
|
||||
20L, Map.of("index", AttributeBO.builder().value("1").type(AttributeTypeFlagEnum.INT).build())
|
||||
20L, Map.of("index", AttributeBO.builder().value("1").type(AttributeTypeEnum.INT).build())
|
||||
));
|
||||
PointBO point = new PointBO();
|
||||
point.setId(20L);
|
||||
|
||||
+8
-8
@@ -25,7 +25,7 @@ import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.entity.dto.MetadataEventDTO;
|
||||
import io.github.pnoker.common.enums.MetadataOperateTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.PointTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -50,7 +50,7 @@ class VirtualDriverCustomServiceImplTest {
|
||||
@InjectMocks
|
||||
private VirtualDriverCustomServiceImpl service;
|
||||
|
||||
private static PointBO pointOfType(PointTypeFlagEnum type) {
|
||||
private static PointBO pointOfType(PointTypeEnum type) {
|
||||
PointBO point = new PointBO();
|
||||
point.setId(1L);
|
||||
point.setPointName("p");
|
||||
@@ -100,23 +100,23 @@ class VirtualDriverCustomServiceImplTest {
|
||||
|
||||
@Test
|
||||
void readReturnsConstantStringForStringPoint() {
|
||||
PointBO point = pointOfType(PointTypeFlagEnum.STRING);
|
||||
PointBO point = pointOfType(PointTypeEnum.STRING);
|
||||
ReadPointValue readPointValue = service.read(null, null, null, point);
|
||||
assertThat(readPointValue.getValue()).isEqualTo("abcd1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
void readProducesParsableBooleanForBooleanPoint() {
|
||||
PointBO point = pointOfType(PointTypeFlagEnum.BOOLEAN);
|
||||
PointBO point = pointOfType(PointTypeEnum.BOOLEAN);
|
||||
ReadPointValue readPointValue = service.read(null, null, null, point);
|
||||
assertThat(readPointValue.getValue()).isIn("true", "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
void readProducesNumericValueInRangeForOtherPointTypes() {
|
||||
for (PointTypeFlagEnum type : new PointTypeFlagEnum[]{
|
||||
PointTypeFlagEnum.INT, PointTypeFlagEnum.LONG, PointTypeFlagEnum.FLOAT, PointTypeFlagEnum.DOUBLE,
|
||||
PointTypeFlagEnum.BYTE, PointTypeFlagEnum.SHORT
|
||||
for (PointTypeEnum type : new PointTypeEnum[]{
|
||||
PointTypeEnum.INT, PointTypeEnum.LONG, PointTypeEnum.FLOAT, PointTypeEnum.DOUBLE,
|
||||
PointTypeEnum.BYTE, PointTypeEnum.SHORT
|
||||
}) {
|
||||
PointBO point = pointOfType(type);
|
||||
ReadPointValue readPointValue = service.read(null, null, null, point);
|
||||
@@ -128,7 +128,7 @@ class VirtualDriverCustomServiceImplTest {
|
||||
@Test
|
||||
void writeReturnsFalseUnconditionally() {
|
||||
Boolean result = service.write(null, null, null, null,
|
||||
WritePointValue.builder().value("anything").type(PointTypeFlagEnum.STRING).build());
|
||||
WritePointValue.builder().value("anything").type(PointTypeEnum.STRING).build());
|
||||
assertThat(result).isFalse();
|
||||
verify(driverSenderService, never()).pointValueSender(org.mockito.ArgumentMatchers.anyList());
|
||||
}
|
||||
|
||||
+7
-7
@@ -21,7 +21,7 @@ import io.github.pnoker.common.driver.entity.bean.DriverHealthState;
|
||||
import io.github.pnoker.common.driver.entity.bo.AttributeBO;
|
||||
import io.github.pnoker.common.driver.metadata.DriverMetadata;
|
||||
import io.github.pnoker.common.driver.service.DriverSenderService;
|
||||
import io.github.pnoker.common.enums.AttributeTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.AttributeTypeEnum;
|
||||
import io.github.pnoker.common.enums.EntityStatusEnum;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -47,18 +47,18 @@ class ZigbeeDriverCustomServiceImplTest {
|
||||
|
||||
private static Map<String, AttributeBO> driverConfig(String serialPort, int baudRate) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("serialPort", AttributeBO.builder().value(serialPort).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("baudRate", AttributeBO.builder().value(String.valueOf(baudRate)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("serialPort", AttributeBO.builder().value(serialPort).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("baudRate", AttributeBO.builder().value(String.valueOf(baudRate)).type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, AttributeBO> pointConfig(String nodeIeeeAddress, int endpointId,
|
||||
int clusterId, int attributeId) {
|
||||
Map<String, AttributeBO> m = new HashMap<>();
|
||||
m.put("nodeIeeeAddress", AttributeBO.builder().value(nodeIeeeAddress).type(AttributeTypeFlagEnum.STRING).build());
|
||||
m.put("endpointId", AttributeBO.builder().value(String.valueOf(endpointId)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("clusterId", AttributeBO.builder().value(String.valueOf(clusterId)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("attributeId", AttributeBO.builder().value(String.valueOf(attributeId)).type(AttributeTypeFlagEnum.INT).build());
|
||||
m.put("nodeIeeeAddress", AttributeBO.builder().value(nodeIeeeAddress).type(AttributeTypeEnum.STRING).build());
|
||||
m.put("endpointId", AttributeBO.builder().value(String.valueOf(endpointId)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("clusterId", AttributeBO.builder().value(String.valueOf(clusterId)).type(AttributeTypeEnum.INT).build());
|
||||
m.put("attributeId", AttributeBO.builder().value(String.valueOf(attributeId)).type(AttributeTypeEnum.INT).build());
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user