|
10 | 10 |
|
11 | 11 | package org.eclipse.milo.opcua.sdk.client; |
12 | 12 |
|
| 13 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
13 | 14 | import static org.junit.jupiter.api.Assertions.assertThrows; |
14 | 15 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 16 | +import static org.mockito.ArgumentMatchers.any; |
| 17 | +import static org.mockito.ArgumentMatchers.anyDouble; |
| 18 | +import static org.mockito.ArgumentMatchers.anyList; |
| 19 | +import static org.mockito.Mockito.mock; |
| 20 | +import static org.mockito.Mockito.when; |
15 | 21 |
|
| 22 | +import java.util.List; |
16 | 23 | import org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest; |
17 | 24 | import org.eclipse.milo.opcua.stack.core.UaException; |
| 25 | +import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; |
| 26 | +import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; |
| 27 | +import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort; |
18 | 28 | import org.junit.jupiter.api.Test; |
19 | 29 |
|
20 | 30 | public class OperationLimitsTest extends AbstractClientServerTest { |
@@ -43,4 +53,69 @@ void readThrowsWhenDisconnected() throws UaException { |
43 | 53 |
|
44 | 54 | assertThrows(UaException.class, () -> client.readOperationLimits()); |
45 | 55 | } |
| 56 | + |
| 57 | + @Test |
| 58 | + void readHandlesUShortValues() throws UaException { |
| 59 | + // Create a mock client that returns UShort values instead of UInteger |
| 60 | + var mockClient = mock(OpcUaClient.class); |
| 61 | + |
| 62 | + // Create DataValues with UShort values (simulating a server that returns the wrong type) |
| 63 | + var values = |
| 64 | + List.of( |
| 65 | + new DataValue(new Variant(UShort.valueOf(100))), // maxNodesPerRead |
| 66 | + new DataValue(new Variant(UShort.valueOf(200))), // maxNodesPerWrite |
| 67 | + new DataValue(new Variant(UShort.valueOf(300))), // maxNodesPerMethodCall |
| 68 | + new DataValue(new Variant(UShort.valueOf(400))), // maxNodesPerBrowse |
| 69 | + new DataValue(new Variant(UShort.valueOf(500))), // maxNodesPerRegisterNodes |
| 70 | + new DataValue( |
| 71 | + new Variant(UShort.valueOf(600))), // maxNodesPerTranslateBrowsePathsToNodeIds |
| 72 | + new DataValue(new Variant(UShort.valueOf(700))), // maxNodesPerNodeManagement |
| 73 | + new DataValue(new Variant(UShort.valueOf(800))), // maxMonitoredItemsPerCall |
| 74 | + new DataValue(new Variant(UShort.valueOf(900))), // maxNodesPerHistoryReadData |
| 75 | + new DataValue(new Variant(UShort.valueOf(1000))), // maxNodesPerHistoryReadEvents |
| 76 | + new DataValue(new Variant(UShort.valueOf(1100))), // maxNodesPerHistoryUpdateData |
| 77 | + new DataValue(new Variant(UShort.valueOf(1200)))); // maxNodesPerHistoryUpdateEvents |
| 78 | + |
| 79 | + when(mockClient.readValues(anyDouble(), any(), anyList())).thenReturn(values); |
| 80 | + |
| 81 | + // Call the static read method with our mock |
| 82 | + var operationLimits = OperationLimits.read(mockClient); |
| 83 | + |
| 84 | + // Verify all values are present and correctly converted from UShort to UInteger |
| 85 | + assertTrue(operationLimits.maxNodesPerRead().isPresent()); |
| 86 | + assertEquals(100, operationLimits.maxNodesPerRead().get().intValue()); |
| 87 | + |
| 88 | + assertTrue(operationLimits.maxNodesPerWrite().isPresent()); |
| 89 | + assertEquals(200, operationLimits.maxNodesPerWrite().get().intValue()); |
| 90 | + |
| 91 | + assertTrue(operationLimits.maxNodesPerMethodCall().isPresent()); |
| 92 | + assertEquals(300, operationLimits.maxNodesPerMethodCall().get().intValue()); |
| 93 | + |
| 94 | + assertTrue(operationLimits.maxNodesPerBrowse().isPresent()); |
| 95 | + assertEquals(400, operationLimits.maxNodesPerBrowse().get().intValue()); |
| 96 | + |
| 97 | + assertTrue(operationLimits.maxNodesPerRegisterNodes().isPresent()); |
| 98 | + assertEquals(500, operationLimits.maxNodesPerRegisterNodes().get().intValue()); |
| 99 | + |
| 100 | + assertTrue(operationLimits.maxNodesPerTranslateBrowsePathsToNodeIds().isPresent()); |
| 101 | + assertEquals(600, operationLimits.maxNodesPerTranslateBrowsePathsToNodeIds().get().intValue()); |
| 102 | + |
| 103 | + assertTrue(operationLimits.maxNodesPerNodeManagement().isPresent()); |
| 104 | + assertEquals(700, operationLimits.maxNodesPerNodeManagement().get().intValue()); |
| 105 | + |
| 106 | + assertTrue(operationLimits.maxMonitoredItemsPerCall().isPresent()); |
| 107 | + assertEquals(800, operationLimits.maxMonitoredItemsPerCall().get().intValue()); |
| 108 | + |
| 109 | + assertTrue(operationLimits.maxNodesPerHistoryReadData().isPresent()); |
| 110 | + assertEquals(900, operationLimits.maxNodesPerHistoryReadData().get().intValue()); |
| 111 | + |
| 112 | + assertTrue(operationLimits.maxNodesPerHistoryReadEvents().isPresent()); |
| 113 | + assertEquals(1000, operationLimits.maxNodesPerHistoryReadEvents().get().intValue()); |
| 114 | + |
| 115 | + assertTrue(operationLimits.maxNodesPerHistoryUpdateData().isPresent()); |
| 116 | + assertEquals(1100, operationLimits.maxNodesPerHistoryUpdateData().get().intValue()); |
| 117 | + |
| 118 | + assertTrue(operationLimits.maxNodesPerHistoryUpdateEvents().isPresent()); |
| 119 | + assertEquals(1200, operationLimits.maxNodesPerHistoryUpdateEvents().get().intValue()); |
| 120 | + } |
46 | 121 | } |
0 commit comments