|
| 1 | +/* |
| 2 | + * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance |
| 5 | + * with the License. A copy of the License is located at |
| 6 | + * |
| 7 | + * http://aws.amazon.com/apache2.0/ |
| 8 | + * |
| 9 | + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 10 | + * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions |
| 11 | + * and limitations under the License. |
| 12 | + */ |
| 13 | +package com.amazonaws.serverless.proxy.jersey; |
| 14 | + |
| 15 | +import static org.junit.Assert.assertEquals; |
| 16 | +import static org.junit.Assert.assertNotNull; |
| 17 | + |
| 18 | +import javax.inject.Singleton; |
| 19 | + |
| 20 | +import org.glassfish.jersey.internal.inject.AbstractBinder; |
| 21 | +import org.glassfish.jersey.media.multipart.MultiPartFeature; |
| 22 | +import org.glassfish.jersey.server.ResourceConfig; |
| 23 | +import org.junit.Test; |
| 24 | + |
| 25 | +import com.amazonaws.serverless.proxy.model.AwsProxyRequest; |
| 26 | +import com.amazonaws.serverless.proxy.model.AwsProxyResponse; |
| 27 | + |
| 28 | +/** |
| 29 | + * Test that one can access the Jersey injection manager |
| 30 | + */ |
| 31 | +public class JerseyInjectionTest { |
| 32 | + |
| 33 | + // Test ressource binder |
| 34 | + private static class ResourceBinder extends AbstractBinder { |
| 35 | + |
| 36 | + @Override |
| 37 | + protected void configure() { |
| 38 | + bind(new JerseyInjectionTest()).to(JerseyInjectionTest.class).in(Singleton.class); |
| 39 | + } |
| 40 | + |
| 41 | + } |
| 42 | + |
| 43 | + private static ResourceConfig app = new ResourceConfig().register(MultiPartFeature.class) |
| 44 | + .register(new ResourceBinder()); |
| 45 | + |
| 46 | + private static JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = JerseyLambdaContainerHandler.getAwsProxyHandler( |
| 47 | + app); |
| 48 | + |
| 49 | + @Test |
| 50 | + public void can_get_injected_resources() throws Exception { |
| 51 | + |
| 52 | + JerseyInjectionTest instance1 = handler.getInjectionManager().getInstance(JerseyInjectionTest.class); |
| 53 | + assertNotNull(instance1); |
| 54 | + |
| 55 | + JerseyInjectionTest instance2 = handler.getInjectionManager().getInstance(JerseyInjectionTest.class); |
| 56 | + assertEquals(instance1, instance2); |
| 57 | + |
| 58 | + } |
| 59 | +} |
0 commit comments