1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package waffle.util;
25
26 import com.sun.jna.Platform;
27
28 import javax.xml.parsers.ParserConfigurationException;
29
30 import org.junit.jupiter.api.Assertions;
31 import org.junit.jupiter.api.Test;
32 import org.w3c.dom.Document;
33 import org.w3c.dom.Element;
34 import org.w3c.dom.Node;
35 import org.w3c.dom.NodeList;
36
37 import waffle.windows.auth.IWindowsAccount;
38 import waffle.windows.auth.IWindowsAuthProvider;
39 import waffle.windows.auth.IWindowsComputer;
40 import waffle.windows.auth.impl.WindowsAccountImpl;
41 import waffle.windows.auth.impl.WindowsAuthProviderImpl;
42
43
44
45
46 class WaffleInfoTest {
47
48
49
50
51
52
53
54 @Test
55 void testWaffleInfo() throws ParserConfigurationException {
56 final WaffleInfo helper = new WaffleInfo();
57 final Document info = helper.getWaffleInfo();
58
59
60 Assertions.assertEquals(Platform.class.getPackage().getImplementationVersion(),
61 info.getDocumentElement().getAttribute("jna"));
62
63
64 final Node node = info.getDocumentElement().getFirstChild().getFirstChild().getNextSibling();
65
66 Assertions.assertEquals("computer", node.getNodeName());
67
68 final IWindowsAuthProvider auth = new WindowsAuthProviderImpl();
69 final IWindowsComputer computer = auth.getCurrentComputer();
70
71 final NodeList nodes = node.getChildNodes();
72 Assertions.assertEquals(computer.getComputerName(), nodes.item(0).getTextContent());
73 Assertions.assertEquals(computer.getMemberOf(), nodes.item(1).getTextContent());
74 Assertions.assertEquals(computer.getJoinStatus(), nodes.item(2).getTextContent());
75
76
77 String lookup = WindowsAccountImpl.getCurrentUsername();
78 final IWindowsAccount account = new WindowsAccountImpl(lookup);
79 Element elem = helper.getLookupInfo(info, lookup);
80 Assertions.assertEquals(lookup, elem.getAttribute("name"));
81 Assertions.assertEquals(account.getName(), elem.getFirstChild().getTextContent());
82
83
84 lookup = "__UNKNOWN_ACCOUNT_NAME___";
85 elem = helper.getLookupInfo(info, lookup);
86 Assertions.assertEquals(lookup, elem.getAttribute("name"));
87 Assertions.assertEquals("exception", elem.getFirstChild().getNodeName());
88 }
89 }