temp commit

backup
Isuri Mendis 1 year ago
parent addeb4c4da
commit 249b098cca

@ -371,6 +371,19 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
<suiteXmlFiles>
<file>src/test/resources/testng.xml</file>
<file>src/test/resources/mysql-testng.xml</file>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>

@ -570,7 +570,7 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
// Remove the special value if it was added due to a previous cyclic relationship
ancestors.remove(-1);
} else {
// Detected cyclic relationship, you can handle it as needed
// Detected cyclic relationship
ancestors.add(-1); // Special value indicating a cyclic relationship
return ancestors;
}

@ -531,7 +531,7 @@ public class DeviceOrganizationMysqlDAOImpl implements DeviceOrganizationDAO {
// Check for indirect cyclic relationship
if (hasCyclicRelationship(conn, deviceID, parentDeviceID)){
log.error("Indirect cyclic relationship detected. Insertion not allowed.");
log.error("cyclic relationship detected. Insertion not allowed.");
return true;
}
return false;
@ -551,7 +551,7 @@ public class DeviceOrganizationMysqlDAOImpl implements DeviceOrganizationDAO {
private boolean hasCyclicRelationship(Connection connection, int deviceID, Integer parentDeviceID) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(
"WITH RECURSIVE all_paths AS\n" +
"(\n" +
"(" +
"SELECT DEVICE_ID AS DEVICE_ID,\n" +
"CAST(DEVICE_ID AS CHAR(500)) AS path, 0 AS is_cycle\n" +
"FROM DM_DEVICE_ORGANIZATION\n" +
@ -559,11 +559,11 @@ public class DeviceOrganizationMysqlDAOImpl implements DeviceOrganizationDAO {
"UNION ALL\n" +
"SELECT r.DEVICE_ID,\n" +
"CONCAT(d.path, ',', r.DEVICE_ID),\n" +
" FIND_IN_SET(r.DEVICE_ID, d.path)!=0\n" +
"FIND_IN_SET(r.DEVICE_ID, d.path)!=0\n" +
"FROM DM_DEVICE_ORGANIZATION r, all_paths d\n" +
"WHERE r.PARENT_DEVICE_ID=d.DEVICE_ID\n" +
"AND is_cycle=0\n" +
" )\n" +
"AND is_cycle=0" +
")\n" +
"SELECT\n" +
" DEVICE_ID,\n" +
" path,\n" +

@ -82,7 +82,7 @@ public class ConnectionManagerUtil {
*
* @throws DBConnectionException If an error occurs while starting the transaction.
*/
public static void beginDBTransaction() throws DBConnectionException {
public static Connection beginDBTransaction() throws DBConnectionException {
Connection conn = currentConnection.get();
if (conn == null) {
conn = getDBConnection();
@ -95,6 +95,8 @@ public class ConnectionManagerUtil {
} catch (SQLException e) {
throw new DBConnectionException("Error occurred while starting a database transaction.", e);
}
return conn;
}
/**

@ -32,6 +32,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection;
import java.util.List;
public class DeviceOrganizationServiceImpl implements DeviceOrganizationService {

@ -52,6 +52,10 @@ public abstract class BaseDeviceOrganizationTest {
private static final String datasourceLocation = "src/test/resources/carbon-home/repository/conf/" +
"datasources/data-source-config.xml";
// private static final String datasourceLocation = "src/test/resources/config/datasource/mysql/" +
// "data-source-config.xml";
private static boolean mock;
@BeforeSuite

@ -18,10 +18,10 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MySQLDeviceManagementCore">
<suite name="MySQLDeviceOrganization">
<parameter name="useDefaultListeners" value="false"/>
<parameter name="datasource" value="src/test/resources/config/datasource/mysql/data-source-config"/>
<parameter name="isMock" value="true"/>
<!-- <parameter name="isMock" value="true"/>-->
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="MySql"/>

Loading…
Cancel
Save