Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
ad030e27
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ad030e27
编写于
3月 17, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13 from yiming187/service_discovery
Add ServiceDiscovery based on ZK
上级
047000dc
c5d37036
变更
36
隐藏空白更改
内联
并排
Showing
36 changed file
with
411 addition
and
63 deletion
+411
-63
apollo-configserver/pom.xml
apollo-configserver/pom.xml
+4
-8
apollo-configserver/src/main/java/com/ctrip/apollo/configserver/ConfigServerApplication.java
...om/ctrip/apollo/configserver/ConfigServerApplication.java
+3
-1
apollo-configserver/src/main/java/com/ctrip/apollo/configserver/service/DiscoveryService.java
...m/ctrip/apollo/configserver/service/DiscoveryService.java
+29
-0
apollo-configserver/src/main/resources/application.yml
apollo-configserver/src/main/resources/application.yml
+2
-0
apollo-configserver/src/main/resources/bootstrap.yml
apollo-configserver/src/main/resources/bootstrap.yml
+10
-3
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/AbstractConfigServerTest.java
...m/ctrip/apollo/configserver/AbstractConfigServerTest.java
+11
-0
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/AllTests.java
...src/test/java/com/ctrip/apollo/configserver/AllTests.java
+13
-0
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/service/DiscoveryServiceTest.java
...rip/apollo/configserver/service/DiscoveryServiceTest.java
+21
-0
apollo-configserver/src/test/resources/application.properties
...lo-configserver/src/test/resources/application.properties
+0
-3
apollo-configserver/src/test/resources/application.yml
apollo-configserver/src/test/resources/application.yml
+14
-0
apollo-configserver/src/test/resources/bootstrap.yml
apollo-configserver/src/test/resources/bootstrap.yml
+10
-0
apollo-core/src/main/java/com/ctrip/apollo/core/ServiceIdConsts.java
.../src/main/java/com/ctrip/apollo/core/ServiceIdConsts.java
+10
-0
apollo-metaserver/pom.xml
apollo-metaserver/pom.xml
+2
-7
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/MetaServerApplication.java
...va/com/ctrip/apollo/metaserver/MetaServerApplication.java
+17
-2
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/controller/ServiceController.java
...ctrip/apollo/metaserver/controller/ServiceController.java
+29
-0
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/service/DiscoveryService.java
...com/ctrip/apollo/metaserver/service/DiscoveryService.java
+29
-0
apollo-metaserver/src/main/resources/application.yml
apollo-metaserver/src/main/resources/application.yml
+11
-0
apollo-metaserver/src/main/resources/bootstrap.yml
apollo-metaserver/src/main/resources/bootstrap.yml
+13
-0
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/AbstractMetaServerTest.java
...a/com/ctrip/apollo/metaserver/AbstractMetaServerTest.java
+11
-0
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/AllTests.java
...r/src/test/java/com/ctrip/apollo/metaserver/AllTests.java
+13
-0
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/service/DiscoveryServiceTest.java
...ctrip/apollo/metaserver/service/DiscoveryServiceTest.java
+21
-0
apollo-metaserver/src/test/resources/application.yml
apollo-metaserver/src/test/resources/application.yml
+5
-0
apollo-metaserver/src/test/resources/bootstrap.yml
apollo-metaserver/src/test/resources/bootstrap.yml
+13
-0
apollo-portal/pom.xml
apollo-portal/pom.xml
+2
-2
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/PrivilegeRepository.java
...m/ctrip/apollo/portal/repository/PrivilegeRepository.java
+3
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/PrivilegeService.java
...ava/com/ctrip/apollo/portal/service/PrivilegeService.java
+19
-10
apollo-portal/src/main/resources/application.properties
apollo-portal/src/main/resources/application.properties
+0
-3
apollo-portal/src/main/resources/application.yml
apollo-portal/src/main/resources/application.yml
+11
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
...test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
+1
-1
apollo-portal/src/test/java/com/ctrip/apollo/portal/PortalApplicationTestConfiguration.java
...rip/apollo/portal/PortalApplicationTestConfiguration.java
+0
-8
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
...com/ctrip/apollo/portal/controller/AppControllerTest.java
+7
-3
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
...com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
+11
-6
apollo-portal/src/test/resources/application.properties
apollo-portal/src/test/resources/application.properties
+0
-5
apollo-portal/src/test/resources/application.yml
apollo-portal/src/test/resources/application.yml
+11
-0
framework-parent/pom.xml
framework-parent/pom.xml
+48
-0
pom.xml
pom.xml
+7
-0
未找到文件。
apollo-configserver/pom.xml
浏览文件 @
ad030e27
...
...
@@ -20,16 +20,12 @@
<artifactId>
spring-cloud-config-server
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-redis
</artifactId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka
</artifactId>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
...
...
apollo-configserver/src/main/java/com/ctrip/apollo/server/ConfigServerApplication.java
→
apollo-configserver/src/main/java/com/ctrip/apollo/
config
server/ConfigServerApplication.java
浏览文件 @
ad030e27
package
com.ctrip.apollo.server
;
package
com.ctrip.apollo.
config
server
;
import
com.jcraft.jsch.JSch
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.config.server.EnableConfigServer
;
@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public
class
ConfigServerApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
apollo-configserver/src/main/java/com/ctrip/apollo/configserver/service/DiscoveryService.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.configserver.service
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.core.ServiceIdConsts
;
@Service
public
class
DiscoveryService
{
@Autowired
private
DiscoveryClient
discoveryClient
;
public
List
<
ServiceInstance
>
getConfigServerServiceInstances
()
{
List
<
ServiceInstance
>
instances
=
discoveryClient
.
getInstances
(
ServiceIdConsts
.
APOLLO_CONFIGSERVER
);
return
instances
;
}
public
List
<
ServiceInstance
>
getMetaServerServiceInstances
()
{
List
<
ServiceInstance
>
instances
=
discoveryClient
.
getInstances
(
ServiceIdConsts
.
APOLLO_METASERVER
);
return
instances
;
}
}
apollo-configserver/src/main/resources/application.yml
浏览文件 @
ad030e27
spring
:
application
:
name
:
apollo-configserver
cloud
:
config
:
server
:
...
...
apollo-configserver/src/main/resources/bootstrap.yml
浏览文件 @
ad030e27
spring
:
application
:
name
:
apollo-server
\ No newline at end of file
eureka
:
instance
:
hostname
:
localhost
preferIpAddress
:
true
client
:
fetchRegistry
:
false
serviceUrl
:
defaultZone
:
http://${eureka.instance.hostname}:${server.port}/eureka/
healthcheck
:
enabled
:
true
\ No newline at end of file
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/AbstractConfigServerTest.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.configserver
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
ConfigServerApplication
.
class
)
public
abstract
class
AbstractConfigServerTest
{
}
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/AllTests.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.configserver
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
})
public
class
AllTests
{
}
apollo-configserver/src/test/java/com/ctrip/apollo/configserver/service/DiscoveryServiceTest.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.configserver.service
;
import
java.util.List
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.client.ServiceInstance
;
import
com.ctrip.apollo.configserver.AbstractConfigServerTest
;
public
class
DiscoveryServiceTest
extends
AbstractConfigServerTest
{
@Autowired
private
DiscoveryService
discoveryService
;
@Test
public
void
testGetLocalMetaServerServices
()
{
List
<
ServiceInstance
>
instances
=
discoveryService
.
getMetaServerServiceInstances
();
System
.
out
.
println
(
instances
);
}
}
apollo-configserver/src/test/resources/application.properties
已删除
100644 → 0
浏览文件 @
047000dc
spring.datasource.url
=
jdbc:h2:file:~/fxapolloconfigdb;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username
=
sa
spring.datasource.password
=
sa
apollo-configserver/src/test/resources/application.yml
0 → 100644
浏览文件 @
ad030e27
server
:
port
:
8888
logging
:
level
:
org.springframework.cloud
:
'
DEBUG'
spring
:
application
:
name
:
apollo-configserver
datasource
:
url
:
jdbc:h2:file:~/fxapolloconfigdb;DB_CLOSE_ON_EXIT=FALSE
username
:
sa
password
:
apollo-configserver/src/test/resources/bootstrap.yml
0 → 100644
浏览文件 @
ad030e27
eureka
:
instance
:
hostname
:
localhost
preferIpAddress
:
true
client
:
fetchRegistry
:
false
serviceUrl
:
defaultZone
:
http://${eureka.instance.hostname}:${server.port}/eureka/
healthcheck
:
enabled
:
true
\ No newline at end of file
apollo-core/src/main/java/com/ctrip/apollo/core/ServiceIdConsts.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.core
;
public
class
ServiceIdConsts
{
public
static
final
String
APOLLO_METASERVER
=
"apollo-metaserver"
;
public
static
final
String
APOLLO_CONFIGSERVER
=
"apollo-configserver"
;
public
static
final
String
APOLLO_PORTAL
=
"apollo-portal"
;
}
apollo-metaserver/pom.xml
浏览文件 @
ad030e27
...
...
@@ -16,13 +16,8 @@
<artifactId>
apollo-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka-server
</artifactId>
</dependency>
</dependencies>
<build>
...
...
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/MetaServerApplication.java
浏览文件 @
ad030e27
package
com.ctrip.apollo.metaserver
;
import
org.springframework.boot.SpringApplication
;
import
java.util.List
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.netflix.eureka.server.EnableEurekaServer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
com.ctrip.apollo.metaserver.service.DiscoveryService
;
import
com.netflix.appinfo.InstanceInfo
;
@SpringBootApplication
@EnableEurekaServer
@EnableEurekaClient
public
class
MetaServerApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
MetaServerApplication
.
class
,
args
);
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
(
MetaServerApplication
.
class
).
web
(
true
).
run
(
args
);
DiscoveryService
discoveryService
=
context
.
getBean
(
DiscoveryService
.
class
);
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServerServiceInstance
();
System
.
out
.
println
(
instances
);
}
}
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/controller/ServiceController.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.metaserver.controller
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.metaserver.service.DiscoveryService
;
import
com.netflix.appinfo.InstanceInfo
;
@RestController
@RequestMapping
(
"/services"
)
public
class
ServiceController
{
@Autowired
private
DiscoveryService
discoveryService
;
@RequestMapping
(
"/meta"
)
public
List
<
InstanceInfo
>
metaServer
()
{
return
discoveryService
.
getMetaServerServiceInstance
();
}
@RequestMapping
(
"/config"
)
public
List
<
InstanceInfo
>
configServer
()
{
return
discoveryService
.
getConfigServerServiceInstance
();
}
}
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/service/DiscoveryService.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.metaserver.service
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.core.ServiceIdConsts
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.shared.Application
;
@Service
public
class
DiscoveryService
{
@Autowired
private
EurekaClient
eurekaClient
;
public
List
<
InstanceInfo
>
getConfigServerServiceInstance
()
{
Application
application
=
eurekaClient
.
getApplication
(
ServiceIdConsts
.
APOLLO_CONFIGSERVER
);
return
application
.
getInstances
();
}
public
List
<
InstanceInfo
>
getMetaServerServiceInstance
()
{
Application
application
=
eurekaClient
.
getApplication
(
ServiceIdConsts
.
APOLLO_METASERVER
);
return
application
.
getInstances
();
}
}
apollo-metaserver/src/main/resources/application.yml
0 → 100644
浏览文件 @
ad030e27
spring
:
application
:
name
:
apollo-metaserver
profiles
:
active
:
native
logging
:
level
:
\ No newline at end of file
apollo-metaserver/src/main/resources/bootstrap.yml
0 → 100644
浏览文件 @
ad030e27
server
:
port
:
8761
eureka
:
instance
:
hostname
:
localhost
preferIpAddress
:
true
client
:
fetchRegistry
:
false
serviceUrl
:
defaultZone
:
http://${eureka.instance.hostname}:${server.port}/eureka/
healthcheck
:
enabled
:
true
\ No newline at end of file
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/AbstractMetaServerTest.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.metaserver
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
MetaServerApplication
.
class
)
public
abstract
class
AbstractMetaServerTest
{
}
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/AllTests.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.metaserver
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
})
public
class
AllTests
{
}
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/service/DiscoveryServiceTest.java
0 → 100644
浏览文件 @
ad030e27
package
com.ctrip.apollo.metaserver.service
;
import
java.util.List
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.ctrip.apollo.metaserver.AbstractMetaServerTest
;
import
com.netflix.appinfo.InstanceInfo
;
public
class
DiscoveryServiceTest
extends
AbstractMetaServerTest
{
@Autowired
private
DiscoveryService
discoveryService
;
@Test
public
void
testGetLocalMetaServerServices
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServerServiceInstance
();
System
.
out
.
println
(
instances
);
}
}
apollo-metaserver/src/test/resources/application.yml
0 → 100644
浏览文件 @
ad030e27
spring
:
application
:
name
:
apollo-metaserver
profiles
:
active
:
native
apollo-metaserver/src/test/resources/bootstrap.yml
0 → 100644
浏览文件 @
ad030e27
server
:
port
:
8761
eureka
:
instance
:
hostname
:
localhost
preferIpAddress
:
true
client
:
fetchRegistry
:
false
serviceUrl
:
defaultZone
:
http://${eureka.instance.hostname}:${server.port}/eureka/
healthcheck
:
enabled
:
true
\ No newline at end of file
apollo-portal/pom.xml
浏览文件 @
ad030e27
...
...
@@ -16,8 +16,8 @@
<artifactId>
apollo-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.
boot
</groupId>
<artifactId>
spring-
boot-starter-web
</artifactId>
<groupId>
org.springframework.
cloud
</groupId>
<artifactId>
spring-
cloud-starter-eureka
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/PrivilegeRepository.java
浏览文件 @
ad030e27
...
...
@@ -10,5 +10,7 @@ public interface PrivilegeRepository extends PagingAndSortingRepository<Privileg
List
<
Privilege
>
findByAppId
(
String
appId
);
Privilege
findByAppIdAndPrivilType
(
String
appId
,
String
privilType
);
List
<
Privilege
>
findByAppIdAndPrivilType
(
String
appId
,
String
privilType
);
Privilege
findByAppIdAndNameAndPrivilType
(
String
appId
,
String
name
,
String
privilType
);
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/PrivilegeService.java
浏览文件 @
ad030e27
...
...
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.portal.entity.Privilege
;
import
com.ctrip.apollo.portal.exception.NotFoundException
;
import
com.ctrip.apollo.portal.repository.PrivilegeRepository
;
@Service
...
...
@@ -18,24 +19,32 @@ public class PrivilegeService {
@Autowired
private
PrivilegeRepository
privilRepo
;
public
Privilege
addPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
if
(
privil
==
null
)
{
privil
=
new
Privilege
();
privil
.
setAppId
(
appId
);
privil
.
setPrivilType
(
privilType
.
name
());
privil
.
setName
(
name
);
privilRepo
.
save
(
privil
);
}
return
privil
;
}
public
boolean
hasPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndPrivilType
(
appId
,
privilType
.
name
());
if
(
privil
!=
null
&&
privil
.
getName
().
equals
(
name
))
return
true
;
return
false
;
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
return
(
privil
!=
null
)
?
true
:
false
;
}
public
List
<
Privilege
>
listPrivileges
(
String
appId
)
{
return
privilRepo
.
findByAppId
(
appId
);
}
public
Privilege
set
Privilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAnd
PrivilType
(
appId
,
privilType
.
name
());
public
void
remove
Privilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAnd
NameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
if
(
privil
==
null
)
{
privil
=
new
Privilege
();
privil
.
setAppId
(
appId
);
privil
.
setPrivilType
(
privilType
.
name
());
throw
new
NotFoundException
();
}
privil
.
setName
(
name
);
return
privilRepo
.
save
(
privil
);
privilRepo
.
delete
(
privil
);
}
}
apollo-portal/src/main/resources/application.properties
已删除
100644 → 0
浏览文件 @
047000dc
spring.datasource.url
=
jdbc:h2:file:~/fxapolloportaldb
spring.datasource.username
=
sa
spring.datasource.password
=
sa
apollo-portal/src/main/resources/application.yml
0 → 100644
浏览文件 @
ad030e27
server
:
port
:
80
spring
:
application
:
name
:
apollo-portal
datasource
:
url
:
jdbc:h2:file:~/fxapolloportaldb
username
:
sa
password
:
sa
apollo-portal/src/test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
浏览文件 @
ad030e27
...
...
@@ -5,7 +5,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
PortalApplication
TestConfiguration
.
class
)
@SpringApplicationConfiguration
(
classes
=
PortalApplication
.
class
)
public
abstract
class
AbstractPortalTest
{
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/PortalApplicationTestConfiguration.java
已删除
100644 → 0
浏览文件 @
047000dc
package
com.ctrip.apollo.portal
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
PortalApplicationTestConfiguration
{
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
浏览文件 @
ad030e27
...
...
@@ -6,6 +6,7 @@ import java.net.URISyntaxException;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -25,6 +26,9 @@ public class AppControllerTest extends AbstractPortalTest {
@Autowired
AppRepository
appRepository
;
@Value
(
"${server.port}"
)
String
serverPort
;
@Test
public
void
testCreate
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
...
...
@@ -32,7 +36,7 @@ public class AppControllerTest extends AbstractPortalTest {
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
URI
uri
=
new
URI
(
"http://localhost:
8080
/apps"
);
URI
uri
=
new
URI
(
"http://localhost:
"
+
serverPort
+
"
/apps"
);
App
createdApp
=
restTemplate
.
postForObject
(
uri
,
newApp
,
App
.
class
);
Assert
.
assertEquals
(
newApp
.
getAppId
(),
createdApp
.
getAppId
());
...
...
@@ -52,7 +56,7 @@ public class AppControllerTest extends AbstractPortalTest {
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
URI
uri
=
new
URI
(
"http://localhost:
8080
/apps"
);
URI
uri
=
new
URI
(
"http://localhost:
"
+
serverPort
+
"
/apps"
);
App
[]
apps
=
restTemplate
.
getForObject
(
uri
,
App
[].
class
);
Assert
.
assertEquals
(
1
,
apps
.
length
);
...
...
@@ -67,7 +71,7 @@ public class AppControllerTest extends AbstractPortalTest {
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
URI
uri
=
new
URI
(
"http://localhost:
8080
/apps?page=2"
);
URI
uri
=
new
URI
(
"http://localhost:
"
+
serverPort
+
"
/apps?page=2"
);
ResponseEntity
<
App
[]>
entity
=
restTemplate
.
getForEntity
(
uri
,
App
[].
class
);
Assert
.
assertEquals
(
HttpStatus
.
NOT_FOUND
,
entity
.
getStatusCode
());
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
浏览文件 @
ad030e27
...
...
@@ -19,19 +19,24 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
PrivilegeService
privilService
;
@Test
public
void
testAddPrivilege
()
{
public
void
testAdd
AndRemove
Privilege
()
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
privilService
.
set
Privilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
privilService
.
add
Privilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
List
<
Privilege
>
privileges
=
privilService
.
listPrivileges
(
newApp
.
getAppId
());
Assert
.
assertEquals
(
1
,
privileges
.
size
());
Assert
.
assertEquals
(
PrivilegeService
.
PrivilType
.
EDIT
.
name
(),
privileges
.
get
(
0
).
getPrivilType
());
Assert
.
assertEquals
(
newApp
.
getOwner
(),
privileges
.
get
(
0
).
getName
());
privilService
.
removePrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
privileges
=
privilService
.
listPrivileges
(
newApp
.
getAppId
());
Assert
.
assertEquals
(
0
,
privileges
.
size
());
}
@Test
...
...
@@ -42,7 +47,7 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
privilService
.
set
Privilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
privilService
.
add
Privilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
));
...
...
@@ -51,13 +56,13 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
RELEASE
));
privilService
.
set
Privilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
);
privilService
.
add
Privilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
));
Assert
.
assert
Fals
e
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
Assert
.
assert
Tru
e
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
));
privilService
.
set
Privilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
);
privilService
.
add
Privilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
));
}
...
...
apollo-portal/src/test/resources/application.properties
已删除
100644 → 0
浏览文件 @
047000dc
spring.datasource.url
=
jdbc:h2:mem:fxapolloportaldb
spring.datasource.username
=
sa
spring.datasource.password
=
spring.jpa.show-sql: true
\ No newline at end of file
apollo-portal/src/test/resources/application.yml
0 → 100644
浏览文件 @
ad030e27
server
:
port
:
80
spring
:
datasource
:
url
:
jdbc:h2:file:~/fxapolloportaldb
username
:
sa
password
:
sa
jpa
:
show-sql
:
true
framework-parent/pom.xml
浏览文件 @
ad030e27
...
...
@@ -15,7 +15,55 @@
<properties>
<java.version>
1.7
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<junit.version>
4.12
</junit.version>
<guava.version>
19.0
</guava.version>
<slf4j-api.version>
1.7.19
</slf4j-api.version>
<httpclient.version>
4.5.2
</httpclient.version>
<httpcore.version>
4.4.4
</httpcore.version>
<fastjson.version>
1.2.8
</fastjson.version>
<netty-all.version>
4.0.34.Final
</netty-all.version>
<commons-codec.version>
1.10
</commons-codec.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
${junit.version}
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
${guava.version}
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<version>
${slf4j-api.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
${httpclient.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
<version>
${httpcore.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
${fastjson.version}
</version>
</dependency>
<dependency>
<groupId>
io.netty
</groupId>
<artifactId>
netty-all
</artifactId>
<version>
${netty-all.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
...
...
pom.xml
浏览文件 @
ad030e27
...
...
@@ -116,6 +116,13 @@
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-netflix
</artifactId>
<version>
1.1.0.M5
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录