Skip to content

Commit d67b0d9

Browse files
committed
Add test for Code39 type without checksum
1 parent 4e018a6 commit d67b0d9

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.aspose.barcode.cloud.test;
2+
3+
import static com.aspose.barcode.cloud.test.TestBase.apiClient;
4+
5+
import static org.junit.Assert.*;
6+
import static org.junit.Assert.assertEquals;
7+
8+
import com.aspose.barcode.cloud.ApiException;
9+
import com.aspose.barcode.cloud.api.BarcodeApi;
10+
import com.aspose.barcode.cloud.model.BarcodeResponse;
11+
import com.aspose.barcode.cloud.model.BarcodeResponseList;
12+
import com.aspose.barcode.cloud.model.ChecksumValidation;
13+
import com.aspose.barcode.cloud.model.DecodeBarcodeType;
14+
import com.aspose.barcode.cloud.requests.ScanBarcodeRequest;
15+
16+
import org.junit.BeforeClass;
17+
import org.junit.Test;
18+
19+
import java.io.File;
20+
import java.nio.file.Path;
21+
import java.nio.file.Paths;
22+
import java.util.Collections;
23+
import java.util.List;
24+
25+
/** Tests for BarcodeApi.Scan endpoint */
26+
public class BarcodeApiScanTest {
27+
28+
private static BarcodeApi api;
29+
30+
@BeforeClass
31+
public static void oneTimeSetUp() {
32+
api = new BarcodeApi(apiClient);
33+
}
34+
35+
/**
36+
* Scan barcode from an url or from request body. Request body can contain raw data bytes of the
37+
* image or encoded with base64.
38+
*
39+
* @throws ApiException if the Api call fails
40+
*/
41+
@Test
42+
public void scanBarcodeTest() throws ApiException {
43+
Path currentRelativePath = Paths.get("");
44+
String currentPath = currentRelativePath.toAbsolutePath().toString();
45+
Path filePath = Paths.get(currentPath, "test_data", "Code39.jpg");
46+
47+
ScanBarcodeRequest request = new ScanBarcodeRequest(new File(String.valueOf(filePath)));
48+
request.decodeTypes = Collections.singletonList(DecodeBarcodeType.CODE39EXTENDED);
49+
request.checksumValidation = ChecksumValidation.OFF.toString();
50+
51+
// Act
52+
BarcodeResponseList response = api.scanBarcode(request);
53+
54+
// Assert
55+
assertNotNull(response);
56+
assertFalse("No barcodes", response.getBarcodes().isEmpty());
57+
58+
List<BarcodeResponse> barcodes = response.getBarcodes();
59+
assertEquals(1, barcodes.size());
60+
61+
assertEquals(DecodeBarcodeType.CODE39EXTENDED.getValue(), barcodes.get(0).getType());
62+
assertEquals("8M93", barcodes.get(0).getBarcodeValue());
63+
}
64+
}

test_data/Code39.jpg

24.2 KB
Loading

0 commit comments

Comments
 (0)