modified test cases

This commit is contained in:
rishwanth1995
2018-06-11 13:36:15 -04:00
parent 7028872771
commit 9f2dbcfccf
3 changed files with 44 additions and 29 deletions
@@ -1554,11 +1554,9 @@ public abstract class AbstractSqlEamDb implements EamDb {
try {
preparedStatement = conn.prepareStatement(sql.toString());
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
instanceTableCallback.process(resultSet);
}
instanceTableCallback.process(resultSet);
} catch (SQLException ex) {
throw new EamDbException("Error getting notable artifact instances.", ex);
throw new EamDbException("Error getting all artifact instances from instances table", ex);
} finally {
EamDbUtil.closePreparedStatement(preparedStatement);
EamDbUtil.closeResultSet(resultSet);
@@ -30,14 +30,14 @@ public interface InstanceTableCallback {
/**
* Process the artifact instance
*
* @param resultSet row of artifact instance table.
* @param resultSet artifact instance table.
*/
public void process(ResultSet resultSet);
/**
*
* @param resultSet row of artifact instance table
* @param resultSet artifact instance table
* @return ID of the instance
* @throws SQLException
*/
@@ -47,7 +47,7 @@ public interface InstanceTableCallback {
/**
*
* @param resultSet row of artifact instance table
* @param resultSet artifact instance table
* @return Case ID of a given instance
* @throws SQLException
*/
@@ -57,7 +57,7 @@ public interface InstanceTableCallback {
/**
*
* @param resultSet row of artifact instance table
* @param resultSet artifact instance table
* @return Data source id of a particular instance
* @throws SQLException
*/
@@ -67,7 +67,7 @@ public interface InstanceTableCallback {
/**
*
* @param resultSet row of artifact instance table
* @param resultSet artifact instance table
* @return md5 hash value of the instance
* @throws SQLException
*/
@@ -77,7 +77,7 @@ public interface InstanceTableCallback {
/**
*
* @param resultSet row of artifact instance table
* @param resultSet artifact instance table
* @return file path of the instance
* @throws SQLException
*/
@@ -87,7 +87,7 @@ public interface InstanceTableCallback {
/**
*
* @param resultSet row of artifact instance table
* @param resultSet artifact instance table
* @return status integer based on whether instance is marked notable or not
* @throws SQLException
*/
@@ -97,7 +97,7 @@ public interface InstanceTableCallback {
/**
*
* @param resultSet row of artifact instance table
* @param resultSet artifact instance table
* @return previous comment made for the instance
* @throws SQLException
*/
@@ -28,6 +28,7 @@ import java.util.HashSet;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.stream.Collectors;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -630,6 +631,9 @@ public class CentralRepoDatamodelTest extends TestCase {
String inDataSource1twicePath2 = "C:\\files\\path2.txt";
String onlyInDataSource3Hash = "2af54305f183778d87de0c70c591fae4";
String onlyInDataSource3Path = "C:\\files\\path3.txt";
String callbackTestFilePath1 = "C:\\files\\_\\path1.txt";
String callbackTestFilePath2 = "C:\\files\\_\\path2.txt";
String callbackTestFileHash = "fb9dd8f04dacd3e82f4917f1a002223c";
// These will all go in dataSource1fromCase1
String emailValue = "test@gmail.com";
@@ -1067,24 +1071,22 @@ public class CentralRepoDatamodelTest extends TestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex);
}
// Test running processinstance which queries all rows from instances table
try {
//test filetype instances
CorrelationAttribute attr = new CorrelationAttribute(fileType, callbackTestFileHash);
CorrelationAttributeInstance inst1 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, callbackTestFilePath1);
CorrelationAttributeInstance inst2 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, callbackTestFilePath2);
attr.addInstance(inst1);
attr.addInstance(inst2);
EamDb DbManager = EamDb.getInstance();
DbManager.addArtifact(attr);
ArtifactInstanceProcessCallbackTest instancetableCallback = new ArtifactInstanceProcessCallbackTest();
EamDb.getInstance().processInstances(fileType, instancetableCallback);
int count = instancetableCallback.getCounter();
assertTrue("Process Instance count for filetype instances: " + count + "-expected 6", count == 6);
} catch (EamDbException ex) {
Exceptions.printStackTrace(ex);
}
try {
//test emailtype instances
ArtifactInstanceProcessCallbackTest instancetableCallback = new ArtifactInstanceProcessCallbackTest();
EamDb.getInstance().processInstances(emailType, instancetableCallback);
int count = instancetableCallback.getCounter();
assertTrue("Process Instance count for filetype instances: " + count + "-expected 1", count == 1);
DbManager.processInstances(fileType, instancetableCallback);
int count1 = instancetableCallback.getCounter();
int count2 = instancetableCallback.getCounterNamingConvention();
assertTrue("Process Instance count with filepath naming convention: " + count2 + "-expected 2", count2 == 2);
assertTrue("Process Instance count with filepath without naming convention: " + count1 + "-expected greater than 0", count1 > 0);
} catch (EamDbException ex) {
Exceptions.printStackTrace(ex);
}
@@ -2650,16 +2652,31 @@ public class CentralRepoDatamodelTest extends TestCase {
public class ArtifactInstanceProcessCallbackTest implements InstanceTableCallback {
int counterNamingConvention = 0;
int counter = 0;
@Override
public void process(ResultSet resultSet) {
counter++;
try {
while(resultSet.next()){
if(InstanceTableCallback.getFilePath(resultSet).contains("_")){
counterNamingConvention++;
}else{
counter++;
}
}
} catch (SQLException ex) {
Exceptions.printStackTrace(ex);
}
}
public int getCounter() {
return counter;
}
public int getCounterNamingConvention(){
return counterNamingConvention;
}
}