diff --git a/.github/workflows/check-badges.yml b/.github/workflows/check-badges.yml index d673011..0232d29 100644 --- a/.github/workflows/check-badges.yml +++ b/.github/workflows/check-badges.yml @@ -2,16 +2,16 @@ name: Check badges in README.md on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: build-and-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Check badges in README.md - run: ./scripts/check-badges.bash "README.md" + - name: Check badges in README.md + run: ./scripts/check-badges.bash "README.md" diff --git a/.github/workflows/check-style.yml b/.github/workflows/check-style.yml index bdd456d..7735e13 100644 --- a/.github/workflows/check-style.yml +++ b/.github/workflows/check-style.yml @@ -2,20 +2,20 @@ name: Java check style on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: 11 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v3 + with: + distribution: "corretto" + java-version: 11 - - name: Lint with CheckStyle - run: ./scripts/checkstyle.bash + - name: Lint with CheckStyle + run: ./scripts/checkstyle.bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0d41381 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +name: Java CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + name: test with Java version ${{ matrix.java-version }} + runs-on: ubuntu-latest + strategy: + matrix: + java-version: [11, 21] + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK ${{ matrix.java-version }} + uses: actions/setup-java@v4 + with: + # Use same in Dockerfile + distribution: "corretto" + java-version: ${{ matrix.java-version }} + cache: "maven" + + - name: Maven Compile + run: mvn compile + + - name: Test with Maven + env: + TEST_CONFIGURATION_ACCESS_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }} + run: | + chmod +x scripts/* + make build + make test + + android-test: + needs: test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: 17 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build Java library JAR + run: mvn package -Dmaven.test.skip=true + + - name: Accept Android SDK Licenses + run: yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses + + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Cache AVD + uses: actions/cache@v4 + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-pixel2-api30-atd + + - name: Run Android Tests + working-directory: android-test + run: > + ./gradlew pixel2api30DebugAndroidTest + -Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 3eb934b..0000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,40 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - # Use same in Dockerfile - distribution: 'corretto' - java-version: 11 - cache: 'maven' - - - name: Maven Compile - run: mvn compile - - - name: Test with Maven - env: - TEST_CONFIGURATION_ACCESS_TOKEN: ${{ secrets.TEST_CONFIGURATION_ACCESS_TOKEN }} - run: | - chmod +x scripts/* - make build - make test - - # TODO: Move to pack.yml - # - name: Build the Docker image - # run: docker build . --file Dockerfile diff --git a/.gitignore b/.gitignore index 236b512..f8b29b9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,10 @@ build aspose-barcode-cloud.iml !tools/* +!**/gradle-wrapper.jar .idea +.gradle +local.properties **/configuration*.json snippets_test/ diff --git a/Makefile b/Makefile index 97e73f2..31f9dcc 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ build: .PHONY: test test: mvn test + mvn dependency:copy-dependencies -DoutputDirectory=target/lib/ ./scripts/run_snippets.sh .PHONY: display-updates diff --git a/README.md b/README.md index b9fcf9d..51318f8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Aspose.BarCode Cloud SDK for Java [![License](https://img.shields.io/github/license/aspose-barcode-cloud/aspose-barcode-cloud-java)](LICENSE) -[![Java CI with Maven](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/maven.yml/badge.svg?branch=main)](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/maven.yml) +[![Java CI with Maven](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/actions/workflows/ci.yml) [![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Freleases.aspose.cloud%2Fjava%2Frepo%2Fcom%2Faspose%2Faspose-barcode-cloud%2Fmaven-metadata.xml)](https://releases.aspose.cloud/java/repo/com/aspose/aspose-barcode-cloud/) - API version: 4.0 diff --git a/android-test/build.gradle b/android-test/build.gradle new file mode 100644 index 0000000..240288b --- /dev/null +++ b/android-test/build.gradle @@ -0,0 +1,58 @@ +plugins { + id 'com.android.library' version '9.1.0' +} + +android { + namespace 'com.aspose.barcode.cloud.androidtest' + compileSdk 35 + + defaultConfig { + minSdk 23 + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + sourceSets { + androidTest { + java { + srcDirs = ['../src/test/java'] + exclude 'com/aspose/barcode/cloud/test/**' + exclude 'com/aspose/barcode/cloud/examples/**' + } + } + } + + testOptions { + managedDevices { + localDevices { + pixel2api30 { + device = "Pixel 2" + apiLevel = 30 + systemImageSource = "aosp-atd" + } + } + } + } +} + +dependencies { + implementation fileTree( + dir: '../target', + include: ['aspose-barcode-cloud-*.jar'], + exclude: [ + 'aspose-barcode-cloud-*-sources.jar', + 'aspose-barcode-cloud-*-javadoc.jar' + ] + ) + implementation 'com.google.code.gson:gson:2.13.2' + implementation 'io.gsonfire:gson-fire:1.9.0' + implementation 'com.squareup.okhttp3:okhttp:5.3.2' + implementation 'io.swagger:swagger-annotations:1.6.16' + androidTestImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test:runner:1.5.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' +} diff --git a/android-test/gradle/wrapper/gradle-wrapper.jar b/android-test/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/android-test/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android-test/gradle/wrapper/gradle-wrapper.properties b/android-test/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..8eb3695 --- /dev/null +++ b/android-test/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jan 27 19:13:42 YEKT 2023 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/android-test/gradlew b/android-test/gradlew new file mode 100755 index 0000000..4f906e0 --- /dev/null +++ b/android-test/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 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. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/android-test/gradlew.bat b/android-test/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/android-test/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/android-test/settings.gradle b/android-test/settings.gradle new file mode 100644 index 0000000..2f9bfa6 --- /dev/null +++ b/android-test/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +rootProject.name = 'android-test' diff --git a/android-test/src/main/AndroidManifest.xml b/android-test/src/main/AndroidManifest.xml new file mode 100644 index 0000000..19d2638 --- /dev/null +++ b/android-test/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/pom.xml b/pom.xml index 3ac4fc1..d296c3b 100644 --- a/pom.xml +++ b/pom.xml @@ -141,6 +141,52 @@ + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + prepare-agent + + prepare-agent + + + + report + test + + report + + + + check + test + + check + + + + + CLASS + + com.aspose.barcode.cloud.api.GenerateApi + com.aspose.barcode.cloud.api.RecognizeApi + com.aspose.barcode.cloud.api.ScanApi + + + + METHOD + COVEREDRATIO + 0.81 + + + + + + + + org.codehaus.mojo versions-maven-plugin @@ -202,6 +248,7 @@ 5.3.2 1.0.0 4.13.2 + 0.8.12 2.21.0 UTF-8 diff --git a/snippets/read/set-image-kind/RecognizeBody.java b/snippets/read/set-image-kind/RecognizeBody.java index 60a6fb2..0607d11 100644 --- a/snippets/read/set-image-kind/RecognizeBody.java +++ b/snippets/read/set-image-kind/RecognizeBody.java @@ -43,7 +43,7 @@ public static void main(String[] args) { Arrays.asList(DecodeBarcodeType.QR, DecodeBarcodeType.PDF417), encodedString); - request.setRecognitionMode(RecognitionMode.NORMAL); + request.setRecognitionMode(RecognitionMode.FAST); BarcodeResponseList response = recognizeApi.recognizeBase64(new RecognizeBase64RequestWrapper(request)); diff --git a/snippets/read/set-quality/RecognizeBody.java b/snippets/read/set-quality/RecognizeBody.java index 60a6fb2..0607d11 100644 --- a/snippets/read/set-quality/RecognizeBody.java +++ b/snippets/read/set-quality/RecognizeBody.java @@ -43,7 +43,7 @@ public static void main(String[] args) { Arrays.asList(DecodeBarcodeType.QR, DecodeBarcodeType.PDF417), encodedString); - request.setRecognitionMode(RecognitionMode.NORMAL); + request.setRecognitionMode(RecognitionMode.FAST); BarcodeResponseList response = recognizeApi.recognizeBase64(new RecognizeBase64RequestWrapper(request)); diff --git a/snippets/read/set-target-types/RecognizeBody.java b/snippets/read/set-target-types/RecognizeBody.java index 4874fd6..342296f 100644 --- a/snippets/read/set-target-types/RecognizeBody.java +++ b/snippets/read/set-target-types/RecognizeBody.java @@ -42,7 +42,7 @@ public static void main(String[] args) { new RecognizeBase64Request( Arrays.asList(DecodeBarcodeType.QR, DecodeBarcodeType.CODE128), encodedString); - request.setRecognitionMode(RecognitionMode.NORMAL); + request.setRecognitionMode(RecognitionMode.FAST); BarcodeResponseList response = recognizeApi.recognizeBase64(new RecognizeBase64RequestWrapper(request)); diff --git a/src/main/java/com/aspose/barcode/cloud/api/GenerateApi.java b/src/main/java/com/aspose/barcode/cloud/api/GenerateApi.java index 74672f6..0643bc6 100644 --- a/src/main/java/com/aspose/barcode/cloud/api/GenerateApi.java +++ b/src/main/java/com/aspose/barcode/cloud/api/GenerateApi.java @@ -71,7 +71,7 @@ protected okhttp3.Call generateCall( // create path and map variables String path = "/barcode/generate/{barcodeType}" - .replaceAll("\\{" + "barcodeType" + "}", request.barcodeType.toString()); + .replace("{" + "barcodeType" + "}", request.barcodeType.toString()); List queryParams = new ArrayList<>(); List collectionQueryParams = new ArrayList<>(); diff --git a/src/test/java/com/aspose/barcode/cloud/api/GenerateApiUnitTest.java b/src/test/java/com/aspose/barcode/cloud/api/GenerateApiUnitTest.java new file mode 100644 index 0000000..3525d74 --- /dev/null +++ b/src/test/java/com/aspose/barcode/cloud/api/GenerateApiUnitTest.java @@ -0,0 +1,338 @@ +package com.aspose.barcode.cloud.api; + +import static org.junit.Assert.*; + +import com.aspose.barcode.cloud.ApiCallback; +import com.aspose.barcode.cloud.ApiClient; +import com.aspose.barcode.cloud.ApiException; +import com.aspose.barcode.cloud.model.*; +import com.aspose.barcode.cloud.requests.GenerateBodyRequestWrapper; +import com.aspose.barcode.cloud.requests.GenerateMultipartRequestWrapper; +import com.aspose.barcode.cloud.requests.GenerateRequestWrapper; + +import okhttp3.Request; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.util.List; +import java.util.Map; + +public class GenerateApiUnitTest { + + private static final String FAKE_TOKEN = "fake-test-token"; + private static GenerateApi api; + + @BeforeClass + public static void setUp() { + ApiClient apiClient = new ApiClient(FAKE_TOKEN); + api = new GenerateApi(apiClient); + } + + // --- Group A: Validation tests --- + + @Test(expected = ApiException.class) + public void testGenerate_NullBarcodeType_ThrowsApiException() throws ApiException { + api.generate(new GenerateRequestWrapper(null, "data")); + } + + @Test(expected = ApiException.class) + public void testGenerate_NullData_ThrowsApiException() throws ApiException { + api.generate(new GenerateRequestWrapper(EncodeBarcodeType.QR, null)); + } + + @Test + public void testGenerate_NullBarcodeType_ErrorMessage() { + try { + api.generate(new GenerateRequestWrapper(null, "data")); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.barcodeType")); + } + } + + @Test + public void testGenerate_NullData_ErrorMessage() { + try { + api.generate(new GenerateRequestWrapper(EncodeBarcodeType.QR, null)); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.data")); + } + } + + @Test(expected = ApiException.class) + public void testGenerateBody_NullParams_ThrowsApiException() throws ApiException { + api.generateBody(new GenerateBodyRequestWrapper(null)); + } + + @Test(expected = ApiException.class) + public void testGenerateMultipart_NullBarcodeType_ThrowsApiException() throws ApiException { + api.generateMultipart(new GenerateMultipartRequestWrapper(null, "data")); + } + + @Test(expected = ApiException.class) + public void testGenerateMultipart_NullData_ThrowsApiException() throws ApiException { + api.generateMultipart(new GenerateMultipartRequestWrapper(EncodeBarcodeType.QR, null)); + } + + // --- Group B: Path construction tests --- + + @Test + public void testGenerateCall_QR_Path() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"); + Request httpRequest = api.generateCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/generate/QR")); + } + + @Test + public void testGenerateCall_Code128_Path() throws ApiException { + GenerateRequestWrapper request = + new GenerateRequestWrapper(EncodeBarcodeType.CODE128, "test"); + Request httpRequest = api.generateCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/generate/Code128")); + } + + @Test + public void testGenerateCall_GS1Code128_Path() throws ApiException { + GenerateRequestWrapper request = + new GenerateRequestWrapper(EncodeBarcodeType.GS1_CODE128, "test"); + Request httpRequest = api.generateCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/generate/GS1Code128")); + } + + @Test + public void testGenerateCall_AllEnumTypes_Path() throws ApiException { + for (EncodeBarcodeType type : EncodeBarcodeType.values()) { + GenerateRequestWrapper request = new GenerateRequestWrapper(type, "test"); + Request httpRequest = api.generateCall(request, null, null).request(); + String url = httpRequest.url().toString(); + assertTrue( + "URL should contain '" + type.toString() + "' for enum " + type.name(), + url.contains("/barcode/generate/" + type.toString())); + } + } + + @Test + public void testGenerateCall_HttpMethodIsGet() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"); + Request httpRequest = api.generateCall(request, null, null).request(); + assertEquals("GET", httpRequest.method()); + } + + @Test + public void testGenerateBodyCall_PathAndMethod() throws ApiException { + EncodeData encodeData = new EncodeData("test"); + GenerateParams params = new GenerateParams(EncodeBarcodeType.QR, encodeData); + GenerateBodyRequestWrapper request = new GenerateBodyRequestWrapper(params); + Request httpRequest = api.generateBodyCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/generate-body")); + assertEquals("POST", httpRequest.method()); + } + + @Test + public void testGenerateMultipartCall_PathAndMethod() throws ApiException { + GenerateMultipartRequestWrapper request = + new GenerateMultipartRequestWrapper(EncodeBarcodeType.QR, "test"); + Request httpRequest = api.generateMultipartCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/generate-multipart")); + assertEquals("POST", httpRequest.method()); + } + + // --- Group C: Query parameter tests --- + + @Test + public void testGenerateCall_RequiredParamsOnly_DefaultsPresent() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "hello"); + String url = api.generateCall(request, null, null).request().url().toString(); + + assertTrue(url.contains("data=")); + assertTrue(url.contains("foregroundColor=")); + assertTrue(url.contains("backgroundColor=")); + assertFalse(url.contains("imageFormat=")); + assertFalse(url.contains("textLocation=")); + assertFalse(url.contains("units=")); + assertFalse(url.contains("resolution=")); + assertFalse(url.contains("imageHeight=")); + assertFalse(url.contains("imageWidth=")); + assertFalse(url.contains("rotationAngle=")); + } + + @Test + public void testGenerateCall_WithImageFormat() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"); + request.imageFormat = BarcodeImageFormat.PNG; + String url = api.generateCall(request, null, null).request().url().toString(); + assertTrue(url.contains("imageFormat=Png")); + } + + @Test + public void testGenerateCall_WithResolution() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"); + request.resolution = 300.0f; + String url = api.generateCall(request, null, null).request().url().toString(); + assertTrue(url.contains("resolution=300")); + } + + @Test + public void testGenerateCall_WithDataType() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"); + request.dataType = EncodeDataType.BASE64_BYTES; + String url = api.generateCall(request, null, null).request().url().toString(); + assertTrue(url.contains("dataType=Base64Bytes")); + } + + @Test + public void testGenerateCall_WithAllOptionalParams() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"); + request.dataType = EncodeDataType.STRING_DATA; + request.imageFormat = BarcodeImageFormat.JPEG; + request.textLocation = CodeLocation.BELOW; + request.foregroundColor = "Red"; + request.backgroundColor = "Blue"; + request.units = GraphicsUnit.PIXEL; + request.resolution = 150.0f; + request.imageHeight = 200.0f; + request.imageWidth = 400.0f; + request.rotationAngle = 90; + + String url = api.generateCall(request, null, null).request().url().toString(); + assertTrue(url.contains("dataType=")); + assertTrue(url.contains("imageFormat=")); + assertTrue(url.contains("textLocation=")); + assertTrue(url.contains("foregroundColor=")); + assertTrue(url.contains("backgroundColor=")); + assertTrue(url.contains("units=")); + assertTrue(url.contains("resolution=")); + assertTrue(url.contains("imageHeight=")); + assertTrue(url.contains("imageWidth=")); + assertTrue(url.contains("rotationAngle=")); + } + + // --- Group D: Content-Type and body tests --- + + @Test + public void testGenerateBodyCall_ContentTypeJson() throws ApiException { + EncodeData encodeData = new EncodeData("test"); + GenerateParams params = new GenerateParams(EncodeBarcodeType.QR, encodeData); + GenerateBodyRequestWrapper request = new GenerateBodyRequestWrapper(params); + Request httpRequest = api.generateBodyCall(request, null, null).request(); + String contentType = httpRequest.header("Content-Type"); + assertTrue(contentType.contains("application/json")); + } + + @Test + public void testGenerateBodyCall_HasBody() throws ApiException { + EncodeData encodeData = new EncodeData("test"); + GenerateParams params = new GenerateParams(EncodeBarcodeType.QR, encodeData); + GenerateBodyRequestWrapper request = new GenerateBodyRequestWrapper(params); + Request httpRequest = api.generateBodyCall(request, null, null).request(); + assertNotNull(httpRequest.body()); + } + + @Test + public void testGenerateMultipartCall_ContentTypeMultipart() throws ApiException { + GenerateMultipartRequestWrapper request = + new GenerateMultipartRequestWrapper(EncodeBarcodeType.QR, "test"); + Request httpRequest = api.generateMultipartCall(request, null, null).request(); + String contentType = httpRequest.header("Content-Type"); + assertTrue(contentType.contains("multipart/form-data")); + } + + @Test + public void testGenerateCall_AuthorizationHeader() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"); + Request httpRequest = api.generateCall(request, null, null).request(); + assertEquals("Bearer " + FAKE_TOKEN, httpRequest.header("Authorization")); + } + + // --- Group E: Edge cases --- + + @Test + public void testGenerateCall_SpecialCharactersInData() throws ApiException { + GenerateRequestWrapper request = + new GenerateRequestWrapper(EncodeBarcodeType.QR, "Hello World!@#$%"); + Request httpRequest = api.generateCall(request, null, null).request(); + assertNotNull(httpRequest.url()); + } + + @Test + public void testGenerateCall_EmptyStringData() throws ApiException { + GenerateRequestWrapper request = new GenerateRequestWrapper(EncodeBarcodeType.QR, ""); + Request httpRequest = api.generateCall(request, null, null).request(); + assertNotNull(httpRequest.url()); + } + + // --- Group F: Public method coverage --- + + private static final ApiCallback NO_OP_CALLBACK = + new ApiCallback() { + @Override + public void onFailure( + ApiException e, int statusCode, Map> headers) {} + + @Override + public void onSuccess( + File result, int statusCode, Map> headers) {} + + @Override + public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {} + + @Override + public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {} + }; + + @Test(expected = ApiException.class) + public void testGenerate_CallsExecute() throws ApiException { + api.generate(new GenerateRequestWrapper(EncodeBarcodeType.QR, "test")); + } + + @Test(expected = ApiException.class) + public void testGenerateWithHttpInfo_CallsExecute() throws ApiException { + api.generateWithHttpInfo(new GenerateRequestWrapper(EncodeBarcodeType.QR, "test")); + } + + @Test(expected = UnsupportedOperationException.class) + public void testGenerateAsync_CallsEnqueue() throws ApiException { + api.generateAsync(new GenerateRequestWrapper(EncodeBarcodeType.QR, "test"), NO_OP_CALLBACK); + } + + @Test(expected = ApiException.class) + public void testGenerateBody_CallsExecute() throws ApiException { + EncodeData encodeData = new EncodeData("test"); + GenerateParams params = new GenerateParams(EncodeBarcodeType.QR, encodeData); + api.generateBody(new GenerateBodyRequestWrapper(params)); + } + + @Test(expected = ApiException.class) + public void testGenerateBodyWithHttpInfo_CallsExecute() throws ApiException { + EncodeData encodeData = new EncodeData("test"); + GenerateParams params = new GenerateParams(EncodeBarcodeType.QR, encodeData); + api.generateBodyWithHttpInfo(new GenerateBodyRequestWrapper(params)); + } + + @Test(expected = UnsupportedOperationException.class) + public void testGenerateBodyAsync_CallsEnqueue() throws ApiException { + EncodeData encodeData = new EncodeData("test"); + GenerateParams params = new GenerateParams(EncodeBarcodeType.QR, encodeData); + api.generateBodyAsync(new GenerateBodyRequestWrapper(params), NO_OP_CALLBACK); + } + + @Test(expected = ApiException.class) + public void testGenerateMultipart_CallsExecute() throws ApiException { + api.generateMultipart(new GenerateMultipartRequestWrapper(EncodeBarcodeType.QR, "test")); + } + + @Test(expected = ApiException.class) + public void testGenerateMultipartWithHttpInfo_CallsExecute() throws ApiException { + api.generateMultipartWithHttpInfo( + new GenerateMultipartRequestWrapper(EncodeBarcodeType.QR, "test")); + } + + @Test(expected = UnsupportedOperationException.class) + public void testGenerateMultipartAsync_CallsEnqueue() throws ApiException { + api.generateMultipartAsync( + new GenerateMultipartRequestWrapper(EncodeBarcodeType.QR, "test"), NO_OP_CALLBACK); + } +} diff --git a/src/test/java/com/aspose/barcode/cloud/api/RecognizeApiUnitTest.java b/src/test/java/com/aspose/barcode/cloud/api/RecognizeApiUnitTest.java new file mode 100644 index 0000000..af203f5 --- /dev/null +++ b/src/test/java/com/aspose/barcode/cloud/api/RecognizeApiUnitTest.java @@ -0,0 +1,321 @@ +package com.aspose.barcode.cloud.api; + +import static org.junit.Assert.*; + +import com.aspose.barcode.cloud.ApiCallback; +import com.aspose.barcode.cloud.ApiClient; +import com.aspose.barcode.cloud.ApiException; +import com.aspose.barcode.cloud.model.BarcodeResponseList; +import com.aspose.barcode.cloud.model.DecodeBarcodeType; +import com.aspose.barcode.cloud.model.RecognitionImageKind; +import com.aspose.barcode.cloud.model.RecognitionMode; +import com.aspose.barcode.cloud.model.RecognizeBase64Request; +import com.aspose.barcode.cloud.requests.RecognizeBase64RequestWrapper; +import com.aspose.barcode.cloud.requests.RecognizeMultipartRequestWrapper; +import com.aspose.barcode.cloud.requests.RecognizeRequestWrapper; + +import okhttp3.Request; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class RecognizeApiUnitTest { + + private static final String FAKE_TOKEN = "fake-test-token"; + private static RecognizeApi api; + + @BeforeClass + public static void setUp() { + ApiClient apiClient = new ApiClient(FAKE_TOKEN); + api = new RecognizeApi(apiClient); + } + + // --- Validation tests --- + + @Test(expected = ApiException.class) + public void testRecognize_NullBarcodeType_ThrowsApiException() throws Exception { + api.recognize(new RecognizeRequestWrapper(null, new URI("https://example.com/img.png"))); + } + + @Test(expected = ApiException.class) + public void testRecognize_NullFileUrl_ThrowsApiException() throws Exception { + api.recognize(new RecognizeRequestWrapper(DecodeBarcodeType.QR, null)); + } + + @Test + public void testRecognize_NullBarcodeType_ErrorMessage() throws Exception { + try { + api.recognize( + new RecognizeRequestWrapper(null, new URI("https://example.com/img.png"))); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.barcodeType")); + } + } + + @Test + public void testRecognize_NullFileUrl_ErrorMessage() throws Exception { + try { + api.recognize(new RecognizeRequestWrapper(DecodeBarcodeType.QR, null)); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.fileUrl")); + } + } + + @Test(expected = ApiException.class) + public void testRecognizeBase64_NullRequest_ThrowsApiException() throws ApiException { + api.recognizeBase64(new RecognizeBase64RequestWrapper(null)); + } + + @Test + public void testRecognizeBase64_NullRequest_ErrorMessage() { + try { + api.recognizeBase64(new RecognizeBase64RequestWrapper(null)); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.recognizeBase64Request")); + } + } + + @Test(expected = ApiException.class) + public void testRecognizeMultipart_NullBarcodeType_ThrowsApiException() throws ApiException { + api.recognizeMultipart(new RecognizeMultipartRequestWrapper(null, new File("dummy.png"))); + } + + @Test(expected = ApiException.class) + public void testRecognizeMultipart_NullFile_ThrowsApiException() throws ApiException { + api.recognizeMultipart(new RecognizeMultipartRequestWrapper(DecodeBarcodeType.QR, null)); + } + + @Test + public void testRecognizeMultipart_NullBarcodeType_ErrorMessage() { + try { + api.recognizeMultipart( + new RecognizeMultipartRequestWrapper(null, new File("dummy.png"))); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.barcodeType")); + } + } + + @Test + public void testRecognizeMultipart_NullFile_ErrorMessage() { + try { + api.recognizeMultipart( + new RecognizeMultipartRequestWrapper(DecodeBarcodeType.QR, null)); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.file")); + } + } + + // --- Path construction tests --- + + @Test + public void testRecognizeCall_Path() throws Exception { + RecognizeRequestWrapper request = + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")); + Request httpRequest = api.recognizeCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/recognize")); + } + + @Test + public void testRecognizeCall_HttpMethodIsGet() throws Exception { + RecognizeRequestWrapper request = + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")); + Request httpRequest = api.recognizeCall(request, null, null).request(); + assertEquals("GET", httpRequest.method()); + } + + @Test + public void testRecognizeBase64Call_PathAndMethod() throws ApiException { + RecognizeBase64Request body = + new RecognizeBase64Request(Arrays.asList(DecodeBarcodeType.QR), "dGVzdA=="); + RecognizeBase64RequestWrapper request = new RecognizeBase64RequestWrapper(body); + Request httpRequest = api.recognizeBase64Call(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/recognize-body")); + assertEquals("POST", httpRequest.method()); + } + + @Test + public void testRecognizeMultipartCall_PathAndMethod() throws ApiException { + RecognizeMultipartRequestWrapper request = + new RecognizeMultipartRequestWrapper(DecodeBarcodeType.QR, new File("dummy.png")); + Request httpRequest = api.recognizeMultipartCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/recognize-multipart")); + assertEquals("POST", httpRequest.method()); + } + + // --- Query parameter tests --- + + @Test + public void testRecognizeCall_QueryContainsBarcodeType() throws Exception { + RecognizeRequestWrapper request = + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")); + String url = api.recognizeCall(request, null, null).request().url().toString(); + assertTrue(url.contains("barcodeType=")); + } + + @Test + public void testRecognizeCall_QueryContainsFileUrl() throws Exception { + RecognizeRequestWrapper request = + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")); + String url = api.recognizeCall(request, null, null).request().url().toString(); + assertTrue(url.contains("fileUrl=")); + } + + @Test + public void testRecognizeCall_WithOptionalParams() throws Exception { + RecognizeRequestWrapper request = + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")); + request.recognitionMode = RecognitionMode.FAST; + request.recognitionImageKind = RecognitionImageKind.CLEAR_IMAGE; + String url = api.recognizeCall(request, null, null).request().url().toString(); + assertTrue(url.contains("recognitionMode=")); + assertTrue(url.contains("recognitionImageKind=")); + } + + @Test + public void testRecognizeCall_WithoutOptionalParams() throws Exception { + RecognizeRequestWrapper request = + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")); + String url = api.recognizeCall(request, null, null).request().url().toString(); + assertFalse(url.contains("recognitionMode=")); + assertFalse(url.contains("recognitionImageKind=")); + } + + // --- Content-Type tests --- + + @Test + public void testRecognizeBase64Call_ContentTypeJson() throws ApiException { + RecognizeBase64Request body = + new RecognizeBase64Request(Arrays.asList(DecodeBarcodeType.QR), "dGVzdA=="); + RecognizeBase64RequestWrapper request = new RecognizeBase64RequestWrapper(body); + Request httpRequest = api.recognizeBase64Call(request, null, null).request(); + String contentType = httpRequest.header("Content-Type"); + assertTrue(contentType.contains("application/json")); + } + + @Test + public void testRecognizeBase64Call_HasBody() throws ApiException { + RecognizeBase64Request body = + new RecognizeBase64Request(Arrays.asList(DecodeBarcodeType.QR), "dGVzdA=="); + RecognizeBase64RequestWrapper request = new RecognizeBase64RequestWrapper(body); + Request httpRequest = api.recognizeBase64Call(request, null, null).request(); + assertNotNull(httpRequest.body()); + } + + @Test + public void testRecognizeMultipartCall_ContentTypeMultipart() throws ApiException { + RecognizeMultipartRequestWrapper request = + new RecognizeMultipartRequestWrapper(DecodeBarcodeType.QR, new File("dummy.png")); + Request httpRequest = api.recognizeMultipartCall(request, null, null).request(); + String contentType = httpRequest.header("Content-Type"); + assertTrue(contentType.contains("multipart/form-data")); + } + + @Test + public void testRecognizeCall_AuthorizationHeader() throws Exception { + RecognizeRequestWrapper request = + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")); + Request httpRequest = api.recognizeCall(request, null, null).request(); + assertEquals("Bearer " + FAKE_TOKEN, httpRequest.header("Authorization")); + } + + // --- Public method coverage --- + + private static final ApiCallback NO_OP_CALLBACK = + new ApiCallback() { + @Override + public void onFailure( + ApiException e, int statusCode, Map> headers) {} + + @Override + public void onSuccess( + BarcodeResponseList result, + int statusCode, + Map> headers) {} + + @Override + public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {} + + @Override + public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {} + }; + + @Test(expected = ApiException.class) + public void testRecognize_CallsExecute() throws Exception { + api.recognize( + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png"))); + } + + @Test(expected = ApiException.class) + public void testRecognizeWithHttpInfo_CallsExecute() throws Exception { + api.recognizeWithHttpInfo( + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png"))); + } + + @Test(expected = UnsupportedOperationException.class) + public void testRecognizeAsync_CallsEnqueue() throws Exception { + api.recognizeAsync( + new RecognizeRequestWrapper( + DecodeBarcodeType.QR, new URI("https://example.com/img.png")), + NO_OP_CALLBACK); + } + + @Test(expected = ApiException.class) + public void testRecognizeBase64_CallsExecute() throws ApiException { + RecognizeBase64Request body = + new RecognizeBase64Request(Arrays.asList(DecodeBarcodeType.QR), "dGVzdA=="); + api.recognizeBase64(new RecognizeBase64RequestWrapper(body)); + } + + @Test(expected = ApiException.class) + public void testRecognizeBase64WithHttpInfo_CallsExecute() throws ApiException { + RecognizeBase64Request body = + new RecognizeBase64Request(Arrays.asList(DecodeBarcodeType.QR), "dGVzdA=="); + api.recognizeBase64WithHttpInfo(new RecognizeBase64RequestWrapper(body)); + } + + @Test(expected = UnsupportedOperationException.class) + public void testRecognizeBase64Async_CallsEnqueue() throws ApiException { + RecognizeBase64Request body = + new RecognizeBase64Request(Arrays.asList(DecodeBarcodeType.QR), "dGVzdA=="); + api.recognizeBase64Async(new RecognizeBase64RequestWrapper(body), NO_OP_CALLBACK); + } + + @Test(expected = ApiException.class) + public void testRecognizeMultipart_CallsExecute() throws ApiException { + api.recognizeMultipart( + new RecognizeMultipartRequestWrapper(DecodeBarcodeType.QR, new File("dummy.png"))); + } + + @Test(expected = ApiException.class) + public void testRecognizeMultipartWithHttpInfo_CallsExecute() throws ApiException { + api.recognizeMultipartWithHttpInfo( + new RecognizeMultipartRequestWrapper(DecodeBarcodeType.QR, new File("dummy.png"))); + } + + @Test(expected = UnsupportedOperationException.class) + public void testRecognizeMultipartAsync_CallsEnqueue() throws ApiException { + api.recognizeMultipartAsync( + new RecognizeMultipartRequestWrapper(DecodeBarcodeType.QR, new File("dummy.png")), + NO_OP_CALLBACK); + } +} diff --git a/src/test/java/com/aspose/barcode/cloud/api/ScanApiUnitTest.java b/src/test/java/com/aspose/barcode/cloud/api/ScanApiUnitTest.java new file mode 100644 index 0000000..e67a6ba --- /dev/null +++ b/src/test/java/com/aspose/barcode/cloud/api/ScanApiUnitTest.java @@ -0,0 +1,228 @@ +package com.aspose.barcode.cloud.api; + +import static org.junit.Assert.*; + +import com.aspose.barcode.cloud.ApiCallback; +import com.aspose.barcode.cloud.ApiClient; +import com.aspose.barcode.cloud.ApiException; +import com.aspose.barcode.cloud.model.BarcodeResponseList; +import com.aspose.barcode.cloud.model.ScanBase64Request; +import com.aspose.barcode.cloud.requests.ScanBase64RequestWrapper; +import com.aspose.barcode.cloud.requests.ScanMultipartRequestWrapper; +import com.aspose.barcode.cloud.requests.ScanRequestWrapper; + +import okhttp3.Request; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.net.URI; +import java.util.List; +import java.util.Map; + +public class ScanApiUnitTest { + + private static final String FAKE_TOKEN = "fake-test-token"; + private static ScanApi api; + + @BeforeClass + public static void setUp() { + ApiClient apiClient = new ApiClient(FAKE_TOKEN); + api = new ScanApi(apiClient); + } + + // --- Validation tests --- + + @Test(expected = ApiException.class) + public void testScan_NullFileUrl_ThrowsApiException() throws Exception { + api.scan(new ScanRequestWrapper(null)); + } + + @Test + public void testScan_NullFileUrl_ErrorMessage() throws Exception { + try { + api.scan(new ScanRequestWrapper(null)); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.fileUrl")); + } + } + + @Test(expected = ApiException.class) + public void testScanBase64_NullRequest_ThrowsApiException() throws ApiException { + api.scanBase64(new ScanBase64RequestWrapper(null)); + } + + @Test + public void testScanBase64_NullRequest_ErrorMessage() { + try { + api.scanBase64(new ScanBase64RequestWrapper(null)); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.scanBase64Request")); + } + } + + @Test(expected = ApiException.class) + public void testScanMultipart_NullFile_ThrowsApiException() throws ApiException { + api.scanMultipart(new ScanMultipartRequestWrapper(null)); + } + + @Test + public void testScanMultipart_NullFile_ErrorMessage() { + try { + api.scanMultipart(new ScanMultipartRequestWrapper(null)); + fail("Expected ApiException"); + } catch (ApiException e) { + assertTrue(e.getMessage().contains("request.file")); + } + } + + // --- Path construction tests --- + + @Test + public void testScanCall_Path() throws Exception { + ScanRequestWrapper request = new ScanRequestWrapper(new URI("https://example.com/img.png")); + Request httpRequest = api.scanCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/scan")); + } + + @Test + public void testScanCall_HttpMethodIsGet() throws Exception { + ScanRequestWrapper request = new ScanRequestWrapper(new URI("https://example.com/img.png")); + Request httpRequest = api.scanCall(request, null, null).request(); + assertEquals("GET", httpRequest.method()); + } + + @Test + public void testScanBase64Call_PathAndMethod() throws ApiException { + ScanBase64Request body = new ScanBase64Request("dGVzdA=="); + ScanBase64RequestWrapper request = new ScanBase64RequestWrapper(body); + Request httpRequest = api.scanBase64Call(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/scan-body")); + assertEquals("POST", httpRequest.method()); + } + + @Test + public void testScanMultipartCall_PathAndMethod() throws ApiException { + ScanMultipartRequestWrapper request = + new ScanMultipartRequestWrapper(new File("dummy.png")); + Request httpRequest = api.scanMultipartCall(request, null, null).request(); + assertTrue(httpRequest.url().toString().contains("/barcode/scan-multipart")); + assertEquals("POST", httpRequest.method()); + } + + // --- Query parameter tests --- + + @Test + public void testScanCall_QueryContainsFileUrl() throws Exception { + ScanRequestWrapper request = new ScanRequestWrapper(new URI("https://example.com/img.png")); + String url = api.scanCall(request, null, null).request().url().toString(); + assertTrue(url.contains("fileUrl=")); + } + + // --- Content-Type tests --- + + @Test + public void testScanBase64Call_ContentTypeJson() throws ApiException { + ScanBase64Request body = new ScanBase64Request("dGVzdA=="); + ScanBase64RequestWrapper request = new ScanBase64RequestWrapper(body); + Request httpRequest = api.scanBase64Call(request, null, null).request(); + String contentType = httpRequest.header("Content-Type"); + assertTrue(contentType.contains("application/json")); + } + + @Test + public void testScanBase64Call_HasBody() throws ApiException { + ScanBase64Request body = new ScanBase64Request("dGVzdA=="); + ScanBase64RequestWrapper request = new ScanBase64RequestWrapper(body); + Request httpRequest = api.scanBase64Call(request, null, null).request(); + assertNotNull(httpRequest.body()); + } + + @Test + public void testScanMultipartCall_ContentTypeMultipart() throws ApiException { + ScanMultipartRequestWrapper request = + new ScanMultipartRequestWrapper(new File("dummy.png")); + Request httpRequest = api.scanMultipartCall(request, null, null).request(); + String contentType = httpRequest.header("Content-Type"); + assertTrue(contentType.contains("multipart/form-data")); + } + + @Test + public void testScanCall_AuthorizationHeader() throws Exception { + ScanRequestWrapper request = new ScanRequestWrapper(new URI("https://example.com/img.png")); + Request httpRequest = api.scanCall(request, null, null).request(); + assertEquals("Bearer " + FAKE_TOKEN, httpRequest.header("Authorization")); + } + + // --- Public method coverage --- + + private static final ApiCallback NO_OP_CALLBACK = + new ApiCallback() { + @Override + public void onFailure( + ApiException e, int statusCode, Map> headers) {} + + @Override + public void onSuccess( + BarcodeResponseList result, + int statusCode, + Map> headers) {} + + @Override + public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {} + + @Override + public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {} + }; + + @Test(expected = ApiException.class) + public void testScan_CallsExecute() throws Exception { + api.scan(new ScanRequestWrapper(new URI("https://example.com/img.png"))); + } + + @Test(expected = ApiException.class) + public void testScanWithHttpInfo_CallsExecute() throws Exception { + api.scanWithHttpInfo(new ScanRequestWrapper(new URI("https://example.com/img.png"))); + } + + @Test(expected = UnsupportedOperationException.class) + public void testScanAsync_CallsEnqueue() throws Exception { + api.scanAsync( + new ScanRequestWrapper(new URI("https://example.com/img.png")), NO_OP_CALLBACK); + } + + @Test(expected = ApiException.class) + public void testScanBase64_CallsExecute() throws ApiException { + api.scanBase64(new ScanBase64RequestWrapper(new ScanBase64Request("dGVzdA=="))); + } + + @Test(expected = ApiException.class) + public void testScanBase64WithHttpInfo_CallsExecute() throws ApiException { + api.scanBase64WithHttpInfo(new ScanBase64RequestWrapper(new ScanBase64Request("dGVzdA=="))); + } + + @Test(expected = UnsupportedOperationException.class) + public void testScanBase64Async_CallsEnqueue() throws ApiException { + api.scanBase64Async( + new ScanBase64RequestWrapper(new ScanBase64Request("dGVzdA==")), NO_OP_CALLBACK); + } + + @Test(expected = ApiException.class) + public void testScanMultipart_CallsExecute() throws ApiException { + api.scanMultipart(new ScanMultipartRequestWrapper(new File("dummy.png"))); + } + + @Test(expected = ApiException.class) + public void testScanMultipartWithHttpInfo_CallsExecute() throws ApiException { + api.scanMultipartWithHttpInfo(new ScanMultipartRequestWrapper(new File("dummy.png"))); + } + + @Test(expected = UnsupportedOperationException.class) + public void testScanMultipartAsync_CallsEnqueue() throws ApiException { + api.scanMultipartAsync( + new ScanMultipartRequestWrapper(new File("dummy.png")), NO_OP_CALLBACK); + } +} diff --git a/src/test/java/com/aspose/barcode/cloud/test/RecognizeApiTest.java b/src/test/java/com/aspose/barcode/cloud/test/RecognizeApiTest.java index aa97df5..5851faf 100644 --- a/src/test/java/com/aspose/barcode/cloud/test/RecognizeApiTest.java +++ b/src/test/java/com/aspose/barcode/cloud/test/RecognizeApiTest.java @@ -84,14 +84,17 @@ public void testBarcodeRecognizeMultipartPost() throws Exception { RecognizeMultipartRequestWrapper request = new RecognizeMultipartRequestWrapper(DecodeBarcodeType.MOST_COMMONLY_USED, file); request.recognitionImageKind = RecognitionImageKind.CLEAR_IMAGE; - request.recognitionMode = RecognitionMode.NORMAL; + request.recognitionMode = RecognitionMode.FAST; BarcodeResponseList response; try { response = api.recognizeMultipart(request); } catch (ApiException e) { throw new AssertionError( - "recognizeMultipart failed: httpCode=" + e.getHttpCode() + ", details=" + e.getDetails(), + "recognizeMultipart failed: httpCode=" + + e.getHttpCode() + + ", details=" + + e.getDetails(), e); } diff --git a/test_data/ManyTypes copy.png b/test_data/ManyTypes copy.png deleted file mode 100644 index c305181..0000000 Binary files a/test_data/ManyTypes copy.png and /dev/null differ diff --git a/test_data/ManyTypes.png b/test_data/ManyTypes.png index c305181..c60e586 100644 Binary files a/test_data/ManyTypes.png and b/test_data/ManyTypes.png differ