Merge pull request #5706 from rozagerardo/geroza/BAEL-9523_migrate-to-parent-pom-2_1

[BAEL-9524] spring-boot | parent-boot-1 to parent-boot-2 for spring-boot
This commit is contained in:
Loredana Crusoveanu 2018-11-17 21:57:57 +02:00 committed by GitHub
commit 6e94e2b213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 133 additions and 83 deletions

View File

View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot</artifactId> <artifactId>spring-boot</artifactId>
@ -55,6 +56,14 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
@ -145,8 +154,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.validation</groupId> <groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId> <artifactId>validation-api</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
@ -170,6 +179,26 @@
<groupId>pl.project13.maven</groupId> <groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId> <artifactId>git-commit-id-plugin</artifactId>
<version>${git-commit-id-plugin.version}</version> <version>${git-commit-id-plugin.version}</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
@ -223,7 +252,7 @@
<graphql-spring-boot-starter.version>3.6.0</graphql-spring-boot-starter.version> <graphql-spring-boot-starter.version>3.6.0</graphql-spring-boot-starter.version>
<graphql-java-tools.version>3.2.0</graphql-java-tools.version> <graphql-java-tools.version>3.2.0</graphql-java-tools.version>
<guava.version>18.0</guava.version> <guava.version>18.0</guava.version>
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version> <git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
</properties> </properties>
</project> </project>

View File

@ -30,7 +30,7 @@ public class ContactInfoValidator implements ConstraintValidator<ContactInfo, St
if (StringUtils.isEmptyOrWhitespace(expressionType)) { if (StringUtils.isEmptyOrWhitespace(expressionType)) {
LOG.error("Contact info type missing!"); LOG.error("Contact info type missing!");
} else { } else {
pattern = expressionRepository.findOne(expressionType).map(ContactInfoExpression::getPattern).orElse(""); pattern = expressionRepository.findById(expressionType).map(ContactInfoExpression::getPattern).orElse("");
} }
} }

View File

@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class DynamicValidationApp { public class DynamicValidationApp {
@RolesAllowed("*") @RolesAllowed("*")
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("security.basic.enabled", "false");
SpringApplication.run(DynamicValidationApp.class, args); SpringApplication.run(DynamicValidationApp.class, args);
} }
} }

View File

@ -7,5 +7,5 @@ import org.springframework.data.repository.Repository;
import com.baeldung.dynamicvalidation.model.ContactInfoExpression; import com.baeldung.dynamicvalidation.model.ContactInfoExpression;
public interface ContactInfoExpressionRepository extends Repository<ContactInfoExpression, String> { public interface ContactInfoExpressionRepository extends Repository<ContactInfoExpression, String> {
Optional<ContactInfoExpression> findOne(String id); Optional<ContactInfoExpression> findById(String id);
} }

View File

@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class FailureAnalyzerApplication { public class FailureAnalyzerApplication {
@RolesAllowed("*") @RolesAllowed("*")
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("security.basic.enabled", "false");
SpringApplication.run(FailureAnalyzerApplication.class, args); SpringApplication.run(FailureAnalyzerApplication.class, args);
} }
} }

View File

@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class InternationalizationApp { public class InternationalizationApp {
@RolesAllowed("*") @RolesAllowed("*")
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("security.basic.enabled", "false");
SpringApplication.run(InternationalizationApp.class, args); SpringApplication.run(InternationalizationApp.class, args);
} }
} }

View File

@ -1,18 +1,17 @@
package com.baeldung.rss; package com.baeldung.rss;
import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import javax.annotation.security.RolesAllowed;
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.rss") @ComponentScan(basePackages = "com.baeldung.rss")
public class RssApp { public class RssApp {
@RolesAllowed("*") @RolesAllowed("*")
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("security.basic.enabled", "false");
SpringApplication.run(RssApp.class, args); SpringApplication.run(RssApp.class, args);
} }

View File

@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class ToggleApplication { public class ToggleApplication {
@RolesAllowed("*") @RolesAllowed("*")
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("security.basic.enabled", "false");
SpringApplication.run(ToggleApplication.class, args); SpringApplication.run(ToggleApplication.class, args);
} }
} }

View File

@ -4,8 +4,6 @@ import org.baeldung.demo.model.Foo;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
@EntityScan(basePackageClasses = Foo.class) @EntityScan(basePackageClasses = Foo.class)
@SpringBootApplication @SpringBootApplication
@ -15,9 +13,4 @@ public class Application {
System.setProperty("spring.profiles.active", "exception"); System.setProperty("spring.profiles.active", "exception");
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
@Bean
public HibernateJpaSessionFactoryBean sessionFactory() {
return new HibernateJpaSessionFactoryBean();
}
} }

View File

@ -1,5 +1,7 @@
package org.baeldung.session.exception.repository; package org.baeldung.session.exception.repository;
import javax.persistence.EntityManagerFactory;
import org.baeldung.demo.model.Foo; import org.baeldung.demo.model.Foo;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -10,16 +12,15 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public class FooRepositoryImpl implements FooRepository { public class FooRepositoryImpl implements FooRepository {
@Autowired @Autowired
private SessionFactory sessionFactory; private EntityManagerFactory emf;
@Override @Override
public void save(Foo foo) { public void save(Foo foo) {
sessionFactory.getCurrentSession().saveOrUpdate(foo); emf.unwrap(SessionFactory.class).getCurrentSession().saveOrUpdate(foo);
} }
@Override @Override
public Foo get(Integer id) { public Foo get(Integer id) {
return sessionFactory.getCurrentSession().get(Foo.class, id); return emf.unwrap(SessionFactory.class).getCurrentSession().get(Foo.class, id);
} }
} }

View File

@ -7,7 +7,7 @@ spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update spring.jpa.hibernate.ddl-auto = update
management.endpoints.jmx.domain=Spring Sample Application management.endpoints.jmx.domain=Spring Sample Application
management.endpoints.jmx.uniqueNames=true spring.jmx.unique-names=true
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true management.endpoint.shutdown.enabled=true
@ -17,7 +17,6 @@ management.endpoint.shutdown.enabled=true
##endpoints.jolokia.path=jolokia ##endpoints.jolokia.path=jolokia
spring.jmx.enabled=true spring.jmx.enabled=true
management.endpoints.jmx.enabled=true
## for pretty printing of json when endpoints accessed over HTTP ## for pretty printing of json when endpoints accessed over HTTP
http.mappers.jsonPrettyPrint=true http.mappers.jsonPrettyPrint=true

View File

@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootAnnotatedApp.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootAnnotatedApp.class)
@TestPropertySource(properties = { "security.basic.enabled=false" })
public class SpringBootWithServletComponentIntegrationTest { public class SpringBootWithServletComponentIntegrationTest {
@Autowired @Autowired

View File

@ -19,7 +19,6 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootPlainApp.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootPlainApp.class)
@TestPropertySource(properties = { "security.basic.enabled=false" })
public class SpringBootWithoutServletComponentIntegrationTest { public class SpringBootWithoutServletComponentIntegrationTest {
@Autowired @Autowired

View File

@ -1,31 +1,34 @@
package com.baeldung.displayallbeans; package com.baeldung.displayallbeans;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.BDDAssertions.then;
import java.net.URI;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.assertj.core.api.BDDAssertions.then;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = { "management.port=0", "endpoints.beans.id=springbeans", "endpoints.beans.sensitive=false" }) @TestPropertySource(properties = { "management.port=0", "management.endpoints.web.exposure.include=*" })
public class DisplayBeanIntegrationTest { public class DisplayBeanIntegrationTest {
@LocalServerPort @LocalServerPort
@ -40,6 +43,8 @@ public class DisplayBeanIntegrationTest {
@Autowired @Autowired
private WebApplicationContext context; private WebApplicationContext context;
private static final String ACTUATOR_PATH = "/actuator";
@Test @Test
public void givenRestTemplate_whenAccessServerUrl_thenHttpStatusOK() throws Exception { public void givenRestTemplate_whenAccessServerUrl_thenHttpStatusOK() throws Exception {
ResponseEntity<String> entity = this.testRestTemplate.getForEntity("http://localhost:" + this.port + "/displayallbeans", String.class); ResponseEntity<String> entity = this.testRestTemplate.getForEntity("http://localhost:" + this.port + "/displayallbeans", String.class);
@ -49,22 +54,27 @@ public class DisplayBeanIntegrationTest {
@Test @Test
public void givenRestTemplate_whenAccessEndpointUrl_thenHttpStatusOK() throws Exception { public void givenRestTemplate_whenAccessEndpointUrl_thenHttpStatusOK() throws Exception {
@SuppressWarnings("rawtypes") ParameterizedTypeReference<Map<String, ContextBeans>> responseType = new ParameterizedTypeReference<Map<String, ContextBeans>>() {
ResponseEntity<List> entity = this.testRestTemplate.getForEntity("http://localhost:" + this.mgt + "/springbeans", List.class); };
RequestEntity<Void> requestEntity = RequestEntity.get(new URI("http://localhost:" + this.mgt + ACTUATOR_PATH + "/beans"))
.accept(MediaType.APPLICATION_JSON)
.build();
ResponseEntity<Map<String, ContextBeans>> entity = this.testRestTemplate.exchange(requestEntity, responseType);
then(entity.getStatusCode()).isEqualTo(HttpStatus.OK); then(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }
@Test @Test
public void givenRestTemplate_whenAccessEndpointUrl_thenReturnsBeanNames() throws Exception { public void givenRestTemplate_whenAccessEndpointUrl_thenReturnsBeanNames() throws Exception {
@SuppressWarnings("rawtypes") RequestEntity<Void> requestEntity = RequestEntity.get(new URI("http://localhost:" + this.mgt + ACTUATOR_PATH + "/beans"))
ResponseEntity<List> entity = this.testRestTemplate.getForEntity("http://localhost:" + this.mgt + "/springbeans", List.class); .accept(MediaType.APPLICATION_JSON)
.build();
ResponseEntity<BeanActuatorResponse> entity = this.testRestTemplate.exchange(requestEntity, BeanActuatorResponse.class);
List<Map<String, Object>> allBeans = (List) ((Map) entity.getBody().get(0)).get("beans"); Collection<String> beanNamesList = entity.getBody()
List<String> beanNamesList = allBeans.stream().map(x -> (String) x.get("bean")).collect(Collectors.toList()); .getBeans();
assertThat(beanNamesList, hasItem("fooController")); assertThat(beanNamesList).contains("fooController", "fooService");
assertThat(beanNamesList, hasItem("fooService"));
} }
@Test @Test
@ -72,7 +82,20 @@ public class DisplayBeanIntegrationTest {
String[] beanNames = context.getBeanDefinitionNames(); String[] beanNames = context.getBeanDefinitionNames();
List<String> beanNamesList = Arrays.asList(beanNames); List<String> beanNamesList = Arrays.asList(beanNames);
assertTrue(beanNamesList.contains("fooController")); assertThat(beanNamesList).contains("fooController", "fooService");
assertTrue(beanNamesList.contains("fooService")); }
private static class BeanActuatorResponse {
private Map<String, Map<String, Map<String, Map<String, Object>>>> contexts;
public Collection<String> getBeans() {
return this.contexts.get("application")
.get("beans")
.keySet();
}
public Map<String, Map<String, Map<String, Map<String, Object>>>> getContexts() {
return contexts;
}
} }
} }

View File

@ -1,17 +1,19 @@
package com.baeldung.git; package com.baeldung.git;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(classes = CommitIdApplication.class) @ContextConfiguration(classes = CommitIdApplication.class)
@TestPropertySource(properties = { "spring.jmx.default-domain=test" })
public class CommitIdIntegrationTest { public class CommitIdIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(CommitIdIntegrationTest.class); private static final Logger LOG = LoggerFactory.getLogger(CommitIdIntegrationTest.class);

View File

@ -18,7 +18,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc @AutoConfigureMockMvc
@TestPropertySource(properties = { "security.basic.enabled=false" })
public class AppLiveTest { public class AppLiveTest {
@Autowired @Autowired

View File

@ -55,7 +55,7 @@ public class KongAdminAPILiveTest {
public void givenKongAdminAPI_whenAddAPI_thenAPIAccessibleViaKong() throws Exception { public void givenKongAdminAPI_whenAddAPI_thenAPIAccessibleViaKong() throws Exception {
restTemplate.delete("http://localhost:8001/apis/stock-api"); restTemplate.delete("http://localhost:8001/apis/stock-api");
APIObject stockAPI = new APIObject("stock-api", "stock.api", "http://localhost:8080", "/"); APIObject stockAPI = new APIObject("stock-api", "stock.api", "http://localhost:9090", "/");
HttpEntity<APIObject> apiEntity = new HttpEntity<>(stockAPI); HttpEntity<APIObject> apiEntity = new HttpEntity<>(stockAPI);
ResponseEntity<String> addAPIResp = restTemplate.postForEntity("http://localhost:8001/apis", apiEntity, String.class); ResponseEntity<String> addAPIResp = restTemplate.postForEntity("http://localhost:8001/apis", apiEntity, String.class);
@ -69,7 +69,7 @@ public class KongAdminAPILiveTest {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Host", "stock.api"); headers.set("Host", "stock.api");
RequestEntity<String> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); RequestEntity<String> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/springbootapp/stock/btc"));
ResponseEntity<String> stockPriceResp = restTemplate.exchange(requestEntity, String.class); ResponseEntity<String> stockPriceResp = restTemplate.exchange(requestEntity, String.class);
assertEquals("10000", stockPriceResp.getBody()); assertEquals("10000", stockPriceResp.getBody());
@ -126,6 +126,10 @@ public class KongAdminAPILiveTest {
givenKongAdminAPI_whenAddAPIConsumer_thenAdded(); givenKongAdminAPI_whenAddAPIConsumer_thenAdded();
} }
PluginObject authPlugin = new PluginObject("key-auth");
ResponseEntity<String> enableAuthResp = restTemplate.postForEntity("http://localhost:8001/apis/stock-api/plugins", new HttpEntity<>(authPlugin), String.class);
assertTrue(HttpStatus.CREATED == enableAuthResp.getStatusCode() || HttpStatus.CONFLICT == enableAuthResp.getStatusCode());
final String consumerKey = "eugenp.pass"; final String consumerKey = "eugenp.pass";
KeyAuthObject keyAuth = new KeyAuthObject(consumerKey); KeyAuthObject keyAuth = new KeyAuthObject(consumerKey);
ResponseEntity<String> keyAuthResp = restTemplate.postForEntity("http://localhost:8001/consumers/eugenp/key-auth", new HttpEntity<>(keyAuth), String.class); ResponseEntity<String> keyAuthResp = restTemplate.postForEntity("http://localhost:8001/consumers/eugenp/key-auth", new HttpEntity<>(keyAuth), String.class);
@ -135,13 +139,13 @@ public class KongAdminAPILiveTest {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Host", "stock.api"); headers.set("Host", "stock.api");
headers.set("apikey", consumerKey); headers.set("apikey", consumerKey);
RequestEntity<String> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); RequestEntity<String> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/springbootapp/stock/btc"));
ResponseEntity<String> stockPriceResp = restTemplate.exchange(requestEntity, String.class); ResponseEntity<String> stockPriceResp = restTemplate.exchange(requestEntity, String.class);
assertEquals("10000", stockPriceResp.getBody()); assertEquals("10000", stockPriceResp.getBody());
headers.set("apikey", "wrongpass"); headers.set("apikey", "wrongpass");
requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/springbootapp/stock/btc"));
stockPriceResp = restTemplate.exchange(requestEntity, String.class); stockPriceResp = restTemplate.exchange(requestEntity, String.class);
assertEquals(HttpStatus.FORBIDDEN, stockPriceResp.getStatusCode()); assertEquals(HttpStatus.FORBIDDEN, stockPriceResp.getStatusCode());
} }

View File

@ -1,28 +1,34 @@
package com.baeldung.kong; package com.baeldung.kong;
import com.baeldung.kong.domain.APIObject; import static org.junit.Assert.assertEquals;
import com.baeldung.kong.domain.TargetObject; import static org.junit.Assert.assertTrue;
import com.baeldung.kong.domain.UpstreamObject; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
import java.net.URI;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.net.URI; import com.baeldung.kong.domain.APIObject;
import com.baeldung.kong.domain.TargetObject;
import static org.junit.Assert.assertEquals; import com.baeldung.kong.domain.UpstreamObject;
import static org.junit.Assert.assertTrue;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
/** /**
* @author aiet * @author aiet
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = DEFINED_PORT, classes = StockApp.class) @SpringBootTest(webEnvironment = DEFINED_PORT, classes = StockApp.class, properties = "server.servlet.contextPath=/springbootapp")
public class KongLoadBalanceLiveTest { public class KongLoadBalanceLiveTest {
@Before @Before
@ -55,13 +61,13 @@ public class KongLoadBalanceLiveTest {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.set("Host", "balanced.stock.api"); headers.set("Host", "balanced.stock.api");
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
RequestEntity<String> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); RequestEntity<String> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/springbootapp/stock/btc"));
ResponseEntity<String> stockPriceResp = restTemplate.exchange(requestEntity, String.class); ResponseEntity<String> stockPriceResp = restTemplate.exchange(requestEntity, String.class);
assertEquals("10000", stockPriceResp.getBody()); assertEquals("10000", stockPriceResp.getBody());
} }
int releaseCount = restTemplate.getForObject("http://localhost:9090/stock/reqcount", Integer.class); int releaseCount = restTemplate.getForObject("http://localhost:9090/springbootapp/stock/reqcount", Integer.class);
int testCount = restTemplate.getForObject("http://localhost:8080/stock/reqcount", Integer.class); int testCount = restTemplate.getForObject("http://localhost:8080/springbootapp/stock/reqcount", Integer.class);
assertTrue(Math.round(releaseCount * 1.0 / testCount) == 4); assertTrue(Math.round(releaseCount * 1.0 / testCount) == 4);
} }

View File

@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.util.SocketUtils;
import com.mongodb.BasicDBObjectBuilder; import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject; import com.mongodb.DBObject;
@ -32,16 +33,16 @@ class ManualEmbeddedMongoDbIntegrationTest {
@BeforeEach @BeforeEach
void setup() throws Exception { void setup() throws Exception {
String ip = "localhost"; String ip = "localhost";
int port = 27017; int randomPort = SocketUtils.findAvailableTcpPort();
IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION) IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION)
.net(new Net(ip, port, Network.localhostIsIPv6())) .net(new Net(ip, randomPort, Network.localhostIsIPv6()))
.build(); .build();
MongodStarter starter = MongodStarter.getDefaultInstance(); MongodStarter starter = MongodStarter.getDefaultInstance();
mongodExecutable = starter.prepare(mongodConfig); mongodExecutable = starter.prepare(mongodConfig);
mongodExecutable.start(); mongodExecutable.start();
mongoTemplate = new MongoTemplate(new MongoClient(ip, port), "test"); mongoTemplate = new MongoTemplate(new MongoClient(ip, randomPort), "test");
} }
@DisplayName("Given object When save object using MongoDB template Then object can be found") @DisplayName("Given object When save object using MongoDB template Then object can be found")

View File

@ -2,7 +2,6 @@ spring.mail.host=localhost
spring.mail.port=8025 spring.mail.port=8025
spring.mail.properties.mail.smtp.auth=false spring.mail.properties.mail.smtp.auth=false
security.basic.enabled=false
# spring.datasource.x # spring.datasource.x
spring.datasource.driver-class-name=org.h2.Driver spring.datasource.driver-class-name=org.h2.Driver
@ -11,9 +10,10 @@ spring.datasource.username=sa
spring.datasource.password=sa spring.datasource.password=sa
# hibernate.X # hibernate.X
hibernate.dialect=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.show_sql=true spring.jpa.hibernate.ddl-auto=create-drop
hibernate.hbm2ddl.auto=create-drop spring.jpa.hibernate.show_sql=true
hibernate.cache.use_second_level_cache=true spring.jpa.hibernate.hbm2ddl.auto=create-drop
hibernate.cache.use_query_cache=true spring.jpa.hibernate.cache.use_second_level_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory spring.jpa.hibernate.cache.use_query_cache=true
spring.jpa.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory

View File

@ -1,6 +1,6 @@
# Security # Security
security.user.name=admin spring.security.user.name=admin
security.user.password=password spring.security.user.password=password
spring.dao.exceptiontranslation.enabled=false spring.dao.exceptiontranslation.enabled=false
spring.profiles.active=exception spring.profiles.active=exception