diff --git a/spring-boot/.attach_pid12812 b/spring-boot/.attach_pid12812 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index f16460b7c3..1f6d39aabe 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 spring-boot @@ -55,6 +56,14 @@ org.springframework.boot spring-boot-starter-data-jpa + + org.ehcache + ehcache + + + org.hibernate + hibernate-ehcache + org.springframework.boot spring-boot-starter-actuator @@ -143,10 +152,10 @@ chaos-monkey-spring-boot ${chaos.monkey.version} - + - javax.validation - validation-api + javax.validation + validation-api @@ -170,6 +179,26 @@ pl.project13.maven git-commit-id-plugin ${git-commit-id-plugin.version} + + + get-the-git-infos + + revision + + initialize + + + validate-the-git-infos + + validateRevision + + package + + + + true + ${project.build.outputDirectory}/git.properties + @@ -223,7 +252,7 @@ 3.6.0 3.2.0 18.0 - 2.2.4 + 2.2.4 diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java index e079b9a665..cc05fd4fbd 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java @@ -30,7 +30,7 @@ public class ContactInfoValidator implements ConstraintValidator { - Optional findOne(String id); + Optional findById(String id); } diff --git a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java index 3489732b6f..7bd5c36786 100644 --- a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java +++ b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java @@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; public class FailureAnalyzerApplication { @RolesAllowed("*") public static void main(String[] args) { - System.setProperty("security.basic.enabled", "false"); SpringApplication.run(FailureAnalyzerApplication.class, args); } } diff --git a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java index c92d1c32e6..c3af611f3b 100644 --- a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java +++ b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java @@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; public class InternationalizationApp { @RolesAllowed("*") public static void main(String[] args) { - System.setProperty("security.basic.enabled", "false"); SpringApplication.run(InternationalizationApp.class, args); } } diff --git a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java index d3d3d0241f..e067d3cfd1 100644 --- a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java +++ b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java @@ -1,18 +1,17 @@ package com.baeldung.rss; +import javax.annotation.security.RolesAllowed; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -import javax.annotation.security.RolesAllowed; - @SpringBootApplication @ComponentScan(basePackages = "com.baeldung.rss") public class RssApp { @RolesAllowed("*") public static void main(String[] args) { - System.setProperty("security.basic.enabled", "false"); SpringApplication.run(RssApp.class, args); } diff --git a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java index 27be6b7cca..fa84cf0d9b 100644 --- a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java +++ b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java @@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; public class ToggleApplication { @RolesAllowed("*") public static void main(String[] args) { - System.setProperty("security.basic.enabled", "false"); SpringApplication.run(ToggleApplication.class, args); } } diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java index 9132e710d1..354c64c258 100644 --- a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java +++ b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java @@ -4,8 +4,6 @@ import org.baeldung.demo.model.Foo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; -import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean; @EntityScan(basePackageClasses = Foo.class) @SpringBootApplication @@ -15,9 +13,4 @@ public class Application { System.setProperty("spring.profiles.active", "exception"); SpringApplication.run(Application.class, args); } - - @Bean - public HibernateJpaSessionFactoryBean sessionFactory() { - return new HibernateJpaSessionFactoryBean(); - } } diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java index 52407a2117..607bae83ba 100644 --- a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java +++ b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java @@ -1,5 +1,7 @@ package org.baeldung.session.exception.repository; +import javax.persistence.EntityManagerFactory; + import org.baeldung.demo.model.Foo; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -10,16 +12,15 @@ import org.springframework.stereotype.Repository; @Repository public class FooRepositoryImpl implements FooRepository { @Autowired - private SessionFactory sessionFactory; + private EntityManagerFactory emf; @Override public void save(Foo foo) { - sessionFactory.getCurrentSession().saveOrUpdate(foo); + emf.unwrap(SessionFactory.class).getCurrentSession().saveOrUpdate(foo); } @Override public Foo get(Integer id) { - return sessionFactory.getCurrentSession().get(Foo.class, id); + return emf.unwrap(SessionFactory.class).getCurrentSession().get(Foo.class, id); } - } \ No newline at end of file diff --git a/spring-boot/src/main/resources/application.properties b/spring-boot/src/main/resources/application.properties index 629e880940..6a52dd1f70 100644 --- a/spring-boot/src/main/resources/application.properties +++ b/spring-boot/src/main/resources/application.properties @@ -7,7 +7,7 @@ spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto = update management.endpoints.jmx.domain=Spring Sample Application -management.endpoints.jmx.uniqueNames=true +spring.jmx.unique-names=true management.endpoints.web.exposure.include=* management.endpoint.shutdown.enabled=true @@ -17,7 +17,6 @@ management.endpoint.shutdown.enabled=true ##endpoints.jolokia.path=jolokia spring.jmx.enabled=true -management.endpoints.jmx.enabled=true ## for pretty printing of json when endpoints accessed over HTTP http.mappers.jsonPrettyPrint=true diff --git a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java index 2c3ac2e159..8c85934fac 100644 --- a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootAnnotatedApp.class) -@TestPropertySource(properties = { "security.basic.enabled=false" }) public class SpringBootWithServletComponentIntegrationTest { @Autowired diff --git a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java index a30d3ed3f2..c29cd75e9d 100644 --- a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java @@ -19,7 +19,6 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootPlainApp.class) -@TestPropertySource(properties = { "security.basic.enabled=false" }) public class SpringBootWithoutServletComponentIntegrationTest { @Autowired diff --git a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java index aab4836b6f..e933920a96 100644 --- a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java @@ -1,31 +1,34 @@ 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.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; 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.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; 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) @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 { @LocalServerPort @@ -40,6 +43,8 @@ public class DisplayBeanIntegrationTest { @Autowired private WebApplicationContext context; + private static final String ACTUATOR_PATH = "/actuator"; + @Test public void givenRestTemplate_whenAccessServerUrl_thenHttpStatusOK() throws Exception { ResponseEntity entity = this.testRestTemplate.getForEntity("http://localhost:" + this.port + "/displayallbeans", String.class); @@ -49,22 +54,27 @@ public class DisplayBeanIntegrationTest { @Test public void givenRestTemplate_whenAccessEndpointUrl_thenHttpStatusOK() throws Exception { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.testRestTemplate.getForEntity("http://localhost:" + this.mgt + "/springbeans", List.class); + ParameterizedTypeReference> responseType = new ParameterizedTypeReference>() { + }; + RequestEntity requestEntity = RequestEntity.get(new URI("http://localhost:" + this.mgt + ACTUATOR_PATH + "/beans")) + .accept(MediaType.APPLICATION_JSON) + .build(); + ResponseEntity> entity = this.testRestTemplate.exchange(requestEntity, responseType); then(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void givenRestTemplate_whenAccessEndpointUrl_thenReturnsBeanNames() throws Exception { - @SuppressWarnings("rawtypes") - ResponseEntity entity = this.testRestTemplate.getForEntity("http://localhost:" + this.mgt + "/springbeans", List.class); + RequestEntity requestEntity = RequestEntity.get(new URI("http://localhost:" + this.mgt + ACTUATOR_PATH + "/beans")) + .accept(MediaType.APPLICATION_JSON) + .build(); + ResponseEntity entity = this.testRestTemplate.exchange(requestEntity, BeanActuatorResponse.class); - List> allBeans = (List) ((Map) entity.getBody().get(0)).get("beans"); - List beanNamesList = allBeans.stream().map(x -> (String) x.get("bean")).collect(Collectors.toList()); + Collection beanNamesList = entity.getBody() + .getBeans(); - assertThat(beanNamesList, hasItem("fooController")); - assertThat(beanNamesList, hasItem("fooService")); + assertThat(beanNamesList).contains("fooController", "fooService"); } @Test @@ -72,7 +82,20 @@ public class DisplayBeanIntegrationTest { String[] beanNames = context.getBeanDefinitionNames(); List beanNamesList = Arrays.asList(beanNames); - assertTrue(beanNamesList.contains("fooController")); - assertTrue(beanNamesList.contains("fooService")); + assertThat(beanNamesList).contains("fooController", "fooService"); + } + + private static class BeanActuatorResponse { + private Map>>> contexts; + + public Collection getBeans() { + return this.contexts.get("application") + .get("beans") + .keySet(); + } + + public Map>>> getContexts() { + return contexts; + } } } diff --git a/spring-boot/src/test/java/com/baeldung/git/CommitIdIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/git/CommitIdIntegrationTest.java index 348d594c05..d7399a4ff5 100644 --- a/spring-boot/src/test/java/com/baeldung/git/CommitIdIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/git/CommitIdIntegrationTest.java @@ -1,17 +1,19 @@ package com.baeldung.git; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; - @RunWith(SpringRunner.class) @ContextConfiguration(classes = CommitIdApplication.class) +@TestPropertySource(properties = { "spring.jmx.default-domain=test" }) public class CommitIdIntegrationTest { private static final Logger LOG = LoggerFactory.getLogger(CommitIdIntegrationTest.class); diff --git a/spring-boot/src/test/java/com/baeldung/intro/AppLiveTest.java b/spring-boot/src/test/java/com/baeldung/intro/AppLiveTest.java index 83b893ae5c..44461c0cf6 100644 --- a/spring-boot/src/test/java/com/baeldung/intro/AppLiveTest.java +++ b/spring-boot/src/test/java/com/baeldung/intro/AppLiveTest.java @@ -18,7 +18,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @AutoConfigureMockMvc -@TestPropertySource(properties = { "security.basic.enabled=false" }) public class AppLiveTest { @Autowired diff --git a/spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java b/spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java index 5cf19dd1db..92d2286518 100644 --- a/spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java +++ b/spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java @@ -55,7 +55,7 @@ public class KongAdminAPILiveTest { public void givenKongAdminAPI_whenAddAPI_thenAPIAccessibleViaKong() throws Exception { 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 apiEntity = new HttpEntity<>(stockAPI); ResponseEntity addAPIResp = restTemplate.postForEntity("http://localhost:8001/apis", apiEntity, String.class); @@ -69,7 +69,7 @@ public class KongAdminAPILiveTest { HttpHeaders headers = new HttpHeaders(); headers.set("Host", "stock.api"); - RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/springbootapp/stock/btc")); ResponseEntity stockPriceResp = restTemplate.exchange(requestEntity, String.class); assertEquals("10000", stockPriceResp.getBody()); @@ -126,22 +126,26 @@ public class KongAdminAPILiveTest { givenKongAdminAPI_whenAddAPIConsumer_thenAdded(); } + PluginObject authPlugin = new PluginObject("key-auth"); + ResponseEntity 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"; KeyAuthObject keyAuth = new KeyAuthObject(consumerKey); ResponseEntity keyAuthResp = restTemplate.postForEntity("http://localhost:8001/consumers/eugenp/key-auth", new HttpEntity<>(keyAuth), String.class); - + assertTrue(HttpStatus.CREATED == keyAuthResp.getStatusCode() || HttpStatus.CONFLICT == keyAuthResp.getStatusCode()); HttpHeaders headers = new HttpHeaders(); headers.set("Host", "stock.api"); headers.set("apikey", consumerKey); - RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/springbootapp/stock/btc")); ResponseEntity stockPriceResp = restTemplate.exchange(requestEntity, String.class); assertEquals("10000", stockPriceResp.getBody()); 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); assertEquals(HttpStatus.FORBIDDEN, stockPriceResp.getStatusCode()); } diff --git a/spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java b/spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java index abc7151720..7cf67453a6 100644 --- a/spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java +++ b/spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java @@ -1,28 +1,34 @@ package com.baeldung.kong; -import com.baeldung.kong.domain.APIObject; -import com.baeldung.kong.domain.TargetObject; -import com.baeldung.kong.domain.UpstreamObject; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; + +import java.net.URI; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; 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 java.net.URI; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; +import com.baeldung.kong.domain.APIObject; +import com.baeldung.kong.domain.TargetObject; +import com.baeldung.kong.domain.UpstreamObject; /** * @author aiet */ @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 { @Before @@ -55,13 +61,13 @@ public class KongLoadBalanceLiveTest { HttpHeaders headers = new HttpHeaders(); headers.set("Host", "balanced.stock.api"); for (int i = 0; i < 1000; i++) { - RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/springbootapp/stock/btc")); ResponseEntity stockPriceResp = restTemplate.exchange(requestEntity, String.class); assertEquals("10000", stockPriceResp.getBody()); } - int releaseCount = restTemplate.getForObject("http://localhost:9090/stock/reqcount", Integer.class); - int testCount = restTemplate.getForObject("http://localhost:8080/stock/reqcount", Integer.class); + int releaseCount = restTemplate.getForObject("http://localhost:9090/springbootapp/stock/reqcount", Integer.class); + int testCount = restTemplate.getForObject("http://localhost:8080/springbootapp/stock/reqcount", Integer.class); assertTrue(Math.round(releaseCount * 1.0 / testCount) == 4); } diff --git a/spring-boot/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java index 30a4d61fbd..c49b99ed99 100644 --- a/spring-boot/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/mongodb/ManualEmbeddedMongoDbIntegrationTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.util.SocketUtils; import com.mongodb.BasicDBObjectBuilder; import com.mongodb.DBObject; @@ -32,16 +33,16 @@ class ManualEmbeddedMongoDbIntegrationTest { @BeforeEach void setup() throws Exception { String ip = "localhost"; - int port = 27017; + int randomPort = SocketUtils.findAvailableTcpPort(); IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION) - .net(new Net(ip, port, Network.localhostIsIPv6())) + .net(new Net(ip, randomPort, Network.localhostIsIPv6())) .build(); MongodStarter starter = MongodStarter.getDefaultInstance(); mongodExecutable = starter.prepare(mongodConfig); 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") diff --git a/spring-boot/src/test/resources/application.properties b/spring-boot/src/test/resources/application.properties index 85e4e6e66f..9ad65e1815 100644 --- a/spring-boot/src/test/resources/application.properties +++ b/spring-boot/src/test/resources/application.properties @@ -2,7 +2,6 @@ spring.mail.host=localhost spring.mail.port=8025 spring.mail.properties.mail.smtp.auth=false -security.basic.enabled=false # spring.datasource.x spring.datasource.driver-class-name=org.h2.Driver @@ -11,9 +10,10 @@ spring.datasource.username=sa spring.datasource.password=sa # hibernate.X -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop -hibernate.cache.use_second_level_cache=true -hibernate.cache.use_query_cache=true -hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory \ No newline at end of file +spring.jpa.hibernate.dialect=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.show_sql=true +spring.jpa.hibernate.hbm2ddl.auto=create-drop +spring.jpa.hibernate.cache.use_second_level_cache=true +spring.jpa.hibernate.cache.use_query_cache=true +spring.jpa.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory diff --git a/spring-boot/src/test/resources/exception.properties b/spring-boot/src/test/resources/exception.properties index c55e415a3a..e82a482968 100644 --- a/spring-boot/src/test/resources/exception.properties +++ b/spring-boot/src/test/resources/exception.properties @@ -1,6 +1,6 @@ # Security -security.user.name=admin -security.user.password=password +spring.security.user.name=admin +spring.security.user.password=password spring.dao.exceptiontranslation.enabled=false spring.profiles.active=exception \ No newline at end of file