Skip to content

Commit

Permalink
Fixes on Smart Routes' unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
miere committed May 25, 2016
1 parent bf40ba4 commit 3cb33cb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
8 changes: 8 additions & 0 deletions kikaha-core/resources/META-INF/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ server:

redirect-to-http: true

# Undertow internals
undertow:
io-threads: -1
worker-threads: -1
Expand All @@ -40,13 +41,20 @@ server:
socket-options:
BACKLOG: 20000

# Static asset routing
static:
enabled: false
location: "webapp"

# Smart routes
routes:
rewrite:
reverse:
cors:
enabled: false
always-allow-origin: false
allowed-methods:
allowed-hosts:

auth:
fixed-auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CORSFilterModule implements Module {

@Override
public void load(Undertow.Builder server, DeploymentContext context) throws IOException {
if ( !config.getBoolean("server.cors.enabled") )
if ( !config.getBoolean("server.smart-routes.cors.enabled") )
return;

final CORSConfig corsConfig = loadCorsConfig();
Expand All @@ -44,9 +44,9 @@ public void load(Undertow.Builder server, DeploymentContext context) throws IOEx

CORSConfig loadCorsConfig(){
return new CORSConfig(
config.getBoolean("server.cors.always-allow-origin"),
asSet(config.getStringList("server.cors.allowed-methods")),
asMatcherSet(config.getStringList("server.cors.allowed-origins")));
config.getBoolean("server.smart-routes.cors.always-allow-origin"),
asSet(config.getStringList("server.smart-routes.cors.allowed-methods")),
asMatcherSet(config.getStringList("server.smart-routes.cors.allowed-origins")));
}

private static <T> Set<T> asSet( List<T> list ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package kikaha.core.modules.smart;

import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.inject.*;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.proxy.ProxyClient;
import io.undertow.server.handlers.proxy.ProxyHandler;
import io.undertow.server.handlers.proxy.*;
import kikaha.config.Config;
import kikaha.core.DeploymentContext;
import kikaha.core.modules.Module;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Getter
@Singleton
Expand All @@ -32,9 +29,9 @@ public class RewriteRoutesModule implements Module {

@PostConstruct
public void loadConfig(){
List<Config> configs = config.getConfigList("server.routes.rewrite");
List<Config> configs = config.getConfigList("server.smart-routes.rewrite");
rewriteRoutes = configs.stream().map( c->RewritableRule.from(c) ).collect(Collectors.toList());
configs = config.getConfigList("server.routes.reverse");
configs = config.getConfigList("server.smart-routes.reverse");
reverseRoutes = configs.stream().map( c->RewritableRule.from(c) ).collect(Collectors.toList());
}

Expand Down
12 changes: 11 additions & 1 deletion kikaha-core/tests-resources/conf/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ server:
static:
enabled: true

routes:
smart-routes:

cors:
enabled: true
always-allow-origin: false
allowed-origins:
- "http://localhost"
- "http://localhost:9000"
allowed-methods:
- "GET"

rewrite:
-
virtual-host: "test.localdomain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.junit.Assert.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
import static sizebay.plugin.plugin.CORSFilterHttpHandler.*;
import static kikaha.core.modules.smart.CORSFilterHttpHandler.*;
import java.net.URL;
import javax.inject.Inject;
import io.undertow.server.*;
Expand Down

0 comments on commit 3cb33cb

Please sign in to comment.