-
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.
Allow writing
null
when "AllowNulls" Property is true
fixes #1254
- Loading branch information
1 parent
7f49b8d
commit 463cd44
Showing
2 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
...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,100 @@ | ||
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.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.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); | ||
} | ||
|
||
@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(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
} |
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