This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
BootstrapTests.java
executable file
·83 lines (67 loc) · 2.74 KB
/
BootstrapTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Cloud Foundry 2012.02.03 Beta
* Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product includes a number of subcomponents with
* separate copyright notices and license terms. Your use of these
* subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file.
*/
package org.cloudfoundry.identity.uaa.login;
import static org.junit.Assert.assertNotNull;
import org.cloudfoundry.identity.uaa.config.YamlPropertiesFactoryBean;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.ViewResolver;
/**
* @author Dave Syer
*
*/
public class BootstrapTests {
private GenericXmlApplicationContext context;
@Before
public void setup() throws Exception {
System.clearProperty("spring.profiles.active");
}
@After
public void cleanup() throws Exception {
System.clearProperty("spring.profiles.active");
if (context!=null) {
context.close();
}
}
@Test
public void testRootContextDefaults() throws Exception {
context = getServletContext("file:./src/main/webapp/WEB-INF/spring-servlet.xml");
assertNotNull(context.getBean("viewResolver", ViewResolver.class));
}
private GenericXmlApplicationContext getServletContext(String... resources) {
String profiles = null;
String[] resourcesToLoad = resources;
if (!resources[0].endsWith(".xml")) {
profiles = resources[0];
resourcesToLoad = new String[resources.length-1];
System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length);
}
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load(resourcesToLoad);
if (profiles!=null) {
context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles));
}
// Simulate what happens in the webapp when the YamlServletProfileInitializer kicks in
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new Resource[] {new FileSystemResource("./src/test/resources/test/config/login.yml")});
context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("servletProperties", factory.getObject()));
context.refresh();
return context;
}
}