Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[#noissue] Apply ConditionalOnProperty to InstallModule #9884

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.navercorp.pinpoint.web.install;

import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDao;
import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDaoFactoryBean;
import com.navercorp.pinpoint.web.install.dao.GithubAgentDownloadInfoDao;
import com.navercorp.pinpoint.web.install.dao.MemoryAgentDownloadInfoDao;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;

/**
Expand All @@ -27,14 +29,19 @@ public InstallModule() {
}

@Bean
public FactoryBean<AgentDownloadInfoDao> agentDownloadInfoDao(
@ConditionalOnProperty(value = "pinpoint.modules.web.install.type", havingValue = "url")
public AgentDownloadInfoDao urlAgentDownloadInfoDao(
@Value("${web.installation.pinpointVersion:}") String version,
@Value("${web.installation.downloadUrl:}") String downloadUrl,
RestTemplate restTemplate) {
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
factoryBean.setVersion(version);
factoryBean.setDownloadUrl(downloadUrl);
factoryBean.setRestTemplate(restTemplate);
return factoryBean;
@Value("${web.installation.downloadUrl:}") String downloadUrl) {
Assert.hasLength(version, "version");
Assert.hasLength(downloadUrl, "downloadUrl");
return new MemoryAgentDownloadInfoDao(version, downloadUrl);

}

@Bean
@ConditionalOnProperty(value = "pinpoint.modules.web.install.type", havingValue = "github", matchIfMissing = true)
public AgentDownloadInfoDao githubAgentDownloadInfoDao(RestTemplate restTemplate) {
return new GithubAgentDownloadInfoDao(restTemplate);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GithubAgentDownloadInfoDao implements AgentDownloadInfoDao {

private static final Pattern STABLE_VERSION_PATTERN = Pattern.compile(IdValidateUtils.STABLE_VERSION_PATTERN_VALUE);
private static final ParameterizedTypeReference<List<GithubAgentDownloadInfo>> responseType
= new ParameterizedTypeReference<List<GithubAgentDownloadInfo>>() {};
= new ParameterizedTypeReference<>() {};

private final RestTemplate restTemplate;

Expand Down
5 changes: 4 additions & 1 deletion web/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ server:
include-binding-errors: always
include-stacktrace: always
whitelabel:
enabled: true
enabled: true

# github or url
pinpoint.modules.web.install.type: github
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.navercorp.pinpoint.common.util.BytesUtils;
import com.navercorp.pinpoint.common.util.IOUtils;
import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDao;
import com.navercorp.pinpoint.web.install.dao.AgentDownloadInfoDaoFactoryBean;
import com.navercorp.pinpoint.web.install.dao.GithubAgentDownloadInfoDao;
import com.navercorp.pinpoint.web.install.dao.MemoryAgentDownloadInfoDao;
import com.navercorp.pinpoint.web.install.model.GithubAgentDownloadInfo;
Expand All @@ -34,6 +33,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Taejin Koo
Expand All @@ -45,41 +45,31 @@ public class AgentDownloadInfoTest {
RestTemplate restTemplate = new RestTemplate();

@Test
void factoryTest1() throws Exception {
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
factoryBean.setVersion(version);
factoryBean.setDownloadUrl(downloadUrl);
factoryBean.setRestTemplate(restTemplate);
void factoryTest1() {
InstallModule module = new InstallModule();

AgentDownloadInfoDao dao = factoryBean.getObject();
AgentDownloadInfoDao dao = module.urlAgentDownloadInfoDao(version, downloadUrl);
assertThat(dao).isInstanceOf(MemoryAgentDownloadInfoDao.class);
assertEquals(version, dao.getDownloadInfoList().get(0).getVersion());
assertEquals(downloadUrl, dao.getDownloadInfoList().get(0).getDownloadUrl());
}

@Test
void factoryTest2() throws Exception {
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
factoryBean.setVersion(version);
factoryBean.setDownloadUrl("");
factoryBean.setRestTemplate(restTemplate);
void factoryTest2() {
InstallModule module = new InstallModule();

AgentDownloadInfoDao dao = factoryBean.getObject();
assertThat(dao).isInstanceOf(GithubAgentDownloadInfoDao.class);
assertThrows(IllegalArgumentException.class,
() -> module.urlAgentDownloadInfoDao(version, ""));
}

@Test
void factoryTest3() throws Exception {
AgentDownloadInfoDaoFactoryBean factoryBean = new AgentDownloadInfoDaoFactoryBean();
factoryBean.setVersion(" ");
factoryBean.setDownloadUrl(downloadUrl);
factoryBean.setRestTemplate(restTemplate);
void factoryTest3() {
InstallModule module = new InstallModule();

AgentDownloadInfoDao dao = factoryBean.getObject();
AgentDownloadInfoDao dao = module.githubAgentDownloadInfoDao(restTemplate);
assertThat(dao).isInstanceOf(GithubAgentDownloadInfoDao.class);
}


@Test
void defaultTest() throws Exception {
String mockResponseString = getMockJsonString();
Expand Down