Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:30:10+00:00 2026-05-24T12:30:10+00:00

I am looking for a way to set session data during functional test. I

  • 0

I am looking for a way to set session data during functional test. I want to test a logout action.

Ideally, I would like to do something like that

    @Test
    public void testLogout() {
        Scope.Session session = Scope.Session.current();
        session.put(Application.SESSION_USER_ID, "1");

        Response response = GET("/application/logout");

        assertEquals(null, session.get(Application.SESSION_USER_ID));
}

Unfortunaly, when I invoke this test, I got the following NullppointerException.

java.lang.NullPointerException
    at ApplicationTest.testLogout(ApplicationTest.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    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$1$1$1.execute(PlayJUnitRunner.java:73)
    at play.Invoker$Invocation.run(Invoker.java:265)
    at play.Invoker.invokeInThread(Invoker.java:67)
    at play.test.PlayJUnitRunner$StartPlay$1$1.evaluate(PlayJUnitRunner.java:68)
    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:48)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:30:11+00:00Added an answer on May 24, 2026 at 12:30 pm

    I’m unsure why the functional test fails, but I can explain how I would test it:

    I made a normal unittest:

    @Before
    public void setUp() {
        Session.current.set(new Session());
        Request.current.set(new Request());
        Response.current.set(new Response());
    }
    

    and then something like that

    @Test
    public void testLogout() {
        Session.current().put(SESSION_KEY_USERID, "1");
        Response.current().setCookie(COOKIE_NAME, "A value");
        assertNotNull(Session.current().get(SESSION_KEY_USERID));
        assertTrue(Response.current().cookies.containsKey(COOKIE_NAME));
        Cookie cookie = Response.current().cookies.get(COOKIE_NAME);
        assertFalse(Integer.valueOf(0).equals(cookie.maxAge));
        assertEquals("A value", cookie.value);
        service.logout();
        assertNull(Session.current().get(SESSION_KEY_USERID));
        cookie = Response.current().cookies.get(COOKIE_NAME);
        assertTrue(Integer.valueOf(0).equals(cookie.maxAge));
        assertEquals("", cookie.value);
    }
    

    I hope with this information you can solve your problem. Sorry that I don’t give you a correct solution, but at the moment I loose to much time solving other peoples problems :-/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to set the default language for visitors comming to
I'm looking for a way to set the checked property based on an integer
I am looking for a way to set permissions on a virtual directory through
I am looking for a way to set a warning that the caller will
Looking for the best way to set-up an iPhone project in XCode ... namely:
I am looking for the best or any way to set the Album Art
I'm looking for a way to generate a set of random sided, but regular,
I'm looking for a way to get and set those oddball chunks in a
I'm looking for a way to sequentially number rows in a result set (not
I'm looking for a simple way to let users define a set of rules

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.