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
9fb54c68
Commit
9fb54c68
authored
May 06, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
f2c7de85
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
217 additions
and
149 deletions
+217
-149
AdminServiceTransactionTest.java
...ctrip/apollo/biz/service/AdminServiceTransactionTest.java
+4
-4
ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+0
-10
NamespaceController.java
...m/ctrip/apollo/portal/controller/NamespaceController.java
+12
-0
ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+0
-87
NamespaceService.java
...ava/com/ctrip/apollo/portal/service/NamespaceService.java
+110
-0
AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+1
-1
ConfigServiceTest.java
.../test/java/com/ctrip/apollo/portal/ConfigServiceTest.java
+0
-47
NamespaceServiceTest.java
...st/java/com/ctrip/apollo/portal/NamespaceServiceTest.java
+90
-0
No files found.
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTransactionTest.java
View file @
9fb54c68
...
@@ -50,7 +50,7 @@ public class AdminServiceTransactionTest {
...
@@ -50,7 +50,7 @@ public class AdminServiceTransactionTest {
System
.
out
.
println
(
app
.
getAppId
());
System
.
out
.
println
(
app
.
getAppId
());
}
}
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
}
...
@@ -58,7 +58,7 @@ public class AdminServiceTransactionTest {
...
@@ -58,7 +58,7 @@ public class AdminServiceTransactionTest {
@Before
@Before
public
void
setUpTestDataWithinTransaction
()
{
public
void
setUpTestDataWithinTransaction
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
}
...
@@ -82,7 +82,7 @@ public class AdminServiceTransactionTest {
...
@@ -82,7 +82,7 @@ public class AdminServiceTransactionTest {
@After
@After
public
void
tearDownWithinTransaction
()
{
public
void
tearDownWithinTransaction
()
{
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
Assert
.
assertEquals
(
1
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
8
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
1
,
clusterRepository
.
count
());
}
}
...
@@ -90,7 +90,7 @@ public class AdminServiceTransactionTest {
...
@@ -90,7 +90,7 @@ public class AdminServiceTransactionTest {
@AfterTransaction
@AfterTransaction
public
void
verifyFinalDatabaseState
()
{
public
void
verifyFinalDatabaseState
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
View file @
9fb54c68
...
@@ -31,16 +31,6 @@ public class ConfigController {
...
@@ -31,16 +31,6 @@ public class ConfigController {
@Autowired
@Autowired
private
ConfigService
configService
;
private
ConfigService
configService
;
@RequestMapping
(
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceVO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
))
{
throw
new
BadRequestException
(
"app id and cluster name can not be empty"
);
}
return
configService
.
findNampspaces
(
appId
,
Env
.
valueOf
(
env
),
clusterName
);
}
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
"application/json"
})
"application/json"
})
public
void
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
public
void
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/NamespaceController.java
View file @
9fb54c68
...
@@ -5,6 +5,7 @@ import com.ctrip.apollo.core.dto.NamespaceDTO;
...
@@ -5,6 +5,7 @@ import com.ctrip.apollo.core.dto.NamespaceDTO;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.service.NamespaceService
;
import
com.ctrip.apollo.portal.service.NamespaceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -18,6 +19,7 @@ import java.util.List;
...
@@ -18,6 +19,7 @@ import java.util.List;
@RestController
@RestController
public
class
NamespaceController
{
public
class
NamespaceController
{
@Autowired
@Autowired
private
NamespaceService
namespaceService
;
private
NamespaceService
namespaceService
;
...
@@ -35,4 +37,14 @@ public class NamespaceController {
...
@@ -35,4 +37,14 @@ public class NamespaceController {
}
}
@RequestMapping
(
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceVO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
))
{
throw
new
BadRequestException
(
"app id and cluster name can not be empty"
);
}
return
namespaceService
.
findNampspaces
(
appId
,
Env
.
valueOf
(
env
),
clusterName
);
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
View file @
9fb54c68
...
@@ -50,90 +50,6 @@ public class ConfigService {
...
@@ -50,90 +50,6 @@ public class ConfigService {
@Autowired
@Autowired
private
ConfigTextResolver
resolver
;
private
ConfigTextResolver
resolver
;
private
Gson
gson
=
new
Gson
();
/**
* load cluster all namespace info with items
*/
public
List
<
NamespaceVO
>
findNampspaces
(
String
appId
,
Env
env
,
String
clusterName
)
{
List
<
NamespaceDTO
>
namespaces
=
namespaceAPI
.
findNamespaceByCluster
(
appId
,
env
,
clusterName
);
if
(
namespaces
==
null
||
namespaces
.
size
()
==
0
)
{
return
Collections
.
emptyList
();
}
List
<
NamespaceVO
>
namespaceVOs
=
new
LinkedList
<>();
for
(
NamespaceDTO
namespace
:
namespaces
)
{
NamespaceVO
namespaceVO
=
null
;
try
{
namespaceVO
=
parseNamespace
(
appId
,
env
,
clusterName
,
namespace
);
namespaceVOs
.
add
(
namespaceVO
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespace
.
getNamespaceName
(),
e
);
throw
e
;
}
}
return
namespaceVOs
;
}
@SuppressWarnings
(
"unchecked"
)
private
NamespaceVO
parseNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
NamespaceDTO
namespace
)
{
NamespaceVO
namespaceVO
=
new
NamespaceVO
();
namespaceVO
.
setNamespace
(
namespace
);
List
<
NamespaceVO
.
ItemVO
>
itemVos
=
new
LinkedList
<>();
namespaceVO
.
setItems
(
itemVos
);
String
namespaceName
=
namespace
.
getNamespaceName
();
//latest Release
ReleaseDTO
release
=
null
;
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
try
{
release
=
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
releaseItems
=
gson
.
fromJson
(
release
.
getConfigurations
(),
Map
.
class
);
}
catch
(
HttpClientErrorException
e
)
{
if
(
e
.
getStatusCode
()
==
HttpStatus
.
NOT_FOUND
)
{
logger
.
warn
(
ExceptionUtils
.
toString
(
e
));
}
else
{
throw
e
;
}
}
//not Release config items
List
<
ItemDTO
>
items
=
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
int
modifiedItemCnt
=
0
;
for
(
ItemDTO
itemDTO
:
items
)
{
NamespaceVO
.
ItemVO
itemVO
=
parseItemVO
(
itemDTO
,
releaseItems
);
if
(
itemVO
.
isModified
())
{
modifiedItemCnt
++;
}
itemVos
.
add
(
itemVO
);
}
namespaceVO
.
setItemModifiedCnt
(
modifiedItemCnt
);
return
namespaceVO
;
}
private
NamespaceVO
.
ItemVO
parseItemVO
(
ItemDTO
itemDTO
,
Map
<
String
,
String
>
releaseItems
)
{
String
key
=
itemDTO
.
getKey
();
NamespaceVO
.
ItemVO
itemVO
=
new
NamespaceVO
.
ItemVO
();
itemVO
.
setItem
(
itemDTO
);
String
newValue
=
itemDTO
.
getValue
();
String
oldValue
=
releaseItems
.
get
(
key
);
if
(!
StringUtils
.
isEmpty
(
key
)
&&
(
oldValue
==
null
||
!
newValue
.
equals
(
oldValue
)))
{
itemVO
.
setModified
(
true
);
itemVO
.
setOldValue
(
oldValue
==
null
?
""
:
oldValue
);
itemVO
.
setNewValue
(
newValue
);
}
return
itemVO
;
}
/**
/**
* parse config text and update config items
* parse config text and update config items
...
@@ -160,10 +76,8 @@ public class ConfigService {
...
@@ -160,10 +76,8 @@ public class ConfigService {
namespaceName
);
namespaceName
);
throw
new
ServiceException
(
e
.
getMessage
());
throw
new
ServiceException
(
e
.
getMessage
());
}
}
}
}
/**
/**
* createRelease config items
* createRelease config items
*/
*/
...
@@ -190,7 +104,6 @@ public class ConfigService {
...
@@ -190,7 +104,6 @@ public class ConfigService {
throw
new
ServiceException
(
String
.
format
(
"sync item error. env:%s, clusterName:%s"
,
namespaceIdentifer
.
getEnv
(),
throw
new
ServiceException
(
String
.
format
(
"sync item error. env:%s, clusterName:%s"
,
namespaceIdentifer
.
getEnv
(),
namespaceIdentifer
.
getClusterName
()),
e
);
namespaceIdentifer
.
getClusterName
()),
e
);
}
}
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/NamespaceService.java
View file @
9fb54c68
package
com
.
ctrip
.
apollo
.
portal
.
service
;
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.google.gson.Gson
;
import
com.ctrip.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.HttpClientErrorException
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
@Service
@Service
public
class
NamespaceService
{
public
class
NamespaceService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
NamespaceService
.
class
);
@Autowired
private
AdminServiceAPI
.
ItemAPI
itemAPI
;
@Autowired
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
@Autowired
@Autowired
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@Autowired
@Autowired
private
PortalSettings
portalSettings
;
private
PortalSettings
portalSettings
;
private
Gson
gson
=
new
Gson
();
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(){
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(){
return
namespaceAPI
.
findPublicAppNamespaces
(
portalSettings
.
getFirstEnv
());
return
namespaceAPI
.
findPublicAppNamespaces
(
portalSettings
.
getFirstEnv
());
}
}
...
@@ -27,4 +54,87 @@ public class NamespaceService {
...
@@ -27,4 +54,87 @@ public class NamespaceService {
return
namespaceAPI
.
save
(
env
,
namespace
);
return
namespaceAPI
.
save
(
env
,
namespace
);
}
}
/**
* load cluster all namespace info with items
*/
public
List
<
NamespaceVO
>
findNampspaces
(
String
appId
,
Env
env
,
String
clusterName
)
{
List
<
NamespaceDTO
>
namespaces
=
namespaceAPI
.
findNamespaceByCluster
(
appId
,
env
,
clusterName
);
if
(
namespaces
==
null
||
namespaces
.
size
()
==
0
)
{
return
Collections
.
emptyList
();
}
List
<
NamespaceVO
>
namespaceVOs
=
new
LinkedList
<>();
for
(
NamespaceDTO
namespace
:
namespaces
)
{
NamespaceVO
namespaceVO
=
null
;
try
{
namespaceVO
=
parseNamespace
(
appId
,
env
,
clusterName
,
namespace
);
namespaceVOs
.
add
(
namespaceVO
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespace
.
getNamespaceName
(),
e
);
throw
e
;
}
}
return
namespaceVOs
;
}
@SuppressWarnings
(
"unchecked"
)
private
NamespaceVO
parseNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
NamespaceDTO
namespace
)
{
NamespaceVO
namespaceVO
=
new
NamespaceVO
();
namespaceVO
.
setNamespace
(
namespace
);
List
<
NamespaceVO
.
ItemVO
>
itemVos
=
new
LinkedList
<>();
namespaceVO
.
setItems
(
itemVos
);
String
namespaceName
=
namespace
.
getNamespaceName
();
//latest Release
ReleaseDTO
release
=
null
;
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
try
{
release
=
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
releaseItems
=
gson
.
fromJson
(
release
.
getConfigurations
(),
Map
.
class
);
}
catch
(
HttpClientErrorException
e
)
{
if
(
e
.
getStatusCode
()
==
HttpStatus
.
NOT_FOUND
)
{
logger
.
warn
(
ExceptionUtils
.
toString
(
e
));
}
else
{
throw
e
;
}
}
//not Release config items
List
<
ItemDTO
>
items
=
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
int
modifiedItemCnt
=
0
;
for
(
ItemDTO
itemDTO
:
items
)
{
NamespaceVO
.
ItemVO
itemVO
=
parseItemVO
(
itemDTO
,
releaseItems
);
if
(
itemVO
.
isModified
())
{
modifiedItemCnt
++;
}
itemVos
.
add
(
itemVO
);
}
namespaceVO
.
setItemModifiedCnt
(
modifiedItemCnt
);
return
namespaceVO
;
}
private
NamespaceVO
.
ItemVO
parseItemVO
(
ItemDTO
itemDTO
,
Map
<
String
,
String
>
releaseItems
)
{
String
key
=
itemDTO
.
getKey
();
NamespaceVO
.
ItemVO
itemVO
=
new
NamespaceVO
.
ItemVO
();
itemVO
.
setItem
(
itemDTO
);
String
newValue
=
itemDTO
.
getValue
();
String
oldValue
=
releaseItems
.
get
(
key
);
if
(!
StringUtils
.
isEmpty
(
key
)
&&
(
oldValue
==
null
||
!
newValue
.
equals
(
oldValue
)))
{
itemVO
.
setModified
(
true
);
itemVO
.
setOldValue
(
oldValue
==
null
?
""
:
oldValue
);
itemVO
.
setNewValue
(
newValue
);
}
return
itemVO
;
}
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
View file @
9fb54c68
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
AppServiceTest
.
class
AppServiceTest
.
class
,
NamespaceServiceTest
.
class
})
})
public
class
AllTests
{
public
class
AllTests
{
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/ConfigServiceTest.java
View file @
9fb54c68
...
@@ -4,12 +4,10 @@ import com.ctrip.apollo.core.ConfigConsts;
...
@@ -4,12 +4,10 @@ import com.ctrip.apollo.core.ConfigConsts;
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
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.ItemDiffs
;
import
com.ctrip.apollo.portal.entity.ItemDiffs
;
import
com.ctrip.apollo.portal.entity.NamespaceIdentifer
;
import
com.ctrip.apollo.portal.entity.NamespaceIdentifer
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.txtresolver.PropertyResolver
;
import
com.ctrip.apollo.portal.service.txtresolver.PropertyResolver
;
...
@@ -48,51 +46,6 @@ public class ConfigServiceTest {
...
@@ -48,51 +46,6 @@ public class ConfigServiceTest {
}
}
@Test
@Test
public
void
testFindNamespace
()
{
String
appId
=
"6666"
;
String
clusterName
=
"default"
;
String
namespaceName
=
"application"
;
NamespaceDTO
application
=
new
NamespaceDTO
();
application
.
setId
(
1
);
application
.
setClusterName
(
clusterName
);
application
.
setAppId
(
appId
);
application
.
setNamespaceName
(
namespaceName
);
NamespaceDTO
hermas
=
new
NamespaceDTO
();
hermas
.
setId
(
2
);
hermas
.
setClusterName
(
"default"
);
hermas
.
setAppId
(
appId
);
hermas
.
setNamespaceName
(
"hermas"
);
List
<
NamespaceDTO
>
namespaces
=
Arrays
.
asList
(
application
,
hermas
);
ReleaseDTO
someRelease
=
new
ReleaseDTO
();
someRelease
.
setConfigurations
(
"{\"a\":\"123\",\"b\":\"123\"}"
);
ItemDTO
i1
=
new
ItemDTO
(
"a"
,
"123"
,
""
,
1
);
ItemDTO
i2
=
new
ItemDTO
(
"b"
,
"1"
,
""
,
2
);
ItemDTO
i3
=
new
ItemDTO
(
""
,
""
,
"#dddd"
,
3
);
ItemDTO
i4
=
new
ItemDTO
(
"c"
,
"1"
,
""
,
4
);
List
<
ItemDTO
>
someItems
=
Arrays
.
asList
(
i1
,
i2
,
i3
,
i4
);
when
(
namespaceAPI
.
findNamespaceByCluster
(
appId
,
Env
.
DEV
,
clusterName
)).
thenReturn
(
namespaces
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someRelease
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
"hermas"
)).
thenReturn
(
someRelease
);
when
(
itemAPI
.
findItems
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someItems
);
List
<
NamespaceVO
>
namespaceVOs
=
configService
.
findNampspaces
(
appId
,
Env
.
DEV
,
clusterName
);
assertEquals
(
2
,
namespaceVOs
.
size
());
NamespaceVO
namespaceVO
=
namespaceVOs
.
get
(
0
);
assertEquals
(
4
,
namespaceVO
.
getItems
().
size
());
assertEquals
(
"a"
,
namespaceVO
.
getItems
().
get
(
0
).
getItem
().
getKey
());
assertEquals
(
2
,
namespaceVO
.
getItemModifiedCnt
());
assertEquals
(
appId
,
namespaceVO
.
getNamespace
().
getAppId
());
assertEquals
(
clusterName
,
namespaceVO
.
getNamespace
().
getClusterName
());
assertEquals
(
namespaceName
,
namespaceVO
.
getNamespace
().
getNamespaceName
());
}
@Test
public
void
testUpdateConfigByText
()
{
public
void
testUpdateConfigByText
()
{
String
appId
=
"6666"
;
String
appId
=
"6666"
;
String
clusterName
=
"default"
;
String
clusterName
=
"default"
;
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/NamespaceServiceTest.java
0 → 100644
View file @
9fb54c68
package
com
.
ctrip
.
apollo
.
portal
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.service.NamespaceService
;
import
com.ctrip.apollo.portal.service.txtresolver.PropertyResolver
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
java.util.Arrays
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
NamespaceServiceTest
{
@Mock
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@Mock
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
@Mock
private
AdminServiceAPI
.
ItemAPI
itemAPI
;
@Mock
private
PropertyResolver
resolver
;
@InjectMocks
private
NamespaceService
namespaceService
;
@Before
public
void
setup
()
{
}
@Test
public
void
testFindNamespace
()
{
String
appId
=
"6666"
;
String
clusterName
=
"default"
;
String
namespaceName
=
"application"
;
NamespaceDTO
application
=
new
NamespaceDTO
();
application
.
setId
(
1
);
application
.
setClusterName
(
clusterName
);
application
.
setAppId
(
appId
);
application
.
setNamespaceName
(
namespaceName
);
NamespaceDTO
hermas
=
new
NamespaceDTO
();
hermas
.
setId
(
2
);
hermas
.
setClusterName
(
"default"
);
hermas
.
setAppId
(
appId
);
hermas
.
setNamespaceName
(
"hermas"
);
List
<
NamespaceDTO
>
namespaces
=
Arrays
.
asList
(
application
,
hermas
);
ReleaseDTO
someRelease
=
new
ReleaseDTO
();
someRelease
.
setConfigurations
(
"{\"a\":\"123\",\"b\":\"123\"}"
);
ItemDTO
i1
=
new
ItemDTO
(
"a"
,
"123"
,
""
,
1
);
ItemDTO
i2
=
new
ItemDTO
(
"b"
,
"1"
,
""
,
2
);
ItemDTO
i3
=
new
ItemDTO
(
""
,
""
,
"#dddd"
,
3
);
ItemDTO
i4
=
new
ItemDTO
(
"c"
,
"1"
,
""
,
4
);
List
<
ItemDTO
>
someItems
=
Arrays
.
asList
(
i1
,
i2
,
i3
,
i4
);
when
(
namespaceAPI
.
findNamespaceByCluster
(
appId
,
Env
.
DEV
,
clusterName
)).
thenReturn
(
namespaces
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someRelease
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
"hermas"
)).
thenReturn
(
someRelease
);
when
(
itemAPI
.
findItems
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someItems
);
List
<
NamespaceVO
>
namespaceVOs
=
namespaceService
.
findNampspaces
(
appId
,
Env
.
DEV
,
clusterName
);
assertEquals
(
2
,
namespaceVOs
.
size
());
NamespaceVO
namespaceVO
=
namespaceVOs
.
get
(
0
);
assertEquals
(
4
,
namespaceVO
.
getItems
().
size
());
assertEquals
(
"a"
,
namespaceVO
.
getItems
().
get
(
0
).
getItem
().
getKey
());
assertEquals
(
2
,
namespaceVO
.
getItemModifiedCnt
());
assertEquals
(
appId
,
namespaceVO
.
getNamespace
().
getAppId
());
assertEquals
(
clusterName
,
namespaceVO
.
getNamespace
().
getClusterName
());
assertEquals
(
namespaceName
,
namespaceVO
.
getNamespace
().
getNamespaceName
());
}
}
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