Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

class CheckPlatformDetailsTest {

Expand All @@ -28,8 +31,7 @@ void setUp() {
// Helpers
// -----------------------------------------------------------------------

private ProcessProfile makeNode(String name, String ip, String httpPublishAddr,
Set<String> boundAddresses) {
private ProcessProfile makeNode(String name, String ip, String httpPublishAddr, Set<String> boundAddresses) {
ProcessProfile p = new ProcessProfile();
p.name = name;
p.ip = ip;
Expand All @@ -50,8 +52,7 @@ void loopbackInput_fallsBackToNicScan_matchesViaIp() {
// Simulate node whose ip matches what getNetworkInterfaces() would return
// We can't mock the real NIC scan, so we exercise findLocalTargetNode with
// a non-loopback host that equals the node ip directly.
ProcessProfile node = makeNode("NTG-PRO-ELA-01", "172.16.1.61", "172.16.1.61",
new java.util.HashSet<>());
ProcessProfile node = makeNode("NTG-PRO-ELA-01", "172.16.1.61", "172.16.1.61", new HashSet<>());
// Non-loopback host that equals the node ip → added to localNetworkInterfaces
ProcessProfile result = checker.findLocalTargetNode("172.16.1.61", List.of(node));
assertNotNull(result);
Expand All @@ -64,10 +65,8 @@ void loopbackInput_fallsBackToNicScan_matchesViaIp() {

@Test
void matchViaBoundAddresses_returnsCorrectNode() {
ProcessProfile node1 = makeNode("node-1", "10.0.0.1", "10.0.0.1",
new java.util.HashSet<>(Set.of("10.0.0.1")));
ProcessProfile node2 = makeNode("node-2", "10.0.0.2", "10.0.0.2",
new java.util.HashSet<>(Set.of("10.0.0.2")));
ProcessProfile node1 = makeNode("node-1", "10.0.0.1", "10.0.0.1", new HashSet<>(Set.of("10.0.0.1")));
ProcessProfile node2 = makeNode("node-2", "10.0.0.2", "10.0.0.2", new HashSet<>(Set.of("10.0.0.2")));

ProcessProfile result = checker.findLocalTargetNode("10.0.0.2", List.of(node1, node2));
assertEquals("node-2", result.name);
Expand All @@ -79,8 +78,7 @@ void matchViaBoundAddresses_returnsCorrectNode() {

@Test
void emptyBoundAddresses_matchViaIpFallback() {
ProcessProfile node = makeNode("NTG-PRO-ELA-01", "172.16.1.61", "172.16.1.61",
new java.util.HashSet<>());
ProcessProfile node = makeNode("NTG-PRO-ELA-01", "172.16.1.61", "172.16.1.61", new HashSet<>());

ProcessProfile result = checker.findLocalTargetNode("172.16.1.61", List.of(node));
assertNotNull(result);
Expand All @@ -90,8 +88,7 @@ void emptyBoundAddresses_matchViaIpFallback() {
@Test
void emptyBoundAddresses_matchViaHttpPublishAddrFallback() {
// ip and httpPublishAddr differ (NAT / publish_host override scenario)
ProcessProfile node = makeNode("NTG-PRO-ELA-01", "10.0.0.5", "172.16.1.61",
new java.util.HashSet<>());
ProcessProfile node = makeNode("NTG-PRO-ELA-01", "10.0.0.5", "172.16.1.61", new HashSet<>());

// local address matches httpPublishAddr, not ip
ProcessProfile result = checker.findLocalTargetNode("172.16.1.61", List.of(node));
Expand All @@ -105,18 +102,13 @@ void emptyBoundAddresses_matchViaHttpPublishAddrFallback() {

@Test
void multipleNodes_emptyBoundAddresses_returnsCorrectOne() {
ProcessProfile ela01 = makeNode("NTG-PRO-ELA-01", "172.16.1.61", "172.16.1.61",
new java.util.HashSet<>());
ProcessProfile ela02 = makeNode("NTG-PRO-ELA-02", "172.16.1.62", "172.16.1.62",
new java.util.HashSet<>());
ProcessProfile ela03 = makeNode("NTG-PRO-ELA-03", "172.16.1.63", "172.16.1.63",
new java.util.HashSet<>());
ProcessProfile ela04 = makeNode("NTG-PRO-ELA-04", "172.16.1.64", "172.16.1.64",
new java.util.HashSet<>());
ProcessProfile ela01 = makeNode("NTG-PRO-ELA-01", "172.16.1.61", "172.16.1.61", new HashSet<>());
ProcessProfile ela02 = makeNode("NTG-PRO-ELA-02", "172.16.1.62", "172.16.1.62", new HashSet<>());
ProcessProfile ela03 = makeNode("NTG-PRO-ELA-03", "172.16.1.63", "172.16.1.63", new HashSet<>());
ProcessProfile ela04 = makeNode("NTG-PRO-ELA-04", "172.16.1.64", "172.16.1.64", new HashSet<>());

// The local machine is NTG-PRO-ELA-01 (172.16.1.61)
ProcessProfile result = checker.findLocalTargetNode("172.16.1.61",
List.of(ela01, ela02, ela03, ela04));
ProcessProfile result = checker.findLocalTargetNode("172.16.1.61", List.of(ela01, ela02, ela03, ela04));
assertNotNull(result);
assertEquals("NTG-PRO-ELA-01", result.name);
}
Expand All @@ -127,10 +119,8 @@ void multipleNodes_emptyBoundAddresses_returnsCorrectOne() {

@Test
void noMatch_throwsRuntimeException() {
ProcessProfile node = makeNode("node-1", "10.0.0.1", "10.0.0.1",
new java.util.HashSet<>());
ProcessProfile node = makeNode("node-1", "10.0.0.1", "10.0.0.1", new HashSet<>());

assertThrows(RuntimeException.class,
() -> checker.findLocalTargetNode("192.168.99.99", List.of(node)));
assertThrows(RuntimeException.class, () -> checker.findLocalTargetNode("192.168.99.99", List.of(node)));
}
}
Loading