-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #4245: Add integration test to check that apache.commons.collec…
…tions is not present anymore (#4279) (#4302) * Fixes #4245: Add integration test to check that apache.commons.collections is not present anymore (#4279) * Fixes #4245: Add integration test to check that apache.commons.collections is not present anymore * fix tests * fix CI error * removed import org.apache.commons.collections
- Loading branch information
Showing
7 changed files
with
232 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package apoc.util; | ||
|
||
import org.testcontainers.weaviate.WeaviateContainer; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static apoc.ml.RestAPIConfig.HEADERS_KEY; | ||
import static apoc.util.Util.map; | ||
import static apoc.vectordb.VectorDbTestUtil.EntityType.FALSE; | ||
import static apoc.vectordb.VectorDbTestUtil.assertBerlinResult; | ||
import static apoc.vectordb.VectorDbTestUtil.assertLondonResult; | ||
import static apoc.vectordb.VectorDbTestUtil.getAuthHeader; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class WeaviateTestUtil { | ||
public static final List<String> FIELDS = List.of("city", "foo"); | ||
public static final String ADMIN_KEY = "jane-secret-key"; | ||
public static final String READONLY_KEY = "ian-secret-key"; | ||
public static final String COLLECTION_NAME = "TestCollection"; | ||
|
||
public static final WeaviateContainer WEAVIATE_CONTAINER = new WeaviateContainer("semitechnologies/weaviate:1.24.5") | ||
.withEnv("AUTHENTICATION_APIKEY_ENABLED", "true") | ||
.withEnv("AUTHENTICATION_APIKEY_ALLOWED_KEYS", ADMIN_KEY + "," + READONLY_KEY) | ||
.withEnv("AUTHENTICATION_APIKEY_USERS", "[email protected],ian-smith") | ||
.withEnv("AUTHORIZATION_ADMINLIST_ENABLED", "true") | ||
.withEnv("AUTHORIZATION_ADMINLIST_USERS", "[email protected],[email protected]") | ||
.withEnv("AUTHORIZATION_ADMINLIST_READONLY_USERS", "ian-smith,[email protected]"); | ||
|
||
public static final Map<String, String> ADMIN_AUTHORIZATION = getAuthHeader(ADMIN_KEY); | ||
public static final Map<String, String> READONLY_AUTHORIZATION = getAuthHeader(READONLY_KEY); | ||
public static final Map<String, Object> ADMIN_HEADER_CONF = map(HEADERS_KEY, ADMIN_AUTHORIZATION); | ||
|
||
public static final String ID_1 = "8ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308"; | ||
public static final String ID_2 = "9ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308"; | ||
|
||
public static String HOST; | ||
public static final int WEAVIATE_PORT = 8080; | ||
|
||
public static final String WEAVIATE_CREATE_COLLECTION_APOC = "CALL apoc.vectordb.weaviate.createCollection($host, 'TestCollection', 'cosine', 4, $conf)"; | ||
|
||
public static final String WEAVIATE_DELETE_COLLECTION_APOC = "CALL apoc.vectordb.weaviate.deleteCollection($host, $collectionName, $conf)"; | ||
|
||
public static final String WEAVIATE_QUERY_APOC = "CALL apoc.vectordb.weaviate.query($host, 'TestCollection', [0.2, 0.1, 0.9, 0.7], null, 5, $conf) YIELD score, vector, id, metadata RETURN * ORDER BY id"; | ||
|
||
public static final String WEAVIATE_DELETE_VECTOR_APOC = "CALL apoc.vectordb.weaviate.delete($host, 'TestCollection', ['7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308', '7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce309'], $conf)"; | ||
|
||
public static final String WEAVIATE_UPSERT_QUERY = """ | ||
CALL apoc.vectordb.weaviate.upsert($host, 'TestCollection', | ||
[ | ||
{id: $id1, vector: [0.05, 0.61, 0.76, 0.74], metadata: {city: "Berlin", foo: "one"}}, | ||
{id: $id2, vector: [0.19, 0.81, 0.75, 0.11], metadata: {city: "London", foo: "two"}}, | ||
{id: '7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308', vector: [0.19, 0.81, 0.75, 0.11], metadata: {foo: "baz"}}, | ||
{id: '7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce309', vector: [0.19, 0.81, 0.75, 0.11], metadata: {foo: "baz"}} | ||
], | ||
$conf) | ||
"""; | ||
|
||
public static void queryVectorsAssertions(Iterator<Map<String, Object>> r) { | ||
Map<String, Object> row = r.next(); | ||
assertBerlinResult(row, ID_1, FALSE); | ||
assertNotNull(row.get("score")); | ||
assertNotNull(row.get("vector")); | ||
|
||
row = r.next(); | ||
assertLondonResult(row, ID_2, FALSE); | ||
assertNotNull(row.get("score")); | ||
assertNotNull(row.get("vector")); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
extended-it/src/test/java/apoc/vectordb/WeaviateEnterpriseTest.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,118 @@ | ||
package apoc.vectordb; | ||
|
||
import apoc.util.MapUtil; | ||
import apoc.util.Neo4jContainerExtension; | ||
import apoc.util.TestContainerUtil; | ||
import apoc.util.WeaviateTestUtil; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.neo4j.driver.Session; | ||
import org.testcontainers.containers.Network; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static apoc.ml.RestAPIConfig.HEADERS_KEY; | ||
import static apoc.util.TestContainerUtil.createEnterpriseDB; | ||
import static apoc.util.TestContainerUtil.testCall; | ||
import static apoc.util.TestContainerUtil.testCallEmpty; | ||
import static apoc.util.TestContainerUtil.testResult; | ||
import static apoc.util.Util.map; | ||
import static apoc.util.WeaviateTestUtil.ADMIN_AUTHORIZATION; | ||
import static apoc.util.WeaviateTestUtil.ADMIN_HEADER_CONF; | ||
import static apoc.util.WeaviateTestUtil.COLLECTION_NAME; | ||
import static apoc.util.WeaviateTestUtil.FIELDS; | ||
import static apoc.util.WeaviateTestUtil.HOST; | ||
import static apoc.util.WeaviateTestUtil.ID_1; | ||
import static apoc.util.WeaviateTestUtil.ID_2; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_CONTAINER; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_CREATE_COLLECTION_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_DELETE_COLLECTION_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_DELETE_VECTOR_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_PORT; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_QUERY_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_UPSERT_QUERY; | ||
import static apoc.vectordb.VectorEmbeddingConfig.ALL_RESULTS_KEY; | ||
import static apoc.vectordb.VectorEmbeddingConfig.FIELDS_KEY; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
|
||
public class WeaviateEnterpriseTest { | ||
|
||
@ClassRule | ||
public static TemporaryFolder storeDir = new TemporaryFolder(); | ||
private static Neo4jContainerExtension neo4jContainer; | ||
private static Session session; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
Network network = Network.newNetwork(); | ||
|
||
// We build the project, the artifact will be placed into ./build/libs | ||
neo4jContainer = createEnterpriseDB(List.of(TestContainerUtil.ApocPackage.EXTENDED), true) | ||
.withNetwork(network) | ||
.withNetworkAliases("neo4j"); | ||
neo4jContainer.start(); | ||
session = neo4jContainer.getSession(); | ||
|
||
String weaviateAlias = "weaviate"; | ||
WEAVIATE_CONTAINER.withNetwork(network) | ||
.withNetworkAliases(weaviateAlias) | ||
.withExposedPorts(WEAVIATE_PORT); | ||
WEAVIATE_CONTAINER.start(); | ||
|
||
HOST = weaviateAlias + ":" + WEAVIATE_PORT; | ||
|
||
testCall(session, WEAVIATE_CREATE_COLLECTION_APOC, | ||
map("host", HOST, "conf", ADMIN_HEADER_CONF), | ||
r -> { | ||
Map value = (Map) r.get("value"); | ||
assertEquals("TestCollection", value.get("class")); | ||
}); | ||
|
||
testResult(session, WEAVIATE_UPSERT_QUERY, | ||
map("host", HOST, "id1", ID_1, "id2", ID_2, "conf", ADMIN_HEADER_CONF), | ||
r -> { | ||
Map<String, Object> row = r.next(); | ||
Map<String, Object> value = (Map<String, Object>) row.get("value"); | ||
|
||
assertEquals(COLLECTION_NAME, value.get("class")); | ||
|
||
while (r.hasNext()) { | ||
row = r.next(); | ||
value = (Map<String, Object>) row.get("value"); | ||
assertEquals(COLLECTION_NAME, value.get("class")); | ||
} | ||
assertFalse(r.hasNext()); | ||
}); | ||
|
||
// -- delete vector | ||
testCall(session, WEAVIATE_DELETE_VECTOR_APOC, | ||
map("host", HOST, "conf", ADMIN_HEADER_CONF), | ||
r -> { | ||
List value = (List) r.get("value"); | ||
assertEquals(List.of("7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308", "7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce309"), value); | ||
}); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() throws Exception { | ||
testCallEmpty(session, WEAVIATE_DELETE_COLLECTION_APOC, | ||
MapUtil.map("host", HOST, "collectionName", COLLECTION_NAME, "conf", ADMIN_HEADER_CONF) | ||
); | ||
session.close(); | ||
neo4jContainer.close(); | ||
WEAVIATE_CONTAINER.stop(); | ||
} | ||
|
||
@Test | ||
public void queryVectors() { | ||
testResult(session, WEAVIATE_QUERY_APOC, | ||
map("host", HOST, "conf", map(ALL_RESULTS_KEY, true, FIELDS_KEY, FIELDS, HEADERS_KEY, ADMIN_AUTHORIZATION)), | ||
WeaviateTestUtil::queryVectorsAssertions); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package apoc.vectordb; | ||
|
||
import apoc.ml.Prompt; | ||
import apoc.util.ExtendedTestUtil; | ||
import apoc.util.MapUtil; | ||
import apoc.util.TestUtil; | ||
import apoc.util.WeaviateTestUtil; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
|
@@ -15,7 +15,6 @@ | |
import org.neo4j.graphdb.GraphDatabaseService; | ||
import org.neo4j.graphdb.ResourceIterator; | ||
import org.neo4j.test.TestDatabaseManagementServiceBuilder; | ||
import org.testcontainers.weaviate.WeaviateContainer; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -27,6 +26,21 @@ | |
import static apoc.util.TestUtil.testCallEmpty; | ||
import static apoc.util.TestUtil.testResult; | ||
import static apoc.util.Util.map; | ||
import static apoc.util.WeaviateTestUtil.ADMIN_AUTHORIZATION; | ||
import static apoc.util.WeaviateTestUtil.ADMIN_HEADER_CONF; | ||
import static apoc.util.WeaviateTestUtil.ADMIN_KEY; | ||
import static apoc.util.WeaviateTestUtil.COLLECTION_NAME; | ||
import static apoc.util.WeaviateTestUtil.FIELDS; | ||
import static apoc.util.WeaviateTestUtil.HOST; | ||
import static apoc.util.WeaviateTestUtil.ID_1; | ||
import static apoc.util.WeaviateTestUtil.ID_2; | ||
import static apoc.util.WeaviateTestUtil.READONLY_AUTHORIZATION; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_CONTAINER; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_CREATE_COLLECTION_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_DELETE_COLLECTION_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_DELETE_VECTOR_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_QUERY_APOC; | ||
import static apoc.util.WeaviateTestUtil.WEAVIATE_UPSERT_QUERY; | ||
import static apoc.vectordb.VectorDbHandler.Type.WEAVIATE; | ||
import static apoc.vectordb.VectorDbTestUtil.EntityType.FALSE; | ||
import static apoc.vectordb.VectorDbTestUtil.EntityType.NODE; | ||
|
@@ -37,12 +51,18 @@ | |
import static apoc.vectordb.VectorDbTestUtil.assertReadOnlyProcWithMappingResults; | ||
import static apoc.vectordb.VectorDbTestUtil.assertRelsCreated; | ||
import static apoc.vectordb.VectorDbTestUtil.dropAndDeleteAll; | ||
import static apoc.vectordb.VectorDbTestUtil.getAuthHeader; | ||
import static apoc.vectordb.VectorDbTestUtil.ragSetup; | ||
import static apoc.vectordb.VectorEmbeddingConfig.ALL_RESULTS_KEY; | ||
import static apoc.vectordb.VectorEmbeddingConfig.FIELDS_KEY; | ||
import static apoc.vectordb.VectorEmbeddingConfig.MAPPING_KEY; | ||
import static apoc.vectordb.VectorMappingConfig.*; | ||
import static apoc.vectordb.VectorMappingConfig.EMBEDDING_KEY; | ||
import static apoc.vectordb.VectorMappingConfig.ENTITY_KEY; | ||
import static apoc.vectordb.VectorMappingConfig.METADATA_KEY; | ||
import static apoc.vectordb.VectorMappingConfig.MODE_KEY; | ||
import static apoc.vectordb.VectorMappingConfig.MappingMode; | ||
import static apoc.vectordb.VectorMappingConfig.NODE_LABEL; | ||
import static apoc.vectordb.VectorMappingConfig.NO_FIELDS_ERROR_MSG; | ||
import static apoc.vectordb.VectorMappingConfig.REL_TYPE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
@@ -54,29 +74,7 @@ | |
|
||
|
||
public class WeaviateTest { | ||
private static final List<String> FIELDS = List.of("city", "foo"); | ||
private static final String ADMIN_KEY = "jane-secret-key"; | ||
private static final String READONLY_KEY = "ian-secret-key"; | ||
private static final String COLLECTION_NAME = "TestCollection"; | ||
|
||
private static final WeaviateContainer WEAVIATE_CONTAINER = new WeaviateContainer("semitechnologies/weaviate:1.24.5") | ||
.withEnv("AUTHENTICATION_APIKEY_ENABLED", "true") | ||
.withEnv("AUTHENTICATION_APIKEY_ALLOWED_KEYS", ADMIN_KEY + "," + READONLY_KEY) | ||
.withEnv("AUTHENTICATION_APIKEY_USERS", "[email protected],ian-smith") | ||
|
||
.withEnv("AUTHORIZATION_ADMINLIST_ENABLED", "true") | ||
.withEnv("AUTHORIZATION_ADMINLIST_USERS", "[email protected],[email protected]") | ||
.withEnv("AUTHORIZATION_ADMINLIST_READONLY_USERS", "ian-smith,[email protected]"); | ||
|
||
private static final Map<String, String> ADMIN_AUTHORIZATION = getAuthHeader(ADMIN_KEY); | ||
private static final Map<String, String> READONLY_AUTHORIZATION = getAuthHeader(READONLY_KEY); | ||
private static final Map<String, Object> ADMIN_HEADER_CONF = map(HEADERS_KEY, ADMIN_AUTHORIZATION); | ||
|
||
private static final String ID_1 = "8ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308"; | ||
private static final String ID_2 = "9ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308"; | ||
|
||
private static String HOST; | ||
|
||
|
||
@ClassRule | ||
public static TemporaryFolder storeDir = new TemporaryFolder(); | ||
|
||
|
@@ -96,23 +94,14 @@ public static void setUp() throws Exception { | |
|
||
TestUtil.registerProcedure(db, Weaviate.class, VectorDb.class, Prompt.class); | ||
|
||
testCall(db, "CALL apoc.vectordb.weaviate.createCollection($host, 'TestCollection', 'cosine', 4, $conf)", | ||
testCall(db, WEAVIATE_CREATE_COLLECTION_APOC, | ||
MapUtil.map("host", HOST, "conf", ADMIN_HEADER_CONF), | ||
r -> { | ||
Map value = (Map) r.get("value"); | ||
assertEquals("TestCollection", value.get("class")); | ||
}); | ||
|
||
testResult(db, """ | ||
CALL apoc.vectordb.weaviate.upsert($host, 'TestCollection', | ||
[ | ||
{id: $id1, vector: [0.05, 0.61, 0.76, 0.74], metadata: {city: "Berlin", foo: "one"}}, | ||
{id: $id2, vector: [0.19, 0.81, 0.75, 0.11], metadata: {city: "London", foo: "two"}}, | ||
{id: '7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308', vector: [0.19, 0.81, 0.75, 0.11], metadata: {foo: "baz"}}, | ||
{id: '7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce309', vector: [0.19, 0.81, 0.75, 0.11], metadata: {foo: "baz"}} | ||
], | ||
$conf) | ||
""", | ||
testResult(db, WEAVIATE_UPSERT_QUERY, | ||
MapUtil.map("host", HOST, "id1", ID_1, "id2", ID_2, "conf", ADMIN_HEADER_CONF), | ||
r -> { | ||
ResourceIterator<Map> values = r.columnAs("value"); | ||
|
@@ -124,9 +113,7 @@ public static void setUp() throws Exception { | |
}); | ||
|
||
// -- delete vector | ||
testCall(db, "CALL apoc.vectordb.weaviate.delete($host, 'TestCollection', " + | ||
"['7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308', '7ef2b3a7-1e56-4ddd-b8c3-2ca8901ce309']" + | ||
", $conf) ", | ||
testCall(db, WEAVIATE_DELETE_VECTOR_APOC, | ||
map("host", HOST, "conf", ADMIN_HEADER_CONF), | ||
r -> { | ||
List value = (List) r.get("value"); | ||
|
@@ -136,7 +123,7 @@ public static void setUp() throws Exception { | |
|
||
@AfterClass | ||
public static void tearDown() throws Exception { | ||
testCallEmpty(db, "CALL apoc.vectordb.weaviate.deleteCollection($host, $collectionName, $conf)", | ||
testCallEmpty(db, WEAVIATE_DELETE_COLLECTION_APOC, | ||
MapUtil.map("host", HOST, "collectionName", COLLECTION_NAME, "conf", ADMIN_HEADER_CONF) | ||
); | ||
|
||
|
@@ -209,20 +196,9 @@ public void getVectorsWithoutVectorResult() { | |
|
||
@Test | ||
public void queryVectors() { | ||
testResult(db, "CALL apoc.vectordb.weaviate.query($host, 'TestCollection', [0.2, 0.1, 0.9, 0.7], null, 5, $conf) " + | ||
" YIELD score, vector, id, metadata RETURN * ORDER BY id", | ||
testResult(db, WEAVIATE_QUERY_APOC, | ||
map("host", HOST, "conf", map(ALL_RESULTS_KEY, true, FIELDS_KEY, FIELDS, HEADERS_KEY, ADMIN_AUTHORIZATION)), | ||
r -> { | ||
Map<String, Object> row = r.next(); | ||
assertBerlinResult(row, ID_1, FALSE); | ||
assertNotNull(row.get("score")); | ||
assertNotNull(row.get("vector")); | ||
|
||
row = r.next(); | ||
assertLondonResult(row, ID_2, FALSE); | ||
assertNotNull(row.get("score")); | ||
assertNotNull(row.get("vector")); | ||
}); | ||
WeaviateTestUtil::queryVectorsAssertions); | ||
} | ||
|
||
@Test | ||
|
@@ -585,7 +561,7 @@ private static void assertQueryVectorsWithSystemDbStorage(String keyConfig, Stri | |
db, | ||
query, | ||
params, | ||
"Caused by: java.io.FileNotFoundException: http://127.0.0.1:" + HOST.split(":")[1] + "/v3/graphql" | ||
"Caused by: java.io.FileNotFoundException: http://127.0.0.1:" + HOST.split(":")[1] + "/v3/graphql" | ||
); | ||
return; | ||
} | ||
|
@@ -634,7 +610,7 @@ MAPPING_KEY, map(EMBEDDING_KEY, "vect", | |
HEADERS_KEY, ADMIN_AUTHORIZATION)); | ||
String query = "CALL apoc.vectordb.weaviate.query($host, 'TestCollection', [0.2, 0.1, 0.9, 0.7], null, 5, $conf) " + | ||
" YIELD score, vector, id, metadata RETURN * ORDER BY id"; | ||
ExtendedTestUtil.assertFails(db, query, params, NO_FIELDS_ERROR_MSG); | ||
assertFails(db, query, params, NO_FIELDS_ERROR_MSG); | ||
} | ||
|
||
@Test | ||
|
@@ -662,6 +638,6 @@ MAPPING_KEY, map(EMBEDDING_KEY, "vect", | |
NODE_LABEL, "Test", | ||
ENTITY_KEY, "myId"))); | ||
String query = "CALL apoc.vectordb.weaviate.queryAndUpdate($host, 'TestCollection', [0.2, 0.1, 0.9, 0.7], null, 5, $conf) YIELD score, vector, id, metadata, node RETURN * ORDER BY id"; | ||
ExtendedTestUtil.assertFails(db, query, params, NO_FIELDS_ERROR_MSG); | ||
assertFails(db, query, params, NO_FIELDS_ERROR_MSG); | ||
} | ||
} |
Oops, something went wrong.