Skip to content
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

Simplify url assembly in test cases #4682

Merged
merged 69 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
fe75b4d
add tech-support-qq-4.png
klboke May 16, 2019
99bf97a
Update README.md
klboke May 16, 2019
1579f41
Merge remote-tracking branch 'upstream/master'
klboke Nov 11, 2020
9f65eed
Merge remote-tracking branch 'upstream/master'
klboke Dec 9, 2020
d7d3fd9
Enhance the user experience in the scenario of submitting duplicate keys
klboke Dec 11, 2020
7329fab
Merge branch 'master' into master
nobodyiam Dec 12, 2020
5def448
Modify the key-value conflict exception prompt, adjust the code style
klboke Dec 12, 2020
6942564
Merge branch 'master' into master
nobodyiam Dec 12, 2020
0fc1f91
Merge remote-tracking branch 'upstream/master'
klboke Dec 19, 2020
61ad016
Merge remote-tracking branch 'origin/master'
klboke Dec 19, 2020
587ce33
rge remote-tracking branch 'upstream/master'
klboke Mar 1, 2021
9de6563
Merge remote-tracking branch 'upstream/master'
klboke Mar 8, 2021
9aab632
Merge remote-tracking branch 'upstream/master'
klboke Mar 25, 2021
050dd0a
Merge branch 'ctripcorp:master' into master
klboke May 10, 2021
5a64035
Merge branch 'master' of github.com:klboke/apollo
klboke May 10, 2021
0648fbd
Merge branch 'ctripcorp:master' into master
klboke May 19, 2021
35bd3a6
Merge branch 'master' of github.com:klboke/apollo
klboke May 19, 2021
bc8149b
Merge branch 'ctripcorp:master' into master
klboke Jun 8, 2021
e771bdd
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 8, 2021
9a1ad83
Merge branch 'ctripcorp:master' into master
klboke Jun 25, 2021
3efef37
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 25, 2021
1274281
Merge branch 'apolloconfig:master' into master
klboke Sep 1, 2021
a968932
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 1, 2021
df8942c
Merge branch 'apolloconfig:master' into master
klboke Jan 7, 2022
f98175a
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 7, 2022
710cdd6
Merge branch 'apolloconfig:master' into master
klboke Feb 18, 2022
3c162b6
Merge branch 'master' of github.com:klboke/apollo
klboke Feb 18, 2022
0101a3f
Merge branch 'apolloconfig:master' into master
klboke Jun 17, 2022
cc6f568
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 17, 2022
21dd30c
Merge branch 'apolloconfig:master' into master
klboke Jun 21, 2022
c1eeb41
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 21, 2022
e85d645
Merge branch 'apolloconfig:master' into master
klboke Jun 27, 2022
8b0056d
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 27, 2022
347e07b
Merge branch 'apolloconfig:master' into master
klboke Jul 1, 2022
d8eb437
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 1, 2022
19bae52
Merge branch 'apolloconfig:master' into master
klboke Jul 4, 2022
7e40fa1
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 4, 2022
fbbb02d
Merge branch 'apolloconfig:master' into master
klboke Jul 6, 2022
19cee24
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 6, 2022
91ba3b7
Merge branch 'apolloconfig:master' into master
klboke Jul 8, 2022
94ad542
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 8, 2022
64e1b0b
Merge branch 'apolloconfig:master' into master
klboke Jul 19, 2022
36ce5e2
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 19, 2022
c1364c2
Merge branch 'apolloconfig:master' into master
klboke Jul 22, 2022
76ed2ea
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 22, 2022
db8cf3d
Merge branch 'apolloconfig:master' into master
klboke Jul 26, 2022
3e4616d
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 26, 2022
47297cc
Merge branch 'apolloconfig:master' into master
klboke Jul 30, 2022
1c320e7
Merge branch 'apolloconfig:master' into master
klboke Aug 2, 2022
e723db5
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 2, 2022
6be6a8b
Merge branch 'apolloconfig:master' into master
klboke Aug 8, 2022
014657d
Merge branch 'apolloconfig:master' into master
klboke Aug 12, 2022
370eec9
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 12, 2022
dfa6c54
Merge branch 'apolloconfig:master' into master
klboke Sep 8, 2022
1a66d08
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 8, 2022
cb2c22e
Merge branch 'apolloconfig:master' into master
klboke Sep 14, 2022
74af869
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 14, 2022
a349f2e
Merge branch 'apolloconfig:master' into master
klboke Sep 22, 2022
7238296
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 22, 2022
c38d00d
Merge branch 'apolloconfig:master' into master
klboke Oct 8, 2022
10cbbed
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 8, 2022
601e17b
Merge branch 'apolloconfig:master' into master
klboke Oct 11, 2022
8fe2ce5
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 11, 2022
04ea7ff
Merge branch 'apolloconfig:master' into master
klboke Dec 12, 2022
cfe577c
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 12, 2022
4e9ba79
Merge branch 'apolloconfig:master' into master
klboke Dec 15, 2022
53d033a
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 15, 2022
5c2b730
refactor(apollo-admin): Simplify url assembly in test cases
klboke Dec 15, 2022
6a52293
Merge branch 'master' into test
nobodyiam Dec 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ private void postConstruct() {
protected String url(String path) {
return "http://localhost:" + port + path;
}

protected String namespaceBaseUrl() {
return url("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}");
}

protected String appBaseUrl() {
return url("/apps/{appId}");
}

protected String clusterBaseUrl() {
return url("/apps/{appId}/clusters/{clusterName}");
}

protected String itemBaseUrl(){
return url("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AppControllerTest extends AbstractControllerTest {
AppRepository appRepository;

private String getBaseAppUrl() {
return "http://localhost:" + port + "/apps/";
return url("/apps/");
}

@Test
Expand Down Expand Up @@ -123,7 +123,7 @@ public void testDelete() {
App app = BeanUtils.transform(App.class, dto);
app = appRepository.save(app);

restTemplate.delete("http://localhost:{port}/apps/{appId}?operator={operator}", port, app.getAppId(), "test");
restTemplate.delete(url("/apps/{appId}?operator={operator}"), app.getAppId(), "test");

App deletedApp = appRepository.findById(app.getId()).orElse(null);
Assert.assertNull(deletedApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public void testCreate(){
dto.setComment(comment);
dto.setDataChangeCreatedBy("apollo");

AppNamespaceDTO resultDto = restTemplate.postForEntity(
String.format("http://localhost:%d/apps/%s/appnamespaces", port, appId),dto, AppNamespaceDTO.class).getBody();
AppNamespaceDTO resultDto = restTemplate.postForEntity(url("/apps/{appId}/appnamespaces"), dto, AppNamespaceDTO.class, appId).getBody();

Assert.assertNotNull(resultDto);
Assert.assertEquals(appId, resultDto.getAppId());
Assert.assertTrue(resultDto.getId() > 0);

Expand All @@ -54,9 +54,5 @@ public void testCreate(){
Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedTime());
Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedBy());
Assert.assertNotNull(savedAppNs.getDataChangeCreatedBy());




}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,23 @@
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;

import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.*;

public class ClusterControllerTest extends AbstractControllerTest {

@InjectMocks
private ClusterController clusterController;

@Mock
private ClusterService clusterService;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
clusterController = new ClusterController(clusterService);
}


@Test(expected = BadRequestException.class)
public void testDeleteDefaultFail() {
Cluster cluster = new Cluster();
Expand All @@ -68,22 +62,18 @@ public void shouldFailWhenRequestBodyInvalid() {
cluster.setAppId("valid");
cluster.setName("notBlank");
ResponseEntity<ClusterDTO> response =
restTemplate.postForEntity(baseUrl() + "/apps/{appId}/clusters", cluster, ClusterDTO.class, cluster.getAppId());
restTemplate.postForEntity(url("/apps/{appId}/clusters"), cluster, ClusterDTO.class, cluster.getAppId());
ClusterDTO createdCluster = response.getBody();
Assert.assertNotNull(createdCluster);
Assert.assertEquals(cluster.getAppId(), createdCluster.getAppId());
Assert.assertEquals(cluster.getName(), createdCluster.getName());

cluster.setName("invalid app name");
try {
restTemplate.postForEntity(baseUrl() + "/apps/{appId}/clusters", cluster, ClusterDTO.class, cluster.getAppId());
restTemplate.postForEntity(url("/apps/{appId}/clusters"), cluster, ClusterDTO.class, cluster.getAppId());
Assert.fail("Should throw");
} catch (HttpClientErrorException e) {
Assert.assertThat(new String(e.getResponseBodyAsByteArray()), containsString(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
}
}

private String baseUrl() {
return "http://localhost:" + port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.PageRequest;
Expand All @@ -40,6 +40,7 @@
@RunWith(MockitoJUnitRunner.class)
public class ControllerExceptionTest {

@InjectMocks
private AppController appController;

@Mock
Expand All @@ -48,11 +49,6 @@ public class ControllerExceptionTest {
@Mock
private AdminService adminService;

@Before
public void setUp() {
appController = new AppController(appService, adminService);
}

@Test(expected = NotFoundException.class)
public void testFindNotExists() {
when(appService.findOne(any(String.class))).thenReturn(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
Expand Down Expand Up @@ -57,8 +56,6 @@ public class ControllerIntegrationExceptionTest extends AbstractControllerTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);

realAdminService = ReflectionTestUtils.getField(appController, "adminService");

ReflectionTestUtils.setField(appController, "adminService", adminService);
Expand All @@ -69,10 +66,6 @@ public void tearDown() throws Exception {
ReflectionTestUtils.setField(appController, "adminService", realAdminService);
}

private String getBaseAppUrl() {
return "http://localhost:" + port + "/apps/";
}

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateFailed() {
Expand All @@ -81,7 +74,7 @@ public void testCreateFailed() {
when(adminService.createNewApp(any(App.class))).thenThrow(new RuntimeException("save failed"));

try {
restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
restTemplate.postForEntity(url("/apps/"), dto, AppDTO.class);
} catch (HttpStatusCodeException e) {
@SuppressWarnings("unchecked")
Map<String, String> attr = GSON.fromJson(e.getResponseBodyAsString(), Map.class);
Expand Down