Search in sources :

Example 1 with AmazonSNSClientFactory

use of com.nextdoor.bender.aws.AmazonSNSClientFactory in project bender by Nextdoor.

the class SNSS3HandlerTest method testExceptionHandlingd.

@Test
public void testExceptionHandlingd() throws Throwable {
    BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_test_sns.json";
    TestContext ctx = new TestContext();
    ctx.setFunctionName("unittest");
    ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");
    /*
     * Invoke handler
     */
    SNSS3Handler fhandler = (SNSS3Handler) getHandler();
    fhandler.init(ctx);
    IpcSenderService ipcSpy = spy(fhandler.getIpcService());
    doThrow(new TransportException("expected")).when(ipcSpy).shutdown();
    fhandler.setIpcService(ipcSpy);
    AmazonSNSClient mockClient = mock(AmazonSNSClient.class);
    AmazonSNSClientFactory mockClientFactory = mock(AmazonSNSClientFactory.class);
    doReturn(mockClient).when(mockClientFactory).newInstance();
    fhandler.snsClientFactory = mockClientFactory;
    SNSEvent event = getTestEvent();
    try {
        fhandler.handler(event, ctx);
    } catch (Exception e) {
    }
    verify(mockClient, times(1)).publish("foo", "basic_input.log", "SNSS3Handler Failed");
}
Also used : IpcSenderService(com.nextdoor.bender.ipc.IpcSenderService) AmazonSNSClientFactory(com.nextdoor.bender.aws.AmazonSNSClientFactory) TestContext(com.nextdoor.bender.aws.TestContext) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) TransportException(com.nextdoor.bender.ipc.TransportException) TransportException(com.nextdoor.bender.ipc.TransportException) SNSEvent(com.amazonaws.services.lambda.runtime.events.SNSEvent) HandlerTest(com.nextdoor.bender.handler.HandlerTest) Test(org.junit.Test)

Aggregations

SNSEvent (com.amazonaws.services.lambda.runtime.events.SNSEvent)1 AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)1 AmazonSNSClientFactory (com.nextdoor.bender.aws.AmazonSNSClientFactory)1 TestContext (com.nextdoor.bender.aws.TestContext)1 HandlerTest (com.nextdoor.bender.handler.HandlerTest)1 IpcSenderService (com.nextdoor.bender.ipc.IpcSenderService)1 TransportException (com.nextdoor.bender.ipc.TransportException)1 Test (org.junit.Test)1