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
b722655c
Commit
b722655c
authored
Jun 16, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ut
parent
04383980
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
39 deletions
+31
-39
BizTestConfiguration.java
.../com/ctrip/framework/apollo/biz/BizTestConfiguration.java
+3
-1
AppRepositoryTest.java
...ip/framework/apollo/biz/repository/AppRepositoryTest.java
+1
-0
AppController.java
...rip/framework/apollo/portal/controller/AppController.java
+5
-0
AppService.java
...com/ctrip/framework/apollo/portal/service/AppService.java
+0
-16
RequestPrecondition.java
...rip/framework/apollo/portal/util/RequestPrecondition.java
+1
-2
config.html
apollo-portal/src/main/resources/static/config.html
+2
-1
ServiceExceptionTest.java
...m/ctrip/framework/apollo/portal/ServiceExceptionTest.java
+19
-19
No files found.
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/BizTestConfiguration.java
View file @
b722655c
package
com
.
ctrip
.
framework
.
apollo
.
biz
;
import
com.ctrip.framework.apollo.common.ApolloCommonConfig
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
@EnableAutoConfiguration
@ComponentScan
(
basePackage
s
=
"com.ctrip.framework.apollo.biz"
)
@ComponentScan
(
basePackage
Classes
=
{
ApolloCommonConfig
.
class
,
ApolloBizConfig
.
class
}
)
public
class
BizTestConfiguration
{
}
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppRepositoryTest.java
View file @
b722655c
...
...
@@ -9,6 +9,7 @@ import org.springframework.test.annotation.Rollback;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.framework.apollo.biz.BizTestConfiguration
;
import
com.ctrip.framework.apollo.common.entity.App
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
View file @
b722655c
...
...
@@ -60,6 +60,11 @@ public class AppController {
return
response
;
}
/**
* 创建App流程: 1.先在portal db中创建 2.再保存到各个环境的apollo db中
*
* 只要第一步成功,就算这次创建app是成功操作,如果某个环境的apollo db创建失败,可通过portal db中的app信息再次创建.
*/
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
create
(
@RequestBody
App
app
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
View file @
b722655c
...
...
@@ -68,19 +68,6 @@ public class AppService {
return
appAPI
.
loadApp
(
env
,
appId
);
}
/**
* 创建App流程: 1.先在portal db中创建 2.再保存到各个环境的apollo db中
*
* 只要第一步成功,就算这次创建app是成功操作,如果某个环境的apollo db创建失败,可通过portal db中的app信息再次创建.
*/
public
void
createApp
(
App
app
)
{
enrichUserInfo
(
app
);
App
localApp
=
createOrUpdateAppInLocal
(
app
);
publisher
.
publishEvent
(
new
AppCreationEvent
(
localApp
));
}
public
void
createApp
(
Env
env
,
App
app
)
{
enrichUserInfo
(
app
);
try
{
...
...
@@ -109,9 +96,6 @@ public class AppService {
return
appRepository
.
save
(
managedApp
);
}
else
{
App
createdApp
=
appRepository
.
save
(
app
);
if
(
app
.
getName
().
equals
(
"xx"
)){
throw
new
RuntimeException
(
"xxxx"
);
}
namespaceService
.
createDefaultAppNamespace
(
appId
);
//role
roleInitializationService
.
initAppRoles
(
createdApp
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RequestPrecondition.java
View file @
b722655c
...
...
@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.portal.util;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.sun.istack.internal.Nullable
;
public
class
RequestPrecondition
{
...
...
@@ -19,7 +18,7 @@ public class RequestPrecondition {
checkArgument
(
valid
,
ILLEGAL_MODEL
);
}
public
static
void
checkArgument
(
boolean
expression
,
@Nullable
Object
errorMessage
)
{
public
static
void
checkArgument
(
boolean
expression
,
Object
errorMessage
)
{
if
(!
expression
)
{
throw
new
BadRequestException
(
String
.
valueOf
(
errorMessage
));
}
...
...
apollo-portal/src/main/resources/static/config.html
View file @
b722655c
...
...
@@ -119,9 +119,10 @@
<div
class=
"btn-group"
role=
"group"
aria-label=
"..."
>
<button
type=
"button"
class=
"btn btn-default btn-sm J_tableview_btn"
ng-show=
"namespace.hasReleasePermission || namespace.hasModifyPermission"
ng-disabled=
"namespace.isTextEditing"
ng-click=
"prepareReleaseNamespace(namespace)"
>
发布
<!--ng-show="namespace.hasReleasePermission"-->
</button>
<button
type=
"button"
class=
"btn btn-default btn-sm J_tableview_btn"
disabled
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/ServiceExceptionTest.java
View file @
b722655c
...
...
@@ -21,11 +21,11 @@ import org.springframework.test.util.ReflectionTestUtils;
import
org.springframework.web.client.HttpServerErrorException
;
import
org.springframework.web.client.HttpStatusCodeException
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
com.ctrip.framework.apollo.portal.
api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.
controller.AppController
;
import
com.ctrip.framework.apollo.portal.service.AppService
;
import
com.google.gson.Gson
;
...
...
@@ -33,26 +33,25 @@ import com.google.gson.Gson;
public
class
ServiceExceptionTest
extends
AbstractPortalTest
{
@Autowired
private
AppService
appService
;
private
AppController
appController
;
@Mock
private
A
dminServiceAPI
.
AppAPI
appAPI
;
private
A
ppService
appService
;
@Before
public
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
ReflectionTestUtils
.
setField
(
app
Service
,
"appAPI"
,
appAPI
);
ReflectionTestUtils
.
setField
(
app
Controller
,
"appService"
,
appService
);
}
private
String
getBaseAppUrl
()
{
return
"http://localhost:"
+
port
+
"/apps
/envs/ALL
"
;
return
"http://localhost:"
+
port
+
"/apps"
;
}
@Test
public
void
testAdminServiceException
()
{
Map
<
String
,
Object
>
errorAttributes
=
new
LinkedHashMap
<>();
errorAttributes
.
put
(
"status"
,
500
);
errorAttributes
.
put
(
"message"
,
"
admin server error
"
);
errorAttributes
.
put
(
"message"
,
"
No available admin service
"
);
errorAttributes
.
put
(
"timestamp"
,
LocalDateTime
.
now
().
format
(
DateTimeFormatter
.
ISO_LOCAL_DATE_TIME
));
errorAttributes
.
put
(
"exception"
,
ServiceException
.
class
.
getName
());
...
...
@@ -61,26 +60,27 @@ public class ServiceExceptionTest extends AbstractPortalTest {
HttpStatusCodeException
adminException
=
new
HttpServerErrorException
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
"admin server error"
,
new
Gson
().
toJson
(
errorAttributes
).
getBytes
(),
Charset
.
defaultCharset
());
when
(
appAPI
.
createApp
(
any
(
Env
.
class
),
any
(
AppDTO
.
class
))).
thenThrow
(
adminException
);
AppDTO
dto
=
generateSampleDTOData
();
when
(
appService
.
createOrUpdateAppInLocal
(
any
(
App
.
class
))).
thenThrow
(
adminException
);
App
app
=
generateSampleApp
();
try
{
restTemplate
.
postForEntity
(
getBaseAppUrl
(),
dto
,
AppDTO
.
class
);
restTemplate
.
postForEntity
(
getBaseAppUrl
(),
app
,
AppDTO
.
class
);
}
catch
(
HttpStatusCodeException
e
)
{
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
String
>
attr
=
new
Gson
().
fromJson
(
e
.
getResponseBodyAsString
(),
Map
.
class
);
System
.
out
.
println
(
ExceptionUtils
.
toString
(
e
));
Assert
.
assertEquals
(
"
admin server error
"
,
attr
.
get
(
"message"
));
Assert
.
assertEquals
(
"
No available admin service
"
,
attr
.
get
(
"message"
));
Assert
.
assertEquals
(
"8848"
,
attr
.
get
(
"errorCode"
));
}
}
private
App
DTO
generateSampleDTOData
()
{
App
DTO
dto
=
new
AppDTO
();
dto
.
setAppId
(
"someAppId"
);
dto
.
setName
(
"someName"
);
dto
.
setOwnerName
(
"someOwner"
);
dto
.
setOwnerEmail
(
"someOwner@ctrip.com"
);
return
dto
;
private
App
generateSampleApp
()
{
App
app
=
new
App
();
app
.
setAppId
(
"someAppId"
);
app
.
setName
(
"someName"
);
app
.
setOwnerName
(
"someOwner"
);
app
.
setOwnerEmail
(
"someOwner@ctrip.com"
);
return
app
;
}
}
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