jamesfredley commented on code in PR #16496: URL: https://github.com/apache/grails-core/pull/16496#discussion_r4174999691
########## grails-data-mongodb/boot-plugin/src/test/groovy/org/grails/datastore/gorm/mongodb/boot/autoconfigure/discovered/MongoDbGormAutoConfigurationDiscoverySpec.groovy: ########## @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.datastore.gorm.mongodb.boot.autoconfigure.discovered + +import grails.gorm.annotation.Entity +import grails.gorm.transactions.Transactional + +import org.springframework.boot.WebApplicationType +import org.springframework.boot.autoconfigure.AutoConfiguration +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.builder.SpringApplicationBuilder +import org.springframework.boot.context.annotation.ImportCandidates +import org.springframework.context.ConfigurableApplicationContext +import org.springframework.stereotype.Service + +import org.apache.grails.testing.mongo.AbstractMongoGrailsExtension +import org.apache.grails.testing.mongo.AutoStartedMongoSpec +import org.grails.datastore.gorm.mongodb.boot.autoconfigure.MongoDbGormAutoConfiguration +import org.grails.datastore.mapping.mongo.MongoDatastore + +/** + * Spring Boot finds an auto-configuration by reading + * {@code META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports}. Nothing here imports + * {@link MongoDbGormAutoConfiguration}, so the application gets GORM only if that file names it. + */ +class MongoDbGormAutoConfigurationDiscoverySpec extends AutoStartedMongoSpec { + + @Override + boolean shouldInitializeDatastore() { + false + } + + void 'the GORM for MongoDB auto-configuration is registered where Spring Boot reads it'() { + expect: + MongoDbGormAutoConfiguration.name in ImportCandidates.load(AutoConfiguration, getClass().classLoader).candidates + } + + void 'a Spring Boot application gets GORM for MongoDB without importing anything'() { + when: + ConfigurableApplicationContext context = new SpringApplicationBuilder(DiscoveringApplication) Review Comment: Non-blocking. This spec covers the discovery path. The `mongodb/springboot` example test still does not start the application. `BookControllerSpec` (lines 39-46) builds a standalone MockMvc and takes `BookService` from a `MongoDatastore` that `SpringBootStartMongoExtension` (lines 46-49) constructs by hand. CI packages the example and runs that test, but it still does not start `example.Application` or check that Spring injects `BookService`. No change required for this PR. An optional follow-up is an application-context test for the example. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
