creating FieldEntry for unit tests

I'm using EMA Java 3.6.5.0 and I would like to write some unit tests. I see elsewhere descriptions on how to use replayers or mock providers, which are really more like integration tests, but I am wanting to write some simple unit tests that run with junit at compile time and do not require spinning up a separate process, so I want to create a FieldEntry and pass it to my methods. I tried the following
FieldEntry field = EmaFactory.createFieldEntry().real(1234, 999, OmmReal.MagnitudeType.EXPONENT_NEG_2);
System.out.println(field.toString());
System.out.println("id="+field.fieldId());
System.out.println("load="+field.load());
System.out.println("code="+field.code());
FieldEntry field = EmaFactory.createFieldEntry().codeReal(5678);
System.out.println(field.toString());
System.out.println("id="+field.fieldId());
System.out.println("load="+field.load());
System.out.println("code="+field.code());
But load()
is null
and code()
throws NullPointerException and toString()
returns "Decoding of just encoded object in the same application is not supported".
How can I do this?
Best Answer
-
Hello @daniel.lipofsky
Please be informed that GitHub-Issue #197 is available on the RTSDK version 2.0.7.L2. You can build the test jar with the following command:
gradlew packageTests
0
Answers
-
As stated in the error message, EMA does not support the decoding of a just encoded message.
However, if you refer to the existing EMA C++ post below - this may help you achieve something similar in EMA Java
decode of just encoded object in EMA C++ - Forum | Refinitiv Developer Community
0 -
@umer.nalla that C++ example relies on the import of a StaticDecoder class. Is there an equivalent in Java? I don't see anything similarly named.
0 -
I checked and found that the RTSDK Java package provides JUnitTestConnect.
You can see the examples in the Java\Ema\Core\src\test\java\com\refinitiv\ema\unittest directory, such as FieldListTests.java.
// Decode FieldList with EMA.
com.refinitiv.ema.access.FieldList fl = JUnitTestConnect.createFieldList();
JUnitTestConnect.setRsslData(fl, buf, Codec.majorVersion(), Codec.minorVersion(), TestUtilities.getDataDictionary(), null);0 -
@Jirapongse
JUnitTestConnect
is part ofcom.refinitiv.ema.ema.3.6.5.0
butTestUtilities
is not. Is this included in another JAR?@umer.nalla I do not see any Java equivalent to that C++ StaticDecoder class you linked to.
0 -
The source code of TestUtilities is in the package.
RTSDK Java doesn't provide StaticDecoder. It uses JUnitTestConnect for unit tests.
0 -
@Jirapongse I see TestUtilities in the SDK code but not in the JAR. I assume if I built the test JAR myself I would see it, but is there a reason you don't push the test jar to maven central (search.maven.org)? That would make it much more convenient. I am trying to build it myself, but I am running into cert issues, and since I don't normally use gradle I do not know how to troubleshoot.
0 -
The TestUtilities class contains the code for our unit tests. It implements the encoding and decoding logic for test data used by the unit tests.
Typically, users need to implement their own encoding and decoding logic to test their specific data. I think this is why it wasn't included in the jar file.
0 -
Usually SDKs exist so that users don't have to implement their own encoding and decoding logic. That's a huge level of effort and a user shouldn't have to understand the underlying encoding/decoding details to implement a simple unit test.
0 -
Yes, you are correct. However, EMA has a limitation that "Decoding of just encoded object in the same application is not supported".
Therefore, to create a field list for unit tests, we need ETA to encode the test data into a buffer. Then, use JUnitTestConnect to create a filed list and encode the buffer into the field list. Finally, use EMA to decode the field list.
0 -
please then consider this a feature request: please add a utility to make it easy for your users to do this. It can be in a test jar, but it would be nice if that jar was published to maven central
0 -
Hello @daniel.lipofsky
I found that you have submitted issues-197 on GitHub to the development team.
If you are using Maven, please be informed that you can build the code in Java/Ema/Core/src/test/ folder by adding the following dependencies in the pom.xml file
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
</dependency>Hope this helps.
0 -
@wasin.w There is no
pom.xml
in the Real-Time-SDK project0 -
Hello @daniel.lipofsky
The RTSDK comes with Gradle build system/script by default. However, as the SDK libraries are available on the Maven central, so you can use the RTSDK with your Maven pom.xml as the following example:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.refinitiv.ema</groupId>
<artifactId>RTSDKJ_Maven</artifactId>
<version>1.0</version>
<name>RTSDKJ_Maven</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<rtsdk.version>3.6.5.0</rtsdk.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>com.refinitiv.ema</groupId>
<artifactId>ema</artifactId>
<version>${rtsdk.version}</version>
</dependency>
</dependencies>
</project>You can find more detail in the How to Set Up Refinitiv Real-Time SDK Java Application with Maven article.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 616 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 557 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 654 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 229 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛