Skip to content

Commit

Permalink
[#noissue] Apply ConditionalOnProperty to InstallModule
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Apr 20, 2023
1 parent 00299d3 commit bd2a24e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 98 deletions.
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

0 comments on commit bd2a24e

Please # to comment.