diff --git a/bonita-integration-tests/bonita-query-tests/build.gradle b/bonita-integration-tests/bonita-query-tests/build.gradle index b269a54a20b..a9df57f842b 100644 --- a/bonita-integration-tests/bonita-query-tests/build.gradle +++ b/bonita-integration-tests/bonita-query-tests/build.gradle @@ -1,6 +1,8 @@ - +plugins { id 'bonita-docker-database' } dependencies { + testAnnotationProcessor(libs.lombok) + testImplementation(libs.lombok) testImplementation "junit:junit:${Deps.junit4Version}" testImplementation "org.assertj:assertj-core:${Deps.assertjVersion}" testImplementation libs.h2 @@ -13,4 +15,7 @@ dependencies { testImplementation project(":bpm:bonita-server") testImplementation project(":bpm:bonita-common") + testRuntimeOnly libs.tomcatDbcp } + +databaseIntegrationTest { include "**/*Test.class" } \ No newline at end of file diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/contract/data/ContractDataTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/contract/data/ContractDataTest.java index 9d84efa3760..382e1f17c42 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/contract/data/ContractDataTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/contract/data/ContractDataTest.java @@ -21,6 +21,7 @@ import javax.inject.Inject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.ContractDataRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -52,20 +53,20 @@ public void should_be_able_to_add_contract_data() { repository.flush(); List> contractData = jdbcTemplate - .queryForList("SELECT kind, name, scopeId, val from contract_data"); + .query("SELECT KIND, NAME, SCOPEID, VAL from contract_data", new JdbcRowMapper("SCOPEID")); assertThat(contractData).hasSize(2); assertThat(contractData).anySatisfy(c -> { - assertThat(c.get("kind")).isEqualTo("PROCESS"); - assertThat(c.get("name")).isEqualTo("myProcessContractData"); - assertThat(c.get("scopeId")).isEqualTo(123L); - assertThat(c.get("val")).isEqualTo("SerializedValue"); + assertThat(c.get("KIND")).isEqualTo("PROCESS"); + assertThat(c.get("NAME")).isEqualTo("myProcessContractData"); + assertThat(c.get("SCOPEID")).isEqualTo(123L); + assertThat(c.get("VAL")).isEqualTo("SerializedValue"); }); assertThat(contractData).anySatisfy(c -> { - assertThat(c.get("kind")).isEqualTo("TASK"); - assertThat(c.get("name")).isEqualTo("myTaskContractData"); - assertThat(c.get("scopeId")).isEqualTo(124L); - assertThat(c.get("val")).isEqualTo("SerializedValue"); + assertThat(c.get("KIND")).isEqualTo("TASK"); + assertThat(c.get("NAME")).isEqualTo("myTaskContractData"); + assertThat(c.get("SCOPEID")).isEqualTo(124L); + assertThat(c.get("VAL")).isEqualTo("SerializedValue"); }); } diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/form/FormMappingTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/form/FormMappingTest.java index 25a47b5e932..f7bdc606a48 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/form/FormMappingTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/form/FormMappingTest.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import org.bonitasoft.engine.page.SPageMapping; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.TestRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -52,24 +53,26 @@ public void should_be_able_to_add_form_mapping() { testRepository.flush(); - List> formMapping = jdbcTemplate.queryForList("SELECT * from form_mapping"); + List> formMapping = jdbcTemplate.query("SELECT * from form_mapping", + new JdbcRowMapper("PAGE_MAPPING_ID", "LASTUPDATEDATE", "LASTUPDATEDBY", "PROCESS")); + assertThat(formMapping).hasSize(2); assertThat(formMapping).anySatisfy(c -> { - assertThat(c.get("task")).isEqualTo("task1"); - assertThat(c.get("type")).isEqualTo(3); - assertThat(c.get("page_mapping_id")).isEqualTo(1L); - assertThat(c.get("lastupdatedate")).isEqualTo(200L); - assertThat(c.get("lastupdatedby")).isEqualTo(100L); - assertThat(c.get("process")).isEqualTo(2L); - assertThat(c.get("target")).isEqualTo("target1"); + assertThat(c.get("TASK")).isEqualTo("task1"); + assertThat(c.get("TYPE")).isEqualTo(3); + assertThat(c.get("PAGE_MAPPING_ID")).isEqualTo(1L); + assertThat(c.get("LASTUPDATEDATE")).isEqualTo(200L); + assertThat(c.get("LASTUPDATEDBY")).isEqualTo(100L); + assertThat(c.get("PROCESS")).isEqualTo(2L); + assertThat(c.get("TARGET")).isEqualTo("target1"); }); assertThat(formMapping).anySatisfy(c -> { - assertThat(c.get("task")).isEqualTo("task2"); - assertThat(c.get("page_mapping_id")).isEqualTo(1L); - assertThat(c.get("type")).isEqualTo(4); - assertThat(c.get("process")).isEqualTo(3L); - assertThat(c.get("target")).isEqualTo("target2"); + assertThat(c.get("TASK")).isEqualTo("task2"); + assertThat(c.get("PAGE_MAPPING_ID")).isEqualTo(1L); + assertThat(c.get("TYPE")).isEqualTo(4); + assertThat(c.get("PROCESS")).isEqualTo(3L); + assertThat(c.get("TARGET")).isEqualTo("target2"); }); } diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveFlowNodeInstanceTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveFlowNodeInstanceTest.java index ddbcd2479dd..32220963b0e 100755 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveFlowNodeInstanceTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveFlowNodeInstanceTest.java @@ -79,7 +79,7 @@ public void should_save_and_get_SAUserTaskInstance_with_task_priority() { .queryForMap("SELECT * FROM arch_flownode_instance where id = " + flowNode.getId()); assertThat(flowNodeFromQuery).isEqualTo(flowNode); - assertThat(flowNodeAsMap.get("PRIORITY")).isEqualTo(3); + assertThat(((Number) flowNodeAsMap.get("PRIORITY")).intValue()).isEqualTo(3); } @Test diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveProcessInstanceQueriesTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveProcessInstanceQueriesTest.java index f19619e545f..447f5256c73 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveProcessInstanceQueriesTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ArchiveProcessInstanceQueriesTest.java @@ -31,6 +31,7 @@ import org.bonitasoft.engine.core.process.instance.model.archive.business.data.SAProcessMultiRefBusinessDataInstance; import org.bonitasoft.engine.core.process.instance.model.archive.business.data.SAProcessSimpleRefBusinessDataInstance; import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.ProcessInstanceRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -84,7 +85,7 @@ public void getArchivedProcessInstancesInAllStates_should_return_empty_list_when } @Test - public void should_save_and_get_multi_business_data_reference_for_process() { + public void should_save_and_get_multi_business_data_reference_for_archived_process() { SAProcessMultiRefBusinessDataInstance multiRefBusinessDataInstance = new SAProcessMultiRefBusinessDataInstance(); multiRefBusinessDataInstance.setDataIds(Arrays.asList(23L, 25L, 27L)); multiRefBusinessDataInstance.setProcessInstanceId(PROCESS_INSTANCE_ID); @@ -96,12 +97,14 @@ public void should_save_and_get_multi_business_data_reference_for_process() { PersistentObject multiRefBusinessData = repository.selectOne("getSARefBusinessDataInstance", pair("processInstanceId", PROCESS_INSTANCE_ID), pair("name", "myMultiProcData")); Map multiRefBusinessDataAsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, KIND, NAME, DATA_CLASSNAME, DATA_ID, ORIG_PROC_INST_ID, ORIG_FN_INST_ID FROM arch_ref_biz_data_inst WHERE orig_proc_inst_id=" - + PROCESS_INSTANCE_ID + " AND name='myMultiProcData'"); + + PROCESS_INSTANCE_ID + " AND name='myMultiProcData'", + new JdbcRowMapper("ID", "DATA_ID", "ORIG_PROC_INST_ID", "ORIG_FN_INST_ID")); List> dataIds = jdbcTemplate - .queryForList("SELECT ID, IDX, DATA_ID FROM arch_multi_biz_data WHERE id=" - + multiRefBusinessDataInstance.getId()); + .query("SELECT ID, IDX, DATA_ID FROM arch_multi_biz_data WHERE id=" + + multiRefBusinessDataInstance.getId(), + new JdbcRowMapper("ID", "IDX", "DATA_ID")); assertThat(((SAProcessMultiRefBusinessDataInstance) multiRefBusinessData).getDataIds()) .isEqualTo(Arrays.asList(23L, 25L, 27L)); @@ -115,13 +118,13 @@ public void should_save_and_get_multi_business_data_reference_for_process() { entry("ORIG_PROC_INST_ID", PROCESS_INSTANCE_ID), entry("ORIG_FN_INST_ID", null)); assertThat(dataIds).containsExactly( - mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 0), pair("DATA_ID", 23L)), - mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 1), pair("DATA_ID", 25L)), - mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 2), pair("DATA_ID", 27L))); + mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 0L), pair("DATA_ID", 23L)), + mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 1L), pair("DATA_ID", 25L)), + mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 2L), pair("DATA_ID", 27L))); } @Test - public void should_save_and_get_single_business_data_reference_for_process() { + public void should_save_and_get_single_business_data_reference_for_archived_process() { SAProcessSimpleRefBusinessDataInstance singleRef = new SAProcessSimpleRefBusinessDataInstance(); singleRef.setDataId(43L); singleRef.setProcessInstanceId(PROCESS_INSTANCE_ID); @@ -133,10 +136,11 @@ public void should_save_and_get_single_business_data_reference_for_process() { PersistentObject singleRefFromQuery = repository.selectOne("getSARefBusinessDataInstance", pair("processInstanceId", PROCESS_INSTANCE_ID), pair("name", "mySingleData")); Map multiRefBusinessDataAsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, KIND, NAME, DATA_CLASSNAME, DATA_ID, ORIG_PROC_INST_ID, ORIG_FN_INST_ID FROM arch_ref_biz_data_inst WHERE orig_proc_inst_id=" + PROCESS_INSTANCE_ID - + " AND name='mySingleData'"); + + " AND name='mySingleData'", + new JdbcRowMapper("ID", "DATA_ID", "ORIG_PROC_INST_ID", "ORIG_FN_INST_ID")); assertThat(singleRefFromQuery).isEqualTo(singleRef); assertThat(multiRefBusinessDataAsMap).containsOnly( entry("ID", singleRef.getId()), @@ -149,7 +153,7 @@ public void should_save_and_get_single_business_data_reference_for_process() { } @Test - public void should_save_and_get_single_business_data_reference_for_flow_node() { + public void should_save_and_get_single_business_data_reference_for_flow_node_of_archived_process() { SAFlowNodeSimpleRefBusinessDataInstance singleRef = new SAFlowNodeSimpleRefBusinessDataInstance(); singleRef.setDataId(43L); singleRef.setFlowNodeInstanceId(FLOW_NODE_INSTANCE_ID); @@ -161,10 +165,11 @@ public void should_save_and_get_single_business_data_reference_for_flow_node() { PersistentObject singleRefFromQuery = repository.selectOne("getSAFlowNodeRefBusinessDataInstance", pair("flowNodeInstanceId", FLOW_NODE_INSTANCE_ID), pair("name", "mySingleData")); Map multiRefBusinessDataAsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, KIND, NAME, DATA_CLASSNAME, DATA_ID, ORIG_PROC_INST_ID, ORIG_FN_INST_ID FROM arch_ref_biz_data_inst WHERE orig_fn_inst_id=" + FLOW_NODE_INSTANCE_ID - + " AND name='mySingleData'"); + + " AND name='mySingleData'", + new JdbcRowMapper("ID", "DATA_ID", "ORIG_PROC_INST_ID", "ORIG_FN_INST_ID")); assertThat(singleRefFromQuery).isEqualTo(singleRef); assertThat(multiRefBusinessDataAsMap).containsOnly( entry("ID", singleRef.getId()), diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/CommentsTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/CommentsTest.java index 4ab35a082f6..d56b281b39d 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/CommentsTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/CommentsTest.java @@ -26,6 +26,7 @@ import org.bonitasoft.engine.core.process.comment.model.SSystemComment; import org.bonitasoft.engine.core.process.comment.model.archive.SAComment; import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.CommentRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -62,7 +63,7 @@ public void should_getComments_of_process_instance() { repository.add(new SHumanComment(PROCESS2_ID, "comment5", JACK_ID)); assertThat(repository.getCommentsOfProcessInstance(PROCESS1_ID)).extracting("content", "userId", "class") - .containsExactly( + .containsExactlyInAnyOrder( tuple("comment1", JACK_ID, SHumanComment.class), tuple("comment2", JOHN_ID, SHumanComment.class), tuple("comment3", JACK_ID, SHumanComment.class), @@ -77,13 +78,15 @@ public void should_save_and_get_SComment() { repository.flush(); Map comment1AsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, KIND, CONTENT, POSTDATE, PROCESSINSTANCEID, USERID FROM process_comment WHERE processInstanceId = " - + PROCESS1_ID); + + PROCESS1_ID, + new JdbcRowMapper("ID", "POSTDATE", "PROCESSINSTANCEID", "USERID")); Map comment2AsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, KIND, CONTENT, POSTDATE, PROCESSINSTANCEID, USERID FROM process_comment WHERE processInstanceId = " - + PROCESS2_ID); + + PROCESS2_ID, + new JdbcRowMapper("ID", "POSTDATE", "PROCESSINSTANCEID", "USERID")); assertThat(comment1AsMap).containsOnly( entry("ID", comment1.getId()), @@ -112,13 +115,17 @@ public void should_save_and_get_SAComment() { PersistentObject comment2FromQuery = repository.selectOne("getArchivedCommentById", pair("id", comment2.getId())); Map comment1AsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, SOURCEOBJECTID, ARCHIVEDATE, CONTENT, POSTDATE, PROCESSINSTANCEID, USERID FROM arch_process_comment WHERE processInstanceId = " - + PROCESS1_ID); + + PROCESS1_ID, + new JdbcRowMapper("ID", "SOURCEOBJECTID", "ARCHIVEDATE", "POSTDATE", "PROCESSINSTANCEID", + "USERID")); Map comment2AsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, SOURCEOBJECTID, ARCHIVEDATE, CONTENT, POSTDATE, PROCESSINSTANCEID, USERID FROM arch_process_comment WHERE processInstanceId = " - + PROCESS2_ID); + + PROCESS2_ID, + new JdbcRowMapper("ID", "SOURCEOBJECTID", "ARCHIVEDATE", "POSTDATE", "PROCESSINSTANCEID", + "USERID")); assertThat(comment1FromQuery).isEqualTo(comment1); assertThat(comment2FromQuery).isEqualTo(comment2); diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ConnectorInstanceQueriesTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ConnectorInstanceQueriesTest.java index 9b4598bcb65..c6b0c98ead4 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ConnectorInstanceQueriesTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ConnectorInstanceQueriesTest.java @@ -72,13 +72,12 @@ public void setUp() { containerType = "Pouet"; containerId = 1L; long differentContainerId = 5L; - long tenantId = 100L; expectedConnector1 = aConnectorInstance().setContainerId(containerId).setContainerType(containerType) .setActivationEvent(ON_FINISH) .withFailureInfo(false).setState(ConnectorState.EXECUTING.toString()).build(); expectedConnector2 = aConnectorInstance().setContainerId(containerId).setContainerType(containerType) .setActivationEvent(ON_ENTER) - .setState(ConnectorState.EXECUTING.toString()).withFailureInfo(false) + .setState(ConnectorState.EXECUTING.toString()).withFailureInfo(false).setExecutionOrder(1) .build(); expectedConnector3 = aConnectorInstance().setContainerId(containerId).setContainerType(containerType) .setActivationEvent(ON_ENTER) @@ -86,7 +85,7 @@ public void setUp() { .build(); expectedConnector4 = aConnectorInstance().setContainerId(containerId).setContainerType(containerType) .setActivationEvent(ON_ENTER) - .setState(ConnectorState.TO_BE_EXECUTED.toString()).withFailureInfo(false) + .setState(ConnectorState.TO_BE_EXECUTED.toString()).withFailureInfo(false).setExecutionOrder(2) .build(); expectedConnector5 = aConnectorInstance().setContainerId(containerId).setContainerType(containerType) .setActivationEvent(ON_ENTER) @@ -143,10 +142,10 @@ public void getNumberOfConnectorInstances() { @Test public void getNextExecutableConnectorInstance() { - SConnectorInstance connectors = repository + SConnectorInstance connector = repository .getNextExecutableConnectorInstance(containerId, containerType, ON_ENTER); - assertThat(connectors).isSameAs(expectedConnector2); + assertThat(connector).isSameAs(expectedConnector2); } @Test diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessDeploymentInfoQueriesTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessDeploymentInfoQueriesTest.java index 1d65f22f299..0dd7f220d61 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessDeploymentInfoQueriesTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessDeploymentInfoQueriesTest.java @@ -33,6 +33,7 @@ import org.bonitasoft.engine.core.process.definition.model.SProcessDefinitionDesignContent; import org.bonitasoft.engine.persistence.PersistentObject; import org.bonitasoft.engine.supervisor.mapping.model.SProcessSupervisor; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.ProcessDeploymentInfoRepository; import org.junit.Before; import org.junit.Test; @@ -884,12 +885,15 @@ public void should_reference_design_content_using_id() { .designContent(content).build()); repository.flush(); - Map processDefinitionMap = jdbcTemplate.queryForMap( - "SELECT name, CONTENT_ID FROM process_definition WHERE processId=123456"); - Map processContentMap = jdbcTemplate.queryForMap("SELECT ID FROM process_content "); + Map processDefinitionMap = jdbcTemplate.queryForObject( + "SELECT name, CONTENT_ID FROM process_definition WHERE processId=123456", + new JdbcRowMapper("CONTENT_ID")); + Map processContentMap = jdbcTemplate.queryForObject("SELECT ID FROM process_content", + new JdbcRowMapper("ID")); - assertThat(processDefinitionMap.get("name")).isEqualTo("MyProcessWithContent"); + assertThat(processDefinitionMap.get("NAME")).isEqualTo("MyProcessWithContent"); assertThat(processDefinitionMap.get("CONTENT_ID")).isEqualTo(content.getId()); assertThat(processContentMap.get("ID")).isEqualTo(content.getId()); } + } diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessInstanceQueriesTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessInstanceQueriesTest.java index 5b73817d1c0..9c57ff31571 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessInstanceQueriesTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/ProcessInstanceQueriesTest.java @@ -46,6 +46,7 @@ import org.bonitasoft.engine.core.process.instance.model.business.data.SProcessSimpleRefBusinessDataInstance; import org.bonitasoft.engine.identity.model.SUser; import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.ProcessInstanceRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -876,10 +877,14 @@ public void should_save_and_get_multi_business_data_reference_for_process() { PersistentObject multiRefBusinessData = repository.selectOne("getSRefBusinessDataInstance", pair("processInstanceId", PROCESS_INSTANCE_ID), pair("name", "myMultiProcData")); Map multiRefBusinessDataAsMap = jdbcTemplate - .queryForMap("SELECT * FROM ref_biz_data_inst WHERE proc_inst_id=" + PROCESS_INSTANCE_ID - + " AND name='myMultiProcData'"); - List> dataIds = jdbcTemplate.queryForList( - "SELECT ID, IDX, DATA_ID FROM multi_biz_data WHERE id=" + multiRefBusinessDataInstance.getId()); + .queryForObject( + "SELECT TENANTID, ID, KIND, NAME, DATA_CLASSNAME, DATA_ID, PROC_INST_ID, FN_INST_ID FROM ref_biz_data_inst WHERE proc_inst_id=" + + PROCESS_INSTANCE_ID + + " AND name='myMultiProcData'", + new JdbcRowMapper("TENANTID", "ID", "DATA_ID", "PROC_INST_ID", "FN_INST_ID")); + List> dataIds = jdbcTemplate.query( + "SELECT ID, IDX, DATA_ID FROM multi_biz_data WHERE id=" + multiRefBusinessDataInstance.getId(), + new JdbcRowMapper("ID", "IDX", "DATA_ID")); assertThat(((SProcessMultiRefBusinessDataInstance) multiRefBusinessData).getDataIds()) .isEqualTo(Arrays.asList(23L, 25L, 27L)); @@ -894,9 +899,9 @@ public void should_save_and_get_multi_business_data_reference_for_process() { entry("PROC_INST_ID", PROCESS_INSTANCE_ID), entry("FN_INST_ID", null)); assertThat(dataIds).containsExactly( - mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 0), pair("DATA_ID", 23L)), - mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 1), pair("DATA_ID", 25L)), - mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 2), pair("DATA_ID", 27L))); + mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 0L), pair("DATA_ID", 23L)), + mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 1L), pair("DATA_ID", 25L)), + mapOf(pair("ID", multiRefBusinessDataInstance.getId()), pair("IDX", 2L), pair("DATA_ID", 27L))); } @Test @@ -912,9 +917,10 @@ public void should_save_and_get_single_business_data_reference_for_process() { PersistentObject singleRefFromQuery = repository.selectOne("getSRefBusinessDataInstance", pair("processInstanceId", PROCESS_INSTANCE_ID), pair("name", "mySingleData")); Map multiRefBusinessDataAsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, KIND, NAME, DATA_CLASSNAME, DATA_ID, PROC_INST_ID, FN_INST_ID FROM ref_biz_data_inst WHERE proc_inst_id=" - + PROCESS_INSTANCE_ID + " AND name='mySingleData'"); + + PROCESS_INSTANCE_ID + " AND name='mySingleData'", + new JdbcRowMapper("ID", "DATA_ID", "PROC_INST_ID", "FN_INST_ID")); assertThat(singleRefFromQuery).isEqualTo(singleRef); assertThat(multiRefBusinessDataAsMap).containsOnly( entry("ID", singleRef.getId()), @@ -940,10 +946,11 @@ public void should_save_and_get_single_business_data_reference_for_flow_node() { PersistentObject singleRefFromQuery = repository.selectOne("getSFlowNodeRefBusinessDataInstance", pair("flowNodeInstanceId", FLOW_NODE_INSTANCE_ID), pair("name", "mySingleData")); Map multiRefBusinessDataAsMap = jdbcTemplate - .queryForMap( + .queryForObject( "SELECT ID, KIND, NAME, DATA_CLASSNAME, DATA_ID, PROC_INST_ID, FN_INST_ID FROM ref_biz_data_inst WHERE fn_inst_id=" + FLOW_NODE_INSTANCE_ID - + " AND name='mySingleData'"); + + " AND name='mySingleData'", + new JdbcRowMapper("ID", "DATA_ID", "PROC_INST_ID", "FN_INST_ID")); assertThat(singleRefFromQuery).isEqualTo(singleRef); assertThat(multiRefBusinessDataAsMap).containsOnly( entry("ID", singleRef.getId()), diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/SADataInstanceQueriesTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/SADataInstanceQueriesTest.java index 511c7d2541b..00c02ebdb59 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/SADataInstanceQueriesTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/SADataInstanceQueriesTest.java @@ -47,6 +47,7 @@ import org.bonitasoft.engine.data.instance.model.archive.SAShortTextDataInstance; import org.bonitasoft.engine.data.instance.model.archive.SAXMLObjectDataInstance; import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.SADataInstanceRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -96,11 +97,17 @@ private void addSADataInstance(final int id, final String name, final int contai } protected Map getDataUsingJDBC(SDataInstance dataInstance) { - return jdbcTemplate.queryForMap("SELECT * FROM data_instance where id = " + dataInstance.getId()); + return jdbcTemplate.queryForObject("SELECT * FROM data_instance where id = " + dataInstance.getId(), + new JdbcRowMapper(List.of("LONGVALUE"), + List.of("BOOLEANVALUE"), + List.of("DOUBLEVALUE"))); } protected Map getDataUsingJDBC(SADataInstance dataInstance) { - return jdbcTemplate.queryForMap("SELECT * FROM arch_data_instance where id = " + dataInstance.getId()); + return jdbcTemplate.queryForObject("SELECT * FROM arch_data_instance where id = " + dataInstance.getId(), + new JdbcRowMapper(List.of("LONGVALUE"), + List.of("BOOLEANVALUE"), + List.of("DOUBLEVALUE"))); } protected PersistentObject getDataInstance(String dataName) { @@ -186,7 +193,7 @@ public void should_save_and_get_SDoubleDataInstance() { assertThat(persistentObject).isEqualTo(dataInstance); assertThat(persistentObject).isInstanceOf(SDoubleDataInstance.class); - assertThat(dataAsMap).containsEntry("DOUBLEVALUE", 1234567890.0); + assertThat(dataAsMap).containsEntry("DOUBLEVALUE", 1234567890.0d); assertThat(dataAsMap).containsEntry("DISCRIMINANT", "SDoubleDataInstanceImpl"); } @@ -233,7 +240,7 @@ public void should_save_and_get_SDateDataInstance() { assertThat(persistentObject).isEqualTo(dataInstance); assertThat(persistentObject).isInstanceOf(SDateDataInstance.class); - assertThat(dataAsMap).containsEntry("LongValue", date.getTime()); + assertThat(dataAsMap).containsEntry("LONGVALUE", date.getTime()); assertThat(dataAsMap).containsEntry("DISCRIMINANT", "SDateDataInstanceImpl"); } @@ -264,7 +271,7 @@ public void should_save_and_get_SFloatDataInstance() { assertThat(persistentObject).isEqualTo(dataInstance); assertThat(persistentObject).isInstanceOf(SFloatDataInstance.class); - assertThat(dataAsMap.get("FLOATVALUE")).isEqualTo(1.0); + assertThat(((Number) dataAsMap.get("FLOATVALUE")).floatValue()).isEqualTo(1.0f); assertThat(dataAsMap).containsEntry("DISCRIMINANT", "SFloatDataInstanceImpl"); } @@ -324,7 +331,7 @@ public void should_save_and_get_SADoubleDataInstance() { assertThat(persistentObject).isEqualTo(dataInstance); assertThat(persistentObject).isInstanceOf(SADoubleDataInstance.class); - assertThat(dataAsMap).containsEntry("DOUBLEVALUE", 1234567890.0); + assertThat(dataAsMap).containsEntry("DOUBLEVALUE", 1234567890.0d); assertThat(dataAsMap).containsEntry("DISCRIMINANT", "SADoubleDataInstanceImpl"); } @@ -371,7 +378,7 @@ public void should_save_and_get_SADateDataInstance() { assertThat(persistentObject).isEqualTo(dataInstance); assertThat(persistentObject).isInstanceOf(SADateDataInstance.class); - assertThat(dataAsMap).containsEntry("LongValue", date.getTime()); + assertThat(dataAsMap).containsEntry("LONGVALUE", date.getTime()); assertThat(dataAsMap).containsEntry("DISCRIMINANT", "SADateDataInstanceImpl"); } @@ -401,7 +408,7 @@ public void should_save_and_get_SAFloatDataInstance() { assertThat(persistentObject).isEqualTo(dataInstance); assertThat(persistentObject).isInstanceOf(SAFloatDataInstance.class); - assertThat(dataAsMap.get("FLOATVALUE")).isEqualTo(1.0); + assertThat(((Number) dataAsMap.get("FLOATVALUE")).floatValue()).isEqualTo(1.0f); assertThat(dataAsMap).containsEntry("DISCRIMINANT", "SAFloatDataInstanceImpl"); } diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/parameter/ParameterTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/parameter/ParameterTest.java index 77e25be07b2..25be3060a91 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/parameter/ParameterTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/parameter/ParameterTest.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.TestRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,7 +49,8 @@ public void should_save_and_get_parameter() { pair("name", "parameterName"), pair("processDefinitionId", 12345L)); testRepository.flush(); Map parameterAsMap = jdbcTemplate - .queryForMap("SELECT * FROM proc_parameter WHERE name = 'parameterName'"); + .queryForObject("SELECT * FROM proc_parameter WHERE name = 'parameterName'", + new JdbcRowMapper("TENANTID", "ID", "PROCESS_ID")); assertThat(parameterFromQuery).isEqualTo(sParameter); assertThat(parameterAsMap).containsOnly( diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/command/model/PlatformCommandTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/command/model/PlatformCommandTest.java index 5dab96470ca..b32a156c148 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/command/model/PlatformCommandTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/command/model/PlatformCommandTest.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.PlatformRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,7 +52,8 @@ public void should_save_and_get_SPlatformCommand() { PersistentObject platformCommandFromQuery = repository.selectOneOnPlatform("getPlatformCommandByName", pair("name", "myPlatformCommand")); - Map platformCommandAsMap = jdbcTemplate.queryForMap("SELECT * FROM platformCommand"); + Map platformCommandAsMap = jdbcTemplate.queryForObject("SELECT * FROM platformCommand", + new JdbcRowMapper("ID")); assertThat(platformCommandFromQuery).isEqualTo(platformCommand); assertThat(platformCommandAsMap).containsOnly( diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/model/impl/PlatformTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/model/impl/PlatformTest.java index 08f2e754053..d131be61982 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/model/impl/PlatformTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/platform/model/impl/PlatformTest.java @@ -16,12 +16,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import java.util.List; import java.util.Map; import javax.inject.Inject; import org.bonitasoft.engine.persistence.PersistentObject; import org.bonitasoft.engine.platform.model.SPlatform; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.PlatformRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,7 +55,8 @@ public void should_save_and_get_SPlatform() { repository.flush(); PersistentObject platformFromQuery = repository.selectOneOnPlatform("getPlatform"); - Map platformAsMap = jdbcTemplate.queryForMap("SELECT * FROM platform"); + Map platformAsMap = jdbcTemplate.queryForObject("SELECT * FROM platform", + new JdbcRowMapper(List.of("ID", "CREATED"), List.of("MAINTENANCE_MESSAGE_ACTIVE"))); assertThat(platformFromQuery).isEqualTo(platform); assertThat(platformAsMap).containsOnly( diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogParameterTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogParameterTest.java index 3ee8b4ebc5f..d28073423d9 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogParameterTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogParameterTest.java @@ -21,6 +21,7 @@ import javax.inject.Inject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.TestRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -65,7 +66,8 @@ public void should_be_able_to_add_querriable_log() { testRepository.flush(); - List> queriableLogs = jdbcTemplate.queryForList("SELECT * from queriableLog_p"); + List> queriableLogs = jdbcTemplate.query("SELECT * from queriableLog_p", + new JdbcRowMapper("ID", "TENANTID", "B_LOG_ID")); assertThat(queriableLogs).hasSize(2); assertThat(queriableLogs.stream().filter(m -> m.get("ID").equals(1L)).findFirst().get()).containsOnly( diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogTest.java index 489861cf4c9..0fbe9e6565c 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/queriablelogger/model/QueriableLogTest.java @@ -21,6 +21,7 @@ import javax.inject.Inject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.TestRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,7 +41,7 @@ public class QueriableLogTest { private JdbcTemplate jdbcTemplate; @Test - public void should_be_able_to_add_querriable_log() { + public void should_be_able_to_add_queriable_log() { SQueriableLog queriableLog = SQueriableLog.builder() .initializeNow()// @@ -75,7 +76,9 @@ public void should_be_able_to_add_querriable_log() { testRepository.flush(); - List> queriableLogs = jdbcTemplate.queryForList("SELECT * from queriable_log"); + List> queriableLogs = jdbcTemplate.query("SELECT * from queriable_log", + new JdbcRowMapper("ID", "TENANTID", "NUMERICINDEX1", "NUMERICINDEX2", "NUMERICINDEX3", + "NUMERICINDEX4", "NUMERICINDEX5", "THREADNUMBER", "LOG_TIMESTAMP")); assertThat(queriableLogs).hasSize(2); assertThat(queriableLogs.stream().filter(m -> m.get("ID").equals(1L)).findFirst().get()).containsOnly( diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/resources/DependencyServiceQueriesTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/resources/DependencyServiceQueriesTest.java index c75133b6502..3b3ca6286d1 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/resources/DependencyServiceQueriesTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/resources/DependencyServiceQueriesTest.java @@ -25,8 +25,13 @@ import javax.inject.Inject; -import org.bonitasoft.engine.dependency.model.*; +import org.bonitasoft.engine.dependency.model.DependencyContent; +import org.bonitasoft.engine.dependency.model.SDependency; +import org.bonitasoft.engine.dependency.model.SDependencyMapping; +import org.bonitasoft.engine.dependency.model.SPlatformDependency; +import org.bonitasoft.engine.dependency.model.SPlatformDependencyMapping; import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.DependencyRepository; import org.bonitasoft.engine.test.persistence.repository.PlatformRepository; import org.junit.Test; @@ -135,7 +140,8 @@ public void should_save_and_get_dependency() { PersistentObject dependencyFromQuery = repository.selectOne("getDependencyByName", pair("name", "dependencyName")); - Map dependencyAsMap = jdbcTemplate.queryForMap("SELECT * FROM dependency"); + Map dependencyAsMap = jdbcTemplate.queryForObject("SELECT * FROM dependency", + new JdbcRowMapper("TENANTID", "ID")); assertThat(dependencyFromQuery).isEqualTo(aDependency); assertThat(dependencyAsMap).containsOnly( @@ -162,7 +168,8 @@ public void should_save_and_get_dependency_mapping() { PersistentObject dependencyMappingFromQuery = repository.selectOne("getDependencyMappingsByDependency", pair("dependencyId", aDependency.getId())); Map dependencyMappingAsMap = jdbcTemplate - .queryForMap("SELECT * FROM dependencymapping WHERE dependencyId=" + aDependency.getId()); + .queryForObject("SELECT * FROM dependencymapping WHERE dependencyId=" + aDependency.getId(), + new JdbcRowMapper("TENANTID", "ID", "ARTIFACTID", "DEPENDENCYID")); assertThat(dependencyMappingFromQuery).isEqualTo(dependencyMapping); assertThat(dependencyMappingAsMap).containsOnly( @@ -183,9 +190,11 @@ public void should_save_and_get_platform_dependency() { PersistentObject dependencyFromQuery = platformRepository.selectOneOnPlatform("getPlatformDependencyByName", pair("name", "dependencyName")); - Map dependencyAsMap = jdbcTemplate.queryForMap("SELECT * FROM pdependency"); + Map dependencyAsMap = jdbcTemplate.queryForObject("SELECT * FROM pdependency", + new JdbcRowMapper("ID")); assertThat(dependencyFromQuery).isEqualTo(aDependency); + assertThat(dependencyAsMap).containsOnly( entry("ID", aDependency.getId()), entry("NAME", "dependencyName"), @@ -209,7 +218,8 @@ public void should_save_and_get_platform_dependency_mapping() { PersistentObject dependencyMappingFromQuery = platformRepository.selectOneOnPlatform( "getPlatformDependencyMappingsByDependency", pair("dependencyId", aDependency.getId())); Map dependencyMappingAsMap = jdbcTemplate - .queryForMap("SELECT * FROM pdependencymapping WHERE dependencyId=" + aDependency.getId()); + .queryForObject("SELECT * FROM pdependencymapping WHERE dependencyId=" + aDependency.getId(), + new JdbcRowMapper("ID", "ARTIFACTID", "DEPENDENCYID")); assertThat(dependencyMappingFromQuery).isEqualTo(dependencyMapping); assertThat(dependencyMappingAsMap).containsOnly( diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/scheduler/SchedulerQueryTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/scheduler/SchedulerQueryTest.java index 8ca800bfe47..95383e1cdce 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/scheduler/SchedulerQueryTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/scheduler/SchedulerQueryTest.java @@ -30,6 +30,7 @@ import org.bonitasoft.engine.scheduler.model.SJobDescriptor; import org.bonitasoft.engine.scheduler.model.SJobLog; import org.bonitasoft.engine.scheduler.model.SJobParameter; +import org.bonitasoft.engine.test.persistence.jdbc.JdbcRowMapper; import org.bonitasoft.engine.test.persistence.repository.JobRepository; import org.hibernate.internal.util.SerializationHelper; import org.junit.Test; @@ -97,7 +98,8 @@ public void should_save_and_get_SJobDescriptor() { Long numberOfSJobDescriptor = jobRepository.selectCount("getNumberOfSJobDescriptor"); PersistentObject searchSJobDescriptor = jobRepository.selectOne("searchSJobDescriptor"); - Map jobDescriptorAsMap = jdbcTemplate.queryForMap("SELECT * FROM job_desc"); + Map jobDescriptorAsMap = jdbcTemplate.queryForObject("SELECT * FROM job_desc", + new JdbcRowMapper("TENANTID", "ID")); assertThat(numberOfSJobDescriptor).isEqualTo(1); assertThat(searchSJobDescriptor).isEqualTo(jobDescriptor); @@ -120,7 +122,8 @@ public void should_save_and_get_SJobParameter() { Long numberOfSJobParameters = jobRepository.selectCount("getNumberOfSJobParameter"); PersistentObject jobParameterFromQuery = jobRepository.selectOne("getJobParameters", pair("jobDescriptorId", 1234L)); - Map jobParameterAsMap = jdbcTemplate.queryForMap("SELECT * FROM job_param"); + Map jobParameterAsMap = jdbcTemplate.queryForObject("SELECT * FROM job_param", + new JdbcRowMapper("TENANTID", "ID", "JOBDESCRIPTORID")); assertThat(numberOfSJobParameters).isEqualTo(1); assertThat(jobParameterFromQuery).isEqualTo(jobParameter); @@ -144,7 +147,8 @@ public void should_save_and_get_SJobLog() { Long numberOfSJobLog = jobRepository.selectCount("getNumberOfSJobLog"); PersistentObject jobLogFromQuery = jobRepository.selectOne("searchSJobLog"); - Map jobLogAsMap = jdbcTemplate.queryForMap("SELECT * FROM job_log"); + Map jobLogAsMap = jdbcTemplate.queryForObject("SELECT * FROM job_log", + new JdbcRowMapper("TENANTID", "ID", "JOBDESCRIPTORID", "RETRYNUMBER", "LASTUPDATEDATE")); assertThat(numberOfSJobLog).isEqualTo(1); assertThat(jobLogFromQuery).isEqualTo(jobLog); diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/temporary/content/TemporaryContentQueryTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/temporary/content/TemporaryContentQueryTest.java index 00742a42ba6..328162bdf4f 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/temporary/content/TemporaryContentQueryTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/temporary/content/TemporaryContentQueryTest.java @@ -26,7 +26,6 @@ import javax.inject.Inject; -import org.apache.commons.io.IOUtils; import org.bonitasoft.engine.test.persistence.repository.TemporaryContentRepository; import org.junit.Test; import org.junit.runner.RunWith; @@ -65,8 +64,9 @@ public void shouldStoreStream() throws IOException, SQLException { InputStream uploadedFileStream = savedTemporaryContent.getContent().getBinaryStream(); assertThat(savedTemporaryContent.getFileName()).isEqualTo(temporaryContent.getFileName()); assertThat(savedTemporaryContent.getMimeType()).isEqualTo(temporaryContent.getMimeType()); - assertThat(tempFilePath.toFile().length()).isEqualTo(uploadedFileStream.available()); - assertArrayEquals(IOUtils.toByteArray(uploadedFileStream), "test".getBytes()); + final byte[] contentByteArray = uploadedFileStream.readAllBytes(); + assertThat(tempFilePath.toFile().length()).isEqualTo(contentByteArray.length); + assertArrayEquals(contentByteArray, "test".getBytes()); } @Test diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java index 36b890b6991..2126bbc4703 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java @@ -13,39 +13,46 @@ **/ package org.bonitasoft.engine.test.persistence; -import org.bonitasoft.engine.persistence.*; +import org.bonitasoft.engine.persistence.PostgresMaterializedBlobType; +import org.bonitasoft.engine.persistence.PostgresMaterializedClobType; +import org.bonitasoft.engine.persistence.PostgresXMLType; +import org.bonitasoft.engine.persistence.XMLType; import org.bonitasoft.engine.services.Vendor; +import org.hibernate.Interceptor; import org.hibernate.SessionFactory; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder; public class TestLocalSessionFactoryBuilder extends LocalSessionFactoryBean { + private Interceptor interceptor; + @Override protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) { Vendor vendor = Vendor.fromHibernateConfiguration(sfb); //register type before loading mappings/entities, type should be present before loading JPA entities switch (vendor) { - case ORACLE: - // FIXME set following interceptor when this module is configured to run on all DB - // sfb.setInterceptor(new OracleInterceptor()); - break; - case MYSQL: - case OTHER: + case ORACLE, OTHER, SQLSERVER: sfb.registerTypeOverride(XMLType.INSTANCE); break; - case SQLSERVER: - // FIXME set following interceptor when this module is configured to run on all DB - // sfb.setInterceptor(new SQLServerInterceptor()); + case MYSQL: + System.setProperty("hibernate.dialect.storage_engine", "innodb"); sfb.registerTypeOverride(XMLType.INSTANCE); break; case POSTGRES: - sfb.setInterceptor(new PostgresInterceptor()); sfb.registerTypeOverride(new PostgresMaterializedBlobType()); sfb.registerTypeOverride(new PostgresMaterializedClobType()); sfb.registerTypeOverride(PostgresXMLType.INSTANCE); break; } + if (interceptor != null) { + sfb.setInterceptor(interceptor); + } return super.buildSessionFactory(sfb); } + + public void setInterceptor(Interceptor interceptor) { + this.interceptor = interceptor; + } + } diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/jdbc/JdbcRowMapper.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/jdbc/JdbcRowMapper.java new file mode 100644 index 00000000000..fc86a561f15 --- /dev/null +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/jdbc/JdbcRowMapper.java @@ -0,0 +1,150 @@ +/** + * Copyright (C) 2024 Bonitasoft S.A. + * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble + * This library is free software; you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation + * version 2.1 of the License. + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301, USA. + **/ +package org.bonitasoft.engine.test.persistence.jdbc; + +import java.sql.Blob; +import java.sql.Clob; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.core.RowMapper; + +/** + * Spring JDBC RowMapper that converts column names and values as Hibernate woulds: + *
    + *
  • converts column names to upper case so that tests can assert on column name whatever the DB vendor
  • + *
  • converts some column values to long, double, int or boolean if needed, notably on Oracle where types seem to be + * harder to detect
  • + *
  • converts Clob and Blob to String and byte[] respectively
  • + *
+ * + * @author Emmanuel Duchastenier + */ +@Slf4j +public class JdbcRowMapper implements RowMapper> { + + private final String dbVendor = System.getProperty("sysprop.bonita.db.vendor", "h2"); + + private List columnsToConvertToLong = new ArrayList<>(); // column names must be upper case + private List columnsToConvertToBoolean = new ArrayList<>(); // column names must be upper case + private List columnsToConvertToDouble = new ArrayList<>(); // column names must be upper case + + private final Map converters = Map.of( + "h2", new DefaultValueConverter(), + "postgres", new DefaultValueConverter(), + "mysql", new DefaultValueConverter(), + "sqlserver", new DefaultValueConverter(), + "oracle", new OracleValueConverter()); + + public JdbcRowMapper() { + log.info("Detected DB vendor: {}", dbVendor); + } + + /** + * @param columnsToConvertToLong column names must be upper case + */ + public JdbcRowMapper(String... columnsToConvertToLong) { + this(); + this.columnsToConvertToLong.addAll(List.of(columnsToConvertToLong)); + } + + /** + * @param columnsToConvertToLong column names must be upper case + * @param columnsToConvertToBoolean column names must be upper case + */ + public JdbcRowMapper(List columnsToConvertToLong, List columnsToConvertToBoolean) { + this(); + this.columnsToConvertToLong = columnsToConvertToLong; + this.columnsToConvertToBoolean = columnsToConvertToBoolean; + } + + public JdbcRowMapper(List columnsToConvertToLong, List columnsToConvertToBoolean, + List columnsToConvertToDouble) { + this(columnsToConvertToLong, columnsToConvertToBoolean); + this.columnsToConvertToDouble = columnsToConvertToDouble; + } + + @Override + public Map mapRow(ResultSet rs, int rowNum) throws SQLException { + Map result = new HashMap<>(); + int columnCount = rs.getMetaData().getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + final Object object = rs.getObject(i); + Object value = converters.get(dbVendor).getValue(rs, object, i); + result.put(rs.getMetaData().getColumnName(i).toUpperCase(), value); + } + return result; + } + + @FunctionalInterface + public interface JdbcValueConverter { + + Object getValue(ResultSet resultSet, Object object, int rowNum) throws SQLException; + } + + class DefaultValueConverter implements JdbcValueConverter { + + @Override + public Object getValue(ResultSet rs, Object object, int columnNumber) throws SQLException { + if (object == null) { + return null; + } + + if (object instanceof Clob) { + final Clob clob = rs.getClob(columnNumber); + return clob.getSubString(1, (int) clob.length()); + } + if (object instanceof Blob) { + final Blob blob = rs.getBlob(columnNumber); + return blob.getBytes(1, (int) blob.length()); + } + + // if value must be converted to double, let's do it: + final String upperCaseColumnName = rs.getMetaData().getColumnName(columnNumber).toUpperCase(); + if (columnsToConvertToDouble.contains(upperCaseColumnName)) { + return ((Number) object).doubleValue(); + } + // if value must be converted to long, let's do it: + if (columnsToConvertToLong.contains(upperCaseColumnName)) { + return ((Number) object).longValue(); + } else if (object instanceof Number) { + // if value can be converted to int, let's do it: + try { + return ((Number) object).intValue(); + } catch (Exception ignored) { + } + } + return object; + } + } + + class OracleValueConverter extends DefaultValueConverter { + + @Override + public Object getValue(ResultSet rs, Object object, int columnNumber) throws SQLException { + if (object != null + && columnsToConvertToBoolean.contains(rs.getMetaData().getColumnName(columnNumber).toUpperCase())) { + return "1".equals(rs.getString(columnNumber)); + } else { + return super.getValue(rs, object, columnNumber); + } + } + } + +} diff --git a/bonita-integration-tests/bonita-query-tests/src/test/resources/datasource/datasource-dependency-h2.xml b/bonita-integration-tests/bonita-query-tests/src/test/resources/datasource/datasource-dependency-h2.xml new file mode 100644 index 00000000000..0b4f6a71019 --- /dev/null +++ b/bonita-integration-tests/bonita-query-tests/src/test/resources/datasource/datasource-dependency-h2.xml @@ -0,0 +1,20 @@ + + + + + + org.hibernate.dialect.H2Dialect + org.h2.jdbcx.JdbcDataSource + jdbc:h2:mem:bonita;DB_CLOSE_ON_EXIT=FALSE;AUTOCOMMIT=OFF;IGNORECASE=TRUE;DATABASE_TO_LOWER=TRUE; + sa + + + + + + + + diff --git a/bonita-integration-tests/bonita-query-tests/src/test/resources/datasource/datasource-dependency-postgres.xml b/bonita-integration-tests/bonita-query-tests/src/test/resources/datasource/datasource-dependency-postgres.xml new file mode 100644 index 00000000000..2cccb4d6acc --- /dev/null +++ b/bonita-integration-tests/bonita-query-tests/src/test/resources/datasource/datasource-dependency-postgres.xml @@ -0,0 +1,24 @@ + + + + + + + org.hibernate.dialect.PostgreSQL10Dialect + org.postgresql.xa.PGXADataSource + localhost + 5432 + bonita + bonita + bonita + jdbc:postgresql://${db.server.name}:${db.server.port}/${db.database.name} + + + + + + + diff --git a/bonita-integration-tests/bonita-query-tests/src/test/resources/testContext.xml b/bonita-integration-tests/bonita-query-tests/src/test/resources/testContext.xml index 9d1b4b34326..80ccbf83c56 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/resources/testContext.xml +++ b/bonita-integration-tests/bonita-query-tests/src/test/resources/testContext.xml @@ -1,24 +1,31 @@ - + + + + + + + + + + + @@ -210,7 +217,6 @@ /org/bonitasoft/engine/platform/model/impl/hibernate/platform.queries.hbm.xml org/bonitasoft/engine/platform/command/model/impl/hibernate/platformCommand.queries.hbm.xml - /org/bonitasoft/engine/core/process/instance/model/impl/hibernate/archived.process.instance.queries.hbm.xml /org/bonitasoft/engine/page/impl/hibernate/page.queries.hbm.xml @@ -235,7 +241,7 @@ create-drop - org.hibernate.dialect.H2Dialect + ${db.hibernate.dialect} false false false diff --git a/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DatabasePluginExtension.groovy b/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DatabasePluginExtension.groovy index bf34db40e28..ccdd8119680 100644 --- a/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DatabasePluginExtension.groovy +++ b/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DatabasePluginExtension.groovy @@ -13,6 +13,8 @@ **/ package org.bonitasoft.engine.gradle.docker +import org.gradle.api.Action + class DatabasePluginExtension { /** @@ -48,28 +50,20 @@ class DatabasePluginExtension { this.includes.add(include) } - def postgres(Closure closure) { - closure.delegate = postgres - closure.resolveStrategy = Closure.DELEGATE_FIRST - closure() + def postgres(Action action) { + action.execute(postgres) } - def mysql(Closure closure) { - closure.delegate = mysql - closure.resolveStrategy = Closure.DELEGATE_FIRST - closure() + def mysql(Action action) { + action.execute(mysql) } - def oracle(Closure closure) { - closure.delegate = oracle - closure.resolveStrategy = Closure.DELEGATE_FIRST - closure() + def oracle(Action action) { + action.execute(oracle) } - def sqlserver(Closure closure) { - closure.delegate = sqlserver - closure.resolveStrategy = Closure.DELEGATE_FIRST - closure() + def sqlserver(Action action) { + action.execute(sqlserver) } } diff --git a/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabaseContainerTasksCreator.groovy b/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabaseContainerTasksCreator.groovy index 59fe77f9897..1d2349d8c5e 100644 --- a/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabaseContainerTasksCreator.groovy +++ b/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabaseContainerTasksCreator.groovy @@ -49,6 +49,9 @@ class DockerDatabaseContainerTasksCreator { } project.plugins.apply('com.bmuschko.docker-remote-api') vendors.each { vendor -> + if (!extension."${vendor.name}".enabled) { + return // do not create docker tasks for disabled database configurations + } def uniqueName = vendor.name.capitalize() DbParser.DbConnectionSettings dbConnectionSettings = new DbParser.DbConnectionSettings() diff --git a/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabasePlugin.groovy b/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabasePlugin.groovy index 530ad3e5ba2..50c5df73145 100644 --- a/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabasePlugin.groovy +++ b/buildSrc/src/main/groovy/org/bonitasoft/engine/gradle/docker/DockerDatabasePlugin.groovy @@ -17,9 +17,9 @@ class DockerDatabasePlugin implements Plugin { driversConfiguration(project) def databaseIntegrationTest = project.extensions.create("databaseIntegrationTest", DatabasePluginExtension) - DockerDatabaseContainerTasksCreator.createTasks(project, databaseIntegrationTest, getVendors()) project.afterEvaluate { + DockerDatabaseContainerTasksCreator.createTasks(project, databaseIntegrationTest, getVendors()) if (!databaseIntegrationTest.includes) { println "No databaseIntegrationTest.include found. No tests to run!" }