Commit 55a0e1b8 authored by nobodyiam's avatar nobodyiam

upgrade spring boot to 2.0.5 and spring cloud to Finchley.SR1

parent 425de29e
...@@ -22,17 +22,15 @@ ...@@ -22,17 +22,15 @@
<!-- end of apollo --> <!-- end of apollo -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<scope>test</scope> <scope>test</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId> <artifactId>spring-cloud-starter-netflix-archaius</artifactId>
spring-cloud-starter-archaius
</artifactId>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>spring-cloud-starter-ribbon</artifactId> <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
......
...@@ -24,7 +24,7 @@ public class AdminServiceHealthIndicator implements HealthIndicator { ...@@ -24,7 +24,7 @@ public class AdminServiceHealthIndicator implements HealthIndicator {
} }
private int check() { private int check() {
PageRequest pageable = new PageRequest(0, 1); PageRequest pageable = PageRequest.of(0, 1);
appService.findAll(pageable); appService.findAll(pageable);
return 0; return 0;
} }
......
...@@ -183,7 +183,7 @@ public class InstanceConfigController { ...@@ -183,7 +183,7 @@ public class InstanceConfigController {
@RequestParam("clusterName") String clusterName, @RequestParam("clusterName") String clusterName,
@RequestParam("namespaceName") String namespaceName) { @RequestParam("namespaceName") String namespaceName) {
Page<Instance> instances = instanceService.findInstancesByNamespace(appId, clusterName, Page<Instance> instances = instanceService.findInstancesByNamespace(appId, clusterName,
namespaceName, new PageRequest(0, 1)); namespaceName, PageRequest.of(0, 1));
return instances.getTotalElements(); return instances.getTotalElements();
} }
} }
...@@ -3,3 +3,4 @@ spring.application.name= apollo-adminservice ...@@ -3,3 +3,4 @@ spring.application.name= apollo-adminservice
ctrip.appid= 100003172 ctrip.appid= 100003172
server.port= 8090 server.port= 8090
logging.file= /opt/logs/100003172/apollo-adminservice.log logging.file= /opt/logs/100003172/apollo-adminservice.log
spring.jmx.default-domain = apollo-adminservice
...@@ -2,6 +2,8 @@ eureka: ...@@ -2,6 +2,8 @@ eureka:
instance: instance:
hostname: ${hostname:localhost} hostname: ${hostname:localhost}
preferIpAddress: true preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
client: client:
serviceUrl: serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/ defaultZone: http://${eureka.instance.hostname}:8080/eureka/
...@@ -9,15 +11,7 @@ eureka: ...@@ -9,15 +11,7 @@ eureka:
enabled: true enabled: true
eurekaServiceUrlPollIntervalSeconds: 60 eurekaServiceUrlPollIntervalSeconds: 60
endpoints:
health:
sensitive: false
management: management:
security:
enabled: false
health: health:
status: status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
...@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s ...@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s
declare -i total_time=0 declare -i total_time=0
printf "Waiting for server startup" printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]]; until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do do
printf "." printf "."
counter+=1 counter+=1
......
...@@ -5,10 +5,10 @@ import com.ctrip.framework.apollo.AdminServiceTestConfiguration; ...@@ -5,10 +5,10 @@ import com.ctrip.framework.apollo.AdminServiceTestConfiguration;
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.autoconfigure.web.HttpMessageConverters; import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.WebIntegrationTest; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -16,14 +16,13 @@ import org.springframework.web.client.RestTemplate; ...@@ -16,14 +16,13 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = AdminServiceTestConfiguration.class) @SpringBootTest(classes = AdminServiceTestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@WebIntegrationTest(randomPort = true)
public abstract class AbstractControllerTest { public abstract class AbstractControllerTest {
@Autowired @Autowired
private HttpMessageConverters httpMessageConverters; private HttpMessageConverters httpMessageConverters;
RestTemplate restTemplate = new TestRestTemplate(); protected RestTemplate restTemplate = (new TestRestTemplate()).getRestTemplate();
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
......
...@@ -53,7 +53,7 @@ public class AppControllerTest extends AbstractControllerTest { ...@@ -53,7 +53,7 @@ public class AppControllerTest extends AbstractControllerTest {
Assert.assertEquals(dto.getAppId(), result.getAppId()); Assert.assertEquals(dto.getAppId(), result.getAppId());
Assert.assertTrue(result.getId() > 0); Assert.assertTrue(result.getId() > 0);
App savedApp = appRepository.findOne(result.getId()); App savedApp = appRepository.findById(result.getId()).orElse(null);
Assert.assertEquals(dto.getAppId(), savedApp.getAppId()); Assert.assertEquals(dto.getAppId(), savedApp.getAppId());
Assert.assertNotNull(savedApp.getDataChangeCreatedTime()); Assert.assertNotNull(savedApp.getDataChangeCreatedTime());
} }
...@@ -69,7 +69,7 @@ public class AppControllerTest extends AbstractControllerTest { ...@@ -69,7 +69,7 @@ public class AppControllerTest extends AbstractControllerTest {
Assert.assertEquals(dto.getAppId(), first.getAppId()); Assert.assertEquals(dto.getAppId(), first.getAppId());
Assert.assertTrue(first.getId() > 0); Assert.assertTrue(first.getId() > 0);
App savedApp = appRepository.findOne(first.getId()); App savedApp = appRepository.findById(first.getId()).orElse(null);
Assert.assertEquals(dto.getAppId(), savedApp.getAppId()); Assert.assertEquals(dto.getAppId(), savedApp.getAppId());
Assert.assertNotNull(savedApp.getDataChangeCreatedTime()); Assert.assertNotNull(savedApp.getDataChangeCreatedTime());
...@@ -108,7 +108,7 @@ public class AppControllerTest extends AbstractControllerTest { ...@@ -108,7 +108,7 @@ public class AppControllerTest extends AbstractControllerTest {
restTemplate.delete("http://localhost:{port}/apps/{appId}?operator={operator}", port, app.getAppId(), "test"); restTemplate.delete("http://localhost:{port}/apps/{appId}?operator={operator}", port, app.getAppId(), "test");
App deletedApp = appRepository.findOne(app.getId()); App deletedApp = appRepository.findById(app.getId()).orElse(null);
Assert.assertNull(deletedApp); Assert.assertNull(deletedApp);
} }
......
...@@ -56,7 +56,7 @@ public class ControllerExceptionTest { ...@@ -56,7 +56,7 @@ public class ControllerExceptionTest {
@Test @Test
public void testFindEmpty() { public void testFindEmpty() {
when(appService.findAll(any(Pageable.class))).thenReturn(new ArrayList<App>()); when(appService.findAll(any(Pageable.class))).thenReturn(new ArrayList<App>());
Pageable pageable = new PageRequest(0, 10); Pageable pageable = PageRequest.of(0, 10);
List<AppDTO> appDTOs = appController.find(null, pageable); List<AppDTO> appDTOs = appController.find(null, pageable);
Assert.assertNotNull(appDTOs); Assert.assertNotNull(appDTOs);
Assert.assertEquals(0, appDTOs.size()); Assert.assertEquals(0, appDTOs.size());
...@@ -68,7 +68,7 @@ public class ControllerExceptionTest { ...@@ -68,7 +68,7 @@ public class ControllerExceptionTest {
@Test @Test
public void testFindByName() { public void testFindByName() {
Pageable pageable = new PageRequest(0, 10); Pageable pageable = PageRequest.of(0, 10);
List<AppDTO> appDTOs = appController.find("unexist", pageable); List<AppDTO> appDTOs = appController.find("unexist", pageable);
Assert.assertNotNull(appDTOs); Assert.assertNotNull(appDTOs);
Assert.assertEquals(0, appDTOs.size()); Assert.assertEquals(0, appDTOs.size());
......
...@@ -20,6 +20,7 @@ import org.mockito.Mock; ...@@ -20,6 +20,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
...@@ -47,7 +48,6 @@ public class InstanceConfigControllerTest { ...@@ -47,7 +48,6 @@ public class InstanceConfigControllerTest {
@Mock @Mock
private InstanceService instanceService; private InstanceService instanceService;
@Mock
private Pageable pageable; private Pageable pageable;
@Before @Before
...@@ -55,6 +55,8 @@ public class InstanceConfigControllerTest { ...@@ -55,6 +55,8 @@ public class InstanceConfigControllerTest {
instanceConfigController = new InstanceConfigController(); instanceConfigController = new InstanceConfigController();
ReflectionTestUtils.setField(instanceConfigController, "releaseService", releaseService); ReflectionTestUtils.setField(instanceConfigController, "releaseService", releaseService);
ReflectionTestUtils.setField(instanceConfigController, "instanceService", instanceService); ReflectionTestUtils.setField(instanceConfigController, "instanceService", instanceService);
pageable = PageRequest.of(0, 2);
} }
@Test @Test
...@@ -230,7 +232,6 @@ public class InstanceConfigControllerTest { ...@@ -230,7 +232,6 @@ public class InstanceConfigControllerTest {
String someIp = "someIp"; String someIp = "someIp";
long someInstanceId = 1; long someInstanceId = 1;
long anotherInstanceId = 2; long anotherInstanceId = 2;
Pageable pageable = mock(Pageable.class);
Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName, Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName,
someNamespaceName, someIp); someNamespaceName, someIp);
...@@ -270,7 +271,6 @@ public class InstanceConfigControllerTest { ...@@ -270,7 +271,6 @@ public class InstanceConfigControllerTest {
String someIp = "someIp"; String someIp = "someIp";
long someInstanceId = 1; long someInstanceId = 1;
long anotherInstanceId = 2; long anotherInstanceId = 2;
Pageable pageable = mock(Pageable.class);
Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName, Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName,
someNamespaceName, someIp); someNamespaceName, someIp);
...@@ -352,4 +352,4 @@ public class InstanceConfigControllerTest { ...@@ -352,4 +352,4 @@ public class InstanceConfigControllerTest {
instanceConfig.setReleaseDeliveryTime(releaseDeliveryTime); instanceConfig.setReleaseDeliveryTime(releaseDeliveryTime);
return instanceConfig; return instanceConfig;
} }
} }
\ No newline at end of file
...@@ -11,7 +11,7 @@ import com.ctrip.framework.apollo.common.dto.NamespaceDTO; ...@@ -11,7 +11,7 @@ import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql;
...@@ -47,7 +47,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -47,7 +47,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets itemSet = new ItemChangeSets(); ItemChangeSets itemSet = new ItemChangeSets();
itemSet.setDataChangeLastModifiedBy("created"); itemSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate(); RestTemplate createdTemplate = (new TestRestTemplate()).getRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters()); createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3; int createdSize = 3;
...@@ -96,7 +96,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -96,7 +96,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets createChangeSet = new ItemChangeSets(); ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created"); createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdRestTemplate = new TestRestTemplate(); RestTemplate createdRestTemplate = (new TestRestTemplate()).getRestTemplate();
createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters()); createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3; int createdSize = 3;
...@@ -123,7 +123,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -123,7 +123,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets updateChangeSet = new ItemChangeSets(); ItemChangeSets updateChangeSet = new ItemChangeSets();
updateChangeSet.setDataChangeLastModifiedBy("updated"); updateChangeSet.setDataChangeLastModifiedBy("updated");
RestTemplate updatedRestTemplate = new TestRestTemplate(); RestTemplate updatedRestTemplate = (new TestRestTemplate()).getRestTemplate();
updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters()); updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
int updatedSize = 2; int updatedSize = 2;
...@@ -170,7 +170,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -170,7 +170,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets createChangeSet = new ItemChangeSets(); ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created"); createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate(); RestTemplate createdTemplate = (new TestRestTemplate()).getRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters()); createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3; int createdSize = 3;
...@@ -196,7 +196,7 @@ public class ItemSetControllerTest extends AbstractControllerTest { ...@@ -196,7 +196,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets deleteChangeSet = new ItemChangeSets(); ItemChangeSets deleteChangeSet = new ItemChangeSets();
deleteChangeSet.setDataChangeLastModifiedBy("deleted"); deleteChangeSet.setDataChangeLastModifiedBy("deleted");
RestTemplate deletedTemplate = new TestRestTemplate(); RestTemplate deletedTemplate = (new TestRestTemplate()).getRestTemplate();
deletedTemplate.setMessageConverters(restTemplate.getMessageConverters()); deletedTemplate.setMessageConverters(restTemplate.getMessageConverters());
int deletedSize = 1; int deletedSize = 1;
......
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1 spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true spring.h2.console.settings.web-allow-others=true
......
eureka: eureka:
instance: instance:
hostname: ${hostname:localhost} hostname: ${hostname:localhost}
preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
client: client:
serviceUrl: serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8090/eureka/ defaultZone: http://${eureka.instance.hostname}:8090/eureka/
healthcheck: healthcheck:
enabled: true enabled: true
endpoints:
health:
sensitive: false
management: management:
security:
enabled: false
health: health:
status: status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
...@@ -6,6 +6,7 @@ import com.ctrip.framework.apollo.portal.PortalApplication; ...@@ -6,6 +6,7 @@ import com.ctrip.framework.apollo.portal.PortalApplication;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
...@@ -24,7 +25,7 @@ public class ApolloApplication { ...@@ -24,7 +25,7 @@ public class ApolloApplication {
* Common * Common
*/ */
ConfigurableApplicationContext commonContext = ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(ApolloApplication.class).web(false).run(args); new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args);
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive()); logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
/** /**
......
...@@ -6,6 +6,7 @@ import com.ctrip.framework.apollo.portal.PortalApplication; ...@@ -6,6 +6,7 @@ import com.ctrip.framework.apollo.portal.PortalApplication;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
...@@ -24,7 +25,7 @@ public class LocalApolloApplication { ...@@ -24,7 +25,7 @@ public class LocalApolloApplication {
* Common * Common
*/ */
ConfigurableApplicationContext commonContext = ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(ApolloApplication.class).web(false).run(args); new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args);
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive()); logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
/** /**
......
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true spring.h2.console.settings.web-allow-others=true
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<!-- eureka --> <!-- eureka -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependency>
<!-- end of eureka --> <!-- end of eureka -->
<dependency> <dependency>
......
...@@ -7,6 +7,7 @@ import java.util.Date; ...@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.PrePersist; import javax.persistence.PrePersist;
import javax.persistence.Table; import javax.persistence.Table;
...@@ -18,7 +19,7 @@ import javax.persistence.Table; ...@@ -18,7 +19,7 @@ import javax.persistence.Table;
@Table(name = "Instance") @Table(name = "Instance")
public class Instance { public class Instance {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id") @Column(name = "Id")
private long id; private long id;
......
...@@ -7,6 +7,7 @@ import java.util.Date; ...@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.PrePersist; import javax.persistence.PrePersist;
import javax.persistence.PreUpdate; import javax.persistence.PreUpdate;
...@@ -19,7 +20,7 @@ import javax.persistence.Table; ...@@ -19,7 +20,7 @@ import javax.persistence.Table;
@Table(name = "InstanceConfig") @Table(name = "InstanceConfig")
public class InstanceConfig { public class InstanceConfig {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id") @Column(name = "Id")
private long id; private long id;
......
...@@ -7,6 +7,7 @@ import java.util.Date; ...@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.PrePersist; import javax.persistence.PrePersist;
import javax.persistence.Table; import javax.persistence.Table;
...@@ -18,7 +19,7 @@ import javax.persistence.Table; ...@@ -18,7 +19,7 @@ import javax.persistence.Table;
@Table(name = "ReleaseMessage") @Table(name = "ReleaseMessage")
public class ReleaseMessage { public class ReleaseMessage {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id") @Column(name = "Id")
private long id; private long id;
......
...@@ -88,7 +88,7 @@ public class DatabaseMessageSender implements MessageSender { ...@@ -88,7 +88,7 @@ public class DatabaseMessageSender implements MessageSender {
private void cleanMessage(Long id) { private void cleanMessage(Long id) {
boolean hasMore = true; boolean hasMore = true;
//double check in case the release message is rolled back //double check in case the release message is rolled back
ReleaseMessage releaseMessage = releaseMessageRepository.findOne(id); ReleaseMessage releaseMessage = releaseMessageRepository.findById(id).orElse(null);
if (releaseMessage == null) { if (releaseMessage == null) {
return; return;
} }
...@@ -96,7 +96,7 @@ public class DatabaseMessageSender implements MessageSender { ...@@ -96,7 +96,7 @@ public class DatabaseMessageSender implements MessageSender {
List<ReleaseMessage> messages = releaseMessageRepository.findFirst100ByMessageAndIdLessThanOrderByIdAsc( List<ReleaseMessage> messages = releaseMessageRepository.findFirst100ByMessageAndIdLessThanOrderByIdAsc(
releaseMessage.getMessage(), releaseMessage.getId()); releaseMessage.getMessage(), releaseMessage.getId());
releaseMessageRepository.delete(messages); releaseMessageRepository.deleteAll(messages);
hasMore = messages.size() == 100; hasMore = messages.size() == 100;
messages.forEach(toRemove -> Tracer.logEvent( messages.forEach(toRemove -> Tracer.logEvent(
......
...@@ -31,7 +31,7 @@ public class AppService { ...@@ -31,7 +31,7 @@ public class AppService {
@Transactional @Transactional
public void delete(long id, String operator) { public void delete(long id, String operator) {
App app = appRepository.findOne(id); App app = appRepository.findById(id).orElse(null);
if (app == null) { if (app == null) {
return; return;
} }
......
...@@ -40,7 +40,7 @@ public class ClusterService { ...@@ -40,7 +40,7 @@ public class ClusterService {
} }
public Cluster findOne(long clusterId) { public Cluster findOne(long clusterId) {
return clusterRepository.findOne(clusterId); return clusterRepository.findById(clusterId).orElse(null);
} }
public List<Cluster> findParentClusters(String appId) { public List<Cluster> findParentClusters(String appId) {
...@@ -85,7 +85,7 @@ public class ClusterService { ...@@ -85,7 +85,7 @@ public class ClusterService {
@Transactional @Transactional
public void delete(long id, String operator) { public void delete(long id, String operator) {
Cluster cluster = clusterRepository.findOne(id); Cluster cluster = clusterRepository.findById(id).orElse(null);
if (cluster == null) { if (cluster == null) {
throw new BadRequestException("cluster not exist"); throw new BadRequestException("cluster not exist");
} }
......
...@@ -41,7 +41,7 @@ public class InstanceService { ...@@ -41,7 +41,7 @@ public class InstanceService {
} }
public List<Instance> findInstancesByIds(Set<Long> instanceIds) { public List<Instance> findInstancesByIds(Set<Long> instanceIds) {
Iterable<Instance> instances = instanceRepository.findAll(instanceIds); Iterable<Instance> instances = instanceRepository.findAllById(instanceIds);
if (instances == null) { if (instances == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -159,7 +159,7 @@ public class InstanceService { ...@@ -159,7 +159,7 @@ public class InstanceService {
@Transactional @Transactional
public InstanceConfig updateInstanceConfig(InstanceConfig instanceConfig) { public InstanceConfig updateInstanceConfig(InstanceConfig instanceConfig) {
InstanceConfig existedInstanceConfig = instanceConfigRepository.findOne(instanceConfig.getId()); InstanceConfig existedInstanceConfig = instanceConfigRepository.findById(instanceConfig.getId()).orElse(null);
Preconditions.checkArgument(existedInstanceConfig != null, String.format( Preconditions.checkArgument(existedInstanceConfig != null, String.format(
"Instance config %d doesn't exist", instanceConfig.getId())); "Instance config %d doesn't exist", instanceConfig.getId()));
......
...@@ -38,7 +38,7 @@ public class ItemService { ...@@ -38,7 +38,7 @@ public class ItemService {
@Transactional @Transactional
public Item delete(long id, String operator) { public Item delete(long id, String operator) {
Item item = itemRepository.findOne(id); Item item = itemRepository.findById(id).orElse(null);
if (item == null) { if (item == null) {
throw new IllegalArgumentException("item not exist. ID:" + id); throw new IllegalArgumentException("item not exist. ID:" + id);
} }
...@@ -81,7 +81,7 @@ public class ItemService { ...@@ -81,7 +81,7 @@ public class ItemService {
} }
public Item findOne(long itemId) { public Item findOne(long itemId) {
Item item = itemRepository.findOne(itemId); Item item = itemRepository.findById(itemId).orElse(null);
return item; return item;
} }
...@@ -147,7 +147,7 @@ public class ItemService { ...@@ -147,7 +147,7 @@ public class ItemService {
@Transactional @Transactional
public Item update(Item item) { public Item update(Item item) {
checkItemValueLength(item.getNamespaceId(), item.getValue()); checkItemValueLength(item.getNamespaceId(), item.getValue());
Item managedItem = itemRepository.findOne(item.getId()); Item managedItem = itemRepository.findById(item.getId()).orElse(null);
BeanUtils.copyEntityProperties(item, managedItem); BeanUtils.copyEntityProperties(item, managedItem);
managedItem = itemRepository.save(managedItem); managedItem = itemRepository.save(managedItem);
......
...@@ -67,7 +67,7 @@ public class NamespaceService { ...@@ -67,7 +67,7 @@ public class NamespaceService {
public Namespace findOne(Long namespaceId) { public Namespace findOne(Long namespaceId) {
return namespaceRepository.findOne(namespaceId); return namespaceRepository.findById(namespaceId).orElse(null);
} }
public Namespace findOne(String appId, String clusterName, String namespaceName) { public Namespace findOne(String appId, String clusterName, String namespaceName) {
......
...@@ -64,7 +64,7 @@ public class ReleaseService { ...@@ -64,7 +64,7 @@ public class ReleaseService {
private ItemSetService itemSetService; private ItemSetService itemSetService;
public Release findOne(long releaseId) { public Release findOne(long releaseId) {
return releaseRepository.findOne(releaseId); return releaseRepository.findById(releaseId).orElse(null);
} }
...@@ -73,7 +73,7 @@ public class ReleaseService { ...@@ -73,7 +73,7 @@ public class ReleaseService {
} }
public List<Release> findByReleaseIds(Set<Long> releaseIds) { public List<Release> findByReleaseIds(Set<Long> releaseIds) {
Iterable<Release> releases = releaseRepository.findAll(releaseIds); Iterable<Release> releases = releaseRepository.findAllById(releaseIds);
if (releases == null) { if (releases == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -397,7 +397,7 @@ public class ReleaseService { ...@@ -397,7 +397,7 @@ public class ReleaseService {
String clusterName = release.getClusterName(); String clusterName = release.getClusterName();
String namespaceName = release.getNamespaceName(); String namespaceName = release.getNamespaceName();
PageRequest page = new PageRequest(0, 2); PageRequest page = PageRequest.of(0, 2);
List<Release> twoLatestActiveReleases = findActiveReleases(appId, clusterName, namespaceName, page); List<Release> twoLatestActiveReleases = findActiveReleases(appId, clusterName, namespaceName, page);
if (twoLatestActiveReleases == null || twoLatestActiveReleases.size() < 2) { if (twoLatestActiveReleases == null || twoLatestActiveReleases.size() < 2) {
throw new BadRequestException(String.format( throw new BadRequestException(String.format(
......
package com.ctrip.framework.apollo.biz; package com.ctrip.framework.apollo.biz;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.WebIntegrationTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.annotation.Rollback; import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -10,8 +10,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -10,8 +10,7 @@ import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@Rollback @Rollback
@Transactional @Transactional
@WebIntegrationTest(randomPort = true) @SpringBootTest(classes = BizTestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@SpringApplicationConfiguration(classes = BizTestConfiguration.class)
public abstract class AbstractIntegrationTest { public abstract class AbstractIntegrationTest {
} }
...@@ -77,4 +77,4 @@ public class BizConfigTest { ...@@ -77,4 +77,4 @@ public class BizConfigTest {
assertEquals(someValidValue, bizConfig.checkInt(someValidValue, Integer.MIN_VALUE, Integer.MAX_VALUE, assertEquals(someValidValue, bizConfig.checkInt(someValidValue, Integer.MIN_VALUE, Integer.MAX_VALUE,
someDefaultValue)); someDefaultValue));
} }
} }
\ No newline at end of file
...@@ -51,7 +51,7 @@ public class AppRepositoryTest extends AbstractIntegrationTest{ ...@@ -51,7 +51,7 @@ public class AppRepositoryTest extends AbstractIntegrationTest{
Assert.assertEquals(1, appRepository.count()); Assert.assertEquals(1, appRepository.count());
appRepository.delete(app.getId()); appRepository.deleteById(app.getId());
Assert.assertEquals(0, appRepository.count()); Assert.assertEquals(0, appRepository.count());
} }
......
...@@ -119,7 +119,7 @@ public class InstanceServiceTest extends AbstractIntegrationTest { ...@@ -119,7 +119,7 @@ public class InstanceServiceTest extends AbstractIntegrationTest {
String someConfigClusterName = "someConfigClusterName"; String someConfigClusterName = "someConfigClusterName";
String someConfigNamespaceName = "someConfigNamespaceName"; String someConfigNamespaceName = "someConfigNamespaceName";
Date someValidDate = new Date(); Date someValidDate = new Date();
Pageable pageable = new PageRequest(0, 10); Pageable pageable = PageRequest.of(0, 10);
String someReleaseKey = "someReleaseKey"; String someReleaseKey = "someReleaseKey";
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
...@@ -165,7 +165,7 @@ public class InstanceServiceTest extends AbstractIntegrationTest { ...@@ -165,7 +165,7 @@ public class InstanceServiceTest extends AbstractIntegrationTest {
someConfigNamespaceName, someReleaseKey, someValidDate); someConfigNamespaceName, someReleaseKey, someValidDate);
Page<Instance> result = instanceService.findInstancesByNamespace(someConfigAppId, Page<Instance> result = instanceService.findInstancesByNamespace(someConfigAppId,
someConfigClusterName, someConfigNamespaceName, new PageRequest(0, 10)); someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
assertEquals(Lists.newArrayList(someInstance, anotherInstance), result.getContent()); assertEquals(Lists.newArrayList(someInstance, anotherInstance), result.getContent());
} }
...@@ -197,9 +197,9 @@ public class InstanceServiceTest extends AbstractIntegrationTest { ...@@ -197,9 +197,9 @@ public class InstanceServiceTest extends AbstractIntegrationTest {
someConfigNamespaceName, someReleaseKey, someValidDate); someConfigNamespaceName, someReleaseKey, someValidDate);
Page<Instance> result = instanceService.findInstancesByNamespaceAndInstanceAppId(someAppId, Page<Instance> result = instanceService.findInstancesByNamespaceAndInstanceAppId(someAppId,
someConfigAppId, someConfigClusterName, someConfigNamespaceName, new PageRequest(0, 10)); someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
Page<Instance> anotherResult = instanceService.findInstancesByNamespaceAndInstanceAppId(anotherAppId, Page<Instance> anotherResult = instanceService.findInstancesByNamespaceAndInstanceAppId(anotherAppId,
someConfigAppId, someConfigClusterName, someConfigNamespaceName, new PageRequest(0, 10)); someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
assertEquals(Lists.newArrayList(someInstance), result.getContent()); assertEquals(Lists.newArrayList(someInstance), result.getContent());
assertEquals(Lists.newArrayList(anotherInstance), anotherResult.getContent()); assertEquals(Lists.newArrayList(anotherInstance), anotherResult.getContent());
......
...@@ -28,7 +28,7 @@ public class NamespaceBranchServiceTest extends AbstractIntegrationTest { ...@@ -28,7 +28,7 @@ public class NamespaceBranchServiceTest extends AbstractIntegrationTest {
private String testNamespace = "application"; private String testNamespace = "application";
private String testBranchName = "child-cluster"; private String testBranchName = "child-cluster";
private String operator = "apollo"; private String operator = "apollo";
private Pageable pageable = new PageRequest(0, 10); private Pageable pageable = PageRequest.of(0, 10);
@Test @Test
@Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
......
...@@ -64,19 +64,19 @@ public class NamespaceServiceIntegrationTest extends AbstractIntegrationTest { ...@@ -64,19 +64,19 @@ public class NamespaceServiceIntegrationTest extends AbstractIntegrationTest {
namespaceService.deleteNamespace(namespace, testUser); namespaceService.deleteNamespace(namespace, testUser);
List<Item> items = itemService.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace); List<Item> items = itemService.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace);
List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10)); List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace); AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster); List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
InstanceConfig instanceConfig = instanceConfigRepository.findOne(1L); InstanceConfig instanceConfig = instanceConfigRepository.findById(1L).orElse(null);
List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster, List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster,
testPrivateNamespace, testPrivateNamespace,
new PageRequest(0, 10)); PageRequest.of(0, 10));
List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster, List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster,
testPrivateNamespace, testPrivateNamespace,
new PageRequest(0, 10)); PageRequest.of(0, 10));
Page<ReleaseHistory> releaseHistories = Page<ReleaseHistory> releaseHistories =
releaseHistoryService releaseHistoryService
.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10)); .findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
assertEquals(0, items.size()); assertEquals(0, items.size());
assertEquals(0, commits.size()); assertEquals(0, commits.size());
......
...@@ -38,7 +38,7 @@ public class NamespaceServiceTest extends AbstractUnitTest { ...@@ -38,7 +38,7 @@ public class NamespaceServiceTest extends AbstractUnitTest {
@Test(expected = BadRequestException.class) @Test(expected = BadRequestException.class)
public void testFindPublicAppNamespaceWithWrongNamespace() { public void testFindPublicAppNamespaceWithWrongNamespace() {
Pageable page = new PageRequest(0, 10); Pageable page = PageRequest.of(0, 10);
when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(null); when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(null);
...@@ -59,7 +59,7 @@ public class NamespaceServiceTest extends AbstractUnitTest { ...@@ -59,7 +59,7 @@ public class NamespaceServiceTest extends AbstractUnitTest {
MockBeanFactory.mockNamespace("app2", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace); MockBeanFactory.mockNamespace("app2", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
Pageable page = new PageRequest(0, 10); Pageable page = PageRequest.of(0, 10);
when(namespaceRepository.findByNamespaceName(testPublicAppNamespace, page)) when(namespaceRepository.findByNamespaceName(testPublicAppNamespace, page))
.thenReturn(Arrays.asList(firstParentNamespace, secondParentNamespace)); .thenReturn(Arrays.asList(firstParentNamespace, secondParentNamespace));
......
...@@ -36,7 +36,7 @@ public class ReleaseCreationTest extends AbstractIntegrationTest { ...@@ -36,7 +36,7 @@ public class ReleaseCreationTest extends AbstractIntegrationTest {
private String testApp = "test"; private String testApp = "test";
private String testNamespace = "application"; private String testNamespace = "application";
private String operator = "apollo"; private String operator = "apollo";
private Pageable pageable = new PageRequest(0, 10); private Pageable pageable = PageRequest.of(0, 10);
@Test @Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
......
...@@ -9,6 +9,7 @@ import com.ctrip.framework.apollo.biz.entity.Release; ...@@ -9,6 +9,7 @@ import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import java.util.Optional;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -65,13 +66,13 @@ public class ReleaseServiceTest extends AbstractUnitTest { ...@@ -65,13 +66,13 @@ public class ReleaseServiceTest extends AbstractUnitTest {
secondRelease.setNamespaceName(namespaceName); secondRelease.setNamespaceName(namespaceName);
secondRelease.setAbandoned(false); secondRelease.setAbandoned(false);
pageRequest = new PageRequest(0, 2); pageRequest = PageRequest.of(0, 2);
} }
@Test(expected = BadRequestException.class) @Test(expected = BadRequestException.class)
public void testNamespaceNotExist() { public void testNamespaceNotExist() {
when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease); when(releaseRepository.findById(releaseId)).thenReturn(Optional.of(firstRelease));
releaseService.rollback(releaseId, user); releaseService.rollback(releaseId, user);
} }
...@@ -79,7 +80,7 @@ public class ReleaseServiceTest extends AbstractUnitTest { ...@@ -79,7 +80,7 @@ public class ReleaseServiceTest extends AbstractUnitTest {
@Test(expected = BadRequestException.class) @Test(expected = BadRequestException.class)
public void testHasNoRelease() { public void testHasNoRelease() {
when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease); when(releaseRepository.findById(releaseId)).thenReturn(Optional.of(firstRelease));
when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId, when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId,
clusterName, clusterName,
namespaceName, namespaceName,
...@@ -92,7 +93,7 @@ public class ReleaseServiceTest extends AbstractUnitTest { ...@@ -92,7 +93,7 @@ public class ReleaseServiceTest extends AbstractUnitTest {
@Test @Test
public void testRollback() { public void testRollback() {
when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease); when(releaseRepository.findById(releaseId)).thenReturn(Optional.of(firstRelease));
when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId, when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId,
clusterName, clusterName,
namespaceName, namespaceName,
...@@ -166,7 +167,7 @@ public class ReleaseServiceTest extends AbstractUnitTest { ...@@ -166,7 +167,7 @@ public class ReleaseServiceTest extends AbstractUnitTest {
List<Release> someReleases = Lists.newArrayList(someRelease, anotherRelease); List<Release> someReleases = Lists.newArrayList(someRelease, anotherRelease);
Set<Long> someReleaseIds = Sets.newHashSet(someReleaseId, anotherReleaseId); Set<Long> someReleaseIds = Sets.newHashSet(someReleaseId, anotherReleaseId);
when(releaseRepository.findAll(someReleaseIds)).thenReturn(someReleases); when(releaseRepository.findAllById(someReleaseIds)).thenReturn(someReleases);
List<Release> result = releaseService.findByReleaseIds(someReleaseIds); List<Release> result = releaseService.findByReleaseIds(someReleaseIds);
......
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true spring.h2.console.settings.web-allow-others=true
......
...@@ -6,7 +6,6 @@ import static org.junit.Assert.assertNull; ...@@ -6,7 +6,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.ConfigFileChangeListener; import com.ctrip.framework.apollo.ConfigFileChangeListener;
import com.ctrip.framework.apollo.enums.PropertyChangeType; import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigFileChangeEvent; import com.ctrip.framework.apollo.model.ConfigFileChangeEvent;
......
...@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.internals; ...@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.internals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -12,11 +11,9 @@ import static org.mockito.Mockito.times; ...@@ -12,11 +11,9 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.Apollo;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
......
...@@ -20,7 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,7 +20,7 @@ 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.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
...@@ -36,7 +36,7 @@ public class BootstrapConfigTest { ...@@ -36,7 +36,7 @@ public class BootstrapConfigTest {
private static final String FX_APOLLO_NAMESPACE = "FX.apollo"; private static final String FX_APOLLO_NAMESPACE = "FX.apollo";
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class) @SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext @DirtiesContext
public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOn extends public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOn extends
AbstractSpringIntegrationTest { AbstractSpringIntegrationTest {
...@@ -90,7 +90,7 @@ public class BootstrapConfigTest { ...@@ -90,7 +90,7 @@ public class BootstrapConfigTest {
} }
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class) @SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext @DirtiesContext
public static class TestWithBootstrapEnabledAndNamespacesAndConditionalOn extends public static class TestWithBootstrapEnabledAndNamespacesAndConditionalOn extends
AbstractSpringIntegrationTest { AbstractSpringIntegrationTest {
...@@ -132,7 +132,7 @@ public class BootstrapConfigTest { ...@@ -132,7 +132,7 @@ public class BootstrapConfigTest {
} }
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class) @SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext @DirtiesContext
public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOnFailed extends public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOnFailed extends
AbstractSpringIntegrationTest { AbstractSpringIntegrationTest {
...@@ -168,7 +168,7 @@ public class BootstrapConfigTest { ...@@ -168,7 +168,7 @@ public class BootstrapConfigTest {
} }
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithoutConditionalOnProperty.class) @SpringBootTest(classes = ConfigurationWithoutConditionalOnProperty.class)
@DirtiesContext @DirtiesContext
public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOff extends public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOff extends
AbstractSpringIntegrationTest { AbstractSpringIntegrationTest {
...@@ -202,7 +202,7 @@ public class BootstrapConfigTest { ...@@ -202,7 +202,7 @@ public class BootstrapConfigTest {
} }
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class) @SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext @DirtiesContext
public static class TestWithBootstrapDisabledAndDefaultNamespacesAndConditionalOn extends public static class TestWithBootstrapDisabledAndDefaultNamespacesAndConditionalOn extends
AbstractSpringIntegrationTest { AbstractSpringIntegrationTest {
...@@ -234,7 +234,7 @@ public class BootstrapConfigTest { ...@@ -234,7 +234,7 @@ public class BootstrapConfigTest {
} }
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithoutConditionalOnProperty.class) @SpringBootTest(classes = ConfigurationWithoutConditionalOnProperty.class)
@DirtiesContext @DirtiesContext
public static class TestWithBootstrapDisabledAndDefaultNamespacesAndConditionalOff extends public static class TestWithBootstrapDisabledAndDefaultNamespacesAndConditionalOff extends
AbstractSpringIntegrationTest { AbstractSpringIntegrationTest {
......
...@@ -30,17 +30,6 @@ ...@@ -30,17 +30,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-spectator</artifactId>
<!-- duplicated with spring-security-core -->
<exclusions>
<exclusion>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
......
package com.ctrip.framework.apollo.common.controller; package com.ctrip.framework.apollo.common.controller;
import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.CharacterEncodingFilter;
......
...@@ -3,7 +3,7 @@ package com.ctrip.framework.apollo.common.controller; ...@@ -3,7 +3,7 @@ package com.ctrip.framework.apollo.common.controller;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.ByteArrayHttpMessageConverter;
......
package com.ctrip.framework.apollo.common.controller; package com.ctrip.framework.apollo.common.controller;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.web.server.MimeMappings;
import org.springframework.boot.context.embedded.MimeMappings; import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List; import java.util.List;
@Configuration @Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter implements EmbeddedServletContainerCustomizer { public class WebMvcConfig implements WebMvcConfigurer, WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
@Override @Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver pageResolver = PageableHandlerMethodArgumentResolver pageResolver =
new PageableHandlerMethodArgumentResolver(); new PageableHandlerMethodArgumentResolver();
pageResolver.setFallbackPageable(new PageRequest(0, 10)); pageResolver.setFallbackPageable(PageRequest.of(0, 10));
argumentResolvers.add(pageResolver); argumentResolvers.add(pageResolver);
} }
...@@ -32,9 +32,9 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter implements EmbeddedSer ...@@ -32,9 +32,9 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter implements EmbeddedSer
} }
@Override @Override
public void customize(ConfigurableEmbeddedServletContainer container) { public void customize(TomcatServletWebServerFactory factory) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("html", "text/html;charset=utf-8"); mappings.add("html", "text/html;charset=utf-8");
container.setMimeMappings(mappings ); factory.setMimeMappings(mappings );
} }
} }
package com.ctrip.framework.apollo.common.customize;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http11.Http11NioProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Component
public class TomcatContainerCustomizer implements EmbeddedServletContainerCustomizer {
private static final Logger logger = LoggerFactory.getLogger(TomcatContainerCustomizer.class);
private static final String TOMCAT_ACCEPTOR_COUNT = "server.tomcat.accept-count";
@Autowired
private Environment environment;
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
return;
}
if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
return;
}
TomcatEmbeddedServletContainerFactory tomcat =
(TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof Http11NioProtocol) {
Http11NioProtocol http = (Http11NioProtocol) handler;
int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT));
http.setBacklog(acceptCount);
logger.info("Setting tomcat accept count to {}", acceptCount);
}
}
});
}
}
...@@ -7,6 +7,7 @@ import java.util.Date; ...@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
...@@ -20,7 +21,7 @@ import javax.persistence.PreUpdate; ...@@ -20,7 +21,7 @@ import javax.persistence.PreUpdate;
public abstract class BaseEntity { public abstract class BaseEntity {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id") @Column(name = "Id")
private long id; private long id;
......
spring.http.converters.preferred-json-mapper=gson spring.http.converters.preferred-json-mapper=gson
# DataSource # DataSource
spring.datasource.testWhileIdle=true spring.datasource.hikari.connectionInitSql=set names utf8mb4
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.validationInterval=5000
spring.datasource.initSQL=set names utf8mb4
# Naming strategy # Naming strategy
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.globally_quoted_identifiers=true spring.jpa.hibernate.globally_quoted_identifiers=true
spring.jpa.properties.hibernate.globally_quoted_identifiers=true spring.jpa.properties.hibernate.globally_quoted_identifiers=true
# Tomcat configuration # Tomcat configuration
server.tomcat.accept-count=5000 server.tomcat.accept-count=5000
# Increase tomcat header size for longer GET query parameter, should be n * 1024 # Increase tomcat header size for longer GET query parameter, should be n * 1024
server.tomcat.maxHttpHeaderSize=10240 server.max-http-header-size=10240
# Spring Boot 2.0
management.endpoints.web.base-path=/
_ _ _
/ \ _ __ ___ | | | ___
/ _ \ | '_ \ / _ \| | |/ _ \
/ ___ \| |_) | (_) | | | (_) |
/_/ \_\ .__/ \___/|_|_|\___/
|_|
:: Spring Boot :: ${spring-boot.formatted-version}
...@@ -23,16 +23,14 @@ ...@@ -23,16 +23,14 @@
<!-- eureka --> <!-- eureka -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId> <artifactId>spring-cloud-starter-netflix-archaius</artifactId>
spring-cloud-starter-archaius
</artifactId>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>spring-cloud-starter-ribbon</artifactId> <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
......
...@@ -24,7 +24,7 @@ public class ConfigServiceHealthIndicator implements HealthIndicator { ...@@ -24,7 +24,7 @@ public class ConfigServiceHealthIndicator implements HealthIndicator {
} }
private int check() { private int check() {
PageRequest pageable = new PageRequest(0, 1); PageRequest pageable = PageRequest.of(0, 1);
appService.findAll(pageable); appService.findAll(pageable);
return 0; return 0;
} }
......
package com.ctrip.framework.apollo.configservice; package com.ctrip.framework.apollo.configservice;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/** /**
* Entry point for traditional web app * Entry point for traditional web app
......
...@@ -186,7 +186,7 @@ public class AppNamespaceServiceWithCache implements InitializingBean { ...@@ -186,7 +186,7 @@ public class AppNamespaceServiceWithCache implements InitializingBean {
} }
List<List<Long>> partitionIds = Lists.partition(ids, 500); List<List<Long>> partitionIds = Lists.partition(ids, 500);
for (List<Long> toRebuild : partitionIds) { for (List<Long> toRebuild : partitionIds) {
Iterable<AppNamespace> appNamespaces = appNamespaceRepository.findAll(toRebuild); Iterable<AppNamespace> appNamespaces = appNamespaceRepository.findAllById(toRebuild);
if (appNamespaces == null) { if (appNamespaces == null) {
continue; continue;
......
...@@ -2,6 +2,8 @@ eureka: ...@@ -2,6 +2,8 @@ eureka:
instance: instance:
hostname: ${hostname:localhost} hostname: ${hostname:localhost}
preferIpAddress: true preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
server: server:
peerEurekaNodesUpdateIntervalMs: 60000 peerEurekaNodesUpdateIntervalMs: 60000
enableSelfPreservation: false enableSelfPreservation: false
...@@ -12,13 +14,7 @@ eureka: ...@@ -12,13 +14,7 @@ eureka:
enabled: true enabled: true
eurekaServiceUrlPollIntervalSeconds: 60 eurekaServiceUrlPollIntervalSeconds: 60
endpoints:
health:
sensitive: false
management: management:
security:
enabled: false
health: health:
status: status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
spring.application.name= apollo-configservice spring.application.name= apollo-configservice
ctrip.appid= 100003171 ctrip.appid= 100003171
server.port= 8080 server.port= 8080
logging.file= /opt/logs/100003171/apollo-configservice.log logging.file= /opt/logs/100003171/apollo-configservice.log
\ No newline at end of file spring.jmx.default-domain = apollo-configservice
...@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s ...@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s
declare -i total_time=0 declare -i total_time=0
printf "Waiting for server startup" printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]]; until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do do
printf "." printf "."
counter+=1 counter+=1
......
...@@ -14,9 +14,9 @@ import com.ctrip.framework.apollo.biz.utils.ReleaseKeyGenerator; ...@@ -14,9 +14,9 @@ import com.ctrip.framework.apollo.biz.utils.ReleaseKeyGenerator;
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.test.SpringApplicationConfiguration; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.WebIntegrationTest; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
...@@ -36,8 +36,7 @@ import javax.annotation.PostConstruct; ...@@ -36,8 +36,7 @@ import javax.annotation.PostConstruct;
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = AbstractBaseIntegrationTest.TestConfiguration.class) @SpringBootTest(classes = AbstractBaseIntegrationTest.TestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@WebIntegrationTest(randomPort = true)
public abstract class AbstractBaseIntegrationTest { public abstract class AbstractBaseIntegrationTest {
@Autowired @Autowired
private ReleaseMessageRepository releaseMessageRepository; private ReleaseMessageRepository releaseMessageRepository;
...@@ -46,7 +45,7 @@ public abstract class AbstractBaseIntegrationTest { ...@@ -46,7 +45,7 @@ public abstract class AbstractBaseIntegrationTest {
private Gson gson = new Gson(); private Gson gson = new Gson();
RestTemplate restTemplate = new TestRestTemplate(); protected RestTemplate restTemplate = (new TestRestTemplate()).getRestTemplate();
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
...@@ -57,7 +56,7 @@ public abstract class AbstractBaseIntegrationTest { ...@@ -57,7 +56,7 @@ public abstract class AbstractBaseIntegrationTest {
int port; int port;
protected String getHostUrl() { protected String getHostUrl() {
return "http://localhost:" + port; return "localhost:" + port;
} }
@Configuration @Configuration
......
...@@ -72,7 +72,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -72,7 +72,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testQueryConfigAsProperties() throws Exception { public void testQueryConfigAsProperties() throws Exception {
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class, .getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace); getHostUrl(), someAppId, someCluster, someNamespace);
String result = response.getBody(); String result = response.getBody();
...@@ -96,12 +96,12 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -96,12 +96,12 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class, .getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class,
getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, grayClientIp); getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, grayClientIp);
ResponseEntity<String> anotherResponse = ResponseEntity<String> anotherResponse =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class, .getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class,
getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, nonGrayClientIp); getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, nonGrayClientIp);
String result = response.getBody(); String result = response.getBody();
...@@ -123,7 +123,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -123,7 +123,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity( .getForEntity(
"{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}", "http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
String.class, String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);
...@@ -140,7 +140,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -140,7 +140,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testQueryConfigAsJson() throws Exception { public void testQueryConfigAsJson() throws Exception {
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class, .getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace); getHostUrl(), someAppId, someCluster, someNamespace);
Map<String, String> configs = gson.fromJson(response.getBody(), mapResponseType); Map<String, String> configs = gson.fromJson(response.getBody(), mapResponseType);
...@@ -155,7 +155,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -155,7 +155,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testQueryConfigAsJsonWithIncorrectCase() throws Exception { public void testQueryConfigAsJsonWithIncorrectCase() throws Exception {
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class, .getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace.toUpperCase()); getHostUrl(), someAppId, someCluster, someNamespace.toUpperCase());
Map<String, String> configs = gson.fromJson(response.getBody(), mapResponseType); Map<String, String> configs = gson.fromJson(response.getBody(), mapResponseType);
...@@ -172,7 +172,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -172,7 +172,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity( .getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}", "http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
String.class, String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);
...@@ -191,7 +191,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -191,7 +191,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity( .getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}", "http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
String.class, String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), someDC); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), someDC);
...@@ -219,14 +219,14 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -219,14 +219,14 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity( .getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}", "http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class, String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, grayClientIp); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, grayClientIp);
ResponseEntity<String> anotherResponse = ResponseEntity<String> anotherResponse =
restTemplate restTemplate
.getForEntity( .getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}", "http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class, String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, nonGrayClientIp); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, nonGrayClientIp);
...@@ -260,14 +260,14 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -260,14 +260,14 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity( .getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}", "http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class, String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), grayClientIp); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), grayClientIp);
ResponseEntity<String> anotherResponse = ResponseEntity<String> anotherResponse =
restTemplate restTemplate
.getForEntity( .getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}", "http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class, String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), nonGrayClientIp); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), nonGrayClientIp);
...@@ -290,7 +290,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -290,7 +290,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testConfigChanged() throws Exception { public void testConfigChanged() throws Exception {
ResponseEntity<String> response = ResponseEntity<String> response =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class, .getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace); getHostUrl(), someAppId, someCluster, someNamespace);
String result = response.getBody(); String result = response.getBody();
...@@ -312,7 +312,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -312,7 +312,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> anotherResponse = ResponseEntity<String> anotherResponse =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class, .getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace); getHostUrl(), someAppId, someCluster, someNamespace);
assertEquals(response.getBody(), anotherResponse.getBody()); assertEquals(response.getBody(), anotherResponse.getBody());
...@@ -325,7 +325,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration ...@@ -325,7 +325,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> newResponse = ResponseEntity<String> newResponse =
restTemplate restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class, .getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace); getHostUrl(), someAppId, someCluster, someNamespace);
result = newResponse.getBody(); result = newResponse.getBody();
......
...@@ -57,7 +57,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -57,7 +57,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop); periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop);
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity( ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace); getHostUrl(), someAppId, someCluster, defaultNamespace);
...@@ -76,7 +76,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -76,7 +76,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop); periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop);
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity( ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace + ".properties"); getHostUrl(), someAppId, someCluster, defaultNamespace + ".properties");
...@@ -98,7 +98,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -98,7 +98,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity( .getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, namespace); getHostUrl(), someAppId, someCluster, namespace);
...@@ -115,7 +115,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -115,7 +115,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespaceWithNotificationIdNull() throws Exception { public void testPollNotificationWithDefaultNamespaceWithNotificationIdNull() throws Exception {
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity( ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace); getHostUrl(), someAppId, someCluster, defaultNamespace);
...@@ -132,7 +132,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -132,7 +132,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
public void testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated() throws Exception { public void testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated() throws Exception {
long someOutDatedNotificationId = 1; long someOutDatedNotificationId = 1;
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity( ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace, someOutDatedNotificationId); getHostUrl(), someAppId, someCluster, defaultNamespace, someOutDatedNotificationId);
...@@ -153,7 +153,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -153,7 +153,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity( .getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace); getHostUrl(), someAppId, someCluster, somePublicNamespace);
...@@ -177,7 +177,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -177,7 +177,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity( .getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace, someDC); getHostUrl(), someAppId, someCluster, somePublicNamespace, someDC);
...@@ -201,7 +201,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -201,7 +201,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity( .getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace + ".properties", someDC); getHostUrl(), someAppId, someCluster, somePublicNamespace + ".properties", someDC);
...@@ -220,7 +220,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati ...@@ -220,7 +220,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
public void testPollNotificationWithPublicNamespaceWithNotificationIdOutDated() throws Exception { public void testPollNotificationWithPublicNamespaceWithNotificationIdOutDated() throws Exception {
long someOutDatedNotificationId = 1; long someOutDatedNotificationId = 1;
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity( ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}", "http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}",
ApolloConfigNotification.class, ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace, someOutDatedNotificationId); getHostUrl(), someAppId, someCluster, somePublicNamespace, someOutDatedNotificationId);
......
...@@ -133,7 +133,7 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -133,7 +133,7 @@ public class AppNamespaceServiceWithCacheTest {
// Add 1 private namespace and 1 public namespace // Add 1 private namespace and 1 public namespace
when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0)).thenReturn(Lists when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0)).thenReturn(Lists
.newArrayList(somePrivateAppNamespace, somePublicAppNamespace)); .newArrayList(somePrivateAppNamespace, somePublicAppNamespace));
when(appNamespaceRepository.findAll(Lists.newArrayList(somePrivateNamespaceId, when(appNamespaceRepository.findAllById(Lists.newArrayList(somePrivateNamespaceId,
somePublicNamespaceId))).thenReturn(Lists.newArrayList(somePrivateAppNamespace, somePublicNamespaceId))).thenReturn(Lists.newArrayList(somePrivateAppNamespace,
somePublicAppNamespace)); somePublicAppNamespace));
...@@ -165,7 +165,7 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -165,7 +165,7 @@ public class AppNamespaceServiceWithCacheTest {
when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(somePublicNamespaceId)) when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(somePublicNamespaceId))
.thenReturn(Lists.newArrayList(anotherPrivateAppNamespace, yetAnotherPrivateAppNamespace, .thenReturn(Lists.newArrayList(anotherPrivateAppNamespace, yetAnotherPrivateAppNamespace,
anotherPublicAppNamespace)); anotherPublicAppNamespace));
when(appNamespaceRepository.findAll(appNamespaceIds)).thenReturn(allAppNamespaces); when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(allAppNamespaces);
scanIntervalTimeUnit.sleep(sleepInterval); scanIntervalTimeUnit.sleep(sleepInterval);
...@@ -213,7 +213,7 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -213,7 +213,7 @@ public class AppNamespaceServiceWithCacheTest {
(somePublicAppNamespace.getDataChangeLastModifiedTime(), 1)); (somePublicAppNamespace.getDataChangeLastModifiedTime(), 1));
// Delete 1 private and 1 public // Delete 1 private and 1 public
when(appNamespaceRepository.findAll(appNamespaceIds)).thenReturn(Lists.newArrayList when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(Lists.newArrayList
(somePrivateAppNamespaceNew, yetAnotherPrivateAppNamespaceNew, somePublicAppNamespaceNew)); (somePrivateAppNamespaceNew, yetAnotherPrivateAppNamespaceNew, somePublicAppNamespaceNew));
scanIntervalTimeUnit.sleep(sleepInterval); scanIntervalTimeUnit.sleep(sleepInterval);
......
...@@ -64,4 +64,4 @@ public class CaseInsensitiveMapWrapperTest { ...@@ -64,4 +64,4 @@ public class CaseInsensitiveMapWrapperTest {
verify(someMap, times(1)).remove(someKey.toLowerCase()); verify(someMap, times(1)).remove(someKey.toLowerCase());
} }
} }
\ No newline at end of file
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1 spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.h2.console.enabled = true spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true spring.h2.console.settings.web-allow-others=true
spring.jpa.properties.hibernate.show_sql=false spring.jpa.properties.hibernate.show_sql=false
......
...@@ -2,20 +2,15 @@ eureka: ...@@ -2,20 +2,15 @@ eureka:
instance: instance:
hostname: ${hostname:localhost} hostname: ${hostname:localhost}
preferIpAddress: true preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
client: client:
serviceUrl: serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/ defaultZone: http://${eureka.instance.hostname}:8080/eureka/
healthcheck: healthcheck:
enabled: true enabled: true
endpoints:
health:
sensitive: false
management: management:
security:
enabled: false
health: health:
status: status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
...@@ -16,7 +16,7 @@ import org.junit.Test; ...@@ -16,7 +16,7 @@ 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.test.SpringApplicationConfiguration; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
...@@ -26,7 +26,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -26,7 +26,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* Create by zhangzheng on 8/16/18 Email:zhangzheng@youzan.com * Create by zhangzheng on 8/16/18 Email:zhangzheng@youzan.com
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = TestConfiguration.class) @SpringBootTest(classes = TestConfiguration.class)
public class ApolloMockServerSpringIntegrationTest { public class ApolloMockServerSpringIntegrationTest {
private static final String otherNamespace = "otherNamespace"; private static final String otherNamespace = "otherNamespace";
......
...@@ -7,6 +7,7 @@ import java.util.Date; ...@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.PrePersist; import javax.persistence.PrePersist;
import javax.persistence.Table; import javax.persistence.Table;
...@@ -18,7 +19,7 @@ import javax.persistence.Table; ...@@ -18,7 +19,7 @@ import javax.persistence.Table;
@Table(name = "ConsumerAudit") @Table(name = "ConsumerAudit")
public class ConsumerAudit { public class ConsumerAudit {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id") @Column(name = "Id")
private long id; private long id;
......
...@@ -109,7 +109,7 @@ public class ConsumerService { ...@@ -109,7 +109,7 @@ public class ConsumerService {
} }
public Consumer getConsumerByConsumerId(long consumerId) { public Consumer getConsumerByConsumerId(long consumerId) {
return consumerRepository.findOne(consumerId); return consumerRepository.findById(consumerId).orElse(null);
} }
public List<ConsumerRole> assignNamespaceRoleToConsumer(String token, String appId, String namespaceName) { public List<ConsumerRole> assignNamespaceRoleToConsumer(String token, String appId, String namespaceName) {
...@@ -177,7 +177,7 @@ public class ConsumerService { ...@@ -177,7 +177,7 @@ public class ConsumerService {
@Transactional @Transactional
public void createConsumerAudits(Iterable<ConsumerAudit> consumerAudits) { public void createConsumerAudits(Iterable<ConsumerAudit> consumerAudits) {
consumerAuditRepository.save(consumerAudits); consumerAuditRepository.saveAll(consumerAudits);
} }
@Transactional @Transactional
......
...@@ -11,7 +11,7 @@ import com.ctrip.framework.apollo.tracer.Tracer; ...@@ -11,7 +11,7 @@ import com.ctrip.framework.apollo.tracer.Tracer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
......
...@@ -7,7 +7,7 @@ import org.apache.http.impl.client.HttpClientBuilder; ...@@ -7,7 +7,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
......
...@@ -20,7 +20,7 @@ import org.springframework.stereotype.Component; ...@@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriTemplateHandler; import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler; import org.springframework.web.util.UriTemplateHandler;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
...@@ -36,7 +36,7 @@ public class RetryableRestTemplate { ...@@ -36,7 +36,7 @@ public class RetryableRestTemplate {
private Logger logger = LoggerFactory.getLogger(RetryableRestTemplate.class); private Logger logger = LoggerFactory.getLogger(RetryableRestTemplate.class);
private UriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler(); private UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory();
private RestTemplate restTemplate; private RestTemplate restTemplate;
......
...@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo; ...@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
...@@ -16,7 +17,7 @@ import javax.persistence.Table; ...@@ -16,7 +17,7 @@ import javax.persistence.Table;
public class UserPO { public class UserPO {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id") @Column(name = "Id")
private long id; private long id;
@Column(name = "Username", nullable = false) @Column(name = "Username", nullable = false)
......
...@@ -77,7 +77,7 @@ public class FavoriteService { ...@@ -77,7 +77,7 @@ public class FavoriteService {
public void deleteFavorite(long favoriteId) { public void deleteFavorite(long favoriteId) {
Favorite favorite = favoriteRepository.findOne(favoriteId); Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null);
checkUserOperatePermission(favorite); checkUserOperatePermission(favorite);
...@@ -85,7 +85,7 @@ public class FavoriteService { ...@@ -85,7 +85,7 @@ public class FavoriteService {
} }
public void adjustFavoriteToFirst(long favoriteId) { public void adjustFavoriteToFirst(long favoriteId) {
Favorite favorite = favoriteRepository.findOne(favoriteId); Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null);
checkUserOperatePermission(favorite); checkUserOperatePermission(favorite);
......
...@@ -22,13 +22,12 @@ import java.util.Collections; ...@@ -22,13 +22,12 @@ import java.util.Collections;
import java.util.EventListener; import java.util.EventListener;
import java.util.Map; import java.util.Map;
import javax.servlet.Filter; import javax.servlet.Filter;
import org.apache.tomcat.jdbc.pool.DataSource; import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletListenerRegistrationBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
...@@ -38,13 +37,13 @@ import org.springframework.ldap.core.ContextSource; ...@@ -38,13 +37,13 @@ import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource; import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.security.authentication.encoding.LdapShaPasswordEncoder;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
import org.springframework.security.provisioning.JdbcUserDetailsManager; import org.springframework.security.provisioning.JdbcUserDetailsManager;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
......
...@@ -4,7 +4,7 @@ import com.ctrip.framework.apollo.openapi.filter.ConsumerAuthenticationFilter; ...@@ -4,7 +4,7 @@ import com.ctrip.framework.apollo.openapi.filter.ConsumerAuthenticationFilter;
import com.ctrip.framework.apollo.openapi.util.ConsumerAuditUtil; import com.ctrip.framework.apollo.openapi.util.ConsumerAuditUtil;
import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil; import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil;
import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
......
...@@ -7,8 +7,8 @@ import com.ctrip.framework.apollo.portal.component.config.PortalConfig; ...@@ -7,8 +7,8 @@ import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
......
...@@ -60,7 +60,7 @@ public class DefaultRolePermissionService implements RolePermissionService { ...@@ -60,7 +60,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
rolePermission.setDataChangeLastModifiedBy(createdRole.getDataChangeLastModifiedBy()); rolePermission.setDataChangeLastModifiedBy(createdRole.getDataChangeLastModifiedBy());
return rolePermission; return rolePermission;
}); });
rolePermissionRepository.save(rolePermissions); rolePermissionRepository.saveAll(rolePermissions);
} }
return createdRole; return createdRole;
...@@ -93,7 +93,7 @@ public class DefaultRolePermissionService implements RolePermissionService { ...@@ -93,7 +93,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
return userRole; return userRole;
}); });
userRoleRepository.save(toCreate); userRoleRepository.saveAll(toCreate);
return toAssignUserIds; return toAssignUserIds;
} }
...@@ -114,7 +114,7 @@ public class DefaultRolePermissionService implements RolePermissionService { ...@@ -114,7 +114,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
userRole.setDataChangeLastModifiedBy(operatorUserId); userRole.setDataChangeLastModifiedBy(operatorUserId);
} }
userRoleRepository.save(existedUserRoles); userRoleRepository.saveAll(existedUserRoles);
} }
/** /**
...@@ -218,7 +218,7 @@ public class DefaultRolePermissionService implements RolePermissionService { ...@@ -218,7 +218,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
targetId); targetId);
} }
Iterable<Permission> results = permissionRepository.save(permissions); Iterable<Permission> results = permissionRepository.saveAll(permissions);
return FluentIterable.from(results).toSet(); return FluentIterable.from(results).toSet();
} }
......
...@@ -4,7 +4,9 @@ spring: ...@@ -4,7 +4,9 @@ spring:
profiles: profiles:
active: ${apollo_profile} active: ${apollo_profile}
resources: resources:
cache-period: 3600 cache:
cachecontrol:
max-age: 3600
server: server:
port: 8080 port: 8080
...@@ -13,12 +15,7 @@ logging: ...@@ -13,12 +15,7 @@ logging:
path: /opt/logs/100003173 path: /opt/logs/100003173
file: ${logging.path}/apollo-portal.log file: ${logging.path}/apollo-portal.log
endpoints:
health:
sensitive: false
management: management:
security:
enabled: false
health: health:
status: status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
......
...@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s ...@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s
declare -i total_time=0 declare -i total_time=0
printf "Waiting for server startup" printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]]; until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do do
printf "." printf "."
counter+=1 counter+=1
......
...@@ -72,4 +72,4 @@ public class ConsumerAuthenticationFilterTest { ...@@ -72,4 +72,4 @@ public class ConsumerAuthenticationFilterTest {
verify(consumerAuditUtil, never()).audit(eq(request), anyLong()); verify(consumerAuditUtil, never()).audit(eq(request), anyLong());
verify(filterChain, never()).doFilter(request, response); verify(filterChain, never()).doFilter(request, response);
} }
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; ...@@ -16,6 +16,7 @@ import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
import com.ctrip.framework.apollo.portal.util.RoleUtils; import com.ctrip.framework.apollo.portal.util.RoleUtils;
import java.util.Optional;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
...@@ -97,10 +98,10 @@ public class ConsumerServiceTest extends AbstractUnitTest { ...@@ -97,10 +98,10 @@ public class ConsumerServiceTest extends AbstractUnitTest {
long someConsumerId = 1; long someConsumerId = 1;
Consumer someConsumer = mock(Consumer.class); Consumer someConsumer = mock(Consumer.class);
when(consumerRepository.findOne(someConsumerId)).thenReturn(someConsumer); when(consumerRepository.findById(someConsumerId)).thenReturn(Optional.of(someConsumer));
assertEquals(someConsumer, consumerService.getConsumerByConsumerId(someConsumerId)); assertEquals(someConsumer, consumerService.getConsumerByConsumerId(someConsumerId));
verify(consumerRepository, times(1)).findOne(someConsumerId); verify(consumerRepository, times(1)).findById(someConsumerId);
} }
@Test @Test
...@@ -131,7 +132,7 @@ public class ConsumerServiceTest extends AbstractUnitTest { ...@@ -131,7 +132,7 @@ public class ConsumerServiceTest extends AbstractUnitTest {
Date generationTime = new Date(); Date generationTime = new Date();
Consumer consumer = mock(Consumer.class); Consumer consumer = mock(Consumer.class);
when(consumerRepository.findOne(someConsumerId)).thenReturn(consumer); when(consumerRepository.findById(someConsumerId)).thenReturn(Optional.of(consumer));
when(consumer.getAppId()).thenReturn(someConsumerAppId); when(consumer.getAppId()).thenReturn(someConsumerAppId);
when(consumerService.generateToken(someConsumerAppId, generationTime, someTokenSalt)) when(consumerService.generateToken(someConsumerAppId, generationTime, someTokenSalt))
.thenReturn(someToken); .thenReturn(someToken);
......
...@@ -88,4 +88,4 @@ public class ConsumerAuditUtilTest { ...@@ -88,4 +88,4 @@ public class ConsumerAuditUtilTest {
assertEquals(someConsumerId, audit.getConsumerId()); assertEquals(someConsumerId, audit.getConsumerId());
} }
} }
\ No newline at end of file
...@@ -76,4 +76,4 @@ public class ConsumerAuthUtilTest { ...@@ -76,4 +76,4 @@ public class ConsumerAuthUtilTest {
consumerAuthUtil.retrieveConsumerId(request); consumerAuthUtil.retrieveConsumerId(request);
} }
} }
\ No newline at end of file
...@@ -3,9 +3,9 @@ package com.ctrip.framework.apollo.portal; ...@@ -3,9 +3,9 @@ package com.ctrip.framework.apollo.portal;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.WebIntegrationTest; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -13,11 +13,10 @@ import org.springframework.web.client.RestTemplate; ...@@ -13,11 +13,10 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = PortalApplication.class) @SpringBootTest(classes = PortalApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@WebIntegrationTest(randomPort = true)
public abstract class AbstractIntegrationTest { public abstract class AbstractIntegrationTest {
RestTemplate restTemplate = new TestRestTemplate(); protected RestTemplate restTemplate = (new TestRestTemplate()).getRestTemplate();
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
......
...@@ -35,7 +35,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -35,7 +35,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
Favorite favorite = instanceOfFavorite(testUser, testApp); Favorite favorite = instanceOfFavorite(testUser, testApp);
favoriteService.addFavorite(favorite); favoriteService.addFavorite(favorite);
List<Favorite> createdFavorites = favoriteService.search(testUser, testApp, new PageRequest(0, 10)); List<Favorite> createdFavorites = favoriteService.search(testUser, testApp, PageRequest.of(0, 10));
Assert.assertEquals(1, createdFavorites.size()); Assert.assertEquals(1, createdFavorites.size());
...@@ -57,7 +57,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -57,7 +57,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByUserId() { public void testSearchByUserId() {
List<Favorite> favorites = favoriteService.search(testUser, null, new PageRequest(0, 10)); List<Favorite> favorites = favoriteService.search(testUser, null, PageRequest.of(0, 10));
Assert.assertEquals(4, favorites.size()); Assert.assertEquals(4, favorites.size());
} }
...@@ -65,7 +65,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -65,7 +65,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByAppId() { public void testSearchByAppId() {
List<Favorite> favorites = favoriteService.search(null, "test0621-04", new PageRequest(0, 10)); List<Favorite> favorites = favoriteService.search(null, "test0621-04", PageRequest.of(0, 10));
Assert.assertEquals(3, favorites.size()); Assert.assertEquals(3, favorites.size());
} }
...@@ -73,7 +73,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -73,7 +73,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByAppIdAndUserId() { public void testSearchByAppIdAndUserId() {
List<Favorite> favorites = favoriteService.search(testUser, "test0621-04", new PageRequest(0, 10)); List<Favorite> favorites = favoriteService.search(testUser, "test0621-04", PageRequest.of(0, 10));
Assert.assertEquals(1, favorites.size()); Assert.assertEquals(1, favorites.size());
} }
...@@ -81,7 +81,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -81,7 +81,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchWithErrorParams() { public void testSearchWithErrorParams() {
favoriteService.search(null, null, new PageRequest(0, 10)); favoriteService.search(null, null, PageRequest.of(0, 10));
} }
@Test @Test
...@@ -90,7 +90,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -90,7 +90,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
public void testDeleteFavorite() { public void testDeleteFavorite() {
long legalFavoriteId = 21L; long legalFavoriteId = 21L;
favoriteService.deleteFavorite(legalFavoriteId); favoriteService.deleteFavorite(legalFavoriteId);
Assert.assertNull(favoriteRepository.findOne(legalFavoriteId)); Assert.assertNull(favoriteRepository.findById(legalFavoriteId).orElse(null));
} }
@Test(expected = BadRequestException.class) @Test(expected = BadRequestException.class)
...@@ -99,7 +99,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -99,7 +99,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
public void testDeleteFavoriteFail() { public void testDeleteFavoriteFail() {
long anotherPersonFavoriteId = 23L; long anotherPersonFavoriteId = 23L;
favoriteService.deleteFavorite(anotherPersonFavoriteId); favoriteService.deleteFavorite(anotherPersonFavoriteId);
Assert.assertNull(favoriteRepository.findOne(anotherPersonFavoriteId)); Assert.assertNull(favoriteRepository.findById(anotherPersonFavoriteId).orElse(null));
} }
@Test(expected = BadRequestException.class) @Test(expected = BadRequestException.class)
...@@ -117,7 +117,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest { ...@@ -117,7 +117,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
long toAdjustFavoriteId = 20; long toAdjustFavoriteId = 20;
favoriteService.adjustFavoriteToFirst(toAdjustFavoriteId); favoriteService.adjustFavoriteToFirst(toAdjustFavoriteId);
List<Favorite> favorites = favoriteService.search(testUser, null, new PageRequest(0, 10)); List<Favorite> favorites = favoriteService.search(testUser, null, PageRequest.of(0, 10));
Favorite firstFavorite = favorites.get(0); Favorite firstFavorite = favorites.get(0);
Favorite secondFavorite = favorites.get(1); Favorite secondFavorite = favorites.get(1);
......
...@@ -67,7 +67,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest { ...@@ -67,7 +67,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest {
Permission created = rolePermissionService.createPermission(somePermission); Permission created = rolePermissionService.createPermission(somePermission);
Permission createdFromDB = permissionRepository.findOne(created.getId()); Permission createdFromDB = permissionRepository.findById(created.getId()).orElse(null);
assertEquals(somePermissionType, createdFromDB.getPermissionType()); assertEquals(somePermissionType, createdFromDB.getPermissionType());
assertEquals(someTargetId, createdFromDB.getTargetId()); assertEquals(someTargetId, createdFromDB.getTargetId());
...@@ -103,7 +103,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest { ...@@ -103,7 +103,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest {
FluentIterable.from(created).transform(BaseEntity::getId) FluentIterable.from(created).transform(BaseEntity::getId)
.toSet(); .toSet();
Iterable<Permission> permissionsFromDB = permissionRepository.findAll(permissionIds); Iterable<Permission> permissionsFromDB = permissionRepository.findAllById(permissionIds);
Set<String> targetIds = Sets.newHashSet(); Set<String> targetIds = Sets.newHashSet();
Set<String> permissionTypes = Sets.newHashSet(); Set<String> permissionTypes = Sets.newHashSet();
...@@ -145,7 +145,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest { ...@@ -145,7 +145,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest {
Role created = rolePermissionService.createRoleWithPermissions(role, permissionIds); Role created = rolePermissionService.createRoleWithPermissions(role, permissionIds);
Role createdFromDB = roleRepository.findOne(created.getId()); Role createdFromDB = roleRepository.findById(created.getId()).orElse(null);
List<RolePermission> rolePermissions = List<RolePermission> rolePermissions =
rolePermissionRepository.findByRoleIdIn(Sets.newHashSet(createdFromDB.getId())); rolePermissionRepository.findByRoleIdIn(Sets.newHashSet(createdFromDB.getId()));
......
spring.datasource.url = jdbc:h2:mem:~/apolloportaldb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1 spring.datasource.url = jdbc:h2:mem:~/apolloportaldb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true spring.h2.console.settings.web-allow-others=true
...@@ -14,14 +14,7 @@ apollo: ...@@ -14,14 +14,7 @@ apollo:
portal: portal:
envs: local envs: local
endpoints:
health:
sensitive: false
management: management:
security:
enabled: false
health: health:
status: status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
...@@ -75,8 +75,9 @@ ...@@ -75,8 +75,9 @@
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>1.3.8.RELEASE</spring-boot.version> <platform-bom.version>Cairo-SR4</platform-bom.version>
<spring-cloud.version>1.2.3.RELEASE</spring-cloud.version> <spring-boot.version>2.0.5.RELEASE</spring-boot.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<!-- Plugins Version --> <!-- Plugins Version -->
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version> <maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
...@@ -287,18 +288,24 @@ ...@@ -287,18 +288,24 @@
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>1.4.191</version> <version>1.4.191</version>
</dependency> </dependency>
<!-- stick with mockito 1.x -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
<!-- declare Spring BOMs in order --> <!-- declare Spring BOMs in order -->
<dependency> <dependency>
<groupId>io.spring.platform</groupId> <groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId> <artifactId>platform-bom</artifactId>
<version>2.0.8.RELEASE</version> <version>${platform-bom.version}</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId> <artifactId>spring-cloud-dependencies</artifactId>
<version>1.2.3.RELEASE</version> <version>${spring-cloud.version}</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
...@@ -323,6 +330,12 @@ ...@@ -323,6 +330,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
...@@ -421,7 +434,7 @@ ...@@ -421,7 +434,7 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.5.RELEASE</version> <version>1.3.8.RELEASE</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
...@@ -655,7 +668,7 @@ ...@@ -655,7 +668,7 @@
<!-- eureka --> <!-- eureka -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${spring-cloud.version}</version> <version>${spring-cloud.version}</version>
<exclusions> <exclusions>
<!-- already in java --> <!-- already in java -->
...@@ -761,7 +774,7 @@ ...@@ -761,7 +774,7 @@
<!-- eureka --> <!-- eureka -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${spring-cloud.version}</version> <version>${spring-cloud.version}</version>
<exclusions> <exclusions>
<!-- already in java --> <!-- already in java -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment