aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-01-28 07:49:38 -0800
committerAnton Tananaev <anton@traccar.org>2023-01-28 07:49:38 -0800
commit42cfe6de84f705971a638e5840d647a9e9c29c05 (patch)
tree6ead41dbfb76e2f69e7f201a709590aef7bffe49 /src
parent5a46718d48e2886d7bd37acd8c52f20c5c9e18bd (diff)
downloadtrackermap-server-42cfe6de84f705971a638e5840d647a9e9c29c05.tar.gz
trackermap-server-42cfe6de84f705971a638e5840d647a9e9c29c05.tar.bz2
trackermap-server-42cfe6de84f705971a638e5840d647a9e9c29c05.zip
Upgrade velocity engine
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/MainModule.java2
-rw-r--r--src/test/java/org/traccar/helper/ServletHelperTest.java48
2 files changed, 11 insertions, 39 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 55211d109..db66e9e5f 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -26,7 +26,6 @@ import com.google.inject.name.Names;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.log.NullLogChute;
import org.eclipse.jetty.util.URIUtil;
import org.traccar.broadcast.BroadcastService;
import org.traccar.broadcast.MulticastBroadcastService;
@@ -361,7 +360,6 @@ public class MainModule extends AbstractModule {
public static VelocityEngine provideVelocityEngine(Config config) {
Properties properties = new Properties();
properties.setProperty("file.resource.loader.path", config.getString(Keys.TEMPLATES_ROOT) + "/");
- properties.setProperty("runtime.log.logsystem.class", NullLogChute.class.getName());
if (config.hasKey(Keys.WEB_URL)) {
properties.setProperty("web.url", config.getString(Keys.WEB_URL).replaceAll("/$", ""));
diff --git a/src/test/java/org/traccar/helper/ServletHelperTest.java b/src/test/java/org/traccar/helper/ServletHelperTest.java
index e419b6491..55b96a41a 100644
--- a/src/test/java/org/traccar/helper/ServletHelperTest.java
+++ b/src/test/java/org/traccar/helper/ServletHelperTest.java
@@ -1,65 +1,39 @@
package org.traccar.helper;
-import org.apache.struts.mock.MockHttpServletRequest;
import org.junit.Test;
-import java.util.HashMap;
-import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class ServletHelperTest {
@Test
public void testRetrieveRemoteAddressProxyMultiple() {
- MockRequest request = new MockRequest();
- request.setRemoteAddress("147.120.1.5");
- request.addHeader("X-FORWARDED-FOR", "231.23.45.65, 10.20.10.33, 10.20.20.34");
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("147.120.1.5");
+ when(request.getHeader("X-FORWARDED-FOR")).thenReturn("231.23.45.65, 10.20.10.33, 10.20.20.34");
assertEquals("231.23.45.65", ServletHelper.retrieveRemoteAddress(request));
}
@Test
public void testRetrieveRemoteAddressProxySingle() {
- MockRequest request = new MockRequest();
- request.setRemoteAddress("147.120.1.5");
- request.addHeader("X-FORWARDED-FOR", "231.23.45.65");
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("147.120.1.5");
+ when(request.getHeader("X-FORWARDED-FOR")).thenReturn("231.23.45.65");
assertEquals("231.23.45.65", ServletHelper.retrieveRemoteAddress(request));
}
@Test
public void testRetrieveRemoteAddressNoProxy() {
- MockRequest request = new MockRequest();
- request.setRemoteAddress("231.23.45.65");
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getRemoteAddr()).thenReturn("231.23.45.65");
assertEquals("231.23.45.65", ServletHelper.retrieveRemoteAddress(request));
}
- private final static class MockRequest extends MockHttpServletRequest {
-
- private String remoteAddress;
-
- private Map<String, String> headers = new HashMap<>();
-
- public void setRemoteAddress(String remoteAddress) {
- this.remoteAddress = remoteAddress;
- }
-
- public void addHeader(String name, String value) {
- headers.put(name, value);
- }
-
- @Override
- public String getHeader(String name) {
- return headers.get(name);
- }
-
- @Override
- public String getRemoteAddr() {
- return remoteAddress;
- }
-
- }
-
}