Magento Java Soap Gzip Compression - java

I tried to compress the communication channel between a soap client and magento :
public static MageApiModelServerWsiHandlerPortType getInstance() {
Client client = null;
if (instance == null) {
try {
logger = Logger.getLogger(SoapClient.class);
Properties properties = Property.getInstance(PropertyType.Application);
String url = properties.getProperty("magUrl");
if (url != null) {
//logger.info("Creating service...");
MagentoService service = new MagentoService(new URL(url));
//logger.info("Calling port...");
instance = service.getMageApiModelServerWsiHandlerPort();
client = ClientProxy.getClient(instance);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setConnectionTimeout(36000);
http.setClient(httpClientPolicy);
client.getInInterceptors().add(new GZIPInInterceptor());
client.getOutInterceptors().add(new GZIPOutInterceptor());
...
which works fine for calling various types of data. But when it comes to creating a product, the sender (magento) returns following error:
javax.xml.ws.soap.SOAPFaultException: Invalid XML
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
at $Proxy33.catalogProductCreate(Unknown Source)
at at.magento.service.SoapService.createProductOnly(SoapService.java:280)
at at.magento.ready.SoapProductTest.testCreateProduct(SoapProductTest.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.cxf.binding.soap.SoapFault: Invalid XML
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1667)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1520)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1428)
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:143)
at org.apache.cxf.io.AbstractWrappedOutputStream.close(AbstractWrappedOutputStream.java:72)
at org.apache.cxf.io.AbstractThresholdOutputStream.close(AbstractThresholdOutputStream.java:102)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:195)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:658)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:532)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:89)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
... 30 more

Related

I am getting the following assertion error in junit

This is my test case:
public class SearchStudentDetailsServiceImpl extends JunitCommonUtil {
#Test
public void searchStudentDetails()
{
StudentDetailsSearch studentDetailsSearch=new StudentDetailsSearch();
String sortFlag = "name";
UserService userService = (UserService) ServiceLocator.getInstance()
.getBean("userService");
StringSearchField srchFld = new StringSearchField();
srchFld.setValue("stu1");
studentDetailsSearch.setId(srchFld);
userService.searchStudentDetails(studentDetailsSearch, sortFlag);
assertEquals("Result", "stu1", studentDetailsSearch.getId());
}
}
The error i am getting while running junit test case:
java.lang.AssertionError: Result expected:<stu1> but was:<com.intertek.domain.StringSearchField#740edac1>
at org.junit.Assert.fail(Assert.java:93)
at org.junit.Assert.failNotEquals(Assert.java:647)
at org.junit.Assert.assertEquals(Assert.java:128)
at com.intertek.test.SearchStudentDetailsServiceImpl.searchStudentDetails(SearchStudentDetailsServiceImpl.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Actually I got the error:
I replaced
assertEquals("Result", "stu1", studentDetailsSearch.getId());
with
assertEquals("Result", "stu1", studentDetailsSearch.getId().getValue());

javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException:

How to pass and set the ID in BetRecordAgEBR? Please Help me:) Thanks in advance. This is my only problem that encounter. The BetRecordAgEBR class is for may database using jpa.
if ("GR".equals(dataType)) {
ByteArrayInputStream bis = new ByteArrayInputStream(
aw.getBytes());
StreamSource ss = new StreamSource(bis);
brElement = (JAXBElement<T>) jaxbUnmarshaller
.unmarshal(ss, BetRecordAgGR.class);
ret2 = brElement.getValue();
counter++;
if (counter > 100) {
return brList;
}
/*
*
* String uuid1 = java.util.UUID.randomUUID()
* .toString(); dataOpe.setEntityManager(em);
* ret2.setID(uuid1); dataOpe.add(ret2);
*/
brList.add((T) ret2);
System.out.println(brList);
}
The Exception:
javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): us.kirin.bc.BetRecordAgGR
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881)
at us.kirin.bc.service.DataService.add(DataService.java:40)
at us.kirin.bc.service.AGServiceTest.BetHistoryAGIN(AGServiceTest.java:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): us.kirin.bc.BetRecordAgGR
at org.hibernate.id.Assigned.generate(Assigned.java:52)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:852)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:826)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:830)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875)
... 26 more
I change ret2 to BetRecordAgGR ret2;
if ("GR".equals(dataType)) {
ByteArrayInputStream bis = new ByteArrayInputStream(
aw.getBytes());
StreamSource ss = new StreamSource(bis);
brElement = (JAXBElement<T>) jaxbUnmarshaller
.unmarshal(ss, BetRecordAgGR.class);
ret2= (BetRecordAgGR) brElement.getValue();
counter++;
if (counter > 100) {
return brList;
}
String uuid1 = java.util.UUID.randomUUID()
.toString();
ret2.setID(uuid1);
dataOpe.setEntityManager(em);
dataOpe.add(ret2);
brList.add((T) ret2);
System.out.println(brList);
}

org.mockito.exceptions.misusing.InvalidUseOfMatchersException

I have this test
#Test
public void addVacancy() throws Exception{
Vacancy mockVacancy = Mockito.mock(Vacancy.class);
BindingResult mockResult= Mockito.mock(BindingResult.class);
RedirectAttributes mockRedirectAttributes=Mockito.mock(RedirectAttributes.class);
Model mockModel = Mockito.mock(Model.class);
ModelAndView modelAndView;
when(mockResult.hasErrors()).thenReturn(false);
VacancyService vacancyService = Mockito.mock(VacancyService.class);
vacancyMenuController.vacancyService = vacancyService;
modelAndView = vacancyMenuController.addVacancy(mockVacancy, mockResult, mockModel, mockRedirectAttributes);
Mockito.verify(vacancyService, Mockito.times(1)).add(Mockito.any(Vacancy.class));//good work
Mockito.verify(mockRedirectAttributes,Mockito.times(1)).addAttribute("message",anyString());// exception
}
for this method:
#RequestMapping("/addVacancy")
public ModelAndView addVacancy(#ModelAttribute("myVacancy") #Valid Vacancy vacancy,BindingResult result, Model model,RedirectAttributes redirectAttributes){
if(result.hasErrors()){
model.addAttribute("message","validation error");
return new ModelAndView("vacancyDetailsAdd");
}
vacancyService.add(vacancy);
ModelAndView mv = new ModelAndView("redirect:goToVacancyDetails");
mv.addObject("idVacancy", vacancy.getId());
redirectAttributes.addAttribute("message", "added correctly at "+ new Date());
return mv;
}
why this string is works good:
Mockito.verify(vacancyService, Mockito.times(1)).add(Mockito.any(Vacancy.class));//good work
but here I see exception
Mockito.verify(mockRedirectAttributes,Mockito.times(1)).addAttribute("message",anyString());// exception
full trace:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at com.epam.hhsystem.web.controllers.VacancyMenuControllerTest.addVacancy(VacancyMenuControllerTest.java:186)
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
For more info see javadoc for Matchers class.
at com.epam.hhsystem.web.controllers.VacancyMenuControllerTest.addVacancy(VacancyMenuControllerTest.java:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Your addAttribute() verify needs to have eq() around the String "message".
When you use one of the matchers you have to use it for all parameters in the method.
Mockito.verify(mockRedirectAttributes,Mockito.times(1)).addAttribute(eq("message"),anyString());
See the added eq.

unable to resolve java.lang.NullPointerException

I have three classes- class 'ABC' 'PQR' and 'XYZ'
class ABC
#Test
public void getModulesid() throws Exception {
Long GrpId= PQR.getExistingGroupId();
System.out.println(GrpId);
}
class PQR
public static Long getExistingGroupId() throws Exception {
Long GrpId;
List<MsecBusGroups> busGroupsList = new ArrayList<MsecBusGroups>();
busGroupsList=XYZ.getBusGroups();
if (busGroupsList!=null){
MsecBusGroups It1=busGroupsList.get(busGroupsList.size()-1);
GrpId=It1.getId();
return GrpId;
} else {
throw new Exception("BUSINESS GROUPS LIST RETURNED IS NULL");
}
}
class XYZ
public List<MsecBusGroups> getBusGroups() throws PersistenceException {
final String METHOD_NAME = "getBusGroups()";
LogHelper.logEntry(CLASS_NAME, METHOD_NAME);
List<MsecBusGroups> list = null;
try {
Query q = em.createNamedQuery("getBusGroups");
list = q.getResultList();
if (list == null) {
LogHelper.debug(CLASS_NAME, METHOD_NAME, "No Record Found");
}
...
}
When I run the test method in ABC class its throwing java.lang.NullPointerException.
java.lang.NullPointerException
at com.causeway.platform.security.model.actions.BusServiceActions.getExistingGroupId(BusServiceActions.java:202)
at com.causeway.platform.security.model.serviceImpl.SecurityBusServiceTest.testDeleteModule(SecurityBusServiceTest.java:1231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I see that getBusGroups() is not static. This means that in busGroupsList=XYZ.getBusGroups(); XYZ is a variable. The NPE is probably thrown because XYZ is null.
securityBusService is probably null. Where is it initialized?

Play framework & CAS - How to log in for functional tests?

I'm using Play 1.2.4 with CAS 3.1 as a secure module. It all works fine during development and I have to log in to use my controller methods.
But I can't get the log in part to work inside my functional tests. I was using this question as a reference:
Playframework Secure module: how do you "log in" to test a secured controller in a FunctionalTest?
My test looks like this:
#Test
public void testThatIndexPageWorks() {
final Map<String, String> loginUserParams = new HashMap<String, String>();
loginUserParams.put("login", "foobar");
loginUserParams.put("password", "foobar");
final Response loginResponse = POST("/#cas/authenticate", loginUserParams);
final Request request = newRequest();
request.cookies = loginResponse.cookies; // makes the request authenticated
request.url = "/";
request.method = "GET";
final Response response = makeRequest(request);
assertIsOk(response);
}
The test fails at the line "POST("/#cas......)" with the following exception:
java.lang.RuntimeException: java.util.concurrent.ExecutionException: play.exceptions.ActionNotFoundException: Action null?ticket=ST-e71ba57f-3f1f-4b71-b16f-0141db78b42f not found
at play.test.FunctionalTest.makeRequest(FunctionalTest.java:299)
at play.test.FunctionalTest.makeRequest(FunctionalTest.java:305)
at play.test.FunctionalTest.POST(FunctionalTest.java:152)
at play.test.FunctionalTest.POST(FunctionalTest.java:200)
at play.test.FunctionalTest.POST(FunctionalTest.java:167)
at ApplicationTest.testThatIndexPageWorks(ApplicationTest.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at play.test.PlayJUnitRunner$StartPlay$2$1.evaluate(PlayJUnitRunner.java:105)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at play.test.PlayJUnitRunner.run(PlayJUnitRunner.java:55)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at play.test.TestEngine.run(TestEngine.java:112)
at controllers.TestRunner.run(TestRunner.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:257)
at play.Invoker$Invocation.run(Invoker.java:278)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.util.concurrent.ExecutionException: play.exceptions.ActionNotFoundException: Action null?ticket=ST-e71ba57f-3f1f-4b71-b16f-0141db78b42f not found
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at play.test.FunctionalTest.makeRequest(FunctionalTest.java:286)
... 57 more
Caused by: play.exceptions.ActionNotFoundException: Action null?ticket=ST-e71ba57f-3f1f-4b71-b16f-0141db78b42f not found
at play.mvc.ActionInvoker.getActionMethod(ActionInvoker.java:590)
at play.mvc.Controller.redirect(Controller.java:555)
at play.mvc.Controller.redirect(Controller.java:532)
at play.mvc.Controller.redirect(Controller.java:501)
at controllers.modules.cas.MockServer.loginAction(MockServer.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at play.test.FunctionalTest$1.execute(FunctionalTest.java:269)
at play.Invoker$Invocation.run(Invoker.java:278)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
... 3 more
Caused by: java.lang.Exception: Controller controllers not found
... 22 more
It looks like the authentication itself works since I get some kind of ticket.
Does anyone know how I can either log into my application via CAS from functional tests or disable CAS / #With(SecureCAS.class) all together while running tests?
Setup CAS to use the MockServer for the play test profile, in application.conf add:
%test.cas.mockserver=true
Then
#Test
public void testThatIndexPageWorks() {
// test with cas functionality
final Map<String, String> loginUserParams = new HashMap<String, String>();
loginUserParams.put("login", "foobar");
loginUserParams.put("password", "foobar");
loginUserParams.put("serviceUrl", "modules.cas.securecas/authenticate"); // must be set but is not used
final Response authenticateResponse = POST("/#cas/authenticate", loginUserParams);
// you get a redirect to the authenticate service: assertEquals(Integer.valueOf(302), authenticateResponse.status);
// extract the ticket from the redirect url:
String location = authenticateResponse.getHeader("Location");
String ticket = location.substring(location.indexOf("ticket=")+7, location.length());
Logger.debug("ticket: "+ticket);
// odd workaround: we have to set the port and create the request by ourself, otherwise play is calling the url without port!
final int port = Http.Request.current() == null ? 80 : Http.Request.current().get().port;
final Request authenticateRequest = newRequest();
authenticateRequest.port = port;
final Response validateResponse = GET(authenticateRequest, "/modules.cas.securecas/authenticate?service=cas/serviceValidate&ticket="+ticket);
// the response is again a redirect, normally to the initially called page: assertEquals(Integer.valueOf(302), authenticateResponse.status);
Logger.debug("Authentication successfull");
// functional test of a html page:
final Request request = newRequest();
request.url = "/";
request.cookies = validateResponse.cookies; // makes the request authenticated
request.method = "GET";
final Response response = makeRequest(request);
assertIsOk(response);
}

Categories

Resources