Skip to content

Commit

Permalink
Merge pull request #136 from andymc12/126-configProviders
Browse files Browse the repository at this point in the history
Issue 126: New tests for providers set in MP Config
  • Loading branch information
andymc12 authored Dec 5, 2018
2 parents 0cd3134 + c612336 commit d0c792f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipse.microprofile.rest.client.tck.WiremockArquillianTest;
import org.eclipse.microprofile.rest.client.tck.interfaces.InterfaceBase;
import org.eclipse.microprofile.rest.client.tck.interfaces.InterfaceWithProvidersDefined;
import org.eclipse.microprofile.rest.client.tck.interfaces.InterfaceWithoutProvidersDefined;
import org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilter;
import org.eclipse.microprofile.rest.client.tck.providers.TestClientResponseFilter;
import org.eclipse.microprofile.rest.client.tck.providers.TestMessageBodyReader;
import org.eclipse.microprofile.rest.client.tck.providers.TestMessageBodyWriter;
import org.eclipse.microprofile.rest.client.tck.providers.TestParamConverterProvider;
import org.eclipse.microprofile.rest.client.tck.providers.TestReaderInterceptor;
import org.eclipse.microprofile.rest.client.tck.providers.TestWriterInterceptor;
import org.jboss.arquillian.container.test.api.Deployment;
Expand All @@ -49,30 +53,65 @@
import static org.testng.Assert.assertEquals;

/**
* Verifies via CDI injection that you can use a programmatic interface. Verifies that the interface includes registered providers.
* Verifies via CDI injection that you can use a programmatic interface.
* Verifies that the interface includes registered providers.
* Also verifies that providers registered via MicroProfile Config are honored.
*/
public class CDIInvokeWithRegisteredProvidersTest extends WiremockArquillianTest {
@Inject
@RestClient
private InterfaceWithProvidersDefined api;
private InterfaceWithProvidersDefined clientProvidersViaAnnotation;

@Inject
@RestClient
private InterfaceWithoutProvidersDefined clientProvidersViaMPConfig;

@Deployment
public static WebArchive createDeployment() {
String propertyName = InterfaceWithProvidersDefined.class.getName()+"/mp-rest/url";
String value = getStringURL();
String urlPropName1 = InterfaceWithProvidersDefined.class.getName() + "/mp-rest/url";
String urlPropName2 = InterfaceWithoutProvidersDefined.class.getName() + "/mp-rest/url";
String urlValue = getStringURL();
String simpleName = CDIInvokeWithRegisteredProvidersTest.class.getSimpleName();
String providersPropName = InterfaceWithoutProvidersDefined.class.getName() + "/mp-rest/providers";
String providersValue = TestClientRequestFilter.class.getName() + "," +
TestClientResponseFilter.class.getName() + "," +
TestMessageBodyReader.class.getName() + "," +
TestMessageBodyWriter.class.getName() + "," +
TestParamConverterProvider.class.getName() + "," +
TestReaderInterceptor.class.getName() + "," +
TestWriterInterceptor.class.getName();
String propsFile = String.format(urlPropName1+"="+urlValue+"%n" +
urlPropName2+"="+urlValue+"%n" +
providersPropName+"="+providersValue);
System.out.println("ANDY propsFile: " + propsFile);
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, simpleName + ".jar")
.addClasses(InterfaceWithProvidersDefined.class, WiremockArquillianTest.class)
.addClasses(InterfaceWithProvidersDefined.class,
InterfaceWithoutProvidersDefined.class,
InterfaceBase.class,
WiremockArquillianTest.class)
.addPackage(TestClientResponseFilter.class.getPackage())
.addAsManifestResource(new StringAsset(propertyName+"="+value), "microprofile-config.properties")
.addAsManifestResource(new StringAsset(propsFile), "microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
return ShrinkWrap.create(WebArchive.class, simpleName + ".war")
.addAsLibrary(jar)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

//@BeforeTest
//public void resetWiremock() {
// setupServer();
//}
@Test
public void testInvokesPostOperation() throws Exception{
public void testInvokesPostOperation_viaAnnotation() throws Exception {
testInvokesPostOperation(clientProvidersViaAnnotation);
}

@Test
public void testInvokesPostOperation_viaMPConfig() throws Exception {
testInvokesPostOperation(clientProvidersViaMPConfig);
}

private void testInvokesPostOperation(InterfaceBase api) throws Exception{
String inputBody = "input body will be removed";
String outputBody = "output body will be removed";
String expectedReceivedBody = "this is the replaced writer "+inputBody;
Expand All @@ -89,7 +128,7 @@ public void testInvokesPostOperation() throws Exception{

assertEquals(body, expectedResponseBody);

verify(1, postRequestedFor(urlEqualTo("/")).withRequestBody(equalTo(expectedReceivedBody)));
verify(postRequestedFor(urlEqualTo("/")).withRequestBody(equalTo(expectedReceivedBody)));

assertEquals(TestClientResponseFilter.getAndResetValue(),1);
assertEquals(TestClientRequestFilter.getAndResetValue(),1);
Expand All @@ -98,7 +137,16 @@ public void testInvokesPostOperation() throws Exception{
}

@Test
public void testInvokesPutOperation() throws Exception {
public void testInvokesPutOperation_viaAnnotation() throws Exception {
testInvokesPutOperation(clientProvidersViaAnnotation);
}

@Test
public void testInvokesPutOperation_viaMPConfig() throws Exception {
testInvokesPutOperation(clientProvidersViaMPConfig);
}

private void testInvokesPutOperation(InterfaceBase api) throws Exception {
String inputBody = "input body will be removed";
String outputBody = "output body will be removed";
String expectedReceivedBody = "this is the replaced writer "+inputBody;
Expand All @@ -117,7 +165,7 @@ public void testInvokesPutOperation() throws Exception {

assertEquals(body, expectedResponseBody);

verify(1, putRequestedFor(urlEqualTo("/"+expectedId)).withRequestBody(equalTo(expectedReceivedBody)));
verify(putRequestedFor(urlEqualTo("/"+expectedId)).withRequestBody(equalTo(expectedReceivedBody)));

assertEquals(TestClientResponseFilter.getAndResetValue(),1);
assertEquals(TestClientRequestFilter.getAndResetValue(),1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2018 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.eclipse.microprofile.rest.client.tck.interfaces;

import javax.ws.rs.core.Response;

public interface InterfaceBase {

Response executePost(String body);

Response executePut(String id, String body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
@RegisterRestClient
public interface InterfaceWithProvidersDefined {
public interface InterfaceWithProvidersDefined extends InterfaceBase {
@POST
@Override
Response executePost(String body);

@PUT
@Path("/{id}")
@Override
Response executePut(@PathParam("id") String id, String body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@Path("/")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public interface InterfaceWithoutProvidersDefined {
@RegisterRestClient
public interface InterfaceWithoutProvidersDefined extends InterfaceBase {

@POST
@Override
Response executePost(String body);

@PUT
@Path("/{id}")
@Override
Response executePut(@PathParam("id") String id, String body);
}

0 comments on commit d0c792f

Please sign in to comment.