Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] NullPointerException when working with addNotification for a request #135

Open
hungdao-testing opened this issue Jul 19, 2021 · 4 comments

Comments

@hungdao-testing
Copy link

Precondition:

  • JDK 8
  • Using cubano template as main framework

Setup

  • Fixture file BankAccountFixture
public class BankAccountFixture extends CubanoTemplateIndex {

    public boolean getResultOfCreatingUserAccount(String name, String username, String password) throws IOException {
        BankAccountService bankAccountService = new BankAccountService();
        return bankAccountService.createUserAccount(name, username, password).getResponseCode() == 201;
    }
}
  • BankAccountService class extends BaseService
public HttpEasyReader createUserAccount(String name, String username, String password){
        String CREATE_USER = "/users";
        String firstName = name.split(" ")[0];
        String lastName = name.split(" ")[1];

        String payload =
                String.format("{\n    \"firstName\": \"%s\",\n   " +
                        " \"lastName\": \"%s\",\n    " +
                        "\"username\": \"%s\",\n    " +
                        "\"password\": \"%s\"\n}", firstName, lastName, username, password);
        try{
            HttpEasyReader response = easy
                    .path(CREATE_USER)
                    .data(payload, MediaType.JSON_UTF_8)
                    .withLogWriter(testLoggerLogWriter)
                    .logRequestDetails()
                    .post();
            addNotification("TestLoggerLogWriter Request", testLoggerLogWriter.getRequest());
            addNotification("Raw JSON Response", response.getJsonReader().asPrettyString());
            addNotification("TestLoggerLogWriter Response", testLoggerLogWriter.getResponse());
            return response;

        }catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

Base Service

@FullOGNL
public class BaseService {
    protected ReportLogger log = ReportLoggerFactory.getReportLogger(BankAccountService.class);
    protected HttpEasy easy = HttpEasy.request().baseUrl(AppConfig.getInstance().getApiUrl());
    protected TestLoggerLogWriter testLoggerLogWriter = new TestLoggerLogWriter();

    protected void addNotification(String name, String data) {
        log
                .with()
                .message(name)
                .attachment(data, name + ".json", MediaType.PLAIN_TEXT)
                .marker(StoryboardMarkerFactory.addCard(
                        name,
                        StockCardImage.JSON, CardResult.SUCCESS))
                .debug();
    }
}

Step:

  • Run Fixture file
    -> got error
NullPointerException

While evaluating expression: getResultOfCreatingUserAccount(#name,#username,#password)

org.concordion.internal.InvalidExpressionException: NullPointerException
at org.concordion.slf4j.ext.FluentLogger.attachment (FluentLogger.java:181)
at org.concordion.slf4j.ext.FluentLogger.attachment (FluentLogger.java:169)
at com.rwa.services.BaseService.addNotification (BaseService.java:27)
at com.rwa.services.BankAccountService.createUserAccount (BankAccountService.java:53)
at com.rwa.specs.bankaccount.BankAccountFixture.getResultOfCreatingUserAccount (BankAccountFixture.java:12)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at ognl.OgnlRuntime.invokeMethodInsideSandbox (OgnlRuntime.java:1266)
at ognl.OgnlRuntime.invokeMethod (OgnlRuntime.java:1251)
at ognl.OgnlRuntime.callAppropriateMethod (OgnlRuntime.java:1969)
at ognl.ObjectMethodAccessor.callMethod (ObjectMethodAccessor.java:68)
  • Markdown file

===============================================

Bank Account

Features:

Scenarios: Create user account

Example:

Given users:

Name : Boby Charton
Username: boby.char
Password: s3cret

Then user could create an account succcessfully

===============================================

@hungdao-testing
Copy link
Author

hungdao-testing commented Jul 19, 2021

If not use addNotification() in BankAccountService -> there is no error, and for sure the response data return properly

Here is the github code for you guys review

https://github.com/hungdao-testing/cubano_rwa/blob/feature%2Fcubano_issue/src/test/java/com/rwa/specs/bankaccount/BankAccountFixture.java

Plz let me know if you need more information

@nigelcharman
Copy link
Member

Hi, which line is line 53 of BankAccountService where the error is occurring? It's a blank line on the cubano_issue branch currently.

@hungdao-testing
Copy link
Author

hungdao-testing commented Jul 19, 2021

@nigelcharman I accidentally format the file and therefore the order of lines in trace_log in original post is not correct
Please refer to the full log below

While evaluating expression: getResultOfCreatingUserAccount(#name,#username,#password)

org.concordion.internal.InvalidExpressionException: NullPointerException
at org.concordion.slf4j.ext.FluentLogger.attachment (FluentLogger.java:181)
at org.concordion.slf4j.ext.FluentLogger.attachment (FluentLogger.java:169)
at com.rwa.services.BaseService.addNotification (BaseService.java:27)
at com.rwa.services.BankAccountService.createUserAccount (BankAccountService.java:55)
at com.rwa.specs.bankaccount.BankAccountFixture.getResultOfCreatingUserAccount (BankAccountFixture.java:12)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at ognl.OgnlRuntime.invokeMethodInsideSandbox (OgnlRuntime.java:1266)
at ognl.OgnlRuntime.invokeMethod (OgnlRuntime.java:1251)
at ognl.OgnlRuntime.callAppropriateMethod (OgnlRuntime.java:1969)
at ognl.ObjectMethodAccessor.callMethod (ObjectMethodAccessor.java:68)
at ognl.OgnlRuntime.callMethod (OgnlRuntime.java:2045)
at ognl.ASTMethod.getValueBody (ASTMethod.java:97)
at ognl.SimpleNode.evaluateGetValueBody (SimpleNode.java:212)
at ognl.SimpleNode.getValue (SimpleNode.java:258)
at ognl.Ognl.getValue (Ognl.java:537)
at ognl.Ognl.getValue (Ognl.java:639)
at ognl.Ognl.getValue (Ognl.java:609)
at org.concordion.internal.OgnlEvaluator.evaluate (OgnlEvaluator.java:25)
at org.concordion.internal.SimpleEvaluator.evaluate (SimpleEvaluator.java:14)
at org.concordion.internal.command.BooleanCommand.verify (BooleanCommand.java:33)
at org.concordion.api.AbstractCommandDecorator$3.run (AbstractCommandDecorator.java:33)
at org.concordion.internal.command.LocalTextDecorator.process (LocalTextDecorator.java:26)
at org.concordion.api.AbstractCommandDecorator.verify (AbstractCommandDecorator.java:31)
at org.concordion.api.AbstractCommandDecorator$3.run (AbstractCommandDecorator.java:33)
at org.concordion.internal.command.ThrowableCatchingDecorator.process (ThrowableCatchingDecorator.java:38)
at org.concordion.api.AbstractCommandDecorator.verify (AbstractCommandDecorator.java:31)
at org.concordion.api.CommandCall.verify (CommandCall.java:76)
at org.concordion.api.CommandCallList.processSequentially (CommandCallList.java:34)
at org.concordion.internal.command.ExampleCommand.execute (ExampleCommand.java:49)
at org.concordion.api.AbstractCommandDecorator$2.run (AbstractCommandDecorator.java:25)
at org.concordion.internal.command.LocalTextDecorator.process (LocalTextDecorator.java:26)
at org.concordion.api.AbstractCommandDecorator.execute (AbstractCommandDecorator.java:23)
at org.concordion.api.AbstractCommandDecorator$2.run (AbstractCommandDecorator.java:25)
at org.concordion.internal.command.ThrowableCatchingDecorator.process (ThrowableCatchingDecorator.java:38)
at org.concordion.api.AbstractCommandDecorator.execute (AbstractCommandDecorator.java:23)
at org.concordion.api.CommandCall.execute (CommandCall.java:72)
at org.concordion.internal.XMLSpecification.processNode (XMLSpecification.java:60)
at org.concordion.internal.XMLSpecification.processExample (XMLSpecification.java:76)
at org.concordion.Concordion.processExample (Concordion.java:92)
at org.concordion.internal.FixtureRunner.run (FixtureRunner.java:41)
at org.concordion.integration.junit4.ConcordionRunner.invoke (ConcordionRunner.java:207)
at org.concordion.integration.junit4.ConcordionRunner$1.invoke (ConcordionRunner.java:31)
at org.concordion.integration.junit4.ConcordionFrameworkMethod.invokeExplosively (ConcordionFrameworkMethod.java:58)
at org.junit.internal.runners.statements.InvokeMethod.evaluate (InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf (ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:78)
at org.concordion.integration.junit4.ConcordionRunner.runChild (ConcordionRunner.java:191)
at org.concordion.integration.junit4.ConcordionRunner.runChild (ConcordionRunner.java:23)
at org.junit.runners.ParentRunner$3.run (ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule (ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000 (ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate (ParentRunner.java:268)
at org.junit.runners.ParentRunner.run (ParentRunner.java:363)
at org.concordion.integration.junit4.ConcordionRunner.run (ConcordionRunner.java:150)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute (JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet (JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke (JUnit4Provider.java:104)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray (ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke (ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider (SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked (SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main (ForkedBooter.java:68)
java.lang.NullPointerException: null
at org.concordion.slf4j.ext.FluentLogger.attachment (FluentLogger.java:181)
at org.concordion.slf4j.ext.FluentLogger.attachment (FluentLogger.java:169)
at com.rwa.services.BaseService.addNotification (BaseService.java:27)
at com.rwa.services.BankAccountService.createUserAccount (BankAccountService.java:55)
at com.rwa.specs.bankaccount.BankAccountFixture.getResultOfCreatingUserAccount (BankAccountFixture.java:12)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at ognl.OgnlRuntime.invokeMethodInsideSandbox (OgnlRuntime.java:1266)
at ognl.OgnlRuntime.invokeMethod (OgnlRuntime.java:1251)
at ognl.OgnlRuntime.callAppropriateMethod (OgnlRuntime.java:1969)
at ognl.ObjectMethodAccessor.callMethod (ObjectMethodAccessor.java:68)
at ognl.OgnlRuntime.callMethod (OgnlRuntime.java:2045)
at ognl.ASTMethod.getValueBody (ASTMethod.java:97)
at ognl.SimpleNode.evaluateGetValueBody (SimpleNode.java:212)
at ognl.SimpleNode.getValue (SimpleNode.java:258)
at ognl.Ognl.getValue (Ognl.java:537)
at ognl.Ognl.getValue (Ognl.java:639)
at ognl.Ognl.getValue (Ognl.java:609)
at org.concordion.internal.OgnlEvaluator.evaluate (OgnlEvaluator.java:25)
at org.concordion.internal.SimpleEvaluator.evaluate (SimpleEvaluator.java:14)
at org.concordion.internal.command.BooleanCommand.verify (BooleanCommand.java:33)
at org.concordion.api.AbstractCommandDecorator$3.run (AbstractCommandDecorator.java:33)
at org.concordion.internal.command.LocalTextDecorator.process (LocalTextDecorator.java:26)
at org.concordion.api.AbstractCommandDecorator.verify (AbstractCommandDecorator.java:31)
at org.concordion.api.AbstractCommandDecorator$3.run (AbstractCommandDecorator.java:33)
at org.concordion.internal.command.ThrowableCatchingDecorator.process (ThrowableCatchingDecorator.java:38)
at org.concordion.api.AbstractCommandDecorator.verify (AbstractCommandDecorator.java:31)
at org.concordion.api.CommandCall.verify (CommandCall.java:76)
at org.concordion.api.CommandCallList.processSequentially (CommandCallList.java:34)
at org.concordion.internal.command.ExampleCommand.execute (ExampleCommand.java:49)
at org.concordion.api.AbstractCommandDecorator$2.run (AbstractCommandDecorator.java:25)
at org.concordion.internal.command.LocalTextDecorator.process (LocalTextDecorator.java:26)
at org.concordion.api.AbstractCommandDecorator.execute (AbstractCommandDecorator.java:23)
at org.concordion.api.AbstractCommandDecorator$2.run (AbstractCommandDecorator.java:25)
at org.concordion.internal.command.ThrowableCatchingDecorator.process (ThrowableCatchingDecorator.java:38)
at org.concordion.api.AbstractCommandDecorator.execute (AbstractCommandDecorator.java:23)
at org.concordion.api.CommandCall.execute (CommandCall.java:72)
at org.concordion.internal.XMLSpecification.processNode (XMLSpecification.java:60)
at org.concordion.internal.XMLSpecification.processExample (XMLSpecification.java:76)
at org.concordion.Concordion.processExample (Concordion.java:92)
at org.concordion.internal.FixtureRunner.run (FixtureRunner.java:41)
at org.concordion.integration.junit4.ConcordionRunner.invoke (ConcordionRunner.java:207)
at org.concordion.integration.junit4.ConcordionRunner$1.invoke (ConcordionRunner.java:31)
at org.concordion.integration.junit4.ConcordionFrameworkMethod.invokeExplosively (ConcordionFrameworkMethod.java:58)
at org.junit.internal.runners.statements.InvokeMethod.evaluate (InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf (ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:78)
at org.concordion.integration.junit4.ConcordionRunner.runChild (ConcordionRunner.java:191)
at org.concordion.integration.junit4.ConcordionRunner.runChild (ConcordionRunner.java:23)
at org.junit.runners.ParentRunner$3.run (ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule (ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren (ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000 (ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate (ParentRunner.java:268)
at org.junit.runners.ParentRunner.run (ParentRunner.java:363)
at org.concordion.integration.junit4.ConcordionRunner.run (ConcordionRunner.java:150)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute (JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet (JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke (JUnit4Provider.java:104)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray (ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke (ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider (SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked (SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main (ForkedBooter.java:68)

@nigelcharman
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants