update tests for instance refactor.

This commit is contained in:
Andrew Ziehl 2018-08-15 16:38:18 -07:00
parent 84471317a3
commit a3eb28f1dc
2 changed files with 117 additions and 129 deletions

View File

@ -91,7 +91,7 @@ public class CorrelationAttributeInstance implements Serializable {
} }
CorrelationAttributeInstance( CorrelationAttributeInstance(
Type type, Type type,
String value, String value,
int instanceId, int instanceId,
CorrelationCase eamCase, CorrelationCase eamCase,
@ -103,6 +103,10 @@ public class CorrelationAttributeInstance implements Serializable {
if (filePath == null) { if (filePath == null) {
throw new EamDbException("file path is null"); throw new EamDbException("file path is null");
} }
if (value == null) {
throw new EamDbException("md5 value is null");
}
this.correlationType = type; this.correlationType = type;
this.correlationValue = value; this.correlationValue = value;

View File

@ -155,9 +155,9 @@ public class CentralRepoDatamodelTest extends TestCase {
org2 = EamDb.getInstance().newOrganization(org2); org2 = EamDb.getInstance().newOrganization(org2);
// Store the file type object for later use // Store the file type object for later use
fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID);
assertTrue("getCorrelationTypeById(FILES_TYPE_ID) returned null", fileType != null); assertTrue("getCorrelationTypeById(FILES_TYPE_ID) returned null", fileType != null);
usbDeviceType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.USBID_TYPE_ID); usbDeviceType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID);
assertTrue("getCorrelationTypeById(USBID_TYPE_ID) returned null", usbDeviceType != null); assertTrue("getCorrelationTypeById(USBID_TYPE_ID) returned null", usbDeviceType != null);
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -220,12 +220,13 @@ public class CentralRepoDatamodelTest extends TestCase {
// Add two instances with notable status // Add two instances with notable status
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, notableHashInBothCases); CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(notableHashInBothCases, fileType, case1, dataSource1fromCase1, "path1",
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, "path1", "", TskData.FileKnown.BAD);
"", TskData.FileKnown.BAD)); EamDb.getInstance().addArtifactInstance(attr1);
attr.addInstance(new CorrelationAttributeInstance(case2, dataSource1fromCase2, "path2", CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(notableHashInBothCases, fileType, case2, dataSource1fromCase2, "path2",
"", TskData.FileKnown.BAD)); "", TskData.FileKnown.BAD);
EamDb.getInstance().addArtifactInstance(attr);
EamDb.getInstance().addArtifactInstance(attr2);
List<CorrelationAttributeInstance> attrs = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, notableHashInBothCases); List<CorrelationAttributeInstance> attrs = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, notableHashInBothCases);
assertTrue("getArtifactInstancesByTypeValue returned " + attrs.size() + " values - expected 2", attrs.size() == 2); assertTrue("getArtifactInstancesByTypeValue returned " + attrs.size() + " values - expected 2", attrs.size() == 2);
@ -239,12 +240,15 @@ public class CentralRepoDatamodelTest extends TestCase {
// Add two instances with one notable, one known // Add two instances with one notable, one known
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, notableHashInOneCaseKnownOther); CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(notableHashInOneCaseKnownOther, fileType, case1, dataSource1fromCase1, "path3",
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, "path3", "", TskData.FileKnown.BAD);
"", TskData.FileKnown.BAD));
attr.addInstance(new CorrelationAttributeInstance(case2, dataSource1fromCase2, "path4", EamDb.getInstance().addArtifactInstance(attr1);
"", TskData.FileKnown.KNOWN));
EamDb.getInstance().addArtifactInstance(attr); CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(notableHashInOneCaseKnownOther, fileType, case2, dataSource1fromCase2, "path4",
"", TskData.FileKnown.KNOWN);
EamDb.getInstance().addArtifactInstance(attr2);
List<CorrelationAttributeInstance> attrs = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, notableHashInOneCaseKnownOther); List<CorrelationAttributeInstance> attrs = EamDb.getInstance().getArtifactInstancesByTypeValue(fileType, notableHashInOneCaseKnownOther);
assertTrue("getArtifactInstancesByTypeValue returned " + attrs.size() + " values - expected 2", attrs.size() == 2); assertTrue("getArtifactInstancesByTypeValue returned " + attrs.size() + " values - expected 2", attrs.size() == 2);
@ -264,9 +268,9 @@ public class CentralRepoDatamodelTest extends TestCase {
// Add an artifact and then update its status // Add an artifact and then update its status
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, hashToChangeToNotable); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(hashToChangeToNotable, fileType, case1, dataSource1fromCase2, "path5",
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase2, "path5", "", TskData.FileKnown.KNOWN);
"", TskData.FileKnown.KNOWN));
EamDb.getInstance().addArtifactInstance(attr); EamDb.getInstance().addArtifactInstance(attr);
EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD); EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD);
@ -280,14 +284,15 @@ public class CentralRepoDatamodelTest extends TestCase {
} }
// Try to update artifact with two CorrelationAttributeInstance instances // Try to update artifact with two CorrelationAttributeInstance instances
// TODO, this seems like it is no longer a valid test.
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "badHash"); CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance("badHash", fileType, case1, dataSource1fromCase1, "badPath",
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, "badPath", "", TskData.FileKnown.KNOWN);
"", TskData.FileKnown.KNOWN)); CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance("badHash", fileType, case1, dataSource1fromCase2, "badPath",
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase2, "badPath", "", TskData.FileKnown.KNOWN);
"", TskData.FileKnown.KNOWN));
EamDb.getInstance().setAttributeInstanceKnownStatus(attr1, TskData.FileKnown.BAD);
EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD); EamDb.getInstance().setAttributeInstanceKnownStatus(attr2, TskData.FileKnown.BAD);
Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for multiple Correlation Attribute Instances"); Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for multiple Correlation Attribute Instances");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -303,9 +308,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Try to update artifact with null known status // Try to update artifact with null known status
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "badHash"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance("badHash", fileType, case1, dataSource1fromCase1, "badPath",
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, "badPath", "", TskData.FileKnown.KNOWN);
"", TskData.FileKnown.KNOWN));
EamDb.getInstance().setAttributeInstanceKnownStatus(attr, null); EamDb.getInstance().setAttributeInstanceKnownStatus(attr, null);
Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for null known status"); Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for null known status");
@ -315,9 +319,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Try to update artifact with null case // Try to update artifact with null case
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "badHash"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance("badHash", fileType, null, dataSource1fromCase1, "badPath",
attr.addInstance(new CorrelationAttributeInstance(null, dataSource1fromCase1, "badPath", "", TskData.FileKnown.KNOWN);
"", TskData.FileKnown.KNOWN));
EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD); EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD);
Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for null case"); Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for null case");
@ -327,9 +330,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Try to update artifact with null data source // Try to update artifact with null data source
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "badHash"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance("badHash", fileType, case1, null, "badPath",
attr.addInstance(new CorrelationAttributeInstance(case1, null, "badPath", "", TskData.FileKnown.KNOWN);
"", TskData.FileKnown.KNOWN));
EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD); EamDb.getInstance().setAttributeInstanceKnownStatus(attr, TskData.FileKnown.BAD);
Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for null case"); Assert.fail("setArtifactInstanceKnownStatus failed to throw exception for null case");
@ -473,18 +475,17 @@ public class CentralRepoDatamodelTest extends TestCase {
assertTrue("getCountArtifactInstancesByCaseDataSource returned non-zero count", originalArtifactCount == 0); assertTrue("getCountArtifactInstancesByCaseDataSource returned non-zero count", originalArtifactCount == 0);
// Create the first list, which will have (bulkThreshold / 2) entries // Create the first list, which will have (bulkThreshold / 2) entries
List<CorrelationAttribute> list1 = new ArrayList<>(); List<CorrelationAttributeInstance> list1 = new ArrayList<>();
for (int i = 0; i < DEFAULT_BULK_THRESHOLD / 2; i++) { for (int i = 0; i < DEFAULT_BULK_THRESHOLD / 2; i++) {
String value = "bulkInsertValue1_" + String.valueOf(i); String value = "bulkInsertValue1_" + String.valueOf(i);
String path = "C:\\bulkInsertPath1\\file" + String.valueOf(i); String path = "C:\\bulkInsertPath1\\file" + String.valueOf(i);
CorrelationAttribute attr = new CorrelationAttribute(fileType, value); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(value, fileType, case1, dataSource1fromCase1, path);
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, path));
list1.add(attr); list1.add(attr);
} }
// Queue up the current list. There should not be enough to trigger the insert // Queue up the current list. There should not be enough to trigger the insert
for (CorrelationAttribute attr : list1) { for (CorrelationAttributeInstance attr : list1) {
EamDb.getInstance().addAttributeInstanceBulk(attr); EamDb.getInstance().addAttributeInstanceBulk(attr);
} }
@ -493,18 +494,17 @@ public class CentralRepoDatamodelTest extends TestCase {
originalArtifactCount == EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), dataSource1fromCase1.getDeviceID())); originalArtifactCount == EamDb.getInstance().getCountArtifactInstancesByCaseDataSource(case1.getCaseUUID(), dataSource1fromCase1.getDeviceID()));
// Make a second list with length equal to bulkThreshold // Make a second list with length equal to bulkThreshold
List<CorrelationAttribute> list2 = new ArrayList<>(); List<CorrelationAttributeInstance> list2 = new ArrayList<>();
for (int i = 0; i < DEFAULT_BULK_THRESHOLD; i++) { for (int i = 0; i < DEFAULT_BULK_THRESHOLD; i++) {
String value = "bulkInsertValue2_" + String.valueOf(i); String value = "bulkInsertValue2_" + String.valueOf(i);
String path = "C:\\bulkInsertPath2\\file" + String.valueOf(i); String path = "C:\\bulkInsertPath2\\file" + String.valueOf(i);
CorrelationAttribute attr = new CorrelationAttribute(fileType, value); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(value, fileType, case1, dataSource1fromCase1, path);
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, path));
list2.add(attr); list2.add(attr);
} }
// Queue up the current list. This will trigger an insert partway through // Queue up the current list. This will trigger an insert partway through
for (CorrelationAttribute attr : list2) { for (CorrelationAttributeInstance attr : list2) {
EamDb.getInstance().addAttributeInstanceBulk(attr); EamDb.getInstance().addAttributeInstanceBulk(attr);
} }
@ -525,7 +525,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test preparing artifact with null type // Test preparing artifact with null type
try { try {
CorrelationAttribute attr = new CorrelationAttribute(null, "value"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, "value");
EamDb.getInstance().addAttributeInstanceBulk(attr); EamDb.getInstance().addAttributeInstanceBulk(attr);
Assert.fail("prepareBulkArtifact failed to throw exception for null type"); Assert.fail("prepareBulkArtifact failed to throw exception for null type");
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -534,8 +534,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test preparing artifact with null case // Test preparing artifact with null case
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "value"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance("value", fileType, null, dataSource1fromCase1, "path");
attr.addInstance(new CorrelationAttributeInstance(null, dataSource1fromCase1, "path"));
EamDb.getInstance().addAttributeInstanceBulk(attr); EamDb.getInstance().addAttributeInstanceBulk(attr);
EamDb.getInstance().commitAttrtibuteInstancesBulk(); EamDb.getInstance().commitAttrtibuteInstancesBulk();
Assert.fail("bulkInsertArtifacts failed to throw exception for null case"); Assert.fail("bulkInsertArtifacts failed to throw exception for null case");
@ -545,8 +544,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test preparing artifact with null data source // Test preparing artifact with null data source
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "value"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance("value", fileType, case1, null, "path");
attr.addInstance(new CorrelationAttributeInstance(case1, null, "path"));
EamDb.getInstance().addAttributeInstanceBulk(attr); EamDb.getInstance().addAttributeInstanceBulk(attr);
EamDb.getInstance().commitAttrtibuteInstancesBulk(); EamDb.getInstance().commitAttrtibuteInstancesBulk();
Assert.fail("prepareBulkArtifact failed to throw exception for null data source"); Assert.fail("prepareBulkArtifact failed to throw exception for null data source");
@ -556,9 +554,9 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test preparing artifact with null path // Test preparing artifact with null path
// CorrelationAttributeInstance will throw an exception // CorrelationAttributeInstance will throw an exception
// TODO, still valid?
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "value"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance("value", fileType, case1, dataSource1fromCase1, null);
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, null));
Assert.fail("CorrelationAttributeInstance failed to throw exception for null path"); Assert.fail("CorrelationAttributeInstance failed to throw exception for null path");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -566,8 +564,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test preparing artifact with null known status // Test preparing artifact with null known status
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "value"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance("value", fileType, case1, dataSource1fromCase1, "path", "comment", null);
attr.addInstance(new CorrelationAttributeInstance(case1, dataSource1fromCase1, "path", "comment", null));
EamDb.getInstance().addAttributeInstanceBulk(attr); EamDb.getInstance().addAttributeInstanceBulk(attr);
EamDb.getInstance().commitAttrtibuteInstancesBulk(); EamDb.getInstance().commitAttrtibuteInstancesBulk();
Assert.fail("prepareBulkArtifact failed to throw exception for null known status"); Assert.fail("prepareBulkArtifact failed to throw exception for null known status");
@ -653,7 +650,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Store the email type // Store the email type
CorrelationAttributeInstance.Type emailType; CorrelationAttributeInstance.Type emailType;
try { try {
emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.EMAIL_TYPE_ID); emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.EMAIL_TYPE_ID);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
Assert.fail(ex); Assert.fail(ex);
@ -662,9 +659,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding attribute with one instance // Test adding attribute with one instance
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, onlyInDataSource3Hash); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(onlyInDataSource3Hash, fileType, case2, dataSource1fromCase2, onlyInDataSource3Path);
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case2, dataSource1fromCase2, onlyInDataSource3Path);
attr.addInstance(inst);
EamDb.getInstance().addArtifactInstance(attr); EamDb.getInstance().addArtifactInstance(attr);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -673,14 +668,13 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding attribute with an instance in each data source // Test adding attribute with an instance in each data source
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, inAllDataSourcesHash); CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource1fromCase1, inAllDataSourcesPath);
CorrelationAttributeInstance inst1 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, inAllDataSourcesPath); EamDb.getInstance().addArtifactInstance(attr1);
attr.addInstance(inst1); CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case1, dataSource2fromCase1, inAllDataSourcesPath);
CorrelationAttributeInstance inst2 = new CorrelationAttributeInstance(case1, dataSource2fromCase1, inAllDataSourcesPath); EamDb.getInstance().addArtifactInstance(attr2);
attr.addInstance(inst2); CorrelationAttributeInstance attr3 = new CorrelationAttributeInstance(inAllDataSourcesHash, fileType, case2, dataSource1fromCase2, inAllDataSourcesPath);
CorrelationAttributeInstance inst3 = new CorrelationAttributeInstance(case2, dataSource1fromCase2, inAllDataSourcesPath); EamDb.getInstance().addArtifactInstance(attr3);
attr.addInstance(inst3);
EamDb.getInstance().addArtifactInstance(attr);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
Assert.fail(ex); Assert.fail(ex);
@ -688,12 +682,11 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding attribute with two instances in one data source // Test adding attribute with two instances in one data source
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, inDataSource1twiceHash); CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath1);
CorrelationAttributeInstance inst1 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, inDataSource1twicePath1); EamDb.getInstance().addArtifactInstance(attr1);
attr.addInstance(inst1); CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(inDataSource1twiceHash, fileType, case1, dataSource1fromCase1, inDataSource1twicePath2);
CorrelationAttributeInstance inst2 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, inDataSource1twicePath2); EamDb.getInstance().addArtifactInstance(attr2);
attr.addInstance(inst2);
EamDb.getInstance().addArtifactInstance(attr);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
Assert.fail(ex); Assert.fail(ex);
@ -702,9 +695,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding the other types // Test adding the other types
// Test adding an email artifact // Test adding an email artifact
try { try {
CorrelationAttribute attr = new CorrelationAttribute(emailType, emailValue); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailValue, emailType, case1, dataSource1fromCase1, emailPath);
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case1, dataSource1fromCase1, emailPath);
attr.addInstance(inst);
EamDb.getInstance().addArtifactInstance(attr); EamDb.getInstance().addArtifactInstance(attr);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -713,10 +704,11 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding a phone artifact // Test adding a phone artifact
try { try {
CorrelationAttribute attr = new CorrelationAttribute(EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.PHONE_TYPE_ID), CorrelationAttributeInstance attr = new CorrelationAttributeInstance(
phoneValue); phoneValue,
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case1, dataSource1fromCase1, phonePath); EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.PHONE_TYPE_ID),
attr.addInstance(inst); case1, dataSource1fromCase1, phonePath);
EamDb.getInstance().addArtifactInstance(attr); EamDb.getInstance().addArtifactInstance(attr);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -725,10 +717,10 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding a domain artifact // Test adding a domain artifact
try { try {
CorrelationAttribute attr = new CorrelationAttribute(EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.DOMAIN_TYPE_ID), CorrelationAttributeInstance attr = new CorrelationAttributeInstance(
domainValue); domainValue,
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case1, dataSource1fromCase1, domainPath); EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.DOMAIN_TYPE_ID),
attr.addInstance(inst); case1, dataSource1fromCase1, domainPath);
EamDb.getInstance().addArtifactInstance(attr); EamDb.getInstance().addArtifactInstance(attr);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -737,10 +729,11 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding a device ID artifact // Test adding a device ID artifact
try { try {
CorrelationAttribute attr = new CorrelationAttribute(EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.USBID_TYPE_ID), CorrelationAttributeInstance attr = new CorrelationAttributeInstance(
devIdValue); devIdValue,
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case1, dataSource1fromCase1, devIdPath); EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.USBID_TYPE_ID),
attr.addInstance(inst); case1, dataSource1fromCase1, devIdPath);
EamDb.getInstance().addArtifactInstance(attr); EamDb.getInstance().addArtifactInstance(attr);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -749,9 +742,9 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test CorrelationAttributeInstance failure cases // Test CorrelationAttributeInstance failure cases
// Create an attribute to use in the next few tests // Create an attribute to use in the next few tests
CorrelationAttribute failAttr; CorrelationAttributeInstance failAttr;
try { try {
failAttr = new CorrelationAttribute(fileType, "badInstances"); failAttr = new CorrelationAttributeInstance(fileType, "badInstances");
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
Assert.fail(ex); Assert.fail(ex);
@ -760,9 +753,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding instance with null case // Test adding instance with null case
try { try {
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(null, dataSource1fromCase2, "badPath"); CorrelationAttributeInstance failAttrInst = new CorrelationAttributeInstance("badInstances", fileType, null, dataSource1fromCase2, "badPath");
failAttr.addInstance(inst); EamDb.getInstance().addArtifactInstance(failAttrInst);
EamDb.getInstance().addArtifactInstance(failAttr);
Assert.fail("addArtifact failed to throw exception for null case"); Assert.fail("addArtifact failed to throw exception for null case");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -771,9 +763,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding instance with invalid case ID // Test adding instance with invalid case ID
try { try {
CorrelationCase badCase = new CorrelationCase("badCaseUuid", "badCaseName"); CorrelationCase badCase = new CorrelationCase("badCaseUuid", "badCaseName");
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(badCase, dataSource1fromCase2, "badPath"); CorrelationAttributeInstance failAttrInst2 = new CorrelationAttributeInstance("badInstances", fileType, badCase, dataSource1fromCase2, "badPath");
failAttr.addInstance(inst); EamDb.getInstance().addArtifactInstance(failAttrInst2);
EamDb.getInstance().addArtifactInstance(failAttr);
Assert.fail("addArtifact failed to throw exception for invalid case"); Assert.fail("addArtifact failed to throw exception for invalid case");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -781,9 +772,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding instance with null data source // Test adding instance with null data source
try { try {
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case1, null, "badPath"); CorrelationAttributeInstance failAttrInst3 = new CorrelationAttributeInstance("badInstances", fileType, case1, null, "badPath");
failAttr.addInstance(inst); EamDb.getInstance().addArtifactInstance(failAttrInst3);
EamDb.getInstance().addArtifactInstance(failAttr);
Assert.fail("addArtifact failed to throw exception for null data source"); Assert.fail("addArtifact failed to throw exception for null data source");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -792,9 +782,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding instance with invalid data source ID // Test adding instance with invalid data source ID
try { try {
CorrelationDataSource badDS = new CorrelationDataSource(case1, "badDSUuid", "badDSName"); CorrelationDataSource badDS = new CorrelationDataSource(case1, "badDSUuid", "badDSName");
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case1, badDS, "badPath"); CorrelationAttributeInstance failAttrInst4 = new CorrelationAttributeInstance("badInstances", fileType, case1, badDS, "badPath");
failAttr.addInstance(inst); EamDb.getInstance().addArtifactInstance(failAttrInst4);
EamDb.getInstance().addArtifactInstance(failAttr);
Assert.fail("addArtifact failed to throw exception for invalid data source"); Assert.fail("addArtifact failed to throw exception for invalid data source");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -803,7 +792,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding instance with null path // Test adding instance with null path
// This will fail in the CorrelationAttributeInstance constructor // This will fail in the CorrelationAttributeInstance constructor
try { try {
new CorrelationAttributeInstance(case1, dataSource1fromCase1, null); new CorrelationAttributeInstance("badInstances", fileType, case1, dataSource1fromCase1, null);
Assert.fail("CorrelationAttributeInstance failed to throw exception for null path"); Assert.fail("CorrelationAttributeInstance failed to throw exception for null path");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -811,9 +800,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test adding instance with null known status // Test adding instance with null known status
try { try {
CorrelationAttributeInstance inst = new CorrelationAttributeInstance(case1, dataSource1fromCase1, null, "comment", null); CorrelationAttributeInstance failAttrInst5 = new CorrelationAttributeInstance("badInstances", fileType, case1, dataSource1fromCase1, null, "comment", null);
failAttr.addInstance(inst); EamDb.getInstance().addArtifactInstance(failAttrInst5);
EamDb.getInstance().addArtifactInstance(failAttr);
Assert.fail("addArtifact failed to throw exception for null known status"); Assert.fail("addArtifact failed to throw exception for null known status");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
@ -822,7 +810,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test CorrelationAttribute failure cases // Test CorrelationAttribute failure cases
// Test null type // Test null type
try { try {
CorrelationAttribute attr = new CorrelationAttribute(null, "badInstances"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, "badInstances");
EamDb.getInstance().addArtifactInstance(attr); EamDb.getInstance().addArtifactInstance(attr);
Assert.fail("addArtifact failed to throw exception for null type"); Assert.fail("addArtifact failed to throw exception for null type");
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -832,8 +820,8 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test null value // Test null value
// This will fail in the CorrelationAttribute constructor // This will fail in the CorrelationAttribute constructor
try { try {
new CorrelationAttribute(fileType, null); new CorrelationAttributeInstance(fileType, null);
Assert.fail("addArtifact failed to throw exception for null value"); Assert.fail("addArtifactInsance failed to throw exception for null value");
} catch (EamDbException ex) { } catch (EamDbException ex) {
// This is the expected behavior // This is the expected behavior
} }
@ -951,7 +939,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test getting frequency of value that is in all three data sources // Test getting frequency of value that is in all three data sources
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, inAllDataSourcesHash); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inAllDataSourcesHash);
int freq = EamDb.getInstance().getFrequencyPercentage(attr); int freq = EamDb.getInstance().getFrequencyPercentage(attr);
assertTrue("getFrequencyPercentage returned " + freq + " - expected 100", freq == 100); assertTrue("getFrequencyPercentage returned " + freq + " - expected 100", freq == 100);
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -961,7 +949,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test getting frequency of value that appears twice in a single data source // Test getting frequency of value that appears twice in a single data source
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, inDataSource1twiceHash); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, inDataSource1twiceHash);
int freq = EamDb.getInstance().getFrequencyPercentage(attr); int freq = EamDb.getInstance().getFrequencyPercentage(attr);
assertTrue("getFrequencyPercentage returned " + freq + " - expected 33", freq == 33); assertTrue("getFrequencyPercentage returned " + freq + " - expected 33", freq == 33);
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -971,7 +959,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test getting frequency of non-file type // Test getting frequency of non-file type
try { try {
CorrelationAttribute attr = new CorrelationAttribute(emailType, emailValue); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(emailType, emailValue);
int freq = EamDb.getInstance().getFrequencyPercentage(attr); int freq = EamDb.getInstance().getFrequencyPercentage(attr);
assertTrue("getFrequencyPercentage returned " + freq + " - expected 33", freq == 33); assertTrue("getFrequencyPercentage returned " + freq + " - expected 33", freq == 33);
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -981,7 +969,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test getting frequency of non-existent value // Test getting frequency of non-existent value
try { try {
CorrelationAttribute attr = new CorrelationAttribute(fileType, "randomValue"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(fileType, "randomValue");
int freq = EamDb.getInstance().getFrequencyPercentage(attr); int freq = EamDb.getInstance().getFrequencyPercentage(attr);
assertTrue("getFrequencyPercentage returned " + freq + " - expected 0", freq == 0); assertTrue("getFrequencyPercentage returned " + freq + " - expected 0", freq == 0);
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -991,7 +979,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test getting frequency with null type // Test getting frequency with null type
try { try {
CorrelationAttribute attr = new CorrelationAttribute(null, "randomValue"); CorrelationAttributeInstance attr = new CorrelationAttributeInstance(null, "randomValue");
EamDb.getInstance().getFrequencyPercentage(attr); EamDb.getInstance().getFrequencyPercentage(attr);
Assert.fail("getFrequencyPercentage failed to throw exception for null type"); Assert.fail("getFrequencyPercentage failed to throw exception for null type");
} catch (EamDbException ex) { } catch (EamDbException ex) {
@ -1008,18 +996,18 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test updating a correlation attribute instance comment // Test updating a correlation attribute instance comment
try { try {
CorrelationAttribute correlationAttribute = EamDb.getInstance().getCorrelationAttribute( CorrelationAttributeInstance correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance(
usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath);
assertNotNull("getCorrelationAttribute returned null", correlationAttribute); assertNotNull("getCorrelationAttribute returned null", correlationAttribute);
correlationAttribute.getInstances().get(0).setComment("new comment"); correlationAttribute.setComment("new comment");
EamDb.getInstance().updateAttributeInstanceComment(correlationAttribute); EamDb.getInstance().updateAttributeInstanceComment(correlationAttribute);
// Get a fresh copy to verify the update. // Get a fresh copy to verify the update.
correlationAttribute = EamDb.getInstance().getCorrelationAttribute( correlationAttribute = EamDb.getInstance().getCorrelationAttributeInstance(
usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath); usbDeviceType, case1, dataSource1fromCase1, devIdValue, devIdPath);
assertEquals("updateAttributeInstanceComment did not set comment to \"new comment\".", assertEquals("updateAttributeInstanceComment did not set comment to \"new comment\".",
"new comment", correlationAttribute.getInstances().get(0).getComment()); "new comment", correlationAttribute.getComment());
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
Assert.fail(ex); Assert.fail(ex);
@ -1099,13 +1087,11 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test running processinstance which queries all rows from instances table // Test running processinstance which queries all rows from instances table
try { try {
// Add two instances to the central repository and use the callback query to verify we can see them // Add two instances to the central repository and use the callback query to verify we can see them
CorrelationAttribute attr = new CorrelationAttribute(fileType, callbackTestFileHash); CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1);
CorrelationAttributeInstance inst1 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, callbackTestFilePath1); CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2);
CorrelationAttributeInstance inst2 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, callbackTestFilePath2);
attr.addInstance(inst1);
attr.addInstance(inst2);
EamDb DbManager = EamDb.getInstance(); EamDb DbManager = EamDb.getInstance();
DbManager.addArtifactInstance(attr); DbManager.addArtifactInstance(attr1);
DbManager.addArtifactInstance(attr2);
AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback();
DbManager.processInstanceTable(fileType, instancetableCallback); DbManager.processInstanceTable(fileType, instancetableCallback);
int count1 = instancetableCallback.getCounter(); int count1 = instancetableCallback.getCounter();
@ -1127,15 +1113,13 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test running processinstance which queries all rows from instances table // Test running processinstance which queries all rows from instances table
try { try {
// Add two instances to the central repository and use the callback query to verify we can see them // Add two instances to the central repository and use the callback query to verify we can see them
CorrelationAttribute attr = new CorrelationAttribute(fileType, callbackTestFileHash); CorrelationAttributeInstance attr1 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath1);
CorrelationAttributeInstance inst1 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, callbackTestFilePath1); CorrelationAttributeInstance attr2 = new CorrelationAttributeInstance(callbackTestFileHash, fileType, case1, dataSource1fromCase1, callbackTestFilePath2);
CorrelationAttributeInstance inst2 = new CorrelationAttributeInstance(case1, dataSource1fromCase1, callbackTestFilePath2);
attr.addInstance(inst1);
attr.addInstance(inst2);
EamDb DbManager = EamDb.getInstance(); EamDb DbManager = EamDb.getInstance();
DbManager.addArtifactInstance(attr); DbManager.addArtifactInstance(attr1);
DbManager.addArtifactInstance(attr2);
AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback(); AttributeInstanceTableCallback instancetableCallback = new AttributeInstanceTableCallback();
DbManager.processInstanceTableWhere(fileType, String.format("id = %s", attr.getID()), instancetableCallback); DbManager.processInstanceTableWhere(fileType, String.format("id = %s", attr1.getID()), instancetableCallback);
int count1 = instancetableCallback.getCounter(); int count1 = instancetableCallback.getCounter();
int count2 = instancetableCallback.getCounterNamingConvention(); int count2 = instancetableCallback.getCounterNamingConvention();
assertTrue("Process Instance count with filepath naming convention: " + count2 + "-expected 2", count2 == 2); assertTrue("Process Instance count with filepath naming convention: " + count2 + "-expected 2", count2 == 2);
@ -1606,7 +1590,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Store the email type object for later use // Store the email type object for later use
try { try {
emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.EMAIL_TYPE_ID); emailType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.EMAIL_TYPE_ID);
assertTrue("getCorrelationTypeById(EMAIL_TYPE_ID) returned null", emailType != null); assertTrue("getCorrelationTypeById(EMAIL_TYPE_ID) returned null", emailType != null);
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
@ -2133,7 +2117,7 @@ public class CentralRepoDatamodelTest extends TestCase {
// Test getting all email reference sets // Test getting all email reference sets
try { try {
List<EamGlobalSet> referenceSets = EamDb.getInstance().getAllReferenceSets(EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.EMAIL_TYPE_ID)); List<EamGlobalSet> referenceSets = EamDb.getInstance().getAllReferenceSets(EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.EMAIL_TYPE_ID));
assertTrue("getAllReferenceSets(EMAIL) returned unexpected number", referenceSets.isEmpty()); assertTrue("getAllReferenceSets(EMAIL) returned unexpected number", referenceSets.isEmpty());
} catch (EamDbException ex) { } catch (EamDbException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);