Merge pull request #681 from nsacyber/v3_main-testfail-fixes

Unit Test failures as of 1/22
This commit is contained in:
Cyrus 2024-01-23 12:59:11 -05:00 committed by GitHub
commit 5494714325
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 73 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import lombok.Setter;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Objects;
@Entity @Entity
@Table(name = "Device") @Table(name = "Device")
@ -112,9 +113,33 @@ public class Device extends AbstractEntity {
} }
public String toString() { public String toString() {
return String.format("Device Name: %s%nStatus: %s%nSummary: %s", return String.format("Device Name: %s%nStatus: %s%nSummary: %s%n",
name, healthStatus.getStatus(), name, healthStatus.getStatus(),
supplyChainValidationStatus.toString(), supplyChainValidationStatus.toString(),
summaryId); summaryId);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Device)) {
return false;
}
Device device = (Device) o;
return isStateOverridden == device.isStateOverridden
&& Objects.equals(name, device.name)
&& healthStatus == device.healthStatus
&& supplyChainValidationStatus == device.supplyChainValidationStatus
&& Objects.equals(lastReportTimestamp, device.lastReportTimestamp)
&& Objects.equals(overrideReason, device.overrideReason)
&& Objects.equals(summaryId, device.summaryId);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name, healthStatus,
supplyChainValidationStatus, lastReportTimestamp,
isStateOverridden, overrideReason, summaryId);
}
} }

View File

@ -10,11 +10,12 @@ import lombok.extern.log4j.Log4j2;
import java.io.Serializable; import java.io.Serializable;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Arrays;
import java.util.Objects;
/** /**
* This class is used to represent the network info of a device. * This class is used to represent the network info of a device.
*/ */
@EqualsAndHashCode
@Log4j2 @Log4j2
@Embeddable @Embeddable
public class NetworkInfo implements Serializable { public class NetworkInfo implements Serializable {
@ -112,4 +113,23 @@ public class NetworkInfo implements Serializable {
log.debug("setting MAC address to: {}", sb); log.debug("setting MAC address to: {}", sb);
this.macAddress = macAddress; this.macAddress = macAddress;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NetworkInfo)) {
return false;
}
NetworkInfo that = (NetworkInfo) o;
return Objects.equals(hostname, that.hostname)
&& Objects.equals(ipAddress, that.ipAddress)
&& Arrays.equals(macAddress, that.macAddress);
}
@Override
public int hashCode() {
int result = Objects.hash(hostname, ipAddress);
result = 31 * result + Arrays.hashCode(macAddress);
return result;
}
} }

View File

@ -20,6 +20,7 @@ import lombok.extern.log4j.Log4j2;
import java.io.Serializable; import java.io.Serializable;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Objects;
/** /**
* A <code>DeviceInfoReport</code> is a <code>Report</code> used to transfer the * A <code>DeviceInfoReport</code> is a <code>Report</code> used to transfer the
@ -230,4 +231,27 @@ public class DeviceInfoReport extends AbstractEntity implements Serializable {
private void setTPMInfo(TPMInfo tpmInfo) { private void setTPMInfo(TPMInfo tpmInfo) {
this.tpmInfo = tpmInfo; this.tpmInfo = tpmInfo;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DeviceInfoReport)) {
return false;
}
DeviceInfoReport that = (DeviceInfoReport) o;
return Objects.equals(networkInfo, that.networkInfo)
&& Objects.equals(osInfo, that.osInfo)
&& Objects.equals(firmwareInfo, that.firmwareInfo)
&& Objects.equals(hardwareInfo, that.hardwareInfo)
&& Objects.equals(tpmInfo, that.tpmInfo)
&& Objects.equals(clientApplicationVersion, that.clientApplicationVersion)
&& Objects.equals(paccorOutputString, that.paccorOutputString);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), networkInfo, osInfo,
firmwareInfo, hardwareInfo, tpmInfo,
clientApplicationVersion, paccorOutputString);
}
} }

View File

@ -100,11 +100,11 @@ public final class DeviceTest {
* Tests that retrieving a null LastReportTimestamp will not trigger an exception. * Tests that retrieving a null LastReportTimestamp will not trigger an exception.
*/ */
@Test @Test
public void testNullLastReportTimeStamp() { public void testNotNullLastReportTimeStamp() {
final String name = "my-laptop"; final String name = "my-laptop";
final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport(); final DeviceInfoReport deviceInfo = DeviceInfoReportTest.getTestReport();
final Device device = new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null); final Device device = new Device(name, deviceInfo, HealthStatus.UNKNOWN, AppraisalStatus.Status.UNKNOWN, null, false, null, null);
assertNull(device.getLastReportTimestamp()); assertNotNull(device.getLastReportTimestamp());
} }
/** /**