grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.79k stars 949 forks source link

Bean Instantiation Exception in grails Testing . Beans are not created in the test environment #10701

Closed sadasivaiahgoli closed 6 years ago

sadasivaiahgoli commented 7 years ago

Grais version : 3.2.9 Gorm Version : 6.1.2.Release Gorm Mongo DB Linux mint 18 In testing I got Bean Instantiation Exception of All controller and dependent services. Event Test Class Also got Bean Instantiation Exception. Even Mongodb Database not set in the test environment. But in bootRun it worked good.

import grails.test.mixin.integration.Integration import grails.transaction. import spock.lang. import grails.plugins.rest.client.RestBuilder import grails.plugins.rest.client.RestResponse import org.springframework.beans.factory.annotation.Value import com.symfore.core.TransactionService import org.springframework.util.LinkedMultiValueMap import org.springframework.util.MultiValueMap import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component; import com.symfore.core.; import com.symfore.util.; import grails.test.mixin.TestFor import grails.test.mixin.Mock

@Integration @Rollback

class TransactionControllerSpec extends Specification { @Value('${local.server.port}') Integer serverPort @Autowired TransactionService transactionService

@Autowired
FileService fileService
@Autowired
def exceptionHandlerService*/
RestBuilder rest
String accessToken

void setup() {
    rest = new RestBuilder()
    //controller=new TransactionController()
    //controller.transactionService = Stub(TransactionService)

    System.out.println("test setup")

    RestResponse resp = rest.post("http://localhost:${serverPort}/symport/api/login") {
        header("Accept", "application/json")
        header("Content-Type", "application/json")
        json {
            username = 'rtalluri'
            password = 'passw0rd'
        }
    }
    if(resp.status==200){
        accessToken= resp.json.access_token

    }
    System.out.println("accessToken="+accessToken)

}

void cleanup() {
}
void "testGetTransactionData"() {
    when:
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>()
    form.add("fromDate","1997-05-01")
    form.add("toDate","2017-05-12")
    RestResponse resp=rest.post("http://localhost:${serverPort}/symport/transaction/getTransactionData") {
        header("Accept", "application/json")
        header("Authorization", "Bearer ${accessToken}")
        contentType("application/x-www-form-urlencoded")
        body(form)
}
     then:
     resp.json.transactionList.size()==1784
}
void "testGetTransactionList"() {
    when:
    def tranList='58eca7a35cc69611a3dd2a58,58eca7a25cc69611a3dd2a2d'
     Map qmap =[transactionList:tranList]// [transactionList:'58eca7a25cc69611a3dd2a2d']

    RestResponse resp=rest.get("http://localhost:${serverPort}/symport/transaction/ getTransactionList?transactionList={transactionList}",qmap) {
        header("Accept", "application/json")
        header("Authorization", "Bearer ${accessToken}")

}
     then:
     resp.json.size()==2
}

} All test classes got bean instantaiton exception what is the reason.

graemerocher commented 7 years ago

Please provide an example that reproduces the issue.

Also this is the third report you have posted on the same issue and the quality of the reports is appalling. I will close the others and leave this open but please stop spamming the issue tracker and try to improve the quality of your reports.

jameskleeh commented 6 years ago

Closing due to lack of feedback