Browse Source

JUnit5 migration in common. Junit-platform.properties and logback-test.xml where added to java resource directories if needed.

Signed-off-by: Oleksandra Matviienko <al.zzzeebra@gmail.com>
pull/10654/head
Oleksandra Matviienko 2 years ago
parent
commit
63df92e995
  1. 5
      common/actor/pom.xml
  2. 46
      common/actor/src/test/java/org/thingsboard/server/actors/ActorSystemTest.java
  3. 3
      common/actor/src/test/resources/junit-platform.properties
  4. 0
      common/actor/src/test/resources/logback-test.xml
  5. 5
      common/cache/pom.xml
  6. 3
      common/cache/src/test/resources/junit-platform.properties
  7. 0
      common/cache/src/test/resources/logback-test.xml
  8. 5
      common/cluster-api/pom.xml
  9. 5
      common/dao-api/pom.xml
  10. 5
      common/data/pom.xml
  11. 14
      common/data/src/test/java/org/thingsboard/server/common/data/DynamicProtoUtilsTest.java
  12. 17
      common/data/src/test/java/org/thingsboard/server/common/data/UUIDConverterTest.java
  13. 6
      common/data/src/test/java/org/thingsboard/server/common/data/id/EntityIdTest.java
  14. 3
      common/data/src/test/resources/junit-platform.properties
  15. 14
      common/data/src/test/resources/logback-test.xml
  16. 5
      common/message/pom.xml
  17. 8
      common/message/src/test/java/org/thingsboard/server/common/msg/TbMsgMetaDataTest.java
  18. 2
      common/message/src/test/java/org/thingsboard/server/common/msg/queue/TopicPartitionInfoTest.java
  19. 2
      common/message/src/test/java/org/thingsboard/server/common/msg/tools/RateLimitsTest.java
  20. 3
      common/message/src/test/resources/junit-platform.properties
  21. 14
      common/message/src/test/resources/logback-test.xml
  22. 5
      common/proto/pom.xml
  23. 19
      common/proto/src/test/java/org/thingsboard/server/common/adaptor/JsonConverterTest.java
  24. 3
      common/proto/src/test/resources/junit-platform.properties
  25. 14
      common/proto/src/test/resources/logback-test.xml
  26. 5
      common/queue/pom.xml
  27. 19
      common/queue/src/test/java/org/thingsboard/server/queue/common/DefaultTbQueueRequestTemplateTest.java
  28. 15
      common/queue/src/test/java/org/thingsboard/server/queue/discovery/ZkDiscoveryServiceTest.java
  29. 2
      common/queue/src/test/java/org/thingsboard/server/queue/memory/DefaultInMemoryStorageTest.java
  30. 3
      common/queue/src/test/resources/junit-platform.properties
  31. 5
      common/script/remote-js-client/pom.xml
  32. 5
      common/script/script-api/pom.xml
  33. 14
      common/script/script-api/src/test/java/org/thingsboard/script/api/tbel/TbDateConstructorTest.java
  34. 416
      common/script/script-api/src/test/java/org/thingsboard/script/api/tbel/TbDateTest.java
  35. 262
      common/script/script-api/src/test/java/org/thingsboard/script/api/tbel/TbUtilsTest.java
  36. 3
      common/script/script-api/src/test/resources/junit-platform.properties
  37. 14
      common/script/script-api/src/test/resources/logback-test.xml
  38. 5
      common/stats/pom.xml
  39. 5
      common/transport/coap/pom.xml
  40. 3
      common/transport/coap/src/test/resources/junit-platform.properties
  41. 14
      common/transport/coap/src/test/resources/logback-test.xml
  42. 5
      common/transport/http/pom.xml
  43. 3
      common/transport/http/src/test/resources/junit-platform.properties
  44. 5
      common/transport/lwm2m/pom.xml
  45. 2
      common/transport/lwm2m/src/test/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientTest.java
  46. 9
      common/transport/lwm2m/src/test/java/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDesTest.java
  47. 3
      common/transport/lwm2m/src/test/resources/junit-platform.properties
  48. 14
      common/transport/lwm2m/src/test/resources/logback-test.xml
  49. 5
      common/transport/mqtt/pom.xml
  50. 24
      common/transport/mqtt/src/test/java/org/thingsboard/server/transport/mqtt/MqttTransportHandlerTest.java
  51. 12
      common/transport/mqtt/src/test/java/org/thingsboard/server/transport/mqtt/util/MqttTopicFilterFactoryTest.java
  52. 3
      common/transport/mqtt/src/test/resources/junit-platform.properties
  53. 14
      common/transport/mqtt/src/test/resources/logback-test.xml
  54. 3
      common/transport/snmp/src/test/resources/junit-platform.properties
  55. 14
      common/transport/snmp/src/test/resources/logback-test.xml
  56. 5
      common/transport/transport-api/pom.xml
  57. 3
      common/transport/transport-api/src/test/resources/junit-platform.properties
  58. 14
      common/transport/transport-api/src/test/resources/logback-test.xml
  59. 5
      common/util/pom.xml
  60. 2
      common/util/src/test/java/org/thingsboard/common/util/ExceptionUtilTest.java
  61. 17
      common/util/src/test/java/org/thingsboard/common/util/JacksonUtilTest.java
  62. 2
      common/util/src/test/java/org/thingsboard/common/util/LinkedHashMapRemoveEldestTest.java
  63. 3
      common/util/src/test/resources/junit-platform.properties
  64. 14
      common/util/src/test/resources/logback-test.xml
  65. 5
      common/version-control/pom.xml

5
common/actor/pom.xml

@ -65,11 +65,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

46
common/actor/src/test/java/org/thingsboard/server/actors/ActorSystemTest.java

@ -16,12 +16,12 @@
package org.thingsboard.server.actors;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.Test;
import org.mockito.junit.jupiter.MockitoExtension;
import org.thingsboard.common.util.ThingsBoardExecutors;
import org.thingsboard.common.util.ThingsBoardThreadFactory;
import org.thingsboard.server.common.data.id.DeviceId;
@ -38,7 +38,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@Slf4j
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class ActorSystemTest {
public static final String ROOT_DISPATCHER = "root-dispatcher";
@ -50,7 +50,7 @@ public class ActorSystemTest {
private ExecutorService executor;
private int parallelism;
@Before
@BeforeEach
public void initActorSystem() {
int cores = Runtime.getRuntime().availableProcessors();
parallelism = Math.max(2, cores / 2);
@ -59,7 +59,7 @@ public class ActorSystemTest {
submitPool = Executors.newFixedThreadPool(parallelism, ThingsBoardThreadFactory.forName(getClass().getSimpleName() + "-submit-test-scope")); //order guaranteed
}
@After
@AfterEach
public void shutdownActorSystem() {
actorSystem.stop();
submitPool.shutdownNow();
@ -126,8 +126,8 @@ public class ActorSystemTest {
actorId2.tell(new IntTbActorMsg(42));
actorSystem.stop(actorId1);
Assert.assertTrue(testCtx2.getLatch().await(1, TimeUnit.SECONDS));
Assert.assertFalse(testCtx1.getLatch().await(1, TimeUnit.SECONDS));
Assertions.assertTrue(testCtx2.getLatch().await(1, TimeUnit.SECONDS));
Assertions.assertFalse(testCtx1.getLatch().await(1, TimeUnit.SECONDS));
}
@Test
@ -149,12 +149,12 @@ public class ActorSystemTest {
});
initLatch.countDown(); //replacement for Thread.wait(500) in the SlowCreateActorCreator
Assert.assertTrue(actorsReadyLatch.await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
Assertions.assertTrue(actorsReadyLatch.await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
actorSystem.tell(actorId, new IntTbActorMsg(42));
Assert.assertTrue(testCtx1.getLatch().await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
Assert.assertFalse(testCtx2.getLatch().await(1, TimeUnit.SECONDS));
Assertions.assertTrue(testCtx1.getLatch().await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
Assertions.assertFalse(testCtx2.getLatch().await(1, TimeUnit.SECONDS));
}
@Test
@ -173,13 +173,13 @@ public class ActorSystemTest {
});
}
initLatch.countDown();
Assert.assertTrue(actorsReadyLatch.await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
Assertions.assertTrue(actorsReadyLatch.await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
actorSystem.tell(actorId, new IntTbActorMsg(42));
Assert.assertTrue(testCtx.getLatch().await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
Assertions.assertTrue(testCtx.getLatch().await(TIMEOUT_AWAIT_MAX_SEC, TimeUnit.SECONDS));
//One for creation and one for message
Assert.assertEquals(2, testCtx.getInvocationCount().get());
Assertions.assertEquals(2, testCtx.getInvocationCount().get());
}
@Test
@ -197,9 +197,9 @@ public class ActorSystemTest {
actorId1.tell(new IntTbActorMsg(42));
actorId2.tell(new IntTbActorMsg(42));
Assert.assertFalse(testCtx1.getLatch().await(2, TimeUnit.SECONDS));
Assert.assertTrue(testCtx2.getLatch().await(1, TimeUnit.SECONDS));
Assert.assertTrue(testCtx1.getLatch().await(3, TimeUnit.SECONDS));
Assertions.assertFalse(testCtx1.getLatch().await(2, TimeUnit.SECONDS));
Assertions.assertTrue(testCtx2.getLatch().await(1, TimeUnit.SECONDS));
Assertions.assertTrue(testCtx1.getLatch().await(3, TimeUnit.SECONDS));
}
@ -237,9 +237,9 @@ public class ActorSystemTest {
if (!success) {
log.warn("Failed: {}, {}", ctx.getActual().get(), ctx.getInvocationCount().get());
}
Assert.assertTrue(success);
Assert.assertEquals(expected, ctx.getActual().get());
Assert.assertEquals(msgNumber, ctx.getInvocationCount().get());
Assertions.assertTrue(success);
Assertions.assertEquals(expected, ctx.getActual().get());
Assertions.assertEquals(msgNumber, ctx.getInvocationCount().get());
ctx.clear();
} catch (InterruptedException e) {
e.printStackTrace();

3
common/actor/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

0
common/actor/src/test/resources/logback.xml → common/actor/src/test/resources/logback-test.xml

5
common/cache/pom.xml

@ -97,11 +97,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

3
common/cache/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

0
common/cache/src/test/resources/logback.xml → common/cache/src/test/resources/logback-test.xml

5
common/cluster-api/pom.xml

@ -109,11 +109,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

5
common/dao-api/pom.xml

@ -105,11 +105,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

5
common/data/pom.xml

@ -73,11 +73,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

14
common/data/src/test/java/org/thingsboard/server/common/data/DynamicProtoUtilsTest.java

@ -19,18 +19,18 @@ import com.github.os72.protobuf.dynamic.DynamicSchema;
import com.google.protobuf.Descriptors;
import com.google.protobuf.DynamicMessage;
import com.squareup.wire.schema.internal.parser.ProtoFileElement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DynamicProtoUtilsTest {
@Test

17
common/data/src/test/java/org/thingsboard/server/common/data/UUIDConverterTest.java

@ -16,11 +16,10 @@
package org.thingsboard.server.common.data;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Random;
import java.util.UUID;
@ -28,14 +27,14 @@ import java.util.UUID;
/**
* Created by ashvayka on 14.07.17.
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension .class)
public class UUIDConverterTest {
@Test
public void basicUuidToStringTest() {
UUID original = UUID.fromString("58e0a7d7-eebc-11d8-9669-0800200c9a66");
String result = UUIDConverter.fromTimeUUID(original);
Assert.assertEquals("1d8eebc58e0a7d796690800200c9a66", result);
Assertions.assertEquals("1d8eebc58e0a7d796690800200c9a66", result);
}
@ -47,13 +46,13 @@ public class UUIDConverterTest {
@Test
public void basicUuidConversion() {
UUID original = UUID.fromString("3dd11790-abf2-11ea-b151-83a091b9d4cc");
Assert.assertEquals(Uuids.unixTimestamp(original), 1591886749577L);
Assertions.assertEquals(Uuids.unixTimestamp(original), 1591886749577L);
}
@Test
public void basicStringToUUIDTest() {
UUID result = UUIDConverter.fromString("1d8eebc58e0a7d796690800200c9a66");
Assert.assertEquals(UUID.fromString("58e0a7d7-eebc-11d8-9669-0800200c9a66"), result);
Assertions.assertEquals(UUID.fromString("58e0a7d7-eebc-11d8-9669-0800200c9a66"), result);
}
@Test
@ -83,7 +82,7 @@ public class UUIDConverterTest {
System.out.println("Before: " + before + " | " + beforeStr);
System.out.println("After: " + after + " | " + afterStr);
}
Assert.assertTrue(afterStr.compareTo(beforeStr) >= 0);
Assertions.assertTrue(afterStr.compareTo(beforeStr) >= 0);
}
}

6
common/data/src/test/java/org/thingsboard/server/common/data/id/EntityIdTest.java

@ -15,14 +15,14 @@
*/
package org.thingsboard.server.common.data.id;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class EntityIdTest {
@Test
public void givenConstantNullUuid_whenCompare_thenToStringEqualsPredefinedUuid() {
Assert.assertEquals("13814000-1dd2-11b2-8080-808080808080", EntityId.NULL_UUID.toString());
Assertions.assertEquals("13814000-1dd2-11b2-8080-808080808080", EntityId.NULL_UUID.toString());
}
}

3
common/data/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/data/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/message/pom.xml

@ -74,11 +74,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

8
common/message/src/test/java/org/thingsboard/server/common/msg/TbMsgMetaDataTest.java

@ -18,12 +18,12 @@ package org.thingsboard.server.common.msg;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TbMsgMetaDataTest {
@ -32,7 +32,7 @@ public class TbMsgMetaDataTest {
private JsonNode metadataJson;
private Map<String, String> metadataExpected;
@Before
@BeforeEach
public void startInit() throws Exception {
metadataJson = objectMapper.readValue(metadataJsonStr, JsonNode.class);
metadataExpected = objectMapper.convertValue(metadataJson, new TypeReference<>() {

2
common/message/src/test/java/org/thingsboard/server/common/msg/queue/TopicPartitionInfoTest.java

@ -15,7 +15,7 @@
*/
package org.thingsboard.server.common.msg.queue;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.thingsboard.server.common.data.id.TenantId;
import static org.hamcrest.CoreMatchers.is;

2
common/message/src/test/java/org/thingsboard/server/common/msg/tools/RateLimitsTest.java

@ -16,7 +16,7 @@
package org.thingsboard.server.common.msg.tools;
import org.awaitility.pollinterval.FixedPollInterval;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit;

3
common/message/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/message/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/proto/pom.xml

@ -66,11 +66,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

19
common/proto/src/test/java/org/thingsboard/server/common/adaptor/JsonConverterTest.java

@ -17,7 +17,6 @@ package org.thingsboard.server.common.adaptor;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -34,55 +33,55 @@ public class JsonConverterTest {
@Test
public void testParseBigDecimalAsLong() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 1E+1}"), 0L);
Assert.assertEquals(10L, result.get(0L).get(0).getLongValue().get().longValue());
Assertions.assertEquals(10L, result.get(0L).get(0).getLongValue().get().longValue());
}
@Test
public void testParseBigDecimalAsDouble() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 101E-1}"), 0L);
Assert.assertEquals(10.1, result.get(0L).get(0).getDoubleValue().get(), 0.0);
Assertions.assertEquals(10.1, result.get(0L).get(0).getDoubleValue().get(), 0.0);
}
@Test
public void testParseAttributesBigDecimalAsLong() {
var result = new ArrayList<>(JsonConverter.convertToAttributes(JsonParser.parseString("{\"meterReadingDelta\": 1E1}")));
Assert.assertEquals(10L, result.get(0).getLongValue().get().longValue());
Assertions.assertEquals(10L, result.get(0).getLongValue().get().longValue());
}
@Test
public void testParseAsDoubleWithZero() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 42.0}"), 0L);
Assert.assertEquals(42.0, result.get(0L).get(0).getDoubleValue().get(), 0.0);
Assertions.assertEquals(42.0, result.get(0L).get(0).getDoubleValue().get(), 0.0);
}
@Test
public void testParseAsDouble() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 1.1}"), 0L);
Assert.assertEquals(1.1, result.get(0L).get(0).getDoubleValue().get(), 0.0);
Assertions.assertEquals(1.1, result.get(0L).get(0).getDoubleValue().get(), 0.0);
}
@Test
public void testParseAsLong() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 11}"), 0L);
Assert.assertEquals(11L, result.get(0L).get(0).getLongValue().get().longValue());
Assertions.assertEquals(11L, result.get(0L).get(0).getLongValue().get().longValue());
}
@Test
public void testParseBigDecimalAsStringOutOfLongRange() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 9.9701010061400066E19}"), 0L);
Assert.assertEquals("99701010061400066000", result.get(0L).get(0).getStrValue().get());
Assertions.assertEquals("99701010061400066000", result.get(0L).get(0).getStrValue().get());
}
@Test
public void testParseBigDecimalAsStringOutOfLongRange2() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 99701010061400066001}"), 0L);
Assert.assertEquals("99701010061400066001", result.get(0L).get(0).getStrValue().get());
Assertions.assertEquals("99701010061400066001", result.get(0L).get(0).getStrValue().get());
}
@Test
public void testParseBigDecimalAsStringOutOfLongRange3() {
var result = JsonConverter.convertToTelemetry(JsonParser.parseString("{\"meterReadingDelta\": 1E19}"), 0L);
Assert.assertEquals("10000000000000000000", result.get(0L).get(0).getStrValue().get());
Assertions.assertEquals("10000000000000000000", result.get(0L).get(0).getStrValue().get());
}
@Test

3
common/proto/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/proto/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/queue/pom.xml

@ -129,11 +129,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

19
common/queue/src/test/java/org/thingsboard/server/queue/common/DefaultTbQueueRequestTemplateTest.java

@ -16,13 +16,13 @@
package org.thingsboard.server.queue.common;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.thingsboard.server.queue.TbQueueAdmin;
import org.thingsboard.server.queue.TbQueueConsumer;
import org.thingsboard.server.queue.TbQueueMsg;
@ -48,6 +48,7 @@ import static org.mockito.BDDMockito.willDoNothing;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@ -56,7 +57,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.longThat;
@Slf4j
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DefaultTbQueueRequestTemplateTest {
@Mock
@ -76,16 +77,16 @@ public class DefaultTbQueueRequestTemplateTest {
DefaultTbQueueRequestTemplate<TbQueueMsg, TbQueueMsg> inst;
@Before
@BeforeEach
public void setUp() throws Exception {
willReturn(topic).given(responseTemplate).getTopic();
lenient().doReturn(topic).when(responseTemplate).getTopic();
inst = spy(new DefaultTbQueueRequestTemplate<>(
queueAdmin, requestTemplate, responseTemplate,
maxRequestTimeout, maxPendingRequests, pollInterval, executorMock));
}
@After
@AfterEach
public void tearDown() throws Exception {
if (executor != null) {
executor.shutdownNow();

15
common/queue/src/test/java/org/thingsboard/server/queue/discovery/ZkDiscoveryServiceTest.java

@ -20,12 +20,13 @@ import org.apache.curator.framework.imps.CuratorFrameworkState;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.util.ReflectionTestUtils;
import org.thingsboard.common.util.ThingsBoardThreadFactory;
@ -39,8 +40,8 @@ import java.util.concurrent.ScheduledExecutorService;
import static org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent.Type.CHILD_ADDED;
import static org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent.Type.CHILD_REMOVED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
@ -49,7 +50,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class ZkDiscoveryServiceTest {
@Mock
@ -78,7 +79,7 @@ public class ZkDiscoveryServiceTest {
final TransportProtos.ServiceInfo childInfo = TransportProtos.ServiceInfo.newBuilder().setServiceId("tb-rule-engine-1").build();
final ChildData childData = new ChildData("/thingsboard/nodes/0000000020", null, childInfo.toByteArray());
@Before
@BeforeEach
public void setup() {
zkDiscoveryService = Mockito.spy(new ZkDiscoveryService(applicationEventPublisher, serviceInfoProvider, partitionService));
ScheduledExecutorService zkExecutorService = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName("zk-discovery"));

2
common/queue/src/test/java/org/thingsboard/server/queue/memory/DefaultInMemoryStorageTest.java

@ -17,7 +17,7 @@ package org.thingsboard.server.queue.memory;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.thingsboard.server.queue.TbQueueMsg;
import org.thingsboard.server.queue.common.DefaultTbQueueMsg;

3
common/queue/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

5
common/script/remote-js-client/pom.xml

@ -66,11 +66,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

5
common/script/script-api/pom.xml

@ -106,11 +106,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

14
common/script/script-api/src/test/java/org/thingsboard/script/api/tbel/TbDateConstructorTest.java

@ -15,8 +15,8 @@
*/
package org.thingsboard.script.api.tbel;
import org.junit.Assert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mvel2.CompileException;
@ -27,8 +27,8 @@ import org.mvel2.SandboxedParserConfiguration;
import java.io.Serializable;
import java.util.HashMap;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mvel2.MVEL.compileExpression;
import static org.mvel2.MVEL.executeTbExpression;
@ -56,14 +56,14 @@ public class TbDateConstructorTest {
String body = "var d = new Date(\"2023-08-06T04:04:05.123Z\"); \n" +
"d.toISOString()";
Object res = executeScript(body);
Assert.assertNotEquals("2023-08-06T04:04:05.123Z".length(), res);
Assertions.assertNotEquals("2023-08-06T04:04:05.123Z".length(), res);
// two: date in String + pattern
body = "var pattern = \"yyyy-MM-dd HH:mm:ss.SSSXXX\";\n" +
"var d = new Date(\"2023-08-06 04:04:05.000Z\", pattern);\n" +
"d.toISOString()";
res = executeScript(body);
Assert.assertNotEquals("2023-08-06T04:04:05Z".length(), res);
Assertions.assertNotEquals("2023-08-06T04:04:05Z".length(), res);
// three: date in String + pattern + locale
@ -71,14 +71,14 @@ public class TbDateConstructorTest {
"var d = new Date(\"02:15:30 PM, Sun 10/09/2022\", pattern, \"en-US\");" +
"d.toISOString()";
res = executeScript(body);
Assert.assertNotEquals("2023-08-06T04:04:05Z".length(), res);
Assertions.assertNotEquals("2023-08-06T04:04:05Z".length(), res);
// four: date in String + pattern + locale + TimeZone
body = "var pattern = \"hh:mm:ss a, EEE M/d/uuuu\";\n" +
"var d = new Date(\"02:15:30 PM, Sun 10/09/2022\", pattern, \"en-US\", \"America/New_York\");" +
"d.toISOString()";
res = executeScript(body);
Assert.assertNotEquals("22022-10-09T18:15:30Z".length(), res);
Assertions.assertNotEquals("22022-10-09T18:15:30Z".length(), res);
}
@Test

416
common/script/script-api/src/test/java/org/thingsboard/script/api/tbel/TbDateTest.java

@ -21,10 +21,9 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.api.Assertions;
import org.assertj.core.data.Offset;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mvel2.ConversionException;
import org.thingsboard.common.util.JacksonUtil;
@ -34,7 +33,6 @@ import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@ -43,8 +41,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Slf4j
class TbDateTest {
@ -129,7 +127,7 @@ class TbDateTest {
String tsStr = String.format(pattern, String.format("%02d", month), date, hrs); //Thu Feb 29 2024 14:35:42.987 GMT+0000
TbDate tbDate = new TbDate(tsStr);
long ts = 1709217342987L; //Thu Feb 29 2024 14:35:42.987 GMT+0000
Assert.assertEquals(ts, tbDate.parseSecondMilli());
Assertions.assertEquals(ts, tbDate.parseSecondMilli());
int offsetLocalSecond = tbDate.getLocaleZoneOffset().getTotalSeconds(); // for example 7200 for GMT + 2
String datePrefix = tsStr; //without time zone
@ -159,18 +157,18 @@ class TbDateTest {
int localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
int hrs = 14 - localOffsetHrs;
String expected = "2022-10-09T" + hrs + ":15:30Z";
Assert.assertEquals(expected, d.toISOString());
Assertions.assertEquals(expected, d.toISOString());
// tz = "-04:00"
s = "2023-08-06T04:04:05.00-04:00";
d = new TbDate(s);
Assert.assertEquals("2023-08-06T08:04:05Z", d.toISOString());
Assertions.assertEquals("2023-08-06T08:04:05Z", d.toISOString());
s = "02:15:30 PM, Sun 10/09/2022";
d = new TbDate(s, pattern, "en-US", "-04:00");
Assert.assertEquals("2022-10-09T18:15:30Z", d.toISOString());
Assertions.assertEquals("2022-10-09T18:15:30Z", d.toISOString());
d = new TbDate(s, pattern,"en-US", "America/New_York");
Assert.assertEquals("2022-10-09T18:15:30Z", d.toISOString());
Assertions.assertEquals("2022-10-09T18:15:30Z", d.toISOString());
// tz = "+02:00"
/**
* For Java 11:
@ -181,7 +179,7 @@ class TbDateTest {
String s_ver = Runtime.version().feature() == 11 ? "09:15:30 nachm., So. 10/09/2022" :
"09:15:30 PM, So. 10/09/2022";
d = new TbDate(s_ver, pattern, "de","Europe/Berlin");
Assert.assertEquals("2022-10-09T19:15:30Z", d.toISOString());
Assertions.assertEquals("2022-10-09T19:15:30Z", d.toISOString());
s = "02:15:30 пп, середа, 4 жовтня 2023 р.";
pattern = "hh:mm:ss a, EEEE, d MMMM y 'р.'";
@ -189,50 +187,50 @@ class TbDateTest {
localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
hrs = 14 - localOffsetHrs;
expected = "2023-10-04T" + hrs + ":15:30Z";
Assert.assertEquals(expected, d.toISOString());
Assertions.assertEquals(expected, d.toISOString());
d = new TbDate(1693962245000L);
Assert.assertEquals("2023-09-06T01:04:05Z", d.toISOString());
Assertions.assertEquals("2023-09-06T01:04:05Z", d.toISOString());
// Depends on time zone, so we just check it works;
Assert.assertNotNull(d.toLocaleDateString());
Assert.assertNotNull(d.toLocaleDateString("en-US"));
Assertions.assertNotNull(d.toLocaleDateString());
Assertions.assertNotNull(d.toLocaleDateString("en-US"));
Assert.assertEquals("9/5/23", d.toLocaleDateString("en-US", "America/New_York"));
Assert.assertEquals("23. 9. 5.", d.toLocaleDateString("ko-KR", "America/New_York"));
Assert.assertEquals("06.09.23", d.toLocaleDateString( "uk-UA", "Europe/Kiev"));
Assert.assertEquals("5\u200F/9\u200F/2023", d.toLocaleDateString( "ar-EG", "America/New_York"));
Assertions.assertEquals("9/5/23", d.toLocaleDateString("en-US", "America/New_York"));
Assertions.assertEquals("23. 9. 5.", d.toLocaleDateString("ko-KR", "America/New_York"));
Assertions.assertEquals("06.09.23", d.toLocaleDateString( "uk-UA", "Europe/Kiev"));
Assertions.assertEquals("5\u200F/9\u200F/2023", d.toLocaleDateString( "ar-EG", "America/New_York"));
Assert.assertEquals("Tuesday, September 5, 2023", d.toLocaleDateString("en-US", JacksonUtil.newObjectNode()
Assertions.assertEquals("Tuesday, September 5, 2023", d.toLocaleDateString("en-US", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("dateStyle", "full")
.toString()));
Assert.assertEquals("2023년 9월 5일 화요일", d.toLocaleDateString("ko-KR", JacksonUtil.newObjectNode()
Assertions.assertEquals("2023년 9월 5일 화요일", d.toLocaleDateString("ko-KR", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("dateStyle", "full")
.toString()));
Assert.assertEquals("середа, 6 вересня 2023 р.", d.toLocaleDateString("uk-UA", JacksonUtil.newObjectNode()
Assertions.assertEquals("середа, 6 вересня 2023 р.", d.toLocaleDateString("uk-UA", JacksonUtil.newObjectNode()
.put("timeZone", "Europe/Kiev")
.put("dateStyle", "full")
.toString()));
Assert.assertEquals("الثلاثاء، 5 سبتمبر 2023", d.toLocaleDateString("ar-EG", JacksonUtil.newObjectNode()
Assertions.assertEquals("الثلاثاء، 5 سبتمبر 2023", d.toLocaleDateString("ar-EG", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("dateStyle", "full")
.toString()));
Assert.assertEquals("Tuesday 9/5/2023", d.toLocaleDateString("en-US", JacksonUtil.newObjectNode()
Assertions.assertEquals("Tuesday 9/5/2023", d.toLocaleDateString("en-US", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "EEEE M/d/yyyy")
.toString()));
Assert.assertEquals("화요일 9/5/2023", d.toLocaleDateString("ko-KR", JacksonUtil.newObjectNode()
Assertions.assertEquals("화요일 9/5/2023", d.toLocaleDateString("ko-KR", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "EEEE M/d/yyyy")
.toString()));
Assert.assertEquals("середа 9/6/2023", d.toLocaleDateString("uk-UA", JacksonUtil.newObjectNode()
Assertions.assertEquals("середа 9/6/2023", d.toLocaleDateString("uk-UA", JacksonUtil.newObjectNode()
.put("timeZone", "Europe/Kiev")
.put("pattern", "EEEE M/d/yyyy")
.toString()));
Assert.assertEquals("الثلاثاء 9/5/2023", d.toLocaleDateString("ar-EG", JacksonUtil.newObjectNode()
Assertions.assertEquals("الثلاثاء 9/5/2023", d.toLocaleDateString("ar-EG", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "EEEE M/d/yyyy")
.toString()));
@ -243,44 +241,44 @@ class TbDateTest {
TbDate d = new TbDate(1693962245000L);
// Depends on time zone, so we just check it works;
Assert.assertNotNull(d.toLocaleTimeString());
Assert.assertNotNull(d.toLocaleTimeString("en-US"));
Assertions.assertNotNull(d.toLocaleTimeString());
Assertions.assertNotNull(d.toLocaleTimeString("en-US"));
Assert.assertEquals("9:04:05 PM", d.toLocaleTimeString("en-US", "America/New_York"));
Assert.assertEquals("오후 9:04:05", d.toLocaleTimeString("ko-KR", "America/New_York"));
Assert.assertEquals("04:04:05", d.toLocaleTimeString( "uk-UA", "Europe/Kiev"));
Assert.assertEquals("9:04:05 م", d.toLocaleTimeString( "ar-EG", "America/New_York"));
Assertions.assertEquals("9:04:05 PM", d.toLocaleTimeString("en-US", "America/New_York"));
Assertions.assertEquals("오후 9:04:05", d.toLocaleTimeString("ko-KR", "America/New_York"));
Assertions.assertEquals("04:04:05", d.toLocaleTimeString( "uk-UA", "Europe/Kiev"));
Assertions.assertEquals("9:04:05 م", d.toLocaleTimeString( "ar-EG", "America/New_York"));
Assert.assertEquals("9:04:05 PM Eastern Daylight Time", d.toLocaleTimeString("en-US", JacksonUtil.newObjectNode()
Assertions.assertEquals("9:04:05 PM Eastern Daylight Time", d.toLocaleTimeString("en-US", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("timeStyle", "full")
.toString()));
Assert.assertEquals("오후 9시 4분 5초 미 동부 하계 표준시", d.toLocaleTimeString("ko-KR", JacksonUtil.newObjectNode()
Assertions.assertEquals("오후 9시 4분 5초 미 동부 하계 표준시", d.toLocaleTimeString("ko-KR", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("timeStyle", "full")
.toString()));
Assert.assertEquals("04:04:05 за східноєвропейським літнім часом", d.toLocaleTimeString("uk-UA", JacksonUtil.newObjectNode()
Assertions.assertEquals("04:04:05 за східноєвропейським літнім часом", d.toLocaleTimeString("uk-UA", JacksonUtil.newObjectNode()
.put("timeZone", "Europe/Kiev")
.put("timeStyle", "full")
.toString()));
Assert.assertEquals("9:04:05 م التوقيت الصيفي الشرقي لأمريكا الشمالية", d.toLocaleTimeString("ar-EG", JacksonUtil.newObjectNode()
Assertions.assertEquals("9:04:05 م التوقيت الصيفي الشرقي لأمريكا الشمالية", d.toLocaleTimeString("ar-EG", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("timeStyle", "full")
.toString()));
Assert.assertEquals("9:04:05 PM", d.toLocaleTimeString("en-US", JacksonUtil.newObjectNode()
Assertions.assertEquals("9:04:05 PM", d.toLocaleTimeString("en-US", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "h:mm:ss a")
.toString()));
Assert.assertEquals("9:04:05 오후", d.toLocaleTimeString("ko-KR", JacksonUtil.newObjectNode()
Assertions.assertEquals("9:04:05 오후", d.toLocaleTimeString("ko-KR", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "h:mm:ss a")
.toString()));
Assert.assertEquals("4:04:05 дп", d.toLocaleTimeString("uk-UA", JacksonUtil.newObjectNode()
Assertions.assertEquals("4:04:05 дп", d.toLocaleTimeString("uk-UA", JacksonUtil.newObjectNode()
.put("timeZone", "Europe/Kiev")
.put("pattern", "h:mm:ss a")
.toString()));
Assert.assertEquals("9:04:05 م", d.toLocaleTimeString("ar-EG", JacksonUtil.newObjectNode()
Assertions.assertEquals("9:04:05 م", d.toLocaleTimeString("ar-EG", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "h:mm:ss a")
.toString()));
@ -291,27 +289,27 @@ class TbDateTest {
TbDate d = new TbDate(1693962245000L);
// Depends on time zone, so we just check it works;
Assert.assertNotNull(d.toLocaleString());
Assert.assertNotNull(d.toLocaleString("en-US"));
Assertions.assertNotNull(d.toLocaleString());
Assertions.assertNotNull(d.toLocaleString("en-US"));
Assert.assertEquals("9/5/23, 9:04:05 PM", d.toLocaleString("en-US", "America/New_York"));
Assert.assertEquals("23. 9. 5. 오후 9:04:05", d.toLocaleString("ko-KR", "America/New_York"));
Assert.assertEquals("06.09.23, 04:04:05", d.toLocaleString( "uk-UA", "Europe/Kiev"));
Assertions.assertEquals("9/5/23, 9:04:05 PM", d.toLocaleString("en-US", "America/New_York"));
Assertions.assertEquals("23. 9. 5. 오후 9:04:05", d.toLocaleString("ko-KR", "America/New_York"));
Assertions.assertEquals("06.09.23, 04:04:05", d.toLocaleString( "uk-UA", "Europe/Kiev"));
String expected_ver = Runtime.version().feature() == 11 ? "5\u200F/9\u200F/2023 9:04:05 م" :
"5\u200F/9\u200F/2023, 9:04:05 م";
Assert.assertEquals(expected_ver, d.toLocaleString( "ar-EG", "America/New_York"));
Assertions.assertEquals(expected_ver, d.toLocaleString( "ar-EG", "America/New_York"));
Assert.assertEquals("Tuesday, September 5, 2023 at 9:04:05 PM Eastern Daylight Time", d.toLocaleString("en-US", JacksonUtil.newObjectNode()
Assertions.assertEquals("Tuesday, September 5, 2023 at 9:04:05 PM Eastern Daylight Time", d.toLocaleString("en-US", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("dateStyle", "full")
.put("timeStyle", "full")
.toString()));
Assert.assertEquals("2023년 9월 5일 화요일 오후 9시 4분 5초 미 동부 하계 표준시", d.toLocaleString("ko-KR", JacksonUtil.newObjectNode()
Assertions.assertEquals("2023년 9월 5일 화요일 오후 9시 4분 5초 미 동부 하계 표준시", d.toLocaleString("ko-KR", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("dateStyle", "full")
.put("timeStyle", "full")
.toString()));
Assert.assertEquals("середа, 6 вересня 2023 р. о 04:04:05 за східноєвропейським літнім часом", d.toLocaleString("uk-UA", JacksonUtil.newObjectNode()
Assertions.assertEquals("середа, 6 вересня 2023 р. о 04:04:05 за східноєвропейським літнім часом", d.toLocaleString("uk-UA", JacksonUtil.newObjectNode()
.put("timeZone", "Europe/Kiev")
.put("dateStyle", "full")
.put("timeStyle", "full")
@ -319,25 +317,25 @@ class TbDateTest {
expected_ver = Runtime.version().feature() == 11 ? "الثلاثاء، 5 سبتمبر 2023 9:04:05 م التوقيت الصيفي الشرقي لأمريكا الشمالية" :
"الثلاثاء، 5 سبتمبر 2023 في 9:04:05 م التوقيت الصيفي الشرقي لأمريكا الشمالية";
Assert.assertEquals(expected_ver, d.toLocaleString("ar-EG", JacksonUtil.newObjectNode()
Assertions.assertEquals(expected_ver, d.toLocaleString("ar-EG", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("dateStyle", "full")
.put("timeStyle", "full")
.toString()));
Assert.assertEquals("9/5/2023, 9:04:05 PM", d.toLocaleString("en-US", JacksonUtil.newObjectNode()
Assertions.assertEquals("9/5/2023, 9:04:05 PM", d.toLocaleString("en-US", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "M/d/yyyy, h:mm:ss a")
.toString()));
Assert.assertEquals("9/5/2023, 9:04:05 오후", d.toLocaleString("ko-KR", JacksonUtil.newObjectNode()
Assertions.assertEquals("9/5/2023, 9:04:05 오후", d.toLocaleString("ko-KR", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "M/d/yyyy, h:mm:ss a")
.toString()));
Assert.assertEquals("9/6/2023, 4:04:05 дп", d.toLocaleString("uk-UA", JacksonUtil.newObjectNode()
Assertions.assertEquals("9/6/2023, 4:04:05 дп", d.toLocaleString("uk-UA", JacksonUtil.newObjectNode()
.put("timeZone", "Europe/Kiev")
.put("pattern", "M/d/yyyy, h:mm:ss a")
.toString()));
Assert.assertEquals("9/5/2023, 9:04:05 م", d.toLocaleString("ar-EG", JacksonUtil.newObjectNode()
Assertions.assertEquals("9/5/2023, 9:04:05 م", d.toLocaleString("ar-EG", JacksonUtil.newObjectNode()
.put("timeZone", "America/New_York")
.put("pattern", "M/d/yyyy, h:mm:ss a")
.toString()));
@ -347,51 +345,51 @@ class TbDateTest {
void TestFromString () {
String stringDateUTC = "2023-09-06T01:04:05.00Z";
TbDate d = new TbDate(stringDateUTC);
Assert.assertEquals("2023-09-06T01:04:05Z", d.toISOString());
Assertions.assertEquals("2023-09-06T01:04:05Z", d.toISOString());
String stringDateTZ = "2023-09-06T01:04:05.00+04:00:00";
d = new TbDate(stringDateTZ);
Assert.assertEquals("2023-09-05T21:04:05Z", d.toISOString());
Assertions.assertEquals("2023-09-05T21:04:05Z", d.toISOString());
stringDateTZ = "2023-09-06T01:04:05.00+04";
d = new TbDate(stringDateTZ);
Assert.assertEquals("2023-09-05T21:04:05Z", d.toISOString());
Assertions.assertEquals("2023-09-05T21:04:05Z", d.toISOString());
stringDateTZ = "2023-09-06T01:04:05.00-04:00";
d = new TbDate(stringDateTZ);
Assert.assertEquals("2023-09-06T05:04:05Z", d.toISOString());
Assertions.assertEquals("2023-09-06T05:04:05Z", d.toISOString());
stringDateTZ = "2023-09-06T01:04:05.00+04:30:56";
d = new TbDate(stringDateTZ);
Assert.assertEquals("2023-09-05T20:33:09Z", d.toISOString());
Assertions.assertEquals("2023-09-05T20:33:09Z", d.toISOString());
stringDateTZ = "2023-09-06T01:04:05.00-02:00";
d = new TbDate(stringDateTZ);
Assert.assertEquals("2023-09-06T03:04:05Z", d.toISOString());
Assertions.assertEquals("2023-09-06T03:04:05Z", d.toISOString());
// Without_TZ
stringDateTZ = "2023-08-06T04:04:05.123";
d = new TbDate(stringDateTZ);
Assert.assertEquals("2023-08-06 04:04:05", d.toLocaleString());
Assertions.assertEquals("2023-08-06 04:04:05", d.toLocaleString());
// With TZ RFC_1123
String stringDateRFC_1123 = "Sat, 3 Jun 2023 11:05:30 GMT";
d = new TbDate(stringDateRFC_1123);
Assert.assertEquals("2023-06-03T11:05:30Z", d.toISOString());
Assertions.assertEquals("2023-06-03T11:05:30Z", d.toISOString());
stringDateRFC_1123 = "Sat, 3 Jun 2023 01:04:05 +043056";
d = new TbDate(stringDateRFC_1123);
Assert.assertEquals("2023-06-02T20:33:09Z", d.toISOString());
Assertions.assertEquals("2023-06-02T20:33:09Z", d.toISOString());
stringDateRFC_1123 = "Sat, 3 Jun 2023 11:05:30 +0400";
d = new TbDate(stringDateRFC_1123);
Assert.assertEquals("2023-06-03T07:05:30Z", d.toISOString());
Assertions.assertEquals("2023-06-03T07:05:30Z", d.toISOString());
stringDateRFC_1123 = "Thu, 29 Feb 2024 11:05:30 -03";
d = new TbDate(stringDateRFC_1123);
Assert.assertEquals("2024-02-29T14:05:30Z", d.toISOString());
Assertions.assertEquals("2024-02-29T14:05:30Z", d.toISOString());
// Without TZ RFC_1123
stringDateRFC_1123 = "Sat, 3 Jun 2023 11:05:30";
d = new TbDate(stringDateRFC_1123);
Assert.assertEquals("2023-06-03 11:05:30", d.toLocaleString());
Assertions.assertEquals("2023-06-03 11:05:30", d.toLocaleString());
// With pattern + locale - ok
String pattern = "hh:mm:ss a, EEE M/d/uuuu";
String stringDate_ver_RFC_1123 = Runtime.version().feature() == 11 ? "09:15:30 nachm., So. 10/09/2022" :
"09:15:30 PM, So. 10/09/2022";
d = new TbDate(stringDate_ver_RFC_1123 , pattern, "de");
Assert.assertEquals("2022-10-09 21:15:30", d.toLocaleString());
Assertions.assertEquals("2022-10-09 21:15:30", d.toLocaleString());
// failed TZ
String expectedMessage = "Cannot parse value";
@ -434,10 +432,10 @@ class TbDateTest {
String stringDateStart = "1970-01-01T00:00:00Z";
TbDate d = new TbDate(stringDateStart);
long actualMillis = TbDate.parse("1970-01-01 T00:00:00");
Assert.assertEquals(-d.getLocaleZoneOffset().getTotalSeconds() * 1000, actualMillis);
Assertions.assertEquals(-d.getLocaleZoneOffset().getTotalSeconds() * 1000, actualMillis);
String pattern = "yyyy-MM-dd HH:mm:ss.SSS";
String stringDate = "1995-12-04 00:12:00.000";
Assert.assertNotEquals(-1L, TbDate.parse(stringDate, pattern));
Assertions.assertNotEquals(-1L, TbDate.parse(stringDate, pattern));
}
@Test
@ -451,67 +449,67 @@ class TbDateTest {
TbDate dLocal1 = new TbDate(d1.parseSecondMilli() + d1.getLocaleZoneOffset().getTotalSeconds()*1000);
TbDate dLocal2 = new TbDate(d2.parseSecondMilli() + d2.getLocaleZoneOffset().getTotalSeconds()*1000);
Assert.assertEquals(dLocal.getUTCFullYear(), d.getFullYear());
Assert.assertEquals(dLocal0.getUTCFullYear(), d0.getFullYear());
Assert.assertEquals(dLocal1.getUTCFullYear(), d1.getFullYear());
Assert.assertEquals(dLocal2.getUTCFullYear(), d2.getFullYear());
Assert.assertEquals(dLocal.getUTCMonth(), d.getMonth());
Assert.assertEquals(dLocal0.getUTCMonth(), d0.getMonth());
Assert.assertEquals(dLocal1.getUTCMonth(), d1.getMonth());
Assert.assertEquals(dLocal2.getUTCMonth(), d2.getMonth());
Assert.assertEquals(dLocal.getUTCDate(), d.getDate());
Assert.assertEquals(dLocal0.getUTCDate(), d0.getDate());
Assert.assertEquals(dLocal1.getUTCDate(), d1.getDate());
Assert.assertEquals(dLocal2.getUTCDate(), d2.getDate());
Assert.assertEquals(dLocal.getUTCDay(), d.getDay());
Assert.assertEquals(dLocal0.getUTCDay(), d0.getDay());
Assert.assertEquals(dLocal1.getUTCDay(), d1.getDay());
Assert.assertEquals(dLocal2.getUTCDay(), d2.getDay());
Assert.assertEquals(dLocal.getUTCHours(), d.getHours());
Assert.assertEquals(dLocal0.getUTCHours(), d0.getHours());
Assert.assertEquals(dLocal1.getUTCHours(), d1.getHours());
Assert.assertEquals(dLocal2.getUTCHours(), d2.getHours());
Assert.assertEquals(dLocal.getUTCMinutes(), d.getMinutes());
Assert.assertEquals(dLocal0.getUTCMinutes(), d0.getMinutes());
Assert.assertEquals(dLocal1.getUTCMinutes(), d1.getMinutes());
Assert.assertEquals(dLocal2.getUTCMinutes(), d2.getMinutes());
Assert.assertEquals(dLocal.getUTCSeconds(), d.getSeconds());
Assert.assertEquals(dLocal0.getUTCSeconds(), d0.getSeconds());
Assert.assertEquals(dLocal1.getUTCSeconds(), d1.getSeconds());
Assert.assertEquals(dLocal2.getUTCSeconds(), d2.getSeconds());
Assert.assertEquals(dLocal.getUTCMilliseconds(), d.getMilliseconds());
Assert.assertEquals(dLocal0.getUTCMilliseconds(), d0.getMilliseconds());
Assert.assertEquals(dLocal1.getUTCMilliseconds(), d1.getMilliseconds());
Assert.assertEquals(dLocal2.getUTCMilliseconds(), d2.getMilliseconds());
Assertions.assertEquals(dLocal.getUTCFullYear(), d.getFullYear());
Assertions.assertEquals(dLocal0.getUTCFullYear(), d0.getFullYear());
Assertions.assertEquals(dLocal1.getUTCFullYear(), d1.getFullYear());
Assertions.assertEquals(dLocal2.getUTCFullYear(), d2.getFullYear());
Assertions.assertEquals(dLocal.getUTCMonth(), d.getMonth());
Assertions.assertEquals(dLocal0.getUTCMonth(), d0.getMonth());
Assertions.assertEquals(dLocal1.getUTCMonth(), d1.getMonth());
Assertions.assertEquals(dLocal2.getUTCMonth(), d2.getMonth());
Assertions.assertEquals(dLocal.getUTCDate(), d.getDate());
Assertions.assertEquals(dLocal0.getUTCDate(), d0.getDate());
Assertions.assertEquals(dLocal1.getUTCDate(), d1.getDate());
Assertions.assertEquals(dLocal2.getUTCDate(), d2.getDate());
Assertions.assertEquals(dLocal.getUTCDay(), d.getDay());
Assertions.assertEquals(dLocal0.getUTCDay(), d0.getDay());
Assertions.assertEquals(dLocal1.getUTCDay(), d1.getDay());
Assertions.assertEquals(dLocal2.getUTCDay(), d2.getDay());
Assertions.assertEquals(dLocal.getUTCHours(), d.getHours());
Assertions.assertEquals(dLocal0.getUTCHours(), d0.getHours());
Assertions.assertEquals(dLocal1.getUTCHours(), d1.getHours());
Assertions.assertEquals(dLocal2.getUTCHours(), d2.getHours());
Assertions.assertEquals(dLocal.getUTCMinutes(), d.getMinutes());
Assertions.assertEquals(dLocal0.getUTCMinutes(), d0.getMinutes());
Assertions.assertEquals(dLocal1.getUTCMinutes(), d1.getMinutes());
Assertions.assertEquals(dLocal2.getUTCMinutes(), d2.getMinutes());
Assertions.assertEquals(dLocal.getUTCSeconds(), d.getSeconds());
Assertions.assertEquals(dLocal0.getUTCSeconds(), d0.getSeconds());
Assertions.assertEquals(dLocal1.getUTCSeconds(), d1.getSeconds());
Assertions.assertEquals(dLocal2.getUTCSeconds(), d2.getSeconds());
Assertions.assertEquals(dLocal.getUTCMilliseconds(), d.getMilliseconds());
Assertions.assertEquals(dLocal0.getUTCMilliseconds(), d0.getMilliseconds());
Assertions.assertEquals(dLocal1.getUTCMilliseconds(), d1.getMilliseconds());
Assertions.assertEquals(dLocal2.getUTCMilliseconds(), d2.getMilliseconds());
}
@Test
void Test_Year_Moth_Date_Hours_Min_Sec_Without_TZ() {
TbDate d = new TbDate(2023, 8, 18);
Assert.assertEquals("2023-08-18 00:00:00", d.toLocaleString());
Assertions.assertEquals("2023-08-18 00:00:00", d.toLocaleString());
d = new TbDate(2023, 9, 17, 17, 34);
Assert.assertEquals("2023-09-17 17:34:00", d.toLocaleString());
Assertions.assertEquals("2023-09-17 17:34:00", d.toLocaleString());
d = new TbDate(23, 9, 7, 8, 4);
Assert.assertEquals("2023-09-07 08:04:00", d.toLocaleString());
Assertions.assertEquals("2023-09-07 08:04:00", d.toLocaleString());
d = new TbDate(23, 9, 7, 8, 4, 5);
Assert.assertEquals("2023-09-07 08:04:05", d.toLocaleString());
Assertions.assertEquals("2023-09-07 08:04:05", d.toLocaleString());
d = new TbDate(23, 9, 7, 8, 4, 5, 567);
Assert.assertEquals("2023-09-07 08:04:05", d.toLocaleString());
Assertions.assertEquals("2023-09-07 08:04:05", d.toLocaleString());
}
@Test
void Test_DateString_With_Pattern() {
String pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX";
TbDate d = new TbDate("2023-08-06 04:04:05.000-04:00", pattern);
Assert.assertEquals("2023-08-06T08:04:05Z", d.toISOString());
Assertions.assertEquals("2023-08-06T08:04:05Z", d.toISOString());
}
@Test
void Test_DateString_With_TZ() {
@ -525,7 +523,7 @@ class TbDateTest {
int localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
TbDateTestEntity tbDateTest = new TbDateTestEntity(23, 9, date, hrs + localOffsetHrs - tz);
String expected = String.format(pattern, tbDateTest.geDateStr(), tbDateTest.geHoursStr());
Assert.assertEquals(expected, d.toLocaleString());
Assertions.assertEquals(expected, d.toLocaleString());
tz = +5;
tzStr = "+05:00";
@ -534,7 +532,7 @@ class TbDateTest {
localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
tbDateTest = new TbDateTestEntity(23, 9, date, hrs + localOffsetHrs - tz);
expected = String.format(pattern, tbDateTest.geDateStr(), tbDateTest.geHoursStr());
Assert.assertEquals(expected, d.toLocaleString());
Assertions.assertEquals(expected, d.toLocaleString());
tz = -2;
tzStr = "-02";
@ -543,7 +541,7 @@ class TbDateTest {
localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
tbDateTest = new TbDateTestEntity(23, 9, date, hrs + localOffsetHrs - tz);
expected = String.format(pattern, tbDateTest.geDateStr(), tbDateTest.geHoursStr());
Assert.assertEquals(expected, d.toLocaleString());
Assertions.assertEquals(expected, d.toLocaleString());
}
@Test
@ -557,13 +555,13 @@ class TbDateTest {
int localOffsetHrs = 0;
TbDateTestEntity tbDateTest = new TbDateTestEntity(23, 9, date, hrs + localOffsetHrs - tz);
String expected = String.format(pattern, tbDateTest.geDateStr(), tbDateTest.geHoursStr());
Assert.assertEquals(expected, d.toLocaleString());
Assertions.assertEquals(expected, d.toLocaleString());
d = new TbDate(23, 9, date, hrs, 4, 5, tzStr);
localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
tbDateTest = new TbDateTestEntity(23, 9, date, hrs + localOffsetHrs - tz);
expected = String.format(pattern, tbDateTest.geDateStr(), tbDateTest.geHoursStr());
Assert.assertEquals(expected, d.toLocaleString());
Assertions.assertEquals(expected, d.toLocaleString());
tz = 3;
tzStr = "+03:00";
@ -571,7 +569,7 @@ class TbDateTest {
localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
tbDateTest = new TbDateTestEntity(23, 9, date, hrs + localOffsetHrs - tz);
expected = String.format(pattern, tbDateTest.geDateStr(), tbDateTest.geHoursStr());
Assert.assertEquals(expected, d.toLocaleString());
Assertions.assertEquals(expected, d.toLocaleString());
tz = -4;
tzStr = "-04:00";
@ -579,19 +577,19 @@ class TbDateTest {
localOffsetHrs = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds()/60/60;
tbDateTest = new TbDateTestEntity(23, 9, date, hrs + localOffsetHrs - tz);
expected = String.format(pattern, tbDateTest.geDateStr(), tbDateTest.geHoursStr());
Assert.assertEquals(expected, d.toLocaleString());
Assertions.assertEquals(expected, d.toLocaleString());
}
@Test
public void TestToUTC() {
Assert.assertEquals(-2209075200000L, TbDate.UTC(0));
Assert.assertEquals("1899-12-31T00:00:00Z", new TbDate(TbDate.UTC(0)).toJSON());
Assert.assertEquals("1996-02-02T03:04:05Z", new TbDate(TbDate.UTC(96, 2, 2, 3, 4, 5)).toJSON());
Assert.assertEquals("2022-12-31T03:04:05.678Z", new TbDate(TbDate.UTC(22, 0, 0, 3, 4, 5, 678)).toJSON());
Assert.assertEquals("0903-12-31T03:04:05.678Z", new TbDate(TbDate.UTC(903, 0, 0, 3, 4, 5, 678)).toJSON());
Assert.assertEquals("1958-12-31T03:04:05.678Z", new TbDate(TbDate.UTC(1958, 0, 0, 3, 4, 5, 678)).toJSON());
Assert.assertEquals("2032-04-05T03:04:05.678Z", new TbDate(TbDate.UTC(2032, 4, 5, 3, 4, 5, 678)).toJSON());
Assert.assertEquals("2024-02-29T03:04:05.678Z", new TbDate(TbDate.UTC(2024, 2, 29, 3, 4, 5, 678)).toJSON());
Assertions.assertEquals(-2209075200000L, TbDate.UTC(0));
Assertions.assertEquals("1899-12-31T00:00:00Z", new TbDate(TbDate.UTC(0)).toJSON());
Assertions.assertEquals("1996-02-02T03:04:05Z", new TbDate(TbDate.UTC(96, 2, 2, 3, 4, 5)).toJSON());
Assertions.assertEquals("2022-12-31T03:04:05.678Z", new TbDate(TbDate.UTC(22, 0, 0, 3, 4, 5, 678)).toJSON());
Assertions.assertEquals("0903-12-31T03:04:05.678Z", new TbDate(TbDate.UTC(903, 0, 0, 3, 4, 5, 678)).toJSON());
Assertions.assertEquals("1958-12-31T03:04:05.678Z", new TbDate(TbDate.UTC(1958, 0, 0, 3, 4, 5, 678)).toJSON());
Assertions.assertEquals("2032-04-05T03:04:05.678Z", new TbDate(TbDate.UTC(2032, 4, 5, 3, 4, 5, 678)).toJSON());
Assertions.assertEquals("2024-02-29T03:04:05.678Z", new TbDate(TbDate.UTC(2024, 2, 29, 3, 4, 5, 678)).toJSON());
Exception actual = assertThrows(DateTimeException.class, () -> {
TbDate.UTC(2023, 2, 29, 3, 4, 5, 678);
});
@ -602,16 +600,16 @@ class TbDateTest {
@Test
void TestMethodGetTimeUTC() {
TbDate ddUTC = new TbDate(TbDate.UTC(1996, 1, 2, 3, 4, 5));
Assert.assertEquals(820551845000L, ddUTC.valueOf());
Assertions.assertEquals(820551845000L, ddUTC.valueOf());
TbDate dd = new TbDate(1996, 1, 2, 3, 4, 5);
int localOffsetMilli = ZoneId.systemDefault().getRules().getOffset(dd.getInstant()).getTotalSeconds()*1000;
Assert.assertEquals((dd.valueOf() + localOffsetMilli), ddUTC.valueOf());
Assertions.assertEquals((dd.valueOf() + localOffsetMilli), ddUTC.valueOf());
ddUTC = new TbDate(TbDate.UTC(1969, 7, 20, 20, 17, 40));
Assert.assertEquals(-14182940000L, ddUTC.valueOf());
Assertions.assertEquals(-14182940000L, ddUTC.valueOf());
TbDate beforeStartUTC = new TbDate(1969, 7, 20, 20, 17, 40);
localOffsetMilli = ZoneId.systemDefault().getRules().getOffset(beforeStartUTC.getInstant()).getTotalSeconds()*1000;
Assert.assertEquals((beforeStartUTC.valueOf() + localOffsetMilli), ddUTC.valueOf());
Assertions.assertEquals((beforeStartUTC.valueOf() + localOffsetMilli), ddUTC.valueOf());
}
@Test
@ -715,20 +713,20 @@ class TbDateTest {
TbDate d1 = new TbDate(1975, 12, 31, 23, 15, 30, 567, "-03:00");
long dateMilliSecond = d1.getTime();
int fiveMinutesInMillis = 5 * 60 * 1000;
Assert.assertEquals(15, d1.getUTCMinutes());
Assert.assertEquals(4, d1.getUTCDay());
Assertions.assertEquals(15, d1.getUTCMinutes());
Assertions.assertEquals(4, d1.getUTCDay());
d1.setTime(dateMilliSecond + fiveMinutesInMillis);
Assert.assertEquals(20, d1.getUTCMinutes());
Assert.assertEquals(4, d1.getUTCDay());
Assertions.assertEquals(20, d1.getUTCMinutes());
Assertions.assertEquals(4, d1.getUTCDay());
d1.setTime(-378682769433L);
Assert.assertEquals(1958, d1.getUTCFullYear());
Assert.assertEquals(1, d1.getUTCMonth());
Assert.assertEquals(1, d1.getUTCDate());
Assert.assertEquals(2, d1.getUTCHours());
Assert.assertEquals(20, d1.getUTCMinutes());
Assert.assertEquals(30, d1.getUTCSeconds());
Assert.assertEquals(567, d1.getUTCMilliseconds());
Assert.assertEquals(3, d1.getUTCDay());
Assertions.assertEquals(1958, d1.getUTCFullYear());
Assertions.assertEquals(1, d1.getUTCMonth());
Assertions.assertEquals(1, d1.getUTCDate());
Assertions.assertEquals(2, d1.getUTCHours());
Assertions.assertEquals(20, d1.getUTCMinutes());
Assertions.assertEquals(30, d1.getUTCSeconds());
Assertions.assertEquals(567, d1.getUTCMilliseconds());
Assertions.assertEquals(3, d1.getUTCDay());
}
@Test
void TestMethodSeFullYearMonthDate() {
@ -788,95 +786,95 @@ class TbDateTest {
d1.setMinutes(5);
d2.setMinutes(15);
Assert.assertEquals(5, d1.getMinutes());
Assert.assertEquals(15, d2.getMinutes());
Assertions.assertEquals(5, d1.getMinutes());
Assertions.assertEquals(15, d2.getMinutes());
d1.setMinutes(5, 34);
d2.setMinutes(25, 43);
Assert.assertEquals(5, d1.getMinutes());
Assert.assertEquals(34, d1.getSeconds());
Assert.assertEquals(25, d2.getMinutes());
Assert.assertEquals(43, d2.getSeconds());
Assertions.assertEquals(5, d1.getMinutes());
Assertions.assertEquals(34, d1.getSeconds());
Assertions.assertEquals(25, d2.getMinutes());
Assertions.assertEquals(43, d2.getSeconds());
d1.setMinutes(25, 14, 567);
d2.setMinutes(45, 3, 876);
Assert.assertEquals(25, d1.getMinutes());
Assert.assertEquals(14, d1.getSeconds());
Assert.assertEquals(567, d1.getMilliseconds());
Assert.assertEquals(45, d2.getMinutes());
Assert.assertEquals(3, d2.getSeconds());
Assert.assertEquals(876, d2.getMilliseconds());
Assertions.assertEquals(25, d1.getMinutes());
Assertions.assertEquals(14, d1.getSeconds());
Assertions.assertEquals(567, d1.getMilliseconds());
Assertions.assertEquals(45, d2.getMinutes());
Assertions.assertEquals(3, d2.getSeconds());
Assertions.assertEquals(876, d2.getMilliseconds());
d1.setSeconds(5);
d2.setSeconds(23);
Assert.assertEquals(5, d1.getSeconds());
Assert.assertEquals(23, d2.getSeconds());
Assertions.assertEquals(5, d1.getSeconds());
Assertions.assertEquals(23, d2.getSeconds());
d1.setSeconds(45, 987);
d2.setSeconds(54, 842);
Assert.assertEquals(45, d1.getSeconds());
Assert.assertEquals(987, d1.getMilliseconds());
Assert.assertEquals(54, d2.getSeconds());
Assert.assertEquals(842, d2.getMilliseconds());
Assertions.assertEquals(45, d1.getSeconds());
Assertions.assertEquals(987, d1.getMilliseconds());
Assertions.assertEquals(54, d2.getSeconds());
Assertions.assertEquals(842, d2.getMilliseconds());
d1.setMilliseconds(675);
d2.setMilliseconds(923);
Assert.assertEquals(675, d1.getMilliseconds());
Assert.assertEquals(923, d2.getMilliseconds());
Assertions.assertEquals(675, d1.getMilliseconds());
Assertions.assertEquals(923, d2.getMilliseconds());
}
@Test
public void toStringAsJs() {
TbDate d1 = new TbDate(1975, 12, 31, 23,15,30, 567,"-04:00");
Assert.assertEquals("четвер, 1 січня 1976 р. о 06:15:30 за східноєвропейським стандартним часом", d1.toString("uk-UA", "Europe/Kyiv"));
Assert.assertEquals("Thursday, January 1, 1976 at 6:15:30 AM Eastern European Standard Time", d1.toString("en-US", "Europe/Kyiv"));
Assert.assertEquals("1976 Jan 1, Thu 06:15:30 Eastern European Time", d1.toString("UTC", "Europe/Kyiv"));
Assert.assertEquals("Wednesday, December 31, 1975 at 10:15:30 PM Eastern Standard Time", d1.toString("en-US", "America/New_York"));
Assert.assertEquals("1975 Dec 31, Wed 22:15:30 Eastern Standard Time", d1.toString("GMT", "America/New_York"));
Assert.assertEquals("1975 Dec 31, Wed 22:15:30 Eastern Standard Time", d1.toString("UTC", "America/New_York"));
Assert.assertEquals(d1.toUTCString("UTC"), d1.toUTCString());
Assert.assertEquals("четвер, 1 січня 1976 р., 03:15:30", d1.toUTCString("uk-UA"));
Assert.assertEquals("Thursday, January 1, 1976, 3:15:30 AM", d1.toUTCString("en-US"));
Assert.assertEquals("1976-01-01T03:15:30.567Z", d1.toJSON());
Assert.assertEquals("1976-01-01T03:15:30.567Z", d1.toISOString());
Assert.assertEquals("1976-01-01 06:15:30", d1.toLocaleString("UTC", "Europe/Kyiv"));
Assert.assertEquals("01.01.76, 06:15:30", d1.toLocaleString("uk-UA", "Europe/Kyiv"));
Assert.assertEquals("1975-12-31 22:15:30", d1.toLocaleString("UTC", "America/New_York"));
Assert.assertEquals("12/31/75, 10:15:30 PM", d1.toLocaleString("en-US", "America/New_York"));
Assert.assertEquals("1976 Jan 1, Thu", d1.toDateString("UTC", "Europe/Kyiv"));
Assert.assertEquals("четвер, 1 січня 1976 р.", d1.toDateString("uk-UA", "Europe/Kyiv"));
Assert.assertEquals("1975 Dec 31, Wed", d1.toDateString("UTC", "America/New_York"));
Assert.assertEquals("Wednesday, December 31, 1975", d1.toDateString("en-US", "America/New_York"));
Assert.assertEquals("06:15:30", d1.toLocaleTimeString("uk-UA", "Europe/Kyiv"));
Assert.assertEquals("06:15:30", d1.toLocaleTimeString("UTC", "Europe/Kyiv"));
Assert.assertEquals("10:15:30 PM", d1.toLocaleTimeString("en-US", "America/New_York"));
Assert.assertEquals("22:15:30", d1.toLocaleTimeString("UTC", "America/New_York"));
Assert.assertEquals("06:15:30 за східноєвропейським стандартним часом", d1.toTimeString("uk-UA", "Europe/Kyiv"));
Assert.assertEquals("06:15:30 Eastern European Time", d1.toTimeString("UTC", "Europe/Kyiv"));
Assert.assertEquals("10:15:30 PM Eastern Standard Time", d1.toTimeString("en-US", "America/New_York"));
Assert.assertEquals("22:15:30 Eastern Standard Time", d1.toTimeString("UTC", "America/New_York"));
Assertions.assertEquals("четвер, 1 січня 1976 р. о 06:15:30 за східноєвропейським стандартним часом", d1.toString("uk-UA", "Europe/Kyiv"));
Assertions.assertEquals("Thursday, January 1, 1976 at 6:15:30 AM Eastern European Standard Time", d1.toString("en-US", "Europe/Kyiv"));
Assertions.assertEquals("1976 Jan 1, Thu 06:15:30 Eastern European Time", d1.toString("UTC", "Europe/Kyiv"));
Assertions.assertEquals("Wednesday, December 31, 1975 at 10:15:30 PM Eastern Standard Time", d1.toString("en-US", "America/New_York"));
Assertions.assertEquals("1975 Dec 31, Wed 22:15:30 Eastern Standard Time", d1.toString("GMT", "America/New_York"));
Assertions.assertEquals("1975 Dec 31, Wed 22:15:30 Eastern Standard Time", d1.toString("UTC", "America/New_York"));
Assertions.assertEquals(d1.toUTCString("UTC"), d1.toUTCString());
Assertions.assertEquals("четвер, 1 січня 1976 р., 03:15:30", d1.toUTCString("uk-UA"));
Assertions.assertEquals("Thursday, January 1, 1976, 3:15:30 AM", d1.toUTCString("en-US"));
Assertions.assertEquals("1976-01-01T03:15:30.567Z", d1.toJSON());
Assertions.assertEquals("1976-01-01T03:15:30.567Z", d1.toISOString());
Assertions.assertEquals("1976-01-01 06:15:30", d1.toLocaleString("UTC", "Europe/Kyiv"));
Assertions.assertEquals("01.01.76, 06:15:30", d1.toLocaleString("uk-UA", "Europe/Kyiv"));
Assertions.assertEquals("1975-12-31 22:15:30", d1.toLocaleString("UTC", "America/New_York"));
Assertions.assertEquals("12/31/75, 10:15:30 PM", d1.toLocaleString("en-US", "America/New_York"));
Assertions.assertEquals("1976 Jan 1, Thu", d1.toDateString("UTC", "Europe/Kyiv"));
Assertions.assertEquals("четвер, 1 січня 1976 р.", d1.toDateString("uk-UA", "Europe/Kyiv"));
Assertions.assertEquals("1975 Dec 31, Wed", d1.toDateString("UTC", "America/New_York"));
Assertions.assertEquals("Wednesday, December 31, 1975", d1.toDateString("en-US", "America/New_York"));
Assertions.assertEquals("06:15:30", d1.toLocaleTimeString("uk-UA", "Europe/Kyiv"));
Assertions.assertEquals("06:15:30", d1.toLocaleTimeString("UTC", "Europe/Kyiv"));
Assertions.assertEquals("10:15:30 PM", d1.toLocaleTimeString("en-US", "America/New_York"));
Assertions.assertEquals("22:15:30", d1.toLocaleTimeString("UTC", "America/New_York"));
Assertions.assertEquals("06:15:30 за східноєвропейським стандартним часом", d1.toTimeString("uk-UA", "Europe/Kyiv"));
Assertions.assertEquals("06:15:30 Eastern European Time", d1.toTimeString("UTC", "Europe/Kyiv"));
Assertions.assertEquals("10:15:30 PM Eastern Standard Time", d1.toTimeString("en-US", "America/New_York"));
Assertions.assertEquals("22:15:30 Eastern Standard Time", d1.toTimeString("UTC", "America/New_York"));
}
@Test
public void testNow() {
Assertions.assertThat(TbDate.now()).isCloseTo(Instant.now().toEpochMilli(), Offset.offset(1000L));
assertThat(TbDate.now()).isCloseTo(Instant.now().toEpochMilli(), Offset.offset(1000L));
}
private void testResultChangeDateTime(TbDate d) {
int localOffset = ZoneId.systemDefault().getRules().getOffset(d.getInstant()).getTotalSeconds();
TbDateTestEntity tbDateTestEntity = new TbDateTestEntity(d.getFullYear(), d.getMonth(), d.getDate(), (d.getHours() - (localOffset/60/60)));
Assert.assertEquals(tbDateTestEntity.getYear(), d.getUTCFullYear());
Assert.assertEquals(tbDateTestEntity.getMonth(), d.getUTCMonth());
Assert.assertEquals(tbDateTestEntity.getDate(), d.getUTCDate());
Assert.assertEquals(tbDateTestEntity.getHours(), d.getUTCHours());
Assert.assertEquals(d.getMinutes(), d.getUTCMinutes());
Assert.assertEquals(d.getSeconds(), d.getUTCSeconds());
Assert.assertEquals(d.getMilliseconds(), d.getUTCMilliseconds());
Assertions.assertEquals(tbDateTestEntity.getYear(), d.getUTCFullYear());
Assertions.assertEquals(tbDateTestEntity.getMonth(), d.getUTCMonth());
Assertions.assertEquals(tbDateTestEntity.getDate(), d.getUTCDate());
Assertions.assertEquals(tbDateTestEntity.getHours(), d.getUTCHours());
Assertions.assertEquals(d.getMinutes(), d.getUTCMinutes());
Assertions.assertEquals(d.getSeconds(), d.getUTCSeconds());
Assertions.assertEquals(d.getMilliseconds(), d.getUTCMilliseconds());
}
@Test
@ -884,7 +882,7 @@ class TbDateTest {
String stringDateUTC = "2023-09-06T01:04:05.345Z";
TbDate expectedDate = new TbDate(stringDateUTC);
String serializedTbDate = JacksonUtil.toJsonNode(JacksonUtil.toString(Map.of("date", expectedDate))).get("date").asText();
Assert.assertNotNull(serializedTbDate);
Assert.assertEquals(expectedDate.toString(), serializedTbDate);
Assertions.assertNotNull(serializedTbDate);
Assertions.assertEquals(expectedDate.toString(), serializedTbDate);
}
}

262
common/script/script-api/src/test/java/org/thingsboard/script/api/tbel/TbUtilsTest.java

@ -17,10 +17,10 @@ package org.thingsboard.script.api.tbel;
import com.google.common.primitives.Bytes;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.mvel2.ExecutionContext;
import org.mvel2.ParserContext;
import org.mvel2.SandboxedParserConfiguration;
@ -57,7 +57,7 @@ public class TbUtilsTest {
private final double doubleValRev = -2.7208640774822924E205;
@Before
@BeforeEach
public void before() {
SandboxedParserConfiguration parserConfig = ParserContext.enableSandboxedMode();
parserConfig.addImport("JSON", TbJson.class);
@ -70,76 +70,76 @@ public class TbUtilsTest {
log.error("Cannot register functions", e);
}
ctx = new ExecutionContext(parserConfig);
Assert.assertNotNull(ctx);
Assertions.assertNotNull(ctx);
}
@After
@AfterEach
public void after() {
ctx.stop();
}
@Test
public void parseHexToInt() {
Assert.assertEquals(0xAB, TbUtils.parseHexToInt("AB"));
Assert.assertEquals(0xABBA, TbUtils.parseHexToInt("ABBA", true));
Assert.assertEquals(0xBAAB, TbUtils.parseHexToInt("ABBA", false));
Assert.assertEquals(0xAABBCC, TbUtils.parseHexToInt("AABBCC", true));
Assert.assertEquals(0xAABBCC, TbUtils.parseHexToInt("CCBBAA", false));
Assert.assertEquals(0xAABBCCDD, TbUtils.parseHexToInt("AABBCCDD", true));
Assert.assertEquals(0xAABBCCDD, TbUtils.parseHexToInt("DDCCBBAA", false));
Assert.assertEquals(0xDDCCBBAA, TbUtils.parseHexToInt("DDCCBBAA", true));
Assert.assertEquals(0xDDCCBBAA, TbUtils.parseHexToInt("AABBCCDD", false));
Assertions.assertEquals(0xAB, TbUtils.parseHexToInt("AB"));
Assertions.assertEquals(0xABBA, TbUtils.parseHexToInt("ABBA", true));
Assertions.assertEquals(0xBAAB, TbUtils.parseHexToInt("ABBA", false));
Assertions.assertEquals(0xAABBCC, TbUtils.parseHexToInt("AABBCC", true));
Assertions.assertEquals(0xAABBCC, TbUtils.parseHexToInt("CCBBAA", false));
Assertions.assertEquals(0xAABBCCDD, TbUtils.parseHexToInt("AABBCCDD", true));
Assertions.assertEquals(0xAABBCCDD, TbUtils.parseHexToInt("DDCCBBAA", false));
Assertions.assertEquals(0xDDCCBBAA, TbUtils.parseHexToInt("DDCCBBAA", true));
Assertions.assertEquals(0xDDCCBBAA, TbUtils.parseHexToInt("AABBCCDD", false));
}
@Test
public void parseBytesToInt_checkPrimitives() {
int expected = 257;
byte[] data = ByteBuffer.allocate(4).putInt(expected).array();
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4));
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 2, 2, true));
Assert.assertEquals(1, TbUtils.parseBytesToInt(data, 3, 1, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 2, 2, true));
Assertions.assertEquals(1, TbUtils.parseBytesToInt(data, 3, 1, true));
expected = Integer.MAX_VALUE;
data = ByteBuffer.allocate(4).putInt(expected).array();
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
expected = 0xAABBCCDD;
data = new byte[]{(byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD};
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
data = new byte[]{(byte) 0xDD, (byte) 0xCC, (byte) 0xBB, (byte) 0xAA};
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, false));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, false));
expected = 0xAABBCC;
data = new byte[]{(byte) 0xAA, (byte) 0xBB, (byte) 0xCC};
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, true));
data = new byte[]{(byte) 0xCC, (byte) 0xBB, (byte) 0xAA};
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, false));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, false));
}
@Test
public void parseBytesToInt_checkLists() {
int expected = 257;
List<Byte> data = toList(ByteBuffer.allocate(4).putInt(expected).array());
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4));
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 2, 2, true));
Assert.assertEquals(1, TbUtils.parseBytesToInt(data, 3, 1, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 2, 2, true));
Assertions.assertEquals(1, TbUtils.parseBytesToInt(data, 3, 1, true));
expected = Integer.MAX_VALUE;
data = toList(ByteBuffer.allocate(4).putInt(expected).array());
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
expected = 0xAABBCCDD;
data = toList(new byte[]{(byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD});
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, true));
data = toList(new byte[]{(byte) 0xDD, (byte) 0xCC, (byte) 0xBB, (byte) 0xAA});
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, false));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 4, false));
expected = 0xAABBCC;
data = toList(new byte[]{(byte) 0xAA, (byte) 0xBB, (byte) 0xCC});
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, true));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, true));
data = toList(new byte[]{(byte) 0xCC, (byte) 0xBB, (byte) 0xAA});
Assert.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, false));
Assertions.assertEquals(expected, TbUtils.parseBytesToInt(data, 0, 3, false));
}
@Test
@ -183,7 +183,7 @@ public class TbUtilsTest {
ExecutionHashMap<String, Object> actualMapWithPaths = TbUtils.toFlatMap(ctx, inputMap, excludeList, true);
Assert.assertEquals(expectedMapWithPath, actualMapWithPaths);
Assertions.assertEquals(expectedMapWithPath, actualMapWithPaths);
ExecutionHashMap<String, Object> expectedMapWithoutPaths = new ExecutionHashMap<>(16, ctx);
expectedMapWithoutPaths.put("timezone", "UTC-5");
@ -199,153 +199,153 @@ public class TbUtilsTest {
ExecutionHashMap<String, Object> actualMapWithoutPaths = TbUtils.toFlatMap(ctx, inputMap, false);
Assert.assertEquals(expectedMapWithoutPaths, actualMapWithoutPaths);
Assertions.assertEquals(expectedMapWithoutPaths, actualMapWithoutPaths);
}
@Test
public void parseInt() {
Assert.assertNull(TbUtils.parseInt(null));
Assert.assertNull(TbUtils.parseInt(""));
Assert.assertNull(TbUtils.parseInt(" "));
Assertions.assertNull(TbUtils.parseInt(null));
Assertions.assertNull(TbUtils.parseInt(""));
Assertions.assertNull(TbUtils.parseInt(" "));
Assert.assertEquals(java.util.Optional.of(0).get(), TbUtils.parseInt("0"));
Assert.assertEquals(java.util.Optional.of(0).get(), TbUtils.parseInt("-0"));
Assert.assertEquals(java.util.Optional.of(473).get(), TbUtils.parseInt("473"));
Assert.assertEquals(java.util.Optional.of(-255).get(), TbUtils.parseInt("-0xFF"));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("FF"));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("0xFG"));
Assertions.assertEquals(java.util.Optional.of(0).get(), TbUtils.parseInt("0"));
Assertions.assertEquals(java.util.Optional.of(0).get(), TbUtils.parseInt("-0"));
Assertions.assertEquals(java.util.Optional.of(473).get(), TbUtils.parseInt("473"));
Assertions.assertEquals(java.util.Optional.of(-255).get(), TbUtils.parseInt("-0xFF"));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("FF"));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("0xFG"));
Assert.assertEquals(java.util.Optional.of(102).get(), TbUtils.parseInt("1100110", 2));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("1100210", 2));
Assertions.assertEquals(java.util.Optional.of(102).get(), TbUtils.parseInt("1100110", 2));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("1100210", 2));
Assert.assertEquals(java.util.Optional.of(63).get(), TbUtils.parseInt("77", 8));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("18", 8));
Assertions.assertEquals(java.util.Optional.of(63).get(), TbUtils.parseInt("77", 8));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("18", 8));
Assert.assertEquals(java.util.Optional.of(-255).get(), TbUtils.parseInt("-FF", 16));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("FG", 16));
Assertions.assertEquals(java.util.Optional.of(-255).get(), TbUtils.parseInt("-FF", 16));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("FG", 16));
Assert.assertEquals(java.util.Optional.of(Integer.MAX_VALUE).get(), TbUtils.parseInt(Integer.toString(Integer.MAX_VALUE), 10));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt(BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.valueOf(1)).toString(10), 10));
Assert.assertEquals(java.util.Optional.of(Integer.MIN_VALUE).get(), TbUtils.parseInt(Integer.toString(Integer.MIN_VALUE), 10));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt(BigInteger.valueOf(Integer.MIN_VALUE).subtract(BigInteger.valueOf(1)).toString(10), 10));
Assertions.assertEquals(java.util.Optional.of(Integer.MAX_VALUE).get(), TbUtils.parseInt(Integer.toString(Integer.MAX_VALUE), 10));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt(BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.valueOf(1)).toString(10), 10));
Assertions.assertEquals(java.util.Optional.of(Integer.MIN_VALUE).get(), TbUtils.parseInt(Integer.toString(Integer.MIN_VALUE), 10));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt(BigInteger.valueOf(Integer.MIN_VALUE).subtract(BigInteger.valueOf(1)).toString(10), 10));
Assert.assertEquals(java.util.Optional.of(506070563).get(), TbUtils.parseInt("KonaIn", 30));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("KonaIn", 10));
Assertions.assertEquals(java.util.Optional.of(506070563).get(), TbUtils.parseInt("KonaIn", 30));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseInt("KonaIn", 10));
}
@Test
public void parseFloat() {
Assert.assertEquals(java.util.Optional.of(floatVal).get(), TbUtils.parseFloat(floatValStr));
Assertions.assertEquals(java.util.Optional.of(floatVal).get(), TbUtils.parseFloat(floatValStr));
}
@Test
public void toFixedFloat() {
float actualF = TbUtils.toFixed(floatVal, 3);
Assert.assertEquals(1, Float.compare(floatVal, actualF));
Assert.assertEquals(0, Float.compare(29.298f, actualF));
Assertions.assertEquals(1, Float.compare(floatVal, actualF));
Assertions.assertEquals(0, Float.compare(29.298f, actualF));
}
@Test
public void parseHexToFloat() {
Assert.assertEquals(0, Float.compare(floatVal, TbUtils.parseHexToFloat(intValHex)));
Assert.assertEquals(0, Float.compare(floatValRev, TbUtils.parseHexToFloat(intValHex, false)));
Assert.assertEquals(0, Float.compare(floatVal, TbUtils.parseBigEndianHexToFloat(intValHex)));
Assert.assertEquals(0, Float.compare(floatVal, TbUtils.parseLittleEndianHexToFloat(floatValHexRev)));
Assertions.assertEquals(0, Float.compare(floatVal, TbUtils.parseHexToFloat(intValHex)));
Assertions.assertEquals(0, Float.compare(floatValRev, TbUtils.parseHexToFloat(intValHex, false)));
Assertions.assertEquals(0, Float.compare(floatVal, TbUtils.parseBigEndianHexToFloat(intValHex)));
Assertions.assertEquals(0, Float.compare(floatVal, TbUtils.parseLittleEndianHexToFloat(floatValHexRev)));
}
@Test
public void arseBytesToFloat() {
byte[] floatValByte = {65, -22, 98, -52};
Assert.assertEquals(0, Float.compare(floatVal, TbUtils.parseBytesToFloat(floatValByte, 0)));
Assert.assertEquals(0, Float.compare(floatValRev, TbUtils.parseBytesToFloat(floatValByte, 0, false)));
Assertions.assertEquals(0, Float.compare(floatVal, TbUtils.parseBytesToFloat(floatValByte, 0)));
Assertions.assertEquals(0, Float.compare(floatValRev, TbUtils.parseBytesToFloat(floatValByte, 0, false)));
List <Byte> floatVaList = Bytes.asList(floatValByte);
Assert.assertEquals(0, Float.compare(floatVal, TbUtils.parseBytesToFloat(floatVaList, 0)));
Assert.assertEquals(0, Float.compare(floatValRev, TbUtils.parseBytesToFloat(floatVaList, 0, false)));
Assertions.assertEquals(0, Float.compare(floatVal, TbUtils.parseBytesToFloat(floatVaList, 0)));
Assertions.assertEquals(0, Float.compare(floatValRev, TbUtils.parseBytesToFloat(floatVaList, 0, false)));
}
@Test
public void parseLong() {
Assert.assertNull(TbUtils.parseLong(null));
Assert.assertNull(TbUtils.parseLong(""));
Assert.assertNull(TbUtils.parseLong(" "));
Assertions.assertNull(TbUtils.parseLong(null));
Assertions.assertNull(TbUtils.parseLong(""));
Assertions.assertNull(TbUtils.parseLong(" "));
Assert.assertEquals(java.util.Optional.of(0L).get(), TbUtils.parseLong("0"));
Assert.assertEquals(java.util.Optional.of(0L).get(), TbUtils.parseLong("-0"));
Assert.assertEquals(java.util.Optional.of(473L).get(), TbUtils.parseLong("473"));
Assert.assertEquals(java.util.Optional.of(-65535L).get(), TbUtils.parseLong("-0xFFFF"));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("FFFFFFFF"));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("0xFGFFFFFF"));
Assertions.assertEquals(java.util.Optional.of(0L).get(), TbUtils.parseLong("0"));
Assertions.assertEquals(java.util.Optional.of(0L).get(), TbUtils.parseLong("-0"));
Assertions.assertEquals(java.util.Optional.of(473L).get(), TbUtils.parseLong("473"));
Assertions.assertEquals(java.util.Optional.of(-65535L).get(), TbUtils.parseLong("-0xFFFF"));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("FFFFFFFF"));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("0xFGFFFFFF"));
Assert.assertEquals(java.util.Optional.of(13158L).get(), TbUtils.parseLong("11001101100110", 2));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("11001101100210", 2));
Assertions.assertEquals(java.util.Optional.of(13158L).get(), TbUtils.parseLong("11001101100110", 2));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("11001101100210", 2));
Assert.assertEquals(java.util.Optional.of(9223372036854775807L).get(), TbUtils.parseLong("777777777777777777777", 8));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("1787", 8));
Assertions.assertEquals(java.util.Optional.of(9223372036854775807L).get(), TbUtils.parseLong("777777777777777777777", 8));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("1787", 8));
Assert.assertEquals(java.util.Optional.of(-255L).get(), TbUtils.parseLong("-FF", 16));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("FG", 16));
Assertions.assertEquals(java.util.Optional.of(-255L).get(), TbUtils.parseLong("-FF", 16));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("FG", 16));
Assert.assertEquals(java.util.Optional.of(Long.MAX_VALUE).get(), TbUtils.parseLong(Long.toString(Long.MAX_VALUE), 10));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1)).toString(10), 10));
Assert.assertEquals(java.util.Optional.of(Long.MIN_VALUE).get(), TbUtils.parseLong(Long.toString(Long.MIN_VALUE), 10));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.valueOf(1)).toString(10), 10));
Assertions.assertEquals(java.util.Optional.of(Long.MAX_VALUE).get(), TbUtils.parseLong(Long.toString(Long.MAX_VALUE), 10));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1)).toString(10), 10));
Assertions.assertEquals(java.util.Optional.of(Long.MIN_VALUE).get(), TbUtils.parseLong(Long.toString(Long.MIN_VALUE), 10));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.valueOf(1)).toString(10), 10));
Assert.assertEquals(java.util.Optional.of(218840926543L).get(), TbUtils.parseLong("KonaLong", 27));
Assert.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("KonaLong", 10));
Assertions.assertEquals(java.util.Optional.of(218840926543L).get(), TbUtils.parseLong("KonaLong", 27));
Assertions.assertThrows(NumberFormatException.class, () -> TbUtils.parseLong("KonaLong", 10));
}
@Test
public void parseHexToLong() {
Assert.assertEquals(longVal, TbUtils.parseHexToLong(longValHex));
Assert.assertEquals(longVal, TbUtils.parseHexToLong(longValHexRev, false));
Assert.assertEquals(longVal, TbUtils.parseBigEndianHexToLong(longValHex));
Assert.assertEquals(longVal, TbUtils.parseLittleEndianHexToLong(longValHexRev));
Assertions.assertEquals(longVal, TbUtils.parseHexToLong(longValHex));
Assertions.assertEquals(longVal, TbUtils.parseHexToLong(longValHexRev, false));
Assertions.assertEquals(longVal, TbUtils.parseBigEndianHexToLong(longValHex));
Assertions.assertEquals(longVal, TbUtils.parseLittleEndianHexToLong(longValHexRev));
}
@Test
public void parseBytesToLong() {
byte[] longValByte = {64, -101, 4, -79, 12, -78, -107, -22};
Assert.assertEquals(longVal, TbUtils.parseBytesToLong(longValByte, 0, 8));
Assertions.assertEquals(longVal, TbUtils.parseBytesToLong(longValByte, 0, 8));
Bytes.reverse(longValByte);
Assert.assertEquals(longVal, TbUtils.parseBytesToLong(longValByte, 0, 8, false));
Assertions.assertEquals(longVal, TbUtils.parseBytesToLong(longValByte, 0, 8, false));
List <Byte> longVaList = Bytes.asList(longValByte);
Assert.assertEquals(longVal, TbUtils.parseBytesToLong(longVaList, 0, 8, false));
Assert.assertEquals(longValRev, TbUtils.parseBytesToLong(longVaList, 0, 8));
Assertions.assertEquals(longVal, TbUtils.parseBytesToLong(longVaList, 0, 8, false));
Assertions.assertEquals(longValRev, TbUtils.parseBytesToLong(longVaList, 0, 8));
}
@Test
public void parsDouble() {
Assert.assertEquals(java.util.Optional.of(doubleVal).get(), TbUtils.parseDouble(doubleValStr));
Assertions.assertEquals(java.util.Optional.of(doubleVal).get(), TbUtils.parseDouble(doubleValStr));
}
@Test
public void toFixedDouble() {
double actualD = TbUtils.toFixed(doubleVal, 3);
Assert.assertEquals(-1, Double.compare(doubleVal, actualD));
Assert.assertEquals(0, Double.compare(1729.173, actualD));
Assertions.assertEquals(-1, Double.compare(doubleVal, actualD));
Assertions.assertEquals(0, Double.compare(1729.173, actualD));
}
@Test
public void parseHexToDouble() {
Assert.assertEquals(0, Double.compare(doubleVal, TbUtils.parseHexToDouble(longValHex)));
Assert.assertEquals(0, Double.compare(doubleValRev, TbUtils.parseHexToDouble(longValHex, false)));
Assert.assertEquals(0, Double.compare(doubleVal, TbUtils.parseBigEndianHexToDouble(longValHex)));
Assert.assertEquals(0, Double.compare(doubleVal, TbUtils.parseLittleEndianHexToDouble(longValHexRev)));
Assertions.assertEquals(0, Double.compare(doubleVal, TbUtils.parseHexToDouble(longValHex)));
Assertions.assertEquals(0, Double.compare(doubleValRev, TbUtils.parseHexToDouble(longValHex, false)));
Assertions.assertEquals(0, Double.compare(doubleVal, TbUtils.parseBigEndianHexToDouble(longValHex)));
Assertions.assertEquals(0, Double.compare(doubleVal, TbUtils.parseLittleEndianHexToDouble(longValHexRev)));
}
@Test
public void parseBytesToDouble() {
byte[] doubleValByte = {64, -101, 4, -79, 12, -78, -107, -22};
Assert.assertEquals(0, Double.compare(doubleVal, TbUtils.parseBytesToDouble(doubleValByte, 0)));
Assert.assertEquals(0, Double.compare(doubleValRev, TbUtils.parseBytesToDouble(doubleValByte, 0, false)));
Assertions.assertEquals(0, Double.compare(doubleVal, TbUtils.parseBytesToDouble(doubleValByte, 0)));
Assertions.assertEquals(0, Double.compare(doubleValRev, TbUtils.parseBytesToDouble(doubleValByte, 0, false)));
List <Byte> doubleVaList = Bytes.asList(doubleValByte);
Assert.assertEquals(0, Double.compare(doubleVal, TbUtils.parseBytesToDouble(doubleVaList, 0)));
Assert.assertEquals(0, Double.compare(doubleValRev, TbUtils.parseBytesToDouble(doubleVaList, 0, false)));
Assertions.assertEquals(0, Double.compare(doubleVal, TbUtils.parseBytesToDouble(doubleVaList, 0)));
Assertions.assertEquals(0, Double.compare(doubleValRev, TbUtils.parseBytesToDouble(doubleVaList, 0, false)));
}
@Test
@ -355,7 +355,7 @@ public class TbUtilsTest {
expectedJson.put("hello", "world");
List<Byte> expectedBytes = TbUtils.stringToBytes(ctx, expectedStr);
Object actualJson = TbUtils.decodeToJson(ctx, expectedBytes);
Assert.assertEquals(expectedJson,actualJson);
Assertions.assertEquals(expectedJson,actualJson);
}
@Test
public void parseStringDecodeToJson() throws IOException {
@ -363,7 +363,7 @@ public class TbUtilsTest {
ExecutionHashMap<String, Object> expectedJson = new ExecutionHashMap<>(1, ctx);
expectedJson.put("hello", "world");
Object actualJson = TbUtils.decodeToJson(ctx, expectedStr);
Assert.assertEquals(expectedJson,actualJson);
Assertions.assertEquals(expectedJson,actualJson);
}
@Test
@ -373,15 +373,15 @@ public class TbUtilsTest {
byte[] arrayBytes = {119, 111, 114, 108, 100};
List<Byte> expectedBytes = Bytes.asList(arrayBytes);
List<Byte> actualBytes = TbUtils.stringToBytes(ctx, ((ExecutionHashMap) inputJson).get("hello"));
Assert.assertEquals(expectedBytes, actualBytes);
Assertions.assertEquals(expectedBytes, actualBytes);
actualBytes = TbUtils.stringToBytes(ctx, ((ExecutionHashMap) inputJson).get("hello"), "UTF-8");
Assert.assertEquals(expectedBytes, actualBytes);
Assertions.assertEquals(expectedBytes, actualBytes);
expectedStr = "{\"hello\": 1234}";
inputJson = TbUtils.decodeToJson(ctx, expectedStr);
Object finalInputJson = inputJson;
Assert.assertThrows(IllegalAccessException.class, () -> TbUtils.stringToBytes(ctx, ((ExecutionHashMap) finalInputJson).get("hello")));
Assert.assertThrows(IllegalAccessException.class, () -> TbUtils.stringToBytes(ctx, ((ExecutionHashMap) finalInputJson).get("hello"), "UTF-8"));
Assertions.assertThrows(IllegalAccessException.class, () -> TbUtils.stringToBytes(ctx, ((ExecutionHashMap) finalInputJson).get("hello")));
Assertions.assertThrows(IllegalAccessException.class, () -> TbUtils.stringToBytes(ctx, ((ExecutionHashMap) finalInputJson).get("hello"), "UTF-8"));
}
@Test
@ -394,13 +394,13 @@ public class TbUtilsTest {
for (Byte element : arrayBytes) {
listBytes.add(element);
}
Assert.assertEquals(expected, TbUtils.bytesToString(listBytes));
Assertions.assertEquals(expected, TbUtils.bytesToString(listBytes));
ArrayList<Object> listMix = new ArrayList<>(arrayMix.length);
for (Object element : arrayMix) {
listMix.add(element);
}
Assert.assertEquals(expected, TbUtils.bytesToString(listMix));
Assertions.assertEquals(expected, TbUtils.bytesToString(listMix));
}
@Test
@ -409,34 +409,34 @@ public class TbUtilsTest {
listHex.add("0xFG");
try {
TbUtils.bytesToString(listHex);
Assert.fail("Should throw NumberFormatException");
Assertions.fail("Should throw NumberFormatException");
} catch (NumberFormatException e) {
Assert.assertTrue(e.getMessage().contains("Failed radix: [16] for value: \"FG\"!"));
Assertions.assertTrue(e.getMessage().contains("Failed radix: [16] for value: \"FG\"!"));
}
listHex.add(0, "1F");
try {
TbUtils.bytesToString(listHex);
Assert.fail("Should throw NumberFormatException");
Assertions.fail("Should throw NumberFormatException");
} catch (NumberFormatException e) {
Assert.assertTrue(e.getMessage().contains("Failed radix: [10] for value: \"1F\"!"));
Assertions.assertTrue(e.getMessage().contains("Failed radix: [10] for value: \"1F\"!"));
}
List<String> listIntString = new ArrayList<>();
listIntString.add("-129");
try {
TbUtils.bytesToString(listIntString);
Assert.fail("Should throw NumberFormatException");
Assertions.fail("Should throw NumberFormatException");
} catch (NumberFormatException e) {
Assert.assertTrue(e.getMessage().contains("The value '-129' could not be correctly converted to a byte. " +
Assertions.assertTrue(e.getMessage().contains("The value '-129' could not be correctly converted to a byte. " +
"Integer to byte conversion requires the use of only 8 bits (with a range of min/max = -128/255)!"));
}
listIntString.add(0, "256");
try {
TbUtils.bytesToString(listIntString);
Assert.fail("Should throw NumberFormatException");
Assertions.fail("Should throw NumberFormatException");
} catch (NumberFormatException e) {
Assert.assertTrue(e.getMessage().contains("The value '256' could not be correctly converted to a byte. " +
Assertions.assertTrue(e.getMessage().contains("The value '256' could not be correctly converted to a byte. " +
"Integer to byte conversion requires the use of only 8 bits (with a range of min/max = -128/255)!"));
}
@ -444,18 +444,18 @@ public class TbUtilsTest {
listIntBytes.add(-129);
try {
TbUtils.bytesToString(listIntBytes);
Assert.fail("Should throw NumberFormatException");
Assertions.fail("Should throw NumberFormatException");
} catch (NumberFormatException e) {
Assert.assertTrue(e.getMessage().contains("The value '-129' could not be correctly converted to a byte. " +
Assertions.assertTrue(e.getMessage().contains("The value '-129' could not be correctly converted to a byte. " +
"Integer to byte conversion requires the use of only 8 bits (with a range of min/max = -128/255)!"));
}
listIntBytes.add(0, 256);
try {
TbUtils.bytesToString(listIntBytes);
Assert.fail("Should throw NumberFormatException");
Assertions.fail("Should throw NumberFormatException");
} catch (NumberFormatException e) {
Assert.assertTrue(e.getMessage().contains("The value '256' could not be correctly converted to a byte. " +
Assertions.assertTrue(e.getMessage().contains("The value '256' could not be correctly converted to a byte. " +
"Integer to byte conversion requires the use of only 8 bits (with a range of min/max = -128/255)!"));
}
@ -465,9 +465,9 @@ public class TbUtilsTest {
listObjects.add(listStringObjects);
try {
TbUtils.bytesToString(listObjects);
Assert.fail("Should throw NumberFormatException");
Assertions.fail("Should throw NumberFormatException");
} catch (NumberFormatException e) {
Assert.assertTrue(e.getMessage().contains("The value '[0xFD]' could not be correctly converted to a byte. " +
Assertions.assertTrue(e.getMessage().contains("The value '[0xFD]' could not be correctly converted to a byte. " +
"Must be a HexDecimal/String/Integer/Byte format !"));
}
}
@ -477,10 +477,10 @@ public class TbUtilsTest {
String uriOriginal = "-_.!~*'();/?:@&=+$,#ht://example.ж д a/path with spaces/?param1=Київ 1&param2=Україна2";
String uriEncodeExpected = "-_.!~*'();/?:@&=+$,#ht://example.%D0%B6%20%D0%B4%20a/path%20with%20spaces/?param1=%D0%9A%D0%B8%D1%97%D0%B2%201&param2=%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B02";
String uriEncodeActual = TbUtils.encodeURI(uriOriginal);
Assert.assertEquals(uriEncodeExpected, uriEncodeActual);
Assertions.assertEquals(uriEncodeExpected, uriEncodeActual);
String uriDecodeActual = TbUtils.decodeURI(uriEncodeActual);
Assert.assertEquals(uriOriginal, uriDecodeActual);
Assertions.assertEquals(uriOriginal, uriDecodeActual);
}
private static List<Byte> toList(byte[] data) {
List<Byte> result = new ArrayList<>(data.length);

3
common/script/script-api/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/script/script-api/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/stats/pom.xml

@ -76,11 +76,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

5
common/transport/coap/pom.xml

@ -81,11 +81,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

3
common/transport/coap/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/transport/coap/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/transport/http/pom.xml

@ -66,11 +66,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

3
common/transport/http/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

5
common/transport/lwm2m/pom.xml

@ -89,11 +89,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

2
common/transport/lwm2m/src/test/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientTest.java

@ -19,7 +19,7 @@ import org.eclipse.leshan.core.endpoint.EndpointUriUtil;
import org.eclipse.leshan.core.link.Link;
import org.eclipse.leshan.core.peer.IpPeer;
import org.eclipse.leshan.server.registration.Registration;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import java.net.InetSocketAddress;

9
common/transport/lwm2m/src/test/java/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDesTest.java

@ -25,8 +25,7 @@ import org.eclipse.leshan.core.node.LwM2mSingleResource;
import org.eclipse.leshan.core.peer.IpPeer;
import org.eclipse.leshan.core.request.WriteRequest;
import org.eclipse.leshan.server.registration.Registration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.thingsboard.server.common.data.TbResource;
import org.thingsboard.server.common.data.device.data.PowerMode;
import org.thingsboard.server.common.data.id.CustomerId;
@ -54,8 +53,8 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -119,7 +118,7 @@ public class LwM2MClientSerDesTest {
client.saveResourceValue("/17_1.0/0/0", multipleResource, provider, WriteRequest.Mode.UPDATE);
byte[] bytes = LwM2MClientSerDes.serialize(client);
Assert.assertNotNull(bytes);
assertNotNull(bytes);
LwM2mClient desClient = LwM2MClientSerDes.deserialize(bytes);

3
common/transport/lwm2m/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/transport/lwm2m/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/transport/mqtt/pom.xml

@ -87,11 +87,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

24
common/transport/mqtt/src/test/java/org/thingsboard/server/transport/mqtt/MqttTransportHandlerTest.java

@ -28,13 +28,14 @@ import io.netty.handler.codec.mqtt.MqttPublishVariableHeader;
import io.netty.handler.codec.mqtt.MqttQoS;
import io.netty.handler.ssl.SslHandler;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.thingsboard.common.util.ThingsBoardThreadFactory;
import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.DeviceProfile;
@ -58,16 +59,17 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.fail;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.willDoNothing;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@ -75,7 +77,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@Slf4j
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class MqttTransportHandlerTest {
public static final int MSG_QUEUE_LIMIT = 10;
@ -96,17 +98,17 @@ public class MqttTransportHandlerTest {
@Spy
TransportService transportService;
@Before
@BeforeEach
public void setUp() throws Exception {
willReturn(MSG_QUEUE_LIMIT).given(context).getMessageQueueSizePerDeviceLimit();
willReturn(transportService).given(context).getTransportService();
lenient().doReturn(MSG_QUEUE_LIMIT).when(context).getMessageQueueSizePerDeviceLimit();
lenient().doReturn(transportService).when(context).getTransportService();
handler = spy(new MqttTransportHandler(context, sslHandler));
willReturn(IP_ADDR).given(handler).getAddress(any());
lenient().doReturn(IP_ADDR).when(handler).getAddress(any());
}
@After
@AfterEach
public void tearDown() {
if (executor != null) {
executor.shutdownNow();

12
common/transport/mqtt/src/test/java/org/thingsboard/server/transport/mqtt/util/MqttTopicFilterFactoryTest.java

@ -15,16 +15,16 @@
*/
package org.thingsboard.server.transport.mqtt.util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import javax.script.ScriptException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class MqttTopicFilterFactoryTest {
private static String TEST_STR_1 = "Sensor/Temperature/House/48";

3
common/transport/mqtt/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/transport/mqtt/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

3
common/transport/snmp/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/transport/snmp/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/transport/transport-api/pom.xml

@ -85,11 +85,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

3
common/transport/transport-api/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/transport/transport-api/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/util/pom.xml

@ -82,11 +82,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

2
common/util/src/test/java/org/thingsboard/common/util/ExceptionUtilTest.java

@ -28,7 +28,7 @@ class ExceptionUtilTest {
@Test
void givenRootCause_whenLookupExceptionInCause_thenReturnRootCauseAndNoStackOverflow() {
Exception e = cause;
for (int i = 0; i <= 16384; i++) {
for (int i = 0; i <= 8000; i++) {
e = new Exception(e);
}
assertThat(ExceptionUtil.lookupExceptionInCause(e, RuntimeException.class)).isSameAs(cause);

17
common/util/src/test/java/org/thingsboard/common/util/JacksonUtilTest.java

@ -17,9 +17,8 @@ package org.thingsboard.common.util;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.thingsboard.server.common.data.asset.Asset;
@ -40,8 +39,8 @@ public class JacksonUtilTest {
JsonNode actualResult = JacksonUtil.toJsonNode(data, JacksonUtil.ALLOW_UNQUOTED_FIELD_NAMES_MAPPER); // should be: {"data": 123}
ObjectNode expectedResult = JacksonUtil.newObjectNode();
expectedResult.put("data", 123); // {"data": 123}
Assert.assertEquals(expectedResult, actualResult);
Assert.assertThrows(IllegalArgumentException.class, () -> JacksonUtil.toJsonNode(data)); // syntax exception due to missing quotes in the field name!
Assertions.assertEquals(expectedResult, actualResult);
Assertions.assertThrows(IllegalArgumentException.class, () -> JacksonUtil.toJsonNode(data)); // syntax exception due to missing quotes in the field name!
}
@Test
@ -53,15 +52,15 @@ public class JacksonUtilTest {
String serializedAsset = JacksonUtil.toString(asset);
JsonNode jsonNode = JacksonUtil.toJsonNode(serializedAsset);
// case: add new field to serialized Asset string and check for backward compatibility with original Asset object
Assert.assertNotNull(jsonNode);
Assertions.assertNotNull(jsonNode);
((ObjectNode) jsonNode).put("test", (String) null);
serializedAsset = JacksonUtil.toString(jsonNode);
// deserialize with FAIL_ON_UNKNOWN_PROPERTIES = false
Asset result = JacksonUtil.fromString(serializedAsset, Asset.class, true);
Assert.assertNotNull(result);
Assert.assertEquals(asset.getId(), result.getId());
Assert.assertEquals(asset.getName(), result.getName());
Assert.assertEquals(asset.getType(), result.getType());
Assertions.assertNotNull(result);
Assertions.assertEquals(asset.getId(), result.getId());
Assertions.assertEquals(asset.getName(), result.getName());
Assertions.assertEquals(asset.getType(), result.getType());
}
@ParameterizedTest

2
common/util/src/test/java/org/thingsboard/common/util/LinkedHashMapRemoveEldestTest.java

@ -16,7 +16,7 @@
package org.thingsboard.common.util;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;

3
common/util/src/test/resources/junit-platform.properties

@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

14
common/util/src/test/resources/logback-test.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>

5
common/version-control/pom.xml

@ -102,11 +102,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>

Loading…
Cancel
Save