forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#9502 from patriot1burke/lambda-clientcon…
…text Read Lambda ClientContext correctly, Issue quarkusio#9395
- Loading branch information
Showing
7 changed files
with
229 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...mbda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkus.amazon.lambda.runtime; | ||
|
||
import java.util.Map; | ||
|
||
import com.amazonaws.services.lambda.runtime.Client; | ||
import com.amazonaws.services.lambda.runtime.ClientContext; | ||
import com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
|
||
public class ClientContextImpl implements ClientContext { | ||
private ClientImpl impl; | ||
private Map<String, String> cust; | ||
private Map<String, String> env; | ||
|
||
@JsonGetter("client") | ||
public ClientImpl getImpl() { | ||
return impl; | ||
} | ||
|
||
@JsonSetter("client") | ||
public void setImpl(ClientImpl impl) { | ||
this.impl = impl; | ||
} | ||
|
||
@JsonGetter("custom") | ||
public Map<String, String> getCust() { | ||
return cust; | ||
} | ||
|
||
@JsonSetter("custom") | ||
public void setCust(Map<String, String> cust) { | ||
this.cust = cust; | ||
} | ||
|
||
@JsonGetter("env") | ||
public Map<String, String> getEnv() { | ||
return env; | ||
} | ||
|
||
@JsonSetter("env") | ||
public void setEnv(Map<String, String> env) { | ||
this.env = env; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public Client getClient() { | ||
return impl; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public Map<String, String> getCustom() { | ||
return cust; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public Map<String, String> getEnvironment() { | ||
return env; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...azon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package io.quarkus.amazon.lambda.runtime; | ||
|
||
import com.amazonaws.services.lambda.runtime.Client; | ||
import com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
|
||
public class ClientImpl implements Client { | ||
private String id; | ||
private String title; | ||
private String versionName; | ||
private String versionCode; | ||
private String packageName; | ||
|
||
@JsonGetter("client_id") | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@JsonSetter("client_id") | ||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
@JsonGetter("app_title") | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
@JsonSetter("app_title") | ||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
@JsonGetter("app_version_name") | ||
public String getVersionName() { | ||
return versionName; | ||
} | ||
|
||
@JsonSetter("app_version_name") | ||
public void setVersionName(String versionName) { | ||
this.versionName = versionName; | ||
} | ||
|
||
@JsonGetter("app_version_code") | ||
public String getVersionCode() { | ||
return versionCode; | ||
} | ||
|
||
@JsonSetter("app_version_code") | ||
public void setVersionCode(String versionCode) { | ||
this.versionCode = versionCode; | ||
} | ||
|
||
@JsonGetter("app_package_name") | ||
public String getPackageName() { | ||
return packageName; | ||
} | ||
|
||
@JsonSetter("app_package_name") | ||
public void setPackageName(String packageName) { | ||
this.packageName = packageName; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getInstallationId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getAppTitle() { | ||
return title; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getAppVersionName() { | ||
return versionName; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getAppVersionCode() { | ||
return versionCode; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getAppPackageName() { | ||
return packageName; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...-lambda/common-runtime/src/test/java/io/quarkus/amazon/lambda/test/ClientContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.quarkus.amazon.lambda.test; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.amazonaws.services.lambda.runtime.ClientContext; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.MapperFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectReader; | ||
|
||
import io.quarkus.amazon.lambda.runtime.ClientContextImpl; | ||
|
||
public class ClientContextTest { | ||
|
||
static final String ctx = "{\n" + | ||
" \"client\": {\n" + | ||
" \"client_id\":\"<client_id>\",\n" + | ||
" \"app_title\":\"<app_title>\",\n" + | ||
" \"app_version_name\":\"<app_version_name>\",\n" + | ||
" \"app_version_code\":\"<app_version_code>\",\n" + | ||
" \"app_package_name\":\"<app_package_name>\"\n" + | ||
" },\n" + | ||
" \n" + | ||
" \"custom\": { \"hello\": \"world\"},\n" + | ||
" \n" + | ||
" \"env\":{\n" + | ||
" \"platform\":\"<platform>\",\n" + | ||
" \"model\":\"<model>\",\n" + | ||
" \"make\":\"<make>\",\n" + | ||
" \"platform_version\":\"<platform_version>\",\n" + | ||
" \"locale\":\"<locale>\"\n" + | ||
" },\n" + | ||
"\n" + | ||
" \"services\": { \n" + | ||
" \"mobile_analytics\": {\n" + | ||
" \"app_id\":\"<mobile_analytics_app_id>\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }"; | ||
|
||
@Test | ||
public void testContextMarshalling() throws Exception { | ||
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); | ||
|
||
ObjectReader reader = mapper.readerFor(ClientContextImpl.class); | ||
|
||
ClientContext clientContext = reader.readValue(ctx); | ||
Assertions.assertNotNull(clientContext.getClient()); | ||
Assertions.assertNotNull(clientContext.getCustom()); | ||
Assertions.assertNotNull(clientContext.getEnvironment()); | ||
|
||
Assertions.assertEquals("<client_id>", clientContext.getClient().getInstallationId()); | ||
Assertions.assertEquals("<app_title>", clientContext.getClient().getAppTitle()); | ||
Assertions.assertEquals("<app_version_name>", clientContext.getClient().getAppVersionName()); | ||
Assertions.assertEquals("<app_version_code>", clientContext.getClient().getAppVersionCode()); | ||
Assertions.assertEquals("<app_package_name>", clientContext.getClient().getAppPackageName()); | ||
|
||
Assertions.assertEquals("world", clientContext.getCustom().get("hello")); | ||
Assertions.assertEquals("<platform>", clientContext.getEnvironment().get("platform")); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters