Java 类org.glassfish.jersey.server.spi.RequestScopedInitializer 实例源码

项目:jrestless    文件:ServiceRequestHandlerTest.java   
@SuppressWarnings("unchecked")
@Test
public void delegateRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() {
    Context context = mock(Context.class);
    DefaultServiceRequest request = new DefaultServiceRequest(null, new HashMap<>(), URI.create("/"), "GET");

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request);

    Ref<ServiceRequest> serviceRequestRef = mock(Ref.class);
    Ref<Context> contextRef = mock(Ref.class);

    InjectionManager injectionManager = mock(InjectionManager.class);
    when(injectionManager.getInstance(SERVICE_REQUEST_TYPE)).thenReturn(serviceRequestRef);
    when(injectionManager.getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE)).thenReturn(contextRef);

    requestScopedInitializer.initialize(injectionManager);

    verify(serviceRequestRef).set(request);
    verify(contextRef).set(context);
}
项目:jrestless    文件:ServiceRequestHandlerTest.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
private RequestScopedInitializer getSetRequestScopedInitializer(Context context, ServiceRequest request) {
    ServiceRequestAndLambdaContext reqAndContext = new ServiceRequestAndLambdaContext(request, context);
    ArgumentCaptor<Consumer> containerEnhancerCaptor = ArgumentCaptor.forClass(Consumer.class);
    serviceHandler.delegateRequest(reqAndContext);
    verify(container).handleRequest(any(), any(), any(), containerEnhancerCaptor.capture());

    ContainerRequest containerRequest = mock(ContainerRequest.class);
    containerEnhancerCaptor.getValue().accept(containerRequest);

    ArgumentCaptor<RequestScopedInitializer> requestScopedInitializerCaptor = ArgumentCaptor.forClass(RequestScopedInitializer.class);

    verify(containerRequest).setRequestScopedInitializer(requestScopedInitializerCaptor.capture());

    return requestScopedInitializerCaptor.getValue();
}
项目:jrestless    文件:GatewayRequestHandlerTest.java   
@SuppressWarnings("unchecked")
@Test
public void delegateRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() {
    Context context = mock(Context.class);
    DefaultGatewayRequest request = new DefaultGatewayRequest();
    request.setPath("/");
    request.setHttpMethod("GET");

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request);

    Ref<GatewayRequest> gatewayRequestRef = mock(Ref.class);
    Ref<Context> contextRef = mock(Ref.class);


    InjectionManager injectionManager = mock(InjectionManager.class);
    when(injectionManager.getInstance(GATEWAY_REQUEST_TYPE)).thenReturn(gatewayRequestRef);
    when(injectionManager.getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE)).thenReturn(contextRef);

    requestScopedInitializer.initialize(injectionManager);

    verify(gatewayRequestRef).set(request);
    verify(contextRef).set(context);
}
项目:jrestless    文件:GatewayRequestHandlerTest.java   
@SuppressWarnings("unchecked")
private RequestScopedInitializer getSetRequestScopedInitializer(Context context, GatewayRequest request) {
    GatewayRequestAndLambdaContext reqAndContext = new GatewayRequestAndLambdaContext(request, context);
    ArgumentCaptor<Consumer<ContainerRequest>> containerEnhancerCaptor = ArgumentCaptor.forClass(Consumer.class);
    gatewayHandler.delegateRequest(reqAndContext);
    verify(container).handleRequest(any(), any(), any(), containerEnhancerCaptor.capture());

    ContainerRequest containerRequest = mock(ContainerRequest.class);
    containerEnhancerCaptor.getValue().accept(containerRequest);

    ArgumentCaptor<RequestScopedInitializer> requestScopedInitializerCaptor = ArgumentCaptor.forClass(RequestScopedInitializer.class);

    verify(containerRequest).setRequestScopedInitializer(requestScopedInitializerCaptor.capture());

    return requestScopedInitializerCaptor.getValue();
}
项目:jrestless    文件:SnsRequestHandlerTest.java   
@SuppressWarnings("unchecked")
@Test
public void delegateRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() {

    Context context = mock(Context.class);
    SNS sns = new SNS();
    sns.setTopicArn(":t");
    SNSRecord snsRecord = new SNSRecord();
    snsRecord.setSns(sns);

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, snsRecord);

    Ref<SNSRecord> snsRef = mock(Ref.class);
    Ref<Context> contextRef = mock(Ref.class);

    InjectionManager injectionManager = mock(InjectionManager.class);
    when(injectionManager.getInstance(SNS_RECORD_TYPE)).thenReturn(snsRef);
    when(injectionManager.getInstance(AbstractLambdaContextReferencingBinder.LAMBDA_CONTEXT_TYPE)).thenReturn(contextRef);

    requestScopedInitializer.initialize(injectionManager);

    verify(snsRef).set(snsRecord);
    verify(contextRef).set(context);
}
项目:jrestless    文件:SnsRequestHandlerTest.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
private RequestScopedInitializer getSetRequestScopedInitializer(Context context, SNSRecord snsRecord) {
    SnsRecordAndLambdaContext reqAndContext = new SnsRecordAndLambdaContext(snsRecord, context);
    ArgumentCaptor<Consumer> containerEnhancerCaptor = ArgumentCaptor.forClass(Consumer.class);
    snsHandler.delegateRequest(reqAndContext);
    verify(container).handleRequest(any(), any(), any(), containerEnhancerCaptor.capture());

    ContainerRequest containerRequest = mock(ContainerRequest.class);
    containerEnhancerCaptor.getValue().accept(containerRequest);

    ArgumentCaptor<RequestScopedInitializer> requestScopedInitializerCaptor = ArgumentCaptor.forClass(RequestScopedInitializer.class);

    verify(containerRequest).setRequestScopedInitializer(requestScopedInitializerCaptor.capture());

    return requestScopedInitializerCaptor.getValue();
}
项目:jrestless    文件:ServiceRequestHandlerTest.java   
@Test
public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() {
    Context context = mock(Context.class);
    DefaultServiceRequest request = new DefaultServiceRequest(null, new HashMap<>(), URI.create("/"), "GET");

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request);

    InjectionManager injectionManager = mock(InjectionManager.class);
    requestScopedInitializer.initialize(injectionManager);
}
项目:jrestless    文件:GatewayRequestHandlerTest.java   
@Test
public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() {

    Context context = mock(Context.class);
    DefaultGatewayRequest request = new DefaultGatewayRequest();
    request.setPath("/");
    request.setHttpMethod("GET");

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, request);

    InjectionManager injectionManager = mock(InjectionManager.class);
    requestScopedInitializer.initialize(injectionManager);
}
项目:jrestless    文件:SnsRequestHandlerTest.java   
@Test
public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() {

    Context context = mock(Context.class);
    SNS sns = new SNS();
    sns.setTopicArn(":t");
    SNSRecord snsRecord = new SNSRecord();
    snsRecord.setSns(sns);

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(context, snsRecord);

    InjectionManager injectionManager = mock(InjectionManager.class);
    requestScopedInitializer.initialize(injectionManager);
}
项目:jrestless    文件:WebActionRequestHandlerTest.java   
@Test
public void delegateRequest_ValidRequestAndNoReferencesGiven_ShouldNotFailOnRequestInitialization() {
    JsonObject jsonRequest = new WebActionRequestBuilder()
            .setHttpMethod("GET")
            .setPath("/")
            .buildJson();

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(jsonRequest);

    InjectionManager injectionManager = mock(InjectionManager.class);
    requestScopedInitializer.initialize(injectionManager);
}
项目:jrestless    文件:WebActionRequestHandlerTest.java   
@SuppressWarnings("unchecked")
private RequestScopedInitializer getSetRequestScopedInitializer(JsonObject request) {
    ArgumentCaptor<Consumer<ContainerRequest>> containerEnhancerCaptor = ArgumentCaptor.forClass(Consumer.class);
    handler.delegateJsonRequest(request);
    verify(container).handleRequest(any(), any(), any(), containerEnhancerCaptor.capture());

    ContainerRequest containerRequest = mock(ContainerRequest.class);
    containerEnhancerCaptor.getValue().accept(containerRequest);

    ArgumentCaptor<RequestScopedInitializer> requestScopedInitializerCaptor = ArgumentCaptor.forClass(RequestScopedInitializer.class);

    verify(containerRequest).setRequestScopedInitializer(requestScopedInitializerCaptor.capture());

    return requestScopedInitializerCaptor.getValue();
}
项目:jrestless    文件:WebActionRequestHandlerTest.java   
@Test
public void delegateJsonRequest_ValidRequestAndReferencesGiven_ShouldSetReferencesOnRequestInitialization() {

    WebActionRequestBuilder requestBuilder = new WebActionRequestBuilder()
            .setHttpMethod("GET")
            .setPath("/");

    JsonObject jsonRequest = requestBuilder.buildJson();
    DefaultWebActionRequest request = requestBuilder.build();

    RequestScopedInitializer requestScopedInitializer = getSetRequestScopedInitializer(jsonRequest);

    @SuppressWarnings("unchecked")
    Ref<WebActionRequest> gatewayRequestRef = mock(Ref.class);

    InjectionManager injectionManager = mock(InjectionManager.class);
    when(injectionManager.getInstance(WEB_ACTION_REQUEST_TYPE)).thenReturn(gatewayRequestRef);

    requestScopedInitializer.initialize(injectionManager);

    verify(gatewayRequestRef).set(request);
}
项目:ameba    文件:Requests.java   
/**
 * <p>getRequestScopedInitializer.</p>
 *
 * @return a {@link org.glassfish.jersey.server.spi.RequestScopedInitializer} object.
 */
public static RequestScopedInitializer getRequestScopedInitializer() {
    return getRequest().getRequestScopedInitializer();
}
项目:ameba    文件:Requests.java   
/**
 * <p>setRequestScopedInitializer.</p>
 *
 * @param requestScopedInitializer a {@link org.glassfish.jersey.server.spi.RequestScopedInitializer} object.
 */
public static void setRequestScopedInitializer(RequestScopedInitializer requestScopedInitializer) {
    getRequest().setRequestScopedInitializer(requestScopedInitializer);
}