This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 530bff5 [type:build] exclude the config files from admin.jar and
bootstrap.jar when packaging (#2409)
530bff5 is described below
commit 530bff5a0618062d3f253dab959785ce728d1f3c
Author: Zhang Yonglun <[email protected]>
AuthorDate: Fri Nov 19 10:40:51 2021 +0800
[type:build] exclude the config files from admin.jar and bootstrap.jar when
packaging (#2409)
* exclude the configurations from admin and bootstrap
* [type:build] exclude the config files from shenyu-admin.jar and
shenyu-bootstrap.jar when packaging
* [type:build] exclude the config files from shenyu-admin.jar and
shenyu-bootstrap.jar when packaging
* [type:build] exclude the config files from shenyu-admin.jar and
shenyu-bootstrap.jar when packaging
---
shenyu-admin/pom.xml | 9 ++
.../admin/exception/ExceptionHandlersTest.java | 17 +---
.../shenyu/admin/service/MetaDataServiceTest.java | 10 +-
.../admin/service/UpstreamCheckServiceTest.java | 19 +---
shenyu-admin/src/test/resources/application-h2.yml | 28 ++++++
shenyu-admin/src/test/resources/application.yml | 111 +++++++++++++++++++++
shenyu-bootstrap/pom.xml | 9 ++
7 files changed, 165 insertions(+), 38 deletions(-)
diff --git a/shenyu-admin/pom.xml b/shenyu-admin/pom.xml
index aec865b..b8f8b52 100644
--- a/shenyu-admin/pom.xml
+++ b/shenyu-admin/pom.xml
@@ -249,6 +249,15 @@
<build>
<finalName>shenyu-admin</finalName>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <excludes>
+ <exclude>*.yml</exclude>
+ <exclude>logback.xml</exclude>
+ </excludes>
+ </resource>
+ </resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java
index 448c151..210ec2f 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/exception/ExceptionHandlersTest.java
@@ -28,8 +28,8 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
+import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
@@ -48,9 +48,6 @@ import java.util.Set;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
@@ -59,7 +56,7 @@ import static org.mockito.Mockito.when;
/**
* Test case for {@link ExceptionHandlers}.
*/
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
@PrepareForTest(ExceptionHandlers.class)
public final class ExceptionHandlersTest {
@@ -89,7 +86,6 @@ public final class ExceptionHandlersTest {
@Test
public void testServerExceptionHandlerByException() {
Exception exception = new Exception();
- doNothing().when(loggerSpy).error(exception.getMessage(), exception);
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleExceptionHandler(exception);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
assertEquals(result.getMessage(), "The system is busy, please try
again later");
@@ -98,7 +94,6 @@ public final class ExceptionHandlersTest {
@Test
public void testServerExceptionHandlerByShenyuException() {
Exception shenyuException = new ShenyuException("Test shenyuException
message!");
- doNothing().when(loggerSpy).error(shenyuException.getMessage(),
shenyuException);
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleExceptionHandler(shenyuException);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
assertEquals(result.getMessage(), shenyuException.getMessage());
@@ -107,7 +102,6 @@ public final class ExceptionHandlersTest {
@Test
public void testServerExceptionHandlerByDuplicateKeyException() {
DuplicateKeyException duplicateKeyException = new
DuplicateKeyException("Test duplicateKeyException message!");
- doNothing().when(loggerSpy).error(anyString(),
eq(duplicateKeyException));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleDuplicateKeyException(duplicateKeyException);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
assertEquals(result.getMessage(),
ShenyuResultMessage.UNIQUE_INDEX_CONFLICT_ERROR);
@@ -116,7 +110,6 @@ public final class ExceptionHandlersTest {
@Test
public void testShiroExceptionHandler() {
UnauthorizedException unauthorizedException =
mock(UnauthorizedException.class);
- doNothing().when(loggerSpy).error(anyString(),
eq(unauthorizedException));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleUnauthorizedException(unauthorizedException);
assertEquals(result.getCode().intValue(),
CommonErrorCode.TOKEN_NO_PERMISSION);
assertEquals(result.getMessage(),
ShenyuResultMessage.TOKEN_HAS_NO_PERMISSION);
@@ -125,7 +118,6 @@ public final class ExceptionHandlersTest {
@Test
public void testNullPointExceptionHandler() {
NullPointerException nullPointerException =
mock(NullPointerException.class);
- doNothing().when(loggerSpy).error(anyString(),
eq(nullPointerException));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleNullPointException(nullPointerException);
assertEquals(result.getCode().intValue(),
CommonErrorCode.NOT_FOUND_EXCEPTION);
assertEquals(result.getMessage(),
ShenyuResultMessage.NOT_FOUND_EXCEPTION);
@@ -134,7 +126,6 @@ public final class ExceptionHandlersTest {
@Test
public void testHandleHttpRequestMethodNotSupportedException() {
HttpRequestMethodNotSupportedException exception =
mock(HttpRequestMethodNotSupportedException.class);
- doNothing().when(loggerSpy).warn(anyString(), eq(exception));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleHttpRequestMethodNotSupportedException(exception);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
assertThat(result.getMessage(), containsString("method is not
supported for this request. Supported methods are"));
@@ -147,7 +138,6 @@ public final class ExceptionHandlersTest {
when(exception.getBindingResult()).thenReturn(bindingResult);
List<FieldError> fieldErrors = mock(List.class);
when(bindingResult.getFieldErrors()).thenReturn(fieldErrors);
- doNothing().when(loggerSpy).warn(anyString(), eq(exception));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleMethodArgumentNotValidException(exception);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
assertThat(result.getMessage(), containsString("Request error! invalid
argument"));
@@ -156,7 +146,6 @@ public final class ExceptionHandlersTest {
@Test
public void testHandleMissingServletRequestParameterException() {
MissingServletRequestParameterException exception =
mock(MissingServletRequestParameterException.class);
- doNothing().when(loggerSpy).warn(anyString(), eq(exception));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleMissingServletRequestParameterException(exception);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
assertThat(result.getMessage(), containsString("parameter is
missing"));
@@ -167,7 +156,6 @@ public final class ExceptionHandlersTest {
MethodArgumentTypeMismatchException exception =
mock(MethodArgumentTypeMismatchException.class);
Class clazz = MethodArgumentTypeMismatchException.class;
when(exception.getRequiredType()).thenReturn(clazz);
- doNothing().when(loggerSpy).warn(anyString(), eq(exception));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleMethodArgumentTypeMismatchException(exception);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
assertThat(result.getMessage(), containsString("should be of type"));
@@ -178,7 +166,6 @@ public final class ExceptionHandlersTest {
ConstraintViolationException exception =
mock(ConstraintViolationException.class);
Set<ConstraintViolation<?>> violations = mock(Set.class);
when(exception.getConstraintViolations()).thenReturn(violations);
- doNothing().when(loggerSpy).warn(anyString(), eq(exception));
ShenyuAdminResult result =
exceptionHandlersUnderTest.handleConstraintViolationException(exception);
assertEquals(result.getCode().intValue(), CommonErrorCode.ERROR);
}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java
index dccfefb..0d662b9 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java
@@ -19,14 +19,14 @@ package org.apache.shenyu.admin.service;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.mapper.MetaDataMapper;
import org.apache.shenyu.admin.model.dto.MetaDataDTO;
import org.apache.shenyu.admin.model.entity.MetaDataDO;
-import org.apache.shenyu.admin.mapper.MetaDataMapper;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageParameter;
import org.apache.shenyu.admin.model.query.MetaDataQuery;
-import org.apache.shenyu.admin.service.impl.MetaDataServiceImpl;
import org.apache.shenyu.admin.model.vo.MetaDataVO;
+import org.apache.shenyu.admin.service.impl.MetaDataServiceImpl;
import org.apache.shenyu.common.constant.AdminConstants;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
@@ -38,8 +38,8 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
+import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
@@ -50,7 +50,6 @@ import java.util.Map;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
@@ -61,7 +60,7 @@ import static org.mockito.Mockito.when;
/**
* Test cases for MetaDataService.
*/
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
@PrepareForTest(MetaDataServiceImpl.class)
public final class MetaDataServiceTest {
@@ -111,7 +110,6 @@ public final class MetaDataServiceTest {
*/
@Test
public void testCreateOrUpdate() {
- doNothing().when(loggerSpy).error(anyString(), isA(MetaDataDTO.class));
testCreateOrUpdateForParamsError();
testCreateOrUpdateForPathExist();
testCreateOrUpdateForInsert();
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java
index fcd6bc7..e078f53 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java
@@ -41,8 +41,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
+import org.mockito.junit.MockitoJUnitRunner;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,8 +63,6 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.isNull;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -72,7 +70,7 @@ import static org.mockito.Mockito.when;
/**
* Test cases for UpstreamCheckService.
*/
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
@PrepareForTest(UpstreamCheckService.class)
public final class UpstreamCheckServiceTest {
@@ -138,8 +136,6 @@ public final class UpstreamCheckServiceTest {
@Test
public void testScheduled() {
- doNothing().when(loggerSpy).error(anyString(), isNull(Object.class));
-
PluginDO pluginDO = PluginDO.builder()
.name(PluginEnum.DIVIDE.getName())
.id(MOCK_PLUGIN_ID)
@@ -154,17 +150,6 @@ public final class UpstreamCheckServiceTest {
.name("UrlReachable")
.handle("[{\"upstreamHost\":\"localhost\",\"protocol\":\"http://\",\"localhost\":\"divide-upstream-60\",\"weight\":60}]")
.build();
-
- when(pluginMapper.selectById(anyString())).thenReturn(pluginDO);
- when(selectorMapper.selectByName(anyString())).then(invocationOnMock
-> {
- Object[] args = invocationOnMock.getArguments();
- if ("UrlError".equals(args[0])) {
- return selectorDOWithUrlError;
- } else if ("UrlReachable".equals(args[0])) {
- return selectorDOWithUrlReachable;
- }
- return null;
- });
try (MockedStatic<UpstreamCheckUtils> mocked =
mockStatic(UpstreamCheckUtils.class)) {
mocked.when(() -> UpstreamCheckUtils.checkUrl("ReachableUrl"))
.thenReturn(true);
diff --git a/shenyu-admin/src/test/resources/application-h2.yml
b/shenyu-admin/src/test/resources/application-h2.yml
new file mode 100644
index 0000000..4e4e6ac
--- /dev/null
+++ b/shenyu-admin/src/test/resources/application-h2.yml
@@ -0,0 +1,28 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+shenyu:
+ database:
+ dialect: h2
+ init_script: "sql-script/h2/schema.sql"
+ init_enable: true
+
+spring:
+ datasource:
+ url: jdbc:h2:mem:~/shenyu;DB_CLOSE_DELAY=-1;MODE=MySQL;
+ username: sa
+ password: sa
+ driver-class-name: org.h2.Driver
+
diff --git a/shenyu-admin/src/test/resources/application.yml
b/shenyu-admin/src/test/resources/application.yml
new file mode 100644
index 0000000..eb74da0
--- /dev/null
+++ b/shenyu-admin/src/test/resources/application.yml
@@ -0,0 +1,111 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+server:
+ port: 9095
+ address: 0.0.0.0
+
+spring:
+ profiles:
+ active: h2
+ thymeleaf:
+ cache: true
+ encoding: utf-8
+ enabled: true
+ prefix: classpath:/static/
+ suffix: .html
+
+mybatis:
+ config-location: classpath:/mybatis/mybatis-config.xml
+ mapper-locations: classpath:/mappers/*.xml
+
+shenyu:
+ register:
+ registerType: http #http #zookeeper #etcd #nacos #consul
+ serverLists: #localhost:2181 #http://localhost:2379 #localhost:8848
+ props:
+ sessionTimeout: 5000
+ connectionTimeout: 2000
+ checked: true
+ zombieCheckTimes: 5
+ scheduledTime: 10
+ nacosNameSpace: ShenyuRegisterCenter
+ sync:
+ websocket:
+ enabled: true
+# zookeeper:
+# url: localhost:2181
+# sessionTimeout: 5000
+# connectionTimeout: 2000
+# http:
+# enabled: true
+# nacos:
+# url: localhost:8848
+# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
+# username:
+# password:
+# acm:
+# enabled: false
+# endpoint: acm.aliyun.com
+# namespace:
+# accessKey:
+# secretKey:
+# etcd:
+# url: http://localhost:2379
+# consul:
+# url: http://localhost:8500
+ aes:
+ secret:
+ key: 2095132720951327
+ iv: 6075877187097700
+ ldap:
+ enabled: false
+ url: ldap://xxxx:xxx
+ bind-dn: cn=xxx,dc=xxx,dc=xxx
+ password: xxxx
+ base-dn: ou=xxx,dc=xxx,dc=xxx
+ object-class: person
+ login-field: cn
+ jwt:
+ expired-seconds: 86400000
+ shiro:
+ white-list:
+ - /
+ - /favicon.*
+ - /static/**
+ - /index**
+ - /plugin
+ - /platform/**
+ - /websocket
+ - /configs/**
+ - /shenyu-client/**
+ - /error
+ - /actuator/health
+ - /swagger-ui.html
+ - /webjars/**
+ - /swagger-resources/**
+ - /v2/api-docs
+ - /csrf
+ swagger:
+ enable: true
+
+logging:
+ level:
+ root: info
+ org.springframework.boot: info
+ org.apache.ibatis: info
+ org.apache.shenyu.bonuspoint: info
+ org.apache.shenyu.lottery: info
+ org.apache.shenyu: info
diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml
index 1a04312..7aff368 100644
--- a/shenyu-bootstrap/pom.xml
+++ b/shenyu-bootstrap/pom.xml
@@ -413,6 +413,15 @@
<build>
<finalName>shenyu-bootstrap</finalName>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <excludes>
+ <exclude>*.yml</exclude>
+ <exclude>logback.xml</exclude>
+ </excludes>
+ </resource>
+ </resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>