mercredi 2 mars 2016

How to instantiate seesion before unit testing execution so that autowired session in service class creates bean corectly?

How to instantiate seesion before unit testing execution so that autowired session in service class creates bean correctly ?

My test uses some methods from a service class. This service class method uses an autowired session. The point is that i don't know how to create/inject into the session in the test (or before it) so that the session bean creates correctly in the service with the details i set beforehand.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {Application.class})
public class MyTestClass{

 @Autowired
 private UserSession session;

 @Autowired
 private MyServiceClass myServiceClass;

   @Test
   public void myTestMethod() {
   ....
   //This is where i wanted to set some session detailes
   //Something like this:
   session.setUserRolls(...);


   myServiceClass.myServiceMethod();

   }
}

In my service class i have something like this:

@Service
public class MyServiceClass{

@Autowired
private UserSession session;


private void myServiceMethod(){
 ....
 List <UserRol> rolls = session.getUserRolls();
 //in this case i want to retrieve user rolls from session object
 //
 //now i get an error in my current implementation that looks like this
 //Error: no Scope registered for scope name "session"
 }
}

Aucun commentaire:

Enregistrer un commentaire