Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
44375b3b
Commit
44375b3b
authored
Apr 13, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #83 from yiming187/item_set
Add ItemChangeSet Integration Test
parents
c99fd43f
58c1a20c
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
304 additions
and
77 deletions
+304
-77
ItemSetController.java
...rip/apollo/adminservice/controller/ItemSetController.java
+2
-4
AbstractControllerTest.java
...pollo/adminservice/controller/AbstractControllerTest.java
+22
-0
AppControllerTest.java
...rip/apollo/adminservice/controller/AppControllerTest.java
+1
-17
ItemSetControllerTest.java
...apollo/adminservice/controller/ItemSetControllerTest.java
+210
-0
application.properties
...lo-adminservice/src/test/resources/application.properties
+3
-1
test-itemset-cleanup.sql
...ce/src/test/resources/controller/test-itemset-cleanup.sql
+6
-0
test-itemset.sql
...minservice/src/test/resources/controller/test-itemset.sql
+7
-0
data.sql
apollo-adminservice/src/test/resources/data.sql
+0
-0
BaseEntity.java
...src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
+2
-2
ItemSetService.java
...ain/java/com/ctrip/apollo/biz/service/ItemSetService.java
+21
-29
BeanUtils.java
...z/src/main/java/com/ctrip/apollo/biz/utils/BeanUtils.java
+12
-2
WebMvcConfig.java
...m/ctrip/apollo/configservice/controller/WebMvcConfig.java
+0
-1
application.properties
...o-configservice/src/test/resources/application.properties
+3
-4
data.sql
apollo-configservice/src/test/resources/data.sql
+0
-0
ItemChangeSets.java
...c/main/java/com/ctrip/apollo/core/dto/ItemChangeSets.java
+8
-9
PropertyResolver.java
...p/apollo/portal/service/txtresolver/PropertyResolver.java
+7
-8
No files found.
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemSetController.java
View file @
44375b3b
...
@@ -3,7 +3,6 @@ package com.ctrip.apollo.adminservice.controller;
...
@@ -3,7 +3,6 @@ package com.ctrip.apollo.adminservice.controller;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
@@ -19,9 +18,8 @@ public class ItemSetController {
...
@@ -19,9 +18,8 @@ public class ItemSetController {
private
ItemSetService
itemSetService
;
private
ItemSetService
itemSetService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
create
(
@PathVariable
String
appId
,
@PathVariable
String
clusterName
,
public
ResponseEntity
<
Void
>
create
(
@RequestBody
ItemChangeSets
changeSet
)
{
@PathVariable
String
namespaceName
,
@RequestBody
ItemChangeSets
changeSet
)
{
itemSetService
.
updateSet
(
changeSet
);
itemSetService
.
updateSet
(
appId
,
clusterName
,
namespaceName
,
changeSet
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
}
}
}
}
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AbstractControllerTest.java
0 → 100644
View file @
44375b3b
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.AdminServiceTestConfiguration
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
AdminServiceTestConfiguration
.
class
)
@WebIntegrationTest
(
randomPort
=
true
)
public
abstract
class
AbstractControllerTest
{
RestTemplate
restTemplate
=
new
TestRestTemplate
();
@Value
(
"${local.server.port}"
)
int
port
;
}
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppControllerTest.java
View file @
44375b3b
...
@@ -2,36 +2,20 @@ package com.ctrip.apollo.adminservice.controller;
...
@@ -2,36 +2,20 @@ package com.ctrip.apollo.adminservice.controller;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.Test
;
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.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
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.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.AdminServiceTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.repository.AppRepository
;
import
com.ctrip.apollo.biz.repository.AppRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.AppDTO
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
AppControllerTest
extends
AbstractControllerTest
{
@SpringApplicationConfiguration
(
classes
=
AdminServiceTestConfiguration
.
class
)
@WebIntegrationTest
(
randomPort
=
true
)
public
class
AppControllerTest
{
RestTemplate
restTemplate
=
new
TestRestTemplate
();
@Autowired
@Autowired
AppRepository
appRepository
;
AppRepository
appRepository
;
@Value
(
"${local.server.port}"
)
private
int
port
;
private
String
getBaseAppUrl
(){
private
String
getBaseAppUrl
(){
return
"http://localhost:"
+
port
+
"/apps/"
;
return
"http://localhost:"
+
port
+
"/apps/"
;
}
}
...
...
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/ItemSetControllerTest.java
0 → 100644
View file @
44375b3b
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
java.util.List
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.context.jdbc.Sql
;
import
org.springframework.test.context.jdbc.Sql.ExecutionPhase
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
public
class
ItemSetControllerTest
extends
AbstractControllerTest
{
@Autowired
ItemRepository
itemRepository
;
@Test
@Sql
(
scripts
=
"/controller/test-itemset.sql"
,
executionPhase
=
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/controller/test-itemset-cleanup.sql"
,
executionPhase
=
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testItemSetCreated
()
{
String
appId
=
"someAppId"
;
AppDTO
app
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
appId
,
AppDTO
.
class
);
ClusterDTO
cluster
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/default"
,
ClusterDTO
.
class
);
NamespaceDTO
namespace
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/application"
,
NamespaceDTO
.
class
);
Assert
.
assertEquals
(
"someAppId"
,
app
.
getAppId
());
Assert
.
assertEquals
(
"default"
,
cluster
.
getName
());
Assert
.
assertEquals
(
"application"
,
namespace
.
getNamespaceName
());
ItemChangeSets
itemSet
=
new
ItemChangeSets
();
itemSet
.
setModifyBy
(
"created"
);
int
createdSize
=
3
;
for
(
int
i
=
0
;
i
<
createdSize
;
i
++)
{
ItemDTO
item
=
new
ItemDTO
();
item
.
setNamespaceId
(
namespace
.
getId
());
item
.
setKey
(
"key_"
+
i
);
item
.
setValue
(
"created_value_"
+
i
);
itemSet
.
addCreateItem
(
item
);
}
ResponseEntity
<
Void
>
response
=
restTemplate
.
postForEntity
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/itemset"
,
itemSet
,
Void
.
class
);
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
List
<
Item
>
items
=
itemRepository
.
findByNamespaceIdOrderByLineNumAsc
(
namespace
.
getId
());
Assert
.
assertEquals
(
createdSize
,
items
.
size
());
Item
item0
=
items
.
get
(
0
);
Assert
.
assertEquals
(
"key_0"
,
item0
.
getKey
());
Assert
.
assertEquals
(
"created_value_0"
,
item0
.
getValue
());
Assert
.
assertEquals
(
"created"
,
item0
.
getDataChangeCreatedBy
());
Assert
.
assertNotNull
(
item0
.
getDataChangeCreatedTime
());
}
@Test
@Sql
(
scripts
=
"/controller/test-itemset.sql"
,
executionPhase
=
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/controller/test-itemset-cleanup.sql"
,
executionPhase
=
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testItemSetUpdated
()
{
String
appId
=
"someAppId"
;
AppDTO
app
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
appId
,
AppDTO
.
class
);
ClusterDTO
cluster
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/default"
,
ClusterDTO
.
class
);
NamespaceDTO
namespace
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/application"
,
NamespaceDTO
.
class
);
Assert
.
assertEquals
(
"someAppId"
,
app
.
getAppId
());
Assert
.
assertEquals
(
"default"
,
cluster
.
getName
());
Assert
.
assertEquals
(
"application"
,
namespace
.
getNamespaceName
());
ItemChangeSets
createChangeSet
=
new
ItemChangeSets
();
createChangeSet
.
setModifyBy
(
"created"
);
int
createdSize
=
3
;
for
(
int
i
=
0
;
i
<
createdSize
;
i
++)
{
ItemDTO
item
=
new
ItemDTO
();
item
.
setNamespaceId
(
namespace
.
getId
());
item
.
setKey
(
"key_"
+
i
);
item
.
setValue
(
"created_value_"
+
i
);
createChangeSet
.
addCreateItem
(
item
);
}
ResponseEntity
<
Void
>
response
=
restTemplate
.
postForEntity
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/itemset"
,
createChangeSet
,
Void
.
class
);
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
ItemDTO
[]
items
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/items"
,
ItemDTO
[].
class
);
ItemChangeSets
udpateChangeSet
=
new
ItemChangeSets
();
udpateChangeSet
.
setModifyBy
(
"updated"
);
int
updatedSize
=
2
;
for
(
int
i
=
0
;
i
<
updatedSize
;
i
++)
{
items
[
i
].
setValue
(
"updated_value_"
+
i
);
udpateChangeSet
.
addUpdateItem
(
items
[
i
]);
}
response
=
restTemplate
.
postForEntity
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/itemset"
,
udpateChangeSet
,
Void
.
class
);
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
List
<
Item
>
savedItems
=
itemRepository
.
findByNamespaceIdOrderByLineNumAsc
(
namespace
.
getId
());
Assert
.
assertEquals
(
createdSize
,
savedItems
.
size
());
Item
item0
=
savedItems
.
get
(
0
);
Assert
.
assertEquals
(
"key_0"
,
item0
.
getKey
());
Assert
.
assertEquals
(
"updated_value_0"
,
item0
.
getValue
());
Assert
.
assertEquals
(
"created"
,
item0
.
getDataChangeCreatedBy
());
Assert
.
assertEquals
(
"updated"
,
item0
.
getDataChangeLastModifiedBy
());
Assert
.
assertNotNull
(
item0
.
getDataChangeCreatedTime
());
Assert
.
assertNotNull
(
item0
.
getDataChangeLastModifiedTime
());
}
@Test
@Sql
(
scripts
=
"/controller/test-itemset.sql"
,
executionPhase
=
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/controller/test-itemset-cleanup.sql"
,
executionPhase
=
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testItemSetDeleted
()
{
String
appId
=
"someAppId"
;
AppDTO
app
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
appId
,
AppDTO
.
class
);
ClusterDTO
cluster
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/default"
,
ClusterDTO
.
class
);
NamespaceDTO
namespace
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/application"
,
NamespaceDTO
.
class
);
Assert
.
assertEquals
(
"someAppId"
,
app
.
getAppId
());
Assert
.
assertEquals
(
"default"
,
cluster
.
getName
());
Assert
.
assertEquals
(
"application"
,
namespace
.
getNamespaceName
());
ItemChangeSets
createChangeSet
=
new
ItemChangeSets
();
createChangeSet
.
setModifyBy
(
"created"
);
int
createdSize
=
3
;
for
(
int
i
=
0
;
i
<
createdSize
;
i
++)
{
ItemDTO
item
=
new
ItemDTO
();
item
.
setNamespaceId
(
namespace
.
getId
());
item
.
setKey
(
"key_"
+
i
);
item
.
setValue
(
"created_value_"
+
i
);
createChangeSet
.
addCreateItem
(
item
);
}
ResponseEntity
<
Void
>
response
=
restTemplate
.
postForEntity
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/itemset"
,
createChangeSet
,
Void
.
class
);
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
ItemDTO
[]
items
=
restTemplate
.
getForObject
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/items"
,
ItemDTO
[].
class
);
ItemChangeSets
deleteChangeSet
=
new
ItemChangeSets
();
deleteChangeSet
.
setModifyBy
(
"deleted"
);
int
deletedSize
=
1
;
for
(
int
i
=
0
;
i
<
deletedSize
;
i
++)
{
items
[
i
].
setValue
(
"deleted_value_"
+
i
);
deleteChangeSet
.
addDeleteItem
(
items
[
i
]);
}
response
=
restTemplate
.
postForEntity
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/itemset"
,
deleteChangeSet
,
Void
.
class
);
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
List
<
Item
>
savedItems
=
itemRepository
.
findByNamespaceIdOrderByLineNumAsc
(
namespace
.
getId
());
Assert
.
assertEquals
(
createdSize
-
deletedSize
,
savedItems
.
size
());
Item
item0
=
savedItems
.
get
(
0
);
Assert
.
assertEquals
(
"key_1"
,
item0
.
getKey
());
Assert
.
assertEquals
(
"created_value_1"
,
item0
.
getValue
());
Assert
.
assertEquals
(
"created"
,
item0
.
getDataChangeCreatedBy
());
Assert
.
assertNotNull
(
item0
.
getDataChangeCreatedTime
());
}
}
apollo-adminservice/src/test/resources/application.properties
View file @
44375b3b
spring.datasource.url
=
jdbc:h2:mem:~/
fxapolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE
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_strategy
=
org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.show_sql
=
true
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
apollo-adminservice/src/test/resources/controller/test-itemset-cleanup.sql
0 → 100644
View file @
44375b3b
DELETE
FROM
Item
;
DELETE
FROM
Namespace
;
DELETE
FROM
AppNamespace
;
DELETE
FROM
Cluster
;
DELETE
FROM
App
;
apollo-adminservice/src/test/resources/controller/test-itemset.sql
0 → 100644
View file @
44375b3b
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'someAppId'
,
'someAppName'
,
'someOwnerName'
,
'someOwnerName@ctrip.com'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'someAppId'
,
'default'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'someAppId'
,
'application'
);
INSERT
INTO
Namespace
(
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
'someAppId'
,
'default'
,
'application'
);
apollo-adminservice/src/test/resources/
import
.sql
→
apollo-adminservice/src/test/resources/
data
.sql
View file @
44375b3b
File moved
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
View file @
44375b3b
...
@@ -20,8 +20,8 @@ public abstract class BaseEntity {
...
@@ -20,8 +20,8 @@ public abstract class BaseEntity {
@GeneratedValue
@GeneratedValue
private
long
id
;
private
long
id
;
@Column
(
name
=
"IsDeleted"
)
@Column
(
name
=
"IsDeleted"
,
columnDefinition
=
"Bit default '0'"
)
protected
boolean
isDeleted
;
protected
boolean
isDeleted
=
false
;
@Column
(
name
=
"DataChange_CreatedBy"
)
@Column
(
name
=
"DataChange_CreatedBy"
)
private
String
dataChangeCreatedBy
;
private
String
dataChangeCreatedBy
;
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemSetService.java
View file @
44375b3b
...
@@ -4,51 +4,43 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -4,51 +4,43 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
java.util.Date
;
@Service
@Service
public
class
ItemSetService
{
public
class
ItemSetService
{
@Autowired
@Autowired
private
ItemRepository
itemRepository
;
private
ItemRepository
itemRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
public
void
updateSet
(
String
appId
,
String
clusterName
,
String
namespaceName
,
ItemChangeSets
changeSet
)
{
Namespace
namespace
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
String
modifyBy
=
changeSet
.
getModifyBy
();
public
void
updateSet
(
ItemChangeSets
changeSet
)
{
for
(
ItemDTO
item
:
changeSet
.
getCreateItems
())
{
if
(
changeSet
.
getCreateItems
()
!=
null
)
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
for
(
ItemDTO
item
:
changeSet
.
getCreateItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
entity
.
setNamespaceId
(
namespace
.
getId
());
entity
.
setDataChangeCreatedBy
(
changeSet
.
getModifyBy
());
entity
.
setDataChangeCreatedBy
(
modifyBy
);
itemRepository
.
save
(
entity
);
entity
.
setDataChangeCreatedTime
(
new
Date
());
}
entity
.
setDataChangeLastModifiedBy
(
modifyBy
);
itemRepository
.
save
(
entity
);
}
}
for
(
ItemDTO
item
:
changeSet
.
getUpdateItems
())
{
if
(
changeSet
.
getUpdateItems
()
!=
null
)
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
for
(
ItemDTO
item
:
changeSet
.
getUpdateItems
())
{
Item
managedItem
=
itemRepository
.
findOne
(
entity
.
getId
());
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
if
(
managedItem
!=
null
){
Item
managedItem
=
itemRepository
.
findOne
(
entity
.
getId
());
BeanUtils
.
copyEntityProperties
(
entity
,
managedItem
,
"id"
,
"namespaceId"
,
"key"
,
"dataChangeCreatedBy"
,
"dataChangeCreatedTime"
);
BeanUtils
.
copyEntityProperties
(
entity
,
managedItem
);
managedItem
.
setDataChangeLastModifiedBy
(
modifyBy
);
managedItem
.
setDataChangeLastModifiedBy
(
changeSet
.
getModifyBy
());
itemRepository
.
save
(
managedItem
);
}
}
itemRepository
.
save
(
managedItem
);
}
}
for
(
ItemDTO
item
:
changeSet
.
getDeletedItems
())
{
if
(
changeSet
.
getDeleteItems
()
!=
null
)
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
for
(
ItemDTO
item
:
changeSet
.
getDeleteItems
())
{
entity
.
setDataChangeLastModifiedBy
(
modifyBy
);
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
itemRepository
.
delete
(
entity
.
getId
());
entity
.
setDataChangeLastModifiedBy
(
changeSet
.
getModifyBy
());
itemRepository
.
save
(
entity
);
itemRepository
.
delete
(
item
.
getId
());
}
}
}
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/BeanUtils.java
View file @
44375b3b
...
@@ -209,12 +209,22 @@ public class BeanUtils {
...
@@ -209,12 +209,22 @@ public class BeanUtils {
}
}
/**
/**
* The copy will ignore <em>id</em> field
*
*
* @param source
* @param source
* @param target
* @param target
*/
*/
public
static
void
copy
Entity
Properties
(
Object
source
,
Object
target
,
String
...
ignoreProperties
)
{
public
static
void
copyProperties
(
Object
source
,
Object
target
,
String
...
ignoreProperties
)
{
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
ignoreProperties
);
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
ignoreProperties
);
}
}
/**
* The copy will ignore <em>BaseEntity</em> field
*
* @param source
* @param target
*/
public
static
void
copyEntityProperties
(
Object
source
,
Object
target
)
{
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
"id"
,
"dataChangeCreatedBy"
,
"dataChangeCreatedTime"
,
"dataChangeLastModifiedBy"
,
"dataChangeLastModifiedTime"
);
}
}
}
apollo-configservice/src/main/java/com/ctrip/apollo/configservice/controller/WebMvcConfig.java
View file @
44375b3b
...
@@ -8,7 +8,6 @@ import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
...
@@ -8,7 +8,6 @@ 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.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
@Configuration
@Configuration
...
...
apollo-configservice/src/test/resources/application.properties
View file @
44375b3b
spring.datasource.url
=
jdbc:h2:mem:~/
fx
apolloconfigdb;mode=mysql
spring.datasource.url
=
jdbc:h2:mem:~/apolloconfigdb;mode=mysql
spring.jpa.hibernate.naming_strategy
=
org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming_strategy
=
org.hibernate.cfg.EJB3NamingStrategy
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
hibernate.globally_quoted_identifiers
=
true
spring.jpa.properties.hibernate.show_sql
=
true
hibernate.show_sql
=
true
\ No newline at end of file
\ No newline at end of file
apollo-configservice/src/test/resources/
import
.sql
→
apollo-configservice/src/test/resources/
data
.sql
View file @
44375b3b
File moved
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ItemChangeSets.java
View file @
44375b3b
...
@@ -11,9 +11,9 @@ public class ItemChangeSets {
...
@@ -11,9 +11,9 @@ public class ItemChangeSets {
private
String
modifyBy
;
private
String
modifyBy
;
private
List
<
ItemDTO
>
createItems
=
new
LinkedList
<>();
private
List
<
ItemDTO
>
createItems
=
new
LinkedList
<>();
private
List
<
ItemDTO
>
updateItems
=
new
LinkedList
<>();
private
List
<
ItemDTO
>
updateItems
=
new
LinkedList
<>();
private
List
<
ItemDTO
>
delete
d
Items
=
new
LinkedList
<>();
private
List
<
ItemDTO
>
deleteItems
=
new
LinkedList
<>();
public
void
addCreate
d
Item
(
ItemDTO
item
)
{
public
void
addCreateItem
(
ItemDTO
item
)
{
createItems
.
add
(
item
);
createItems
.
add
(
item
);
}
}
...
@@ -21,11 +21,10 @@ public class ItemChangeSets {
...
@@ -21,11 +21,10 @@ public class ItemChangeSets {
updateItems
.
add
(
item
);
updateItems
.
add
(
item
);
}
}
public
void
addDelete
d
Item
(
ItemDTO
item
)
{
public
void
addDeleteItem
(
ItemDTO
item
)
{
delete
d
Items
.
add
(
item
);
deleteItems
.
add
(
item
);
}
}
public
List
<
ItemDTO
>
getCreateItems
()
{
public
List
<
ItemDTO
>
getCreateItems
()
{
return
createItems
;
return
createItems
;
}
}
...
@@ -34,8 +33,8 @@ public class ItemChangeSets {
...
@@ -34,8 +33,8 @@ public class ItemChangeSets {
return
updateItems
;
return
updateItems
;
}
}
public
List
<
ItemDTO
>
getDelete
d
Items
()
{
public
List
<
ItemDTO
>
getDeleteItems
()
{
return
delete
d
Items
;
return
deleteItems
;
}
}
public
void
setCreateItems
(
List
<
ItemDTO
>
createItems
)
{
public
void
setCreateItems
(
List
<
ItemDTO
>
createItems
)
{
...
@@ -46,8 +45,8 @@ public class ItemChangeSets {
...
@@ -46,8 +45,8 @@ public class ItemChangeSets {
this
.
updateItems
=
updateItems
;
this
.
updateItems
=
updateItems
;
}
}
public
void
setDelete
dItems
(
List
<
ItemDTO
>
deleted
Items
)
{
public
void
setDelete
Items
(
List
<
ItemDTO
>
delete
Items
)
{
this
.
delete
dItems
=
deleted
Items
;
this
.
delete
Items
=
delete
Items
;
}
}
public
String
getModifyBy
()
{
public
String
getModifyBy
()
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/PropertyResolver.java
View file @
44375b3b
...
@@ -4,11 +4,10 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
...
@@ -4,11 +4,10 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
import
com.sun.tools.javac.util.Assert
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -43,7 +42,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -43,7 +42,7 @@ public class PropertyResolver implements ConfigTextResolver {
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
result
.
setChangeSets
(
changeSets
);
result
.
setChangeSets
(
changeSets
);
Map
<
Integer
,
String
>
newLineNumMapItem
=
new
Hash
ed
Map
();
//use for delete blank and comment item
Map
<
Integer
,
String
>
newLineNumMapItem
=
new
HashMap
();
//use for delete blank and comment item
int
lineCounter
=
1
;
int
lineCounter
=
1
;
for
(
String
newItem
:
newItems
)
{
for
(
String
newItem
:
newItems
)
{
newItem
=
newItem
.
trim
();
newItem
=
newItem
.
trim
();
...
@@ -82,13 +81,13 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -82,13 +81,13 @@ public class PropertyResolver implements ConfigTextResolver {
String
oldComment
=
oldItemByLine
==
null
?
""
:
oldItemByLine
.
getComment
();
String
oldComment
=
oldItemByLine
==
null
?
""
:
oldItemByLine
.
getComment
();
//create comment. implement update comment by delete old comment and create new comment
//create comment. implement update comment by delete old comment and create new comment
if
(!(
isCommentItem
(
oldItemByLine
)
&&
newItem
.
equals
(
oldComment
)))
{
if
(!(
isCommentItem
(
oldItemByLine
)
&&
newItem
.
equals
(
oldComment
)))
{
changeSets
.
addCreate
d
Item
(
buildCommentItem
(
0
l
,
newItem
,
lineCounter
));
changeSets
.
addCreateItem
(
buildCommentItem
(
0
l
,
newItem
,
lineCounter
));
}
}
}
}
private
void
handleBlankLine
(
ItemDTO
oldItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
private
void
handleBlankLine
(
ItemDTO
oldItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
if
(!
isBlankItem
(
oldItem
))
{
if
(!
isBlankItem
(
oldItem
))
{
changeSets
.
addCreate
d
Item
(
buildBlankItem
(
0
l
,
lineCounter
));
changeSets
.
addCreateItem
(
buildBlankItem
(
0
l
,
lineCounter
));
}
}
}
}
...
@@ -110,7 +109,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -110,7 +109,7 @@ public class PropertyResolver implements ConfigTextResolver {
ItemDTO
oldItem
=
keyMapOldItem
.
get
(
newKey
);
ItemDTO
oldItem
=
keyMapOldItem
.
get
(
newKey
);
if
(
oldItem
==
null
)
{
//new item
if
(
oldItem
==
null
)
{
//new item
changeSets
.
addCreate
d
Item
(
buildNormalItem
(
0
l
,
newKey
,
newValue
,
""
,
lineCounter
));
changeSets
.
addCreateItem
(
buildNormalItem
(
0
l
,
newKey
,
newValue
,
""
,
lineCounter
));
}
else
if
(!
newValue
.
equals
(
oldItem
.
getValue
())){
//update item
}
else
if
(!
newValue
.
equals
(
oldItem
.
getValue
())){
//update item
changeSets
.
addUpdateItem
(
changeSets
.
addUpdateItem
(
buildNormalItem
(
oldItem
.
getId
(),
newKey
,
newValue
,
oldItem
.
getComment
(),
buildNormalItem
(
oldItem
.
getId
(),
newKey
,
newValue
,
oldItem
.
getComment
(),
...
@@ -139,7 +138,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -139,7 +138,7 @@ public class PropertyResolver implements ConfigTextResolver {
private
void
deleteNormalKVItem
(
Map
<
String
,
ItemDTO
>
baseKeyMapItem
,
ItemChangeSets
changeSets
)
{
private
void
deleteNormalKVItem
(
Map
<
String
,
ItemDTO
>
baseKeyMapItem
,
ItemChangeSets
changeSets
)
{
//surplus item is to be deleted
//surplus item is to be deleted
for
(
Map
.
Entry
<
String
,
ItemDTO
>
entry
:
baseKeyMapItem
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
ItemDTO
>
entry
:
baseKeyMapItem
.
entrySet
())
{
changeSets
.
addDelete
d
Item
(
entry
.
getValue
());
changeSets
.
addDeleteItem
(
entry
.
getValue
());
}
}
}
}
...
@@ -156,7 +155,7 @@ public class PropertyResolver implements ConfigTextResolver {
...
@@ -156,7 +155,7 @@ public class PropertyResolver implements ConfigTextResolver {
//2.old is comment by now is not exist or modified
//2.old is comment by now is not exist or modified
if
((
isBlankItem
(
oldItem
)
&&
!
isBlankItem
(
newItem
))
if
((
isBlankItem
(
oldItem
)
&&
!
isBlankItem
(
newItem
))
||
isCommentItem
(
oldItem
)
&&
(
newItem
==
null
||
!
newItem
.
equals
(
oldItem
)))
{
||
isCommentItem
(
oldItem
)
&&
(
newItem
==
null
||
!
newItem
.
equals
(
oldItem
)))
{
changeSets
.
addDelete
d
Item
(
oldItem
);
changeSets
.
addDeleteItem
(
oldItem
);
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment