RestClientBuilder and jUnit >> No RestClientBuilderResolver implementation found!

2,084 views
Skip to first unread message

Ralph Soika

unread,
Apr 29, 2018, 8:00:06 AM4/29/18
to Eclipse MicroProfile
Hi,

how to test a MicroProfile Rest Client with jUnit? I can't find an example. 

I build my test code like this:

 URL apiUrl = new URL(base_uri);
 
MyService docService =
     
RestClientBuilder.newBuilder()
                     
.baseUrl(apiUrl)
                     
.build(MytService.class);


but I got the following exception in junit testing:

java.lang.IllegalStateException: No RestClientBuilderResolver implementation found!
 at org
.eclipse.microprofile.rest.client.spi.RestClientBuilderResolver.instance(RestClientBuilderResolver.java:84)
 at org
.eclipse.microprofile.rest.client.RestClientBuilder.newBuilder(RestClientBuilder.java:41)
 at org
.imixs.workflow.rest.WorkflowClientMicroprofile.getDocumentCustom(WorkflowClientMicroprofile.java:81)
 at org
.imixs.workflow.rest.TestReportServiceMicroprofile.testGetDocument(TestReportServiceMicroprofile.java:36)
 
.....


My maven dependenciesl looks like this: 



 
<dependencies>


 
<!-- JEE Dependencies -->
 
<dependency>
 
<groupId>javax</groupId>
 
<artifactId>javaee-api</artifactId>
 
<version>8.0</version>
 
<scope>provided</scope>
 
</dependency>

.....

 
<!-- microprofile-rest-client-api -->
 
<dependency>
 
<groupId>org.eclipse.microprofile.rest.client</groupId>
 
<artifactId>microprofile-rest-client-api</artifactId>
 
<version>1.0.1</version>
 
</dependency>

 
<!-- JUnit Tests -->
 
<dependency>
 
<groupId>junit</groupId>
 
<artifactId>junit</artifactId>
 
<version>4.8.1</version>
 
<scope>test</scope>
 
</dependency>

 
<!-- JAX-RS 2.0 Test dependencies -->
 
<dependency>
 
<groupId>org.glassfish.jersey.core</groupId>
 
<artifactId>jersey-client</artifactId>
 
<version>2.27</version>
 
<scope>test</scope>
 
</dependency>

 
<dependency>
 
<groupId>org.apache.cxf</groupId>
 
<artifactId>cxf-rt-rs-client</artifactId>
 
<version>3.0.15</version>
 
<scope>test</scope>
 
</dependency>


 
</dependencies>



Can anybody give me a short example?

===
Ralph

Emily Jiang

unread,
Apr 30, 2018, 10:29:11 AM4/30/18
to Eclipse MicroProfile
To make it running as a junit, you need to provide an implementation of RestClientBuilderResolver, which is a kind of bootstrap.

Emily

Andy McCright

unread,
Apr 30, 2018, 4:55:44 PM4/30/18
to Eclipse MicroProfile
Emily is right.  You have the CXF RS Client in the pom.xml, but you will also need the cxf.rt.rs.mp.client artifact - this module contains CXF's MP Rest Client implementation - and it depends on rt-rs-client module that you already import.

If it helps, you can view the pom.xml file that we use with OpenLiberty for running the MP Rest Client TCK at:
(Notice that we use system scope to use the CXF libraries that we re-package in Liberty - unless you are also using Liberty, you will want to change the scope)

Hope this helps,
Andy
Reply all
Reply to author
Forward
0 new messages