Skip to content

Commit def4daa

Browse files
desokroshanKarthikeyan
authored andcommitted
Integration test for lambda (#753)
* Integration test for lambda * Update run_integrationtest.py * Update license header * Update NameInfo.java
1 parent 560641f commit def4daa

File tree

10 files changed

+303
-0
lines changed

10 files changed

+303
-0
lines changed

CircleciScripts/run_integrationtest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"aws-android-sdk-kinesis-test",
1818
"aws-android-sdk-kinesisvideo-archivedmedia",
1919
"aws-android-sdk-kinesisvideo",
20+
"aws-android-sdk-lambda-test",
2021
"aws-android-sdk-mobile-client",
2122
"aws-android-sdk-rekognition-test",
2223
"aws-android-sdk-polly-test",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 27
5+
6+
7+
8+
defaultConfig {
9+
minSdkVersion 21
10+
targetSdkVersion 27
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
packagingOptions {
26+
exclude 'META-INF/DEPENDENCIES'
27+
}
28+
29+
}
30+
31+
dependencies {
32+
implementation fileTree(dir: 'libs', include: ['*.jar'])
33+
api (project(":aws-android-sdk-lambda")){
34+
exclude group: "com.google.android", module: "android"
35+
}
36+
testImplementation 'junit:junit:4.12'
37+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
38+
androidTestImplementation project(":aws-android-sdk-testutils")
39+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
public interface MyInterface {
20+
21+
@LambdaFunction
22+
NameInfo echo(NameInfo nameInfo);
23+
24+
@LambdaFunction(functionName = "echo")
25+
void noEcho(NameInfo nameInfo);
26+
27+
@LambdaFunction(logType = "Tail")
28+
String echoFirst(NameInfo nameInfo);
29+
30+
@LambdaFunction(functionName = "echo", invocationType = "RequestResponse")
31+
void syncSilence();
32+
33+
@LambdaFunction(functionName = "echoFirst", qualifier = "7")
34+
String echoFirstVersion(NameInfo nameInfo);
35+
36+
@LambdaFunction(functionName = "echoFirst", qualifier = "alias")
37+
String echoFirstAlias(NameInfo nameInfo);
38+
39+
@LambdaFunction(functionName = "echo", invocationType = "Event")
40+
void echoEventLogNone(NameInfo nameInfo);
41+
42+
@LambdaFunction(functionName = "echo", invocationType = "Event", logType = "Tail")
43+
void echoEventLogTail(NameInfo nameInfo);
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
public class NameInfo {
19+
20+
// -------------------------------------------------------------
21+
// Variables - Private
22+
// -------------------------------------------------------------
23+
24+
private String firstName;
25+
private String lastName;
26+
27+
// -------------------------------------------------------------
28+
// Constructors
29+
// -------------------------------------------------------------
30+
31+
public NameInfo() {
32+
}
33+
34+
public NameInfo(String firstName, String lastName) {
35+
this.firstName = firstName;
36+
this.lastName = lastName;
37+
}
38+
39+
// -------------------------------------------------------------
40+
// Methods - Getter/Setter
41+
// -------------------------------------------------------------
42+
43+
public String getFirstName() {
44+
return firstName;
45+
}
46+
47+
public void setFirstName(String firstName) {
48+
this.firstName = firstName;
49+
}
50+
51+
public String getLastName() {
52+
return lastName;
53+
}
54+
55+
public void setLastName(String lastName) {
56+
this.lastName = lastName;
57+
}
58+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.amazonaws.lambdatest" >
3+
<uses-permission android:name="android.permission.INTERNET"/>
4+
</manifest>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">aws-android-sdk-lambda-test</string>
3+
</resources>

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ include ':aws-android-sdk-polly-test'
5858
include ':aws-android-sdk-comprehend-test'
5959
include ':aws-android-sdk-comprehend'
6060
include ':aws-android-sdk-ddb-mapper-test'
61+
include ':aws-android-sdk-lambda-test'

0 commit comments

Comments
 (0)