java - Context Configuration in spock test -


i have such application class:

@configuration @enableautoconfiguration @componentscan @importresource("classpath:applicationcontext.xml") @enablejparepositories("ibd.jpa") public class application {  public static void main(string[] args) {     springapplication.run(application.class, args); } } 

also have userservice class (it discovered @enablejparepositories("ibd.jpa"))

@restcontroller @requestmapping("/user") public class userservice {  @autowired private userrepository userrepository;  @requestmapping(method = requestmethod.post) public user createuser(@requestparam string login, @requestparam string password){     return userrepository.save(new user(login,password)); }  ******** 

and try test userservice :

@contextconfiguration class userservicetest extends specification {  @autowired def userservice userservice   def "if user not exists 404 status in response sent , corresponding message shown"() {     when: 'rest account url hit'     mockmvc mockmvc = standalonesetup(userservice).build()         def response = mockmvc.perform(get('/user?login=wrongusername&password=wrongpassword')).andreturn().response     then:         response.status == not_found.value()         response.errormessage == "login or password not correct"  } 

but issue is: userservice in test null - doesn't wired. means context isn't loaded. please tell me problem in contextconfiguration of test.

was solved by:

@contextconfiguration(loader = springapplicationcontextloader.class, classes = application.class) @webappconfiguration @integrationtest 

and usage of resttemplate

as in question


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -