Add simple custom zuul filter example

This commit is contained in:
Dave Syer
2016-05-04 08:53:08 +01:00
parent 801698edc4
commit a0167042de
4 changed files with 72 additions and 8 deletions

View File

@@ -1,11 +1,14 @@
package demo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient;
@@ -15,18 +18,24 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ZuulApplication.class)
@DirtiesContext
@WebIntegrationTest(randomPort=true)
@WebIntegrationTest(randomPort = true)
public class ZuulApplicationTests {
@Autowired
DiscoveryClient discoveryClient;
@Value("${local.server.port}")
int port;
@Test
public void contextLoads() {
assertEquals("Hello World", new TestRestTemplate()
.getForObject("http://localhost:" + this.port + "/static", String.class));
}
@Test
public void discoveryClientIsNoop() {
assertTrue("discoveryClient is wrong type", discoveryClient instanceof NoopDiscoveryClient);
assertTrue("discoveryClient is wrong type",
this.discoveryClient instanceof NoopDiscoveryClient);
}
}