-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #1254
- Loading branch information
1 parent
7f49b8d
commit 6a67a12
Showing
3 changed files
with
144 additions
and
137 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
...n-tests/src/test/java/org/eclipse/milo/opcua/sdk/server/api/util/AttributeWriterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package org.eclipse.milo.opcua.sdk.server.api.util; | ||
|
||
import org.eclipse.milo.opcua.sdk.core.AccessLevel; | ||
import org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode; | ||
import org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest; | ||
import org.eclipse.milo.opcua.stack.core.Identifiers; | ||
import org.eclipse.milo.opcua.stack.core.StatusCodes; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; | ||
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class AttributeWriterTest extends AbstractClientServerTest { | ||
|
||
@Test | ||
void writeNullAllowed() throws Exception { | ||
StatusCode statusCode = client.writeValue( | ||
new NodeId(2, "AllowNulls"), | ||
DataValue.valueOnly(Variant.NULL_VALUE) | ||
).get(); | ||
|
||
assertEquals(StatusCode.GOOD, statusCode); | ||
} | ||
|
||
@Test | ||
void writeNullDisallowed() throws Exception { | ||
StatusCode statusCode = client.writeValue( | ||
new NodeId(2, "DisallowNulls"), | ||
DataValue.valueOnly(Variant.NULL_VALUE) | ||
).get(); | ||
|
||
assertEquals(new StatusCode(StatusCodes.Bad_TypeMismatch), statusCode); | ||
} | ||
|
||
@Test | ||
void writeNullNotConfigured() throws Exception { | ||
// Default behavior when AllowNulls property is not configured is to reject null values. | ||
StatusCode statusCode = client.writeValue( | ||
new NodeId(2, "AllowNullsNotConfigured"), | ||
DataValue.valueOnly(Variant.NULL_VALUE) | ||
).get(); | ||
|
||
assertEquals(new StatusCode(StatusCodes.Bad_TypeMismatch), statusCode); | ||
} | ||
|
||
@Test | ||
void writeByteStringToUByteArray() throws Exception { | ||
StatusCode statusCode = client.writeValue( | ||
new NodeId(2, "UByteArray"), | ||
DataValue.valueOnly(new Variant(ByteString.of(new byte[]{1, 2, 3}))) | ||
).get(); | ||
|
||
assertEquals(StatusCode.GOOD, statusCode); | ||
} | ||
|
||
@BeforeAll | ||
void configure() { | ||
testNamespace.configureNode((context, nodeManager) -> { | ||
UaVariableNode allowNulls = UaVariableNode.build( | ||
context, | ||
b -> { | ||
b.setNodeId(new NodeId(2, "AllowNulls")); | ||
b.setBrowseName(new QualifiedName(2, "AllowNulls")); | ||
b.setDisplayName(LocalizedText.english("AllowNulls")); | ||
b.setDataType(Identifiers.String); | ||
b.setAccessLevel(AccessLevel.READ_WRITE); | ||
b.setUserAccessLevel(AccessLevel.READ_WRITE); | ||
return b.buildAndAdd(); | ||
} | ||
); | ||
|
||
allowNulls.setAllowNulls(true); | ||
|
||
UaVariableNode disallowNulls = UaVariableNode.build( | ||
context, | ||
b -> { | ||
b.setNodeId(new NodeId(2, "DisallowNulls")); | ||
b.setBrowseName(new QualifiedName(2, "DisallowNulls")); | ||
b.setDisplayName(LocalizedText.english("DisallowNulls")); | ||
b.setDataType(Identifiers.String); | ||
b.setAccessLevel(AccessLevel.READ_WRITE); | ||
b.setUserAccessLevel(AccessLevel.READ_WRITE); | ||
return b.buildAndAdd(); | ||
} | ||
); | ||
|
||
disallowNulls.setAllowNulls(false); | ||
|
||
UaVariableNode.build( | ||
context, | ||
b -> { | ||
b.setNodeId(new NodeId(2, "AllowNullsNotConfigured")); | ||
b.setBrowseName(new QualifiedName(2, "AllowNullsNotConfigured")); | ||
b.setDisplayName(LocalizedText.english("AllowNullsNotConfigured")); | ||
b.setDataType(Identifiers.String); | ||
b.setAccessLevel(AccessLevel.READ_WRITE); | ||
b.setUserAccessLevel(AccessLevel.READ_WRITE); | ||
return b.buildAndAdd(); | ||
} | ||
); | ||
|
||
UaVariableNode.build( | ||
context, | ||
b -> { | ||
b.setNodeId(new NodeId(2, "UByteArray")); | ||
b.setBrowseName(new QualifiedName(2, "UByteArray")); | ||
b.setDisplayName(LocalizedText.english("UByteArray")); | ||
b.setDataType(Identifiers.Byte); | ||
b.setArrayDimensions(new UInteger[]{UInteger.valueOf(0)}); | ||
b.setAccessLevel(AccessLevel.READ_WRITE); | ||
b.setUserAccessLevel(AccessLevel.READ_WRITE); | ||
return b.buildAndAdd(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 0 additions & 133 deletions
133
.../sdk-server/src/test/java/org/eclipse/milo/opcua/sdk/server/util/AttributeWriterTest.java
This file was deleted.
Oops, something went wrong.