forked from spring-cloud/spring-cloud-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure there is a single bootstrap parent context
Only one neds to be created, and once it is in place in the hierarchy it should be usable by all the child contexts that get added. Fixes spring-cloudgh-153
- Loading branch information
Dave Syer
committed
Feb 24, 2017
1 parent
8347c57
commit 331e790
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...rg/springframework/cloud/bootstrap/config/BootstrapListenerHierarchyIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2013-2017 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.springframework.cloud.bootstrap.config; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import org.junit.Test; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Integration tests for Bootstrap Listener's functionality of adding a bootstrap context | ||
* as the root Application Context | ||
* | ||
* @author Biju Kunjummen | ||
*/ | ||
public class BootstrapListenerHierarchyIntegrationTests { | ||
|
||
@Test | ||
public void shouldAddInABootstrapContext() { | ||
ConfigurableApplicationContext context = new SpringApplicationBuilder() | ||
.sources(BasicConfiguration.class).web(false).run(); | ||
|
||
assertNotNull(context.getParent()); | ||
} | ||
|
||
@Test | ||
public void shouldAddInOneBootstrapForABasicParentChildHierarchy() { | ||
ConfigurableApplicationContext context = new SpringApplicationBuilder() | ||
.sources(RootConfiguration.class).web(false) | ||
.child(BasicConfiguration.class).web(false).run(); | ||
|
||
// Should be RootConfiguration based context | ||
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) context | ||
.getParent(); | ||
assertEquals("rootBean", parent.getBean("rootBean", String.class)); | ||
|
||
// Parent should have the bootstrap context as parent | ||
assertNotNull(parent.getParent()); | ||
|
||
ConfigurableApplicationContext bootstrapContext = (ConfigurableApplicationContext) parent | ||
.getParent(); | ||
|
||
// Bootstrap should be the root, there should be no other parent | ||
assertNull(bootstrapContext.getParent()); | ||
} | ||
|
||
@Test | ||
public void shouldAddInOneBootstrapForSiblingsBasedHierarchy() { | ||
ConfigurableApplicationContext context = new SpringApplicationBuilder() | ||
.sources(RootConfiguration.class).web(false) | ||
.child(BasicConfiguration.class).web(false) | ||
.sibling(BasicConfiguration.class).web(false).run(); | ||
|
||
// Should be RootConfiguration based context | ||
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) context | ||
.getParent(); | ||
assertEquals("rootBean", parent.getBean("rootBean", String.class)); | ||
|
||
// Parent should have the bootstrap context as parent | ||
assertNotNull(parent.getParent()); | ||
|
||
ConfigurableApplicationContext bootstrapContext = (ConfigurableApplicationContext) parent | ||
.getParent(); | ||
|
||
// Bootstrap should be the root, there should be no other parent | ||
assertNull(bootstrapContext.getParent()); | ||
} | ||
|
||
@Configuration | ||
static class BasicConfiguration { | ||
} | ||
|
||
@Configuration | ||
static class RootConfiguration { | ||
|
||
@Bean | ||
public String rootBean() { | ||
return "rootBean"; | ||
} | ||
} | ||
} |