-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
469 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
extended-it/src/test/java/apoc/azure/AzureStorageBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package apoc.azure; | ||
|
||
import com.azure.core.util.Context; | ||
import com.azure.storage.blob.BlobClient; | ||
import com.azure.storage.blob.BlobContainerClient; | ||
import com.azure.storage.blob.BlobContainerClientBuilder; | ||
import com.azure.storage.blob.sas.BlobSasPermission; | ||
import com.azure.storage.blob.sas.BlobServiceSasSignatureValues; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.time.OffsetDateTime; | ||
import java.util.UUID; | ||
|
||
public class AzureStorageBaseTest { | ||
|
||
public static GenericContainer<?> azuriteContainer; | ||
public static BlobContainerClient containerClient; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
DockerImageName azuriteImg = DockerImageName.parse("mcr.microsoft.com/azure-storage/azurite"); | ||
azuriteContainer = new GenericContainer<>(azuriteImg) | ||
.withExposedPorts(10000); | ||
|
||
azuriteContainer.start(); | ||
|
||
var accountName = "devstoreaccount1"; | ||
var accountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; | ||
var blobEndpoint = "http://%s:%d/%s".formatted(azuriteContainer.getHost(), azuriteContainer.getMappedPort(10000), accountName); | ||
var connectionString = "DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s;BlobEndpoint=%s;" | ||
.formatted(accountName, accountKey, blobEndpoint); | ||
|
||
containerClient = new BlobContainerClientBuilder() | ||
.connectionString(connectionString) | ||
.containerName("test-container") | ||
.buildClient(); | ||
containerClient.create(); | ||
} | ||
|
||
@AfterClass | ||
public static void teardown() { | ||
azuriteContainer.close(); | ||
} | ||
|
||
public static String putToAzureStorageAndGetUrl(String url) { | ||
try { | ||
File file = new File(url); | ||
byte[] content = FileUtils.readFileToByteArray(file); | ||
|
||
var blobClient = getBlobClient(content); | ||
BlobSasPermission permission = new BlobSasPermission().setReadPermission(true); | ||
OffsetDateTime expiryTime = OffsetDateTime.now().plusHours(1); | ||
String sasToken = blobClient.generateSas(new BlobServiceSasSignatureValues(expiryTime, permission), new Context("Azure-Storage-Log-String-To-Sign", "true")); | ||
return blobClient.getBlobUrl() + "?" + sasToken; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static BlobClient getBlobClient(byte[] content) { | ||
var blobName = "blob-" + UUID.randomUUID(); | ||
var blobClient = containerClient.getBlobClient(blobName); | ||
blobClient.upload(new ByteArrayInputStream(content)); | ||
return blobClient; | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
extended-it/src/test/java/apoc/azure/ImportAzureStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package apoc.azure; | ||
|
||
import apoc.export.arrow.ExportArrow; | ||
import apoc.export.arrow.ImportArrow; | ||
import apoc.export.arrow.ImportArrowTestUtil; | ||
import apoc.load.Gexf; | ||
import apoc.meta.Meta; | ||
import apoc.util.TestUtil; | ||
import apoc.util.s3.S3BaseTest; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
import org.neo4j.test.rule.DbmsRule; | ||
import org.neo4j.test.rule.ImpermanentDbmsRule; | ||
|
||
import java.io.File; | ||
import java.util.Map; | ||
|
||
import static apoc.ApocConfig.APOC_EXPORT_FILE_ENABLED; | ||
import static apoc.ApocConfig.APOC_IMPORT_FILE_ENABLED; | ||
import static apoc.ApocConfig.apocConfig; | ||
import static apoc.export.arrow.ImportArrowTestUtil.ARROW_BASE_FOLDER; | ||
import static apoc.export.arrow.ImportArrowTestUtil.MAPPING_ALL; | ||
import static apoc.export.arrow.ImportArrowTestUtil.prepareDbForArrow; | ||
import static apoc.export.arrow.ImportArrowTestUtil.testImportCommon; | ||
import static apoc.util.ExtendedITUtil.EXTENDED_PATH; | ||
import static apoc.util.ExtendedTestUtil.clearDb; | ||
import static apoc.util.GexfTestUtil.testImportGexfCommon; | ||
|
||
public class ImportAzureStorageTest extends AzureStorageBaseTest { | ||
private static File directory = new File(ARROW_BASE_FOLDER); | ||
static { //noinspection ResultOfMethodCallIgnored | ||
directory.mkdirs(); | ||
} | ||
|
||
@ClassRule | ||
public static DbmsRule db = new ImpermanentDbmsRule(); | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
TestUtil.registerProcedure(db, ExportArrow.class, ImportArrow.class, Meta.class, Gexf.class); | ||
prepareDbForArrow(db); | ||
apocConfig().setProperty(APOC_IMPORT_FILE_ENABLED, true); | ||
apocConfig().setProperty(APOC_EXPORT_FILE_ENABLED, true); | ||
} | ||
|
||
@Test | ||
public void testImportArrow() { | ||
String fileWithPath = ARROW_BASE_FOLDER + File.separator + "test_all.arrow"; | ||
String url = putToAzureStorageAndGetUrl(fileWithPath); | ||
|
||
testImportCommon(db, url, MAPPING_ALL); | ||
} | ||
|
||
@Test | ||
public void testImportGexf() { | ||
clearDb(db); | ||
String filename = EXTENDED_PATH + "src/test/resources/gexf/data.gexf"; | ||
String url = putToAzureStorageAndGetUrl(filename); | ||
testImportGexfCommon(db, url); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
extended-it/src/test/java/apoc/azure/LoadAzureStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package apoc.azure; | ||
|
||
import apoc.load.LoadCsv; | ||
import apoc.load.LoadDirectory; | ||
import apoc.load.LoadHtml; | ||
import apoc.load.LoadJson; | ||
import apoc.load.Xml; | ||
import apoc.load.xls.LoadXls; | ||
import apoc.util.TestUtil; | ||
import com.azure.core.util.Context; | ||
import com.azure.storage.blob.*; | ||
import com.azure.storage.blob.sas.BlobSasPermission; | ||
import com.azure.storage.blob.sas.BlobServiceSasSignatureValues; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.neo4j.test.rule.DbmsRule; | ||
import org.neo4j.test.rule.ImpermanentDbmsRule; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.time.OffsetDateTime; | ||
import java.util.UUID; | ||
|
||
import static apoc.ApocConfig.APOC_IMPORT_FILE_ENABLED; | ||
import static apoc.ApocConfig.APOC_IMPORT_FILE_USE_NEO4J_CONFIG; | ||
import static apoc.ApocConfig.apocConfig; | ||
import static apoc.load.LoadCsvTest.commonTestLoadCsv; | ||
import static apoc.load.LoadHtmlTest.testLoadHtmlWithGetLinksCommon; | ||
import static apoc.load.xls.LoadXlsTest.testLoadXlsCommon; | ||
import static apoc.util.ExtendedITUtil.EXTENDED_PATH; | ||
import static apoc.util.ExtendedITUtil.testLoadJsonCommon; | ||
import static apoc.util.ExtendedITUtil.testLoadXmlCommon; | ||
import static apoc.util.TestUtil.testResult; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
|
||
public class LoadAzureStorageTest extends AzureStorageBaseTest { | ||
|
||
|
||
@ClassRule | ||
public static DbmsRule db = new ImpermanentDbmsRule(); | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
AzureStorageBaseTest.setUp(); | ||
|
||
TestUtil.registerProcedure(db, LoadCsv.class, LoadDirectory.class, LoadJson.class, LoadHtml.class, LoadXls.class, Xml.class); | ||
apocConfig().setProperty(APOC_IMPORT_FILE_ENABLED, true); | ||
apocConfig().setProperty(APOC_IMPORT_FILE_USE_NEO4J_CONFIG, false); | ||
} | ||
|
||
|
||
@Test | ||
public void testLoadCsv() { | ||
String url = putToAzureStorageAndGetUrl(EXTENDED_PATH + "src/test/resources/test.csv"); | ||
commonTestLoadCsv(db, url); | ||
} | ||
|
||
@Test | ||
public void testLoadJson() { | ||
String url = putToAzureStorageAndGetUrl(EXTENDED_PATH + "src/test/resources/map.json"); | ||
testLoadJsonCommon(db, url); | ||
} | ||
|
||
@Test | ||
public void testLoadXml() { | ||
String url = putToAzureStorageAndGetUrl(EXTENDED_PATH + "src/test/resources/xml/books.xml"); | ||
testLoadXmlCommon(db, url); | ||
} | ||
|
||
@Test | ||
public void testLoadXls() { | ||
String url = putToAzureStorageAndGetUrl(EXTENDED_PATH + "src/test/resources/load_test.xlsx"); | ||
testLoadXlsCommon(db, url); | ||
} | ||
|
||
@Test | ||
public void testLoadHtml() { | ||
String url = putToAzureStorageAndGetUrl(EXTENDED_PATH + "src/test/resources/wikipedia.html"); | ||
testLoadHtmlWithGetLinksCommon(db, url); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
extended-it/src/test/java/apoc/azure/ParquetAzureStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package apoc.azure; | ||
|
||
import apoc.export.parquet.ParquetTestUtil; | ||
import apoc.util.collection.Iterators; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.neo4j.test.rule.DbmsRule; | ||
import org.neo4j.test.rule.ImpermanentDbmsRule; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import static apoc.export.parquet.ParquetTest.MAPPING_ALL; | ||
import static apoc.export.parquet.ParquetTestUtil.beforeClassCommon; | ||
import static apoc.export.parquet.ParquetTestUtil.beforeCommon; | ||
import static apoc.export.parquet.ParquetTestUtil.testImportAllCommon; | ||
import static apoc.util.ExtendedITUtil.EXTENDED_PATH; | ||
import static apoc.util.GoogleCloudStorageContainerExtension.gcsUrl; | ||
import static apoc.util.TestUtil.testCall; | ||
import static apoc.util.TestUtil.testResult; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ParquetAzureStorageTest extends AzureStorageBaseTest { | ||
|
||
private final String EXPORT_FILENAME = "test_all.parquet"; | ||
|
||
@ClassRule | ||
public static DbmsRule db = new ImpermanentDbmsRule(); | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
beforeClassCommon(db); | ||
} | ||
|
||
@Before | ||
public void before() { | ||
beforeCommon(db); | ||
} | ||
|
||
@Test | ||
public void testLoadParquet() { | ||
String query = "CALL apoc.load.parquet($url, $config) YIELD value " + | ||
"RETURN value"; | ||
|
||
String url = putToAzureStorageAndGetUrl(EXTENDED_PATH + "src/test/resources/" + EXPORT_FILENAME); | ||
testResult(db, query, Map.of("url", url, "config", MAPPING_ALL), | ||
ParquetTestUtil::roundtripLoadAllAssertions); | ||
} | ||
|
||
@Test | ||
public void testImportParquet() { | ||
String url = putToAzureStorageAndGetUrl(EXTENDED_PATH + "src/test/resources/" + EXPORT_FILENAME); | ||
|
||
Map<String, Object> params = Map.of("file", url, "config", MAPPING_ALL); | ||
testImportAllCommon(db, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.