Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ public class JwtUtil {
private TokenBlacklistService tokenBlacklistService;

private static final long EXPIRATION_TIME = 21600000L; // 6小时 = 6 * 60 * 60 * 1000 = 21600000 毫秒
private static final String DEFAULT_SECRET = "tiny-engine-backend-secret-key-at-jwt-login";

// 避免启动时环境变量未加载的问题
private static String getSecretString() {
return Optional.ofNullable(System.getenv("SECRET_STRING"))
.orElse(DEFAULT_SECRET);
return System.getenv("SECRET_STRING");
}

public static SecretKey getSecretKey() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,357 @@
package com.tinyengine.it.dynamic.service;

import cn.hutool.core.util.ReflectUtil;
import com.tinyengine.it.common.context.LoginUserContext;
import com.tinyengine.it.dynamic.dto.DynamicDelete;
import com.tinyengine.it.dynamic.dto.DynamicInsert;
import com.tinyengine.it.dynamic.dto.DynamicQuery;
import com.tinyengine.it.dynamic.dto.DynamicUpdate;
import com.tinyengine.it.model.dto.ParametersDto;
import com.tinyengine.it.model.entity.Model;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.KeyHolder;

import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;


class DynamicModelServiceTest {

@Mock
private JdbcTemplate jdbcTemplate;

@Mock
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

@Mock
private LoginUserContext loginUserContext;

@InjectMocks
private DynamicModelService dynamicModelService;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
MockitoAnnotations.openMocks(this);
ReflectUtil.setFieldValue(dynamicModelService, "jdbcTemplate", jdbcTemplate);
ReflectUtil.setFieldValue(dynamicModelService, "loginUserContext", loginUserContext);
ReflectUtil.setFieldValue(dynamicModelService, "namedParameterJdbcTemplate", namedParameterJdbcTemplate);

}
Comment on lines +43 to +51
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Redundant openMocks call and unnecessary ReflectUtil usage.

  • Line 45–46: MockitoAnnotations.openMocks(this) is invoked twice; the second call creates a new set of mocks that are then discarded, and leaks the first AutoCloseable. Keep one call (and ideally close it in @AfterEach, or switch to @ExtendWith(MockitoExtension.class)).
  • Lines 47–49: DynamicModelService uses Lombok @RequiredArgsConstructor over final fields (see DynamicModelService.java:32-39), so @InjectMocks already performs constructor injection with the three mocks. The ReflectUtil.setFieldValue(...) calls are redundant, and if the constructor injection ever silently fails (e.g. a mock is unnamed), reflection will mask that failure.
♻️ Proposed simplification
-    `@BeforeEach`
-    void setUp() {
-        MockitoAnnotations.openMocks(this);
-        MockitoAnnotations.openMocks(this);
-        ReflectUtil.setFieldValue(dynamicModelService, "jdbcTemplate", jdbcTemplate);
-        ReflectUtil.setFieldValue(dynamicModelService, "loginUserContext", loginUserContext);
-        ReflectUtil.setFieldValue(dynamicModelService, "namedParameterJdbcTemplate", namedParameterJdbcTemplate);
-
-    }
+    `@BeforeEach`
+    void setUp() {
+        MockitoAnnotations.openMocks(this);
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
MockitoAnnotations.openMocks(this);
ReflectUtil.setFieldValue(dynamicModelService, "jdbcTemplate", jdbcTemplate);
ReflectUtil.setFieldValue(dynamicModelService, "loginUserContext", loginUserContext);
ReflectUtil.setFieldValue(dynamicModelService, "namedParameterJdbcTemplate", namedParameterJdbcTemplate);
}
`@BeforeEach`
void setUp() {
MockitoAnnotations.openMocks(this);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java`
around lines 43 - 51, Remove the duplicate MockitoAnnotations.openMocks(this)
call in DynamicModelServiceTest.setUp and drop the three
ReflectUtil.setFieldValue(...) calls for jdbcTemplate, loginUserContext and
namedParameterJdbcTemplate because `@InjectMocks` on dynamicModelService already
performs constructor injection; either store the AutoCloseable returned by the
single openMocks call and close it in an `@AfterEach` method, or replace manual
initialization with `@ExtendWith`(MockitoExtension.class) on the test class to
handle mock lifecycle automatically.



@Test
void createDynamicTable() {
// Arrange
Model model = new Model();
model.setNameEn("test_table");
ParametersDto parametersDto = new ParametersDto();
parametersDto.setProp("name");
parametersDto.setType("String");
parametersDto.setRequired(true);
parametersDto.setDefaultValue("1");
parametersDto.setDescription("1");
model.setParameters(Collections.singletonList(parametersDto));

// Mock JdbcTemplate behavior
doNothing().when(jdbcTemplate).execute(anyString());

// Act & Assert
assertDoesNotThrow(() -> dynamicModelService.createDynamicTable(model));
verify(jdbcTemplate, times(1)).execute(anyString());
}

@Test
void dropDynamicTable() {
// Arrange
Model model = new Model();
model.setNameEn("test_table");

// Mock JdbcTemplate behavior
doNothing().when(jdbcTemplate).execute(anyString());

// Act & Assert
assertDoesNotThrow(() -> dynamicModelService.dropDynamicTable(model));
verify(jdbcTemplate, times(1)).execute("DROP TABLE IF EXISTS dynamic_test_table;");
}

@Test
void initializeDynamicTable() {
// Arrange
Model model = new Model();
model.setNameEn("test_table");
ParametersDto param1 = new ParametersDto();
param1.setProp("name");
param1.setType("String");
param1.setDefaultValue("default_name");
param1.setRequired(true);
model.setParameters(Collections.singletonList(param1));

Long userId = 1L;

// Mock JdbcTemplate behavior
when(jdbcTemplate.update(anyString(), any(Object[].class))).thenReturn(1);

// Act & Assert
assertDoesNotThrow(() -> dynamicModelService.initializeDynamicTable(model, userId));
verify(jdbcTemplate, times(1)).update(anyString(), any(Object[].class));
}

@Test
void dynamicQuery() {
// Arrange
String tableName = "test_table";
List<String> fields = Arrays.asList("id", "name");
Map<String, Object> conditions = Map.of("id", 1);
String orderBy = "id DESC";
Integer limit = 10;

List<Map<String, Object>> mockResult = new ArrayList<>();
mockResult.add(Map.of("id", 1, "name", "test_name"));

when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockResult);

// Act
List<Map<String, Object>> result = dynamicModelService.dynamicQuery(tableName, fields, conditions, orderBy, limit);

// Assert
assertNotNull(result);
assertEquals(1, result.size());
assertEquals("test_name", result.get(0).get("name"));
verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap());
}

@Test
void dynamicCount() {
// Arrange
String tableName = "test_table";
Map<String, Object> conditions = Map.of("id", 1);

List<Map<String, Object>> mockResult = new ArrayList<>();
mockResult.add(Map.of("count", 5L));

when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockResult);

// Act
List<Map<String, Object>> result = dynamicModelService.dynamicCount(tableName, conditions);

// Assert
assertNotNull(result);
assertEquals(1, result.size());
assertEquals(5L, result.get(0).get("count"));
verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap());
}

@Test
void count() {
// Arrange
String tableName = "test_table";
Map<String, Object> conditions = Map.of("id", 1);

List<Map<String, Object>> mockResult = new ArrayList<>();
mockResult.add(Map.of("count", 10L));

when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockResult);

// Act
Long result = dynamicModelService.count(tableName, conditions);

// Assert
assertNotNull(result);
assertEquals(10L, result);
verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap());
}

@Test
void queryWithPage() {
// Arrange
DynamicQuery dto = new DynamicQuery();
dto.setNameEn("test_table");
dto.setFields(Arrays.asList("id", "name"));
dto.setParams(Map.of("id", 1));
dto.setOrderBy("id DESC");
dto.setCurrentPage(1);
dto.setPageSize(10);

List<Map<String, Object>> mockData = new ArrayList<>();
mockData.add(Map.of("id", 1, "name", "test_name"));

when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockData);
when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(List.of(Map.of("count", 1L)));

// Act
Map<String, Object> result = dynamicModelService.queryWithPage(dto);

// Assert
assertNotNull(result);
assertTrue((Boolean) result.get("success"));
assertEquals(1L, result.get("total"));
assertEquals(1, ((List<?>) result.get("data")).size());
verify(namedParameterJdbcTemplate, times(2)).queryForList(anyString(), anyMap());
}
Comment on lines +187 to +202
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

queryWithPage test: second stubbing overrides the first — data branch is never exercised.

Both when(...) calls on lines 190 and 191 target the exact same method signature queryForList(String, Map), so Mockito replaces the first stub with the second. Both the data query and the count query inside queryWithPage will now return [{count=1}], so result.get("data") depends on how the service interprets that single row — the assertions pass only incidentally and the test does not actually validate pagination.

Use sequential stubbing (order must match the production call order) or distinguish by SQL:

♻️ Proposed fix
-        when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockData);
-        when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(List.of(Map.of("count", 1L)));
+        when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap()))
+            .thenReturn(mockData)                       // first call: data page
+            .thenReturn(List.of(Map.of("count", 1L)));  // second call: total count

Confirm the actual call order in queryWithPage before finalizing.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
List<Map<String, Object>> mockData = new ArrayList<>();
mockData.add(Map.of("id", 1, "name", "test_name"));
when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockData);
when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(List.of(Map.of("count", 1L)));
// Act
Map<String, Object> result = dynamicModelService.queryWithPage(dto);
// Assert
assertNotNull(result);
assertTrue((Boolean) result.get("success"));
assertEquals(1L, result.get("total"));
assertEquals(1, ((List<?>) result.get("data")).size());
verify(namedParameterJdbcTemplate, times(2)).queryForList(anyString(), anyMap());
}
List<Map<String, Object>> mockData = new ArrayList<>();
mockData.add(Map.of("id", 1, "name", "test_name"));
when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap()))
.thenReturn(mockData) // first call: data page
.thenReturn(List.of(Map.of("count", 1L))); // second call: total count
// Act
Map<String, Object> result = dynamicModelService.queryWithPage(dto);
// Assert
assertNotNull(result);
assertTrue((Boolean) result.get("success"));
assertEquals(1L, result.get("total"));
assertEquals(1, ((List<?>) result.get("data")).size());
verify(namedParameterJdbcTemplate, times(2)).queryForList(anyString(), anyMap());
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java`
around lines 187 - 202, The test stubs two calls to
namedParameterJdbcTemplate.queryForList(String, Map) but the second when(...)
overwrites the first, so the data branch in DynamicModelService.queryWithPage
isn't exercised; update the test in DynamicModelServiceTest to stub the two
calls in order — use
Mockito.when(...).thenReturn(firstDataList).thenReturn(countList) or use
doReturn(firstDataList).doReturn(countList).when(namedParameterJdbcTemplate).queryForList(anyString(),
anyMap()) so the first call returns the row data
(List.of(Map.of("id",1,"name","test_name"))) and the second returns the count
(List.of(Map.of("count",1L))); alternatively, distinguish stubs by matching the
SQL string argument if you prefer, ensuring the sequence matches the actual call
order in queryWithPage.




@Test
void createData() {
// Arrange
DynamicInsert dataDto = new DynamicInsert();
dataDto.setNameEn("test_table");
dataDto.setParams(Map.of("name", "test"));

when(loginUserContext.getLoginUserId()).thenReturn("1");
when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenAnswer(invocation -> {
KeyHolder keyHolder = invocation.getArgument(1);
keyHolder.getKeyList().add(Map.of("GENERATED_KEY", 1L));
return 1;
});

// Act
Map<String, Object> result = dynamicModelService.createData(dataDto);

// Assert
assertNotNull(result);
assertEquals(1L, result.get("id"));
verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class));
}

@Test
void getDataById() {
// Arrange
String modelId = "test_table";
Long id = 1L;

List<Map<String, Object>> mockResult = new ArrayList<>();
mockResult.add(Map.of("id", 1, "name", "test_name"));

when(jdbcTemplate.queryForList(anyString(), Optional.ofNullable(any()))).thenReturn(mockResult);

// Act
Map<String, Object> result = dynamicModelService.getDataById(modelId, id);

// Assert
assertNotNull(result);
assertEquals("test_name", result.get("name"));
verify(jdbcTemplate, times(1)).queryForList(anyString(), Optional.ofNullable(any()));
}
Comment on lines +238 to +247
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -nP -C2 'jdbcTemplate\.(queryForList|update)\s*\(' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java

Repository: opentiny/tiny-engine-backend-java

Length of output: 1355


🏁 Script executed:

cat -n base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java | sed -n '230,350p'

Repository: opentiny/tiny-engine-backend-java

Length of output: 4583


🏁 Script executed:

cat -n base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java | sed -n '350,360p'

Repository: opentiny/tiny-engine-backend-java

Length of output: 341


🏁 Script executed:

rg -n 'import.*jdbcTemplate|import.*JdbcTemplate' base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java

Repository: opentiny/tiny-engine-backend-java

Length of output: 209


🏁 Script executed:

rg -n -A10 'public.*getDataById|public.*deleteDataById' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java | head -60

Repository: opentiny/tiny-engine-backend-java

Length of output: 876


🏁 Script executed:

cat -n base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java | sed -n '640,645p'

Repository: opentiny/tiny-engine-backend-java

Length of output: 370


🏁 Script executed:

rg -n 'queryForList|\.update\(' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java | grep -E '\.toArray|Object\[\]'

Repository: opentiny/tiny-engine-backend-java

Length of output: 206


🏁 Script executed:

rg -n -B2 'jdbcTemplate\.(queryForList|update)' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java

Repository: opentiny/tiny-engine-backend-java

Length of output: 1017


🏁 Script executed:

python3 << 'EOF'
# Let's trace what the actual parameter types are in the production code
production_calls = {
    "line_586": "queryForList(sql, id)",  # id is Long
    "line_642": "update(sql, id)",        # id is Long  
    "line_169": "update(sql, values.toArray())",  # Object[]
    "line_623": "update(sql.toString(), params.toArray())",  # Object[]
}

test_stubs = {
    "lines_238_246": "queryForList(anyString(), Optional.ofNullable(any()))",
    "lines_275_283": "update(anyString(), Optional.ofNullable(any()))",
    "lines_349_353": "update(anyString(), Optional.ofNullable(any()))",
}

print("Production code parameter types:")
print("- queryForList(String, Long) - matches test at lines 238, 246")
print("- update(String, Long) - matches test at lines 275, 283, 349, 353")
print("- update(String, Object[]) - different overload")
print()
print("Test stub matcher issues:")
print("- Optional.ofNullable(any()) is INVALID matcher syntax")
print("- Should be any() for single parameter (Long)")
print("- Should be any(Object[].class) for array parameter")
EOF

Repository: opentiny/tiny-engine-backend-java

Length of output: 465


Fix invalid Mockito matcher usage: replace Optional.ofNullable(any()) with appropriate matchers.

Optional.ofNullable(any()) wraps the matcher incorrectly, evaluating it outside Mockito's context. The production code calls these methods with single Long parameters, not arrays.

Correct fixes:

  • Lines 238, 246 (queryForList): Use any() instead
  • Lines 275, 283, 349, 353 (update with single parameter): Use any() instead

Example:

-        when(jdbcTemplate.queryForList(anyString(), Optional.ofNullable(any()))).thenReturn(mockResult);
+        when(jdbcTemplate.queryForList(anyString(), any())).thenReturn(mockResult);
...
-        verify(jdbcTemplate, times(1)).update(anyString(), Optional.ofNullable(any())).thenReturn(1);
+        verify(jdbcTemplate, times(1)).update(anyString(), any());

Note: The method calls at lines 169 and 623 in production use Object[] parameters, but no test mocks those overloads with this bug.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java`
around lines 238 - 247, The Mockito matcher Optional.ofNullable(any()) is used
incorrectly in DynamicModelServiceTest when stubbing jdbcTemplate.queryForList
and jdbcTemplate.update; replace those wrapped matchers with the simple any()
matcher so mocks match the production calls that pass single Long/Object
parameters (update all occurrences noted: the queryForList stubs around
dynamicModelService.getDataById and the jdbcTemplate.update stubs at the other
referenced test lines); ensure you use any() for the parameter arguments in the
when(...) and verify(...) calls targeting jdbcTemplate so Mockito matchers
operate correctly.


@Test
void updateDateById() {
// Arrange
DynamicUpdate dto = new DynamicUpdate();
dto.setNameEn("test_table");
dto.setParams(Map.of("id", 1));
dto.setData(Map.of("name", "updated_name"));

when(jdbcTemplate.update(anyString(), any(Object[].class))).thenReturn(1);

// Act
Map<String, Object> result = dynamicModelService.updateDateById(dto);

// Assert
assertNotNull(result);
assertEquals(1, result.get("rowsAffected"));
verify(jdbcTemplate, times(1)).update(anyString(), any(Object[].class));
}

@Test
void deleteDataById() {
// Arrange
DynamicDelete dto = new DynamicDelete();
dto.setNameEn("test_table");
dto.setId(1);

when(jdbcTemplate.update(anyString(), Optional.ofNullable(any()))).thenReturn(1);

// Act
Map<String, Object> result = dynamicModelService.deleteDataById(dto);

// Assert
assertNotNull(result);
assertEquals(1, result.get("rowsAffected"));
verify(jdbcTemplate, times(1)).update(anyString(), Optional.ofNullable(any()));
}


@Test
void testCreateDynamicTable() {
Model model = new Model();
model.setNameEn("test_table");
ParametersDto parametersDto = new ParametersDto();
parametersDto.setProp("name");
parametersDto.setType("String");
parametersDto.setRequired(true);
parametersDto.setDefaultValue("1");
parametersDto.setDescription("1");
model.setParameters(Collections.singletonList(parametersDto));

doNothing().when(jdbcTemplate).execute(anyString());

assertDoesNotThrow(() -> dynamicModelService.createDynamicTable(model));
verify(jdbcTemplate, times(1)).execute(anyString());
}

@Test
void testDropDynamicTable() {
Model model = new Model();
model.setNameEn("test_table");

doNothing().when(jdbcTemplate).execute(anyString());

assertDoesNotThrow(() -> dynamicModelService.dropDynamicTable(model));
verify(jdbcTemplate, times(1)).execute(anyString());
}

@Test
void testDynamicQuery() {
String tableName = "test_table";
List<String> fields = Arrays.asList("id", "name");
Map<String, Object> conditions = Map.of("id", 1);

when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(new ArrayList<>());

List<Map<String, Object>> result = dynamicModelService.dynamicQuery(tableName, fields, conditions, null, null);
assertNotNull(result);
verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap());
}

@Test
void testCreateData() {
DynamicInsert dataDto = new DynamicInsert();
dataDto.setNameEn("test_table");
dataDto.setParams(Map.of("name", "test"));

when(loginUserContext.getLoginUserId()).thenReturn("1");
when(jdbcTemplate.update(any(), any(PreparedStatementCreator.class), any())).thenReturn(1);

Map<String, Object> result = dynamicModelService.createData(dataDto);
assertNotNull(result);
verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any());
}
Comment on lines +329 to +341
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

testCreateData stubs a non-matching overload and will not verify what it claims.

Line 336 stubs jdbcTemplate.update(any(), any(PreparedStatementCreator.class), any()) with three arguments, but JdbcTemplate has no 3-arg update overload that accepts PreparedStatementCreator in the middle position. Either this fails to compile/resolves to an unintended varargs overload, or simply never matches the call performed in createData (which uses update(PreparedStatementCreator, KeyHolder), as correctly verified on line 340). The assertNotNull(result) assertion is therefore meaningless.

This whole test* block (lines 287–354) also largely duplicates the earlier createDynamicTable / dropDynamicTable / dynamicQuery / createData / deleteDataById tests — consider removing the duplicates and keeping a single, correct version per scenario.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java`
around lines 329 - 341, The testCreateData test stubs the wrong JdbcTemplate
overload (a non-existent three-arg variant) so the stub never matches the actual
call; update the stub to match the real call used by
dynamicModelService.createData by stubbing
jdbcTemplate.update(PreparedStatementCreator, KeyHolder) (e.g.
when(jdbcTemplate.update(any(PreparedStatementCreator.class),
any(KeyHolder.class))).thenReturn(1)) and adjust the verify to match that
signature (verify(jdbcTemplate).update(any(PreparedStatementCreator.class),
any(KeyHolder.class))); also ensure loginUserContext.getLoginUserId() remains
stubbed and assert the real returned Map contents (or remove the duplicate test
altogether and keep a single correct test for createData) so
assertNotNull(result) is meaningful.


@Test
void testDeleteDataById() {
DynamicDelete dto = new DynamicDelete();
dto.setNameEn("test_table");
dto.setId(1);

when(jdbcTemplate.update(anyString(), Optional.ofNullable(any()))).thenReturn(1);

Map<String, Object> result = dynamicModelService.deleteDataById(dto);
assertEquals(1, result.get("rowsAffected"));
verify(jdbcTemplate, times(1)).update(anyString(), Optional.ofNullable(any()));
}


}
Loading