From 19c58e07d329f48fbbdf6e1dc5217a6090485aac Mon Sep 17 00:00:00 2001 From: hanahmily Date: Wed, 28 Feb 2018 15:34:00 +0800 Subject: [PATCH] Add test case --- .travis.yml | 2 +- .../webapp/tools/RewritePathFilterTest.java | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/tools/RewritePathFilterTest.java diff --git a/.travis.yml b/.travis.yml index 84e4b1395..8b2c7b1d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,6 @@ before_install: install: - jdk_switcher use oraclejdk8 - - mvn clean install --quiet jacoco:report coveralls:report -X + - mvn clean install --quiet jacoco:report coveralls:report - mvn clean javadoc:javadoc -Dmaven.test.skip=true --quiet diff --git a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/tools/RewritePathFilterTest.java b/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/tools/RewritePathFilterTest.java new file mode 100644 index 000000000..b856fb608 --- /dev/null +++ b/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/tools/RewritePathFilterTest.java @@ -0,0 +1,60 @@ +/* + * 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. + * + */ + +package org.apache.skywalking.apm.webapp.tools; + +import com.netflix.zuul.context.RequestContext; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; +import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER; + +public class RewritePathFilterTest { + + private RewritePathFilter filter; + + @Before + public void init() { + filter = new RewritePathFilter("/graphql"); + } + + @Test + public void filterOrder() { + assertThat(filter.filterOrder(), is(PRE_DECORATION_FILTER_ORDER + 1)); + } + + @Test + public void filterType() { + assertThat(filter.filterType(), is("pre")); + } + + @Test + public void shouldFilter() { + assertFalse(filter.shouldFilter()); + RequestContext.getCurrentContext().set("requestURI"); + assertTrue(filter.shouldFilter()); + } + + @Test + public void run() { + filter.run(); + assertThat(RequestContext.getCurrentContext().get("requestURI"), is("/graphql")); + } +} \ No newline at end of file