trance12
asked on
easymock compilation issue
Can someone advice what is wrong with the below syntax in my JwsShortMesssageServiceUni tTest file?
HandlePollingMessageRespon seDto resp = new HandlePollingMessageRespon seDto();
resp.setResponse_Text("tes t");
resp.setSmsc_Number(9999);
expect(mockSpringShortMess ageFacade. handlePoll ingMessage ((PollAnsw er) anyObject())).andReturn(re sp);
PollAnswer is a domain model object and the facade returns a domain model object PollSetup
The error it returns is:
The method anyObject() is undefined for the type JwsShortMesssageServiceUni tTest
- The method expect(PollSetup) is undefined for the type
JwsShortMesssageServiceUni tTest
Thanks
HandlePollingMessageRespon
resp.setResponse_Text("tes
resp.setSmsc_Number(9999);
expect(mockSpringShortMess
PollAnswer is a domain model object and the facade returns a domain model object PollSetup
The error it returns is:
The method anyObject() is undefined for the type JwsShortMesssageServiceUni
- The method expect(PollSetup) is undefined for the type
JwsShortMesssageServiceUni
Thanks
public PollSetup handlePollingMessage(PollAnswer pollAnswer)
throws ServiceUnavailableException, ShortMessageApplicationException,
InvalidResponseException;
looks like it should be EasyMock.anyObject
Whats the compilation error you are getting?
ASKER
This is the error:
The method anyObject() is undefined for the type JwsShortMesssageServiceUni tTest
- The method expect(PollSetup) is undefined for the type
JwsShortMesssageServiceUni tTest
The method anyObject() is undefined for the type JwsShortMesssageServiceUni
- The method expect(PollSetup) is undefined for the type
JwsShortMesssageServiceUni
ASKER
actually making it EasyMock.anyObject took care of the 1st issue but not the second one..
how is mockSpringShortMessageFaca de defined?
> actually making it EasyMock.anyObject took care of the 1st issue but not the second one..
thats because you have 2 different problems :)
thats because you have 2 different problems :)
ASKER
mockSpringShortMessageFaca de is defined as
private SpringShortMessageApplicat ionFacade mockSpringShortMessageFaca de and that implements ShortMessageFacade
private SpringShortMessageApplicat
public interface ShortMessageFacade {
public PollSetup handlePollingMessage(PollAnswer pollAnswer)
throws ServiceUnavailableException, ShortMessageApplicationException,
InvalidResponseException;
}
how is it initialized? It looks like is not a mock instance
ASKER
private SpringShortMessageApplicat ionFacade mockSpringShortMessageFaca de;
mockSpringShortMessageFaca de = EasyMock.createMock(Spring ShortMessa geApplicat ionFacade. class);
and the SpringShortMessageApplicat ionFacade class is shown below
mockSpringShortMessageFaca
and the SpringShortMessageApplicat
public class SpringShortMessageApplicationFacade implements ShortMessageFacade {
@Autowired
protected MessageDao messageDao;
protected PollAnswerDao pollAnswerDao;
protected PollSetupDao pollSetupDao;
protected PollSetup pollSetup;
protected PollAnswer pollAnswer;
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public PollSetup handlePollingMessage(PollAnswer message)
throws ServiceUnavailableException, ShortMessageApplicationException,
InvalidResponseException {
pollAnswerDao.create(message);
return pollSetupDao.readPollingMessageResponse(message.getSmscNumber());
}
}
is the error message the same?
can you post the complete unit test method
can you post the complete unit test method
ASKER
Here is the complete class...
public class JwsShortMesssageServiceUnitTest {
private static final Logger logger = LoggerFactory.getLogger(JwsShortMesssageServiceUnitTest.class);
private JwsShortMessageService shortMessageService;
private SpringShortMessageApplicationFacade mockSpringShortMessageFacade;
/**
* setUp
*
* @throws BeansException .
*/
@Before
public void setUp() throws BeansException {
if (logger.isDebugEnabled()) {
logger.debug("##################################################");
logger.debug("Before Adding test data");
logger.debug("##################################################");
}
mockSpringShortMessageFacade = EasyMock.createMock(SpringShortMessageApplicationFacade.class);
final ShortMessageAssembler smUtil = new ShortMessageAssembler();
shortMessageService = new JwsShortMessageService() {
ApplicationContext context = new GenericApplicationContext() {
public Object getBean(String arg0)
throws BeansException {
if (arg0.equals(
"facade-shortmessageenablerApplicationFacade")) {
return mockSpringShortMessageFacade;
} else if (arg0.equals(
"util-shortMessageUtil")) {
return smUtil;
} else {
return super.getBean(arg0);
}
}
};
/**
* Gets the application context.
*
* @return the application context
*/
protected ApplicationContext getApplicationContext() {
logger.debug("bBefore cleaning test data");
return context;
}
};
}
// /**
// * tearDown
// */
@After
public void tearDown() {
if (logger.isDebugEnabled()) {
logger.debug("##################################################");
logger.debug("Before cleaning test data");
logger.debug("##################################################");
}
reset(mockSpringShortMessageFacade);
}
@Test()
public void testSmsPollingOK()
throws ServiceUnavailableException, InvalidResponseException {
// SETUP
HandlePollingMessageRequestDto dto = new HandlePollingMessageRequestDto();
dto.setCallerIdentity("someuser");
dto.setClientId("someuser");
dto.setClientPassword("someuser");
dto.setMessage("some message");
dto.setMsisdn("13001456");
dto.setProcessId("someuser");
dto.setSignOnIdentity("someuser");
dto.setShort_Message_Id(4444);
dto.setMessage("test only");
HandlePollingMessageResponseDto resp = new HandlePollingMessageResponseDto();
resp.setResponse_Text("test");
resp.setSmsc_Number(9999);
expect(mockSpringShortMessageFacade.handlePollingMessage((PollAnswer) EasyMock.anyObject())).andReturn(resp);
replay(mockSpringShortMessageFacade);
resp = shortMessageService.handlePollingMessage(dto);
// VERIFY
//shortMessageService.handlePollingMessage(dto);
verify(mockSpringShortMessageFacade);
logger.debug("yayayaya");
}
}
ASKER
yes..the error message is the same..
ASKER
I just realized that resp should be a domain object and not a dto...in line 82
Although it doesnt take away the error
Although it doesnt take away the error
PollSetup resp = new PollSetup();
resp.setResponseText("test");
resp.setSmscNumber(9999);
expect(mockSpringShortMessageFacade.handlePollingMessage((PollAnswer) EasyMock.anyObject())).andReturn(resp);
replay(mockSpringShortMessageFacade);
shortMessageService.handlePollingMessage(dto);
try :
expect(mockSpringShortMess ageFacade. handlePoll ingMessage (EasyMock. anyObject( ))).andRet urn(resp);
expect(mockSpringShortMess
ASKER
I tried that..it gives
The method handlePollingMessage(PollA nswer) in the type SpringShortMessageApplicat ionFacade is not applicable for the arguments (Object)
The method handlePollingMessage(PollA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes...thats been imported..
ASKER
sorry i checked the wrong file...I'm not in the right frame of mind..:)...
yes i forgot to import import static org.easymock.EasyMock.*;.. ....that did it..:)
Thanks heaps...!!
yes i forgot to import import static org.easymock.EasyMock.*;..
Thanks heaps...!!