Skip to content

Commit 99deca7

Browse files
committed
[#noissue] Apply ConditionalOnProperty to InstallModule
1 parent 00299d3 commit 99deca7

File tree

5 files changed

+33
-98
lines changed

5 files changed

+33
-98
lines changed

web/src/main/java/com/navercorp/pinpoint/web/install/InstallModule.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package com.navercorp.pinpoint.web.install;
22

33
import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDao;
4-
import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDaoFactoryBean;
4+
import com.navercorp.pinpoint.web.install.dao.GithubAgentDownloadInfoDao;
5+
import com.navercorp.pinpoint.web.install.dao.MemoryAgentDownloadInfoDao;
56
import org.apache.logging.log4j.LogManager;
67
import org.apache.logging.log4j.Logger;
7-
import org.springframework.beans.factory.FactoryBean;
88
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
910
import org.springframework.context.annotation.Bean;
1011
import org.springframework.context.annotation.ComponentScan;
1112
import org.springframework.context.annotation.Configuration;
13+
import org.springframework.util.Assert;
1214
import org.springframework.web.client.RestTemplate;
1315

1416
/**
@@ -27,14 +29,19 @@ public InstallModule() {
2729
}
2830

2931
@Bean
30-
public FactoryBean<AgentDownloadInfoDao> agentDownloadInfoDao(
32+
@ConditionalOnProperty(value = "pinpoint.modules.web.install.type", havingValue = "url")
33+
public AgentDownloadInfoDao urlAgentDownloadInfoDao(
3134
@Value("${web.installation.pinpointVersion:}") String version,
32-
@Value("${web.installation.downloadUrl:}") String downloadUrl,
33-
RestTemplate restTemplate) {
34-
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
35-
factoryBean.setVersion(version);
36-
factoryBean.setDownloadUrl(downloadUrl);
37-
factoryBean.setRestTemplate(restTemplate);
38-
return factoryBean;
35+
@Value("${web.installation.downloadUrl:}") String downloadUrl) {
36+
Assert.hasLength(version, "version");
37+
Assert.hasLength(downloadUrl, "downloadUrl");
38+
return new MemoryAgentDownloadInfoDao(version, downloadUrl);
39+
40+
}
41+
42+
@Bean
43+
@ConditionalOnProperty(value = "pinpoint.modules.web.install.type", havingValue = "github", matchIfMissing = true)
44+
public AgentDownloadInfoDao githubAgentDownloadInfoDao(RestTemplate restTemplate) {
45+
return new GithubAgentDownloadInfoDao(restTemplate);
3946
}
4047
}

web/src/main/java/com/navercorp/pinpoint/web/install/dao/AgentDownloadInfoDaoFactoryBean.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

web/src/main/java/com/navercorp/pinpoint/web/install/dao/GithubAgentDownloadInfoDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class GithubAgentDownloadInfoDao implements AgentDownloadInfoDao {
4242

4343
private static final Pattern STABLE_VERSION_PATTERN = Pattern.compile(IdValidateUtils.STABLE_VERSION_PATTERN_VALUE);
4444
private static final ParameterizedTypeReference<List<GithubAgentDownloadInfo>> responseType
45-
= new ParameterizedTypeReference<List<GithubAgentDownloadInfo>>() {};
45+
= new ParameterizedTypeReference<>() {};
4646

4747
private final RestTemplate restTemplate;
4848

web/src/main/resources/application.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ server:
1212
include-binding-errors: always
1313
include-stacktrace: always
1414
whitelabel:
15-
enabled: true
15+
enabled: true
16+
17+
# github or url
18+
pinpoint.modules.web.install.type: github

web/src/test/java/com/navercorp/pinpoint/web/install/AgentDownloadInfoTest.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.navercorp.pinpoint.common.util.BytesUtils;
2222
import com.navercorp.pinpoint.common.util.IOUtils;
2323
import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDao;
24-
import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDaoFactoryBean;
2524
import com.navercorp.pinpoint.web.install.dao.GithubAgentDownloadInfoDao;
2625
import com.navercorp.pinpoint.web.install.dao.MemoryAgentDownloadInfoDao;
2726
import com.navercorp.pinpoint.web.install.model.GithubAgentDownloadInfo;
@@ -34,6 +33,7 @@
3433

3534
import static org.assertj.core.api.Assertions.assertThat;
3635
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertThrows;
3737

3838
/**
3939
* @author Taejin Koo
@@ -45,41 +45,31 @@ public class AgentDownloadInfoTest {
4545
RestTemplate restTemplate = new RestTemplate();
4646

4747
@Test
48-
void factoryTest1() throws Exception {
49-
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
50-
factoryBean.setVersion(version);
51-
factoryBean.setDownloadUrl(downloadUrl);
52-
factoryBean.setRestTemplate(restTemplate);
48+
void factoryTest1() {
49+
InstallModule module = new InstallModule();
5350

54-
AgentDownloadInfoDao dao = factoryBean.getObject();
51+
AgentDownloadInfoDao dao = module.urlAgentDownloadInfoDao(version, downloadUrl);
5552
assertThat(dao).isInstanceOf(MemoryAgentDownloadInfoDao.class);
5653
assertEquals(version, dao.getDownloadInfoList().get(0).getVersion());
5754
assertEquals(downloadUrl, dao.getDownloadInfoList().get(0).getDownloadUrl());
5855
}
5956

6057
@Test
61-
void factoryTest2() throws Exception {
62-
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
63-
factoryBean.setVersion(version);
64-
factoryBean.setDownloadUrl("");
65-
factoryBean.setRestTemplate(restTemplate);
58+
void factoryTest2() {
59+
InstallModule module = new InstallModule();
6660

67-
AgentDownloadInfoDao dao = factoryBean.getObject();
68-
assertThat(dao).isInstanceOf(GithubAgentDownloadInfoDao.class);
61+
assertThrows(IllegalArgumentException.class,
62+
() -> module.urlAgentDownloadInfoDao(version, ""));
6963
}
7064

7165
@Test
72-
void factoryTest3() throws Exception {
73-
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
74-
factoryBean.setVersion(" ");
75-
factoryBean.setDownloadUrl(downloadUrl);
76-
factoryBean.setRestTemplate(restTemplate);
66+
void factoryTest3() {
67+
InstallModule module = new InstallModule();
7768

78-
AgentDownloadInfoDao dao = factoryBean.getObject();
69+
AgentDownloadInfoDao dao = module.githubAgentDownloadInfoDao(restTemplate);
7970
assertThat(dao).isInstanceOf(GithubAgentDownloadInfoDao.class);
8071
}
8172

82-
8373
@Test
8474
void defaultTest() throws Exception {
8575
String mockResponseString = getMockJsonString();

0 commit comments

Comments
 (0)