grails - 测试在Amazon和Codeship上失败

标签 grails amazon-web-services groovy google-api codeship

在Groovy中使用Dropbox和Google Drive构建应用程序,测试运行良好。

码:

 def "It instantiates and configures the googleAuthorizationCodeFlowBuilder component"() {
         given:
         def ctx = grailsApplication.mainContext
         GoogleAuthorizationCodeFlow.Builder builder = ctx.googleAuthorizationCodeFlowBuilder

         expect:
 }

但是,在Codeship和Amazon上运行时,测试失败:

Message: Error creating bean with name 'googleAuthorizationCodeFlowBuilder': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow$Builder]: Constructor threw exception; nested exception is java.lang.NullPointerException

Line | Method ->> 285 | autowireConstructor in org.springframework.beans.factory.support.ConstructorResolver

| 1075 | autowireConstructor in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory

/* stuff */

org.apache.catalina.core.ContainerBase$StartChild | 1549 | call in '' | 262 | run . . . . . . . . . . . . . . in java.util.concurrent.FutureTask | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor | 615 | run . . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker ^ 745 | run in java.lang.Thread

Caused by BeanInstantiationException: Could not instantiate bean class [com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow$Builder]: Constructor threw exception; nested exception is java.lang.NullPointerException ->> 163 | instantiateClass in org.springframework.beans.BeanUtils

| 121 | instantiate in org.springframework.beans.factory.support.SimpleInstantiationStrategy | 277 | autowireConstructor . . . . . . in org.springframework.beans.factory.support.ConstructorResolver | 1075 | autowireConstructor in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory | 979 | createBeanInstance . . . . . . in '' | 487 | doCreateBean in '' | 123 | doCreateBean . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor

/* more stacktrace */

| 615 | run . . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker ^ 745 | run in java.lang.Thread



googleAuthorizationflowBuilder Bean仅创建一个GoogleAuthorizationCodeFlow.Builder(我使用Google Java API)。

编辑1:我通过修改doWithSpring重现了我的机器上的错误:
def doWithSpring = {
        def config = application.config
        String googleSecret = getConfigValue(config, 'storage.google.secret')
        String googleAppId = null//getConfigValue(config, 'storage.google.appId')
        String appName = getConfigValue(config, 'storage.appName')

        if (!ConfigUtils.optional(config,'storage.google.disabled')) {
            googleNetHttpTransport(NetHttpTransport)
            googleJsonFactory(JacksonFactory)
            googleCredentialsBuilder(GoogleCredential.Builder) {
                transport = googleNetHttpTransport
                jsonFactory = googleJsonFactory
            }
       googleAuthorizationCodeFlowBuilder(GoogleAuthorizationCodeFlow.Builder, ref('googleNetHttpTransport'), ref('googleJsonFactory'),
                googleAppId, googleSecret, [DRIVE])
        }
    }

编辑2:似乎错误专门发生在AppId为null时...问题是为什么它在云上而不是在我的机器上为null ...

最佳答案

好的,似乎未在Codebase项目上设置用于初始化Config.groovy的值的环境变量,从而导致上述错误。

缺少的环境变量已在Codeship上初始化,并且现在一切正常。

关于grails - 测试在Amazon和Codeship上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29142381/

相关文章:

java - 如何在Java中运行groovy

java - 有没有一种方法可以防止请求使用过滤器到达 grails 中的操作

hibernate - 如何使用最新的库(Spring 3,Hibernate 4,Maven 3)实现独立的GORM?

grails - 使用泛型在Groovy中传递类的实例

mysql - 在mysql表字段中拆分一个字符串并存储到两个字段

mysql - 使用 SSL 443 而不是 3306 访问 rds MySql 数据库

java - Grails,Spring Security LDAP 插件

grails - gorm-无法将对象保存到数据库

amazon-web-services - AWS 负载均衡器中的持续后端连接错误

git - Jenkins 管道抛出 java.io.NotSerializableException : org. jenkinsci.plugins.workflow.job.WorkflowRun 即使使用 @NonCPS