This is an automated email from the ASF dual-hosted git repository. xiangying pushed a commit to branch branch-0.5.0 in repository https://gitbox.apache.org/repos/asf/pulsar-manager.git
commit 7b56ca816828fc4f4827450ea80155a029a824f2 Author: Jonas Geiregat <jonasgeire...@users.noreply.github.com> AuthorDate: Fri Feb 16 23:38:34 2024 +0100 chore: upgrade gradle,java and spring-boot (#546) * chore: upgrade gradle,java and spring-boot Bumped gradle to 8.5 Bumped spring-boot to 2.5.3 Removed useless BookiesServiceImplTest that was not asserting anything. Removed static nature of HttpUtils to make it injectable and better testable (favor Mockito over staticly mocking things using Powermock). * test: revert page helper version Turned out newer versions of page helper do not work zero indexed but rather use one as the first page. * test: fix flaky DashboardServiceImplTest Removed unnecessary mocking of httpUtil. The id generation is not always deterministic when saving an entity. Therefore, I opted to let the test code use the id returned by the save method instead of relying on a deterministic value. Enabled distTar again by replacing the deprecated property by the new one. * fix: make getTopicsStatsImplTest deterministic --------- Co-authored-by: JonasG <jonas.geire...@sabam.be> (cherry picked from commit 9e34505419bcbff212b506fe208be1f0cb486e96) --- build.gradle | 11 ++-- gradle.properties | 10 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- .../pulsar/manager/EmbeddedTomcatCustomizer.java | 2 +- .../manager/service/impl/BookiesServiceImpl.java | 19 ++++-- .../org/apache/pulsar/manager/utils/HttpUtil.java | 8 +-- .../manager/service/BookiesServiceImplTest.java | 76 ---------------------- .../manager/service/DashboardServiceImplTest.java | 66 ++++++++----------- .../manager/service/PulsarEventImplTest.java | 12 ++-- .../manager/service/TopicsServiceImplTest.java | 2 +- .../manager/service/UsersServiceImplTest.java | 28 ++------ .../service/impl/BrokerTokensServiceImplTest.java | 15 ++--- src/test/resources/application-test.properties | 15 +++++ 13 files changed, 84 insertions(+), 182 deletions(-) diff --git a/build.gradle b/build.gradle index af81b41..2a65e8f 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { ext { - springBootVersion = '2.0.2.RELEASE' + springBootVersion = '2.5.3' } repositories { mavenCentral() @@ -72,12 +72,13 @@ task incrementVersion { dependencyManagement { imports { mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES - mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.SR2' + mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.6' } applyMavenExclusions = false } distributions { + main { contents { from 'src/main/resources/application.properties' @@ -87,7 +88,7 @@ distributions { } distTar { - archiveName "pulsar-manager.tar" + archiveFileName = "pulsar-manager.tar" } jar { @@ -108,7 +109,7 @@ dependencies { implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: springBootVersion implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion - implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-zuul', version: springBootVersion + implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-zuul', version: '2.2.10.RELEASE' implementation group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: springMybatisVersion implementation group: 'com.github.pagehelper', name: 'pagehelper', version: pagehelperVersion implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: springBootVersion @@ -152,8 +153,6 @@ dependencies { compileOnly group: 'org.springframework.boot', name: 'spring-boot-devtools', version: springBootVersion testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion - testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: apiMockitoVersion - testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: mockitoJunit4Version constraints { implementation("org.bouncycastle:bcprov-jdk15on:${bouncycastleVersion}") diff --git a/gradle.properties b/gradle.properties index cb0710d..ede35b6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,19 +6,17 @@ hibernateValidatorVersion=6.0.13.Final jsonWebTokenVersion=0.9.0 jsonWebTokenApiVersion=0.10.5 jsonWebTokenImplVersion=0.10.5 -lombokVersion=1.18.26 -pageHelperVersion=1.2.4 -mockitoVersion=2.8.47 +lombokVersion=1.18.30 +pageHelperVersion=2.1.0 +mockitoVersion=3.11.2 guavaVersion=21.0 pulsarVersion=2.7.0 athenzVersion=1.10.9 swagger2Version=2.9.2 swaggeruiVersion=2.9.2 -apiMockitoVersion=1.7.1 -mockitoJunit4Version=1.7.1 gsonVersion=2.8.2 postgresqlVersion=42.2.5 -herddbVersion=0.24.0 +herddbVersion=0.28.0 commonsValidatorVersion=1.6 bkvmVersion=3.1.1 tomcatVersion=8.5.31 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8049c68..a595206 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/org/apache/pulsar/manager/EmbeddedTomcatCustomizer.java b/src/main/java/org/apache/pulsar/manager/EmbeddedTomcatCustomizer.java index e262c97..0032906 100644 --- a/src/main/java/org/apache/pulsar/manager/EmbeddedTomcatCustomizer.java +++ b/src/main/java/org/apache/pulsar/manager/EmbeddedTomcatCustomizer.java @@ -93,7 +93,7 @@ public class EmbeddedTomcatCustomizer implements } } return super.getTomcatWebServer(tomcat); - } catch (IOException | ServletException ex) { + } catch (IOException ex) { throw new RuntimeException(ex); } } diff --git a/src/main/java/org/apache/pulsar/manager/service/impl/BookiesServiceImpl.java b/src/main/java/org/apache/pulsar/manager/service/impl/BookiesServiceImpl.java index e1dcacf..5430fc2 100644 --- a/src/main/java/org/apache/pulsar/manager/service/impl/BookiesServiceImpl.java +++ b/src/main/java/org/apache/pulsar/manager/service/impl/BookiesServiceImpl.java @@ -20,6 +20,8 @@ import org.apache.pulsar.manager.service.BookiesService; import org.apache.pulsar.manager.service.EnvironmentCacheService; import org.apache.pulsar.manager.utils.HttpUtil; import org.apache.commons.lang3.StringUtils; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -49,6 +51,9 @@ public class BookiesServiceImpl implements BookiesService { @Value("${backend.jwt.token}") private static String pulsarJwtToken; + @Autowired + HttpUtil httpUtil; + private static final Map<String, String> header = new HashMap<String, String>(){{ put("Authorization", String.format("Bearer %s", pulsarJwtToken)); @@ -76,15 +81,15 @@ public class BookiesServiceImpl implements BookiesService { if(StringUtils.isBlank(bookieUrl)){ return bookiesMap; } - String rwBookieList = HttpUtil.doGet( + String rwBookieList = httpUtil.doGet( bookieUrl + "/api/v1/bookie/list_bookies?type=rw&print_hostnames=true", header); Map<String, String> rwBookies = gson.fromJson( rwBookieList, new TypeToken<Map<String, String>>() {}.getType()); - String roBookieList = HttpUtil.doGet( + String roBookieList = httpUtil.doGet( bookieUrl + "/api/v1/bookie/list_bookies?type=ro&print_hostnames=true", header); Map<String, String> roBookies = gson.fromJson( roBookieList, new TypeToken<Map<String, String>>() {}.getType()); - String listBookieInfo = HttpUtil.doGet( + String listBookieInfo = httpUtil.doGet( bookieUrl + "/api/v1/bookie/list_bookie_info", header); Map<String, String> listBookies = gson.fromJson( listBookieInfo, new TypeToken<Map<String, String>>() {}.getType()); @@ -122,13 +127,13 @@ public class BookiesServiceImpl implements BookiesService { public String forwardBookiesHeartbeat(String bookie) { bookie = checkBookie(bookie); - return HttpUtil.doGet(bookie + "/heartbeat", header); + return httpUtil.doGet(bookie + "/heartbeat", header); } public void forwardGc(String bookie) { bookie = checkBookie(bookie); try { - HttpUtil.doPut(bookie + "/api/v1/bookie/gc", header, ""); + httpUtil.doPut(bookie + "/api/v1/bookie/gc", header, ""); } catch (UnsupportedEncodingException e) { } @@ -141,7 +146,7 @@ public class BookiesServiceImpl implements BookiesService { Map<String, Object> body = Maps.newHashMap(); body.put("bookie_src", bookieSrc); body.put("bookie_dest", bookieDest); - HttpUtil.doPut(bookieUrl + "/api/v1/autorecovery/bookie/", header, gson.toJson(body)); + httpUtil.doPut(bookieUrl + "/api/v1/autorecovery/bookie/", header, gson.toJson(body)); } catch (UnsupportedEncodingException e) { } @@ -153,7 +158,7 @@ public class BookiesServiceImpl implements BookiesService { body.put("bookie_src", bookie); try { Gson gson = new Gson(); - HttpUtil.doPut(bookie + "/api/v1/autorecovery/decommission", header, gson.toJson(body)); + httpUtil.doPut(bookie + "/api/v1/autorecovery/decommission", header, gson.toJson(body)); } catch (UnsupportedEncodingException e) { } diff --git a/src/main/java/org/apache/pulsar/manager/utils/HttpUtil.java b/src/main/java/org/apache/pulsar/manager/utils/HttpUtil.java index c45662c..248ad94 100644 --- a/src/main/java/org/apache/pulsar/manager/utils/HttpUtil.java +++ b/src/main/java/org/apache/pulsar/manager/utils/HttpUtil.java @@ -130,7 +130,7 @@ public class HttpUtil { } } - public static String doGet(String url, Map<String, String> header){ + public String doGet(String url, Map<String, String> header){ HttpGet request = new HttpGet(url); return httpRequest(request, header); } @@ -143,21 +143,21 @@ public class HttpUtil { * @return HTTP response information * @throws UnsupportedEncodingException */ - public static String doPost(String url, Map<String, String> header, String body) + public String doPost(String url, Map<String, String> header, String body) throws UnsupportedEncodingException { HttpPost request = new HttpPost(url); request.setEntity(new StringEntity(body)); return httpRequest(request, header); } - public static String doPut(String url, Map<String, String> header, String body) + public String doPut(String url, Map<String, String> header, String body) throws UnsupportedEncodingException { HttpPut request = new HttpPut(url); request.setEntity(new StringEntity(body)); return httpRequest(request, header); } - public static String httpRequest(HttpUriRequest request, Map<String, String> header) { + public String httpRequest(HttpUriRequest request, Map<String, String> header) { CloseableHttpResponse response = null; try { for (Map.Entry<String, String> entry: header.entrySet()) { diff --git a/src/test/java/org/apache/pulsar/manager/service/BookiesServiceImplTest.java b/src/test/java/org/apache/pulsar/manager/service/BookiesServiceImplTest.java deleted file mode 100644 index f814300..0000000 --- a/src/test/java/org/apache/pulsar/manager/service/BookiesServiceImplTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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 org.apache.pulsar.manager.service; - -import com.google.common.collect.Maps; -import org.apache.commons.lang3.StringUtils; -import org.apache.pulsar.manager.PulsarManagerApplication; -import org.apache.pulsar.manager.profiles.HerdDBTestProfile; -import org.apache.pulsar.manager.utils.HttpUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Map; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore( {"javax.*", "sun.*", "com.sun.*", "org.xml.*", "org.w3c.*"}) -@PrepareForTest(HttpUtil.class) -@TestPropertySource(locations= "classpath:test-bookie.properties") -@SpringBootTest( - classes = { - PulsarManagerApplication.class, - HerdDBTestProfile.class - } -) -@ActiveProfiles("test") -public class BookiesServiceImplTest { - - @Autowired - private EnvironmentCacheService environmentCacheService; - @Autowired - private BookiesService bookiesService ; - - @Value("${backend.jwt.token}") - private static String pulsarJwtToken; - - @Test - public void bookiesServiceTest() { - PowerMockito.mockStatic(HttpUtil.class); - Map<String, String> header = Maps.newHashMap(); - header.put("Content-Type", "application/json"); - if (StringUtils.isNotBlank(pulsarJwtToken)) { - header.put("Authorization", String.format("Bearer %s", pulsarJwtToken)); - } - PowerMockito.when(HttpUtil.doGet("http://localhost:8050/api/v1/bookie/list_bookies?type=rw&print_hostnames=true", header)) - .thenReturn("{\"192.168.2.116:3181\" : \"192.168.2.116\"}"); - PowerMockito.when(HttpUtil.doGet("http://localhost:8080/admin/v2/brokers/standalone", header)) - .thenReturn("{ }"); - PowerMockito.when(HttpUtil.doGet("http://localhost:8050/api/v1/bookie/list_bookie_info", header)) - .thenReturn("{\"192.168.2.116:3181\" : \": {Free: 48920571904(48.92GB), Total: 250790436864(250.79GB)}," + - "\",\"ClusterInfo: \" : \"{Free: 48920571904(48.92GB), Total: 250790436864(250.79GB)}\" }"); - HttpUtil.doGet("http://localhost:8080/admin/v2/brokers/standalone", header); - } -} diff --git a/src/test/java/org/apache/pulsar/manager/service/DashboardServiceImplTest.java b/src/test/java/org/apache/pulsar/manager/service/DashboardServiceImplTest.java index c9f7d20..02bc56a 100644 --- a/src/test/java/org/apache/pulsar/manager/service/DashboardServiceImplTest.java +++ b/src/test/java/org/apache/pulsar/manager/service/DashboardServiceImplTest.java @@ -13,41 +13,41 @@ */ package org.apache.pulsar.manager.service; -import com.google.common.collect.Maps; -import org.apache.commons.lang3.StringUtils; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + import org.apache.pulsar.manager.PulsarManagerApplication; -import org.apache.pulsar.manager.entity.*; +import org.apache.pulsar.manager.entity.ConsumerStatsEntity; +import org.apache.pulsar.manager.entity.ConsumersStatsRepository; +import org.apache.pulsar.manager.entity.NamespaceEntity; +import org.apache.pulsar.manager.entity.NamespacesRepository; +import org.apache.pulsar.manager.entity.TenantEntity; +import org.apache.pulsar.manager.entity.TenantsRepository; +import org.apache.pulsar.manager.entity.TopicStatsEntity; +import org.apache.pulsar.manager.entity.TopicsStatsRepository; import org.apache.pulsar.manager.profiles.HerdDBTestProfile; import org.apache.pulsar.manager.utils.HttpUtil; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore( {"javax.*", "sun.*", "com.sun.*", "org.xml.*", "org.w3c.*"}) -@PrepareForTest(HttpUtil.class) -@TestPropertySource(locations= "classpath:test-bookie.properties") +@RunWith(SpringRunner.class) +@TestPropertySource(locations = "classpath:test-bookie.properties") @SpringBootTest( - classes = { - PulsarManagerApplication.class, - HerdDBTestProfile.class - } + classes = { + PulsarManagerApplication.class, + HerdDBTestProfile.class + } ) @ActiveProfiles("test") public class DashboardServiceImplTest { @@ -67,8 +67,9 @@ public class DashboardServiceImplTest { @Autowired NamespacesRepository namespacesRepository; - @Value("${backend.jwt.token}") - private static String pulsarJwtToken; + @MockBean + HttpUtil httpUtil; + @Test public void getDashboardStatsTest() { @@ -81,21 +82,7 @@ public class DashboardServiceImplTest { int producerPerTopic = 1; int consumerPerTopic = 1; - PowerMockito.mockStatic(HttpUtil.class); - Map<String, String> header = Maps.newHashMap(); - header.put("Content-Type", "application/json"); - if (StringUtils.isNotBlank(pulsarJwtToken)) { - header.put("Authorization", String.format("Bearer %s", pulsarJwtToken)); - } - PowerMockito.when(HttpUtil.doGet("http://localhost:8050/api/v1/bookie/list_bookies?type=rw&print_hostnames=true", header)) - .thenReturn("{\"192.168.2.116:3181\" : \"192.168.2.116\"}"); - PowerMockito.when(HttpUtil.doGet("http://localhost:8080/admin/v2/brokers/standalone", header)) - .thenReturn("{ }"); - PowerMockito.when(HttpUtil.doGet("http://localhost:8050/api/v1/bookie/list_bookie_info", header)) - .thenReturn("{\"192.168.2.116:3181\" : \": {Free: 48920571904(48.92GB), Total: 250790436864(250.79GB)}," + - "\",\"ClusterInfo: \" : \"{Free: 48920571904(48.92GB), Total: 250790436864(250.79GB)}\" }"); - - long topicStatsId = 0L; + long topicStatsId; for (String tenant: tenantList) { TenantEntity tenantEntity = new TenantEntity(); tenantEntity.setEnvironmentName(environmentList.get(0)); @@ -123,14 +110,14 @@ public class DashboardServiceImplTest { topicStatsEntity.setTopic("neutral"); topicStatsEntity.setProducerCount(producerPerTopic); topicStatsEntity.setTime_stamp(timestamp); - topicsStatsRepository.save(topicStatsEntity); - topicStatsId++; + topicStatsId = topicsStatsRepository.save(topicStatsEntity); for (int i = 0; i < consumerPerTopic; i++) { ConsumerStatsEntity consumerStatsEntity = new ConsumerStatsEntity(); consumerStatsEntity.setConsumer("neutral"); consumerStatsEntity.setTopicStatsId(topicStatsId); consumerStatsEntity.setTime_stamp(timestamp); consumersStatsRepository.save(consumerStatsEntity); + System.out.println("2 saves, TS " + timestamp); } } } @@ -138,6 +125,7 @@ public class DashboardServiceImplTest { } long topicCount = clusterList.size() * brokerList.size(); + System.out.println("searching for env " + environmentList.get(0)); Map<String, Object> dashboardStats = dashboardService.getDashboardStats(Arrays.asList(environmentList.get(0))); Assert.assertEquals(clusterList.size(), dashboardStats.get("totalClusterCount")); Assert.assertEquals(brokerList.size(), dashboardStats.get("totalBrokerCount")); diff --git a/src/test/java/org/apache/pulsar/manager/service/PulsarEventImplTest.java b/src/test/java/org/apache/pulsar/manager/service/PulsarEventImplTest.java index 1914183..944dcac 100644 --- a/src/test/java/org/apache/pulsar/manager/service/PulsarEventImplTest.java +++ b/src/test/java/org/apache/pulsar/manager/service/PulsarEventImplTest.java @@ -13,6 +13,8 @@ */ package org.apache.pulsar.manager.service; +import java.util.Optional; + import org.apache.pulsar.manager.PulsarManagerApplication; import org.apache.pulsar.manager.entity.NamespaceEntity; import org.apache.pulsar.manager.entity.NamespacesRepository; @@ -20,21 +22,15 @@ import org.apache.pulsar.manager.profiles.HerdDBTestProfile; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import java.util.Optional; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore( {"javax.*", "sun.*", "com.sun.*", "org.xml.*", "org.w3c.*"}) +@RunWith(SpringRunner.class) @SpringBootTest( classes = { PulsarManagerApplication.class, diff --git a/src/test/java/org/apache/pulsar/manager/service/TopicsServiceImplTest.java b/src/test/java/org/apache/pulsar/manager/service/TopicsServiceImplTest.java index bdeef37..ad147b9 100644 --- a/src/test/java/org/apache/pulsar/manager/service/TopicsServiceImplTest.java +++ b/src/test/java/org/apache/pulsar/manager/service/TopicsServiceImplTest.java @@ -91,7 +91,7 @@ public class TopicsServiceImplTest { @Test public void getTopicsStatsImplTest() throws Exception { - String environment = "staging"; + String environment = "topic-stats-test-environment"; String tenant = "public"; String namespace = "functions"; String topic = "metadata"; diff --git a/src/test/java/org/apache/pulsar/manager/service/UsersServiceImplTest.java b/src/test/java/org/apache/pulsar/manager/service/UsersServiceImplTest.java index 460c4ba..c811926 100644 --- a/src/test/java/org/apache/pulsar/manager/service/UsersServiceImplTest.java +++ b/src/test/java/org/apache/pulsar/manager/service/UsersServiceImplTest.java @@ -13,36 +13,16 @@ */ package org.apache.pulsar.manager.service; -import org.apache.pulsar.manager.PulsarManagerApplication; +import java.util.Map; + import org.apache.pulsar.manager.entity.UserInfoEntity; -import org.apache.pulsar.manager.profiles.HerdDBTestProfile; +import org.apache.pulsar.manager.service.impl.UsersServiceImpl; import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Map; -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore( {"javax.*", "sun.*", "com.sun.*", "org.xml.*", "org.w3c.*"}) -@SpringBootTest( - classes = { - PulsarManagerApplication.class, - HerdDBTestProfile.class - } -) -@ActiveProfiles("test") public class UsersServiceImplTest { - @Autowired - private UsersService usersService; + private UsersService usersService = new UsersServiceImpl(); @Test public void validateUserInfoTest() { diff --git a/src/test/java/org/apache/pulsar/manager/service/impl/BrokerTokensServiceImplTest.java b/src/test/java/org/apache/pulsar/manager/service/impl/BrokerTokensServiceImplTest.java index 3b936fc..2e89a26 100644 --- a/src/test/java/org/apache/pulsar/manager/service/impl/BrokerTokensServiceImplTest.java +++ b/src/test/java/org/apache/pulsar/manager/service/impl/BrokerTokensServiceImplTest.java @@ -13,29 +13,26 @@ */ package org.apache.pulsar.manager.service.impl; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.Jwt; -import io.jsonwebtoken.Jwts; import org.apache.pulsar.manager.PulsarManagerApplication; import org.apache.pulsar.manager.profiles.HerdDBTestProfile; import org.apache.pulsar.manager.service.impl.JwtServiceImpl; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwt; +import io.jsonwebtoken.Jwts; + import java.security.Key; -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore( {"javax.*", "sun.*", "com.sun.*", "org.xml.*", "org.w3c.*"}) +@RunWith(SpringRunner.class) @TestPropertySource( properties = { "jwt.broker.token.mode=SECRET", diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties new file mode 100644 index 0000000..cae3fcb --- /dev/null +++ b/src/test/resources/application-test.properties @@ -0,0 +1,15 @@ +# +# 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. +# + +spring.main.allow-bean-definition-overriding=true