Building an application using Dropbox and Google Drive in Groovy, the tests run fine.
Code:
def "It instantiates and configures the googleAuthorizationCodeFlowBuilder component"() {
given:
def ctx = grailsApplication.mainContext
GoogleAuthorizationCodeFlow.Builder builder = ctx.googleAuthorizationCodeFlowBuilder
expect:
}
When running on Codeship and Amazon however, the test fails:
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
The googleAuthorizationflowBuilder bean only creates a GoogleAuthorizationCodeFlow.Builder (I use the Google java API).
EDIT 1: I reproduced the error on my machine by modifying 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])
}
}
EDIT 2 : It seems that the error happen specifically when the AppId is null... The question is why is it null on the cloud and not on my machine...
Okay, it seems that the environment variables used to initialize the values of Config.groovy weren't set on the Codebase project, resulting in the aforementioned error.
The missing environment variables have been initialized on Codeship and everything works great now.