-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic type check for Item value (#4542)
* 增加配置项类型判断,后端以及sql修改。 * apollo配置项增加类型校验 * update CHANGES.md * Update apollo-portal/src/main/resources/static/i18n/zh-CN.json Co-authored-by: mghio <[email protected]> * add ddl sql to delta file * add ddl sql to delta file ( in a new foler v200-v210) * Update scripts/sql/delta/v200-v210/apolloconfigdb-v200-v210.sql Co-authored-by: Jason Song <[email protected]> * Update scripts/sql/apolloconfigdb.sql Co-authored-by: Jason Song <[email protected]> * [openapi] add item type * Optimize the code after review. * [openapi] add type check. * Fix unit tests. * Update apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js Co-authored-by: Jason Song <[email protected]> * Update apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js Co-authored-by: Jason Song <[email protected]> * Update apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js Co-authored-by: Jason Song <[email protected]> * Update apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js Co-authored-by: Jason Song <[email protected]> * Update apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js Co-authored-by: Jason Song <[email protected]> * Fix adminservice unit tests. * Revert "Optimize the code after review." This reverts commit 6b983a0 * Re optimize the code after review. * 1. use english comments. 2. move openapi check to service side. * move openapi check to service side. * move openapi check to service side. * move type check to com.ctrip.framework.apollo.biz.service.ItemService. * add type in gray and related namespace pages. * correct comments and update com.ctrip.framework.apollo.biz.service.ItemSetService#doUpdateItems * Fix 'Type missing problem' while click 'Full Release' in Grayscale Version * correct comments * Add unit tests for ItemService. Co-authored-by: Bobji <[email protected]> Co-authored-by: mghio <[email protected]> Co-authored-by: Jason Song <[email protected]>
- Loading branch information
1 parent
70b70c3
commit e1636d4
Showing
22 changed files
with
403 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ItemServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2022 Apollo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.ctrip.framework.apollo.biz.service; | ||
|
||
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest; | ||
import com.ctrip.framework.apollo.biz.entity.Item; | ||
import com.ctrip.framework.apollo.common.exception.BadRequestException; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
public class ItemServiceTest extends AbstractIntegrationTest { | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
|
||
@Test | ||
@Sql(scripts = "/sql/item-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
public void testSaveItem() { | ||
Item item = new Item(); | ||
item.setNamespaceId(3); | ||
item.setKey("k3"); | ||
item.setType(-1); | ||
item.setValue("v3"); | ||
item.setComment(""); | ||
item.setLineNum(3); | ||
|
||
try { | ||
itemService.save(item); | ||
Assert.fail(); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e instanceof BadRequestException); | ||
} | ||
|
||
item.setType(0); | ||
Item dbItem = itemService.save(item); | ||
Assert.assertEquals(0, dbItem.getType()); | ||
} | ||
|
||
@Test | ||
@Sql(scripts = "/sql/item-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
public void testUpdateItem() { | ||
Item item = new Item(); | ||
item.setId(9901); | ||
item.setNamespaceId(1); | ||
item.setKey("k1"); | ||
item.setType(2); | ||
item.setValue("v1-new"); | ||
item.setComment(""); | ||
item.setLineNum(1); | ||
|
||
Item dbItem = itemService.update(item); | ||
Assert.assertEquals(2, dbItem.getType()); | ||
Assert.assertEquals("v1-new", dbItem.getValue()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- | ||
-- Copyright 2022 Apollo Authors | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
INSERT INTO `item` (`Id`, `NamespaceId`, `Key`, `Type`, `Value`, `Comment`, `LineNum`) | ||
VALUES | ||
(9901, 1, 'k1', 0, 'v1', '', 1), | ||
(9902, 2, 'k2', 2, 'v2', '', 2); | ||
|
||
|
||
|
Oops, something went wrong.