This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new eeef144 CAMEL-17750: Optimize implementation of HuaweiCloud FaceRecognition S… (#7117) eeef144 is described below commit eeef144b5c8f7964bc100a8ad6631b3e5065cffe Author: Hokutor <hwca...@huawei.com> AuthorDate: Sun Mar 6 14:55:05 2022 +0800 CAMEL-17750: Optimize implementation of HuaweiCloud FaceRecognition S… (#7117) * CAMEL-17750: Optimize implementation of HuaweiCloud FaceRecognition Service component Co-Authored-By: lyndonmiao <lyndonm...@qq.com> * CAMEL-17750: Optimize implementation of HuaweiCloud FaceRecognition Service component Co-Authored-By: lyndonmiao <lyndonm...@qq.com> Co-authored-by: lyndonmiao <lyndonm...@qq.com> --- .../huaweicloud/common/models/InputSourceType.java | 23 ++ .../huaweicloud/frs/FaceRecognitionProducer.java | 300 +++++++++------------ .../frs/models/ClientConfigurations.java | 13 + .../frs/FaceRecognitionInvalidParamsTest.java | 185 +++++++------ ...erificationWithImageBae64AndMockClientTest.java | 56 +++- ...LiveDetectionWithVideoUrlAndMockClientTest.java | 2 +- 6 files changed, 296 insertions(+), 283 deletions(-) diff --git a/components/camel-huawei/camel-huaweicloud-common/src/main/java/org/apache/camel/component/huaweicloud/common/models/InputSourceType.java b/components/camel-huawei/camel-huaweicloud-common/src/main/java/org/apache/camel/component/huaweicloud/common/models/InputSourceType.java new file mode 100644 index 0000000..daca920 --- /dev/null +++ b/components/camel-huawei/camel-huaweicloud-common/src/main/java/org/apache/camel/component/huaweicloud/common/models/InputSourceType.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.camel.component.huaweicloud.common.models; + +public enum InputSourceType { + BASE64, + URL, + FILE_PATH; +} diff --git a/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionProducer.java b/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionProducer.java index 0ff0115..67a2d3d 100644 --- a/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionProducer.java +++ b/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionProducer.java @@ -43,6 +43,7 @@ import com.huaweicloud.sdk.frs.v2.model.LiveDetectBase64Req; import com.huaweicloud.sdk.frs.v2.model.LiveDetectUrlReq; import com.huaweicloud.sdk.frs.v2.region.FrsRegion; import org.apache.camel.Exchange; +import org.apache.camel.component.huaweicloud.common.models.InputSourceType; import org.apache.camel.component.huaweicloud.frs.constants.FaceRecognitionConstants; import org.apache.camel.component.huaweicloud.frs.constants.FaceRecognitionProperties; import org.apache.camel.component.huaweicloud.frs.models.ClientConfigurations; @@ -98,8 +99,8 @@ public class FaceRecognitionProducer extends DefaultProducer { /** * initialize clientConfigurations * - * @param endpoint FrsEndpoint - * @return ClientConfigurations + * @param endpoint FrsEndpoint + * @return ClientConfigurations */ private ClientConfigurations initializeConfigurations(FaceRecognitionEndpoint endpoint) { ClientConfigurations clientConfigurations = new ClientConfigurations(); @@ -170,22 +171,23 @@ public class FaceRecognitionProducer extends DefaultProducer { private void performFaceDetectionOperation(Exchange exchange, ClientConfigurations clientConfigurations) { updateFaceDetectionConfigurations(exchange, clientConfigurations); SdkResponse result; - if (!StringUtils.isEmpty(clientConfigurations.getImageBase64())) { - FaceDetectBase64Req reqBody = new FaceDetectBase64Req().withImageBase64(clientConfigurations.getImageBase64()); - result = this.frsClient.detectFaceByBase64(new DetectFaceByBase64Request().withBody(reqBody)); - } else if (!StringUtils.isEmpty(clientConfigurations.getImageUrl())) { - FaceDetectUrlReq reqBody = new FaceDetectUrlReq().withImageUrl(clientConfigurations.getImageUrl()); - result = this.frsClient.detectFaceByUrl(new DetectFaceByUrlRequest().withBody(reqBody)); - } else { - File imageFile = getFile(clientConfigurations.getImageFilePath()); - DetectFaceByFileRequestBody reqBody; - try { - reqBody = new DetectFaceByFileRequestBody().withImageFile(new FileInputStream(imageFile), imageFile.getName()); - } catch (FileNotFoundException e) { - throw new IllegalArgumentException( - String.format("Image file not found: %s", clientConfigurations.getImageFilePath())); - } - result = this.frsClient.detectFaceByFile(new DetectFaceByFileRequest().withBody(reqBody)); + switch (clientConfigurations.getInputSourceType()) { + case BASE64: + FaceDetectBase64Req base64ReqBody = new FaceDetectBase64Req().withImageBase64(clientConfigurations.getImageBase64()); + result = this.frsClient.detectFaceByBase64(new DetectFaceByBase64Request().withBody(base64ReqBody)); + break; + case URL: + FaceDetectUrlReq urlReqBody = new FaceDetectUrlReq().withImageUrl(clientConfigurations.getImageUrl()); + result = this.frsClient.detectFaceByUrl(new DetectFaceByUrlRequest().withBody(urlReqBody)); + break; + default: + try (FileInputStream inputStream = new FileInputStream(clientConfigurations.getImageFilePath())) { + DetectFaceByFileRequestBody fileReqBody = new DetectFaceByFileRequestBody().withImageFile(inputStream, getFileName(clientConfigurations.getImageFilePath())); + result = this.frsClient.detectFaceByFile(new DetectFaceByFileRequest().withBody(fileReqBody)); + } catch (IOException e) { + throw new IllegalArgumentException( + String.format("Image file path is invalid: %s", clientConfigurations.getImageFilePath())); + } } exchange.getMessage().setBody(result); } @@ -197,31 +199,29 @@ public class FaceRecognitionProducer extends DefaultProducer { */ private void performFaceVerificationOperation(Exchange exchange, ClientConfigurations clientConfigurations) { updateFaceVerificationConfigurations(exchange, clientConfigurations); - SdkResponse result; - if (!StringUtils.isEmpty(clientConfigurations.getImageBase64()) - && !StringUtils.isEmpty(clientConfigurations.getAnotherImageBase64())) { - FaceCompareBase64Req reqBody = new FaceCompareBase64Req().withImage1Base64(clientConfigurations.getImageBase64()) - .withImage2Base64(clientConfigurations.getAnotherImageBase64()); - result = this.frsClient.compareFaceByBase64(new CompareFaceByBase64Request().withBody(reqBody)); - } else if (!StringUtils.isEmpty(clientConfigurations.getImageUrl()) - && !StringUtils.isEmpty(clientConfigurations.getAnotherImageUrl())) { - FaceCompareUrlReq reqBody = new FaceCompareUrlReq().withImage1Url(clientConfigurations.getImageUrl()) - .withImage2Url(clientConfigurations.getAnotherImageUrl()); - result = this.frsClient.compareFaceByUrl(new CompareFaceByUrlRequest().withBody(reqBody)); - } else { - File image1File = getFile(clientConfigurations.getImageFilePath()); - File image2File = getFile(clientConfigurations.getAnotherImageFilePath()); - CompareFaceByFileRequestBody reqBody; - try { - reqBody = new CompareFaceByFileRequestBody() - .withImage1File(new FileInputStream(image1File), image1File.getName()) - .withImage2File(new FileInputStream(image2File), image2File.getName()); - } catch (FileNotFoundException e) { - throw new IllegalArgumentException( - String.format("Image file not found: %s", clientConfigurations.getImageFilePath())); - } - result = this.frsClient.compareFaceByFile(new CompareFaceByFileRequest().withBody(reqBody)); + switch (clientConfigurations.getInputSourceType()) { + case BASE64: + FaceCompareBase64Req base64ReqBody = new FaceCompareBase64Req().withImage1Base64(clientConfigurations.getImageBase64()) + .withImage2Base64(clientConfigurations.getAnotherImageBase64()); + result = this.frsClient.compareFaceByBase64(new CompareFaceByBase64Request().withBody(base64ReqBody)); + break; + case URL: + FaceCompareUrlReq urlReqBody = new FaceCompareUrlReq().withImage1Url(clientConfigurations.getImageUrl()) + .withImage2Url(clientConfigurations.getAnotherImageUrl()); + result = this.frsClient.compareFaceByUrl(new CompareFaceByUrlRequest().withBody(urlReqBody)); + break; + default: + try (FileInputStream image1InputStream = new FileInputStream(clientConfigurations.getImageFilePath()); + FileInputStream image2InputStream = new FileInputStream(clientConfigurations.getAnotherImageFilePath())) { + CompareFaceByFileRequestBody fileReqBody = new CompareFaceByFileRequestBody() + .withImage1File(image1InputStream, getFileName(clientConfigurations.getImageFilePath())) + .withImage2File(image2InputStream, getFileName(clientConfigurations.getAnotherImageFilePath())); + result = this.frsClient.compareFaceByFile(new CompareFaceByFileRequest().withBody(fileReqBody)); + } catch (IOException e) { + throw new IllegalArgumentException( + String.format("Image file paths are invalid: %s, %s", clientConfigurations.getImageFilePath(), clientConfigurations.getAnotherImageFilePath())); + } } exchange.getMessage().setBody(result); } @@ -234,192 +234,136 @@ public class FaceRecognitionProducer extends DefaultProducer { private void performLiveDetectOperation(Exchange exchange, ClientConfigurations clientConfigurations) { updateLiveDetectConfigurations(exchange, clientConfigurations); SdkResponse result; - if (!StringUtils.isEmpty(clientConfigurations.getVideoBase64())) { - LiveDetectBase64Req reqBody = new LiveDetectBase64Req().withVideoBase64(clientConfigurations.getVideoBase64()) - .withActions(clientConfigurations.getActions()).withActionTime(clientConfigurations.getActionTimes()); - result = this.frsClient.detectLiveByBase64(new DetectLiveByBase64Request().withBody(reqBody)); - } else if (!StringUtils.isEmpty(clientConfigurations.getVideoUrl())) { - LiveDetectUrlReq reqBody = new LiveDetectUrlReq().withVideoUrl(clientConfigurations.getVideoUrl()) - .withActions(clientConfigurations.getActions()).withActionTime(clientConfigurations.getActionTimes()); - result = this.frsClient.detectLiveByUrl(new DetectLiveByUrlRequest().withBody(reqBody)); - } else { - File videoFile = getFile(clientConfigurations.getVideoFilePath()); - DetectLiveByFileRequestBody reqBody; - try { - reqBody = new DetectLiveByFileRequestBody().withVideoFile(new FileInputStream(videoFile), videoFile.getName()) + switch (clientConfigurations.getInputSourceType()) { + case BASE64: + LiveDetectBase64Req base64ReqBody = new LiveDetectBase64Req().withVideoBase64(clientConfigurations.getVideoBase64()) .withActions(clientConfigurations.getActions()).withActionTime(clientConfigurations.getActionTimes()); - } catch (FileNotFoundException e) { - throw new IllegalArgumentException( - String.format("Video file not found: %s", clientConfigurations.getImageFilePath())); - } - result = this.frsClient.detectLiveByFile(new DetectLiveByFileRequest().withBody(reqBody)); + result = this.frsClient.detectLiveByBase64(new DetectLiveByBase64Request().withBody(base64ReqBody)); + break; + case URL: + LiveDetectUrlReq urlReqBody = new LiveDetectUrlReq().withVideoUrl(clientConfigurations.getVideoUrl()) + .withActions(clientConfigurations.getActions()).withActionTime(clientConfigurations.getActionTimes()); + result = this.frsClient.detectLiveByUrl(new DetectLiveByUrlRequest().withBody(urlReqBody)); + break; + default: + try (FileInputStream inputStream = new FileInputStream(clientConfigurations.getVideoFilePath())) { + DetectLiveByFileRequestBody fileReqBody = new DetectLiveByFileRequestBody().withVideoFile(inputStream, getFileName(clientConfigurations.getVideoFilePath())) + .withActions(clientConfigurations.getActions()).withActionTime(clientConfigurations.getActionTimes()); + result = this.frsClient.detectLiveByFile(new DetectLiveByFileRequest().withBody(fileReqBody)); + } catch (IOException e) { + throw new IllegalArgumentException( + String.format("Video file path is invalid: %s", clientConfigurations.getVideoFilePath())); + } } exchange.getMessage().setBody(result); } - private File getFile(String filePath) { - File file = new File(filePath); - if (!file.exists() || !file.isFile()) { - throw new IllegalArgumentException(String.format("File path is invalid: %s", file)); - } - return file; + private String getFileName(String filePath) { + return new File(filePath).getName(); } private void updateFaceDetectionConfigurations(Exchange exchange, ClientConfigurations clientConfigurations) { - boolean isImageBase64Set = true; - boolean isImageUrlSet = true; - boolean isImageFilePathSet = true; - String imageBase64 = exchange.getProperty(FaceRecognitionProperties.FACE_IMAGE_BASE64, String.class); - if (!StringUtils.isEmpty(imageBase64)) { - clientConfigurations.setImageBase64(imageBase64); - } else if (!StringUtils.isEmpty(this.endpoint.getImageBase64())) { - clientConfigurations.setImageBase64(this.endpoint.getImageBase64()); - } else { - isImageBase64Set = false; + clientConfigurations.setImageBase64(StringUtils.isEmpty(imageBase64) ? this.endpoint.getImageBase64() : imageBase64); + if (!StringUtils.isEmpty(clientConfigurations.getImageBase64())) { + clientConfigurations.setInputSourceType(InputSourceType.BASE64); + return; } - String imageUrl = exchange.getProperty(FaceRecognitionProperties.FACE_IMAGE_URL, String.class); - if (!StringUtils.isEmpty(imageUrl)) { - clientConfigurations.setImageUrl(imageUrl); - } else if (!StringUtils.isEmpty(this.endpoint.getImageUrl())) { - clientConfigurations.setImageUrl(this.endpoint.getImageUrl()); - } else { - isImageUrlSet = false; + clientConfigurations.setImageUrl(StringUtils.isEmpty(imageUrl) ? this.endpoint.getImageUrl() : imageUrl); + if (!StringUtils.isEmpty(clientConfigurations.getImageUrl())) { + clientConfigurations.setInputSourceType(InputSourceType.URL); + return; } - String imageFilePath = exchange.getProperty(FaceRecognitionProperties.FACE_IMAGE_FILE_PATH, String.class); - if (!StringUtils.isEmpty(imageFilePath)) { - clientConfigurations.setImageFilePath(imageFilePath); - } else if (!StringUtils.isEmpty(this.endpoint.getImageFilePath())) { - clientConfigurations.setImageFilePath(this.endpoint.getImageFilePath()); - } else { - isImageFilePathSet = false; - } - if (!isImageBase64Set && !isImageUrlSet && !isImageFilePathSet) { - throw new IllegalArgumentException("any one of image base64, url and filePath needs to be set"); + clientConfigurations.setImageFilePath(StringUtils.isEmpty(imageFilePath) ? this.endpoint.getImageFilePath() : imageFilePath); + if (!StringUtils.isEmpty(clientConfigurations.getImageFilePath())) { + clientConfigurations.setInputSourceType(InputSourceType.FILE_PATH); + return; } + throw new IllegalArgumentException("any one of image base64, url and filePath needs to be set"); } private void updateFaceVerificationConfigurations(Exchange exchange, ClientConfigurations clientConfigurations) { - boolean isImageBase64Set = true; - boolean isImageUrlSet = true; - boolean isImageFilePathSet = true; - String image1Base64 = exchange.getProperty(FaceRecognitionProperties.FACE_IMAGE_BASE64, String.class); String image2Base64 = exchange.getProperty(FaceRecognitionProperties.ANOTHER_FACE_IMAGE_BASE64, String.class); - if (!StringUtils.isEmpty(image1Base64) && !StringUtils.isEmpty(image2Base64)) { - clientConfigurations.setImageBase64(image1Base64); - clientConfigurations.setAnotherImageBase64(image2Base64); - } else if (!StringUtils.isEmpty(this.endpoint.getImageBase64()) - && !StringUtils.isEmpty(this.endpoint.getAnotherImageBase64())) { - clientConfigurations.setImageBase64(this.endpoint.getImageBase64()); - clientConfigurations.setAnotherImageBase64(this.endpoint.getAnotherImageBase64()); - } else { - isImageBase64Set = false; + clientConfigurations.setImageBase64(StringUtils.isEmpty(image1Base64) ? this.endpoint.getImageBase64() : image1Base64); + clientConfigurations.setAnotherImageBase64(StringUtils.isEmpty(image2Base64) ? this.endpoint.getAnotherImageBase64() : image2Base64); + if (!StringUtils.isEmpty(clientConfigurations.getImageBase64()) && !StringUtils.isEmpty(clientConfigurations.getAnotherImageBase64())) { + clientConfigurations.setInputSourceType(InputSourceType.BASE64); + return; } - String image1Url = exchange.getProperty(FaceRecognitionProperties.FACE_IMAGE_URL, String.class); String image2Url = exchange.getProperty(FaceRecognitionProperties.ANOTHER_FACE_IMAGE_URL, String.class); - if (!StringUtils.isEmpty(image1Url) && !StringUtils.isEmpty(image2Url)) { - clientConfigurations.setImageUrl(image1Url); - clientConfigurations.setAnotherImageUrl(image2Url); - } else if (!StringUtils.isEmpty(this.endpoint.getImageUrl()) - && !StringUtils.isEmpty(this.endpoint.getAnotherImageUrl())) { - clientConfigurations.setImageUrl(this.endpoint.getImageUrl()); - clientConfigurations.setAnotherImageUrl(this.endpoint.getAnotherImageUrl()); - } else { - isImageUrlSet = false; + clientConfigurations.setImageUrl(StringUtils.isEmpty(image1Url) ? this.endpoint.getImageUrl() : image1Url); + clientConfigurations.setAnotherImageUrl(StringUtils.isEmpty(image2Url) ? this.endpoint.getAnotherImageUrl() : image2Url); + if (!StringUtils.isEmpty(clientConfigurations.getImageUrl()) && !StringUtils.isEmpty(clientConfigurations.getAnotherImageUrl())) { + clientConfigurations.setInputSourceType(InputSourceType.URL); + return; } - String image1FilePath = exchange.getProperty(FaceRecognitionProperties.FACE_IMAGE_FILE_PATH, String.class); String image2FilePath = exchange.getProperty(FaceRecognitionProperties.ANOTHER_FACE_IMAGE_FILE_PATH, String.class); - if (!StringUtils.isEmpty(image1FilePath) && !StringUtils.isEmpty(image2FilePath)) { - clientConfigurations.setImageFilePath(image1FilePath); - clientConfigurations.setAnotherImageFilePath(image2FilePath); - } else if (!StringUtils.isEmpty(this.endpoint.getImageFilePath()) - && !StringUtils.isEmpty(this.endpoint.getAnotherImageFilePath())) { - clientConfigurations.setImageFilePath(this.endpoint.getImageFilePath()); - clientConfigurations.setAnotherImageFilePath(this.endpoint.getAnotherImageFilePath()); - } else { - isImageFilePathSet = false; - } - - if (!isImageBase64Set && !isImageUrlSet && !isImageFilePathSet) { - throw new IllegalArgumentException("any one of image base64, url and filePath needs to be set"); + clientConfigurations.setImageFilePath(StringUtils.isEmpty(image1FilePath) ? this.endpoint.getImageFilePath() : image1FilePath); + clientConfigurations.setAnotherImageFilePath(StringUtils.isEmpty(image2FilePath) ? this.endpoint.getAnotherImageFilePath() : image2FilePath); + if (!StringUtils.isEmpty(clientConfigurations.getImageFilePath()) && !StringUtils.isEmpty(clientConfigurations.getAnotherImageFilePath())) { + clientConfigurations.setInputSourceType(InputSourceType.FILE_PATH); + return; } + throw new IllegalArgumentException("any one of image base64, url and filePath needs to be set"); } private void updateLiveDetectConfigurations(Exchange exchange, ClientConfigurations clientConfigurations) { - boolean isVideoBase64Set = true; - boolean isVideoUrlSet = true; - boolean isVideoFilePathSet = true; - - String videoBase64 = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_BASE64, String.class); - if (!StringUtils.isEmpty(videoBase64)) { - clientConfigurations.setVideoBase64(videoBase64); - } else if (!StringUtils.isEmpty(this.endpoint.getVideoBase64())) { - clientConfigurations.setVideoBase64(this.endpoint.getVideoBase64()); - } else { - isVideoBase64Set = false; - } - - String videoUrl = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_URL, String.class); - if (!StringUtils.isEmpty(videoUrl)) { - clientConfigurations.setVideoUrl(videoUrl); - } else if (!StringUtils.isEmpty(this.endpoint.getVideoUrl())) { - clientConfigurations.setVideoUrl(this.endpoint.getVideoUrl()); - } else { - isVideoUrlSet = false; - } - - String videoFilePath = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_FILE_PATH, String.class); - if (!StringUtils.isEmpty(videoFilePath)) { - clientConfigurations.setVideoFilePath(videoFilePath); - } else if (!StringUtils.isEmpty(this.endpoint.getVideoFilePath())) { - clientConfigurations.setVideoFilePath(this.endpoint.getVideoFilePath()); - } else { - isVideoFilePathSet = false; - } - - if (!isVideoBase64Set && !isVideoUrlSet && !isVideoFilePathSet) { - throw new IllegalArgumentException("any one of video base64, url and filePath needs to be set"); - } + updateVideoSource(exchange, clientConfigurations); String actions = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_ACTIONS, String.class); - if (!StringUtils.isEmpty(actions)) { - clientConfigurations.setActions(actions); - } else if (!StringUtils.isEmpty(this.endpoint.getActions())) { - clientConfigurations.setActions(this.endpoint.getActions()); - } else { + clientConfigurations.setActions(StringUtils.isEmpty(actions) ? this.endpoint.getActions() : actions); + if (StringUtils.isEmpty(clientConfigurations.getActions())) { throw new IllegalArgumentException("actions needs to be set"); } - String actionTimes = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_ACTION_TIMES, String.class); clientConfigurations.setActionTimes( StringUtils.isEmpty(actionTimes) ? this.endpoint.getActionTimes() : actionTimes); + } + private void updateVideoSource(Exchange exchange, ClientConfigurations clientConfigurations) { + String videoBase64 = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_BASE64, String.class); + clientConfigurations.setVideoBase64(StringUtils.isEmpty(videoBase64) ? this.endpoint.getVideoBase64() : videoBase64); + if (!StringUtils.isEmpty(clientConfigurations.getVideoBase64())) { + clientConfigurations.setInputSourceType(InputSourceType.BASE64); + return; + } + String videoUrl = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_URL, String.class); + clientConfigurations.setVideoUrl(StringUtils.isEmpty(videoUrl) ? this.endpoint.getVideoUrl() : videoUrl); + if (!StringUtils.isEmpty(clientConfigurations.getVideoUrl())) { + clientConfigurations.setInputSourceType(InputSourceType.URL); + return; + } + String videoFilePath = exchange.getProperty(FaceRecognitionProperties.FACE_VIDEO_FILE_PATH, String.class); + clientConfigurations.setVideoFilePath(StringUtils.isEmpty(videoFilePath) ? this.endpoint.getVideoFilePath() : videoFilePath); + if (!StringUtils.isEmpty(clientConfigurations.getVideoFilePath())) { + clientConfigurations.setInputSourceType(InputSourceType.FILE_PATH); + return; + } + throw new IllegalArgumentException("any one of video base64, url and filePath needs to be set"); } private String getAccessKey(FaceRecognitionEndpoint endpoint) { if (!StringUtils.isEmpty(endpoint.getAccessKey())) { return endpoint.getAccessKey(); - } else if (endpoint.getServiceKeys() != null - && !StringUtils.isEmpty(endpoint.getServiceKeys().getAccessKey())) { + } + if (endpoint.getServiceKeys() != null && !StringUtils.isEmpty(endpoint.getServiceKeys().getAccessKey())) { return endpoint.getServiceKeys().getAccessKey(); - } else { - throw new IllegalArgumentException("authentication parameter access key (AK) not found"); } + throw new IllegalArgumentException("authentication parameter access key (AK) not found"); } private String getSecretKey(FaceRecognitionEndpoint endpoint) { if (!StringUtils.isEmpty(endpoint.getSecretKey())) { return endpoint.getSecretKey(); - } else if (endpoint.getServiceKeys() != null - && !StringUtils.isEmpty(endpoint.getServiceKeys().getSecretKey())) { + } + if (endpoint.getServiceKeys() != null && !StringUtils.isEmpty(endpoint.getServiceKeys().getSecretKey())) { return endpoint.getServiceKeys().getSecretKey(); - } else { - throw new IllegalArgumentException("authentication parameter secret key (SK) not found"); } + throw new IllegalArgumentException("authentication parameter secret key (SK) not found"); } private String getProjectId(FaceRecognitionEndpoint endpoint) { diff --git a/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/models/ClientConfigurations.java b/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/models/ClientConfigurations.java index 7e1fd83..ade42d5 100644 --- a/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/models/ClientConfigurations.java +++ b/components/camel-huawei/camel-huaweicloud-frs/src/main/java/org/apache/camel/component/huaweicloud/frs/models/ClientConfigurations.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.huaweicloud.frs.models; +import org.apache.camel.component.huaweicloud.common.models.InputSourceType; + public class ClientConfigurations { private String accessKey; @@ -58,6 +60,8 @@ public class ClientConfigurations { private String actionTimes; + private InputSourceType inputSourceType; + public String getAccessKey() { return accessKey; } @@ -217,4 +221,13 @@ public class ClientConfigurations { public void setActionTimes(String actionTimes) { this.actionTimes = actionTimes; } + + public InputSourceType getInputSourceType() { + return inputSourceType; + } + + public void setInputSourceType(InputSourceType inputSourceType) { + this.inputSourceType = inputSourceType; + } + } diff --git a/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionInvalidParamsTest.java b/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionInvalidParamsTest.java index 4ecc6552c5..4e69702 100644 --- a/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionInvalidParamsTest.java +++ b/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/FaceRecognitionInvalidParamsTest.java @@ -22,8 +22,7 @@ import org.apache.camel.component.huaweicloud.frs.constants.FaceRecognitionPrope import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { private final TestConfiguration testConfiguration = new TestConfiguration(); @@ -35,91 +34,91 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { public void configure() { from("direct:access_key_not_set") .to("hwcloud-frs:faceDetection?" - + "secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:secret_key_not_set") .to("hwcloud-frs:faceDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:project_id_not_set") .to("hwcloud-frs:faceDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:region_id_not_set") .to("hwcloud-frs:faceDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:operation_not_set") .to("hwcloud-frs:?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:operation_invalid") .to("hwcloud-frs:test?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_detection_image_not_set") .to("hwcloud-frs:faceDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_detection_image_file_not_found") .setProperty(FaceRecognitionProperties.FACE_IMAGE_FILE_PATH, constant(testFilePath)) .to("hwcloud-frs:faceDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_verification_image_not_set") .to("hwcloud-frs:faceVerification?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_verification_only_one_image_set") .setProperty(FaceRecognitionProperties.FACE_IMAGE_FILE_PATH, constant(testConfiguration.getProperty("imageFilePath"))) .to("hwcloud-frs:faceVerification?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_verification_image_sources_not_match") @@ -128,11 +127,11 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { .setProperty(FaceRecognitionProperties.ANOTHER_FACE_IMAGE_URL, constant(testConfiguration.getProperty("imageFilePath"))) .to("hwcloud-frs:faceVerification?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_verification_image_file_not_found") @@ -140,43 +139,43 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { .setProperty(FaceRecognitionProperties.ANOTHER_FACE_IMAGE_FILE_PATH, constant(testConfiguration.getProperty("imageFilePath"))) .to("hwcloud-frs:faceVerification?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_live_detection_video_not_set") .to("hwcloud-frs:faceLiveDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&actions=1,2,3" - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&actions=1,2,3" + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_live_detection_video_file_not_found") .setProperty(FaceRecognitionProperties.FACE_VIDEO_FILE_PATH, constant(testFilePath)) .to("hwcloud-frs:faceLiveDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&actions=1,2,3" - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&actions=1,2,3" + + "&ignoreSslVerification=true") .to("mock:result"); from("direct:face_live_detection_actions_not_set") .setProperty(FaceRecognitionProperties.FACE_VIDEO_FILE_PATH, constant(testConfiguration.getProperty("videoFilePath"))) .to("hwcloud-frs:faceLiveDetection?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true") .to("mock:result"); } }; @@ -191,7 +190,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:access_key_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "authentication parameter access key (AK) not found"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -203,7 +202,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:secret_key_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "authentication parameter secret key (SK) not found"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -215,7 +214,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:project_id_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "Project id not found"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -227,7 +226,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:region_id_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "either endpoint or region needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -239,7 +238,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:operation_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "operation needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -251,7 +250,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:operation_invalid", "")); assertTrue(exception.getCause() instanceof UnsupportedOperationException); String expectedMessage = "operation needs to be faceDetection, faceVerification or faceLiveDetection"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -263,7 +262,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { () -> template.sendBody("direct:face_detection_image_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "any one of image base64, url and filePath needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -274,8 +273,8 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { Exception exception = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:face_detection_image_file_not_found", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); - String expectedMessage = String.format("File path is invalid: %s", testFilePath); - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + String expectedMessage = String.format("Image file path is invalid: %s", testFilePath); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -287,7 +286,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { () -> template.sendBody("direct:face_verification_image_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "any one of image base64, url and filePath needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -299,7 +298,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { () -> template.sendBody("direct:face_verification_only_one_image_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "any one of image base64, url and filePath needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -313,7 +312,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { () -> template.sendBody("direct:face_verification_image_sources_not_match", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "any one of image base64, url and filePath needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -324,8 +323,8 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { Exception exception = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:face_verification_image_file_not_found", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); - String expectedMessage = String.format("File path is invalid: %s", testFilePath); - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + String expectedMessage = String.format("Image file paths are invalid: %s, %s", testFilePath, testConfiguration.getProperty("imageFilePath")); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -337,7 +336,7 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { () -> template.sendBody("direct:face_live_detection_video_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "any one of video base64, url and filePath needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -348,8 +347,8 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { Exception exception = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:face_live_detection_video_file_not_found", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); - String expectedMessage = String.format("File path is invalid: %s", testFilePath); - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + String expectedMessage = String.format("Video file path is invalid: %s", testFilePath); + assertEquals(exception.getCause().getMessage(), expectedMessage); } /** @@ -361,6 +360,6 @@ public class FaceRecognitionInvalidParamsTest extends CamelTestSupport { () -> template.sendBody("direct:face_live_detection_actions_not_set", "")); assertTrue(exception.getCause() instanceof IllegalArgumentException); String expectedMessage = "actions needs to be set"; - assertTrue(exception.getCause().getMessage().contains(expectedMessage)); + assertEquals(exception.getCause().getMessage(), expectedMessage); } } diff --git a/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/FaceVerificationWithImageBae64AndMockClientTest.java b/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/FaceVerificationWithImageBae64AndMockClientTest.java index e81901b..70cdfbd 100644 --- a/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/FaceVerificationWithImageBae64AndMockClientTest.java +++ b/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/FaceVerificationWithImageBae64AndMockClientTest.java @@ -38,20 +38,34 @@ public class FaceVerificationWithImageBae64AndMockClientTest extends CamelTestSu protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { - from("direct:trigger_route") + from("direct:trigger_route_01") .setProperty(FaceRecognitionProperties.FACE_IMAGE_BASE64, constant(testConfiguration.getProperty("imageBase64"))) .setProperty(FaceRecognitionProperties.ANOTHER_FACE_IMAGE_BASE64, constant(testConfiguration.getProperty("anotherImageBase64"))) .to("hwcloud-frs:faceVerification?" - + "accessKey=" + testConfiguration.getProperty("accessKey") - + "&secretKey=" + testConfiguration.getProperty("secretKey") - + "&projectId=" + testConfiguration.getProperty("projectId") - + "®ion=" + testConfiguration.getProperty("region") - + "&ignoreSslVerification=true" - + "&frsClient=#frsClient") + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&ignoreSslVerification=true" + + "&frsClient=#frsClient") .log("perform faceVerification successfully") - .to("mock:perform_face_verification_result"); + .to("mock:perform_face_verification_result_01"); + + from("direct:trigger_route_02") + .setProperty(FaceRecognitionProperties.FACE_IMAGE_BASE64, + constant(testConfiguration.getProperty("imageBase64"))) + .to("hwcloud-frs:faceVerification?" + + "accessKey=" + testConfiguration.getProperty("accessKey") + + "&secretKey=" + testConfiguration.getProperty("secretKey") + + "&projectId=" + testConfiguration.getProperty("projectId") + + "®ion=" + testConfiguration.getProperty("region") + + "&anotherImageBase64=" + constant(testConfiguration.getProperty("anotherImageBase64")) + + "&ignoreSslVerification=true" + + "&frsClient=#frsClient") + .log("perform faceVerification successfully") + .to("mock:perform_face_verification_result_02"); } }; } @@ -62,10 +76,30 @@ public class FaceVerificationWithImageBae64AndMockClientTest extends CamelTestSu * @throws Exception */ @Test - public void testFaceVerification() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:perform_face_verification_result"); + public void testFaceVerification01() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:perform_face_verification_result_01"); + mock.expectedMinimumMessageCount(1); + template.sendBody("direct:trigger_route_01", ""); + Exchange responseExchange = mock.getExchanges().get(0); + mock.assertIsSatisfied(); + + assertTrue(responseExchange.getIn().getBody() instanceof CompareFaceByBase64Response); + CompareFaceByBase64Response response = (CompareFaceByBase64Response) responseExchange.getIn().getBody(); + assertEquals(response.getImage1Face(), MockResult.getCompareFaceResult()); + assertEquals(response.getImage2Face(), MockResult.getCompareFaceResult()); + assertEquals(response.getSimilarity(), 1.0); + } + + /** + * use imageBase64 to perform faceVerification + * + * @throws Exception + */ + @Test + public void testFaceVerification02() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:perform_face_verification_result_02"); mock.expectedMinimumMessageCount(1); - template.sendBody("direct:trigger_route", ""); + template.sendBody("direct:trigger_route_02", ""); Exchange responseExchange = mock.getExchanges().get(0); mock.assertIsSatisfied(); diff --git a/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/LiveDetectionWithVideoUrlAndMockClientTest.java b/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/LiveDetectionWithVideoUrlAndMockClientTest.java index 79db135..9259691 100644 --- a/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/LiveDetectionWithVideoUrlAndMockClientTest.java +++ b/components/camel-huawei/camel-huaweicloud-frs/src/test/java/org/apache/camel/component/huaweicloud/frs/mock/LiveDetectionWithVideoUrlAndMockClientTest.java @@ -61,7 +61,7 @@ public class LiveDetectionWithVideoUrlAndMockClientTest extends CamelTestSupport * @throws Exception */ @Test - public void testFaceDetection() throws Exception { + public void testFaceLiveDetection() throws Exception { MockEndpoint mock = getMockEndpoint("mock:perform_live_detection_result"); mock.expectedMinimumMessageCount(1); template.sendBody("direct:trigger_route", "");