|
| 1 | +/* |
| 2 | + * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at: |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 11 | + * OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | + * License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package com.amazonaws.mobileconnectors.lambdainvoker; |
| 17 | + |
| 18 | + |
| 19 | +import android.support.test.InstrumentationRegistry; |
| 20 | + |
| 21 | +import com.amazonaws.auth.AWSCredentialsProvider; |
| 22 | +import com.amazonaws.internal.StaticCredentialsProvider; |
| 23 | +import com.amazonaws.regions.Regions; |
| 24 | +import com.amazonaws.testutils.AWSTestBase; |
| 25 | + |
| 26 | +import org.junit.After; |
| 27 | +import org.junit.Assert; |
| 28 | +import org.junit.Before; |
| 29 | +import org.junit.Test; |
| 30 | +import org.robolectric.shadows.ShadowLog; |
| 31 | + |
| 32 | +import java.util.Locale; |
| 33 | + |
| 34 | +public class MyInterfaceIntegrationTest extends AWSTestBase { |
| 35 | + |
| 36 | + private static Locale LOCALE_DEFAULT = Locale.getDefault(); |
| 37 | + private MyInterface myInterface; |
| 38 | + |
| 39 | + @Before |
| 40 | + public void setup() throws Exception { |
| 41 | + setUpCredentials(); |
| 42 | + |
| 43 | + AWSCredentialsProvider provider = new StaticCredentialsProvider(credentials); |
| 44 | + LambdaInvokerFactory factory = new LambdaInvokerFactory(InstrumentationRegistry.getContext(), Regions.US_WEST_2, |
| 45 | + provider); |
| 46 | + LambdaDataBinder dataBinder = new LambdaJsonBinder(); |
| 47 | + myInterface = factory.build(MyInterface.class, dataBinder); |
| 48 | + |
| 49 | + // redirect Android log |
| 50 | + ShadowLog.stream = System.out; |
| 51 | + } |
| 52 | + |
| 53 | + @After |
| 54 | + public void teardown() { |
| 55 | + Locale.setDefault(LOCALE_DEFAULT); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testEcho() { |
| 60 | + NameInfo nameInfo = new NameInfo("Big", "Bird"); |
| 61 | + |
| 62 | + NameInfo result = myInterface.echo(nameInfo); |
| 63 | + |
| 64 | + Assert.assertEquals(result.getFirstName(), nameInfo.getFirstName()); |
| 65 | + Assert.assertEquals(result.getLastName(), nameInfo.getLastName()); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testEchoLocale() { |
| 70 | + Locale.setDefault(new Locale("tr", "TR")); |
| 71 | + NameInfo nameInfo = new NameInfo("Big", "Oğuzlar"); |
| 72 | + |
| 73 | + NameInfo result = myInterface.echo(nameInfo); |
| 74 | + |
| 75 | + Assert.assertEquals(result.getFirstName(), nameInfo.getFirstName()); |
| 76 | + Assert.assertEquals(result.getLastName(), nameInfo.getLastName()); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testNoEcho() { |
| 81 | + NameInfo nameInfo = new NameInfo("Big", "Bird"); |
| 82 | + |
| 83 | + myInterface.noEcho(nameInfo); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testEchoFirstName() { |
| 88 | + NameInfo nameInfo = new NameInfo("Oscar", "Grouch"); |
| 89 | + |
| 90 | + String result = myInterface.echoFirst(nameInfo); |
| 91 | + |
| 92 | + Assert.assertEquals(result, nameInfo.getFirstName()); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testSilence() { |
| 97 | + myInterface.syncSilence(); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void testVersion() { |
| 102 | + NameInfo nameInfo = new NameInfo("Oscar", "Grouch"); |
| 103 | + |
| 104 | + String result = myInterface.echoFirstVersion(nameInfo); |
| 105 | + |
| 106 | + Assert.assertEquals("versioned result", result, "versioned: " + nameInfo.getFirstName()); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void testAlias() { |
| 111 | + NameInfo nameInfo = new NameInfo("Oscar", "Grouch"); |
| 112 | + |
| 113 | + String result = myInterface.echoFirstAlias(nameInfo); |
| 114 | + |
| 115 | + Assert.assertEquals("alias result", result, "alias: " + nameInfo.getFirstName()); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void testEchoEventLogNone() { |
| 120 | + NameInfo nameInfo = new NameInfo("Oscar", "Grouch"); |
| 121 | + |
| 122 | + myInterface.echoEventLogNone(nameInfo); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + public void testEchoEventLogTail() { |
| 127 | + NameInfo nameInfo = new NameInfo("Oscar", "Grouch"); |
| 128 | + |
| 129 | + myInterface.echoEventLogTail(nameInfo); |
| 130 | + } |
| 131 | +} |
0 commit comments