Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Create dynamic structure for testing
January 21, 2019
17:48, EEST
Forum Posts: 68
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

we want to use the new features of ExtensionObject’s in our OPC UA Client product. Now i want to write some unit tests for my code. Is it possible to create a valid dynamic structure for testing?
Could you maybe provide some example code how to create a valid DynamicStructure.



January 22, 2019
14:11, EEST
Bjarne Boström
Forum Posts: 336
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline


It is primarily intended as return value from TypeDictionary, i.e. constructing it is somewhat SDK internals. However it should be doable manually as well, but the current constructors are quite ugly to use, depending on what kind of fields your Structure does have (e.g. are they known/standard types?) and how exactly your code interacts with it?

Do you need the encoded binary format or is interacting with the DynamicStructure object enough?
Do you need a real DynamicStructure, or could you just mock it?

If a mock is enough, you could use e.g. https://site.mockito.org/, and for example

//typically these are imported as static in tests
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
//note that I only added static imports for the forum in this example, it will have normal imports as well

public void example() throws Exception {
DynamicStructure ds = mock(DynamicStructure.class);

// You need to mock all return values you need, see mockito manuals for more info

// Simulating your code interacting with the DynamicStructure instance
assertEquals("TESTVALUE", ds.get("AA")); //your code would get the "TESTVALUE" if it asked ds.get("AA")
ds.set("Name", "Value"); // e.g. your code could call this
verify(ds).set("Name", "Value"); // verifies that your code did call this

Do note that multidimensional fields are not possible (as they were added in UA 1.04, which the current release version does not yet support).

January 22, 2019
17:11, EEST
Forum Posts: 68
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi Bjarne,
thanks for the example. Yes i only need to handle the DynamicStructure. Our code converts ExtensionObjects into JSON in a generic way and vise versa. So i need to create a DynamicStructure and pass it to the converter Method and look at the json that is created. Your approach looks nice i will see how far i will come with that..


Forum Timezone: Europe/Helsinki

Most Users Ever Online: 78

Currently Online:
9 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 89

pramanj: 86

ibrahim: 68

kapsl: 57

gjevremovic: 49

TimK: 41

Fransua33: 39

fred: 36

Rainer Versteeg: 32

vonGohren: 25

Member Stats:

Guest Posters: 0

Members: 815

Moderators: 11

Admins: 1

Forum Stats:

Groups: 3

Forums: 14

Topics: 841

Posts: 3556

Newest Members:

waldlatscher, keithwalmar, shanjaved, opcua-user, DmitryPervukhin, DPer, YeaTeshy, marttin, bouncycastlerentals, Sayan B

Moderators: Jouni Aro: 824, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 336, Heikki Tahvanainen: 402, Jukka Asikainen: 1, Teppo Uimonen: 14

Administrators: admin: 0