Search in sources :

Example 1 with ShenyuContext

use of org.apache.shenyu.plugin.api.context.ShenyuContext in project incubator-shenyu by apache.

the class ApacheDubboPluginTest method skip.

@Test
public void skip() {
    final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("localhost").build());
    ShenyuContext context = mock(ShenyuContext.class);
    when(context.getRpcType()).thenReturn(RpcTypeEnum.DUBBO.getName());
    exchange.getAttributes().put(Constants.CONTEXT, context);
    exchange.getAttributes().put(Constants.META_DATA, metaData);
    final boolean result = apacheDubboPlugin.skip(exchange);
    assertFalse(result);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) ShenyuContext(org.apache.shenyu.plugin.api.context.ShenyuContext) Test(org.junit.jupiter.api.Test)

Example 2 with ShenyuContext

use of org.apache.shenyu.plugin.api.context.ShenyuContext in project incubator-shenyu by apache.

the class RpcParamTransformPluginTest method testSimpleBody.

/**
 * Test simple body.
 */
@Test
public void testSimpleBody() {
    ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("localhost").body("test"));
    Mockito.when(chain.execute(exchange)).thenReturn(Mono.empty());
    ShenyuContext context = new ShenyuContext();
    context.setRpcType(RpcTypeEnum.DUBBO.getName());
    exchange.getAttributes().put(Constants.CONTEXT, context);
    Mono<Void> result = rpcParamTransformPlugin.execute(exchange, chain);
    StepVerifier.create(result).expectSubscription().verifyComplete();
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) ShenyuContext(org.apache.shenyu.plugin.api.context.ShenyuContext) Test(org.junit.jupiter.api.Test)

Example 3 with ShenyuContext

use of org.apache.shenyu.plugin.api.context.ShenyuContext in project incubator-shenyu by apache.

the class AlibabaDubboPluginTest method testAlibabaDubboPlugin.

@Test
public void testAlibabaDubboPlugin() {
    final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("localhost").remoteAddress(new InetSocketAddress("127.0.0.1", 20880)).build());
    ShenyuContext context = mock(ShenyuContext.class);
    when(context.getRpcType()).thenReturn(RpcTypeEnum.DUBBO.getName());
    exchange.getAttributes().put(Constants.CONTEXT, context);
    exchange.getAttributes().put(Constants.META_DATA, metaData);
    ShenyuPluginChain chain = mock(ShenyuPluginChain.class);
    when(chain.execute(exchange)).thenReturn(Mono.empty());
    RuleData data = mock(RuleData.class);
    SelectorData selectorData = mock(SelectorData.class);
    Mono<Void> voidMono = alibabaDubboPluginUnderTest.doExecute(exchange, chain, selectorData, data);
    StepVerifier.create(voidMono).expectSubscription().verifyComplete();
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) RuleData(org.apache.shenyu.common.dto.RuleData) ShenyuContext(org.apache.shenyu.plugin.api.context.ShenyuContext) InetSocketAddress(java.net.InetSocketAddress) ShenyuPluginChain(org.apache.shenyu.plugin.api.ShenyuPluginChain) SelectorData(org.apache.shenyu.common.dto.SelectorData) Test(org.junit.jupiter.api.Test)

Example 4 with ShenyuContext

use of org.apache.shenyu.plugin.api.context.ShenyuContext in project incubator-shenyu by apache.

the class AlibabaDubboPluginTest method testAlibabaDubboPluginMetaDataNull.

@Test
public void testAlibabaDubboPluginMetaDataNull() {
    final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("localhost").remoteAddress(new InetSocketAddress("127.0.0.1", 20880)).build());
    ShenyuContext context = mock(ShenyuContext.class);
    when(context.getRpcType()).thenReturn(RpcTypeEnum.DUBBO.getName());
    exchange.getAttributes().put(Constants.CONTEXT, context);
    exchange.getAttributes().put(Constants.META_DATA, new MetaData());
    ShenyuPluginChain chain = mock(ShenyuPluginChain.class);
    when(chain.execute(exchange)).thenReturn(Mono.empty());
    RuleData data = mock(RuleData.class);
    SelectorData selectorData = mock(SelectorData.class);
    try (MockedStatic<ShenyuResultWrap> shenyuResultWrapMockedStatic = mockStatic(ShenyuResultWrap.class)) {
        shenyuResultWrapMockedStatic.when(() -> ShenyuResultWrap.error(exchange, ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM, null)).thenReturn(new Object());
        Mono<Void> voidMono = alibabaDubboPluginUnderTest.doExecute(exchange, chain, selectorData, data);
        StepVerifier.create(voidMono).expectSubscription().verifyComplete();
    }
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) RuleData(org.apache.shenyu.common.dto.RuleData) ShenyuContext(org.apache.shenyu.plugin.api.context.ShenyuContext) ShenyuResultWrap(org.apache.shenyu.plugin.api.result.ShenyuResultWrap) InetSocketAddress(java.net.InetSocketAddress) MetaData(org.apache.shenyu.common.dto.MetaData) ShenyuPluginChain(org.apache.shenyu.plugin.api.ShenyuPluginChain) SelectorData(org.apache.shenyu.common.dto.SelectorData) Test(org.junit.jupiter.api.Test)

Example 5 with ShenyuContext

use of org.apache.shenyu.plugin.api.context.ShenyuContext in project incubator-shenyu by apache.

the class AlibabaDubboPluginTest method testSkip.

@Test
public void testSkip() {
    final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("localhost").build());
    ShenyuContext context = mock(ShenyuContext.class);
    when(context.getRpcType()).thenReturn(RpcTypeEnum.DUBBO.getName());
    exchange.getAttributes().put(Constants.CONTEXT, context);
    exchange.getAttributes().put(Constants.META_DATA, metaData);
    final boolean result = alibabaDubboPluginUnderTest.skip(exchange);
    assertFalse(result);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) ShenyuContext(org.apache.shenyu.plugin.api.context.ShenyuContext) Test(org.junit.jupiter.api.Test)

Aggregations

ShenyuContext (org.apache.shenyu.plugin.api.context.ShenyuContext)61 Test (org.junit.jupiter.api.Test)27 ServerWebExchange (org.springframework.web.server.ServerWebExchange)22 SelectorData (org.apache.shenyu.common.dto.SelectorData)21 RuleData (org.apache.shenyu.common.dto.RuleData)19 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)17 ShenyuPluginChain (org.apache.shenyu.plugin.api.ShenyuPluginChain)15 InetSocketAddress (java.net.InetSocketAddress)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10 MetaData (org.apache.shenyu.common.dto.MetaData)9 Constants (org.apache.shenyu.common.constant.Constants)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Mono (reactor.core.publisher.Mono)6 StringUtils (org.apache.commons.lang3.StringUtils)5 RpcTypeEnum (org.apache.shenyu.common.enums.RpcTypeEnum)5 ShenyuResultWrap (org.apache.shenyu.plugin.api.result.ShenyuResultWrap)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 HttpStatus (org.springframework.http.HttpStatus)5 URI (java.net.URI)4