From b63822b8e5c301b573fc88379d604e112c696305 Mon Sep 17 00:00:00 2001 From: Andrii Landiak Date: Thu, 20 Nov 2025 09:43:37 +0200 Subject: [PATCH] Fix error in tests for SystemPatchApplier --- .../server/controller/AbstractWebTest.java | 16 +++++++++------ .../server/common/data/pat/ApiKey.java | 2 +- .../server/common/data/pat/ApiKeyInfo.java | 20 +++++++++---------- .../server/dao/service/ApiKeyServiceTest.java | 1 + 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java b/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java index 7bc6f9876c..51d77bd134 100644 --- a/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java @@ -38,8 +38,6 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.http.HttpHeaders; @@ -53,6 +51,8 @@ import org.springframework.mock.http.MockHttpInputMessage; import org.springframework.mock.http.MockHttpOutputMessage; import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockPart; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -167,6 +167,7 @@ import org.thingsboard.server.service.entitiy.tenant.profile.TbTenantProfileServ import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest; import org.thingsboard.server.service.security.auth.rest.LoginRequest; import org.thingsboard.server.service.security.model.token.JwtTokenFactory; +import org.thingsboard.server.service.system.SystemPatchApplier; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -295,18 +296,21 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { @Autowired private JwtTokenFactory jwtTokenFactory; - @SpyBean - protected MailService mailService; - @Autowired protected InMemoryStorage storage; @Autowired protected JdbcTemplate jdbcTemplate; - @MockBean + @MockitoSpyBean + protected MailService mailService; + + @MockitoBean protected CfRocksDb cfRocksDb; + @MockitoBean + protected SystemPatchApplier systemPatchApplier; + @Rule public TestRule watcher = new TestWatcher() { protected void starting(Description description) { diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKey.java b/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKey.java index 81753322ba..a48be1c9c4 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKey.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKey.java @@ -32,7 +32,7 @@ public class ApiKey extends ApiKeyInfo { private static final long serialVersionUID = -2313196723950490263L; @NoXss - @Schema(description = "Api key value", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "API key value", requiredMode = Schema.RequiredMode.REQUIRED) private String value; public ApiKey() { diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKeyInfo.java b/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKeyInfo.java index 770f4e64f6..41f7e49cdc 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKeyInfo.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/pat/ApiKeyInfo.java @@ -38,26 +38,26 @@ public class ApiKeyInfo extends BaseData implements HasTenantId { @Serial private static final long serialVersionUID = -2313196723950490263L; - @Schema(description = "JSON object with Tenant Id. Tenant Id of the api key cannot be changed.", accessMode = Schema.AccessMode.READ_ONLY) + @Schema(description = "JSON object with Tenant Id. Tenant Id of the API key cannot be changed.", accessMode = Schema.AccessMode.READ_ONLY) private TenantId tenantId; - @Schema(description = "JSON object with User Id. User Id of the api key cannot be changed.") + @Schema(description = "JSON object with User Id. User Id of the API key cannot be changed.") private UserId userId; - @Schema(description = "Expiration time of the api key.") + @Schema(description = "Expiration time of the API key.") private long expirationTime; @NoXss @NotBlank @Length(fieldName = "description") - @Schema(description = "Api Key description.", example = "Api Key description") + @Schema(description = "API Key description.", example = "API Key description") private String description; - @Schema(description = "Enabled/disabled api key.", example = "true") + @Schema(description = "Enabled/disabled API key.", example = "true") private boolean enabled; @JsonProperty(access = JsonProperty.Access.READ_ONLY) - @Schema(description = "Indicates if the api key is expired based on current time. Returns false if expirationTime is 0 (no expiry).", + @Schema(description = "Indicates if the API key is expired based on current time. Returns false if expirationTime is 0 (no expiry).", example = "false", accessMode = Schema.AccessMode.READ_ONLY) public boolean isExpired() { @@ -67,10 +67,10 @@ public class ApiKeyInfo extends BaseData implements HasTenantId { return System.currentTimeMillis() > expirationTime; } - @Schema(description = "JSON object with the Api Key Id. " + - "Specify this field to update the Api Key. " + - "Referencing non-existing Api Key Id will cause error. " + - "Omit this field to create new Api Key.") + @Schema(description = "JSON object with the API Key Id. " + + "Specify this field to update the API Key. " + + "Referencing non-existing API Key Id will cause error. " + + "Omit this field to create new API Key.") @Override public ApiKeyId getId() { return super.getId(); diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/ApiKeyServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/ApiKeyServiceTest.java index e7658d4fcf..64444a0d31 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/ApiKeyServiceTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/ApiKeyServiceTest.java @@ -42,6 +42,7 @@ public class ApiKeyServiceTest extends AbstractServiceTest { @Autowired ApiKeyService apiKeyService; + @Autowired UserService userService;