I have a service/dao layer. Service layer method calls 1st method of dao from which I get response and call the second method in dao passing some arguments including the value from the response of 1st dao method. I tried using mock but its failing with null pointer.
pseudo code is something like below:
Service{
serviceMethod(some_args){
response1 = dao.method1(some_args);
someItem = response1.get("someItem");
/* do some logic on someitem to create otherItem*/
request2.setArgs(someItem);
response2 = dao.method2(request2);
}
}
I have tried to mock as below but its not working.
#Test
public void testPass(){
mockResponse1 = new Response1();
mockRequest2 = new MockRequest2();
when(dao.method1(some_args)).thenReturn(mockResponse1)
mockResponse1.setArgs(some_args);
mockRequest2.setArgs(mockResponse1.getargs());
mockResponse2 = new Response2();
when(dao.method2(mockRequest2)).thenReturn(mockResponse2)
service.serviceMethod(some_args)
}
You could use an ArgumentCaptor to get the value that was passed into dao.method2(...) and then make assertions on that.
For example, say I had this DAO...
public interface DAO {
Response method1(Request request);
Response method2(Request request);
}
And this service...
public class Service {
private DAO dao;
public void setDao(DAO dao) {
this.dao = dao;
}
public Response serviceMethod(Request someArgs) {
Response response1 = dao.method1(someArgs);
String someItem = response1.getTheResponse();
Request request2 = new Request(someItem);
return dao.method2(request2);
}
}
A test for this service could be...
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
public class ServiceTest {
#Mock
private Request request;
#Mock
private Response response;
#Mock
private Response serviceResponse;
#Mock
private DAO dao;
#InjectMocks
private Service service;
#Captor
private ArgumentCaptor<Request> requestCaptor;
#Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
#Test
public void shouldDoServiceMethod() {
// Set up
when(dao.method1(request)).thenReturn(response);
when(response.getTheResponse()).thenReturn("[ARGUMENT]");
when(dao.method2(any(Request.class))).thenReturn(serviceResponse);
// Code under test
Response actualResponse = service.serviceMethod(request);
// Verification
assertThat(actualResponse).isSameAs(serviceResponse);
verify(dao).method2(requestCaptor.capture());
Request actualSecondRequest = requestCaptor.getValue();
assertThat(actualSecondRequest.getArgs()).isEqualTo("[ARGUMENT]");
}
}
The key line being...
verify(dao).method2(requestCaptor.capture());
This verifies that method2 was called and captures the value that it was called with.
You then get the value...
Request actualSecondRequest = requestCaptor.getValue();
...and you can then verify that the relevant information was set...
assertThat(actualSecondRequest.getArgs()).isEqualTo("[ARGUMENT]");
Hope this helps.
For completeness, here's Request and Response...
public class Request {
private String args;
public Request(String args) {
this.args = args;
}
public String getArgs() {
return args;
}
}
public class Response {
private String theResponse;
public Response(String theResponse) {
this.theResponse = theResponse;
}
public String getTheResponse() {
return theResponse;
}
}
Related
I have a class that implements javax.ws.rs.client.ClientRequestFilter:
public class CustomFilter implements ClientRequestFilter {
#Override
public void filter(ClientRequestContext context) throws IOException {
URI newUri = ... //replace a new uri
context.setUri(URI.create(newUri));
if (context.getMethod == "POST") {
context.setMethod("GET");
context.getHeaders().putSingle("ID","some string");
}
}
What I want is somehow to mock the ClientRequestContext. I want to compare that after calling the filter() function:
The new uri is set correctly.
The new http method is set correctly.
A new header "ID" is set with "some string" for the context.
As I tried to figure out, I can only mock the getter methods, and I do not know how to mock ClientRequestContext properly and use my CustomerFilter class to call the real function filter() to change values of the ClientRequestContext object since it is an interface. Could you help me to achieve the 3 requirements?
The class ClientRequestFilter is an interface, so you can mock it either using the static Mockito.mock method or annotating the field as #Mock in the test. So, if you want to check if the setUri method is called, you should do the following in your test method:
CustomFilter customFilter = new CustomFilter();
customFilter.filter(context);
Mockito.verify(context, Mockito.once()).setUri(ArgumentMatchers.any(URI.class));
For older Mockito versions:
CustomFilter customFilter = new CustomFilter();
customFilter.filter(context);
Mockito.verify(context, Mockito.once()).setUri(Matchers.any());
You don't have to verify that the underlying implementation is working. Since you are using an interface you will trust that the implementation that you will have at runtime is correct, because it is not necessary to test you dependencies. You simply have to be sure that the code you wrote is working and is forwarding requests to other classes.
In similar way you can test the other requirement:
Mockito.when(context.getMethod()).thenReturn("POST");
MultivaluedMap headers = Mockito.mock(MultivaluedMap.class);
Mockito.when(context.getHeaders()).thenReturn(headers);
CustomFilter customFilter = new CustomFilter();
customFilter.filter(context);
Mockito.verify(context, Mockito.once()).setUri(Matchers.any());
Mockito.verify(context, Mockito.once()).setMethod(Matchers.any());
Mockito.verify(context, Mockito.once()).getHeaders();
You can use argument mockito matchers and/or argument captors. Or you cat write a stub for request context and spy on it:
package test;
import org.junit.Test;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.net.URI;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.mockito.Mockito.*;
public class ClientRequestContextTest {
abstract static class ClientRequestContextStub implements ClientRequestContext {
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
URI uri = null;
String method = null;
ClientRequestContextStub(){}
#Override public String getMethod() { return method; }
#Override public void setMethod(String method) { this.method = method; }
#Override public URI getUri() { return uri; }
#Override public void setUri(URI uri) { this.uri = uri; }
#Override public MultivaluedMap<String, Object> getHeaders() { return headers; }
}
static class CustomFilter implements ClientRequestFilter {
private String newUri = null;
CustomFilter(String newUri) { this.newUri = newUri; }
#Override
public void filter(ClientRequestContext context) throws IOException {
context.setUri(URI.create(newUri));
if (context.getMethod().equals("POST")) {
context.setMethod("GET");
context.getHeaders().putSingle("ID", "some string");
}
}
}
#Test
public void checkCustomFilter() throws IOException {
URI newUriValue = URI.create("https://user:password#localhost:12345/suffix");
ClientRequestContext context = spy(ClientRequestContextStub.class);
context.setUri(URI.create("localhost:8080"));
context.setMethod("POST");
assertThat(context.getMethod(), equalTo("POST"));
assertThat(context.getUri().toString(), equalTo("localhost:8080"));
assertThat(context.getHeaders().size(), equalTo(0));
new CustomFilter(newUriValue.toString()).filter(context);
assertThat(context.getMethod(), equalTo("GET"));
assertThat(context.getUri(), equalTo(newUriValue));
assertThat(context.getHeaders().size(), equalTo(1));
assertThat(context.getHeaders().getFirst("ID").toString(), is("some string"));
}
}
I have an actor class EmployeeActor, inside that actor, some other actor is fired using payrollRunActor.tell(). I need to write a JUnit test for EmployeeActor.java, but I don't want to fire payrollRunActor.tell(), means I want to mock it.
Is there a way to do it? I tried a lot, but real payrollRunActor is getting fired.
Here is the actual code of my EmployeeActor class.
package com.test.periodic.actors;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.test.avs.domain.boundedcontext.Employee;
import com.test.avs.domain.boundedcontext.PayrollRun;
import com.test.entity.BusinessDTO;
import com.test.periodic.actors.aggregrators.EmployeeAggregator;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.routing.RoundRobinPool;
public class EmployeeActor extends AbstractActor {
private static final Logger logger = LoggerFactory.getLogger(EmployeeActor.class);
private boolean rollup;
public static Props props() {
return Props.create(EmployeeActorTest.class);
}
private List<PayrollRun> payrollRuns;
private String instanceId;
private String employeeAggregatorId;
private Employee employee;
private ActorRef organizationAggregatorActor;
private List<BusinessDTO> businessDTOs;
final ActorSystem payrollRunSystem = ActorSystem.create("payrollRun");
ActorRef employeeAggregator;
public EmployeeActor(ActorRef organizationAggregatorActor, List<PayrollRun> payrollRuns,
Employee employee, List<BusinessDTO> businessDTOs, boolean rollup) {
this.payrollRuns = payrollRuns;
this.employee = employee;
this.organizationAggregatorActor = organizationAggregatorActor;
this.businessDTOs = businessDTOs;
this.rollup = rollup;
}
#Override
public void preStart() throws Exception {
instanceId = RandomStringUtils.randomAlphanumeric(6);
employeeAggregatorId = "employeeAggregator-" + instanceId;
employeeAggregator = getContext().system().actorOf(
Props.create(EmployeeAggregator.class, organizationAggregatorActor, employee),
employeeAggregatorId);
super.preStart();
}
#Override
public Receive createReceive() {
return receiveBuilder().match(Employee.class, employee -> {
if (rollup) {
logger.info("Rollingup business entities.");
employeeAggregator.tell(employee, getSelf());
} else {
ActorRef payrollRunActor = payrollRunSystem.actorOf(new RoundRobinPool(payrollRuns.size())
.props(Props.create(PayrollRunActor.class, employeeAggregator, employee, businessDTOs)));
for (PayrollRun payrollRun : payrollRuns) {
**payrollRunActor.tell(payrollRun, getSelf());**
}
}
}).match(PayrollRun.class, maxPaydatePayrollRun -> {
ActorRef payrollRunActor = payrollRunSystem
.actorOf(Props.create(PayrollRunActor.class, employeeAggregator, employee, businessDTOs));
**payrollRunActor.tell(maxPaydatePayrollRun, getSelf());**
}).build();
}
}
First of all you would have to mock the static method call which is invoked during the creation of class under test. Then make it return a spied object and mock the method you want to avoid calling:
#RunWith(PowerMockRunner.class)
#PrepareForTest(ActorSystem.class)
public void TestClass{
#Test
public void test(){
// Arrange
PowerMockito.mockStatic(ActorSystem.class);
ActorSystem actorSystemMock = Mockito.mock(ActorSystem.class);
Actor actorSpy = Mockito.spy(new Actor());
Mockito.when(ActorSystem.create("payrollRun")).thenReturn(actorSystemSpy);
Mockito.when(actorSystemMock.actorOf(any(RoundRobinPool.class)))
.thenReturn(actorSpy);
Mockito.doNothing().when(actorSpy)
.tell(Mockito.any(PayrollRun.class), Mockito.any(Self.class));
EmployeeActor employeeActor = new EmployeeActor();
// Act and assert...
employeeActor.createReceive();
}
}
Remember that all other methods of actorSystemSpy will be called will real implementation. If you want to mock all of them then use Mockito.mock instead of spy.
I have a simple line of Code:
DraftCampaignDetails createdDraft = draftCampaignI.createDraftCampaign(ConvertionUtil
.getDraftCampaignDetailsfromCreateDraftRequest(request));
I am trying to mock it like this:
ConvertionUtil action1 = PowerMockito.mock(ConvertionUtil.class);
when(action1.getDraftCampaignDetailsfromCreateDraftRequest(request)).thenReturn(details);
when(draftCampaignI.createDraftCampaign(details)).thenReturn(details);
But I am getting this error:
when() requires an argument which has to be 'a method call on a mock'.
Adding entire test class for more clarity:
public class DraftCampaignActivityTest {
#Mock
IDraftCampaign draftCampaignI;
/* #Mock
ConvertionUtil util;*/
#Before
#SuppressWarnings("unchecked")
public void setup()
{
MockitoAnnotations.initMocks(this);
}
#Test
public void createDraft_newDraft() {
DraftCampaignActivity draftContoller = new DraftCampaignActivity();
CreateDraftCampaignRequest request = createRequest();
DraftCampaignDetails details = buildDraftDetails();
if(draftCampaignI != null){
System.out.println("sccdscscd");
}
/*
if(util != null) {
System.out.println("wewewew");
}*/
/// ConvertionUtil action1 = PowerMockito.mock(ConvertionUtil.class);
PowerMockito.mockStatic(ConvertionUtil.class);
PowerMockito.when(
ConvertionUtil.getDraftCampaignDetailsfromCreateDraftRequest(request)
).thenReturn(details);
when(draftCampaignI.createDraftCampaign(details)).thenReturn(details);
// when(util.getDraftCampaignDetailsfromCreateDraftRequest(request)).thenReturn(details);
CreateDraftCampaignResponse response = new CreateDraftCampaignResponse();
draftContoller.createDraftCampaign(request);
response.setDraftCampaignId(details.getDraftId());
Assert.assertEquals(response.getDraftCampaignId(),"ww");
}
private DraftCampaignDetails buildDraftDetails() {
DraftCampaignDetails details = new DraftCampaignDetails();
details.setDraftId("ww");
return details;
}
private CreateDraftCampaignRequest createRequest() {
CreateDraftCampaignRequest request = new CreateDraftCampaignRequest();
request.setCampaignInfo("campaignInfo");
request.setMarketplaceId("adadedaedaed");
DraftCampaignDetailsBase base = new DraftCampaignDetailsBase();
Money money = new Money();
money.setCurrencyCode("USD");
money.setMillicents(10L);
base.setCampaignBudget(money);
base.setCampaignName("name");
base.setDraftCampaignState("DRAFT");
request.setDraftCampaignDetailsBase(base);
return request;
//request
}
I am new to Mockito and Powermock. please help! Any help will be greatly appreciated!
To work draftCampaignI must be injected into draftContoller, to do so you need to declare draftContoller as a field of your test class annotated with #InjectMocks, no need to create the instance of DraftCampaignActivity explicitly anymore, leave it to Mockito, as next:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
public class DraftCampaignActivityTest {
#Mock
IDraftCampaign draftCampaignI;
#InjectMocks
DraftCampaignActivity draftContoller;
#Test
#PrepareForTest(ConvertionUtil.class)
public void createDraft_newDraft() {
CreateDraftCampaignRequest request = new CreateDraftCampaignRequest();
DraftCampaignDetails details = new DraftCampaignDetails();
PowerMockito.mockStatic(ConvertionUtil.class);
PowerMockito.when(
ConvertionUtil.getDraftCampaignDetailsfromCreateDraftRequest(request)
).thenReturn(details);
when(draftCampaignI.createDraftCampaign(details)).thenReturn(details);
draftContoller.createDraftCampaign(request);
}
}
Assuming that the class DraftCampaignActivity is of type:
public class DraftCampaignActivity {
...
private IDraftCampaign draftCampaignI;
...
}
More details about the annotation InjectMocks.
NB: As we use #RunWith(PowerMockRunner.class), we have no need to call MockitoAnnotations.initMocks(this) explicitly as it will be done internally such that the method setup is useless and can be removed.
I have an existing class I'm trying to hook into to get some header parameters to SSO a user into our system. The class is as follows.
import java.util.Map;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.springframework.stereotype.Component;
#Component
#Path("/http")
public class HttpResource {
#GET
#Path("/getHeaders")
#Produces(MediaType.APPLICATION_JSON)
public Map<String, String> getAllHeaders(#Context HttpHeaders headers) {
Map<String, String> headerList = new HashMap<String, String>();
for (String key : headers.getRequestHeaders().keySet()) {
String value = headers.getRequestHeader(key).get(0);
System.out.println(key + " : " + value);
headerList.put(key, value);
}
return headerList;
}
}
What I'm trying to figure out is how do I call getAllHeaders() with the #Context argument? I've found a ton of examples of the class I have, but nothing that shows how to call it.
I've also tried putting the annotation inside the class instead of as an argument.
#Context
HttpHeaders httpHeaders;
but when I try to access httpHeaders.getAllHeaders() it returns null. I assume because it's not actually created because the javax documents say it will never return null.
I'm trying to call this within my SSOAuthorizationFilter.java, but have also tried accessing it via a controller as well.
Write an Annotation first.
#Retention(RUNTIME)
#Target({ PARAMETER })
#Documented
public #interface SSOAuthorization {}
And then a Resolver for that.
public class SSOAuthorizationResolver {
public static class SSOAuthorizationInjectionResolver extends
ParamInjectionResolver<SSOAuthorization> {
public SSOAuthorizationInjectionResolver() {
super(SSOAuthorizationValueFactoryProvider.class);
}
}
#Singleton
public static class SSOAuthorizationValueFactoryProvider extends
AbstractValueFactoryProvider {
#Context
private HttpHeaders httpHeaders;
#Inject
public SSOAuthorizationValueFactoryProvider(
final MultivaluedParameterExtractorProvider mpep,
final ServiceLocator injector) {
super(mpep, injector, Parameter.Source.UNKNOWN);
}
#Override
protected Factory<?> createValueFactory(final Parameter parameter) {
final Class<?> classType = parameter.getRawType();
if (!Language.class.equals(classType)
|| parameter.getAnnotation(SSOAuthorization.class) == null) {
return null;
}
return new AbstractContainerRequestValueFactory<String>() {
#Override
public String provide() {
// Can use httpHeader to get your header here.
return httpHeader.getHeaderString("SSOAuthorization");
}
};
}
}
// Binder implementation
public static class Binder extends AbstractBinder {
#Override
protected void configure() {
bind(SSOAuthorizationValueFactoryProvider.class).to(
ValueFactoryProvider.class).in(Singleton.class);
bind(SSOAuthorizationInjectionResolver.class).to(
new TypeLiteral<InjectionResolver<SSOAuthorization>>() {
}).in(Singleton.class);
}
}
}
And in the ResourceConfig just register the Resolver
public class MyResourceConfig extends ResourceConfig {
public MyResourceConfig(Class... classes) {
super(classes);
register(new SSOAuthorizationResolver.Binder());
}
}
And finally use it in your controller with the #SSOAuthorization annotation.
#GET
#Path("/get")
#Produces(MediaType.APPLICATION_JSON)
public String someMethod(#SSOAuthorization String auth) {
return auth;
}
I am trying to write integration test case for Jersey Using Grizzly and Mockito, Spring, I am not able to mock the service Class. how can I mock the service class which is injected in my Resource class with #AutoWired
#AutoWired
MyFirstService myFirstServiceImpl;
#AutoWired
MySecondService mySecondServiceImpl;
#GET
#Path("/abc")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response getDetails(#QueryParam("xyz") String xyz,
#QueryParam("pqr") String pqr) {
Gson gson = new Gson();
Map<String, Object> someMap= new HashMap<String, Object>();
try {
map.put("a", myFirstServiceImpl.getSomeDetails(xyz);
map.put("b", mySecondService.getSomeMoreDetails(pqr);
} catch (Exception e) {
e.printStackTrace();
}
return Response.status(200).entity(gson.toJson(someMap)).build();
}
Test Class:
#Mock
private static MySecondService mySecondServiceImpl;;
#Mock
private static MyFirstService myFirstServiceImpl;
#Before
public void initMocks() {
resource = new MyResource();
MockitoAnnotations.initMocks(this);
resource.setMyFirstService (firstService);
resource.setSecondService(secondService);
}
#Override
protected TestContainerFactory getTestContainerFactory() {
return new GrizzlyWebTestContainerFactory();
}
private DeploymentContext getRestResourcesWithFilter() {
System.setProperty("jersey.config.test.container.port", "8104");
ServletDeploymentContext context =
ServletDeploymentContext
.forServlet(
new ServletContainer(new ResourceConfig(MyResource.class).property(
ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true")))
.addListener(ContextLoaderListener.class).addListener(RequestContextListener.class)
.initParam("contextConfigLocation", "classpath:applicationContext.xml")
.build();
return context;
#Test
public void test() throws Exception {
SomeOBject object= new SomeObject();
Object2 obj= new Object2();
when(myFirstServiceImpl.getSomeDetails(any(String.class))).thenReturn(object);
when(mySecondService.getSomeMoreDetails(pqr)).thenReturn(obj);
Response response = target("v1/abc").request().get();
}
This Test case is passing but the service class which I mocked are not mocking I am getting null pointer exception when ever code hits that line
So there are a couple problems
The #Before method. JerseyTest already implements a #Before method, where it creates the test container. So your mocks won't be created in time and the services will be null. Best thing to do is to just create the services in the configureDeployment() method, where you are initializing the Jersey application. A new container will be created for each test case, so you will have new mocks for each test.
You are simple passing the class to the ResourceConfig constructor, which will cause the Jersey runtime to create the instance of the resource class. So after you create the resource class, instead of new ResourceConfig(MyResource.class), do new ResourceConfig().register(resource).
So the configureDeployment() method should look more like
#Override
public DeploymentContext configureDeployment() {
resource = new MyResource();
MockitoAnnotations.initMocks(this);
resource.setMyFirstService(firstService);
resource.setSecondService(secondService);
ServletDeploymentContext context
= ServletDeploymentContext.forServlet(
new ServletContainer(new ResourceConfig().register(resource).property(
ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true")))
.build();
return context;
}
Another problem is that you are not actually passing any query parameters in the request. So in your resource method, the parameters will be null. Your request should look more like
target(...).queryParam(key1, value1).queryParam(key2, value2)
Here is a complete test
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import junit.framework.Assert;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.ServletDeploymentContext;
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
import org.glassfish.jersey.test.spi.TestContainerFactory;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
public class MockitoTest extends JerseyTest {
public static interface Service {
String getMessage(String name);
}
#Mock
private Service service;
#Path("mock")
public static class MyResource {
private Service service;
public void setService(Service service) {
this.service = service;
}
#GET
public String get(#QueryParam("name") String name) {
return service.getMessage(name);
}
}
#Override
public DeploymentContext configureDeployment() {
MyResource resource = new MyResource();
MockitoAnnotations.initMocks(this);
resource.setService(service);
ServletDeploymentContext context
= ServletDeploymentContext.forServlet(
new ServletContainer(new ResourceConfig().register(resource).property(
ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true")))
.build();
return context;
}
#Override
protected TestContainerFactory getTestContainerFactory() {
return new GrizzlyWebTestContainerFactory();
}
#Test
public void doTest() {
Mockito.when(service.getMessage(Mockito.anyString())).thenAnswer(new Answer<String>(){
#Override
public String answer(InvocationOnMock invocation) throws Throwable {
return "Hello " + (String)invocation.getArguments()[0];
}
});
Response response = target("mock").queryParam("name", "peeskillet").request().get();
Assert.assertEquals(200, response.getStatus());
String message = response.readEntity(String.class);
Assert.assertEquals("Hello peeskillet", message);
System.out.println(message);
}
}