本文整理汇总了Java中com.netflix.zuul.context.RequestContext.testSetCurrentContext方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.testSetCurrentContext方法的具体用法?Java RequestContext.testSetCurrentContext怎么用?Java RequestContext.testSetCurrentContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.zuul.context.RequestContext
的用法示例。
在下文中一共展示了RequestContext.testSetCurrentContext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldFilter
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void shouldFilter() {
RequestContext.testSetCurrentContext(new RequestContext());
when(request.getScheme()).thenReturn(SERVER_PROTOCOL);
when(request.getServerName()).thenReturn(SERVER_NAME);
when(request.getServerPort()).thenReturn(SERVER_PORT);
RequestContext.getCurrentContext().setRequest(request);
ZuulFilterResult result = filter.runFilter();
Assert.assertEquals(ExecutionStatus.SUCCESS, result.getStatus());
Assert.assertTrue(filter.shouldFilter());
Assert.assertEquals("pre", filter.filterType());
Assert.assertEquals(0, filter.filterOrder());
Assert.assertEquals(SERVER_PROTOCOL, RequestContext.getCurrentContext().getZuulRequestHeaders().get(
HEADER_SCHEME));
Assert.assertEquals(SERVER_NAME, RequestContext.getCurrentContext().getZuulRequestHeaders().get(HEADER_DOMAIN));
Assert.assertEquals(String.valueOf(SERVER_PORT), RequestContext.getCurrentContext().getZuulRequestHeaders().get(HEADER_PORT));
Assert.assertEquals(TENANT, RequestContext.getCurrentContext().getZuulRequestHeaders().get(HEADER_TENANT));
}
示例2: should_execute_all_checks_when_using_RateLimitConditionMatchingStrategy_All
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void should_execute_all_checks_when_using_RateLimitConditionMatchingStrategy_All() {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
RequestContext context = new RequestContext();
context.setRequest(request);
RequestContext.testSetCurrentContext(context);
when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
when(rateLimitCheck2.rateLimit(any())).thenReturn(consumptionProbe);
when(rateLimitCheck3.rateLimit(any())).thenReturn(consumptionProbe);
configuration.setStrategy(RateLimitConditionMatchingStrategy.ALL);
filter.run();
verify(rateLimitCheck1, times(1)).rateLimit(any());
verify(rateLimitCheck2, times(1)).rateLimit(any());
verify(rateLimitCheck3, times(1)).rateLimit(any());
}
示例3: should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST() {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
RequestContext context = new RequestContext();
context.setRequest(request);
RequestContext.testSetCurrentContext(context);
configuration.setStrategy(RateLimitConditionMatchingStrategy.FIRST);
when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
filter.run();
verify(rateLimitCheck1, times(1)).rateLimit(any());
verify(rateLimitCheck2, times(0)).rateLimit(any());
verify(rateLimitCheck3, times(0)).rateLimit(any());
}
示例4: should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
RequestContext context = new RequestContext();
context.setRequest(request);
RequestContext.testSetCurrentContext(context);
configuration.setStrategy(RateLimitConditionMatchingStrategy.FIRST);
when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
standaloneSetup(new TestController())
.addFilters(filter).build()
.perform(get(("/test")));
verify(rateLimitCheck1, times(1)).rateLimit(any());
verify(rateLimitCheck2, times(0)).rateLimit(any());
verify(rateLimitCheck3, times(0)).rateLimit(any());
}
示例5: shouldFilterThrow
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void shouldFilterThrow() {
RequestContext.testSetCurrentContext(new RequestContext());
when(request.getScheme()).thenReturn(SERVER_PROTOCOL);
when(request.getServerName()).thenReturn("NOMAPPING");
when(request.getServerPort()).thenReturn(SERVER_PORT);
RequestContext.getCurrentContext().setRequest(request);
ZuulFilterResult result = filter.runFilter();
Assert.assertEquals(ExecutionStatus.SUCCESS, result.getStatus());
Assert.assertEquals(TENANT, RequestContext.getCurrentContext().getZuulRequestHeaders().get(HEADER_TENANT));
}
示例6: testRun
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void testRun() {
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getMethod()).thenReturn("GET");
when(req.getRequestURL()).thenReturn(new StringBuffer("http://foo"));
RequestContext context = mock(RequestContext.class);
when(context.getRequest()).thenReturn(req);
RequestContext.testSetCurrentContext(context);
filter.run();
this.outputCapture.expect(Matchers.containsString("GET request to http://foo"));
}
示例7: setup
import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Before
public void setup() {
RequestContext.testSetCurrentContext(new RequestContext());
}