jamesfredley commented on code in PR #15815: URL: https://github.com/apache/grails-core/pull/15815#discussion_r3519905089
########## grails-shell-cli/src/test/groovy/org/grails/cli/boot/SpringApplicationWebApplicationInitializerSpec.groovy: ########## @@ -0,0 +1,54 @@ +/* + * 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.cli.boot + +import jakarta.servlet.ServletContext +import spock.lang.Specification + +/** + * Verifies that {@link SpringApplicationWebApplicationInitializer} stays inert when it is + * discovered on the classpath of a standard {@code bootWar} deployed to an external servlet + * container, i.e. when the {@code Spring-Application-Source-Classes} manifest entry is absent. + * + * Regression test for <a href="https://github.com/apache/grails-core/issues/15377">#15377</a>. + */ +class SpringApplicationWebApplicationInitializerSpec extends Specification { + + void "onStartup is inert when the source-classes manifest entry is absent"() { + given: 'an initializer discovered in a non CLI-packaged WAR' + def initializer = new SpringApplicationWebApplicationInitializer() + ServletContext servletContext = Mock(ServletContext) { + getResourceAsStream('/META-INF/MANIFEST.MF') >> manifestStream + } + + when: 'the servlet container invokes onStartup' + initializer.onStartup(servletContext) + + then: 'the application boot is not disturbed and no NPE is raised' + noExceptionThrown() + + where: 'the manifest is missing or lacks the source-classes entry' + manifestStream << [ + null, + new ByteArrayInputStream('Manifest-Version: 1.0\r\n\r\n'.getBytes('UTF-8')), + new ByteArrayInputStream( + 'Manifest-Version: 1.0\r\nImplementation-Title: my-app\r\n\r\n'.getBytes('UTF-8')) + ] Review Comment: Good catch - addressed in 7d6a85ff01. Added two where cases to the spec: a present-but-empty Spring-Application-Source-Classes value and a whitespace-only value, so the sources.isBlank() inert path is now exercised alongside the missing-manifest and missing-entry cases. The spec passes all 5 cases. -- 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]
