You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/03/19 06:39:41 UTC
[camel] 06/22: CAMEL-15963 Create a Google Cloud Functions component
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit cd704e9377adabc1496e2cea734d71002a54456a
Author: Raffaele Marcello <ma...@gmail.com>
AuthorDate: Mon Mar 8 20:44:20 2021 +0100
CAMEL-15963 Create a Google Cloud Functions component
---
.../functions/GoogleCloudFunctionsOperations.java | 27 +-
.../functions/GoogleCloudFunctionsProducer.java | 183 ++++++++--
.../unit/GoogleCloudFunctionsComponentTest.java | 388 ++++++++++++++++++---
...GoogleCloudFunctionsEndpointBuilderFactory.java | 7 +-
4 files changed, 522 insertions(+), 83 deletions(-)
diff --git a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsOperations.java b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsOperations.java
index fa48fd9..cbf8b78 100644
--- a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsOperations.java
+++ b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsOperations.java
@@ -20,25 +20,10 @@ public enum GoogleCloudFunctionsOperations {
listFunctions,
getFunction,
- callFunction;
-
- //TODO Clean up
- // listFunctions,
- // getFunction,
- // createAlias,
- // deleteAlias,
- // getAlias,
- // listAliases,
- // createFunction,
- // deleteFunction,
- // invokeFunction,
- // updateFunction,
- // createEventSourceMapping,
- // deleteEventSourceMapping,
- // listEventSourceMapping,
- // listTags,
- // tagResource,
- // untagResource,
- // publishVersion,
- // listVersions
+ callFunction,
+ generateDownloadUrl,
+ generateUploadUrl,
+ createFunction,
+ updateFunction,
+ deleteFunction;
}
diff --git a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
index d5328ce..3464705 100644
--- a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
+++ b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.google.functions;
import java.util.List;
+import java.util.concurrent.ExecutionException;
import com.google.api.client.util.Lists;
import com.google.api.gax.rpc.ApiException;
@@ -26,8 +27,16 @@ import com.google.cloud.functions.v1.CloudFunction;
import com.google.cloud.functions.v1.CloudFunctionName;
import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
import com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
+import com.google.cloud.functions.v1.CreateFunctionRequest;
+import com.google.cloud.functions.v1.DeleteFunctionRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlResponse;
+import com.google.cloud.functions.v1.GenerateUploadUrlRequest;
+import com.google.cloud.functions.v1.GenerateUploadUrlResponse;
import com.google.cloud.functions.v1.ListFunctionsRequest;
import com.google.cloud.functions.v1.LocationName;
+import com.google.cloud.functions.v1.UpdateFunctionRequest;
+import com.google.protobuf.Empty;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.Message;
@@ -51,18 +60,33 @@ public class GoogleCloudFunctionsProducer extends DefaultProducer {
@Override
public void process(final Exchange exchange) throws Exception {
switch (determineOperation(exchange)) {
- case listFunctions:
- listFunctions(endpoint.getClient(), exchange);
- break;
- case getFunction:
- getFunction(endpoint.getClient(), exchange);
- break;
- case callFunction:
- callFunction(endpoint.getClient(), exchange);
- break;
-
- default:
- throw new IllegalArgumentException("Unsupported operation");
+ case listFunctions:
+ listFunctions(endpoint.getClient(), exchange);
+ break;
+ case getFunction:
+ getFunction(endpoint.getClient(), exchange);
+ break;
+ case callFunction:
+ callFunction(endpoint.getClient(), exchange);
+ break;
+ case generateDownloadUrl:
+ generateDownloadUrl(endpoint.getClient(), exchange);
+ break;
+ case generateUploadUrl:
+ generateUploadUrl(endpoint.getClient(), exchange);
+ break;
+ case createFunction:
+ createFunction(endpoint.getClient(), exchange);
+ break;
+ case updateFunction:
+ updateFunction(endpoint.getClient(), exchange);
+ break;
+ case deleteFunction:
+ deleteFunction(endpoint.getClient(), exchange);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unsupported operation");
}
}
@@ -123,32 +147,151 @@ public class GoogleCloudFunctionsProducer extends DefaultProducer {
if (payload instanceof CallFunctionRequest) {
CallFunctionResponse result;
try {
- result = client.callFunction( (CallFunctionRequest) payload );
+ result = client.callFunction((CallFunctionRequest) payload);
Message message = getMessageForResponse(exchange);
message.setBody(result);
} catch (ApiException ae) {
LOG.trace("callFunction command returned the error code {}", ae.getStatusCode());
throw ae;
- }
+ }
}
} else {
String data = exchange.getIn().getBody(String.class);
- CloudFunctionName cfName = CloudFunctionName.of(getConfiguration().getProject(), getConfiguration().getLocation(), getConfiguration().getFunctionName());
- CallFunctionRequest request = CallFunctionRequest.newBuilder()
- .setName(cfName.toString())
- .setData(data)
- .build();
+ CloudFunctionName cfName = CloudFunctionName.of(getConfiguration().getProject(),
+ getConfiguration().getLocation(), getConfiguration().getFunctionName());
+ CallFunctionRequest request = CallFunctionRequest.newBuilder().setName(cfName.toString()).setData(data)
+ .build();
CallFunctionResponse result = client.callFunction(request);
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
}
+ private void generateDownloadUrl(CloudFunctionsServiceClient client, Exchange exchange)
+ throws InvalidPayloadException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof GenerateDownloadUrlRequest) {
+ try {
+ GenerateDownloadUrlResponse result = client
+ .generateDownloadUrl((GenerateDownloadUrlRequest) payload);
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ } catch (ApiException ae) {
+ LOG.trace("generateDownloadUrl command returned the error code {}", ae.getStatusCode());
+ throw ae;
+ }
+ }
+ } else {
+ CloudFunctionName cfName = CloudFunctionName.of(getConfiguration().getProject(),
+ getConfiguration().getLocation(), getConfiguration().getFunctionName());
+ GenerateDownloadUrlRequest request = GenerateDownloadUrlRequest.newBuilder().setName(cfName.toString())
+ .build();
+ GenerateDownloadUrlResponse result = client.generateDownloadUrl(request);
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ }
+ }
+
+ private void generateUploadUrl(CloudFunctionsServiceClient client, Exchange exchange)
+ throws InvalidPayloadException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof GenerateUploadUrlRequest) {
+ try {
+ GenerateUploadUrlResponse result = client.generateUploadUrl((GenerateUploadUrlRequest) payload);
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ } catch (ApiException ae) {
+ LOG.trace("generateUploadUrl command returned the error code {}", ae.getStatusCode());
+ throw ae;
+ }
+ }
+ } else {
+ LocationName locationName = LocationName.of(getConfiguration().getProject(),
+ getConfiguration().getLocation());
+ GenerateUploadUrlRequest request = GenerateUploadUrlRequest.newBuilder().setParent(locationName.toString())
+ .build();
+ GenerateUploadUrlResponse result = client.generateUploadUrl(request);
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ }
+ }
+
+ private void createFunction(CloudFunctionsServiceClient client, Exchange exchange)
+ throws InvalidPayloadException, InterruptedException, ExecutionException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof CreateFunctionRequest) {
+ try {
+ CloudFunction result = client.createFunctionAsync((CreateFunctionRequest) payload).get();
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ } catch (ApiException ae) {
+ LOG.trace("createFunction command returned the error code {}", ae.getStatusCode());
+ throw ae;
+ }
+ }
+ } else {
+ LocationName locationName = LocationName.of(getConfiguration().getProject(),
+ getConfiguration().getLocation());
+ CreateFunctionRequest request = CreateFunctionRequest.newBuilder().setLocation(locationName.toString())
+ .setFunction(CloudFunction.newBuilder().build()).build(); // TODO check if add function name
+ CloudFunction result = client.createFunctionAsync(request).get();
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ }
+ }
+
+ private void updateFunction(CloudFunctionsServiceClient client, Exchange exchange)
+ throws InvalidPayloadException, InterruptedException, ExecutionException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof UpdateFunctionRequest) {
+ try {
+ CloudFunction result = client.updateFunctionAsync((UpdateFunctionRequest) payload).get();
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ } catch (ApiException ae) {
+ LOG.trace("updateFunction command returned the error code {}", ae.getStatusCode());
+ throw ae;
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("updateFunction supported only in pojo mode"); // TODO check
+ }
+ }
+
+ private void deleteFunction(CloudFunctionsServiceClient client, Exchange exchange)
+ throws InvalidPayloadException, InterruptedException, ExecutionException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof DeleteFunctionRequest) {
+ try {
+ Empty result = client.deleteFunctionAsync((DeleteFunctionRequest) payload).get();
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ } catch (ApiException ae) {
+ LOG.trace("deleteFunction command returned the error code {}", ae.getStatusCode());
+ throw ae;
+ }
+ }
+ } else {
+ CloudFunctionName cfName = CloudFunctionName.of(getConfiguration().getProject(),
+ getConfiguration().getLocation(), getConfiguration().getFunctionName());
+ DeleteFunctionRequest request = DeleteFunctionRequest.newBuilder().setName(cfName.toString()).build();
+ Empty result = client.deleteFunctionAsync(request).get();
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ }
+ }
+
private GoogleCloudFunctionsOperations determineOperation(Exchange exchange) {
GoogleCloudFunctionsOperations operation = exchange.getIn().getHeader(GoogleCloudFunctionsConstants.OPERATION,
GoogleCloudFunctionsOperations.class);
if (operation == null) {
- operation = getConfiguration().getOperation() == null ? GoogleCloudFunctionsOperations.callFunction
+ operation = getConfiguration().getOperation() == null
+ ? GoogleCloudFunctionsOperations.callFunction
: getConfiguration().getOperation();
}
return operation;
diff --git a/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java b/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java
index 898684b..f478683 100644
--- a/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java
+++ b/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java
@@ -16,10 +16,6 @@
*/
package org.apache.camel.component.google.functions.unit;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -31,26 +27,37 @@ import com.google.cloud.functions.v1.CallFunctionResponse;
import com.google.cloud.functions.v1.CloudFunction;
import com.google.cloud.functions.v1.CloudFunctionName;
import com.google.cloud.functions.v1.CloudFunctionStatus;
+import com.google.cloud.functions.v1.CreateFunctionRequest;
+import com.google.cloud.functions.v1.DeleteFunctionRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlResponse;
+import com.google.cloud.functions.v1.GenerateUploadUrlRequest;
+import com.google.cloud.functions.v1.GenerateUploadUrlResponse;
import com.google.cloud.functions.v1.GetFunctionRequest;
import com.google.cloud.functions.v1.ListFunctionsRequest;
import com.google.cloud.functions.v1.ListFunctionsResponse;
import com.google.cloud.functions.v1.LocationName;
+import com.google.cloud.functions.v1.UpdateFunctionRequest;
+import com.google.longrunning.Operation;
import com.google.protobuf.AbstractMessage;
+import com.google.protobuf.Any;
import com.google.protobuf.Duration;
+import com.google.protobuf.Empty;
+import com.google.protobuf.FieldMask;
import com.google.protobuf.Timestamp;
-
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseTest {
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
- private static final Logger log = LoggerFactory.getLogger(GoogleCloudFunctionsComponentTest.class);
+public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseTest {
@EndpointInject("mock:result")
private MockEndpoint mock;
@@ -63,25 +70,87 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- //simple routes
- from("direct:listFunctions").to("google-functions://" + functionName + "?project=" + project
- + "&location=" + location + "&operation=listFunctions").to("mock:result");
- from("direct:getFunction").to("google-functions://" + functionName + "?project=" + project
- + "&location=" + location + "&operation=getFunction").to("mock:result");
- from("direct:callFunction").to("google-functions://" + functionName + "?project=" + project
- + "&location=" + location + "&operation=callFunction").to("mock:result");
- //pojo routes
- from("direct:listFunctionsPojo").to("google-functions://" + functionName + "?project=" + project
- + "&location=" + location + "&operation=listFunctions&pojoRequest=true").to("mock:result");
- from("direct:getFunctionPojo").to("google-functions://" + functionName + "?project=" + project
- + "&location=" + location + "&operation=getFunction&pojoRequest=true").to("mock:result");
- from("direct:callFunctionPojo").to("google-functions://" + functionName + "?project=" + project
- + "&location=" + location + "&operation=callFunction&pojoRequest=true").to("mock:result");
+ // simple routes
+ from("direct:listFunctions")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location + "&operation=listFunctions")
+ .to("mock:result");
+ from("direct:getFunction")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location + "&operation=getFunction")
+ .to("mock:result");
+ from("direct:callFunction")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location + "&operation=callFunction")
+ .to("mock:result");
+
+ from("direct:generateDownloadUrl").to("google-functions://" + functionName + "?project="
+ + project + "&location=" + location + "&operation=generateDownloadUrl")
+ .to("mock:result");
+ from("direct:generateUploadUrl").to("google-functions://" + functionName + "?project="
+ + project + "&location=" + location + "&operation=generateUploadUrl")
+ .to("mock:result");
+ from("direct:createFunction")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location + "&operation=createFunction")
+ .to("mock:result");
+ from("direct:updateFunction")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location + "&operation=updateFunction")
+ .to("mock:result");
+ from("direct:deleteFunction")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location + "&operation=deleteFunction")
+ .to("mock:result");
+
+ // pojo routes
+ from("direct:listFunctionsPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=listFunctions&pojoRequest=true")
+ .to("mock:result");
+ from("direct:getFunctionPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=getFunction&pojoRequest=true")
+ .to("mock:result");
+ from("direct:callFunctionPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=callFunction&pojoRequest=true")
+ .to("mock:result");
+
+ from("direct:generateDownloadUrlPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=generateDownloadUrl&pojoRequest=true")
+ .to("mock:result");
+ from("direct:generateUploadUrlPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=generateUploadUrl&pojoRequest=true")
+ .to("mock:result");
+ from("direct:createFunctionPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=createFunction&pojoRequest=true")
+ .to("mock:result");
+ from("direct:updateFunctionPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=updateFunction&pojoRequest=true")
+ .to("mock:result");
+ from("direct:deleteFunctionPojo")
+ .to("google-functions://" + functionName + "?project=" + project
+ + "&location=" + location
+ + "&operation=deleteFunction&pojoRequest=true")
+ .to("mock:result");
}
};
}
@Test
+ @SuppressWarnings("unchecked")
public void listFunctionsTest() throws Exception {
CloudFunction cf1 = CloudFunction.newBuilder().build();
CloudFunction cf2 = CloudFunction.newBuilder().build();
@@ -92,6 +161,7 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
Exchange exchange = template.send("direct:listFunctions", ExchangePattern.InOut, exc -> {
});
+
List<CloudFunction> result = exchange.getMessage().getBody(List.class);
assertNotNull(result);
assertEquals(cfList.size(), result.size());
@@ -103,6 +173,7 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
}
@Test
+ @SuppressWarnings("unchecked")
public void listFunctionsPojoTest() throws Exception {
CloudFunction cf1 = CloudFunction.newBuilder().build();
CloudFunction cf2 = CloudFunction.newBuilder().build();
@@ -135,11 +206,12 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
.setDescription("description-1724546052").setStatus(CloudFunctionStatus.forNumber(0))
.setEntryPoint("entryPoint-1979329474").setRuntime("runtime1550962648")
.setTimeout(Duration.newBuilder().build()).setAvailableMemoryMb(1964533661)
- .setServiceAccountEmail("serviceAccountEmail1825953988").setUpdateTime(Timestamp.newBuilder().build())
- .setVersionId(-670497310).putAllLabels(new HashMap<String, String>())
- .putAllEnvironmentVariables(new HashMap<String, String>()).setNetwork("network1843485230")
- .setMaxInstances(-330682013).setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785")
- .build();
+ .setServiceAccountEmail("serviceAccountEmail1825953988")
+ .setUpdateTime(Timestamp.newBuilder().build()).setVersionId(-670497310)
+ .putAllLabels(new HashMap<String, String>())
+ .putAllEnvironmentVariables(new HashMap<String, String>())
+ .setNetwork("network1843485230").setMaxInstances(-330682013)
+ .setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785").build();
mockCloudFunctionsService.addResponse(expectedResponse);
CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
@@ -160,18 +232,18 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
@Test
public void getFunctionPojoTest() throws Exception {
CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
- CloudFunction expectedResponse = CloudFunction.newBuilder()
- .setName( cfName.toString())
+ CloudFunction expectedResponse = CloudFunction.newBuilder().setName(cfName.toString())
.setDescription("description-1724546052").setStatus(CloudFunctionStatus.forNumber(0))
.setEntryPoint("entryPoint-1979329474").setRuntime("runtime1550962648")
.setTimeout(Duration.newBuilder().build()).setAvailableMemoryMb(1964533661)
- .setServiceAccountEmail("serviceAccountEmail1825953988").setUpdateTime(Timestamp.newBuilder().build())
- .setVersionId(-670497310).putAllLabels(new HashMap<String, String>())
- .putAllEnvironmentVariables(new HashMap<String, String>()).setNetwork("network1843485230")
- .setMaxInstances(-330682013).setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785")
- .build();
+ .setServiceAccountEmail("serviceAccountEmail1825953988")
+ .setUpdateTime(Timestamp.newBuilder().build()).setVersionId(-670497310)
+ .putAllLabels(new HashMap<String, String>())
+ .putAllEnvironmentVariables(new HashMap<String, String>())
+ .setNetwork("network1843485230").setMaxInstances(-330682013)
+ .setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785").build();
mockCloudFunctionsService.addResponse(expectedResponse);
-
+
Exchange exchange = template.send("direct:getFunctionPojo", ExchangePattern.InOut, exc -> {
exc.getIn().setBody(cfName);
});
@@ -190,8 +262,8 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
@Test
public void callFunctionTest() throws Exception {
CallFunctionResponse expectedResponse = CallFunctionResponse.newBuilder()
- .setExecutionId("executionId-454906285").setResult("result-934426595").setError("error96784904")
- .build();
+ .setExecutionId("executionId-454906285").setResult("result-934426595")
+ .setError("error96784904").build();
mockCloudFunctionsService.addResponse(expectedResponse);
CloudFunctionName name = CloudFunctionName.of(project, location, functionName);
@@ -216,13 +288,14 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
@Test
public void callFunctionPojoTest() throws Exception {
CallFunctionResponse expectedResponse = CallFunctionResponse.newBuilder()
- .setExecutionId("executionId-454906285").setResult("result-934426595").setError("error96784904")
- .build();
+ .setExecutionId("executionId-454906285").setResult("result-934426595")
+ .setError("error96784904").build();
mockCloudFunctionsService.addResponse(expectedResponse);
CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
String data = "data3076010";
- CallFunctionRequest request = CallFunctionRequest.newBuilder().setName(cfName.toString()).setData(data).build();
+ CallFunctionRequest request = CallFunctionRequest.newBuilder().setName(cfName.toString()).setData(data)
+ .build();
Exchange exchange = template.send("direct:callFunctionPojo", ExchangePattern.InOut, exc -> {
exc.getIn().setBody(request);
@@ -240,4 +313,237 @@ public class GoogleCloudFunctionsComponentTest extends GoogleCloudFunctionsBaseT
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
+ @Test
+ public void generateDownloadUrlTest() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+
+ GenerateDownloadUrlResponse expectedResponse = GenerateDownloadUrlResponse.newBuilder()
+ .setDownloadUrl("downloadUrl-1211148345").build();
+ mockCloudFunctionsService.addResponse(expectedResponse);
+
+ Exchange exchange = template.send("direct:generateDownloadUrl", ExchangePattern.InOut, exc -> {
+ });
+ GenerateDownloadUrlResponse actualResponse = exchange.getMessage()
+ .getBody(GenerateDownloadUrlResponse.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ GenerateDownloadUrlRequest actualRequest = ((GenerateDownloadUrlRequest) actualRequests.get(0));
+ assertEquals(cfName.toString(), actualRequest.getName());
+
+ }
+
+ @Test
+ public void generateDownloadUrlPojoTest() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+
+ GenerateDownloadUrlResponse expectedResponse = GenerateDownloadUrlResponse.newBuilder()
+ .setDownloadUrl("downloadUrl-1211148345").build();
+ mockCloudFunctionsService.addResponse(expectedResponse);
+
+ GenerateDownloadUrlRequest request = GenerateDownloadUrlRequest.newBuilder().setName(cfName.toString())
+ .build();
+
+ Exchange exchange = template.send("direct:generateDownloadUrlPojo", ExchangePattern.InOut, exc -> {
+ exc.getIn().setBody(request);
+ });
+ GenerateDownloadUrlResponse actualResponse = exchange.getMessage()
+ .getBody(GenerateDownloadUrlResponse.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ GenerateDownloadUrlRequest actualRequest = ((GenerateDownloadUrlRequest) actualRequests.get(0));
+ assertEquals(cfName.toString(), actualRequest.getName());
+ }
+
+ @Test
+ public void generateUploadUrlTest() throws Exception {
+ LocationName locationName = LocationName.of(project, location);
+ GenerateUploadUrlResponse expectedResponse = GenerateUploadUrlResponse.newBuilder()
+ .setUploadUrl("uploadUrl1239085998").build();
+ mockCloudFunctionsService.addResponse(expectedResponse);
+
+ Exchange exchange = template.send("direct:generateUploadUrl", ExchangePattern.InOut, exc -> {
+ });
+ GenerateUploadUrlResponse actualResponse = exchange.getMessage()
+ .getBody(GenerateUploadUrlResponse.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ GenerateUploadUrlRequest actualRequest = ((GenerateUploadUrlRequest) actualRequests.get(0));
+ assertEquals(locationName.toString(), actualRequest.getParent());
+ }
+
+ @Test
+ public void generateUploadUrlTestPojo() throws Exception {
+ LocationName locationName = LocationName.of(project, location);
+ GenerateUploadUrlResponse expectedResponse = GenerateUploadUrlResponse.newBuilder()
+ .setUploadUrl("uploadUrl1239085998").build();
+ mockCloudFunctionsService.addResponse(expectedResponse);
+
+ GenerateUploadUrlRequest request = GenerateUploadUrlRequest.newBuilder()
+ .setParent(locationName.toString()).build();
+ Exchange exchange = template.send("direct:generateUploadUrlPojo", ExchangePattern.InOut, exc -> {
+ exc.getIn().setBody(request);
+ });
+ GenerateUploadUrlResponse actualResponse = exchange.getMessage()
+ .getBody(GenerateUploadUrlResponse.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ GenerateUploadUrlRequest actualRequest = ((GenerateUploadUrlRequest) actualRequests.get(0));
+ assertEquals(locationName.toString(), actualRequest.getParent());
+ }
+
+ @Test
+ public void createFunctionTest() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+ CloudFunction expectedResponse = CloudFunction.newBuilder().setName(cfName.toString())
+ .setDescription("description-1724546052").setStatus(CloudFunctionStatus.forNumber(0))
+ .setEntryPoint("entryPoint-1979329474").setRuntime("runtime1550962648")
+ .setTimeout(Duration.newBuilder().build()).setAvailableMemoryMb(1964533661)
+ .setServiceAccountEmail("serviceAccountEmail1825953988")
+ .setUpdateTime(Timestamp.newBuilder().build()).setVersionId(-670497310)
+ .putAllLabels(new HashMap<String, String>())
+ .putAllEnvironmentVariables(new HashMap<String, String>())
+ .setNetwork("network1843485230").setMaxInstances(-330682013)
+ .setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785").build();
+ Operation resultOperation = Operation.newBuilder().setName("createFunctionTest").setDone(true)
+ .setResponse(Any.pack(expectedResponse)).build();
+ mockCloudFunctionsService.addResponse(resultOperation);
+ Exchange exchange = template.send("direct:createFunction", ExchangePattern.InOut, exc -> {
+ });
+ CloudFunction actualResponse = exchange.getMessage().getBody(CloudFunction.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ }
+
+ @Test
+ public void createFunctionTestPojo() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+ CloudFunction expectedResponse = CloudFunction.newBuilder().setName(cfName.toString())
+ .setDescription("description-1724546052").setStatus(CloudFunctionStatus.forNumber(0))
+ .setEntryPoint("entryPoint-1979329474").setRuntime("runtime1550962648")
+ .setTimeout(Duration.newBuilder().build()).setAvailableMemoryMb(1964533661)
+ .setServiceAccountEmail("serviceAccountEmail1825953988")
+ .setUpdateTime(Timestamp.newBuilder().build()).setVersionId(-670497310)
+ .putAllLabels(new HashMap<String, String>())
+ .putAllEnvironmentVariables(new HashMap<String, String>())
+ .setNetwork("network1843485230").setMaxInstances(-330682013)
+ .setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785").build();
+ Operation resultOperation = Operation.newBuilder().setName("createFunctionTest").setDone(true)
+ .setResponse(Any.pack(expectedResponse)).build();
+ mockCloudFunctionsService.addResponse(resultOperation);
+
+ LocationName locationName = LocationName.of(project, location);
+ CreateFunctionRequest request = CreateFunctionRequest.newBuilder().setLocation(locationName.toString())
+ .setFunction(CloudFunction.newBuilder().build()).build();
+ Exchange exchange = template.send("direct:createFunctionPojo", ExchangePattern.InOut, exc -> {
+ exc.getIn().setBody(request);
+ });
+ CloudFunction actualResponse = exchange.getMessage().getBody(CloudFunction.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ }
+
+ @Disabled
+ @Test
+ public void updateFunctionTest() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+ CloudFunction expectedResponse = CloudFunction.newBuilder().setName(cfName.toString())
+ .setDescription("description-1724546052").setStatus(CloudFunctionStatus.forNumber(0))
+ .setEntryPoint("entryPoint-1979329474").setRuntime("runtime1550962648")
+ .setTimeout(Duration.newBuilder().build()).setAvailableMemoryMb(1964533661)
+ .setServiceAccountEmail("serviceAccountEmail1825953988")
+ .setUpdateTime(Timestamp.newBuilder().build()).setVersionId(-670497310)
+ .putAllLabels(new HashMap<String, String>())
+ .putAllEnvironmentVariables(new HashMap<String, String>())
+ .setNetwork("network1843485230").setMaxInstances(-330682013)
+ .setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785").build();
+ Operation resultOperation = Operation.newBuilder().setName("updateFunctionTest").setDone(true)
+ .setResponse(Any.pack(expectedResponse)).build();
+ mockCloudFunctionsService.addResponse(resultOperation);
+
+ Exchange exchange = template.send("direct:updateFunction", ExchangePattern.InOut, exc -> {
+ });
+ CloudFunction actualResponse = exchange.getMessage().getBody(CloudFunction.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ }
+
+ @Test
+ public void updateFunctionTestPojo() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+ CloudFunction expectedResponse = CloudFunction.newBuilder().setName(cfName.toString())
+ .setDescription("description-1724546052").setStatus(CloudFunctionStatus.forNumber(0))
+ .setEntryPoint("entryPoint-1979329474").setRuntime("runtime1550962648")
+ .setTimeout(Duration.newBuilder().build()).setAvailableMemoryMb(1964533661)
+ .setServiceAccountEmail("serviceAccountEmail1825953988")
+ .setUpdateTime(Timestamp.newBuilder().build()).setVersionId(-670497310)
+ .putAllLabels(new HashMap<String, String>())
+ .putAllEnvironmentVariables(new HashMap<String, String>())
+ .setNetwork("network1843485230").setMaxInstances(-330682013)
+ .setVpcConnector("vpcConnector2101559652").setBuildId("buildId230943785").build();
+ Operation resultOperation = Operation.newBuilder().setName("updateFunctionTest").setDone(true)
+ .setResponse(Any.pack(expectedResponse)).build();
+ mockCloudFunctionsService.addResponse(resultOperation);
+
+ UpdateFunctionRequest request = UpdateFunctionRequest.newBuilder()
+ .setFunction(CloudFunction.newBuilder().build())
+ .setUpdateMask(FieldMask.newBuilder().build()).build();
+ Exchange exchange = template.send("direct:updateFunctionPojo", ExchangePattern.InOut, exc -> {
+ exc.getIn().setBody(request);
+ });
+ CloudFunction actualResponse = exchange.getMessage().getBody(CloudFunction.class);
+ assertEquals(expectedResponse, actualResponse);
+
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ }
+
+ @Test
+ public void deleteFunctionTest() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+ Empty expectedResponse = Empty.newBuilder().build();
+ Operation resultOperation = Operation.newBuilder().setName(cfName.toString()).setDone(true)
+ .setResponse(Any.pack(expectedResponse)).build();
+ mockCloudFunctionsService.addResponse(resultOperation);
+ Exchange exchange = template.send("direct:deleteFunction", ExchangePattern.InOut, exc -> {
+ });
+ Empty actualResponse = exchange.getMessage().getBody(Empty.class);
+ assertNotNull(actualResponse);
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ DeleteFunctionRequest actualRequest = ((DeleteFunctionRequest) actualRequests.get(0));
+ assertEquals(cfName.toString(), actualRequest.getName());
+ }
+
+ @Test
+ public void deleteFunctionPojoTest() throws Exception {
+ CloudFunctionName cfName = CloudFunctionName.of(project, location, functionName);
+ Empty expectedResponse = Empty.newBuilder().build();
+ Operation resultOperation = Operation.newBuilder().setName(cfName.toString()).setDone(true)
+ .setResponse(Any.pack(expectedResponse)).build();
+ mockCloudFunctionsService.addResponse(resultOperation);
+ DeleteFunctionRequest request = DeleteFunctionRequest.newBuilder().setName(cfName.toString()).build();
+ Exchange exchange = template.send("direct:deleteFunctionPojo", ExchangePattern.InOut, exc -> {
+ exc.getIn().setBody(request);
+ });
+ Empty actualResponse = exchange.getMessage().getBody(Empty.class);
+ assertNotNull(actualResponse);
+ List<AbstractMessage> actualRequests = mockCloudFunctionsService.getRequests();
+ assertEquals(1, actualRequests.size());
+ DeleteFunctionRequest actualRequest = ((DeleteFunctionRequest) actualRequests.get(0));
+ assertEquals(cfName.toString(), actualRequest.getName());
+ }
}
diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java
index 230ef09..2ab5f20 100644
--- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java
@@ -247,7 +247,12 @@ public interface GoogleCloudFunctionsEndpointBuilderFactory {
enum GoogleCloudFunctionsOperations {
listFunctions,
getFunction,
- callFunction;
+ callFunction,
+ generateDownloadUrl,
+ generateUploadUrl,
+ createFunction,
+ updateFunction,
+ deleteFunction;
}
public interface GoogleCloudFunctionsBuilders {