-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Refactor the createCommit method #4811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+175
−44
Merged
Changes from all commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
fe75b4d
add tech-support-qq-4.png
klboke 99bf97a
Update README.md
klboke 1579f41
Merge remote-tracking branch 'upstream/master'
klboke 9f65eed
Merge remote-tracking branch 'upstream/master'
klboke d7d3fd9
Enhance the user experience in the scenario of submitting duplicate keys
klboke 7329fab
Merge branch 'master' into master
nobodyiam 5def448
Modify the key-value conflict exception prompt, adjust the code style
klboke 6942564
Merge branch 'master' into master
nobodyiam 0fc1f91
Merge remote-tracking branch 'upstream/master'
klboke 61ad016
Merge remote-tracking branch 'origin/master'
klboke 587ce33
rge remote-tracking branch 'upstream/master'
klboke 9de6563
Merge remote-tracking branch 'upstream/master'
klboke 9aab632
Merge remote-tracking branch 'upstream/master'
klboke 050dd0a
Merge branch 'ctripcorp:master' into master
klboke 5a64035
Merge branch 'master' of github.com:klboke/apollo
klboke 0648fbd
Merge branch 'ctripcorp:master' into master
klboke 35bd3a6
Merge branch 'master' of github.com:klboke/apollo
klboke bc8149b
Merge branch 'ctripcorp:master' into master
klboke e771bdd
Merge branch 'master' of github.com:klboke/apollo
klboke 9a1ad83
Merge branch 'ctripcorp:master' into master
klboke 3efef37
Merge branch 'master' of github.com:klboke/apollo
klboke 1274281
Merge branch 'apolloconfig:master' into master
klboke a968932
Merge branch 'master' of github.com:klboke/apollo
klboke df8942c
Merge branch 'apolloconfig:master' into master
klboke f98175a
Merge branch 'master' of github.com:klboke/apollo
klboke 710cdd6
Merge branch 'apolloconfig:master' into master
klboke 3c162b6
Merge branch 'master' of github.com:klboke/apollo
klboke 0101a3f
Merge branch 'apolloconfig:master' into master
klboke cc6f568
Merge branch 'master' of github.com:klboke/apollo
klboke 21dd30c
Merge branch 'apolloconfig:master' into master
klboke c1eeb41
Merge branch 'master' of github.com:klboke/apollo
klboke e85d645
Merge branch 'apolloconfig:master' into master
klboke 8b0056d
Merge branch 'master' of github.com:klboke/apollo
klboke 347e07b
Merge branch 'apolloconfig:master' into master
klboke d8eb437
Merge branch 'master' of github.com:klboke/apollo
klboke 19bae52
Merge branch 'apolloconfig:master' into master
klboke 7e40fa1
Merge branch 'master' of github.com:klboke/apollo
klboke fbbb02d
Merge branch 'apolloconfig:master' into master
klboke 19cee24
Merge branch 'master' of github.com:klboke/apollo
klboke 91ba3b7
Merge branch 'apolloconfig:master' into master
klboke 94ad542
Merge branch 'master' of github.com:klboke/apollo
klboke 64e1b0b
Merge branch 'apolloconfig:master' into master
klboke 36ce5e2
Merge branch 'master' of github.com:klboke/apollo
klboke c1364c2
Merge branch 'apolloconfig:master' into master
klboke 76ed2ea
Merge branch 'master' of github.com:klboke/apollo
klboke db8cf3d
Merge branch 'apolloconfig:master' into master
klboke 3e4616d
Merge branch 'master' of github.com:klboke/apollo
klboke 47297cc
Merge branch 'apolloconfig:master' into master
klboke 1c320e7
Merge branch 'apolloconfig:master' into master
klboke e723db5
Merge branch 'master' of github.com:klboke/apollo
klboke 6be6a8b
Merge branch 'apolloconfig:master' into master
klboke 014657d
Merge branch 'apolloconfig:master' into master
klboke 370eec9
Merge branch 'master' of github.com:klboke/apollo
klboke dfa6c54
Merge branch 'apolloconfig:master' into master
klboke 1a66d08
Merge branch 'master' of github.com:klboke/apollo
klboke cb2c22e
Merge branch 'apolloconfig:master' into master
klboke 74af869
Merge branch 'master' of github.com:klboke/apollo
klboke a349f2e
Merge branch 'apolloconfig:master' into master
klboke 7238296
Merge branch 'master' of github.com:klboke/apollo
klboke c38d00d
Merge branch 'apolloconfig:master' into master
klboke 10cbbed
Merge branch 'master' of github.com:klboke/apollo
klboke 601e17b
Merge branch 'apolloconfig:master' into master
klboke 8fe2ce5
Merge branch 'master' of github.com:klboke/apollo
klboke 04ea7ff
Merge branch 'apolloconfig:master' into master
klboke cfe577c
Merge branch 'master' of github.com:klboke/apollo
klboke 4e9ba79
Merge branch 'apolloconfig:master' into master
klboke 53d033a
Merge branch 'master' of github.com:klboke/apollo
klboke 3789a6d
Merge branch 'apolloconfig:master' into master
klboke 2a1f3bc
Merge branch 'master' of github.com:klboke/apollo
klboke 0c7c63f
Merge branch 'apolloconfig:master' into master
klboke eaf3b3d
Merge branch 'master' of github.com:klboke/apollo
klboke 312abaa
Merge branch 'apolloconfig:master' into master
klboke f7c95f2
Merge branch 'master' of github.com:klboke/apollo
klboke 39cc719
Merge branch 'apolloconfig:master' into master
klboke e410062
Merge branch 'master' of github.com:klboke/apollo
klboke bb2bf94
Merge branch 'apolloconfig:master' into master
klboke 95cf566
Merge branch 'master' of github.com:klboke/apollo
klboke 0c10b9d
Merge branch 'apolloconfig:master' into master
klboke aa95cdd
Merge branch 'master' of github.com:klboke/apollo
klboke 3441587
Merge branch 'apolloconfig:master' into master
klboke a09b174
Merge branch 'master' of github.com:klboke/apollo
klboke 7f639da
refactor(apollo-biz): Refactor the createCommit method.
klboke 8f81034
refactor(apollo-biz): Add test cases related to ItemController.
klboke 9cb7426
refactor(apollo-biz): Add license
klboke 8419fca
Merge branch 'apolloconfig:master' into master
klboke d8d0664
Merge branch 'master' of github.com:klboke/apollo
klboke 113d9fb
refactor(apollo-biz): Refactor the createCommit method.
klboke b9e6f49
refactor(apollo-biz): Add test cases related to ItemController.
klboke f065b5c
refactor(apollo-biz): Add license
klboke 84bd232
refactor(apollo-biz): Optimize code formatting
klboke 92e9f70
Merge remote-tracking branch 'origin/commitservice' into commitservice
klboke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
153 changes: 153 additions & 0 deletions
153
.../src/test/java/com/ctrip/framework/apollo/adminservice/controller/ItemControllerTest.java
This file contains hidden or 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,153 @@ | ||
| /* | ||
| * Copyright 2023 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.adminservice.controller; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.ctrip.framework.apollo.biz.entity.Commit; | ||
| import com.ctrip.framework.apollo.biz.repository.CommitRepository; | ||
| import com.ctrip.framework.apollo.biz.repository.ItemRepository; | ||
| import com.ctrip.framework.apollo.common.dto.AppDTO; | ||
| import com.ctrip.framework.apollo.common.dto.ClusterDTO; | ||
| import com.ctrip.framework.apollo.common.dto.ItemDTO; | ||
| import com.ctrip.framework.apollo.common.dto.NamespaceDTO; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.data.domain.Pageable; | ||
| 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; | ||
|
|
||
| /** | ||
| * @author kl (http://kailing.pub) | ||
| * @since 2023/3/21 | ||
| */ | ||
| public class ItemControllerTest extends AbstractControllerTest { | ||
|
|
||
| @Autowired | ||
| private CommitRepository commitRepository; | ||
|
|
||
| @Autowired | ||
| private ItemRepository itemRepository; | ||
|
|
||
| @Test | ||
| @Sql(scripts = "/controller/test-itemset.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD) | ||
| @Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD) | ||
| public void testCreate() { | ||
| String appId = "someAppId"; | ||
| AppDTO app = restTemplate.getForObject(appBaseUrl(), AppDTO.class, appId); | ||
| assert app != null; | ||
| ClusterDTO cluster = restTemplate.getForObject(clusterBaseUrl(), ClusterDTO.class, app.getAppId(), "default"); | ||
| assert cluster != null; | ||
| NamespaceDTO namespace = restTemplate.getForObject(namespaceBaseUrl(), | ||
| NamespaceDTO.class, app.getAppId(), cluster.getName(), "application"); | ||
|
|
||
| String itemKey = "test-key"; | ||
| String itemValue = "test-value"; | ||
| ItemDTO item = new ItemDTO(itemKey, itemValue, "", 1); | ||
| assert namespace != null; | ||
| item.setNamespaceId(namespace.getId()); | ||
| item.setDataChangeLastModifiedBy("apollo"); | ||
|
|
||
| ResponseEntity<ItemDTO> response = restTemplate.postForEntity(itemBaseUrl(), | ||
| item, ItemDTO.class, app.getAppId(), cluster.getName(), namespace.getNamespaceName()); | ||
| Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
| Assert.assertEquals(itemKey, Objects.requireNonNull(response.getBody()).getKey()); | ||
|
|
||
| List<Commit> commitList = commitRepository.findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(app.getAppId(), cluster.getName(), namespace.getNamespaceName(), | ||
| Pageable.ofSize(10)); | ||
| Assert.assertEquals(1, commitList.size()); | ||
|
|
||
| Commit commit = commitList.get(0); | ||
| Assert.assertTrue(commit.getChangeSets().contains(itemKey)); | ||
| Assert.assertTrue(commit.getChangeSets().contains(itemValue)); | ||
| } | ||
|
|
||
| @Test | ||
| @Sql(scripts = "/controller/test-itemset.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD) | ||
| @Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD) | ||
| public void testUpdate() { | ||
| this.testCreate(); | ||
|
|
||
| String appId = "someAppId"; | ||
| AppDTO app = restTemplate.getForObject(appBaseUrl(), AppDTO.class, appId); | ||
| assert app != null; | ||
| ClusterDTO cluster = restTemplate.getForObject(clusterBaseUrl(), ClusterDTO.class, app.getAppId(), "default"); | ||
| assert cluster != null; | ||
| NamespaceDTO namespace = restTemplate.getForObject(namespaceBaseUrl(), | ||
| NamespaceDTO.class, app.getAppId(), cluster.getName(), "application"); | ||
|
|
||
| String itemKey = "test-key"; | ||
| String itemValue = "test-value-updated"; | ||
|
|
||
| long itemId = itemRepository.findByKey(itemKey, Pageable.ofSize(1)) | ||
| .getContent() | ||
| .get(0) | ||
| .getId(); | ||
| ItemDTO item = new ItemDTO(itemKey, itemValue, "", 1); | ||
| item.setDataChangeLastModifiedBy("apollo"); | ||
|
|
||
| String updateUrl = url( "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}"); | ||
| assert namespace != null; | ||
| restTemplate.put(updateUrl, item, app.getAppId(), cluster.getName(), namespace.getNamespaceName(), itemId); | ||
|
|
||
| itemRepository.findById(itemId).ifPresent(item1 -> { | ||
| assertThat(item1.getValue()).isEqualTo(itemValue); | ||
| assertThat(item1.getKey()).isEqualTo(itemKey); | ||
| }); | ||
|
|
||
| List<Commit> commitList = commitRepository.findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(app.getAppId(), cluster.getName(), namespace.getNamespaceName(), | ||
| Pageable.ofSize(10)); | ||
| assertThat(commitList).hasSize(2); | ||
| } | ||
|
|
||
| @Test | ||
| @Sql(scripts = "/controller/test-itemset.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD) | ||
| @Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD) | ||
| public void testDelete() { | ||
| this.testCreate(); | ||
|
|
||
| String appId = "someAppId"; | ||
| AppDTO app = restTemplate.getForObject(appBaseUrl(), AppDTO.class, appId); | ||
| assert app != null; | ||
| ClusterDTO cluster = restTemplate.getForObject(clusterBaseUrl(), ClusterDTO.class, app.getAppId(), "default"); | ||
| assert cluster != null; | ||
| NamespaceDTO namespace = restTemplate.getForObject(namespaceBaseUrl(), | ||
| NamespaceDTO.class, app.getAppId(), cluster.getName(), "application"); | ||
|
|
||
| String itemKey = "test-key"; | ||
|
|
||
| long itemId = itemRepository.findByKey(itemKey, Pageable.ofSize(1)) | ||
| .getContent() | ||
| .get(0) | ||
| .getId(); | ||
|
|
||
| String deleteUrl = url( "/items/{itemId}?operator=apollo"); | ||
| restTemplate.delete(deleteUrl, itemId); | ||
| assertThat(itemRepository.findById(itemId).isPresent()) | ||
| .isFalse(); | ||
|
|
||
| assert namespace != null; | ||
| List<Commit> commitList = commitRepository.findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(app.getAppId(), cluster.getName(), namespace.getNamespaceName(), | ||
| Pageable.ofSize(10)); | ||
| assertThat(commitList).hasSize(2); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.