Added code for new module
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.spring.cloud.ribbon.client;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.embedded.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ServerLocationApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class ServerLocationAppTests {
|
||||
ConfigurableApplicationContext application2;
|
||||
ConfigurableApplicationContext application3;
|
||||
|
||||
@Before
|
||||
public void startApps() {
|
||||
this.application2 = startApp(9092);
|
||||
this.application3 = startApp(9999);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeApps() {
|
||||
this.application2.close();
|
||||
this.application3.close();
|
||||
}
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate testRestTemplate;
|
||||
|
||||
@Test
|
||||
public void loadBalancingServersTest() throws InterruptedException {
|
||||
ResponseEntity<String> response = this.testRestTemplate.getForEntity("http://localhost:" + this.port + "/server-location", String.class);
|
||||
assertEquals(response.getBody(), "Australia");
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext startApp(int port) {
|
||||
return SpringApplication.run(TestConfig.class, "--server.port=" + port, "--spring.jmx.enabled=false");
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.spring.cloud.ribbon.client;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@RestController
|
||||
public class TestConfig {
|
||||
|
||||
@RequestMapping(value = "/locaus")
|
||||
public String locationAUSDetails() {
|
||||
return "Australia";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user