Add GCP Background Functions Unit Tests
Simplify conversion and polish remove the package-related changes. Resolves #502
This commit is contained in:
committed by
Oleg Zhurakousky
parent
021e384d27
commit
29dc59bb7e
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.adapter.gcloud;
|
||||
|
||||
/**
|
||||
* An immutable implementation of the Google Cloud Function
|
||||
* {@link com.google.cloud.functions.Context} interface.
|
||||
*
|
||||
* @author Mike Eltsufin
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class Context implements com.google.cloud.functions.Context {
|
||||
|
||||
private String eventId;
|
||||
|
||||
private String timestamp;
|
||||
|
||||
private String eventType;
|
||||
|
||||
private String resource;
|
||||
|
||||
public Context() {
|
||||
}
|
||||
|
||||
public Context(String eventId, String timestamp, String eventType, String resource) {
|
||||
this.eventId = eventId;
|
||||
this.timestamp = timestamp;
|
||||
this.eventType = eventType;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String eventId() {
|
||||
return this.eventId;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String timestamp() {
|
||||
return this.timestamp;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String eventType() {
|
||||
return this.eventType;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -115,21 +115,8 @@ public class FunctionInvoker extends AbstractSpringFunctionAdapterInitializer<Ht
|
||||
public void accept(String json, Context context) {
|
||||
|
||||
Function<Message<String>, Message<byte[]>> function = lookupFunction();
|
||||
Message<String> message;
|
||||
|
||||
if ("google.pubsub.topic.publish".equals(context.eventType()) && getInputType() != PubSubMessage.class) {
|
||||
// If the input type is not PubSubMessage, use the PubSubMessage.data field as
|
||||
// payload, and put the full PubSubMessage and Context into message headers.
|
||||
|
||||
PubSubMessage pubSubMessage = this.jsonMapper.fromJson(json, PubSubMessage.class);
|
||||
|
||||
message = getInputType() == Void.class ? null : MessageBuilder.withPayload(pubSubMessage.getData())
|
||||
.setHeader("gcf_context", context).setHeader("gcf_message", pubSubMessage).build();
|
||||
}
|
||||
else {
|
||||
message = getInputType() == Void.class ? null
|
||||
: MessageBuilder.withPayload(json).setHeader("context", context).build();
|
||||
}
|
||||
Message<String> message = getInputType() == Void.class ? null
|
||||
: MessageBuilder.withPayload(json).setHeader("gcf_context", context).build();
|
||||
|
||||
Message<byte[]> result = function.apply(message);
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.adapter.gcloud;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A class that can be mapped to the GCF Pub/Sub Message event type. This is for use in
|
||||
* the background functions.
|
||||
*
|
||||
* @author Mike Eltsufin
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class PubSubMessage {
|
||||
|
||||
private String data;
|
||||
|
||||
private Map<String, String> attributes;
|
||||
|
||||
private String messageId;
|
||||
|
||||
private String publishTime;
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(Map<String, String> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public String getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(String messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public String getPublishTime() {
|
||||
return publishTime;
|
||||
}
|
||||
|
||||
public void setPublishTime(String publishTime) {
|
||||
this.publishTime = publishTime;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user