question

Upvotes
Accepted
3 3 4 8

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?

ema-apijava#technology#productjunit
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
17.5k 35 12 12

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 


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
25k 87 11 23

Hi @daniel.lipofsky

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

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@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.

Upvote
56.3k 145 45 65

@daniel.lipofsky

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);


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 3 4 8

@Jirapongse JUnitTestConnect is part of com.refinitiv.ema.ema.3.6.5.0 but TestUtilities 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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@daniel.lipofsky

The source code of TestUtilities is in the package.

RTSDK Java doesn't provide StaticDecoder. It uses JUnitTestConnect for unit tests.

@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.

Upvotes
56.3k 145 45 65

@daniel.lipofsky

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.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.

@daniel.lipofsky

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.

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

Upvotes
17.5k 35 12 12

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 3 4 8

@wasin.w There is no pom.xml in the Real-Time-SDK project

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
17.5k 35 12 12

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.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.