Java Code Examples for com.sun.net.httpserver.HttpServer#removeContext()

The following examples show how to use com.sun.net.httpserver.HttpServer#removeContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextInstanceDataAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void placeHolder_noExplicitConfiguration_createInstanceDataResolverForAwsEnvironment()
		throws Exception {
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext instanceIdHttpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler("testInstanceId"));

	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ContextInstanceDataAutoConfiguration.class);

	// Act
	this.context.refresh();

	// Assert
	assertThat(this.context
			.containsBean("AmazonEc2InstanceDataPropertySourcePostProcessor"))
					.isTrue();

	httpServer.removeContext(instanceIdHttpContext);
}
 
Example 2
Source File: ContextInstanceDataAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void placeHolder_noExplicitConfiguration_missingInstanceDataResolverForNotAwsEnvironment()
		throws Exception {
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext instanceIdHttpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler(null));

	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ContextInstanceDataAutoConfiguration.class);

	// Act
	this.context.refresh();

	// Assert
	assertThat(this.context
			.containsBean("AmazonEc2InstanceDataPropertySourcePostProcessor"))
					.isFalse();

	httpServer.removeContext(instanceIdHttpContext);
}
 
Example 3
Source File: ContextInstanceDataAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void placeHolder_noExplicitConfiguration_createInstanceDataResolverThatResolvesWithDefaultAttributes()
		throws Exception {
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext instanceIdHttpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler("testInstanceId"));
	HttpContext userDataHttpContext = httpServer.createContext("/latest/user-data",
			new MetaDataServer.HttpResponseWriterHandler("a:b;c:d"));

	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ContextInstanceDataAutoConfiguration.class);

	// Act
	this.context.refresh();

	// Assert
	assertThat(this.context.getEnvironment().getProperty("a")).isEqualTo("b");
	assertThat(this.context.getEnvironment().getProperty("c")).isEqualTo("d");

	httpServer.removeContext(instanceIdHttpContext);
	httpServer.removeContext(userDataHttpContext);
}
 
Example 4
Source File: ContextStackAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void stackRegistry_autoConfigurationEnabled_returnsAutoConfiguredStackRegistry()
		throws Exception {
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext httpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler("test"));

	this.contextRunner
			.withUserConfiguration(
					AutoConfigurationStackRegistryTestConfiguration.class)
			.run(context -> assertThat(context.getBean(StackResourceRegistry.class))
					.isNotNull());

	httpServer.removeContext(httpContext);
	MetaDataServer.shutdownHttpServer();
}
 
Example 5
Source File: ContextInstanceDataConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void propertySource_enableInstanceData_propertySourceConfigured() throws Exception {
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext httpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler("test"));

	// Act
	this.context = new AnnotationConfigApplicationContext(
			ApplicationConfiguration.class);

	// Assert
	assertThat(this.context.getEnvironment().getProperty("instance-id"))
			.isEqualTo("test");
	httpServer.removeContext(httpContext);
}
 
Example 6
Source File: ContextInstanceDataConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void propertySource_enableInstanceDataWithCustomAttributeSeparator_propertySourceConfiguredAndUsesCustomAttributeSeparator()
		throws Exception {
	// @checkstyle:on
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext httpContext = httpServer.createContext("/latest/user-data",
			new MetaDataServer.HttpResponseWriterHandler("a:b/c:d"));

	// Act
	this.context = new AnnotationConfigApplicationContext(
			ApplicationConfigurationWithCustomAttributeSeparator.class);

	// Assert
	assertThat(this.context.getEnvironment().getProperty("a")).isEqualTo("b");
	assertThat(this.context.getEnvironment().getProperty("c")).isEqualTo("d");

	httpServer.removeContext(httpContext);
}
 
Example 7
Source File: ContextInstanceDataConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void propertySource_enableInstanceDataWithCustomValueSeparator_propertySourceConfiguredAndUsesCustomValueSeparator()
		throws Exception {
	// @checkstyle:on
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext httpContext = httpServer.createContext("/latest/user-data",
			new MetaDataServer.HttpResponseWriterHandler("a=b;c=d"));

	// Act
	this.context = new AnnotationConfigApplicationContext(
			ApplicationConfigurationWithCustomValueSeparator.class);

	// Assert
	assertThat(this.context.getEnvironment().getProperty("a")).isEqualTo("b");
	assertThat(this.context.getEnvironment().getProperty("c")).isEqualTo("d");

	httpServer.removeContext(httpContext);
}
 
Example 8
Source File: ContextStackConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void stackRegistry_noStackNameConfigured_returnsAutoConfiguredStackRegistry()
		throws Exception {
	// Arrange
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ApplicationConfigurationWithEmptyStackName.class);
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext httpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler("test"));

	// Act
	this.context.refresh();

	// Assert
	StackResourceRegistry stackResourceRegistry = this.context
			.getBean(StackResourceRegistry.class);
	assertThat(stackResourceRegistry).isNotNull();
	assertThat(stackResourceRegistry.getStackName()).isEqualTo("testStack");

	httpServer.removeContext(httpContext);
}
 
Example 9
Source File: ContextInstanceDataAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void placeHolder_customValueSeparator_createInstanceDataResolverThatResolvesWithCustomValueSeparator()
		throws Exception {
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext instanceIdHttpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler("testInstanceId"));
	HttpContext userDataHttpContext = httpServer.createContext("/latest/user-data",
			new MetaDataServer.HttpResponseWriterHandler("a=b;c=d"));

	this.context = new AnnotationConfigApplicationContext();

	TestPropertyValues.of("cloud.aws.instance.data.valueSeparator:=")
			.applyTo(this.context);

	this.context.register(ContextInstanceDataAutoConfiguration.class);

	// Act
	this.context.refresh();

	// Assert
	assertThat(this.context.getEnvironment().getProperty("a")).isEqualTo("b");
	assertThat(this.context.getEnvironment().getProperty("c")).isEqualTo("d");

	httpServer.removeContext(instanceIdHttpContext);
	httpServer.removeContext(userDataHttpContext);
}
 
Example 10
Source File: ContextInstanceDataAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void placeHolder_customAttributeSeparator_createInstanceDataResolverThatResolvesWithCustomAttribute()
		throws Exception {
	// Arrange
	HttpServer httpServer = MetaDataServer.setupHttpServer();
	HttpContext instanceIdHttpContext = httpServer.createContext(
			"/latest/meta-data/instance-id",
			new MetaDataServer.HttpResponseWriterHandler("testInstanceId"));
	HttpContext userDataHttpContext = httpServer.createContext("/latest/user-data",
			new MetaDataServer.HttpResponseWriterHandler("a:b/c:d"));

	this.context = new AnnotationConfigApplicationContext();

	TestPropertyValues.of("cloud.aws.instance.data.attributeSeparator:/")
			.applyTo(this.context);

	this.context.register(ContextInstanceDataAutoConfiguration.class);

	// Act
	this.context.refresh();

	// Assert
	assertThat(this.context.getEnvironment().getProperty("a")).isEqualTo("b");
	assertThat(this.context.getEnvironment().getProperty("c")).isEqualTo("d");

	httpServer.removeContext(instanceIdHttpContext);
	httpServer.removeContext(userDataHttpContext);
}