karatelabs / karate

Test Automation Made Simple
https://karatelabs.github.io/karate
MIT License
8.26k stars 1.94k forks source link

"When method post" throws NullPointerException #5

Closed ejfrancis closed 7 years ago

ejfrancis commented 7 years ago

This works fine

Feature: Intelligence

  Scenario: Creates a new model

    Given url urlBase + '/model'
    When method get
    Then status 200
    And match response == { success: true, result: '#notnull' }

But when I change the method to post

Feature: Intelligence

  Scenario: Creates a new model

    Given url urlBase + '/model'
    When method post
    Then status 200
    And match response == { success: true, result: '#notnull' }

I get this NullPointerException

java.lang.NullPointerException
    at com.intuit.karate.StepDefs.method(StepDefs.java:197)
    at ✽.When method post(intelligence/intelligence.feature:6)

I'm able to make POST requests to the endpoint via PostMan just fine

ejfrancis commented 7 years ago

This is interesting: I added another test below that initial POST test that fails, and now they both work fine

ptrthomas commented 7 years ago

@ejfrancis thanks for reporting this, actually for POST, PUT etc - the 'request' keyword has to be used as the payload is mandatory. I just added an error message to make it more clear.

ptrthomas commented 7 years ago

... and if the intent was to have an 'empty' body, you can always do:

Given request ''
When method post
Then status 201

Can you confirm that things look ok with the latest released version 0.1.4 ?

ejfrancis commented 7 years ago

@ptrthomas yup that works fine, thanks for the clarification

showtime25st commented 5 years ago

or send json with body: {}, it worked for me

palakjainq commented 4 years ago

@ptrthomas for POST, PUT etc - the 'request' keyword has to be used as the payload is mandatory. Can you please provide an example as i am facing the same issue

ptrthomas commented 4 years ago

@palakjainq I think the comments above answers your question so read them again. else, please use stack overflow: https://stackoverflow.com/questions/tagged/karate

palakjainq commented 4 years ago

@ptrthomas

Even on using 'request' keyword as payload , i am getting null pointer exception for below request:

[ { "id":

{ "partyId":'', "partyType": "AID", "parentSchemeId": 1, "enforcedQualifier": "SALE" } , "saleLimit": '', "saleStartDateTime": '', "saleEndDateTime": '' }, { "id":

{ "partyId": '', "partyType": "AID", "parentSchemeId": 2, "enforcedQualifier": "SALE" } , "saleLimit": '', "saleStartDateTime": '', "saleEndDateTime": '' }, { "id":

{ "partyId": '', "partyType": "AID", "parentSchemeId": 5, "enforcedQualifier": "SALE" } , "saleLimit": '', "saleStartDateTime": '', "saleEndDateTime": '' } ]

Feature: test criteria of View Enforced Sale Limits API

Background:

@MerchantLevel Scenario Outline: Set 1 Day Enforced Sale - merchant

Given path 'merchantEnforcedLimits' And path '' And param userid = 'yesgate' And request reqJson And print date When method patch Then status 200

com.intuit.karate.exception.KarateException: testcriteria_enforcedsalelimit.feature:30 - status code was: 500, expected: 200, response time: 974, url: http://localhost:8080/merchantEnforcedLimits/000000000000330?userid=yesgate, response: {"timestamp":"2020-01-09T06:51:47.314+0000","status":500,"error":"Internal Server Error","message":"No message available","trace":"java.lang.NullPointerException\r\n\tat com.sun.xml.bind.v2.runtime.XMLSerializer.leafElement(XMLSerializer.java:324)\r\n\tat com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$StringImplImpl.writeLeafElement(RuntimeBuiltinLeafInfoImpl.java:1066)\r\n\tat com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$StringImplImpl.writeLeafElement(RuntimeBuiltinLeafInfoImpl.java:1045)\r\n\tat com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.writeLeafElement(TransducedAccessor.java:248)\r\n\tat com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:130)\r\n\tat com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)\r\n\tat com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)\r\n\tat com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:341)\r\n\tat com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)\r\n\tat com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)\r\n\tat com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:256)\r\n\tat javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:116)\r\n\tat com.worldpay.wpt.yesgate.commons.ReplicationHelper.entityToXMLConverter(ReplicationHelper.java:70)\r\n\tat com.worldpay.wpt.yesgate.commons.ReplicationHelper.saveReplicationEntity(ReplicationHelper.java:57)\r\n\tat com.worldpay.wpt.yesgate.services.EnforcedLimitsService.updateAuditEvents(EnforcedLimitsService.java:163)\r\n\tat com.worldpay.wpt.yesgate.services.EnforcedLimitsService.upsertEnforcedLimitsList(EnforcedLimitsService.java:145)\r\n\tat com.worldpay.wpt.yesgate.controller.EnforcedLimitsController.updateEnforcedLimitForMerchant(EnforcedLimitsController.java:105)\r\n\tat com.worldpay.wpt.yesgate.controller.EnforcedLimitsController$$FastClassBySpringCGLIB$$be3da62e.invoke()\r\n\tat org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)\r\n\tat org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\r\n\tat org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:120)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)\r\n\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)\r\n\tat com.worldpay.wpt.yesgate.controller.EnforcedLimitsController$$EnhancerBySpringCGLIB$$3fdcc2e7.updateEnforcedLimitForMerchant()\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:893)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:798)\r\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:880)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:97)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:94)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\r\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)\r\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)\r\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)\r\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat java.lang.Thread.run(Thread.java:748)\r\n","path":"/merchantEnforcedLimits/000000000000330"}

palakjainq commented 4 years ago

I'm able to make PATCH requests to the endpoint via PostMan just fine.Even with karate ,sometimes the above script works and other times experience null pointer exception

ptrthomas commented 4 years ago

@palakjainq sorry I'm not going to read all of this. please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue