java - Why session scope bean is the same for different mock session in tests -


i'm trying test session scoped bean in spring-boot i've encountered problem. i've created 2 mockhttpsession , try inject them controller method, add them scoped bean. if run application beans different in each scope, when try test it, object same. here test:

@runwith(springjunit4classrunner.class) @springboottest public class observersessionscopedit {  @autowired private observercontroller controller;  @rule public temporaryfolder temporaryfolder = new temporaryfolder();  @test public void sessionscope() throws exception {      mockhttpsession sessionfirst = new mockhttpsession();     mockhttpsession sessionsecond = new mockhttpsession();      sessionfirst.changesessionid();     sessionsecond.changesessionid();      controller.startobserving(temporaryfolder.getroot().getabsolutepath(), sessionfirst);     controller.startobserving(temporaryfolder.getroot().getabsolutepath(), sessionsecond);      subscriptions subscriptionsfirst = (subscriptions) sessionfirst.getattribute("subscriptions");     subscriptions subscriptionssecond = (subscriptions) sessionsecond.getattribute("subscriptions");      assertions.assertthat(subscriptionsfirst).isnotsameas(subscriptionssecond);  } 

and here how menage in controller:

private static final string subscription = "subscriptions"; (...)  @autowired private subscriptions subscriptions;  @crossorigin @requestmapping(path = "/start", method = requestmethod.post) @responsebody responseentity<string> startobserving(@requestbody string path, httpsession httpsession) throws ioexception {      (...)     httpsession.setattribute(subscription, subscriptions);      (...)     } 

and definition of subscriptions object:

@service @sessionscope public class subscriptions implements autocloseable{ 

why have 2 different objects while application works, in test it's same reference? think might connected context in test, can run tests main application context?


Comments

Popular posts from this blog

Formatting string according to pattern without regex in php -

c - zlib and gdi32 with OpenSSL? -

java - inputmismatch exception -