From 15edca886ae3df239e29e1a159828ed85a4d7cfb Mon Sep 17 00:00:00 2001 From: Pawel Maslej <151659533+pawellhasa@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:26:32 +0100 Subject: [PATCH 01/45] feature-1659: Initial draft (#1680) * feature-1659: Initial draft * feature-1659: Added dedicated exception: EncryptionException --- .../com/arcadedb/database/DataEncryption.java | 30 +++++ .../java/com/arcadedb/database/Database.java | 10 ++ .../arcadedb/database/DatabaseInternal.java | 5 + .../database/DefaultDataEncryption.java | 122 ++++++++++++++++++ .../exception/EncryptionException.java | 33 +++++ .../arcadedb/serializer/BinarySerializer.java | 39 ++++-- .../arcadedb/database/DataEncryptionTest.java | 96 ++++++++++++++ .../database/DefaultDataEncryptionTest.java | 64 +++++++++ 8 files changed, 391 insertions(+), 8 deletions(-) create mode 100644 engine/src/main/java/com/arcadedb/database/DataEncryption.java create mode 100644 engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java create mode 100644 engine/src/main/java/com/arcadedb/exception/EncryptionException.java create mode 100644 engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java create mode 100644 engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java diff --git a/engine/src/main/java/com/arcadedb/database/DataEncryption.java b/engine/src/main/java/com/arcadedb/database/DataEncryption.java new file mode 100644 index 0000000000..017a061e65 --- /dev/null +++ b/engine/src/main/java/com/arcadedb/database/DataEncryption.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2024-present Arcade Data Ltd (info@arcadedata.com) + * + * 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 + * + * 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. + * + * SPDX-FileCopyrightText: 2024-present Arcade Data Ltd (info@arcadedata.com) + * SPDX-License-Identifier: Apache-2.0 + */ +package com.arcadedb.database; + +/** + * Provides methods to intercept serialization of data allowing encryption and decryption. + * + * @author Pawel Maslej + * @since 27 Jun 2024 + */ +public interface DataEncryption { + public byte[] encrypt(byte[] data); + public byte[] decrypt(byte[] data); +} \ No newline at end of file diff --git a/engine/src/main/java/com/arcadedb/database/Database.java b/engine/src/main/java/com/arcadedb/database/Database.java index 2963c5c1d1..ffd657b095 100644 --- a/engine/src/main/java/com/arcadedb/database/Database.java +++ b/engine/src/main/java/com/arcadedb/database/Database.java @@ -331,4 +331,14 @@ Edge newEdgeByKeys(Vertex sourceVertex, String destinationVertexType, String[] d * @see #isAsyncFlush() */ Database setAsyncFlush(boolean value); + + /** + * Sets data encryption to be used by the database.
+ * THIS MUST BE DONE BEFORE WRITING ANY DATA TO THE DATABASE. + * + * @param encryption implementation of DataEncryption + * + * @see DefaultDataEncryption + */ + void setDataEncryption(DataEncryption encryption); } diff --git a/engine/src/main/java/com/arcadedb/database/DatabaseInternal.java b/engine/src/main/java/com/arcadedb/database/DatabaseInternal.java index d197e9881c..fbf7182885 100644 --- a/engine/src/main/java/com/arcadedb/database/DatabaseInternal.java +++ b/engine/src/main/java/com/arcadedb/database/DatabaseInternal.java @@ -128,4 +128,9 @@ default TransactionContext getTransaction() { * Executes an operation after having locked files. */ RET executeLockingFiles(Collection fileIds, Callable callable); + + @Override + default void setDataEncryption(DataEncryption encryption) { + getSerializer().setDataEncryption(encryption); + } } diff --git a/engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java b/engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java new file mode 100644 index 0000000000..68b9902aa3 --- /dev/null +++ b/engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java @@ -0,0 +1,122 @@ +/* + * Copyright © 2024-present Arcade Data Ltd (info@arcadedata.com) + * + * 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 + * + * 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. + * + * SPDX-FileCopyrightText: 2024-present Arcade Data Ltd (info@arcadedata.com) + * SPDX-License-Identifier: Apache-2.0 + */ +package com.arcadedb.database; + +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.GCMParameterSpec; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; + +import com.arcadedb.exception.EncryptionException; + +/** + * Provides configurable default with implementation for data encryption and decryption. + * + * @author Pawel Maslej + * @since 27 Jun 2024 + */ +public class DefaultDataEncryption implements DataEncryption { + public static final int DEFAULT_SALT_ITERATIONS = 65536; + public static final int DEFAULT_KEY_LENGTH = 256; + public static final String DEFAULT_PASSWORD_ALGORITHM = "PBKDF2WithHmacSHA256"; + public static final String DEFAULT_SECRET_KEY_ALGORITHM = "AES"; + + public static final String DEFAULT_ALGORITHM = "AES/GCM/NoPadding"; + public static final int DEFAULT_IV_SIZE = 12; + public static final int DEFAULT_TAG_SIZE = 128; + + private SecretKey secretKey; + private String algorithm; + private int ivSize; + private int tagSize; + + public DefaultDataEncryption(SecretKey secretKey, String algorithm, int ivSize, int tagSize) throws NoSuchAlgorithmException, NoSuchPaddingException { + this.secretKey = secretKey; + this.algorithm = algorithm; + this.ivSize = ivSize; + this.tagSize = tagSize; + Cipher.getInstance(algorithm); // validates before execution + } + + @Override + public byte[] encrypt(byte[] data) { + try { + var ivBytes = generateIv(ivSize); + var cipher = Cipher.getInstance(algorithm); + cipher.init(Cipher.ENCRYPT_MODE, secretKey, new GCMParameterSpec(tagSize, ivBytes)); + byte[] encryptedData = cipher.doFinal(data); + byte[] ivAndEncryptedData = new byte[ivBytes.length + encryptedData.length]; + System.arraycopy(ivBytes, 0, ivAndEncryptedData, 0, ivBytes.length); + System.arraycopy(encryptedData, 0, ivAndEncryptedData, ivBytes.length, encryptedData.length); + return ivAndEncryptedData; + } catch (Exception e) { + throw new EncryptionException("Error while encrypting data", e); + } + } + + @Override + public byte[] decrypt(byte[] data) { + try { + byte[] ivBytes = new byte[ivSize]; + byte[] encryptedData = new byte[data.length - ivSize]; + System.arraycopy(data, 0, ivBytes, 0, ivSize); + System.arraycopy(data, ivSize, encryptedData, 0, encryptedData.length); + var decipher = Cipher.getInstance(algorithm); + decipher.init(Cipher.DECRYPT_MODE, secretKey, new GCMParameterSpec(tagSize, ivBytes)); + return decipher.doFinal(encryptedData); + } catch (Exception e) { + throw new EncryptionException("Error while decrypting data", e); + } + } + + public static DefaultDataEncryption useDefaults(SecretKey secretKey) throws NoSuchAlgorithmException, NoSuchPaddingException { + return new DefaultDataEncryption(secretKey, DEFAULT_ALGORITHM, DEFAULT_IV_SIZE, DEFAULT_TAG_SIZE); + } + + public static SecretKey generateRandomSecretKeyUsingDefaults() throws NoSuchAlgorithmException { + KeyGenerator keyGen = KeyGenerator.getInstance(DEFAULT_SECRET_KEY_ALGORITHM); + keyGen.init(DEFAULT_KEY_LENGTH); + return keyGen.generateKey(); + } + + public static SecretKey getSecretKeyFromPasswordUsingDefaults(String password, String salt) throws NoSuchAlgorithmException, InvalidKeySpecException { + return getKeyFromPassword(password, salt, DEFAULT_PASSWORD_ALGORITHM, DEFAULT_SECRET_KEY_ALGORITHM, DEFAULT_SALT_ITERATIONS, DEFAULT_KEY_LENGTH); + } + + private static byte[] generateIv(int ivSize) { + final byte[] iv = new byte[ivSize]; + new SecureRandom().nextBytes(iv); + return iv; + } + + public static SecretKey getKeyFromPassword(String password, String salt, String passwordAlgorithm, String secretKeyAlgorithm, int saltIterations, int keyLength) + throws NoSuchAlgorithmException, InvalidKeySpecException { + final SecretKeyFactory factory = SecretKeyFactory.getInstance(passwordAlgorithm); + final KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), saltIterations, keyLength); + return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), secretKeyAlgorithm); + } +} \ No newline at end of file diff --git a/engine/src/main/java/com/arcadedb/exception/EncryptionException.java b/engine/src/main/java/com/arcadedb/exception/EncryptionException.java new file mode 100644 index 0000000000..91f996b03f --- /dev/null +++ b/engine/src/main/java/com/arcadedb/exception/EncryptionException.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2024-present Arcade Data Ltd (info@arcadedata.com) + * + * 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 + * + * 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. + * + * SPDX-FileCopyrightText: 2024-present Arcade Data Ltd (info@arcadedata.com) + * SPDX-License-Identifier: Apache-2.0 + */ +package com.arcadedb.exception; + +public class EncryptionException extends ArcadeDBException { + public EncryptionException(final String message) { + super(message); + } + + public EncryptionException(final String message, final Throwable cause) { + super(message, cause); + } + + public EncryptionException(final Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java b/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java index da31de08ba..90281c855c 100644 --- a/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java +++ b/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java @@ -22,6 +22,7 @@ import com.arcadedb.GlobalConfiguration; import com.arcadedb.database.BaseRecord; import com.arcadedb.database.Binary; +import com.arcadedb.database.DataEncryption; import com.arcadedb.database.Database; import com.arcadedb.database.DatabaseContext; import com.arcadedb.database.DatabaseInternal; @@ -65,6 +66,7 @@ public class BinarySerializer { private final BinaryComparator comparator = new BinaryComparator(); private Class dateImplementation; private Class dateTimeImplementation; + private DataEncryption dataEncryption; public BinarySerializer(final ContextConfiguration configuration) throws ClassNotFoundException { setDateImplementation(configuration.getValue(GlobalConfiguration.DATE_IMPLEMENTATION)); @@ -332,9 +334,10 @@ else if (properties == 0) return null; } - public void serializeValue(final Database database, final Binary content, final byte type, Object value) { + public void serializeValue(final Database database, final Binary serialized, final byte type, Object value) { if (value == null) return; + Binary content = dataEncryption != null ? new Binary() : serialized; switch (type) { case BinaryTypes.TYPE_NULL: @@ -393,8 +396,8 @@ else if (value instanceof LocalDate) break; case BinaryTypes.TYPE_COMPRESSED_RID: { final RID rid = ((Identifiable) value).getIdentity(); - content.putNumber(rid.getBucketId()); - content.putNumber(rid.getPosition()); + serialized.putNumber(rid.getBucketId()); + serialized.putNumber(rid.getPosition()); break; } case BinaryTypes.TYPE_RID: { @@ -403,8 +406,8 @@ else if (value instanceof LocalDate) value = ((Result) value).getElement().get(); final RID rid = ((Identifiable) value).getIdentity(); - content.putInt(rid.getBucketId()); - content.putLong(rid.getPosition()); + serialized.putInt(rid.getBucketId()); + serialized.putLong(rid.getPosition()); break; } case BinaryTypes.TYPE_UUID: { @@ -563,10 +566,26 @@ else if (value instanceof LocalDate) default: LogManager.instance().log(this, Level.INFO, "Error on serializing value '" + value + "', type not supported"); } + + if (dataEncryption != null) { + switch (type) { + case BinaryTypes.TYPE_NULL: + case BinaryTypes.TYPE_COMPRESSED_RID: + case BinaryTypes.TYPE_RID: + break; + default: + serialized.putBytes(dataEncryption.encrypt(content.toByteArray())); + } + } } - public Object deserializeValue(final Database database, final Binary content, final byte type, + public Object deserializeValue(final Database database, final Binary deserialized, final byte type, final EmbeddedModifier embeddedModifier) { + Binary content = dataEncryption != null && + type != BinaryTypes.TYPE_NULL && + type != BinaryTypes.TYPE_COMPRESSED_RID && + type != BinaryTypes.TYPE_RID ? new Binary(dataEncryption.decrypt(deserialized.getBytes())) : deserialized; + final Object value; switch (type) { case BinaryTypes.TYPE_NULL: @@ -626,10 +645,10 @@ public Object deserializeValue(final Database database, final Binary content, fi value = new BigDecimal(new BigInteger(unscaledValue), scale); break; case BinaryTypes.TYPE_COMPRESSED_RID: - value = new RID(database, (int) content.getNumber(), content.getNumber()); + value = new RID(database, (int) deserialized.getNumber(), deserialized.getNumber()); break; case BinaryTypes.TYPE_RID: - value = new RID(database, content.getInt(), content.getLong()); + value = new RID(database, deserialized.getInt(), deserialized.getLong()); break; case BinaryTypes.TYPE_UUID: value = new UUID(content.getNumber(), content.getNumber()); @@ -799,4 +818,8 @@ private void serializeDateTime(final Binary content, final Object value, final b content.putUnsignedNumber(DateUtils.dateTimeToTimestamp(value, DateUtils.getPrecisionFromBinaryType(type))); } + public void setDataEncryption(final DataEncryption dataEncryption) { + this.dataEncryption = dataEncryption; + } + } diff --git a/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java b/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java new file mode 100644 index 0000000000..ccca4fcbec --- /dev/null +++ b/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java @@ -0,0 +1,96 @@ +/* + * Copyright © 2024-present Arcade Data Ltd (info@arcadedata.com) + * + * 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 + * + * 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. + * + * SPDX-FileCopyrightText: 2024-present Arcade Data Ltd (info@arcadedata.com) + * SPDX-License-Identifier: Apache-2.0 + */ +package com.arcadedb.database; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; +import java.util.concurrent.atomic.AtomicReference; + +import javax.crypto.NoSuchPaddingException; + +import org.junit.jupiter.api.Test; + +import com.arcadedb.TestHelper; +import com.arcadedb.graph.Vertex; +import com.arcadedb.graph.Vertex.DIRECTION; + +/** + * @author Pawel Maslej + * @since 1 Jul 2024 + */ +class DataEncryptionTest extends TestHelper { + + String password = "password"; + String salt = "salt"; + + @Test + void dataIsEncrypted() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException { + database.setDataEncryption(DefaultDataEncryption.useDefaults(DefaultDataEncryption.getSecretKeyFromPasswordUsingDefaults(password, salt))); + + database.command("sql", "create vertex type Person"); + database.command("sql", "create property Person.id string"); + database.command("sql", "create index on Person (id) unique"); + database.command("sql", "create property Person.name string"); + database.command("sql", "create edge type Knows"); + + var v1Id = new AtomicReference(null); + var v2Id = new AtomicReference(null); + + database.transaction(() -> { + var v1 = database.newVertex("Person").set("name", "John").save(); + var v2 = database.newVertex("Person").set("name", "Doe").save(); + v1.newEdge("Knows", v2, false, "since", 2024); + verify(v1, v2, true); + v1Id.set(v1.getIdentity()); + v2Id.set(v2.getIdentity()); + }); + verify(v1Id.get(), v2Id.get(), true); + + database.setDataEncryption(null); + verify(v1Id.get(), v2Id.get(), false); + + reopenDatabase(); + verify(v1Id.get(), v2Id.get(), false); + + database.setDataEncryption(DefaultDataEncryption.useDefaults(DefaultDataEncryption.getSecretKeyFromPasswordUsingDefaults(password, salt))); + verify(v1Id.get(), v2Id.get(), true); + } + + private void verify(RID rid1, RID rid2, boolean isEquals) { + database.transaction(() -> { + var p1 = database.lookupByRID(rid1, true).asVertex(); + var p2 = database.lookupByRID(rid2, true).asVertex(); + verify(p1, p2, isEquals); + }); + } + + private void verify(Vertex p1, Vertex p2, boolean isEquals) { + if (isEquals) { + assertEquals("John", p1.get("name")); + assertEquals("Doe", p2.get("name")); + assertEquals(2024, p1.getEdges(DIRECTION.OUT, "Knows").iterator().next().get("since")); + } else { + assertFalse(((String) p1.get("name")).contains("John")); + assertFalse(((String) p2.get("name")).contains("Doe")); + assertFalse(p1.getEdges(DIRECTION.OUT, "Knows").iterator().next().get("since").toString().contains("2024")); + } + } +} \ No newline at end of file diff --git a/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java b/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java new file mode 100644 index 0000000000..b45e35e70b --- /dev/null +++ b/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java @@ -0,0 +1,64 @@ +/* + * Copyright © 2024-present Arcade Data Ltd (info@arcadedata.com) + * + * 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 + * + * 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. + * + * SPDX-FileCopyrightText: 2024-present Arcade Data Ltd (info@arcadedata.com) + * SPDX-License-Identifier: Apache-2.0 + */ +package com.arcadedb.database; + +import static org.junit.jupiter.api.Assertions.*; + +import java.nio.ByteBuffer; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; + +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * @author Pawel Maslej + * @since 1 Jul 2024 + */ +class DefaultDataEncryptionTest { + static SecretKey key; + + @BeforeAll + public static void beforeAll() throws NoSuchAlgorithmException, InvalidKeySpecException { + String password = "password"; + String salt = "salt"; + key = DefaultDataEncryption.getSecretKeyFromPasswordUsingDefaults(password, salt); + } + + @Test + void testEncryptionOfString() throws NoSuchAlgorithmException, NoSuchPaddingException { + var dde = DefaultDataEncryption.useDefaults(key); + String data = "data"; + byte[] encryptedData = dde.encrypt(data.getBytes()); + String decryptedData = new String(dde.decrypt(encryptedData)); + assertEquals(data, decryptedData); + } + + @Test + void testEncryptionOfDouble() throws NoSuchAlgorithmException, NoSuchPaddingException { + var dde = DefaultDataEncryption.useDefaults(key); + double data = 1000000d; + byte[] encryptedData = dde.encrypt(ByteBuffer.allocate(8).putLong(Double.doubleToLongBits(data)).array()); + var decryptedData = Double.longBitsToDouble(ByteBuffer.wrap(dde.decrypt(encryptedData)).getLong()); + assertEquals(data, decryptedData); + } +} \ No newline at end of file From 72f7038cc1a84fc6d4c5d8439461d2f84b478d71 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Thu, 5 Sep 2024 20:11:21 +0200 Subject: [PATCH 02/45] fix pre-commit errors --- engine/src/main/java/com/arcadedb/database/DataEncryption.java | 2 +- .../main/java/com/arcadedb/database/DefaultDataEncryption.java | 2 +- .../main/java/com/arcadedb/exception/EncryptionException.java | 2 +- .../src/test/java/com/arcadedb/database/DataEncryptionTest.java | 2 +- .../java/com/arcadedb/database/DefaultDataEncryptionTest.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/src/main/java/com/arcadedb/database/DataEncryption.java b/engine/src/main/java/com/arcadedb/database/DataEncryption.java index 017a061e65..42e44f4309 100644 --- a/engine/src/main/java/com/arcadedb/database/DataEncryption.java +++ b/engine/src/main/java/com/arcadedb/database/DataEncryption.java @@ -27,4 +27,4 @@ public interface DataEncryption { public byte[] encrypt(byte[] data); public byte[] decrypt(byte[] data); -} \ No newline at end of file +} diff --git a/engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java b/engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java index 68b9902aa3..fcf312e921 100644 --- a/engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java +++ b/engine/src/main/java/com/arcadedb/database/DefaultDataEncryption.java @@ -119,4 +119,4 @@ public static SecretKey getKeyFromPassword(String password, String salt, String final KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), saltIterations, keyLength); return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), secretKeyAlgorithm); } -} \ No newline at end of file +} diff --git a/engine/src/main/java/com/arcadedb/exception/EncryptionException.java b/engine/src/main/java/com/arcadedb/exception/EncryptionException.java index 91f996b03f..9ed4c65746 100644 --- a/engine/src/main/java/com/arcadedb/exception/EncryptionException.java +++ b/engine/src/main/java/com/arcadedb/exception/EncryptionException.java @@ -30,4 +30,4 @@ public EncryptionException(final String message, final Throwable cause) { public EncryptionException(final Throwable cause) { super(cause); } -} \ No newline at end of file +} diff --git a/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java b/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java index ccca4fcbec..f29fcce5d8 100644 --- a/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java +++ b/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java @@ -93,4 +93,4 @@ private void verify(Vertex p1, Vertex p2, boolean isEquals) { assertFalse(p1.getEdges(DIRECTION.OUT, "Knows").iterator().next().get("since").toString().contains("2024")); } } -} \ No newline at end of file +} diff --git a/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java b/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java index b45e35e70b..83c77c3dca 100644 --- a/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java +++ b/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java @@ -61,4 +61,4 @@ void testEncryptionOfDouble() throws NoSuchAlgorithmException, NoSuchPaddingExce var decryptedData = Double.longBitsToDouble(ByteBuffer.wrap(dde.decrypt(encryptedData)).getLong()); assertEquals(data, decryptedData); } -} \ No newline at end of file +} From 9f793137fbfe3651cbdd4050f77c17c61a613523 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 10:53:26 -0400 Subject: [PATCH 03/45] build(deps): bump org.codehaus.mojo:buildnumber-maven-plugin (#1718) Bumps [org.codehaus.mojo:buildnumber-maven-plugin](https://github.com/mojohaus/buildnumber-maven-plugin) from 1.4 to 3.2.1. - [Release notes](https://github.com/mojohaus/buildnumber-maven-plugin/releases) - [Commits](https://github.com/mojohaus/buildnumber-maven-plugin/compare/buildnumber-maven-plugin-1.4...3.2.1) --- updated-dependencies: - dependency-name: org.codehaus.mojo:buildnumber-maven-plugin dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- engine/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/pom.xml b/engine/pom.xml index 518fadb943..461e63fd73 100644 --- a/engine/pom.xml +++ b/engine/pom.xml @@ -55,7 +55,7 @@ org.codehaus.mojo buildnumber-maven-plugin - 1.4 + 3.2.1 validate From c48bff3664bbac77d1b52720ae4b34f720834a98 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 10:53:41 -0400 Subject: [PATCH 04/45] build(deps): bump mockito-core.version from 5.12.0 to 5.13.0 (#1717) Bumps `mockito-core.version` from 5.12.0 to 5.13.0. Updates `org.mockito:mockito-core` from 5.12.0 to 5.13.0 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.12.0...v5.13.0) Updates `org.mockito:mockito-junit-jupiter` from 5.12.0 to 5.13.0 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.12.0...v5.13.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.mockito:mockito-junit-jupiter dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- network/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/pom.xml b/network/pom.xml index 3ed3b9545e..7c2f6b8946 100644 --- a/network/pom.xml +++ b/network/pom.xml @@ -33,7 +33,7 @@ jar - 5.12.0 + 5.13.0 From 7bc21a1f2bc052247832bcd7e66590888ab44dc6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:02:35 -0400 Subject: [PATCH 05/45] build(deps-dev): bump ch.qos.logback:logback-classic from 1.5.7 to 1.5.8 (#1716) Bumps [ch.qos.logback:logback-classic](https://github.com/qos-ch/logback) from 1.5.7 to 1.5.8. - [Commits](https://github.com/qos-ch/logback/compare/v_1.5.7...v_1.5.8) --- updated-dependencies: - dependency-name: ch.qos.logback:logback-classic dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- e2e/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/pom.xml b/e2e/pom.xml index b897800132..866c8fdee9 100644 --- a/e2e/pom.xml +++ b/e2e/pom.xml @@ -32,7 +32,7 @@ 1.20.1 42.7.4 - 1.5.7 + 1.5.8 true From b1b76170f56fe155dccb3135fb27eba6f78fa6a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:03:04 -0400 Subject: [PATCH 06/45] build(deps): bump io.netty:netty-transport (#1715) Bumps [io.netty:netty-transport](https://github.com/netty/netty) from 4.1.112.Final to 4.1.113.Final. - [Commits](https://github.com/netty/netty/compare/netty-4.1.112.Final...netty-4.1.113.Final) --- updated-dependencies: - dependency-name: io.netty:netty-transport dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- mongodbw/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongodbw/pom.xml b/mongodbw/pom.xml index eeac7459f8..fc7a7e24d0 100644 --- a/mongodbw/pom.xml +++ b/mongodbw/pom.xml @@ -34,7 +34,7 @@ 1.45.0 3.12.13 - 4.1.112.Final + 4.1.113.Final From b5d55a622afc38d8b67c92d18edae3d9633eb2e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:48:36 -0400 Subject: [PATCH 07/45] build(deps-dev): bump org.apache.tomcat:tomcat-jdbc (#1728) Bumps org.apache.tomcat:tomcat-jdbc from 10.1.28 to 10.1.30. --- updated-dependencies: - dependency-name: org.apache.tomcat:tomcat-jdbc dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- postgresw/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresw/pom.xml b/postgresw/pom.xml index 4821ab55c4..f243f4bce7 100644 --- a/postgresw/pom.xml +++ b/postgresw/pom.xml @@ -34,7 +34,7 @@ 42.7.4 - 10.1.28 + 10.1.30 From 527c5b71509c33e3b3d0b61f688edcb4c99e45e7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:51:40 -0400 Subject: [PATCH 08/45] build(deps): bump jline.version from 3.26.3 to 3.27.0 (#1726) Bumps `jline.version` from 3.26.3 to 3.27.0. Updates `org.jline:jline-terminal` from 3.26.3 to 3.27.0 - [Release notes](https://github.com/jline/jline3/releases) - [Changelog](https://github.com/jline/jline3/blob/master/changelog.md) - [Commits](https://github.com/jline/jline3/compare/jline-parent-3.26.3...jline-3.27.0) Updates `org.jline:jline-reader` from 3.26.3 to 3.27.0 - [Release notes](https://github.com/jline/jline3/releases) - [Changelog](https://github.com/jline/jline3/blob/master/changelog.md) - [Commits](https://github.com/jline/jline3/compare/jline-parent-3.26.3...jline-3.27.0) Updates `org.jline:jline-terminal-jansi` from 3.26.3 to 3.27.0 - [Release notes](https://github.com/jline/jline3/releases) - [Changelog](https://github.com/jline/jline3/blob/master/changelog.md) - [Commits](https://github.com/jline/jline3/compare/jline-parent-3.26.3...jline-3.27.0) --- updated-dependencies: - dependency-name: org.jline:jline-terminal dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.jline:jline-reader dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.jline:jline-terminal-jansi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- console/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/pom.xml b/console/pom.xml index 2bf074ba59..ce5b44edf0 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -30,7 +30,7 @@ - 3.26.3 + 3.27.0 arcadedb-console From ff10fa62781efc1f7f1cbc89dbac91a5103e23b0 Mon Sep 17 00:00:00 2001 From: lvca Date: Wed, 25 Sep 2024 17:31:26 -0400 Subject: [PATCH 09/45] fix: avoid file channel closing when the thread is interrupted. This issue was found with ArcadeBrain when a ScriptAction (Javascript) exceeds the max timeout and the Future task is canceled. --- .../engine/PaginatedComponentFile.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java b/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java index b68666313a..07844d7fdc 100644 --- a/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java +++ b/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java @@ -21,8 +21,10 @@ import com.arcadedb.log.LogManager; import java.io.*; +import java.lang.reflect.*; import java.nio.*; import java.nio.channels.*; +import java.nio.channels.spi.*; import java.util.logging.*; import java.util.zip.*; @@ -32,6 +34,14 @@ public class PaginatedComponentFile extends ComponentFile { private FileChannel channel; private int pageSize; + public class InterruptibleInvocationHandler implements InvocationHandler { + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + LogManager.instance().log(this, Level.SEVERE, "Attempt to close channel"); + return null; + } + } + public PaginatedComponentFile() { } @@ -195,6 +205,22 @@ protected void open(final String filePath, final MODE mode) throws FileNotFoundE this.osFile = new File(filePath); this.file = new RandomAccessFile(osFile, mode == MODE.READ_WRITE ? "rw" : "r"); this.channel = this.file.getChannel(); + doNotCloseOnInterrupt(this.channel); this.open = true; } + + private void doNotCloseOnInterrupt(final FileChannel fc) { + try { + Field field = AbstractInterruptibleChannel.class.getDeclaredField("interruptor"); + Class interruptibleClass = field.getType(); + field.setAccessible(true); + field.set(fc, Proxy.newProxyInstance( + interruptibleClass.getClassLoader(), + new Class[] { interruptibleClass }, + new InterruptibleInvocationHandler())); + } catch (final Exception e) { + System.err.println("Couldn't disable close on interrupt"); + e.printStackTrace(); + } + } } From 41ba44bc3898ae03ca3c8060eb4867991dab6114 Mon Sep 17 00:00:00 2001 From: lvca Date: Wed, 25 Sep 2024 18:30:18 -0400 Subject: [PATCH 10/45] feat: supported timezone as 2nd param in format method with dates --- .../arcadedb/query/sql/method/string/SQLMethodFormat.java | 2 +- engine/src/main/java/com/arcadedb/utility/DateUtils.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/engine/src/main/java/com/arcadedb/query/sql/method/string/SQLMethodFormat.java b/engine/src/main/java/com/arcadedb/query/sql/method/string/SQLMethodFormat.java index 325922558d..9e26b631e3 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/method/string/SQLMethodFormat.java +++ b/engine/src/main/java/com/arcadedb/query/sql/method/string/SQLMethodFormat.java @@ -60,7 +60,7 @@ public Object execute(final Object value, final Identifiable iRecord, final Comm return result; } else if (DateUtils.isDate(value)) { - return DateUtils.format(value, format); + return DateUtils.format(value, format, iParams.length > 1 ? (String) iParams[1] : null); } return value != null ? String.format(format, value) : null; } diff --git a/engine/src/main/java/com/arcadedb/utility/DateUtils.java b/engine/src/main/java/com/arcadedb/utility/DateUtils.java index f6ad883b59..2ba77632c0 100755 --- a/engine/src/main/java/com/arcadedb/utility/DateUtils.java +++ b/engine/src/main/java/com/arcadedb/utility/DateUtils.java @@ -369,7 +369,12 @@ else if (obj instanceof Date) return getFormatter(format).format(millisToLocalDateTime(((Date) obj).getTime(), timeZone)); else if (obj instanceof Calendar) return getFormatter(format).format(millisToLocalDateTime(((Calendar) obj).getTimeInMillis(), timeZone)); - else if (obj instanceof TemporalAccessor) + else if (obj instanceof LocalDateTime) { + if (timeZone != null) + return ((LocalDateTime) obj).atZone(ZoneId.of(timeZone)).format(getFormatter(format)); + else + return getFormatter(format).format(((LocalDateTime) obj)); + } else if (obj instanceof TemporalAccessor) return getFormatter(format).format((TemporalAccessor) obj); return null; } From e439865bd295bb65d999c42cac6432b9303f019f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 00:49:33 -0400 Subject: [PATCH 11/45] build(deps): bump lucene.version from 9.11.1 to 9.12.0 (#1739) Bumps `lucene.version` from 9.11.1 to 9.12.0. Updates `org.apache.lucene:lucene-analysis-common` from 9.11.1 to 9.12.0 Updates `org.apache.lucene:lucene-queryparser` from 9.11.1 to 9.12.0 --- updated-dependencies: - dependency-name: org.apache.lucene:lucene-analysis-common dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.lucene:lucene-queryparser dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- engine/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/pom.xml b/engine/pom.xml index 461e63fd73..1a441b8cc5 100644 --- a/engine/pom.xml +++ b/engine/pom.xml @@ -37,7 +37,7 @@ 1.2.21 2.11.0 1.8.0 - 9.11.1 + 9.12.0 22.3.5 1.1.0 0.8 From 9978b4cb22d1120bc0b4b45b946062e85b5d58e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 00:49:53 -0400 Subject: [PATCH 12/45] build(deps): bump org.apache.maven.plugins:maven-gpg-plugin (#1738) Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.5 to 3.2.7. - [Release notes](https://github.com/apache/maven-gpg-plugin/releases) - [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.5...maven-gpg-plugin-3.2.7) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-gpg-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fd5789572a..64c747cb56 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ 3.3.1 3.10.0 3.3.1 - 3.2.5 + 3.2.7 2.17.1 3.4.2 3.6.0 From 071ffd670d62a5386302edde28a6d3ebc7c7bd98 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 00:50:17 -0400 Subject: [PATCH 13/45] build(deps): bump com.mycila:license-maven-plugin from 4.5 to 4.6 (#1737) Bumps [com.mycila:license-maven-plugin](https://github.com/mathieucarbou/license-maven-plugin) from 4.5 to 4.6. - [Release notes](https://github.com/mathieucarbou/license-maven-plugin/releases) - [Commits](https://github.com/mathieucarbou/license-maven-plugin/compare/license-maven-plugin-4.5...license-maven-plugin-4.6) --- updated-dependencies: - dependency-name: com.mycila:license-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 64c747cb56..9b7cd1dced 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ true - 4.5 + 4.6 5.13.0 3.1.3 From a20d39f6564799ff385359c3fc749622a268ad2c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 00:50:46 -0400 Subject: [PATCH 14/45] build(deps): bump junit.jupiter.version from 5.11.0 to 5.11.1 (#1736) Bumps `junit.jupiter.version` from 5.11.0 to 5.11.1. Updates `org.junit.jupiter:junit-jupiter` from 5.11.0 to 5.11.1 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.11.0...r5.11.1) Updates `org.junit.vintage:junit-vintage-engine` from 5.11.0 to 5.11.1 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.11.0...r5.11.1) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.junit.vintage:junit-vintage-engine dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9b7cd1dced..625771bb15 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ 1.7.0 3.26.3 - 5.11.0 + 5.11.1 true From 611222752591248a82696651c5e3c15bca47d3cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 00:51:05 -0400 Subject: [PATCH 15/45] build(deps): bump io.fabric8:docker-maven-plugin from 0.45.0 to 0.45.1 (#1734) Bumps [io.fabric8:docker-maven-plugin](https://github.com/fabric8io/docker-maven-plugin) from 0.45.0 to 0.45.1. - [Release notes](https://github.com/fabric8io/docker-maven-plugin/releases) - [Changelog](https://github.com/fabric8io/docker-maven-plugin/blob/master/doc/changelog.md) - [Commits](https://github.com/fabric8io/docker-maven-plugin/compare/v0.45.0...v0.45.1) --- updated-dependencies: - dependency-name: io.fabric8:docker-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/pom.xml b/package/pom.xml index bd21b69377..438d20720b 100644 --- a/package/pom.xml +++ b/package/pom.xml @@ -35,7 +35,7 @@ 1.12.0 arm64v8/,amd64/,winamd64/,arm32v7/ - 0.45.0 + 0.45.1 linux/amd64 From 442a3ae743289b5d296d944627b8bd07fbc73dd7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 00:51:12 -0400 Subject: [PATCH 16/45] build(deps): bump org.mockito:mockito-core from 5.13.0 to 5.14.0 (#1735) Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.13.0 to 5.14.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.13.0...v5.14.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 625771bb15..75a8eb98a8 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 4.6 - 5.13.0 + 5.14.0 3.1.3 From e18c658a6424ad6dbee3b1bbbb20ea33f616af3e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:22:11 -0400 Subject: [PATCH 17/45] build(deps): bump io.netty:netty-transport (#1746) Bumps [io.netty:netty-transport](https://github.com/netty/netty) from 4.1.113.Final to 4.1.114.Final. - [Commits](https://github.com/netty/netty/compare/netty-4.1.113.Final...netty-4.1.114.Final) --- updated-dependencies: - dependency-name: io.netty:netty-transport dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- mongodbw/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongodbw/pom.xml b/mongodbw/pom.xml index fc7a7e24d0..2cfb3f533c 100644 --- a/mongodbw/pom.xml +++ b/mongodbw/pom.xml @@ -34,7 +34,7 @@ 1.45.0 3.12.13 - 4.1.113.Final + 4.1.114.Final From c9edaf2ab0144b633211432ef7a34e6dcf2418a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:22:23 -0400 Subject: [PATCH 18/45] build(deps): bump org.apache.maven.plugins:maven-javadoc-plugin (#1745) Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.10.0 to 3.10.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.10.0...maven-javadoc-plugin-3.10.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 75a8eb98a8..6e67974b72 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 3.5.0 3.7.1 3.3.1 - 3.10.0 + 3.10.1 3.3.1 3.2.7 2.17.1 From bf24f79f972c086cdeef328c5c71806d7e6c474a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:22:35 -0400 Subject: [PATCH 19/45] build(deps): bump org.mockito:mockito-core from 5.13.0 to 5.14.1 (#1744) Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.13.0 to 5.14.1. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.13.0...v5.14.1) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6e67974b72..fcd3dfacb5 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 4.6 - 5.14.0 + 5.14.1 3.1.3 From ba9fae5ace7d7e8d0a5deeb54f171975bffa733e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:22:47 -0400 Subject: [PATCH 20/45] build(deps): bump junit.jupiter.version from 5.11.1 to 5.11.2 (#1743) Bumps `junit.jupiter.version` from 5.11.1 to 5.11.2. Updates `org.junit.jupiter:junit-jupiter` from 5.11.1 to 5.11.2 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.11.1...r5.11.2) Updates `org.junit.vintage:junit-vintage-engine` from 5.11.1 to 5.11.2 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.11.1...r5.11.2) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.junit.vintage:junit-vintage-engine dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fcd3dfacb5..5d6b070968 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ 1.7.0 3.26.3 - 5.11.1 + 5.11.2 true From 83d7908edee38562cc3df0748f6fe65cb1f482ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:23:01 -0400 Subject: [PATCH 21/45] build(deps-dev): bump testcontainers.version from 1.20.1 to 1.20.2 (#1742) Bumps `testcontainers.version` from 1.20.1 to 1.20.2. Updates `org.testcontainers:testcontainers` from 1.20.1 to 1.20.2 - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.20.1...1.20.2) Updates `org.testcontainers:junit-jupiter` from 1.20.1 to 1.20.2 - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.20.1...1.20.2) --- updated-dependencies: - dependency-name: org.testcontainers:testcontainers dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: org.testcontainers:junit-jupiter dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- e2e/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/pom.xml b/e2e/pom.xml index 866c8fdee9..52a8fe5d5b 100644 --- a/e2e/pom.xml +++ b/e2e/pom.xml @@ -30,7 +30,7 @@ - 1.20.1 + 1.20.2 42.7.4 1.5.8 true From 70464bc46c26dc0bbf23d3ef81ec0120ce104e72 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:23:14 -0400 Subject: [PATCH 22/45] build(deps): bump org.apache.maven.plugins:maven-surefire-plugin (#1741) Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.5.0 to 3.5.1. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.5.0...surefire-3.5.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5d6b070968..010bc5f655 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ 1.4.13 3.13.0 0.8.12 - 3.5.0 + 3.5.1 3.5.0 3.7.1 3.3.1 From 2f10144950cf8f84e60aeef22c4c0344b4481bb0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:24:23 -0400 Subject: [PATCH 23/45] build(deps): bump org.apache.maven.plugins:maven-failsafe-plugin (#1740) Bumps [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) from 3.5.0 to 3.5.1. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.5.0...surefire-3.5.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 010bc5f655..bd7d0aac97 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ 3.13.0 0.8.12 3.5.1 - 3.5.0 + 3.5.1 3.7.1 3.3.1 3.10.1 From ac46a0da6ebe4f5d337e50874f3d8a0d1bf092b1 Mon Sep 17 00:00:00 2001 From: lvca Date: Fri, 11 Oct 2024 11:57:04 -0400 Subject: [PATCH 24/45] Minor optimization --- .../main/java/com/arcadedb/server/http/HttpSessionManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/main/java/com/arcadedb/server/http/HttpSessionManager.java b/server/src/main/java/com/arcadedb/server/http/HttpSessionManager.java index b6c1032e55..52e9d2eee4 100644 --- a/server/src/main/java/com/arcadedb/server/http/HttpSessionManager.java +++ b/server/src/main/java/com/arcadedb/server/http/HttpSessionManager.java @@ -58,6 +58,9 @@ public void close() { } public int checkSessionsValidity() { + if (sessions.isEmpty()) + return 0; + return executeInWriteLock(() -> { int expired = 0; Map.Entry s; From 965a61bc685ed69d3e02eff57dccc1e1f1dd1f10 Mon Sep 17 00:00:00 2001 From: lvca Date: Sat, 12 Oct 2024 12:57:00 -0400 Subject: [PATCH 25/45] Updated version to 24.11.1-SNAPSHOT --- console/pom.xml | 2 +- coverage/pom.xml | 2 +- e2e/pom.xml | 2 +- engine/pom.xml | 2 +- .../test/java/com/arcadedb/engine/DeleteAllTest.java | 10 +++++----- graphql/pom.xml | 2 +- gremlin/pom.xml | 2 +- integration/pom.xml | 2 +- mongodbw/pom.xml | 2 +- network/pom.xml | 2 +- package/pom.xml | 2 +- pom.xml | 3 ++- postgresw/pom.xml | 2 +- redisw/pom.xml | 2 +- server/pom.xml | 2 +- studio/pom.xml | 2 +- 16 files changed, 21 insertions(+), 20 deletions(-) diff --git a/console/pom.xml b/console/pom.xml index ce5b44edf0..303c5f3b1c 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/coverage/pom.xml b/coverage/pom.xml index f74d322e67..f9677f1433 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -26,7 +26,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/e2e/pom.xml b/e2e/pom.xml index 52a8fe5d5b..ad87c6a3b6 100644 --- a/e2e/pom.xml +++ b/e2e/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/engine/pom.xml b/engine/pom.xml index 1a441b8cc5..b9b6605436 100644 --- a/engine/pom.xml +++ b/engine/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java b/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java index 0c03c14ed7..034521a74f 100644 --- a/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java +++ b/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java @@ -28,10 +28,10 @@ public void testCreateAndDeleteGraph() { db.getSchema().createEdgeType(EDGE_TYPE, 1); for (int i = 0; i < CYCLES; i++) { - System.out.println("Cycle " + i); - List.of(new File(databaseFactory.getDatabasePath()).listFiles()) - .forEach(f -> System.out.println("- " + f.getName() + ": " + FileUtils.getSizeAsString( - f.length()))); + //System.out.println("Cycle " + i); +// List.of(new File(databaseFactory.getDatabasePath()).listFiles()) +// .forEach(f -> System.out.println("- " + f.getName() + ": " + FileUtils.getSizeAsString( +// f.length()))); db.transaction(() -> { final MutableVertex root = db.newVertex(VERTEX_TYPE)// @@ -59,7 +59,7 @@ public void testCreateAndDeleteGraph() { } final ResultSet result = db.command("sql", "check database"); - System.out.println(result.nextIfAvailable().toJSON()); +// System.out.println(result.nextIfAvailable().toJSON()); } finally { if (databaseFactory.exists()) diff --git a/graphql/pom.xml b/graphql/pom.xml index a66455ae5a..fd6e7edb66 100644 --- a/graphql/pom.xml +++ b/graphql/pom.xml @@ -24,7 +24,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/gremlin/pom.xml b/gremlin/pom.xml index d7b8ee2237..bd786790db 100644 --- a/gremlin/pom.xml +++ b/gremlin/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/integration/pom.xml b/integration/pom.xml index ab3a74905d..4edaaf2414 100644 --- a/integration/pom.xml +++ b/integration/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/mongodbw/pom.xml b/mongodbw/pom.xml index 2cfb3f533c..13a97284f7 100644 --- a/mongodbw/pom.xml +++ b/mongodbw/pom.xml @@ -24,7 +24,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/network/pom.xml b/network/pom.xml index 7c2f6b8946..3075f62faa 100644 --- a/network/pom.xml +++ b/network/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/package/pom.xml b/package/pom.xml index 438d20720b..6e2c146bd1 100644 --- a/package/pom.xml +++ b/package/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index bd7d0aac97..bcf82dcd7e 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent pom - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ArcadeDB https://arcadedata.com/ @@ -184,6 +184,7 @@ --add-exports java.management/sun.management=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED + --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED diff --git a/postgresw/pom.xml b/postgresw/pom.xml index f243f4bce7..c177c8916a 100644 --- a/postgresw/pom.xml +++ b/postgresw/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/redisw/pom.xml b/redisw/pom.xml index d7f46eeabc..7cf71053c7 100644 --- a/redisw/pom.xml +++ b/redisw/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/server/pom.xml b/server/pom.xml index 166d145d14..d863dff592 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -25,7 +25,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT ../pom.xml diff --git a/studio/pom.xml b/studio/pom.xml index 925c8e0d49..58cc539567 100644 --- a/studio/pom.xml +++ b/studio/pom.xml @@ -6,7 +6,7 @@ com.arcadedb arcadedb-parent - 24.8.1-SNAPSHOT + 24.11.1-SNAPSHOT arcadedb-studio From f518b2eac7b335eb113f773b130ce6c5565b6229 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Sat, 12 Oct 2024 10:09:39 -0700 Subject: [PATCH 26/45] fix: remove meterian token and add oss true flag (#1747) --- .github/workflows/meterian.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/meterian.yml b/.github/workflows/meterian.yml index d6d3956808..755adc7241 100644 --- a/.github/workflows/meterian.yml +++ b/.github/workflows/meterian.yml @@ -23,5 +23,5 @@ jobs: uses: actions/checkout@v4 - name: Meterian Scanner uses: MeterianHQ/meterian-github-action@v1.0.17 - env: - METERIAN_API_TOKEN: ${{ secrets.METERIAN_API_TOKEN }} + with: + oss: true From 1e7607614126d991b59235a39f336612df6477c8 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Sat, 12 Oct 2024 13:29:38 -0700 Subject: [PATCH 27/45] pre-commit reconf (#1748) [skip ci] --- .github/workflows/mvn-deploy.yml | 6 +++--- .github/workflows/mvn-test.yml | 6 +++--- .pre-commit-config.yaml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/mvn-deploy.yml b/.github/workflows/mvn-deploy.yml index b3ab95f801..9e21642247 100644 --- a/.github/workflows/mvn-deploy.yml +++ b/.github/workflows/mvn-deploy.yml @@ -16,9 +16,9 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} run: clean, cancel verbose: false - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - - uses: pre-commit/action@v3.0.1 + - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + # - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 + # - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - name: Login to Docker Hub uses: docker/login-action@v3 diff --git a/.github/workflows/mvn-test.yml b/.github/workflows/mvn-test.yml index c084fa0c9f..a61aa8b9ee 100644 --- a/.github/workflows/mvn-test.yml +++ b/.github/workflows/mvn-test.yml @@ -19,9 +19,9 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} run: clean, cancel verbose: false - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - - uses: pre-commit/action@v3.0.1 + - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + # - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 + # - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - name: Set up QEMU uses: docker/setup-qemu-action@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 686b176b06..cab27eeb96 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: fix-byte-order-marker - id: trailing-whitespace From 14dea61a154a72767e797cc1e361ee51f3512a99 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 00:41:02 -0400 Subject: [PATCH 28/45] build(deps): bump mockito-core.version from 5.13.0 to 5.14.1 (#1752) Bumps `mockito-core.version` from 5.13.0 to 5.14.1. Updates `org.mockito:mockito-core` from 5.13.0 to 5.14.1 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.13.0...v5.14.1) Updates `org.mockito:mockito-junit-jupiter` from 5.13.0 to 5.14.1 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.13.0...v5.14.1) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.mockito:mockito-junit-jupiter dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- network/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/pom.xml b/network/pom.xml index 3075f62faa..2cd7865d0c 100644 --- a/network/pom.xml +++ b/network/pom.xml @@ -33,7 +33,7 @@ jar - 5.13.0 + 5.14.1 From e117e512e3d3a96658f4cc4e6ea89677b9f83765 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 00:41:12 -0400 Subject: [PATCH 29/45] build(deps-dev): bump org.apache.tomcat:tomcat-jdbc (#1751) Bumps org.apache.tomcat:tomcat-jdbc from 10.1.30 to 11.0.0. --- updated-dependencies: - dependency-name: org.apache.tomcat:tomcat-jdbc dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- postgresw/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresw/pom.xml b/postgresw/pom.xml index c177c8916a..00f65ca681 100644 --- a/postgresw/pom.xml +++ b/postgresw/pom.xml @@ -34,7 +34,7 @@ 42.7.4 - 10.1.30 + 11.0.0 From 588e16c8391ef7cb09c3f90c76c0f8d0fdb98001 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 00:41:22 -0400 Subject: [PATCH 30/45] build(deps-dev): bump ch.qos.logback:logback-classic (#1750) Bumps [ch.qos.logback:logback-classic](https://github.com/qos-ch/logback) from 1.5.8 to 1.5.10. - [Commits](https://github.com/qos-ch/logback/compare/v_1.5.8...v_1.5.10) --- updated-dependencies: - dependency-name: ch.qos.logback:logback-classic dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- e2e/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/pom.xml b/e2e/pom.xml index ad87c6a3b6..1d5319ff8e 100644 --- a/e2e/pom.xml +++ b/e2e/pom.xml @@ -32,7 +32,7 @@ 1.20.2 42.7.4 - 1.5.8 + 1.5.10 true From 6fc92e692e51683c9ad325276fc849ac6a8c9a35 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Mon, 14 Oct 2024 10:30:25 -0700 Subject: [PATCH 31/45] Revert "build(deps-dev): bump org.apache.tomcat:tomcat-jdbc from 10.1.30 to 11.0.0" (#1755) --- postgresw/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresw/pom.xml b/postgresw/pom.xml index 00f65ca681..c177c8916a 100644 --- a/postgresw/pom.xml +++ b/postgresw/pom.xml @@ -34,7 +34,7 @@ 42.7.4 - 11.0.0 + 10.1.30 From 4207821d055e37cbd74b76683e45073da759c2de Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Mon, 14 Oct 2024 10:49:36 -0700 Subject: [PATCH 32/45] #1753 add opens module to all scripts (#1754) --- .../arcadedb/engine/PaginatedComponentFile.java | 3 +-- package/src/main/docker/Dockerfile | 7 ++++++- package/src/main/scripts/console.bat | 9 ++++++++- package/src/main/scripts/console.sh | 9 ++++++++- package/src/main/scripts/restore.sh | 8 +++++++- package/src/main/scripts/server.bat | 16 ++++++++++++++-- package/src/main/scripts/server.sh | 15 +++++++++++++-- pom.xml | 1 + 8 files changed, 58 insertions(+), 10 deletions(-) diff --git a/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java b/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java index 07844d7fdc..b93a5b13ae 100644 --- a/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java +++ b/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java @@ -219,8 +219,7 @@ private void doNotCloseOnInterrupt(final FileChannel fc) { new Class[] { interruptibleClass }, new InterruptibleInvocationHandler())); } catch (final Exception e) { - System.err.println("Couldn't disable close on interrupt"); - e.printStackTrace(); + LogManager.instance().log(this, Level.SEVERE, "Couldn't disable close on interrupt", e); } } } diff --git a/package/src/main/docker/Dockerfile b/package/src/main/docker/Dockerfile index b94cb3131d..d62f7f1f2c 100644 --- a/package/src/main/docker/Dockerfile +++ b/package/src/main/docker/Dockerfile @@ -23,7 +23,12 @@ ENV JAVA_OPTS=" " ENV ARCADEDB_OPTS_MEMORY="-Xms2G -Xmx2G" -ENV ARCADEDB_JMX="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9998" +ENV ARCADEDB_JMX="-Dcom.sun.management.jmxremote=true \ + -Dcom.sun.management.jmxremote.local.only=false \ + -Dcom.sun.management.jmxremote.authenticate=false \ + -Dcom.sun.management.jmxremote.ssl=false \ + -Dcom.sun.management.jmxremote.port=9999 \ + -Dcom.sun.management.jmxremote.rmi.port=9998" RUN useradd -ms /bin/bash arcadedb diff --git a/package/src/main/scripts/console.bat b/package/src/main/scripts/console.bat index 09d6430604..0352d88e4d 100755 --- a/package/src/main/scripts/console.bat +++ b/package/src/main/scripts/console.bat @@ -59,7 +59,14 @@ cd /d %ARCADEDB_HOME% rem Get full command line arguments for the batch file set CMD_LINE_ARGS=%* -set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -Dfile.encoding=UTF8 -Dpolyglot.engine.WarnInterpreterOnly=false +set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError ^ + --add-exports java.management/sun.management=ALL-UNNAMED ^ + --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED ^ + --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED ^ + -Dpolyglot.engine.WarnInterpreterOnly=false ^ + -Djava.awt.headless=true ^ + -Dfile.encoding=UTF8 ^ + -Djava.util.logging.config.file=config/arcadedb-log.properties "%JAVACMD%" ^ -client ^ diff --git a/package/src/main/scripts/console.sh b/package/src/main/scripts/console.sh index 4c04e89d35..078567c4d6 100644 --- a/package/src/main/scripts/console.sh +++ b/package/src/main/scripts/console.sh @@ -48,7 +48,14 @@ fi if [ -z "$JAVA_OPTS_SCRIPT" ] ; then - JAVA_OPTS_SCRIPT="-XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.io=ALL-UNNAMED -Dpolyglot.engine.WarnInterpreterOnly=false -Djava.awt.headless=true -Dfile.encoding=UTF8 --illegal-access=deny" + JAVA_OPTS_SCRIPT="-XX:+HeapDumpOnOutOfMemoryError \ + --add-exports java.management/sun.management=ALL-UNNAMED \ + --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED \ + --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED \ + -Dpolyglot.engine.WarnInterpreterOnly=false \ + -Djava.awt.headless=true \ + -Dfile.encoding=UTF8 \ + --illegal-access=deny" fi if [ $# -gt 0 ] ; then diff --git a/package/src/main/scripts/restore.sh b/package/src/main/scripts/restore.sh index 7c473bff5c..6fb9ff38d2 100644 --- a/package/src/main/scripts/restore.sh +++ b/package/src/main/scripts/restore.sh @@ -47,7 +47,13 @@ else fi if [ -z "$JAVA_OPTS_SCRIPT" ] ; then - JAVA_OPTS_SCRIPT="-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -Dfile.encoding=UTF8 -Dpolyglot.engine.WarnInterpreterOnly=false" + JAVA_OPTS_SCRIPT="-XX:+HeapDumpOnOutOfMemoryError \ + --add-exports java.management/sun.management=ALL-UNNAMED \ + --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED \ + --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED \ + -Dpolyglot.engine.WarnInterpreterOnly=false \ + -Djava.awt.headless=true -Dfile.encoding=UTF8 \ + -Djava.util.logging.config.file=config/arcadedb-log.properties" fi exec "$JAVA" $JAVA_OPTS \ diff --git a/package/src/main/scripts/server.bat b/package/src/main/scripts/server.bat index 2f101d4ad8..99cb079d55 100755 --- a/package/src/main/scripts/server.bat +++ b/package/src/main/scripts/server.bat @@ -75,12 +75,24 @@ set CMD_LINE_ARGS=%* :doneSetArgs -set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError --add-exports java.management/sun.management=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED -Dpolyglot.engine.WarnInterpreterOnly=false -Djava.awt.headless=true -Dfile.encoding=UTF8 -Djava.util.logging.config.file=config/arcadedb-log.properties +set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError ^ + --add-exports java.management/sun.management=ALL-UNNAMED ^ + --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED ^ + --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED ^ + -Dpolyglot.engine.WarnInterpreterOnly=false ^ + -Djava.awt.headless=true ^ + -Dfile.encoding=UTF8 ^ + -Djava.util.logging.config.file=config/arcadedb-log.properties rem ARCADEDB memory options, default uses the available RAM. To set it to a specific value, like 2GB of heap, use "-Xms2G -Xmx2G" set ARCADEDB_OPTS_MEMORY= -set ARCADEDB_JMX=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9998 +set ARCADEDB_JMX=-Dcom.sun.management.jmxremote=true ^ + -Dcom.sun.management.jmxremote.local.only=false ^ + -Dcom.sun.management.jmxremote.authenticate=false ^ + -Dcom.sun.management.jmxremote.ssl=false ^ + -Dcom.sun.management.jmxremote.port=9999 ^ + -Dcom.sun.management.jmxremote.rmi.port=9998 rem TO DEBUG ARCADEDB SERVER RUN IT WITH THESE OPTIONS: rem -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 diff --git a/package/src/main/scripts/server.sh b/package/src/main/scripts/server.sh index aed21d564b..5eda0b3a0c 100644 --- a/package/src/main/scripts/server.sh +++ b/package/src/main/scripts/server.sh @@ -73,11 +73,22 @@ if [ -z "$ARCADEDB_OPTS_MEMORY" ]; then fi if [ -z "$JAVA_OPTS_SCRIPT" ]; then - JAVA_OPTS_SCRIPT="-XX:+HeapDumpOnOutOfMemoryError --add-exports java.management/sun.management=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED -Dpolyglot.engine.WarnInterpreterOnly=false -Djava.awt.headless=true -Dfile.encoding=UTF8 -Djava.util.logging.config.file=config/arcadedb-log.properties" + JAVA_OPTS_SCRIPT="-XX:+HeapDumpOnOutOfMemoryError \ + --add-exports java.management/sun.management=ALL-UNNAMED \ + --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED \ + --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED \ + -Dpolyglot.engine.WarnInterpreterOnly=false \ + -Djava.awt.headless=true -Dfile.encoding=UTF8 \ + -Djava.util.logging.config.file=config/arcadedb-log.properties" fi if [ -z "$ARCADEDB_JMX" ]; then - ARCADEDB_JMX="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9998" + ARCADEDB_JMX="-Dcom.sun.management.jmxremote=true \ + -Dcom.sun.management.jmxremote.local.only=false \ + -Dcom.sun.management.jmxremote.authenticate=false \ + -Dcom.sun.management.jmxremote.ssl=false \ + -Dcom.sun.management.jmxremote.port=9999 \ + -Dcom.sun.management.jmxremote.rmi.port=9998" fi echo $$ >$ARCADEDB_PID diff --git a/pom.xml b/pom.xml index bcf82dcd7e..02b9ff08f8 100644 --- a/pom.xml +++ b/pom.xml @@ -221,6 +221,7 @@ --add-exports java.management/sun.management=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED + --add-opens java.base/java.nio.channels.spi=ALL-UNNAMED From 29a0bff75455269a84b3bd9cf165a12222988766 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Tue, 15 Oct 2024 06:18:41 -0700 Subject: [PATCH 33/45] fix: re-enable pre-commit (#1758) --- .github/workflows/mvn-deploy.yml | 11 ++++------- .github/workflows/mvn-test.yml | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/mvn-deploy.yml b/.github/workflows/mvn-deploy.yml index 9e21642247..851ed6c26f 100644 --- a/.github/workflows/mvn-deploy.yml +++ b/.github/workflows/mvn-deploy.yml @@ -11,14 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: xembly/workflow-manager@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - run: clean, cancel - verbose: false - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 - # - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 - # - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 + with: + python-version: "3.13.0" + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - name: Login to Docker Hub uses: docker/login-action@v3 diff --git a/.github/workflows/mvn-test.yml b/.github/workflows/mvn-test.yml index a61aa8b9ee..ed3e8d97be 100644 --- a/.github/workflows/mvn-test.yml +++ b/.github/workflows/mvn-test.yml @@ -14,14 +14,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: xembly/workflow-manager@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - run: clean, cancel - verbose: false - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 - # - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 - # - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0 + with: + python-version: "3.13.0" + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - name: Set up QEMU uses: docker/setup-qemu-action@v3 From f937a09eea330bad173d5b52384a02b51095cd1c Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Sat, 19 Oct 2024 08:29:29 -0700 Subject: [PATCH 34/45] Fix code scanning alert no. 45: Implicit narrowing conversion in compound assignment (#1768) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- console/src/test/java/com/arcadedb/console/ConsoleTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/src/test/java/com/arcadedb/console/ConsoleTest.java b/console/src/test/java/com/arcadedb/console/ConsoleTest.java index 1cf81de5da..a19882b3c2 100644 --- a/console/src/test/java/com/arcadedb/console/ConsoleTest.java +++ b/console/src/test/java/com/arcadedb/console/ConsoleTest.java @@ -321,7 +321,7 @@ public void testImportCSVConsoleOK() throws IOException { newConsole.close(); int vertices = 0; - int edges = 0; + long edges = 0; try (final DatabaseFactory factory = new DatabaseFactory("./target/databases/" + DATABASE_PATH)) { try (final Database database = factory.open()) { From b69eb48fd2915f38e93da03e8e4207a1c0b58f70 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Sat, 19 Oct 2024 08:30:01 -0700 Subject: [PATCH 35/45] #1756 add upload SARIF to workflow (#1767) --- .github/workflows/meterian.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/meterian.yml b/.github/workflows/meterian.yml index 755adc7241..2695cb2a9e 100644 --- a/.github/workflows/meterian.yml +++ b/.github/workflows/meterian.yml @@ -24,4 +24,9 @@ jobs: - name: Meterian Scanner uses: MeterianHQ/meterian-github-action@v1.0.17 with: + cli_args: "--report-sarif=report.sarif" oss: true + - uses: github/codeql-action/upload-sarif@v3 + if: success() || failure() + with: + sarif_file: report.sarif From 74bbccd9569f6719e1748b3b8637fdc73e4973f5 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Sat, 19 Oct 2024 08:33:40 -0700 Subject: [PATCH 36/45] Fix code scanning alert no. 86: Client-side cross-site scripting Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- studio/src/main/resources/static/query.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/studio/src/main/resources/static/query.html b/studio/src/main/resources/static/query.html index 80fb88a6fe..66c22fac3f 100644 --- a/studio/src/main/resources/static/query.html +++ b/studio/src/main/resources/static/query.html @@ -368,8 +368,10 @@ var limitPar = getURLParameter("limit"); if (limitPar != null && limitPar != "null") { - if (limitPar != "25" && limitPar != "100" && limitPar != "500" && limitPar != "-1") - $("#inputLimit").append(""); + if (limitPar != "25" && limitPar != "100" && limitPar != "500" && limitPar != "-1") { + var sanitizedLimitPar = escapeHtml(limitPar); + $("#inputLimit").append(""); + } $("#inputLimit").val(escapeHtml(limitPar)); } From e9dddbe0495d8ffe2a860608e40af128cb717094 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:40:29 +0000 Subject: [PATCH 37/45] build(deps-dev): bump ch.qos.logback:logback-classic Bumps [ch.qos.logback:logback-classic](https://github.com/qos-ch/logback) from 1.5.10 to 1.5.11. - [Commits](https://github.com/qos-ch/logback/compare/v_1.5.10...v_1.5.11) --- updated-dependencies: - dependency-name: ch.qos.logback:logback-classic dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- e2e/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/pom.xml b/e2e/pom.xml index 1d5319ff8e..59c814e5e1 100644 --- a/e2e/pom.xml +++ b/e2e/pom.xml @@ -32,7 +32,7 @@ 1.20.2 42.7.4 - 1.5.10 + 1.5.11 true From a0fab409791fd0faa38a3ebafaa7310864934dbd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:40:41 +0000 Subject: [PATCH 38/45] build(deps): bump jline.version from 3.27.0 to 3.27.1 Bumps `jline.version` from 3.27.0 to 3.27.1. Updates `org.jline:jline-terminal` from 3.27.0 to 3.27.1 - [Release notes](https://github.com/jline/jline3/releases) - [Changelog](https://github.com/jline/jline3/blob/master/changelog.md) - [Commits](https://github.com/jline/jline3/compare/jline-3.27.0...jline-3.27.1) Updates `org.jline:jline-reader` from 3.27.0 to 3.27.1 - [Release notes](https://github.com/jline/jline3/releases) - [Changelog](https://github.com/jline/jline3/blob/master/changelog.md) - [Commits](https://github.com/jline/jline3/compare/jline-3.27.0...jline-3.27.1) Updates `org.jline:jline-terminal-jansi` from 3.27.0 to 3.27.1 - [Release notes](https://github.com/jline/jline3/releases) - [Changelog](https://github.com/jline/jline3/blob/master/changelog.md) - [Commits](https://github.com/jline/jline3/compare/jline-3.27.0...jline-3.27.1) --- updated-dependencies: - dependency-name: org.jline:jline-terminal dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.jline:jline-reader dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.jline:jline-terminal-jansi dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- console/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/pom.xml b/console/pom.xml index 303c5f3b1c..985fc40e2a 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -30,7 +30,7 @@ - 3.27.0 + 3.27.1 arcadedb-console From 34aec428b2d3934477e57e0668180bd0872a1122 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:40:45 +0000 Subject: [PATCH 39/45] build(deps): bump io.undertow:undertow-core Bumps [io.undertow:undertow-core](https://github.com/undertow-io/undertow) from 2.3.17.Final to 2.3.18.Final. - [Release notes](https://github.com/undertow-io/undertow/releases) - [Commits](https://github.com/undertow-io/undertow/compare/2.3.17.Final...2.3.18.Final) --- updated-dependencies: - dependency-name: io.undertow:undertow-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- server/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/pom.xml b/server/pom.xml index d863dff592..ad720cdaa8 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -35,7 +35,7 @@ 4.2.19 2.0.16 - 2.3.17.Final + 2.3.18.Final From cbf4b79bd1f936e16dd9692ca09d6d8e8efbd7ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:40:54 +0000 Subject: [PATCH 40/45] build(deps): bump org.mockito:mockito-core from 5.14.1 to 5.14.2 Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.14.1 to 5.14.2. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.14.1...v5.14.2) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 02b9ff08f8..7fafde8b16 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 4.6 - 5.14.1 + 5.14.2 3.1.3 From df7d7fcbd9cf82e9a72ffbc22d5da95fbeac3e19 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 15:41:12 +0000 Subject: [PATCH 41/45] build(deps-dev): bump org.apache.tomcat:tomcat-jdbc Bumps org.apache.tomcat:tomcat-jdbc from 10.1.30 to 11.0.0. --- updated-dependencies: - dependency-name: org.apache.tomcat:tomcat-jdbc dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- postgresw/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresw/pom.xml b/postgresw/pom.xml index c177c8916a..00f65ca681 100644 --- a/postgresw/pom.xml +++ b/postgresw/pom.xml @@ -34,7 +34,7 @@ 42.7.4 - 10.1.30 + 11.0.0 From b94da2df4bcbc1b61307571d940f91ab778fca05 Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Mon, 14 Oct 2024 18:44:03 -0400 Subject: [PATCH 42/45] #1756 migrate build and runtime in docker file to java 17 --- .github/workflows/mvn-deploy.yml | 4 ++-- .github/workflows/mvn-release.yml | 4 ++-- .github/workflows/mvn-test.yml | 4 ++-- package/src/main/docker/Dockerfile | 2 +- pom.xml | 2 +- studio/pom.xml | 1 + 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/mvn-deploy.yml b/.github/workflows/mvn-deploy.yml index 851ed6c26f..02e72a3ff8 100644 --- a/.github/workflows/mvn-deploy.yml +++ b/.github/workflows/mvn-deploy.yml @@ -29,11 +29,11 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: "temurin" - java-version: 11 + java-version: 17 cache: "maven" server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/mvn-release.yml b/.github/workflows/mvn-release.yml index 89a08b7dae..9de79ae3e2 100644 --- a/.github/workflows/mvn-release.yml +++ b/.github/workflows/mvn-release.yml @@ -26,11 +26,11 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: "temurin" - java-version: 11 + java-version: 17 cache: "maven" server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/mvn-test.yml b/.github/workflows/mvn-test.yml index ed3e8d97be..8dc5cb73fb 100644 --- a/.github/workflows/mvn-test.yml +++ b/.github/workflows/mvn-test.yml @@ -26,11 +26,11 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: "temurin" - java-version: 11 + java-version: 17 cache: "maven" - name: Install jars diff --git a/package/src/main/docker/Dockerfile b/package/src/main/docker/Dockerfile index d62f7f1f2c..26702a1c7c 100644 --- a/package/src/main/docker/Dockerfile +++ b/package/src/main/docker/Dockerfile @@ -15,7 +15,7 @@ # -FROM eclipse-temurin:11 +FROM eclipse-temurin:17 LABEL maintainer="Arcade Data LTD (info@arcadedb.com)" diff --git a/pom.xml b/pom.xml index 7fafde8b16..68d22aff22 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ - 11 + 17 UTF-8 diff --git a/studio/pom.xml b/studio/pom.xml index 58cc539567..91db744dbe 100644 --- a/studio/pom.xml +++ b/studio/pom.xml @@ -7,6 +7,7 @@ com.arcadedb arcadedb-parent 24.11.1-SNAPSHOT + ../pom.xml arcadedb-studio From 146c98edf9589c0e3e3c6aafa68a91724f73770d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:21:44 +0000 Subject: [PATCH 43/45] build(deps): bump mockito-core.version from 5.14.1 to 5.14.2 Bumps `mockito-core.version` from 5.14.1 to 5.14.2. Updates `org.mockito:mockito-core` from 5.14.1 to 5.14.2 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.14.1...v5.14.2) Updates `org.mockito:mockito-junit-jupiter` from 5.14.1 to 5.14.2 - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.14.1...v5.14.2) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.mockito:mockito-junit-jupiter dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- network/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/pom.xml b/network/pom.xml index 2cd7865d0c..ee05b9333e 100644 --- a/network/pom.xml +++ b/network/pom.xml @@ -33,7 +33,7 @@ jar - 5.14.1 + 5.14.2 From 551b1b34ce219ba930705e298f68057fb5b94ced Mon Sep 17 00:00:00 2001 From: Roberto Franchini Date: Sun, 15 Sep 2024 17:38:16 +0200 Subject: [PATCH 44/45] #1764 migrate form Junit5 Assertions to AssertJ --- .../console/CompositeIndexUpdateTest.java | 33 +- .../console/ConsoleAsyncInsertTest.java | 43 +- .../arcadedb/console/ConsoleBatchTest.java | 9 +- .../com/arcadedb/console/ConsoleTest.java | 320 ++-- .../com/arcadedb/console/RemoteConsoleIT.java | 196 +-- .../com/arcadedb/ACIDTransactionTest.java | 91 +- .../src/test/java/com/arcadedb/AsyncTest.java | 61 +- .../src/test/java/com/arcadedb/BLOBTest.java | 7 +- .../src/test/java/com/arcadedb/CRUDTest.java | 52 +- .../com/arcadedb/ConcurrentWriteTest.java | 9 +- .../java/com/arcadedb/ConfigurationTest.java | 16 +- .../test/java/com/arcadedb/ConstantsTest.java | 21 +- .../test/java/com/arcadedb/DocumentTest.java | 52 +- .../com/arcadedb/GlobalConfigurationTest.java | 20 +- .../java/com/arcadedb/LargeRecordsTest.java | 11 +- .../test/java/com/arcadedb/LoggerTest.java | 7 +- .../src/test/java/com/arcadedb/MVCCTest.java | 29 +- .../com/arcadedb/MultipleDatabasesTest.java | 35 +- .../com/arcadedb/PageManagerStressTest.java | 7 +- .../java/com/arcadedb/PolymorphicTest.java | 127 +- .../test/java/com/arcadedb/ProfilerTest.java | 13 +- .../arcadedb/RandomTestMultiThreadsTest.java | 7 +- .../java/com/arcadedb/ReusingSpaceTest.java | 7 +- .../test/java/com/arcadedb/TestHelper.java | 39 +- .../com/arcadedb/TransactionBucketTest.java | 77 +- .../arcadedb/TransactionIsolationTest.java | 92 +- .../com/arcadedb/TransactionTypeTest.java | 96 +- .../java/com/arcadedb/TypeConversionTest.java | 264 ++-- .../arcadedb/compression/CompressionTest.java | 7 +- .../com/arcadedb/database/BucketSQLTest.java | 47 +- .../arcadedb/database/CheckDatabaseTest.java | 267 ++-- .../arcadedb/database/DataEncryptionTest.java | 15 +- .../database/DatabaseFactoryTest.java | 23 +- .../database/DefaultDataEncryptionTest.java | 6 +- .../arcadedb/database/RecordFactoryTest.java | 40 +- .../com/arcadedb/engine/BloomFilterTest.java | 7 +- .../com/arcadedb/engine/DeleteAllTest.java | 12 +- ...lectWithThreadBucketSelectionStrategy.java | 11 +- .../arcadedb/event/DatabaseEventsTest.java | 115 +- .../arcadedb/event/RecordEncryptionTest.java | 20 +- .../com/arcadedb/event/TypeEventsTest.java | 87 +- .../function/java/JavaFunctionTest.java | 50 +- .../polyglot/PolyglotFunctionTest.java | 22 +- .../SQLDefinedJavascriptFunctionTest.java | 24 +- .../sql/SQLDefinedSQLFunctionTest.java | 29 +- .../com/arcadedb/graph/BaseGraphTest.java | 46 +- .../com/arcadedb/graph/BasicGraphTest.java | 285 ++-- .../arcadedb/graph/InsertGraphIndexTest.java | 17 +- .../com/arcadedb/graph/TestVertexDelete.java | 8 +- .../java/com/arcadedb/graph/TxGraphTest.java | 33 +- .../index/CompressedRID2RIDIndexTest.java | 13 +- .../com/arcadedb/index/DropIndexTest.java | 57 +- .../index/LSMTreeFullTextIndexTest.java | 38 +- .../index/LSMTreeIndexCompactionTest.java | 31 +- .../index/LSMTreeIndexCompositeTest.java | 22 +- .../index/LSMTreeIndexPolymorphicTest.java | 72 +- .../com/arcadedb/index/LSMTreeIndexTest.java | 309 ++-- .../index/MultipleTypesIndexTest.java | 47 +- .../arcadedb/index/NullValuesIndexTest.java | 50 +- .../index/PlainLuceneFullTextIndexTest.java | 5 +- .../arcadedb/index/TypeLSMTreeIndexTest.java | 350 ++--- .../arcadedb/query/java/JavaQueryTest.java | 46 +- .../query/polyglot/PolyglotQueryTest.java | 54 +- .../query/select/SelectExecutionIT.java | 80 +- .../query/select/SelectIndexExecutionIT.java | 76 +- .../query/select/SelectOrderByIT.java | 19 +- .../com/arcadedb/query/sql/BatchTest.java | 63 +- .../java/com/arcadedb/query/sql/DDLTest.java | 12 +- .../com/arcadedb/query/sql/OrderByTest.java | 25 +- .../query/sql/QueryAndIndexesTest.java | 22 +- .../com/arcadedb/query/sql/QueryTest.java | 197 ++- .../arcadedb/query/sql/SQLDeleteEdgeTest.java | 63 +- .../com/arcadedb/query/sql/SQLScriptTest.java | 79 +- .../executor/AlterDatabaseExecutionTest.java | 11 +- .../executor/AlterPropertyExecutionTest.java | 97 +- .../sql/executor/AlterTypeExecutionTest.java | 63 +- .../executor/BeginStatementExecutionTest.java | 18 +- .../executor/CheckClusterTypeStepTest.java | 11 +- .../sql/executor/CheckRecordTypeStepTest.java | 16 +- .../sql/executor/CheckSafeDeleteStepTest.java | 8 +- .../sql/executor/CheckTypeTypeStepTest.java | 12 +- .../ConsoleStatementExecutionTest.java | 31 +- .../ConvertToResultInternalStepTest.java | 11 +- .../ConvertToUpdatableResultStepTest.java | 11 +- .../sql/executor/CountFromIndexStepTest.java | 9 +- .../sql/executor/CountFromTypeStepTest.java | 9 +- .../query/sql/executor/CountStepTest.java | 7 +- ...ateDocumentTypeStatementExecutionTest.java | 15 +- .../CreateEdgeStatementExecutionTest.java | 12 +- .../CreatePropertyStatementExecutionTest.java | 71 +- .../CreateVertexStatementExecutionTest.java | 105 +- .../executor/DistinctExecutionStepTest.java | 9 +- .../DropBucketStatementExecutionTest.java | 17 +- .../DropTypeStatementExecutionTest.java | 35 +- .../ExplainStatementExecutionTest.java | 13 +- .../sql/executor/GroupByExecutionTest.java | 7 +- .../executor/IfStatementExecutionTest.java | 13 +- .../InsertStatementExecutionTest.java | 277 ++-- .../sql/executor/MatchInheritanceTest.java | 17 +- .../query/sql/executor/MatchResultTest.java | 5 +- .../executor/MatchStatementExecutionTest.java | 744 +++++----- .../MoveVertexStatementExecutionTest.java | 35 +- .../ProfileStatementExecutionTest.java | 7 +- .../query/sql/executor/ResultSetTest.java | 23 +- .../sql/executor/ScriptExecutionTest.java | 83 +- .../SelectStatementExecutionTest.java | 1294 +++++++++-------- .../SelectStatementExecutionTestIT.java | 7 +- .../executor/SleepStatementExecutionTest.java | 13 +- .../TraverseStatementExecutionTest.java | 39 +- .../TruncateClassStatementExecutionTest.java | 21 +- .../UpdateStatementExecutionTest.java | 464 +++--- .../UpsertStatementExecutionTest.java | 139 +- .../sql/executor/WhileBlockExecutionTest.java | 15 +- .../coll/SQLFunctionIntersectTest.java | 7 +- .../SQLFunctionSymmetricDifferenceTest.java | 7 +- .../functions/geo/SQLGeoFunctionsTest.java | 93 +- .../graph/SQLFunctionAdjacencyTest.java | 63 +- .../functions/graph/SQLFunctionAstarTest.java | 121 +- .../graph/SQLFunctionDijkstraTest.java | 11 +- .../graph/SQLFunctionShortestPathTest.java | 53 +- .../math/SQLFunctionAbsoluteValueTest.java | 72 +- .../functions/math/SQLFunctionModeTest.java | 16 +- .../math/SQLFunctionPercentileTest.java | 23 +- .../math/SQLFunctionRandomIntTest.java | 15 +- .../math/SQLFunctionSquareRootTest.java | 58 +- .../math/SQLFunctionVarianceTest.java | 11 +- .../sql/functions/misc/FunctionTest.java | 62 +- .../misc/SQLFunctionBoolAndTest.java | 69 +- .../functions/misc/SQLFunctionBoolOrTest.java | 45 +- .../misc/SQLFunctionCoalesceTest.java | 15 +- .../misc/SQLFunctionConvertTest.java | 62 +- .../misc/SQLFunctionEncodeDecodeTest.java | 13 +- .../functions/misc/SQLFunctionUUIDTest.java | 13 +- .../functions/sql/CustomSQLFunctionsTest.java | 24 +- .../sql/functions/sql/SQLFunctionsTest.java | 224 +-- .../text/SQLFunctionStrcmpciTest.java | 38 +- .../method/collection/SQLMethodJoinTest.java | 2 +- .../method/collection/SQLMethodKeysTest.java | 4 +- .../collection/SQLMethodValuesTest.java | 4 +- .../conversion/SQLMethodAsJSONTest.java | 14 +- .../conversion/SQLMethodAsListTest.java | 16 +- .../method/conversion/SQLMethodAsMapTest.java | 14 +- .../method/conversion/SQLMethodAsSetTest.java | 16 +- .../sql/method/misc/SQLMethodExcludeTest.java | 11 +- .../sql/method/misc/SQLMethodIncludeTest.java | 11 +- .../method/misc/SQLMethodPrecisionTest.java | 17 +- .../sql/method/string/SQLMethodSplitTest.java | 5 +- .../method/string/SQLMethodSubStringTest.java | 29 +- .../query/sql/parser/AbstractParserTest.java | 10 +- .../query/sql/parser/BatchScriptTest.java | 11 +- .../sql/parser/CreateEdgeStatementTest.java | 9 +- .../sql/parser/CreateVertexStatementTest.java | 9 +- .../sql/parser/DeleteEdgeStatementTest.java | 9 +- .../query/sql/parser/DeleteStatementTest.java | 14 +- .../sql/parser/ExecutionPlanCacheTest.java | 15 +- .../query/sql/parser/IdentifierTest.java | 9 +- .../query/sql/parser/InsertStatementTest.java | 9 +- .../query/sql/parser/MatchStatementTest.java | 9 +- .../query/sql/parser/MathExpressionTest.java | 87 +- .../sql/parser/PatternTestParserTest.java | 47 +- .../query/sql/parser/ProjectionTest.java | 17 +- .../query/sql/parser/SelectStatementTest.java | 74 +- .../query/sql/parser/StatementCacheTest.java | 15 +- .../sql/parser/TraverseStatementTest.java | 9 +- .../sql/parser/UpdateEdgeStatementTest.java | 9 +- .../query/sql/parser/UpdateStatementTest.java | 9 +- .../operators/ContainsConditionTest.java | 21 +- .../operators/ContainsKeyOperatorTest.java | 17 +- .../operators/ContainsValueOperatorTest.java | 19 +- .../operators/EqualsCompareOperatorTest.java | 53 +- .../sql/parser/operators/GeOperatorTest.java | 42 +- .../sql/parser/operators/GtOperatorTest.java | 41 +- .../parser/operators/ILikeOperatorTest.java | 29 +- .../sql/parser/operators/InOperatorTest.java | 23 +- .../sql/parser/operators/LeOperatorTest.java | 42 +- .../parser/operators/LikeOperatorTest.java | 29 +- .../sql/parser/operators/LtOperatorTest.java | 58 +- .../sql/parser/operators/NeOperatorTest.java | 47 +- .../sql/parser/operators/NeqOperatorTest.java | 47 +- .../NullSafeEqualsCompareOperatorTest.java | 47 +- .../com/arcadedb/schema/DictionaryTest.java | 54 +- .../schema/DocumentValidationTest.java | 78 +- .../com/arcadedb/schema/DropBucketTest.java | 7 +- .../com/arcadedb/schema/DropTypeTest.java | 47 +- .../java/com/arcadedb/schema/SchemaTest.java | 25 +- .../serializer/JavaBinarySerializerTest.java | 41 +- .../arcadedb/serializer/SerializerTest.java | 223 +-- .../arcadedb/serializer/json/JSONTest.java | 27 +- .../performance/LocalDatabaseBenchmark.java | 17 +- .../PerformanceComplexIndexTest.java | 6 +- .../PerformanceIndexCompaction.java | 9 +- .../PerformanceInsertGraphIndexTest.java | 17 +- .../java/performance/PerformanceParsing.java | 10 +- .../performance/PerformanceSQLSelect.java | 7 +- .../PerformanceVertexIndexTest.java | 18 +- ...ctGraphQLNativeLanguageDirectivesTest.java | 45 +- .../arcadedb/graphql/GraphQLBasicTest.java | 79 +- .../parser/GraphQLParserSchemaTest.java | 10 +- .../graphql/parser/GraphQLParserTest.java | 5 +- .../gremlin/CypherQueryEngineTest.java | 54 +- .../java/com/arcadedb/gremlin/CypherTest.java | 79 +- .../com/arcadedb/gremlin/GremlinTest.java | 114 +- .../arcadedb/gremlin/SQLFromGremlinTest.java | 11 +- .../com/arcadedb/gremlin/VectorGremlinIT.java | 37 +- .../exporter/GraphMLExporterIT.java | 21 +- .../exporter/GraphSONExporterIT.java | 21 +- .../importer/GraphMLImporterIT.java | 29 +- .../importer/GraphSONImporterIT.java | 29 +- .../gremlin/AbstractGremlinServerIT.java | 16 +- .../gremlin/ConnectRemoteGremlinServerIT.java | 5 +- .../gremlin/GremlinServerSecurityTest.java | 22 +- .../server/gremlin/GremlinServerTest.java | 5 +- .../server/gremlin/LocalGremlinFactoryIT.java | 15 +- .../server/gremlin/RemoteGraphOrderIT.java | 44 +- .../gremlin/RemoteGremlinFactoryIT.java | 68 +- .../server/gremlin/RemoteGremlinIT.java | 15 +- .../com/arcadedb/integration/TestHelper.java | 5 +- .../integration/backup/FullBackupIT.java | 37 +- .../integration/exporter/JsonlExporterIT.java | 22 +- .../exporter/SQLLocalExporterTest.java | 31 +- .../integration/importer/CSVImporterIT.java | 11 +- .../integration/importer/GloVeImporterIT.java | 7 +- .../integration/importer/JSONImporterIT.java | 43 +- .../integration/importer/Neo4jImporterIT.java | 85 +- .../importer/OrientDBImporterIT.java | 33 +- .../importer/SQLLocalImporterIT.java | 7 +- .../importer/SQLRemoteImporterIT.java | 11 +- .../importer/Word2VecImporterIT.java | 5 +- .../com/arcadedb/mongo/MongoDBQueryTest.java | 6 +- .../com/arcadedb/mongo/MongoDBServerTest.java | 45 +- .../arcadedb/remote/RemoteDatabaseHttpIT.java | 13 +- pom.xml | 7 + postgresw/pom.xml | 2 + .../arcadedb/postgres/PostgresWJdbcTest.java | 82 +- ...TomcatConnectionPoolPostgresWJdbcTest.java | 7 +- .../java/com/arcadedb/redis/RedisWTest.java | 75 +- .../com/arcadedb/remote/RemoteDatabaseIT.java | 255 ++-- .../com/arcadedb/remote/RemoteSchemaIT.java | 61 +- .../com/arcadedb/server/AsyncInsertTest.java | 23 +- .../arcadedb/server/BaseGraphServerTest.java | 45 +- .../server/BatchInsertUpdateTest.java | 6 +- .../arcadedb/server/CompositeIndexTest.java | 14 +- .../com/arcadedb/server/HTTPDocumentIT.java | 142 +- .../java/com/arcadedb/server/HTTPGraphIT.java | 144 +- .../java/com/arcadedb/server/HTTPSSLIT.java | 7 +- .../arcadedb/server/HTTPTransactionIT.java | 61 +- .../com/arcadedb/server/RemoteDateIT.java | 13 +- .../com/arcadedb/server/RemoteQueriesIT.java | 29 +- .../com/arcadedb/server/SelectOrderTest.java | 30 +- .../server/ServerBackupDatabaseIT.java | 5 +- .../server/ServerConfigurationIT.java | 8 +- .../server/ServerDefaultDatabasesIT.java | 18 +- .../server/ServerImportDatabaseIT.java | 5 +- .../server/ServerReadOnlyDatabasesIT.java | 10 +- .../server/ServerRestoreDatabaseIT.java | 22 +- .../com/arcadedb/server/TestServerHelper.java | 14 +- .../arcadedb/server/ha/HAConfigurationIT.java | 8 +- .../arcadedb/server/ha/HARandomCrashIT.java | 19 +- .../arcadedb/server/ha/HASplitBrainIT.java | 5 +- .../arcadedb/server/ha/HTTP2ServersIT.java | 50 +- .../server/ha/HTTPGraphConcurrentIT.java | 16 +- .../server/ha/IndexOperations3ServersIT.java | 1 + .../server/ha/ReplicationChangeSchemaIT.java | 37 +- .../server/ha/ReplicationServerIT.java | 42 +- ...eplicationServerLeaderChanges3TimesIT.java | 19 +- .../ha/ReplicationServerLeaderDownIT.java | 17 +- ...erLeaderDownNoTransactionsToForwardIT.java | 17 +- ...tionServerQuorumMajority2ServersOutIT.java | 14 +- .../ReplicationServerReplicaHotResyncIT.java | 18 +- ...nServerReplicaRestartForceDbInstallIT.java | 10 +- .../server/ha/ServerDatabaseAlignIT.java | 62 +- .../server/ha/ServerDatabaseBackupIT.java | 15 +- .../server/ha/ServerDatabaseSqlScriptIT.java | 9 +- .../server/security/ServerProfilingIT.java | 45 +- .../server/security/ServerSecurityIT.java | 46 +- .../server/ws/WebSocketClientHelper.java | 6 +- .../server/ws/WebSocketEventBusIT.java | 167 ++- .../java/performance/BasePerformanceTest.java | 4 +- .../performance/RemoteDatabaseBenchmark.java | 9 +- .../ReplicationSpeedQuorumMajorityIT.java | 5 +- 280 files changed, 7241 insertions(+), 6736 deletions(-) diff --git a/console/src/test/java/com/arcadedb/console/CompositeIndexUpdateTest.java b/console/src/test/java/com/arcadedb/console/CompositeIndexUpdateTest.java index 2af8591f7d..906e303556 100644 --- a/console/src/test/java/com/arcadedb/console/CompositeIndexUpdateTest.java +++ b/console/src/test/java/com/arcadedb/console/CompositeIndexUpdateTest.java @@ -39,14 +39,19 @@ import com.arcadedb.server.TestServerHelper; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.*; -import java.time.*; -import java.util.*; -import java.util.concurrent.atomic.*; +import java.io.File; +import java.io.PrintStream; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Issue https://github.com/ArcadeData/arcadedb/issues/1233 @@ -153,16 +158,16 @@ public void testWhereAfterAsyncInsert() { System.out.println(); // insert TOTAL_ORDERS orders - Assertions.assertEquals(insertOrders(database, TOTAL_ORDERS).get("totalRows"), TOTAL_ORDERS); + assertThat(TOTAL_ORDERS).isEqualTo(insertOrders(database, TOTAL_ORDERS).get("totalRows")); // retrieve next eligible, it should return order id = 1 - Assertions.assertEquals(retrieveNextEligibleOrder(database), 1); + assertThat(retrieveNextEligibleOrder(database)).isEqualTo(1); // update order 1 to ERROR updateOrderAsync(database, 1, "ERROR", LocalDateTime.now(), LocalDateTime.now().plusMinutes(5), "cs2minipds-test"); // retrieve next eligible, it should return order id = 2 - Assertions.assertEquals(retrieveNextEligibleOrder(database), 2); + assertThat(retrieveNextEligibleOrder(database)).isEqualTo(2); database.async().waitCompletion(); // re-submit order @@ -171,7 +176,7 @@ public void testWhereAfterAsyncInsert() { // retrieve correct order by id try (ResultSet resultSet = database.query("sql", "select status from Order where id = 1")) { - Assertions.assertEquals(resultSet.next().getProperty("status"), "PENDING"); + assertThat(resultSet.next().getProperty("status")).isEqualTo("PENDING"); } try (ResultSet resultSet = database.query("sql", "SELECT FROM Order WHERE status = 'PENDING' ORDER BY id ASC")) { @@ -183,7 +188,7 @@ public void testWhereAfterAsyncInsert() { // retrieve next eligible, it should return order id = 1 try { - Assertions.assertEquals(1, retrieveNextEligibleOrder(database)); + assertThat(retrieveNextEligibleOrder(database)).isEqualTo(1); } finally { arcadeDBServer.stop(); } @@ -269,7 +274,7 @@ private int retrieveNextEligibleOrder(Database database) { System.out.println("retrieve result = " + result.toJSON()); return result.getProperty("id"); } else { - Assertions.fail("no orders found"); + fail("no orders found"); return 0; } } @@ -289,10 +294,10 @@ record = indexCursor.next().getRecord().asDocument(true).modify(); System.out.println("modified record = " + record); record.save(); } else { - Assertions.fail("could not find order id = " + orderId); + fail("could not find order id = " + orderId); } if (!database.async().waitCompletion(3000)) { - Assertions.fail("timeout expired before order update completion"); + fail("timeout expired before order update completion"); } return updateCount.get(); } @@ -309,7 +314,7 @@ private MutableDocument resubmitOrder(Database database, int orderId) { } }); } catch (Exception e) { - Assertions.fail(); + fail(""); } return record[0]; } diff --git a/console/src/test/java/com/arcadedb/console/ConsoleAsyncInsertTest.java b/console/src/test/java/com/arcadedb/console/ConsoleAsyncInsertTest.java index 69e1d478ae..354347fac2 100644 --- a/console/src/test/java/com/arcadedb/console/ConsoleAsyncInsertTest.java +++ b/console/src/test/java/com/arcadedb/console/ConsoleAsyncInsertTest.java @@ -42,8 +42,9 @@ import com.arcadedb.server.TestServerHelper; import com.arcadedb.server.security.ServerSecurity; import com.arcadedb.utility.FileUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,6 +54,8 @@ import java.util.concurrent.atomic.*; import static com.arcadedb.server.StaticBaseServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; /** * From Discussion https://github.com/ArcadeData/arcadedb/discussions/1129#discussioncomment-6226545 @@ -165,7 +168,7 @@ public void testBulkAsyncInsertProductsUsingSQL() { dtProducts.setBucketSelectionStrategy(new ThreadBucketSelectionStrategy()); - Assertions.assertEquals(PARALLEL_LEVEL, dtProducts.getBuckets(false).size()); + assertThat(dtProducts.getBuckets(false).size()).isEqualTo(PARALLEL_LEVEL); }); } } @@ -242,7 +245,7 @@ public void testBulkAsyncInsertProductsUsingAPI() { //dtProducts.setBucketSelectionStrategy(new ThreadBucketSelectionStrategy()); dtProducts.setBucketSelectionStrategy(new PartitionedBucketSelectionStrategy(List.of("name"))); - Assertions.assertEquals(PARALLEL_LEVEL, dtProducts.getBuckets(false).size()); + assertThat(dtProducts.getBuckets(false).size()).isEqualTo(PARALLEL_LEVEL); }); } } @@ -354,7 +357,7 @@ public void testOrderByAfterDeleteInsert() { try (ResultSet resultSet = database.command("sql", "insert into Product set name = ?, type = ?, start = ?, stop = ?, v = ? return @rid", arcadeDBServer.getConfiguration(), p.fileName, p.fileType, p.getStartValidity(), p.getStopValidity(), p.getVersion())) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); Result result = resultSet.next(); rid = result.getProperty("@rid").toString(); } @@ -367,29 +370,29 @@ public void testOrderByAfterDeleteInsert() { orders.add(new CandidateOrder("SIR1LRM-7.1", rid, start, stop, "cs2minipds-test", "PENDING")); } JSONObject insertResult = insertOrdersAsync(database, orders); - Assertions.assertEquals(insertResult.getInt("totalRows"), TOTAL); + assertThat(TOTAL).isEqualTo(insertResult.getInt("totalRows")); int firstOrderId = 1; int lastOrderId = TOTAL; try (ResultSet resultSet = database.query("sql", "select from Order order by id")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } String DELETE_ORDERS = "DELETE FROM Order WHERE id >= ? AND id <= ?"; try (ResultSet resultSet = database.command("sql", DELETE_ORDERS, firstOrderId, lastOrderId)) { - Assertions.assertEquals(TOTAL, (Long) resultSet.next().getProperty("count")); + assertThat((Long) resultSet.next().getProperty("count")).isEqualTo(TOTAL); } try (ResultSet resultSet = database.query("sql", "select from Order order by id")) { - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); } insertResult = insertOrdersAsync(database, orders); - Assertions.assertEquals(TOTAL, insertResult.getInt("totalRows")); + assertThat(insertResult.getInt("totalRows")).isEqualTo(TOTAL); try (ResultSet resultSet = database.query("sql", "select from Order")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } try (ResultSet resultSet = database.query("sql", "select from Order order by processor")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } try (ResultSet resultSet = database.query("sql", "select from Order order by id")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } finally { arcadeDBServer.stop(); FileUtils.deleteRecursively(new File(arcadeDBServer.getRootPath() + File.separator + "config")); @@ -398,25 +401,25 @@ public void testOrderByAfterDeleteInsert() { private void checkResults(AtomicLong txErrorCounter, Database database, AtomicLong okCount, AtomicLong errCount, long N, long begin) { - Assertions.assertTrue(database.async().waitCompletion(30_000)); + assertThat(database.async().waitCompletion(30_000)).isTrue(); System.out.println("Total async insertion of " + N + " elements in " + (System.currentTimeMillis() - begin)); - Assertions.assertEquals(okCount.get(), N); - Assertions.assertEquals(errCount.get(), 0); - Assertions.assertEquals(txErrorCounter.get(), 0); + assertThat(N).isEqualTo(okCount.get()); + assertThat(errCount.get()).isEqualTo(0); + assertThat(txErrorCounter.get()).isEqualTo(0); try (ResultSet resultSet = database.query("sql", "SELECT count(*) as total FROM Product")) { Result result = resultSet.next(); - Assertions.assertEquals((Long) result.getProperty("total"), N); + assertThat(N).isEqualTo((Long) result.getProperty("total")); Console console = new Console(); String URL = "remote:localhost/" + DATABASE_NAME + " " + userName + " " + password; - Assertions.assertTrue(console.parse("connect " + URL)); + assertThat(console.parse("connect " + URL)).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select count(*) from Product")); + assertThat(console.parse("select count(*) from Product")).isTrue(); String[] lines = buffer.toString().split("\\r?\\n|\\r"); int count = Integer.parseInt(lines[4].split("\\|")[2].trim()); - Assertions.assertEquals(N, count); + assertThat(count).isEqualTo(N); } catch (IOException e) { System.out.println(e.getMessage()); } diff --git a/console/src/test/java/com/arcadedb/console/ConsoleBatchTest.java b/console/src/test/java/com/arcadedb/console/ConsoleBatchTest.java index 0dee216024..d3ff0c7368 100644 --- a/console/src/test/java/com/arcadedb/console/ConsoleBatchTest.java +++ b/console/src/test/java/com/arcadedb/console/ConsoleBatchTest.java @@ -24,18 +24,19 @@ import com.arcadedb.server.TestServerHelper; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ConsoleBatchTest { @Test public void batchMode() throws IOException { Console.execute(new String[] { "-b", "create database console; create vertex type ConsoleOnlyVertex;" }); final Database db = new DatabaseFactory("./target/databases/console").open(); - Assertions.assertTrue(db.getSchema().existsType("ConsoleOnlyVertex")); + assertThat(db.getSchema().existsType("ConsoleOnlyVertex")).isTrue(); db.drop(); } @@ -43,7 +44,7 @@ public void batchMode() throws IOException { public void interactiveMode() throws IOException { Console.execute(new String[] { "create database console; create vertex type ConsoleOnlyVertex;exit" }); final Database db = new DatabaseFactory("./target/databases/console").open(); - Assertions.assertTrue(db.getSchema().existsType("ConsoleOnlyVertex")); + assertThat(db.getSchema().existsType("ConsoleOnlyVertex")).isTrue(); db.drop(); } @@ -52,7 +53,7 @@ public void swallowSettings() throws IOException { FileUtils.deleteRecursively(new File("./console")); Console.execute(new String[] { "-Darcadedb.server.databaseDirectory=.", "create database console; create vertex type ConsoleOnlyVertex;exit;" }); final Database db = new DatabaseFactory("./console").open(); - Assertions.assertTrue(db.getSchema().existsType("ConsoleOnlyVertex")); + assertThat(db.getSchema().existsType("ConsoleOnlyVertex")).isTrue(); db.drop(); GlobalConfiguration.resetAll(); } diff --git a/console/src/test/java/com/arcadedb/console/ConsoleTest.java b/console/src/test/java/com/arcadedb/console/ConsoleTest.java index a19882b3c2..5e788fe771 100644 --- a/console/src/test/java/com/arcadedb/console/ConsoleTest.java +++ b/console/src/test/java/com/arcadedb/console/ConsoleTest.java @@ -33,7 +33,7 @@ import com.arcadedb.server.TestServerHelper; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,6 +41,9 @@ import java.text.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class ConsoleTest { private static final String DB_NAME = "console"; private static Console console; @@ -53,14 +56,14 @@ public void populate() throws IOException { FileUtils.deleteRecursively(dbFile); GlobalConfiguration.SERVER_ROOT_PATH.setValue("./target"); console = new Console(); - Assertions.assertTrue(console.parse("create database " + DB_NAME + "; close")); + assertThat(console.parse("create database " + DB_NAME + "; close")).isTrue(); } @AfterEach public void drop() throws IOException { console.close(); TestServerHelper.checkActiveDatabases(); - Assertions.assertTrue(console.parse("drop database " + DB_NAME + "; close", false)); + assertThat(console.parse("drop database " + DB_NAME + "; close", false)).isTrue(); GlobalConfiguration.resetAll(); } @@ -70,57 +73,57 @@ public void testDropCreateWithLocalUrl() throws IOException { return; String localUrl = "local:/" + absoluteDBPath + "/" + DB_NAME; - Assertions.assertTrue(console.parse("drop database " + localUrl + "; close", false)); - Assertions.assertTrue(console.parse("create database " + localUrl + "; close", false)); + assertThat(console.parse("drop database " + localUrl + "; close", false)).isTrue(); + assertThat(console.parse("create database " + localUrl + "; close", false)).isTrue(); } @Test public void testNull() throws IOException { - Assertions.assertTrue(console.parse(null)); + assertThat(console.parse(null)).isTrue(); } @Test public void testEmpty() throws IOException { - Assertions.assertTrue(console.parse("")); + assertThat(console.parse("")).isTrue(); } @Test public void testEmpty2() throws IOException { - Assertions.assertTrue(console.parse(" ")); + assertThat(console.parse(" ")).isTrue(); } @Test public void testEmpty3() throws IOException { - Assertions.assertTrue(console.parse(";")); + assertThat(console.parse(";")).isTrue(); } @Test public void testComment() throws IOException { - Assertions.assertTrue(console.parse("-- This is a comment;")); + assertThat(console.parse("-- This is a comment;")).isTrue(); } @Test public void testListDatabases() throws IOException { - Assertions.assertTrue(console.parse("list databases;")); + assertThat(console.parse("list databases;")).isTrue(); } @Test public void testConnect() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME + ";info types")); + assertThat(console.parse("connect " + DB_NAME + ";info types")).isTrue(); } @Test public void testLocalConnect() throws IOException { if (System.getProperty("os.name").toLowerCase().contains("windows")) return; - Assertions.assertTrue(console.parse("connect local:/" + absoluteDBPath + "/" + DB_NAME + ";info types", false)); + assertThat(console.parse("connect local:/" + absoluteDBPath + "/" + DB_NAME + ";info types", false)).isTrue(); } @Test public void testSetVerbose() throws IOException { try { console.parse("set verbose = 2; close; connect " + DB_NAME + "XX"); - Assertions.fail(); + fail(""); } catch (final DatabaseOperationException e) { // EXPECTED } @@ -133,59 +136,59 @@ public void testSetLanguage() throws IOException { @Test public void testCreateClass() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type Person")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("info types")); - Assertions.assertTrue(buffer.toString().contains("Person")); + assertThat(console.parse("info types")).isTrue(); + assertThat(buffer.toString().contains("Person")).isTrue(); buffer.setLength(0); - Assertions.assertTrue(console.parse("info type Person")); - Assertions.assertTrue(buffer.toString().contains("DOCUMENT TYPE 'Person'")); + assertThat(console.parse("info type Person")).isTrue(); + assertThat(buffer.toString().contains("DOCUMENT TYPE 'Person'")).isTrue(); } @Test public void testInsertAndSelectRecord() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type Person")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Jay', lastname='Miner'")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Jay', lastname='Miner'")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select from Person")); - Assertions.assertTrue(buffer.toString().contains("Jay")); + assertThat(console.parse("select from Person")).isTrue(); + assertThat(buffer.toString().contains("Jay")).isTrue(); } @Test public void testInsertAndRollback() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("begin")); - Assertions.assertTrue(console.parse("create document type Person")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Jay', lastname='Miner'")); - Assertions.assertTrue(console.parse("rollback")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("begin")).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.parse("rollback")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select from Person")); - Assertions.assertFalse(buffer.toString().contains("Jay")); + assertThat(console.parse("select from Person")).isTrue(); + assertThat(buffer.toString().contains("Jay")).isFalse(); } @Test public void testHelp() throws IOException { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("?")); - Assertions.assertTrue(buffer.toString().contains("quit")); + assertThat(console.parse("?")).isTrue(); + assertThat(buffer.toString().contains("quit")).isTrue(); } @Test public void testInfoError() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); try { - Assertions.assertTrue(console.parse("info blablabla")); - Assertions.fail(); + assertThat(console.parse("info blablabla")).isTrue(); + fail(""); } catch (final ConsoleException e) { // EXPECTED } @@ -193,25 +196,24 @@ public void testInfoError() throws IOException { @Test public void testAllRecordTypes() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type D")); - Assertions.assertTrue(console.parse("create vertex type V")); - Assertions.assertTrue(console.parse("create edge type E")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type D")).isTrue(); + assertThat(console.parse("create vertex type V")).isTrue(); + assertThat(console.parse("create edge type E")).isTrue(); - Assertions.assertTrue(console.parse("insert into D set name = 'Jay', lastname='Miner'")); - Assertions.assertTrue(console.parse("insert into V set name = 'Jay', lastname='Miner'")); - Assertions.assertTrue(console.parse("insert into V set name = 'Elon', lastname='Musk'")); - Assertions.assertTrue( - console.parse("create edge E from (select from V where name ='Jay') to (select from V where name ='Elon')")); + assertThat(console.parse("insert into D set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.parse("insert into V set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.parse("insert into V set name = 'Elon', lastname='Musk'")).isTrue(); + assertThat(console.parse("create edge E from (select from V where name ='Jay') to (select from V where name ='Elon')")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select from D")); - Assertions.assertTrue(buffer.toString().contains("Jay")); + assertThat(console.parse("select from D")).isTrue(); + assertThat(buffer.toString().contains("Jay")).isTrue(); - Assertions.assertTrue(console.parse("select from V")); - Assertions.assertTrue(console.parse("select from E")); - Assertions.assertTrue(buffer.toString().contains("Elon")); + assertThat(console.parse("select from V")).isTrue(); + assertThat(console.parse("select from E")).isTrue(); + assertThat(buffer.toString().contains("Elon")).isTrue(); } /** @@ -219,34 +221,34 @@ public void testAllRecordTypes() throws IOException { */ @Test public void testNotStringProperties() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("CREATE VERTEX TYPE v")); - Assertions.assertTrue(console.parse("CREATE PROPERTY v.s STRING")); - Assertions.assertTrue(console.parse("CREATE PROPERTY v.i INTEGER")); - Assertions.assertTrue(console.parse("CREATE PROPERTY v.b BOOLEAN")); - Assertions.assertTrue(console.parse("CREATE PROPERTY v.sh SHORT")); - Assertions.assertTrue(console.parse("CREATE PROPERTY v.d DOUBLE")); - Assertions.assertTrue(console.parse("CREATE PROPERTY v.da DATETIME")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("CREATE VERTEX TYPE v")).isTrue(); + assertThat(console.parse("CREATE PROPERTY v.s STRING")).isTrue(); + assertThat(console.parse("CREATE PROPERTY v.i INTEGER")).isTrue(); + assertThat(console.parse("CREATE PROPERTY v.b BOOLEAN")).isTrue(); + assertThat(console.parse("CREATE PROPERTY v.sh SHORT")).isTrue(); + assertThat(console.parse("CREATE PROPERTY v.d DOUBLE")).isTrue(); + assertThat(console.parse("CREATE PROPERTY v.da DATETIME")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("CREATE VERTEX v SET s=\"abc\", i=1, b=true, sh=2, d=3.5, da=\"2022-12-20 18:00\"")); - Assertions.assertTrue(buffer.toString().contains("true")); + assertThat(console.parse("CREATE VERTEX v SET s=\"abc\", i=1, b=true, sh=2, d=3.5, da=\"2022-12-20 18:00\"")).isTrue(); + assertThat(buffer.toString().contains("true")).isTrue(); } @Test public void testUserMgmtLocalError() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); try { - Assertions.assertTrue(console.parse("create user elon identified by musk")); - Assertions.fail("local connection allowed user creation"); + assertThat(console.parse("create user elon identified by musk")).isTrue(); + fail("local connection allowed user creation"); } catch (final Exception e) { // EXPECTED } try { - Assertions.assertTrue(console.parse("drop user jack")); - Assertions.fail("local connection allowed user deletion"); + assertThat(console.parse("drop user jack")).isTrue(); + fail("local connection allowed user deletion"); } catch (final Exception e) { // EXPECTED } @@ -265,31 +267,31 @@ public void testImportNeo4jConsoleOK() throws IOException { try (final DatabaseFactory factory = new DatabaseFactory("./target/databases/" + DATABASE_PATH)) { try (final Database database = factory.open()) { final DocumentType personType = database.getSchema().getType("User"); - Assertions.assertNotNull(personType); - Assertions.assertEquals(3, database.countType("User", true)); + assertThat(personType).isNotNull(); + assertThat(database.countType("User", true)).isEqualTo(3); final IndexCursor cursor = database.lookupByKey("User", "id", "0"); - Assertions.assertTrue(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); final Vertex v = cursor.next().asVertex(); - Assertions.assertEquals("Adam", v.get("name")); - Assertions.assertEquals("2015-07-04T19:32:24", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(v.getLong("born"))); + assertThat(v.get("name")).isEqualTo("Adam"); + assertThat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(v.getLong("born"))).isEqualTo("2015-07-04T19:32:24"); final Map place = (Map) v.get("place"); - Assertions.assertEquals(33.46789, ((Number) place.get("latitude")).doubleValue()); - Assertions.assertNull(place.get("height")); + assertThat(((Number) place.get("latitude")).doubleValue()).isEqualTo(33.46789); + assertThat(place.get("height")).isNull(); - Assertions.assertEquals(Arrays.asList("Sam", "Anna", "Grace"), v.get("kids")); + assertThat(v.get("kids")).isEqualTo(Arrays.asList("Sam", "Anna", "Grace")); final DocumentType friendType = database.getSchema().getType("KNOWS"); - Assertions.assertNotNull(friendType); - Assertions.assertEquals(1, database.countType("KNOWS", true)); + assertThat(friendType).isNotNull(); + assertThat(database.countType("KNOWS", true)).isEqualTo(1); final Iterator relationships = v.getEdges(Vertex.DIRECTION.OUT, "KNOWS").iterator(); - Assertions.assertTrue(relationships.hasNext()); + assertThat(relationships.hasNext()).isTrue(); final Edge e = relationships.next(); - Assertions.assertEquals(1993, e.get("since")); - Assertions.assertEquals("P5M1DT12H", e.get("bffSince")); + assertThat(e.get("since")).isEqualTo(1993); + assertThat(e.get("bffSince")).isEqualTo("P5M1DT12H"); } } } @@ -333,34 +335,34 @@ public void testImportCSVConsoleOK() throws IOException { } } - Assertions.assertEquals(101, vertices); - Assertions.assertEquals(135, edges); + assertThat(vertices).isEqualTo(101); + assertThat(edges).isEqualTo(135); } @Test public void testNullValues() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type Person")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Jay', lastname='Miner', nothing = null")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Thom', lastname='Yorke', nothing = 'something'")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Jay', lastname='Miner', nothing = null")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Thom', lastname='Yorke', nothing = 'something'")).isTrue(); { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select from Person where nothing is null")); - Assertions.assertTrue(buffer.toString().contains("")); + assertThat(console.parse("select from Person where nothing is null")).isTrue(); + assertThat(buffer.toString().contains("")).isTrue(); } { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select nothing, lastname, name from Person where nothing is null")); - Assertions.assertTrue(buffer.toString().contains("")); + assertThat(console.parse("select nothing, lastname, name from Person where nothing is null")).isTrue(); + assertThat(buffer.toString().contains("")).isTrue(); } { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select nothing, lastname, name from Person")); - Assertions.assertTrue(buffer.toString().contains("")); + assertThat(console.parse("select nothing, lastname, name from Person")).isTrue(); + assertThat(buffer.toString().contains("")).isTrue(); } } @@ -369,89 +371,89 @@ public void testNullValues() throws IOException { */ @Test public void testProjectionOrder() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type Order")); - Assertions.assertTrue(console.parse( - "insert into Order set processor = 'SIR1LRM-7.1', vstart = '20220319_002624.404379', vstop = '20220319_002826.525650', status = 'PENDING'")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type Order")).isTrue(); + assertThat(console.parse( + "insert into Order set processor = 'SIR1LRM-7.1', vstart = '20220319_002624.404379', vstop = '20220319_002826.525650', status = 'PENDING'")).isTrue(); { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select processor, vstart, vstop, pstart, pstop, status, node from Order")); + assertThat(console.parse("select processor, vstart, vstop, pstart, pstop, status, node from Order")).isTrue(); int pos = buffer.toString().indexOf("processor"); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("vstart", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("vstop", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("pstart", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("pstop", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("status", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("node", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); } } @Test public void testAsyncMode() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type D")); - Assertions.assertTrue(console.parse("create vertex type V")); - Assertions.assertTrue(console.parse("create edge type E")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type D")).isTrue(); + assertThat(console.parse("create vertex type V")).isTrue(); + assertThat(console.parse("create edge type E")).isTrue(); - Assertions.assertTrue(console.parse("insert into D set name = 'Jay', lastname='Miner'")); + assertThat(console.parse("insert into D set name = 'Jay', lastname='Miner'")).isTrue(); int asyncOperations = (int) ((DatabaseAsyncExecutorImpl) ((DatabaseInternal) console.getDatabase()).async()).getStats().scheduledTasks; - Assertions.assertEquals(0, asyncOperations); + assertThat(asyncOperations).isEqualTo(0); - Assertions.assertTrue(console.parse("set asyncMode = true")); + assertThat(console.parse("set asyncMode = true")).isTrue(); - Assertions.assertTrue(console.parse("insert into V set name = 'Jay', lastname='Miner'")); - Assertions.assertTrue(console.parse("insert into V set name = 'Elon', lastname='Musk'")); + assertThat(console.parse("insert into V set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.parse("insert into V set name = 'Elon', lastname='Musk'")).isTrue(); - Assertions.assertTrue(console.parse("set asyncMode = false")); + assertThat(console.parse("set asyncMode = false")).isTrue(); asyncOperations = (int) ((DatabaseAsyncExecutorImpl) ((DatabaseInternal) console.getDatabase()).async()).getStats().scheduledTasks; - Assertions.assertEquals(2, asyncOperations); + assertThat(asyncOperations).isEqualTo(2); } @Test public void testBatchMode() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type D")); - Assertions.assertTrue(console.parse("create vertex type V")); - Assertions.assertTrue(console.parse("create edge type E")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type D")).isTrue(); + assertThat(console.parse("create vertex type V")).isTrue(); + assertThat(console.parse("create edge type E")).isTrue(); - Assertions.assertTrue(console.parse("set transactionBatchSize = 2")); + assertThat(console.parse("set transactionBatchSize = 2")).isTrue(); - Assertions.assertTrue(console.parse("insert into D set name = 'Jay', lastname='Miner'")); - Assertions.assertEquals(1, console.currentOperationsInBatch); + assertThat(console.parse("insert into D set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.currentOperationsInBatch).isEqualTo(1); - Assertions.assertTrue(((DatabaseInternal) console.getDatabase()).getTransaction().isActive()); - Assertions.assertTrue(((DatabaseInternal) console.getDatabase()).getTransaction().getModifiedPages() > 0); + assertThat(((DatabaseInternal) console.getDatabase()).getTransaction().isActive()).isTrue(); + assertThat(((DatabaseInternal) console.getDatabase()).getTransaction().getModifiedPages() > 0).isTrue(); - Assertions.assertTrue(console.parse("insert into V set name = 'Jay', lastname='Miner'")); - Assertions.assertEquals(2, console.currentOperationsInBatch); - Assertions.assertTrue(console.parse("insert into V set name = 'Elon', lastname='Musk'")); - Assertions.assertEquals(1, console.currentOperationsInBatch); + assertThat(console.parse("insert into V set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.currentOperationsInBatch).isEqualTo(2); + assertThat(console.parse("insert into V set name = 'Elon', lastname='Musk'")).isTrue(); + assertThat(console.currentOperationsInBatch).isEqualTo(1); - Assertions.assertTrue(console.parse("set transactionBatchSize = 0")); + assertThat(console.parse("set transactionBatchSize = 0")).isTrue(); } @Test public void testLoad() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("load " + new File("src/test/resources/console-batch.sql").toString().replace('\\', '/'))); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("load " + new File("src/test/resources/console-batch.sql").toString().replace('\\', '/'))).isTrue(); final String[] urls = new String[] { "http://arcadedb.com", "https://www.arcadedb.com", "file://this/is/myfile.txt" }; // VALIDATE WITH PLAIN JAVA REGEXP FIRST for (String url : urls) - Assertions.assertTrue(url.matches("^([a-zA-Z]{1,15}:)(\\/\\/)?[^\\s\\/$.?#].[^\\s]*$"), "Cannot validate URL: " + url); + assertThat(url.matches("^([a-zA-Z]{1,15}:)(\\/\\/)?[^\\s\\/$.?#].[^\\s]*$")).as("Cannot validate URL: " + url).isTrue(); // VALIDATE WITH DATABASE SCHEMA for (String url : urls) @@ -460,19 +462,17 @@ public void testLoad() throws IOException { @Test public void testCustomPropertyInSchema() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("CREATE DOCUMENT TYPE doc;")); - Assertions.assertTrue(console.parse("CREATE PROPERTY doc.prop STRING;")); - Assertions.assertTrue(console.parse("ALTER PROPERTY doc.prop CUSTOM test = true;")); - Assertions.assertEquals(true, console.getDatabase().getSchema().getType("doc").getProperty("prop").getCustomValue("test")); - - Assertions.assertEquals(Type.BOOLEAN.name().toUpperCase(), - console.getDatabase().query("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() - .getProperty("type")); - - Assertions.assertEquals(Type.BOOLEAN.name().toUpperCase(), - console.getDatabase().command("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() - .getProperty("type")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("CREATE DOCUMENT TYPE doc;")).isTrue(); + assertThat(console.parse("CREATE PROPERTY doc.prop STRING;")).isTrue(); + assertThat(console.parse("ALTER PROPERTY doc.prop CUSTOM test = true;")).isTrue(); + assertThat(console.getDatabase().getSchema().getType("doc").getProperty("prop").getCustomValue("test")).isEqualTo(true); + + assertThat(console.getDatabase().query("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() + .getProperty("type")).isEqualTo(Type.BOOLEAN.name().toUpperCase()); + + assertThat(console.getDatabase().command("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() + .getProperty("type")).isEqualTo(Type.BOOLEAN.name().toUpperCase()); } /** @@ -480,21 +480,21 @@ public void testCustomPropertyInSchema() throws IOException { */ @Test public void testNotNullProperties() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("CREATE DOCUMENT TYPE doc;")); - Assertions.assertTrue(console.parse("CREATE PROPERTY doc.prop STRING (notnull);")); - Assertions.assertTrue(console.getDatabase().getSchema().getType("doc").getProperty("prop").isNotNull()); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("CREATE DOCUMENT TYPE doc;")).isTrue(); + assertThat(console.parse("CREATE PROPERTY doc.prop STRING (notnull);")).isTrue(); + assertThat(console.getDatabase().getSchema().getType("doc").getProperty("prop").isNotNull()).isTrue(); - Assertions.assertTrue(console.parse("INSERT INTO doc set a = null;")); + assertThat(console.parse("INSERT INTO doc set a = null;")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("INSERT INTO doc set prop = null;")); + assertThat(console.parse("INSERT INTO doc set prop = null;")).isTrue(); int pos = buffer.toString().indexOf("ValidationException"); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); - Assertions.assertNull(console.getDatabase().query("sql", "SELECT FROM doc").nextIfAvailable().getProperty("prop")); + assertThat(console.getDatabase().query("sql", "SELECT FROM doc").nextIfAvailable().getProperty("prop")).isNull(); } /** @@ -502,23 +502,23 @@ public void testNotNullProperties() throws IOException { */ @Test public void testPercentWildcardInQuery() throws IOException { - Assertions.assertTrue(console.parse("connect " + DB_NAME)); - Assertions.assertTrue(console.parse("create document type Person")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Jay', lastname='Miner', nothing = null")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Thom', lastname='Yorke', nothing = 'something'")); + assertThat(console.parse("connect " + DB_NAME)).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Jay', lastname='Miner', nothing = null")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Thom', lastname='Yorke', nothing = 'something'")).isTrue(); { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select from Person where name like 'Thom%'")); - Assertions.assertTrue(buffer.toString().contains("Yorke")); + assertThat(console.parse("select from Person where name like 'Thom%'")).isTrue(); + assertThat(buffer.toString().contains("Yorke")).isTrue(); } { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select from Person where not ( name like 'Thom%' )")); - Assertions.assertTrue(buffer.toString().contains("Miner")); + assertThat(console.parse("select from Person where not ( name like 'Thom%' )")).isTrue(); + assertThat(buffer.toString().contains("Miner")).isTrue(); } } } diff --git a/console/src/test/java/com/arcadedb/console/RemoteConsoleIT.java b/console/src/test/java/com/arcadedb/console/RemoteConsoleIT.java index 7575d409bc..9c5bed3107 100644 --- a/console/src/test/java/com/arcadedb/console/RemoteConsoleIT.java +++ b/console/src/test/java/com/arcadedb/console/RemoteConsoleIT.java @@ -25,11 +25,13 @@ import com.arcadedb.server.BaseGraphServerTest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class RemoteConsoleIT extends BaseGraphServerTest { private static final String URL = "remote:localhost:2480/console root " + DEFAULT_PASSWORD_FOR_TESTS; @@ -47,24 +49,24 @@ public void setTestConfiguration() { @Test public void testCreateDatabase() throws IOException { - Assertions.assertTrue(console.parse("create database " + URL_NEW_DB)); + assertThat(console.parse("create database " + URL_NEW_DB)).isTrue(); } @Test public void testConnect() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); + assertThat(console.parse("connect " + URL)).isTrue(); } @Test public void testConnectShortURL() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL_SHORT)); + assertThat(console.parse("connect " + URL_SHORT)).isTrue(); } @Test public void testConnectNoCredentials() throws IOException { try { - Assertions.assertTrue(console.parse("connect " + URL_NOCREDENTIALS + ";create document type VVVV")); - Assertions.fail("Security was bypassed!"); + assertThat(console.parse("connect " + URL_NOCREDENTIALS + ";create document type VVVV")).isTrue(); + fail("Security was bypassed!"); } catch (final ConsoleException e) { // EXPECTED } @@ -73,8 +75,8 @@ public void testConnectNoCredentials() throws IOException { @Test public void testConnectWrongPassword() throws IOException { try { - Assertions.assertTrue(console.parse("connect " + URL_WRONGPASSWD + ";create document type VVVV")); - Assertions.fail("Security was bypassed!"); + assertThat(console.parse("connect " + URL_WRONGPASSWD + ";create document type VVVV")).isTrue(); + fail("Security was bypassed!"); } catch (final SecurityException e) { // EXPECTED } @@ -82,95 +84,95 @@ public void testConnectWrongPassword() throws IOException { @Test public void testCreateType() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("create document type Person2")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("create document type Person2")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(buffer::append); - Assertions.assertTrue(console.parse("info types")); - Assertions.assertTrue(buffer.toString().contains("Person2")); - Assertions.assertTrue(console.parse("drop type Person2")); + assertThat(console.parse("info types")).isTrue(); + assertThat(buffer.toString().contains("Person2")).isTrue(); + assertThat(console.parse("drop type Person2")).isTrue(); } @Test public void testInsertAndSelectRecord() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("create document type Person2")); - Assertions.assertTrue(console.parse("insert into Person2 set name = 'Jay', lastname='Miner'")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("create document type Person2")).isTrue(); + assertThat(console.parse("insert into Person2 set name = 'Jay', lastname='Miner'")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(buffer::append); - Assertions.assertTrue(console.parse("select from Person2")); - Assertions.assertTrue(buffer.toString().contains("Jay")); - Assertions.assertTrue(console.parse("drop type Person2")); + assertThat(console.parse("select from Person2")).isTrue(); + assertThat(buffer.toString().contains("Jay")).isTrue(); + assertThat(console.parse("drop type Person2")).isTrue(); } @Test public void testListDatabases() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("list databases;")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("list databases;")).isTrue(); } @Test public void testInsertAndRollback() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("begin")); - Assertions.assertTrue(console.parse("create document type Person")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Jay', lastname='Miner'")); - Assertions.assertTrue(console.parse("rollback")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("begin")).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.parse("rollback")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(buffer::append); - Assertions.assertTrue(console.parse("select from Person")); - Assertions.assertFalse(buffer.toString().contains("Jay")); + assertThat(console.parse("select from Person")).isTrue(); + assertThat(buffer.toString().contains("Jay")).isFalse(); } @Test public void testInsertAndCommit() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("begin")); - Assertions.assertTrue(console.parse("create document type Person")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Jay', lastname='Miner'")); - Assertions.assertTrue(console.parse("commit")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("begin")).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Jay', lastname='Miner'")).isTrue(); + assertThat(console.parse("commit")).isTrue(); final StringBuilder buffer = new StringBuilder(); console.setOutput(buffer::append); - Assertions.assertTrue(console.parse("select from Person")); - Assertions.assertTrue(buffer.toString().contains("Jay")); + assertThat(console.parse("select from Person")).isTrue(); + assertThat(buffer.toString().contains("Jay")).isTrue(); } @Test public void testTransactionExpired() throws IOException, InterruptedException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("begin")); - Assertions.assertTrue(console.parse("create document type Person")); - Assertions.assertTrue(console.parse("insert into Person set name = 'Jay', lastname='Miner'")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("begin")).isTrue(); + assertThat(console.parse("create document type Person")).isTrue(); + assertThat(console.parse("insert into Person set name = 'Jay', lastname='Miner'")).isTrue(); Thread.sleep(5000); try { - Assertions.assertTrue(console.parse("commit")); - Assertions.fail(); + assertThat(console.parse("commit")).isTrue(); + fail(""); } catch (final Exception e) { // EXPECTED } final StringBuilder buffer = new StringBuilder(); console.setOutput(buffer::append); - Assertions.assertTrue(console.parse("select from Person")); - Assertions.assertFalse(buffer.toString().contains("Jay")); + assertThat(console.parse("select from Person")).isTrue(); + assertThat(buffer.toString().contains("Jay")).isFalse(); } @Test public void testUserMgmt() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); + assertThat(console.parse("connect " + URL)).isTrue(); try { - Assertions.assertTrue(console.parse("drop user elon")); + assertThat(console.parse("drop user elon")).isTrue(); } catch (final Exception e) { // EXPECTED IF ALREADY EXISTENT } try { - Assertions.assertTrue(console.parse("create user jay identified by m")); - Assertions.fail(); + assertThat(console.parse("create user jay identified by m")).isTrue(); + fail(""); } catch (final RuntimeException e) { // PASSWORD MUST BE AT LEAST 5 CHARS } @@ -180,34 +182,34 @@ public void testUserMgmt() throws IOException { for (int i = 0; i < 257; i++) longPassword += "P"; - Assertions.assertTrue(console.parse("create user jay identified by " + longPassword)); - Assertions.fail(); + assertThat(console.parse("create user jay identified by " + longPassword)).isTrue(); + fail(""); } catch (final RuntimeException e) { // PASSWORD MUST BE MAX 256 CHARS LONG } - Assertions.assertTrue(console.parse("create user elon identified by musk")); - Assertions.assertTrue(console.parse("drop user elon")); + assertThat(console.parse("create user elon identified by musk")).isTrue(); + assertThat(console.parse("drop user elon")).isTrue(); // TEST SYNTAX ERROR try { - Assertions.assertTrue(console.parse("create user elon identified by musk grand connect on db1")); - Assertions.fail(); + assertThat(console.parse("create user elon identified by musk grand connect on db1")).isTrue(); + fail(""); } catch (final Exception e) { // EXPECTED } - Assertions.assertTrue(console.parse("create user elon identified by musk grant connect to db1")); - Assertions.assertTrue(console.parse("create user jeff identified by amazon grant connect to db1:readonly")); - Assertions.assertTrue(console.parse("drop user elon")); + assertThat(console.parse("create user elon identified by musk grant connect to db1")).isTrue(); + assertThat(console.parse("create user jeff identified by amazon grant connect to db1:readonly")).isTrue(); + assertThat(console.parse("drop user elon")).isTrue(); } @Test public void testHelp() throws IOException { final StringBuilder buffer = new StringBuilder(); console.setOutput(buffer::append); - Assertions.assertTrue(console.parse("?")); - Assertions.assertTrue(buffer.toString().contains("quit")); + assertThat(console.parse("?")).isTrue(); + assertThat(buffer.toString().contains("quit")).isTrue(); } /** @@ -215,84 +217,82 @@ public void testHelp() throws IOException { */ @Test public void testProjectionOrder() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("create document type Order")); - Assertions.assertTrue(console.parse( - "insert into Order set processor = 'SIR1LRM-7.1', vstart = '20220319_002624.404379', vstop = '20220319_002826.525650', status = 'PENDING'")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("create document type Order")).isTrue(); + assertThat(console.parse( + "insert into Order set processor = 'SIR1LRM-7.1', vstart = '20220319_002624.404379', vstop = '20220319_002826.525650', status = 'PENDING'")).isTrue(); { final StringBuilder buffer = new StringBuilder(); console.setOutput(output -> buffer.append(output)); - Assertions.assertTrue(console.parse("select processor, vstart, vstop, pstart, pstop, status, node from Order")); + assertThat(console.parse("select processor, vstart, vstop, pstart, pstop, status, node from Order")).isTrue(); int pos = buffer.toString().indexOf("processor"); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("vstart", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("vstop", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("pstart", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("pstop", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("status", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); pos = buffer.toString().indexOf("node", pos); - Assertions.assertTrue(pos > -1); + assertThat(pos > -1).isTrue(); } } @Test public void testCustomPropertyInSchema() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("CREATE DOCUMENT TYPE doc;")); - Assertions.assertTrue(console.parse("ALTER TYPE doc CUSTOM testType = 444;")); - Assertions.assertTrue(console.parse("CREATE PROPERTY doc.prop STRING;")); - Assertions.assertTrue(console.parse("ALTER PROPERTY doc.prop CUSTOM test = true;")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("CREATE DOCUMENT TYPE doc;")).isTrue(); + assertThat(console.parse("ALTER TYPE doc CUSTOM testType = 444;")).isTrue(); + assertThat(console.parse("CREATE PROPERTY doc.prop STRING;")).isTrue(); + assertThat(console.parse("ALTER PROPERTY doc.prop CUSTOM test = true;")).isTrue(); - Assertions.assertEquals(444, console.getDatabase().getSchema().getType("doc").getCustomValue("testType")); - Assertions.assertEquals(true, console.getDatabase().getSchema().getType("doc").getProperty("prop").getCustomValue("test")); + assertThat(console.getDatabase().getSchema().getType("doc").getCustomValue("testType")).isEqualTo(444); + assertThat(console.getDatabase().getSchema().getType("doc").getProperty("prop").getCustomValue("test")).isEqualTo(true); console.getDatabase().getSchema().getType("doc").setCustomValue("testType", "555"); - Assertions.assertEquals("555", console.getDatabase().getSchema().getType("doc").getCustomValue("testType")); + assertThat(console.getDatabase().getSchema().getType("doc").getCustomValue("testType")).isEqualTo("555"); - Assertions.assertEquals(Type.BOOLEAN.name().toUpperCase(), - console.getDatabase().query("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() - .getProperty("type")); + assertThat(console.getDatabase().query("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() + .getProperty("type")).isEqualTo(Type.BOOLEAN.name().toUpperCase()); - Assertions.assertEquals(Type.BOOLEAN.name().toUpperCase(), - console.getDatabase().command("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() - .getProperty("type")); + assertThat(console.getDatabase().command("sql", "SELECT properties.custom.test[0].type() as type FROM schema:types").next() + .getProperty("type")).isEqualTo(Type.BOOLEAN.name().toUpperCase()); } @Test public void testIfWithSchemaResult() throws IOException { - Assertions.assertTrue(console.parse("connect " + URL)); - Assertions.assertTrue(console.parse("CREATE DOCUMENT TYPE doc;")); - Assertions.assertTrue(console.parse("CREATE PROPERTY doc.prop STRING;")); + assertThat(console.parse("connect " + URL)).isTrue(); + assertThat(console.parse("CREATE DOCUMENT TYPE doc;")).isTrue(); + assertThat(console.parse("CREATE PROPERTY doc.prop STRING;")).isTrue(); - Assertions.assertTrue(console.parse("INSERT INTO doc set name = 'doc'")); + assertThat(console.parse("INSERT INTO doc set name = 'doc'")).isTrue(); ResultSet resultSet = console.getDatabase().command("sql", "SELECT name, (name = 'doc') as name2, if( (name = 'doc'), true, false) as name3, if( (name IN ['doc','XXX']), true, false) as name4, ifnull( (name = 'doc'), null) as name5 FROM schema:types"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); Result result = resultSet.next(); - Assertions.assertEquals("doc", result.getProperty("name")); - Assertions.assertTrue((boolean) result.getProperty("name2")); - Assertions.assertTrue((boolean) result.getProperty("name3")); - Assertions.assertTrue((boolean) result.getProperty("name4")); - Assertions.assertTrue((boolean) result.getProperty("name5")); + assertThat(result.getProperty("name")).isEqualTo("doc"); + assertThat( result.getProperty("name2")).isTrue(); + assertThat( result.getProperty("name3")).isTrue(); + assertThat( result.getProperty("name4")).isTrue(); + assertThat( result.getProperty("name5")).isTrue(); resultSet = console.getDatabase().command("sql", "SELECT name FROM schema:types WHERE 'a_b' = 'a b'.replace(' ','_')"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertEquals("doc", result.getProperty("name")); + assertThat(result.getProperty("name")).isEqualTo("doc"); } @Override @@ -315,7 +315,7 @@ public void beginTest() { console = new Console(); console.parse("close"); } catch (final IOException e) { - Assertions.fail(e); + fail("", e); } } diff --git a/engine/src/test/java/com/arcadedb/ACIDTransactionTest.java b/engine/src/test/java/com/arcadedb/ACIDTransactionTest.java index 7f0d22e0b0..eb45bdc402 100644 --- a/engine/src/test/java/com/arcadedb/ACIDTransactionTest.java +++ b/engine/src/test/java/com/arcadedb/ACIDTransactionTest.java @@ -25,15 +25,17 @@ import com.arcadedb.database.bucketselectionstrategy.ThreadBucketSelectionStrategy; import com.arcadedb.engine.WALException; import com.arcadedb.engine.WALFile; +import com.arcadedb.exception.NeedRetryException; import com.arcadedb.exception.TransactionException; import com.arcadedb.graph.MutableVertex; import com.arcadedb.log.LogManager; +import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; @@ -42,6 +44,10 @@ import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; + public class ACIDTransactionTest extends TestHelper { @Test public void testAsyncTX() { @@ -75,7 +81,7 @@ public void testAsyncTX() { } } catch (final TransactionException e) { - Assertions.assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause() instanceof IOException).isTrue(); } ((DatabaseInternal) db).kill(); @@ -84,7 +90,7 @@ public void testAsyncTX() { verifyDatabaseWasNotClosedProperly(); - database.transaction(() -> Assertions.assertEquals(TOT, database.countType("V", true))); + database.transaction(() -> assertThat(database.countType("V", true)).isEqualTo(TOT)); } @Test @@ -106,17 +112,17 @@ public void testIndexCreationWhileAsyncMustFail() { db.async().createRecord(v, null); } + // creating the index should throw exception because there's an aync creation ongoing: sometimes it doesn't happen, the async is finished try { database.getSchema().getType("V").createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, "id"); - Assertions.fail(); - } catch (Exception e) { - // EXPECTED + } catch (NeedRetryException e) { + //no action } db.async().waitCompletion(); } catch (final TransactionException e) { - Assertions.assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause() instanceof IOException).isTrue(); } ((DatabaseInternal) db).kill(); @@ -125,13 +131,13 @@ public void testIndexCreationWhileAsyncMustFail() { verifyDatabaseWasNotClosedProperly(); - database.transaction(() -> Assertions.assertEquals(TOT, database.countType("V", true))); + database.transaction(() -> assertThat(database.countType("V", true)).isEqualTo(TOT)); } @Test public void testDatabaseInternals() { - Assertions.assertNotNull(((DatabaseInternal) database).getStats()); - Assertions.assertNull(database.getCurrentUserName()); + assertThat(((DatabaseInternal) database).getStats()).isNotNull(); + assertThat(database.getCurrentUserName()).isNull(); } @Test @@ -151,7 +157,7 @@ public void testCrashDuringTx() { verifyDatabaseWasNotClosedProperly(); - database.transaction(() -> Assertions.assertEquals(0, database.countType("V", true))); + database.transaction(() -> assertThat(database.countType("V", true)).isEqualTo(0)); } @Test @@ -174,10 +180,10 @@ public void testIOExceptionAfterWALIsWritten() { db.commit(); - Assertions.fail("Expected commit to fail"); + fail("Expected commit to fail"); } catch (final TransactionException e) { - Assertions.assertTrue(e.getCause() instanceof WALException); + assertThat(e.getCause() instanceof WALException).isTrue(); } ((DatabaseInternal) db).kill(); @@ -185,7 +191,7 @@ public void testIOExceptionAfterWALIsWritten() { verifyDatabaseWasNotClosedProperly(); - database.transaction(() -> Assertions.assertEquals(1, database.countType("V", true))); + database.transaction(() -> assertThat(database.countType("V", true)).isEqualTo(1)); ((DatabaseInternal) db).unregisterCallback(DatabaseInternal.CALLBACK_EVENT.TX_AFTER_WAL_WRITE, callback); } @@ -236,10 +242,10 @@ public Void call() throws IOException { // IGNORE IT } - Assertions.assertEquals(1, errors.get()); + assertThat(errors.get()).isEqualTo(1); } catch (final TransactionException e) { - Assertions.assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause() instanceof IOException).isTrue(); } ((DatabaseInternal) db).kill(); @@ -247,7 +253,7 @@ public Void call() throws IOException { verifyDatabaseWasNotClosedProperly(); - database.transaction(() -> Assertions.assertEquals(TOT, database.countType("V", true))); + database.transaction(() -> assertThat(database.countType("V", true)).isEqualTo(TOT)); } @Test @@ -260,16 +266,16 @@ public void testAsyncIOExceptionAfterWALIsWrittenManyRecords() { final AtomicInteger errors = new AtomicInteger(0); db.async().setTransactionSync(WALFile.FLUSH_TYPE.YES_NOMETADATA); - Assertions.assertEquals(WALFile.FLUSH_TYPE.YES_NOMETADATA, db.async().getTransactionSync()); + assertThat(db.async().getTransactionSync()).isEqualTo(WALFile.FLUSH_TYPE.YES_NOMETADATA); db.async().setTransactionUseWAL(true); - Assertions.assertTrue(db.async().isTransactionUseWAL()); + assertThat(db.async().isTransactionUseWAL()).isTrue(); db.async().setCommitEvery(1000000); - Assertions.assertEquals(1000000, db.async().getCommitEvery()); + assertThat(db.async().getCommitEvery()).isEqualTo(1000000); db.async().setBackPressure(1); - Assertions.assertEquals(1, db.async().getBackPressure()); + assertThat(db.async().getBackPressure()).isEqualTo(1); db.async().onError(exception -> errors.incrementAndGet()); @@ -291,10 +297,10 @@ public void testAsyncIOExceptionAfterWALIsWrittenManyRecords() { db.async().waitCompletion(); - Assertions.assertTrue(errors.get() > 0); + assertThat(errors.get() > 0).isTrue(); } catch (final TransactionException e) { - Assertions.assertTrue(e.getCause() instanceof IOException); + assertThat(e.getCause() instanceof IOException).isTrue(); } ((DatabaseInternal) db).kill(); @@ -302,7 +308,7 @@ public void testAsyncIOExceptionAfterWALIsWrittenManyRecords() { verifyDatabaseWasNotClosedProperly(); - database.transaction(() -> Assertions.assertEquals(TOT, database.countType("V", true))); + database.transaction(() -> assertThat(database.countType("V", true)).isEqualTo(TOT)); } @Test @@ -365,20 +371,21 @@ public void multiThreadConcurrentTransactions() { database.async().waitCompletion(); - Assertions.assertEquals(0, errors.get()); + assertThat(errors.get()).isEqualTo(0); database.transaction(() -> { - Assertions.assertEquals(TOT_STOCKS * TOT_DAYS, database.countType("Stock", true)); - Assertions.assertEquals(0, database.countType("Aggregate", true)); + assertThat(database.countType("Stock", true)).isEqualTo(TOT_STOCKS * TOT_DAYS); + assertThat(database.countType("Aggregate", true)).isEqualTo(0); final Calendar now = Calendar.getInstance(); now.setTimeInMillis(startingDay.getTimeInMillis()); for (int i = 0; i < TOT_DAYS; ++i) { for (int stockId = 0; stockId < TOT_STOCKS; ++stockId) { - final ResultSet result = database.query("sql", "select from Stock where symbol = ? and date = ?", "" + stockId, now.getTimeInMillis()); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext(), "Cannot find stock=" + stockId + " date=" + now.getTimeInMillis()); + final ResultSet result = database.query("sql", "select from Stock where symbol = ? and date = ?", "" + stockId, + now.getTimeInMillis()); + assertThat((Iterator) result).isNotNull(); + assertThat(result.hasNext()).withFailMessage("Cannot find stock=" + stockId + " date=" + now.getTimeInMillis()).isTrue(); } now.add(Calendar.DAY_OF_YEAR, +1); } @@ -395,16 +402,16 @@ public void testAsyncEdges() { final AtomicInteger errors = new AtomicInteger(0); db.async().setTransactionSync(WALFile.FLUSH_TYPE.YES_NOMETADATA); - Assertions.assertEquals(WALFile.FLUSH_TYPE.YES_NOMETADATA, db.async().getTransactionSync()); + assertThat(db.async().getTransactionSync()).isEqualTo(WALFile.FLUSH_TYPE.YES_NOMETADATA); db.async().setTransactionUseWAL(true); - Assertions.assertTrue(db.async().isTransactionUseWAL()); + assertThat(db.async().isTransactionUseWAL()).isTrue(); db.async().setCommitEvery(TOT); - Assertions.assertEquals(TOT, db.async().getCommitEvery()); + assertThat(db.async().getCommitEvery()).isEqualTo(TOT); db.async().setBackPressure(1); - Assertions.assertEquals(1, db.async().getBackPressure()); + assertThat(db.async().getBackPressure()).isEqualTo(1); db.async().onError(exception -> errors.incrementAndGet()); @@ -423,14 +430,14 @@ public void testAsyncEdges() { } db.async().waitCompletion(); - Assertions.assertEquals(0, errors.get()); + assertThat(errors.get()).isEqualTo(0); for (int i = 1; i < TOT; ++i) { db.async().newEdgeByKeys("Node", "id", i, "Node", "id", i - 1, false, "Arc", true, false, null, "id", i); } db.async().waitCompletion(); - Assertions.assertEquals(0, errors.get()); + assertThat(errors.get()).isEqualTo(0); ((DatabaseInternal) db).kill(); @@ -438,8 +445,8 @@ public void testAsyncEdges() { verifyDatabaseWasNotClosedProperly(); - database.transaction(() -> Assertions.assertEquals(TOT, database.countType("Node", true))); - database.transaction(() -> Assertions.assertEquals(TOT - 1, database.countType("Arc", true))); + database.transaction(() -> assertThat(database.countType("Node", true)).isEqualTo(TOT)); + database.transaction(() -> assertThat(database.countType("Arc", true)).isEqualTo(TOT - 1)); } private void verifyDatabaseWasNotClosedProperly() { @@ -452,15 +459,15 @@ private void verifyDatabaseWasNotClosedProperly() { }); database = factory.open(); - Assertions.assertTrue(dbNotClosedCaught.get()); + assertThat(dbNotClosedCaught.get()).isTrue(); } private void verifyWALFilesAreStillPresent() { final File dbDir = new File(getDatabasePath()); - Assertions.assertTrue(dbDir.exists()); - Assertions.assertTrue(dbDir.isDirectory()); + assertThat(dbDir.exists()).isTrue(); + assertThat(dbDir.isDirectory()).isTrue(); final File[] files = dbDir.listFiles((dir, name) -> name.endsWith("wal")); - Assertions.assertTrue(files.length > 0); + assertThat(files.length > 0).isTrue(); } @Override diff --git a/engine/src/test/java/com/arcadedb/AsyncTest.java b/engine/src/test/java/com/arcadedb/AsyncTest.java index 0267255ef7..23a3f51d8a 100644 --- a/engine/src/test/java/com/arcadedb/AsyncTest.java +++ b/engine/src/test/java/com/arcadedb/AsyncTest.java @@ -25,13 +25,16 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class AsyncTest extends TestHelper { private static final int TOT = 10000; private static final String TYPE_NAME = "V"; @@ -47,7 +50,7 @@ public void testScan() { return true; }); - Assertions.assertEquals(TOT, callbackInvoked.get()); + assertThat(callbackInvoked.get()).isEqualTo(TOT); database.async().waitCompletion(); database.async().waitCompletion(); @@ -78,13 +81,13 @@ public void testSyncScanAndAsyncUpdate() { database.commit(); } - Assertions.assertEquals(TOT, callbackInvoked.get()); - Assertions.assertEquals(TOT, updatedRecords.get()); + assertThat(callbackInvoked.get()).isEqualTo(TOT); + assertThat(updatedRecords.get()).isEqualTo(TOT); final ResultSet resultSet = database.query("sql", "select count(*) as count from " + TYPE_NAME + " where updated = true"); - Assertions.assertTrue(resultSet.hasNext()); - Assertions.assertEquals(TOT, ((Number) resultSet.next().getProperty("count")).intValue()); + assertThat(resultSet.hasNext()).isTrue(); + assertThat(((Number) resultSet.next().getProperty("count")).intValue()).isEqualTo(TOT); } @Test @@ -102,13 +105,13 @@ public void testAsyncDelete() { database.async().waitCompletion(); - Assertions.assertEquals(TOT, callbackInvoked.get()); - Assertions.assertEquals(TOT, deletedRecords.get()); + assertThat(callbackInvoked.get()).isEqualTo(TOT); + assertThat(deletedRecords.get()).isEqualTo(TOT); final ResultSet resultSet = database.query("sql", "select count(*) as count from " + TYPE_NAME + " where updated = true"); - Assertions.assertTrue(resultSet.hasNext()); - Assertions.assertEquals(0, ((Number) resultSet.next().getProperty("count")).intValue()); + assertThat(resultSet.hasNext()).isTrue(); + assertThat(((Number) resultSet.next().getProperty("count")).intValue()).isEqualTo(0); populateDatabase(); @@ -130,7 +133,7 @@ public void testScanInterrupt() { return callbackInvoked.getAndIncrement() < 10; }); - Assertions.assertTrue(callbackInvoked.get() < 20); + assertThat(callbackInvoked.get() < 20).isTrue(); } finally { database.commit(); @@ -158,8 +161,8 @@ public void onError(final Exception exception) { database.async().waitCompletion(5_000); - Assertions.assertEquals(1, completeCallbackInvoked.get()); - Assertions.assertEquals(0, errorCallbackInvoked.get()); + assertThat(completeCallbackInvoked.get()).isEqualTo(1); + assertThat(errorCallbackInvoked.get()).isEqualTo(0); } finally { database.commit(); @@ -189,9 +192,9 @@ public void testParallelQueries() throws InterruptedException { // WAIT INDEFINITELY counter.await(); - Assertions.assertTrue(resultSets[0].hasNext()); - Assertions.assertTrue(resultSets[1].hasNext()); - Assertions.assertTrue(resultSets[2].hasNext()); + assertThat(resultSets[0].hasNext()).isTrue(); + assertThat(resultSets[1].hasNext()).isTrue(); + assertThat(resultSets[2].hasNext()).isTrue(); } finally { database.commit(); @@ -219,8 +222,8 @@ public void onError(final Exception exception) { database.async().waitCompletion(5_000); - Assertions.assertEquals(1, completeCallbackInvoked.get()); - Assertions.assertEquals(0, errorCallbackInvoked.get()); + assertThat(completeCallbackInvoked.get()).isEqualTo(1); + assertThat(errorCallbackInvoked.get()).isEqualTo(0); } finally { database.commit(); @@ -237,9 +240,9 @@ public void testCommandFetchVarargParamsNoCallback() { final IndexCursor resultSet = database.lookupByKey(TYPE_NAME, "id", Integer.MAX_VALUE); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Document record = resultSet.next().asDocument(); - Assertions.assertEquals(Integer.MAX_VALUE, record.get("id")); + assertThat(record.get("id")).isEqualTo(Integer.MAX_VALUE); } finally { database.commit(); @@ -268,8 +271,8 @@ public void onError(final Exception exception) { database.async().waitCompletion(5_000); - Assertions.assertEquals(1, completeCallbackInvoked.get()); - Assertions.assertEquals(0, errorCallbackInvoked.get()); + assertThat(completeCallbackInvoked.get()).isEqualTo(1); + assertThat(errorCallbackInvoked.get()).isEqualTo(0); } finally { database.commit(); @@ -297,8 +300,8 @@ public void onError(final Exception exception) { database.async().waitCompletion(5_000); - Assertions.assertEquals(1, completeCallbackInvoked.get()); - Assertions.assertEquals(0, errorCallbackInvoked.get()); + assertThat(completeCallbackInvoked.get()).isEqualTo(1); + assertThat(errorCallbackInvoked.get()).isEqualTo(0); } finally { database.commit(); @@ -326,8 +329,8 @@ public void onError(final Exception exception) { database.async().waitCompletion(5_000); - Assertions.assertEquals(0, completeCallbackInvoked.get()); - Assertions.assertEquals(1, errorCallbackInvoked.get()); + assertThat(completeCallbackInvoked.get()).isEqualTo(0); + assertThat(errorCallbackInvoked.get()).isEqualTo(1); } finally { database.commit(); @@ -338,7 +341,7 @@ public void onError(final Exception exception) { protected void beginTest() { database.begin(); - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final AtomicLong okCallbackInvoked = new AtomicLong(); @@ -346,7 +349,7 @@ protected void beginTest() { database.async().setParallelLevel(3); database.async().onOk(() -> okCallbackInvoked.incrementAndGet()); - database.async().onError(exception -> Assertions.fail("Error on creating async record", exception)); + database.async().onError(exception -> fail("Error on creating async record", exception)); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); type.createProperty("id", Integer.class); @@ -358,7 +361,7 @@ protected void beginTest() { populateDatabase(); - Assertions.assertTrue(okCallbackInvoked.get() > 0); + assertThat(okCallbackInvoked.get() > 0).isTrue(); } private void populateDatabase() { diff --git a/engine/src/test/java/com/arcadedb/BLOBTest.java b/engine/src/test/java/com/arcadedb/BLOBTest.java index 48f04cc667..09e3d0fce1 100644 --- a/engine/src/test/java/com/arcadedb/BLOBTest.java +++ b/engine/src/test/java/com/arcadedb/BLOBTest.java @@ -22,9 +22,12 @@ import com.arcadedb.database.MutableDocument; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class BLOBTest extends TestHelper { @Override public void beginTest() { @@ -44,7 +47,7 @@ public void testWriteAndRead() { database.transaction(() -> { final Document blob = database.iterateType("Blob", false).next().asDocument(); - Assertions.assertEquals("This is a test", new String( blob.getBinary("binary"))); + assertThat(new String( blob.getBinary("binary"))).isEqualTo("This is a test"); }); } } diff --git a/engine/src/test/java/com/arcadedb/CRUDTest.java b/engine/src/test/java/com/arcadedb/CRUDTest.java index b4e240cb2f..cecc140b53 100644 --- a/engine/src/test/java/com/arcadedb/CRUDTest.java +++ b/engine/src/test/java/com/arcadedb/CRUDTest.java @@ -27,12 +27,16 @@ import com.arcadedb.log.LogManager; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.*; import java.util.logging.*; +import org.assertj.core.api.Assertions; +import static org.assertj.core.api.Assertions.assertThat; + + public class CRUDTest extends TestHelper { private static final int TOT = ((int) GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE.getDefValue()) * 2; @@ -59,11 +63,11 @@ public void testUpdate() { db.begin(); - Assertions.assertEquals(TOT, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(TOT); db.scanType("V", true, record -> { - Assertions.assertEquals(true, record.get("update")); - Assertions.assertEquals("This is a large field to force the page overlap at some point", record.get("largeField")); + assertThat(record.get("update")).isEqualTo(true); + assertThat(record.get("largeField")).isEqualTo("This is a large field to force the page overlap at some point"); return true; }); @@ -83,16 +87,15 @@ public void testMultiUpdatesOverlap() { final String largeField = "largeField" + i; updateAll(largeField); - Assertions.assertEquals(TOT, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(TOT); - Assertions.assertEquals(TOT, - ((Long) db.query("sql", "select count(*) as count from V where " + largeField + " is not null").nextIfAvailable() - .getProperty("count")).intValue(), "Count not expected for field '" + largeField + "'"); + assertThat(((Long) db.query("sql", "select count(*) as count from V where " + largeField + " is not null").nextIfAvailable() + .getProperty("count")).intValue()).as("Count not expected for field '" + largeField + "'").isEqualTo(TOT); db.commit(); db.begin(); - Assertions.assertEquals(TOT, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(TOT); LogManager.instance().log(this, Level.FINE, "Completed %d cycle of updates", i); } @@ -111,24 +114,23 @@ public void testMultiUpdatesOverlap() { final String largeField = "largeField" + i; updateAll(largeField); - Assertions.assertEquals(TOT, db.countType("V", true)); - Assertions.assertEquals(TOT, - ((Long) db.query("sql", "select count(*) as count from V where " + largeField + " is not null").nextIfAvailable() - .getProperty("count")).intValue(), "Count not expected for field '" + largeField + "'"); + assertThat(db.countType("V", true)).isEqualTo(TOT); + assertThat(((Long) db.query("sql", "select count(*) as count from V where " + largeField + " is not null").nextIfAvailable() + .getProperty("count")).intValue()).as("Count not expected for field '" + largeField + "'").isEqualTo(TOT); db.commit(); db.begin(); - Assertions.assertEquals(TOT, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(TOT); LogManager.instance().log(this, Level.FINE, "Completed %d cycle of updates", i); } db.scanType("V", true, record -> { - Assertions.assertEquals(true, record.get("update")); + assertThat(record.get("update")).isEqualTo(true); for (int i = 0; i < 10; ++i) - Assertions.assertEquals("This is a large field to force the page overlap at some point", record.get("largeField" + i)); + assertThat(record.get("largeField" + i)).isEqualTo("This is a large field to force the page overlap at some point"); return true; }); @@ -184,39 +186,37 @@ public void testMultiUpdatesAndDeleteOverlap() { db.begin(); - Assertions.assertEquals(TOT, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(TOT); updateAll("largeField" + i); - Assertions.assertEquals(TOT, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(TOT); db.commit(); db.begin(); - Assertions.assertEquals(TOT, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(TOT); db.scanType("V", true, record -> { - Assertions.assertEquals(true, record.get("update")); - - Assertions.assertEquals("This is a large field to force the page overlap at some point", - record.get("largeField" + counter), "Unexpected content in record " + record.getIdentity()); + assertThat(record.get("update")).isEqualTo(true); + assertThat(record.get("largeField" + counter)).isEqualTo("This is a large field to force the page overlap at some point"); return true; }); deleteAll(); - Assertions.assertEquals(0, db.countType("V", true)); + assertThat(db.countType("V", true)).isEqualTo(0); db.commit(); - database.transaction(() -> Assertions.assertEquals(0, db.countType("V", true))); + database.transaction(() -> assertThat(db.countType("V", true)).isEqualTo(0)); LogManager.instance().log(this, Level.FINE, "Completed %d cycle of updates+delete", i); createAll(); - database.transaction(() -> Assertions.assertEquals(TOT, db.countType("V", true))); + database.transaction(() -> assertThat(db.countType("V", true)).isEqualTo(TOT)); } } finally { diff --git a/engine/src/test/java/com/arcadedb/ConcurrentWriteTest.java b/engine/src/test/java/com/arcadedb/ConcurrentWriteTest.java index 13b586cf79..4efe970750 100644 --- a/engine/src/test/java/com/arcadedb/ConcurrentWriteTest.java +++ b/engine/src/test/java/com/arcadedb/ConcurrentWriteTest.java @@ -25,13 +25,14 @@ import com.arcadedb.exception.ConcurrentModificationException; import com.arcadedb.graph.MutableVertex; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ConcurrentWriteTest { private static final int TOTAL = 10_000; private static final int BATCH_TX = 1; @@ -84,11 +85,11 @@ public void checkConcurrentInsertWithHighConcurrencyOnSamePage() { List allIds = checkRecordSequence(database); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, allIds.size()); + assertThat(allIds.size()).isEqualTo(TOTAL * CONCURRENT_THREADS); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, totalRecordsOnClusters); + assertThat(totalRecordsOnClusters).isEqualTo(TOTAL * CONCURRENT_THREADS); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, database.countType("User", true)); + assertThat(database.countType("User", true)).isEqualTo(TOTAL * CONCURRENT_THREADS); } private List checkRecordSequence(final Database database) { diff --git a/engine/src/test/java/com/arcadedb/ConfigurationTest.java b/engine/src/test/java/com/arcadedb/ConfigurationTest.java index 7236c1eaa1..8827f7be23 100644 --- a/engine/src/test/java/com/arcadedb/ConfigurationTest.java +++ b/engine/src/test/java/com/arcadedb/ConfigurationTest.java @@ -18,41 +18,41 @@ */ package com.arcadedb; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import static com.arcadedb.GlobalConfiguration.TEST; +import static org.assertj.core.api.Assertions.assertThat; public class ConfigurationTest { @Test public void testGlobalExport2Json() { - Assertions.assertFalse(TEST.getValueAsBoolean()); + assertThat(TEST.getValueAsBoolean()).isFalse(); final String json = GlobalConfiguration.toJSON(); TEST.setValue(true); - Assertions.assertTrue(TEST.getValueAsBoolean()); + assertThat(TEST.getValueAsBoolean()).isTrue(); GlobalConfiguration.fromJSON(json); - Assertions.assertFalse(TEST.getValueAsBoolean()); + assertThat(TEST.getValueAsBoolean()).isFalse(); } @Test public void testContextExport2Json() { final ContextConfiguration cfg = new ContextConfiguration(); cfg.setValue(TEST, false); - Assertions.assertFalse(cfg.getValueAsBoolean(TEST)); + assertThat(cfg.getValueAsBoolean(TEST)).isFalse(); final String json = cfg.toJSON(); cfg.setValue(TEST, true); - Assertions.assertTrue(cfg.getValueAsBoolean(TEST)); + assertThat(cfg.getValueAsBoolean(TEST)).isTrue(); cfg.fromJSON(json); - Assertions.assertFalse(cfg.getValueAsBoolean(TEST)); + assertThat(cfg.getValueAsBoolean(TEST)).isFalse(); } @Test public void testDump() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); GlobalConfiguration.dumpConfiguration(new PrintStream(out)); - Assertions.assertTrue(out.size() > 0); + assertThat(out.size() > 0).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/ConstantsTest.java b/engine/src/test/java/com/arcadedb/ConstantsTest.java index eb9f814609..3bfb31dc49 100644 --- a/engine/src/test/java/com/arcadedb/ConstantsTest.java +++ b/engine/src/test/java/com/arcadedb/ConstantsTest.java @@ -18,53 +18,54 @@ */ package com.arcadedb; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + class ConstantsTest { @Test void getVersionMajor() { - Assertions.assertNotNull(Constants.getVersionMajor()); + assertThat(Constants.getVersionMajor()).isNotNull(); } @Test void getVersionMinor() { - Assertions.assertNotNull(Constants.getVersionMinor()); + assertThat(Constants.getVersionMinor()).isNotNull(); } @Test void getVersionHotfix() { - Assertions.assertNotNull(Constants.getVersionHotfix()); + assertThat(Constants.getVersionHotfix()).isNotNull(); } @Test void getVersion() { - Assertions.assertNotNull(Constants.getVersion()); + assertThat(Constants.getVersion()).isNotNull(); } @Test void getRawVersion() { - Assertions.assertNotNull(Constants.getRawVersion()); + assertThat(Constants.getRawVersion()).isNotNull(); } @Test void getBranch() { - Assertions.assertNotNull(Constants.getBranch()); + assertThat(Constants.getBranch()).isNotNull(); } @Test void getBuildNumber() { - Assertions.assertNotNull(Constants.getBuildNumber()); + assertThat(Constants.getBuildNumber()).isNotNull(); } @Test void getTimestamp() { - Assertions.assertNotNull(Constants.getTimestamp()); + assertThat(Constants.getTimestamp()).isNotNull(); } @Test void isSnapshot() { - Assertions.assertNotNull(Constants.isSnapshot()); + assertThat(Constants.isSnapshot()).isNotNull(); } } diff --git a/engine/src/test/java/com/arcadedb/DocumentTest.java b/engine/src/test/java/com/arcadedb/DocumentTest.java index 520765b349..1e0fb5f506 100644 --- a/engine/src/test/java/com/arcadedb/DocumentTest.java +++ b/engine/src/test/java/com/arcadedb/DocumentTest.java @@ -23,11 +23,15 @@ import com.arcadedb.database.MutableDocument; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + + public class DocumentTest extends TestHelper { @Override public void beginTest() { @@ -68,37 +72,37 @@ public void testDetached() { doc.reload(); doc.detach(); - Assertions.assertEquals("Tim", detached.getString("name")); - Assertions.assertEquals(embeddedObj, detached.get("embeddedObj")); - Assertions.assertEquals(embeddedList, detached.get("embeddedList")); - Assertions.assertEquals(embeddedMap, detached.get("embeddedMap")); - Assertions.assertNull(detached.getString("lastname")); + assertThat(detached.getString("name")).isEqualTo("Tim"); + assertThat(detached.get("embeddedObj")).isEqualTo(embeddedObj); + assertThat(detached.get("embeddedList")).isEqualTo(embeddedList); + assertThat(detached.get("embeddedMap")).isEqualTo(embeddedMap); + assertThat(detached.getString("lastname")).isNull(); final Set props = detached.getPropertyNames(); - Assertions.assertEquals(4, props.size()); - Assertions.assertTrue(props.contains("name")); - Assertions.assertTrue(props.contains("embeddedObj")); - Assertions.assertTrue(props.contains("embeddedList")); - Assertions.assertTrue(props.contains("embeddedMap")); + assertThat(props).hasSize(4); + assertThat(props.contains("name")).isTrue(); + assertThat(props.contains("embeddedObj")).isTrue(); + assertThat(props.contains("embeddedList")).isTrue(); + assertThat(props.contains("embeddedMap")).isTrue(); final Map map = detached.toMap(); - Assertions.assertEquals(6, map.size()); + assertThat(map).hasSize(6); - Assertions.assertEquals("Tim", map.get("name")); - Assertions.assertEquals(embeddedObj, map.get("embeddedObj")); - Assertions.assertTrue(((DetachedDocument) map.get("embeddedObj")).getBoolean("embeddedObj")); - Assertions.assertEquals(embeddedList, map.get("embeddedList")); - Assertions.assertTrue(((List) map.get("embeddedList")).get(0).getBoolean("embeddedList")); - Assertions.assertEquals(embeddedMap, map.get("embeddedMap")); - Assertions.assertTrue(((Map) map.get("embeddedMap")).get("first").getBoolean("embeddedMap")); + assertThat(map.get("name")).isEqualTo("Tim"); + assertThat(map.get("embeddedObj")).isEqualTo(embeddedObj); + assertThat(((DetachedDocument) map.get("embeddedObj")).getBoolean("embeddedObj")).isTrue(); + assertThat(map.get("embeddedList")).isEqualTo(embeddedList); + assertThat(((List) map.get("embeddedList")).get(0).getBoolean("embeddedList")).isTrue(); + assertThat(map.get("embeddedMap")).isEqualTo(embeddedMap); + assertThat(((Map) map.get("embeddedMap")).get("first").getBoolean("embeddedMap")).isTrue(); - Assertions.assertEquals("Tim", detached.toJSON().get("name")); + assertThat(detached.toJSON().get("name")).isEqualTo("Tim"); detached.toString(); try { detached.modify(); - Assertions.fail("modify"); + fail("modify"); } catch (final UnsupportedOperationException e) { } @@ -106,12 +110,12 @@ public void testDetached() { try { detached.setBuffer(null); - Assertions.fail("setBuffer"); + fail("setBuffer"); } catch (final UnsupportedOperationException e) { } - Assertions.assertNull(detached.getString("name")); - Assertions.assertNull(detached.getString("lastname")); + assertThat(detached.getString("name")).isNull(); + assertThat(detached.getString("lastname")).isNull(); }); } } diff --git a/engine/src/test/java/com/arcadedb/GlobalConfigurationTest.java b/engine/src/test/java/com/arcadedb/GlobalConfigurationTest.java index 2010eba7da..3be4f0fda0 100644 --- a/engine/src/test/java/com/arcadedb/GlobalConfigurationTest.java +++ b/engine/src/test/java/com/arcadedb/GlobalConfigurationTest.java @@ -18,26 +18,28 @@ */ package com.arcadedb; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class GlobalConfigurationTest extends TestHelper { @Test public void testServerMode() { final String original = GlobalConfiguration.SERVER_MODE.getValueAsString(); GlobalConfiguration.SERVER_MODE.setValue("development"); - Assertions.assertEquals("development", GlobalConfiguration.SERVER_MODE.getValueAsString()); + assertThat(GlobalConfiguration.SERVER_MODE.getValueAsString()).isEqualTo("development"); GlobalConfiguration.SERVER_MODE.setValue("test"); - Assertions.assertEquals("test", GlobalConfiguration.SERVER_MODE.getValueAsString()); + assertThat(GlobalConfiguration.SERVER_MODE.getValueAsString()).isEqualTo("test"); GlobalConfiguration.SERVER_MODE.setValue("production"); - Assertions.assertEquals("production", GlobalConfiguration.SERVER_MODE.getValueAsString()); + assertThat(GlobalConfiguration.SERVER_MODE.getValueAsString()).isEqualTo("production"); try { GlobalConfiguration.SERVER_MODE.setValue("notvalid"); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -51,7 +53,7 @@ public void testTypeConversion() { try { GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.setValue("notvalid"); - Assertions.fail(); + fail(""); } catch (final NumberFormatException e) { // EXPECTED } @@ -64,10 +66,10 @@ public void testDefaultValue() { GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.reset(); final int original = GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.getValueAsInteger(); - Assertions.assertEquals(original, GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.getDefValue()); - Assertions.assertFalse(GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.isChanged()); + assertThat(GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.getDefValue()).isEqualTo(original); + assertThat(GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.isChanged()).isFalse(); GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.setValue(0); - Assertions.assertTrue(GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.isChanged()); + assertThat(GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.isChanged()).isTrue(); GlobalConfiguration.INITIAL_PAGE_CACHE_SIZE.setValue(original); } diff --git a/engine/src/test/java/com/arcadedb/LargeRecordsTest.java b/engine/src/test/java/com/arcadedb/LargeRecordsTest.java index af939d771d..761043b2d5 100644 --- a/engine/src/test/java/com/arcadedb/LargeRecordsTest.java +++ b/engine/src/test/java/com/arcadedb/LargeRecordsTest.java @@ -21,11 +21,14 @@ import com.arcadedb.database.MutableDocument; import com.arcadedb.engine.LocalBucket; import com.arcadedb.schema.DocumentType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Populate the database with records 3X the page size of buckets. */ @@ -47,14 +50,14 @@ public void testScan() { final long pageOverSize = ((LocalBucket) type.getBuckets(true).get(0)).getPageSize() * 3; database.scanType("BigRecords", true, record -> { - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final String buffer = record.asDocument().getString("buffer"); - Assertions.assertEquals(pageOverSize, buffer.length()); + assertThat(buffer.length()).isEqualTo(pageOverSize); total.incrementAndGet(); return true; }); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); database.commit(); } diff --git a/engine/src/test/java/com/arcadedb/LoggerTest.java b/engine/src/test/java/com/arcadedb/LoggerTest.java index e00c786249..4663a320c5 100644 --- a/engine/src/test/java/com/arcadedb/LoggerTest.java +++ b/engine/src/test/java/com/arcadedb/LoggerTest.java @@ -21,11 +21,12 @@ import com.arcadedb.log.DefaultLogger; import com.arcadedb.log.LogManager; import com.arcadedb.log.Logger; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class LoggerTest extends TestHelper { private boolean logged = false; private boolean flushed = false; @@ -54,11 +55,11 @@ public void flush() { LogManager.instance().log(this, Level.FINE, "This is a test"); - Assertions.assertEquals(true, logged); + assertThat(logged).isTrue(); LogManager.instance().flush(); - Assertions.assertEquals(true, flushed); + assertThat(flushed).isTrue(); } finally { LogManager.instance().setLogger(new DefaultLogger()); } diff --git a/engine/src/test/java/com/arcadedb/MVCCTest.java b/engine/src/test/java/com/arcadedb/MVCCTest.java index 082a8eec74..b6efef8e11 100644 --- a/engine/src/test/java/com/arcadedb/MVCCTest.java +++ b/engine/src/test/java/com/arcadedb/MVCCTest.java @@ -32,7 +32,8 @@ import com.arcadedb.schema.EdgeType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; @@ -40,6 +41,9 @@ import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + public class MVCCTest extends TestHelper { private static final int CYCLES = 3; private static final int TOT_ACCOUNT = 10000; @@ -77,8 +81,8 @@ public void testMVCC() { database.async().transaction(() -> { final TransactionContext tx = ((DatabaseInternal) database).getTransaction(); - Assertions.assertTrue(tx.getModifiedPages() == 0); - Assertions.assertNull(tx.getPageCounter(1)); + assertThat(tx.getModifiedPages()).isEqualTo(0); + assertThat(tx.getPageCounter(1)).isNull(); final MutableDocument doc = database.newVertex("Transaction"); doc.set("uuid", UUID.randomUUID().toString()); @@ -88,7 +92,7 @@ public void testMVCC() { final IndexCursor accounts = database.lookupByKey("Account", new String[] { "id" }, new Object[] { 0 }); - Assertions.assertTrue(accounts.hasNext()); + assertThat(accounts.hasNext()).isTrue(); final Identifiable account = accounts.next(); @@ -101,9 +105,9 @@ public void testMVCC() { } finally { new DatabaseChecker(database).setVerboseLevel(0).check(); - Assertions.assertTrue(mvccErrors.get() > 0); - Assertions.assertEquals(0, otherErrors.get()); - Assertions.assertEquals(0, txErrors.get()); + assertThat(mvccErrors.get() > 0).isTrue(); + assertThat(otherErrors.get()).isEqualTo(0); + assertThat(txErrors.get()).isEqualTo(0); database.drop(); database = factory.create(); @@ -138,14 +142,14 @@ public void testNoConflictOnUpdateTx() { final long finalAccountId = accountId; final IndexCursor accounts = database.lookupByKey("Account", new String[] { "id" }, new Object[] { finalAccountId }); - Assertions.assertTrue(accounts.hasNext()); + assertThat(accounts.hasNext()).isTrue(); final Vertex account = accounts.next().asVertex(); final int slot = ((DatabaseAsyncExecutorImpl) database.async()).getSlot(account.getIdentity().getBucketId()); database.async().transaction(() -> { final TransactionContext tx = ((DatabaseInternal) database).getTransaction(); - Assertions.assertTrue(tx.getModifiedPages() == 0); + assertThat(tx.getModifiedPages()).isEqualTo(0); account.modify().set("updated", true).save(); }, 0, null, null, slot); @@ -153,14 +157,13 @@ public void testNoConflictOnUpdateTx() { database.async().waitCompletion(); - Assertions.assertEquals(TOT_ACCOUNT, - (long) database.query("sql", "select count(*) as count from Account where updated = true").nextIfAvailable().getProperty("count")); + assertThat((long) database.query("sql", "select count(*) as count from Account where updated = true").nextIfAvailable().getProperty("count")).isEqualTo(TOT_ACCOUNT); } finally { new DatabaseChecker(database).setVerboseLevel(0).check(); - Assertions.assertEquals(0, mvccErrors.get()); - Assertions.assertEquals(0, otherErrors.get()); + assertThat(mvccErrors.get()).isEqualTo(0); + assertThat(otherErrors.get()).isEqualTo(0); database.drop(); database = factory.create(); diff --git a/engine/src/test/java/com/arcadedb/MultipleDatabasesTest.java b/engine/src/test/java/com/arcadedb/MultipleDatabasesTest.java index 07b9d20bde..3572a4ddc9 100644 --- a/engine/src/test/java/com/arcadedb/MultipleDatabasesTest.java +++ b/engine/src/test/java/com/arcadedb/MultipleDatabasesTest.java @@ -24,13 +24,20 @@ import com.arcadedb.exception.DatabaseOperationException; import com.arcadedb.graph.MutableVertex; import com.arcadedb.utility.FileUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.*; -import java.util.*; +import java.io.File; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class MultipleDatabasesTest extends TestHelper { @Test @@ -51,7 +58,7 @@ public void testMovingRecordsAcrossDatabases() { final MutableVertex v = database.newVertex("V1").set("db", 1).save(); try { v.newEmbeddedDocument("V1", "embedded").set("db", 1).set("embedded", true).save(); - Assertions.fail(); + fail(); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -83,17 +90,17 @@ public void testMovingRecordsAcrossDatabases() { }); // CHECK PRESENCE OF RECORDS IN EACH DATABASE - Assertions.assertEquals(1, database.iterateType("V1", true).next().asVertex().get("db")); - Assertions.assertEquals(1, database.iterateType("V1", true).next().asVertex().getEmbedded("embedded").get("db")); - Assertions.assertEquals(2, database2.iterateType("V1", true).next().asVertex().get("db")); - Assertions.assertEquals(2, database2.iterateType("V1", true).next().asVertex().getEmbedded("embedded").get("db")); - Assertions.assertEquals(3, database3.iterateType("V1", true).next().asVertex().get("db")); - Assertions.assertEquals(3, database3.iterateType("V1", true).next().asVertex().getEmbedded("embedded").get("db")); + assertThat(database.iterateType("V1", true).next().asVertex().get("db")).isEqualTo(1); + assertThat(database.iterateType("V1", true).next().asVertex().getEmbedded("embedded").get("db")).isEqualTo(1); + assertThat(database2.iterateType("V1", true).next().asVertex().get("db")).isEqualTo(2); + assertThat(database2.iterateType("V1", true).next().asVertex().getEmbedded("embedded").get("db")).isEqualTo(2); + assertThat(database3.iterateType("V1", true).next().asVertex().get("db")).isEqualTo(3); + assertThat(database3.iterateType("V1", true).next().asVertex().getEmbedded("embedded").get("db")).isEqualTo(3); // CHECK COPIED RECORDS TOO - Assertions.assertEquals(1, database3.iterateType("V1", true).next().asVertex().getEmbedded("embedded1").get("db")); - Assertions.assertEquals(2, ((List) database3.iterateType("V1", true).next().asVertex().get("list2")).get(0).get("db")); - Assertions.assertEquals(2, ((Map) database3.iterateType("V1", true).next().asVertex().get("map2")).get("copied2").get("db")); + assertThat(database3.iterateType("V1", true).next().asVertex().getEmbedded("embedded1").get("db")).isEqualTo(1); + assertThat(((List) database3.iterateType("V1", true).next().asVertex().get("list2")).get(0).get("db")).isEqualTo(2); + assertThat(((Map) database3.iterateType("V1", true).next().asVertex().get("map2")).get("copied2").get("db")).isEqualTo(2); database.close(); database2.close(); @@ -106,7 +113,7 @@ public void testMovingRecordsAcrossDatabases() { public void testErrorMultipleDatabaseInstancesSamePath() { try { new DatabaseFactory(getDatabasePath()).open(); - Assertions.fail(); + fail(""); } catch (final DatabaseOperationException e) { // EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/PageManagerStressTest.java b/engine/src/test/java/com/arcadedb/PageManagerStressTest.java index 4c6b4ec28a..53cfc75662 100644 --- a/engine/src/test/java/com/arcadedb/PageManagerStressTest.java +++ b/engine/src/test/java/com/arcadedb/PageManagerStressTest.java @@ -26,12 +26,13 @@ import com.arcadedb.engine.WALFile; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import performance.PerformanceTest; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class PageManagerStressTest { private static final int TOT = 1_000_000; private static final String TYPE_NAME = "Device"; @@ -100,8 +101,8 @@ public void stressPageManagerFlush() { } final PageManager.PPageManagerStats stats = ((DatabaseInternal) database).getPageManager().getStats(); - Assertions.assertTrue(stats.evictionRuns > 0); - Assertions.assertTrue(stats.pagesEvicted > 0); + assertThat(stats.evictionRuns > 0).isTrue(); + assertThat(stats.pagesEvicted > 0).isTrue(); } finally { database.close(); diff --git a/engine/src/test/java/com/arcadedb/PolymorphicTest.java b/engine/src/test/java/com/arcadedb/PolymorphicTest.java index e853405a6f..13a171e4c5 100644 --- a/engine/src/test/java/com/arcadedb/PolymorphicTest.java +++ b/engine/src/test/java/com/arcadedb/PolymorphicTest.java @@ -23,10 +23,15 @@ import com.arcadedb.exception.ValidationException; import com.arcadedb.graph.MutableVertex; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class PolymorphicTest extends TestHelper { @@ -45,26 +50,26 @@ protected void beginTest() { try { motorcycle.createProperty("brand", String.class); - Assertions.fail("Expected to fail by creating the same property name as the parent type"); + fail("Expected to fail by creating the same property name as the parent type"); } catch (final SchemaException e) { } - Assertions.assertTrue(database.getSchema().getType("Motorcycle").instanceOf("Vehicle")); + assertThat(database.getSchema().getType("Motorcycle").instanceOf("Vehicle")).isTrue(); database.getSchema().buildVertexType().withName("Car").withTotalBuckets(3).create().addSuperType("Vehicle"); - Assertions.assertTrue(database.getSchema().getType("Car").instanceOf("Vehicle")); + assertThat(database.getSchema().getType("Car").instanceOf("Vehicle")).isTrue(); database.getSchema().buildVertexType().withName("Supercar").withTotalBuckets(3).create().addSuperType("Car"); - Assertions.assertTrue(database.getSchema().getType("Supercar").instanceOf("Car")); - Assertions.assertTrue(database.getSchema().getType("Supercar").instanceOf("Vehicle")); + assertThat(database.getSchema().getType("Supercar").instanceOf("Car")).isTrue(); + assertThat(database.getSchema().getType("Supercar").instanceOf("Vehicle")).isTrue(); //------------ // PEOPLE VERTICES //------------ final VertexType person = database.getSchema().createVertexType("Person"); database.getSchema().createVertexType("Client").addSuperType(person); - Assertions.assertTrue(database.getSchema().getType("Client").instanceOf("Person")); - Assertions.assertFalse(database.getSchema().getType("Client").instanceOf("Vehicle")); + assertThat(database.getSchema().getType("Client").instanceOf("Person")).isTrue(); + assertThat(database.getSchema().getType("Client").instanceOf("Vehicle")).isFalse(); //------------ // EDGES @@ -72,8 +77,8 @@ protected void beginTest() { database.getSchema().createEdgeType("Drives"); database.getSchema().createEdgeType("Owns").addSuperType("Drives"); - Assertions.assertTrue(database.getSchema().getType("Owns").instanceOf("Drives")); - Assertions.assertFalse(database.getSchema().getType("Owns").instanceOf("Vehicle")); + assertThat(database.getSchema().getType("Owns").instanceOf("Drives")).isTrue(); + assertThat(database.getSchema().getType("Owns").instanceOf("Vehicle")).isFalse(); }); final Database db = database; @@ -114,35 +119,33 @@ public void count() throws Exception { database.begin(); try { // NON POLYMORPHIC COUNTING - Assertions.assertEquals(0, database.countType("Vehicle", false)); - Assertions.assertEquals(1, database.countType("Car", false)); - Assertions.assertEquals(1, database.countType("Supercar", false)); - Assertions.assertEquals(1, database.countType("Motorcycle", false)); + assertThat(database.countType("Vehicle", false)).isEqualTo(0); + assertThat(database.countType("Car", false)).isEqualTo(1); + assertThat(database.countType("Supercar", false)).isEqualTo(1); + assertThat(database.countType("Motorcycle", false)).isEqualTo(1); - Assertions.assertEquals(0, database.countType("Person", false)); - Assertions.assertEquals(1, database.countType("Client", false)); + assertThat(database.countType("Person", false)).isEqualTo(0); + assertThat(database.countType("Client", false)).isEqualTo(1); - Assertions.assertEquals(1, database.countType("Drives", false)); - Assertions.assertEquals(2, database.countType("Owns", false)); + assertThat(database.countType("Drives", false)).isEqualTo(1); + assertThat(database.countType("Owns", false)).isEqualTo(2); // POLYMORPHIC COUNTING - Assertions.assertEquals(3, database.countType("Vehicle", true)); - Assertions.assertEquals(2, database.countType("Car", true)); - Assertions.assertEquals(1, database.countType("Supercar", true)); - Assertions.assertEquals(1, database.countType("Motorcycle", true)); + assertThat(database.countType("Vehicle", true)).isEqualTo(3); + assertThat(database.countType("Car", true)).isEqualTo(2); + assertThat(database.countType("Supercar", true)).isEqualTo(1); + assertThat(database.countType("Motorcycle", true)).isEqualTo(1); - Assertions.assertEquals(1, database.countType("Person", true)); - Assertions.assertEquals(1, database.countType("Client", true)); + assertThat(database.countType("Person", true)).isEqualTo(1); + assertThat(database.countType("Client", true)).isEqualTo(1); - Assertions.assertEquals(3, database.countType("Drives", true)); - Assertions.assertEquals(2, database.countType("Owns", true)); + assertThat(database.countType("Drives", true)).isEqualTo(3); + assertThat(database.countType("Owns", true)).isEqualTo(2); - Assertions.assertEquals(3L, - (long) database.query("sql", "select count(*) as count from Vehicle").nextIfAvailable().getProperty("count")); + assertThat((long) database.query("sql", "select count(*) as count from Vehicle").nextIfAvailable().getProperty("count")).isEqualTo(3L); - Assertions.assertEquals(3L, - (long) database.query("sql", "select count(*) as count from Vehicle WHERE $this INSTANCEOF Vehicle").nextIfAvailable() - .getProperty("count")); + assertThat((long) database.query("sql", "select count(*) as count from Vehicle WHERE $this INSTANCEOF Vehicle").nextIfAvailable() + .getProperty("count")).isEqualTo(3L); } finally { database.commit(); @@ -153,28 +156,28 @@ public void count() throws Exception { public void scan() { database.begin(); try { - Assertions.assertEquals(0, scanAndCountType(database, "Vehicle", false)); - Assertions.assertEquals(1, scanAndCountType(database, "Car", false)); - Assertions.assertEquals(1, scanAndCountType(database, "Supercar", false)); - Assertions.assertEquals(1, scanAndCountType(database, "Motorcycle", false)); + assertThat(scanAndCountType(database, "Vehicle", false)).isEqualTo(0); + assertThat(scanAndCountType(database, "Car", false)).isEqualTo(1); + assertThat(scanAndCountType(database, "Supercar", false)).isEqualTo(1); + assertThat(scanAndCountType(database, "Motorcycle", false)).isEqualTo(1); - Assertions.assertEquals(0, scanAndCountType(database, "Person", false)); - Assertions.assertEquals(1, scanAndCountType(database, "Client", false)); + assertThat(scanAndCountType(database, "Person", false)).isEqualTo(0); + assertThat(scanAndCountType(database, "Client", false)).isEqualTo(1); - Assertions.assertEquals(1, scanAndCountType(database, "Drives", false)); - Assertions.assertEquals(2, scanAndCountType(database, "Owns", false)); + assertThat(scanAndCountType(database, "Drives", false)).isEqualTo(1); + assertThat(scanAndCountType(database, "Owns", false)).isEqualTo(2); // POLYMORPHIC COUNTING - Assertions.assertEquals(3, scanAndCountType(database, "Vehicle", true)); - Assertions.assertEquals(2, scanAndCountType(database, "Car", true)); - Assertions.assertEquals(1, scanAndCountType(database, "Supercar", true)); - Assertions.assertEquals(1, scanAndCountType(database, "Motorcycle", true)); + assertThat(scanAndCountType(database, "Vehicle", true)).isEqualTo(3); + assertThat(scanAndCountType(database, "Car", true)).isEqualTo(2); + assertThat(scanAndCountType(database, "Supercar", true)).isEqualTo(1); + assertThat(scanAndCountType(database, "Motorcycle", true)).isEqualTo(1); - Assertions.assertEquals(1, scanAndCountType(database, "Person", true)); - Assertions.assertEquals(1, scanAndCountType(database, "Client", true)); + assertThat(scanAndCountType(database, "Person", true)).isEqualTo(1); + assertThat(scanAndCountType(database, "Client", true)).isEqualTo(1); - Assertions.assertEquals(3, scanAndCountType(database, "Drives", true)); - Assertions.assertEquals(2, scanAndCountType(database, "Owns", true)); + assertThat(scanAndCountType(database, "Drives", true)).isEqualTo(3); + assertThat(scanAndCountType(database, "Owns", true)).isEqualTo(2); } finally { database.commit(); @@ -192,7 +195,7 @@ public void testConstraintsInInheritance() { try { database.command("sql", "INSERT INTO V1 SET prop2 = 'test'"); // this throws the exception as expected since I didn't set the mandatory prop1 - Assertions.fail(); + fail(""); } catch (ValidationException e) { // EXPECTED } @@ -200,7 +203,7 @@ public void testConstraintsInInheritance() { try { database.command("sql", "INSERT INTO V2 SET prop2 = 'test'"); // this ignores the constraint on prop1 and insert the record although I didn't set the value - Assertions.fail(); + fail(""); } catch (ValidationException e) { // EXPECTED } @@ -211,14 +214,14 @@ public void testConstraintsInInheritance() { */ @Test public void testBrokenInheritanceAfterTypeDropLast() { - Assertions.assertEquals(3, database.countType("Vehicle", true)); + assertThat(database.countType("Vehicle", true)).isEqualTo(3); database.transaction(() -> { database.command("sql", "DELETE FROM Supercar"); database.getSchema().dropType("Supercar"); }); - Assertions.assertEquals(2, database.countType("Vehicle", true)); - Assertions.assertEquals(1, database.countType("Car", true)); - Assertions.assertEquals(1, database.countType("Motorcycle", true)); + assertThat(database.countType("Vehicle", true)).isEqualTo(2); + assertThat(database.countType("Car", true)).isEqualTo(1); + assertThat(database.countType("Motorcycle", true)).isEqualTo(1); } /** @@ -226,13 +229,13 @@ public void testBrokenInheritanceAfterTypeDropLast() { */ @Test public void testBrokenInheritanceAfterTypeDropMiddle() { - Assertions.assertEquals(3, database.countType("Vehicle", true)); + assertThat(database.countType("Vehicle", true)).isEqualTo(3); database.transaction(() -> { database.command("sql", "DELETE FROM Car"); database.getSchema().dropType("Car"); }); - Assertions.assertEquals(1, database.countType("Vehicle", true)); - Assertions.assertEquals(1, database.countType("Motorcycle", true)); + assertThat(database.countType("Vehicle", true)).isEqualTo(1); + assertThat(database.countType("Motorcycle", true)).isEqualTo(1); } /** @@ -240,20 +243,20 @@ public void testBrokenInheritanceAfterTypeDropMiddle() { */ @Test public void testBrokenInheritanceAfterTypeDropFirst() { - Assertions.assertEquals(3, database.countType("Vehicle", true)); + assertThat(database.countType("Vehicle", true)).isEqualTo(3); database.transaction(() -> { database.getSchema().dropType("Vehicle"); }); - Assertions.assertEquals(2, database.countType("Car", true)); - Assertions.assertEquals(1, database.countType("Supercar", true)); - Assertions.assertEquals(1, database.countType("Motorcycle", true)); + assertThat(database.countType("Car", true)).isEqualTo(2); + assertThat(database.countType("Supercar", true)).isEqualTo(1); + assertThat(database.countType("Motorcycle", true)).isEqualTo(1); } private int scanAndCountType(final Database db, final String type, final boolean polymorphic) { // NON POLYMORPHIC COUNTING final AtomicInteger counter = new AtomicInteger(); db.scanType(type, polymorphic, record -> { - Assertions.assertTrue(db.getSchema().getType(record.getTypeName()).instanceOf(type)); + assertThat(db.getSchema().getType(record.getTypeName()).instanceOf(type)).isTrue(); counter.incrementAndGet(); return true; }); diff --git a/engine/src/test/java/com/arcadedb/ProfilerTest.java b/engine/src/test/java/com/arcadedb/ProfilerTest.java index 33b1640301..baa54c42f4 100644 --- a/engine/src/test/java/com/arcadedb/ProfilerTest.java +++ b/engine/src/test/java/com/arcadedb/ProfilerTest.java @@ -19,26 +19,27 @@ package com.arcadedb; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ProfilerTest { @Test public void testDumpProfileMetrics() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); Profiler.INSTANCE.dumpMetrics(new PrintStream(out)); - Assertions.assertTrue(out.size() > 0); + assertThat(out.size() > 0).isTrue(); } @Test public void testMetricsToJSON() { JSONObject json = Profiler.INSTANCE.toJSON(); - Assertions.assertTrue(json.has("diskFreeSpace")); - Assertions.assertTrue(json.has("diskTotalSpace")); - Assertions.assertTrue(json.has("updateRecord")); - Assertions.assertTrue(json.has("totalDatabases")); + assertThat(json.has("diskFreeSpace")).isTrue(); + assertThat(json.has("diskTotalSpace")).isTrue(); + assertThat(json.has("updateRecord")).isTrue(); + assertThat(json.has("totalDatabases")).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/RandomTestMultiThreadsTest.java b/engine/src/test/java/com/arcadedb/RandomTestMultiThreadsTest.java index ee0362d29f..24463f2ba5 100644 --- a/engine/src/test/java/com/arcadedb/RandomTestMultiThreadsTest.java +++ b/engine/src/test/java/com/arcadedb/RandomTestMultiThreadsTest.java @@ -32,7 +32,6 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.VertexType; import com.arcadedb.utility.Pair; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; @@ -40,6 +39,8 @@ import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class RandomTestMultiThreadsTest extends TestHelper { private static final int CYCLES = 10000; private static final int STARTING_ACCOUNT = 10000; @@ -106,7 +107,7 @@ public void run() { while (result.hasNext()) { final Result record = result.next(); record.toJSON(); - Assertions.assertEquals(randomId, (Long) record.getProperty("id")); + assertThat((Long) record.getProperty("id")).isEqualTo(randomId); } } else if (op >= 40 && op <= 59) { @@ -123,7 +124,7 @@ public void run() { if (randomUUID != (Long) record.getProperty("uuid")) { System.out.printf("Looking for %d but found %d%n", randomUUID, (Long) record.getProperty("uuid")); } - Assertions.assertEquals(randomUUID, (Long) record.getProperty("uuid")); + assertThat((Long) record.getProperty("uuid")).isEqualTo(randomUUID); } } else if (op >= 60 && op <= 64) { LogManager.instance().log(this, Level.FINE, "Scanning Account records (thread=%d)...", threadId); diff --git a/engine/src/test/java/com/arcadedb/ReusingSpaceTest.java b/engine/src/test/java/com/arcadedb/ReusingSpaceTest.java index 73633d75f7..fa108e1479 100644 --- a/engine/src/test/java/com/arcadedb/ReusingSpaceTest.java +++ b/engine/src/test/java/com/arcadedb/ReusingSpaceTest.java @@ -21,9 +21,10 @@ import com.arcadedb.database.Database; import com.arcadedb.engine.DatabaseChecker; import com.arcadedb.graph.MutableVertex; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class ReusingSpaceTest extends TestHelper { @Test public void testAddAndDeleteLatest() { @@ -35,7 +36,7 @@ public void testAddAndDeleteLatest() { db.getSchema().dropType("CreateAndDelete"); db.getSchema().getOrCreateVertexType("CreateAndDelete", 1); } - Assertions.assertEquals(0, db.countType("CreateAndDelete", true)); + assertThat(db.countType("CreateAndDelete", true)).isEqualTo(0); for (int i = 0; i < 3000; i++) { final MutableVertex[] v = new MutableVertex[1]; @@ -53,7 +54,7 @@ public void testAddAndDeleteLatest() { }); } - Assertions.assertEquals(0, db.countType("CreateAndDelete", true)); + assertThat(db.countType("CreateAndDelete", true)).isEqualTo(0); } finally { new DatabaseChecker(database).setVerboseLevel(0).check(); diff --git a/engine/src/test/java/com/arcadedb/TestHelper.java b/engine/src/test/java/com/arcadedb/TestHelper.java index ab7f774bae..1ccda4d57d 100644 --- a/engine/src/test/java/com/arcadedb/TestHelper.java +++ b/engine/src/test/java/com/arcadedb/TestHelper.java @@ -30,13 +30,16 @@ import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import java.io.*; import java.util.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public abstract class TestHelper { protected static final int PARALLEL_LEVEL = 4; protected final DatabaseFactory factory; @@ -60,7 +63,7 @@ protected TestHelper(final boolean cleanBeforeTest) { FileUtils.deleteRecursively(new File(getDatabasePath())); factory = new DatabaseFactory(getDatabasePath()); database = factory.exists() ? factory.open() : factory.create(); - Assertions.assertEquals(database, DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())).isEqualTo(database); if (autoStartTx) database.begin(); @@ -74,11 +77,11 @@ public static void executeInNewDatabase(final DatabaseTest callback) t try (final DatabaseFactory factory = new DatabaseFactory("./target/databases/" + UUID.randomUUID())) { if (factory.exists()) { factory.open().drop(); - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())).isNull(); } final Database database = factory.create(); - Assertions.assertEquals(database, DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())).isEqualTo(database); try { database.begin(); callback.call(database); @@ -101,12 +104,12 @@ public static void executeInNewDatabase(final String testName, final DatabaseTes factory.open().drop(); final DatabaseInternal database = (DatabaseInternal) factory.create(); - Assertions.assertEquals(database, DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())).isEqualTo(database); try { callback.call(database); } finally { database.drop(); - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())).isNull(); } } } @@ -119,27 +122,27 @@ public static DatabaseFactory dropDatabase(final String databaseName) { final DatabaseFactory factory = new DatabaseFactory(databaseName); if (factory.exists()) factory.open().drop(); - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(factory.getDatabasePath())).isNull(); return factory; } protected void reopenDatabase() { if (database != null) { database.close(); - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())).isNull(); } database = factory.open(); - Assertions.assertEquals(database, DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())).isEqualTo(database); } protected void reopenDatabaseInReadOnlyMode() { if (database != null) { database.close(); - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())).isNull(); } database = factory.open(ComponentFile.MODE.READ_ONLY); - Assertions.assertEquals(database, DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(database.getDatabasePath())).isEqualTo(database); } protected String getDatabasePath() { @@ -196,7 +199,7 @@ public static void expectException(final CallableNoReturn callback, final Class< throws Exception { try { callback.call(); - Assertions.fail(); + fail(""); } catch (final Throwable e) { if (e.getClass().equals(expectedException)) // EXPECTED @@ -214,11 +217,11 @@ protected void checkDatabaseIntegrity() { while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(0, ((Collection) row.getProperty("corruptedRecords")).size()); - Assertions.assertEquals(0, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(0, ((Collection) row.getProperty("warnings")).size(), "Warnings" + row.getProperty("warnings")); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(0); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo(0); + assertThat(((Collection) row.getProperty("warnings")).size()).as("Warnings" + row.getProperty("warnings")).isEqualTo(0); } } @@ -232,6 +235,6 @@ public static void checkActiveDatabases() { for (final Database db : activeDatabases) db.close(); - Assertions.assertTrue(activeDatabases.isEmpty(), "Found active databases: " + activeDatabases); + assertThat(activeDatabases.isEmpty()).as("Found active databases: " + activeDatabases).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/TransactionBucketTest.java b/engine/src/test/java/com/arcadedb/TransactionBucketTest.java index 9638661d32..4e5641b22e 100644 --- a/engine/src/test/java/com/arcadedb/TransactionBucketTest.java +++ b/engine/src/test/java/com/arcadedb/TransactionBucketTest.java @@ -26,12 +26,18 @@ import com.arcadedb.graph.MutableEdge; import com.arcadedb.graph.MutableVertex; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; + public class TransactionBucketTest extends TestHelper { private static final int TOT = 10000; @@ -49,21 +55,21 @@ public void testScan() { database.begin(); database.scanBucket("V_0", record -> { - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Set prop = new HashSet(); prop.addAll(((Document) record).getPropertyNames()); - Assertions.assertEquals(3, ((Document) record).getPropertyNames().size(), 9); - Assertions.assertTrue(prop.contains("id")); - Assertions.assertTrue(prop.contains("name")); - Assertions.assertTrue(prop.contains("surname")); + assertThat(((Document) record).getPropertyNames().size()).isCloseTo(3, within(9)); + assertThat(prop.contains("id")).isTrue(); + assertThat(prop.contains("name")).isTrue(); + assertThat(prop.contains("surname")).isTrue(); total.incrementAndGet(); return true; }); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); database.commit(); } @@ -78,21 +84,22 @@ public void testIterator() { while (iterator.hasNext()) { final Document record = (Document) iterator.next(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Set prop = new HashSet(); prop.addAll(record.getPropertyNames()); - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); - Assertions.assertTrue(prop.contains("id")); - Assertions.assertTrue(prop.contains("name")); - Assertions.assertTrue(prop.contains("surname")); + + assertThat(record.getPropertyNames().size()).isCloseTo(3, within(9)); + assertThat(prop.contains("id")).isTrue(); + assertThat(prop.contains("name")).isTrue(); + assertThat(prop.contains("surname")).isTrue(); total.incrementAndGet(); } - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); database.commit(); } @@ -105,16 +112,16 @@ public void testLookupAllRecordsByRID() { database.scanBucket("V_0", record -> { final Document record2 = (Document) database.lookupByRID(record.getIdentity(), false); - Assertions.assertNotNull(record2); - Assertions.assertEquals(record, record2); + assertThat(record2).isNotNull(); + assertThat(record2).isEqualTo(record); final Set prop = new HashSet(); prop.addAll(record2.getPropertyNames()); - Assertions.assertEquals(record2.getPropertyNames().size(), 3); - Assertions.assertTrue(prop.contains("id")); - Assertions.assertTrue(prop.contains("name")); - Assertions.assertTrue(prop.contains("surname")); + assertThat(record2.getPropertyNames()).hasSize(3); + assertThat(prop.contains("id")).isTrue(); + assertThat(prop.contains("name")).isTrue(); + assertThat(prop.contains("surname")).isTrue(); total.incrementAndGet(); return true; @@ -122,7 +129,7 @@ public void testLookupAllRecordsByRID() { database.commit(); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); } @Test @@ -140,23 +147,23 @@ public void testDeleteAllRecordsReuseSpace() { }); } finally { - Assertions.assertEquals(0, database.countBucket("V_0")); + assertThat(database.countBucket("V_0")).isEqualTo(0); } database.commit(); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); beginTest(); - database.transaction(() -> Assertions.assertEquals(TOT, database.countBucket("V_0"))); + database.transaction(() -> assertThat(database.countBucket("V_0")).isEqualTo(TOT)); } @Test public void testDeleteFail() { reopenDatabaseInReadOnlyMode(); - Assertions.assertThrows(DatabaseIsReadOnlyException.class, () -> { + assertThatExceptionOfType(DatabaseIsReadOnlyException.class).isThrownBy(() -> { database.begin(); database.scanBucket("V_0", record -> { @@ -186,8 +193,8 @@ public void testIteratorOnEdges() { database.scanType("testIteratorOnEdges_Edge", true, record -> { final Edge e1 = (Edge) record; - Assertions.assertEquals(v1.getIdentity(), e1.getOut()); - Assertions.assertEquals(v2.getIdentity(), e1.getIn()); + assertThat(e1.getOut()).isEqualTo(v1.getIdentity()); + assertThat(e1.getIn()).isEqualTo(v2.getIdentity()); total.incrementAndGet(); return true; @@ -195,7 +202,7 @@ public void testIteratorOnEdges() { database.commit(); - Assertions.assertEquals(1, total.get()); + assertThat(total.get()).isEqualTo(1); } @Test @@ -211,15 +218,15 @@ public void testScanOnEdges() { final ResultSet result = database.query("sql", "select from testIteratorOnEdges_Edge"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Record record = result.next().getRecord().get(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Edge e2 = (Edge) record; - Assertions.assertEquals(v1.getIdentity(), e2.getOut()); - Assertions.assertEquals(v2.getIdentity(), e2.getIn()); + assertThat(e2.getOut()).isEqualTo(v1.getIdentity()); + assertThat(e2.getIn()).isEqualTo(v2.getIdentity()); database.commit(); } @@ -238,15 +245,15 @@ public void testScanOnEdgesAfterTx() { database.transaction(() -> { final ResultSet result = database.query("sql", "select from testIteratorOnEdges_Edge"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Record record = result.next().getRecord().get(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Edge e2 = (Edge) record; - Assertions.assertNotNull(e2.getOutVertex()); - Assertions.assertNotNull(e2.getInVertex()); + assertThat(e2.getOutVertex()).isNotNull(); + assertThat(e2.getInVertex()).isNotNull(); }); } diff --git a/engine/src/test/java/com/arcadedb/TransactionIsolationTest.java b/engine/src/test/java/com/arcadedb/TransactionIsolationTest.java index 3ed3249a88..56e02aea13 100644 --- a/engine/src/test/java/com/arcadedb/TransactionIsolationTest.java +++ b/engine/src/test/java/com/arcadedb/TransactionIsolationTest.java @@ -1,33 +1,15 @@ -/* - * Copyright © 2021-present Arcade Data Ltd (info@arcadedata.com) - * - * 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 - * - * 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. - * - * SPDX-FileCopyrightText: 2021-present Arcade Data Ltd (info@arcadedata.com) - * SPDX-License-Identifier: Apache-2.0 - */ package com.arcadedb; import com.arcadedb.database.Database; import com.arcadedb.graph.MutableVertex; -import org.junit.jupiter.api.Assertions; +import com.arcadedb.query.sql.executor.ResultSet; import org.junit.jupiter.api.Test; -import java.util.concurrent.*; +import java.util.concurrent.CountDownLatch; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; -/** - * Tests the isolation of transactions based on the configured settings. - */ public class TransactionIsolationTest extends TestHelper { @Override protected void beginTest() { @@ -46,23 +28,23 @@ public void testNoDirtyReads() throws InterruptedException { final Thread thread1 = new Thread(() -> { database.transaction(() -> { try { - Assertions.assertEquals(0, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(0); final MutableVertex v = database.newVertex("Node"); v.set("id", 0); v.set("origin", "thread1"); v.save(); - Assertions.assertEquals(1, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(1); sem1.countDown(); sem2.await(); - Assertions.assertEquals(1, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(1); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); @@ -73,19 +55,19 @@ public void testNoDirtyReads() throws InterruptedException { try { sem1.await(); - Assertions.assertEquals(0, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(0); final MutableVertex v = database.newVertex("Node"); v.set("id", 1); v.set("origin", "thread2"); v.save(); - Assertions.assertEquals(1, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(1); sem2.countDown(); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); @@ -110,7 +92,7 @@ public void testReadCommitted() throws InterruptedException { final Thread thread1 = new Thread(() -> { database.transaction(() -> { database.newVertex("Node").set("id", 0, "origin", "thread1").save(); - Assertions.assertEquals(1, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(1); }); sem1.countDown(); @@ -119,17 +101,17 @@ public void testReadCommitted() throws InterruptedException { try { sem2.await(); // CHECK THE NEW RECORD (PHANTOM READ) IS VISIBLE - Assertions.assertEquals(2, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(2); database.newVertex("Node").set("id", 3, "origin", "thread1").save(); - Assertions.assertEquals(3, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(3); // MODIFY A RECORD database.query("sql", "select from Node where id = 0").nextIfAvailable().getRecord().get().asVertex().modify().set("modified", true).save(); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); @@ -143,13 +125,13 @@ public void testReadCommitted() throws InterruptedException { sem1.await(); // CHECK THE NEW RECORD (PHANTOM READ) IS VISIBLE - Assertions.assertEquals(1, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(1); database.newVertex("Node").set("id", 1, "origin", "thread2").save(); - Assertions.assertEquals(2, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(2); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); @@ -160,13 +142,13 @@ public void testReadCommitted() throws InterruptedException { try { sem3.await(); - Assertions.assertEquals(3, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(3); // CHECK THE NEW RECORD WAS MODIFIED - Assertions.assertTrue((Boolean) database.query("sql", "select from Node where id = 0").nextIfAvailable().getProperty("modified")); + assertThat((Boolean) database.query("sql", "select from Node where id = 0").nextIfAvailable().getProperty("modified")).isTrue(); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); @@ -194,7 +176,7 @@ public void testRepeatableRead() throws InterruptedException { final Thread thread1 = new Thread(() -> { database.transaction(() -> { database.newVertex("Node").set("id", 0, "origin", "thread1").save(); - Assertions.assertEquals(1, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(1); }); sem1.countDown(); @@ -203,17 +185,17 @@ public void testRepeatableRead() throws InterruptedException { try { sem2.await(); // CHECK THE NEW RECORD (PHANTOM READ) IS VISIBLE - Assertions.assertEquals(2, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(2); database.newVertex("Node").set("id", 3, "origin", "thread1").save(); - Assertions.assertEquals(3, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(3); // MODIFY A RECORD database.query("sql", "select from Node where id = 0").nextIfAvailable().getRecord().get().asVertex().modify().set("modified", true).save(); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); @@ -227,13 +209,13 @@ public void testRepeatableRead() throws InterruptedException { sem1.await(); // CHECK THE NEW RECORD (PHANTOM READ) IS VISIBLE - Assertions.assertEquals(1, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(1); database.newVertex("Node").set("id", 1, "origin", "thread2").save(); - Assertions.assertEquals(2, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(2); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); @@ -242,17 +224,25 @@ public void testRepeatableRead() throws InterruptedException { sem2.countDown(); try { - Assertions.assertEquals(2, database.countType("Node", true)); + assertThat(database.countType("Node", true)).isEqualTo(2); - Assertions.assertNull(database.query("sql", "select from Node where id = 0").nextIfAvailable().getProperty("modified")); + assertThat( + database.query("sql", "select from Node where id = 0") + .nextIfAvailable() + .getProperty("modified") + ).isNull(); sem3.await(); // CHECK THE NEW RECORD WAS MODIFIED - Assertions.assertNull(database.query("sql", "select from Node where id = 0").nextIfAvailable().getProperty("modified")); + assertThat( + database.query("sql", "select from Node where id = 0") + .nextIfAvailable() + .getProperty("modified") + ).isNull(); } catch (InterruptedException e) { - Assertions.fail(); + fail("InterruptedException occurred"); throw new RuntimeException(e); } }); diff --git a/engine/src/test/java/com/arcadedb/TransactionTypeTest.java b/engine/src/test/java/com/arcadedb/TransactionTypeTest.java index a092bb84b7..d7dc42ffb1 100644 --- a/engine/src/test/java/com/arcadedb/TransactionTypeTest.java +++ b/engine/src/test/java/com/arcadedb/TransactionTypeTest.java @@ -1,21 +1,3 @@ -/* - * Copyright © 2021-present Arcade Data Ltd (info@arcadedata.com) - * - * 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 - * - * 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. - * - * SPDX-FileCopyrightText: 2021-present Arcade Data Ltd (info@arcadedata.com) - * SPDX-License-Identifier: Apache-2.0 - */ package com.arcadedb; import com.arcadedb.database.Document; @@ -27,13 +9,15 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.utility.CollectionUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; + public class TransactionTypeTest extends TestHelper { private static final int TOT = 10000; private static final String TYPE_NAME = "V"; @@ -50,21 +34,21 @@ public void testScan() { database.begin(); database.scanType(TYPE_NAME, true, record -> { - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Set prop = new HashSet(); prop.addAll(record.getPropertyNames()); - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); - Assertions.assertTrue(prop.contains("id")); - Assertions.assertTrue(prop.contains("name")); - Assertions.assertTrue(prop.contains("surname")); + assertThat(record.getPropertyNames().size()).isEqualTo(3); + assertThat(prop.contains("id")).isTrue(); + assertThat(prop.contains("name")).isTrue(); + assertThat(prop.contains("surname")).isTrue(); total.incrementAndGet(); return true; }); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); database.commit(); } @@ -77,16 +61,16 @@ public void testLookupAllRecordsByRID() { database.scanType(TYPE_NAME, true, record -> { final Document record2 = (Document) database.lookupByRID(record.getIdentity(), false); - Assertions.assertNotNull(record2); - Assertions.assertEquals(record, record2); + assertThat(record2).isNotNull(); + assertThat(record2).isEqualTo(record); final Set prop = new HashSet(); prop.addAll(record2.getPropertyNames()); - Assertions.assertEquals(record2.getPropertyNames().size(), 3); - Assertions.assertTrue(prop.contains("id")); - Assertions.assertTrue(prop.contains("name")); - Assertions.assertTrue(prop.contains("surname")); + assertThat(record2.getPropertyNames().size()).isEqualTo(3); + assertThat(prop.contains("id")).isTrue(); + assertThat(prop.contains("name")).isTrue(); + assertThat(prop.contains("surname")).isTrue(); total.incrementAndGet(); return true; @@ -94,7 +78,7 @@ public void testLookupAllRecordsByRID() { database.commit(); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); } @Test @@ -105,27 +89,27 @@ public void testLookupAllRecordsByKey() { for (int i = 0; i < TOT; i++) { final IndexCursor result = database.lookupByKey(TYPE_NAME, new String[] { "id" }, new Object[] { i }); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat(Optional.ofNullable(result)).isNotNull(); + assertThat(result.hasNext()).isTrue(); final Document record2 = (Document) result.next().getRecord(); - Assertions.assertEquals(i, record2.get("id")); + assertThat(record2.get("id")).isEqualTo(i); final Set prop = new HashSet(); prop.addAll(record2.getPropertyNames()); - Assertions.assertEquals(record2.getPropertyNames().size(), 3); - Assertions.assertTrue(prop.contains("id")); - Assertions.assertTrue(prop.contains("name")); - Assertions.assertTrue(prop.contains("surname")); + assertThat(record2.getPropertyNames().size()).isEqualTo(3); + assertThat(prop.contains("id")).isTrue(); + assertThat(prop.contains("name")).isTrue(); + assertThat(prop.contains("surname")).isTrue(); total.incrementAndGet(); } database.commit(); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); } @Test @@ -142,22 +126,22 @@ public void testDeleteAllRecordsReuseSpace() throws IOException { database.commit(); - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); database.begin(); - Assertions.assertEquals(0, database.countType(TYPE_NAME, true)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(0); // GET EACH ITEM TO CHECK IT HAS BEEN DELETED final Index[] indexes = database.getSchema().getIndexes(); for (int i = 0; i < TOT; ++i) { for (final Index index : indexes) - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i); + assertThat(index.get(new Object[]{i}).hasNext()).as("Found item with key " + i).isFalse(); } beginTest(); - database.transaction(() -> Assertions.assertEquals(TOT, database.countType(TYPE_NAME, true))); + database.transaction(() -> assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT)); } @Test @@ -176,11 +160,11 @@ public void testDeleteRecordsCheckScanAndIterators() throws IOException { database.commit(); - Assertions.assertEquals(1, total.get()); + assertThat(total.get()).isEqualTo(1); database.begin(); - Assertions.assertEquals(originalCount - 1, database.countType(TYPE_NAME, true)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(originalCount - 1); // COUNT WITH SCAN total.set(0); @@ -188,14 +172,14 @@ public void testDeleteRecordsCheckScanAndIterators() throws IOException { total.incrementAndGet(); return true; }); - Assertions.assertEquals(originalCount - 1, total.get()); + assertThat(total.get()).isEqualTo(originalCount - 1); // COUNT WITH ITERATE TYPE total.set(0); for (final Iterator it = database.iterateType(TYPE_NAME, true); it.hasNext(); it.next()) total.incrementAndGet(); - Assertions.assertEquals(originalCount - 1, total.get()); + assertThat(total.get()).isEqualTo(originalCount - 1); } @Test @@ -214,11 +198,11 @@ public void testPlaceholderOnScanAndIterate() throws IOException { database.commit(); - Assertions.assertEquals(1, total.get()); + assertThat(total.get()).isEqualTo(1); database.begin(); - Assertions.assertEquals(originalCount, database.countType(TYPE_NAME, true)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(originalCount); // COUNT WITH SCAN total.set(0); @@ -226,21 +210,21 @@ public void testPlaceholderOnScanAndIterate() throws IOException { total.incrementAndGet(); return true; }); - Assertions.assertEquals(originalCount, total.get()); + assertThat(total.get()).isEqualTo(originalCount); // COUNT WITH ITERATE TYPE total.set(0); for (final Iterator it = database.iterateType(TYPE_NAME, true); it.hasNext(); it.next()) total.incrementAndGet(); - Assertions.assertEquals(originalCount, total.get()); + assertThat(total.get()).isEqualTo(originalCount); } @Test public void testDeleteFail() { reopenDatabaseInReadOnlyMode(); - Assertions.assertThrows(DatabaseIsReadOnlyException.class, () -> { + assertThatExceptionOfType(DatabaseIsReadOnlyException.class).isThrownBy(() -> { database.begin(); @@ -262,9 +246,9 @@ public void testNestedTx() { database.transaction(() -> database.newDocument(TYPE_NAME).set("id", -2, "tx", 2).save()); }); - Assertions.assertEquals(0, CollectionUtils.countEntries(database.query("sql", "select from " + TYPE_NAME + " where tx = 0"))); - Assertions.assertEquals(1, CollectionUtils.countEntries(database.query("sql", "select from " + TYPE_NAME + " where tx = 1"))); - Assertions.assertEquals(1, CollectionUtils.countEntries(database.query("sql", "select from " + TYPE_NAME + " where tx = 2"))); + assertThat(CollectionUtils.countEntries(database.query("sql", "select from " + TYPE_NAME + " where tx = 0"))).isEqualTo(0); + assertThat(CollectionUtils.countEntries(database.query("sql", "select from " + TYPE_NAME + " where tx = 1"))).isEqualTo(1); + assertThat(CollectionUtils.countEntries(database.query("sql", "select from " + TYPE_NAME + " where tx = 2"))).isEqualTo(1); } @Override diff --git a/engine/src/test/java/com/arcadedb/TypeConversionTest.java b/engine/src/test/java/com/arcadedb/TypeConversionTest.java index 45afe7dad0..50c53a9653 100644 --- a/engine/src/test/java/com/arcadedb/TypeConversionTest.java +++ b/engine/src/test/java/com/arcadedb/TypeConversionTest.java @@ -26,7 +26,7 @@ import com.arcadedb.schema.Type; import com.arcadedb.utility.DateUtils; import com.arcadedb.utility.NanoClock; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.math.*; @@ -37,6 +37,10 @@ import java.util.*; import java.util.concurrent.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class TypeConversionTest extends TestHelper { @Override public void beginTest() { @@ -82,21 +86,21 @@ public void testNoConversion() { doc.set("localDate", localDate); // SCHEMALESS doc.set("localDateTime", localDateTime); // SCHEMALESS - Assertions.assertEquals(33, doc.get("int")); - Assertions.assertEquals(33l, doc.get("long")); - Assertions.assertEquals(33.33f, doc.get("float")); - Assertions.assertEquals(33.33d, doc.get("double")); - Assertions.assertEquals(new BigDecimal("33.33"), doc.get("decimal")); - Assertions.assertEquals(now, doc.get("date")); - - Assertions.assertEquals(0, ((LocalDateTime) doc.get("datetime_second")).getNano()); - Assertions.assertEquals(now, doc.get("datetime_millis")); - Assertions.assertEquals(ChronoUnit.MILLIS, DateUtils.getPrecision(doc.getLocalDateTime("datetime_millis").getNano())); - Assertions.assertEquals(ChronoUnit.MILLIS, DateUtils.getPrecision(((LocalDateTime) doc.get("datetime_micros")).getNano())); - Assertions.assertEquals(ChronoUnit.MILLIS, DateUtils.getPrecision(((LocalDateTime) doc.get("datetime_nanos")).getNano())); - - Assertions.assertEquals(localDate, doc.get("localDate")); - Assertions.assertEquals(localDateTime, doc.get("localDateTime")); + assertThat(doc.get("int")).isEqualTo(33); + assertThat(doc.get("long")).isEqualTo(33l); + assertThat(doc.get("float")).isEqualTo(33.33f); + assertThat(doc.get("double")).isEqualTo(33.33d); + assertThat(doc.get("decimal")).isEqualTo(new BigDecimal("33.33")); + assertThat(doc.get("date")).isEqualTo(now); + + assertThat(((LocalDateTime) doc.get("datetime_second")).getNano()).isEqualTo(0); + assertThat(doc.get("datetime_millis")).isEqualTo(now); + assertThat(DateUtils.getPrecision(doc.getLocalDateTime("datetime_millis").getNano())).isEqualTo(ChronoUnit.MILLIS); + assertThat(DateUtils.getPrecision(((LocalDateTime) doc.get("datetime_micros")).getNano())).isEqualTo(ChronoUnit.MILLIS); + assertThat(DateUtils.getPrecision(((LocalDateTime) doc.get("datetime_nanos")).getNano())).isEqualTo(ChronoUnit.MILLIS); + + assertThat(doc.get("localDate")).isEqualTo(localDate); + assertThat(doc.get("localDateTime")).isEqualTo(localDateTime); }); } @@ -108,19 +112,19 @@ public void testConversionDecimals() { final Date now = new Date(); doc.set("decimal", "33.33"); - Assertions.assertEquals(new BigDecimal("33.33"), doc.get("decimal")); + assertThat(doc.get("decimal")).isEqualTo(new BigDecimal("33.33")); doc.set("decimal", 33.33f); - Assertions.assertEquals(new BigDecimal("33.33"), doc.get("decimal")); + assertThat(doc.get("decimal")).isEqualTo(new BigDecimal("33.33")); doc.set("decimal", 33.33d); - Assertions.assertEquals(new BigDecimal("33.33"), doc.get("decimal")); + assertThat(doc.get("decimal")).isEqualTo(new BigDecimal("33.33")); doc.save(); - Assertions.assertEquals(String.format("%.1f", 33.3F), + assertEquals(String.format("%.1f", 33.3F), database.query("sql", "select decimal.format('%.1f') as d from " + doc.getIdentity()).nextIfAvailable().getProperty("d")); - Assertions.assertEquals(String.format("%.2f", 33.33F), + assertEquals(String.format("%.2f", 33.33F), database.query("sql", "select decimal.format('%.2f') as d from " + doc.getIdentity()).nextIfAvailable().getProperty("d")); doc.delete(); @@ -136,30 +140,30 @@ public void testConversionDates() { doc.set("date", now.getTime()); doc.set("datetime_millis", now.getTime()); - Assertions.assertEquals(now, doc.get("date")); - Assertions.assertEquals(now, doc.get("datetime_millis")); + assertThat(doc.get("date")).isEqualTo(now); + assertThat(doc.get("datetime_millis")).isEqualTo(now); doc.set("date", "" + now.getTime()); doc.set("datetime_millis", "" + now.getTime()); - Assertions.assertEquals(now, doc.get("date")); - Assertions.assertEquals(now, doc.get("datetime_millis")); + assertThat(doc.get("date")).isEqualTo(now); + assertThat(doc.get("datetime_millis")).isEqualTo(now); final SimpleDateFormat df = new SimpleDateFormat(database.getSchema().getDateTimeFormat()); doc.set("date", df.format(now)); doc.set("datetime_millis", df.format(now)); - Assertions.assertEquals(df.format(now), df.format(doc.get("date"))); - Assertions.assertEquals(df.format(now), df.format(doc.get("datetime_millis"))); + assertThat(df.format(doc.get("date"))).isEqualTo(df.format(now)); + assertThat(df.format(doc.get("datetime_millis"))).isEqualTo(df.format(now)); final LocalDate localDate = LocalDate.now(); final LocalDateTime localDateTime = LocalDateTime.now(); doc.set("date", localDate); doc.set("datetime_nanos", localDateTime); - Assertions.assertEquals(localDate, doc.getLocalDate("date")); - Assertions.assertEquals(localDateTime.truncatedTo(DateUtils.getPrecision(localDateTime.getNano())), + assertThat(doc.getLocalDate("date")).isEqualTo(localDate); + assertEquals(localDateTime.truncatedTo(DateUtils.getPrecision(localDateTime.getNano())), doc.getLocalDateTime("datetime_nanos")); - Assertions.assertEquals( + assertEquals( TimeUnit.MILLISECONDS.convert(localDateTime.toEpochSecond(ZoneOffset.UTC), TimeUnit.SECONDS) + localDateTime.getLong( ChronoField.MILLI_OF_SECOND), doc.getCalendar("datetime_nanos").getTime().getTime()); }); @@ -170,21 +174,21 @@ public void testDateAndDateTimeSettingsAreSavedInDatabase() { database.command("sql", "alter database `arcadedb.dateTimeImplementation` `java.time.LocalDateTime`"); database.command("sql", "alter database `arcadedb.dateImplementation` `java.time.LocalDate`"); - Assertions.assertEquals(LocalDateTime.class, ((DatabaseInternal) database).getSerializer().getDateTimeImplementation()); - Assertions.assertEquals(LocalDate.class, ((DatabaseInternal) database).getSerializer().getDateImplementation()); + assertThat(((DatabaseInternal) database).getSerializer().getDateTimeImplementation()).isEqualTo(LocalDateTime.class); + assertThat(((DatabaseInternal) database).getSerializer().getDateImplementation()).isEqualTo(LocalDate.class); database.close(); database = factory.open(); - Assertions.assertEquals(LocalDateTime.class, ((DatabaseInternal) database).getSerializer().getDateTimeImplementation()); - Assertions.assertEquals(LocalDate.class, ((DatabaseInternal) database).getSerializer().getDateImplementation()); + assertThat(((DatabaseInternal) database).getSerializer().getDateTimeImplementation()).isEqualTo(LocalDateTime.class); + assertThat(((DatabaseInternal) database).getSerializer().getDateImplementation()).isEqualTo(LocalDate.class); database.command("sql", "alter database `arcadedb.dateTimeImplementation` `java.util.Date`"); database.command("sql", "alter database `arcadedb.dateImplementation` `java.util.Date`"); - Assertions.assertEquals(Date.class, ((DatabaseInternal) database).getSerializer().getDateTimeImplementation()); - Assertions.assertEquals(Date.class, ((DatabaseInternal) database).getSerializer().getDateImplementation()); + assertThat(((DatabaseInternal) database).getSerializer().getDateTimeImplementation()).isEqualTo(Date.class); + assertThat(((DatabaseInternal) database).getSerializer().getDateImplementation()).isEqualTo(Date.class); } @Test @@ -202,7 +206,7 @@ public void testLocalDateTime() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.SECONDS), doc.get("datetime_second")); + assertThat(doc.get("datetime_second")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.SECONDS)); database.transaction(() -> { // TEST MILLISECONDS PRECISION @@ -211,7 +215,7 @@ public void testLocalDateTime() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.MILLIS), doc.get("datetime_millis")); + assertThat(doc.get("datetime_millis")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.MILLIS)); // TEST MICROSECONDS PRECISION database.transaction(() -> { @@ -220,7 +224,7 @@ public void testLocalDateTime() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.MICROS), doc.get("datetime_micros")); + assertThat(doc.get("datetime_micros")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.MICROS)); // TEST NANOSECOND PRECISION database.transaction(() -> { @@ -228,25 +232,21 @@ public void testLocalDateTime() throws ClassNotFoundException { doc.save(); }); doc.reload(); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.NANOS), doc.get("datetime_nanos")); - - Assertions.assertNotNull( - database.query("sql", "select datetime_second.asLong() as long from ConversionTest").nextIfAvailable() - .getProperty("long")); - Assertions.assertNotNull( - database.query("sql", "select datetime_millis.asLong() as long from ConversionTest").nextIfAvailable() - .getProperty("long")); - Assertions.assertNotNull( - database.query("sql", "select datetime_micros.asLong() as long from ConversionTest").nextIfAvailable() - .getProperty("long")); - Assertions.assertNotNull(database.query("sql", "select datetime_nanos.asLong() as long from ConversionTest").nextIfAvailable() - .getProperty("long")); - - Assertions.assertEquals( - TimeUnit.MILLISECONDS.convert(localDateTime.toEpochSecond(ZoneOffset.UTC), TimeUnit.SECONDS) + localDateTime.getLong( - ChronoField.MILLI_OF_SECOND), doc.getDate("datetime_millis").getTime()); + assertThat(doc.get("datetime_nanos")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.NANOS)); + + assertThat((Long) database.query("sql", "select datetime_second.asLong() as long from ConversionTest").nextIfAvailable() + .getProperty("long")).isNotNull(); + assertThat((Long) database.query("sql", "select datetime_millis.asLong() as long from ConversionTest").nextIfAvailable() + .getProperty("long")).isNotNull(); + assertThat((Long) database.query("sql", "select datetime_micros.asLong() as long from ConversionTest").nextIfAvailable() + .getProperty("long")).isNotNull(); + assertThat((Long) database.query("sql", "select datetime_nanos.asLong() as long from ConversionTest").nextIfAvailable() + .getProperty("long")).isNotNull(); + + assertThat(doc.getDate("datetime_millis").getTime()).isEqualTo(TimeUnit.MILLISECONDS.convert(localDateTime.toEpochSecond(ZoneOffset.UTC), TimeUnit.SECONDS) + localDateTime.getLong( + ChronoField.MILLI_OF_SECOND)); - Assertions.assertTrue(localDateTime.isEqual(doc.getLocalDateTime("datetime_nanos"))); + assertThat(localDateTime.isEqual(doc.getLocalDateTime("datetime_nanos"))).isTrue(); } finally { ((DatabaseInternal) database).getSerializer().setDateTimeImplementation(Date.class); @@ -261,20 +261,20 @@ public void testSQL() throws ClassNotFoundException { try { database.begin(); ResultSet result = database.command("sql", "insert into ConversionTest set datetime_second = ?", localDateTime); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.SECONDS), result.next().toElement().get("datetime_second")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().toElement().get("datetime_second")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.SECONDS)); result = database.command("sql", "insert into ConversionTest set datetime_millis = ?", localDateTime); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.MILLIS), result.next().toElement().get("datetime_millis")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().toElement().get("datetime_millis")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.MILLIS)); result = database.command("sql", "insert into ConversionTest set datetime_micros = ?", localDateTime); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.MICROS), result.next().toElement().get("datetime_micros")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().toElement().get("datetime_micros")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.MICROS)); result = database.command("sql", "insert into ConversionTest set datetime_nanos = ?", localDateTime); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(localDateTime.truncatedTo(ChronoUnit.NANOS), result.next().toElement().get("datetime_nanos")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().toElement().get("datetime_nanos")).isEqualTo(localDateTime.truncatedTo(ChronoUnit.NANOS)); database.commit(); } finally { @@ -297,8 +297,8 @@ public void testCalendar() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertEquals(calendar, doc.get("datetime_millis")); - Assertions.assertEquals(calendar, doc.getCalendar("datetime_millis")); + assertThat(doc.get("datetime_millis")).isEqualTo(calendar); + assertThat(doc.getCalendar("datetime_millis")).isEqualTo(calendar); } finally { ((DatabaseInternal) database).getSerializer().setDateTimeImplementation(Date.class); @@ -320,8 +320,8 @@ public void testLocalDate() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertEquals(localDate, doc.get("date")); - Assertions.assertTrue(localDate.isEqual(doc.getLocalDate("date"))); + assertThat(doc.get("date")).isEqualTo(localDate); + assertThat(localDate.isEqual(doc.getLocalDate("date"))).isTrue(); } finally { ((DatabaseInternal) database).getSerializer().setDateImplementation(Date.class); @@ -344,8 +344,7 @@ public void testZonedDateTime() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertTrue( - zonedDateTime.truncatedTo(ChronoUnit.SECONDS).isEqual((ChronoZonedDateTime) doc.get("datetime_second"))); + assertThat(zonedDateTime.truncatedTo(ChronoUnit.SECONDS).isEqual((ChronoZonedDateTime) doc.get("datetime_second"))).isTrue(); database.transaction(() -> { // TEST MILLISECONDS PRECISION @@ -354,8 +353,7 @@ public void testZonedDateTime() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertTrue( - zonedDateTime.truncatedTo(ChronoUnit.MILLIS).isEqual((ChronoZonedDateTime) doc.get("datetime_millis"))); + assertThat(zonedDateTime.truncatedTo(ChronoUnit.MILLIS).isEqual((ChronoZonedDateTime) doc.get("datetime_millis"))).isTrue(); if (!System.getProperty("os.name").startsWith("Windows")) { // NOTE: ON WINDOWS MICROSECONDS ARE NOT HANDLED CORRECTLY @@ -367,8 +365,7 @@ public void testZonedDateTime() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertTrue( - zonedDateTime.truncatedTo(ChronoUnit.MICROS).isEqual((ChronoZonedDateTime) doc.get("datetime_micros"))); + assertThat(zonedDateTime.truncatedTo(ChronoUnit.MICROS).isEqual((ChronoZonedDateTime) doc.get("datetime_micros"))).isTrue(); } // TEST NANOSECOND PRECISION @@ -377,9 +374,8 @@ public void testZonedDateTime() throws ClassNotFoundException { doc.save(); }); doc.reload(); - Assertions.assertTrue( - zonedDateTime.truncatedTo(ChronoUnit.NANOS).isEqual((ChronoZonedDateTime) doc.get("datetime_nanos"))); - Assertions.assertTrue(zonedDateTime.isEqual(doc.getZonedDateTime("datetime_nanos"))); + assertThat(zonedDateTime.truncatedTo(ChronoUnit.NANOS).isEqual((ChronoZonedDateTime) doc.get("datetime_nanos"))).isTrue(); + assertThat(zonedDateTime.isEqual(doc.getZonedDateTime("datetime_nanos"))).isTrue(); } finally { ((DatabaseInternal) database).getSerializer().setDateTimeImplementation(Date.class); @@ -401,7 +397,7 @@ public void testInstant() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertEquals(instant.truncatedTo(ChronoUnit.SECONDS), doc.get("datetime_second")); + assertThat(doc.get("datetime_second")).isEqualTo(instant.truncatedTo(ChronoUnit.SECONDS)); database.transaction(() -> { // TEST MILLISECONDS PRECISION @@ -410,7 +406,7 @@ public void testInstant() throws ClassNotFoundException { }); doc.reload(); - Assertions.assertEquals(instant.truncatedTo(ChronoUnit.MILLIS), doc.get("datetime_millis")); + assertThat(doc.get("datetime_millis")).isEqualTo(instant.truncatedTo(ChronoUnit.MILLIS)); // TEST MICROSECONDS PRECISION database.transaction(() -> { @@ -421,7 +417,7 @@ public void testInstant() throws ClassNotFoundException { doc.reload(); if (!System.getProperty("os.name").startsWith("Windows")) // NOTE: ON WINDOWS MICROSECONDS ARE NOT HANDLED CORRECTLY - Assertions.assertEquals(instant.truncatedTo(ChronoUnit.MICROS), doc.get("datetime_micros")); + assertThat(doc.get("datetime_micros")).isEqualTo(instant.truncatedTo(ChronoUnit.MICROS)); // TEST NANOSECOND PRECISION database.transaction(() -> { @@ -429,8 +425,8 @@ public void testInstant() throws ClassNotFoundException { doc.save(); }); doc.reload(); - Assertions.assertEquals(instant.truncatedTo(ChronoUnit.NANOS), doc.get("datetime_nanos")); - Assertions.assertEquals(instant, doc.getInstant("datetime_nanos")); + assertThat(doc.get("datetime_nanos")).isEqualTo(instant.truncatedTo(ChronoUnit.NANOS)); + assertThat(doc.getInstant("datetime_nanos")).isEqualTo(instant); } finally { ((DatabaseInternal) database).getSerializer().setDateTimeImplementation(Date.class); @@ -439,25 +435,25 @@ public void testInstant() throws ClassNotFoundException { @Test public void testConversion() { - Assertions.assertEquals(10, DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.SECONDS)); - Assertions.assertEquals(10_000, DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.MILLIS)); - Assertions.assertEquals(10_000_000, DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.MICROS)); - Assertions.assertEquals(10_000_000_000L, DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.NANOS)); - - Assertions.assertEquals(10, DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.SECONDS)); - Assertions.assertEquals(10_000, DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.MILLIS)); - Assertions.assertEquals(10_000_000, DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.MICROS)); - Assertions.assertEquals(10_000_000_000L, DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.NANOS)); - - Assertions.assertEquals(10, DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.SECONDS)); - Assertions.assertEquals(10_000, DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.MILLIS)); - Assertions.assertEquals(10_000_000, DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.MICROS)); - Assertions.assertEquals(10_000_000_000L, DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.NANOS)); - - Assertions.assertEquals(10, DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.SECONDS)); - Assertions.assertEquals(10_000, DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.MILLIS)); - Assertions.assertEquals(10_000_000, DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.MICROS)); - Assertions.assertEquals(10_000_000_000L, DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.NANOS)); + assertThat(DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.SECONDS)).isEqualTo(10); + assertThat(DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.MILLIS)).isEqualTo(10_000); + assertThat(DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.MICROS)).isEqualTo(10_000_000); + assertThat(DateUtils.convertTimestamp(10_000_000_000L, ChronoUnit.NANOS, ChronoUnit.NANOS)).isEqualTo(10_000_000_000L); + + assertThat(DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.SECONDS)).isEqualTo(10); + assertThat(DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.MILLIS)).isEqualTo(10_000); + assertThat(DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.MICROS)).isEqualTo(10_000_000); + assertThat(DateUtils.convertTimestamp(10_000_000, ChronoUnit.MICROS, ChronoUnit.NANOS)).isEqualTo(10_000_000_000L); + + assertThat(DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.SECONDS)).isEqualTo(10); + assertThat(DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.MILLIS)).isEqualTo(10_000); + assertThat(DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.MICROS)).isEqualTo(10_000_000); + assertThat(DateUtils.convertTimestamp(10_000, ChronoUnit.MILLIS, ChronoUnit.NANOS)).isEqualTo(10_000_000_000L); + + assertThat(DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.SECONDS)).isEqualTo(10); + assertThat(DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.MILLIS)).isEqualTo(10_000); + assertThat(DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.MICROS)).isEqualTo(10_000_000); + assertThat(DateUtils.convertTimestamp(10, ChronoUnit.SECONDS, ChronoUnit.NANOS)).isEqualTo(10_000_000_000L); } @Test @@ -471,20 +467,20 @@ public void testSQLMath() { database.begin(); final LocalDateTime date1 = LocalDateTime.now(); ResultSet resultSet = database.command("sql", "insert into ConversionTest set datetime_micros = ?", date1); - Assertions.assertTrue(resultSet.hasNext()); - Assertions.assertEquals(date1.truncatedTo(ChronoUnit.MICROS), resultSet.next().toElement().get("datetime_micros")); + assertThat(resultSet.hasNext()).isTrue(); + assertThat(resultSet.next().toElement().get("datetime_micros")).isEqualTo(date1.truncatedTo(ChronoUnit.MICROS)); final LocalDateTime date2 = LocalDateTime.now().plusSeconds(1); resultSet = database.command("sql", "insert into ConversionTest set datetime_micros = ?", date2); - Assertions.assertTrue(resultSet.hasNext()); - Assertions.assertEquals(date2.truncatedTo(ChronoUnit.MICROS), resultSet.next().toElement().get("datetime_micros")); + assertThat(resultSet.hasNext()).isTrue(); + assertThat(resultSet.next().toElement().get("datetime_micros")).isEqualTo(date2.truncatedTo(ChronoUnit.MICROS)); resultSet = database.command("sql", "select from ConversionTest where datetime_micros between ? and ?", date1, date2); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); resultSet.next(); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); resultSet.next(); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); try { Thread.sleep(1001); @@ -494,68 +490,68 @@ public void testSQLMath() { resultSet = database.command("sql", "select sysdate() - datetime_micros as diff from ConversionTest"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); Result result = resultSet.next(); - Assertions.assertFalse(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isFalse(); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertFalse(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isFalse(); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); resultSet = database.command("sql", "select sysdate() - datetime_micros as diff from ConversionTest where sysdate() - datetime_micros < duration(100000000000, 'nanosecond')"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertFalse(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isFalse(); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertFalse(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isFalse(); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); resultSet = database.command("sql", "select datetime_micros - sysdate() as diff from ConversionTest where abs( datetime_micros - sysdate() ) < duration(100000000000, 'nanosecond')"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertTrue(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isTrue(); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertTrue(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isTrue(); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); resultSet = database.command("sql", "select datetime_micros - date(?, 'yyyy-MM-dd HH:mm:ss.SSS') as diff from ConversionTest where abs( datetime_micros - sysdate() ) < duration(100000000000, 'nanosecond')", DateUtils.getFormatter("yyyy-MM-dd HH:mm:ss.SSS").format(LocalDateTime.now())); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertTrue(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isTrue(); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertTrue(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isTrue(); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); resultSet = database.command("sql", "select datetime_micros - date(?, 'yyyy-MM-dd HH:mm:ss.SSS') as diff from ConversionTest where abs( datetime_micros - sysdate() ) < duration(3, \"second\")", DateUtils.getFormatter("yyyy-MM-dd HH:mm:ss.SSS").format(LocalDateTime.now())); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertTrue(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isTrue(); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertTrue(((Duration) result.getProperty("diff")).isNegative(), "Returned " + result.getProperty("diff")); + assertThat(((Duration) result.getProperty("diff")).isNegative()).as("Returned " + result.getProperty("diff")).isTrue(); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); database.commit(); } finally { diff --git a/engine/src/test/java/com/arcadedb/compression/CompressionTest.java b/engine/src/test/java/com/arcadedb/compression/CompressionTest.java index b45fb59dad..6b75838681 100644 --- a/engine/src/test/java/com/arcadedb/compression/CompressionTest.java +++ b/engine/src/test/java/com/arcadedb/compression/CompressionTest.java @@ -19,9 +19,10 @@ package com.arcadedb.compression; import com.arcadedb.database.Binary; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class CompressionTest { @Test public void testCompression() { @@ -30,7 +31,7 @@ public void testCompression() { final Binary compressed = CompressionFactory.getDefault().compress(buffer); final Binary decompressed = CompressionFactory.getDefault().decompress(compressed, buffer.size()); - Assertions.assertEquals(buffer, decompressed); + assertThat(decompressed).isEqualTo(buffer); } @Test @@ -40,6 +41,6 @@ public void testEmptyCompression() { final Binary compressed = CompressionFactory.getDefault().compress(buffer); final Binary decompressed = CompressionFactory.getDefault().decompress(compressed, buffer.size()); - Assertions.assertEquals(buffer, decompressed); + assertThat(decompressed).isEqualTo(buffer); } } diff --git a/engine/src/test/java/com/arcadedb/database/BucketSQLTest.java b/engine/src/test/java/com/arcadedb/database/BucketSQLTest.java index 6adb3af4df..f88b5f6c2b 100644 --- a/engine/src/test/java/com/arcadedb/database/BucketSQLTest.java +++ b/engine/src/test/java/com/arcadedb/database/BucketSQLTest.java @@ -1,21 +1,3 @@ -/* - * Copyright © 2021-present Arcade Data Ltd (info@arcadedata.com) - * - * 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 - * - * 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. - * - * SPDX-FileCopyrightText: 2021-present Arcade Data Ltd (info@arcadedata.com) - * SPDX-License-Identifier: Apache-2.0 - */ package com.arcadedb.database; import com.arcadedb.GlobalConfiguration; @@ -23,11 +5,12 @@ import com.arcadedb.engine.Bucket; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.schema.DocumentType; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class BucketSQLTest extends TestHelper { @Test public void testPopulate() { @@ -50,31 +33,31 @@ protected void beginTest() { final DocumentType customer = database.getSchema().getType("Customer"); final List buckets = customer.getBuckets(true); - Assertions.assertEquals(4, buckets.size()); + assertThat(buckets.size()).isEqualTo(4); ResultSet resultset = database.command("sql", "INSERT INTO BUCKET:Customer_Europe CONTENT { firstName: 'Enzo', lastName: 'Ferrari' }"); - Assertions.assertTrue(resultset.hasNext()); + assertThat(resultset.hasNext()).isTrue(); final Document enzo = resultset.next().getRecord().get().asDocument(); - Assertions.assertFalse(resultset.hasNext()); - Assertions.assertEquals(database.getSchema().getBucketByName("Customer_Europe").getFileId(), enzo.getIdentity().bucketId); + assertThat(resultset.hasNext()).isFalse(); + assertThat(enzo.getIdentity().bucketId).isEqualTo(database.getSchema().getBucketByName("Customer_Europe").getFileId()); resultset = database.command("sql", "INSERT INTO BUCKET:Customer_Americas CONTENT { firstName: 'Jack', lastName: 'Tramiel' }"); - Assertions.assertTrue(resultset.hasNext()); + assertThat(resultset.hasNext()).isTrue(); final Document jack = resultset.next().getRecord().get().asDocument(); - Assertions.assertFalse(resultset.hasNext()); - Assertions.assertEquals(database.getSchema().getBucketByName("Customer_Americas").getFileId(), jack.getIdentity().bucketId); + assertThat(resultset.hasNext()).isFalse(); + assertThat(jack.getIdentity().bucketId).isEqualTo(database.getSchema().getBucketByName("Customer_Americas").getFileId()); resultset = database.command("sql", "INSERT INTO BUCKET:Customer_Asia CONTENT { firstName: 'Bruce', lastName: 'Lee' }"); - Assertions.assertTrue(resultset.hasNext()); + assertThat(resultset.hasNext()).isTrue(); final Document bruce = resultset.next().getRecord().get().asDocument(); - Assertions.assertFalse(resultset.hasNext()); - Assertions.assertEquals(database.getSchema().getBucketByName("Customer_Asia").getFileId(), bruce.getIdentity().bucketId); + assertThat(resultset.hasNext()).isFalse(); + assertThat(bruce.getIdentity().bucketId).isEqualTo(database.getSchema().getBucketByName("Customer_Asia").getFileId()); resultset = database.command("sql", "INSERT INTO BUCKET:Customer_Other CONTENT { firstName: 'Penguin', lastName: 'Hungry' }"); - Assertions.assertTrue(resultset.hasNext()); + assertThat(resultset.hasNext()).isTrue(); final Document penguin = resultset.next().getRecord().get().asDocument(); - Assertions.assertFalse(resultset.hasNext()); - Assertions.assertEquals(database.getSchema().getBucketByName("Customer_Other").getFileId(), penguin.getIdentity().bucketId); + assertThat(resultset.hasNext()).isFalse(); + assertThat(penguin.getIdentity().bucketId).isEqualTo(database.getSchema().getBucketByName("Customer_Other").getFileId()); }); } } diff --git a/engine/src/test/java/com/arcadedb/database/CheckDatabaseTest.java b/engine/src/test/java/com/arcadedb/database/CheckDatabaseTest.java index b5c2a444b2..55e9b61d62 100644 --- a/engine/src/test/java/com/arcadedb/database/CheckDatabaseTest.java +++ b/engine/src/test/java/com/arcadedb/database/CheckDatabaseTest.java @@ -31,13 +31,16 @@ import com.arcadedb.index.TypeIndex; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + public class CheckDatabaseTest extends TestHelper { private static final int TOTAL = 10_000; @@ -46,40 +49,40 @@ public class CheckDatabaseTest extends TestHelper { @Test public void checkDatabase() { final ResultSet result = database.command("sql", "check database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat(row.getProperty("totalActiveVertices")).isEqualTo(TOTAL); + assertThat(row.getProperty("totalActiveEdges")).isEqualTo(TOTAL - 1); + assertThat(row.getProperty("autoFix")).isEqualTo(0L); } } @Test public void checkTypes() { ResultSet result = database.command("sql", "check database type Person"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveRecords")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("totalActiveRecords")).isEqualTo(TOTAL); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0); } result = database.command("sql", "check database type Person, Knows"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(TOTAL * 2 - 1, (Long) row.getProperty("totalActiveRecords")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("totalActiveRecords")).isEqualTo(TOTAL * 2 - 1); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0); } } @@ -88,20 +91,20 @@ public void checkRegularDeleteEdges() { database.transaction(() -> database.command("sql", "delete from Knows")); final ResultSet result = database.command("sql", "check database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(0L, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(0L, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(0, ((Collection) row.getProperty("corruptedRecords")).size()); - Assertions.assertEquals(0L, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals(0L, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(0, ((Collection) row.getProperty("warnings")).size()); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0L); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(0L); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(TOTAL - 1); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(0); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0L); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo(0L); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo(0); } } @@ -111,76 +114,76 @@ public void checkBrokenDeletedEdges() { database.transaction(() -> { final Iterator iter = database.iterateType("Knows", false); - Assertions.assertTrue(iter.hasNext()); + assertThat(iter.hasNext()).isTrue(); final Record edge = iter.next(); deletedEdge.set(edge.getIdentity()); - Assertions.assertEquals(root.getIdentity(), edge.asEdge().getOut()); + assertThat(edge.asEdge().getOut()).isEqualTo(root.getIdentity()); // DELETE THE EDGE AT LOW LEVEL database.getSchema().getBucketById(edge.getIdentity().getBucketId()).deleteRecord(edge.getIdentity()); }); ResultSet result = database.command("sql", "check database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(TOTAL - 2, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(1, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(1, ((Collection) row.getProperty("corruptedRecords")).size()); - Assertions.assertEquals(0, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals(2, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(1, ((Collection) row.getProperty("warnings")).size()); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(TOTAL - 2); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(1); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(1); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo(2); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo(1); } - Assertions.assertEquals(TOTAL - 2, countEdges(root.getIdentity())); - Assertions.assertEquals(TOTAL - 1, countEdgesSegmentList(root.getIdentity())); + assertThat(countEdges(root.getIdentity())).isEqualTo(TOTAL - 2); + assertThat(countEdgesSegmentList(root.getIdentity())).isEqualTo(TOTAL - 1); result = database.command("sql", "check database fix"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(1, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(TOTAL - 2, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(1, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(1, ((Collection) row.getProperty("corruptedRecords")).size()); - Assertions.assertEquals(0, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals(2, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(1, ((Collection) row.getProperty("warnings")).size()); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(1); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(TOTAL - 2); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(1); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(1); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo(2); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo(1); } - Assertions.assertEquals(TOTAL - 2, countEdges(root.getIdentity())); - Assertions.assertEquals(TOTAL - 2, countEdgesSegmentList(root.getIdentity())); + assertThat(countEdges(root.getIdentity())).isEqualTo(TOTAL - 2); + assertThat(countEdgesSegmentList(root.getIdentity())).isEqualTo(TOTAL - 2); result = database.command("sql", "check database fix"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(TOTAL - 2, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(1, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(0, ((Collection) row.getProperty("corruptedRecords")).size()); - Assertions.assertEquals(0, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals(0, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(0, ((Collection) row.getProperty("warnings")).size()); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(TOTAL - 2); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(1); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(0); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo(0); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo(0); } - Assertions.assertEquals(TOTAL - 2, countEdges(root.getIdentity())); - Assertions.assertEquals(TOTAL - 2, countEdgesSegmentList(root.getIdentity())); + assertThat(countEdges(root.getIdentity())).isEqualTo(TOTAL - 2); + assertThat(countEdgesSegmentList(root.getIdentity())).isEqualTo(TOTAL - 2); } @Test @@ -191,52 +194,52 @@ public void checkBrokenDeletedVertex() { }); ResultSet result = database.command("sql", "check database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(1, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(TOTAL, ((Collection) row.getProperty("corruptedRecords")).size()); // ALL THE EDGES + ROOT VERTEX - Assertions.assertEquals(0, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals((TOTAL - 1) * 2, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(TOTAL - 1, ((Collection) row.getProperty("warnings")).size()); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(1); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(TOTAL); // ALL THE EDGES + ROOT VERTEX + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo((TOTAL - 1) * 2); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo(TOTAL - 1); } result = database.command("sql", "check database fix"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals((TOTAL - 1) * 2, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(0, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(TOTAL - 1, ((Collection) row.getProperty("corruptedRecords")).size()); - Assertions.assertEquals(0, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals((TOTAL - 1) * 2, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals((TOTAL - 1) * 2, ((Collection) row.getProperty("warnings")).size()); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo((TOTAL - 1) * 2); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(0); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(TOTAL); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo((TOTAL - 1) * 2); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo((TOTAL - 1) * 2); result = database.command("sql", "check database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertEquals(0, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalActiveVertices")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(0, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(TOTAL, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(0, ((Collection) row.getProperty("corruptedRecords")).size()); - Assertions.assertEquals(0, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals(0, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(0, ((Collection) row.getProperty("warnings")).size()); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0); + assertThat((Long) row.getProperty("totalActiveVertices")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(0); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(TOTAL); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(0); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo(0); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo(0); } @Test @@ -256,48 +259,48 @@ public void checkBrokenPage() { }); ResultSet result = database.command("sql", "check database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result row = result.next(); - Assertions.assertEquals("check database", row.getProperty("operation")); - Assertions.assertTrue((Long) row.getProperty("totalErrors") > 0L); - Assertions.assertEquals(0L, (Long) row.getProperty("autoFix")); - Assertions.assertTrue((Long) row.getProperty("totalActiveVertices") < TOTAL); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalAllocatedEdges")); - Assertions.assertEquals(TOTAL - 1, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(0L, (Long) row.getProperty("totalDeletedRecords")); - Assertions.assertEquals(0L, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertTrue((Long) row.getProperty("invalidLinks") > 0L); - Assertions.assertTrue(((Collection) row.getProperty("warnings")).size() > 0L); - Assertions.assertEquals(1, ((Collection) row.getProperty("rebuiltIndexes")).size()); - Assertions.assertTrue(((Collection) row.getProperty("corruptedRecords")).size() > 0L); + assertThat(row.getProperty("operation")).isEqualTo("check database"); + assertThat((Long) row.getProperty("totalErrors") > 0L).isTrue(); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0L); + assertThat((Long) row.getProperty("totalActiveVertices") < TOTAL).isTrue(); + assertThat((Long) row.getProperty("totalAllocatedEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(TOTAL - 1); + assertThat((Long) row.getProperty("totalDeletedRecords")).isEqualTo(0L); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0L); + assertThat((Long) row.getProperty("invalidLinks") > 0L).isTrue(); + assertThat(((Collection) row.getProperty("warnings")).size() > 0L).isTrue(); + assertThat(((Collection) row.getProperty("rebuiltIndexes")).size()).isEqualTo(1); + assertThat(((Collection) row.getProperty("corruptedRecords")).size() > 0L).isTrue(); result = database.command("sql", "check database fix"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); row = result.next(); - Assertions.assertTrue((Long) row.getProperty("autoFix") > 0L); - Assertions.assertEquals(0L, (Long) row.getProperty("totalActiveEdges")); - Assertions.assertEquals(1, ((Collection) row.getProperty("rebuiltIndexes")).size()); - Assertions.assertTrue((Long) row.getProperty("totalActiveVertices") < TOTAL); - Assertions.assertTrue(((Collection) row.getProperty("corruptedRecords")).size() > 0L); + assertThat((Long) row.getProperty("autoFix") > 0L).isTrue(); + assertThat((Long) row.getProperty("totalActiveEdges")).isEqualTo(0L); + assertThat(((Collection) row.getProperty("rebuiltIndexes")).size()).isEqualTo(1); + assertThat((Long) row.getProperty("totalActiveVertices") < TOTAL).isTrue(); + assertThat(((Collection) row.getProperty("corruptedRecords")).size() > 0L).isTrue(); result = database.command("sql", "check database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); row = result.next(); - Assertions.assertEquals(0L, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(0L, (Long) row.getProperty("totalErrors")); - Assertions.assertEquals(0L, (Long) row.getProperty("autoFix")); - Assertions.assertEquals(0L, (Long) row.getProperty("missingReferenceBack")); - Assertions.assertEquals(0L, (Long) row.getProperty("invalidLinks")); - Assertions.assertEquals(0L, ((Collection) row.getProperty("warnings")).size()); - Assertions.assertEquals(0, ((Collection) row.getProperty("rebuiltIndexes")).size()); - Assertions.assertEquals(0L, ((Collection) row.getProperty("corruptedRecords")).size()); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0L); + assertThat((Long) row.getProperty("totalErrors")).isEqualTo(0L); + assertThat((Long) row.getProperty("autoFix")).isEqualTo(0L); + assertThat((Long) row.getProperty("missingReferenceBack")).isEqualTo(0L); + assertThat((Long) row.getProperty("invalidLinks")).isEqualTo(0L); + assertThat(((Collection) row.getProperty("warnings")).size()).isEqualTo(0L); + assertThat(((Collection) row.getProperty("rebuiltIndexes")).size()).isEqualTo(0); + assertThat(((Collection) row.getProperty("corruptedRecords")).size()).isEqualTo(0L); // CHECK CORRUPTED RECORD ARE NOT INDEXED ANYMORE final List indexes = database.getSchema().getType("Person").getIndexesByProperties("id"); - Assertions.assertEquals(1, indexes.size()); + assertThat(indexes.size()).isEqualTo(1); - Assertions.assertEquals((Long) row.getProperty("totalActiveVertices"), indexes.get(0).countEntries()); + assertThat(indexes.get(0).countEntries()).isEqualTo((Long) row.getProperty("totalActiveVertices")); } @Override diff --git a/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java b/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java index f29fcce5d8..82e648e4b9 100644 --- a/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java +++ b/engine/src/test/java/com/arcadedb/database/DataEncryptionTest.java @@ -18,8 +18,7 @@ */ package com.arcadedb.database; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; import java.util.concurrent.atomic.AtomicReference; @@ -84,13 +83,13 @@ private void verify(RID rid1, RID rid2, boolean isEquals) { private void verify(Vertex p1, Vertex p2, boolean isEquals) { if (isEquals) { - assertEquals("John", p1.get("name")); - assertEquals("Doe", p2.get("name")); - assertEquals(2024, p1.getEdges(DIRECTION.OUT, "Knows").iterator().next().get("since")); + assertThat(p1.get("name")).isEqualTo("John"); + assertThat(p2.get("name")).isEqualTo("Doe"); + assertThat(p1.getEdges(DIRECTION.OUT, "Knows").iterator().next().get("since")).isEqualTo(2024); } else { - assertFalse(((String) p1.get("name")).contains("John")); - assertFalse(((String) p2.get("name")).contains("Doe")); - assertFalse(p1.getEdges(DIRECTION.OUT, "Knows").iterator().next().get("since").toString().contains("2024")); + assertThat(((String) p1.get("name")).contains("John")).isFalse(); + assertThat(((String) p2.get("name")).contains("Doe")).isFalse(); + assertThat(p1.getEdges(DIRECTION.OUT, "Knows").iterator().next().get("since").toString().contains("2024")).isFalse(); } } } diff --git a/engine/src/test/java/com/arcadedb/database/DatabaseFactoryTest.java b/engine/src/test/java/com/arcadedb/database/DatabaseFactoryTest.java index 2095afd998..a8424b3e7f 100644 --- a/engine/src/test/java/com/arcadedb/database/DatabaseFactoryTest.java +++ b/engine/src/test/java/com/arcadedb/database/DatabaseFactoryTest.java @@ -21,9 +21,12 @@ import com.arcadedb.TestHelper; import com.arcadedb.exception.DatabaseOperationException; import com.arcadedb.security.SecurityManager; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; + /** * @author Luca Garulli (l.garulli@arcadedata.com) **/ @@ -33,14 +36,14 @@ class DatabaseFactoryTest extends TestHelper { void invalidFactories() { try { new DatabaseFactory(null); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } try { new DatabaseFactory(""); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -50,7 +53,7 @@ void invalidFactories() { void testGetterSetter() { final DatabaseFactory f = new DatabaseFactory("test/"); f.setAutoTransaction(true); - Assertions.assertNotNull(f.getContextConfiguration()); + assertThat(f.getContextConfiguration()).isNotNull(); final SecurityManager security = new SecurityManager() { @Override @@ -58,7 +61,7 @@ public void updateSchema(final DatabaseInternal database) { } }; f.setSecurity(security); - Assertions.assertEquals(security, f.getSecurity()); + assertThat(f.getSecurity()).isEqualTo(security); } @Test @@ -68,7 +71,7 @@ void testDatabaseRegistration() { DatabaseFactory.getActiveDatabaseInstances().contains(db); DatabaseFactory.removeActiveDatabaseInstance(db.getDatabasePath()); - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(db.getDatabasePath())); + assertThat(DatabaseFactory.getActiveDatabaseInstance(db.getDatabasePath())).isNull(); db.drop(); f.close(); @@ -79,10 +82,10 @@ void testDatabaseRegistrationWithDifferentPathTypes() { final DatabaseFactory f = new DatabaseFactory("target/path/to/database"); final Database db = f.exists() ? f.open() : f.create(); - Assertions.assertEquals(db, DatabaseFactory.getActiveDatabaseInstance("target/path/to/database")); + assertThat(DatabaseFactory.getActiveDatabaseInstance("target/path/to/database")).isEqualTo(db); if (System.getProperty("os.name").toLowerCase().contains("windows")) - Assertions.assertEquals(db, DatabaseFactory.getActiveDatabaseInstance("target\\path\\to\\database")); - Assertions.assertEquals(db, DatabaseFactory.getActiveDatabaseInstance("./target/path/../../target/path/to/database")); + assertThat(DatabaseFactory.getActiveDatabaseInstance("target\\path\\to\\database")).isEqualTo(db); + assertThat(DatabaseFactory.getActiveDatabaseInstance("./target/path/../../target/path/to/database")).isEqualTo(db); db.drop(); f.close(); @@ -97,7 +100,7 @@ void testDuplicatedDatabaseCreationWithDifferentPathTypes() { final Database db = f1.create(); final DatabaseFactory f2 = new DatabaseFactory(".\\path\\to\\database"); - Assertions.assertThrows(DatabaseOperationException.class, () -> f2.create()); + assertThatExceptionOfType(DatabaseOperationException.class).isThrownBy(() -> f2.create()); db.drop(); f1.close(); diff --git a/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java b/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java index 83c77c3dca..477e624891 100644 --- a/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java +++ b/engine/src/test/java/com/arcadedb/database/DefaultDataEncryptionTest.java @@ -18,7 +18,7 @@ */ package com.arcadedb.database; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.nio.ByteBuffer; import java.security.NoSuchAlgorithmException; @@ -50,7 +50,7 @@ void testEncryptionOfString() throws NoSuchAlgorithmException, NoSuchPaddingExce String data = "data"; byte[] encryptedData = dde.encrypt(data.getBytes()); String decryptedData = new String(dde.decrypt(encryptedData)); - assertEquals(data, decryptedData); + assertThat(decryptedData).isEqualTo(data); } @Test @@ -59,6 +59,6 @@ void testEncryptionOfDouble() throws NoSuchAlgorithmException, NoSuchPaddingExce double data = 1000000d; byte[] encryptedData = dde.encrypt(ByteBuffer.allocate(8).putLong(Double.doubleToLongBits(data)).array()); var decryptedData = Double.longBitsToDouble(ByteBuffer.wrap(dde.decrypt(encryptedData)).getLong()); - assertEquals(data, decryptedData); + assertThat(decryptedData).isEqualTo(data); } } diff --git a/engine/src/test/java/com/arcadedb/database/RecordFactoryTest.java b/engine/src/test/java/com/arcadedb/database/RecordFactoryTest.java index fa689c1f1b..6fedc24ce0 100644 --- a/engine/src/test/java/com/arcadedb/database/RecordFactoryTest.java +++ b/engine/src/test/java/com/arcadedb/database/RecordFactoryTest.java @@ -30,9 +30,11 @@ import com.arcadedb.schema.EdgeType; import com.arcadedb.schema.VertexType; import com.arcadedb.serializer.BinaryTypes; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luca Garulli (l.garulli@arcadedata.com) **/ @@ -44,27 +46,27 @@ void newImmutableRecord() { final DocumentType documentType = database.getSchema().createDocumentType("Document"); final Record document = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, documentType, EMPTY_RID, Document.RECORD_TYPE); - Assertions.assertTrue(document instanceof Document); + assertThat(document instanceof Document).isTrue(); final VertexType vertexType = database.getSchema().createVertexType("Vertex"); final Record vertex = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, vertexType, EMPTY_RID, Vertex.RECORD_TYPE); - Assertions.assertTrue(vertex instanceof Vertex); + assertThat(vertex instanceof Vertex).isTrue(); final EdgeType edgeType = database.getSchema().createEdgeType("Edge"); final Record edge = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, edgeType, EMPTY_RID, Edge.RECORD_TYPE); - Assertions.assertTrue(edge instanceof Edge); + assertThat(edge instanceof Edge).isTrue(); final Record edgeSegment = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, null, EMPTY_RID, EdgeSegment.RECORD_TYPE); - Assertions.assertTrue(edgeSegment instanceof EdgeSegment); + assertThat(edgeSegment instanceof EdgeSegment).isTrue(); final DocumentType embeddedDocumentType = database.getSchema().createDocumentType("EmbeddedDocument"); final Record embeddedDocument = ((DatabaseInternal) database).getRecordFactory() .newImmutableRecord(database, embeddedDocumentType, EMPTY_RID, EmbeddedDocument.RECORD_TYPE); - Assertions.assertTrue(embeddedDocument instanceof EmbeddedDocument); + assertThat(embeddedDocument instanceof EmbeddedDocument).isTrue(); try { ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, embeddedDocumentType, EMPTY_RID, (byte) 'Z'); - Assertions.fail(); + fail(""); } catch (final DatabaseMetadataException e) { // EXPECTED } @@ -80,7 +82,7 @@ void testNewImmutableRecord() { final DocumentType documentType = database.getSchema().createDocumentType("Document"); final Record document = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, documentType, EMPTY_RID, binary, null); - Assertions.assertTrue(document instanceof Document); + assertThat(document instanceof Document).isTrue(); binary.clear(); binary.putByte(Vertex.RECORD_TYPE); @@ -92,7 +94,7 @@ void testNewImmutableRecord() { final VertexType vertexType = database.getSchema().createVertexType("Vertex"); final Record vertex = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, vertexType, EMPTY_RID, binary, null); - Assertions.assertTrue(vertex instanceof Vertex); + assertThat(vertex instanceof Vertex).isTrue(); binary.clear(); binary.putByte(Edge.RECORD_TYPE); @@ -102,14 +104,14 @@ void testNewImmutableRecord() { final EdgeType edgeType = database.getSchema().createEdgeType("Edge"); final Record edge = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, edgeType, EMPTY_RID, binary, null); - Assertions.assertTrue(edge instanceof Edge); + assertThat(edge instanceof Edge).isTrue(); binary.clear(); binary.putByte(EdgeSegment.RECORD_TYPE); binary.flip(); final Record edgeSegment = ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, null, EMPTY_RID, binary, null); - Assertions.assertTrue(edgeSegment instanceof EdgeSegment); + assertThat(edgeSegment instanceof EdgeSegment).isTrue(); binary.clear(); binary.putByte(EmbeddedDocument.RECORD_TYPE); @@ -118,7 +120,7 @@ void testNewImmutableRecord() { final DocumentType embeddedDocumentType = database.getSchema().createDocumentType("EmbeddedDocument"); final Record embeddedDocument = ((DatabaseInternal) database).getRecordFactory() .newImmutableRecord(database, embeddedDocumentType, EMPTY_RID, binary, null); - Assertions.assertTrue(embeddedDocument instanceof EmbeddedDocument); + assertThat(embeddedDocument instanceof EmbeddedDocument).isTrue(); binary.clear(); binary.putByte((byte) 'Z'); @@ -126,7 +128,7 @@ void testNewImmutableRecord() { try { ((DatabaseInternal) database).getRecordFactory().newImmutableRecord(database, embeddedDocumentType, EMPTY_RID, binary, null); - Assertions.fail(); + fail(""); } catch (final DatabaseMetadataException e) { // EXPECTED } @@ -142,7 +144,7 @@ void newMutableRecord() { final DocumentType documentType = database.getSchema().createDocumentType("Document"); final Record document = ((DatabaseInternal) database).getRecordFactory().newMutableRecord(database, documentType, EMPTY_RID, binary, null); - Assertions.assertTrue(document instanceof MutableDocument); + assertThat(document instanceof MutableDocument).isTrue(); binary.clear(); binary.putByte(Vertex.RECORD_TYPE); @@ -154,7 +156,7 @@ void newMutableRecord() { final VertexType vertexType = database.getSchema().createVertexType("Vertex"); final Record vertex = ((DatabaseInternal) database).getRecordFactory().newMutableRecord(database, vertexType, EMPTY_RID, binary, null); - Assertions.assertTrue(vertex instanceof MutableVertex); + assertThat(vertex instanceof MutableVertex).isTrue(); binary.clear(); binary.putByte(Edge.RECORD_TYPE); @@ -164,14 +166,14 @@ void newMutableRecord() { final EdgeType edgeType = database.getSchema().createEdgeType("Edge"); final Record edge = ((DatabaseInternal) database).getRecordFactory().newMutableRecord(database, edgeType, EMPTY_RID, binary, null); - Assertions.assertTrue(edge instanceof MutableEdge); + assertThat(edge instanceof MutableEdge).isTrue(); binary.clear(); binary.putByte(EdgeSegment.RECORD_TYPE); binary.flip(); final Record edgeSegment = ((DatabaseInternal) database).getRecordFactory().newMutableRecord(database, null, EMPTY_RID, binary, null); - Assertions.assertTrue(edgeSegment instanceof MutableEdgeSegment); + assertThat(edgeSegment instanceof MutableEdgeSegment).isTrue(); binary.clear(); binary.putByte(EmbeddedDocument.RECORD_TYPE); @@ -179,7 +181,7 @@ void newMutableRecord() { final DocumentType embeddedDocumentType = database.getSchema().createDocumentType("EmbeddedDocument"); final Record embeddedDocument = ((DatabaseInternal) database).getRecordFactory().newMutableRecord(database, embeddedDocumentType, EMPTY_RID, binary, null); - Assertions.assertTrue(embeddedDocument instanceof MutableEmbeddedDocument); + assertThat(embeddedDocument instanceof MutableEmbeddedDocument).isTrue(); binary.clear(); binary.putByte((byte) 'Z'); @@ -187,7 +189,7 @@ void newMutableRecord() { try { ((DatabaseInternal) database).getRecordFactory().newMutableRecord(database, embeddedDocumentType, EMPTY_RID, binary, null); - Assertions.fail(); + fail(""); } catch (final DatabaseMetadataException e) { // EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/engine/BloomFilterTest.java b/engine/src/test/java/com/arcadedb/engine/BloomFilterTest.java index 4ee12ad845..e98fba7b4c 100644 --- a/engine/src/test/java/com/arcadedb/engine/BloomFilterTest.java +++ b/engine/src/test/java/com/arcadedb/engine/BloomFilterTest.java @@ -19,9 +19,10 @@ package com.arcadedb.engine; import com.arcadedb.database.Binary; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class BloomFilterTest { @Test public void testBloomFilter() { @@ -36,12 +37,12 @@ private void testValidity(final BufferBloomFilter bf, final int count) { if (bf.mightContain(i)) ++might; - Assertions.assertTrue(might < count); + assertThat(might < count).isTrue(); for (int i = 0; i < count; i++) bf.add(i); for (int i = 0; i < count; i++) - Assertions.assertTrue(bf.mightContain(i)); + assertThat(bf.mightContain(i)).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java b/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java index 034521a74f..665f79e700 100644 --- a/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java +++ b/engine/src/test/java/com/arcadedb/engine/DeleteAllTest.java @@ -5,12 +5,14 @@ import com.arcadedb.graph.MutableVertex; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class DeleteAllTest { private final static int TOT_RECORDS = 100_000; private final static String VERTEX_TYPE = "Product"; @@ -48,13 +50,13 @@ public void testCreateAndDeleteGraph() { }); db.transaction(() -> { - Assertions.assertEquals(TOT_RECORDS, db.countType(VERTEX_TYPE, true)); - Assertions.assertEquals(TOT_RECORDS - 1, db.countType(EDGE_TYPE, true)); + assertThat(db.countType(VERTEX_TYPE, true)).isEqualTo(TOT_RECORDS); + assertThat(db.countType(EDGE_TYPE, true)).isEqualTo(TOT_RECORDS - 1); db.command("sql", "delete from " + VERTEX_TYPE); - Assertions.assertEquals(0, db.countType(VERTEX_TYPE, true)); - Assertions.assertEquals(0, db.countType(EDGE_TYPE, true)); + assertThat(db.countType(VERTEX_TYPE, true)).isEqualTo(0); + assertThat(db.countType(EDGE_TYPE, true)).isEqualTo(0); }); } diff --git a/engine/src/test/java/com/arcadedb/engine/TestInsertAndSelectWithThreadBucketSelectionStrategy.java b/engine/src/test/java/com/arcadedb/engine/TestInsertAndSelectWithThreadBucketSelectionStrategy.java index 9a442a590e..c9e530c790 100644 --- a/engine/src/test/java/com/arcadedb/engine/TestInsertAndSelectWithThreadBucketSelectionStrategy.java +++ b/engine/src/test/java/com/arcadedb/engine/TestInsertAndSelectWithThreadBucketSelectionStrategy.java @@ -8,12 +8,13 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.time.*; import java.time.format.*; +import static org.assertj.core.api.Assertions.assertThat; + public class TestInsertAndSelectWithThreadBucketSelectionStrategy { @Test public void testInsertAndSelectWithThreadBucketSelectionStrategy() { @@ -54,12 +55,12 @@ public void testInsertAndSelectWithThreadBucketSelectionStrategy() { database.begin(); String sqlString = "UPDATE Product SET name = ?, type = ?, start = ?, stop = ?, v = ? UPSERT WHERE name = ?"; try (ResultSet resultSet = database.command("sql", sqlString, name1, type, validityStart, validityStop, version1, name1)) { - Assertions.assertTrue((long) resultSet.nextIfAvailable().getProperty("count", 0) == 1); + assertThat((long) resultSet.nextIfAvailable().getProperty("count", 0)).isEqualTo(1); } // database.commit(); // database.begin(); try (ResultSet resultSet = database.command("sql", sqlString, name2, type, validityStart, validityStop, version2, name2)) { - Assertions.assertTrue((long) resultSet.nextIfAvailable().getProperty("count", 0) == 1); + assertThat((long) resultSet.nextIfAvailable().getProperty("count", 0)).isEqualTo(1); } database.commit(); } catch (Exception e) { @@ -73,10 +74,10 @@ public void testInsertAndSelectWithThreadBucketSelectionStrategy() { String sqlString = "SELECT name, start, stop FROM Product WHERE type = ? AND start <= ? AND stop >= ? ORDER BY start DESC, stop DESC, v DESC LIMIT 1"; int total = 0; try (ResultSet resultSet = database.query("sql", sqlString, type, queryStart, queryStop)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); ++total; } - Assertions.assertEquals(1, total); + assertThat(total).isEqualTo(1); } finally { database.drop(); } diff --git a/engine/src/test/java/com/arcadedb/event/DatabaseEventsTest.java b/engine/src/test/java/com/arcadedb/event/DatabaseEventsTest.java index c6025af904..c9dae6355a 100644 --- a/engine/src/test/java/com/arcadedb/event/DatabaseEventsTest.java +++ b/engine/src/test/java/com/arcadedb/event/DatabaseEventsTest.java @@ -22,11 +22,14 @@ import com.arcadedb.graph.MutableVertex; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * TODO: ADD TESTS FOR DOCUMENTS AND EDGES * @@ -53,16 +56,16 @@ public void testBeforeCreate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(1); + assertThat(database.countType("Vertex", true)).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2"); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); v2.save(); - Assertions.assertEquals(2, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(2); + assertThat(database.countType("Vertex", true)).isEqualTo(1); }); } finally { @@ -80,16 +83,16 @@ public void testAfterCreate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(1); + assertThat(database.countType("Vertex", true)).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2"); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); v2.save(); - Assertions.assertEquals(2, counter.get()); - Assertions.assertEquals(2, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(2); + assertThat(database.countType("Vertex", true)).isEqualTo(2); }); } finally { @@ -110,16 +113,16 @@ public void testBeforeRead() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.set("modified2", true); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } finally { @@ -140,28 +143,28 @@ public void testBeforeUpdate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.set("modified2", true); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); v1.save(); - Assertions.assertEquals(2, counter.get()); + assertThat(counter.get()).isEqualTo(2); }); - Assertions.assertFalse(database.iterateType("Vertex", true).next().asVertex().has("modified2")); + assertThat(database.iterateType("Vertex", true).next().asVertex().has("modified2")).isFalse(); } finally { database.getEvents().unregisterListener(listener); @@ -181,16 +184,16 @@ public void testAfterRead() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.set("modified2", true); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } finally { @@ -208,16 +211,16 @@ public void testAfterUpdate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } finally { @@ -238,29 +241,29 @@ public void testBeforeDelete() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.delete(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2").save(); v2.delete(); - Assertions.assertEquals(2, counter.get()); + assertThat(counter.get()).isEqualTo(2); }); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(database.countType("Vertex", true)).isEqualTo(1); } finally { database.getEvents().unregisterListener(listener); @@ -277,29 +280,29 @@ public void testAfterDelete() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.delete(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2").save(); v2.delete(); - Assertions.assertEquals(2, counter.get()); + assertThat(counter.get()).isEqualTo(2); }); - Assertions.assertEquals(0, database.countType("Vertex", true)); + assertThat(database.countType("Vertex", true)).isEqualTo(0); } finally { database.getEvents().unregisterListener(listener); @@ -321,21 +324,21 @@ public void testBeforeCreateEmulateIncrement() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("IndexedVertex").set("id", "test"); - Assertions.assertFalse(v1.has("counter")); + assertThat(v1.has("counter")).isFalse(); v1.save(); - Assertions.assertEquals(1, v1.get("counter")); - Assertions.assertEquals(1, database.countType("IndexedVertex", true)); + assertThat(v1.get("counter")).isEqualTo(1); + assertThat(database.countType("IndexedVertex", true)).isEqualTo(1); // SHOULD OVERWRITE THIS database.newVertex("IndexedVertex").set("id", "test2").set("counter", 1).save(); final MutableVertex v2 = database.newVertex("IndexedVertex").set("id", "test3"); - Assertions.assertFalse(v2.has("counter")); + assertThat(v2.has("counter")).isFalse(); v2.save(); - Assertions.assertEquals(3, v2.get("counter")); - Assertions.assertEquals(3, database.countType("IndexedVertex", true)); + assertThat(v2.get("counter")).isEqualTo(3); + assertThat(database.countType("IndexedVertex", true)).isEqualTo(3); - Assertions.assertEquals("test2", database.query("SQL", "select from `IndexedVertex` where counter= 2").nextIfAvailable().getProperty("id")); + assertThat(database.query("SQL", "select from `IndexedVertex` where counter= 2").nextIfAvailable().getProperty("id")).isEqualTo("test2"); }); } finally { diff --git a/engine/src/test/java/com/arcadedb/event/RecordEncryptionTest.java b/engine/src/test/java/com/arcadedb/event/RecordEncryptionTest.java index 32a4b91b45..378a682572 100644 --- a/engine/src/test/java/com/arcadedb/event/RecordEncryptionTest.java +++ b/engine/src/test/java/com/arcadedb/event/RecordEncryptionTest.java @@ -24,7 +24,8 @@ import com.arcadedb.graph.MutableVertex; import com.arcadedb.graph.Vertex; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import javax.crypto.BadPaddingException; @@ -41,6 +42,9 @@ import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Implements record encryption by using the database events. * @@ -81,30 +85,30 @@ public void testEncryption() { .save(); }); - Assertions.assertEquals(1, creates.get()); + assertThat(creates.get()).isEqualTo(1); database.setTransactionIsolationLevel(Database.TRANSACTION_ISOLATION_LEVEL.REPEATABLE_READ); database.transaction(() -> { final Vertex v1 = database.iterateType("BackAccount", true).next().asVertex(); - Assertions.assertEquals("Nobody must know Elon and Zuck are brothers", v1.getString("secret")); + assertThat(v1.getString("secret")).isEqualTo("Nobody must know Elon and Zuck are brothers"); }); - Assertions.assertEquals(1, reads.get()); + assertThat(reads.get()).isEqualTo(1); database.transaction(() -> { final MutableVertex v1 = database.iterateType("BackAccount", true).next().asVertex().modify(); v1.set("secret", "Tool late, everybody knows it").save(); }); - Assertions.assertEquals(1, updates.get()); - Assertions.assertEquals(2, reads.get()); + assertThat(updates.get()).isEqualTo(1); + assertThat(reads.get()).isEqualTo(2); database.transaction(() -> { final Vertex v1 = database.iterateType("BackAccount", true).next().asVertex(); - Assertions.assertEquals("Tool late, everybody knows it", v1.getString("secret")); + assertThat(v1.getString("secret")).isEqualTo("Tool late, everybody knows it"); }); - Assertions.assertEquals(3, reads.get()); + assertThat(reads.get()).isEqualTo(3); } @Override diff --git a/engine/src/test/java/com/arcadedb/event/TypeEventsTest.java b/engine/src/test/java/com/arcadedb/event/TypeEventsTest.java index 76e81f3c61..476a05dff5 100644 --- a/engine/src/test/java/com/arcadedb/event/TypeEventsTest.java +++ b/engine/src/test/java/com/arcadedb/event/TypeEventsTest.java @@ -20,11 +20,14 @@ import com.arcadedb.TestHelper; import com.arcadedb.graph.MutableVertex; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.*; +import org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -49,16 +52,16 @@ public void testBeforeCreate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(1); + assertThat(database.countType("Vertex", true)).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2"); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); v2.save(); - Assertions.assertEquals(2, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(2); + assertThat(database.countType("Vertex", true)).isEqualTo(1); }); } finally { @@ -76,16 +79,16 @@ public void testAfterCreate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(1); + assertThat(database.countType("Vertex", true)).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2"); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); v2.save(); - Assertions.assertEquals(2, counter.get()); - Assertions.assertEquals(2, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(2); + assertThat(database.countType("Vertex", true)).isEqualTo(2); }); } finally { @@ -106,28 +109,28 @@ public void testBeforeUpdate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.set("modified2", true); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); v1.save(); - Assertions.assertEquals(2, counter.get()); + assertThat(counter.get()).isEqualTo(2); }); - Assertions.assertFalse(database.iterateType("Vertex", true).next().asVertex().has("modified2")); + assertThat(database.iterateType("Vertex", true).next().asVertex().has("modified2")).isFalse(); } finally { database.getSchema().getType("Vertex").getEvents().unregisterListener(listener); @@ -144,16 +147,16 @@ public void testAfterUpdate() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } finally { @@ -174,29 +177,29 @@ public void testBeforeDelete() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.delete(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2").save(); v2.delete(); - Assertions.assertEquals(2, counter.get()); + assertThat(counter.get()).isEqualTo(2); }); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(database.countType("Vertex", true)).isEqualTo(1); } finally { database.getSchema().getType("Vertex").getEvents().unregisterListener(listener); @@ -213,29 +216,29 @@ public void testAfterDelete() { database.transaction(() -> { final MutableVertex v1 = database.newVertex("Vertex").set("id", "test"); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); - Assertions.assertEquals(1, database.countType("Vertex", true)); + assertThat(counter.get()).isEqualTo(0); + assertThat(database.countType("Vertex", true)).isEqualTo(1); v1.set("modified", true); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); v1.save(); - Assertions.assertEquals(0, counter.get()); + assertThat(counter.get()).isEqualTo(0); }); database.transaction(() -> { final MutableVertex v1 = database.iterateType("Vertex", true).next().asVertex().modify(); v1.delete(); - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); final MutableVertex v2 = database.newVertex("Vertex").set("id", "test2").save(); v2.delete(); - Assertions.assertEquals(2, counter.get()); + assertThat(counter.get()).isEqualTo(2); }); - Assertions.assertEquals(0, database.countType("Vertex", true)); + assertThat(database.countType("Vertex", true)).isEqualTo(0); } finally { database.getSchema().getType("Vertex").getEvents().unregisterListener(listener); diff --git a/engine/src/test/java/com/arcadedb/function/java/JavaFunctionTest.java b/engine/src/test/java/com/arcadedb/function/java/JavaFunctionTest.java index 017c3de975..03f2e7417e 100644 --- a/engine/src/test/java/com/arcadedb/function/java/JavaFunctionTest.java +++ b/engine/src/test/java/com/arcadedb/function/java/JavaFunctionTest.java @@ -4,10 +4,12 @@ import com.arcadedb.function.FunctionExecutionException; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.lang.reflect.*; +import java.lang.reflect.InvocationTargetException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class JavaFunctionTest extends TestHelper { @@ -23,13 +25,13 @@ public static int SUM(final int a, final int b) { @Test public void testRegistration() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { // TEST REGISTRATION HERE registerClass(); try { registerClass(); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -40,13 +42,13 @@ public void testRegistration() @Test public void testRegistrationByClassInstance() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { // TEST REGISTRATION HERE database.getSchema().registerFunctionLibrary(new JavaClassFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class)); try { database.getSchema().registerFunctionLibrary(new JavaClassFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class)); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -57,29 +59,29 @@ public void testRegistrationByClassInstance() @Test public void testRegistrationSingleMethods() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { // TEST REGISTRATION HERE database.getSchema() - .registerFunctionLibrary(new JavaMethodFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class.getMethod("sum", Integer.TYPE, Integer.TYPE))); + .registerFunctionLibrary(new JavaMethodFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class.getMethod("sum", Integer.TYPE, Integer.TYPE))); try { database.getSchema() - .registerFunctionLibrary(new JavaMethodFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class.getMethod("sum", Integer.TYPE, Integer.TYPE))); - Assertions.fail(); + .registerFunctionLibrary(new JavaMethodFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class.getMethod("sum", Integer.TYPE, Integer.TYPE))); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } database.getSchema().unregisterFunctionLibrary("math"); database.getSchema() - .registerFunctionLibrary(new JavaMethodFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class.getMethod("sum", Integer.TYPE, Integer.TYPE))); + .registerFunctionLibrary(new JavaMethodFunctionLibraryDefinition("math", JavaFunctionTest.Sum.class.getMethod("sum", Integer.TYPE, Integer.TYPE))); } @Test public void testFunctionNotFound() { try { database.getSchema().getFunction("math", "sum"); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -87,35 +89,35 @@ public void testFunctionNotFound() { @Test public void testMethodParameterByPosition() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { // TEST REGISTRATION HERE registerClass(); final Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test public void testStaticMethodParameterByPosition() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { registerClass(); final Integer result = (Integer) database.getSchema().getFunction("math", "SUM").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test public void testExecuteFromSQL() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { registerClass(); database.transaction(() -> { final ResultSet rs = database.command("SQL", "SELECT `math.sum`(20,7) as sum"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertFalse(record.getIdentity().isPresent()); - Assertions.assertEquals(27, ((Number) record.getProperty("sum")).intValue()); + assertThat(record).isNotNull(); + assertThat(record.getIdentity()).isNotPresent(); + assertThat(((Number) record.getProperty("sum")).intValue()).isEqualTo(27); }); } @@ -124,7 +126,7 @@ public void testNotFound() throws ClassNotFoundException, InvocationTargetExcept registerClass(); try { database.getSchema().getFunction("math", "NOT_found").execute(3, 5); - Assertions.fail(); + fail(""); } catch (IllegalArgumentException e) { // EXPECTED } @@ -132,11 +134,11 @@ public void testNotFound() throws ClassNotFoundException, InvocationTargetExcept @Test public void testExecutionError() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { registerClass(); try { database.getSchema().getFunction("math", "SUM").execute("invalid", 5); - Assertions.fail(); + fail(""); } catch (FunctionExecutionException e) { // EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/function/polyglot/PolyglotFunctionTest.java b/engine/src/test/java/com/arcadedb/function/polyglot/PolyglotFunctionTest.java index 36fc6d77dc..fd5356ef54 100644 --- a/engine/src/test/java/com/arcadedb/function/polyglot/PolyglotFunctionTest.java +++ b/engine/src/test/java/com/arcadedb/function/polyglot/PolyglotFunctionTest.java @@ -2,17 +2,19 @@ import com.arcadedb.TestHelper; import com.arcadedb.function.FunctionExecutionException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.lang.reflect.*; +import java.lang.reflect.InvocationTargetException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class PolyglotFunctionTest extends TestHelper { @Test public void testEmbeddedFunction() { registerFunctions(); final Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test @@ -20,10 +22,10 @@ public void testReuseSameQueryEngine() { registerFunctions(); Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test @@ -31,11 +33,11 @@ public void testRedefineFunction() { registerFunctions(); Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(100, 50); - Assertions.assertEquals(150, result); + assertThat(result).isEqualTo(150); try { database.getSchema().getFunctionLibrary("math").registerFunction(new JavascriptFunctionDefinition("sum", "return a - b;", "a", "b")); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -44,7 +46,7 @@ public void testRedefineFunction() { database.getSchema().getFunctionLibrary("math").registerFunction(new JavascriptFunctionDefinition("sum", "return a - b;", "a", "b")); result = (Integer) database.getSchema().getFunction("math", "sum").execute(50, 100); - Assertions.assertEquals(-50, result); + assertThat(result).isEqualTo(-50); } @Test @@ -52,7 +54,7 @@ public void testNotFound() throws ClassNotFoundException, InvocationTargetExcept registerFunctions(); try { database.getSchema().getFunction("math", "NOT_found").execute(3, 5); - Assertions.fail(); + fail(""); } catch (IllegalArgumentException e) { // EXPECTED } @@ -66,7 +68,7 @@ public void testExecutionError() { .registerFunction(new JavascriptFunctionDefinition("sum", "return a ++++ b;", "a", "b"))); database.getSchema().getFunction("math", "sum").execute("invalid", 5); - Assertions.fail(); + fail(""); } catch (FunctionExecutionException e) { // EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/function/polyglot/SQLDefinedJavascriptFunctionTest.java b/engine/src/test/java/com/arcadedb/function/polyglot/SQLDefinedJavascriptFunctionTest.java index 5c1d7d3e7f..cdf778222b 100644 --- a/engine/src/test/java/com/arcadedb/function/polyglot/SQLDefinedJavascriptFunctionTest.java +++ b/engine/src/test/java/com/arcadedb/function/polyglot/SQLDefinedJavascriptFunctionTest.java @@ -3,22 +3,24 @@ import com.arcadedb.TestHelper; import com.arcadedb.function.FunctionLibraryDefinition; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class SQLDefinedJavascriptFunctionTest extends TestHelper { @Test public void testEmbeddedFunction() { registerFunctions(); final Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test public void testCallFromSQL() { registerFunctions(); final ResultSet result = database.command("sql", "select `math.sum`(?,?) as result", 3, 5); - Assertions.assertEquals(8, (Integer) result.next().getProperty("result")); + assertThat((Integer) result.next().getProperty("result")).isEqualTo(8); } @Test @@ -26,16 +28,16 @@ public void testReuseSameQueryEngine() { registerFunctions(); Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); result = (Integer) database.getSchema().getFunction("util", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); result = (Integer) database.getSchema().getFunction("util", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test @@ -43,11 +45,11 @@ public void testRedefineFunction() { registerFunctions(); Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(100, 50); - Assertions.assertEquals(150, result); + assertThat(result).isEqualTo(150); try { database.getSchema().getFunctionLibrary("math").registerFunction(new JavascriptFunctionDefinition("sum", "return a - b;", "a", "b")); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -56,7 +58,7 @@ public void testRedefineFunction() { database.getSchema().getFunctionLibrary("math").registerFunction(new JavascriptFunctionDefinition("sum", "return a - b;", "a", "b")); result = (Integer) database.getSchema().getFunction("math", "sum").execute(50, 100); - Assertions.assertEquals(-50, result); + assertThat(result).isEqualTo(-50); } private void registerFunctions() { @@ -64,6 +66,6 @@ private void registerFunctions() { database.command("sql", "define function util.sum \"return a + b\" parameters [a,b] language js"); final FunctionLibraryDefinition flib = database.getSchema().getFunctionLibrary("math"); - Assertions.assertNotNull(flib); + assertThat(flib).isNotNull(); } } diff --git a/engine/src/test/java/com/arcadedb/function/sql/SQLDefinedSQLFunctionTest.java b/engine/src/test/java/com/arcadedb/function/sql/SQLDefinedSQLFunctionTest.java index 654b7a39d1..22ce2d4a26 100644 --- a/engine/src/test/java/com/arcadedb/function/sql/SQLDefinedSQLFunctionTest.java +++ b/engine/src/test/java/com/arcadedb/function/sql/SQLDefinedSQLFunctionTest.java @@ -4,36 +4,39 @@ import com.arcadedb.exception.CommandSQLParsingException; import com.arcadedb.function.FunctionLibraryDefinition; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class SQLDefinedSQLFunctionTest extends TestHelper { @Test public void testEmbeddedFunction() { registerFunctions(); final Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test public void testCallFromSQLWithParams() { registerFunctions(); final ResultSet result = database.command("sql", "select `math.sum`(?,?) as result", 3, 5); - Assertions.assertEquals(8, (Integer) result.next().getProperty("result")); + assertThat((Integer) result.next().getProperty("result")).isEqualTo(8); } @Test public void testCallFromSQLNoParams() { database.command("sql", "define function math.hello \"select 'hello'\" language sql"); final ResultSet result = database.command("sql", "select `math.hello`() as result"); - Assertions.assertEquals("hello", result.next().getProperty("result")); + assertThat(result.next().getProperty("result")).isEqualTo("hello"); } @Test public void errorTestCallFromSQLEmptyParams() { try { database.command("sql", "define function math.hello \"select 'hello'\" parameters [] language sql"); - Assertions.fail(); + fail(""); } catch (CommandSQLParsingException e) { // EXPECTED } @@ -44,16 +47,16 @@ public void testReuseSameQueryEngine() { registerFunctions(); Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); result = (Integer) database.getSchema().getFunction("math", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); result = (Integer) database.getSchema().getFunction("util", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); result = (Integer) database.getSchema().getFunction("util", "sum").execute(3, 5); - Assertions.assertEquals(8, result); + assertThat(result).isEqualTo(8); } @Test @@ -61,11 +64,11 @@ public void testRedefineFunction() { registerFunctions(); Integer result = (Integer) database.getSchema().getFunction("math", "sum").execute(100, 50); - Assertions.assertEquals(150, result); + assertThat(result).isEqualTo(150); try { database.command("sql", "define function math.sum \"select :a + :b;\" parameters [a,b] language sql"); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -74,7 +77,7 @@ public void testRedefineFunction() { database.command("sql", "define function math.sum \"select :a + :b;\" parameters [a,b] language sql"); result = (Integer) database.getSchema().getFunction("math", "sum").execute(-350, 150); - Assertions.assertEquals(-200, result); + assertThat(result).isEqualTo(-200); } private void registerFunctions() { @@ -82,6 +85,6 @@ private void registerFunctions() { database.command("sql", "define function util.sum \"select :a + :b;\" parameters [a,b] language sql"); final FunctionLibraryDefinition flib = database.getSchema().getFunctionLibrary("math"); - Assertions.assertNotNull(flib); + assertThat(flib).isNotNull(); } } diff --git a/engine/src/test/java/com/arcadedb/graph/BaseGraphTest.java b/engine/src/test/java/com/arcadedb/graph/BaseGraphTest.java index f2aa80b1bb..c7ec26c1ba 100644 --- a/engine/src/test/java/com/arcadedb/graph/BaseGraphTest.java +++ b/engine/src/test/java/com/arcadedb/graph/BaseGraphTest.java @@ -23,11 +23,15 @@ import com.arcadedb.database.Database; import com.arcadedb.database.RID; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.Assertions; + import java.io.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public abstract class BaseGraphTest extends TestHelper { protected static final String VERTEX1_TYPE_NAME = "V1"; protected static final String VERTEX2_TYPE_NAME = "V2"; @@ -43,10 +47,10 @@ public void beginTest() { FileUtils.deleteRecursively(new File(DB_PATH)); database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType(VERTEX1_TYPE_NAME)); + assertThat(database.getSchema().existsType(VERTEX1_TYPE_NAME)).isFalse(); database.getSchema().buildVertexType().withName(VERTEX1_TYPE_NAME).withTotalBuckets(3).create(); - Assertions.assertFalse(database.getSchema().existsType(VERTEX2_TYPE_NAME)); + assertThat(database.getSchema().existsType(VERTEX2_TYPE_NAME)).isFalse(); database.getSchema().buildVertexType().withName(VERTEX2_TYPE_NAME).withTotalBuckets(3).create(); database.getSchema().buildEdgeType().withName(EDGE1_TYPE_NAME).create(); @@ -66,24 +70,24 @@ public void beginTest() { // CREATION OF EDGE PASSING PARAMS AS VARARGS final MutableEdge e1 = v1.newEdge(EDGE1_TYPE_NAME, v2, true, "name", "E1"); - Assertions.assertEquals(e1.getOut(), v1); - Assertions.assertEquals(e1.getIn(), v2); + assertThat(v1).isEqualTo(e1.getOut()); + assertThat(v2).isEqualTo(e1.getIn()); final MutableVertex v3 = db.newVertex(VERTEX2_TYPE_NAME); v3.set("name", "V3"); v3.save(); - Assertions.assertEquals(v3, v3.asVertex()); - Assertions.assertEquals(v3, v3.asVertex(true)); + assertThat(v3.asVertex()).isEqualTo(v3); + assertThat(v3.asVertex(true)).isEqualTo(v3); try { - Assertions.assertNotNull(v3.asEdge()); - Assertions.fail(); + assertThat(v3.asEdge()).isNotNull(); + fail(""); } catch (final ClassCastException e) { // EXPECTED } try { - Assertions.assertNotNull(v3.asEdge(true)); - Assertions.fail(); + assertThat(v3.asEdge(true)).isNotNull(); + fail(""); } catch (final ClassCastException e) { // EXPECTED } @@ -93,28 +97,28 @@ public void beginTest() { // CREATION OF EDGE PASSING PARAMS AS MAP final MutableEdge e2 = v2.newEdge(EDGE2_TYPE_NAME, v3, true, params); - Assertions.assertEquals(e2.getOut(), v2); - Assertions.assertEquals(e2.getIn(), v3); + assertThat(v2).isEqualTo(e2.getOut()); + assertThat(v3).isEqualTo(e2.getIn()); - Assertions.assertEquals(e2, e2.asEdge()); - Assertions.assertEquals(e2, e2.asEdge(true)); + assertThat(e2.asEdge()).isEqualTo(e2); + assertThat(e2.asEdge(true)).isEqualTo(e2); try { - Assertions.assertNotNull(e2.asVertex()); - Assertions.fail(); + assertThat(e2.asVertex()).isNotNull(); + fail(""); } catch (final ClassCastException e) { // EXPECTED } try { - Assertions.assertNotNull(e2.asVertex(true)); - Assertions.fail(); + assertThat(e2.asVertex(true)).isNotNull(); + fail(""); } catch (final ClassCastException e) { // EXPECTED } final ImmutableLightEdge e3 = v1.newLightEdge(EDGE2_TYPE_NAME, v3, true); - Assertions.assertEquals(e3.getOut(), v1); - Assertions.assertEquals(e3.getIn(), v3); + assertThat(v1).isEqualTo(e3.getOut()); + assertThat(v3).isEqualTo(e3.getIn()); db.commit(); diff --git a/engine/src/test/java/com/arcadedb/graph/BasicGraphTest.java b/engine/src/test/java/com/arcadedb/graph/BasicGraphTest.java index a5af1c2cfc..a3e5bc08fc 100644 --- a/engine/src/test/java/com/arcadedb/graph/BasicGraphTest.java +++ b/engine/src/test/java/com/arcadedb/graph/BasicGraphTest.java @@ -32,65 +32,70 @@ import com.arcadedb.query.sql.function.SQLFunctionAbstract; import com.arcadedb.schema.EdgeType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class BasicGraphTest extends BaseGraphTest { @Test public void checkVertices() { database.begin(); try { - Assertions.assertEquals(1, database.countType(VERTEX1_TYPE_NAME, false)); - Assertions.assertEquals(2, database.countType(VERTEX2_TYPE_NAME, false)); + assertThat(database.countType(VERTEX1_TYPE_NAME, false)).isEqualTo(1); + assertThat(database.countType(VERTEX2_TYPE_NAME, false)).isEqualTo(2); final Vertex v1 = (Vertex) database.lookupByRID(root, false); - Assertions.assertNotNull(v1); + assertThat(v1).isNotNull(); // TEST CONNECTED VERTICES - Assertions.assertEquals(VERTEX1_TYPE_NAME, v1.getTypeName()); - Assertions.assertEquals(VERTEX1_TYPE_NAME, v1.get("name")); + assertThat(v1.getTypeName()).isEqualTo(VERTEX1_TYPE_NAME); + assertThat(v1.get("name")).isEqualTo(VERTEX1_TYPE_NAME); final Iterator vertices2level = v1.getVertices(Vertex.DIRECTION.OUT, new String[] { EDGE1_TYPE_NAME }).iterator(); - Assertions.assertNotNull(vertices2level); - Assertions.assertTrue(vertices2level.hasNext()); + assertThat(vertices2level).isNotNull(); + assertThat(vertices2level.hasNext()).isTrue(); final Vertex v2 = vertices2level.next(); - Assertions.assertNotNull(v2); - Assertions.assertEquals(VERTEX2_TYPE_NAME, v2.getTypeName()); - Assertions.assertEquals(VERTEX2_TYPE_NAME, v2.get("name")); + assertThat(v2).isNotNull(); + assertThat(v2.getTypeName()).isEqualTo(VERTEX2_TYPE_NAME); + assertThat(v2.get("name")).isEqualTo(VERTEX2_TYPE_NAME); final Iterator vertices2level2 = v1.getVertices(Vertex.DIRECTION.OUT, new String[] { EDGE2_TYPE_NAME }).iterator(); - Assertions.assertTrue(vertices2level2.hasNext()); + assertThat(vertices2level2.hasNext()).isTrue(); final Vertex v3 = vertices2level2.next(); - Assertions.assertNotNull(v3); + assertThat(v3).isNotNull(); - Assertions.assertEquals(VERTEX2_TYPE_NAME, v3.getTypeName()); - Assertions.assertEquals("V3", v3.get("name")); + assertThat(v3.getTypeName()).isEqualTo(VERTEX2_TYPE_NAME); + assertThat(v3.get("name")).isEqualTo("V3"); final Iterator vertices3level = v2.getVertices(Vertex.DIRECTION.OUT, new String[] { EDGE2_TYPE_NAME }).iterator(); - Assertions.assertNotNull(vertices3level); - Assertions.assertTrue(vertices3level.hasNext()); + assertThat(vertices3level).isNotNull(); + assertThat(vertices3level.hasNext()).isTrue(); final Vertex v32 = vertices3level.next(); - Assertions.assertNotNull(v32); - Assertions.assertEquals(VERTEX2_TYPE_NAME, v32.getTypeName()); - Assertions.assertEquals("V3", v32.get("name")); + assertThat(v32).isNotNull(); + assertThat(v32.getTypeName()).isEqualTo(VERTEX2_TYPE_NAME); + assertThat(v32.get("name")).isEqualTo("V3"); - Assertions.assertTrue(v1.isConnectedTo(v2)); - Assertions.assertTrue(v2.isConnectedTo(v1)); - Assertions.assertTrue(v1.isConnectedTo(v3)); - Assertions.assertTrue(v3.isConnectedTo(v1)); - Assertions.assertTrue(v2.isConnectedTo(v3)); + assertThat(v1.isConnectedTo(v2)).isTrue(); + assertThat(v2.isConnectedTo(v1)).isTrue(); + assertThat(v1.isConnectedTo(v3)).isTrue(); + assertThat(v3.isConnectedTo(v1)).isTrue(); + assertThat(v2.isConnectedTo(v3)).isTrue(); - Assertions.assertFalse(v3.isConnectedTo(v1, Vertex.DIRECTION.OUT)); - Assertions.assertFalse(v3.isConnectedTo(v2, Vertex.DIRECTION.OUT)); + assertThat(v3.isConnectedTo(v1, Vertex.DIRECTION.OUT)).isFalse(); + assertThat(v3.isConnectedTo(v2, Vertex.DIRECTION.OUT)).isFalse(); } finally { database.commit(); @@ -103,19 +108,19 @@ public void autoPersistLightWeightEdge() { database.begin(); try { final Vertex v1 = (Vertex) database.lookupByRID(root, false); - Assertions.assertNotNull(v1); + assertThat(v1).isNotNull(); final Iterator edges3 = v1.getEdges(Vertex.DIRECTION.OUT, new String[] { EDGE2_TYPE_NAME }).iterator(); - Assertions.assertNotNull(edges3); - Assertions.assertTrue(edges3.hasNext()); + assertThat(edges3).isNotNull(); + assertThat(edges3.hasNext()).isTrue(); try { final MutableEdge edge = edges3.next().modify(); - Assertions.fail("Cannot modify lightweight edges"); + fail("Cannot modify lightweight edges"); // edge.set("upgraded", true); // edge.save(); // -// Assertions.assertTrue(edge.getIdentity().getPosition() > -1); +// Assertions.assertThat(edge.getIdentity().getPosition() > -1).isTrue(); } catch (final IllegalStateException e) { } @@ -129,50 +134,50 @@ public void checkEdges() { database.begin(); try { - Assertions.assertEquals(1, database.countType(EDGE1_TYPE_NAME, false)); - Assertions.assertEquals(1, database.countType(EDGE2_TYPE_NAME, false)); + assertThat(database.countType(EDGE1_TYPE_NAME, false)).isEqualTo(1); + assertThat(database.countType(EDGE2_TYPE_NAME, false)).isEqualTo(1); final Vertex v1 = (Vertex) database.lookupByRID(root, false); - Assertions.assertNotNull(v1); + assertThat(v1).isNotNull(); // TEST CONNECTED EDGES final Iterator edges1 = v1.getEdges(Vertex.DIRECTION.OUT, new String[] { EDGE1_TYPE_NAME }).iterator(); - Assertions.assertNotNull(edges1); - Assertions.assertTrue(edges1.hasNext()); + assertThat(edges1).isNotNull(); + assertThat(edges1.hasNext()).isTrue(); final Edge e1 = edges1.next(); - Assertions.assertNotNull(e1); - Assertions.assertEquals(EDGE1_TYPE_NAME, e1.getTypeName()); - Assertions.assertEquals(v1, e1.getOut()); - Assertions.assertEquals("E1", e1.get("name")); + assertThat(e1).isNotNull(); + assertThat(e1.getTypeName()).isEqualTo(EDGE1_TYPE_NAME); + assertThat(e1.getOut()).isEqualTo(v1); + assertThat(e1.get("name")).isEqualTo("E1"); final Vertex v2 = e1.getInVertex(); - Assertions.assertEquals(VERTEX2_TYPE_NAME, v2.get("name")); + assertThat(v2.get("name")).isEqualTo(VERTEX2_TYPE_NAME); final Iterator edges2 = v2.getEdges(Vertex.DIRECTION.OUT, new String[] { EDGE2_TYPE_NAME }).iterator(); - Assertions.assertTrue(edges2.hasNext()); + assertThat(edges2.hasNext()).isTrue(); final Edge e2 = edges2.next(); - Assertions.assertNotNull(e2); + assertThat(e2).isNotNull(); - Assertions.assertEquals(EDGE2_TYPE_NAME, e2.getTypeName()); - Assertions.assertEquals(v2, e2.getOut()); - Assertions.assertEquals("E2", e2.get("name")); + assertThat(e2.getTypeName()).isEqualTo(EDGE2_TYPE_NAME); + assertThat(e2.getOut()).isEqualTo(v2); + assertThat(e2.get("name")).isEqualTo("E2"); final Vertex v3 = e2.getInVertex(); - Assertions.assertEquals("V3", v3.get("name")); + assertThat(v3.get("name")).isEqualTo("V3"); final Iterator edges3 = v1.getEdges(Vertex.DIRECTION.OUT, new String[] { EDGE2_TYPE_NAME }).iterator(); - Assertions.assertNotNull(edges3); - Assertions.assertTrue(edges3.hasNext()); + assertThat(edges3).isNotNull(); + assertThat(edges3.hasNext()).isTrue(); final Edge e3 = edges3.next(); - Assertions.assertNotNull(e3); - Assertions.assertEquals(EDGE2_TYPE_NAME, e3.getTypeName()); - Assertions.assertEquals(v1, e3.getOutVertex()); - Assertions.assertEquals(v3, e3.getInVertex()); + assertThat(e3).isNotNull(); + assertThat(e3.getTypeName()).isEqualTo(EDGE2_TYPE_NAME); + assertThat(e3.getOutVertex()).isEqualTo(v1); + assertThat(e3.getInVertex()).isEqualTo(v3); v2.getEdges(); @@ -186,11 +191,11 @@ public void updateVerticesAndEdges() { database.begin(); try { - Assertions.assertEquals(1, database.countType(EDGE1_TYPE_NAME, false)); - Assertions.assertEquals(1, database.countType(EDGE2_TYPE_NAME, false)); + assertThat(database.countType(EDGE1_TYPE_NAME, false)).isEqualTo(1); + assertThat(database.countType(EDGE2_TYPE_NAME, false)).isEqualTo(1); final Vertex v1 = (Vertex) database.lookupByRID(root, false); - Assertions.assertNotNull(v1); + assertThat(v1).isNotNull(); final MutableVertex v1Copy = v1.modify(); v1Copy.set("newProperty1", "TestUpdate1"); @@ -198,12 +203,12 @@ public void updateVerticesAndEdges() { // TEST CONNECTED EDGES final Iterator edges1 = v1.getEdges(Vertex.DIRECTION.OUT, new String[] { EDGE1_TYPE_NAME }).iterator(); - Assertions.assertNotNull(edges1); - Assertions.assertTrue(edges1.hasNext()); + assertThat(edges1).isNotNull(); + assertThat(edges1.hasNext()).isTrue(); final Edge e1 = edges1.next(); - Assertions.assertNotNull(e1); + assertThat(e1).isNotNull(); final MutableEdge e1Copy = e1.modify(); e1Copy.set("newProperty2", "TestUpdate2"); @@ -212,9 +217,9 @@ public void updateVerticesAndEdges() { database.commit(); final Vertex v1CopyReloaded = (Vertex) database.lookupByRID(v1Copy.getIdentity(), true); - Assertions.assertEquals("TestUpdate1", v1CopyReloaded.get("newProperty1")); + assertThat(v1CopyReloaded.get("newProperty1")).isEqualTo("TestUpdate1"); final Edge e1CopyReloaded = (Edge) database.lookupByRID(e1Copy.getIdentity(), true); - Assertions.assertEquals("TestUpdate2", e1CopyReloaded.get("newProperty2")); + assertThat(e1CopyReloaded.get("newProperty2")).isEqualTo("TestUpdate2"); } finally { new DatabaseChecker(database).setVerboseLevel(0).check(); @@ -227,16 +232,16 @@ public void deleteVertices() { try { final Vertex v1 = (Vertex) database.lookupByRID(root, false); - Assertions.assertNotNull(v1); + assertThat(v1).isNotNull(); Iterator vertices = v1.getVertices(Vertex.DIRECTION.OUT).iterator(); - Assertions.assertTrue(vertices.hasNext()); + assertThat(vertices.hasNext()).isTrue(); Vertex v3 = vertices.next(); - Assertions.assertNotNull(v3); + assertThat(v3).isNotNull(); - Assertions.assertTrue(vertices.hasNext()); + assertThat(vertices.hasNext()).isTrue(); Vertex v2 = vertices.next(); - Assertions.assertNotNull(v2); + assertThat(v2).isNotNull(); final long totalVertices = database.countType(v1.getTypeName(), true); @@ -244,41 +249,41 @@ public void deleteVertices() { // ----------------------- database.deleteRecord(v1); - Assertions.assertEquals(totalVertices - 1, database.countType(v1.getTypeName(), true)); + assertThat(database.countType(v1.getTypeName(), true)).isEqualTo(totalVertices - 1); vertices = v2.getVertices(Vertex.DIRECTION.IN).iterator(); - Assertions.assertFalse(vertices.hasNext()); + assertThat(vertices.hasNext()).isFalse(); vertices = v2.getVertices(Vertex.DIRECTION.OUT).iterator(); - Assertions.assertTrue(vertices.hasNext()); + assertThat(vertices.hasNext()).isTrue(); // Expecting 1 edge only: V2 is still connected to V3 vertices = v3.getVertices(Vertex.DIRECTION.IN).iterator(); - Assertions.assertTrue(vertices.hasNext()); + assertThat(vertices.hasNext()).isTrue(); vertices.next(); - Assertions.assertFalse(vertices.hasNext()); + assertThat(vertices.hasNext()).isFalse(); // RELOAD AND CHECK AGAIN // ----------------------- v2 = (Vertex) database.lookupByRID(v2.getIdentity(), true); vertices = v2.getVertices(Vertex.DIRECTION.IN).iterator(); - Assertions.assertFalse(vertices.hasNext()); + assertThat(vertices.hasNext()).isFalse(); vertices = v2.getVertices(Vertex.DIRECTION.OUT).iterator(); - Assertions.assertTrue(vertices.hasNext()); + assertThat(vertices.hasNext()).isTrue(); v3 = (Vertex) database.lookupByRID(v3.getIdentity(), true); // Expecting 1 edge only: V2 is still connected to V3 vertices = v3.getVertices(Vertex.DIRECTION.IN).iterator(); - Assertions.assertTrue(vertices.hasNext()); + assertThat(vertices.hasNext()).isTrue(); vertices.next(); - Assertions.assertFalse(vertices.hasNext()); + assertThat(vertices.hasNext()).isFalse(); try { database.lookupByRID(root, true); - Assertions.fail("Expected deleted record"); + fail("Expected deleted record"); } catch (final RecordNotFoundException e) { } @@ -294,16 +299,16 @@ public void deleteEdges() { try { final Vertex v1 = (Vertex) database.lookupByRID(root, false); - Assertions.assertNotNull(v1); + assertThat(v1).isNotNull(); Iterator edges = v1.getEdges(Vertex.DIRECTION.OUT).iterator(); - Assertions.assertTrue(edges.hasNext()); + assertThat(edges.hasNext()).isTrue(); final Edge e3 = edges.next(); - Assertions.assertNotNull(e3); + assertThat(e3).isNotNull(); - Assertions.assertTrue(edges.hasNext()); + assertThat(edges.hasNext()).isTrue(); final Edge e2 = edges.next(); - Assertions.assertNotNull(e2); + assertThat(e2).isNotNull(); // DELETE THE EDGE // ----------------------- @@ -311,33 +316,33 @@ public void deleteEdges() { Vertex vOut = e2.getOutVertex(); edges = vOut.getEdges(Vertex.DIRECTION.OUT).iterator(); - Assertions.assertTrue(edges.hasNext()); + assertThat(edges.hasNext()).isTrue(); edges.next(); - Assertions.assertFalse(edges.hasNext()); + assertThat(edges.hasNext()).isFalse(); Vertex vIn = e2.getInVertex(); edges = vIn.getEdges(Vertex.DIRECTION.IN).iterator(); - Assertions.assertFalse(edges.hasNext()); + assertThat(edges.hasNext()).isFalse(); // RELOAD AND CHECK AGAIN // ----------------------- try { database.lookupByRID(e2.getIdentity(), true); - Assertions.fail("Expected deleted record"); + fail("Expected deleted record"); } catch (final RecordNotFoundException e) { } vOut = e2.getOutVertex(); edges = vOut.getEdges(Vertex.DIRECTION.OUT).iterator(); - Assertions.assertTrue(edges.hasNext()); + assertThat(edges.hasNext()).isTrue(); edges.next(); - Assertions.assertFalse(edges.hasNext()); + assertThat(edges.hasNext()).isFalse(); vIn = e2.getInVertex(); edges = vIn.getEdges(Vertex.DIRECTION.IN).iterator(); - Assertions.assertFalse(edges.hasNext()); + assertThat(edges.hasNext()).isFalse(); } finally { database.commit(); @@ -351,34 +356,34 @@ public void deleteEdgesFromEdgeIterator() { try { final Vertex v1 = (Vertex) database.lookupByRID(root, false); - Assertions.assertNotNull(v1); + assertThat(v1).isNotNull(); Iterator edges = v1.getEdges(Vertex.DIRECTION.OUT).iterator(); - Assertions.assertTrue(edges.hasNext()); + assertThat(edges.hasNext()).isTrue(); final Edge e3 = edges.next(); - Assertions.assertNotNull(e3); + assertThat(e3).isNotNull(); - Assertions.assertTrue(edges.hasNext()); + assertThat(edges.hasNext()).isTrue(); final Edge e2 = edges.next(); - Assertions.assertNotNull(e2); + assertThat(e2).isNotNull(); // DELETE THE EDGE // ----------------------- edges.remove(); - Assertions.assertFalse(edges.hasNext()); + assertThat(edges.hasNext()).isFalse(); try { e2.getOutVertex(); - Assertions.fail(); + fail(""); } catch (RecordNotFoundException e) { // EXPECTED } try { e2.getInVertex(); - Assertions.fail(); + fail(""); } catch (RecordNotFoundException e) { // EXPECTED } @@ -387,7 +392,7 @@ public void deleteEdgesFromEdgeIterator() { // ----------------------- try { database.lookupByRID(e2.getIdentity(), true); - Assertions.fail("Expected deleted record"); + fail("Expected deleted record"); } catch (final RecordNotFoundException e) { // EXPECTED } @@ -408,36 +413,36 @@ public void selfLoopEdges() { database.command("sql", "create edge " + EDGE1_TYPE_NAME + " from ? to ? unidirectional", v1, v1); - Assertions.assertTrue(v1.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()); - Assertions.assertEquals(v1, v1.getVertices(Vertex.DIRECTION.OUT).iterator().next()); - Assertions.assertFalse(v1.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()); + assertThat(v1.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()).isTrue(); + assertThat(v1.getVertices(Vertex.DIRECTION.OUT).iterator().next()).isEqualTo(v1); + assertThat(v1.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()).isFalse(); // BIDIRECTIONAL EDGE final Vertex v2 = database.newVertex(VERTEX1_TYPE_NAME).save(); v2.newEdge(EDGE1_TYPE_NAME, v2, true).save(); - Assertions.assertTrue(v2.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()); - Assertions.assertEquals(v2, v2.getVertices(Vertex.DIRECTION.OUT).iterator().next()); + assertThat(v2.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()).isTrue(); + assertThat(v2.getVertices(Vertex.DIRECTION.OUT).iterator().next()).isEqualTo(v2); - Assertions.assertTrue(v2.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()); - Assertions.assertEquals(v2, v2.getVertices(Vertex.DIRECTION.IN).iterator().next()); + assertThat(v2.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()).isTrue(); + assertThat(v2.getVertices(Vertex.DIRECTION.IN).iterator().next()).isEqualTo(v2); database.commit(); // UNIDIRECTIONAL EDGE final Vertex v1reloaded = (Vertex) database.lookupByRID(v1.getIdentity(), true); - Assertions.assertTrue(v1reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()); - Assertions.assertEquals(v1reloaded, v1reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().next()); - Assertions.assertFalse(v1reloaded.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()); + assertThat(v1reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()).isTrue(); + assertThat(v1reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().next()).isEqualTo(v1reloaded); + assertThat(v1reloaded.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()).isFalse(); // BIDIRECTIONAL EDGE final Vertex v2reloaded = (Vertex) database.lookupByRID(v2.getIdentity(), true); - Assertions.assertTrue(v2reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()); - Assertions.assertEquals(v2reloaded, v2reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().next()); + assertThat(v2reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()).isTrue(); + assertThat(v2reloaded.getVertices(Vertex.DIRECTION.OUT).iterator().next()).isEqualTo(v2reloaded); - Assertions.assertTrue(v2reloaded.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()); - Assertions.assertEquals(v2reloaded, v2reloaded.getVertices(Vertex.DIRECTION.IN).iterator().next()); + assertThat(v2reloaded.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()).isTrue(); + assertThat(v2reloaded.getVertices(Vertex.DIRECTION.IN).iterator().next()).isEqualTo(v2reloaded); } finally { new DatabaseChecker(database).setVerboseLevel(0).check(); @@ -460,15 +465,17 @@ public void shortestPath() { final Record v2 = v2Iterator.next(); final ResultSet result = database.query("sql", "select shortestPath(?,?) as sp", v1, v2); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result line = result.next(); - Assertions.assertNotNull(line); - Assertions.assertTrue(line.getPropertyNames().contains("sp")); - Assertions.assertNotNull(line.getProperty("sp")); - Assertions.assertEquals(2, ((List) line.getProperty("sp")).size()); - Assertions.assertEquals(v1, ((List) line.getProperty("sp")).get(0)); - Assertions.assertEquals(v2, ((List) line.getProperty("sp")).get(1)); + assertThat(line).isNotNull(); + assertThat(line.getPropertyNames().contains("sp")).isTrue(); + List sp = line.>getProperty("sp"); + assertThat(sp).isNotNull(); + assertThat(sp).hasSize(2); + + assertThat(sp.get(0)).isEqualTo(v1); + assertThat(sp.get(1)).isEqualTo(v2); } } @@ -495,12 +502,12 @@ public String getSyntax() { }); final ResultSet result = database.query("sql", "select ciao() as ciao"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result line = result.next(); - Assertions.assertNotNull(line); - Assertions.assertTrue(line.getPropertyNames().contains("ciao")); - Assertions.assertEquals("Ciao", line.getProperty("ciao")); + assertThat(line).isNotNull(); + assertThat(line.getPropertyNames().contains("ciao")).isTrue(); + assertThat(line.getProperty("ciao")).isEqualTo("Ciao"); } finally { new DatabaseChecker(database).setVerboseLevel(0).check(); @@ -518,12 +525,12 @@ public void customReflectionFunction() { ((SQLQueryEngine) database.getQueryEngine("sql")).getFunctionFactory().getReflectionFactory().register("test_", getClass()); final ResultSet result = database.query("sql", "select test_testReflectionMethod() as testReflectionMethod"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result line = result.next(); - Assertions.assertNotNull(line); - Assertions.assertTrue(line.getPropertyNames().contains("testReflectionMethod")); - Assertions.assertEquals("reflect on this", line.getProperty("testReflectionMethod")); + assertThat(line).isNotNull(); + assertThat(line.getPropertyNames().contains("testReflectionMethod")).isTrue(); + assertThat(line.getProperty("testReflectionMethod")).isEqualTo("reflect on this"); } finally { new DatabaseChecker(database).setVerboseLevel(0).check(); @@ -563,7 +570,7 @@ public void rollbackEdge() { v2.set("rid", v1RID.get()); v2.save(); - Assertions.assertFalse(v1a.isConnectedTo(v2)); + assertThat(v1a.isConnectedTo(v2)).isFalse(); }); } @@ -589,13 +596,13 @@ public void reuseRollbackedTx() { v2.set("rid", v1RID.get()); v2.save(); - Assertions.fail(); + fail(""); } catch (final RuntimeException e) { // EXPECTED } - Assertions.assertFalse(v1a.isConnectedTo(v2)); + assertThat(v1a.isConnectedTo(v2)).isFalse(); } @Test @@ -613,7 +620,7 @@ public void edgeUnivocity() { try { database.transaction(() -> v1[0].newEdge("OnlyOneBetweenVertices", v2[0], true)); - Assertions.fail(); + fail(""); } catch (final DuplicatedKeyException ex) { // EXPECTED } @@ -649,19 +656,19 @@ public void edgeUnivocitySQL() { v1[0] = database.newVertex(VERTEX1_TYPE_NAME).set("id", 1001).save(); v2[0] = database.newVertex(VERTEX1_TYPE_NAME).set("id", 1002).save(); final ResultSet result = database.command("sql", "create edge OnlyOneBetweenVertices from ? to ?", v1[0], v2[0]); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); }); try { database.transaction(() -> v1[0].newEdge("OnlyOneBetweenVertices", v2[0], true)); - Assertions.fail(); + fail(""); } catch (final DuplicatedKeyException ex) { // EXPECTED } try { database.transaction(() -> database.command("sql", "create edge OnlyOneBetweenVertices from ? to ?", v1[0], v2[0])); - Assertions.fail(); + fail(""); } catch (final DuplicatedKeyException ex) { // EXPECTED } @@ -681,19 +688,19 @@ public void edgeConstraints() { v1[0] = database.newVertex(VERTEX1_TYPE_NAME).set("id", 1001).save(); v2[0] = database.newVertex(VERTEX2_TYPE_NAME).set("id", 1002).save(); final ResultSet result = database.command("sql", "create edge EdgeConstraint from ? to ?", v1[0], v2[0]); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); }); try { database.transaction(() -> v2[0].newEdge("EdgeConstraint", v1[0], true)); - Assertions.fail(); + fail(""); } catch (final ValidationException ex) { // EXPECTED } try { database.transaction(() -> database.command("sql", "create edge EdgeConstraint from ? to ?", v2[0], v1[0])); - Assertions.fail(); + fail(""); } catch (final ValidationException ex) { // EXPECTED } @@ -711,7 +718,7 @@ public void testEdgeTypeNotFromVertex() { try { final Edge e1 = v1.newEdge("a-vertex", v2, /*= bidirectional */ true); // <-- expect IllegalArgumentException - Assertions.fail("Created an edge of vertex type"); + fail("Created an edge of vertex type"); } catch (final ClassCastException e) { // EXPECTED } @@ -732,7 +739,7 @@ public void testEdgeDescendantOrder() { final Iterator vertices = v1.getVertices(Vertex.DIRECTION.OUT).iterator(); for (int i = 10000 - 1; vertices.hasNext(); --i) { - Assertions.assertEquals(i, vertices.next().get("id")); + assertThat(vertices.next().get("id")).isEqualTo(i); } }); } diff --git a/engine/src/test/java/com/arcadedb/graph/InsertGraphIndexTest.java b/engine/src/test/java/com/arcadedb/graph/InsertGraphIndexTest.java index c0497dc4f9..370d5149d9 100644 --- a/engine/src/test/java/com/arcadedb/graph/InsertGraphIndexTest.java +++ b/engine/src/test/java/com/arcadedb/graph/InsertGraphIndexTest.java @@ -26,11 +26,12 @@ import com.arcadedb.log.LogManager; import com.arcadedb.schema.Schema; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class InsertGraphIndexTest extends TestHelper { private static final int VERTICES = 1_000; private static final int EDGES_PER_VERTEX = 1_000; @@ -125,7 +126,7 @@ private Vertex[] loadVertices() { } }); - Assertions.assertEquals(VERTICES, cachedVertices.length); + assertThat(cachedVertices.length).isEqualTo(VERTICES); return cachedVertices; } @@ -162,7 +163,7 @@ public void call(final Throwable exception) { database.async().waitCompletion(); - Assertions.assertEquals(VERTICES, database.countType(VERTEX_TYPE_NAME, true)); + assertThat(database.countType(VERTEX_TYPE_NAME, true)).isEqualTo(VERTICES); } finally { final long elapsed = System.currentTimeMillis() - startOfTest; @@ -175,7 +176,7 @@ private void createSchema() { vertex.createProperty("id", Integer.class); database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, VERTEX_TYPE_NAME, "id"); - Assertions.assertEquals("round-robin", vertex.getBucketSelectionStrategy().getName()); + assertThat(vertex.getBucketSelectionStrategy().getName()).isEqualTo("round-robin"); database.getSchema().buildEdgeType().withName(EDGE_TYPE_NAME).withTotalBuckets(PARALLEL).create(); @@ -183,10 +184,10 @@ private void createSchema() { vertexNotInUse.createProperty("id", Integer.class); database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, "NotInUse", "id"); - Assertions.assertEquals("round-robin", vertexNotInUse.getBucketSelectionStrategy().getName()); + assertThat(vertexNotInUse.getBucketSelectionStrategy().getName()).isEqualTo("round-robin"); vertexNotInUse.setBucketSelectionStrategy("partitioned('id')"); - Assertions.assertEquals("partitioned", vertexNotInUse.getBucketSelectionStrategy().getName()); + assertThat(vertexNotInUse.getBucketSelectionStrategy().getName()).isEqualTo("partitioned"); } @@ -202,10 +203,10 @@ private void checkGraph(final Vertex[] cachedVertices) { for (; i < VERTICES; ++i) { int edges = 0; final long outEdges = cachedVertices[i].countEdges(Vertex.DIRECTION.OUT, EDGE_TYPE_NAME); - Assertions.assertEquals(expectedEdges, outEdges); + assertThat(outEdges).isEqualTo(expectedEdges); final long inEdges = cachedVertices[i].countEdges(Vertex.DIRECTION.IN, EDGE_TYPE_NAME); - Assertions.assertEquals(expectedEdges, inEdges); + assertThat(inEdges).isEqualTo(expectedEdges); if (++edges > EDGES_PER_VERTEX) break; diff --git a/engine/src/test/java/com/arcadedb/graph/TestVertexDelete.java b/engine/src/test/java/com/arcadedb/graph/TestVertexDelete.java index a9fcb52761..23dc9a8191 100644 --- a/engine/src/test/java/com/arcadedb/graph/TestVertexDelete.java +++ b/engine/src/test/java/com/arcadedb/graph/TestVertexDelete.java @@ -2,13 +2,15 @@ import com.arcadedb.database.Database; import com.arcadedb.database.DatabaseFactory; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; import java.nio.file.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class TestVertexDelete { public static class DeleteOnClose implements AutoCloseable { public DeleteOnClose(Path p) { @@ -58,8 +60,8 @@ public void testFullEdgeDeletion() throws IOException, InterruptedException { db.transaction(() -> { var v1c = db.countType("v1", false); var pc = db.countType("hasParent", false); - Assertions.assertEquals(0, v1c); - Assertions.assertEquals(0, pc); + assertThat(v1c).isEqualTo(0); + assertThat(pc).isEqualTo(0); }); } } diff --git a/engine/src/test/java/com/arcadedb/graph/TxGraphTest.java b/engine/src/test/java/com/arcadedb/graph/TxGraphTest.java index bbe190ceaf..afb20aae2a 100644 --- a/engine/src/test/java/com/arcadedb/graph/TxGraphTest.java +++ b/engine/src/test/java/com/arcadedb/graph/TxGraphTest.java @@ -22,9 +22,14 @@ import com.arcadedb.database.RID; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.Date; + +import static org.assertj.core.api.Assertions.assertThat; + public class TxGraphTest extends TestHelper { protected static final String DB_PATH = "target/databases/graph"; @@ -50,38 +55,38 @@ public void testEdgeChunkIsLoadedFromCurrentTx() { commodore[0].asVertex(false).newEdge("SELLS", vic20, true).set("date", System.currentTimeMillis()).save(); - Assertions.assertEquals(2, commodore[0].asVertex().countEdges(Vertex.DIRECTION.OUT, "SELLS")); + assertThat(commodore[0].asVertex().countEdges(Vertex.DIRECTION.OUT,"SELLS")).isEqualTo(2); ResultSet result = database.query("sql", "select expand( in().include('name') ) from Good"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result next = result.next(); - Assertions.assertNotNull(next.getProperty("name")); - Assertions.assertNull(next.getProperty("date")); + assertThat(next.getProperty("name")).isNotNull(); + assertThat(next.getProperty("date")).isNull(); } result = database.query("sql", "select expand( in().include('date') ) from Good"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result next = result.next(); - Assertions.assertNotNull(next.getProperty("date")); - Assertions.assertNull(next.getProperty("name")); + assertThat(next.getProperty("date")).isNotNull(); + assertThat(next.getProperty("name")).isNull(); } result = database.query("sql", "select expand( in().exclude('name') ) from Good"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result next = result.next(); - Assertions.assertNotNull(next.getProperty("date")); - Assertions.assertNull(next.getProperty("name")); + assertThat(next.getProperty("date")).isNotNull(); + assertThat(next.getProperty("name")).isNull(); } result = database.query("sql", "select expand( in().exclude('date') ) from Good"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { final Result next = result.next(); - Assertions.assertNotNull(next.getProperty("name")); - Assertions.assertNull(next.getProperty("date")); + assertThat(next.getProperty("date")).isNull(); + assertThat(next.getProperty("name")).isNotNull(); } }); } diff --git a/engine/src/test/java/com/arcadedb/index/CompressedRID2RIDIndexTest.java b/engine/src/test/java/com/arcadedb/index/CompressedRID2RIDIndexTest.java index 27253125cc..8242e1d9c4 100644 --- a/engine/src/test/java/com/arcadedb/index/CompressedRID2RIDIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/CompressedRID2RIDIndexTest.java @@ -20,9 +20,10 @@ import com.arcadedb.TestHelper; import com.arcadedb.database.RID; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class CompressedRID2RIDIndexTest extends TestHelper { private static final int TOT = 10_000_000; @@ -34,21 +35,21 @@ public void testIndexPutAndGet() throws ClassNotFoundException { index.put(new RID(database, 3, i), new RID(database, 4, i)); for (int i = 0; i < TOT; i++) - Assertions.assertEquals(new RID(database, 4, i), index.get(new RID(database, 3, i))); + assertThat(index.get(new RID(database, 3, i))).isEqualTo(new RID(database, 4, i)); int found = 0; for (CompressedRID2RIDIndex.EntryIterator it = index.entryIterator(); it.hasNext(); ) { final RID key = it.getKeyRID(); final RID value = it.getValueRID(); - Assertions.assertEquals(3, key.getBucketId()); - Assertions.assertEquals(4, value.getBucketId()); - Assertions.assertEquals(key.getPosition(), value.getPosition()); + assertThat(key.getBucketId()).isEqualTo(3); + assertThat(value.getBucketId()).isEqualTo(4); + assertThat(value.getPosition()).isEqualTo(key.getPosition()); ++found; it.moveNext(); } - Assertions.assertEquals(TOT, found); + assertThat(found).isEqualTo(TOT); } } diff --git a/engine/src/test/java/com/arcadedb/index/DropIndexTest.java b/engine/src/test/java/com/arcadedb/index/DropIndexTest.java index cec5322066..14c4924ed0 100644 --- a/engine/src/test/java/com/arcadedb/index/DropIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/DropIndexTest.java @@ -26,11 +26,14 @@ import com.arcadedb.index.lsm.LSMTreeIndexAbstract; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class DropIndexTest extends TestHelper { private static final int TOT = 10; private static final String TYPE_NAME = "V"; @@ -40,7 +43,7 @@ public class DropIndexTest extends TestHelper { @Test public void testDropAndRecreate() { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); final DocumentType type2 = database.getSchema().buildDocumentType().withName(TYPE_NAME2).withTotalBuckets(3).create(); @@ -70,9 +73,9 @@ public void testDropAndRecreate() { database.commit(); - Assertions.assertEquals(TOT + 1, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(TOT, database.countType(TYPE_NAME2, false)); - Assertions.assertEquals(1, database.countType(TYPE_NAME, false)); + Assertions.assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT + 1); + Assertions.assertThat(database.countType(TYPE_NAME2, false)).isEqualTo(TOT); + Assertions.assertThat(database.countType(TYPE_NAME, false)).isEqualTo(1); database.begin(); @@ -98,9 +101,9 @@ public void testDropAndRecreate() { final Index typeIndex3 = database.getSchema() .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); - Assertions.assertEquals(TOT + 1, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(TOT, database.countType(TYPE_NAME2, false)); - Assertions.assertEquals(1, database.countType(TYPE_NAME, false)); + Assertions.assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT + 1); + Assertions.assertThat(database.countType(TYPE_NAME2, false)).isEqualTo(TOT); + Assertions.assertThat(database.countType(TYPE_NAME, false)).isEqualTo(1); for (int i = 0; i < TOT; ++i) { final MutableDocument v2 = database.newDocument(TYPE_NAME2); @@ -114,26 +117,26 @@ public void testDropAndRecreate() { v3.set("id", TOT * 3 + 1); v3.save(); - Assertions.assertEquals(TOT * 2 + 2, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(TOT * 2, database.countType(TYPE_NAME2, false)); - Assertions.assertEquals(2, database.countType(TYPE_NAME, false)); + Assertions.assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT * 2 + 2); + Assertions.assertThat(database.countType(TYPE_NAME2, true)).isEqualTo(TOT * 2); + Assertions.assertThat(database.countType(TYPE_NAME, false)).isEqualTo(2); }, false, 0); } @Test public void testDropAndRecreateTypeWithIndex() { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); final DocumentType type2 = database.getSchema().buildDocumentType().withName(TYPE_NAME2).withTotalBuckets(3) .withSuperType(type.getName()).create(); - Assertions.assertEquals(type.getName(), type2.getSuperTypes().get(0).getName()); + assertThat(type2.getSuperTypes().get(0).getName()).isEqualTo(type.getName()); final DocumentType type3 = database.getSchema().buildDocumentType().withName(TYPE_NAME3).withTotalBuckets(3) .withSuperType(type2.getName()).create(); - Assertions.assertEquals(type.getName(), type2.getSuperTypes().get(0).getName()); + assertThat(type2.getSuperTypes().get(0).getName()).isEqualTo(type.getName()); type.createProperty("id", Integer.class); type.createProperty("name", String.class); @@ -196,33 +199,33 @@ public void testDropAndRecreateTypeWithIndex() { // CHECK TYPE HAS BEEN REMOVED FROM INHERITANCE for (final DocumentType parent : type2.getSuperTypes()) - Assertions.assertFalse(parent.getSubTypes().contains(type2)); + Assertions.assertThat(parent.getSubTypes().contains(type2)).isFalse(); for (final DocumentType sub : type2.getSubTypes()) - Assertions.assertFalse(sub.getSuperTypes().contains(type2)); + Assertions.assertThat(sub.getSuperTypes().contains(type2)).isFalse(); // CHECK INHERITANCE CHAIN IS CONSISTENT for (final DocumentType parent : type2.getSuperTypes()) - Assertions.assertTrue(parent.getSubTypes().contains(type2.getSubTypes().get(0))); + Assertions.assertThat(parent.getSubTypes().contains(type2.getSubTypes().get(0))).isTrue(); - Assertions.assertEquals(1, database.countType(TYPE_NAME, true)); + Assertions.assertThat(database.countType(TYPE_NAME, true)).isEqualTo(1); final DocumentType newType = database.getSchema().getOrCreateDocumentType(TYPE_NAME2); - Assertions.assertEquals(1, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(0, database.countType(TYPE_NAME2, true)); + Assertions.assertThat(database.countType(TYPE_NAME, true)).isEqualTo(1); + Assertions.assertThat(database.countType(TYPE_NAME2, true)).isEqualTo(0); newType.addSuperType(TYPE_NAME); // CHECK INHERITANCE CHAIN IS CONSISTENT AGAIN for (final DocumentType parent : newType.getSuperTypes()) - Assertions.assertTrue(parent.getSubTypes().contains(newType)); + Assertions.assertThat(parent.getSubTypes().contains(newType)).isTrue(); for (final DocumentType sub : newType.getSubTypes()) - Assertions.assertTrue(sub.getSuperTypes().contains(newType)); + Assertions.assertThat(sub.getSuperTypes().contains(newType)).isTrue(); - Assertions.assertEquals(1, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(0, database.countType(TYPE_NAME2, true)); + Assertions.assertThat(database.countType(TYPE_NAME, true)).isEqualTo(1); + Assertions.assertThat(database.countType(TYPE_NAME2, true)).isEqualTo(0); database.begin(); @@ -242,9 +245,9 @@ public void testDropAndRecreateTypeWithIndex() { v3.set("id", TOT); v3.save(); - Assertions.assertEquals(TOT + 2, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(TOT, database.countType(TYPE_NAME2, false)); - Assertions.assertEquals(2, database.countType(TYPE_NAME, false)); + Assertions.assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT + 2); + Assertions.assertThat(database.countType(TYPE_NAME2, false)).isEqualTo(TOT); + Assertions.assertThat(database.countType(TYPE_NAME, false)).isEqualTo(2); type.setBucketSelectionStrategy(new RoundRobinBucketSelectionStrategy()); diff --git a/engine/src/test/java/com/arcadedb/index/LSMTreeFullTextIndexTest.java b/engine/src/test/java/com/arcadedb/index/LSMTreeFullTextIndexTest.java index 2a97ee96ca..97faf65d0f 100644 --- a/engine/src/test/java/com/arcadedb/index/LSMTreeFullTextIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/LSMTreeFullTextIndexTest.java @@ -27,11 +27,15 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class LSMTreeFullTextIndexTest extends TestHelper { private static final int TOT = 10000; private static final String TYPE_NAME = "V"; @@ -39,14 +43,14 @@ public class LSMTreeFullTextIndexTest extends TestHelper { @Test public void testIndexing() { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(1).create(); type.createProperty("text", String.class); final Index typeIndex = database.getSchema() .createTypeIndex(Schema.INDEX_TYPE.FULL_TEXT, false, TYPE_NAME, new String[] { "text" }, PAGE_SIZE); - Assertions.assertTrue(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isTrue(); final String text = "Jay Glenn Miner (May 31, 1932 – June 20, 1994) was an American integrated circuit designer, known primarily for developing multimedia chips for the Atari 2600 and Atari 8-bit family and as the \"father of the Amiga\". He received a BS in EECS from UC Berkeley in 1959.[2]\n" @@ -77,7 +81,7 @@ public void testIndexing() { final List keywords = ((LSMTreeFullTextIndex) ((TypeIndex) typeIndex).getIndexesOnBuckets()[0]).analyzeText( ((LSMTreeFullTextIndex) ((TypeIndex) typeIndex).getIndexesOnBuckets()[0]).getAnalyzer(), new Object[] { text }); - Assertions.assertFalse(keywords.isEmpty()); + assertThat(keywords.isEmpty()).isFalse(); for (final String k : keywords) { int totalPerKeyword = 0; @@ -94,24 +98,24 @@ public void testIndexing() { ++totalPerIndex; } - Assertions.assertEquals(result.estimateSize(), totalPerIndex); + assertThat(totalPerIndex).isEqualTo(result.estimateSize()); totalPerKeyword += totalPerIndex; } - Assertions.assertEquals(TOT, totalPerKeyword); + assertThat(totalPerKeyword).isEqualTo(TOT); } }); reopenDatabase(); - Assertions.assertEquals(Schema.INDEX_TYPE.FULL_TEXT, database.getSchema().getIndexes()[0].getType()); + assertThat(database.getSchema().getIndexes()[0].getType()).isEqualTo(Schema.INDEX_TYPE.FULL_TEXT); database.getSchema().dropIndex(typeIndex.getName()); } @Test public void testIndexingComposite() { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(1).create(); type.createProperty("text", String.class); @@ -119,7 +123,7 @@ public void testIndexingComposite() { try { database.getSchema() .createTypeIndex(Schema.INDEX_TYPE.FULL_TEXT, false, TYPE_NAME, new String[] { "text", "type" }, PAGE_SIZE); - Assertions.fail(); + fail(""); } catch (IndexException e) { // EXPECTED } @@ -128,14 +132,14 @@ public void testIndexingComposite() { @Test public void testQuery() { database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType("Docs")); + assertThat(database.getSchema().existsType("Docs")).isFalse(); final DocumentType type = database.getSchema().createDocumentType("Docs"); type.createProperty("text", String.class); final Index typeIndex = database.getSchema() .createTypeIndex(Schema.INDEX_TYPE.FULL_TEXT, false, "Docs", new String[] { "text" }); - Assertions.assertTrue(database.getSchema().existsType("Docs")); + assertThat(database.getSchema().existsType("Docs")).isTrue(); final String text = "Jay Glenn Miner (May 31, 1932 – June 20, 1994) was an American integrated circuit designer, known primarily for developing multimedia chips for the Atari 2600 and Atari 8-bit family and as the \"father of the Amiga\". He received a BS in EECS from UC Berkeley in 1959.[2]\n" @@ -178,13 +182,17 @@ public void testQuery() { continue; final ResultSet result = database.query("sql", "select from Docs where text = '" + toFind + "'", toFind); - Assertions.assertTrue(result.hasNext(), "Cannot find key '" + toFind + "'"); + assertThat(result.hasNext()) + .isTrue() + .withFailMessage("Cannot find key '" + toFind + "'"); final Result res = result.next(); - Assertions.assertNotNull(res); + assertThat(res).isNotNull(); final String content = res.getProperty("text").toString().toLowerCase(); - Assertions.assertTrue(content.contains(toFind), "Cannot find the word '" + toFind + "' in indexed text '" + content + "'"); + assertThat(content.contains(toFind)) + .isTrue() + .withFailMessage("Cannot find the word '" + toFind + "' in indexed text '" + content + "'"); } }); } @@ -198,7 +206,7 @@ public void testNullValuesViaSQL() { database.command("sql", "CREATE INDEX ON doc (str) FULL_TEXT null_strategy error"); database.command("sql", "INSERT INTO doc (str) VALUES ('a'), ('b'), (null)"); }); - Assertions.fail(); + fail(""); } catch (TransactionException e) { } diff --git a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompactionTest.java b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompactionTest.java index ab7b099164..db57d889e1 100644 --- a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompactionTest.java +++ b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompactionTest.java @@ -29,13 +29,16 @@ import com.arcadedb.log.LogManager; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * This test stresses the index compaction by forcing using only 1MB of RAM for compaction causing multiple page compacted index. * @@ -110,7 +113,7 @@ public void run() { checkRanges(1, 3); } catch (final InterruptedException e) { - Assertions.fail(e); + fail("", e); } finally { GlobalConfiguration.INDEX_COMPACTION_RAM_MB.setValue(300); GlobalConfiguration.INDEX_COMPACTION_MIN_PAGES_SCHEDULE.setValue(10); @@ -125,7 +128,7 @@ private void compaction() { ((IndexInternal) index).scheduleCompaction(); ((IndexInternal) index).compact(); } catch (final Exception e) { - Assertions.fail(e); + fail("", e); } } } @@ -161,7 +164,7 @@ private void insertData() { public void call(final Throwable exception) { LogManager.instance().log(this, Level.SEVERE, "TEST: ERROR: ", exception); exception.printStackTrace(); - Assertions.fail(exception); + fail(exception); } }); @@ -209,7 +212,7 @@ public void execute() { } private void checkLookups(final int step, final int expectedItemsPerSameKey) { - database.transaction(() -> Assertions.assertEquals(TOT * expectedItemsPerSameKey, database.countType(TYPE_NAME, false))); + database.transaction(() -> assertThat(database.countType(TYPE_NAME,false)).isEqualTo(TOT * expectedItemsPerSameKey)); LogManager.instance().log(this, Level.FINE, "TEST: Lookup all the keys..."); @@ -220,20 +223,20 @@ private void checkLookups(final int step, final int expectedItemsPerSameKey) { for (long id = 0; id < TOT; id += step) { try { final IndexCursor records = database.lookupByKey(TYPE_NAME, new String[] { "id" }, new Object[] { id }); - Assertions.assertNotNull(records); + assertThat(Optional.ofNullable(records)).isNotNull(); int count = 0; for (final Iterator it = records.iterator(); it.hasNext(); ) { final Identifiable rid = it.next(); final Document record = (Document) rid.getRecord(); - Assertions.assertEquals("" + id, record.get("id")); + assertThat(record.get("id")).isEqualTo("" + id); ++count; } if (count != expectedItemsPerSameKey) LogManager.instance().log(this, Level.FINE, "Cannot find key '%s'", null, id); - Assertions.assertEquals(expectedItemsPerSameKey, count, "Wrong result for lookup of key " + id); + assertThat(count).as("Wrong result for lookup of key " + id).isEqualTo(expectedItemsPerSameKey); checked++; @@ -245,14 +248,14 @@ private void checkLookups(final int step, final int expectedItemsPerSameKey) { begin = System.currentTimeMillis(); } } catch (final Exception e) { - Assertions.fail("Error on lookup key " + id, e); + fail("Error on lookup key " + id, e); } } LogManager.instance().log(this, Level.FINE, "TEST: Lookup finished in " + (System.currentTimeMillis() - begin) + "ms"); } private void checkRanges(final int step, final int expectedItemsPerSameKey) { - database.transaction(() -> Assertions.assertEquals(TOT * expectedItemsPerSameKey, database.countType(TYPE_NAME, false))); + database.transaction(() -> assertThat(database.countType(TYPE_NAME,false)).isEqualTo(TOT * expectedItemsPerSameKey)); LogManager.instance().log(this, Level.FINE, "TEST: Range pair of keys..."); @@ -265,14 +268,14 @@ private void checkRanges(final int step, final int expectedItemsPerSameKey) { for (long number = 0; number < TOT - 1; number += step) { try { final IndexCursor records = ((RangeIndex) index).range(true, new Object[] { number }, true, new Object[] { number + 1 }, true); - Assertions.assertNotNull(records); + assertThat(Optional.ofNullable(records)).isNotNull(); int count = 0; for (final Iterator it = records.iterator(); it.hasNext(); ) { for (int i = 0; i < expectedItemsPerSameKey; i++) { final Identifiable rid = it.next(); final Document record = (Document) rid.getRecord(); - Assertions.assertEquals(number + count, record.getLong("number")); + assertThat(record.getLong("number")).isEqualTo(number + count); } ++count; } @@ -280,7 +283,7 @@ private void checkRanges(final int step, final int expectedItemsPerSameKey) { if (count != 2) LogManager.instance().log(this, Level.FINE, "Cannot find key '%s'", null, number); - Assertions.assertEquals(2, count, "Wrong result for lookup of key " + number); + assertThat(count).as("Wrong result for lookup of key " + number).isEqualTo(2); checked++; @@ -292,7 +295,7 @@ private void checkRanges(final int step, final int expectedItemsPerSameKey) { begin = System.currentTimeMillis(); } } catch (final Exception e) { - Assertions.fail("Error on lookup key " + number, e); + fail("Error on lookup key " + number, e); } } LogManager.instance().log(this, Level.FINE, "TEST: Lookup finished in " + (System.currentTimeMillis() - begin) + "ms"); diff --git a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompositeTest.java b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompositeTest.java index 69c2f1fc0f..32e6c2112f 100644 --- a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompositeTest.java +++ b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexCompositeTest.java @@ -24,11 +24,13 @@ import com.arcadedb.graph.Vertex; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class LSMTreeIndexCompositeTest extends TestHelper { private static final int TOT = 100; @@ -38,8 +40,8 @@ public void testGetAbsoluteId() { final TypeIndex index = database.getSchema().getType("File").getIndexesByProperties("absoluteId").get(0); for (int i = 0; i < TOT * TOT; ++i) { final IndexCursor value = index.get(new Object[] { i }); - Assertions.assertTrue(value.hasNext()); - Assertions.assertEquals(i, value.next().asVertex().get("absoluteId")); + assertThat(value.hasNext()).isTrue(); + assertThat(value.next().asVertex().get("absoluteId")).isEqualTo(i); } }); } @@ -51,11 +53,11 @@ public void testGetRelative() { for (int i = 0; i < TOT; ++i) { for (int k = 0; k < TOT; ++k) { final IndexCursor value = index.get(new Object[] { i, k }); - Assertions.assertTrue(value.hasNext(), "id[" + i + "," + k + "]"); + assertThat(value.hasNext()).withFailMessage("id[" + i + "," + k + "]").isTrue(); final Vertex v = value.next().asVertex(); - Assertions.assertEquals(i, v.get("directoryId")); - Assertions.assertEquals(k, v.get("fileId")); + assertThat(v.get("directoryId")).isEqualTo(i); + assertThat(v.get("fileId")).isEqualTo(k); } } }); @@ -67,10 +69,10 @@ public void testPartialNullGet() { final TypeIndex index = database.getSchema().getType("File").getIndexesByProperties("directoryId", "fileId").get(0); for (int i = 0; i < TOT; ++i) { final IndexCursor value = index.get(new Object[] { i, null }); - Assertions.assertTrue(value.hasNext(), "id[" + i + "]"); + assertThat(value.hasNext()).withFailMessage( "id[" + i + "]").isTrue(); final Vertex v = value.next().asVertex(); - Assertions.assertEquals(i, v.get("directoryId")); + assertThat(v.get("directoryId")).isEqualTo(i); } }); } @@ -78,7 +80,7 @@ public void testPartialNullGet() { protected void beginTest() { // CREATE SIMPLE GRAPH OF 2 LEVELS DIRECTORY FILE SYSTEM database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType("File")); + assertThat(database.getSchema().existsType("File")).isFalse(); final DocumentType file = database.getSchema().createVertexType("File"); file.createProperty("absoluteId", Integer.class); file.createProperty("directoryId", Integer.class); @@ -88,7 +90,7 @@ protected void beginTest() { file.setBucketSelectionStrategy(new RoundRobinBucketSelectionStrategy()); - Assertions.assertFalse(database.getSchema().existsType("HasChildren")); + assertThat(database.getSchema().existsType("HasChildren")).isFalse(); database.getSchema().createEdgeType("HasChildren"); database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, "HasChildren", "@out", "@in"); diff --git a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexPolymorphicTest.java b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexPolymorphicTest.java index 3394f0de8d..faff86c9f2 100644 --- a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexPolymorphicTest.java +++ b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexPolymorphicTest.java @@ -26,10 +26,16 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.Arrays; +import java.util.Map; + +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class LSMTreeIndexPolymorphicTest extends TestHelper { @@ -44,11 +50,11 @@ public void testPolymorphic() { final MutableDocument docChildDuplicated = database.newDocument("TestChild"); database.transaction(() -> { docChildDuplicated.set("name", "Root"); - Assertions.assertEquals("Root", docChildDuplicated.get("name")); + assertThat(docChildDuplicated.get("name")).isEqualTo("Root"); docChildDuplicated.save(); }, true, 0); - Assertions.fail("Duplicated shouldn't be allowed by unique index on sub type"); + fail("Duplicated shouldn't be allowed by unique index on sub type"); } catch (final DuplicatedKeyException e) { // EXPECTED @@ -76,15 +82,15 @@ public void testDocumentAfterCreation2() { testChild2.setSuperTypes(Arrays.asList(typeRoot2)); final MutableDocument doc = database.newDocument("TestChild2"); doc.set("name", "Document Name"); - Assertions.assertEquals("Document Name", doc.get("name")); + assertThat(doc.get("name")).isEqualTo("Document Name"); doc.save(); - Assertions.assertEquals("Document Name", doc.get("name")); + assertThat(doc.get("name")).isEqualTo("Document Name"); try (final ResultSet rs = database.query("sql", "select from TestChild2 where name = :name", Map.of("arg0", "Test2", "name", "Document Name"))) { - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Document docRetrieved = rs.next().getElement().orElse(null); - Assertions.assertEquals("Document Name", docRetrieved.get("name")); - Assertions.assertFalse(rs.hasNext()); + assertThat(docRetrieved.get("name")).isEqualTo("Document Name"); + assertThat(rs.hasNext()).isFalse(); } database.commit(); } @@ -103,15 +109,15 @@ public void testDocumentAfterCreation2AutoTx() { database.setAutoTransaction(true); final MutableDocument doc = database.newDocument("TestChild2"); doc.set("name", "Document Name"); - Assertions.assertEquals("Document Name", doc.get("name")); + assertThat(doc.get("name")).isEqualTo("Document Name"); doc.save(); - Assertions.assertEquals("Document Name", doc.get("name")); + assertThat(doc.get("name")).isEqualTo("Document Name"); try (final ResultSet rs = database.query("sql", "select from TestChild2 where name = :name", Map.of("arg0", "Test2", "name", "Document Name"))) { - Assertions.assertTrue(rs.hasNext()); //<<<<<<----------FAILING HERE + assertThat(rs.hasNext()).isTrue(); //<<<<<<----------FAILING HERE final Document docRetrieved = rs.next().getElement().orElse(null); - Assertions.assertEquals("Document Name", docRetrieved.get("name")); - Assertions.assertFalse(rs.hasNext()); + assertThat(docRetrieved.get("name")).isEqualTo("Document Name"); + assertThat(rs.hasNext()).isFalse(); } } @@ -127,62 +133,62 @@ private void populate(final Schema.INDEX_TYPE indexType) { final MutableDocument docRoot = database.newDocument("TestRoot"); database.transaction(() -> { docRoot.set("name", "Root"); - Assertions.assertEquals("Root", docRoot.get("name")); + assertThat(docRoot.get("name")).isEqualTo("Root"); docRoot.save(); }); - Assertions.assertEquals("Root", docRoot.get("name")); + assertThat(docRoot.get("name")).isEqualTo("Root"); final MutableDocument docChild = database.newDocument("TestChild"); database.transaction(() -> { docChild.set("name", "Child"); - Assertions.assertEquals("Child", docChild.get("name")); + assertThat(docChild.get("name")).isEqualTo("Child"); docChild.save(); }); - Assertions.assertEquals("Child", docChild.get("name")); + assertThat(docChild.get("name")).isEqualTo("Child"); } private void checkQueries() { try (final ResultSet rs = database.query("sql", "select from TestRoot where name <> :name", Map.of("arg0", "Test2", "name", "Nonsense"))) { - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Document doc1Retrieved = rs.next().getElement().orElse(null); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Document doc2Retrieved = rs.next().getElement().orElse(null); if (doc1Retrieved.getTypeName().equals("TestRoot")) - Assertions.assertEquals("Root", doc1Retrieved.get("name")); + assertThat(doc1Retrieved.get("name")).isEqualTo("Root"); else if (doc2Retrieved.getTypeName().equals("TestChild")) - Assertions.assertEquals("Child", doc2Retrieved.get("name")); + assertThat(doc2Retrieved.get("name")).isEqualTo("Child"); else - Assertions.fail(); + fail(""); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); } try (final ResultSet rs = database.query("sql", "select from TestChild where name = :name", Map.of("arg0", "Test2", "name", "Child"))) { - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Document doc1Retrieved = rs.next().getElement().orElse(null); - Assertions.assertEquals("Child", doc1Retrieved.get("name")); - Assertions.assertFalse(rs.hasNext()); + assertThat(doc1Retrieved.get("name")).isEqualTo("Child"); + assertThat(rs.hasNext()).isFalse(); } typeChild.removeSuperType(typeRoot); try (final ResultSet rs = database.query("sql", "select from TestChild where name = :name", Map.of("arg0", "Test2", "name", "Child"))) { - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Document doc1Retrieved = rs.next().getElement().orElse(null); - Assertions.assertEquals("Child", doc1Retrieved.get("name")); - Assertions.assertFalse(rs.hasNext()); + assertThat(doc1Retrieved.get("name")).isEqualTo("Child"); + assertThat(rs.hasNext()).isFalse(); } try (final ResultSet rs = database.query("sql", "select from TestRoot where name <> :name", Map.of("arg0", "Test2", "name", "Nonsense"))) { - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Document doc1Retrieved = rs.next().getElement().orElse(null); - Assertions.assertEquals("Root", doc1Retrieved.get("name")); - Assertions.assertFalse(rs.hasNext()); + assertThat(doc1Retrieved.get("name")).isEqualTo("Root"); + assertThat(rs.hasNext()).isFalse(); } } } diff --git a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexTest.java b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexTest.java index 205ba3256d..b6a0c89e7f 100644 --- a/engine/src/test/java/com/arcadedb/index/LSMTreeIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/LSMTreeIndexTest.java @@ -18,6 +18,7 @@ */ package com.arcadedb.index; +import com.arcadedb.GlobalConfiguration; import com.arcadedb.TestHelper; import com.arcadedb.database.Document; import com.arcadedb.database.Identifiable; @@ -30,13 +31,16 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class LSMTreeIndexTest extends TestHelper { private static final int TOT = 100000; private static final String TYPE_NAME = "V"; @@ -61,11 +65,11 @@ public void testGet() { } total++; - Assertions.assertEquals(1, results.size()); - Assertions.assertEquals(i, (int) results.get(0)); + assertThat(results).hasSize(1); + assertThat((int) results.get(0)).isEqualTo(i); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); }); } @@ -81,23 +85,23 @@ public void testGetAsRange() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterator) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertEquals(i, fieldValue); + assertThat(fieldValue).isEqualTo(i); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -106,7 +110,7 @@ public void testGetAsRange() { } } - Assertions.assertEquals(1, total, "Get item with id=" + i); + assertThat(total).withFailMessage("Get item with id=" + i).isEqualTo(1); } }); } @@ -123,28 +127,28 @@ public void testRangeFromHead() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; iterator = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i + 1 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= i && fieldValue <= i + 1); + assertThat(fieldValue >= i && fieldValue <= i + 1).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); ++total; } } - Assertions.assertEquals(2, total, "range " + i + "-" + (i + 1)); + assertThat(total).withFailMessage("range " + i + "-" + (i + 1)).isEqualTo(2); } }); } @@ -162,28 +166,28 @@ public void testRangeFromHead() { // for (Index index : indexes) { // if( index instanceof TypeIndex) // continue; -// Assertions.assertNotNull(index); +// Assertions.assertThat(index).isNotNull(); // // final IndexCursor iterator; // iterator = ((RangeIndex) index).range(new Object[] { i }, true, new Object[] { i - 1 }, true); -// Assertions.assertNotNull(iterator); +// Assertions.assertThat(iterator).isNotNull(); // // while (iterator.hasNext()) { // Identifiable value = iterator.next(); // -// Assertions.assertNotNull(value); +// Assertions.assertThat(value).isNotNull(); // // int fieldValue = (int) value.asDocument().get("id"); -// Assertions.assertTrue(fieldValue >= i - 1 && fieldValue <= i); +// Assertions.assertThat(fieldValue >= i - 1 && fieldValue <= i).isTrue(); // -// Assertions.assertNotNull(iterator.getKeys()); -// Assertions.assertEquals(1, iterator.getKeys().length); +// Assertions.assertThat(iterator.getKeys()).isNotNull(); +// Assertions.assertThat(iterator.getKeys().length).isEqualTo(1); // // ++total; // } // } // -// Assertions.assertEquals(2, total, "range " + i + "-" + (i - 1)); +// Assertions.assertThat(total).isEqualTo(2, within("range " + i + "-" + (i - 1))); // } // } // }); @@ -213,17 +217,18 @@ public void testRemoveKeys() { } } - Assertions.assertEquals(1, found, "Key '" + Arrays.toString(key) + "' found " + found + " times"); + assertThat(found).isEqualTo(1).withFailMessage("Key '" + Arrays.toString(key) + "' found " + found + " times"); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); // GET EACH ITEM TO CHECK IT HAS BEEN DELETED for (int i = 0; i < TOT; ++i) { for (final Index index : indexes) { if (index instanceof TypeIndex) continue; - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i + " inside the TX by using get()"); + assertThat(index.get(new Object[] { i }).hasNext()).isFalse() + .withFailMessage("Found item with key " + i + " inside the TX by using get()"); } } @@ -235,7 +240,7 @@ public void testRemoveKeys() { // continue; // final IndexCursor cursor = ((RangeIndex) index).range(new Object[] { i }, true, new Object[] { i }, true); // -// Assertions.assertFalse(cursor.hasNext() && cursor.next() != null, "Found item with key " + i + " inside the TX by using range()"); +// Assertions.assertThat(cursor.hasNext() && cursor.next().isFalse() != null, "Found item with key " + i + " inside the TX by using range()"); // } // } }, true, 0); @@ -247,7 +252,9 @@ public void testRemoveKeys() { for (final Index index : indexes) { if (index instanceof TypeIndex) continue; - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i + " after the TX was committed"); + assertThat(index.get(new Object[] { i }).hasNext()) + .withFailMessage("Found item with key " + i + " after the TX was committed") + .isFalse(); } } @@ -258,7 +265,9 @@ public void testRemoveKeys() { continue; final IndexCursor cursor = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i }, true); - Assertions.assertFalse(cursor.hasNext() && cursor.next() != null, "Found item with key " + i + " after the TX was committed by using range()"); + + assertThat(cursor.hasNext() && cursor.next() != null).isFalse() + .withFailMessage("Found item with key " + i + " after the TX was committed by using range()"); } } }, true, 0); @@ -289,10 +298,12 @@ public void testRemoveEntries() { } } - Assertions.assertEquals(1, found, "Key '" + Arrays.toString(key) + "' found " + found + " times"); + assertThat(found) + .withFailMessage("Key '" + Arrays.toString(key) + "' found " + found + " times") + .isEqualTo(1); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); // GET EACH ITEM TO CHECK IT HAS BEEN DELETED for (int i = 0; i < TOT; ++i) { @@ -300,7 +311,7 @@ public void testRemoveEntries() { if (index instanceof TypeIndex) continue; - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i); + assertThat(index.get(new Object[] { i }).hasNext()).withFailMessage("Found item with key " + i).isFalse(); } } @@ -311,7 +322,7 @@ public void testRemoveEntries() { // if (index instanceof TypeIndex) // continue; // -// Assertions.assertFalse(((RangeIndex) index).range(new Object[] { i }, true, new Object[] { i }, true).hasNext(), +// Assertions.assertThat(((RangeIndex) index).isFalse().range(new Object[] { i }, true, new Object[] { i }, true).hasNext(), // "Found item with key " + i + " inside the TX by using range()"); // } // } @@ -325,7 +336,9 @@ public void testRemoveEntries() { if (index instanceof TypeIndex) continue; - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i + " after the TX was committed"); + assertThat(index.get(new Object[] { i }).hasNext()) + .withFailMessage("Found item with key " + i + " after the TX was committed") + .isFalse(); } } @@ -336,7 +349,10 @@ public void testRemoveEntries() { continue; final IndexCursor cursor = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i }, true); - Assertions.assertFalse(cursor.hasNext() && cursor.next() != null, "Found item with key " + i + " after the TX was committed by using range()"); + + assertThat(cursor.hasNext() && cursor.next() != null) + .withFailMessage("Found item with key " + i + " after the TX was committed by using range()") + .isFalse(); } } }, true, 0); @@ -369,10 +385,10 @@ public void testRemoveEntriesMultipleTimes() { } } - Assertions.assertEquals(1, found, "Key '" + Arrays.toString(key) + "' found " + found + " times"); + assertThat(found).isEqualTo(1).withFailMessage("Key '" + Arrays.toString(key) + "' found " + found + " times"); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); // GET EACH ITEM TO CHECK IT HAS BEEN DELETED for (int i = 0; i < TOT; ++i) { @@ -380,7 +396,7 @@ public void testRemoveEntriesMultipleTimes() { if (index instanceof TypeIndex) continue; - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i); + assertThat(index.get(new Object[] { i }).hasNext()).isFalse().withFailMessage("Found item with key " + i); } } }); @@ -416,10 +432,10 @@ public void testRemoveAndPutEntries() { } } - Assertions.assertEquals(1, found, "Key '" + Arrays.toString(key) + "' found " + found + " times"); + assertThat(found).isEqualTo(1).withFailMessage("Key '" + Arrays.toString(key) + "' found " + found + " times"); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); // GET EACH ITEM TO CHECK IT HAS BEEN DELETED for (int i = 0; i < TOT; ++i) { @@ -427,7 +443,7 @@ public void testRemoveAndPutEntries() { if (index instanceof TypeIndex) continue; - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i); + assertThat(index.get(new Object[] { i }).hasNext()).isFalse().withFailMessage("Found item with key " + i); } } }); @@ -441,7 +457,7 @@ public void testRemoveAndPutEntries() { if (index instanceof TypeIndex) continue; - Assertions.assertTrue(index.get(new Object[] { i }).hasNext(), "Cannot find item with key " + i); + assertThat(index.get(new Object[] { i }).hasNext()).isTrue().withFailMessage("Cannot find item with key " + i); } } }); @@ -452,7 +468,7 @@ public void testChangePrimaryKeySameTx() { database.transaction(() -> { for (int i = 0; i < 1000; ++i) { final IndexCursor cursor = database.lookupByKey(TYPE_NAME, "id", i); - Assertions.assertTrue(cursor.hasNext(), "Key " + i + " not found"); + assertThat(cursor.hasNext()).isTrue().withFailMessage("Key " + i + " not found"); final Document doc = cursor.next().asDocument(); doc.modify().set("id", i + TOT).save(); @@ -465,20 +481,20 @@ public void testDeleteCreateSameKeySameTx() { database.transaction(() -> { for (int i = 0; i < 1000; ++i) { final IndexCursor cursor = database.lookupByKey(TYPE_NAME, "id", i); - Assertions.assertTrue(cursor.hasNext(), "Key " + i + " not found"); + assertThat(cursor.hasNext()).withFailMessage("Key " + i + " not found").isTrue(); final Document doc = cursor.next().asDocument(); doc.delete(); database.newDocument(TYPE_NAME).fromMap(doc.toMap()).set("version", 2).save(); } - }, true, 0); + }, true, 2); database.transaction(() -> { for (int i = 0; i < 1000; ++i) { final IndexCursor cursor = database.lookupByKey(TYPE_NAME, "id", i); - Assertions.assertTrue(cursor.hasNext(), "Key " + i + " not found"); - Assertions.assertEquals(2, cursor.next().asDocument().getInteger("version")); + assertThat(cursor.hasNext()).withFailMessage("Key " + i + " not found").isTrue(); + assertThat(cursor.next().asDocument().getInteger("version")).isEqualTo(2); } }); } @@ -492,7 +508,7 @@ public void testUpdateKeys() { for (final ResultSet it = resultSet; it.hasNext(); ) { final Result r = it.next(); - Assertions.assertNotNull(r.getElement().get().get("id")); + assertThat(r.getElement().get().get("id")).isNotNull(); final MutableDocument record = r.getElement().get().modify(); record.set("id", (Integer) record.get("id") + 1000000); @@ -521,10 +537,10 @@ public void testUpdateKeys() { } } - Assertions.assertEquals(0, found, "Key '" + Arrays.toString(key) + "' found " + found + " times"); + assertThat(found).isEqualTo(0).withFailMessage("Key '" + Arrays.toString(key) + "' found " + found + " times"); } - Assertions.assertEquals(0, total); + assertThat(total).isEqualTo(0); total = 0; @@ -549,15 +565,16 @@ public void testUpdateKeys() { } } - Assertions.assertEquals(1, found, "Key '" + Arrays.toString(key) + "' found " + found + " times"); + assertThat(found).withFailMessage("Key '" + Arrays.toString(key) + "' found " + found + " times").isEqualTo(1); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); // GET EACH ITEM TO CHECK IT HAS BEEN DELETED for (int i = 0; i < TOT; ++i) { for (final Index index : indexes) - Assertions.assertFalse(index.get(new Object[] { i }).hasNext(), "Found item with key " + i); + assertThat(index.get(new Object[] { i }).hasNext()).withFailMessage("Found item with key " + i).isFalse(); + ; } }); @@ -594,10 +611,10 @@ public void testPutDuplicates() { } } - Assertions.assertEquals(1, found, "Key '" + Arrays.toString(key) + "' found " + found + " times"); + assertThat(found).withFailMessage("Key '" + Arrays.toString(key) + "' found " + found + " times").isEqualTo(1); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); }); } @@ -619,22 +636,21 @@ public void testScanIndexAscending() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); - final IndexCursor iterator; try { - iterator = ((RangeIndex) index).iterator(true); + final IndexCursor iterator = ((RangeIndex) index).iterator(true); // LogManager.instance() // .log(this, Level.INFO, "*****************************************************************************\nCURSOR BEGIN%s", iterator.dumpStats()); - Assertions.assertNotNull(iterator); + assertThat((Iterator) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -647,7 +663,7 @@ public void testScanIndexAscending() { } } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); }); } @@ -669,23 +685,23 @@ public void testScanIndexDescending() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); - final IndexCursor iterator; try { - iterator = ((RangeIndex) index).iterator(false); - Assertions.assertNotNull(iterator); + final IndexCursor iterator = ((RangeIndex) index).iterator(false); + assertThat((Iterator) iterator).isNotNull(); Object prevKey = null; while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); final Object[] keys = iterator.getKeys(); - Assertions.assertNotNull(keys); - Assertions.assertEquals(1, keys.length); + assertThat(keys).isNotNull(); + assertThat(keys.length).isEqualTo(1); if (prevKey != null) - Assertions.assertTrue(((Comparable) keys[0]).compareTo(prevKey) < 0, "Key " + keys[0] + " is not minor than " + prevKey); + assertThat(((Comparable) keys[0]).compareTo(prevKey) < 0).withFailMessage( + "Key " + keys[0] + " is not minor than " + prevKey).isTrue(); prevKey = keys[0]; ++total; @@ -696,7 +712,7 @@ public void testScanIndexDescending() { } } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); }); } @@ -710,19 +726,19 @@ public void testScanIndexAscendingPartialInclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(true, new Object[] { 10 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -731,7 +747,7 @@ public void testScanIndexAscendingPartialInclusive() { } } - Assertions.assertEquals(TOT - 10, total); + assertThat(total).isEqualTo(TOT - 10); }); } @@ -745,19 +761,19 @@ public void testScanIndexAscendingPartialExclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(true, new Object[] { 10 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -766,7 +782,7 @@ public void testScanIndexAscendingPartialExclusive() { } } - Assertions.assertEquals(TOT - 11, total); + assertThat(total).isEqualTo(TOT - 11); }); } @@ -780,18 +796,18 @@ public void testScanIndexDescendingPartialInclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(false, new Object[] { 9 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -800,7 +816,7 @@ public void testScanIndexDescendingPartialInclusive() { } } - Assertions.assertEquals(10, total); + assertThat(total).isEqualTo(10); }); } @@ -814,18 +830,18 @@ public void testScanIndexDescendingPartialExclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(false, new Object[] { 9 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -834,7 +850,7 @@ public void testScanIndexDescendingPartialExclusive() { } } - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); }); } @@ -848,23 +864,23 @@ public void testScanIndexRangeInclusive2Inclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, true, new Object[] { 19 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= 10 && fieldValue <= 19); + assertThat(fieldValue >= 10 && fieldValue <= 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -873,7 +889,7 @@ public void testScanIndexRangeInclusive2Inclusive() { } } - Assertions.assertEquals(10, total); + assertThat(total).isEqualTo(10); }); } @@ -887,23 +903,23 @@ public void testScanIndexRangeInclusive2Exclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, true, new Object[] { 19 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= 10 && fieldValue < 19); + assertThat(fieldValue >= 10 && fieldValue < 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -912,7 +928,7 @@ public void testScanIndexRangeInclusive2Exclusive() { } } - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); }); } @@ -926,23 +942,23 @@ public void testScanIndexRangeExclusive2Inclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, false, new Object[] { 19 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue > 10 && fieldValue <= 19); + assertThat(fieldValue > 10 && fieldValue <= 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -951,7 +967,7 @@ public void testScanIndexRangeExclusive2Inclusive() { } } - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); }); } @@ -965,23 +981,23 @@ public void testScanIndexRangeExclusive2Exclusive() { if (index instanceof TypeIndex) continue; - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, false, new Object[] { 19 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue > 10 && fieldValue < 19); + assertThat(fieldValue > 10 && fieldValue < 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -990,7 +1006,7 @@ public void testScanIndexRangeExclusive2Exclusive() { } } - Assertions.assertEquals(8, total); + assertThat(total).isEqualTo(8); }); } @@ -1041,34 +1057,39 @@ public void run() { crossThreadsInserted.incrementAndGet(); if (threadInserted % 1000 == 0) - LogManager.instance().log(this, Level.INFO, "%s Thread %d inserted record %s, total %d records with key %d (total=%d)", null, getClass(), - Thread.currentThread().getId(), v.getIdentity(), i, threadInserted, crossThreadsInserted.get()); + LogManager.instance() + .log(this, Level.INFO, "%s Thread %d inserted record %s, total %d records with key %d (total=%d)", null, + getClass(), + Thread.currentThread().getId(), v.getIdentity(), i, threadInserted, crossThreadsInserted.get()); keyPresent = true; } catch (final NeedRetryException e) { needRetryExceptions.incrementAndGet(); - Assertions.assertFalse(database.isTransactionActive()); + assertThat(database.isTransactionActive()).isFalse(); continue; } catch (final DuplicatedKeyException e) { duplicatedExceptions.incrementAndGet(); keyPresent = true; - Assertions.assertFalse(database.isTransactionActive()); + assertThat(database.isTransactionActive()).isFalse(); } catch (final Exception e) { - LogManager.instance().log(this, Level.SEVERE, "%s Thread %d Generic Exception", e, getClass(), Thread.currentThread().getId()); - Assertions.assertFalse(database.isTransactionActive()); + LogManager.instance() + .log(this, Level.SEVERE, "%s Thread %d Generic Exception", e, getClass(), Thread.currentThread().getId()); + assertThat(database.isTransactionActive()).isFalse(); return; } } if (!keyPresent) - LogManager.instance().log(this, Level.WARNING, "%s Thread %d Cannot create key %d after %d retries! (total=%d)", null, getClass(), - Thread.currentThread().getId(), i, maxRetries, crossThreadsInserted.get()); + LogManager.instance() + .log(this, Level.WARNING, "%s Thread %d Cannot create key %d after %d retries! (total=%d)", null, getClass(), + Thread.currentThread().getId(), i, maxRetries, crossThreadsInserted.get()); } LogManager.instance() - .log(this, Level.INFO, "%s Thread %d completed (inserted=%d)", null, getClass(), Thread.currentThread().getId(), threadInserted); + .log(this, Level.INFO, "%s Thread %d completed (inserted=%d)", null, getClass(), Thread.currentThread().getId(), + threadInserted); } catch (final Exception e) { LogManager.instance().log(this, Level.SEVERE, "%s Thread %d Error", e, getClass(), Thread.currentThread().getId()); @@ -1090,7 +1111,8 @@ public void run() { } LogManager.instance() - .log(this, Level.INFO, "%s Completed (inserted=%d needRetryExceptions=%d duplicatedExceptions=%d)", null, getClass(), crossThreadsInserted.get(), + .log(this, Level.INFO, "%s Completed (inserted=%d needRetryExceptions=%d duplicatedExceptions=%d)", null, getClass(), + crossThreadsInserted.get(), needRetryExceptions.get(), duplicatedExceptions.get()); if (total != crossThreadsInserted.get()) { @@ -1122,20 +1144,21 @@ public void run() { } } - Assertions.assertEquals(total, crossThreadsInserted.get()); -// Assertions.assertTrue(needRetryExceptions.get() > 0); - Assertions.assertTrue(duplicatedExceptions.get() > 0); + assertThat(crossThreadsInserted.get()).isEqualTo(total); +// Assertions.assertThat(needRetryExceptions.get() > 0).isTrue(); + assertThat(duplicatedExceptions.get() > 0).isTrue(); - Assertions.assertEquals(startingWith + total, database.countType(TYPE_NAME, true)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(startingWith + total); } protected void beginTest() { database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); type.createProperty("id", Integer.class); - final Index typeIndex = database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); + final Index typeIndex = database.getSchema() + .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); for (int i = 0; i < TOT; ++i) { final MutableDocument v = database.newDocument(TYPE_NAME); @@ -1150,7 +1173,7 @@ protected void beginTest() { database.begin(); for (final Index index : ((TypeIndex) typeIndex).getIndexesOnBuckets()) { - Assertions.assertTrue(((IndexInternal) index).getStats().get("pages") > 1); + assertThat(((IndexInternal) index).getStats().get("pages") > 1).isTrue(); } }); } diff --git a/engine/src/test/java/com/arcadedb/index/MultipleTypesIndexTest.java b/engine/src/test/java/com/arcadedb/index/MultipleTypesIndexTest.java index 8dd1922f52..9ae6968292 100644 --- a/engine/src/test/java/com/arcadedb/index/MultipleTypesIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/MultipleTypesIndexTest.java @@ -25,11 +25,14 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + public class MultipleTypesIndexTest extends TestHelper { private static final int TOT = 100000; private static final String TYPE_NAME = "Profile"; @@ -40,38 +43,38 @@ public void testCollection() { final Index index = database.getSchema().getIndexByName(TYPE_NAME + "[keywords]"); IndexCursor cursor = index.get(new Object[] { List.of("ceo", "tesla", "spacex", "boring", "neuralink", "twitter") }); - Assertions.assertTrue(cursor.hasNext()); - Assertions.assertEquals("Musk", cursor.next().asVertex().getString("lastName")); - Assertions.assertFalse(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); + assertThat(cursor.next().asVertex().getString("lastName")).isEqualTo("Musk"); + assertThat(cursor.hasNext()).isFalse(); ResultSet resultset = database.query("sql", "select from " + TYPE_NAME + " where keywords CONTAINS ?", "tesla"); - Assertions.assertTrue(resultset.hasNext()); - Assertions.assertEquals("Musk", resultset.next().toElement().asVertex().getString("lastName")); - Assertions.assertFalse(resultset.hasNext()); + assertThat(resultset.hasNext()).isTrue(); + assertThat(resultset.next().toElement().asVertex().getString("lastName")).isEqualTo("Musk"); + assertThat(resultset.hasNext()).isFalse(); resultset = database.query("sql", "select from " + TYPE_NAME + " where 'tesla' IN keywords"); - Assertions.assertTrue(resultset.hasNext()); - Assertions.assertEquals("Musk", resultset.next().toElement().asVertex().getString("lastName")); - Assertions.assertFalse(resultset.hasNext()); + assertThat(resultset.hasNext()).isTrue(); + assertThat(resultset.next().toElement().asVertex().getString("lastName")).isEqualTo("Musk"); + assertThat(resultset.hasNext()).isFalse(); resultset = database.query("sql", "select from " + TYPE_NAME + " where ? IN keywords", "tesla"); - Assertions.assertTrue(resultset.hasNext()); - Assertions.assertEquals("Musk", resultset.next().toElement().asVertex().getString("lastName")); - Assertions.assertFalse(resultset.hasNext()); + assertThat(resultset.hasNext()).isTrue(); + assertThat(resultset.next().toElement().asVertex().getString("lastName")).isEqualTo("Musk"); + assertThat(resultset.hasNext()).isFalse(); cursor = index.get(new Object[] { List.of("inventor", "commodore", "amiga", "atari", "80s") }); - Assertions.assertTrue(cursor.hasNext()); - Assertions.assertEquals("Jay", cursor.next().asVertex().getString("firstName")); - Assertions.assertFalse(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); + assertThat(cursor.next().asVertex().getString("firstName")).isEqualTo("Jay"); + assertThat(cursor.hasNext()).isFalse(); cursor = index.get(new Object[] { List.of("writer") }); - Assertions.assertTrue(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); int i = 0; for (; cursor.hasNext(); i++) { cursor.next(); } - Assertions.assertEquals(TOT - 2, i); + assertThat(i).isEqualTo(TOT - 2); }); } @@ -92,9 +95,9 @@ public void testNullItemInCollection() { v.save(); IndexCursor cursor = index.get(new Object[] { list }); - Assertions.assertTrue(cursor.hasNext()); - Assertions.assertEquals("Zuck", cursor.next().asVertex().getString("lastName")); - Assertions.assertFalse(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); + assertThat(cursor.next().asVertex().getString("lastName")).isEqualTo("Zuck"); + assertThat(cursor.hasNext()).isFalse(); }); } @@ -118,7 +121,7 @@ public void testUpdateCompositeKeyIndex() { protected void beginTest() { database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildVertexType().withName(TYPE_NAME).withTotalBuckets(3).create(); type.createProperty("id", Integer.class); diff --git a/engine/src/test/java/com/arcadedb/index/NullValuesIndexTest.java b/engine/src/test/java/com/arcadedb/index/NullValuesIndexTest.java index 80875d6442..ac71d226e4 100644 --- a/engine/src/test/java/com/arcadedb/index/NullValuesIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/NullValuesIndexTest.java @@ -26,9 +26,13 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.VertexType; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class NullValuesIndexTest extends TestHelper { private static final int TOT = 10; private static final String TYPE_NAME = "V"; @@ -36,14 +40,16 @@ public class NullValuesIndexTest extends TestHelper { @Test public void testNullStrategyError() { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); type.createProperty("id", Integer.class); type.createProperty("name", String.class); - final Index indexes = database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); + final Index indexes = database.getSchema() + .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); final Index indexes2 = database.getSchema() - .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, false, TYPE_NAME, new String[] { "name" }, PAGE_SIZE, LSMTreeIndexAbstract.NULL_STRATEGY.ERROR, null); + .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, false, TYPE_NAME, new String[] { "name" }, PAGE_SIZE, + LSMTreeIndexAbstract.NULL_STRATEGY.ERROR, null); try { database.transaction(() -> { @@ -63,26 +69,28 @@ public void testNullStrategyError() { database.begin(); for (final Index index : ((TypeIndex) indexes).getIndexesOnBuckets()) { - Assertions.assertTrue(((IndexInternal) index).getStats().get("pages") > 1); + assertThat(((IndexInternal) index).getStats().get("pages") > 1).isTrue(); } }); - Assertions.fail(); + fail(""); } catch (final TransactionException e) { - Assertions.assertTrue(e.getCause() instanceof IllegalArgumentException); - Assertions.assertTrue(e.getCause().getMessage().startsWith("Indexed key V[name] cannot be NULL")); + assertThat(e.getCause() instanceof IllegalArgumentException).isTrue(); + assertThat(e.getCause().getMessage().startsWith("Indexed key V[name] cannot be NULL")).isTrue(); } } @Test public void testNullStrategySkip() { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); type.createProperty("id", Integer.class); type.createProperty("name", String.class); - final Index indexes = database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); + final Index indexes = database.getSchema() + .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); final Index indexes2 = database.getSchema() - .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, false, TYPE_NAME, new String[] { "name" }, PAGE_SIZE, LSMTreeIndexAbstract.NULL_STRATEGY.SKIP, null); + .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, false, TYPE_NAME, new String[] { "name" }, PAGE_SIZE, + LSMTreeIndexAbstract.NULL_STRATEGY.SKIP, null); database.transaction(() -> { for (int i = 0; i < TOT; ++i) { @@ -101,14 +109,16 @@ public void testNullStrategySkip() { database.begin(); }); - database.transaction(() -> Assertions.assertEquals(database.countType(TYPE_NAME, true), TOT + 1)); + database.transaction(() -> assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT + 1)); database.close(); database = factory.open(); // TRY AGAIN WITH A RE-OPEN DATABASE database.transaction(() -> { - Assertions.assertTrue(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isTrue(); + + assertThat(database.getSchema().existsType(TYPE_NAME)).isTrue(); for (int i = TOT + 2; i < TOT + TOT; ++i) { final MutableDocument v = database.newDocument(TYPE_NAME); @@ -125,20 +135,22 @@ public void testNullStrategySkip() { database.commit(); database.begin(); }); - - database.transaction(() -> Assertions.assertEquals(database.countType(TYPE_NAME, true), TOT + TOT)); + database.transaction(() -> assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT + TOT)); } @Test public void testNullStrategySkipUnique() { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); + + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final VertexType type = database.getSchema().buildVertexType().withName(TYPE_NAME).withTotalBuckets(3).create(); type.createProperty("id", Integer.class); type.createProperty("absent", String.class); database.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "id" }, PAGE_SIZE); database.getSchema() - .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "absent" }, PAGE_SIZE, LSMTreeIndexAbstract.NULL_STRATEGY.SKIP, null); + .createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, TYPE_NAME, new String[] { "absent" }, PAGE_SIZE, + LSMTreeIndexAbstract.NULL_STRATEGY.SKIP, null); database.transaction(() -> { for (int i = 0; i < TOT; ++i) { @@ -153,14 +165,14 @@ public void testNullStrategySkipUnique() { database.begin(); }); - database.transaction(() -> Assertions.assertEquals(database.countType(TYPE_NAME, true), TOT)); + database.transaction(() -> assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT)); database.close(); database = factory.open(); // TRY AGAIN WITH A RE-OPEN DATABASE database.transaction(() -> { - Assertions.assertTrue(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isTrue(); for (int i = TOT; i < TOT + TOT; ++i) { final MutableVertex v = database.newVertex(TYPE_NAME); @@ -174,6 +186,6 @@ public void testNullStrategySkipUnique() { database.begin(); }); - database.transaction(() -> Assertions.assertEquals(database.countType(TYPE_NAME, true), TOT + TOT)); + database.transaction(() -> assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT + TOT)); } } diff --git a/engine/src/test/java/com/arcadedb/index/PlainLuceneFullTextIndexTest.java b/engine/src/test/java/com/arcadedb/index/PlainLuceneFullTextIndexTest.java index 95a198016b..9ec14fe62b 100644 --- a/engine/src/test/java/com/arcadedb/index/PlainLuceneFullTextIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/PlainLuceneFullTextIndexTest.java @@ -34,12 +34,13 @@ import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; import org.apache.lucene.store.FSDirectory; -import org.junit.jupiter.api.Assertions; import java.io.*; import java.nio.file.*; import java.util.stream.*; +import static org.assertj.core.api.Assertions.assertThat; + public class PlainLuceneFullTextIndexTest { public static void main(String[] args) throws IOException, ParseException { final Path path = Paths.get("./target/databases/testIndex"); @@ -102,7 +103,7 @@ public static void main(String[] args) throws IOException, ParseException { final Query query = parser.parse("elec*"); final ScoreDoc[] hits = searcher.search(query, 1000, Sort.RELEVANCE).scoreDocs; - Assertions.assertEquals(501, hits.length); + assertThat(hits.length).isEqualTo(501); // Iterate through the results: for (int i = 0; i < hits.length; i++) { final Document hitDoc = searcher.doc(hits[i].doc); diff --git a/engine/src/test/java/com/arcadedb/index/TypeLSMTreeIndexTest.java b/engine/src/test/java/com/arcadedb/index/TypeLSMTreeIndexTest.java index 73e54d2ffb..0db18c6c51 100644 --- a/engine/src/test/java/com/arcadedb/index/TypeLSMTreeIndexTest.java +++ b/engine/src/test/java/com/arcadedb/index/TypeLSMTreeIndexTest.java @@ -32,13 +32,17 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + public class TypeLSMTreeIndexTest extends TestHelper { private static final int TOT = 100000; private static final String TYPE_NAME = "V"; @@ -61,51 +65,17 @@ public void testGet() { } total++; - Assertions.assertEquals(1, results.size()); - Assertions.assertEquals(i, (int) results.get(0)); + assertThat(results).hasSize(1); + assertThat((int) results.get(0)).isEqualTo(i); } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); }); } @Test public void testGetAsRange() { - database.transaction(() -> { - - final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); - for (int i = 0; i < TOT; ++i) { - int total = 0; - - for (final Index index : indexes) { - Assertions.assertNotNull(index); - - final IndexCursor iterator; - try { - iterator = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i }, true); - Assertions.assertNotNull(iterator); - - while (iterator.hasNext()) { - final Identifiable value = iterator.next(); - - Assertions.assertNotNull(value); - - final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertEquals(i, fieldValue); - - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); - - total++; - } - } catch (final Exception e) { - Assertions.fail(e); - } - } - - Assertions.assertEquals(1, total, "Get item with id=" + i); - } - }); + database.transaction(this::execute); } @Test @@ -117,28 +87,27 @@ public void testRangeFromHead() { int total = 0; for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); - final IndexCursor iterator; - iterator = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i + 1 }, true); - Assertions.assertNotNull(iterator); + final IndexCursor iterator = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i + 1 }, true); + assertThat((Iterator) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= i && fieldValue <= i + 1); + assertThat(fieldValue >= i && fieldValue <= i + 1).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); ++total; } } - Assertions.assertEquals(2, total, "range " + i + "-" + (i + 1)); + assertThat(total).isEqualTo(2).withFailMessage("range " + i + "-" + (i + 1)); } }); } @@ -152,28 +121,28 @@ public void testRangeFromTail() { int total = 0; for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; iterator = ((RangeIndex) index).range(false, new Object[] { i }, true, new Object[] { i - 1 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= i - 1 && fieldValue <= i); + assertThat(fieldValue >= i - 1 && fieldValue <= i).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); ++total; } } - Assertions.assertEquals(2, total, "range " + i + "-" + (i - 1)); + assertThat(total).isEqualTo(2). withFailMessage("range " + i + "-" + (i - 1)); } }); } @@ -184,27 +153,26 @@ public void testRangeWithSQL() { for (int i = 0; i < TOT - 1; ++i) { int total = 0; - final ResultSet iterator; try { + final ResultSet iterator; iterator = database.command("sql", "select from " + TYPE_NAME + " where id >= " + i + " and id <= " + (i + 1)); - Assertions.assertNotNull(iterator); + assertThat((Iterator) iterator).isNotNull(); while (iterator.hasNext()) { final Result value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.getProperty("id"); - Assertions.assertTrue(fieldValue >= i && fieldValue <= i + 1); + assertThat(fieldValue >= i && fieldValue <= i + 1).isTrue(); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } - - Assertions.assertEquals(2, total, "For ids >= " + i + " and <= " + (i + 1)); + assertThat(total).isEqualTo(2).withFailMessage("For ids >= " + i + " and <= " + (i + 1)); } }); } @@ -224,7 +192,7 @@ public void testScanIndexAscending() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { @@ -233,13 +201,13 @@ public void testScanIndexAscending() { // LogManager.instance() // .log(this, Level.INFO, "*****************************************************************************\nCURSOR BEGIN%s", iterator.dumpStats()); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } @@ -248,11 +216,11 @@ public void testScanIndexAscending() { // iterator.dumpStats()); } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); }); } @@ -271,29 +239,29 @@ public void testScanIndexDescending() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); //LogManager.instance().log(this, Level.INFO, "Index %s Key %s", null, index, Arrays.toString(iterator.getKeys())); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(TOT, total); + assertThat(total).isEqualTo(TOT); }); } @@ -305,28 +273,28 @@ public void testScanIndexAscendingPartialInclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(true, new Object[] { 10 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(TOT - 10, total); + assertThat(total).isEqualTo(TOT - 10); }); } @@ -338,28 +306,28 @@ public void testScanIndexAscendingPartialExclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(true, new Object[] { 10 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(TOT - 11, total); + assertThat(total).isEqualTo(TOT - 11); }); } @@ -371,27 +339,27 @@ public void testScanIndexDescendingPartialInclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(false, new Object[] { 9 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(10, total); + assertThat(total).isEqualTo(10); }); } @@ -403,27 +371,27 @@ public void testScanIndexDescendingPartialExclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).iterator(false, new Object[] { 9 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { - Assertions.assertNotNull(iterator.next()); + assertThat(iterator.next()).isNotNull(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); }); } @@ -435,32 +403,32 @@ public void testScanIndexRangeInclusive2Inclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, true, new Object[] { 19 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= 10 && fieldValue <= 19); + assertThat(fieldValue >= 10 && fieldValue <= 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(10, total); + assertThat(total).isEqualTo(10); }); } @@ -472,32 +440,32 @@ public void testScanIndexRangeInclusive2Exclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, true, new Object[] { 19 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= 10 && fieldValue < 19); + assertThat(fieldValue >= 10 && fieldValue < 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); }); } @@ -509,32 +477,32 @@ public void testScanIndexRangeExclusive2Inclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, false, new Object[] { 19 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue > 10 && fieldValue <= 19); + assertThat(fieldValue > 10 && fieldValue <= 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); }); } @@ -546,32 +514,32 @@ public void testScanIndexRangeExclusive2InclusiveInverse() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(false, new Object[] { 19 }, false, new Object[] { 10 }, true); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue >= 10 && fieldValue < 19); + assertThat(fieldValue >= 10 && fieldValue < 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); }); } @@ -583,32 +551,32 @@ public void testScanIndexRangeExclusive2Exclusive() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(true, new Object[] { 10 }, false, new Object[] { 19 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue > 10 && fieldValue < 19); + assertThat(fieldValue > 10 && fieldValue < 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(8, total); + assertThat(total).isEqualTo(8); }); } @@ -620,32 +588,32 @@ public void testScanIndexRangeExclusive2ExclusiveInverse() { final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); for (final Index index : indexes) { - Assertions.assertNotNull(index); + assertThat(index).isNotNull(); final IndexCursor iterator; try { iterator = ((RangeIndex) index).range(false, new Object[] { 19 }, false, new Object[] { 10 }, false); - Assertions.assertNotNull(iterator); + assertThat((Iterable) iterator).isNotNull(); while (iterator.hasNext()) { final Identifiable value = iterator.next(); - Assertions.assertNotNull(value); + assertThat(value).isNotNull(); final int fieldValue = (int) value.asDocument().get("id"); - Assertions.assertTrue(fieldValue > 10 && fieldValue < 19); + assertThat(fieldValue > 10 && fieldValue < 19).isTrue(); - Assertions.assertNotNull(iterator.getKeys()); - Assertions.assertEquals(1, iterator.getKeys().length); + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); total++; } } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } - Assertions.assertEquals(8, total); + assertThat(total).isEqualTo(8); }); } @@ -707,16 +675,16 @@ public void run() { } catch (final NeedRetryException e) { needRetryExceptions.incrementAndGet(); - Assertions.assertFalse(database.isTransactionActive()); + assertThat(database.isTransactionActive()).isFalse(); continue; } catch (final DuplicatedKeyException e) { duplicatedExceptions.incrementAndGet(); keyPresent = true; - Assertions.assertFalse(database.isTransactionActive()); + assertThat(database.isTransactionActive()).isFalse(); } catch (final Exception e) { LogManager.instance() .log(this, Level.SEVERE, "%s Thread %d Generic Exception", e, getClass(), Thread.currentThread().getId()); - Assertions.assertFalse(database.isTransactionActive()); + assertThat(database.isTransactionActive()).isFalse(); return; } } @@ -784,29 +752,29 @@ public void run() { } } - Assertions.assertEquals(total, crossThreadsInserted.get()); -// Assertions.assertTrue(needRetryExceptions.get() > 0); - Assertions.assertTrue(duplicatedExceptions.get() > 0); + assertThat(crossThreadsInserted.get()).isEqualTo(total); +// Assertions.assertThat(needRetryExceptions.get() > 0).isTrue(); + assertThat(duplicatedExceptions.get() > 0).isTrue(); - Assertions.assertEquals(startingWith + total, database.countType(TYPE_NAME, true)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(startingWith + total); } @Test public void testRebuildIndex() { final Index typeIndexBefore = database.getSchema().getIndexByName(TYPE_NAME + "[id]"); - Assertions.assertNotNull(typeIndexBefore); - Assertions.assertEquals(1, typeIndexBefore.getPropertyNames().size()); + assertThat(typeIndexBefore).isNotNull(); + assertThat(typeIndexBefore.getPropertyNames().size()).isEqualTo(1); database.command("sql", "rebuild index * with batchSize = 1000"); final Index typeIndexAfter = database.getSchema().getIndexByName(TYPE_NAME + "[id]"); - Assertions.assertNotNull(typeIndexAfter); - Assertions.assertEquals(1, typeIndexAfter.getPropertyNames().size()); + assertThat(typeIndexAfter).isNotNull(); + assertThat(typeIndexAfter.getPropertyNames().size()).isEqualTo(1); - Assertions.assertEquals(typeIndexBefore.getName(), typeIndexAfter.getName()); + assertThat(typeIndexAfter.getName()).isEqualTo(typeIndexBefore.getName()); - Assertions.assertTrue(typeIndexAfter.get(new Object[] { 0 }).hasNext()); - Assertions.assertEquals(0, typeIndexAfter.get(new Object[] { 0 }).next().asDocument().getInteger("id")); + assertThat(typeIndexAfter.get(new Object[] { 0 }).hasNext()).isTrue(); + assertThat(typeIndexAfter.get(new Object[] { 0 }).next().asDocument().getInteger("id")).isEqualTo(0); } @Test @@ -849,21 +817,20 @@ public void testIndexNameSpecialCharactersUsingSQL() throws InterruptedException database = factory.exists() ? factory.open() : factory.create(); database.command("sql", "rebuild index `This.is:special[other.special:property]`"); - Assertions.assertEquals("testEncoding", - database.query("sql", "select from `This.is:special` where `other.special:property` = 'testEncoding'").nextIfAvailable() - .getProperty("other.special:property")); + assertThat(database.query("sql", "select from `This.is:special` where `other.special:property` = 'testEncoding'") + .nextIfAvailable().getProperty("other.special:property")).isEqualTo("testEncoding"); } @Test public void testSQL() { final Index typeIndexBefore = database.getSchema().getIndexByName(TYPE_NAME + "[id]"); - Assertions.assertNotNull(typeIndexBefore); + assertThat(typeIndexBefore).isNotNull(); database.command("sql", "create index if not exists on " + TYPE_NAME + " (id) UNIQUE"); } protected void beginTest() { database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); type.createProperty("id", Integer.class); @@ -882,9 +849,46 @@ protected void beginTest() { database.commit(); database.begin(); - for (final Index index : ((TypeIndex) typeIndex).getIndexesOnBuckets()) { - Assertions.assertTrue(((IndexInternal) index).getStats().get("pages") > 1); + for (final IndexInternal index : ((TypeIndex) typeIndex).getIndexesOnBuckets()) { + + assertThat(index.getStats().get("pages")).isGreaterThan(1); } }); } + + private void execute() { + + final Collection indexes = database.getSchema().getType(TYPE_NAME).getAllIndexes(false); + for (int i = 0; i < TOT; ++i) { + int total = 0; + + for (final Index index : indexes) { + assertThat(index).isNotNull(); + + try { + final IndexCursor iterator; + iterator = ((RangeIndex) index).range(true, new Object[] { i }, true, new Object[] { i }, true); + assertThat((Iterable) iterator).isNotNull(); + + while (iterator.hasNext()) { + final Identifiable value = iterator.next(); + + assertThat(value).isNotNull(); + + final int fieldValue = (int) value.asDocument().get("id"); + assertThat(fieldValue).isEqualTo(i); + + assertThat(iterator.getKeys()).isNotNull(); + assertThat(iterator.getKeys().length).isEqualTo(1); + + total++; + } + } catch (final Exception e) { + fail(e); + } + } + + assertThat(total).isEqualTo(1); + } + } } diff --git a/engine/src/test/java/com/arcadedb/query/java/JavaQueryTest.java b/engine/src/test/java/com/arcadedb/query/java/JavaQueryTest.java index b791c63ee9..91a61e2ffc 100644 --- a/engine/src/test/java/com/arcadedb/query/java/JavaQueryTest.java +++ b/engine/src/test/java/com/arcadedb/query/java/JavaQueryTest.java @@ -4,10 +4,12 @@ import com.arcadedb.exception.CommandExecutionException; import com.arcadedb.query.QueryEngine; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.HashMap; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; class JavaMethods { public JavaMethods() { @@ -29,13 +31,13 @@ public static void hello() { public class JavaQueryTest extends TestHelper { @Test public void testRegisteredMethod() { - Assertions.assertEquals("java", database.getQueryEngine("java").getLanguage()); + assertThat(database.getQueryEngine("java").getLanguage()).isEqualTo("java"); database.getQueryEngine("java").registerFunctions("com.arcadedb.query.java.JavaMethods::sum"); final ResultSet result = database.command("java", "com.arcadedb.query.java.JavaMethods::sum", 5, 3); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(8, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(8); } @Test @@ -44,12 +46,12 @@ public void testRegisteredMethods() { database.getQueryEngine("java").registerFunctions("com.arcadedb.query.java.JavaMethods::SUM"); ResultSet result = database.command("java", "com.arcadedb.query.java.JavaMethods::sum", 5, 3); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(8, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(8); result = database.command("java", "com.arcadedb.query.java.JavaMethods::SUM", 5, 3); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(8, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(8); database.getQueryEngine("java").unregisterFunctions(); } @@ -59,12 +61,12 @@ public void testRegisteredClass() { database.getQueryEngine("java").registerFunctions("com.arcadedb.query.java.JavaMethods"); ResultSet result = database.command("java", "com.arcadedb.query.java.JavaMethods::sum", 5, 3); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(8, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(8); result = database.command("java", "com.arcadedb.query.java.JavaMethods::SUM", 5, 3); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(8, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(8); database.getQueryEngine("java").unregisterFunctions(); } @@ -73,10 +75,10 @@ public void testRegisteredClass() { public void testUnRegisteredMethod() { try { database.command("java", "com.arcadedb.query.java.JavaMethods::sum", 5, 3); - Assertions.fail(); + fail(""); } catch (final CommandExecutionException e) { // EXPECTED - Assertions.assertTrue(e.getCause() instanceof SecurityException); + assertThat(e.getCause() instanceof SecurityException).isTrue(); } } @@ -85,10 +87,10 @@ public void testNotExistentMethod() { database.getQueryEngine("java").registerFunctions("com.arcadedb.query.java.JavaMethods"); try { database.command("java", "com.arcadedb.query.java.JavaMethods::totallyInvented", 5, 3); - Assertions.fail(); + fail(""); } catch (final CommandExecutionException e) { // EXPECTED - Assertions.assertTrue(e.getCause() instanceof NoSuchMethodException); + assertThat(e.getCause() instanceof NoSuchMethodException).isTrue(); } } @@ -96,8 +98,8 @@ public void testNotExistentMethod() { public void testAnalyzeQuery() { database.getQueryEngine("java").registerFunctions("com.arcadedb.query.java.JavaMethods"); final QueryEngine.AnalyzedQuery analyzed = database.getQueryEngine("java").analyze("com.arcadedb.query.java.JavaMethods::totallyInvented"); - Assertions.assertFalse(analyzed.isDDL()); - Assertions.assertFalse(analyzed.isIdempotent()); + assertThat(analyzed.isDDL()).isFalse(); + assertThat(analyzed.isIdempotent()).isFalse(); } @Test @@ -105,7 +107,7 @@ public void testUnsupportedMethods() { database.getQueryEngine("java").registerFunctions("com.arcadedb.query.java.JavaMethods"); try { database.query("java", "com.arcadedb.query.java.JavaMethods::sum", 5, 3); - Assertions.fail(); + fail(""); } catch (final UnsupportedOperationException e) { // EXPECTED } @@ -115,7 +117,7 @@ public void testUnsupportedMethods() { final HashMap map = new HashMap(); map.put("name", 1); database.getQueryEngine("java").command("com.arcadedb.query.java.JavaMethods::hello", null, map); - Assertions.fail(); + fail(""); } catch (final UnsupportedOperationException e) { // EXPECTED } @@ -123,7 +125,7 @@ public void testUnsupportedMethods() { database.getQueryEngine("java").registerFunctions("com.arcadedb.query.java.JavaMethods"); try { database.getQueryEngine("java").query("com.arcadedb.query.java.JavaMethods::sum", null, new HashMap<>()); - Assertions.fail(); + fail(""); } catch (final UnsupportedOperationException e) { // EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/query/polyglot/PolyglotQueryTest.java b/engine/src/test/java/com/arcadedb/query/polyglot/PolyglotQueryTest.java index 7d904c7669..069ec452e0 100644 --- a/engine/src/test/java/com/arcadedb/query/polyglot/PolyglotQueryTest.java +++ b/engine/src/test/java/com/arcadedb/query/polyglot/PolyglotQueryTest.java @@ -9,19 +9,21 @@ import com.arcadedb.query.QueryEngine; import com.arcadedb.query.sql.executor.ResultSet; import org.graalvm.polyglot.PolyglotException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.math.*; -import java.util.*; -import java.util.concurrent.*; +import java.math.BigDecimal; +import java.util.Collections; +import java.util.concurrent.TimeoutException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class PolyglotQueryTest extends TestHelper { @Test public void testSum() { final ResultSet result = database.command("js", "3 + 5"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(8, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(8); } @Test @@ -32,11 +34,11 @@ public void testDatabaseQuery() { }); final ResultSet result = database.command("js", "database.query('sql', 'select from Product')"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Vertex vertex = result.next().getRecord().get().asVertex(); - Assertions.assertEquals("Amiga 1200", vertex.get("name")); - Assertions.assertEquals(900, vertex.get("price")); + assertThat(vertex.get("name")).isEqualTo("Amiga 1200"); + assertThat(vertex.get("price")).isEqualTo(900); } @Test @@ -44,12 +46,12 @@ public void testSandbox() { // BY DEFAULT NO JAVA PACKAGES ARE ACCESSIBLE try { final ResultSet result = database.command("js", "let BigDecimal = Java.type('java.math.BigDecimal'); new BigDecimal(1)"); - Assertions.assertFalse(result.hasNext()); - Assertions.fail("It should not execute the function"); + assertThat(result.hasNext()).isFalse(); + fail("It should not execute the function"); } catch (final Exception e) { - Assertions.assertTrue(e instanceof CommandExecutionException); - Assertions.assertTrue(e.getCause() instanceof PolyglotException); - Assertions.assertTrue(e.getCause().getMessage().contains("java.math.BigDecimal")); + assertThat(e instanceof CommandExecutionException).isTrue(); + assertThat(e.getCause() instanceof PolyglotException).isTrue(); + assertThat(e.getCause().getMessage().contains("java.math.BigDecimal")).isTrue(); } // ALLOW ACCESSING TO BIG DECIMAL CLASS @@ -59,8 +61,8 @@ public void testSandbox() { final ResultSet result = database.command("js", "let BigDecimal = Java.type('java.math.BigDecimal'); new BigDecimal(1)"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(new BigDecimal(1), result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("value")).isEqualTo(new BigDecimal(1)); } @Test @@ -68,12 +70,12 @@ public void testSandboxSystem() { // BY DEFAULT NO JAVA PACKAGES ARE ACCESSIBLE try { final ResultSet result = database.command("js", "let System = Java.type('java.lang.System'); System.exit(1)"); - Assertions.assertFalse(result.hasNext()); - Assertions.fail("It should not execute the function"); + assertThat(result.hasNext()).isFalse(); + fail("It should not execute the function"); } catch (final Exception e) { - Assertions.assertTrue(e instanceof CommandExecutionException); - Assertions.assertTrue(e.getCause() instanceof PolyglotException); - Assertions.assertTrue(e.getCause().getMessage().contains("java.lang.System")); + assertThat(e instanceof CommandExecutionException).isTrue(); + assertThat(e.getCause() instanceof PolyglotException).isTrue(); + assertThat(e.getCause().getMessage().contains("java.lang.System")).isTrue(); } } @@ -82,10 +84,10 @@ public void testTimeout() { GlobalConfiguration.POLYGLOT_COMMAND_TIMEOUT.setValue(2000); try { database.command("js", "while(true);"); - Assertions.fail("It should go in timeout"); + fail("It should go in timeout"); } catch (final Exception e) { - Assertions.assertTrue(e instanceof CommandExecutionException); - Assertions.assertTrue(e.getCause() instanceof TimeoutException); + assertThat(e instanceof CommandExecutionException).isTrue(); + assertThat(e.getCause() instanceof TimeoutException).isTrue(); } finally { GlobalConfiguration.POLYGLOT_COMMAND_TIMEOUT.reset(); } @@ -94,7 +96,7 @@ public void testTimeout() { @Test public void testAnalyzeQuery() { final QueryEngine.AnalyzedQuery analyzed = database.getQueryEngine("js").analyze("3 + 5"); - Assertions.assertFalse(analyzed.isDDL()); - Assertions.assertFalse(analyzed.isIdempotent()); + assertThat(analyzed.isDDL()).isFalse(); + assertThat(analyzed.isIdempotent()).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/select/SelectExecutionIT.java b/engine/src/test/java/com/arcadedb/query/select/SelectExecutionIT.java index 6253f9da32..6ddef7f346 100644 --- a/engine/src/test/java/com/arcadedb/query/select/SelectExecutionIT.java +++ b/engine/src/test/java/com/arcadedb/query/select/SelectExecutionIT.java @@ -25,6 +25,7 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; import com.arcadedb.serializer.json.JSONObject; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -32,6 +33,10 @@ import java.util.concurrent.*; import java.util.stream.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -57,8 +62,8 @@ protected void beginTest() { for (int i = 1; i < 100; i++) { final Vertex root = database.select().fromType("Vertex").where().property("id").eq().value(0).vertices().nextOrNull(); - Assertions.assertNotNull(root); - Assertions.assertEquals(0, root.getInteger("id")); + assertNotNull(root); + assertEquals(0, root.getInteger("id")); root.newEdge("Edge", database.select().fromType("Vertex").where().property("id").eq().value(i).vertices().nextOrNull(), true).save(); @@ -76,7 +81,7 @@ public void okFromBuckets() { .and().property("name").eq().value("Elon").compile(); for (int i = 0; i < 100; i++) - Assertions.assertEquals(i, select.parameter("value", i).vertices().nextOrNull().getInteger("id")); + assertThat(select.parameter("value", i).vertices().nextOrNull().getInteger("id")).isEqualTo(i); } { @@ -87,7 +92,7 @@ public void okFromBuckets() { .and().property("name").eq().value("Elon").compile(); for (int i = 0; i < 100; i++) - Assertions.assertEquals(i, select.parameter("value", i).vertices().nextOrNull().getInteger("id")); + assertThat(select.parameter("value", i).vertices().nextOrNull().getInteger("id")).isEqualTo(i); } } @@ -99,7 +104,7 @@ public void okAnd() { .and().property("name").eq().value("Elon").compile(); for (int i = 0; i < 100; i++) - Assertions.assertEquals(i, select.parameter("value", i).vertices().nextOrNull().getInteger("id")); + assertThat(select.parameter("value", i).vertices().nextOrNull().getInteger("id")).isEqualTo(i); } { @@ -107,7 +112,7 @@ public void okAnd() { .where().property("id").eq().parameter("value")// .and().property("name").eq().value("Elon2").compile(); - Assertions.assertFalse(select.parameter("value", 3).vertices().hasNext()); + assertThat(select.parameter("value", 3).vertices().hasNext()).isFalse(); } { @@ -115,7 +120,7 @@ public void okAnd() { .where().property("id").eq().value(-1)// .and().property("name").eq().value("Elon").compile(); - Assertions.assertFalse(select.vertices().hasNext()); + assertThat(select.vertices().hasNext()).isFalse(); } { @@ -126,7 +131,7 @@ public void okAnd() { .and().property("name").eq().value("Elon").compile(); for (int i = 0; i < 100; i++) - Assertions.assertEquals(i, select.parameter("value", i).vertices().nextOrNull().getInteger("id")); + assertThat(select.parameter("value", i).vertices().nextOrNull().getInteger("id")).isEqualTo(i); } } @@ -139,7 +144,7 @@ public void okOr() { for (SelectIterator result = select.parameter("value", 3).vertices(); result.hasNext(); ) { final Vertex v = result.next(); - Assertions.assertTrue(v.getInteger("id").equals(3) || v.getString("name").equals("Elon")); + assertThat(v.getInteger("id").equals(3) || v.getString("name").equals("Elon")).isTrue(); } } @@ -150,7 +155,7 @@ public void okOr() { for (SelectIterator result = select.parameter("value", 3).vertices(); result.hasNext(); ) { final Vertex v = result.next(); - Assertions.assertTrue(v.getInteger("id").equals(3) || v.getString("name").equals("Elon2")); + assertThat(v.getInteger("id").equals(3) || v.getString("name").equals("Elon2")).isTrue(); } } @@ -161,7 +166,7 @@ public void okOr() { for (SelectIterator result = select.parameter("value", 3).vertices(); result.hasNext(); ) { final Vertex v = result.next(); - Assertions.assertTrue(v.getInteger("id").equals(-1) || v.getString("name").equals("Elon")); + assertThat(v.getInteger("id").equals(-1) || v.getString("name").equals("Elon")).isTrue(); } } } @@ -176,8 +181,8 @@ public void okAndOr() { for (SelectIterator result = select.parameter("value", 3).vertices(); result.hasNext(); ) { final Vertex v = result.next(); - Assertions.assertTrue(v.getInteger("id").equals(3) && v.getString("name").equals("Elon2") ||// - v.getString("name").equals("Elon")); + assertThat(v.getInteger("id").equals(3) && v.getString("name").equals("Elon2") ||// + v.getString("name").equals("Elon")).isTrue(); } } @@ -189,8 +194,8 @@ public void okAndOr() { for (SelectIterator result = select.parameter("value", 3).vertices(); result.hasNext(); ) { final Vertex v = result.next(); - Assertions.assertTrue(v.getInteger("id").equals(3) ||// - v.getString("name").equals("Elon2") && v.getString("name").equals("Elon")); + assertThat(v.getInteger("id").equals(3) ||// + v.getString("name").equals("Elon2") && v.getString("name").equals("Elon")).isTrue(); } } } @@ -204,10 +209,10 @@ public void okLimit() { final SelectIterator iter = select.vertices(); int browsed = 0; while (iter.hasNext()) { - Assertions.assertTrue(iter.next().getInteger("id") < 10); + assertThat(iter.next().getInteger("id") < 10).isTrue(); ++browsed; } - Assertions.assertEquals(10, browsed); + assertThat(browsed).isEqualTo(10); } @Test @@ -219,10 +224,10 @@ public void okSkip() { SelectIterator iter = select.vertices(); int browsed = 0; while (iter.hasNext()) { - Assertions.assertTrue(iter.next().getInteger("id") < 10); + assertThat(iter.next().getInteger("id") < 10).isTrue(); ++browsed; } - Assertions.assertEquals(0, browsed); + assertThat(browsed).isEqualTo(0); select = database.select().fromType("Vertex")// .where().property("id").lt().value(10)// @@ -231,10 +236,10 @@ public void okSkip() { iter = select.vertices(); browsed = 0; while (iter.hasNext()) { - Assertions.assertTrue(iter.next().getInteger("id") < 10); + assertThat(iter.next().getInteger("id") < 10).isTrue(); ++browsed; } - Assertions.assertEquals(10, browsed); + assertThat(browsed).isEqualTo(10); select = database.select().fromType("Vertex")// .where().property("id").lt().value(10)// @@ -243,10 +248,10 @@ public void okSkip() { iter = select.vertices(); browsed = 0; while (iter.hasNext()) { - Assertions.assertTrue(iter.next().getInteger("id") < 10); + assertThat(iter.next().getInteger("id") < 10).isTrue(); ++browsed; } - Assertions.assertEquals(8, browsed); + assertThat(browsed).isEqualTo(8); } @Test @@ -262,7 +267,7 @@ public void okUpdate() { database.select().fromType("Vertex")// .where().property("id").lt().value(10)// .and().property("name").eq().value("Elon").limit(10).vertices() - .forEachRemaining(r -> Assertions.assertTrue(r.getInteger("id") < 10 && r.getBoolean("modified"))); + .forEachRemaining(r -> assertTrue(r.getInteger("id") < 10 && r.getBoolean("modified"))); } @Test @@ -299,8 +304,8 @@ public void okNeq() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(99, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getInteger("id") != finalI)); + assertThat(list.size()).isEqualTo(99); + list.forEach(r -> assertTrue(r.getInteger("id") != finalI)); } } @@ -327,8 +332,8 @@ public void okParallel() { final SelectIterator result = select.vertices(); final List list = result.toList(); - Assertions.assertEquals(1_000_000, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getString("name").startsWith("E"))); + assertThat(list.size()).isEqualTo(1_000_000); + list.forEach(r -> assertTrue(r.getString("name").startsWith("E"))); System.out.println(i + " " + (System.currentTimeMillis() - beginTime)); } @@ -342,8 +347,8 @@ public void okLike() { for (int i = 0; i < 100; i++) { final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(100, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getString("name").startsWith("E"))); + assertThat(list.size()).isEqualTo(100); + list.forEach(r -> assertTrue(r.getString("name").startsWith("E"))); } } @@ -355,8 +360,8 @@ public void okILike() { for (int i = 0; i < 100; i++) { final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(100, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getString("name").startsWith("E"))); + assertThat(list.size()).isEqualTo(100); + list.forEach(r -> assertTrue(r.getString("name").startsWith("E"))); } } @@ -373,7 +378,7 @@ public void errorMissingParameter() { public void okReuse() { final SelectCompiled select = database.select().fromType("Vertex").where().property("id").eq().parameter("value").compile(); for (int i = 0; i < 100; i++) - Assertions.assertEquals(i, select.parameter("value", i).vertices().nextOrNull().getInteger("id")); + assertThat(select.parameter("value", i).vertices().nextOrNull().getInteger("id")).isEqualTo(i); } @Test @@ -388,7 +393,7 @@ public void okJSON() { final JSONObject json2 = database.select().json(json).compile().json(); - Assertions.assertEquals(json, json2); + assertThat(json2).isEqualTo(json); } } @@ -402,12 +407,11 @@ private void expectingException(final Runnable callback, final Class result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(i < 100 ? 1 : 0, list.size()); + assertThat(list.size()).isEqualTo(i < 100 ? 1 : 0); - list.forEach(r -> Assertions.assertTrue(r.getInteger("id") == finalI && r.getString("name").equals("Elon"))); + list.forEach(r -> assertThat(r.getInteger("id") == finalI && r.getString("name").equals("Elon")).isTrue()); // CHECK 1 FOR ID = I + 100 FOR NAME = ELON (ALL OF THEM) - Assertions.assertEquals(1L, result.getMetrics().get("evaluatedRecords"), "With id " + i); - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("evaluatedRecords")).as("With id " + i).isEqualTo(1L); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } } @@ -89,11 +91,11 @@ public void okBothAvailableIndexes() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); - result.forEachRemaining(r -> Assertions.assertTrue(r.getInteger("id") == finalI || r.getString("name").equals("Elon"))); + result.forEachRemaining(r -> assertThat(r.getInteger("id") == finalI || r.getString("name").equals("Elon")).isTrue()); // CHECK 1 FOR ID = I + 100 FOR NAME = ELON (ALL OF THEM) - Assertions.assertEquals(i < 100 ? 100L : 101L, result.getMetrics().get("evaluatedRecords"), "" + finalI); - Assertions.assertEquals(2, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("evaluatedRecords")).as("" + finalI).isEqualTo(i < 100 ? 100L : 101L); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(2); } } } @@ -110,11 +112,11 @@ public void okOneIndexUsed() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); - result.forEachRemaining(r -> Assertions.assertEquals((int) r.getInteger("id"), finalI)); + result.forEachRemaining(r -> assertThat((int) r.getInteger("id")).isEqualTo(finalI)); // CHECK 1 FOR ID = I + 100 FOR NAME = ELON (ALL OF THEM) - Assertions.assertEquals(1L, result.getMetrics().get("evaluatedRecords")); - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("evaluatedRecords")).isEqualTo(1L); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } @@ -128,11 +130,11 @@ public void okOneIndexUsed() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); - result.forEachRemaining(r -> Assertions.assertEquals((int) r.getInteger("id"), finalI)); + result.forEachRemaining(r -> assertThat((int) r.getInteger("id")).isEqualTo(finalI)); // CHECK 1 FOR ID = I + 100 FOR NAME = ELON (ALL OF THEM) - Assertions.assertEquals(1L, result.getMetrics().get("evaluatedRecords")); - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("evaluatedRecords")).isEqualTo(1L); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } } @@ -150,8 +152,8 @@ public void okNoIndexUsed() { result.toList(); // CHECK 1 FOR ID = I + 100 FOR NAME = ELON (ALL OF THEM) - Assertions.assertEquals(110L, result.getMetrics().get("evaluatedRecords")); - Assertions.assertEquals(0, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("evaluatedRecords")).isEqualTo(110L); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(0); } } @@ -166,8 +168,8 @@ public void okNoIndexUsed() { result.toList(); // CHECK 1 FOR ID = I + 100 FOR NAME = ELON (ALL OF THEM) - Assertions.assertEquals(110L, result.getMetrics().get("evaluatedRecords")); - Assertions.assertEquals(0, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("evaluatedRecords")).isEqualTo(110L); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(0); } } @@ -183,13 +185,13 @@ public void okNoIndexUsed() { final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(1, list.size()); + assertThat(list.size()).isEqualTo(1); - list.forEach(r -> Assertions.assertEquals((int) r.getInteger("id"), finalI)); + list.forEach(r -> assertThat((int) r.getInteger("id")).isEqualTo(finalI)); // CHECK 1 FOR ID = I + 100 FOR NAME = ELON (ALL OF THEM) - Assertions.assertEquals(1L, result.getMetrics().get("evaluatedRecords")); - Assertions.assertEquals(2, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("evaluatedRecords")).isEqualTo(1L); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(2); } } @@ -205,9 +207,9 @@ public void okRanges() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(109 - i, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getInteger("id") > finalI)); - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(list.size()).isEqualTo(109 - i); + list.forEach(r -> assertThat(r.getInteger("id")).isGreaterThan(finalI)); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } @@ -219,9 +221,9 @@ public void okRanges() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(110 - i, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getInteger("id") >= finalI)); - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(list.size()).isEqualTo(110 - i); + list.forEach(r -> assertThat(r.getInteger("id")).isGreaterThanOrEqualTo(finalI)); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } @@ -233,9 +235,9 @@ public void okRanges() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(i, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getInteger("id") < finalI)); - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(list.size()).isEqualTo(i); + list.forEach(r -> assertThat(r.getInteger("id")).isLessThan(finalI)); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } @@ -247,9 +249,9 @@ public void okRanges() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(i + 1, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getInteger("id") <= finalI)); - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(list.size()).isEqualTo(i + 1); + list.forEach(r -> assertThat(r.getInteger("id")).isLessThanOrEqualTo(finalI)); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } @@ -261,9 +263,9 @@ public void okRanges() { final int finalI = i; final SelectIterator result = select.parameter("value", i).vertices(); final List list = result.toList(); - Assertions.assertEquals(109, list.size()); - list.forEach(r -> Assertions.assertTrue(r.getInteger("id") != finalI)); - Assertions.assertEquals(0, result.getMetrics().get("usedIndexes")); + assertThat(list.size()).isEqualTo(109); + list.forEach(r -> assertThat(r.getInteger("id")).isNotEqualTo(finalI)); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(0); } } } diff --git a/engine/src/test/java/com/arcadedb/query/select/SelectOrderByIT.java b/engine/src/test/java/com/arcadedb/query/select/SelectOrderByIT.java index c87f2c4018..618d9f79ef 100644 --- a/engine/src/test/java/com/arcadedb/query/select/SelectOrderByIT.java +++ b/engine/src/test/java/com/arcadedb/query/select/SelectOrderByIT.java @@ -23,9 +23,10 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -61,11 +62,11 @@ public void okOrderByNoIndex() { while (result.hasNext()) { final Integer id = result.next().getInteger("notIndexedId"); - Assertions.assertTrue(id > lastId); + assertThat(id > lastId).isTrue(); lastId = id; } - Assertions.assertEquals(0, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(0); } // DESCENDING @@ -76,11 +77,11 @@ public void okOrderByNoIndex() { while (result.hasNext()) { final Integer id = result.next().getInteger("notIndexedId"); - Assertions.assertTrue(id < lastId); + assertThat(id < lastId).isTrue(); lastId = id; } - Assertions.assertEquals(0, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(0); } } @@ -95,11 +96,11 @@ public void okOrderBy1Index() { while (result.hasNext()) { final Integer id = result.next().getInteger("id"); - Assertions.assertTrue(id > lastId); + assertThat(id > lastId).isTrue(); lastId = id; } - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } // DESCENDING @@ -110,11 +111,11 @@ public void okOrderBy1Index() { while (result.hasNext()) { final Integer id = result.next().getInteger("id"); - Assertions.assertTrue(id < lastId); + assertThat(id < lastId).isTrue(); lastId = id; } - Assertions.assertEquals(1, result.getMetrics().get("usedIndexes")); + assertThat(result.getMetrics().get("usedIndexes")).isEqualTo(1); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/BatchTest.java b/engine/src/test/java/com/arcadedb/query/sql/BatchTest.java index ef11c587ea..941a3b0984 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/BatchTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/BatchTest.java @@ -22,25 +22,30 @@ import com.arcadedb.exception.CommandSQLParsingException; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class BatchTest extends TestHelper { @Test public void testReturnArrayOnDeprecated() { database.transaction(() -> { final ResultSet rs = database.command("SQLSCRIPT", "let a = select 1 as result;let b = select 2 as result;return [$a,$b];"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertEquals("{\"value\":[{\"result\":1}]}", record.toJSON().toString()); + assertThat(record).isNotNull(); + assertThat(record.toJSON().toString()).isEqualTo("{\"value\":[{\"result\":1}]}"); record = rs.next(); - Assertions.assertEquals("{\"value\":[{\"result\":2}]}", record.toJSON().toString()); - Assertions.assertNotNull(record); + assertThat(record.toJSON().toString()).isEqualTo("{\"value\":[{\"result\":2}]}"); + assertThat(record).isNotNull(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); }); } @@ -49,16 +54,16 @@ public void testReturnArray() { database.transaction(() -> { final ResultSet rs = database.command("SQLScript", "let a = select 1 as result;let b = select 2 as result;return [$a,$b];"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertEquals("{\"value\":[{\"result\":1}]}", record.toJSON().toString()); + assertThat(record).isNotNull(); + assertThat(record.toJSON().toString()).isEqualTo("{\"value\":[{\"result\":1}]}"); record = rs.next(); - Assertions.assertEquals("{\"value\":[{\"result\":2}]}", record.toJSON().toString()); - Assertions.assertNotNull(record); + assertThat(record.toJSON().toString()).isEqualTo("{\"value\":[{\"result\":2}]}"); + assertThat(record).isNotNull(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); }); } @@ -79,7 +84,7 @@ public void testWhile() { final ResultSet result = database.query("sql", "select from TestWhile order by id"); for (int i = 0; i < 10; i++) { final Result record = result.next(); - Assertions.assertEquals(i, (int) record.getProperty("id")); + assertThat((int) record.getProperty("id")).isEqualTo(i); } } @@ -103,9 +108,9 @@ public void testWhileWithReturn() { final ResultSet result = database.query("sql", "select from TestWhileWithReturn order by id"); for (int i = 0; i < 5; i++) { final Result record = result.next(); - Assertions.assertEquals(i, (int) record.getProperty("id")); + assertThat((int) record.getProperty("id")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } @Test @@ -123,7 +128,7 @@ public void testForeach() { final ResultSet result = database.query("sql", "select from TestForeach order by id"); for (int i = 1; i <= 3; i++) { final Result record = result.next(); - Assertions.assertEquals(i, (int) record.getProperty("id")); + assertThat((int) record.getProperty("id")).isEqualTo(i); } } @@ -145,9 +150,9 @@ public void testForeachWithReturn() { final ResultSet result = database.query("sql", "select from TestForeachWithReturn order by id"); for (int i = 1; i <= 1; i++) { final Result record = result.next(); - Assertions.assertEquals(i, (int) record.getProperty("id")); + assertThat((int) record.getProperty("id")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } /** @@ -171,8 +176,8 @@ public void testLetUSeRightScope() { + "RETURN \"List is empty\";"; final ResultSet result = database.command("sqlscript", script); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("List element detected", result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("value")).isEqualTo("List element detected"); } /** @@ -191,8 +196,8 @@ public void testBreakInsideForeach() { + "RETURN $result;"; final ResultSet result = database.command("sqlscript", script); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("Return statement 2", result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("value")).isEqualTo("Return statement 2"); } // Isue https://github.com/ArcadeData/arcadedb/issues/1673 @@ -222,8 +227,8 @@ public void testNestedBreak() { + "RETURN $counter;"; final ResultSet result = database.command("sqlscript", script); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(7, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(7); } @Test @@ -243,22 +248,22 @@ public void testForeachResultSet() { + "RETURN $counter;"; final ResultSet result = database.command("sqlscript", script); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(100, (Integer) result.next().getProperty("value")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("value")).isEqualTo(100); } @Test public void testUsingReservedVariableNames() { try { database.command("sqlscript", "FOREACH ($parent IN [1, 2, 3]){\nRETURN;\n}"); - Assertions.fail(); + fail(""); } catch (CommandSQLParsingException e) { // EXPECTED } try { database.command("sqlscript", "LET parent = 33;"); - Assertions.fail(); + fail(""); } catch (CommandSQLParsingException e) { // EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/query/sql/DDLTest.java b/engine/src/test/java/com/arcadedb/query/sql/DDLTest.java index f009aa9613..76a8fc73bb 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/DDLTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/DDLTest.java @@ -19,7 +19,7 @@ package com.arcadedb.query.sql; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.stream.*; @@ -62,17 +62,13 @@ void testGraphWithSql() { database.transaction(() -> { final Long persons = database.command("sql", "SELECT count(*) as persons FROM Person ").next().getProperty("persons"); - - Assertions.assertEquals(numOfElements, persons); - + assertThat(persons).isEqualTo(numOfElements); final Long cars = database.command("sql", "SELECT count(*) as cars FROM Car").next().getProperty("cars"); - Assertions.assertEquals(numOfElements, cars); - + assertThat(cars).isEqualTo(numOfElements); final Long vs = database.command("sql", "SELECT count(*) as vs FROM V").next().getProperty("vs"); - Assertions.assertEquals(numOfElements * 2, vs); - + assertThat(vs).isEqualTo(numOfElements * 2); final Long edges = database.command("sql", "SELECT count(*) as edges FROM Drives").next().getProperty("edges"); }); diff --git a/engine/src/test/java/com/arcadedb/query/sql/OrderByTest.java b/engine/src/test/java/com/arcadedb/query/sql/OrderByTest.java index a97af952b2..ea6dab579b 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/OrderByTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/OrderByTest.java @@ -29,12 +29,15 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.time.*; import java.time.format.*; +import static org.assertj.core.api.Assertions.*; + /** * From Issue https://github.com/ArcadeData/arcadedb/issues/839 */ @@ -81,7 +84,7 @@ public void testLocalDateTimeOrderBy() { stop = LocalDateTime.parse("20220320T002323", FILENAME_TIME_FORMAT); Object[] parameters1 = { name, type, start, stop }; try (ResultSet resultSet = database.command("sql", sqlString, parameters1)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); } catch (Exception e) { System.out.println(e.getMessage()); @@ -98,15 +101,17 @@ public void testLocalDateTimeOrderBy() { try (ResultSet resultSet = database.query("sql", sqlString, parameters3)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) { result = resultSet.next(); start = result.getProperty("start"); - if (lastStart != null) - Assertions.assertTrue(start.compareTo(lastStart) <= 0, "" + start + " is greater than " + lastStart); + if (lastStart != null) { + assertThat(start.compareTo(lastStart)).isLessThanOrEqualTo(0) + .withFailMessage("" + start + " is greater than " + lastStart); + } lastStart = start; } @@ -116,15 +121,19 @@ public void testLocalDateTimeOrderBy() { sqlString = "SELECT name, start, stop FROM Product WHERE type = ? AND start <= ? AND stop >= ? ORDER BY start ASC"; try (ResultSet resultSet = database.query("sql", sqlString, parameters3)) { - Assertions.assertTrue(resultSet.hasNext()); + + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) { result = resultSet.next(); start = result.getProperty("start"); - if (lastStart != null) - Assertions.assertTrue(start.compareTo(lastStart) >= 0, "" + start + " is smaller than " + lastStart); + if (lastStart != null) { + + assertThat(start.compareTo(lastStart)).isGreaterThanOrEqualTo(0) + .withFailMessage("" + start + " is smaller than " + lastStart); + } lastStart = start; } diff --git a/engine/src/test/java/com/arcadedb/query/sql/QueryAndIndexesTest.java b/engine/src/test/java/com/arcadedb/query/sql/QueryAndIndexesTest.java index 500f04d5cf..ea05a696ee 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/QueryAndIndexesTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/QueryAndIndexesTest.java @@ -24,12 +24,14 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.schema.Schema; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + public class QueryAndIndexesTest extends TestHelper { private static final int TOT = 10000; @@ -66,20 +68,20 @@ public void testEqualsFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Set prop = new HashSet<>(); prop.addAll(record.getPropertyNames()); - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); - Assertions.assertEquals(123, (int) record.getProperty("id")); - Assertions.assertEquals("Jay", record.getProperty("name")); - Assertions.assertEquals("Miner123", record.getProperty("surname")); + assertThat(record.getPropertyNames().size()).isEqualTo(3); + assertThat((int) record.getProperty("id")).isEqualTo(123); + assertThat(record.getProperty("name")).isEqualTo("Jay"); + assertThat(record.getProperty("surname")).isEqualTo("Miner123"); total.incrementAndGet(); } - Assertions.assertEquals(1, total.get()); + assertThat(total.get()).isEqualTo(1); }); } @@ -95,17 +97,17 @@ public void testPartialMatchingFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Set prop = new HashSet<>(); prop.addAll(record.getPropertyNames()); - Assertions.assertEquals("Jay", record.getProperty("name")); + assertThat(record.getProperty("name")).isEqualTo("Jay"); total.incrementAndGet(); } - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/QueryTest.java b/engine/src/test/java/com/arcadedb/query/sql/QueryTest.java index c97fbf66a9..dc609fb607 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/QueryTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/QueryTest.java @@ -32,6 +32,9 @@ import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Fail.fail; + public class QueryTest extends TestHelper { private static final int TOT = 10000; @@ -62,21 +65,21 @@ public void testScan() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Set prop = new HashSet<>(); prop.addAll(record.getPropertyNames()); - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); - Assertions.assertTrue(prop.contains("id")); - Assertions.assertTrue(prop.contains("name")); - Assertions.assertTrue(prop.contains("surname")); + assertThat(record.getPropertyNames().size()).isEqualTo(3); + assertThat(prop).contains("id", "name", "surname"); total.incrementAndGet(); } - Assertions.assertEquals(TOT, total.get()); - }); + assertThat(total.get()).isEqualTo(TOT); + + } + ); } @Test @@ -91,17 +94,16 @@ public void testEqualsFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); - Assertions.assertEquals(123, (int) record.getProperty("id")); - Assertions.assertEquals("Jay", record.getProperty("name")); - Assertions.assertEquals("Miner123", record.getProperty("surname")); + assertThat(record).isNotNull(); + assertThat(record.getPropertyNames().size()).isEqualTo(3); + assertThat((int) record.getProperty("id")).isEqualTo(123); + assertThat(record.getProperty("name")).isEqualTo("Jay"); + assertThat(record.getProperty("surname")).isEqualTo("Miner123"); total.incrementAndGet(); } - Assertions.assertEquals(1, total.get()); + assertThat(total.get()).isEqualTo(1); }); } @@ -116,13 +118,12 @@ public void testNullSafeEqualsFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); + assertThat(record).isNotNull(); + assertThat(record.getPropertyNames().size()).isEqualTo(3); total.incrementAndGet(); } - Assertions.assertEquals(TOT, total.get()); + assertThat(total.get()).isEqualTo(TOT); }); } @@ -138,25 +139,22 @@ public void testCachedStatementAndExecutionPlan() { AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); - Assertions.assertEquals(123, (int) record.getProperty("id")); - Assertions.assertEquals("Jay", record.getProperty("name")); - Assertions.assertEquals("Miner123", record.getProperty("surname")); + assertThat(record).isNotNull(); + assertThat(record.getPropertyNames().size()).isEqualTo(3); + assertThat((int) record.getProperty("id")).isEqualTo(123); + assertThat(record.getProperty("name")).isEqualTo("Jay"); + assertThat(record.getProperty("surname")).isEqualTo("Miner123"); total.incrementAndGet(); } - Assertions.assertEquals(1, total.get()); + assertThat(total.get()).isEqualTo(1); // CHECK STATEMENT CACHE - Assertions.assertTrue( - ((DatabaseInternal) database).getStatementCache().contains("SELECT FROM V WHERE name = :name AND surname = :surname")); + assertThat(((DatabaseInternal) database).getStatementCache().contains("SELECT FROM V WHERE name = :name AND surname = :surname")).isTrue(); // CHECK EXECUTION PLAN CACHE - Assertions.assertTrue(((DatabaseInternal) database).getExecutionPlanCache() - .contains("SELECT FROM V WHERE name = :name AND surname = :surname")); + assertThat(((DatabaseInternal) database).getExecutionPlanCache().contains("SELECT FROM V WHERE name = :name AND surname = :surname")).isTrue(); // EXECUTE THE 2ND TIME rs = database.command("SQL", "SELECT FROM V WHERE name = :name AND surname = :surname", params); @@ -164,17 +162,17 @@ public void testCachedStatementAndExecutionPlan() { total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - - Assertions.assertEquals(3, record.getPropertyNames().size(), 9); - Assertions.assertEquals(123, (int) record.getProperty("id")); - Assertions.assertEquals("Jay", record.getProperty("name")); - Assertions.assertEquals("Miner123", record.getProperty("surname")); + assertThat(record).isNotNull(); +assertThat(record).isNotNull(); +assertThat(record.getPropertyNames().size()).isEqualTo(3); +assertThat((int) record.getProperty("id")).isEqualTo(123); +assertThat(record.getProperty("name")).isEqualTo("Jay"); +assertThat(record.getProperty("surname")).isEqualTo("Miner123"); total.incrementAndGet(); } - Assertions.assertEquals(1, total.get()); + assertThat(total.get()).isEqualTo(1); }); } @@ -188,11 +186,11 @@ public void testMajorFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertTrue((int) record.getProperty("id") > TOT - 11); + assertThat(record).isNotNull(); + assertThat(record.getProperty("id") > TOT - 11).isTrue(); total.incrementAndGet(); } - Assertions.assertEquals(10, total.get()); + assertThat(total.get()).isEqualTo(10); }); } @@ -206,11 +204,12 @@ public void testMajorEqualsFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertTrue((int) record.getProperty("id") >= TOT - 11); + assertThat(record).isNotNull(); + assertThat(record.getProperty("id") >= TOT - 11).isTrue(); + total.incrementAndGet(); } - Assertions.assertEquals(11, total.get()); + assertThat(total.get()).isEqualTo(11); }); } @@ -224,11 +223,11 @@ public void testMinorFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertTrue((int) record.getProperty("id") < 10); + assertThat(record).isNotNull(); + assertThat( record.getProperty("id") < 10).isTrue(); total.incrementAndGet(); } - Assertions.assertEquals(10, total.get()); + assertThat(total.get()).isEqualTo(10); }); } @@ -242,11 +241,11 @@ public void testMinorEqualsFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertTrue((int) record.getProperty("id") <= 10); + assertThat(record).isNotNull(); + assertThat(record.getProperty("id") <= 10).isTrue(); total.incrementAndGet(); } - Assertions.assertEquals(11, total.get()); + assertThat(total.get()).isEqualTo(11); }); } @@ -260,11 +259,11 @@ public void testNotFiltering() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertTrue((int) record.getProperty("id") <= 10); + assertThat(record).isNotNull(); + assertThat(record.getProperty("id") <= 10).isTrue(); total.incrementAndGet(); } - Assertions.assertEquals(11, total.get()); + assertThat(total.get()).isEqualTo(11); }); } @@ -276,11 +275,11 @@ public void testCreateVertexType() { database.command("SQL", "CREATE VERTEX Foo SET name = 'bar'"); final ResultSet rs = database.query("SQL", "SELECT FROM Foo"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -297,9 +296,9 @@ public void testCreateEdge() { "CREATE EDGE TheEdge FROM (SELECT FROM Foo WHERE name ='foo') TO (SELECT FROM Foo WHERE name ='bar')"); final ResultSet rs = database.query("SQL", "SELECT FROM TheEdge"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -319,18 +318,18 @@ public void testQueryEdge() { + " WHERE name ='bar')"); ResultSet rs = database.query("SQL", "SELECT FROM " + edgeClass); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("SQL", "SELECT out()[0].name as name from " + vertexClass + " where name = 'foo'"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Result item = rs.next(); final String name = item.getProperty("name"); - Assertions.assertTrue(name.contains("bar")); - Assertions.assertFalse(rs.hasNext()); + assertThat(name.contains("bar")).isTrue(); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -340,10 +339,10 @@ public void testQueryEdge() { public void testMethod() { database.transaction(() -> { final ResultSet rs = database.query("SQL", "SELECT 'bar'.prefix('foo') as name"); - Assertions.assertTrue(rs.hasNext()); - Assertions.assertEquals("foobar", rs.next().getProperty("name")); + assertThat(rs.hasNext()).isTrue(); + assertThat(rs.next().getProperty("name")).isEqualTo("foobar"); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -363,17 +362,17 @@ public void testMatch() { + " WHERE name ='bar')"); ResultSet rs = database.query("SQL", "SELECT FROM " + edgeClass); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("SQL", "MATCH {type:" + vertexClass + ", as:a} -" + edgeClass + "->{} RETURN $patterns"); rs.getExecutionPlan().get().prettyPrint(0, 2); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Result item = rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -393,17 +392,17 @@ public void testAnonMatch() { + " WHERE name ='bar')"); ResultSet rs = database.query("SQL", "SELECT FROM " + edgeClass); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("SQL", "MATCH {type:" + vertexClass + ", as:a} --> {} RETURN $patterns"); rs.getExecutionPlan().get().prettyPrint(0, 2); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); final Result item = rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -413,19 +412,19 @@ public void testAnonMatch() { public void testLike() { database.transaction(() -> { ResultSet rs = database.command("SQL", "SELECT FROM V WHERE surname LIKE '%in%' LIMIT 1"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.command("SQL", "SELECT FROM V WHERE surname LIKE 'Mi?er%' LIMIT 1"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.command("SQL", "SELECT FROM V WHERE surname LIKE 'baz' LIMIT 1"); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -439,20 +438,20 @@ public void testLikeEncoding() { database.command("SQL", "insert into V set age = '100%'"); ResultSet rs = database.command("SQL", "SELECT FROM V WHERE age LIKE '10\\%'"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); Result result = rs.next(); - Assertions.assertEquals("10%", result.getProperty("age")); - Assertions.assertFalse(rs.hasNext()); + assertThat(result.getProperty("age")).isEqualTo("10%"); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.command("SQL", "SELECT FROM V WHERE age LIKE \"10%\" ORDER BY age"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); result = rs.next(); - Assertions.assertEquals("10%", result.getProperty("age")); - Assertions.assertTrue(rs.hasNext()); + assertThat(result.getProperty("age")).isEqualTo("10%"); + assertThat(rs.hasNext()).isTrue(); result = rs.next(); - Assertions.assertEquals("100%", result.getProperty("age")); - Assertions.assertFalse(rs.hasNext()); + assertThat(result.getProperty("age")).isEqualTo("100%"); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); } @@ -475,7 +474,7 @@ public void testTimeout() { final Result record = rs.next(); LogManager.instance().log(this, Level.INFO, "Found record %s", null, record); } - Assertions.fail("Timeout should be triggered"); + fail("Timeout should be triggered"); } catch (final TimeoutException e) { // OK } @@ -493,19 +492,19 @@ public void testOrderByRID() { final AtomicInteger total = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); final Set prop = new HashSet<>(); prop.addAll(record.getPropertyNames()); - Assertions.assertEquals(2, record.getPropertyNames().size()); - Assertions.assertTrue(prop.contains("@rid")); - Assertions.assertTrue(prop.contains("name")); + assertThat(record.getPropertyNames()).hasSize(2); + assertThat(prop.contains("@rid")).isTrue(); + assertThat(prop.contains("name")).isTrue(); total.incrementAndGet(); } - Assertions.assertEquals(2, total.get()); + assertThat(total.get()).isEqualTo(2); }); } @@ -522,7 +521,7 @@ public void testFlattenWhereCondition() { query += ")"; try (ResultSet set = database.query("sql", query)) { - Assertions.assertEquals(set.stream().count(), 0); + assertThat(set.stream().count()).isEqualTo(0); } }); } @@ -530,11 +529,11 @@ public void testFlattenWhereCondition() { @Test public void testCollectionsInProjections() { try (ResultSet set = database.query("sql", "SELECT [\"a\",\"b\",\"c\"] as coll")) { - Collection coll = set.nextIfAvailable().getProperty("coll"); - Assertions.assertEquals(3, coll.size()); - Assertions.assertTrue(coll.contains("a")); - Assertions.assertTrue(coll.contains("b")); - Assertions.assertTrue(coll.contains("c")); + Collection coll = set.nextIfAvailable().getProperty("coll"); + assertThat(coll.size()).isEqualTo(3); + assertThat(coll.contains("a")).isTrue(); + assertThat(coll.contains("b")).isTrue(); + assertThat(coll.contains("c")).isTrue(); } } @@ -542,7 +541,7 @@ public void testCollectionsInProjections() { public void testCollectionsInProjectionsContains() { try (ResultSet set = database.query("sql", "SELECT ([\"a\",\"b\",\"c\"] CONTAINS (@this ILIKE \"C\")) as coll")) { final Object coll = set.nextIfAvailable().getProperty("coll"); - Assertions.assertTrue((Boolean) coll); + assertThat((Boolean) coll).isTrue(); } } @@ -551,7 +550,7 @@ public void testCollectionsOfObjectsInProjectionsContains() { try (ResultSet set = database.query("sql", "SELECT ([{\"x\":\"a\"},{\"x\":\"b\"},{\"x\":\"c\"}] CONTAINS (x ILIKE \"C\")) as coll")) { final Object coll = set.nextIfAvailable().getProperty("coll"); - Assertions.assertTrue((Boolean) coll); + assertThat((Boolean) coll).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/SQLDeleteEdgeTest.java b/engine/src/test/java/com/arcadedb/query/sql/SQLDeleteEdgeTest.java index 6b8fcfef4d..4d0589cd22 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/SQLDeleteEdgeTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/SQLDeleteEdgeTest.java @@ -5,11 +5,14 @@ import com.arcadedb.database.Identifiable; import com.arcadedb.exception.CommandExecutionException; import com.arcadedb.utility.CollectionUtils; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class SQLDeleteEdgeTest extends TestHelper { @Test public void testDeleteFromTo() { @@ -27,12 +30,12 @@ public void testDeleteFromTo() { database.command("sql", "CREATE EDGE testFromToTwoE from " + result.get(1).getIdentity() + " to " + result.get(0).getIdentity()); List resultTwo = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "select expand(outE()) from " + result.get(1).getIdentity())); - Assertions.assertEquals(resultTwo.size(), 2); + assertThat(resultTwo.size()).isEqualTo(2); database.command("sql", "DELETE EDGE testFromToTwoE from " + result.get(1).getIdentity() + " to" + result.get(0).getIdentity()); resultTwo = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "select expand(outE()) from " + result.get(1).getIdentity())); - Assertions.assertEquals(resultTwo.size(), 1); + assertThat(resultTwo.size()).isEqualTo(1); database.command("sql", "DELETE FROM testFromToOneE unsafe"); database.command("sql", "DELETE FROM testFromToTwoE unsafe"); @@ -56,12 +59,12 @@ public void testDeleteFrom() { database.command("sql", "CREATE EDGE testFromTwoE from " + result.get(1).getIdentity() + " to " + result.get(0).getIdentity()); List resultTwo = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "select expand(outE()) from " + result.get(1).getIdentity())); - Assertions.assertEquals(2, resultTwo.size()); + assertThat(resultTwo.size()).isEqualTo(2); database.command("sql", "DELETE EDGE testFromTwoE from " + result.get(1).getIdentity()); resultTwo = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "select expand(outE()) from " + result.get(1).getIdentity())); - Assertions.assertEquals(1, resultTwo.size()); + assertThat(resultTwo.size()).isEqualTo(1); database.command("sql", "DELETE FROM testFromOneE unsafe"); database.command("sql", "DELETE FROM testFromTwoE unsafe"); @@ -85,12 +88,12 @@ public void testDeleteTo() { database.command("sql", "CREATE EDGE testToTwoE from " + result.get(1).getIdentity() + " to " + result.get(0).getIdentity()); List resultTwo = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "select expand(outE()) from " + result.get(1).getIdentity())); - Assertions.assertEquals(resultTwo.size(), 2); + assertThat(resultTwo.size()).isEqualTo(2); database.command("sql", "DELETE EDGE testToTwoE to " + result.get(0).getIdentity()); resultTwo = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "select expand(outE()) from " + result.get(1).getIdentity())); - Assertions.assertEquals(resultTwo.size(), 1); + assertThat(resultTwo.size()).isEqualTo(1); database.command("sql", "DELETE FROM testToOneE unsafe"); database.command("sql", "DELETE FROM testToTwoE unsafe"); @@ -112,30 +115,30 @@ public void testDropTypeVandEwithUnsafe() { database.transaction(() -> { try { database.command("sql", "DROP TYPE SuperV"); - Assertions.assertTrue(false); + fail("Expected CommandExecutionException"); } catch (final CommandExecutionException e) { - Assertions.assertTrue(true); + assertThat(true).isTrue(); } try { database.command("sql", "DROP TYPE SuperE"); - Assertions.assertTrue(false); + fail("Expected CommandExecutionException"); } catch (final CommandExecutionException e) { - Assertions.assertTrue(true); + assertThat(true).isTrue(); } try { database.command("sql", "DROP TYPE SuperV unsafe"); - Assertions.assertTrue(true); + assertThat(true).isTrue(); } catch (final CommandExecutionException e) { - Assertions.assertTrue(false); + fail("Unexpected CommandExecutionException"); } try { database.command("sql", "DROP TYPE SuperE UNSAFE"); - Assertions.assertTrue(true); + assertThat(true).isTrue(); } catch (final CommandExecutionException e) { - Assertions.assertTrue(false); + fail("Unexpected CommandExecutionException"); } }); } @@ -152,32 +155,32 @@ public void testDropTypeVandEwithDeleteElements() { try { database.command("sql", "DROP TYPE SuperV"); - Assertions.fail(); + fail("Expected CommandExecutionException"); } catch (final CommandExecutionException e) { - Assertions.assertTrue(true); + assertThat(true).isTrue(); } try { database.command("sql", "DROP TYPE SuperE"); - Assertions.fail(); + fail("Expected CommandExecutionException"); } catch (final CommandExecutionException e) { - Assertions.assertTrue(true); + assertThat(true).isTrue(); } final long deleted = database.command("sql", "DELETE FROM SuperV").nextIfAvailable().getProperty("count", 0); try { database.command("sql", "DROP TYPE SuperV"); - Assertions.assertTrue(true); + assertThat(true).isTrue(); } catch (final CommandExecutionException e) { - Assertions.assertTrue(false); + fail("Unexpected CommandExecutionException"); } try { database.command("sql", "DROP TYPE SuperE"); - Assertions.assertTrue(true); + assertThat(true).isTrue(); } catch (final CommandExecutionException e) { - Assertions.assertTrue(false); + fail("Unexpected CommandExecutionException"); } }); } @@ -196,13 +199,13 @@ public void testFromInString() { database.command("sql", "create edge FromInStringE from " + v1.getIdentity() + " to " + v3.getIdentity()); List result = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "SELECT expand(out()[name = ' FROM ']) FROM FromInStringV")); - Assertions.assertEquals(result.size(), 1); + assertThat(result.size()).isEqualTo(1); result = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "SELECT expand(in()[name = ' from ']) FROM FromInStringV")); - Assertions.assertEquals(result.size(), 2); + assertThat(result.size()).isEqualTo(2); result = CollectionUtils.resultsetToListOfDocuments(database.query("sql", "SELECT expand(out()[name = ' TO ']) FROM FromInStringV")); - Assertions.assertEquals(result.size(), 1); + assertThat(result.size()).isEqualTo(1); }); } @@ -210,13 +213,13 @@ public void testFromInString() { public void testDeleteVertexWithReturn() { database.transaction(() -> { database.command("sql", "create vertex type V"); - final Identifiable v1 = CollectionUtils.getFirstResultAsDocument(database.command("sql", "create vertex V set returning = true")); + final Document v1 = CollectionUtils.getFirstResultAsDocument(database.command("sql", "create vertex V set returning = true")); final List v2s = CollectionUtils.resultsetToListOfDocuments( - database.command("sql", "delete vertex from V return before where returning = true")); + database.command("sql", "delete vertex from V return before where returning = true")); - Assertions.assertEquals(v2s.size(), 1); - Assertions.assertTrue(v2s.contains(v1)); + assertThat(v2s.size()).isEqualTo(1); + assertThat(v2s).contains(v1); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/SQLScriptTest.java b/engine/src/test/java/com/arcadedb/query/sql/SQLScriptTest.java index 06e7534fd6..1c304d8ff7 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/SQLScriptTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/SQLScriptTest.java @@ -7,11 +7,13 @@ import com.arcadedb.serializer.json.JSONArray; import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.utility.CollectionUtils; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class SQLScriptTest extends TestHelper { public void beginTest() { database.transaction(() -> { @@ -32,7 +34,7 @@ public void testQueryOnDeprecated() { script.append("return $a;\n"); ResultSet qResult = database.command("sqlscript", script.toString()); - Assertions.assertEquals(3, CollectionUtils.countEntries(qResult)); + assertThat(CollectionUtils.countEntries(qResult)).isEqualTo(3); } @Test @@ -44,7 +46,7 @@ public void testQuery() { script.append("return $a;\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertEquals(3, CollectionUtils.countEntries(qResult)); + assertThat(CollectionUtils.countEntries(qResult)).isEqualTo(3); } @Test @@ -56,7 +58,7 @@ public void testTx() { script.append("return $a;\n"); Document qResult = database.command("SQLScript", script.toString()).next().toElement(); - Assertions.assertNotNull(qResult); + assertThat(qResult).isNotNull(); } @Test @@ -66,8 +68,7 @@ public void testReturnExpanded() { script.append("let $a = insert into V set test = 'sql script test';\n"); script.append("return $a.asJSON();\n"); String qResult = database.command("SQLScript", script.toString()).next().getProperty("value").toString(); - Assertions.assertNotNull(qResult); - + assertThat(qResult).isNotNull(); // VALIDATE JSON new JSONObject(qResult); @@ -76,10 +77,10 @@ public void testReturnExpanded() { script.append("return $a.asJSON();\n"); String result = database.command("SQLScript", script.toString()).next().getProperty("value").toString(); - Assertions.assertNotNull(result); + + assertThat(result).isNotNull(); result = result.trim(); - Assertions.assertTrue(result.startsWith("{")); - Assertions.assertTrue(result.endsWith("}")); + assertThat(result).startsWith("{").endsWith("}"); // VALIDATE JSON new JSONObject(result); @@ -95,7 +96,7 @@ public void testSleep() { script.append("sleep 500"); database.command("SQLScript", script.toString()); - Assertions.assertTrue(System.currentTimeMillis() - begin >= 500); + assertThat(System.currentTimeMillis() - begin >= 500).isTrue(); } //@Test @@ -128,10 +129,10 @@ public void testReturnObject() { script.append("return [{ a: 'b' }]"); ResultSet result = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(result); + assertThat(Optional.ofNullable(result)).isNotNull(); - Assertions.assertEquals("b", result.next().getProperty("a")); - Assertions.assertFalse(result.hasNext()); + assertThat(result.next().getProperty("a")).isEqualTo("b"); + assertThat(result.hasNext()).isFalse(); } @Test @@ -145,10 +146,9 @@ public void testIncrementAndLet() { script.append("UPDATE TestCounter SET weight += $counter[0].count RETURN AfTER @this;\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertTrue(qResult.hasNext()); - final Result result = qResult.next(); - - Assertions.assertEquals(4L, (Long) result.getProperty("weight")); + assertThat(qResult.hasNext()).isTrue(); + Result result = qResult.next(); + assertThat(result.getProperty("weight")).isEqualTo(4L); }); } @@ -163,8 +163,8 @@ public void testIf1() { script.append("return 'FAIL';\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(qResult); - Assertions.assertEquals(qResult.next().getProperty("value"), "OK"); + assertThat(Optional.ofNullable(qResult)).isNotNull(); + assertThat(qResult.next().getProperty("value")).isEqualTo("OK"); } @Test @@ -178,8 +178,8 @@ public void testIf2() { script.append("return 'FAIL';\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(qResult); - Assertions.assertEquals(qResult.next().getProperty("value"), "OK"); + assertThat(Optional.ofNullable(qResult)).isNotNull(); + assertThat(qResult.next().getProperty("value")).isEqualTo("OK"); } @Test @@ -187,8 +187,8 @@ public void testIf3() { StringBuilder script = new StringBuilder(); script.append("let $a = select 1 as one; if($a[0].one = 1){return 'OK';}return 'FAIL';"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(qResult); - Assertions.assertEquals(qResult.next().getProperty("value"), "OK"); + assertThat(Optional.ofNullable(qResult)).isNotNull(); + assertThat(qResult.next().getProperty("value")).isEqualTo("OK"); } @Test @@ -205,8 +205,8 @@ public void testNestedIf2() { script.append("return 'FAIL';\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(qResult); - Assertions.assertEquals(qResult.next().getProperty("value"), "OK"); + assertThat(Optional.ofNullable(qResult)).isNotNull(); + assertThat(qResult.next().getProperty("value")).isEqualTo("OK"); } @Test @@ -223,8 +223,8 @@ public void testNestedIf3() { script.append("return 'OK';\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(qResult); - Assertions.assertEquals(qResult.next().getProperty("value"), "OK"); + assertThat(Optional.ofNullable(qResult)).isNotNull(); + assertThat(qResult.next().getProperty("value")).isEqualTo("OK"); } @Test @@ -238,8 +238,8 @@ public void testIfRealQuery() { script.append("return 'FAIL';\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(qResult); - Assertions.assertEquals(3, CollectionUtils.countEntries(qResult)); + assertThat(Optional.ofNullable(qResult)).isNotNull(); + assertThat(CollectionUtils.countEntries(qResult)).isEqualTo(3); } @Test @@ -254,8 +254,8 @@ public void testIfMultipleStatements() { script.append("return 'FAIL';\n"); ResultSet qResult = database.command("SQLScript", script.toString()); - Assertions.assertNotNull(qResult); - Assertions.assertEquals(qResult.next().getProperty("value"), "OK"); + assertThat(Optional.ofNullable(qResult)).isNotNull(); + assertThat(qResult.next().getProperty("value")).isEqualTo("OK"); } @Test @@ -276,8 +276,10 @@ public void testQuotedRegex() { ResultSet result = database.query("sql", "SELECT FROM QuotedRegex2"); Document doc = result.next().toElement(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertEquals("'';", doc.get("regexp")); + + assertThat(result.hasNext()).isFalse(); + assertThat(doc.get("regexp")).isEqualTo("'';"); + }); } @@ -299,7 +301,7 @@ public void testParameters1() { rs = database.query("sql", "SELECT FROM " + className + " WHERE name = ?", "bozo"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); rs.close(); } @@ -318,7 +320,7 @@ public void testPositionalParameters() { rs = database.query("sql", "SELECT FROM " + className + " WHERE name = ?", "bozo"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); rs.close(); } @@ -327,6 +329,7 @@ public void testPositionalParameters() { public void testInsertJsonNewLines() { database.transaction(() -> { database.getSchema().createDocumentType("doc"); + final ResultSet result = database.command("sqlscript", "INSERT INTO doc CONTENT {\n" + // "\"head\" : {\n" + // " \"vars\" : [ \"item\", \"itemLabel\" ]\n" + // @@ -356,10 +359,10 @@ public void testInsertJsonNewLines() { " }\n" + // "}"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result res = result.next(); - Assertions.assertTrue(res.hasProperty("head")); - Assertions.assertTrue(res.hasProperty("results")); + assertThat(res.hasProperty("head")).isTrue(); + assertThat(res.hasProperty("results")).isTrue(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/AlterDatabaseExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/AlterDatabaseExecutionTest.java index d301ab5e9b..0dbc84c7f6 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/AlterDatabaseExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/AlterDatabaseExecutionTest.java @@ -20,9 +20,10 @@ import com.arcadedb.GlobalConfiguration; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -30,18 +31,18 @@ public class AlterDatabaseExecutionTest extends TestHelper { @Test public void testBasicCreateProperty() { final int defPageSize = ((int) GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE.getDefValue()); - Assertions.assertEquals(defPageSize, database.getConfiguration().getValueAsInteger(GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE)); + assertThat(database.getConfiguration().getValueAsInteger(GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE)).isEqualTo(defPageSize); database.command("sql", "ALTER DATABASE `arcadedb.bucketDefaultPageSize` 262144"); - Assertions.assertEquals(262144, database.getConfiguration().getValueAsInteger(GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE)); + assertThat(database.getConfiguration().getValueAsInteger(GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE)).isEqualTo(262144); database.command("sql", "ALTER DATABASE `arcadedb.bucketDefaultPageSize` " + defPageSize); - Assertions.assertEquals(defPageSize, database.getConfiguration().getValueAsInteger(GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE)); + assertThat(database.getConfiguration().getValueAsInteger(GlobalConfiguration.BUCKET_DEFAULT_PAGE_SIZE)).isEqualTo(defPageSize); database.command("sql", "ALTER DATABASE `arcadedb.dateTimeFormat` 'yyyy-MM-dd HH:mm:ss.SSS'"); - Assertions.assertEquals("yyyy-MM-dd HH:mm:ss.SSS", database.getSchema().getDateTimeFormat()); + assertThat(database.getSchema().getDateTimeFormat()).isEqualTo("yyyy-MM-dd HH:mm:ss.SSS"); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/AlterPropertyExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/AlterPropertyExecutionTest.java index 5214e0929c..37a3a6d929 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/AlterPropertyExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/AlterPropertyExecutionTest.java @@ -22,12 +22,16 @@ import com.arcadedb.graph.Vertex; import com.arcadedb.schema.Type; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.time.*; import java.util.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -35,39 +39,40 @@ public class AlterPropertyExecutionTest extends TestHelper { @Test public void sqlAlterPropertyCustom() { database.command("sql", "CREATE VERTEX TYPE Car"); - Assertions.assertTrue(database.getSchema().getType("Car").getSuperTypes().isEmpty()); + assertThat(database.getSchema().getType("Car").getSuperTypes().isEmpty()).isTrue(); database.command("sql", "CREATE PROPERTY Car.name STRING"); - Assertions.assertTrue(database.getSchema().getType("Car").existsProperty("name")); - Assertions.assertEquals(Type.STRING, database.getSchema().getType("Car").getProperty("name").getType()); + assertThat(database.getSchema().getType("Car").existsProperty("name")).isTrue(); + assertThat(database.getSchema().getType("Car").getProperty("name").getType()).isEqualTo(Type.STRING); database.command("sql", "ALTER PROPERTY Car.name CUSTOM description = 'test'"); - Assertions.assertEquals("test", database.getSchema().getType("Car").getProperty("name").getCustomValue("description")); + assertThat(database.getSchema().getType("Car").getProperty("name").getCustomValue("description")).isEqualTo("test"); database.command("sql", "ALTER PROPERTY Car.name CUSTOM age = 3"); - Assertions.assertEquals(3, database.getSchema().getType("Car").getProperty("name").getCustomValue("age")); + assertThat(database.getSchema().getType("Car").getProperty("name").getCustomValue("age")).isEqualTo(3); final JSONObject cfg = database.getSchema().getEmbedded().toJSON(); - final JSONObject customMap = cfg.getJSONObject("types").getJSONObject("Car").getJSONObject("properties").getJSONObject("name").getJSONObject("custom"); - Assertions.assertEquals("test", customMap.getString("description")); - Assertions.assertEquals(3, customMap.getInt("age")); + final JSONObject customMap = cfg.getJSONObject("types").getJSONObject("Car").getJSONObject("properties").getJSONObject("name") + .getJSONObject("custom"); + assertThat(customMap.getString("description")).isEqualTo("test"); + assertThat(customMap.getInt("age")).isEqualTo(3); database.close(); database = factory.open(); - Assertions.assertEquals("test", database.getSchema().getType("Car").getProperty("name").getCustomValue("description")); - Assertions.assertEquals(3, ((Number) database.getSchema().getType("Car").getProperty("name").getCustomValue("age")).intValue()); + assertThat(database.getSchema().getType("Car").getProperty("name").getCustomValue("description")).isEqualTo("test"); + assertThat(((Number) database.getSchema().getType("Car").getProperty("name").getCustomValue("age")).intValue()).isEqualTo(3); database.command("sql", "ALTER PROPERTY Car.name CUSTOM age = null"); - Assertions.assertNull(database.getSchema().getType("Car").getProperty("name").getCustomValue("age")); - Assertions.assertFalse(database.getSchema().getType("Car").getProperty("name").getCustomKeys().contains("age")); + assertThat(database.getSchema().getType("Car").getProperty("name").getCustomValue("age")).isNull(); + assertThat(database.getSchema().getType("Car").getProperty("name").getCustomKeys().contains("age")).isFalse(); final ResultSet resultset = database.query("sql", "SELECT properties FROM schema:types"); while (resultset.hasNext()) { final Result result = resultset.next(); final Object custom = ((Result) ((List) result.getProperty("properties")).get(0)).getProperty("custom"); - Assertions.assertTrue(custom instanceof Map); - Assertions.assertFalse(((Map) custom).isEmpty()); + assertThat(custom instanceof Map).isTrue(); + assertThat(((Map) custom).isEmpty()).isFalse(); } } @@ -76,71 +81,73 @@ public void sqlAlterPropertyDefault() { database.command("sql", "CREATE VERTEX TYPE Vehicle"); database.command("sql", "CREATE PROPERTY Vehicle.id STRING"); database.command("sql", "ALTER PROPERTY Vehicle.id DEFAULT \"12345\""); - Assertions.assertTrue(database.getSchema().getType("Vehicle").getSuperTypes().isEmpty()); + assertThat(database.getSchema().getType("Vehicle").getSuperTypes().isEmpty()).isTrue(); database.command("sql", "CREATE VERTEX TYPE Car EXTENDS Vehicle"); - Assertions.assertTrue(!database.getSchema().getType("Car").getSuperTypes().isEmpty()); + assertThat(database.getSchema().getType("Car").getSuperTypes().isEmpty()).isFalse(); database.command("sql", "CREATE PROPERTY Car.name STRING"); - Assertions.assertTrue(database.getSchema().getType("Car").existsProperty("name")); - Assertions.assertEquals(Type.STRING, database.getSchema().getType("Car").getProperty("name").getType()); + assertThat(database.getSchema().getType("Car").existsProperty("name")).isTrue(); + assertThat(database.getSchema().getType("Car").getProperty("name").getType()).isEqualTo(Type.STRING); database.command("sql", "ALTER PROPERTY Car.name DEFAULT \"test\""); - Assertions.assertEquals("test", database.getSchema().getType("Car").getProperty("name").getDefaultValue()); + assertThat(database.getSchema().getType("Car").getProperty("name").getDefaultValue()).isEqualTo("test"); database.command("sql", "CREATE VERTEX TYPE Suv EXTENDS Car"); - Assertions.assertFalse(database.getSchema().getType("Suv").getSuperTypes().isEmpty()); + assertThat(database.getSchema().getType("Suv").getSuperTypes().isEmpty()).isFalse(); database.command("sql", "CREATE PROPERTY Suv.weight float"); - Assertions.assertTrue(database.getSchema().getType("Suv").existsProperty("weight")); - Assertions.assertEquals(Type.FLOAT, database.getSchema().getType("Suv").getProperty("weight").getType()); + assertThat(database.getSchema().getType("Suv").existsProperty("weight")).isTrue(); + assertThat(database.getSchema().getType("Suv").getProperty("weight").getType()).isEqualTo(Type.FLOAT); database.command("sql", "ALTER PROPERTY Suv.weight DEFAULT 1"); - Assertions.assertEquals(1.0F, database.getSchema().getType("Suv").getProperty("weight").getDefaultValue()); + assertThat(database.getSchema().getType("Suv").getProperty("weight").getDefaultValue()).isEqualTo(1.0F); final JSONObject cfg = database.getSchema().getEmbedded().toJSON(); - final String def1 = cfg.getJSONObject("types").getJSONObject("Car").getJSONObject("properties").getJSONObject("name").getString("default"); - Assertions.assertEquals("\"test\"", def1); - final Float def2 = cfg.getJSONObject("types").getJSONObject("Suv").getJSONObject("properties").getJSONObject("weight").getFloat("default"); - Assertions.assertEquals(1, def2); + final String def1 = cfg.getJSONObject("types").getJSONObject("Car").getJSONObject("properties").getJSONObject("name") + .getString("default"); + assertThat(def1).isEqualTo("\"test\""); + final Float def2 = cfg.getJSONObject("types").getJSONObject("Suv").getJSONObject("properties").getJSONObject("weight") + .getFloat("default"); + assertThat(def2).isEqualTo(1); database.transaction(() -> { database.command("sql", "CREATE VERTEX Car"); final ResultSet result = database.command("sql", "SELECT FROM Car"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Vertex v = result.next().getVertex().get(); - Assertions.assertEquals("test", v.get("name")); + assertThat(v.get("name")).isEqualTo("test"); }); database.transaction(() -> { database.command("sql", "CREATE VERTEX Suv"); final ResultSet result = database.command("sql", "SELECT FROM Suv"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Vertex v = result.next().getVertex().get(); - Assertions.assertEquals("12345", v.get("id")); - Assertions.assertEquals("test", v.get("name")); - Assertions.assertEquals(1.0F, v.get("weight")); + assertThat(v.get("id")).isEqualTo("12345"); + assertThat(v.get("name")).isEqualTo("test"); + assertThat(v.get("weight")).isEqualTo(1.0F); }); database.close(); database = factory.open(); - Assertions.assertEquals("test", database.getSchema().getType("Car").getProperty("name").getDefaultValue()); + assertThat(database.getSchema().getType("Car").getProperty("name").getDefaultValue()).isEqualTo("test"); database.command("sql", "ALTER PROPERTY Car.name DEFAULT null"); - Assertions.assertNull(database.getSchema().getType("Car").getProperty("name").getDefaultValue()); + assertThat(database.getSchema().getType("Car").getProperty("name").getDefaultValue()).isNull(); } @Test public void sqlAlterPropertyDefaultFunctions() { database.command("sql", "CREATE VERTEX TYPE Log"); - Assertions.assertTrue(database.getSchema().getType("Log").getSuperTypes().isEmpty()); + assertThat(database.getSchema().getType("Log").getSuperTypes().isEmpty()).isTrue(); database.command("sql", "CREATE PROPERTY Log.createdOn DATETIME_MICROS"); - Assertions.assertTrue(database.getSchema().getType("Log").existsProperty("createdOn")); - Assertions.assertEquals(Type.DATETIME_MICROS, database.getSchema().getType("Log").getProperty("createdOn").getType()); + assertThat(database.getSchema().getType("Log").existsProperty("createdOn")).isTrue(); + assertThat(database.getSchema().getType("Log").getProperty("createdOn").getType()).isEqualTo(Type.DATETIME_MICROS); database.command("sql", "ALTER PROPERTY Log.createdOn DEFAULT sysDate()"); @@ -156,25 +163,25 @@ public void sqlAlterPropertyDefaultFunctions() { database.command("sql", "CREATE VERTEX Log"); ResultSet result = database.command("sql", "SELECT FROM Log"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Vertex v = result.next().getVertex().get(); final LocalDateTime createdOn1 = v.getLocalDateTime("createdOn"); - Assertions.assertNotNull(createdOn1); + assertThat(createdOn1).isNotNull(); v = result.next().getVertex().get(); final LocalDateTime createdOn2 = v.getLocalDateTime("createdOn"); - Assertions.assertNotNull(createdOn2); + assertThat(createdOn2).isNotNull(); - Assertions.assertNotEquals(createdOn1, createdOn2); + assertThat(createdOn1).isNotEqualTo(createdOn2); v.modify().set("lastUpdateOn", LocalDateTime.now()).save(); result = database.command("sql", "SELECT FROM Log"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); v = result.next().getVertex().get(); - Assertions.assertEquals(createdOn1, v.getLocalDateTime("createdOn")); + assertThat(v.getLocalDateTime("createdOn")).isEqualTo(createdOn1); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/AlterTypeExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/AlterTypeExecutionTest.java index 0327a3a53b..cc642dc474 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/AlterTypeExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/AlterTypeExecutionTest.java @@ -22,11 +22,12 @@ import com.arcadedb.database.bucketselectionstrategy.BucketSelectionStrategy; import com.arcadedb.database.bucketselectionstrategy.PartitionedBucketSelectionStrategy; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.stream.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -35,40 +36,40 @@ public class AlterTypeExecutionTest extends TestHelper { public void sqlAlterTypeInheritanceUsing() { database.command("sql", "CREATE VERTEX TYPE Car"); - Assertions.assertTrue(database.getSchema().getType("Car").getSuperTypes().isEmpty()); + assertThat(database.getSchema().getType("Car").getSuperTypes().isEmpty()).isTrue(); database.command("sql", "CREATE VERTEX TYPE Vehicle"); database.command("sql", "ALTER TYPE Car SUPERTYPE +Vehicle"); - Assertions.assertEquals(1, database.getSchema().getType("Car").getSuperTypes().size()); - Assertions.assertTrue(database.getSchema().getType("Car").getSuperTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Vehicle")); - Assertions.assertEquals(1, database.getSchema().getType("Vehicle").getSubTypes().size()); - Assertions.assertTrue(database.getSchema().getType("Vehicle").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Car")); - Assertions.assertTrue(database.getSchema().getType("Vehicle").isSuperTypeOf("Car")); + assertThat(database.getSchema().getType("Car").getSuperTypes().size()).isEqualTo(1); + assertThat(database.getSchema().getType("Car").getSuperTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Vehicle")).isTrue(); + assertThat(database.getSchema().getType("Vehicle").getSubTypes().size()).isEqualTo(1); + assertThat(database.getSchema().getType("Vehicle").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Car")).isTrue(); + assertThat(database.getSchema().getType("Vehicle").isSuperTypeOf("Car")).isTrue(); database.command("sql", "CREATE VERTEX TYPE Suv"); - Assertions.assertTrue(database.getSchema().getType("Suv").getSuperTypes().isEmpty()); + assertThat(database.getSchema().getType("Suv").getSuperTypes().isEmpty()).isTrue(); database.command("sql", "ALTER TYPE Suv SUPERTYPE +Car"); - Assertions.assertEquals(1, database.getSchema().getType("Suv").getSuperTypes().size()); - Assertions.assertTrue(database.getSchema().getType("Car").isSuperTypeOf("Suv")); - Assertions.assertEquals(1, database.getSchema().getType("Car").getSubTypes().size()); - Assertions.assertTrue(database.getSchema().getType("Car").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Suv")); - Assertions.assertTrue(database.getSchema().getType("Car").isSuperTypeOf("Suv")); + assertThat(database.getSchema().getType("Suv").getSuperTypes().size()).isEqualTo(1); + assertThat(database.getSchema().getType("Car").isSuperTypeOf("Suv")).isTrue(); + assertThat(database.getSchema().getType("Car").getSubTypes().size()).isEqualTo(1); + assertThat(database.getSchema().getType("Car").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Suv")).isTrue(); + assertThat(database.getSchema().getType("Car").isSuperTypeOf("Suv")).isTrue(); database.command("sql", "ALTER TYPE Car SUPERTYPE -Vehicle"); - Assertions.assertTrue(database.getSchema().getType("Car").getSuperTypes().isEmpty()); - Assertions.assertTrue(database.getSchema().getType("Vehicle").getSubTypes().isEmpty()); + assertThat(database.getSchema().getType("Car").getSuperTypes().isEmpty()).isTrue(); + assertThat(database.getSchema().getType("Vehicle").getSubTypes().isEmpty()).isTrue(); database.command("sql", "ALTER TYPE Suv SUPERTYPE +Vehicle, +Car"); - Assertions.assertEquals(2, database.getSchema().getType("Suv").getSuperTypes().size()); - Assertions.assertTrue(database.getSchema().getType("Car").isSuperTypeOf("Suv")); - Assertions.assertTrue(database.getSchema().getType("Vehicle").isSuperTypeOf("Suv")); - Assertions.assertEquals(1, database.getSchema().getType("Car").getSubTypes().size()); - Assertions.assertEquals(1, database.getSchema().getType("Vehicle").getSubTypes().size()); - Assertions.assertTrue(database.getSchema().getType("Car").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Suv")); - Assertions.assertTrue(database.getSchema().getType("Car").isSuperTypeOf("Suv")); - Assertions.assertTrue(database.getSchema().getType("Vehicle").isSuperTypeOf("Suv")); + assertThat(database.getSchema().getType("Suv").getSuperTypes().size()).isEqualTo(2); + assertThat(database.getSchema().getType("Car").isSuperTypeOf("Suv")).isTrue(); + assertThat(database.getSchema().getType("Vehicle").isSuperTypeOf("Suv")).isTrue(); + assertThat(database.getSchema().getType("Car").getSubTypes().size()).isEqualTo(1); + assertThat(database.getSchema().getType("Vehicle").getSubTypes().size()).isEqualTo(1); + assertThat(database.getSchema().getType("Car").getSubTypes().stream().map(x -> x.getName()).collect(Collectors.toSet()).contains("Suv")).isTrue(); + assertThat(database.getSchema().getType("Car").isSuperTypeOf("Suv")).isTrue(); + assertThat(database.getSchema().getType("Vehicle").isSuperTypeOf("Suv")).isTrue(); } @Test @@ -79,8 +80,8 @@ public void sqlAlterTypeBucketSelectionStrategy() { database.command("sql", "ALTER TYPE Account BucketSelectionStrategy `partitioned('id')`"); final BucketSelectionStrategy strategy = database.getSchema().getType("Account").getBucketSelectionStrategy(); - Assertions.assertEquals("partitioned", strategy.getName()); - Assertions.assertEquals("id", ((PartitionedBucketSelectionStrategy) strategy).getProperties().get(0)); + assertThat(strategy.getName()).isEqualTo("partitioned"); + assertThat(((PartitionedBucketSelectionStrategy) strategy).getProperties().get(0)).isEqualTo("id"); } @Test @@ -88,18 +89,18 @@ public void sqlAlterTypeCustom() { database.command("sql", "CREATE VERTEX TYPE Suv"); database.command("sql", "ALTER TYPE Suv CUSTOM description = 'test'"); - Assertions.assertEquals("test", database.getSchema().getType("Suv").getCustomValue("description")); + assertThat(database.getSchema().getType("Suv").getCustomValue("description")).isEqualTo("test"); database.command("sql", "ALTER TYPE Suv CUSTOM age = 3"); - Assertions.assertEquals(3, database.getSchema().getType("Suv").getCustomValue("age")); + assertThat(database.getSchema().getType("Suv").getCustomValue("age")).isEqualTo(3); final JSONObject cfg = database.getSchema().getEmbedded().toJSON(); final JSONObject customMap = cfg.getJSONObject("types").getJSONObject("Suv").getJSONObject("custom"); - Assertions.assertEquals("test", customMap.getString("description")); - Assertions.assertEquals(3, customMap.getInt("age")); + assertThat(customMap.getString("description")).isEqualTo("test"); + assertThat(customMap.getInt("age")).isEqualTo(3); database.command("sql", "ALTER TYPE Suv CUSTOM age = null"); - Assertions.assertNull(database.getSchema().getType("Suv").getCustomValue("age")); - Assertions.assertFalse(database.getSchema().getType("Suv").getCustomKeys().contains("age")); + assertThat(database.getSchema().getType("Suv").getCustomValue("age")).isNull(); + assertThat(database.getSchema().getType("Suv").getCustomKeys().contains("age")).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/BeginStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/BeginStatementExecutionTest.java index be1eac6713..ce3e42c268 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/BeginStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/BeginStatementExecutionTest.java @@ -19,9 +19,13 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; +import java.util.*; + +import static org.assertj.core.api.Assertions.*; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -29,15 +33,15 @@ public class BeginStatementExecutionTest { @Test public void testBegin() throws Exception { TestHelper.executeInNewDatabase("OCommitStatementExecutionTest", (db) -> { - Assertions.assertTrue(db.getTransaction() == null || !db.getTransaction().isActive()); + assertThat(db.getTransaction() == null || !db.getTransaction().isActive()).isTrue(); final ResultSet result = db.command("sql", "begin"); //printExecutionPlan(null, result); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat((Iterator) result).isNotNull(); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals("begin", item.getProperty("operation")); - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(db.getTransaction() == null || !db.getTransaction().isActive()); + assertThat(item.getProperty("operation")).isEqualTo("begin"); + assertThat(result.hasNext()).isFalse(); + assertThat(db.getTransaction() == null || !db.getTransaction().isActive()).isFalse(); db.commit(); }); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckClusterTypeStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckClusterTypeStepTest.java index 90b56cd167..85d9e5a160 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckClusterTypeStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckClusterTypeStepTest.java @@ -21,9 +21,13 @@ import com.arcadedb.TestHelper; import com.arcadedb.exception.CommandExecutionException; import com.arcadedb.schema.DocumentType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.fail; + public class CheckClusterTypeStepTest { private static final String CLASS_CLUSTER_NAME = "ClassClusterName"; @@ -39,7 +43,8 @@ public void shouldCheckClusterType() throws Exception { final CheckClusterTypeStep step = new CheckClusterTypeStep(CLASS_CLUSTER_NAME, clazz.getName(), context); final ResultSet result = step.syncPull(context, 20); - Assertions.assertEquals(0, result.stream().count()); + + assertThat(result.stream().count()).isEqualTo(0); }); } @@ -53,7 +58,7 @@ public void shouldThrowExceptionWhenClusterIsWrong() throws Exception { step.syncPull(context, 20); }); - Assertions.fail("Expected CommandExecutionException"); + fail("Expected CommandExecutionException"); } catch (final CommandExecutionException e) { // OK } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckRecordTypeStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckRecordTypeStepTest.java index 03e8293fe7..b5f52adde3 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckRecordTypeStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckRecordTypeStepTest.java @@ -22,9 +22,13 @@ import com.arcadedb.exception.CommandExecutionException; import com.arcadedb.exception.TimeoutException; import com.arcadedb.schema.DocumentType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.fail; + public class CheckRecordTypeStepTest { @Test @@ -54,8 +58,8 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T step.setPrevious(previous); final ResultSet result = step.syncPull(context, 20); - Assertions.assertEquals(10, result.stream().count()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.stream().count()).isEqualTo(10); + assertThat(result.hasNext()).isFalse(); }); } @@ -86,8 +90,8 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T step.setPrevious(previous); final ResultSet result = step.syncPull(context, 20); - Assertions.assertEquals(10, result.stream().count()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.stream().count()).isEqualTo(10); + assertThat(result.hasNext()).isFalse(); }); } @@ -123,7 +127,7 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T result.next(); } }); - Assertions.fail("Expected CommandExecutionException"); + fail("Expected CommandExecutionException"); } catch (final CommandExecutionException e) { // OK diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckSafeDeleteStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckSafeDeleteStepTest.java index 79b0b1c582..5aaa466117 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckSafeDeleteStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckSafeDeleteStepTest.java @@ -20,9 +20,11 @@ import com.arcadedb.TestHelper; import com.arcadedb.exception.TimeoutException; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class CheckSafeDeleteStepTest { @Test @@ -50,8 +52,8 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T step.setPrevious(previous); final ResultSet result = step.syncPull(context, 10); - Assertions.assertEquals(10, result.stream().count()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.stream().count()).isEqualTo(10); + assertThat(result.hasNext()).isFalse(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckTypeTypeStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckTypeTypeStepTest.java index 7bd6de237e..47125168bc 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CheckTypeTypeStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CheckTypeTypeStepTest.java @@ -21,9 +21,13 @@ import com.arcadedb.TestHelper; import com.arcadedb.exception.CommandExecutionException; import com.arcadedb.schema.DocumentType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.fail; + public class CheckTypeTypeStepTest { @Test @@ -36,7 +40,7 @@ public void shouldCheckSubclasses() throws Exception { final CheckTypeTypeStep step = new CheckTypeTypeStep(childClass.getName(), parentClass.getName(), context); final ResultSet result = step.syncPull(context, 20); - Assertions.assertEquals(0, result.stream().count()); + assertThat(result.stream().count()).isEqualTo(0); }); } @@ -49,7 +53,7 @@ public void shouldCheckOneType() throws Exception { final CheckTypeTypeStep step = new CheckTypeTypeStep(className, className, context); final ResultSet result = step.syncPull(context, 20); - Assertions.assertEquals(0, result.stream().count()); + assertThat(result.stream().count()).isEqualTo(0); }); } @@ -64,7 +68,7 @@ public void shouldThrowExceptionWhenClassIsNotParent() throws Exception { step.syncPull(context, 20); }); - Assertions.fail("Expected CommandExecutionException"); + fail("Expected CommandExecutionException"); } catch (final CommandExecutionException e) { // OK } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/ConsoleStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/ConsoleStatementExecutionTest.java index 59e390de43..1240ec6e84 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/ConsoleStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/ConsoleStatementExecutionTest.java @@ -2,9 +2,14 @@ import com.arcadedb.TestHelper; import com.arcadedb.exception.CommandExecutionException; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdatabase.com) */ @@ -13,34 +18,34 @@ public class ConsoleStatementExecutionTest extends TestHelper { @Test public void testError() { ResultSet result = database.command("sqlscript", "console.`error` 'foo bar'"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat(Optional.ofNullable(result)).isNotNull(); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("error", item.getProperty("level")); - Assertions.assertEquals("foo bar", item.getProperty("message")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("level")).isEqualTo("error"); + assertThat(item.getProperty("message")).isEqualTo("foo bar"); } @Test public void testLog() { ResultSet result = database.command("sqlscript", "console.log 'foo bar'"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat(Optional.ofNullable(result)).isNotNull(); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("log", item.getProperty("level")); - Assertions.assertEquals("foo bar", item.getProperty("message")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("level")).isEqualTo("log"); + assertThat(item.getProperty("message")).isEqualTo("foo bar"); } @Test public void testInvalidLevel() { try { database.command("sqlscript", "console.bla 'foo bar'"); - Assertions.fail(); + fail(""); } catch (CommandExecutionException x) { // EXPECTED } catch (Exception x2) { - Assertions.fail(); + fail(""); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToResultInternalStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToResultInternalStepTest.java index 02afc400e7..d210fdea10 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToResultInternalStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToResultInternalStepTest.java @@ -22,11 +22,14 @@ import com.arcadedb.database.Document; import com.arcadedb.database.MutableDocument; import com.arcadedb.exception.TimeoutException; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + public class ConvertToResultInternalStepTest { private static final String STRING_PROPERTY = "stringPropertyName"; @@ -68,13 +71,13 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T while (result.hasNext()) { final Result currentItem = result.next(); if (!(currentItem.getClass().equals(ResultInternal.class))) { - Assertions.fail("There is an item in result set that is not an instance of ResultInternal"); + fail("There is an item in result set that is not an instance of ResultInternal"); } if (!currentItem.getElement().get().get(STRING_PROPERTY).equals(documents.get(counter).get(STRING_PROPERTY))) { - Assertions.fail("String Document property inside Result instance is not preserved"); + fail("String Document property inside Result instance is not preserved"); } if (!currentItem.getElement().get().get(INTEGER_PROPERTY).equals(documents.get(counter).get(INTEGER_PROPERTY))) { - Assertions.fail("Integer Document property inside Result instance is not preserved"); + fail("Integer Document property inside Result instance is not preserved"); } counter++; } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToUpdatableResultStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToUpdatableResultStepTest.java index 104322192a..54b792fac6 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToUpdatableResultStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/ConvertToUpdatableResultStepTest.java @@ -22,11 +22,14 @@ import com.arcadedb.database.Document; import com.arcadedb.database.MutableDocument; import com.arcadedb.exception.TimeoutException; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + public class ConvertToUpdatableResultStepTest { private static final String STRING_PROPERTY = "stringPropertyName"; @@ -69,13 +72,13 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T while (result.hasNext()) { final Result currentItem = result.next(); if (!(currentItem.getClass().equals(UpdatableResult.class))) { - Assertions.fail("There is an item in result set that is not an instance of OUpdatableResult"); + fail("There is an item in result set that is not an instance of OUpdatableResult"); } if (!currentItem.getElement().get().get(STRING_PROPERTY).equals(documents.get(counter).get(STRING_PROPERTY))) { - Assertions.fail("String Document property inside Result instance is not preserved"); + fail("String Document property inside Result instance is not preserved"); } if (!currentItem.getElement().get().get(INTEGER_PROPERTY).equals(documents.get(counter).get(INTEGER_PROPERTY))) { - Assertions.fail("Integer Document property inside Result instance is not preserved"); + fail("Integer Document property inside Result instance is not preserved"); } counter++; } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromIndexStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromIndexStepTest.java index c6fd9fae66..83de0e6d7a 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromIndexStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromIndexStepTest.java @@ -25,11 +25,14 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + public class CountFromIndexStepTest { private static final String PROPERTY_NAME = "testPropertyName"; @@ -75,8 +78,8 @@ public void shouldCountRecordsOfIndex() throws Exception { final CountFromIndexStep step = new CountFromIndexStep(identifier, ALIAS, context); final ResultSet result = step.syncPull(context, 20); - Assertions.assertEquals(20, (long) result.next().getProperty(ALIAS)); - Assertions.assertFalse(result.hasNext()); + assertThat((long) result.next().getProperty(ALIAS)).isEqualTo(20); + assertThat(result.hasNext()).isFalse(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromTypeStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromTypeStepTest.java index 4754160a4d..c9509d06ff 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromTypeStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CountFromTypeStepTest.java @@ -20,9 +20,12 @@ import com.arcadedb.TestHelper; import com.arcadedb.database.MutableDocument; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + public class CountFromTypeStepTest { private static final String ALIAS = "size"; @@ -41,8 +44,8 @@ public void shouldCountRecordsOfClass() throws Exception { final CountFromTypeStep step = new CountFromTypeStep(className, ALIAS, context); final ResultSet result = step.syncPull(context, 20); - Assertions.assertEquals(20, (long) result.next().getProperty(ALIAS)); - Assertions.assertFalse(result.hasNext()); + assertThat((long) result.next().getProperty(ALIAS)).isEqualTo(20); + assertThat(result.hasNext()).isFalse(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CountStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CountStepTest.java index 63152fe169..3d5f8e1242 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CountStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CountStepTest.java @@ -19,9 +19,10 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.exception.TimeoutException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class CountStepTest { @@ -55,7 +56,7 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T step.setPrevious(previous); final ResultSet result = step.syncPull(context, 100); - Assertions.assertEquals(100, (long) result.next().getProperty(COUNT_PROPERTY_NAME)); - Assertions.assertFalse(result.hasNext()); + assertThat((long) result.next().getProperty(COUNT_PROPERTY_NAME)).isEqualTo(100); + assertThat(result.hasNext()).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CreateDocumentTypeStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CreateDocumentTypeStatementExecutionTest.java index 36d32aa5a8..0c238f38ca 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CreateDocumentTypeStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CreateDocumentTypeStatementExecutionTest.java @@ -21,9 +21,12 @@ import com.arcadedb.TestHelper; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -35,7 +38,7 @@ public void testPlain() throws Exception { final ResultSet result = db.command("sql", "create document type " + className); final Schema schema = db.getSchema(); final DocumentType clazz = schema.getType(className); - Assertions.assertNotNull(clazz); + assertThat(clazz).isNotNull(); result.close(); }); } @@ -47,8 +50,8 @@ public void testClusters() throws Exception { final ResultSet result = db.command("sql", "create document type " + className + " buckets 32"); final Schema schema = db.getSchema(); final DocumentType clazz = schema.getType(className); - Assertions.assertNotNull(clazz); - Assertions.assertEquals(32, clazz.getBuckets(false).size()); + assertThat(clazz).isNotNull(); + assertThat(clazz.getBuckets(false)).hasSize(32); result.close(); }); } @@ -60,12 +63,12 @@ public void testIfNotExists() throws Exception { ResultSet result = db.command("sql", "create document type " + className + " if not exists"); final Schema schema = db.getSchema(); DocumentType clazz = schema.getType(className); - Assertions.assertNotNull(clazz); + assertThat(clazz).isNotNull(); result.close(); result = db.command("sql", "create document type " + className + " if not exists"); clazz = schema.getType(className); - Assertions.assertNotNull(clazz); + assertThat(clazz).isNotNull(); result.close(); }); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CreateEdgeStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CreateEdgeStatementExecutionTest.java index ff70a57670..70ba2975e8 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CreateEdgeStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CreateEdgeStatementExecutionTest.java @@ -22,9 +22,11 @@ import com.arcadedb.exception.CommandSQLParsingException; import com.arcadedb.graph.Edge; import com.arcadedb.graph.MutableVertex; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -56,17 +58,17 @@ public void okEdgesContentJsonArray() { int count = 0; while (result.hasNext()) { final Result r = result.next(); - Assertions.assertTrue(r.isEdge()); + assertThat(r.isEdge()).isTrue(); Edge edge = r.getEdge().get(); - Assertions.assertEquals(count, edge.getInteger("x")); + assertThat(edge.getInteger("x")).isEqualTo(count); ++count; } result.close(); - Assertions.assertEquals(1, count); + assertThat(count).isEqualTo(1); } @Test @@ -89,7 +91,7 @@ public void errorEdgesContentJsonArray() { try { ResultSet result = database.command("sql", "create edge " + edgeClassName + " from ? to ? CONTENT " + array, v1, v2); - Assertions.fail(); + fail(""); } catch (CommandSQLParsingException e) { // EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CreatePropertyStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CreatePropertyStatementExecutionTest.java index a60ef917af..4e1a3fba3d 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CreatePropertyStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CreatePropertyStatementExecutionTest.java @@ -25,11 +25,14 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Property; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -47,8 +50,8 @@ public void testBasicCreateProperty() { final DocumentType companyClass = database.getSchema().getType("testBasicCreateProperty"); final Property nameProperty = companyClass.getProperty(PROP_NAME); - Assertions.assertEquals(nameProperty.getName(), PROP_NAME); - Assertions.assertEquals(nameProperty.getType(), Type.STRING); + assertThat(nameProperty.getName()).isEqualTo(PROP_NAME); + assertThat(nameProperty.getType()).isEqualTo(Type.STRING); } @Test @@ -59,8 +62,8 @@ public void testCreateMandatoryPropertyWithEmbeddedType() { final DocumentType companyClass = database.getSchema().getType("testCreateMandatoryPropertyWithEmbeddedType"); final Property nameProperty = companyClass.getProperty(PROP_OFFICERS); - Assertions.assertEquals(nameProperty.getName(), PROP_OFFICERS); - Assertions.assertEquals(nameProperty.getType(), Type.LIST); + assertThat(nameProperty.getName()).isEqualTo(PROP_OFFICERS); + assertThat(nameProperty.getType()).isEqualTo(Type.LIST); } @Test @@ -71,8 +74,8 @@ public void testCreateUnsafePropertyWithEmbeddedType() { final DocumentType companyClass = database.getSchema().getType("testCreateUnsafePropertyWithEmbeddedType"); final Property nameProperty = companyClass.getProperty(PROP_OFFICERS); - Assertions.assertEquals(nameProperty.getName(), PROP_OFFICERS); - Assertions.assertEquals(nameProperty.getType(), Type.LIST); + assertThat(nameProperty.getName()).isEqualTo(PROP_OFFICERS); + assertThat(nameProperty.getType()).isEqualTo(Type.LIST); } @Test @@ -83,8 +86,8 @@ public void testExtraSpaces() { final DocumentType companyClass = database.getSchema().getType("testExtraSpaces"); final Property idProperty = companyClass.getProperty(PROP_ID); - Assertions.assertEquals(idProperty.getName(), PROP_ID); - Assertions.assertEquals(idProperty.getType(), Type.INTEGER); + assertThat(idProperty.getName()).isEqualTo(PROP_ID); + assertThat(idProperty.getType()).isEqualTo(Type.INTEGER); } @Test @@ -92,7 +95,7 @@ public void testInvalidAttributeName() { try { database.command("sql", "create document type CommandExecutionException").close(); database.command("sql", "CREATE PROPERTY CommandExecutionException.id INTEGER (MANDATORY, INVALID, NOTNULL) UNSAFE").close(); - Assertions.fail("Expected CommandSQLParsingException"); + fail("Expected CommandSQLParsingException"); } catch (final CommandSQLParsingException e) { // OK } @@ -112,29 +115,29 @@ public void testLinkedTypeConstraint() { final DocumentType invoiceType = database.getSchema().getType("Invoice"); final Property productsProperty = invoiceType.getProperty("products"); - Assertions.assertEquals(productsProperty.getName(), "products"); - Assertions.assertEquals(productsProperty.getType(), Type.LIST); - Assertions.assertEquals(productsProperty.getOfType(), "Product"); + assertThat(productsProperty.getName()).isEqualTo("products"); + assertThat(productsProperty.getType()).isEqualTo(Type.LIST); + assertThat(productsProperty.getOfType()).isEqualTo("Product"); final Property tagsProperty = invoiceType.getProperty("tags"); - Assertions.assertEquals(tagsProperty.getName(), "tags"); - Assertions.assertEquals(tagsProperty.getType(), Type.LIST); - Assertions.assertEquals(tagsProperty.getOfType(), "STRING"); + assertThat(tagsProperty.getName()).isEqualTo("tags"); + assertThat(tagsProperty.getType()).isEqualTo(Type.LIST); + assertThat(tagsProperty.getOfType()).isEqualTo("STRING"); final Property settingsProperty = invoiceType.getProperty("settings"); - Assertions.assertEquals(settingsProperty.getName(), "settings"); - Assertions.assertEquals(settingsProperty.getType(), Type.MAP); - Assertions.assertEquals(settingsProperty.getOfType(), "STRING"); + assertThat(settingsProperty.getName()).isEqualTo("settings"); + assertThat(settingsProperty.getType()).isEqualTo(Type.MAP); + assertThat(settingsProperty.getOfType()).isEqualTo("STRING"); final Property mainProductProperty = invoiceType.getProperty("mainProduct"); - Assertions.assertEquals(mainProductProperty.getName(), "mainProduct"); - Assertions.assertEquals(mainProductProperty.getType(), Type.LINK); - Assertions.assertEquals(mainProductProperty.getOfType(), "Product"); + assertThat(mainProductProperty.getName()).isEqualTo("mainProduct"); + assertThat(mainProductProperty.getType()).isEqualTo(Type.LINK); + assertThat(mainProductProperty.getOfType()).isEqualTo("Product"); final Property embeddedProperty = invoiceType.getProperty("embedded"); - Assertions.assertEquals(embeddedProperty.getName(), "embedded"); - Assertions.assertEquals(embeddedProperty.getType(), Type.EMBEDDED); - Assertions.assertEquals(embeddedProperty.getOfType(), "Product"); + assertThat(embeddedProperty.getName()).isEqualTo("embedded"); + assertThat(embeddedProperty.getType()).isEqualTo(Type.EMBEDDED); + assertThat(embeddedProperty.getOfType()).isEqualTo("Product"); final MutableDocument[] validInvoice = new MutableDocument[1]; database.transaction(() -> { @@ -153,21 +156,21 @@ public void testLinkedTypeConstraint() { database.newDocument("Invoice").set("products",// List.of(database.newDocument("Invoice").save())).save(); }); - Assertions.fail(); + fail(""); } catch (ValidationException e) { // EXPECTED } try { validInvoice[0].set("tags", List.of(3, "hard to close")).save(); - Assertions.fail(); + fail(""); } catch (ValidationException e) { // EXPECTED } try { validInvoice[0].set("settings", Map.of("test", 10F)).save(); - Assertions.fail(); + fail(""); } catch (ValidationException e) { // EXPECTED } @@ -176,7 +179,7 @@ public void testLinkedTypeConstraint() { database.transaction(() -> { validInvoice[0].set("mainProduct", database.newDocument("Invoice").save()).save(); }); - Assertions.fail(); + fail(""); } catch (ValidationException e) { // EXPECTED } @@ -185,7 +188,7 @@ public void testLinkedTypeConstraint() { database.transaction(() -> { validInvoice[0].newEmbeddedDocument("Invoice", "embedded").save(); }); - Assertions.fail(); + fail(""); } catch (ValidationException e) { // EXPECTED } @@ -199,15 +202,15 @@ public void testIfNotExists() { DocumentType clazz = database.getSchema().getType("testIfNotExists"); Property nameProperty = clazz.getProperty(PROP_NAME); - Assertions.assertEquals(nameProperty.getName(), PROP_NAME); - Assertions.assertEquals(nameProperty.getType(), Type.STRING); + assertThat(nameProperty.getName()).isEqualTo(PROP_NAME); + assertThat(nameProperty.getType()).isEqualTo(Type.STRING); database.command("sql", "CREATE property testIfNotExists.name if not exists STRING").close(); clazz = database.getSchema().getType("testIfNotExists"); nameProperty = clazz.getProperty(PROP_NAME); - Assertions.assertEquals(nameProperty.getName(), PROP_NAME); - Assertions.assertEquals(nameProperty.getType(), Type.STRING); + assertThat(nameProperty.getName()).isEqualTo(PROP_NAME); + assertThat(nameProperty.getType()).isEqualTo(Type.STRING); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/CreateVertexStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/CreateVertexStatementExecutionTest.java index 68309b0946..e0af3143b9 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/CreateVertexStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/CreateVertexStatementExecutionTest.java @@ -21,11 +21,14 @@ import com.arcadedb.TestHelper; import com.arcadedb.exception.CommandExecutionException; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -50,25 +53,25 @@ public void testVerticesContentJsonArray() { ResultSet result = database.command("sql", "create vertex " + className + " content " + array); for (int i = 0; i < 1000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name" + i, item.getProperty("name").toString()); - Assertions.assertEquals("surname" + i, item.getProperty("surname").toString()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name").toString()).isEqualTo("name" + i); + assertThat(item.getProperty("surname").toString()).isEqualTo("surname" + i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name" + i, item.getProperty("name").toString()); - Assertions.assertEquals("surname" + i, item.getProperty("surname").toString()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name").toString()).isEqualTo("name" + i); + assertThat(item.getProperty("surname").toString()).isEqualTo("surname" + i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -81,21 +84,21 @@ public void testInsertSet() { ResultSet result = database.command("sql", "create vertex " + className + " set name = 'name1'"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -107,10 +110,10 @@ public void testInsertSetNoVertex() { try { final ResultSet result = database.command("sql", "create vertex " + className + " set name = 'name1'"); - Assertions.fail(); + fail(""); } catch (final CommandExecutionException e1) { } catch (final Exception e2) { - Assertions.fail(); + fail(""); } } @@ -123,22 +126,22 @@ public void testInsertValue() { ResultSet result = database.command("sql", "create vertex " + className + " (name, surname) values ('name1', 'surname1')"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); - Assertions.assertEquals("surname1", item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); + assertThat(item.getProperty("surname")).isEqualTo("surname1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -152,28 +155,28 @@ public void testInsertValue2() { "create vertex " + className + " (name, surname) values ('name1', 'surname1'), ('name2', 'surname2')"); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name" + (i + 1), item.getProperty("name")); - Assertions.assertEquals("surname" + (i + 1), item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name" + (i + 1)); + assertThat(item.getProperty("surname")).isEqualTo("surname" + (i + 1)); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Set names = new HashSet<>(); names.add("name1"); names.add("name2"); result = database.query("sql", "select from " + className); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - names.remove(item.getProperty("name")); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); + names.remove(item.getProperty("name")); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(names.isEmpty()); + assertThat(result.hasNext()).isFalse(); + assertThat(names.isEmpty()).isTrue(); result.close(); } @@ -186,22 +189,22 @@ public void testContent() { ResultSet result = database.command("sql", "create vertex " + className + " content {'name':'name1', 'surname':'surname1'}"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); - Assertions.assertEquals("surname1", item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); + assertThat(item.getProperty("surname")).isEqualTo("surname1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/DistinctExecutionStepTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/DistinctExecutionStepTest.java index 1e998618c3..cb857c69ca 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/DistinctExecutionStepTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/DistinctExecutionStepTest.java @@ -19,9 +19,10 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.exception.TimeoutException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * Created by luigidellaquila on 26/07/16. */ @@ -52,10 +53,10 @@ public ResultSet syncPull(final CommandContext ctx, final int nRecords) throws T step.setPrevious(prev); final ResultSet res = step.syncPull(ctx, 10); - Assertions.assertTrue(res.hasNext()); + assertThat(res.hasNext()).isTrue(); res.next(); - Assertions.assertTrue(res.hasNext()); + assertThat(res.hasNext()).isTrue(); res.next(); - Assertions.assertFalse(res.hasNext()); + assertThat(res.hasNext()).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/DropBucketStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/DropBucketStatementExecutionTest.java index 0cca3dff91..8b97f1b2af 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/DropBucketStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/DropBucketStatementExecutionTest.java @@ -22,9 +22,12 @@ import com.arcadedb.engine.Bucket; import com.arcadedb.exception.CommandExecutionException; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -35,12 +38,12 @@ public void testDropBucketWithExistentType() { final Schema schema = database.getSchema(); schema.createDocumentType(className); - Assertions.assertNotNull(schema.getType(className)); + assertThat(schema.getType(className)).isNotNull(); for (Bucket bucket : database.getSchema().getType(className).getBuckets(false)) { try { database.command("sql", "drop bucket " + bucket.getName()); - Assertions.fail(); + fail(""); } catch (CommandExecutionException e) { // EXPECTED } @@ -48,13 +51,13 @@ public void testDropBucketWithExistentType() { database.command("sql", "alter type " + className + " bucket -" + bucket.getName()); final ResultSet result = database.command("sql", "drop bucket " + bucket.getName()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertEquals("drop bucket", next.getProperty("operation")); - Assertions.assertFalse(result.hasNext()); + assertThat(next.getProperty("operation")).isEqualTo("drop bucket"); + assertThat(result.hasNext()).isFalse(); result.close(); - Assertions.assertFalse(schema.existsBucket(bucket.getName())); + assertThat(schema.existsBucket(bucket.getName())).isFalse(); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/DropTypeStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/DropTypeStatementExecutionTest.java index 28c2c09d8e..961ef7340e 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/DropTypeStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/DropTypeStatementExecutionTest.java @@ -20,9 +20,10 @@ import com.arcadedb.TestHelper; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -33,16 +34,16 @@ public void testPlain() { final Schema schema = database.getSchema(); schema.createDocumentType(className); - Assertions.assertNotNull(schema.getType(className)); + assertThat(schema.getType(className)).isNotNull(); final ResultSet result = database.command("sql", "drop type " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertEquals("drop type", next.getProperty("operation")); - Assertions.assertFalse(result.hasNext()); + assertThat(next.getProperty("operation")).isEqualTo("drop type"); + assertThat(result.hasNext()).isFalse(); result.close(); - Assertions.assertFalse(schema.existsType(className)); + assertThat(schema.existsType(className)).isFalse(); } @Test @@ -51,21 +52,21 @@ public void testIfExists() { final Schema schema = database.getSchema(); schema.createDocumentType(className); - Assertions.assertNotNull(schema.getType(className)); + assertThat(schema.getType(className)).isNotNull(); ResultSet result = database.command("sql", "drop type " + className + " if exists"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertEquals("drop type", next.getProperty("operation")); - Assertions.assertFalse(result.hasNext()); + assertThat(next.getProperty("operation")).isEqualTo("drop type"); + assertThat(result.hasNext()).isFalse(); result.close(); - Assertions.assertFalse(schema.existsType(className)); + assertThat(schema.existsType(className)).isFalse(); result = database.command("sql", "drop type " + className + " if exists"); result.close(); - Assertions.assertFalse(schema.existsType(className)); + assertThat(schema.existsType(className)).isFalse(); } @Test @@ -74,15 +75,15 @@ public void testParam() { final Schema schema = database.getSchema(); schema.createDocumentType(className); - Assertions.assertNotNull(schema.getType(className)); + assertThat(schema.getType(className)).isNotNull(); final ResultSet result = database.command("sql", "drop type ?", className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertEquals("drop type", next.getProperty("operation")); - Assertions.assertFalse(result.hasNext()); + assertThat(next.getProperty("operation")).isEqualTo("drop type"); + assertThat(result.hasNext()).isFalse(); result.close(); - Assertions.assertFalse(schema.existsType(className)); + assertThat(schema.existsType(className)).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/ExplainStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/ExplainStatementExecutionTest.java index c59b9ac089..3dfe313063 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/ExplainStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/ExplainStatementExecutionTest.java @@ -19,11 +19,12 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -31,14 +32,14 @@ public class ExplainStatementExecutionTest extends TestHelper { @Test public void testExplainSelectNoTarget() { final ResultSet result = database.query("sql", "explain select 1 as one, 2 as two, 2+3"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next.getProperty("executionPlan")); - Assertions.assertNotNull(next.getProperty("executionPlanAsString")); + assertThat(next.getProperty("executionPlan")).isNotNull(); + assertThat(next.getProperty("executionPlanAsString")).isNotNull(); final Optional plan = result.getExecutionPlan(); - Assertions.assertTrue(plan.isPresent()); - Assertions.assertTrue(plan.get() instanceof SelectExecutionPlan); + assertThat(plan.isPresent()).isTrue(); + assertThat(plan.get() instanceof SelectExecutionPlan).isTrue(); result.close(); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/GroupByExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/GroupByExecutionTest.java index 7ee889c093..3479019da2 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/GroupByExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/GroupByExecutionTest.java @@ -19,11 +19,12 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -50,8 +51,8 @@ public void testGroupByCount() { final ResultSet result = database.query("sql", "select address, count(*) as occurrences from InputTx where address is not null group by address limit 10"); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertNotNull(row.getProperty("address")); - Assertions.assertNotNull(row.getProperty("occurrences")); + assertThat(row.getProperty("address")).isNotNull(); + assertThat(row.getProperty("occurrences")).isNotNull(); } result.close(); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/IfStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/IfStatementExecutionTest.java index 1eb2bbac5e..da52f3c71c 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/IfStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/IfStatementExecutionTest.java @@ -19,7 +19,6 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -32,26 +31,26 @@ public class IfStatementExecutionTest extends TestHelper { @Test public void testPositive() { final ResultSet results = database.command("sql", "if(1=1){ select 1 as a; }"); - Assertions.assertTrue(results.hasNext()); + assertThat(results.hasNext()).isTrue(); final Result result = results.next(); assertThat((Integer) result.getProperty("a")).isEqualTo(1); - Assertions.assertFalse(results.hasNext()); + assertThat(results.hasNext()).isFalse(); results.close(); } @Test public void testNegative() { final ResultSet results = database.command("sql", "if(1=2){ select 1 as a; }"); - Assertions.assertFalse(results.hasNext()); + assertThat(results.hasNext()).isFalse(); results.close(); } @Test public void testIfReturn() { final ResultSet results = database.command("sql", "if(1=1){ return 'yes'; }"); - Assertions.assertTrue(results.hasNext()); - Assertions.assertEquals("yes", results.next().getProperty("value")); - Assertions.assertFalse(results.hasNext()); + assertThat(results.hasNext()).isTrue(); + assertThat(results.next().getProperty("value")).isEqualTo("yes"); + assertThat(results.hasNext()).isFalse(); results.close(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/InsertStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/InsertStatementExecutionTest.java index 9cd0fd6864..d4ac135708 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/InsertStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/InsertStatementExecutionTest.java @@ -22,11 +22,14 @@ import com.arcadedb.database.EmbeddedDocument; import com.arcadedb.database.Identifiable; import com.arcadedb.database.MutableDocument; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -43,21 +46,21 @@ public void testInsertSet() { ResultSet result = database.command("sql", "insert into " + className + " set name = 'name1'"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -69,22 +72,22 @@ public void testInsertValue() { ResultSet result = database.command("sql", "insert into " + className + " (name, surname) values ('name1', 'surname1')"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); - Assertions.assertEquals("surname1", item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); + assertThat(item.getProperty("surname")).isEqualTo("surname1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -97,28 +100,28 @@ public void testInsertValue2() { "insert into " + className + " (name, surname) values ('name1', 'surname1'), ('name2', 'surname2')"); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name" + (i + 1), item.getProperty("name")); - Assertions.assertEquals("surname" + (i + 1), item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name" + (i + 1)); + assertThat(item.getProperty("surname")).isEqualTo("surname" + (i + 1)); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Set names = new HashSet<>(); names.add("name1"); names.add("name2"); result = database.query("sql", "select from " + className); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - names.remove(item.getProperty("name")); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); + names.remove(item.getProperty("name")); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(names.isEmpty()); + assertThat(result.hasNext()).isFalse(); + assertThat(names.isEmpty()).isTrue(); result.close(); } @@ -138,13 +141,13 @@ public void testInsertFromSelect1() { ResultSet result = database.command("sql", "insert into " + className2 + " from select from " + className1); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Set names = new HashSet<>(); for (int i = 0; i < 10; i++) { @@ -152,15 +155,15 @@ public void testInsertFromSelect1() { } result = database.query("sql", "select from " + className2); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - names.remove(item.getProperty("name")); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); + names.remove(item.getProperty("name")); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(names.isEmpty()); + assertThat(result.hasNext()).isFalse(); + assertThat(names.isEmpty()).isTrue(); result.close(); } @@ -180,13 +183,13 @@ public void testInsertFromSelect2() { ResultSet result = database.command("sql", "insert into " + className2 + " ( select from " + className1 + ")"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Set names = new HashSet<>(); for (int i = 0; i < 10; i++) { @@ -194,15 +197,15 @@ public void testInsertFromSelect2() { } result = database.query("sql", "select from " + className2); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - names.remove(item.getProperty("name")); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); + names.remove(item.getProperty("name")); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(names.isEmpty()); + assertThat(result.hasNext()).isFalse(); + assertThat(names.isEmpty()).isTrue(); result.close(); } @@ -213,13 +216,13 @@ public void testInsertFromSelectRawValue() { ResultSet result = database.command("sql", "insert into " + className1 + " set test = ( select 777 )"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); List list = item.getProperty("test"); - Assertions.assertEquals(1, list.size()); - Assertions.assertEquals(777, list.get(0)); - Assertions.assertFalse(result.hasNext()); + assertThat(list.size()).isEqualTo(1); + assertThat(list.get(0)).isEqualTo(777); + assertThat(result.hasNext()).isFalse(); } @Test @@ -229,15 +232,15 @@ public void testInsertFromSelectRawValues() { ResultSet result = database.command("sql", "insert into " + className1 + " set test = ( select 777, 888 )"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); List list = item.getProperty("test"); - Assertions.assertEquals(1, list.size()); + assertThat(list.size()).isEqualTo(1); Map map = list.get(0); - Assertions.assertEquals(777, map.get("777")); - Assertions.assertEquals(888, map.get("888")); - Assertions.assertFalse(result.hasNext()); + assertThat(map.get("777")).isEqualTo(777); + assertThat(map.get("888")).isEqualTo(888); + assertThat(result.hasNext()).isFalse(); } @Test @@ -248,22 +251,22 @@ public void testContent() { ResultSet result = database.command("sql", "insert into " + className + " content {'name':'name1', 'surname':'surname1'}"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); - Assertions.assertEquals("surname1", item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); + assertThat(item.getProperty("surname")).isEqualTo("surname1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -283,25 +286,25 @@ public void testContentJsonArray() { ResultSet result = database.command("sql", "insert into " + className + " content " + array); for (int i = 0; i < 1000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name" + i, item.getProperty("name").toString()); - Assertions.assertEquals("surname" + i, item.getProperty("surname").toString()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name").toString()).isEqualTo("name" + i); + assertThat(item.getProperty("surname").toString()).isEqualTo("surname" + i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name" + i, item.getProperty("name").toString()); - Assertions.assertEquals("surname" + i, item.getProperty("surname").toString()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name").toString()).isEqualTo("name" + i); + assertThat(item.getProperty("surname").toString()).isEqualTo("surname" + i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -314,14 +317,14 @@ public void testContentEmbedded() { "insert into " + className + " content { 'embedded': { '@type':'testContent', 'name':'name1', 'surname':'surname1'} }"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); EmbeddedDocument embedded = item.getProperty("embedded"); - Assertions.assertEquals("name1", embedded.getString("name")); - Assertions.assertEquals("surname1", embedded.getString("surname")); + assertThat(embedded.getString("name")).isEqualTo("name1"); + assertThat(embedded.getString("surname")).isEqualTo("surname1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } @Test @@ -337,22 +340,22 @@ public void testContentWithParam() { ResultSet result = database.command("sql", "insert into " + className + " content :theContent", params); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); - Assertions.assertEquals("surname1", item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); + assertThat(item.getProperty("surname")).isEqualTo("surname1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -375,11 +378,11 @@ public void testLinkConversion() { final ResultSet result = database.query("sql", "seLECT FROM " + className2); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result row = result.next(); final Object val = row.getProperty("processingType"); - Assertions.assertNotNull(val); - Assertions.assertTrue(val instanceof Identifiable); + assertThat(val).isNotNull(); + assertThat(val instanceof Identifiable).isTrue(); } result.close(); } @@ -398,16 +401,16 @@ public void testLISTConversion() { final ResultSet result = database.query("sql", "seLECT FROM " + className2); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result row = result.next(); final Object list = row.getProperty("sub"); - Assertions.assertNotNull(list); - Assertions.assertTrue(list instanceof List); - Assertions.assertEquals(1, ((List) list).size()); + assertThat(list).isNotNull(); + assertThat(list instanceof List).isTrue(); + assertThat(((List) list).size()).isEqualTo(1); final Object o = ((List) list).get(0); - Assertions.assertTrue(o instanceof Map); - Assertions.assertEquals("foo", ((Map) o).get("name")); + assertThat(o instanceof Map).isTrue(); + assertThat(((Map) o).get("name")).isEqualTo("foo"); } result.close(); } @@ -426,16 +429,16 @@ public void testLISTConversion2() { final ResultSet result = database.query("sql", "seLECT FROM " + className2); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result row = result.next(); final Object list = row.getProperty("sub"); - Assertions.assertNotNull(list); - Assertions.assertTrue(list instanceof List); - Assertions.assertEquals(1, ((List) list).size()); + assertThat(list).isNotNull(); + assertThat(list instanceof List).isTrue(); + assertThat(((List) list).size()).isEqualTo(1); final Object o = ((List) list).get(0); - Assertions.assertTrue(o instanceof Map); - Assertions.assertEquals("foo", ((Map) o).get("name")); + assertThat(o instanceof Map).isTrue(); + assertThat(((Map) o).get("name")).isEqualTo("foo"); } result.close(); } @@ -448,21 +451,21 @@ public void testInsertReturn() { ResultSet result = database.command("sql", "insert into " + className + " set name = 'name1' RETURN 'OK' as result"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("OK", item.getProperty("result")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("result")).isEqualTo("OK"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result = database.query("sql", "select from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -480,12 +483,12 @@ public void testNestedInsert() { for (int i = 0; i < 2; i++) { final Result item = result.next(); - if (item.getProperty("name").equals("parent")) { - Assertions.assertTrue(item.getProperty("children") instanceof Collection); - Assertions.assertEquals(1, ((Collection) item.getProperty("children")).size()); + if (item.getProperty("name").equals("parent")) { + assertThat(item.getProperty("children") instanceof Collection).isTrue(); + assertThat(((Collection) item.getProperty("children")).size()).isEqualTo(1); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -506,10 +509,10 @@ public void testLinkMapWithSubqueries() { final Result item = result.next(); final Map theMap = item.getProperty("mymap"); - Assertions.assertEquals(1, theMap.size()); - Assertions.assertNotNull(theMap.get("A-1")); + assertThat(theMap.size()).isEqualTo(1); + assertThat(theMap.get("A-1")).isNotNull(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -525,9 +528,9 @@ public void testQuotedCharactersInJson() { final Result item = result.next(); final String memo = item.getProperty("memo"); - Assertions.assertEquals("this is a \n multi line text", memo); + assertThat(memo).isEqualTo("this is a \n multi line text"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -537,7 +540,7 @@ public void testInsertEdgeMustFail() { database.getSchema().createEdgeType(className); try { database.command("sql", "insert into " + className + " set `@out` = #1:10, `@in` = #1:11"); - Assertions.fail(); + fail(""); } catch (final IllegalArgumentException e) { // EXPECTED } @@ -575,10 +578,10 @@ public void testInsertJsonNewLines() { " }\n" + // "}"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result res = result.next(); - Assertions.assertTrue(res.hasProperty("head")); - Assertions.assertTrue(res.hasProperty("results")); + assertThat(res.hasProperty("head")).isTrue(); + assertThat(res.hasProperty("results")).isTrue(); } @Test @@ -586,8 +589,8 @@ public void testInsertEncoding() { database.getSchema().createDocumentType("RegInfoDoc"); final ResultSet result = database.command("sql", "insert into RegInfoDoc set payload = \"(Pn/m)*1000kg/kW, with \\\"Pn\\\" being the\\n\\np and \\\"m\\\" (kg)\""); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("(Pn/m)*1000kg/kW, with \"Pn\" being the\n\np and \"m\" (kg)", result.next().getProperty("payload")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("payload")).isEqualTo("(Pn/m)*1000kg/kW, with \"Pn\" being the\n\np and \"m\" (kg)"); } @Test @@ -607,6 +610,6 @@ public void testInsertFromSelect() { for (; result.hasNext(); i++) result.next(); - Assertions.assertEquals(3, i); + assertThat(i).isEqualTo(3); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/MatchInheritanceTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/MatchInheritanceTest.java index 5da7f55b18..5fb7d08056 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/MatchInheritanceTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/MatchInheritanceTest.java @@ -2,9 +2,10 @@ import com.arcadedb.TestHelper; import com.arcadedb.graph.Vertex; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class MatchInheritanceTest extends TestHelper { @Test public void testInheritance() { @@ -18,7 +19,7 @@ public void testInheritance() { Result record = result.next(); ++selectFromServices; } - Assertions.assertEquals(4, selectFromServices); + assertThat(selectFromServices).isEqualTo(4); sql = "SELECT FROM Attractions"; result = database.command("SQL", sql); @@ -27,7 +28,7 @@ public void testInheritance() { Result record = result.next(); ++selectFromAttractions; } - Assertions.assertEquals(4, selectFromAttractions); + assertThat(selectFromAttractions).isEqualTo(4); sql = "SELECT FROM Locations"; @@ -37,27 +38,27 @@ public void testInheritance() { Result record = result.next(); ++selectFromLocations; } - Assertions.assertEquals(8, selectFromLocations); + assertThat(selectFromLocations).isEqualTo(8); sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Monuments} " + "RETURN $pathelements"; result = database.query("SQL", sql); - Assertions.assertEquals(2, result.stream().count()); + assertThat(result.stream().count()).isEqualTo(2); sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Services} " + "RETURN $pathelements"; result = database.query("SQL", sql); - Assertions.assertEquals(8, result.stream().count()); + assertThat(result.stream().count()).isEqualTo(8); sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Attractions} " + "RETURN $pathelements"; result = database.query("SQL", sql); - Assertions.assertEquals(8, result.stream().count()); + assertThat(result.stream().count()).isEqualTo(8); sql = "MATCH {type: Customers, as: customer, where: (OrderedId=1)}--{type: Locations} " + "RETURN $pathelements"; result = database.query("SQL", sql); - Assertions.assertEquals(16, result.stream().count()); + assertThat(result.stream().count()).isEqualTo(16); } @Override diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/MatchResultTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/MatchResultTest.java index 22869563cf..fa0059400f 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/MatchResultTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/MatchResultTest.java @@ -3,11 +3,12 @@ import com.arcadedb.TestHelper; import com.arcadedb.database.RID; import com.arcadedb.graph.Vertex; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class MatchResultTest extends TestHelper { /** @@ -40,6 +41,6 @@ public void testIssue1689() { set.add(next.getIdentity()); } - Assertions.assertEquals(3, set.size()); + assertThat(set.size()).isEqualTo(3); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/MatchStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/MatchStatementExecutionTest.java index b014252508..d02de5fe64 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/MatchStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/MatchStatementExecutionTest.java @@ -19,20 +19,19 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import com.arcadedb.database.Database; -import com.arcadedb.database.Document; -import com.arcadedb.database.Identifiable; -import com.arcadedb.database.MutableDocument; +import com.arcadedb.database.*; import com.arcadedb.graph.MutableVertex; import com.arcadedb.graph.Vertex; import com.arcadedb.index.TypeIndex; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.*; -import java.util.stream.*; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class MatchStatementExecutionTest extends TestHelper { public MatchStatementExecutionTest() { @@ -237,11 +236,11 @@ public void testSimple() { for (int i = 0; i < 6; i++) { final Result item = qResult.next(); - Assertions.assertEquals(1, item.getPropertyNames().size()); + assertThat(item.getPropertyNames().size()).isEqualTo(1); final Document person = item.getProperty("person"); final String name = person.getString("name"); - Assertions.assertTrue(name.startsWith("n")); + assertThat(name.startsWith("n")).isTrue(); } qResult.close(); } @@ -253,12 +252,12 @@ public void testSimpleWhere() { for (int i = 0; i < 2; i++) { final Result item = qResult.next(); - Assertions.assertTrue(item.getPropertyNames().size() == 1); + assertThat(item.getPropertyNames().size()).isEqualTo(1); final Document personId = item.getProperty("person"); final MutableDocument person = personId.getRecord().asVertex().modify(); final String name = person.getString("name"); - Assertions.assertTrue(name.equals("n1") || name.equals("n2")); + assertThat(name.equals("n1") || name.equals("n2")).isTrue(); } qResult.close(); } @@ -267,9 +266,9 @@ public void testSimpleWhere() { public void testSimpleLimit() { final ResultSet qResult = database.query("sql", "match {type:Person, as: person, where: (name = 'n1' or name = 'n2')} return person limit 1"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); qResult.next(); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -278,7 +277,7 @@ public void testSimpleLimit2() { final ResultSet qResult = database.query("sql", "match {type:Person, as: person, where: (name = 'n1' or name = 'n2')} return person limit -1"); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); qResult.next(); } qResult.close(); @@ -290,7 +289,7 @@ public void testSimpleLimit3() { final ResultSet qResult = database.query("sql", "match {type:Person, as: person, where: (name = 'n1' or name = 'n2')} return person limit 3"); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); qResult.next(); } qResult.close(); @@ -304,11 +303,11 @@ public void testSimpleUnnamedParams() { for (int i = 0; i < 2; i++) { final Result item = qResult.next(); - Assertions.assertEquals(1, item.getPropertyNames().size()); + assertThat(item.getPropertyNames().size()).isEqualTo(1); final Document person = item.getProperty("person"); final String name = person.getString("name"); - Assertions.assertTrue(name.equals("n1") || name.equals("n2")); + assertThat(name.equals("n1") || name.equals("n2")).isTrue(); } qResult.close(); } @@ -319,10 +318,10 @@ public void testCommonFriends() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return friend)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -332,10 +331,10 @@ public void testCommonFriendsPatterns() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return $patterns)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -344,11 +343,11 @@ public void testPattens() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return $patterns"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals(1, item.getPropertyNames().size()); - Assertions.assertEquals("friend", item.getPropertyNames().iterator().next()); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getPropertyNames().size()).isEqualTo(1); + assertThat(item.getPropertyNames().iterator().next()).isEqualTo("friend"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -357,10 +356,10 @@ public void testPaths() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return $paths"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals(3, item.getPropertyNames().size()); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getPropertyNames().size()).isEqualTo(3); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -369,10 +368,10 @@ public void testElements() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return $elements"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -386,12 +385,12 @@ public void testPathElements() { expected.add("n2"); expected.add("n4"); for (int i = 0; i < 3; i++) { - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - expected.remove(item.getProperty("name")); + expected.remove(item.getProperty("name")); } - Assertions.assertFalse(qResult.hasNext()); - Assertions.assertTrue(expected.isEmpty()); + assertThat(qResult.hasNext()).isFalse(); + assertThat(expected.isEmpty()).isTrue(); qResult.close(); } @@ -401,10 +400,10 @@ public void testCommonFriendsMatches() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return $matches)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -414,10 +413,10 @@ public void testCommonFriendsArrows() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend-{as:friend}-Friend-{type: Person, where:(name = 'n4')} return friend)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -427,10 +426,10 @@ public void testCommonFriendsArrowsPatterns() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend-{as:friend}-Friend-{type: Person, where:(name = 'n4')} return $patterns)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -440,10 +439,10 @@ public void testCommonFriends2() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return friend.name as name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -453,10 +452,10 @@ public void testCommonFriends2Arrows() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}-Friend-{as:friend}-Friend-{type: Person, where:(name = 'n4')} return friend.name as name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -464,10 +463,10 @@ public void testCommonFriends2Arrows() { public void testReturnMethod() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return friend.name.toUpperCase(Locale.ENGLISH) as name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("N2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("N2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -475,10 +474,10 @@ public void testReturnMethod() { public void testReturnMethodArrows() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}-Friend-{as:friend}-Friend-{type: Person, where:(name = 'n4')} return friend.name.toUpperCase(Locale.ENGLISH) as name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("N2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("N2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -487,10 +486,10 @@ public void testReturnExpression() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return friend.name + ' ' +friend.name as name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2 n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2 n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -499,10 +498,10 @@ public void testReturnExpressionArrows() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}-Friend-{as:friend}-Friend-{type: Person, where:(name = 'n4')} return friend.name + ' ' +friend.name as name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2 n2", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n2 n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -511,10 +510,10 @@ public void testReturnDefaultAlias() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}.both('Friend'){as:friend}.both('Friend'){type: Person, where:(name = 'n4')} return friend.name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("friend.name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("friend.name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -523,10 +522,10 @@ public void testReturnDefaultAliasArrows() { final ResultSet qResult = database.query("sql", "match {type:Person, where:(name = 'n1')}-Friend-{as:friend}-Friend-{type: Person, where:(name = 'n4')} return friend.name"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n2", item.getProperty("friend.name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("friend.name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -535,10 +534,10 @@ public void testFriendsOfFriends() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend').out('Friend'){as:friend} return $matches)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n4", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n4"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -547,10 +546,10 @@ public void testFriendsOfFriendsArrows() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{}-Friend->{as:friend} return $matches)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertEquals("n4", item.getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("n4"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -559,10 +558,10 @@ public void testFriendsOfFriends2() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1'), as: me}.both('Friend').both('Friend'){as:friend, where: ($matched.me != $currentMatch)} return $matches)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); while (qResult.hasNext()) { final Result item = qResult.next(); - Assertions.assertNotEquals("n1", item.getProperty("name")); + assertThat(item.getProperty("name")).isNotEqualTo("n1"); } qResult.close(); } @@ -572,9 +571,9 @@ public void testFriendsOfFriends2Arrows() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1'), as: me}-Friend-{}-Friend-{as:friend, where: ($matched.me != $currentMatch)} return $matches)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); while (qResult.hasNext()) { - Assertions.assertNotEquals("n1", qResult.next().getProperty("name")); + assertThat(qResult.next().getProperty("name")).isNotEqualTo("n1"); } qResult.close(); } @@ -584,9 +583,9 @@ public void testFriendsWithName() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1' and 1 + 1 = 2)}.out('Friend'){as:friend, where:(name = 'n2' and 1 + 1 = 2)} return friend)"); - Assertions.assertTrue(qResult.hasNext()); - Assertions.assertEquals("n2", qResult.next().getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); + assertThat(qResult.next().getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -594,9 +593,9 @@ public void testFriendsWithName() { public void testFriendsWithNameArrows() { final ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1' and 1 + 1 = 2)}-Friend->{as:friend, where:(name = 'n2' and 1 + 1 = 2)} return friend)"); - Assertions.assertTrue(qResult.hasNext()); - Assertions.assertEquals("n2", qResult.next().getProperty("name")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); + assertThat(qResult.next().getProperty("name")).isEqualTo("n2"); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); } @@ -605,32 +604,32 @@ public void testWhile() { ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, while: ($depth < 1)} return friend)"); - Assertions.assertEquals(3, size(qResult)); + assertThat(size(qResult)).isEqualTo(3); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, while: ($depth < 2), where: ($depth=1) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, while: ($depth < 4), where: ($depth=1) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, while: (true) } return friend)"); - Assertions.assertEquals(6, size(qResult)); + assertThat(size(qResult)).isEqualTo(6); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, while: (true) } return friend limit 3)"); - Assertions.assertEquals(3, size(qResult)); + assertThat(size(qResult)).isEqualTo(3); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, while: (true) } return friend) limit 3"); - Assertions.assertEquals(3, size(qResult)); + assertThat(size(qResult)).isEqualTo(3); qResult.close(); } @@ -647,22 +646,22 @@ private int size(final ResultSet qResult) { public void testWhileArrows() { ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, while: ($depth < 1)} return friend)"); - Assertions.assertEquals(3, size(qResult)); + assertThat(size(qResult)).isEqualTo(3); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, while: ($depth < 2), where: ($depth=1) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, while: ($depth < 4), where: ($depth=1) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, while: (true) } return friend)"); - Assertions.assertEquals(6, size(qResult)); + assertThat(size(qResult)).isEqualTo(6); qResult.close(); } @@ -670,22 +669,22 @@ public void testWhileArrows() { public void testMaxDepth() { ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 1, where: ($depth=1) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 1 } return friend)"); - Assertions.assertEquals(3, size(qResult)); + assertThat(size(qResult)).isEqualTo(3); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 0 } return friend)"); - Assertions.assertEquals(1, size(qResult)); + assertThat(size(qResult)).isEqualTo(1); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}.out('Friend'){as:friend, maxDepth: 1, where: ($depth > 0) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); } @@ -693,22 +692,22 @@ public void testMaxDepth() { public void testMaxDepthArrow() { ResultSet qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, maxDepth: 1, where: ($depth=1) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, maxDepth: 1 } return friend)"); - Assertions.assertEquals(3, size(qResult)); + assertThat(size(qResult)).isEqualTo(3); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, maxDepth: 0 } return friend)"); - Assertions.assertEquals(1, size(qResult)); + assertThat(size(qResult)).isEqualTo(1); qResult.close(); qResult = database.query("sql", "select friend.name as name from (match {type:Person, where:(name = 'n1')}-Friend->{as:friend, maxDepth: 1, where: ($depth > 0) } return friend)"); - Assertions.assertEquals(2, size(qResult)); + assertThat(size(qResult)).isEqualTo(2); qResult.close(); } @@ -716,15 +715,15 @@ public void testMaxDepthArrow() { public void testManager() { // the manager of a person is the manager of the department that person belongs to. // if that department does not have a direct manager, climb up the hierarchy until you find one - Assertions.assertEquals("c", getManager("p10").get("name")); - Assertions.assertEquals("c", getManager("p12").get("name")); - Assertions.assertEquals("b", getManager("p6").get("name")); - Assertions.assertEquals("b", getManager("p11").get("name")); + assertThat(getManager("p10").get("name")).isEqualTo("c"); + assertThat(getManager("p12").get("name")).isEqualTo("c"); + assertThat(getManager("p6").get("name")).isEqualTo("b"); + assertThat(getManager("p11").get("name")).isEqualTo("b"); - Assertions.assertEquals("c", getManagerArrows("p10").get("name")); - Assertions.assertEquals("c", getManagerArrows("p12").get("name")); - Assertions.assertEquals("b", getManagerArrows("p6").get("name")); - Assertions.assertEquals("b", getManagerArrows("p11").get("name")); + assertThat(getManagerArrows("p10").get("name")).isEqualTo("c"); + assertThat(getManagerArrows("p12").get("name")).isEqualTo("c"); + assertThat(getManagerArrows("p6").get("name")).isEqualTo("b"); + assertThat(getManagerArrows("p11").get("name")).isEqualTo("b"); } @Test @@ -744,12 +743,12 @@ public void testExpanded() { query.append(")"); final ResultSet qResult = database.query("sql", query.toString()); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); - Assertions.assertEquals("Employee", item.getProperty("@type")); + assertThat(item.getProperty("@type")).isEqualTo("Employee"); } private Document getManager(final String personName) { @@ -766,9 +765,9 @@ private Document getManager(final String personName) { query.append(")"); final ResultSet qResult = database.query("sql", query.toString()); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); return item.getElement().get().getRecord().asVertex(); } @@ -786,9 +785,9 @@ private Document getManagerArrows(final String personName) { final ResultSet qResult = database.query("sql", query.toString()); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); return item.getElement().get().getRecord().asVertex(); } @@ -798,15 +797,15 @@ public void testManager2() { // the manager of a person is the manager of the department that person belongs to. // if that department does not have a direct manager, climb up the hierarchy until you find one - Assertions.assertEquals("c", getManager2("p10").getProperty("name")); - Assertions.assertEquals("c", getManager2("p12").getProperty("name")); - Assertions.assertEquals("b", getManager2("p6").getProperty("name")); - Assertions.assertEquals("b", getManager2("p11").getProperty("name")); + assertThat(getManager2("p10").getProperty("name")).isEqualTo("c"); + assertThat(getManager2("p12").getProperty("name")).isEqualTo("c"); + assertThat(getManager2("p6").getProperty("name")).isEqualTo("b"); + assertThat(getManager2("p11").getProperty("name")).isEqualTo("b"); - Assertions.assertEquals("c", getManager2Arrows("p10").getProperty("name")); - Assertions.assertEquals("c", getManager2Arrows("p12").getProperty("name")); - Assertions.assertEquals("b", getManager2Arrows("p6").getProperty("name")); - Assertions.assertEquals("b", getManager2Arrows("p11").getProperty("name")); + assertThat(getManager2Arrows("p10").getProperty("name")).isEqualTo("c"); + assertThat(getManager2Arrows("p12").getProperty("name")).isEqualTo("c"); + assertThat(getManager2Arrows("p6").getProperty("name")).isEqualTo("b"); + assertThat(getManager2Arrows("p11").getProperty("name")).isEqualTo("b"); } private Result getManager2(final String personName) { @@ -824,9 +823,9 @@ private Result getManager2(final String personName) { query.append(")"); final ResultSet qResult = database.query("sql", query.toString()); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); return item; } @@ -844,9 +843,9 @@ private Result getManager2Arrows(final String personName) { query.append(")"); final ResultSet qResult = database.query("sql", query.toString()); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result item = qResult.next(); - Assertions.assertFalse(qResult.hasNext()); + assertThat(qResult.hasNext()).isFalse(); qResult.close(); return item; } @@ -856,10 +855,10 @@ public void testManaged() { // people managed by a manager are people who belong to his department or people who belong to // sub-departments without a manager final ResultSet managedByA = getManagedBy("a"); - Assertions.assertTrue(managedByA.hasNext()); + assertThat(managedByA.hasNext()).isTrue(); final Result item = managedByA.next(); - Assertions.assertFalse(managedByA.hasNext()); - Assertions.assertEquals("p1", item.getProperty("name")); + assertThat(managedByA.hasNext()).isFalse(); + assertThat(item.getProperty("name")).isEqualTo("p1"); managedByA.close(); final ResultSet managedByB = getManagedBy("b"); @@ -872,12 +871,12 @@ public void testManaged() { expectedNames.add("p11"); final Set names = new HashSet(); for (int i = 0; i < 5; i++) { - Assertions.assertTrue(managedByB.hasNext()); + assertThat(managedByB.hasNext()).isTrue(); final Result id = managedByB.next(); final String name = id.getProperty("name"); names.add(name); } - Assertions.assertEquals(expectedNames, names); + assertThat(names).isEqualTo(expectedNames); managedByB.close(); } @@ -902,10 +901,10 @@ public void testManagedArrows() { // people managed by a manager are people who belong to his department or people who belong to // sub-departments without a manager final ResultSet managedByA = getManagedByArrows("a"); - Assertions.assertTrue(managedByA.hasNext()); + assertThat(managedByA.hasNext()).isTrue(); final Result item = managedByA.next(); - Assertions.assertFalse(managedByA.hasNext()); - Assertions.assertEquals("p1", item.getProperty("name")); + assertThat(managedByA.hasNext()).isFalse(); + assertThat(item.getProperty("name")).isEqualTo("p1"); managedByA.close(); final ResultSet managedByB = getManagedByArrows("b"); @@ -917,12 +916,12 @@ public void testManagedArrows() { expectedNames.add("p11"); final Set names = new HashSet(); for (int i = 0; i < 5; i++) { - Assertions.assertTrue(managedByB.hasNext()); + assertThat(managedByB.hasNext()).isTrue(); final Result id = managedByB.next(); final String name = id.getProperty("name"); names.add(name); } - Assertions.assertEquals(expectedNames, names); + assertThat(names).isEqualTo(expectedNames); managedByB.close(); } @@ -945,10 +944,10 @@ public void testManaged2() { // people managed by a manager are people who belong to his department or people who belong to // sub-departments without a manager final ResultSet managedByA = getManagedBy2("a"); - Assertions.assertTrue(managedByA.hasNext()); + assertThat(managedByA.hasNext()).isTrue(); final Result item = managedByA.next(); - Assertions.assertFalse(managedByA.hasNext()); - Assertions.assertEquals("p1", item.getProperty("name")); + assertThat(managedByA.hasNext()).isFalse(); + assertThat(item.getProperty("name")).isEqualTo("p1"); managedByA.close(); final ResultSet managedByB = getManagedBy2("b"); @@ -960,12 +959,12 @@ public void testManaged2() { expectedNames.add("p11"); final Set names = new HashSet(); for (int i = 0; i < 5; i++) { - Assertions.assertTrue(managedByB.hasNext()); + assertThat(managedByB.hasNext()).isTrue(); final Result id = managedByB.next(); final String name = id.getProperty("name"); names.add(name); } - Assertions.assertEquals(expectedNames, names); + assertThat(names).isEqualTo(expectedNames); managedByB.close(); } @@ -990,10 +989,10 @@ public void testManaged2Arrows() { // people managed by a manager are people who belong to his department or people who belong to // sub-departments without a manager final ResultSet managedByA = getManagedBy2Arrows("a"); - Assertions.assertTrue(managedByA.hasNext()); + assertThat(managedByA.hasNext()).isTrue(); final Result item = managedByA.next(); - Assertions.assertFalse(managedByA.hasNext()); - Assertions.assertEquals("p1", item.getProperty("name")); + assertThat(managedByA.hasNext()).isFalse(); + assertThat(item.getProperty("name")).isEqualTo("p1"); managedByA.close(); final ResultSet managedByB = getManagedBy2Arrows("b"); @@ -1005,12 +1004,12 @@ public void testManaged2Arrows() { expectedNames.add("p11"); final Set names = new HashSet(); for (int i = 0; i < 5; i++) { - Assertions.assertTrue(managedByB.hasNext()); + assertThat(managedByB.hasNext()).isTrue(); final Result id = managedByB.next(); final String name = id.getProperty("name"); names.add(name); } - Assertions.assertEquals(expectedNames, names); + assertThat(names).isEqualTo(expectedNames); managedByB.close(); } @@ -1042,9 +1041,9 @@ public void testTriangle1() { final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1057,9 +1056,9 @@ public void testTriangle1Arrows() { query.append("return $matches"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1076,14 +1075,14 @@ public void testTriangle2Old() { final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); final Document friend1 = doc.getProperty("friend1"); final Document friend2 = doc.getProperty("friend2"); final Document friend3 = doc.getProperty("friend3"); - Assertions.assertEquals(0, friend1.getInteger("uid")); - Assertions.assertEquals(1, friend2.getInteger("uid")); - Assertions.assertEquals(2, friend3.getInteger("uid")); + assertThat(friend1.getInteger("uid")).isEqualTo(0); + assertThat(friend2.getInteger("uid")).isEqualTo(1); + assertThat(friend3.getInteger("uid")).isEqualTo(2); result.close(); } @@ -1099,15 +1098,15 @@ public void testTriangle2() { query.append("return $patterns"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Document friend1 = doc.getProperty("friend1"); final Document friend2 = doc.getProperty("friend2"); final Document friend3 = doc.getProperty("friend3"); - Assertions.assertEquals(0, friend1.getInteger("uid")); - Assertions.assertEquals(1, friend2.getInteger("uid")); - Assertions.assertEquals(2, friend3.getInteger("uid")); + assertThat(friend1.getInteger("uid")).isEqualTo(0); + assertThat(friend2.getInteger("uid")).isEqualTo(1); + assertThat(friend3.getInteger("uid")).isEqualTo(2); result.close(); } @@ -1123,15 +1122,15 @@ public void testTriangle2Arrows() { query.append("return $matches"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Document friend1 = doc.getProperty("friend1"); final Document friend2 = doc.getProperty("friend2"); final Document friend3 = doc.getProperty("friend3"); - Assertions.assertEquals(0, friend1.getInteger("uid")); - Assertions.assertEquals(1, friend2.getInteger("uid")); - Assertions.assertEquals(2, friend3.getInteger("uid")); + assertThat(friend1.getInteger("uid")).isEqualTo(0); + assertThat(friend2.getInteger("uid")).isEqualTo(1); + assertThat(friend3.getInteger("uid")).isEqualTo(2); result.close(); } @@ -1147,9 +1146,9 @@ public void testTriangle3() { query.append("return $matches"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1165,9 +1164,9 @@ public void testTriangle4() { query.append("return $matches"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1183,9 +1182,9 @@ public void testTriangle4Arrows() { query.append("return $matches"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1202,9 +1201,9 @@ public void testTriangleWithEdges4() { final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1219,12 +1218,12 @@ public void testCartesianProduct() { final ResultSet result = database.query("sql", query.toString()); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); final Vertex friend1 = doc.getProperty("friend1"); - Assertions.assertEquals(friend1.getInteger("uid"), 1); + assertThat(friend1.getInteger("uid")).isEqualTo(1); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1241,10 +1240,10 @@ public void testNoPrefetch() { .ifPresent(x -> x.getSteps().stream().filter(y -> y instanceof MatchPrefetchStep).forEach(prefetchStepFound -> fail())); for (int i = 0; i < 1000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1258,11 +1257,11 @@ public void testCartesianProductLimit() { final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result d = result.next(); final Document friend1 = d.getProperty("friend1"); - Assertions.assertEquals(friend1.getInteger("uid"), 1); - Assertions.assertFalse(result.hasNext()); + assertThat(friend1.getInteger("uid")).isEqualTo(1); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1275,12 +1274,12 @@ public void testArrayNumber() { final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); final Object foo = doc.getProperty("foo"); - Assertions.assertNotNull(foo); - Assertions.assertTrue(foo instanceof Vertex); + assertThat(foo).isNotNull(); + assertThat(foo instanceof Vertex).isTrue(); result.close(); } @@ -1292,13 +1291,13 @@ public void testArraySingleSelectors2() { query.append("return friend1.out('TriangleE')[0,1] as foo"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Object foo = doc.getProperty("foo"); - Assertions.assertNotNull(foo); - Assertions.assertTrue(foo instanceof List); - Assertions.assertEquals(2, ((List) foo).size()); + assertThat(foo).isNotNull(); + assertThat(foo instanceof List).isTrue(); + assertThat(((List) foo).size()).isEqualTo(2); result.close(); } @@ -1310,14 +1309,14 @@ public void testArrayRangeSelectors1() { query.append("return friend1.out('TriangleE')[0..1] as foo"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Object foo = doc.getProperty("foo"); - Assertions.assertNotNull(foo); - Assertions.assertTrue(foo instanceof List); - Assertions.assertEquals(1, ((List) foo).size()); + assertThat(foo).isNotNull(); + assertThat(foo instanceof List).isTrue(); + assertThat(((List) foo).size()).isEqualTo(1); result.close(); } @@ -1329,14 +1328,14 @@ public void testArrayRange2() { query.append("return friend1.out('TriangleE')[0..2] as foo"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Object foo = doc.getProperty("foo"); - Assertions.assertNotNull(foo); - Assertions.assertTrue(foo instanceof List); - Assertions.assertEquals(2, ((List) foo).size()); + assertThat(foo).isNotNull(); + assertThat(foo instanceof List).isTrue(); + assertThat(((List) foo).size()).isEqualTo(2); result.close(); } @@ -1348,14 +1347,14 @@ public void testArrayRange3() { query.append("return friend1.out('TriangleE')[0..3] as foo"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Object foo = doc.getProperty("foo"); - Assertions.assertNotNull(foo); - Assertions.assertTrue(foo instanceof List); - Assertions.assertEquals(2, ((List) foo).size()); + assertThat(foo).isNotNull(); + assertThat(foo instanceof List).isTrue(); + assertThat(((List) foo).size()).isEqualTo(2); result.close(); } @@ -1367,16 +1366,16 @@ public void testConditionInSquareBrackets() { query.append("return friend1.out('TriangleE')[uid = 2] as foo"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Object foo = doc.getProperty("foo"); - Assertions.assertNotNull(foo); - Assertions.assertTrue(foo instanceof List); - Assertions.assertEquals(1, ((List) foo).size()); + assertThat(foo).isNotNull(); + assertThat(foo instanceof List).isTrue(); + assertThat(((List) foo).size()).isEqualTo(1); final Vertex resultVertex = (Vertex) ((List) foo).get(0); - Assertions.assertEquals(2, resultVertex.getInteger("uid")); + assertThat(resultVertex.getInteger("uid")).isEqualTo(2); result.close(); } @@ -1390,9 +1389,9 @@ public void testIndexedEdge() { final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1405,9 +1404,9 @@ public void testIndexedEdgeArrows() { query.append("return one, two"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1419,9 +1418,9 @@ public void testJson() { query.append("return {'name':'foo', 'uuid':one.uid}"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); // Document doc = result.get(0); // assertEquals("foo", doc.set("name"); @@ -1437,9 +1436,9 @@ public void testJson2() { query.append("return {'name':'foo', 'sub': {'uuid':one.uid}}"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); // Document doc = result.get(0); // assertEquals("foo", doc.set("name"); // assertEquals(0, doc.set("sub.uuid"); @@ -1454,9 +1453,9 @@ public void testJson3() { query.append("return {'name':'foo', 'sub': [{'uuid':one.uid}]}"); final ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); // Document doc = result.get(0); // assertEquals("foo", doc.set("name"); // assertEquals(0, doc.set("sub[0].uuid"); @@ -1473,9 +1472,9 @@ public void testUnique() { ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); query = new StringBuilder(); query.append("match "); @@ -1485,9 +1484,9 @@ public void testUnique() { result.close(); result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); // Document doc = result.get(0); // assertEquals("foo", doc.set("name"); @@ -1503,11 +1502,11 @@ public void testNotUnique() { ResultSet result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result doc = result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); query = new StringBuilder(); @@ -1516,11 +1515,11 @@ public void testNotUnique() { query.append("return one.uid, two.uid"); result = database.query("sql", query.toString()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); doc = result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); doc = result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); // Document doc = result.get(0); // assertEquals("foo", doc.set("name"); @@ -1540,13 +1539,13 @@ public void testManagedElements() { expectedNames.add("p11"); final Set names = new HashSet(); for (int i = 0; i < 6; i++) { - Assertions.assertTrue(managedByB.hasNext()); + assertThat(managedByB.hasNext()).isTrue(); final Result doc = managedByB.next(); final String name = doc.getProperty("name"); names.add(name); } - Assertions.assertFalse(managedByB.hasNext()); - Assertions.assertEquals(expectedNames, names); + assertThat(managedByB.hasNext()).isFalse(); + assertThat(names).isEqualTo(expectedNames); managedByB.close(); } @@ -1579,13 +1578,13 @@ public void testManagedPathElements() { expectedNames.add("p11"); final Set names = new HashSet(); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(managedByB.hasNext()); + assertThat(managedByB.hasNext()).isTrue(); final Result doc = managedByB.next(); final String name = doc.getProperty("name"); names.add(name); } - Assertions.assertFalse(managedByB.hasNext()); - Assertions.assertEquals(expectedNames, names); + assertThat(managedByB.hasNext()).isFalse(); + assertThat(names).isEqualTo(expectedNames); managedByB.close(); } @@ -1595,13 +1594,13 @@ public void testOptional() { "match {type:Person, as: person} -NonExistingEdge-> {as:b, optional:true} return person, b.name"); for (int i = 0; i < 6; i++) { - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result doc = qResult.next(); - Assertions.assertTrue(doc.getPropertyNames().size() == 2); + assertThat(doc.getPropertyNames().size()).isEqualTo(2); final Vertex person = doc.getProperty("person"); final String name = person.getString("name"); - Assertions.assertTrue(name.startsWith("n")); + assertThat(name.startsWith("n")).isTrue(); } } @@ -1611,13 +1610,13 @@ public void testOptional2() { "match {type:Person, as: person} --> {as:b, optional:true, where:(nonExisting = 12)} return person, b.name"); for (int i = 0; i < 6; i++) { - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result doc = qResult.next(); - Assertions.assertTrue(doc.getPropertyNames().size() == 2); + assertThat(doc.getPropertyNames().size()).isEqualTo(2); final Vertex person = doc.getProperty("person"); final String name = person.getString("name"); - Assertions.assertTrue(name.startsWith("n")); + assertThat(name.startsWith("n")).isTrue(); } } @@ -1628,11 +1627,11 @@ public void testOptional3() { + "{as:a}.out(){as:b, where:(nonExisting = 12), optional:true}," + "{as:friend}.out(){as:b, optional:true}" + " return friend, b)"); - Assertions.assertTrue(qResult.hasNext()); + assertThat(qResult.hasNext()).isTrue(); final Result doc = qResult.next(); - Assertions.assertEquals("n2", doc.getProperty("name")); - Assertions.assertNull(doc.getProperty("b")); - Assertions.assertFalse(qResult.hasNext()); + assertThat(doc.getProperty("name")).isEqualTo("n2"); + assertThat(doc.getProperty("b")).isNull(); + assertThat(qResult.hasNext()).isFalse(); } @Test @@ -1647,15 +1646,15 @@ public void testOrderByAsc() { final String query = "MATCH { type: testOrderByAsc, as:a} RETURN a.name as name order by name asc"; final ResultSet result = database.query("sql", query); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("aaa", result.next().getProperty("name")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("bbb", result.next().getProperty("name")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("ccc", result.next().getProperty("name")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("zzz", result.next().getProperty("name")); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("aaa"); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("bbb"); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("ccc"); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("zzz"); + assertThat(result.hasNext()).isFalse(); } @Test @@ -1670,15 +1669,15 @@ public void testOrderByDesc() { final String query = "MATCH { type: testOrderByDesc, as:a} RETURN a.name as name order by name desc"; final ResultSet result = database.query("sql", query); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("zzz", result.next().getProperty("name")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("ccc", result.next().getProperty("name")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("bbb", result.next().getProperty("name")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("aaa", result.next().getProperty("name")); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("zzz"); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("ccc"); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("bbb"); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("name")).isEqualTo("aaa"); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1692,12 +1691,12 @@ public void testNestedProjections() { final String query = "MATCH { type: " + clazz + ", as:a} RETURN a:{name}, 'x' "; final ResultSet result = database.query("sql", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Result a = item.getProperty("a"); - Assertions.assertEquals("bbb", a.getProperty("name")); - Assertions.assertNull(a.getProperty("surname")); - Assertions.assertFalse(result.hasNext()); + assertThat(a.getProperty("name")).isEqualTo("bbb"); + assertThat(a.getProperty("surname")).isNull(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1716,14 +1715,14 @@ public void testNestedProjectionsStar() { final String query = "MATCH { type: " + clazz + ", as:a} RETURN a:{*, @rid}, 'x' "; final ResultSet result = database.query("sql", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Result a = item.getProperty("a"); - Assertions.assertEquals("bbb", a.getProperty("name")); - Assertions.assertEquals("ccc", a.getProperty("surname")); - Assertions.assertNotNull(a.getProperty("@rid")); - Assertions.assertEquals(4, a.getPropertyNames().size()); - Assertions.assertFalse(result.hasNext()); + assertThat(a.getProperty("name")).isEqualTo("bbb"); + assertThat(a.getProperty("surname")).isEqualTo("ccc"); + assertThat(a.getProperty("@rid")).isNotNull(); + assertThat(a.getPropertyNames().size()).isEqualTo(4); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1742,11 +1741,11 @@ public void testExpand() { final String query = "MATCH { type: " + clazz + ", as:a} RETURN expand(a) "; final ResultSet result = database.query("sql", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result a = result.next(); - Assertions.assertEquals("bbb", a.getProperty("name")); - Assertions.assertEquals("ccc", a.getProperty("surname")); - Assertions.assertFalse(result.hasNext()); + assertThat(a.getProperty("name")).isEqualTo("bbb"); + assertThat(a.getProperty("surname")).isEqualTo("ccc"); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1766,17 +1765,17 @@ public void testAggregate() { "MATCH { type: " + clazz + ", as:a} RETURN a.name as a, max(a.num) as maxNum group by a.name order by a.name"; final ResultSet result = database.query("sql", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals("aaa", item.getProperty("a")); - Assertions.assertEquals(3, (int) item.getProperty("maxNum")); + assertThat(item.getProperty("a")).isEqualTo("aaa"); + assertThat((int) item.getProperty("maxNum")).isEqualTo(3); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertEquals("bbb", item.getProperty("a")); - Assertions.assertEquals(6, (int) item.getProperty("maxNum")); + assertThat(item.getProperty("a")).isEqualTo("bbb"); + assertThat((int) item.getProperty("maxNum")).isEqualTo(6); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1793,13 +1792,13 @@ public void testOrderByOutOfProjAsc() { final ResultSet result = database.query("sql", query); for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals("aaa", item.getProperty("name")); - Assertions.assertEquals(i, (int) item.getProperty("num")); + assertThat(item.getProperty("name")).isEqualTo("aaa"); + assertThat((int) item.getProperty("num")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1817,13 +1816,13 @@ public void testOrderByOutOfProjDesc() { final ResultSet result = database.query("sql", query); for (int i = 2; i >= 0; i--) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals("aaa", item.getProperty("name")); - Assertions.assertEquals(i, (int) item.getProperty("num")); + assertThat(item.getProperty("name")).isEqualTo("aaa"); + assertThat((int) item.getProperty("num")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1840,15 +1839,15 @@ public void testUnwind() { int sum = 0; final ResultSet result = database.query("sql", query); for (int i = 0; i < 4; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - sum += (Integer) item.getProperty("num"); + sum += item.getProperty("num"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); - Assertions.assertEquals(10, sum); + assertThat(sum).isEqualTo(10); } @Test @@ -1865,15 +1864,15 @@ public void testSkip() { final ResultSet result = database.query("sql", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals("bbb", item.getProperty("name")); + assertThat(item.getProperty("name")).isEqualTo("bbb"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertEquals("ccc", item.getProperty("name")); + assertThat(item.getProperty("name")).isEqualTo("ccc"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1902,31 +1901,31 @@ public void testDepthAlias() { int sum = 0; for (int i = 0; i < 4; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Object depth = item.getProperty("xy"); - Assertions.assertTrue(depth instanceof Integer); - Assertions.assertEquals("aaa", item.getProperty("name")); + assertThat(depth instanceof Integer).isTrue(); + assertThat(item.getProperty("name")).isEqualTo("aaa"); switch ((int) depth) { case 0: - Assertions.assertEquals("aaa", item.getProperty("bname")); + assertThat(item.getProperty("bname")).isEqualTo("aaa"); break; case 1: - Assertions.assertEquals("bbb", item.getProperty("bname")); + assertThat(item.getProperty("bname")).isEqualTo("bbb"); break; case 2: - Assertions.assertEquals("ccc", item.getProperty("bname")); + assertThat(item.getProperty("bname")).isEqualTo("ccc"); break; case 3: - Assertions.assertEquals("ddd", item.getProperty("bname")); + assertThat(item.getProperty("bname")).isEqualTo("ddd"); break; default: - fail(); + fail(""); } sum += (int) depth; } - Assertions.assertEquals(sum, 6); - Assertions.assertFalse(result.hasNext()); + assertThat(sum).isEqualTo(6); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1954,30 +1953,30 @@ public void testPathAlias() { final ResultSet result = database.query("sql", query); for (int i = 0; i < 4; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Object path = item.getProperty("xy"); - Assertions.assertTrue(path instanceof List); + assertThat(path instanceof List).isTrue(); final List thePath = (List) path; final String bname = item.getProperty("bname"); if (bname.equals("aaa")) { - Assertions.assertEquals(0, thePath.size()); + assertThat(thePath.size()).isEqualTo(0); } else if (bname.equals("aaa")) { - Assertions.assertEquals(1, thePath.size()); - Assertions.assertEquals("bbb", ((Document) thePath.get(0).getRecord()).getString("name")); + assertThat(thePath.size()).isEqualTo(1); + assertThat(((Document) thePath.get(0).getRecord()).getString("name")).isEqualTo("bbb"); } else if (bname.equals("ccc")) { - Assertions.assertEquals(2, thePath.size()); - Assertions.assertEquals("bbb", ((Document) thePath.get(0).getRecord()).getString("name")); - Assertions.assertEquals("ccc", ((Document) thePath.get(1).getRecord()).getString("name")); + assertThat(thePath.size()).isEqualTo(2); + assertThat(((Document) thePath.get(0).getRecord()).getString("name")).isEqualTo("bbb"); + assertThat(((Document) thePath.get(1).getRecord()).getString("name")).isEqualTo("ccc"); } else if (bname.equals("ddd")) { - Assertions.assertEquals(3, thePath.size()); - Assertions.assertEquals("bbb", ((Document) thePath.get(0).getRecord()).getString("name")); - Assertions.assertEquals("ccc", ((Document) thePath.get(1).getRecord()).getString("name")); - Assertions.assertEquals("ddd", ((Document) thePath.get(2).getRecord()).getString("name")); + assertThat(thePath.size()).isEqualTo(3); + assertThat(((Document) thePath.get(0).getRecord()).getString("name")).isEqualTo("bbb"); + assertThat(((Document) thePath.get(1).getRecord()).getString("name")).isEqualTo("ccc"); + assertThat(((Document) thePath.get(2).getRecord()).getString("name")).isEqualTo("ddd"); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2018,59 +2017,56 @@ public void testBucketTarget() { final ResultSet result = database.query("SQL", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals("one", item.getProperty("aname")); - Assertions.assertEquals("two", item.getProperty("bname")); + assertThat(item.getProperty("aname")).isEqualTo("one"); + assertThat(item.getProperty("bname")).isEqualTo("two"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); - Assertions.assertTrue(database.getSchema().getIndexByName(clazz + "[name]").get(new String[] { "one" }).hasNext()); - Assertions.assertTrue(database.getSchema().getIndexByName(clazz + "[name]").get(new String[] { "onex" }).hasNext()); - Assertions.assertTrue(database.getSchema().getIndexByName(clazz + "[name]").get(new String[] { "two" }).hasNext()); - Assertions.assertTrue(database.getSchema().getIndexByName(clazz + "[name]").get(new String[] { "three" }).hasNext()); + assertThat(database.getSchema().getIndexByName(clazz + "[name]").get(new String[]{"one"}).hasNext()).isTrue(); + assertThat(database.getSchema().getIndexByName(clazz + "[name]").get(new String[]{"onex"}).hasNext()).isTrue(); + assertThat(database.getSchema().getIndexByName(clazz + "[name]").get(new String[]{"two"}).hasNext()).isTrue(); + assertThat(database.getSchema().getIndexByName(clazz + "[name]").get(new String[]{"three"}).hasNext()).isTrue(); //-------------------------------------------------------------------------------------------------------- // CHECK THE SUB-INDEX EXISTS - Assertions.assertTrue(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() - .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) - .contains(database.getSchema().getBucketByName(clazz + "_one").getFileId())); + assertThat(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() + .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) + .contains(database.getSchema().getBucketByName(clazz + "_one").getFileId())).isTrue(); database.command("SQL", "ALTER TYPE " + clazz + " BUCKET -" + clazz + "_one").close(); // CHECK THE SUB-INDEX HAS BEN REMOVED - Assertions.assertFalse( - Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() - .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) - .contains(database.getSchema().getBucketByName(clazz + "_one").getFileId())); + assertThat(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() + .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) + .contains(database.getSchema().getBucketByName(clazz + "_one").getFileId())).isFalse(); //-------------------------------------------------------------------------------------------------------- // CHECK THE SUB-INDEX EXISTS - Assertions.assertTrue(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() - .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) - .contains(database.getSchema().getBucketByName(clazz + "_two").getFileId())); + assertThat(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() + .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) + .contains(database.getSchema().getBucketByName(clazz + "_two").getFileId())).isTrue(); database.command("SQL", "ALTER TYPE " + clazz + " BUCKET -" + clazz + "_two").close(); // CHECK THE SUB-INDEX HAS BEN REMOVED - Assertions.assertFalse( - Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() - .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) - .contains(database.getSchema().getBucketByName(clazz + "_two").getFileId())); + assertThat(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() + .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) + .contains(database.getSchema().getBucketByName(clazz + "_two").getFileId())).isFalse(); //-------------------------------------------------------------------------------------------------------- // CHECK THE SUB-INDEX EXISTS - Assertions.assertTrue(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() - .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) - .contains(database.getSchema().getBucketByName(clazz + "_three").getFileId())); + assertThat(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() + .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) + .contains(database.getSchema().getBucketByName(clazz + "_three").getFileId())).isTrue(); database.command("SQL", "ALTER TYPE " + clazz + " BUCKET -" + clazz + "_three").close(); // CHECK THE SUB-INDEX HAS BEN REMOVED - Assertions.assertFalse( - Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() - .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) - .contains(database.getSchema().getBucketByName(clazz + "_three").getFileId())); + assertThat(Set.of(((TypeIndex) database.getSchema().getIndexByName(clazz + "[name]")).getIndexesOnBuckets()).stream() + .map((r) -> r.getAssociatedBucketId()).collect(Collectors.toSet()) + .contains(database.getSchema().getBucketByName(clazz + "_three").getFileId())).isFalse(); result.close(); } @@ -2100,9 +2096,9 @@ public void testNegativePattern() { query += " RETURN $patterns"; final ResultSet result = database.query("SQL", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2133,7 +2129,7 @@ public void testNegativePattern2() { query += " RETURN $patterns"; final ResultSet result = database.query("SQL", query); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2164,9 +2160,9 @@ public void testNegativePattern3() { query += " RETURN $patterns"; final ResultSet result = database.query("SQL", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2198,12 +2194,12 @@ public void testPathTraversal() { query += " RETURN a.name as a, b.name as b"; ResultSet result = database.query("SQL", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals("a", item.getProperty("a")); - Assertions.assertEquals("b", item.getProperty("b")); + assertThat(item.getProperty("a")).isEqualTo("a"); + assertThat(item.getProperty("b")).isEqualTo("b"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); @@ -2211,12 +2207,12 @@ public void testPathTraversal() { query += " RETURN a.name as a, b.name as b"; result = database.query("SQL", query); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertEquals("a", item.getProperty("a")); - Assertions.assertEquals("b", item.getProperty("b")); + assertThat(item.getProperty("a")).isEqualTo("a"); + assertThat(item.getProperty("b")).isEqualTo("b"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2242,7 +2238,7 @@ public void testQuotedClassName() { final String query = "MATCH {type: `" + className + "`, as:foo} RETURN $elements"; try (final ResultSet rs = database.query("SQL", query)) { - Assertions.assertEquals(1L, rs.stream().count()); + assertThat(rs.stream().count()).isEqualTo(1L); } } @@ -2250,7 +2246,7 @@ public void testQuotedClassName() { public void testMatchInSubQuery() { try (final ResultSet rs = database.query("SQL", "SELECT $a LET $a=(MATCH{type:Person,as:Person_0}RETURN expand(Person_0))")) { - Assertions.assertEquals(1L, rs.stream().count()); + assertThat(rs.stream().count()).isEqualTo(1L); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/MoveVertexStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/MoveVertexStatementExecutionTest.java index af1216018a..95af2f547e 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/MoveVertexStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/MoveVertexStatementExecutionTest.java @@ -1,9 +1,10 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * original @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdatabase.com) * Ported by @author Luca Garulli (l.garulli@arcadedata.com) @@ -37,27 +38,27 @@ public void testMoveVertex() { + vertexClassName1 + " where name = 'a') to type:" + vertexClassName2); ResultSet rs = database.query("sql", "select from " + vertexClassName1); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("sql", "select from " + vertexClassName2); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("sql", "select expand(out()) from " + vertexClassName2); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("sql", "select expand(in()) from " + vertexClassName1); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); } @@ -88,27 +89,27 @@ public void testMoveVertexBatch() { + vertexClassName1 + " where name = 'a') to type:" + vertexClassName2 + " BATCH 2"); ResultSet rs = database.query("sql", "select from " + vertexClassName1); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("sql", "select from " + vertexClassName2); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("sql", "select expand(out()) from " + vertexClassName2); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); rs = database.query("sql", "select expand(in()) from " + vertexClassName1); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); rs.close(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/ProfileStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/ProfileStatementExecutionTest.java index d4b0a05490..7c59b3fadf 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/ProfileStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/ProfileStatementExecutionTest.java @@ -19,9 +19,12 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -34,7 +37,7 @@ public void testProfile() throws Exception { db.command("sql", "insert into testProfile set name ='bar'"); final ResultSet result = db.query("sql", "PROFILE SELECT FROM testProfile WHERE name ='bar'"); - Assertions.assertTrue(result.getExecutionPlan().get().prettyPrint(0, 2).contains("μs")); + assertThat(result.getExecutionPlan().get().prettyPrint(0, 2).contains("μs")).isTrue(); result.close(); }); diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/ResultSetTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/ResultSetTest.java index 711902bab3..4682397c1b 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/ResultSetTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/ResultSetTest.java @@ -18,11 +18,12 @@ */ package com.arcadedb.query.sql.executor; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Created by luigidellaquila on 04/11/16. */ @@ -36,8 +37,8 @@ public void testResultStream() { rs.add(item); } final Optional result = rs.stream().map(x -> (int) x.getProperty("i")).reduce((a, b) -> a + b); - Assertions.assertTrue(result.isPresent()); - Assertions.assertEquals(45, result.get().intValue()); + assertThat(result.isPresent()).isTrue(); + assertThat(result.get().intValue()).isEqualTo(45); } @Test @@ -49,7 +50,7 @@ public void testResultEmptyVertexStream() { rs.add(item); } final Optional result = rs.vertexStream().map(x -> (int) x.get("i")).reduce((a, b) -> a + b); - Assertions.assertFalse(result.isPresent()); + assertThat(result.isPresent()).isFalse(); } @Test @@ -61,7 +62,7 @@ public void testResultEdgeVertexStream() { rs.add(item); } final Optional result = rs.vertexStream().map(x -> (int) x.get("i")).reduce((a, b) -> a + b); - Assertions.assertFalse(result.isPresent()); + assertThat(result.isPresent()).isFalse(); } @Test @@ -71,13 +72,13 @@ public void testResultConversion() { item.setProperty("long", 10L); item.setProperty("short", (short) 10); - Assertions.assertEquals(10, (int) item.getProperty("int", 10)); - Assertions.assertEquals(10L, (int) item.getProperty("int", 10L)); + assertThat((int) item.getProperty("int", 10)).isEqualTo(10); + assertThat((int) item.getProperty("int", 10L)).isEqualTo(10L); - Assertions.assertEquals(10L, (long) item.getProperty("long", 10)); - Assertions.assertEquals(10L, (long) item.getProperty("long", 10L)); + assertThat((long) item.getProperty("long", 10)).isEqualTo(10L); + assertThat((long) item.getProperty("long", 10L)).isEqualTo(10L); - Assertions.assertEquals(10, (int) item.getProperty("absent", 10)); - Assertions.assertEquals(10L, (long) item.getProperty("absent", 10L)); + assertThat((int) item.getProperty("absent", 10)).isEqualTo(10); + assertThat((long) item.getProperty("absent", 10L)).isEqualTo(10L); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/ScriptExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/ScriptExecutionTest.java index 014bb7beb0..6053370d87 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/ScriptExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/ScriptExecutionTest.java @@ -11,11 +11,14 @@ import com.arcadedb.exception.ConcurrentModificationException; import com.arcadedb.query.sql.SQLQueryEngine; import com.arcadedb.query.sql.function.SQLFunctionAbstract; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdatabase.com) */ @@ -54,7 +57,7 @@ public void testTwoInserts() { "INSERT INTO " + className + " SET name = 'foo';INSERT INTO " + className + " SET name = 'bar';"); }); ResultSet rs = database.query("sql", "SELECT count(*) as count from " + className); - Assertions.assertEquals((Object) 2L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 2L); } @Test @@ -76,7 +79,7 @@ public void testIf() { database.command("sqlscript", script); }); ResultSet rs = database.query("sql", "SELECT count(*) as count from " + className); - Assertions.assertEquals((Object) 2L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo( 2L); } @Test @@ -97,7 +100,7 @@ public void testReturnInIf() { }); final ResultSet rs = database.query("sql", "SELECT count(*) as count from " + className); - Assertions.assertEquals((Object) 2L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo(2L); } @Test @@ -117,7 +120,7 @@ public void testReturnInIf2() { Result item = result.next(); - Assertions.assertEquals("OK", item.getProperty("value")); + assertThat(item.getProperty("value")).isEqualTo("OK"); result.close(); }); } @@ -139,7 +142,7 @@ public void testReturnInIf3() { Result item = result.next(); - Assertions.assertEquals("OK", item.getProperty("value")); + assertThat(item.getProperty("value")).isEqualTo("OK"); result.close(); }); } @@ -158,7 +161,7 @@ public void testLazyExecutionPlanning() { Result item = result.next(); - Assertions.assertEquals("OK", item.getProperty("value")); + assertThat(item.getProperty("value")).isEqualTo("OK"); result.close(); }); } @@ -184,10 +187,10 @@ public void testCommitRetry() { }); ResultSet result = database.query("sql", "select from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals(4, (int) item.getProperty("attempt")); - Assertions.assertFalse(result.hasNext()); + assertThat((int) item.getProperty("attempt")).isEqualTo(4); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -215,10 +218,10 @@ public void testCommitRetryMultiThreadsSQLIncrement() throws IOException { database.async().waitCompletion(); ResultSet result = database.query("sql", "select from " + className + " where id = 0"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - //Assertions.assertTrue((Integer) item.getProperty("attempt") < TOTAL); - Assertions.assertFalse(result.hasNext()); + //Assertions.assertThat((Integer).isTrue() item.getProperty("attempt") < TOTAL); + assertThat(result.hasNext()).isFalse(); result.close(); // USE RETRY, EXPECTING NO MISS OF UPDATES @@ -243,7 +246,7 @@ public void testCommitRetryMultiThreadsSQLIncrement() throws IOException { ImmutablePage page = ((LocalDatabase) database).getPageManager().getImmutablePage(new PageId(2, 0), ((PaginatedComponentFile) ((LocalDatabase) database).getFileManager().getFile(2)).getPageSize(), false, false); - Assertions.assertEquals(TOTAL + 1, page.getVersion(), "Page v." + page.getVersion()); + assertThat(page.getVersion()).as("Page v." + page.getVersion()).isEqualTo(TOTAL + 1); } @Test @@ -270,10 +273,10 @@ public void testCommitRetryMultiThreadsSQLIncrementRepeatableRead() throws IOExc database.async().waitCompletion(); ResultSet result = database.query("sql", "select from " + className + " where id = 0"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertTrue((Integer) item.getProperty("attempt") < TOTAL, "Found attempts = " + item.getProperty("attempt")); - Assertions.assertFalse(result.hasNext()); + assertThat((Integer) item.getProperty("attempt") < TOTAL).as("Found attempts = " + item.getProperty("attempt")).isTrue(); + assertThat(result.hasNext()).isFalse(); result.close(); // USE RETRY, EXPECTING NO MISS OF UPDATES @@ -298,13 +301,13 @@ public void testCommitRetryMultiThreadsSQLIncrementRepeatableRead() throws IOExc ImmutablePage page = ((LocalDatabase) database).getPageManager().getImmutablePage(new PageId(2, 0), ((PaginatedComponentFile) ((LocalDatabase) database).getFileManager().getFile(2)).getPageSize(), false, false); - Assertions.assertEquals(TOTAL + 1, page.getVersion(), "Page v." + page.getVersion()); + assertThat(page.getVersion()).as("Page v." + page.getVersion()).isEqualTo(TOTAL + 1); result = database.query("sql", "select from " + className + " where id = 1"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertEquals(TOTAL, (Integer) item.getProperty("attempt")); - Assertions.assertFalse(result.hasNext()); + assertThat((Integer) item.getProperty("attempt")).isEqualTo(TOTAL); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -329,7 +332,7 @@ public void testCommitRetryWithFailure() { } ResultSet result = database.query("sql", "select from " + className); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); }); } @@ -354,10 +357,10 @@ public void testCommitRetryWithFailureAndContinue() { database.command("sqlscript", script); ResultSet result = database.query("sql", "select from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals("foo", item.getProperty("name")); - Assertions.assertFalse(result.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("foo"); + assertThat(result.hasNext()).isFalse(); result.close(); }); } @@ -384,10 +387,10 @@ public void testCommitRetryWithFailureScriptAndContinue() { }); ResultSet result = database.query("sql", "select from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals("foo", item.getProperty("name")); - Assertions.assertFalse(result.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("foo"); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -417,10 +420,10 @@ public void testCommitRetryWithFailureScriptAndFail() { }); ResultSet result = database.query("sql", "select from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals("foo", item.getProperty("name")); - Assertions.assertFalse(result.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("foo"); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -450,10 +453,10 @@ public void testCommitRetryWithFailureScriptAndFail2() { } ResultSet result = database.query("sql", "select from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertEquals("foo", item.getProperty("name")); - Assertions.assertFalse(result.hasNext()); + assertThat(item.getProperty("name")).isEqualTo("foo"); + assertThat(result.hasNext()).isFalse(); result.close(); }); } @@ -471,10 +474,10 @@ public void testFunctionAsStatement() { } ResultSet rs = database.command("sqlscript", script); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); Result item = rs.next(); - Assertions.assertEquals(8, (Integer) item.getProperty("result")); - Assertions.assertFalse(rs.hasNext()); + assertThat((Integer) item.getProperty("result")).isEqualTo(8); + assertThat(rs.hasNext()).isFalse(); rs.close(); }); @@ -510,9 +513,9 @@ public void testAssignOnEdgeCreate() { database.command("sqlscript", script).close(); try (ResultSet rs = database.query("sql", "select from IndirectEdge")) { - Assertions.assertTrue(rs.hasNext()); - Assertions.assertEquals("foo2", rs.next().getProperty("Source")); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); + assertThat(rs.next().getProperty("Source")).isEqualTo("foo2"); + assertThat(rs.hasNext()).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTest.java index c8b72fcbcd..38145a0f8d 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTest.java @@ -34,23 +34,26 @@ import com.arcadedb.schema.Property; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.lang.reflect.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class SelectStatementExecutionTest extends TestHelper { @Test public void testSelectNoTarget() { final ResultSet result = database.query("sql", "select 1 as one, 2 as two, 2+3"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(1, item.getProperty("one")); - Assertions.assertEquals(2, item.getProperty("two")); - Assertions.assertEquals(5, item.getProperty("2 + 3")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("one")).isEqualTo(1); + assertThat(item.getProperty("two")).isEqualTo(2); + assertThat(item.getProperty("2 + 3")).isEqualTo(5); result.close(); } @@ -76,8 +79,8 @@ public void testGroupByCount() { "select address, count(*) as occurrences from InputTx where address is not null group by address limit 10"); while (result.hasNext()) { final Result row = result.next(); - Assertions.assertNotNull(row.getProperty("address")); // <== FALSE! - Assertions.assertNotNull(row.getProperty("occurrences")); + assertThat(row.getProperty("address")).isNotNull(); // <== FALSE! + assertThat(row.getProperty("occurrences")).isNotNull(); } result.close(); } @@ -85,7 +88,7 @@ public void testGroupByCount() { @Test public void testSelectNoTargetSkip() { final ResultSet result = database.query("sql", "select 1 as one, 2 as two, 2+3 skip 1"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -93,12 +96,12 @@ public void testSelectNoTargetSkip() { @Test public void testSelectNoTargetSkipZero() { final ResultSet result = database.query("sql", "select 1 as one, 2 as two, 2+3 skip 0"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(1, item.getProperty("one")); - Assertions.assertEquals(2, item.getProperty("two")); - Assertions.assertEquals(5, item.getProperty("2 + 3")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("one")).isEqualTo(1); + assertThat(item.getProperty("two")).isEqualTo(2); + assertThat(item.getProperty("2 + 3")).isEqualTo(5); result.close(); } @@ -106,7 +109,7 @@ public void testSelectNoTargetSkipZero() { @Test public void testSelectNoTargetLimit0() { final ResultSet result = database.query("sql", "select 1 as one, 2 as two, 2+3 limit 0"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -114,12 +117,12 @@ public void testSelectNoTargetLimit0() { @Test public void testSelectNoTargetLimit1() { final ResultSet result = database.query("sql", "select 1 as one, 2 as two, 2+3 limit 1"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(1, item.getProperty("one")); - Assertions.assertEquals(2, item.getProperty("two")); - Assertions.assertEquals(5, item.getProperty("2 + 3")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("one")).isEqualTo(1); + assertThat(item.getProperty("two")).isEqualTo(2); + assertThat(item.getProperty("2 + 3")).isEqualTo(5); result.close(); } @@ -144,12 +147,12 @@ public void testSelectFullScan1() { database.commit(); final ResultSet result = database.query("sql", "select from " + className); for (int i = 0; i < 100000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(("" + item.getProperty("name")).startsWith("name")); + assertThat(item).isNotNull(); + assertThat(("" + item.getProperty("name")).startsWith("name")).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -168,16 +171,16 @@ public void testSelectFullScanOrderByRidAsc() { final ResultSet result = database.query("sql", "select from " + className + " ORDER BY @rid ASC"); Document lastItem = null; for (int i = 0; i < 100000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(("" + item.getProperty("name")).startsWith("name")); + assertThat(item).isNotNull(); + assertThat(("" + item.getProperty("name")).startsWith("name")).isTrue(); if (lastItem != null) { - Assertions.assertTrue(lastItem.getIdentity().compareTo(item.getElement().get().getIdentity()) < 0); + assertThat(lastItem.getIdentity().compareTo(item.getElement().get().getIdentity()) < 0).isTrue(); } lastItem = item.getElement().get(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -197,16 +200,16 @@ public void testSelectFullScanOrderByRidDesc() { final ResultSet result = database.query("sql", "select from " + className + " ORDER BY @rid DESC"); Document lastItem = null; for (int i = 0; i < 100000; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(("" + item.getProperty("name")).startsWith("name")); + assertThat(item).isNotNull(); + assertThat(("" + item.getProperty("name")).startsWith("name")).isTrue(); if (lastItem != null) { - Assertions.assertTrue(lastItem.getIdentity().compareTo(item.getElement().get().getIdentity()) > 0); + assertThat(lastItem.getIdentity().compareTo(item.getElement().get().getIdentity()) > 0).isTrue(); } lastItem = item.getElement().get(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -227,12 +230,12 @@ public void testSelectFullScanLimit1() { final ResultSet result = database.query("sql", "select from " + className + " limit 10"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(("" + item.getProperty("name")).startsWith("name")); + assertThat(item).isNotNull(); + assertThat(("" + item.getProperty("name")).startsWith("name")).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -252,12 +255,12 @@ public void testSelectFullScanSkipLimit1() { final ResultSet result = database.query("sql", "select from " + className + " skip 100 limit 10"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(("" + item.getProperty("name")).startsWith("name")); + assertThat(item).isNotNull(); + assertThat(("" + item.getProperty("name")).startsWith("name")).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -278,16 +281,16 @@ public void testSelectOrderByDesc() { String lastSurname = null; for (int i = 0; i < 30; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - final String thisSurname = item.getProperty("surname"); + assertThat(item).isNotNull(); + final String thisSurname = item.getProperty("surname"); if (lastSurname != null) { - Assertions.assertTrue(lastSurname.compareTo(thisSurname) >= 0); + assertThat(lastSurname.compareTo(thisSurname) >= 0).isTrue(); } lastSurname = thisSurname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -307,16 +310,16 @@ public void testSelectOrderByAsc() { String lastSurname = null; for (int i = 0; i < 30; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - final String thisSurname = item.getProperty("surname"); + assertThat(item).isNotNull(); + final String thisSurname = item.getProperty("surname"); if (lastSurname != null) { - Assertions.assertTrue(lastSurname.compareTo(thisSurname) <= 0); + assertThat(lastSurname.compareTo(thisSurname) <= 0).isTrue(); } lastSurname = thisSurname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -337,12 +340,12 @@ public void testSelectOrderByMassiveAsc() { // System.out.println("elapsed: " + (System.nanoTime() - begin)); for (int i = 0; i < 100; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("surname0", item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isEqualTo("surname0"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -364,17 +367,17 @@ public void testSelectOrderWithProjections() { String lastName = null; for (int i = 0; i < 100; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - Assertions.assertNotNull(name); + assertThat(name).isNotNull(); if (i > 0) { - Assertions.assertTrue(name.compareTo(lastName) >= 0); + assertThat(name.compareTo(lastName) >= 0).isTrue(); } lastName = name; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -396,17 +399,17 @@ public void testSelectOrderWithProjections2() { String lastName = null; for (int i = 0; i < 100; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - Assertions.assertNotNull(name); + assertThat(name).isNotNull(); if (i > 0) { - Assertions.assertTrue(name.compareTo(lastName) >= 0); + assertThat(name.compareTo(lastName) >= 0).isTrue(); } lastName = name; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -425,13 +428,13 @@ public void testSelectFullScanWithFilter1() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name1' or name = 'name7' "); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object name = item.getProperty("name"); - Assertions.assertTrue("name1".equals(name) || "name7".equals(name)); + assertThat("name1".equals(name) || "name7".equals(name)).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -450,13 +453,13 @@ public void testSelectFullScanWithFilter2() { final ResultSet result = database.query("sql", "select from " + className + " where name <> 'name1' "); for (int i = 0; i < 299; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object name = item.getProperty("name"); - Assertions.assertFalse("name1".equals(name)); + assertThat(name).isNotEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -475,17 +478,17 @@ public void testProjections() { final ResultSet result = database.query("sql", "select name from " + className); for (int i = 0; i < 300; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - final String surname = item.getProperty("surname"); - Assertions.assertNotNull(name); - Assertions.assertTrue(name.startsWith("name")); - Assertions.assertNull(surname); - Assertions.assertFalse(item.getElement().isPresent()); + final String surname = item.getProperty("surname"); + assertThat(name).isNotNull(); + assertThat(name.startsWith("name")).isTrue(); + assertThat(surname).isNull(); + assertThat(item.getElement().isPresent()).isFalse(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -503,16 +506,16 @@ public void testCountStar() { try { final ResultSet result = database.query("sql", "select count(*) from " + className); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat(Optional.ofNullable(result)).isNotNull(); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals(7L, (Object) next.getProperty("count(*)")); - Assertions.assertFalse(result.hasNext()); + assertThat(next).isNotNull(); + assertThat((Object) next.getProperty("count(*)")).isEqualTo(7L); + assertThat(result.hasNext()).isFalse(); result.close(); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail(); + fail(""); } } @@ -531,18 +534,18 @@ public void testCountStar2() { try { final ResultSet result = database.query("sql", "select count(*), name from " + className + " group by name"); - Assertions.assertNotNull(result); + assertThat(Optional.ofNullable(result)).isNotNull(); for (int i = 0; i < 5; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals(2L, (Object) next.getProperty("count(*)")); + assertThat(next).isNotNull(); + assertThat((Object) next.getProperty("count(*)")).isEqualTo(2L); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail(); + fail(""); } } @@ -560,16 +563,16 @@ public void testCountStarEmptyNoIndex() { try { final ResultSet result = database.query("sql", "select count(*) from " + className + " where name = 'foo'"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat(Optional.ofNullable(result)).isNotNull(); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals(0L, (Object) next.getProperty("count(*)")); - Assertions.assertFalse(result.hasNext()); + assertThat(next).isNotNull(); + assertThat((Object) next.getProperty("count(*)")).isEqualTo(0L); + assertThat(result.hasNext()).isFalse(); result.close(); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail(); + fail(""); } } @@ -587,16 +590,16 @@ public void testCountStarEmptyNoIndexWithAlias() { try { final ResultSet result = database.query("sql", "select count(*) as a from " + className + " where name = 'foo'"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat(Optional.ofNullable(result)).isNotNull(); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals(0L, (Object) next.getProperty("a")); - Assertions.assertFalse(result.hasNext()); + assertThat(next).isNotNull(); + assertThat((Object) next.getProperty("a")).isEqualTo(0L); + assertThat(result.hasNext()).isFalse(); result.close(); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail(); + fail(""); } } @@ -607,11 +610,11 @@ public void testAggregateMixedWithNonAggregate() { try { database.query("sql", "select max(a) + max(b) + pippo + pluto as foo, max(d) + max(e), f from " + className).close(); - Assertions.fail(); + fail(""); } catch (final CommandExecutionException x) { } catch (final Exception e) { - Assertions.fail(); + fail(""); } } @@ -622,11 +625,11 @@ public void testAggregateMixedWithNonAggregateInCollection() { try { database.query("sql", "select [max(a), max(b), foo] from " + className).close(); - Assertions.fail(); + fail(""); } catch (final CommandExecutionException x) { } catch (final Exception e) { - Assertions.fail(); + fail(""); } } @@ -640,7 +643,7 @@ public void testAggregateInCollection() { final ResultSet result = database.query("sql", query); result.close(); } catch (final Exception x) { - Assertions.fail(); + fail(""); } } @@ -656,7 +659,7 @@ public void testAggregateMixedWithNonAggregateConstants() { result.close(); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail(); + fail(""); } } @@ -673,10 +676,10 @@ public void testAggregateSum() { } database.commit(); final ResultSet result = database.query("sql", "select sum(val) from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(45, (Object) item.getProperty("sum(val)")); + assertThat(item).isNotNull(); + assertThat((Object) item.getProperty("sum(val)")).isEqualTo(45); result.close(); } @@ -697,20 +700,20 @@ public void testAggregateSumGroupBy() { boolean evenFound = false; boolean oddFound = false; for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); if ("even".equals(item.getProperty("type"))) { - Assertions.assertEquals(20, item.getProperty("sum(val)")); + assertThat(item.getProperty("sum(val)")).isEqualTo(20); evenFound = true; } else if ("odd".equals(item.getProperty("type"))) { - Assertions.assertEquals(25, item.getProperty("sum(val)")); + assertThat(item.getProperty("sum(val)")).isEqualTo(25); oddFound = true; } } - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(evenFound); - Assertions.assertTrue(oddFound); + assertThat(result.hasNext()).isFalse(); + assertThat(evenFound).isTrue(); + assertThat(oddFound).isTrue(); result.close(); } @@ -731,24 +734,24 @@ public void testAggregateSumMaxMinGroupBy() { boolean evenFound = false; boolean oddFound = false; for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); if ("even".equals(item.getProperty("type"))) { - Assertions.assertEquals(20, item.getProperty("sum(val)")); - Assertions.assertEquals(8, item.getProperty("max(val)")); - Assertions.assertEquals(0, item.getProperty("min(val)")); + assertThat(item.getProperty("sum(val)")).isEqualTo(20); + assertThat(item.getProperty("max(val)")).isEqualTo(8); + assertThat(item.getProperty("min(val)")).isEqualTo(0); evenFound = true; } else if ("odd".equals(item.getProperty("type"))) { - Assertions.assertEquals(25, item.getProperty("sum(val)")); - Assertions.assertEquals(9, item.getProperty("max(val)")); - Assertions.assertEquals(1, item.getProperty("min(val)")); + assertThat(item.getProperty("sum(val)")).isEqualTo(25); + assertThat(item.getProperty("max(val)")).isEqualTo(9); + assertThat(item.getProperty("min(val)")).isEqualTo(1); oddFound = true; } } - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(evenFound); - Assertions.assertTrue(oddFound); + assertThat(result.hasNext()).isFalse(); + assertThat(evenFound).isTrue(); + assertThat(oddFound).isTrue(); result.close(); } @@ -768,9 +771,9 @@ public void testAggregateSumNoGroupByInProjection() { boolean evenFound = false; boolean oddFound = false; for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object sum = item.getProperty("sum(val)"); if (sum.equals(20)) { evenFound = true; @@ -778,9 +781,9 @@ public void testAggregateSumNoGroupByInProjection() { oddFound = true; } } - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(evenFound); - Assertions.assertTrue(oddFound); + assertThat(result.hasNext()).isFalse(); + assertThat(evenFound).isTrue(); + assertThat(oddFound).isTrue(); result.close(); } @@ -798,13 +801,13 @@ public void testAggregateSumNoGroupByInProjection2() { database.commit(); final ResultSet result = database.query("sql", "select sum(val) from " + className + " group by type.substring(0,1)"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object sum = item.getProperty("sum(val)"); - Assertions.assertEquals(45, sum); + assertThat(sum).isEqualTo(45); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -825,14 +828,14 @@ public void testFetchFromBucketNumber() { final ResultSet result = database.query("sql", "select from bucket:" + targetClusterName); int sum = 0; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Integer val = item.getProperty("val"); - Assertions.assertNotNull(val); + assertThat(val).isNotNull(); sum += val; } - Assertions.assertEquals(45, sum); - Assertions.assertFalse(result.hasNext()); + assertThat(sum).isEqualTo(45); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -854,13 +857,13 @@ public void testFetchFromBucketNumberOrderByRidDesc() { final ResultSet result = database.query("sql", "select from bucket:" + targetBucketName + " order by @rid desc"); final int sum = 0; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Integer val = item.getProperty("val"); - Assertions.assertEquals(i, 9 - val); + assertThat(9 - val).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -882,13 +885,13 @@ public void testFetchFromClusterNumberOrderByRidAsc() { final ResultSet result = database.query("sql", "select from bucket:" + targetClusterName + " order by @rid asc"); final int sum = 0; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Integer val = item.getProperty("val"); - Assertions.assertEquals((Object) i, val); + assertThat(val).isEqualTo((Object) i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -922,13 +925,13 @@ public void testFetchFromClustersNumberOrderByRidAsc() { "select from bucket:[" + targetClusterName + ", " + targetClusterName2 + "] order by @rid asc"); for (int i = 0; i < 20; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Integer val = item.getProperty("val"); - Assertions.assertEquals((Object) (i % 10), val); + assertThat(val).isEqualTo((Object) (i % 10)); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -948,13 +951,13 @@ public void testQueryAsTarget() { final ResultSet result = database.query("sql", "select from (select from " + className + " where val > 2) where val < 8"); for (int i = 0; i < 5; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Integer val = item.getProperty("val"); - Assertions.assertTrue(val > 2); - Assertions.assertTrue(val < 8); + assertThat(val > 2).isTrue(); + assertThat(val < 8).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -965,17 +968,17 @@ public void testQuerySchema() { final ResultSet result = database.query("sql", "select from schema:types"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals("testQuerySchema", item.getProperty("name")); + assertThat(item.getProperty("name")).isEqualTo("testQuerySchema"); final Map customType = item.getProperty("custom"); - Assertions.assertNotNull(customType); - Assertions.assertEquals(1, customType.size()); + assertThat(customType).isNotNull(); + assertThat(customType.size()).isEqualTo(1); - Assertions.assertEquals("this is just a test", customType.get("description")); + assertThat(customType.get("description")).isEqualTo("this is just a test"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -988,13 +991,13 @@ public void testQueryMetadataIndexManager() { final ResultSet result = database.query("sql", "select from schema:indexes"); while (result.hasNext()) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item.getProperty("name")); - Assertions.assertEquals("STRING", ((List) item.getProperty("keyTypes")).get(0)); - Assertions.assertFalse((Boolean) item.getProperty("unique")); + assertThat(item.getProperty("name")).isNotNull(); + assertThat( item.>getProperty("keyTypes")).first().isEqualTo("STRING"); + assertThat( item.getProperty("unique")).isFalse(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1002,10 +1005,10 @@ public void testQueryMetadataIndexManager() { public void testQueryMetadataDatabase() { final ResultSet result = database.query("sql", "select from schema:database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item.getProperty("name")); - Assertions.assertFalse(result.hasNext()); + assertThat(item.getProperty("name")).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1013,7 +1016,7 @@ public void testQueryMetadataDatabase() { public void testNonExistingRids() { final int bucketId = database.getSchema().createDocumentType("testNonExistingRids").getBuckets(false).get(0).getFileId(); final ResultSet result = database.query("sql", "select from #" + bucketId + ":100000000"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); try { result.next(); @@ -1031,9 +1034,9 @@ public void testFetchFromSingleRid() { doc.save(); database.commit(); final ResultSet result = database.query("sql", "select from #1:0"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1045,9 +1048,9 @@ public void testFetchFromSingleRid2() { doc.save(); database.commit(); final ResultSet result = database.query("sql", "select from [#1:0]"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1059,9 +1062,9 @@ public void testFetchFromSingleRidParam() { doc.save(); database.commit(); final ResultSet result = database.query("sql", "select from ?", new RID(database, 1, 0)); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1076,11 +1079,11 @@ public void testFetchFromSingleRid3() { database.commit(); final ResultSet result = database.query("sql", "select from [#1:0, #2:0]"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1095,12 +1098,12 @@ public void testFetchFromSingleRid4() { database.commit(); final ResultSet result = database.query("sql", "select from [#1:0, #2:0, #1:100000]"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); try { result.next(); } catch (RecordNotFoundException e) { @@ -1124,19 +1127,19 @@ public void testFetchFromClassWithIndex() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name2'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals("name2", next.getProperty("name")); + assertThat(next).isNotNull(); + assertThat(next.getProperty("name")).isEqualTo("name2"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Optional p = result.getExecutionPlan(); - Assertions.assertTrue(p.isPresent()); + assertThat(p.isPresent()).isTrue(); final ExecutionPlan p2 = p.get(); - Assertions.assertTrue(p2 instanceof SelectExecutionPlan); + assertThat(p2 instanceof SelectExecutionPlan).isTrue(); final SelectExecutionPlan plan = (SelectExecutionPlan) p2; - Assertions.assertEquals(FetchFromIndexStep.class, plan.getSteps().get(0).getClass()); + assertThat(plan.getSteps().get(0).getClass()).isEqualTo(FetchFromIndexStep.class); result.close(); } @@ -1158,18 +1161,18 @@ public void testFetchFromIndex() { final ResultSet result = database.query("sql", "select from index:`" + indexName + "` where key = 'name2'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Optional p = result.getExecutionPlan(); - Assertions.assertTrue(p.isPresent()); + assertThat(p.isPresent()).isTrue(); final ExecutionPlan p2 = p.get(); - Assertions.assertTrue(p2 instanceof SelectExecutionPlan); + assertThat(p2 instanceof SelectExecutionPlan).isTrue(); final SelectExecutionPlan plan = (SelectExecutionPlan) p2; - Assertions.assertEquals(FetchFromIndexStep.class, plan.getSteps().get(0).getClass()); + assertThat(plan.getSteps().get(0).getClass()).isEqualTo(FetchFromIndexStep.class); result.close(); } @@ -1193,23 +1196,23 @@ public void testFetchFromClassWithIndexes() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name2' or surname = 'surname3'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (int i = 0; i < 2; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertTrue("name2".equals(next.getProperty("name")) || ("surname3".equals(next.getProperty("surname")))); + assertThat(next).isNotNull(); + assertThat("name2".equals(next.getProperty("name")) || ("surname3".equals(next.getProperty("surname")))).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final Optional p = result.getExecutionPlan(); - Assertions.assertTrue(p.isPresent()); + assertThat(p.isPresent()).isTrue(); final ExecutionPlan p2 = p.get(); - Assertions.assertTrue(p2 instanceof SelectExecutionPlan); + assertThat(p2 instanceof SelectExecutionPlan).isTrue(); final SelectExecutionPlan plan = (SelectExecutionPlan) p2; - Assertions.assertEquals(ParallelExecStep.class, plan.getSteps().get(0).getClass()); + assertThat(plan.getSteps().get(0).getClass()).isEqualTo(ParallelExecStep.class); final ParallelExecStep parallel = (ParallelExecStep) plan.getSteps().get(0); - Assertions.assertEquals(2, parallel.getSubExecutionPlans().size()); + assertThat(parallel.getSubExecutionPlans().size()).isEqualTo(2); result.close(); } @@ -1234,7 +1237,7 @@ public void testFetchFromClassWithIndexes2() { final ResultSet result = database.query("sql", "select from " + className + " where foo is not null and (name = 'name2' or surname = 'surname3')"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1260,14 +1263,14 @@ public void testFetchFromClassWithIndexes3() { final ResultSet result = database.query("sql", "select from " + className + " where foo < 100 and (name = 'name2' or surname = 'surname3')"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (int i = 0; i < 2; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertTrue("name2".equals(next.getProperty("name")) || ("surname3".equals(next.getProperty("surname")))); + assertThat(next).isNotNull(); + assertThat("name2".equals(next.getProperty("name")) || ("surname3".equals(next.getProperty("surname")))).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1293,14 +1296,14 @@ public void testFetchFromClassWithIndexes4() { final ResultSet result = database.query("sql", "select from " + className + " where foo < 100 and ((name = 'name2' and foo < 20) or surname = 'surname3') and ( 4<5 and foo < 50)"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (int i = 0; i < 2; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertTrue("name2".equals(next.getProperty("name")) || ("surname3".equals(next.getProperty("surname")))); + assertThat(next).isNotNull(); + assertThat("name2".equals(next.getProperty("name")) || ("surname3".equals(next.getProperty("surname")))).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1324,14 +1327,14 @@ public void testFetchFromClassWithIndexes5() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name3' and surname >= 'surname1'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (int i = 0; i < 1; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals("name3", next.getProperty("name")); + assertThat(next).isNotNull(); + assertThat(next.getProperty("name")).isEqualTo("name3"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1355,7 +1358,7 @@ public void testFetchFromClassWithIndexes6() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name3' and surname > 'surname3'"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1380,10 +1383,10 @@ public void testFetchFromClassWithIndexes7() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name3' and surname >= 'surname3'"); for (int i = 0; i < 1; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals("name3", next.getProperty("name")); + assertThat(next).isNotNull(); + assertThat(next.getProperty("name")).isEqualTo("name3"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1407,7 +1410,7 @@ public void testFetchFromClassWithIndexes8() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name3' and surname < 'surname3'"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1432,10 +1435,10 @@ public void testFetchFromClassWithIndexes9() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name3' and surname <= 'surname3'"); for (int i = 0; i < 1; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); - Assertions.assertEquals("name3", next.getProperty("name")); + assertThat(next).isNotNull(); + assertThat(next.getProperty("name")).isEqualTo("name3"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1459,11 +1462,11 @@ public void testFetchFromClassWithIndexes10() { final ResultSet result = database.query("sql", "select from " + className + " where name > 'name3' "); for (int i = 0; i < 6; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1488,9 +1491,9 @@ public void testFetchFromClassWithIndexes11() { final ResultSet result = database.query("sql", "select from " + className + " where name >= 'name3' "); for (int i = 0; i < 7; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1515,9 +1518,9 @@ public void testFetchFromClassWithIndexes12() { final ResultSet result = database.query("sql", "select from " + className + " where name < 'name3' "); for (int i = 0; i < 3; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1542,9 +1545,9 @@ public void testFetchFromClassWithIndexes13() { final ResultSet result = database.query("sql", "select from " + className + " where name <= 'name3' "); for (int i = 0; i < 4; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1569,11 +1572,11 @@ public void testFetchFromClassWithIndexes14() { final ResultSet result = database.query("sql", "select from " + className + " where name > 'name3' and name < 'name5'"); for (int i = 0; i < 1; i++) { final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final SelectExecutionPlan plan = (SelectExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); result.close(); } @@ -1597,9 +1600,9 @@ public void testFetchFromClassWithIndexes15() { final ResultSet result = database.query("sql", "select from " + className + " where name > 'name6' and name = 'name3' and surname > 'surname2' and surname < 'surname5' "); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final SelectExecutionPlan plan = (SelectExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); result.close(); } @@ -1625,11 +1628,11 @@ public void testFetchFromClassWithIndexes15() { // // // for (int i = 0; i < 1; i++) { -// Assertions.assertTrue(result.hasNext()); +// Assertions.assertThat(result.hasNext()).isTrue(); // Result next = result.next(); -// Assertions.assertNotNull(next); +// Assertions.assertThat(next).isNotNull(); // } -// Assertions.assertFalse(result.hasNext()); +// Assertions.assertThat(result.hasNext()).isFalse(); // SelectExecutionPlan plan = (SelectExecutionPlan) result.getExecutionPlan().get(); // Assertions.assertEquals( // 1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); @@ -1658,11 +1661,11 @@ public void testFetchFromClassWithIndexes15() { // // // for (int i = 0; i < 1; i++) { -// Assertions.assertTrue(result.hasNext()); +// Assertions.assertThat(result.hasNext()).isTrue(); // Result next = result.next(); -// Assertions.assertNotNull(next); +// Assertions.assertThat(next).isNotNull(); // } -// Assertions.assertFalse(result.hasNext()); +// Assertions.assertThat(result.hasNext()).isFalse(); // SelectExecutionPlan plan = (SelectExecutionPlan) result.getExecutionPlan().get(); // Assertions.assertEquals( // FetchFromClassExecutionStep.class, plan.getSteps().get(0).getClass()); // index not used @@ -1693,22 +1696,22 @@ public void testExpand1() { ResultSet result = database.query("sql", "select expand(linked) from " + parentClassName); for (int i = 0; i < count; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); try { result = database.query("sql", "select expand(linked).asString() from " + parentClassName); - Assertions.fail(); + fail(""); } catch (CommandSQLParsingException e) { // EXPECTED } try { result = database.query("sql", "SELECT expand([{'name':2},2,3,4]).name from " + parentClassName); - Assertions.fail(); + fail(""); } catch (CommandSQLParsingException e) { // EXPECTED } @@ -1744,11 +1747,11 @@ public void testExpand2() { final ResultSet result = database.query("sql", "select expand(linked) from " + parentClassName); for (int i = 0; i < count * collSize; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1781,15 +1784,15 @@ public void testExpand3() { String last = null; for (int i = 0; i < count * collSize; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); if (i > 0) { - Assertions.assertTrue(last.compareTo(next.getProperty("name")) <= 0); + assertThat(last.compareTo(next.getProperty("name")) <= 0).isTrue(); } last = next.getProperty("name"); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1811,11 +1814,11 @@ public void testDistinct1() { final ResultSet result = database.query("sql", "select distinct name, surname from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1838,59 +1841,59 @@ public void testDistinct2() { final ResultSet result = database.query("sql", "select distinct(name) from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result next = result.next(); - Assertions.assertNotNull(next); + assertThat(next).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testLet1() { final ResultSet result = database.query("sql", "select $a as one, $b as two let $a = 1, $b = 1+1"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(1, item.getProperty("one")); - Assertions.assertEquals(2, item.getProperty("two")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("one")).isEqualTo(1); + assertThat(item.getProperty("two")).isEqualTo(2); result.close(); } @Test public void testLet1Long() { final ResultSet result = database.query("sql", "select $a as one, $b as two let $a = 1L, $b = 1L+1"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(1l, item.getProperty("one")); - Assertions.assertEquals(2l, item.getProperty("two")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("one")).isEqualTo(1l); + assertThat(item.getProperty("two")).isEqualTo(2l); result.close(); } @Test public void testLet2() { final ResultSet result = database.query("sql", "select $a as one let $a = (select 1 as a)"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object one = item.getProperty("one"); - Assertions.assertTrue(one instanceof List); - Assertions.assertEquals(1, ((List) one).size()); + assertThat(one instanceof List).isTrue(); + assertThat(((List) one).size()).isEqualTo(1); final Object x = ((List) one).get(0); - Assertions.assertTrue(x instanceof Result); - Assertions.assertEquals(1, (Object) ((Result) x).getProperty("a")); + assertThat(x instanceof Result).isTrue(); + assertThat((Object) ((Result) x).getProperty("a")).isEqualTo(1); result.close(); } @Test public void testLet3() { final ResultSet result = database.query("sql", "select $a[0].foo as one let $a = (select 1 as foo)"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object one = item.getProperty("one"); - Assertions.assertEquals(1, one); + assertThat(one).isEqualTo(1); result.close(); } @@ -1911,12 +1914,12 @@ public void testLet4() { final ResultSet result = database.query("sql", "select name, surname, $nameAndSurname as fullname from " + className + " let $nameAndSurname = name + ' ' + surname"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(item.getProperty("fullname"), item.getProperty("name") + " " + item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name") + " " + item.getProperty("surname")).isEqualTo(item.getProperty("fullname")); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1937,12 +1940,12 @@ public void testLet5() { final ResultSet result = database.query("sql", "select from " + className + " where name in (select name from " + className + " where name = 'name1')"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1964,13 +1967,13 @@ public void testLet6() { "select $foo as name from " + className + " let $foo = (select name from " + className + " where name = $parent.$current.name)"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - Assertions.assertTrue(item.getProperty("name") instanceof Collection); + assertThat(item).isNotNull(); + assertThat(item.>getProperty("name")).isNotNull(); + assertThat(item.getProperty("name") instanceof Collection).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -1992,13 +1995,13 @@ public void testLet7() { "select $bar as name from " + className + " " + "let $foo = (select name from " + className + " where name = $parent.$current.name)," + "$bar = $foo[0].name"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); - Assertions.assertTrue(item.getProperty("name") instanceof String); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); + assertThat(item.getProperty("name") instanceof String).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2038,7 +2041,7 @@ public void testLetWithTraverseFunction() { } } } - Assertions.assertEquals(1, counter); + assertThat(counter).isEqualTo(1); resultSet.close(); } @@ -2058,16 +2061,16 @@ public void testUnwind1() { final ResultSet result = database.query("sql", "select i, iSeq from " + className + " unwind iSeq"); for (int i = 0; i < 30; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("i")); - Assertions.assertNotNull(item.getProperty("iSeq")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("i")).isNotNull(); + assertThat(item.getProperty("iSeq")).isNotNull(); final Integer first = item.getProperty("i"); final Integer second = item.getProperty("iSeq"); - Assertions.assertTrue(first + second == 0 || second % first == 0); + assertThat(first + second == 0 || second % first == 0).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2091,16 +2094,16 @@ public void testUnwind2() { final ResultSet result = database.query("sql", "select i, iSeq from " + className + " unwind iSeq"); for (int i = 0; i < 30; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("i")); - Assertions.assertNotNull(item.getProperty("iSeq")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("i")).isNotNull(); + assertThat(item.getProperty("iSeq")).isNotNull(); final Integer first = item.getProperty("i"); final Integer second = item.getProperty("iSeq"); - Assertions.assertTrue(first + second == 0 || second % first == 0); + assertThat(first + second == 0 || second % first == 0).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2141,13 +2144,13 @@ public void testFetchFromSubclassIndexes1() { final ResultSet result = database.query("sql", "select from " + parent + " where name = 'name1'"); final InternalExecutionPlan plan = (InternalExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertTrue(plan.getSteps().get(0) instanceof ParallelExecStep); + assertThat(plan.getSteps().get(0) instanceof ParallelExecStep).isTrue(); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2186,13 +2189,13 @@ public void testFetchFromSubclassIndexes2() { final ResultSet result = database.query("sql", "select from " + parent + " where name = 'name1' and surname = 'surname1'"); final InternalExecutionPlan plan = (InternalExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertTrue(plan.getSteps().get(0) instanceof ParallelExecStep); + assertThat(plan.getSteps().get(0) instanceof ParallelExecStep).isTrue(); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2230,13 +2233,13 @@ public void testFetchFromSubclassIndexes3() { final ResultSet result = database.query("sql", "select from " + parent + " where name = 'name1' and surname = 'surname1'"); final InternalExecutionPlan plan = (InternalExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertTrue(plan.getSteps().get(0) instanceof FetchFromTypeExecutionStep); // no index used + assertThat(plan.getSteps().get(0) instanceof FetchFromTypeExecutionStep).isTrue(); // no index used for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2279,14 +2282,13 @@ public void testFetchFromSubclassIndexes4() { final ResultSet result = database.query("sql", "select from " + parent + " where name = 'name1' and surname = 'surname1'"); final InternalExecutionPlan plan = (InternalExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertTrue( - plan.getSteps().get(0) instanceof FetchFromTypeExecutionStep); // no index, because the superclass is not empty + assertThat(plan.getSteps().get(0) instanceof FetchFromTypeExecutionStep).isTrue(); // no index, because the superclass is not empty for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2342,13 +2344,13 @@ public void testFetchFromSubSubclassIndexes() { final ResultSet result = database.query("sql", "select from " + parent + " where name = 'name1' and surname = 'surname1'"); final InternalExecutionPlan plan = (InternalExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertTrue(plan.getSteps().get(0) instanceof ParallelExecStep); + assertThat(plan.getSteps().get(0) instanceof ParallelExecStep).isTrue(); for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2401,13 +2403,13 @@ public void testFetchFromSubSubclassIndexesWithDiamond() { final ResultSet result = database.query("sql", "select from " + parent + " where name = 'name1' and surname = 'surname1'"); final InternalExecutionPlan plan = (InternalExecutionPlan) result.getExecutionPlan().get(); - Assertions.assertTrue(plan.getSteps().get(0) instanceof FetchFromTypeExecutionStep); + assertThat(plan.getSteps().get(0) instanceof FetchFromTypeExecutionStep).isTrue(); for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2431,21 +2433,21 @@ public void testIndexPlusSort1() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name1' order by surname ASC"); String lastSurname = null; for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); - final String surname = item.getProperty("surname"); + final String surname = item.getProperty("surname"); if (i > 0) { - Assertions.assertTrue(surname.compareTo(lastSurname) > 0); + assertThat(surname.compareTo(lastSurname) > 0).isTrue(); } lastSurname = surname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final ExecutionPlan plan = result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); - Assertions.assertEquals(0, plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); + assertThat(plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()).isEqualTo(0); result.close(); } @@ -2471,21 +2473,21 @@ public void testIndexPlusSort2() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name1' order by surname DESC"); String lastSurname = null; for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); - final String surname = item.getProperty("surname"); + final String surname = item.getProperty("surname"); if (i > 0) { - Assertions.assertTrue(surname.compareTo(lastSurname) < 0); + assertThat(surname.compareTo(lastSurname) < 0).isTrue(); } lastSurname = surname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final ExecutionPlan plan = result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); - Assertions.assertEquals(0, plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); + assertThat(plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()).isEqualTo(0); result.close(); } @@ -2510,21 +2512,21 @@ public void testIndexPlusSort3() { "select from " + className + " where name = 'name1' order by name DESC, surname DESC"); String lastSurname = null; for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); - final String surname = item.getProperty("surname"); + final String surname = item.getProperty("surname"); if (i > 0) { - Assertions.assertTrue(((String) item.getProperty("surname")).compareTo(lastSurname) < 0); + assertThat(((String) item.getProperty("surname")).compareTo(lastSurname) < 0).isTrue(); } lastSurname = surname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final ExecutionPlan plan = result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); - Assertions.assertEquals(0, plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); + assertThat(plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()).isEqualTo(0); result.close(); } @@ -2549,21 +2551,21 @@ public void testIndexPlusSort4() { "select from " + className + " where name = 'name1' order by name ASC, surname ASC"); String lastSurname = null; for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); - final String surname = item.getProperty("surname"); + final String surname = item.getProperty("surname"); if (i > 0) { - Assertions.assertTrue(surname.compareTo(lastSurname) > 0); + assertThat(surname.compareTo(lastSurname) > 0).isTrue(); } lastSurname = surname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final ExecutionPlan plan = result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); - Assertions.assertEquals(0, plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); + assertThat(plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()).isEqualTo(0); result.close(); } @@ -2589,20 +2591,20 @@ public void testIndexPlusSort5() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name1' order by surname ASC"); String lastSurname = null; for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); - final String surname = item.getProperty("surname"); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); + final String surname = item.getProperty("surname"); if (i > 0) { - Assertions.assertTrue(surname.compareTo(lastSurname) > 0); + assertThat(surname.compareTo(lastSurname) > 0).isTrue(); } lastSurname = surname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final ExecutionPlan plan = result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); - Assertions.assertEquals(0, plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); + assertThat(plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()).isEqualTo(0); result.close(); } @@ -2628,20 +2630,20 @@ public void testIndexPlusSort6() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name1' order by surname DESC"); String lastSurname = null; for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); - final String surname = item.getProperty("surname"); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); + final String surname = item.getProperty("surname"); if (i > 0) { - Assertions.assertTrue(surname.compareTo(lastSurname) < 0); + assertThat(surname.compareTo(lastSurname) < 0).isTrue(); } lastSurname = surname; } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); final ExecutionPlan plan = result.getExecutionPlan().get(); - Assertions.assertEquals(1, plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()); - Assertions.assertEquals(0, plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()); + assertThat(plan.getSteps().stream().filter(step -> step instanceof FetchFromIndexStep).count()).isEqualTo(1); + assertThat(plan.getSteps().stream().filter(step -> step instanceof OrderByStep).count()).isEqualTo(0); result.close(); } @@ -2667,12 +2669,12 @@ public void testIndexPlusSort7() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name1' order by address DESC"); for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); boolean orderStepFound = false; for (final ExecutionStep step : result.getExecutionPlan().get().getSteps()) { if (step instanceof OrderByStep) { @@ -2680,7 +2682,7 @@ public void testIndexPlusSort7() { break; } } - Assertions.assertTrue(orderStepFound); + assertThat(orderStepFound).isTrue(); result.close(); } @@ -2704,13 +2706,13 @@ public void testIndexPlusSort8() { final ResultSet result = database.query("sql", "select from " + className + " where name = 'name1' order by name ASC, surname DESC"); for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); + assertThat(result.hasNext()).isFalse(); boolean orderStepFound = false; for (final ExecutionStep step : result.getExecutionPlan().get().getSteps()) { if (step instanceof OrderByStep) { @@ -2718,7 +2720,7 @@ public void testIndexPlusSort8() { break; } } - Assertions.assertTrue(orderStepFound); + assertThat(orderStepFound).isTrue(); result.close(); } @@ -2741,13 +2743,13 @@ public void testIndexPlusSort9() { final ResultSet result = database.query("sql", "select from " + className + " order by name , surname ASC"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); + assertThat(result.hasNext()).isFalse(); boolean orderStepFound = false; for (final ExecutionStep step : result.getExecutionPlan().get().getSteps()) { if (step instanceof OrderByStep) { @@ -2755,7 +2757,7 @@ public void testIndexPlusSort9() { break; } } - Assertions.assertFalse(orderStepFound); + assertThat(orderStepFound).isFalse(); result.close(); } @@ -2778,13 +2780,13 @@ public void testIndexPlusSort10() { final ResultSet result = database.query("sql", "select from " + className + " order by name desc, surname desc"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); + assertThat(result.hasNext()).isFalse(); boolean orderStepFound = false; for (final ExecutionStep step : result.getExecutionPlan().get().getSteps()) { if (step instanceof OrderByStep) { @@ -2792,7 +2794,7 @@ public void testIndexPlusSort10() { break; } } - Assertions.assertFalse(orderStepFound); + assertThat(orderStepFound).isFalse(); result.close(); } @@ -2815,13 +2817,13 @@ public void testIndexPlusSort11() { final ResultSet result = database.query("sql", "select from " + className + " order by name asc, surname desc"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); + assertThat(result.hasNext()).isFalse(); boolean orderStepFound = false; for (final ExecutionStep step : result.getExecutionPlan().get().getSteps()) { if (step instanceof OrderByStep) { @@ -2829,7 +2831,7 @@ public void testIndexPlusSort11() { break; } } - Assertions.assertTrue(orderStepFound); + assertThat(orderStepFound).isTrue(); result.close(); } @@ -2853,19 +2855,19 @@ public void testIndexPlusSort12() { final ResultSet result = database.query("sql", "select from " + className + " order by name"); String last = null; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isNotNull(); final String name = item.getProperty("name"); //System.out.println(name); if (i > 0) { - Assertions.assertTrue(name.compareTo(last) >= 0); + assertThat(name.compareTo(last) >= 0).isTrue(); } last = name; } - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); + assertThat(result.hasNext()).isFalse(); boolean orderStepFound = false; for (final ExecutionStep step : result.getExecutionPlan().get().getSteps()) { if (step instanceof OrderByStep) { @@ -2873,7 +2875,7 @@ public void testIndexPlusSort12() { break; } } - Assertions.assertFalse(orderStepFound); + assertThat(orderStepFound).isFalse(); result.close(); } @@ -2891,12 +2893,12 @@ public void testSelectFromStringParam() { final ResultSet result = database.query("sql", "select from ?", className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(("" + item.getProperty("name")).startsWith("name")); + assertThat(item).isNotNull(); + assertThat(("" + item.getProperty("name")).startsWith("name")).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2916,12 +2918,12 @@ public void testSelectFromStringNamedParam() { final ResultSet result = database.query("sql", "select from :target", params); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(("" + item.getProperty("name")).startsWith("name")); + assertThat(item).isNotNull(); + assertThat(("" + item.getProperty("name")).startsWith("name")).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2939,12 +2941,12 @@ public void testMatches() { final ResultSet result = database.query("sql", "select from " + className + " where name matches 'name1'"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(item.getProperty("name"), "name1"); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2962,26 +2964,26 @@ public void testRange() { final ResultSet result = database.query("sql", "select name[0..3] as names from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object names = item.getProperty("names"); if (names == null) { - Assertions.fail(); + fail(""); } if (names instanceof Collection) { - Assertions.assertEquals(3, ((Collection) names).size()); + assertThat(((Collection) names).size()).isEqualTo(3); final Iterator iter = ((Collection) names).iterator(); - Assertions.assertEquals("a", iter.next()); - Assertions.assertEquals("b", iter.next()); - Assertions.assertEquals("c", iter.next()); + assertThat(iter.next()).isEqualTo("a"); + assertThat(iter.next()).isEqualTo("b"); + assertThat(iter.next()).isEqualTo("c"); } else if (names.getClass().isArray()) { - Assertions.assertEquals(3, Array.getLength(names)); + assertThat(Array.getLength(names)).isEqualTo(3); } else { - Assertions.fail(); + fail(""); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -2999,26 +3001,26 @@ public void testRangeParams1() { final ResultSet result = database.query("sql", "select name[?..?] as names from " + className, 0, 3); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object names = item.getProperty("names"); if (names == null) { - Assertions.fail(); + fail(""); } if (names instanceof Collection) { - Assertions.assertEquals(3, ((Collection) names).size()); + assertThat(((Collection) names).size()).isEqualTo(3); final Iterator iter = ((Collection) names).iterator(); - Assertions.assertEquals("a", iter.next()); - Assertions.assertEquals("b", iter.next()); - Assertions.assertEquals("c", iter.next()); + assertThat(iter.next()).isEqualTo("a"); + assertThat(iter.next()).isEqualTo("b"); + assertThat(iter.next()).isEqualTo("c"); } else if (names.getClass().isArray()) { - Assertions.assertEquals(3, Array.getLength(names)); + assertThat(Array.getLength(names)).isEqualTo(3); } else { - Assertions.fail(); + fail(""); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3039,26 +3041,26 @@ public void testRangeParams2() { final ResultSet result = database.query("sql", "select name[:a..:b] as names from " + className, params); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object names = item.getProperty("names"); if (names == null) { - Assertions.fail(); + fail(""); } if (names instanceof Collection) { - Assertions.assertEquals(3, ((Collection) names).size()); + assertThat(((Collection) names).size()).isEqualTo(3); final Iterator iter = ((Collection) names).iterator(); - Assertions.assertEquals("a", iter.next()); - Assertions.assertEquals("b", iter.next()); - Assertions.assertEquals("c", iter.next()); + assertThat(iter.next()).isEqualTo("a"); + assertThat(iter.next()).isEqualTo("b"); + assertThat(iter.next()).isEqualTo("c"); } else if (names.getClass().isArray()) { - Assertions.assertEquals(3, Array.getLength(names)); + assertThat(Array.getLength(names)).isEqualTo(3); } else { - Assertions.fail(); + fail(""); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3076,43 +3078,43 @@ public void testEllipsis() { final ResultSet result = database.query("sql", "select name[0...2] as names from " + className); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Object names = item.getProperty("names"); if (names == null) { - Assertions.fail(); + fail(""); } if (names instanceof Collection) { - Assertions.assertEquals(3, ((Collection) names).size()); + assertThat(((Collection) names).size()).isEqualTo(3); final Iterator iter = ((Collection) names).iterator(); - Assertions.assertEquals("a", iter.next()); - Assertions.assertEquals("b", iter.next()); - Assertions.assertEquals("c", iter.next()); + assertThat(iter.next()).isEqualTo("a"); + assertThat(iter.next()).isEqualTo("b"); + assertThat(iter.next()).isEqualTo("c"); } else if (names.getClass().isArray()) { - Assertions.assertEquals(3, Array.getLength(names)); - Assertions.assertEquals("a", Array.get(names, 0)); - Assertions.assertEquals("b", Array.get(names, 1)); - Assertions.assertEquals("c", Array.get(names, 2)); + assertThat(Array.getLength(names)).isEqualTo(3); + assertThat(Array.get(names, 0)).isEqualTo("a"); + assertThat(Array.get(names, 1)).isEqualTo("b"); + assertThat(Array.get(names, 2)).isEqualTo("c"); } else { - Assertions.fail(); + fail(""); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testNewRid() { final ResultSet result = database.query("sql", "select {\"@rid\":\"#12:0\"} as theRid "); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); final Object rid = item.getProperty("theRid"); - Assertions.assertTrue(rid instanceof Identifiable); + assertThat(rid instanceof Identifiable).isTrue(); final Identifiable id = (Identifiable) rid; - Assertions.assertEquals(12, id.getIdentity().getBucketId()); - Assertions.assertEquals(0L, id.getIdentity().getPosition()); - Assertions.assertFalse(result.hasNext()); + assertThat(id.getIdentity().getBucketId()).isEqualTo(12); + assertThat(id.getIdentity().getPosition()).isEqualTo(0L); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3144,20 +3146,20 @@ public void testNestedProjections1() { database.commit(); final ResultSet result = database.query("sql", "select name, elem1:{*}, elem2:{!surname} from " + className + " where name = 'd'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Result elem1Result = item.getProperty("elem1"); - Assertions.assertEquals("a", elem1Result.getProperty("name")); - Assertions.assertEquals(elem1.getIdentity(), elem1Result.getProperty("@rid")); - Assertions.assertEquals(elem1.getTypeName(), elem1Result.getProperty("@type")); + assertThat(elem1Result.getProperty("name")).isEqualTo("a"); + assertThat(elem1Result.getProperty("@rid")).isEqualTo(elem1.getIdentity()); + assertThat(elem1Result.getProperty("@type")).isEqualTo(elem1.getTypeName()); final Result elem2Result = item.getProperty("elem2"); - Assertions.assertEquals("b", elem2Result.getProperty("name")); - Assertions.assertNull(elem2Result.getProperty("surname")); - Assertions.assertEquals(elem2.getIdentity(), elem2Result.getProperty("@rid")); - Assertions.assertEquals(elem2.getTypeName(), elem2Result.getProperty("@type")); + assertThat(elem2Result.getProperty("name")).isEqualTo("b"); + assertThat(elem2Result.getProperty("surname")).isNull(); + assertThat(elem2Result.getProperty("@rid")).isEqualTo(elem2.getIdentity()); + assertThat(elem2Result.getProperty("@type")).isEqualTo(elem2.getTypeName()); result.close(); } @@ -3177,33 +3179,33 @@ public void testSimpleCollectionFiltering() { database.commit(); ResultSet result = database.query("sql", "select coll[='foo'] as filtered from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); List res = item.getProperty("filtered"); - Assertions.assertEquals(1, res.size()); - Assertions.assertEquals("foo", res.get(0)); + assertThat(res.size()).isEqualTo(1); + assertThat(res.get(0)).isEqualTo("foo"); result.close(); result = database.query("sql", "select coll[<'ccc'] as filtered from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); res = item.getProperty("filtered"); - Assertions.assertEquals(2, res.size()); + assertThat(res.size()).isEqualTo(2); result.close(); result = database.query("sql", "select coll[LIKE 'ba%'] as filtered from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); res = item.getProperty("filtered"); - Assertions.assertEquals(2, res.size()); + assertThat(res.size()).isEqualTo(2); result.close(); result = database.query("sql", "select coll[in ['bar']] as filtered from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); res = item.getProperty("filtered"); - Assertions.assertEquals(1, res.size()); - Assertions.assertEquals("bar", res.get(0)); + assertThat(res.size()).isEqualTo(1); + assertThat(res.get(0)).isEqualTo("bar"); result.close(); } @@ -3230,19 +3232,19 @@ public void testContaninsWithConversion() { database.commit(); ResultSet result = database.query("sql", "select from " + className + " where coll contains 1"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "select from " + className + " where coll contains 1L"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "select from " + className + " where coll contains 12L"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3277,12 +3279,12 @@ public void testContainsIntegers() { for (final EmbeddedDocument d : embeddedList) valueMatches.add(d.getInteger("value")); - Assertions.assertTrue(valueMatches.contains(3)); + assertThat(valueMatches.contains(3)).isTrue(); ++totalFound; } - Assertions.assertEquals(3, totalFound); + assertThat(totalFound).isEqualTo(3); } @Test @@ -3316,12 +3318,12 @@ public void testContainsStrings() { for (final EmbeddedDocument d : embeddedList) valueMatches.add(d.getString("value")); - Assertions.assertTrue(valueMatches.contains("3")); + assertThat(valueMatches.contains("3")).isTrue(); ++totalFound; } - Assertions.assertEquals(3, totalFound); + assertThat(totalFound).isEqualTo(3); } @Test @@ -3357,12 +3359,12 @@ public void testContainsStringsInMap() { for (final Map d : embeddedList) valueMatches.add((String) d.get("value")); - Assertions.assertTrue(valueMatches.contains("3")); + assertThat(valueMatches.contains("3")).isTrue(); ++totalFound; } - Assertions.assertEquals(3, totalFound); + assertThat(totalFound).isEqualTo(3); } @Test @@ -3378,9 +3380,9 @@ public void testIndexPrefixUsage() { database.commit(); final ResultSet result = database.query("sql", "select from " + className + " where name = 'Bar'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3397,9 +3399,9 @@ public void testNamedParams() { params.put("p1", "Foo"); params.put("p2", "Fox"); final ResultSet result = database.query("sql", "select from " + className + " where name = :p1 and surname = :p2", params); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3417,9 +3419,9 @@ public void testNamedParamsWithIndex() { final Map params = new HashMap<>(); params.put("p1", "Foo"); final ResultSet result = database.query("sql", "select from " + className + " where name = :p1", params); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3434,9 +3436,9 @@ public void testIsDefined() { database.commit(); final ResultSet result = database.query("sql", "select from " + className + " where name is defined"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3451,9 +3453,9 @@ public void testIsNotDefined() { database.commit(); final ResultSet result = database.query("sql", "select from " + className + " where name is not defined"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -3480,7 +3482,7 @@ public void testRidPagination1() { final ExecutionPlan execPlan = result.getExecutionPlan().get(); for (final ExecutionStep ExecutionStep : execPlan.getSteps()) { if (ExecutionStep instanceof FetchFromTypeExecutionStep) { - Assertions.assertEquals(clusterIds.length - 1, ExecutionStep.getSubSteps().size()); + assertThat(ExecutionStep.getSubSteps().size()).isEqualTo(clusterIds.length - 1); // clusters - 1 + fetch from tx... } } @@ -3490,7 +3492,7 @@ public void testRidPagination1() { result.next(); } result.close(); - Assertions.assertEquals(clusterIds.length - 1, count); + assertThat(count).isEqualTo(clusterIds.length - 1); } @Test @@ -3518,7 +3520,7 @@ public void testRidPagination2() { final ExecutionPlan execPlan = result.getExecutionPlan().get(); for (final ExecutionStep ExecutionStep : execPlan.getSteps()) { if (ExecutionStep instanceof FetchFromTypeExecutionStep) { - Assertions.assertEquals(clusterIds.length - 1, ExecutionStep.getSubSteps().size()); + assertThat(ExecutionStep.getSubSteps().size()).isEqualTo(clusterIds.length - 1); // clusters - 1 + fetch from tx... } } @@ -3528,7 +3530,7 @@ public void testRidPagination2() { result.next(); } result.close(); - Assertions.assertEquals(clusterIds.length - 1, count); + assertThat(count).isEqualTo(clusterIds.length - 1); } @Test @@ -3549,11 +3551,11 @@ public void testContainsWithSubquery() { try (final ResultSet result = database.query("sql", "select from " + className + 2 + " where tags contains (select from " + className + 1 + " where name = 'foo')")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3575,11 +3577,11 @@ public void testInWithSubquery() { try (final ResultSet result = database.query("sql", "select from " + className + 2 + " where (select from " + className + 1 + " where name = 'foo') in tags")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3596,31 +3598,31 @@ public void testContainsAny() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['foo','baz']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['foo','bar']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['foo','bbb']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['xx','baz']")) { - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany []")) { - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3638,36 +3640,36 @@ public void testContainsAnyWithIndex() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['foo','baz']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['foo','bar']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['foo','bbb']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany ['xx','baz']")) { - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsany []")) { - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } } @@ -3683,17 +3685,17 @@ public void testContainsAll() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsall ['foo','bar']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tags containsall ['foo']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3710,11 +3712,11 @@ public void testBetween() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where val between 2 and 3")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3731,36 +3733,36 @@ public void testInWithIndex() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where tag in ['foo','baz']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tag in ['foo','bar']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tag in []")) { - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } final List params = new ArrayList<>(); params.add("foo"); params.add("bar"); try (final ResultSet result = database.query("sql", "select from " + className + " where tag in (?)", params)) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertTrue(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isTrue(); } } @@ -3776,36 +3778,36 @@ public void testInWithoutIndex() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where tag in ['foo','baz']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tag in ['foo','bar']")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where tag in []")) { - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isFalse(); } final List params = new ArrayList<>(); params.add("foo"); params.add("bar"); try (final ResultSet result = database.query("sql", "select from " + className + " where tag in (?)", params)) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); - Assertions.assertFalse(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)); + assertThat(result.hasNext()).isFalse(); + assertThat(result.getExecutionPlan().get().getSteps().stream().anyMatch(x -> x instanceof FetchFromIndexStep)).isFalse(); } } @@ -3823,9 +3825,9 @@ public void testListOfMapsContains() { try (final ResultSet result = database.query("sql", "select from " + className + " where thelist CONTAINS ( name = ?)", "Jack")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3872,8 +3874,8 @@ public void testContainsMultipleConditions() { try (final ResultSet result = database.query("sql", TEST_QUERY)) { final Result row = result.nextIfAvailable(); - Assertions.assertEquals("21087591856", row.getProperty("cuij")); - Assertions.assertEquals(1L, (Long) row.getProperty("count")); + assertThat(row.getProperty("cuij")).isEqualTo("21087591856"); + assertThat((Long) row.getProperty("count")).isEqualTo(1L); } } @@ -3893,9 +3895,9 @@ public void testContainsEmptyCollection() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where test contains []")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3915,9 +3917,9 @@ public void testContainsCollection() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where test contains [1]")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } @@ -3942,7 +3944,7 @@ public void testHeapLimitForOrderBy() { try (final ResultSet result = database.query("sql", "select from " + className + " ORDER BY name")) { result.forEachRemaining(x -> x.getProperty("name")); } - Assertions.fail(); + fail(""); } catch (final CommandExecutionException ex) { } } finally { @@ -3953,10 +3955,10 @@ public void testHeapLimitForOrderBy() { @Test public void testXor() { try (final ResultSet result = database.query("sql", "select 15 ^ 4 as foo")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals(11, (int) item.getProperty("foo")); - Assertions.assertFalse(result.hasNext()); + assertThat((int) item.getProperty("foo")).isEqualTo(11); + assertThat(result.hasNext()).isFalse(); } } @@ -3973,35 +3975,35 @@ public void testLike() { database.commit(); try (final ResultSet result = database.query("sql", "select from " + className + " where name LIKE 'foo%'")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where name LIKE '%foo%baz%'")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where name LIKE '%bar%'")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where name LIKE 'bar%'")) { - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } try (final ResultSet result = database.query("sql", "select from " + className + " where name LIKE '%bar'")) { - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } final String specialChars = "[]{}()|*^."; for (final char c : specialChars.toCharArray()) { try (final ResultSet result = database.query("sql", "select from " + className + " where name LIKE '%" + c + "%'")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); } } } @@ -4021,10 +4023,10 @@ public void testCountGroupBy() { database.commit(); final ResultSet result = database.query("sql", "select count(val) as count from " + className + " limit 3"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals(10L, (long) item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat((long) item.getProperty("count")).isEqualTo(10L); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -4147,10 +4149,10 @@ public void testSimpleRangeQueryWithIndexGTE() { final ResultSet result = database.query("sql", "select from " + className + " WHERE name >= 'name5'"); for (int i = 0; i < 5; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -4171,10 +4173,10 @@ public void testSimpleRangeQueryWithIndexLTE() { final ResultSet result = database.query("sql", "select from " + className + " WHERE name <= 'name5'"); for (int i = 0; i < 6; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -4205,11 +4207,11 @@ public void testIndexWithSubquery() { try (final ResultSet rs = database.query("sql", "select from " + classNamePrefix + "Report where id in (select out('" + classNamePrefix + "hasOwnership').id from " + classNamePrefix + "User where id = 'admin');")) { - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); } database.command("sql", "create index ON " + classNamePrefix + "Report(id) unique;").close(); @@ -4217,11 +4219,11 @@ public void testIndexWithSubquery() { try (final ResultSet rs = database.query("sql", "select from " + classNamePrefix + "Report where id in (select out('" + classNamePrefix + "hasOwnership').id from " + classNamePrefix + "User where id = 'admin');")) { - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); rs.next(); - Assertions.assertFalse(rs.hasNext()); + assertThat(rs.hasNext()).isFalse(); } } @@ -4237,11 +4239,11 @@ public void testExclude() { database.commit(); final ResultSet result = database.query("sql", "select *, !surname from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("foo", item.getProperty("name")); - Assertions.assertNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("foo"); + assertThat(item.getProperty("surname")).isNull(); result.close(); } @@ -4261,17 +4263,17 @@ public void testOrderByLet() { try (final ResultSet result = database.query("sql", "select from " + className + " LET $order = name.substring(1) ORDER BY $order ASC LIMIT 1")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("baaa", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("baaa"); } try (final ResultSet result = database.query("sql", "select from " + className + " LET $order = name.substring(1) ORDER BY $order DESC LIMIT 1")) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("abbb", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("abbb"); } } @@ -4281,14 +4283,14 @@ public void testSchemaMap() { database.command("sql", "ALTER TYPE SchemaMap CUSTOM label = 'Document'"); final ResultSet result = database.query("sql", "SELECT map(name,custom.label) as map FROM schema:types"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); Object map = item.getProperty("map"); - Assertions.assertTrue(map instanceof Map); + assertThat(map instanceof Map).isTrue(); - Assertions.assertEquals("Document", ((Map) map).get("SchemaMap")); + assertThat(((Map) map).get("SchemaMap")).isEqualTo("Document"); result.close(); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTestIT.java b/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTestIT.java index 6c67a02400..8fd46e1123 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTestIT.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/SelectStatementExecutionTestIT.java @@ -20,9 +20,10 @@ import com.arcadedb.TestHelper; import com.arcadedb.database.MutableDocument; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * Created by tglman on 09/06/17. */ @@ -51,9 +52,9 @@ public void stressTest() { final Result item = result.next(); // Assertions.assertNotNull(item); final Object name = item.getProperty("name"); - Assertions.assertFalse("name1".equals(name)); + assertThat(name).isNotEqualTo("name1"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); final long end = System.nanoTime(); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/SleepStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/SleepStatementExecutionTest.java index 3a29a7d2f2..22344c45e3 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/SleepStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/SleepStatementExecutionTest.java @@ -19,9 +19,10 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -30,12 +31,12 @@ public class SleepStatementExecutionTest extends TestHelper { public void testBasic() { final long begin = System.currentTimeMillis(); final ResultSet result = database.command("sql", "sleep 1000"); - Assertions.assertTrue(System.currentTimeMillis() - begin >= 1000); + assertThat(System.currentTimeMillis() - begin >= 1000).isTrue(); //printExecutionPlan(null, result); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); +// assertThat(result).isNotNull(); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals("sleep", item.getProperty("operation")); - Assertions.assertFalse(result.hasNext()); + assertThat(item.getProperty("operation")).isEqualTo("sleep"); + assertThat(result.hasNext()).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/TraverseStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/TraverseStatementExecutionTest.java index ae272b44d5..4b23c1c294 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/TraverseStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/TraverseStatementExecutionTest.java @@ -20,11 +20,14 @@ import com.arcadedb.TestHelper; import com.arcadedb.database.RID; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -53,11 +56,11 @@ public void testPlainTraverse() { final ResultSet result = database.query("sql", "traverse out() from (select from " + classPrefix + "V where name = 'a')"); for (int i = 0; i < 4; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals(i, item.getMetadata("$depth")); + assertThat(item.getMetadata("$depth")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); }); } @@ -87,11 +90,11 @@ public void testWithDepth() { "traverse out() from (select from " + classPrefix + "V where name = 'a') WHILE $depth < 2"); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals(i, item.getMetadata("$depth")); + assertThat(item.getMetadata("$depth")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); }); } @@ -121,21 +124,21 @@ public void testMaxDepth() { "traverse out() from (select from " + classPrefix + "V where name = 'a') MAXDEPTH 1"); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals(i, item.getMetadata("$depth")); + assertThat(item.getMetadata("$depth")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "traverse out() from (select from " + classPrefix + "V where name = 'a') MAXDEPTH 2"); for (int i = 0; i < 3; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals(i, item.getMetadata("$depth")); + assertThat(item.getMetadata("$depth")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); }); } @@ -165,11 +168,11 @@ public void testBreadthFirst() { "traverse out() from (select from " + classPrefix + "V where name = 'a') STRATEGY BREADTH_FIRST"); for (int i = 0; i < 4; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertEquals(i, item.getMetadata("$depth")); + assertThat(item.getMetadata("$depth")).isEqualTo(i); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); }); } @@ -195,9 +198,9 @@ public void testTraverseInBatchTx() { script += "return $top;"; final ResultSet result = database.command("sqlscript", script); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); }); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/TruncateClassStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/TruncateClassStatementExecutionTest.java index a49a37d73b..ab48de3602 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/TruncateClassStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/TruncateClassStatementExecutionTest.java @@ -23,11 +23,12 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -54,14 +55,14 @@ public void testTruncateClass() { database.newDocument(testClass.getName()).set("name", "y").set("data", Arrays.asList(8, 9, -1)).save(); final ResultSet result = database.query("sql", "SElect from test_class"); - // Assertions.assertEquals(result.size(), 2); + // Assertions.assertThat(2).isEqualTo(result.size()); final Set set = new HashSet(); while (result.hasNext()) { set.addAll(result.next().getProperty("data")); } result.close(); - Assertions.assertTrue(set.containsAll(Arrays.asList(5, 6, 7, 8, 9, -1))); + assertThat(set.containsAll(Arrays.asList(5, 6, 7, 8, 9, -1))).isTrue(); schema.dropType("test_class"); database.commit(); @@ -79,22 +80,22 @@ public void testTruncateVertexClassSubclasses() { ResultSet result = database.query("sql", "SElect from TestTruncateVertexClassSuperclass"); for (int i = 0; i < 2; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); database.command("sql", "truncate type TestTruncateVertexClassSuperclass "); result = database.query("sql", "SElect from TestTruncateVertexClassSubclass"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); result.next(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); database.command("sql", "truncate type TestTruncateVertexClassSuperclass polymorphic"); result = database.query("sql", "SElect from TestTruncateVertexClassSubclass"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); database.commit(); } @@ -130,13 +131,13 @@ public void testTruncateClassWithCommandCache() { database.newDocument(testClass.getName()).set("name", "y").set("data", Arrays.asList(3, 0)).save(); ResultSet result = database.query("sql", "SElect from test_class"); - Assertions.assertEquals(toList(result).size(), 2); + assertThat(toList(result).size()).isEqualTo(2); result.close(); database.command("sql", "truncate type test_class"); result = database.query("sql", "SElect from test_class"); - Assertions.assertEquals(toList(result).size(), 0); + assertThat(toList(result).size()).isEqualTo(0); result.close(); schema.dropType("test_class"); diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/UpdateStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/UpdateStatementExecutionTest.java index 1264955434..d2d792653a 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/UpdateStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/UpdateStatementExecutionTest.java @@ -32,13 +32,16 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.time.*; import java.time.format.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -87,22 +90,22 @@ protected void endTest() { @Test public void testSetString() { ResultSet result = database.command("sql", "update " + className + " set surname = 'foo'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("foo", item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isEqualTo("foo"); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -110,117 +113,114 @@ public void testSetString() { public void testCopyField() { ResultSet result = database.command("sql", "update " + className + " set surname = name"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo(10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) item.getProperty("name"), item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isEqualTo( item.getProperty("name")); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testSetExpression() { ResultSet result = database.command("sql", "update " + className + " set surname = 'foo'+name "); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo(10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("foo" + item.getProperty("name"), item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isEqualTo("foo" + item.getProperty("name")); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testConditionalSet() { ResultSet result = database.command("sql", "update " + className + " set surname = 'foo' where name = 'name3'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo(1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); boolean found = false; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); if ("name3".equals(item.getProperty("name"))) { - Assertions.assertEquals("foo", item.getProperty("surname")); + assertThat(item.getProperty("surname")).isEqualTo("foo"); found = true; } } - Assertions.assertTrue(found); - Assertions.assertFalse(result.hasNext()); + assertThat(found).isTrue(); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testSetOnList() { ResultSet result = database.command("sql", "update " + className + " set tagsList[0] = 'abc' where name = 'name3'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo( 1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); boolean found = false; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); if ("name3".equals(item.getProperty("name"))) { - final List tags = new ArrayList<>(); - tags.add("abc"); - tags.add("bar"); - tags.add("baz"); - Assertions.assertEquals(tags, item.getProperty("tagsList")); + final List tags = List.of("abc", "bar", "baz"); + assertThat(item.>getProperty("tagsList")).isEqualTo(tags); found = true; } } - Assertions.assertTrue(found); - Assertions.assertFalse(result.hasNext()); + assertThat(found).isTrue(); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testSetOnList2() { ResultSet result = database.command("sql", "update " + className + " set tagsList[6] = 'abc' where name = 'name3'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); boolean found = false; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); if ("name3".equals(item.getProperty("name"))) { final List tags = new ArrayList<>(); tags.add("foo"); @@ -230,48 +230,48 @@ public void testSetOnList2() { tags.add(null); tags.add(null); tags.add("abc"); - Assertions.assertEquals(tags, item.getProperty("tagsList")); + assertThat(item.>getProperty("tagsList")).isEqualTo(tags); found = true; } } - Assertions.assertTrue(found); - Assertions.assertFalse(result.hasNext()); + assertThat(found).isTrue(); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testSetOnMap() { ResultSet result = database.command("sql", "update " + className + " set tagsMap['foo'] = 'abc' where name = 'name3'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); boolean found = false; for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); if ("name3".equals(item.getProperty("name"))) { final Map tags = new HashMap<>(); tags.put("foo", "abc"); tags.put("bar", "bar"); tags.put("baz", "baz"); - Assertions.assertEquals(tags, item.getProperty("tagsMap")); + assertThat(item.>getProperty("tagsMap")).isEqualTo(tags); found = true; } else { final Map tags = new HashMap<>(); tags.put("foo", "foo"); tags.put("bar", "bar"); tags.put("baz", "baz"); - Assertions.assertEquals(tags, item.getProperty("tagsMap")); + assertThat(item.>getProperty("tagsMap")).isEqualTo(tags); } } - Assertions.assertTrue(found); - Assertions.assertFalse(result.hasNext()); + assertThat(found).isTrue(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -281,21 +281,21 @@ public void testPlusAssignCollection() { "insert into " + className + " set listStrings = ['this', 'is', 'a', 'test'], listNumbers = [1,2,3]"); final RID rid = result.next().getIdentity().get(); result = database.command("sql", "update " + rid + " set listStrings += '!', listNumbers += 9"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); result = database.command("sql", "select from " + rid); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); List listStrings = item.getProperty("listStrings"); - Assertions.assertEquals(5, listStrings.size()); - Assertions.assertEquals("!", listStrings.get(4)); + assertThat(listStrings.size()).isEqualTo(5); + assertThat(listStrings.get(4)).isEqualTo("!"); List listNumbers = item.getProperty("listNumbers"); - Assertions.assertEquals(4, listNumbers.size()); - Assertions.assertEquals(9, listNumbers.get(3)); + assertThat(listNumbers.size()).isEqualTo(4); + assertThat(listNumbers.get(3)).isEqualTo(9); } @Test @@ -303,23 +303,23 @@ public void testPlusAssignMap() { ResultSet result = database.command("sql", "insert into " + className + " set map1 = {'name':'Jay'}, map2 = {'name':'Jay'}"); final RID rid = result.next().getIdentity().get(); result = database.command("sql", "update " + rid + " set map1 += { 'last': 'Miner'}, map2 += [ 'last', 'Miner']"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); result = database.command("sql", "select from " + rid); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); Map map1 = item.getProperty("map1"); - Assertions.assertEquals(2, map1.size()); - Assertions.assertEquals("Jay", map1.get("name")); - Assertions.assertEquals("Miner", map1.get("last")); + assertThat(map1.size()).isEqualTo(2); + assertThat(map1.get("name")).isEqualTo("Jay"); + assertThat(map1.get("last")).isEqualTo("Miner"); Map map2 = item.getProperty("map2"); - Assertions.assertEquals(2, map2.size()); - Assertions.assertEquals("Jay", map2.get("name")); - Assertions.assertEquals("Miner", map2.get("last")); + assertThat(map2.size()).isEqualTo(2); + assertThat(map2.get("name")).isEqualTo("Jay"); + assertThat(map2.get("last")).isEqualTo("Miner"); } /** @@ -333,68 +333,68 @@ public void testPlusAssignNestedMaps() { database.command("sql", "update " + rid + " set bars = map( \"23-03-24\" , { \"volume\": 100 } )"); result = database.command("sql", "update " + rid + " set bars += { \"2023-03-08\": { \"volume\": 134 }}"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); result = database.command("sql", "select from " + rid); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); Map map1 = item.getProperty("bars"); - Assertions.assertEquals(2, map1.size()); + assertThat(map1.size()).isEqualTo(2); Map nestedMap = (Map) map1.get("23-03-24"); - Assertions.assertNotNull(nestedMap); - Assertions.assertEquals(100, nestedMap.get("volume")); + assertThat(nestedMap).isNotNull(); + assertThat(nestedMap.get("volume")).isEqualTo(100); nestedMap = (Map) map1.get("2023-03-08"); - Assertions.assertNotNull(nestedMap); - Assertions.assertEquals(134, nestedMap.get("volume")); + assertThat(nestedMap).isNotNull(); + assertThat(nestedMap.get("volume")).isEqualTo(134); } @Test public void testPlusAssign() { ResultSet result = database.command("sql", "update " + className + " set name += 'foo', newField += 'bar', number += 5"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertTrue(item.getProperty("name").toString().endsWith("foo")); // test concatenate string to string - Assertions.assertEquals(8, item.getProperty("name").toString().length()); - Assertions.assertEquals("bar", item.getProperty("newField")); // test concatenate null to string - Assertions.assertEquals((Object) 9L, item.getProperty("number")); // test sum numbers + assertThat(item).isNotNull(); + assertThat(item.getProperty("name").toString().endsWith("foo")).isTrue(); // test concatenate string to string + assertThat(item.getProperty("name").toString().length()).isEqualTo(8); + assertThat(item.getProperty("newField")).isEqualTo("bar"); // test concatenate null to string + assertThat(item.getProperty("number")).isEqualTo( 9L); // test sum numbers } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testMinusAssign() { ResultSet result = database.command("sql", "update " + className + " set number -= 5"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) (-1L), item.getProperty("number")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("number")).isEqualTo((Object) (-1L)); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -404,21 +404,21 @@ public void testMinusAssignCollection() { "insert into " + className + " set listStrings = ['this', 'is', 'a', 'test'], listNumbers = [1,2,3]"); final RID rid = result.next().getIdentity().get(); result = database.command("sql", "update " + rid + " set listStrings -= 'a', listNumbers -= 2"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); result = database.command("sql", "select from " + rid); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); List listStrings = item.getProperty("listStrings"); - Assertions.assertEquals(3, listStrings.size()); - Assertions.assertFalse(listStrings.contains("!")); + assertThat(listStrings.size()).isEqualTo(3); + assertThat(listStrings.contains("!")).isFalse(); List listNumbers = item.getProperty("listNumbers"); - Assertions.assertEquals(2, listNumbers.size()); - Assertions.assertFalse(listNumbers.contains(2)); + assertThat(listNumbers.size()).isEqualTo(2); + assertThat(listNumbers.contains(2)).isFalse(); } @Test @@ -426,60 +426,60 @@ public void testMinusAssignMap() { ResultSet result = database.command("sql", "insert into " + className + " set map1 = {'name':'Jay'}, map2 = {'name':'Jay'}"); final RID rid = result.next().getIdentity().get(); result = database.command("sql", "update " + rid + " set map1 -= {'name':'Jay'}, map2 -= [ 'name' ]"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNotNull(result.next()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next()).isNotNull(); result = database.command("sql", "select from " + rid); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); Map map1 = item.getProperty("map1"); - Assertions.assertEquals(0, map1.size()); + assertThat(map1.size()).isEqualTo(0); Map map2 = item.getProperty("map2"); - Assertions.assertEquals(0, map2.size()); + assertThat(map2.size()).isEqualTo(0); } @Test public void testStarAssign() { ResultSet result = database.command("sql", "update " + className + " set number *= 5"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 20L, item.getProperty("number")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("number")).isEqualTo(20L); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testSlashAssign() { ResultSet result = database.command("sql", "update " + className + " set number /= 2"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 2L, item.getProperty("number")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("number")).isEqualTo(2L); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -487,31 +487,31 @@ public void testSlashAssign() { public void testRemove() { ResultSet result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertNotNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("surname")).isNotNull(); } result.close(); result = database.command("sql", "update " + className + " remove surname"); for (int i = 0; i < 1; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertFalse(item.toElement().has("surname")); + assertThat(item).isNotNull(); + assertThat(item.toElement().has("surname")).isFalse(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -519,23 +519,23 @@ public void testRemove() { public void testContent() { ResultSet result = database.command("sql", "update " + className + " content {'name': 'foo', 'secondName': 'bar'}"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("foo", item.getProperty("name")); - Assertions.assertEquals("bar", item.getProperty("secondName")); - Assertions.assertNull(item.getProperty("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("foo"); + assertThat(item.getProperty("secondName")).isEqualTo("bar"); + assertThat(item.getProperty("surname")).isNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -543,23 +543,23 @@ public void testContent() { public void testMerge() { ResultSet result = database.command("sql", "update " + className + " merge {'name': 'foo', 'secondName': 'bar'}"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 10L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 10L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("foo", item.getProperty("name")); - Assertions.assertEquals("bar", item.getProperty("secondName")); - Assertions.assertTrue(item.getProperty("surname").toString().startsWith("surname")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("foo"); + assertThat(item.getProperty("secondName")).isEqualTo("bar"); + assertThat(item.getProperty("surname").toString().startsWith("surname")).isTrue(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -580,21 +580,21 @@ public void testRemove1() { doc.save(); ResultSet result = database.command("sql", "update " + className + " remove theProperty[0]"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final List ls = item.getProperty("theProperty"); - Assertions.assertNotNull(ls); - Assertions.assertEquals(9, ls.size()); - Assertions.assertFalse(ls.contains("n0")); - Assertions.assertFalse(result.hasNext()); + assertThat(ls).isNotNull(); + assertThat(ls.size()).isEqualTo(9); + assertThat(ls.contains("n0")).isFalse(); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -614,27 +614,27 @@ public void testRemove2() { doc.save(); ResultSet result = database.command("sql", "update " + className + " remove theProperty[0, 1, 3]"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final List ls = item.getProperty("theProperty"); - Assertions.assertNotNull(ls); - Assertions.assertEquals(ls.size(), 7); - Assertions.assertFalse(ls.contains("n0")); - Assertions.assertFalse(ls.contains("n1")); - Assertions.assertTrue(ls.contains("n2")); - Assertions.assertFalse(ls.contains("n3")); - Assertions.assertTrue(ls.contains("n4")); + assertThat(ls).isNotNull(); + assertThat(ls.size()).isEqualTo(7); + assertThat(ls.contains("n0")).isFalse(); + assertThat(ls.contains("n1")).isFalse(); + assertThat(ls.contains("n2")).isTrue(); + assertThat(ls.contains("n3")).isFalse(); + assertThat(ls.contains("n4")).isTrue(); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -653,21 +653,21 @@ public void testRemove3() { doc.save(); ResultSet result = database.command("sql", "update " + className + " remove theProperty.sub"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final EmbeddedDocument ls = item.getProperty("theProperty"); - Assertions.assertNotNull(ls); - Assertions.assertFalse(ls.getPropertyNames().contains("sub")); - Assertions.assertEquals("bar", ls.getString("aaa")); - Assertions.assertFalse(result.hasNext()); + assertThat(ls).isNotNull(); + assertThat(ls.getPropertyNames().contains("sub")).isFalse(); + assertThat(ls.getString("aaa")).isEqualTo("bar"); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -678,13 +678,13 @@ public void testRemoveFromMapSquare() { final ResultSet result = database.query("sql", "SELECT tagsMap FROM " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(2, ((Map) item.getProperty("tagsMap")).size()); - Assertions.assertFalse(((Map) item.getProperty("tagsMap")).containsKey("bar")); + assertThat(item).isNotNull(); + assertThat(((Map) item.getProperty("tagsMap")).size()).isEqualTo(2); + assertThat(((Map) item.getProperty("tagsMap")).containsKey("bar")).isFalse(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -695,13 +695,13 @@ public void testRemoveFromMapEquals() { final ResultSet result = database.query("sql", "SELECT tagsMap FROM " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals(2, ((Map) item.getProperty("tagsMap")).size()); - Assertions.assertFalse(((Map) item.getProperty("tagsMap")).containsKey("bar")); + assertThat(item).isNotNull(); + assertThat(((Map) item.getProperty("tagsMap")).size()).isEqualTo(2); + assertThat(((Map) item.getProperty("tagsMap")).containsKey("bar")).isFalse(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -709,12 +709,12 @@ public void testRemoveFromMapEquals() { public void testReturnBefore() { final ResultSet result = database.command("sql", "update " + className + " set name = 'foo' RETURN BEFORE where name = 'name1'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("name1", item.getProperty("name")); + assertThat(item).isNotNull(); + assertThat(item.getProperty("name")).isEqualTo("name1"); - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -762,12 +762,12 @@ public void testLocalDateTimeUpsertWithIndexMicros() throws ClassNotFoundExcepti try (ResultSet resultSet = database.query("sql", "SELECT start, stop FROM Product WHERE start <= ? AND stop >= ? ORDER BY start DESC, stop DESC LIMIT 1", start, stop)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) { result = resultSet.next(); - Assertions.assertNotNull(result.getProperty("start")); - Assertions.assertNotNull(result.getProperty("stop")); + assertThat(result.getProperty("start")).isNotNull(); + assertThat(result.getProperty("stop")).isNotNull(); } } }); @@ -813,8 +813,8 @@ public void testCompositeIndexLookup() { String sqlString = "SELECT id, processor, status FROM Order WHERE status = ?"; try (ResultSet resultSet1 = database.query("sql", sqlString, parameters2)) { final Result record = resultSet1.next(); - Assertions.assertEquals("PENDING", record.getProperty("status")); - Assertions.assertEquals("2", record.getProperty("id")); + assertThat(record.getProperty("status")).isEqualTo("PENDING"); + assertThat(record.getProperty("id")).isEqualTo("2"); } }); // drop index @@ -825,7 +825,7 @@ public void testCompositeIndexLookup() { Object[] parameters2 = { "PENDING" }; String sqlString = "SELECT id, processor, status FROM Order WHERE status = ?"; try (ResultSet resultSet1 = database.query("sql", sqlString, parameters2)) { - Assertions.assertEquals("PENDING", resultSet1.next().getProperty("status")); + assertThat(resultSet1.next().getProperty("status")).isEqualTo("PENDING"); } }); @@ -833,7 +833,7 @@ public void testCompositeIndexLookup() { Object[] parameters2 = { "PENDING" }; try (ResultSet resultSet1 = database.query("sql", "SELECT id, status FROM Order WHERE status = 'PENDING' OR status = 'READY' ORDER BY id ASC LIMIT 1")) { - Assertions.assertEquals("PENDING", resultSet1.next().getProperty("status")); + assertThat(resultSet1.next().getProperty("status")).isEqualTo("PENDING"); } }); } @@ -853,14 +853,14 @@ public void testSelectAfterUpdate() { String INSERT_ORDER = "INSERT INTO Order SET id = ?, status = ?"; database.begin(); try (ResultSet resultSet = database.command("sql", INSERT_ORDER, 1, "PENDING")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } database.commit(); // update order database.begin(); String UPDATE_ORDER = "UPDATE Order SET status = ? RETURN AFTER WHERE id = ?"; try (ResultSet resultSet = database.command("sql", UPDATE_ORDER, "ERROR", 1)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } database.commit(); // resubmit order 1 @@ -868,17 +868,17 @@ public void testSelectAfterUpdate() { // "UPDATE Order SET status = ? WHERE (status != ? AND status != ?) AND id = ?"; String RESUBMIT_ORDER = "UPDATE Order SET status = ? RETURN AFTER WHERE (status != ? AND status != ?) AND id = ?"; try (ResultSet resultSet = database.command("sql", RESUBMIT_ORDER, "PENDING", "PENDING", "PROCESSING", 1)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } database.commit(); // retrieve order 1 by id try (ResultSet resultSet = database.query("sql", "SELECT FROM Order WHERE id = 1")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } // retrieve order 1 by status String RETRIEVE_NEXT_ELIGIBLE_ORDERS = "SELECT id, status FROM Order WHERE status = 'PENDING' OR status = 'READY' ORDER BY id ASC LIMIT 1"; try (ResultSet resultSet = database.query("sql", RETRIEVE_NEXT_ELIGIBLE_ORDERS)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); } } @@ -900,9 +900,9 @@ public void testUpdateVariable() { "return $e;"); ResultSet resultSet = database.query("sql", "SELECT from Account where name = 'bob'"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) - Assertions.assertEquals("bob", resultSet.next().getProperty("name")); + assertThat(resultSet.next().getProperty("name")).isEqualTo("bob"); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/UpsertStatementExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/UpsertStatementExecutionTest.java index 39397fbad8..00850765bf 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/UpsertStatementExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/UpsertStatementExecutionTest.java @@ -29,13 +29,16 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.time.*; import java.time.format.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) @@ -90,7 +93,7 @@ public void testUpsertBucket() { final List resultSet = database.select().fromType(className).where().property("name").eq().value("name1").documents() .toList(); - Assertions.assertEquals(1, resultSet.size()); + assertThat(resultSet.size()).isEqualTo(1); final Document record = resultSet.get(0); final String bucketName = database.getSchema().getBucketById(record.getIdentity().getBucketId()).getName(); @@ -98,86 +101,86 @@ public void testUpsertBucket() { // BY BUCKET NAME ResultSet result = database.command("sql", "update bucket:" + bucketName + " set foo = 'bar' upsert where name = 'name1'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo( 1L); + assertThat(result.hasNext()).isFalse(); result.close(); // BY BUCKET ID result = database.command("sql", "update bucket:" + record.getIdentity().getBucketId() + " set foo = 'bar' upsert where name = 'name1'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo( 1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from bucket:" + buckets.get(0).getName()); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - Assertions.assertNotNull(name); + assertThat(name).isNotNull(); if ("name1".equals(name)) { - Assertions.assertEquals("bar", item.getProperty("foo")); + assertThat(item.getProperty("foo")).isEqualTo("bar"); } else { - Assertions.assertNull(item.getProperty("foo")); + assertThat(item.getProperty("foo")).isNull(); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.command("sql", "update bucket:" + bucketName + " remove foo upsert where name = 'name1'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from bucket:" + bucketName); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); while (result.hasNext()) { item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - Assertions.assertNotNull(name); - Assertions.assertNull(item.getProperty("foo")); + assertThat(name).isNotNull(); + assertThat(item.getProperty("foo")).isNull(); } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @Test public void testUpsert1() { ResultSet result = database.command("sql", "update " + className + " set foo = 'bar' upsert where name = 'name1'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - Assertions.assertNotNull(name); + assertThat(name).isNotNull(); if ("name1".equals(name)) { - Assertions.assertEquals("bar", item.getProperty("foo")); + assertThat(item.getProperty("foo")).isEqualTo("bar"); } else { - Assertions.assertNull(item.getProperty("foo")); + assertThat(item.getProperty("foo")).isNull(); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -192,12 +195,12 @@ public void testUpsertVertices() { final ResultSet result = database.command("sql", "update extra_node set extraitem = 'Hugo2' upsert return after $current where extraitem = 'Hugo'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final Vertex current = item.getProperty("$current"); - Assertions.assertEquals("Hugo2", current.getString("extraitem")); - Assertions.assertFalse(result.hasNext()); + assertThat(current.getString("extraitem")).isEqualTo("Hugo2"); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -206,11 +209,11 @@ public void testUpsertAndReturn() { final ResultSet result = database.command("sql", "update " + className + " set foo = 'bar' upsert return after where name = 'name1' "); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals("bar", item.getProperty("foo")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("foo")).isEqualTo("bar"); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -218,27 +221,27 @@ public void testUpsertAndReturn() { public void testUpsert2() { ResultSet result = database.command("sql", "update " + className + " set foo = 'bar' upsert where name = 'name11'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo((Object) 1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from " + className); for (int i = 0; i < 11; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - Assertions.assertNotNull(name); + assertThat(name).isNotNull(); if ("name11".equals(name)) { - Assertions.assertEquals("bar", item.getProperty("foo")); + assertThat(item.getProperty("foo")).isEqualTo("bar"); } else { - Assertions.assertNull(item.getProperty("foo")); + assertThat(item.getProperty("foo")).isNull(); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -270,27 +273,27 @@ public void testUpsertVertices2() { } ResultSet result = database.command("sql", "update UpsertableVertex set foo = 'bar' upsert where name = 'name1'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result item = result.next(); - Assertions.assertNotNull(item); - Assertions.assertEquals((Object) 1L, item.getProperty("count")); - Assertions.assertFalse(result.hasNext()); + assertThat(item).isNotNull(); + assertThat(item.getProperty("count")).isEqualTo(1L); + assertThat(result.hasNext()).isFalse(); result.close(); result = database.query("sql", "SElect from UpsertableVertex"); for (int i = 0; i < 10; i++) { - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); item = result.next(); - Assertions.assertNotNull(item); + assertThat(item).isNotNull(); final String name = item.getProperty("name"); - Assertions.assertNotNull(name); + assertThat(name).isNotNull(); if ("name1".equals(name)) { - Assertions.assertEquals("bar", item.getProperty("foo")); + assertThat(item.getProperty("foo")).isEqualTo("bar"); } else { - Assertions.assertNull(item.getProperty("foo")); + assertThat(item.getProperty("foo")).isNull(); } } - Assertions.assertFalse(result.hasNext()); + assertThat(result.hasNext()).isFalse(); result.close(); } @@ -325,8 +328,8 @@ public void testLocalDateTimeUpsertWithIndex() throws ClassNotFoundException { ResultSet resultSet = database.query("sql", "SELECT from Product"); while (resultSet.hasNext()) { result = resultSet.next(); - Assertions.assertNotNull(result.getProperty("start")); - Assertions.assertNotNull(result.getProperty("stop")); + assertThat(result.getProperty("start")).isNotNull(); + assertThat(result.getProperty("stop")).isNotNull(); } }); } @@ -376,12 +379,12 @@ public void testLocalDateTimeUpsertWithIndexMicros() throws ClassNotFoundExcepti try (ResultSet resultSet = database.query("sql", "SELECT start, stop FROM Product WHERE start <= ? AND stop >= ? ORDER BY start DESC, stop DESC LIMIT 1", start, stop)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) { result = resultSet.next(); - Assertions.assertNotNull(result.getProperty("start")); - Assertions.assertNotNull(result.getProperty("stop")); + assertThat(result.getProperty("start")).isNotNull(); + assertThat(result.getProperty("stop")).isNotNull(); } } }); diff --git a/engine/src/test/java/com/arcadedb/query/sql/executor/WhileBlockExecutionTest.java b/engine/src/test/java/com/arcadedb/query/sql/executor/WhileBlockExecutionTest.java index f7ae5b0daf..b9cc28c722 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/executor/WhileBlockExecutionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/executor/WhileBlockExecutionTest.java @@ -19,9 +19,10 @@ package com.arcadedb.query.sql.executor; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com) */ @@ -51,11 +52,11 @@ public void testPlain() { int sum = 0; while (results.hasNext()) { final Result item = results.next(); - sum += (Integer) item.getProperty("value"); + sum += item.getProperty("value"); tot++; } - Assertions.assertEquals(3, tot); - Assertions.assertEquals(3, sum); + assertThat(tot).isEqualTo(3); + assertThat(sum).isEqualTo(3); results.close(); } @@ -83,11 +84,11 @@ public void testReturn() { int sum = 0; while (results.hasNext()) { final Result item = results.next(); - sum += (Integer) item.getProperty("value"); + sum += item.getProperty("value"); tot++; } - Assertions.assertEquals(2, tot); - Assertions.assertEquals(1, sum); + assertThat(tot).isEqualTo(2); + assertThat(sum).isEqualTo(1); results.close(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionIntersectTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionIntersectTest.java index 7f744d9d11..f1a3de8327 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionIntersectTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionIntersectTest.java @@ -20,11 +20,12 @@ import com.arcadedb.query.sql.executor.BasicCommandContext; import com.arcadedb.query.sql.function.coll.SQLFunctionIntersect; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -39,7 +40,7 @@ public void intersectInline() { final ArrayList result = (ArrayList) function.execute(null, null, null, new Object[] { coll1, coll2 }, new BasicCommandContext()); - Assertions.assertEquals(new HashSet<>(result), new HashSet<>(Arrays.asList(1, 3, 0))); + assertThat(new HashSet<>(Arrays.asList(1, 3, 0))).isEqualTo(new HashSet<>(result)); } @Test @@ -52,6 +53,6 @@ public void intersectNotInline() { function.execute(null, null, null, new Object[] { coll1 }, new BasicCommandContext()); function.execute(null, null, null, new Object[] { coll2 }, new BasicCommandContext()); - Assertions.assertEquals(function.getResult(), new HashSet<>(Arrays.asList(1, 3, 0))); + assertThat(new HashSet<>(Arrays.asList(1, 3, 0))).isEqualTo(function.getResult()); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionSymmetricDifferenceTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionSymmetricDifferenceTest.java index 1c75821fb2..5301f30451 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionSymmetricDifferenceTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/coll/SQLFunctionSymmetricDifferenceTest.java @@ -20,11 +20,12 @@ import com.arcadedb.query.sql.executor.BasicCommandContext; import com.arcadedb.query.sql.function.coll.SQLFunctionSymmetricDifference; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author edegtyarenko * @since 11.10.12 14:40 @@ -62,9 +63,9 @@ public void testExecute() { } private void assertSetEquals(final Set actualResult, final Set expectedResult) { - Assertions.assertEquals(actualResult.size(), expectedResult.size()); + assertThat(expectedResult.size()).isEqualTo(actualResult.size()); for (final Object o : actualResult) { - Assertions.assertTrue(expectedResult.contains(o)); + assertThat(expectedResult.contains(o)).isTrue(); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/geo/SQLGeoFunctionsTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/geo/SQLGeoFunctionsTest.java index e23d2355e3..265d54b109 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/geo/SQLGeoFunctionsTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/geo/SQLGeoFunctionsTest.java @@ -26,7 +26,8 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.locationtech.spatial4j.io.GeohashUtils; import org.locationtech.spatial4j.shape.Circle; @@ -34,6 +35,8 @@ import org.locationtech.spatial4j.shape.Rectangle; import org.locationtech.spatial4j.shape.Shape; +import static org.assertj.core.api.Assertions.*; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -43,9 +46,9 @@ public class SQLGeoFunctionsTest { public void testPoint() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select point(11,11) as point"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Point point = result.next().getProperty("point"); - Assertions.assertNotNull(point); + assertThat(point).isNotNull(); }); } @@ -53,9 +56,9 @@ public void testPoint() throws Exception { public void testRectangle() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select rectangle(10,10,20,20) as shape"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Rectangle rectangle = result.next().getProperty("shape"); - Assertions.assertNotNull(rectangle); + assertThat(rectangle).isNotNull(); }); } @@ -63,24 +66,25 @@ public void testRectangle() throws Exception { public void testCircle() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select circle(10,10,10) as circle"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Circle circle = result.next().getProperty("circle"); - Assertions.assertNotNull(circle); + assertThat(circle).isNotNull(); }); } @Test public void testPolygon() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { - ResultSet result = db.query("sql", "select polygon( [ point(10,10), point(20,10), point(20,20), point(10,20), point(10,10) ] ) as polygon"); - Assertions.assertTrue(result.hasNext()); + ResultSet result = db.query("sql", + "select polygon( [ point(10,10), point(20,10), point(20,20), point(10,20), point(10,10) ] ) as polygon"); + assertThat(result.hasNext()).isTrue(); Shape polygon = result.next().getProperty("polygon"); - Assertions.assertNotNull(polygon); + assertThat(polygon).isNotNull(); result = db.query("sql", "select polygon( [ [10,10], [20,10], [20,20], [10,20], [10,10] ] ) as polygon"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); polygon = result.next().getProperty("polygon"); - Assertions.assertNotNull(polygon); + assertThat(polygon).isNotNull(); }); } @@ -88,12 +92,12 @@ public void testPolygon() throws Exception { public void testPointIsWithinRectangle() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select point(11,11).isWithin( rectangle(10,10,20,20) ) as isWithin"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("isWithin")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("isWithin")).isTrue(); result = db.query("sql", "select point(11,21).isWithin( rectangle(10,10,20,20) ) as isWithin"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("isWithin")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("isWithin")).isFalse(); }); } @@ -101,12 +105,12 @@ public void testPointIsWithinRectangle() throws Exception { public void testPointIsWithinCircle() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select point(11,11).isWithin( circle(10,10,10) ) as isWithin"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("isWithin")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("isWithin")).isTrue(); result = db.query("sql", "select point(10,21).isWithin( circle(10,10,10) ) as isWithin"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("isWithin")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("isWithin")).isFalse(); }); } @@ -114,12 +118,12 @@ public void testPointIsWithinCircle() throws Exception { public void testPointIntersectWithRectangle() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select rectangle(9,9,11,11).intersectsWith( rectangle(10,10,20,20) ) as intersectsWith"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("intersectsWith")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("intersectsWith")).isTrue(); result = db.query("sql", "select rectangle(9,9,9.9,9.9).intersectsWith( rectangle(10,10,20,20) ) as intersectsWith"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("intersectsWith")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("intersectsWith")).isFalse(); }); } @@ -128,12 +132,13 @@ public void testPointIntersectWithPolygons() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select polygon( [ [10,10], [20,10], [20,20], [10,20], [10,10] ] ).intersectsWith( rectangle(10,10,20,20) ) as intersectsWith"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("intersectsWith")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("intersectsWith")).isTrue(); - result = db.query("sql", "select polygon( [ [10,10], [20,10], [20,20], [10,20], [10,10] ] ).intersectsWith( rectangle(21,21,22,22) ) as intersectsWith"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("intersectsWith")); + result = db.query("sql", + "select polygon( [ [10,10], [20,10], [20,20], [10,20], [10,10] ] ).intersectsWith( rectangle(21,21,22,22) ) as intersectsWith"); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("intersectsWith")).isFalse(); }); } @@ -142,13 +147,13 @@ public void testLineStringsIntersect() throws Exception { TestHelper.executeInNewDatabase("GeoDatabase", (db) -> { ResultSet result = db.query("sql", "select linestring( [ [10,10], [20,10], [20,20], [10,20], [10,10] ] ).intersectsWith( rectangle(10,10,20,20) ) as intersectsWith"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("intersectsWith")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("intersectsWith")).isTrue(); result = db.query("sql", "select linestring( [ [10,10], [20,10], [20,20], [10,20], [10,10] ] ).intersectsWith( rectangle(21,21,22,22) ) as intersectsWith"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("intersectsWith")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("intersectsWith")).isFalse(); }); } @@ -183,12 +188,12 @@ public void testGeoManualIndexPoints() throws Exception { begin = System.currentTimeMillis(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); int returned = 0; while (result.hasNext()) { final Document record = result.next().toElement(); - Assertions.assertTrue(record.getDouble("lat") >= 10.5); - Assertions.assertTrue(record.getDouble("long") <= 10.55); + assertThat(record.getDouble("lat")).isGreaterThanOrEqualTo(10.5); + assertThat(record.getDouble("long")).isLessThanOrEqualTo(10.55); // System.out.println(record.toJSON()); ++returned; @@ -196,7 +201,7 @@ public void testGeoManualIndexPoints() throws Exception { //System.out.println("Elapsed browsing: " + (System.currentTimeMillis() - begin)); - Assertions.assertEquals(6, returned); + assertThat(returned).isEqualTo(6); }); }); } @@ -226,7 +231,7 @@ public void testGeoManualIndexBoundingBoxes() throws Exception { } for (Index idx : type.getAllIndexes(false)) { - Assertions.assertEquals(TOTAL, idx.countEntries()); + assertThat(idx.countEntries()).isEqualTo(TOTAL); } //System.out.println("Elapsed insert: " + (System.currentTimeMillis() - begin)); @@ -243,14 +248,14 @@ public void testGeoManualIndexBoundingBoxes() throws Exception { begin = System.currentTimeMillis(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); int returned = 0; while (result.hasNext()) { final Document record = result.next().toElement(); - Assertions.assertTrue(record.getDouble("x1") >= 10.0001D, "x1: " + record.getDouble("x1")); - Assertions.assertTrue(record.getDouble("y1") >= 10.0001D, "y1: " + record.getDouble("y1")); - Assertions.assertTrue(record.getDouble("x2") <= 10.020D, "x2: " + record.getDouble("x2")); - Assertions.assertTrue(record.getDouble("y2") <= 10.020D, "y2: " + record.getDouble("y2")); + assertThat(record.getDouble("x1")).isGreaterThanOrEqualTo(10.0001D).withFailMessage("x1: " + record.getDouble("x1")); + assertThat(record.getDouble("y1")).isGreaterThanOrEqualTo(10.0001D).withFailMessage("y1: " + record.getDouble("y1")); + assertThat(record.getDouble("x2")).isLessThanOrEqualTo(10.020D).withFailMessage("x2: " + record.getDouble("x2")); + assertThat(record.getDouble("y2")).isLessThanOrEqualTo(10.020D).withFailMessage("y2: " + record.getDouble("y2")); //System.out.println(record.toJSON()); ++returned; @@ -258,7 +263,7 @@ public void testGeoManualIndexBoundingBoxes() throws Exception { //System.out.println("Elapsed browsing: " + (System.currentTimeMillis() - begin)); - Assertions.assertEquals(20, returned); + assertThat(returned).isEqualTo(20); }); }); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAdjacencyTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAdjacencyTest.java index 874df1f3b2..21e91e4cc6 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAdjacencyTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAdjacencyTest.java @@ -36,11 +36,14 @@ import com.arcadedb.query.sql.function.graph.SQLFunctionOut; import com.arcadedb.query.sql.function.graph.SQLFunctionOutE; import com.arcadedb.query.sql.function.graph.SQLFunctionOutV; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + public class SQLFunctionAdjacencyTest { private final Map vertices = new HashMap<>(); @@ -57,14 +60,14 @@ public void testOutE() throws Exception { final Set result = new HashSet<>(); while (iterator.hasNext()) { final Edge edge = iterator.next().asEdge(true); - Assertions.assertNotNull(edge); + assertThat(edge).isNotNull(); result.add(edge.getIdentity()); } - Assertions.assertTrue(result.contains(edges.get(3).getIdentity())); - Assertions.assertTrue(result.contains(edges.get(4).getIdentity())); + assertThat(result.contains(edges.get(3).getIdentity())).isTrue(); + assertThat(result.contains(edges.get(4).getIdentity())).isTrue(); - Assertions.assertEquals(2, result.size()); + assertThat(result).hasSize(2); }); } @@ -79,13 +82,13 @@ public void testInE() throws Exception { final Set result = new HashSet<>(); while (iterator.hasNext()) { final Edge edge = iterator.next().asEdge(true); - Assertions.assertNotNull(edge); + assertThat(edge).isNotNull(); result.add(edge.getIdentity()); } - Assertions.assertTrue(result.contains(edges.get(2).getIdentity())); + assertThat(result.contains(edges.get(2).getIdentity())).isTrue(); - Assertions.assertEquals(1, result.size()); + assertThat(result).hasSize(1); }); } @@ -100,15 +103,15 @@ public void testBothE() throws Exception { final Set result = new HashSet<>(); while (iterator.hasNext()) { final Edge edge = iterator.next().asEdge(true); - Assertions.assertNotNull(edge); + assertThat(edge).isNotNull(); result.add(edge.getIdentity()); } - Assertions.assertTrue(result.contains(edges.get(2).getIdentity())); - Assertions.assertTrue(result.contains(edges.get(3).getIdentity())); - Assertions.assertTrue(result.contains(edges.get(4).getIdentity())); + assertThat(result.contains(edges.get(2).getIdentity())).isTrue(); + assertThat(result.contains(edges.get(3).getIdentity())).isTrue(); + assertThat(result.contains(edges.get(4).getIdentity())).isTrue(); - Assertions.assertEquals(3, result.size()); + assertThat(result).hasSize(3); }); } @@ -123,15 +126,15 @@ public void testBoth() throws Exception { final Set result = new HashSet<>(); while (iterator.hasNext()) { final Vertex vertex = iterator.next().asVertex(true); - Assertions.assertNotNull(vertex); + assertThat(vertex).isNotNull(); result.add(vertex.getIdentity()); } - Assertions.assertTrue(result.contains(vertices.get(2).getIdentity())); - Assertions.assertTrue(result.contains(vertices.get(1).getIdentity())); - Assertions.assertTrue(result.contains(vertices.get(4).getIdentity())); + assertThat(result.contains(vertices.get(2).getIdentity())).isTrue(); + assertThat(result.contains(vertices.get(1).getIdentity())).isTrue(); + assertThat(result.contains(vertices.get(4).getIdentity())).isTrue(); - Assertions.assertEquals(3, result.size()); + assertThat(result).hasSize(3); }); } @@ -146,14 +149,14 @@ public void testOut() throws Exception { final Set result = new HashSet<>(); while (iterator.hasNext()) { final Vertex vertex = iterator.next().asVertex(true); - Assertions.assertNotNull(vertex); + assertThat(vertex).isNotNull(); result.add(vertex.getIdentity()); } - Assertions.assertTrue(result.contains(vertices.get(1).getIdentity())); - Assertions.assertTrue(result.contains(vertices.get(4).getIdentity())); + assertThat(result.contains(vertices.get(1).getIdentity())).isTrue(); + assertThat(result.contains(vertices.get(4).getIdentity())).isTrue(); - Assertions.assertEquals(2, result.size()); + assertThat(result).hasSize(2); }); } @@ -168,13 +171,13 @@ public void testIn() throws Exception { final Set result = new HashSet<>(); while (iterator.hasNext()) { final Vertex vertex = iterator.next().asVertex(true); - Assertions.assertNotNull(vertex); + assertThat(vertex).isNotNull(); result.add(vertex.getIdentity()); } - Assertions.assertTrue(result.contains(vertices.get(2).getIdentity())); + assertThat(result.contains(vertices.get(2).getIdentity())).isTrue(); - Assertions.assertEquals(1, result.size()); + assertThat(result).hasSize(1); }); } @@ -185,7 +188,7 @@ public void testOutV() throws Exception { final Vertex v = (Vertex) new SQLFunctionOutV().execute(edges.get(3), null, null, new Object[] {}, new BasicCommandContext().setDatabase(graph)); - Assertions.assertEquals(v.getIdentity(), vertices.get(3).getIdentity()); + assertThat(vertices.get(3).getIdentity()).isEqualTo(v.getIdentity()); }); } @@ -196,7 +199,7 @@ public void testInV() throws Exception { final Vertex v = (Vertex) new SQLFunctionInV().execute(edges.get(3), null, null, new Object[] {}, new BasicCommandContext().setDatabase(graph)); - Assertions.assertEquals(v.getIdentity(), vertices.get(1).getIdentity()); + assertThat(vertices.get(1).getIdentity()).isEqualTo(v.getIdentity()); }); } @@ -208,10 +211,10 @@ public void testBothV() throws Exception { final ArrayList iterator = (ArrayList) new SQLFunctionBothV().execute(edges.get(3), null, null, new Object[] {}, new BasicCommandContext().setDatabase(graph)); - Assertions.assertTrue(iterator.contains(vertices.get(3).getIdentity())); - Assertions.assertTrue(iterator.contains(vertices.get(1).getIdentity())); + assertThat(iterator.contains(vertices.get(3).getIdentity())).isTrue(); + assertThat(iterator.contains(vertices.get(1).getIdentity())).isTrue(); - Assertions.assertEquals(2, iterator.size()); + assertThat(iterator).hasSize(2); }); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAstarTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAstarTest.java index 85a3f6f5cb..5df39e18f6 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAstarTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionAstarTest.java @@ -33,6 +33,7 @@ import java.util.*; import java.util.stream.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; /* @@ -195,14 +196,14 @@ public void test1Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v1, v4, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(4, result.size()); - assertEquals(v1, result.get(0)); - assertEquals(v2, result.get(1)); - assertEquals(v3, result.get(2)); - assertEquals(v4, result.get(3)); + assertThat(result).hasSize(4); + assertThat(result.get(0)).isEqualTo(v1); + assertThat(result.get(1)).isEqualTo(v2); + assertThat(result.get(2)).isEqualTo(v3); + assertThat(result.get(3)).isEqualTo(v4); }); } @@ -220,12 +221,12 @@ public void test2Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v1, v6, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(3, result.size()); - assertEquals(v1, result.get(0)); - assertEquals(v5, result.get(1)); - assertEquals(v6, result.get(2)); + assertThat(result).hasSize(3); + assertThat(result.get(0)).isEqualTo(v1); + assertThat(result.get(1)).isEqualTo(v5); + assertThat(result.get(2)).isEqualTo(v6); }); } @@ -244,13 +245,13 @@ public void test3Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v1, v6, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(3, result.size()); - assertEquals(v1, result.get(0)); - assertEquals(v5, result.get(1)); - assertEquals(v6, result.get(2)); + assertThat(result).hasSize(3); + assertThat(result.get(0)).isEqualTo(v1); + assertThat(result.get(1)).isEqualTo(v5); + assertThat(result.get(2)).isEqualTo(v6); }); } @@ -269,13 +270,13 @@ public void test4Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v1, v6, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(3, result.size()); - assertEquals(v1, result.get(0)); - assertEquals(v5, result.get(1)); - assertEquals(v6, result.get(2)); + assertThat(result).hasSize(3); + assertThat(result.get(0)).isEqualTo(v1); + assertThat(result.get(1)).isEqualTo(v5); + assertThat(result.get(2)).isEqualTo(v6); }); } @@ -294,13 +295,13 @@ public void test5Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v3, v5, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(3, result.size()); - assertEquals(v3, result.get(0)); - assertEquals(v6, result.get(1)); - assertEquals(v5, result.get(2)); + assertThat(result).hasSize(3); + assertThat(result.get(0)).isEqualTo(v3); + assertThat(result.get(1)).isEqualTo(v6); + assertThat(result.get(2)).isEqualTo(v5); }); } @@ -319,16 +320,16 @@ public void test6Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v6, v1, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(6, result.size()); - assertEquals(v6, result.get(0)); - assertEquals(v5, result.get(1)); - assertEquals(v2, result.get(2)); - assertEquals(v3, result.get(3)); - assertEquals(v4, result.get(4)); - assertEquals(v1, result.get(5)); + assertThat(result).hasSize(6); + assertThat(result.get(0)).isEqualTo(v6); + assertThat(result.get(1)).isEqualTo(v5); + assertThat(result.get(2)).isEqualTo(v2); + assertThat(result.get(3)).isEqualTo(v3); + assertThat(result.get(4)).isEqualTo(v4); + assertThat(result.get(5)).isEqualTo(v1); }); } @@ -348,16 +349,16 @@ public void test7Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v6, v1, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(6, result.size()); - assertEquals(v6, result.get(0)); - assertEquals(v5, result.get(1)); - assertEquals(v2, result.get(2)); - assertEquals(v3, result.get(3)); - assertEquals(v4, result.get(4)); - assertEquals(v1, result.get(5)); + assertThat(result).hasSize(6); + assertThat(result.get(0)).isEqualTo(v6); + assertThat(result.get(1)).isEqualTo(v5); + assertThat(result.get(2)).isEqualTo(v2); + assertThat(result.get(3)).isEqualTo(v3); + assertThat(result.get(4)).isEqualTo(v4); + assertThat(result.get(5)).isEqualTo(v1); }); } @@ -378,15 +379,15 @@ public void test8Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v6, v1, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(5, result.size()); - assertEquals(v6, result.get(0)); - assertEquals(v5, result.get(1)); - assertEquals(v2, result.get(2)); - assertEquals(v4, result.get(3)); - assertEquals(v1, result.get(4)); + assertThat(result).hasSize(5); + assertThat(result.get(0)).isEqualTo(v6); + assertThat(result.get(1)).isEqualTo(v5); + assertThat(result.get(2)).isEqualTo(v2); + assertThat(result.get(3)).isEqualTo(v4); + assertThat(result.get(4)).isEqualTo(v1); }); } @@ -407,13 +408,13 @@ public void test9Execute() throws Exception { ctx.setDatabase(graph); final List result = functionAstar.execute(null, null, null, new Object[] { v6, v1, "'weight'", options }, ctx); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(3, result.size()); - assertEquals(v6, result.get(0)); - assertEquals(v5, result.get(1)); - assertEquals(v1, result.get(2)); + assertThat(result).hasSize(3); + assertThat(result.get(0)).isEqualTo(v6); + assertThat(result.get(1)).isEqualTo(v5); + assertThat(result.get(2)).isEqualTo(v1); }); } @@ -429,14 +430,14 @@ public void testSql() throws Exception { final List result = new ArrayList(); result.addAll(r.stream().map(Result::toElement).collect(Collectors.toList())); try (final ResultSet rs = graph.query("sql", "select count(*) as count from has_path")) { - assertEquals((Object) 16L, rs.next().getProperty("count")); + assertThat(rs.next().getProperty("count")).isEqualTo((Object) 16L); } - assertEquals(4, result.size()); - assertEquals(v1.getIdentity(), result.get(0)); - assertEquals(v2.getIdentity(), result.get(1)); - assertEquals(v3.getIdentity(), result.get(2)); - assertEquals(v4.getIdentity(), result.get(3)); + assertThat(result).hasSize(4); + assertThat(result.get(0)).isEqualTo(v1.getIdentity()); + assertThat(result.get(1)).isEqualTo(v2.getIdentity()); + assertThat(result.get(2)).isEqualTo(v3.getIdentity()); + assertThat(result.get(3)).isEqualTo(v4.getIdentity()); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionDijkstraTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionDijkstraTest.java index 8f9b6c5319..3f866608d8 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionDijkstraTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionDijkstraTest.java @@ -29,6 +29,7 @@ import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; public class SQLFunctionDijkstraTest { @@ -80,11 +81,11 @@ public void testExecute() throws Exception { setUp(graph); final List result = functionDijkstra.execute(null, null, null, new Object[] { v1, v4, "'weight'" }, new BasicCommandContext()); - assertEquals(4, result.size()); - assertEquals(v1, result.get(0)); - assertEquals(v2, result.get(1)); - assertEquals(v3, result.get(2)); - assertEquals(v4, result.get(3)); + assertThat(result).hasSize(4); + assertThat(result.get(0)).isEqualTo(v1); + assertThat(result.get(1)).isEqualTo(v2); + assertThat(result.get(2)).isEqualTo(v3); + assertThat(result.get(3)).isEqualTo(v4); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionShortestPathTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionShortestPathTest.java index 173995b8f6..0b0d63e01b 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionShortestPathTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/graph/SQLFunctionShortestPathTest.java @@ -29,6 +29,7 @@ import java.util.*; import static java.util.Arrays.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; public class SQLFunctionShortestPathTest { @@ -43,10 +44,10 @@ public void testExecute() throws Exception { function = new SQLFunctionShortestPath(); final List result = function.execute(null, null, null, new Object[] { vertices.get(1), vertices.get(4) }, new BasicCommandContext()); - assertEquals(3, result.size()); - assertEquals(vertices.get(1).getIdentity(), result.get(0)); - assertEquals(vertices.get(3).getIdentity(), result.get(1)); - assertEquals(vertices.get(4).getIdentity(), result.get(2)); + assertThat(result).hasSize(3); + assertThat(result.get(0)).isEqualTo(vertices.get(1).getIdentity()); + assertThat(result.get(1)).isEqualTo(vertices.get(3).getIdentity()); + assertThat(result.get(2)).isEqualTo(vertices.get(4).getIdentity()); }); } @@ -58,11 +59,11 @@ public void testExecuteOut() throws Exception { final List result = function.execute(null, null, null, new Object[] { vertices.get(1), vertices.get(4), "out", null }, new BasicCommandContext()); - assertEquals(4, result.size()); - assertEquals(vertices.get(1).getIdentity(), result.get(0)); - assertEquals(vertices.get(2).getIdentity(), result.get(1)); - assertEquals(vertices.get(3).getIdentity(), result.get(2)); - assertEquals(vertices.get(4).getIdentity(), result.get(3)); + assertThat(result).hasSize(4); + assertThat(result.get(0)).isEqualTo(vertices.get(1).getIdentity()); + assertThat(result.get(1)).isEqualTo(vertices.get(2).getIdentity()); + assertThat(result.get(2)).isEqualTo(vertices.get(3).getIdentity()); + assertThat(result.get(3)).isEqualTo(vertices.get(4).getIdentity()); }); } @@ -74,11 +75,11 @@ public void testExecuteOnlyEdge1() throws Exception { final List result = function.execute(null, null, null, new Object[] { vertices.get(1), vertices.get(4), null, "Edge1" }, new BasicCommandContext()); - assertEquals(4, result.size()); - assertEquals(vertices.get(1).getIdentity(), result.get(0)); - assertEquals(vertices.get(2).getIdentity(), result.get(1)); - assertEquals(vertices.get(3).getIdentity(), result.get(2)); - assertEquals(vertices.get(4).getIdentity(), result.get(3)); + assertThat(result).hasSize(4); + assertThat(result.get(0)).isEqualTo(vertices.get(1).getIdentity()); + assertThat(result.get(1)).isEqualTo(vertices.get(2).getIdentity()); + assertThat(result.get(2)).isEqualTo(vertices.get(3).getIdentity()); + assertThat(result.get(3)).isEqualTo(vertices.get(4).getIdentity()); }); } @@ -91,10 +92,10 @@ public void testExecuteOnlyEdge1AndEdge2() throws Exception { final List result = function .execute(null, null, null, new Object[] { vertices.get(1), vertices.get(4), "BOTH", asList("Edge1", "Edge2") }, new BasicCommandContext()); - assertEquals(3, result.size()); - assertEquals(vertices.get(1).getIdentity(), result.get(0)); - assertEquals(vertices.get(3).getIdentity(), result.get(1)); - assertEquals(vertices.get(4).getIdentity(), result.get(2)); + assertThat(result).hasSize(3); + assertThat(result.get(0)).isEqualTo(vertices.get(1).getIdentity()); + assertThat(result.get(1)).isEqualTo(vertices.get(3).getIdentity()); + assertThat(result.get(2)).isEqualTo(vertices.get(4).getIdentity()); }); } @@ -106,12 +107,12 @@ public void testLong() throws Exception { final List result = function.execute(null, null, null, new Object[] { vertices.get(1), vertices.get(20) }, new BasicCommandContext()); - assertEquals(11, result.size()); - assertEquals(vertices.get(1).getIdentity(), result.get(0)); - assertEquals(vertices.get(3).getIdentity(), result.get(1)); + assertThat(result).hasSize(11); + assertThat(result.get(0)).isEqualTo(vertices.get(1).getIdentity()); + assertThat(result.get(1)).isEqualTo(vertices.get(3).getIdentity()); int next = 2; for (int i = 4; i <= 20; i += 2) { - assertEquals(vertices.get(i).getIdentity(), result.get(next++)); + assertThat(result.get(next++)).isEqualTo(vertices.get(i).getIdentity()); } }); } @@ -127,7 +128,7 @@ public void testMaxDepth1() throws Exception { final List result = function .execute(null, null, null, new Object[] { vertices.get(1), vertices.get(20), null, null, additionalParams }, new BasicCommandContext()); - assertEquals(11, result.size()); + assertThat(result).hasSize(11); }); } @@ -142,7 +143,7 @@ public void testMaxDepth2() throws Exception { final List result = function .execute(null, null, null, new Object[] { vertices.get(1), vertices.get(20), null, null, additionalParams }, new BasicCommandContext()); - assertEquals(11, result.size()); + assertThat(result).hasSize(11); }); } @@ -157,7 +158,7 @@ public void testMaxDepth3() throws Exception { final List result = function .execute(null, null, null, new Object[] { vertices.get(1), vertices.get(20), null, null, additionalParams }, new BasicCommandContext()); - assertEquals(0, result.size()); + assertThat(result).isEmpty(); }); } @@ -172,7 +173,7 @@ public void testMaxDepth4() throws Exception { final List result = function .execute(null, null, null, new Object[] { vertices.get(1), vertices.get(20), null, null, additionalParams }, new BasicCommandContext()); - assertEquals(0, result.size()); + assertThat(result).isEmpty(); }); } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionAbsoluteValueTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionAbsoluteValueTest.java index 9bfe2656f0..c57d6ddd49 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionAbsoluteValueTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionAbsoluteValueTest.java @@ -21,15 +21,15 @@ import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.query.sql.function.math.SQLFunctionAbsoluteValue; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.math.*; +import java.math.BigDecimal; +import java.math.BigInteger; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests the absolute value function. The key is that the mathematical abs function is correctly @@ -49,133 +49,133 @@ public void setup() { @Test public void testEmpty() { final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testNull() { function.execute(null, null, null, new Object[]{null}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveInteger() { function.execute(null, null, null, new Object[]{10}, null); final Object result = function.getResult(); - assertTrue(result instanceof Integer); - assertEquals(result, 10); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(10); } @Test public void testNegativeInteger() { function.execute(null, null, null, new Object[]{-10}, null); final Object result = function.getResult(); - assertTrue(result instanceof Integer); - assertEquals(result, 10); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(10); } @Test public void testPositiveLong() { function.execute(null, null, null, new Object[]{10L}, null); final Object result = function.getResult(); - assertTrue(result instanceof Long); - assertEquals(result, 10L); + assertThat(result instanceof Long).isTrue(); + assertThat(result).isEqualTo(10L); } @Test public void testNegativeLong() { function.execute(null, null, null, new Object[]{-10L}, null); final Object result = function.getResult(); - assertTrue(result instanceof Long); - assertEquals(result, 10L); + assertThat(result instanceof Long).isTrue(); + assertThat(result).isEqualTo(10L); } @Test public void testPositiveShort() { function.execute(null, null, null, new Object[]{(short) 10}, null); final Object result = function.getResult(); - assertTrue(result instanceof Short); - assertEquals(result, (short) 10); + assertThat(result instanceof Short).isTrue(); + assertThat((short) 10).isEqualTo(result); } @Test public void testNegativeShort() { function.execute(null, null, null, new Object[]{(short) -10}, null); final Object result = function.getResult(); - assertTrue(result instanceof Short); - assertEquals(result, (short) 10); + assertThat(result instanceof Short).isTrue(); + assertThat((short) 10).isEqualTo(result); } @Test public void testPositiveDouble() { function.execute(null, null, null, new Object[]{10.5D}, null); final Object result = function.getResult(); - assertTrue(result instanceof Double); - assertEquals(result, 10.5D); + assertThat(result instanceof Double).isTrue(); + assertThat(result).isEqualTo(10.5D); } @Test public void testNegativeDouble() { function.execute(null, null, null, new Object[]{-10.5D}, null); final Object result = function.getResult(); - assertTrue(result instanceof Double); - assertEquals(result, 10.5D); + assertThat(result instanceof Double).isTrue(); + assertThat(result).isEqualTo(10.5D); } @Test public void testPositiveFloat() { function.execute(null, null, null, new Object[]{10.5F}, null); final Object result = function.getResult(); - assertTrue(result instanceof Float); - assertEquals(result, 10.5F); + assertThat(result instanceof Float).isTrue(); + assertThat(result).isEqualTo(10.5F); } @Test public void testNegativeFloat() { function.execute(null, null, null, new Object[]{-10.5F}, null); final Object result = function.getResult(); - assertTrue(result instanceof Float); - assertEquals(result, 10.5F); + assertThat(result instanceof Float).isTrue(); + assertThat(result).isEqualTo(10.5F); } @Test public void testPositiveBigDecimal() { function.execute(null, null, null, new Object[]{new BigDecimal("10.5")}, null); final Object result = function.getResult(); - assertTrue(result instanceof BigDecimal); - assertEquals(result, new BigDecimal("10.5")); + assertThat(result instanceof BigDecimal).isTrue(); + assertThat(new BigDecimal("10.5")).isEqualTo(result); } @Test public void testNegativeBigDecimal() { function.execute(null, null, null, new Object[]{BigDecimal.valueOf(-10.5D)}, null); final Object result = function.getResult(); - assertTrue(result instanceof BigDecimal); - assertEquals(result, new BigDecimal("10.5")); + assertThat(result instanceof BigDecimal).isTrue(); + assertThat(new BigDecimal("10.5")).isEqualTo(result); } @Test public void testPositiveBigInteger() { function.execute(null, null, null, new Object[]{new BigInteger("10")}, null); final Object result = function.getResult(); - assertTrue(result instanceof BigInteger); - assertEquals(result, new BigInteger("10")); + assertThat(result instanceof BigInteger).isTrue(); + assertThat(new BigInteger("10")).isEqualTo(result); } @Test public void testNegativeBigInteger() { function.execute(null, null, null, new Object[]{new BigInteger("-10")}, null); final Object result = function.getResult(); - assertTrue(result instanceof BigInteger); - assertEquals(result, new BigInteger("10")); + assertThat(result instanceof BigInteger).isTrue(); + assertThat(new BigInteger("10")).isEqualTo(result); } @Test public void testNonNumber() { try { function.execute(null, null, null, new Object[]{"abc"}, null); - Assertions.fail("Expected IllegalArgumentException"); + fail("Expected IllegalArgumentException"); } catch (final IllegalArgumentException e) { // OK } @@ -185,7 +185,7 @@ public void testNonNumber() { public void testFromQuery() throws Exception { TestHelper.executeInNewDatabase("./target/databases/testAbsFunction", (db) -> { final ResultSet result = db.query("sql", "select abs(-45.4) as abs"); - assertEquals(45.4F, ((Number) result.next().getProperty("abs")).floatValue()); + assertThat(((Number) result.next().getProperty("abs")).floatValue()).isEqualTo(45.4F); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionModeTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionModeTest.java index 92f697e1c5..7408c22f8c 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionModeTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionModeTest.java @@ -24,9 +24,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class SQLFunctionModeTest { @@ -40,7 +38,7 @@ public void setup() { @Test public void testEmpty() { final Object result = mode.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test @@ -52,7 +50,7 @@ public void testSingleMode() { } final Object result = mode.getResult(); - assertEquals(3, (int) ((List) result).get(0)); + assertThat((int) ((List) result).get(0)).isEqualTo(3); } @Test @@ -65,9 +63,9 @@ public void testMultiMode() { final Object result = mode.getResult(); final List modes = (List) result; - assertEquals(2, modes.size()); - assertTrue(modes.contains(2)); - assertTrue(modes.contains(3)); + assertThat(modes.size()).isEqualTo(2); + assertThat(modes.contains(2)).isTrue(); + assertThat(modes.contains(3)).isTrue(); } @Test @@ -81,6 +79,6 @@ public void testMultiValue() { } final Object result = mode.getResult(); - assertEquals(1, (int) ((List) result).get(0)); + assertThat((int) ((List) result).get(0)).isEqualTo(1); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionPercentileTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionPercentileTest.java index b4374eedd9..d883a02dbe 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionPercentileTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionPercentileTest.java @@ -24,8 +24,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; public class SQLFunctionPercentileTest { @@ -41,19 +40,19 @@ public void beforeMethod() { @Test public void testEmpty() { final Object result = percentile.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testSingleValueLower() { percentile.execute(null, null, null, new Object[] {10, .25}, null); - assertEquals(10, percentile.getResult()); + assertThat(percentile.getResult()).isEqualTo(10); } @Test public void testSingleValueUpper() { percentile.execute(null, null, null, new Object[] {10, .75}, null); - assertEquals(10, percentile.getResult()); + assertThat(percentile.getResult()).isEqualTo(10); } @Test @@ -65,7 +64,7 @@ public void test50thPercentileOdd() { } final Object result = percentile.getResult(); - assertEquals(3.0, result); + assertThat(result).isEqualTo(3.0); } @Test @@ -77,7 +76,7 @@ public void test50thPercentileOddWithNulls() { } final Object result = percentile.getResult(); - assertEquals(3.0, result); + assertThat(result).isEqualTo(3.0); } @Test @@ -89,7 +88,7 @@ public void test50thPercentileEven() { } final Object result = percentile.getResult(); - assertEquals(3.0, result); + assertThat(result).isEqualTo(3.0); } @Test @@ -101,7 +100,7 @@ public void testFirstQuartile() { } final Object result = percentile.getResult(); - assertEquals(1.5, result); + assertThat(result).isEqualTo(1.5); } @Test @@ -113,7 +112,7 @@ public void testThirdQuartile() { } final Object result = percentile.getResult(); - assertEquals(4.5, result); + assertThat(result).isEqualTo(4.5); } @Test @@ -125,7 +124,7 @@ public void testMultiQuartile() { } final List result = (List) percentile.getResult(); - assertEquals(1.5, result.get(0).doubleValue(), 0); - assertEquals(4.5, result.get(1).doubleValue(), 0); + assertThat(result.get(0).doubleValue()).isEqualTo(1.5); + assertThat(result.get(1).doubleValue()).isEqualTo(4.5); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionRandomIntTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionRandomIntTest.java index 41ea4acbd7..10f734f0a5 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionRandomIntTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionRandomIntTest.java @@ -19,13 +19,16 @@ package com.arcadedb.query.sql.functions.math; import com.arcadedb.TestHelper; +import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.query.sql.function.math.SQLFunctionRandomInt; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Luca Garulli (l.garulli@arcadedata.com) @@ -41,27 +44,27 @@ public void setup() { @Test public void testEmpty() { final Object result = random.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testResultWithIntParameter() { final Integer result = (Integer) random.execute(null, null, null, new Integer[] { 1000 }, null); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test public void testResultWithStringParameter() { final Integer result = (Integer) random.execute(null, null, null, new Object[] { "1000" }, null); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test public void testQuery() throws Exception { TestHelper.executeInNewDatabase("SQLFunctionRandomInt", (db) -> { final ResultSet result = db.query("sql", "select randomInt(1000) as random"); - assertNotNull(result); - assertNotNull(result.next().getProperty("random")); + assertThat((Iterator) result).isNotNull(); + assertThat(result.next().getProperty("random")).isNotNull(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java index 2019098c66..223c34b75d 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java @@ -21,15 +21,15 @@ import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.query.sql.function.math.SQLFunctionSquareRoot; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.math.*; +import java.math.BigDecimal; +import java.math.BigInteger; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; public class SQLFunctionSquareRootTest { @@ -43,126 +43,126 @@ public void setup() { @Test public void testEmpty() { final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testNull() { function.execute(null, null, null, new Object[]{null}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveInteger() { function.execute(null, null, null, new Object[]{4}, null); final Object result = function.getResult(); - assertTrue(result instanceof Integer); - assertEquals(result, 2); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(2); } @Test public void testNegativeInteger() { function.execute(null, null, null, new Object[]{-4}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveLong() { function.execute(null, null, null, new Object[]{4L}, null); final Object result = function.getResult(); - assertTrue(result instanceof Long); - assertEquals(result, 2L); + assertThat(result instanceof Long).isTrue(); + assertThat(result).isEqualTo(2L); } @Test public void testNegativeLong() { function.execute(null, null, null, new Object[]{-4L}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveShort() { function.execute(null, null, null, new Object[]{(short) 4}, null); final Object result = function.getResult(); - assertTrue(result instanceof Short); - assertEquals(result, (short) 2); + assertThat(result instanceof Short).isTrue(); + assertThat((short) 2).isEqualTo(result); } @Test public void testNegativeShort() { function.execute(null, null, null, new Object[]{(short) -4}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveDouble() { function.execute(null, null, null, new Object[]{4.0D}, null); final Object result = function.getResult(); - assertTrue(result instanceof Double); - assertEquals(result, 2.0D); + assertThat(result instanceof Double).isTrue(); + assertThat(result).isEqualTo(2.0D); } @Test public void testNegativeDouble() { function.execute(null, null, null, new Object[]{-4.0D}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveFloat() { function.execute(null, null, null, new Object[]{4.0F}, null); final Object result = function.getResult(); - assertTrue(result instanceof Float); - assertEquals(result, 2.0F); + assertThat(result instanceof Float).isTrue(); + assertThat(result).isEqualTo(2.0F); } @Test public void testNegativeFloat() { function.execute(null, null, null, new Object[]{-4.0F}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveBigDecimal() { function.execute(null, null, null, new Object[]{new BigDecimal("4.0")}, null); final Object result = function.getResult(); - assertTrue(result instanceof BigDecimal); - assertEquals(result, new BigDecimal("2")); + assertThat(result instanceof BigDecimal).isTrue(); + assertThat(new BigDecimal("2")).isEqualTo(result); } @Test public void testNegativeBigDecimal() { function.execute(null, null, null, new Object[]{BigDecimal.valueOf(-4.0D)}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testPositiveBigInteger() { function.execute(null, null, null, new Object[]{new BigInteger("4")}, null); final Object result = function.getResult(); - assertTrue(result instanceof BigInteger); - assertEquals(result, new BigInteger("2")); + assertThat(result instanceof BigInteger).isTrue(); + assertThat(new BigInteger("2")).isEqualTo(result); } @Test public void testNegativeBigInteger() { function.execute(null, null, null, new Object[]{new BigInteger("-4")}, null); final Object result = function.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testNonNumber() { try { function.execute(null, null, null, new Object[]{"abc"}, null); - Assertions.fail("Expected IllegalArgumentException"); + fail("Expected IllegalArgumentException"); } catch (final IllegalArgumentException e) { // OK } @@ -172,7 +172,7 @@ public void testNonNumber() { public void testFromQuery() throws Exception { TestHelper.executeInNewDatabase("./target/databases/testSqrtFunction", (db) -> { final ResultSet result = db.query("sql", "select sqrt(4.0) as sqrt"); - assertEquals(2.0F, ((Number) result.next().getProperty("sqrt")).floatValue()); + assertThat(((Number) result.next().getProperty("sqrt")).floatValue()).isEqualTo(2.0F); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionVarianceTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionVarianceTest.java index 5837128dc4..f3f268dcf8 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionVarianceTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionVarianceTest.java @@ -19,11 +19,10 @@ package com.arcadedb.query.sql.functions.math; import com.arcadedb.query.sql.function.math.SQLFunctionVariance; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; public class SQLFunctionVarianceTest { @@ -37,7 +36,7 @@ public void setup() { @Test public void testEmpty() { final Object result = variance.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test @@ -49,7 +48,7 @@ public void testVariance() { } final Object result = variance.getResult(); - Assertions.assertEquals(22.1875, result); + assertThat(result).isEqualTo(22.1875); } @Test @@ -61,7 +60,7 @@ public void testVariance1() { } final Object result = variance.getResult(); - Assertions.assertEquals(2.25, result); + assertThat(result).isEqualTo(2.25); } @Test @@ -73,6 +72,6 @@ public void testVariance2() { } final Object result = variance.getResult(); - Assertions.assertEquals(36.0, result); + assertThat(result).isEqualTo(36.0); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/FunctionTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/FunctionTest.java index dbe64271d2..433df8c9fb 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/FunctionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/FunctionTest.java @@ -23,12 +23,16 @@ import com.arcadedb.query.sql.SQLQueryEngine; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + public class FunctionTest extends TestHelper { private static final int TOT = 10000; @@ -59,12 +63,12 @@ public void testCountFunction() { final AtomicInteger counter = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertFalse(record.getIdentity().isPresent()); - Assertions.assertEquals(10, ((Number) record.getProperty("count")).intValue()); + assertThat(record).isNotNull(); + assertThat(record.getIdentity().isPresent()).isFalse(); + assertThat(((Number) record.getProperty("count")).intValue()).isEqualTo(10); counter.incrementAndGet(); } - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } @@ -73,17 +77,17 @@ public void testIfEvalFunction() { database.transaction(() -> { final ResultSet rs = database.command("SQL", "SELECT id, if( eval( 'id > 3' ), 'high', 'low') as value FROM V"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertFalse(record.getIdentity().isPresent()); + assertThat(record).isNotNull(); + assertThat(record.getIdentity().isPresent()).isFalse(); final Object value = record.getProperty("value"); if ((Integer) record.getProperty("id") > 3) - Assertions.assertEquals("high", value); + assertThat(value).isEqualTo("high"); else - Assertions.assertEquals("low", value); + assertThat(value).isEqualTo("low"); } }); } @@ -93,17 +97,17 @@ public void testIfFunction() { database.transaction(() -> { final ResultSet rs = database.command("SQL", "SELECT id, if( ( id > 3 ), 'high', 'low') as value FROM V"); - Assertions.assertTrue(rs.hasNext()); + assertThat(rs.hasNext()).isTrue(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertFalse(record.getIdentity().isPresent()); + assertThat(record).isNotNull(); + assertThat(record.getIdentity().isPresent()).isFalse(); final Object value = record.getProperty("value"); if ((Integer) record.getProperty("id") > 3) - Assertions.assertEquals("high", value); + assertThat(value).isEqualTo("high"); else - Assertions.assertEquals("low", value); + assertThat(value).isEqualTo("low"); } }); } @@ -118,12 +122,12 @@ public void testAvgFunction() { final AtomicInteger counter = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertFalse(record.getIdentity().isPresent()); - Assertions.assertEquals(4, ((Number) record.getProperty("avg")).intValue()); + assertThat(record).isNotNull(); + assertThat(record.getIdentity().isPresent()).isFalse(); + assertThat(((Number) record.getProperty("avg")).intValue()).isEqualTo(4); counter.incrementAndGet(); } - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } @@ -136,12 +140,12 @@ public void testMaxFunction() { final AtomicInteger counter = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertFalse(record.getIdentity().isPresent()); - Assertions.assertEquals(TOT - 1, ((Number) record.getProperty("max")).intValue()); + assertThat(record).isNotNull(); + assertThat(record.getIdentity().isPresent()).isFalse(); + assertThat(((Number) record.getProperty("max")).intValue()).isEqualTo(TOT - 1); counter.incrementAndGet(); } - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } @@ -154,12 +158,12 @@ public void testMinFunction() { final AtomicInteger counter = new AtomicInteger(); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertFalse(record.getIdentity().isPresent()); - Assertions.assertEquals(0, ((Number) record.getProperty("min")).intValue()); + assertThat(record).isNotNull(); + assertThat(record.getIdentity().isPresent()).isFalse(); + assertThat(((Number) record.getProperty("min")).intValue()).isEqualTo(0); counter.incrementAndGet(); } - Assertions.assertEquals(1, counter.get()); + assertThat(counter.get()).isEqualTo(1); }); } @@ -167,8 +171,8 @@ public void testMinFunction() { public void testAllFunctionsHaveSyntax() { final SQLQueryEngine sqlEngine = (SQLQueryEngine) database.getQueryEngine("sql"); for (final String name : sqlEngine.getFunctionFactory().getFunctionNames()) { - Assertions.assertNotNull(sqlEngine.getFunction(name).getName()); - Assertions.assertNotNull(sqlEngine.getFunction(name).getSyntax()); + assertThat(sqlEngine.getFunction(name).getName()).isNotNull(); + assertThat(sqlEngine.getFunction(name).getSyntax()).isNotNull(); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolAndTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolAndTest.java index bbd883747e..93b9db944b 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolAndTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolAndTest.java @@ -20,9 +20,12 @@ import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -35,8 +38,8 @@ public void testBoolAnd_SingleNull() { database.command("sql", "create property doc0.bool boolean;"); database.command("sql", "insert into doc0 set bool = null;"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc0;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isTrue(); }); } @@ -47,8 +50,8 @@ public void testBoolAnd_SingleTrue() { database.command("sql", "create property doc1.bool boolean;"); database.command("sql", "insert into doc1 set bool = true;"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc1;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isTrue(); }); } @@ -59,8 +62,8 @@ public void testBoolAnd_SingleFalse() { database.command("sql", "create property doc2.bool boolean;"); database.command("sql", "insert into doc2 set bool = false;"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc2;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isFalse(); }); } @@ -71,8 +74,8 @@ public void testBoolAnd_MultiNull() { database.command("sql", "create property doc3.bool boolean;"); database.command("sql", "insert into doc3 (bool) values (null), (null), (null);"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc3;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isTrue(); }); } @@ -83,8 +86,8 @@ public void testBoolAnd_MultiTrue() { database.command("sql", "create property doc4.bool boolean;"); database.command("sql", "insert into doc4 (bool) values (true), (true), (true);"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc4;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isTrue(); }); } @@ -95,8 +98,8 @@ public void testBoolAnd_MultiFalse() { database.command("sql", "create property doc5.bool boolean;"); database.command("sql", "insert into doc5 (bool) values (true), (true), (false);"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc5;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isFalse(); }); } @@ -107,8 +110,8 @@ public void testBoolAnd_MultiTrueHasNull() { database.command("sql", "create property doc6.bool boolean;"); database.command("sql", "insert into doc6 (bool) values (true), (null), (true);"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc6;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isTrue(); }); } @@ -119,8 +122,8 @@ public void testBoolAnd_MultiFalseHasNull() { database.command("sql", "create property doc7.bool boolean;"); database.command("sql", "insert into doc7 (bool) values (true), (null), (false);"); ResultSet result = database.query("sql", "select bool_and(bool) as bool_and from doc7;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isFalse(); }); } @@ -131,8 +134,8 @@ public void testBoolAnd_MultiNullIsNull() { database.command("sql", "create property doc8.bool boolean;"); database.command("sql", "insert into doc8 (bool) values (null), (null), (null);"); ResultSet result = database.query("sql", "select bool_and((bool is null)) as bool_and from doc8;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isTrue(); }); } @@ -143,8 +146,8 @@ public void testBoolAnd_MultiHasNull() { database.command("sql", "create property doc9.bool boolean;"); database.command("sql", "insert into doc9 (bool) values (true), (null), (false);"); ResultSet result = database.query("sql", "select bool_and((bool is not null)) as bool_and from doc9;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_and")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_and")).isFalse(); }); } @@ -152,28 +155,28 @@ public void testBoolAnd_MultiHasNull() { public void testBoolAndNull() { database.transaction(() -> { ResultSet result = database.query("sql", "SELECT (true AND null) as result"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNull(result.next().getProperty("result")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("result")).isNull(); result = database.query("sql", "SELECT (false AND null) as result"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean)result.next().getProperty("result")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean)result.next().getProperty("result")).isFalse(); result = database.query("sql", "SELECT (null AND null) as result"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNull(result.next().getProperty("result")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("result")).isNull(); result = database.query("sql", "SELECT (true OR null) as result"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean)result.next().getProperty("result")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean)result.next().getProperty("result")).isTrue(); result = database.query("sql", "SELECT (false OR null) as result"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNull(result.next().getProperty("result")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("result")).isNull(); result = database.query("sql", "SELECT (null OR null) as result"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertNull(result.next().getProperty("result")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("result")).isNull(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolOrTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolOrTest.java index f173650655..c3b39160e6 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolOrTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionBoolOrTest.java @@ -20,9 +20,12 @@ import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -35,8 +38,8 @@ public void testBoolOr_SingleNull() { database.command("sql", "create property doc0.bool boolean;"); database.command("sql", "insert into doc0 set bool = null;"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc0;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isFalse(); }); } @@ -47,8 +50,8 @@ public void testBoolOr_SingleTrue() { database.command("sql", "create property doc1.bool boolean;"); database.command("sql", "insert into doc1 set bool = true;"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc1;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isTrue(); }); } @@ -59,8 +62,8 @@ public void testBoolOr_SingleFalse() { database.command("sql", "create property doc2.bool boolean;"); database.command("sql", "insert into doc2 set bool = false;"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc2;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isFalse(); }); } @@ -71,8 +74,8 @@ public void testBoolOr_MultiNull() { database.command("sql", "create property doc3.bool boolean;"); database.command("sql", "insert into doc3 (bool) values (null), (null), (null);"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc3;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isFalse(); }); } @@ -83,8 +86,8 @@ public void testBoolOr_MultiTrue() { database.command("sql", "create property doc4.bool boolean;"); database.command("sql", "insert into doc4 (bool) values (false), (false), (true);"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc4;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isTrue(); }); } @@ -95,8 +98,8 @@ public void testBoolOr_MultiFalse() { database.command("sql", "create property doc5.bool boolean;"); database.command("sql", "insert into doc5 (bool) values (false), (false), (false);"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc5;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isFalse(); }); } @@ -107,8 +110,8 @@ public void testBoolOr_MultiTrueHasNull() { database.command("sql", "create property doc6.bool boolean;"); database.command("sql", "insert into doc6 (bool) values (false), (null), (true);"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc6;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isTrue(); }); } @@ -119,8 +122,8 @@ public void testBoolOr_MultiFalseHasNull() { database.command("sql", "create property doc7.bool boolean;"); database.command("sql", "insert into doc7 (bool) values (false), (null), (false);"); ResultSet result = database.query("sql","select bool_or(bool) as bool_or from doc7;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isFalse(); }); } @@ -131,8 +134,8 @@ public void testBoolOr_MultiNullIsNull() { database.command("sql", "create property doc8.bool boolean;"); database.command("sql", "insert into doc8 (bool) values (null), (null), (null);"); ResultSet result = database.query("sql","select bool_or((bool is not null)) as bool_or from doc8;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertFalse((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isFalse(); }); } @@ -143,8 +146,8 @@ public void testBoolOr_MultiHasNull() { database.command("sql", "create property doc9.bool boolean;"); database.command("sql", "insert into doc9 (bool) values (true), (null), (false);"); ResultSet result = database.query("sql","select bool_or((bool is null)) as bool_or from doc9;"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue((Boolean) result.next().getProperty("bool_or")); + assertThat(result.hasNext()).isTrue(); + assertThat((Boolean) result.next().getProperty("bool_or")).isTrue(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionCoalesceTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionCoalesceTest.java index 45e84c6450..8ca3720692 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionCoalesceTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionCoalesceTest.java @@ -20,11 +20,14 @@ import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -36,19 +39,19 @@ public void testBoolAnd_SingleNull() { database.command("sql", "CREATE DOCUMENT TYPE doc"); database.command("sql", "INSERT INTO doc (num) VALUES (1),(3),(5),(2),(4)"); - Assertions.assertEquals(5, database.countType("doc", true)); + assertThat(database.countType("doc", true)).isEqualTo(5); ResultSet result = database.query("sql", "SELECT coalesce((SELECT num FROM doc)) as coal"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); List coal = result.next().getProperty("coal"); - Assertions.assertEquals(5, coal.size()); + assertThat(coal).hasSize(5); result = database.query("sql", "SELECT coalesce((SELECT num FROM doc ORDER BY num)) as coal"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); coal = result.next().getProperty("coal"); - Assertions.assertEquals(5, coal.size()); + assertThat(coal).hasSize(5); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionConvertTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionConvertTest.java index 3013b3931f..52b5878060 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionConvertTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionConvertTest.java @@ -21,12 +21,14 @@ import com.arcadedb.GlobalConfiguration; import com.arcadedb.TestHelper; import com.arcadedb.database.Document; +import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import org.junit.jupiter.api.Test; import java.math.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -52,80 +54,80 @@ public void testSQLConversions() throws Exception { db.command("sql", "update TestConversion set selfrid = 'foo" + doc.getIdentity() + "'"); ResultSet results = db.query("sql", "select string.asString() as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); Object convert = results.next().getProperty("convert"); - assertTrue(convert instanceof String, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof String).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.asDate() as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Date, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Date).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select dateAsString.asDate(\"yyyy-MM-dd'T'HH:mm:ss.SSS\") as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Date, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Date).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.asDateTime() as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Date, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Date).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select dateAsString.asDateTime(\"yyyy-MM-dd'T'HH:mm:ss.SSS\") as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Date, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Date).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.asInteger() as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Integer, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Integer).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.asLong() as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Long, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Long).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.asFloat() as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Float, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Float).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.asDecimal() as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof BigDecimal, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof BigDecimal).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select \"100000.123\".asDecimal()*1000 as convert"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof BigDecimal, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof BigDecimal).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.convert('LONG') as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Long, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Long).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.convert('SHORT') as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Short, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Short).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select number.convert('DOUBLE') as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertTrue(convert instanceof Double, "Found " + convert.getClass() + " instead"); + assertThat(convert instanceof Double).as("Found " + convert.getClass() + " instead").isTrue(); results = db.query("sql", "select selfrid.substring(3).convert('LINK').string as convert from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("convert"); - assertEquals(convert, "Jay"); + assertThat(convert).isEqualTo("Jay"); results = db.query("sql", "select list.transform('toLowerCase') as list from TestConversion"); - assertNotNull(results); + assertThat((Iterator) results).isNotNull(); convert = results.next().getProperty("list"); final List list = (List) convert; - assertTrue(list.containsAll(List.of("a", "b"))); + assertThat(list.containsAll(List.of("a", "b"))).isTrue(); })); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionEncodeDecodeTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionEncodeDecodeTest.java index 50f40d818c..23b4ab902d 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionEncodeDecodeTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionEncodeDecodeTest.java @@ -19,15 +19,18 @@ package com.arcadedb.query.sql.functions.misc; import com.arcadedb.TestHelper; +import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.query.sql.function.misc.SQLFunctionDecode; import com.arcadedb.query.sql.function.misc.SQLFunctionEncode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; public class SQLFunctionEncodeDecodeTest { @@ -43,22 +46,22 @@ public void setup() { @Test public void testEmpty() { final Object result = encode.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testResult() { final String result = (String) encode.execute(null, null, null, new Object[] { "abc123", "base64" }, null); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test public void testQuery() throws Exception { TestHelper.executeInNewDatabase("SQLFunctionEncodeTest", (db) -> { final ResultSet result = db.query("sql", "select decode( encode('abc123', 'base64'), 'base64' ).asString() as encode"); - assertNotNull(result); + assertThat((Iterator) result).isNotNull(); final Object prop = result.next().getProperty("encode"); - assertEquals("abc123", prop); + assertThat(prop).isEqualTo("abc123"); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionUUIDTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionUUIDTest.java index ab1511105f..156fa40f78 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionUUIDTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/misc/SQLFunctionUUIDTest.java @@ -19,13 +19,16 @@ package com.arcadedb.query.sql.functions.misc; import com.arcadedb.TestHelper; +import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.query.sql.function.misc.SQLFunctionUUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; public class SQLFunctionUUIDTest { @@ -39,21 +42,21 @@ public void setup() { @Test public void testEmpty() { final Object result = uuid.getResult(); - assertNull(result); + assertThat(result).isNull(); } @Test public void testResult() { final String result = (String) uuid.execute(null, null, null, null, null); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test public void testQuery() throws Exception { TestHelper.executeInNewDatabase("SQLFunctionUUIDTest", (db) -> { final ResultSet result = db.query("sql", "select uuid() as uuid"); - assertNotNull(result); - assertNotNull(result.next().getProperty("uuid")); + assertThat((Iterator) result).isNotNull(); + assertThat(result.next().getProperty("uuid")).isNotNull(); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/sql/CustomSQLFunctionsTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/sql/CustomSQLFunctionsTest.java index aea5e16442..b009ab97eb 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/sql/CustomSQLFunctionsTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/sql/CustomSQLFunctionsTest.java @@ -21,10 +21,13 @@ import com.arcadedb.TestHelper; import com.arcadedb.exception.CommandParsingException; import com.arcadedb.query.sql.executor.ResultSet; +import org.assertj.core.data.Offset; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.assertj.core.api.AssertionsForClassTypes.within; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; public class CustomSQLFunctionsTest { @@ -32,7 +35,7 @@ public class CustomSQLFunctionsTest { public void testRandom() throws Exception { TestHelper.executeInNewDatabase("testRandom", (db) -> { final ResultSet result = db.query("sql", "select math_random() as random"); - assertTrue((Double) result.next().getProperty("random") > 0); + assertThat(result.next().getProperty("random")).isGreaterThan(0); }); } @@ -40,7 +43,7 @@ public void testRandom() throws Exception { public void testLog10() throws Exception { TestHelper.executeInNewDatabase("testRandom", (db) -> { final ResultSet result = db.query("sql", "select math_log10(10000) as log10"); - assertEquals(result.next().getProperty("log10"), 4.0, 0.0001); + assertThat(result.next().getProperty("log10")).isCloseTo(4.0, within(0.0001)); }); } @@ -48,7 +51,7 @@ public void testLog10() throws Exception { public void testAbsInt() throws Exception { TestHelper.executeInNewDatabase("testRandom", (db) -> { final ResultSet result = db.query("sql", "select math_abs(-5) as abs"); - assertTrue((Integer) result.next().getProperty("abs") == 5); + assertThat(result.next().getProperty("abs")).isEqualTo(5); }); } @@ -56,7 +59,7 @@ public void testAbsInt() throws Exception { public void testAbsDouble() throws Exception { TestHelper.executeInNewDatabase("testRandom", (db) -> { final ResultSet result = db.query("sql", "select math_abs(-5.0d) as abs"); - assertTrue((Double) result.next().getProperty("abs") == 5.0); + assertThat(result.next().getProperty("abs")).isEqualTo(5.0); }); } @@ -64,15 +67,16 @@ public void testAbsDouble() throws Exception { public void testAbsFloat() throws Exception { TestHelper.executeInNewDatabase("testRandom", (db) -> { final ResultSet result = db.query("sql", "select math_abs(-5.0f) as abs"); - assertTrue((Float) result.next().getProperty("abs") == 5.0); + assertThat(result.next().getProperty("abs")).isEqualTo(5.0f); }); } @Test public void testNonExistingFunction() { - assertThrows(CommandParsingException.class, () -> TestHelper.executeInNewDatabase("testRandom", (db) -> { - final ResultSet result = db.query("sql", "select math_min('boom', 'boom') as boom"); - result.next(); - })); + assertThatExceptionOfType(CommandParsingException.class).isThrownBy( + () -> TestHelper.executeInNewDatabase("testRandom", (db) -> { + final ResultSet result = db.query("sql", "select math_min('boom', 'boom') as boom"); + result.next(); + })); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/sql/SQLFunctionsTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/sql/SQLFunctionsTest.java index 0a9d953b80..e7223ce0f9 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/sql/SQLFunctionsTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/sql/SQLFunctionsTest.java @@ -36,8 +36,9 @@ import com.arcadedb.schema.Type; import com.arcadedb.utility.CollectionUtils; import com.arcadedb.utility.FileUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,8 +46,12 @@ import java.security.*; import java.text.*; import java.util.*; +import java.util.stream.Collectors; import static com.arcadedb.TestHelper.checkActiveDatabases; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class SQLFunctionsTest { private final DatabaseFactory factory = new DatabaseFactory("./target/databases/SQLFunctionsTest"); @@ -55,65 +60,65 @@ public class SQLFunctionsTest { @Test public void queryMax() { final ResultSet result = database.command("sql", "select max(id) as max from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("max")); + assertThat(d.getProperty("max")).isNotNull(); } } @Test public void queryMaxInline() { final ResultSet result = database.command("sql", "select max(1,2,7,0,-2,3) as max"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("max")); + assertThat(d.getProperty("max")).isNotNull(); - Assertions.assertEquals(((Number) d.getProperty("max")).intValue(), 7); + assertThat(((Number) d.getProperty("max")).intValue()).isEqualTo(7); } } @Test public void queryMin() { final ResultSet result = database.command("sql", "select min(id) as min from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("min")); - Assertions.assertEquals(((Number) d.getProperty("min")).longValue(), 0l); + assertThat(d.getProperty("min")).isNotNull(); + assertThat(((Number) d.getProperty("min")).longValue()).isEqualTo(0l); } } @Test public void queryMinInline() { final ResultSet result = database.command("sql", "select min(1,2,7,0,-2,3) as min"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("min")); - Assertions.assertEquals(((Number) d.getProperty("min")).intValue(), -2); + assertThat(d.getProperty("min")).isNotNull(); + assertThat(((Number) d.getProperty("min")).intValue()).isEqualTo(-2); } } @Test public void querySum() { final ResultSet result = database.command("sql", "select sum(id) as sum from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("sum")); + assertThat(d.getProperty("sum")).isNotNull(); } } @Test public void queryCount() { final ResultSet result = database.command("sql", "select count(*) as total from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("total")); - Assertions.assertTrue(((Number) d.getProperty("total")).longValue() > 0); + assertThat(d.getProperty("total")).isNotNull(); + assertThat(((Number) d.getProperty("total")).longValue() > 0).isTrue(); } } @@ -130,11 +135,11 @@ public void queryCountWithConditions() { final ResultSet result = database.command("sql", "select count(*) as total from Indexed where key > 'one'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("total")); - Assertions.assertTrue(((Number) d.getProperty("total")).longValue() > 0); + assertThat(d.getProperty("total")).isNotNull(); + assertThat(((Number) d.getProperty("total")).longValue()).isGreaterThan( 0); } }); } @@ -143,13 +148,13 @@ public void queryCountWithConditions() { public void queryDistinct() { final ResultSet result = database.command("sql", "select distinct(name) as name from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Set cities = new HashSet<>(); for (final ResultSet it = result; it.hasNext(); ) { final Result city = it.next(); final String cityName = city.getProperty("name"); - Assertions.assertFalse(cities.contains(cityName)); + assertThat(cities.contains(cityName)).isFalse(); cities.add(cityName); } } @@ -158,11 +163,11 @@ public void queryDistinct() { public void queryFunctionRenamed() { final ResultSet result = database.command("sql", "select distinct(name) from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result city = it.next(); - Assertions.assertTrue(city.hasProperty("name")); + assertThat(city.hasProperty("name")).isTrue(); } } @@ -173,23 +178,23 @@ public void queryUnionAllAsAggregationNotRemoveDuplicates() { final int count = (int) CollectionUtils.countEntries(result); result = database.command("sql", "select unionAll(name) as name from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Collection citiesFound = result.next().getProperty("name"); - Assertions.assertEquals(citiesFound.size(), count); + assertThat(count).isEqualTo(citiesFound.size()); } @Test public void querySetNotDuplicates() { final ResultSet result = database.command("sql", "select set(name) as name from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Collection citiesFound = result.next().getProperty("name"); - Assertions.assertTrue(citiesFound.size() > 1); + assertThat(citiesFound.size() > 1).isTrue(); final Set cities = new HashSet(); for (final Object city : citiesFound) { - Assertions.assertFalse(cities.contains(city.toString())); + assertThat(cities.contains(city.toString())).isFalse(); cities.add(city.toString()); } } @@ -198,12 +203,12 @@ public void querySetNotDuplicates() { public void queryList() { final ResultSet result = database.command("sql", "select list(name) as names from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); final List citiesFound = d.getProperty("names"); - Assertions.assertTrue(citiesFound.size() > 1); + assertThat(citiesFound.size() > 1).isTrue(); } } @@ -211,36 +216,36 @@ public void queryList() { public void testSelectMap() { final ResultSet result = database.query("sql", "select list( 1, 4, 5.00, 'john', map( 'kAA', 'vAA' ) ) as myresult"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result document = result.next(); final List myresult = document.getProperty("myresult"); - Assertions.assertNotNull(myresult); + assertThat(myresult).isNotNull(); - Assertions.assertTrue(myresult.remove(Integer.valueOf(1))); - Assertions.assertTrue(myresult.remove(Integer.valueOf(4))); - Assertions.assertTrue(myresult.remove(Float.valueOf(5))); - Assertions.assertTrue(myresult.remove("john")); + assertThat(myresult.remove(Integer.valueOf(1))).isTrue(); + assertThat(myresult.remove(Integer.valueOf(4))).isTrue(); + assertThat(myresult.remove(Float.valueOf(5))).isTrue(); + assertThat(myresult.remove("john")).isTrue(); - Assertions.assertEquals(myresult.size(), 1); + assertThat(myresult.size()).isEqualTo(1); - Assertions.assertTrue(myresult.get(0) instanceof Map, "The object is: " + myresult.getClass()); + assertThat(myresult.get(0) instanceof Map).as("The object is: " + myresult.getClass()).isTrue(); final Map map = (Map) myresult.get(0); final String value = (String) map.get("kAA"); - Assertions.assertEquals(value, "vAA"); + assertThat(value).isEqualTo("vAA"); - Assertions.assertEquals(map.size(), 1); + assertThat(map.size()).isEqualTo(1); } @Test public void querySet() { final ResultSet result = database.command("sql", "select set(name) as names from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); final Set citiesFound = d.getProperty("names"); - Assertions.assertTrue(citiesFound.size() > 1); + assertThat(citiesFound.size() > 1).isTrue(); } } @@ -248,12 +253,12 @@ public void querySet() { public void queryMap() { final ResultSet result = database.command("sql", "select map(name, country.name) as names from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); final Map citiesFound = d.getProperty("names"); - Assertions.assertEquals(1, citiesFound.size()); + assertThat(citiesFound.size()).isEqualTo(1); } } @@ -261,11 +266,11 @@ public void queryMap() { public void queryUnionAllAsInline() { final ResultSet result = database.command("sql", "select unionAll(name, country) as edges from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertEquals(1, d.getPropertyNames().size()); - Assertions.assertTrue(d.hasProperty("edges")); + assertThat(d.getPropertyNames().size()).isEqualTo(1); + assertThat(d.hasProperty("edges")).isTrue(); } } @@ -273,28 +278,27 @@ public void queryUnionAllAsInline() { public void queryComposedAggregates() { final ResultSet result = database.command("sql", "select MIN(id) as min, max(id) as max, AVG(id) as average, sum(id) as total from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("min")); - Assertions.assertNotNull(d.getProperty("max")); - Assertions.assertNotNull(d.getProperty("average")); - Assertions.assertNotNull(d.getProperty("total")); - - Assertions.assertTrue(((Number) d.getProperty("max")).longValue() > ((Number) d.getProperty("average")).longValue()); - Assertions.assertTrue(((Number) d.getProperty("average")).longValue() >= ((Number) d.getProperty("min")).longValue()); - Assertions.assertTrue(((Number) d.getProperty("total")).longValue() >= ((Number) d.getProperty("max")).longValue(), - "Total " + d.getProperty("total") + " max " + d.getProperty("max")); + assertThat(d.getProperty("min")).isNotNull(); + assertThat(d.getProperty("max")).isNotNull(); + assertThat(d.getProperty("average")).isNotNull(); + assertThat(d.getProperty("total")).isNotNull(); + + assertThat(((Number) d.getProperty("max")).longValue() > ((Number) d.getProperty("average")).longValue()).isTrue(); + assertThat(((Number) d.getProperty("average")).longValue() >= ((Number) d.getProperty("min")).longValue()).isTrue(); + assertThat(((Number) d.getProperty("total")).longValue() >= ((Number) d.getProperty("max")).longValue()).as("Total " + d.getProperty("total") + " max " + d.getProperty("max")).isTrue(); } } @Test public void queryFormat() { final ResultSet result = database.command("sql", "select format('%d - %s (%s)', nr, street, type, dummy ) as output from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("output")); + assertThat(d.getProperty("output")).isNotNull(); } } @@ -302,11 +306,11 @@ public void queryFormat() { public void querySysdateNoFormat() { final ResultSet result = database.command("sql", "select sysdate() as date from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Object lastDate = null; for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("date")); + assertThat(d.getProperty("date")).isNotNull(); if (lastDate != null) d.getProperty("date").equals(lastDate); @@ -319,15 +323,15 @@ public void querySysdateNoFormat() { public void querySysdateWithFormat() { ResultSet result = database.command("sql", "select sysdate().format('dd-MM-yyyy') as date from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Object lastDate = null; for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); final String date = d.getProperty("date"); - Assertions.assertNotNull(date); - Assertions.assertEquals(10, date.length()); + assertThat(date).isNotNull(); + assertThat(date.length()).isEqualTo(10); if (lastDate != null) d.getProperty("date").equals(lastDate); @@ -337,15 +341,15 @@ public void querySysdateWithFormat() { result = database.command("sql", "select sysdate().format('yyyy-MM-dd HH:mm:ss') as date"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); lastDate = null; for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); final String date = d.getProperty("date"); - Assertions.assertNotNull(date); - Assertions.assertEquals(19, date.length()); + assertThat(date).isNotNull(); + assertThat(date.length()).isEqualTo(19); if (lastDate != null) d.getProperty("date").equals(lastDate); @@ -355,15 +359,15 @@ public void querySysdateWithFormat() { result = database.command("sql", "select sysdate().format('yyyy-MM-dd HH:mm:ss', 'GMT-5') as date"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); lastDate = null; for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); final String date = d.getProperty("date"); - Assertions.assertNotNull(date); - Assertions.assertEquals(19, date.length()); + assertThat(date).isNotNull(); + assertThat(date.length()).isEqualTo(19); if (lastDate != null) d.getProperty("date").equals(lastDate); @@ -375,12 +379,12 @@ public void querySysdateWithFormat() { @Test public void queryDate() { ResultSet result = database.command("sql", "select count(*) as tot from Account"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final int tot = ((Number) result.next().getProperty("tot")).intValue(); database.transaction(() -> { final ResultSet result2 = database.command("sql", "update Account set created = date()"); - Assertions.assertEquals(tot, (Long) result2.next().getProperty("count")); + assertThat((Long) result2.next().getProperty("count")).isEqualTo(tot); }); final String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; @@ -391,17 +395,17 @@ public void queryDate() { int count = 0; for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("created")); + assertThat(d.getProperty("created")).isNotNull(); ++count; } - Assertions.assertEquals(tot, count); + assertThat(count).isEqualTo(tot); } @Test public void queryUndefinedFunction() { try { database.command("sql", "select blaaaa(salary) as max from Account"); - Assertions.fail(); + fail(""); } catch (final CommandExecutionException e) { // EXPECTED } @@ -436,10 +440,10 @@ public Object execute(final Object iThis, final Identifiable iCurrentRecord, fin final ResultSet result = database.command("sql", "select from Account where bigger(id,1000) = 1000"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertTrue((Integer) d.getProperty("id") <= 1000); + assertThat((Integer) d.getProperty("id") <= 1000).isTrue(); } ((SQLQueryEngine) database.getQueryEngine("sql")).getFunctionFactory().unregister("bigger"); @@ -451,12 +455,12 @@ public void queryAsLong() { final String sql = "select numberString.asLong() as value from ( select '" + moreThanInteger + "' as numberString from Account ) limit 1"; final ResultSet result = database.command("sql", sql); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("value")); - Assertions.assertTrue(d.getProperty("value") instanceof Long); - Assertions.assertEquals(moreThanInteger, (Long) d.getProperty("value")); + assertThat(d.getProperty("value")).isNotNull(); + assertThat(d.getProperty("value") instanceof Long).isTrue(); + assertThat((Long) d.getProperty("value")).isEqualTo(moreThanInteger); } } @@ -464,13 +468,13 @@ public void queryAsLong() { public void testHashMethod() throws UnsupportedEncodingException, NoSuchAlgorithmException { final ResultSet result = database.command("sql", "select name, name.hash() as n256, name.hash('sha-512') as n512 from City"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); final String name = d.getProperty("name"); - Assertions.assertEquals(SQLMethodHash.createHash(name, "SHA-256"), d.getProperty("n256")); - Assertions.assertEquals(SQLMethodHash.createHash(name, "SHA-512"), d.getProperty("n512")); + assertThat(d.getProperty("n256")).isEqualTo(SQLMethodHash.createHash(name, "SHA-256")); + assertThat(d.getProperty("n512")).isEqualTo(SQLMethodHash.createHash(name, "SHA-512")); } } @@ -488,10 +492,10 @@ public void testFirstFunction() { final ResultSet result = database.command("sql", "select first(sequence) as first from V where sequence is not null"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(0, (Long) result.next().getProperty("first")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(1, (Long) result.next().getProperty("first")); + assertThat(result.hasNext()).isTrue(); + assertThat((Long) result.next().getProperty("first")).isEqualTo(0); + assertThat(result.hasNext()).isTrue(); + assertThat((Long) result.next().getProperty("first")).isEqualTo(1); } @Test @@ -507,15 +511,15 @@ public void testFirstAndLastFunctionsWithMultipleValues() { final ResultSet result = database.query("sql", "SELECT first(value) as first, last(value) as last FROM mytype"); - final Object[] array = result.stream().toArray(); + final List array = result.stream().collect(Collectors.toList()); - Assertions.assertEquals(4, array.length); - for (final Object r : array) { - ((Result) r).hasProperty("first"); - Assertions.assertNotNull(((Result) r).getProperty("first")); + assertThat(array).hasSize(4); + for (final Result r : array) { + assertThat(r.hasProperty("first")).isTrue(); + assertThat( r.getProperty("first")).isNotNull(); - ((Result) r).hasProperty("last"); - Assertions.assertNotNull(((Result) r).getProperty("last")); + assertThat(r.hasProperty("last")).isTrue(); + assertThat(r.getProperty("last")).isNotNull(); } } @@ -534,10 +538,10 @@ public void testLastFunction() { final ResultSet result = database.command("sql", "select last(sequence2) as last from V where sequence2 is not null"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(99, (Long) result.next().getProperty("last")); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(98, (Long) result.next().getProperty("last")); + assertThat(result.hasNext()).isTrue(); + assertThat((Long) result.next().getProperty("last")).isEqualTo(99); + assertThat(result.hasNext()).isTrue(); + assertThat((Long) result.next().getProperty("last")).isEqualTo(98); } @Test @@ -546,18 +550,18 @@ public void querySplit() { final ResultSet result = database.command("sql", sql); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); for (final ResultSet it = result; it.hasNext(); ) { final Result d = it.next(); - Assertions.assertNotNull(d.getProperty("value")); - Assertions.assertTrue(d.getProperty("value").getClass().isArray()); + assertThat(d.getProperty("value")).isNotNull(); + assertThat(d.getProperty("value").getClass().isArray()).isTrue(); final Object[] array = d.getProperty("value"); - Assertions.assertEquals(array.length, 3); - Assertions.assertEquals(array[0], "1"); - Assertions.assertEquals(array[1], "2"); - Assertions.assertEquals(array[2], "3"); + assertThat(array.length).isEqualTo(3); + assertThat(array[0]).isEqualTo("1"); + assertThat(array[1]).isEqualTo("2"); + assertThat(array[2]).isEqualTo("3"); } } @@ -566,10 +570,10 @@ public void CheckAllFunctions() { final DefaultSQLFunctionFactory fFactory = ((SQLQueryEngine) database.getQueryEngine("sql")).getFunctionFactory(); for (String fName : fFactory.getFunctionNames()) { final SQLFunction f = fFactory.getFunctionInstance(fName); - Assertions.assertNotNull(f); + assertThat(f).isNotNull(); - Assertions.assertFalse(f.getName().isEmpty()); - Assertions.assertFalse(f.getSyntax().isEmpty()); + assertThat(f.getName().isEmpty()).isFalse(); + assertThat(f.getSyntax().isEmpty()).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/text/SQLFunctionStrcmpciTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/text/SQLFunctionStrcmpciTest.java index a4540c7ef2..094bddc948 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/text/SQLFunctionStrcmpciTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/text/SQLFunctionStrcmpciTest.java @@ -21,10 +21,14 @@ import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.query.sql.function.text.SQLFunctionStrcmpci; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -40,44 +44,44 @@ public void setup() { @Test public void testEmpty() { final Object result = function.getResult(); - Assertions.assertNull(result); + assertThat(result).isNull(); } @Test public void testResult() { - Assertions.assertEquals(0, function.execute(null, null, null, new String[] { "ThisIsATest", "THISISATEST" }, null)); + assertThat(function.execute(null, null, null, new String[]{"ThisIsATest", "THISISATEST"}, null)).isEqualTo(0); } @Test public void testQuery() throws Exception { TestHelper.executeInNewDatabase("SQLFunctionStrcmpci", (db) -> { ResultSet result = db.query("sql", "select strcmpci('ThisIsATest', 'THISISATEST') as strcmpci"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(0, (Integer) result.next().getProperty("strcmpci")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("strcmpci")).isEqualTo(0); result = db.query("sql", "select strcmpci(null, null) as strcmpci"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(0, (Integer) result.next().getProperty("strcmpci")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("strcmpci")).isEqualTo(0); result = db.query("sql", "select strcmpci('ThisIsATest', null) as strcmpci"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(1, (Integer) result.next().getProperty("strcmpci")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("strcmpci")).isEqualTo(1); result = db.query("sql", "select strcmpci(null, 'ThisIsATest') as strcmpci"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(-1, (Integer) result.next().getProperty("strcmpci")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("strcmpci")).isEqualTo(-1); result = db.query("sql", "select strcmpci('ThisIsATest', 'THISISATESTO') as strcmpci"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(-1, (Integer) result.next().getProperty("strcmpci")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("strcmpci")).isEqualTo(-1); result = db.query("sql", "select strcmpci('ThisIsATestO', 'THISISATEST') as strcmpci"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(+1, (Integer) result.next().getProperty("strcmpci")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("strcmpci")).isEqualTo(+1); result = db.query("sql", "select strcmpci('ThisIsATestO', 'THISISATESTE') as strcmpci"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(+1, (Integer) result.next().getProperty("strcmpci")); + assertThat(result.hasNext()).isTrue(); + assertThat((Integer) result.next().getProperty("strcmpci")).isEqualTo(+1); }); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodJoinTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodJoinTest.java index 522644aae3..c8e1849f54 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodJoinTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodJoinTest.java @@ -9,7 +9,7 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; class SQLMethodJoinTest { diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodKeysTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodKeysTest.java index 7ceedd9323..c9cfc54b4b 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodKeysTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodKeysTest.java @@ -25,7 +25,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class SQLMethodKeysTest { @@ -43,6 +43,6 @@ public void testWithResult() { resultInternal.setProperty("surname", "Bar"); final Object result = function.execute(resultInternal, null, null, null); - assertEquals(new LinkedHashSet(Arrays.asList("name", "surname")), result); + assertThat(result).isEqualTo(new LinkedHashSet(Arrays.asList("name", "surname"))); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodValuesTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodValuesTest.java index fee8cb13ac..b26e0b8290 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodValuesTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodValuesTest.java @@ -25,7 +25,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class SQLMethodValuesTest { private SQLMethod function; @@ -43,6 +43,6 @@ public void testWithResult() { resultInternal.setProperty("surname", "Bar"); final Object result = function.execute(resultInternal, null, null, null); - assertEquals(Arrays.asList("Foo", "Bar"), new ArrayList<>((Collection) result)); + assertThat(new ArrayList<>((Collection) result)).isEqualTo(Arrays.asList("Foo", "Bar")); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsJSONTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsJSONTest.java index 9c07c8ac46..ead664f3d6 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsJSONTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsJSONTest.java @@ -21,11 +21,11 @@ import com.arcadedb.query.sql.executor.SQLMethod; import com.arcadedb.serializer.json.JSONException; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; class SQLMethodAsJSONTest { @@ -39,28 +39,28 @@ void setUp() { @Test void testNull() { final Object result = method.execute(null, null, null, null); - Assertions.assertNull(result); + assertThat(result).isNull(); } @Test void testEmptyJsonIsReturned() { final Object result = method.execute("", null, null, null); - Assertions.assertTrue(result instanceof JSONObject); - Assertions.assertTrue(((JSONObject) result).isEmpty()); + assertThat(result instanceof JSONObject).isTrue(); + assertThat(((JSONObject) result).isEmpty()).isTrue(); } @Test void testStringIsReturnedAsString() { final Object result = method.execute(new JSONObject().put("name", "robot").toString(), null, null, null); - Assertions.assertTrue(result instanceof JSONObject); - Assertions.assertEquals("robot", ((JSONObject) result).getString("name")); + assertThat(result instanceof JSONObject).isTrue(); + assertThat(((JSONObject) result).getString("name")).isEqualTo("robot"); } @Test void testErrorJsonParsing() { try { final Object result = method.execute("{\"name\"]", null, null, null); - Assertions.fail(); + fail(""); } catch (JSONException e) { //EXPECTED } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsListTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsListTest.java index eb0a5c3f20..375a5ba3f6 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsListTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsListTest.java @@ -27,7 +27,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the "asList()" method implemented by the OSQLMethodAsList class. Note that the only input @@ -49,7 +49,7 @@ public void setup() { public void testNull() { // The expected behavior is to return an empty list. final Object result = function.execute(null, null, null, null); - assertEquals(result, new ArrayList()); + assertThat(new ArrayList()).isEqualTo(result); } @Test @@ -59,7 +59,7 @@ public void testList() { aList.add(1); aList.add("2"); final Object result = function.execute(aList, null, null, null); - assertEquals(result, aList); + assertThat(aList).isEqualTo(result); } @Test @@ -74,7 +74,7 @@ public void testCollection() { final ArrayList expected = new ArrayList(); expected.add(1); expected.add("2"); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -88,7 +88,7 @@ public void testIterable() { final TestIterable anIterable = new TestIterable(expected); final Object result = function.execute(anIterable, null, null, null); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -102,7 +102,7 @@ public void testIterator() { final TestIterable anIterable = new TestIterable(expected); final Object result = function.execute(anIterable.iterator(), null, null, null); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -121,7 +121,7 @@ public void testDocument() { final ArrayList expected = new ArrayList(); expected.add(doc); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -132,6 +132,6 @@ public void testOtherSingleValue() { final Object result = function.execute(Integer.valueOf(4), null, null, null); final ArrayList expected = new ArrayList(); expected.add(Integer.valueOf(4)); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsMapTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsMapTest.java index 66388bf6f9..90ac45b3a3 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsMapTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsMapTest.java @@ -26,7 +26,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the "asMap()" method implemented by the OSQLMethodAsMap class. Note that the only input to @@ -48,7 +48,7 @@ public void setup() { public void testNull() { // The expected behavior is to return an empty map. final Object result = function.execute(null, null, null, null); - assertEquals(result, new HashMap()); + assertThat(new HashMap()).isEqualTo(result); } @Test @@ -58,7 +58,7 @@ public void testMap() { aMap.put("p1", 1); aMap.put("p2", 2); final Object result = function.execute(aMap, null, null, null); - assertEquals(result, aMap); + assertThat(aMap).isEqualTo(result); } @Test @@ -73,7 +73,7 @@ public void testDocument() { final Object result = function.execute(doc, null, null, null); - assertEquals(doc.toMap(false), result); + assertThat(result).isEqualTo(doc.toMap(false)); } @Test @@ -92,7 +92,7 @@ public void testIterable() { final HashMap expected = new HashMap(); expected.put("p1", 1); expected.put("p2", 2); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -111,13 +111,13 @@ public void testIterator() { final HashMap expected = new HashMap(); expected.put("p1", 1); expected.put("p2", 2); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test public void testOtherValue() { // The expected behavior is to return null. final Object result = function.execute(Integer.valueOf(4), null, null, null); - assertEquals(result, null); + assertThat(result).isNull(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsSetTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsSetTest.java index 417d45a743..314b3935fa 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsSetTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/conversion/SQLMethodAsSetTest.java @@ -26,7 +26,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the "asSet()" method implemented by the OSQLMethodAsSet class. Note that the only input to @@ -51,14 +51,14 @@ public void testSet() { aSet.add(1); aSet.add("2"); final Object result = function.execute(aSet, null, null, null); - assertEquals(result, aSet); + assertThat(aSet).isEqualTo(result); } @Test public void testNull() { // The expected behavior is to return an empty set. final Object result = function.execute(null, null, null, null); - assertEquals(result, new HashSet()); + assertThat(new HashSet()).isEqualTo(result); } @Test @@ -73,7 +73,7 @@ public void testCollection() { final HashSet expected = new HashSet(); expected.add(1); expected.add("2"); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -91,7 +91,7 @@ public void testIterable() { expected.add(1); expected.add("2"); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -109,7 +109,7 @@ public void testIterator() { expected.add(1); expected.add("2"); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -127,7 +127,7 @@ public void testDocument() { final HashSet expected = new HashSet(); expected.add(doc); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } @Test @@ -138,6 +138,6 @@ public void testOtherSingleValue() { final Object result = function.execute(Integer.valueOf(4), null, null, null); final HashSet expected = new HashSet(); expected.add(Integer.valueOf(4)); - assertEquals(result, expected); + assertThat(expected).isEqualTo(result); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodExcludeTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodExcludeTest.java index 9de41a1d3f..67b30d1a6a 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodExcludeTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodExcludeTest.java @@ -22,12 +22,13 @@ import com.arcadedb.query.sql.executor.ResultInternal; import com.arcadedb.query.sql.executor.SQLMethod; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + class SQLMethodExcludeTest { private SQLMethod method; @@ -45,9 +46,9 @@ void testFieldValue() { resultInternal.setProperty("surname", "Bar"); final Object result = method.execute(resultInternal, null, null, new Object[] { "name" }); - Assertions.assertNotNull(result); - Assertions.assertTrue(((Map) result).containsKey("surname")); - Assertions.assertFalse(((Map) result).containsKey("name")); - Assertions.assertEquals("Bar", ((Map) result).get("surname")); + assertThat(result).isNotNull(); + assertThat(((Map) result).containsKey("surname")).isTrue(); + assertThat(((Map) result).containsKey("name")).isFalse(); + assertThat(((Map) result).get("surname")).isEqualTo("Bar"); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodIncludeTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodIncludeTest.java index 65405c379e..3990052123 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodIncludeTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodIncludeTest.java @@ -22,12 +22,13 @@ import com.arcadedb.query.sql.executor.ResultInternal; import com.arcadedb.query.sql.executor.SQLMethod; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + class SQLMethodIncludeTest { private SQLMethod method; @@ -45,9 +46,9 @@ void testFieldValue() { resultInternal.setProperty("surname", "Bar"); final Object result = method.execute(resultInternal, null, null, new Object[] { "name" }); - Assertions.assertNotNull(result); - Assertions.assertTrue(((Map) result).containsKey("name")); - Assertions.assertFalse(((Map) result).containsKey("surname")); - Assertions.assertEquals("Foo", ((Map) result).get("name")); + assertThat(result).isNotNull(); + assertThat(((Map) result).containsKey("name")).isTrue(); + assertThat(((Map) result).containsKey("surname")).isFalse(); + assertThat(((Map) result).get("name")).isEqualTo("Foo"); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodPrecisionTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodPrecisionTest.java index 2a5241cd14..7a519aa1fe 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodPrecisionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/misc/SQLMethodPrecisionTest.java @@ -21,16 +21,17 @@ import com.arcadedb.query.sql.executor.SQLMethod; import com.arcadedb.utility.DateUtils; import com.arcadedb.utility.NanoClock; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.time.*; -import java.time.temporal.*; -import java.util.*; -import java.util.concurrent.*; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.concurrent.Callable; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; class SQLMethodPrecisionTest { private SQLMethod method; @@ -44,7 +45,7 @@ void setUp() { void testRequiredArgs() { try { method.execute(null, null, null, new Object[] { null }); - Assertions.fail(); + fail(""); } catch (IllegalArgumentException e) { // EXPECTED } @@ -74,7 +75,7 @@ void testDate() { final Date now = new Date(); Object result = method.execute(now, null, null, new String[] { "millisecond" }); assertThat(result).isInstanceOf(Date.class); - Assertions.assertEquals(now, result); + assertThat(result).isEqualTo(now); } private void testPrecision(final String precisionAsString, final Callable getNow) throws Exception { @@ -91,6 +92,6 @@ private void testPrecision(final String precisionAsString, final Callable parts = CodeUtils.split(rid, ':', 2); - Assertions.assertEquals(2, parts.size()); + assertThat(parts.size()).isEqualTo(2); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/method/string/SQLMethodSubStringTest.java b/engine/src/test/java/com/arcadedb/query/sql/method/string/SQLMethodSubStringTest.java index c279e5625a..78e46b949a 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/method/string/SQLMethodSubStringTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/method/string/SQLMethodSubStringTest.java @@ -20,11 +20,10 @@ */ package com.arcadedb.query.sql.method.string; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the "asList()" method implemented by the OSQLMethodAsList class. Note that the only input @@ -46,49 +45,49 @@ public void setup() { public void testRange() { Object result = function.execute("foobar", null, null, new Object[] { 1, 3 }); - assertEquals(result, "foobar".substring(1, 3)); + assertThat("foobar".substring(1, 3)).isEqualTo(result); result = function.execute("foobar", null, null, new Object[] { 0, 0 }); - assertEquals(result, "foobar".substring(0, 0)); + assertThat("foobar".substring(0, 0)).isEqualTo(result); result = function.execute("foobar", null, null, new Object[] { 0, 1000 }); - assertEquals(result, "foobar"); + assertThat(result).isEqualTo("foobar"); result = function.execute("foobar", null, null, new Object[] { 0, -1 }); - assertEquals(result, ""); + assertThat(result).isEqualTo(""); result = function.execute("foobar", null, null, new Object[] { 6, 6 }); - assertEquals(result, "foobar".substring(6, 6)); + assertThat("foobar".substring(6, 6)).isEqualTo(result); result = function.execute("foobar", null, null, new Object[] { 1, 9 }); - assertEquals(result, "foobar".substring(1, 6)); + assertThat("foobar".substring(1, 6)).isEqualTo(result); result = function.execute("foobar", null, null, new Object[] { -7, 4 }); - assertEquals(result, "foobar".substring(0, 4)); + assertThat("foobar".substring(0, 4)).isEqualTo(result); } @Test public void testFrom() { Object result = function.execute("foobar", null, null, new Object[] { 1 }); - assertEquals(result, "foobar".substring(1)); + assertThat("foobar".substring(1)).isEqualTo(result); result = function.execute("foobar", null, null, new Object[] { 0 }); - assertEquals(result, "foobar"); + assertThat(result).isEqualTo("foobar"); result = function.execute("foobar", null, null, new Object[] { 6 }); - assertEquals(result, "foobar".substring(6)); + assertThat("foobar".substring(6)).isEqualTo(result); result = function.execute("foobar", null, null, new Object[] { 12 }); - assertEquals(result, ""); + assertThat(result).isEqualTo(""); result = function.execute("foobar", null, null, new Object[] { -7 }); - assertEquals(result, "foobar"); + assertThat(result).isEqualTo("foobar"); } @Test public void testNull() { final Object result = function.execute(null, null, null, null); - Assertions.assertNull(result); + assertThat(result).isNull(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/AbstractParserTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/AbstractParserTest.java index b4af5d664d..83fbb894ba 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/AbstractParserTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/AbstractParserTest.java @@ -18,7 +18,7 @@ */ package com.arcadedb.query.sql.parser; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public abstract class AbstractParserTest { @@ -54,14 +54,14 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { result.validate(); if (!isCorrect) - fail(); + fail(""); return result; } catch (final Exception e) { if (isCorrect) { System.out.println(query); e.printStackTrace(); - fail(); + fail(""); } } return null; @@ -72,14 +72,14 @@ protected SimpleNode checkSyntaxServer(final String query, final boolean isCorre try { final SimpleNode result = osql.Parse(); if (!isCorrect) - fail(); + fail(""); return result; } catch (final Exception e) { if (isCorrect) { System.out.println(query); e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/BatchScriptTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/BatchScriptTest.java index 37ccd9bb8d..0a91e2f843 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/BatchScriptTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/BatchScriptTest.java @@ -20,10 +20,11 @@ import org.junit.jupiter.api.Test; -import java.io.*; -import java.util.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.List; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class BatchScriptTest { @@ -99,14 +100,14 @@ protected List checkSyntax(final String query, final boolean isCorrec // System.out.println(stm.toString()+";"); // } if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/CreateEdgeStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/CreateEdgeStatementTest.java index bfca6b29a6..e2366e4ba6 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/CreateEdgeStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/CreateEdgeStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class CreateEdgeStatementTest { @@ -40,13 +41,13 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { try { final SimpleNode result = osql.Parse(); if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/CreateVertexStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/CreateVertexStatementTest.java index ba6950c0f0..17f502cfac 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/CreateVertexStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/CreateVertexStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class CreateVertexStatementTest { @@ -39,13 +40,13 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { try { final SimpleNode result = osql.Parse(); if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteEdgeStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteEdgeStatementTest.java index 16b6293358..76291db88f 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteEdgeStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteEdgeStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class DeleteEdgeStatementTest { @@ -39,13 +40,13 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { try { final SimpleNode result = osql.Parse(); if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteStatementTest.java index 62d14775e8..9a626fd540 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/DeleteStatementTest.java @@ -23,13 +23,13 @@ import com.arcadedb.database.MutableDocument; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.CollectionUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import java.util.*; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class DeleteStatementTest extends TestHelper { @@ -59,11 +59,11 @@ public void deleteFromSubqueryWithWhereTest() { database.command("sql", "delete from (select expand(arr) from Bar) where k = 'key2'"); final ResultSet result = database.query("sql", "select from Foo"); - Assertions.assertNotNull(result); - Assertions.assertEquals(CollectionUtils.countEntries(result), 2); + assertThat(Optional.ofNullable(result)).isNotNull(); + assertThat(CollectionUtils.countEntries(result)).isEqualTo(2); for (final ResultSet it = result; it.hasNext(); ) { final Document doc = it.next().toElement(); - Assertions.assertNotEquals(doc.getString("k"), "key2"); + assertThat(doc.getString("k")).isNotEqualTo("key2"); } database.commit(); } @@ -87,13 +87,13 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { try { final SimpleNode result = osql.Parse(); if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/ExecutionPlanCacheTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/ExecutionPlanCacheTest.java index 05c289d324..05c183e5f4 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/ExecutionPlanCacheTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/ExecutionPlanCacheTest.java @@ -25,9 +25,10 @@ import com.arcadedb.schema.Property; import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class ExecutionPlanCacheTest { @Test @@ -57,30 +58,30 @@ public void testCacheInvalidation1() throws InterruptedException { // schema changes db.query("sql", stm).close(); cache = ExecutionPlanCache.instance(db); - Assertions.assertTrue(cache.contains(stm)); + assertThat(cache.contains(stm)).isTrue(); final DocumentType clazz = db.getSchema().createDocumentType(testName); - Assertions.assertFalse(cache.contains(stm)); + assertThat(cache.contains(stm)).isFalse(); Thread.sleep(2); // schema changes 2 db.query("sql", stm).close(); cache = ExecutionPlanCache.instance(db); - Assertions.assertTrue(cache.contains(stm)); + assertThat(cache.contains(stm)).isTrue(); final Property prop = clazz.createProperty("name", Type.STRING); - Assertions.assertFalse(cache.contains(stm)); + assertThat(cache.contains(stm)).isFalse(); Thread.sleep(2); // index changes db.query("sql", stm).close(); cache = ExecutionPlanCache.instance(db); - Assertions.assertTrue(cache.contains(stm)); + assertThat(cache.contains(stm)).isTrue(); db.getSchema().createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, false, testName, "name"); - Assertions.assertFalse(cache.contains(stm)); + assertThat(cache.contains(stm)).isFalse(); } finally { db.drop(); diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/IdentifierTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/IdentifierTest.java index e24737cb52..d36d22a3ab 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/IdentifierTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/IdentifierTest.java @@ -18,9 +18,10 @@ */ package com.arcadedb.query.sql.parser; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * Created by luigidellaquila on 26/04/16. */ @@ -30,8 +31,8 @@ public class IdentifierTest { public void testBackTickQuoted() { final Identifier identifier = new Identifier("foo`bar"); - //Assertions.assertEquals(identifier.getStringValue(), "foo`bar"); - Assertions.assertEquals("foo\\`bar", identifier.getStringValue()); - Assertions.assertEquals("foo\\`bar", identifier.getValue()); + //Assertions.assertThat("foo`bar").isEqualTo(identifier.getStringValue()); + assertThat(identifier.getStringValue()).isEqualTo("foo\\`bar"); + assertThat(identifier.getValue()).isEqualTo("foo\\`bar"); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/InsertStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/InsertStatementTest.java index 236387e337..7874bf6f0c 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/InsertStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/InsertStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class InsertStatementTest { @@ -39,13 +40,13 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { try { final SimpleNode result = osql.Parse(); if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/MatchStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/MatchStatementTest.java index e8f770b1f1..6b8b773aee 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/MatchStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/MatchStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class MatchStatementTest { @@ -42,13 +43,13 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { try { final SimpleNode result = osql.Parse(); if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/MathExpressionTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/MathExpressionTest.java index 1247690547..477e2bb351 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/MathExpressionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/MathExpressionTest.java @@ -19,12 +19,13 @@ package com.arcadedb.query.sql.parser; import com.arcadedb.query.sql.executor.Result; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Created by luigidellaquila on 02/07/15. */ @@ -39,28 +40,28 @@ public void testTypes() { MathExpression.Operator.STAR, MathExpression.Operator.SLASH, MathExpression.Operator.REM }; for (final MathExpression.Operator op : basicOps) { - Assertions.assertEquals(op.apply(1, 1).getClass(), Integer.class); + assertThat(op.apply(1, 1).getClass()).isEqualTo(Integer.class); - Assertions.assertEquals(op.apply((short) 1, (short) 1).getClass(), Integer.class); + assertThat(op.apply((short) 1, (short) 1).getClass()).isEqualTo(Integer.class); - Assertions.assertEquals(op.apply(1l, 1l).getClass(), Long.class); - Assertions.assertEquals(op.apply(1f, 1f).getClass(), Float.class); - Assertions.assertEquals(op.apply(1d, 1d).getClass(), Double.class); - Assertions.assertEquals(op.apply(BigDecimal.ONE, BigDecimal.ONE).getClass(), BigDecimal.class); + assertThat(op.apply(1l, 1l).getClass()).isEqualTo(Long.class); + assertThat(op.apply(1f, 1f).getClass()).isEqualTo(Float.class); + assertThat(op.apply(1d, 1d).getClass()).isEqualTo(Double.class); + assertThat(op.apply(BigDecimal.ONE, BigDecimal.ONE).getClass()).isEqualTo(BigDecimal.class); - Assertions.assertEquals(op.apply(1l, 1).getClass(), Long.class); - Assertions.assertEquals(op.apply(1f, 1).getClass(), Float.class); - Assertions.assertEquals(op.apply(1d, 1).getClass(), Double.class); - Assertions.assertEquals(op.apply(BigDecimal.ONE, 1).getClass(), BigDecimal.class); + assertThat(op.apply(1l, 1).getClass()).isEqualTo(Long.class); + assertThat(op.apply(1f, 1).getClass()).isEqualTo(Float.class); + assertThat(op.apply(1d, 1).getClass()).isEqualTo(Double.class); + assertThat(op.apply(BigDecimal.ONE, 1).getClass()).isEqualTo(BigDecimal.class); - Assertions.assertEquals(op.apply(1, 1l).getClass(), Long.class); - Assertions.assertEquals(op.apply(1, 1f).getClass(), Float.class); - Assertions.assertEquals(op.apply(1, 1d).getClass(), Double.class); - Assertions.assertEquals(op.apply(1, BigDecimal.ONE).getClass(), BigDecimal.class); + assertThat(op.apply(1, 1l).getClass()).isEqualTo(Long.class); + assertThat(op.apply(1, 1f).getClass()).isEqualTo(Float.class); + assertThat(op.apply(1, 1d).getClass()).isEqualTo(Double.class); + assertThat(op.apply(1, BigDecimal.ONE).getClass()).isEqualTo(BigDecimal.class); } - Assertions.assertEquals(MathExpression.Operator.PLUS.apply(Integer.MAX_VALUE, 1).getClass(), Long.class); - Assertions.assertEquals(MathExpression.Operator.MINUS.apply(Integer.MIN_VALUE, 1).getClass(), Long.class); + assertThat(MathExpression.Operator.PLUS.apply(Integer.MAX_VALUE, 1).getClass()).isEqualTo(Long.class); + assertThat(MathExpression.Operator.MINUS.apply(Integer.MIN_VALUE, 1).getClass()).isEqualTo(Long.class); } @Test @@ -79,8 +80,8 @@ public void testPriority() { exp.childExpressions.add(integer(1)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(208, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(208); } @Test @@ -105,8 +106,8 @@ public void testPriority2() { exp.childExpressions.add(integer(1)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(16, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(16); } @Test @@ -119,8 +120,8 @@ public void testPriority3() { exp.childExpressions.add(integer(1)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(2, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(2); } @Test @@ -133,8 +134,8 @@ public void testPriority4() { exp.childExpressions.add(integer(1)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(3, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(3); } @Test @@ -145,8 +146,8 @@ public void testAnd() { exp.childExpressions.add(integer(1)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(1, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(1); } @Test @@ -157,8 +158,8 @@ public void testAnd2() { exp.childExpressions.add(integer(4)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(4, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(4); } @Test @@ -169,8 +170,8 @@ public void testDivide() { exp.childExpressions.add(integer(4)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(5, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(5); } @Test @@ -181,7 +182,7 @@ public void testDivideByNull() { exp.childExpressions.add(nullValue()); final Object result = exp.execute((Result) null, null); - Assertions.assertNull(result); + assertThat(result).isNull(); } @Test @@ -192,8 +193,8 @@ public void testOr() { exp.childExpressions.add(integer(1)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(5, result); + assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(5); } @Test @@ -213,8 +214,8 @@ public void testAddListOfNumbers() { exp.childExpressions.add(integer(5)); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof List); - Assertions.assertEquals(5, ((List) result).get(3)); + assertThat(result instanceof List).isTrue(); + assertThat(((List) result).get(3)).isEqualTo(5); } @Test @@ -225,8 +226,8 @@ public void testAddListOfStrings() { exp.childExpressions.add(str("test")); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof List); - Assertions.assertEquals("test", ((List) result).get(3)); + assertThat(result instanceof List).isTrue(); + assertThat(((List) result).get(3)).isEqualTo("test"); } @Test @@ -237,9 +238,9 @@ public void testRemoveListOfStrings() { exp.childExpressions.add(str("a")); final Object result = exp.execute((Result) null, null); - Assertions.assertTrue(result instanceof List); - Assertions.assertEquals(3, ((List) result).size()); - Assertions.assertFalse(((List) result).contains("a")); + assertThat(result instanceof List).isTrue(); + assertThat(((List) result).size()).isEqualTo(3); + assertThat(((List) result).contains("a")).isFalse(); } private void testNullCoalescingGeneric(final MathExpression left, final MathExpression right, final Object expected) { @@ -249,8 +250,8 @@ private void testNullCoalescingGeneric(final MathExpression left, final MathExpr exp.childExpressions.add(right); final Object result = exp.execute((Result) null, null); - // Assertions.assertTrue(result instanceof Integer); - Assertions.assertEquals(expected, result); + // Assertions.assertThat(result instanceof Integer).isTrue(); + assertThat(result).isEqualTo(expected); } private MathExpression integer(final Number i) { diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/PatternTestParserTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/PatternTestParserTest.java index 754d194330..6dd5897f4a 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/PatternTestParserTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/PatternTestParserTest.java @@ -18,11 +18,14 @@ */ package com.arcadedb.query.sql.parser; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** Created by luigidellaquila on 11/10/16. */ public class PatternTestParserTest extends AbstractParserTest { @@ -34,12 +37,12 @@ public void testSimplePattern() { final MatchStatement stm = (MatchStatement) parser.Parse(); stm.buildPatterns(); final Pattern pattern = stm.pattern; - Assertions.assertEquals(0, pattern.getNumOfEdges()); - Assertions.assertEquals(1, pattern.getAliasToNode().size()); - Assertions.assertNotNull(pattern.getAliasToNode().get("a")); - Assertions.assertEquals(1, pattern.getDisjointPatterns().size()); + assertThat(pattern.getNumOfEdges()).isEqualTo(0); + assertThat(pattern.getAliasToNode().size()).isEqualTo(1); + assertThat(pattern.getAliasToNode().get("a")).isNotNull(); + assertThat(pattern.getDisjointPatterns().size()).isEqualTo(1); } catch (final ParseException e) { - Assertions.fail(); + fail(""); } } @@ -51,25 +54,25 @@ public void testCartesianProduct() { final MatchStatement stm = (MatchStatement) parser.Parse(); stm.buildPatterns(); final Pattern pattern = stm.pattern; - Assertions.assertEquals(0, pattern.getNumOfEdges()); - Assertions.assertEquals(2, pattern.getAliasToNode().size()); - Assertions.assertNotNull(pattern.getAliasToNode().get("a")); + assertThat(pattern.getNumOfEdges()).isEqualTo(0); + assertThat(pattern.getAliasToNode().size()).isEqualTo(2); + assertThat(pattern.getAliasToNode().get("a")).isNotNull(); final List subPatterns = pattern.getDisjointPatterns(); - Assertions.assertEquals(2, subPatterns.size()); - Assertions.assertEquals(0, subPatterns.get(0).getNumOfEdges()); - Assertions.assertEquals(1, subPatterns.get(0).getAliasToNode().size()); - Assertions.assertEquals(0, subPatterns.get(1).getNumOfEdges()); - Assertions.assertEquals(1, subPatterns.get(1).getAliasToNode().size()); + assertThat(subPatterns.size()).isEqualTo(2); + assertThat(subPatterns.get(0).getNumOfEdges()).isEqualTo(0); + assertThat(subPatterns.get(0).getAliasToNode().size()).isEqualTo(1); + assertThat(subPatterns.get(1).getNumOfEdges()).isEqualTo(0); + assertThat(subPatterns.get(1).getAliasToNode().size()).isEqualTo(1); final Set aliases = new HashSet<>(); aliases.add("a"); aliases.add("b"); aliases.remove(subPatterns.get(0).getAliasToNode().keySet().iterator().next()); aliases.remove(subPatterns.get(1).getAliasToNode().keySet().iterator().next()); - Assertions.assertEquals(0, aliases.size()); + assertThat(aliases.size()).isEqualTo(0); } catch (final ParseException e) { - Assertions.fail(); + fail(""); } } @@ -82,11 +85,11 @@ public void testComplexCartesianProduct() { final MatchStatement stm = (MatchStatement) parser.Parse(); stm.buildPatterns(); final Pattern pattern = stm.pattern; - Assertions.assertEquals(4, pattern.getNumOfEdges()); - Assertions.assertEquals(6, pattern.getAliasToNode().size()); - Assertions.assertNotNull(pattern.getAliasToNode().get("a")); + assertThat(pattern.getNumOfEdges()).isEqualTo(4); + assertThat(pattern.getAliasToNode().size()).isEqualTo(6); + assertThat(pattern.getAliasToNode().get("a")).isNotNull(); final List subPatterns = pattern.getDisjointPatterns(); - Assertions.assertEquals(2, subPatterns.size()); + assertThat(subPatterns.size()).isEqualTo(2); final Set aliases = new HashSet<>(); aliases.add("a"); @@ -97,10 +100,10 @@ public void testComplexCartesianProduct() { aliases.add("f"); aliases.removeAll(subPatterns.get(0).getAliasToNode().keySet()); aliases.removeAll(subPatterns.get(1).getAliasToNode().keySet()); - Assertions.assertEquals(0, aliases.size()); + assertThat(aliases.size()).isEqualTo(0); } catch (final ParseException e) { - Assertions.fail(); + fail(""); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/ProjectionTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/ProjectionTest.java index ad399d7f58..1b40861e13 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/ProjectionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/ProjectionTest.java @@ -19,10 +19,13 @@ package com.arcadedb.query.sql.parser; import com.arcadedb.exception.CommandSQLParsingException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Created by luigidellaquila on 02/07/15. @@ -33,15 +36,15 @@ public class ProjectionTest { public void testIsExpand() throws ParseException { final SqlParser parser = getParserFor("select expand(foo) from V"); final SelectStatement stm = (SelectStatement) parser.Parse(); - Assertions.assertTrue(stm.getProjection().isExpand()); + assertThat(stm.getProjection().isExpand()).isTrue(); final SqlParser parser2 = getParserFor("select foo from V"); final SelectStatement stm2 = (SelectStatement) parser2.Parse(); - Assertions.assertFalse(stm2.getProjection().isExpand()); + assertThat(stm2.getProjection().isExpand()).isFalse(); final SqlParser parser3 = getParserFor("select expand from V"); final SelectStatement stm3 = (SelectStatement) parser3.Parse(); - Assertions.assertFalse(stm3.getProjection().isExpand()); + assertThat(stm3.getProjection().isExpand()).isFalse(); } @Test @@ -53,11 +56,11 @@ public void testValidate() throws ParseException { try { getParserFor("select expand(foo), bar from V").Parse(); - Assertions.fail(); + fail(""); } catch (final CommandSQLParsingException ex) { } catch (final Exception x) { - Assertions.fail(); + fail(""); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/SelectStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/SelectStatementTest.java index 34a7451b33..d80353393f 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/SelectStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/SelectStatementTest.java @@ -25,12 +25,8 @@ import java.io.*; import java.util.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class SelectStatementTest { @@ -58,7 +54,7 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { // System.out.println(builder.toString()); // System.out.println("............"); // } - fail(); + fail(""); } return result; @@ -66,7 +62,7 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { if (isCorrect) { //System.out.println(query); e.printStackTrace(); - fail(); + fail(""); } } return null; @@ -75,23 +71,23 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { @Test public void testParserSimpleSelect1() { final SimpleNode stm = checkRightSyntax("select from Foo"); - assertTrue(stm instanceof SelectStatement); + assertThat(stm instanceof SelectStatement).isTrue(); final SelectStatement select = (SelectStatement) stm; - assertNull(select.getProjection()); - assertNotNull(select.getTarget()); - assertNull(select.getWhereClause()); + assertThat(select.getProjection()).isNull(); + assertThat(select.getTarget()).isNotNull(); + assertThat(select.getWhereClause()).isNull(); } @Test public void testParserSimpleSelect2() { final SimpleNode stm = checkRightSyntax("select bar from Foo"); - assertTrue(stm instanceof SelectStatement); + assertThat(stm instanceof SelectStatement).isTrue(); final SelectStatement select = (SelectStatement) stm; - assertNotNull(select.getProjection()); - assertNotNull(select.getProjection().getItems()); - assertEquals(select.getProjection().getItems().size(), 1); - assertNotNull(select.getTarget()); - assertNull(select.getWhereClause()); + assertThat(select.getProjection()).isNotNull(); + assertThat(select.getProjection().getItems()).isNotNull(); + assertThat(select.getProjection().getItems().size()).isEqualTo(1); + assertThat(select.getTarget()).isNotNull(); + assertThat(select.getWhereClause()).isNull(); } @Test @@ -165,7 +161,7 @@ public void testSimpleSelectWhere() { public void testIn() { final SimpleNode result = checkRightSyntax("select count(*) from OFunction where name in [\"a\"]"); // result.dump(" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -173,7 +169,7 @@ public void testIn() { public void testNotIn() { final SimpleNode result = checkRightSyntax("select count(*) from OFunction where name not in [\"a\"]"); // result.dump(" "); - assertTrue(result instanceof Statement); + assertThat(result instanceof Statement).isTrue(); } @@ -181,7 +177,7 @@ public void testNotIn() { public void testMath1() { final SimpleNode result = checkRightSyntax("" + "select * from sqlSelectIndexReuseTestClass where prop1 = 1 + 1"); // result.dump(" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -189,7 +185,7 @@ public void testMath1() { public void testMath2() { final SimpleNode result = checkRightSyntax("" + "select * from sqlSelectIndexReuseTestClass where prop1 = foo + 1"); // result.dump(" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -197,7 +193,7 @@ public void testMath2() { public void testMath5() { final SimpleNode result = checkRightSyntax("" + "select * from sqlSelectIndexReuseTestClass where prop1 = foo + 1 * bar - 5"); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -205,7 +201,7 @@ public void testMath5() { public void testContainsWithCondition() { final SimpleNode result = checkRightSyntax("select from Profile where customReferences.values() CONTAINS 'a'"); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -213,7 +209,7 @@ public void testContainsWithCondition() { public void testNamedParam() { final SimpleNode result = checkRightSyntax("select from JavaComplexTestClass where enumField = :enumItem"); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -221,7 +217,7 @@ public void testNamedParam() { public void testBoolean() { final SimpleNode result = checkRightSyntax("select from Foo where bar = true"); // result.dump(" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -229,14 +225,14 @@ public void testBoolean() { public void testDottedAtField() { final SimpleNode result = checkRightSyntax("select from City where country.@type = 'Country'"); // result.dump(" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @Test public void testQuotedFieldNameFrom() { final SimpleNode result = checkRightSyntax("select `from` from City where country.@type = 'Country'"); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -257,7 +253,7 @@ public void testQuotedFieldName() { public void testLongDotted() { final SimpleNode result = checkRightSyntax("select from Profile where location.city.country.name = 'Spain'"); // result.dump(" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -265,7 +261,7 @@ public void testLongDotted() { public void testInIsNotAReservedWord() { final SimpleNode result = checkRightSyntax("select count(*) from TRVertex where in.type() not in [\"LINKSET\"] "); // result.dump(" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @@ -273,13 +269,13 @@ public void testInIsNotAReservedWord() { public void testSelectFunction() { final SimpleNode result = checkRightSyntax("select max(1,2,7,0,-2,3), 'pluto'"); // result.dump(" "); - assertTrue(result instanceof SelectWithoutTargetStatement); + assertThat(result instanceof SelectWithoutTargetStatement).isTrue(); } @Test public void testEscape1() { final SimpleNode result = checkRightSyntax("select from bucket:internal where \"\\u005C\\u005C\" = \"\\u005C\\u005C\" "); - assertTrue(result instanceof SelectStatement); + assertThat(result instanceof SelectStatement).isTrue(); } @Test @@ -299,9 +295,9 @@ public void testEmptyCollection() { final StringBuilder parsed = new StringBuilder(); stm.toString(params, parsed); - assertEquals(parsed.toString(), "SELECT FROM bar WHERE name NOT IN []"); + assertThat(parsed.toString()).isEqualTo("SELECT FROM bar WHERE name NOT IN []"); } catch (final Exception e) { - fail(); + fail(""); } } @@ -309,7 +305,7 @@ public void testEmptyCollection() { public void testEscape2() { try { checkWrongSyntax("select from bucket:internal where \"\\u005C\" = \"\\u005C\" "); - fail(); + fail(""); } catch (final Error e) { // EXPECTED } @@ -548,10 +544,10 @@ public void testReturn() { public void testFlatten() { final SelectStatement stm = (SelectStatement) checkRightSyntax("select from ouser where name = 'foo'"); final List flattened = stm.whereClause.flatten(); - assertTrue(((BinaryCondition) flattened.get(0).subBlocks.get(0)).left.isBaseIdentifier()); - assertFalse(((BinaryCondition) flattened.get(0).subBlocks.get(0)).right.isBaseIdentifier()); - assertFalse(((BinaryCondition) flattened.get(0).subBlocks.get(0)).left.isEarlyCalculated(new BasicCommandContext())); - assertTrue(((BinaryCondition) flattened.get(0).subBlocks.get(0)).right.isEarlyCalculated(new BasicCommandContext())); + assertThat(((BinaryCondition) flattened.get(0).subBlocks.get(0)).left.isBaseIdentifier()).isTrue(); + assertThat(((BinaryCondition) flattened.get(0).subBlocks.get(0)).right.isBaseIdentifier()).isFalse(); + assertThat(((BinaryCondition) flattened.get(0).subBlocks.get(0)).left.isEarlyCalculated(new BasicCommandContext())).isFalse(); + assertThat(((BinaryCondition) flattened.get(0).subBlocks.get(0)).right.isEarlyCalculated(new BasicCommandContext())).isTrue(); } @Test diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/StatementCacheTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/StatementCacheTest.java index ff168b314f..7f28b4b35d 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/StatementCacheTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/StatementCacheTest.java @@ -18,9 +18,10 @@ */ package com.arcadedb.query.sql.parser; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class StatementCacheTest { @Test @@ -30,15 +31,15 @@ public void testInIsNotAReservedWord() { cache.get("select from bar"); cache.get("select from baz"); - Assertions.assertTrue(cache.contains("select from bar")); - Assertions.assertTrue(cache.contains("select from baz")); - Assertions.assertFalse(cache.contains("select from foo")); + assertThat(cache.contains("select from bar")).isTrue(); + assertThat(cache.contains("select from baz")).isTrue(); + assertThat(cache.contains("select from foo")).isFalse(); cache.get("select from bar"); cache.get("select from foo"); - Assertions.assertTrue(cache.contains("select from bar")); - Assertions.assertTrue(cache.contains("select from foo")); - Assertions.assertFalse(cache.contains("select from baz")); + assertThat(cache.contains("select from bar")).isTrue(); + assertThat(cache.contains("select from foo")).isTrue(); + assertThat(cache.contains("select from baz")).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/TraverseStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/TraverseStatementTest.java index 5e09ebb495..3146e4ad26 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/TraverseStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/TraverseStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class TraverseStatementTest { @@ -45,7 +46,7 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { // System.out.println(result.toString()); // System.out.println("............"); // } - fail(); + fail(""); } return result; @@ -53,7 +54,7 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { if (isCorrect) { System.out.println(query); e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateEdgeStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateEdgeStatementTest.java index aa30aafea6..76c88c033a 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateEdgeStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateEdgeStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class UpdateEdgeStatementTest { protected SimpleNode checkRightSyntax(final String query) { @@ -39,14 +40,14 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { try { final SimpleNode result = osql.Parse(); if (!isCorrect) { - fail(); + fail(""); } return result; } catch (final Exception e) { if (isCorrect) { e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateStatementTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateStatementTest.java index 427c0c6648..58671a3027 100755 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateStatementTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/UpdateStatementTest.java @@ -20,9 +20,10 @@ import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class UpdateStatementTest { @@ -46,7 +47,7 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { // System.out.println(result.toString()); // System.out.println("............"); // } - fail(); + fail(""); } // System.out.println(query); // System.out.println("->"); @@ -58,7 +59,7 @@ protected SimpleNode checkSyntax(final String query, final boolean isCorrect) { if (isCorrect) { //System.out.println(query); e.printStackTrace(); - fail(); + fail(""); } } return null; diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsConditionTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsConditionTest.java index 7f2ec3865a..da27d7d812 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsConditionTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsConditionTest.java @@ -23,8 +23,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) @@ -34,22 +33,22 @@ public class ContainsConditionTest { public void test() { final ContainsCondition op = new ContainsCondition(-1); - assertFalse(op.execute(null, null)); - assertFalse(op.execute(null, "foo")); + assertThat(op.execute(null, null)).isFalse(); + assertThat(op.execute(null, "foo")).isFalse(); final List left = new ArrayList(); - assertFalse(op.execute(left, "foo")); - assertFalse(op.execute(left, null)); + assertThat(op.execute(left, "foo")).isFalse(); + assertThat(op.execute(left, null)).isFalse(); left.add("foo"); left.add("bar"); - assertTrue(op.execute(left, "foo")); - assertTrue(op.execute(left, "bar")); - assertFalse(op.execute(left, "fooz")); + assertThat(op.execute(left, "foo")).isTrue(); + assertThat(op.execute(left, "bar")).isTrue(); + assertThat(op.execute(left, "fooz")).isFalse(); left.add(null); - assertTrue(op.execute(left, null)); + assertThat(op.execute(left, null)).isTrue(); } @Test @@ -73,6 +72,6 @@ public Iterator iterator() { }; final ContainsCondition op = new ContainsCondition(-1); - assertTrue(op.execute(left, right)); + assertThat(op.execute(left, right)).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsKeyOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsKeyOperatorTest.java index 17e597b433..3b73124622 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsKeyOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsKeyOperatorTest.java @@ -23,8 +23,7 @@ import java.util.*; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) @@ -35,18 +34,18 @@ public class ContainsKeyOperatorTest { public void test() { final ContainsKeyOperator op = new ContainsKeyOperator(-1); - assertFalse(op.execute(null, null, null)); - assertFalse(op.execute(null, null, "foo")); + assertThat(op.execute(null, null, null)).isFalse(); + assertThat(op.execute(null, null, "foo")).isFalse(); final Map originMap = new HashMap(); - assertFalse(op.execute(null, originMap, "foo")); - assertFalse(op.execute(null, originMap, null)); + assertThat(op.execute(null, originMap, "foo")).isFalse(); + assertThat(op.execute(null, originMap, null)).isFalse(); originMap.put("foo", "bar"); originMap.put(1, "baz"); - assertTrue(op.execute(null, originMap, "foo")); - assertTrue(op.execute(null, originMap, 1)); - assertFalse(op.execute(null, originMap, "fooz")); + assertThat(op.execute(null, originMap, "foo")).isTrue(); + assertThat(op.execute(null, originMap, 1)).isTrue(); + assertThat(op.execute(null, originMap, "fooz")).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsValueOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsValueOperatorTest.java index 6633f8aa57..e5a6cfe743 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsValueOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ContainsValueOperatorTest.java @@ -19,31 +19,32 @@ package com.arcadedb.query.sql.parser.operators; import com.arcadedb.query.sql.parser.ContainsValueOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ public class ContainsValueOperatorTest { @Test public void test() { final ContainsValueOperator op = new ContainsValueOperator(-1); - Assertions.assertFalse(op.execute(null,null, null)); - Assertions.assertFalse(op.execute(null,null, "foo")); + assertThat(op.execute(null, null, null)).isFalse(); + assertThat(op.execute(null, null, "foo")).isFalse(); final Map originMap = new HashMap(); - Assertions.assertFalse(op.execute(null,originMap, "bar")); - Assertions.assertFalse(op.execute(null,originMap, null)); + assertThat(op.execute(null, originMap, "bar")).isFalse(); + assertThat(op.execute(null, originMap, null)).isFalse(); originMap.put("foo", "bar"); originMap.put(1, "baz"); originMap.put(2, 12); - Assertions.assertTrue(op.execute(null,originMap, "bar")); - Assertions.assertTrue(op.execute(null,originMap, "baz")); - Assertions.assertTrue(op.execute(null,originMap, 12)); - Assertions.assertFalse(op.execute(null,originMap, "asdfafsd")); + assertThat(op.execute(null, originMap, "bar")).isTrue(); + assertThat(op.execute(null, originMap, "baz")).isTrue(); + assertThat(op.execute(null, originMap, 12)).isTrue(); + assertThat(op.execute(null, originMap, "asdfafsd")).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/EqualsCompareOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/EqualsCompareOperatorTest.java index 9af14a1e6e..77ab1d357c 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/EqualsCompareOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/EqualsCompareOperatorTest.java @@ -20,12 +20,13 @@ import com.arcadedb.database.RID; import com.arcadedb.query.sql.parser.EqualsCompareOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ @@ -34,42 +35,42 @@ public class EqualsCompareOperatorTest { public void test() { final EqualsCompareOperator op = new EqualsCompareOperator(-1); - Assertions.assertFalse(op.execute(null, null, 1)); - Assertions.assertFalse(op.execute(null, 1, null)); - Assertions.assertFalse(op.execute(null, null, null)); + assertThat(op.execute(null, null, 1)).isFalse(); + assertThat(op.execute(null, 1, null)).isFalse(); + assertThat(op.execute(null, null, null)).isFalse(); - Assertions.assertTrue(op.execute(null, 1, 1)); - Assertions.assertFalse(op.execute(null, 1, 0)); - Assertions.assertFalse(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isTrue(); + assertThat(op.execute(null, 1, 0)).isFalse(); + assertThat(op.execute(null, 0, 1)).isFalse(); - Assertions.assertFalse(op.execute(null, "aaa", "zzz")); - Assertions.assertFalse(op.execute(null, "zzz", "aaa")); - Assertions.assertTrue(op.execute(null, "aaa", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isFalse(); + assertThat(op.execute(null, "zzz", "aaa")).isFalse(); + assertThat(op.execute(null, "aaa", "aaa")).isTrue(); - Assertions.assertFalse(op.execute(null, 1, 1.1)); - Assertions.assertFalse(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isFalse(); + assertThat(op.execute(null, 1.1, 1)).isFalse(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertTrue(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isTrue(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isTrue(); - Assertions.assertFalse(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertFalse(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isFalse(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isFalse(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isFalse(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isFalse(); - Assertions.assertTrue(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))); - Assertions.assertFalse(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))).isTrue(); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))).isFalse(); - Assertions.assertFalse(op.execute(null, new Object(), new Object())); + assertThat(op.execute(null, new Object(), new Object())).isFalse(); // MAPS - Assertions.assertTrue(op.execute(null, Map.of("a", "b"), Map.of("a", "b"))); + assertThat(op.execute(null, Map.of("a", "b"), Map.of("a", "b"))).isTrue(); - Assertions.assertTrue(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b", "c", 3))); - Assertions.assertFalse(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b"))); + assertThat(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b", "c", 3))).isTrue(); + assertThat(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b"))).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GeOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GeOperatorTest.java index e016595f93..57a1cc1788 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GeOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GeOperatorTest.java @@ -19,10 +19,12 @@ package com.arcadedb.query.sql.parser.operators; import com.arcadedb.query.sql.parser.GeOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.math.*; +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) @@ -31,32 +33,32 @@ public class GeOperatorTest { @Test public void test() { final GeOperator op = new GeOperator(-1); - Assertions.assertTrue(op.execute(null, 1, 1)); - Assertions.assertTrue(op.execute(null, 1, 0)); - Assertions.assertFalse(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isTrue(); + assertThat(op.execute(null, 1, 0)).isTrue(); + assertThat(op.execute(null, 0, 1)).isFalse(); - Assertions.assertFalse(op.execute(null, "aaa", "zzz")); - Assertions.assertTrue(op.execute(null, "zzz", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isFalse(); + assertThat(op.execute(null, "zzz", "aaa")).isTrue(); - Assertions.assertFalse(op.execute(null, 1, 1.1)); - Assertions.assertTrue(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isFalse(); + assertThat(op.execute(null, 1.1, 1)).isTrue(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertTrue(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isTrue(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isTrue(); - Assertions.assertTrue(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertTrue(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isTrue(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isTrue(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isTrue(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isFalse(); try { - Assertions.assertFalse(op.execute(null, new Object(), new Object())); - Assertions.fail(); + assertThat(op.execute(null, new Object(), new Object())).isFalse(); + fail(""); } catch (final Exception e) { - Assertions.assertTrue(e instanceof ClassCastException); + assertThat(e instanceof ClassCastException).isTrue(); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GtOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GtOperatorTest.java index d807806562..f975cabd20 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GtOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/GtOperatorTest.java @@ -19,11 +19,12 @@ package com.arcadedb.query.sql.parser.operators; import com.arcadedb.query.sql.parser.GtOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ @@ -31,33 +32,33 @@ public class GtOperatorTest { @Test public void test() { final GtOperator op = new GtOperator(-1); - Assertions.assertFalse(op.execute(null, 1, 1)); - Assertions.assertTrue(op.execute(null, 1, 0)); - Assertions.assertFalse(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isFalse(); + assertThat(op.execute(null, 1, 0)).isTrue(); + assertThat(op.execute(null, 0, 1)).isFalse(); - Assertions.assertFalse(op.execute(null, "aaa", "zzz")); - Assertions.assertTrue(op.execute(null, "zzz", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isFalse(); + assertThat(op.execute(null, "zzz", "aaa")).isTrue(); - Assertions.assertFalse(op.execute(null, "aaa", "aaa")); + assertThat(op.execute(null, "aaa", "aaa")).isFalse(); - Assertions.assertFalse(op.execute(null, 1, 1.1)); - Assertions.assertTrue(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isFalse(); + assertThat(op.execute(null, 1.1, 1)).isTrue(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertFalse(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isFalse(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isFalse(); - Assertions.assertFalse(op.execute(null, 1.1, 1.1)); - Assertions.assertFalse(op.execute(null, new BigDecimal(15), new BigDecimal(15))); + assertThat(op.execute(null, 1.1, 1.1)).isFalse(); + assertThat(op.execute(null, new BigDecimal(15), new BigDecimal(15))).isFalse(); - Assertions.assertTrue(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertTrue(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isTrue(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isTrue(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isTrue(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isFalse(); - Assertions.assertFalse(op.execute(null, new Object(), new Object())); + assertThat(op.execute(null, new Object(), new Object())).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ILikeOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ILikeOperatorTest.java index b3049953a3..5b7a59cb18 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ILikeOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/ILikeOperatorTest.java @@ -20,9 +20,10 @@ import com.arcadedb.query.sql.executor.QueryHelper; import com.arcadedb.query.sql.parser.ILikeOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ @@ -30,22 +31,22 @@ public class ILikeOperatorTest { @Test public void test() { final ILikeOperator op = new ILikeOperator(-1); - Assertions.assertTrue(op.execute(null, "FOOBAR", "%ooba%")); - Assertions.assertTrue(op.execute(null, "FOOBAR", "%oo%")); - Assertions.assertFalse(op.execute(null, "FOOBAR", "oo%")); - Assertions.assertFalse(op.execute(null, "FOOBAR", "%oo")); - Assertions.assertFalse(op.execute(null, "FOOBAR", "%fff%")); - Assertions.assertTrue(op.execute(null, "FOOBAR", "foobar")); - Assertions.assertTrue(op.execute(null, "100%", "100\\%")); - Assertions.assertTrue(op.execute(null, "100%", "100%")); - Assertions.assertTrue(op.execute(null, "", "")); - Assertions.assertTrue(op.execute(null, "100?", "100\\?")); - Assertions.assertTrue(op.execute(null, "100?", "100?")); - Assertions.assertTrue(op.execute(null, "abc\ndef", "%E%")); + assertThat(op.execute(null, "FOOBAR", "%ooba%")).isTrue(); + assertThat(op.execute(null, "FOOBAR", "%oo%")).isTrue(); + assertThat(op.execute(null, "FOOBAR", "oo%")).isFalse(); + assertThat(op.execute(null, "FOOBAR", "%oo")).isFalse(); + assertThat(op.execute(null, "FOOBAR", "%fff%")).isFalse(); + assertThat(op.execute(null, "FOOBAR", "foobar")).isTrue(); + assertThat(op.execute(null, "100%", "100\\%")).isTrue(); + assertThat(op.execute(null, "100%", "100%")).isTrue(); + assertThat(op.execute(null, "", "")).isTrue(); + assertThat(op.execute(null, "100?", "100\\?")).isTrue(); + assertThat(op.execute(null, "100?", "100?")).isTrue(); + assertThat(op.execute(null, "abc\ndef", "%E%")).isTrue(); } @Test public void replaceSpecialCharacters() { - Assertions.assertEquals("(?s)\\\\\\[\\]\\{\\}\\(\\)\\|\\*\\+\\$\\^\\...*", QueryHelper.convertForRegExp("\\[]{}()|*+$^.?%")); + assertThat(QueryHelper.convertForRegExp("\\[]{}()|*+$^.?%")).isEqualTo("(?s)\\\\\\[\\]\\{\\}\\(\\)\\|\\*\\+\\$\\^\\...*"); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/InOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/InOperatorTest.java index df59388320..6734b46c7b 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/InOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/InOperatorTest.java @@ -19,11 +19,12 @@ package com.arcadedb.query.sql.parser.operators; import com.arcadedb.query.sql.parser.InOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ @@ -32,22 +33,22 @@ public class InOperatorTest { public void test() { final InOperator op = new InOperator(-1); - Assertions.assertFalse(op.execute(null, null, null)); - Assertions.assertFalse(op.execute(null, null, "foo")); - Assertions.assertFalse(op.execute(null, "foo", null)); - Assertions.assertFalse(op.execute(null, "foo", "foo")); + assertThat(op.execute(null, null, null)).isFalse(); + assertThat(op.execute(null, null, "foo")).isFalse(); + assertThat(op.execute(null, "foo", null)).isFalse(); + assertThat(op.execute(null, "foo", "foo")).isFalse(); final List list1 = new ArrayList(); - Assertions.assertFalse(op.execute(null, "foo", list1)); - Assertions.assertFalse(op.execute(null, null, list1)); - Assertions.assertTrue(op.execute(null, list1, list1)); + assertThat(op.execute(null, "foo", list1)).isFalse(); + assertThat(op.execute(null, null, list1)).isFalse(); + assertThat(op.execute(null, list1, list1)).isTrue(); list1.add("a"); list1.add(1); - Assertions.assertFalse(op.execute(null, "foo", list1)); - Assertions.assertTrue(op.execute(null, "a", list1)); - Assertions.assertTrue(op.execute(null, 1, list1)); + assertThat(op.execute(null, "foo", list1)).isFalse(); + assertThat(op.execute(null, "a", list1)).isTrue(); + assertThat(op.execute(null, 1, list1)).isTrue(); // TODO } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LeOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LeOperatorTest.java index 6c7446eb49..72dd7ae5c1 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LeOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LeOperatorTest.java @@ -19,10 +19,12 @@ package com.arcadedb.query.sql.parser.operators; import com.arcadedb.query.sql.parser.LeOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.math.*; +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) @@ -31,32 +33,32 @@ public class LeOperatorTest { @Test public void test() { final LeOperator op = new LeOperator(-1); - Assertions.assertTrue(op.execute(null, 1, 1)); - Assertions.assertFalse(op.execute(null, 1, 0)); - Assertions.assertTrue(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isTrue(); + assertThat(op.execute(null, 1, 0)).isFalse(); + assertThat(op.execute(null, 0, 1)).isTrue(); - Assertions.assertTrue(op.execute(null, "aaa", "zzz")); - Assertions.assertFalse(op.execute(null, "zzz", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isTrue(); + assertThat(op.execute(null, "zzz", "aaa")).isFalse(); - Assertions.assertTrue(op.execute(null, 1, 1.1)); - Assertions.assertFalse(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isTrue(); + assertThat(op.execute(null, 1.1, 1)).isFalse(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertTrue(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isTrue(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isTrue(); - Assertions.assertFalse(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertFalse(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isFalse(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isFalse(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isFalse(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isTrue(); try { - Assertions.assertFalse(op.execute(null, new Object(), new Object())); - Assertions.fail(); + assertThat(op.execute(null, new Object(), new Object())).isFalse(); + fail(""); } catch (final Exception e) { - Assertions.assertTrue(e instanceof ClassCastException); + assertThat(e instanceof ClassCastException).isTrue(); } } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LikeOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LikeOperatorTest.java index fb1dc8cffd..ddd703e1e3 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LikeOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LikeOperatorTest.java @@ -20,9 +20,10 @@ import com.arcadedb.query.sql.executor.QueryHelper; import com.arcadedb.query.sql.parser.LikeOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ @@ -30,22 +31,22 @@ public class LikeOperatorTest { @Test public void test() { final LikeOperator op = new LikeOperator(-1); - Assertions.assertTrue(op.execute(null, "foobar", "%ooba%")); - Assertions.assertTrue(op.execute(null, "foobar", "%oo%")); - Assertions.assertFalse(op.execute(null, "foobar", "oo%")); - Assertions.assertFalse(op.execute(null, "foobar", "%oo")); - Assertions.assertFalse(op.execute(null, "foobar", "%fff%")); - Assertions.assertTrue(op.execute(null, "foobar", "foobar")); - Assertions.assertTrue(op.execute(null, "100%", "100\\%")); - Assertions.assertTrue(op.execute(null, "100%", "100%")); - Assertions.assertTrue(op.execute(null, "", "")); - Assertions.assertTrue(op.execute(null, "100?", "100\\?")); - Assertions.assertTrue(op.execute(null, "100?", "100?")); - Assertions.assertTrue(op.execute(null, "abc\ndef", "%e%")); + assertThat(op.execute(null, "foobar", "%ooba%")).isTrue(); + assertThat(op.execute(null, "foobar", "%oo%")).isTrue(); + assertThat(op.execute(null, "foobar", "oo%")).isFalse(); + assertThat(op.execute(null, "foobar", "%oo")).isFalse(); + assertThat(op.execute(null, "foobar", "%fff%")).isFalse(); + assertThat(op.execute(null, "foobar", "foobar")).isTrue(); + assertThat(op.execute(null, "100%", "100\\%")).isTrue(); + assertThat(op.execute(null, "100%", "100%")).isTrue(); + assertThat(op.execute(null, "", "")).isTrue(); + assertThat(op.execute(null, "100?", "100\\?")).isTrue(); + assertThat(op.execute(null, "100?", "100?")).isTrue(); + assertThat(op.execute(null, "abc\ndef", "%e%")).isTrue(); } @Test public void replaceSpecialCharacters() { - Assertions.assertEquals("(?s)\\\\\\[\\]\\{\\}\\(\\)\\|\\*\\+\\$\\^\\...*", QueryHelper.convertForRegExp("\\[]{}()|*+$^.?%")); + assertThat(QueryHelper.convertForRegExp("\\[]{}()|*+$^.?%")).isEqualTo("(?s)\\\\\\[\\]\\{\\}\\(\\)\\|\\*\\+\\$\\^\\...*"); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LtOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LtOperatorTest.java index bb5a6000df..75fc176e14 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LtOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/LtOperatorTest.java @@ -19,11 +19,13 @@ package com.arcadedb.query.sql.parser.operators; import com.arcadedb.query.sql.parser.LtOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.math.*; -import java.util.*; +import java.math.BigDecimal; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) @@ -32,45 +34,45 @@ public class LtOperatorTest { @Test public void test() { final LtOperator op = new LtOperator(-1); - Assertions.assertFalse(op.execute(null, 1, 1)); - Assertions.assertFalse(op.execute(null, 1, 0)); - Assertions.assertTrue(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isFalse(); + assertThat(op.execute(null, 1, 0)).isFalse(); + assertThat(op.execute(null, 0, 1)).isTrue(); - Assertions.assertTrue(op.execute(null, "aaa", "zzz")); - Assertions.assertFalse(op.execute(null, "zzz", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isTrue(); + assertThat(op.execute(null, "zzz", "aaa")).isFalse(); - Assertions.assertFalse(op.execute(null, "aaa", "aaa")); + assertThat(op.execute(null, "aaa", "aaa")).isFalse(); - Assertions.assertTrue(op.execute(null, 1, 1.1)); - Assertions.assertFalse(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isTrue(); + assertThat(op.execute(null, 1.1, 1)).isFalse(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertFalse(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isFalse(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isFalse(); - Assertions.assertFalse(op.execute(null, 1.1, 1.1)); - Assertions.assertFalse(op.execute(null, new BigDecimal(15), new BigDecimal(15))); + assertThat(op.execute(null, 1.1, 1.1)).isFalse(); + assertThat(op.execute(null, new BigDecimal(15), new BigDecimal(15))).isFalse(); - Assertions.assertFalse(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertFalse(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isFalse(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isFalse(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isFalse(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isTrue(); try { - Assertions.assertTrue(op.execute(null, new Object(), new Object())); - Assertions.fail(); + assertThat(op.execute(null, new Object(), new Object())).isTrue(); + fail(""); } catch (final Exception e) { - Assertions.assertTrue(e instanceof ClassCastException); + assertThat(e instanceof ClassCastException).isTrue(); } // MAPS - Assertions.assertFalse(op.execute(null, Map.of("a", "b"), Map.of("a", "b"))); + assertThat(op.execute(null, Map.of("a", "b"), Map.of("a", "b"))).isFalse(); - Assertions.assertFalse(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b", "c", 3))); - Assertions.assertFalse(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b"))); + assertThat(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b", "c", 3))).isFalse(); + assertThat(op.execute(null, Map.of("a", "b", "c", 3), Map.of("a", "b"))).isFalse(); - Assertions.assertTrue(op.execute(null, Map.of("a", "b"), Map.of("a", "b", "c", 3))); + assertThat(op.execute(null, Map.of("a", "b"), Map.of("a", "b", "c", 3))).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeOperatorTest.java index 08c019ea2e..e44718244b 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeOperatorTest.java @@ -20,11 +20,12 @@ import com.arcadedb.database.RID; import com.arcadedb.query.sql.parser.NeOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ @@ -33,36 +34,36 @@ public class NeOperatorTest { public void test() { final NeOperator op = new NeOperator(-1); - Assertions.assertTrue(op.execute(null, null, 1)); - Assertions.assertTrue(op.execute(null, 1, null)); - Assertions.assertTrue(op.execute(null, null, null)); + assertThat(op.execute(null, null, 1)).isTrue(); + assertThat(op.execute(null, 1, null)).isTrue(); + assertThat(op.execute(null, null, null)).isTrue(); - Assertions.assertFalse(op.execute(null, 1, 1)); - Assertions.assertTrue(op.execute(null, 1, 0)); - Assertions.assertTrue(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isFalse(); + assertThat(op.execute(null, 1, 0)).isTrue(); + assertThat(op.execute(null, 0, 1)).isTrue(); - Assertions.assertTrue(op.execute(null, "aaa", "zzz")); - Assertions.assertTrue(op.execute(null, "zzz", "aaa")); - Assertions.assertFalse(op.execute(null, "aaa", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isTrue(); + assertThat(op.execute(null, "zzz", "aaa")).isTrue(); + assertThat(op.execute(null, "aaa", "aaa")).isFalse(); - Assertions.assertTrue(op.execute(null, 1, 1.1)); - Assertions.assertTrue(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isTrue(); + assertThat(op.execute(null, 1.1, 1)).isTrue(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertFalse(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isFalse(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isFalse(); - Assertions.assertTrue(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertTrue(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isTrue(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isTrue(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isTrue(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isTrue(); - Assertions.assertFalse(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))); - Assertions.assertTrue(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))).isFalse(); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))).isTrue(); - Assertions.assertTrue(op.execute(null, new Object(), new Object())); + assertThat(op.execute(null, new Object(), new Object())).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeqOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeqOperatorTest.java index fc08a9f2f4..12189dd86f 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeqOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NeqOperatorTest.java @@ -20,11 +20,12 @@ import com.arcadedb.database.RID; import com.arcadedb.query.sql.parser.NeqOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luigi Dell'Aquila (luigi.dellaquila-(at)-gmail.com) */ @@ -32,36 +33,36 @@ public class NeqOperatorTest { @Test public void test() { final NeqOperator op = new NeqOperator(-1); - Assertions.assertTrue(op.execute(null, null, 1)); - Assertions.assertTrue(op.execute(null, 1, null)); - Assertions.assertTrue(op.execute(null, null, null)); + assertThat(op.execute(null, null, 1)).isTrue(); + assertThat(op.execute(null, 1, null)).isTrue(); + assertThat(op.execute(null, null, null)).isTrue(); - Assertions.assertFalse(op.execute(null, 1, 1)); - Assertions.assertTrue(op.execute(null, 1, 0)); - Assertions.assertTrue(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isFalse(); + assertThat(op.execute(null, 1, 0)).isTrue(); + assertThat(op.execute(null, 0, 1)).isTrue(); - Assertions.assertTrue(op.execute(null, "aaa", "zzz")); - Assertions.assertTrue(op.execute(null, "zzz", "aaa")); - Assertions.assertFalse(op.execute(null, "aaa", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isTrue(); + assertThat(op.execute(null, "zzz", "aaa")).isTrue(); + assertThat(op.execute(null, "aaa", "aaa")).isFalse(); - Assertions.assertTrue(op.execute(null, 1, 1.1)); - Assertions.assertTrue(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isTrue(); + assertThat(op.execute(null, 1.1, 1)).isTrue(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertFalse(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isFalse(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isFalse(); - Assertions.assertTrue(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertTrue(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isTrue(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isTrue(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isTrue(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isTrue(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isTrue(); - Assertions.assertFalse(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))); - Assertions.assertTrue(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))).isFalse(); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))).isTrue(); - Assertions.assertTrue(op.execute(null, new Object(), new Object())); + assertThat(op.execute(null, new Object(), new Object())).isTrue(); } } diff --git a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NullSafeEqualsCompareOperatorTest.java b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NullSafeEqualsCompareOperatorTest.java index 6a82721301..ca3f30a4c8 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NullSafeEqualsCompareOperatorTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/parser/operators/NullSafeEqualsCompareOperatorTest.java @@ -20,11 +20,12 @@ import com.arcadedb.database.RID; import com.arcadedb.query.sql.parser.NullSafeEqualsCompareOperator; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.math.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli */ @@ -33,36 +34,36 @@ public class NullSafeEqualsCompareOperatorTest { public void test() { final NullSafeEqualsCompareOperator op = new NullSafeEqualsCompareOperator(-1); - Assertions.assertFalse(op.execute(null, null, 1)); - Assertions.assertFalse(op.execute(null, 1, null)); - Assertions.assertTrue(op.execute(null, null, null)); + assertThat(op.execute(null, null, 1)).isFalse(); + assertThat(op.execute(null, 1, null)).isFalse(); + assertThat(op.execute(null, null, null)).isTrue(); - Assertions.assertTrue(op.execute(null, 1, 1)); - Assertions.assertFalse(op.execute(null, 1, 0)); - Assertions.assertFalse(op.execute(null, 0, 1)); + assertThat(op.execute(null, 1, 1)).isTrue(); + assertThat(op.execute(null, 1, 0)).isFalse(); + assertThat(op.execute(null, 0, 1)).isFalse(); - Assertions.assertFalse(op.execute(null, "aaa", "zzz")); - Assertions.assertFalse(op.execute(null, "zzz", "aaa")); - Assertions.assertTrue(op.execute(null, "aaa", "aaa")); + assertThat(op.execute(null, "aaa", "zzz")).isFalse(); + assertThat(op.execute(null, "zzz", "aaa")).isFalse(); + assertThat(op.execute(null, "aaa", "aaa")).isTrue(); - Assertions.assertFalse(op.execute(null, 1, 1.1)); - Assertions.assertFalse(op.execute(null, 1.1, 1)); + assertThat(op.execute(null, 1, 1.1)).isFalse(); + assertThat(op.execute(null, 1.1, 1)).isFalse(); - Assertions.assertTrue(op.execute(null, BigDecimal.ONE, 1)); - Assertions.assertTrue(op.execute(null, 1, BigDecimal.ONE)); + assertThat(op.execute(null, BigDecimal.ONE, 1)).isTrue(); + assertThat(op.execute(null, 1, BigDecimal.ONE)).isTrue(); - Assertions.assertFalse(op.execute(null, 1.1, BigDecimal.ONE)); - Assertions.assertFalse(op.execute(null, 2, BigDecimal.ONE)); + assertThat(op.execute(null, 1.1, BigDecimal.ONE)).isFalse(); + assertThat(op.execute(null, 2, BigDecimal.ONE)).isFalse(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0.999999)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 0)); + assertThat(op.execute(null, BigDecimal.ONE, 0.999999)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 0)).isFalse(); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 2)); - Assertions.assertFalse(op.execute(null, BigDecimal.ONE, 1.0001)); + assertThat(op.execute(null, BigDecimal.ONE, 2)).isFalse(); + assertThat(op.execute(null, BigDecimal.ONE, 1.0001)).isFalse(); - Assertions.assertTrue(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))); - Assertions.assertFalse(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 10))).isTrue(); + assertThat(op.execute(null, new RID( 1, 10), new RID( (short) 1, 20))).isFalse(); - Assertions.assertFalse(op.execute(null, new Object(), new Object())); + assertThat(op.execute(null, new Object(), new Object())).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/schema/DictionaryTest.java b/engine/src/test/java/com/arcadedb/schema/DictionaryTest.java index d9c41bb6ce..5eb576b9c5 100644 --- a/engine/src/test/java/com/arcadedb/schema/DictionaryTest.java +++ b/engine/src/test/java/com/arcadedb/schema/DictionaryTest.java @@ -25,16 +25,20 @@ import com.arcadedb.graph.MutableVertex; import com.arcadedb.graph.Vertex; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.Iterator; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class DictionaryTest extends TestHelper { @Test public void updateName() { database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType("V")); + Assertions.assertThat(database.getSchema().existsType("V")).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName("V").withTotalBuckets(3).create(); type.createProperty("id", Integer.class); @@ -49,10 +53,10 @@ public void updateName() { } }); - Assertions.assertEquals(4, database.getSchema().getDictionary().getDictionaryMap().size()); + assertThat(database.getSchema().getDictionary().getDictionaryMap().size()).isEqualTo(4); database.transaction(() -> { - Assertions.assertTrue(database.getSchema().existsType("V")); + Assertions.assertThat(database.getSchema().existsType("V")).isTrue(); final MutableDocument v = database.newDocument("V"); v.set("id", 10); @@ -62,14 +66,14 @@ public void updateName() { v.save(); }); - Assertions.assertEquals(5, database.getSchema().getDictionary().getDictionaryMap().size()); + assertThat(database.getSchema().getDictionary().getDictionaryMap().size()).isEqualTo(5); database.transaction(() -> { - Assertions.assertTrue(database.getSchema().existsType("V")); + Assertions.assertThat(database.getSchema().existsType("V")).isTrue(); database.getSchema().getDictionary().updateName("name", "firstName"); }); - Assertions.assertEquals(5, database.getSchema().getDictionary().getDictionaryMap().size()); + assertThat(database.getSchema().getDictionary().getDictionaryMap().size()).isEqualTo(5); database.transaction(() -> { final ResultSet iter = database.query("sql", "select from V order by id asc"); @@ -78,29 +82,29 @@ public void updateName() { while (iter.hasNext()) { final Document d = (Document) iter.next().getRecord().get(); - Assertions.assertEquals(i, d.getInteger("id")); - Assertions.assertEquals("Jay", d.getString("firstName")); - Assertions.assertEquals("Miner", d.getString("surname")); + Assertions.assertThat(d.getInteger("id")).isEqualTo(i); + Assertions.assertThat(d.getString("firstName")).isEqualTo("Jay"); + Assertions.assertThat(d.getString("surname")).isEqualTo("Miner"); if (i == 10) - Assertions.assertEquals("newProperty", d.getString("newProperty")); + Assertions.assertThat(d.getString("newProperty")).isEqualTo("newProperty"); else - Assertions.assertNull(d.getString("newProperty")); + Assertions.assertThat(d.getString("newProperty")).isNull(); - Assertions.assertNull(d.getString("name")); + Assertions.assertThat(d.getString("name")).isNull(); ++i; } - Assertions.assertEquals(11, i); + Assertions.assertThat(i).isEqualTo(11); }); try { database.transaction(() -> { - Assertions.assertTrue(database.getSchema().existsType("V")); + Assertions.assertThat(database.getSchema().existsType("V")).isTrue(); database.getSchema().getDictionary().updateName("V", "V2"); }); - Assertions.fail(); + fail(""); } catch (final Exception e) { } } @@ -123,13 +127,13 @@ public void namesClash() { for (final Iterator iterator = database.iterateType("Babylonia", true); iterator.hasNext(); ) { final Vertex v = iterator.next().asVertex(); - Assertions.assertEquals(11, v.getPropertyNames().size()); + assertThat(v.getPropertyNames().size()).isEqualTo(11); final int origin = v.getInteger("origin"); for (int k = 0; k < 10; k++) { final Integer value = v.getInteger("p" + ((origin * 10) + k)); - Assertions.assertEquals((origin * 10) + k, value); + assertThat(value).isEqualTo((origin * 10) + k); } } } @@ -156,13 +160,13 @@ public void namesClashPropertyCreatedOnSchemaBefore() { for (final Iterator iterator = database.iterateType("Babylonia", true); iterator.hasNext(); ) { final Vertex v = iterator.next().asVertex(); - Assertions.assertEquals(11, v.getPropertyNames().size()); + assertThat(v.getPropertyNames().size()).isEqualTo(11); final int origin = v.getInteger("origin"); for (int k = 0; k < 10; k++) { final Integer value = v.getInteger("p" + ((origin * 10) + k)); - Assertions.assertEquals((origin * 10) + k, value); + assertThat(value).isEqualTo((origin * 10) + k); } } } @@ -189,13 +193,13 @@ public void namesClashPropertyCreatedOnSchemaSameTx() { for (final Iterator iterator = database.iterateType("Babylonia", true); iterator.hasNext(); ) { final Vertex v = iterator.next().asVertex(); - Assertions.assertEquals(11, v.getPropertyNames().size()); + assertThat(v.getPropertyNames().size()).isEqualTo(11); final int origin = v.getInteger("origin"); for (int k = 0; k < 10; k++) { final Integer value = v.getInteger("p" + ((origin * 10) + k)); - Assertions.assertEquals((origin * 10) + k, value); + assertThat(value).isEqualTo((origin * 10) + k); } } } @@ -224,13 +228,13 @@ public void namesClashPropertyCreatedOnSchemaSubTx() { for (final Iterator iterator = database.iterateType("Babylonia", true); iterator.hasNext(); ) { final Vertex v = iterator.next().asVertex(); - Assertions.assertEquals(11, v.getPropertyNames().size()); + assertThat(v.getPropertyNames().size()).isEqualTo(11); final int origin = v.getInteger("origin"); for (int k = 0; k < 10; k++) { final Integer value = v.getInteger("p" + ((origin * 10) + k)); - Assertions.assertEquals((origin * 10) + k, value); + assertThat(value).isEqualTo((origin * 10) + k); } } } diff --git a/engine/src/test/java/com/arcadedb/schema/DocumentValidationTest.java b/engine/src/test/java/com/arcadedb/schema/DocumentValidationTest.java index 0e6abd978c..0c38b82376 100644 --- a/engine/src/test/java/com/arcadedb/schema/DocumentValidationTest.java +++ b/engine/src/test/java/com/arcadedb/schema/DocumentValidationTest.java @@ -10,12 +10,16 @@ import com.arcadedb.graph.MutableVertex; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import java.text.*; +import java.text.SimpleDateFormat; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class DocumentValidationTest extends TestHelper { @Test @@ -176,16 +180,16 @@ public void testDefaultValueIsSetWithSQL() { database.command("sql", "create property Validation.string STRING (default \"1\")"); database.command("sql", "create property Validation.dat DATETIME (default sysdate('YYYY-MM-DD HH:MM:SS'))"); - Assertions.assertEquals(1L, clazz.getProperty("long").getDefaultValue()); - Assertions.assertEquals("1", clazz.getProperty("string").getDefaultValue()); - Assertions.assertTrue(clazz.getProperty("dat").getDefaultValue() instanceof Date); + assertThat(clazz.getProperty("long").getDefaultValue()).isEqualTo(1L); + assertThat(clazz.getProperty("string").getDefaultValue()).isEqualTo("1"); + assertThat(clazz.getProperty("dat").getDefaultValue() instanceof Date).isTrue(); database.transaction(() -> { final MutableDocument d = database.newDocument("Validation"); d.save(); - Assertions.assertEquals(1L, d.get("long")); - Assertions.assertEquals("1", d.get("string")); - Assertions.assertTrue(d.get("dat") instanceof Date); + assertThat(d.get("long")).isEqualTo(1L); + assertThat(d.get("string")).isEqualTo("1"); + assertThat(d.get("dat") instanceof Date); }); } @@ -195,12 +199,12 @@ public void testDefaultNotNullValueIsSetWithSQL() { database.command("sql", "create property Validation.string STRING (notnull, default \"1\")"); - Assertions.assertEquals("1", clazz.getProperty("string").getDefaultValue()); + assertThat(clazz.getProperty("string").getDefaultValue()).isEqualTo("1"); database.transaction(() -> { final MutableDocument d = database.newDocument("Validation"); d.save(); - Assertions.assertEquals("1", d.get("string")); + assertThat(d.get("string")).isEqualTo("1"); }); } @@ -211,23 +215,23 @@ public void testDefaultNotNullMandatoryValueIsSetWithSQL() { database.command("sql", "create property Validation.string STRING (mandatory true, notnull true, default \"Hi\")"); database.command("sql", "create property Validation.dat DATETIME (mandatory true, default null)"); - Assertions.assertEquals("Hi", clazz.getProperty("string").getDefaultValue()); - Assertions.assertNull(clazz.getProperty("dat").getDefaultValue()); + assertThat(clazz.getProperty("string").getDefaultValue()).isEqualTo("Hi"); + assertThat(clazz.getProperty("dat").getDefaultValue()).isNull(); database.transaction(() -> { final MutableDocument d = database.newDocument("Validation"); d.save(); - Assertions.assertEquals("Hi", d.get("string")); - Assertions.assertNull(d.get("dat")); + assertThat(d.get("string")).isEqualTo("Hi"); + assertThat(d.get("dat")).isNull(); final ResultSet resultSet = database.command("sql", "insert into Validation set string = null"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result result = resultSet.next(); - Assertions.assertEquals("Hi", result.getProperty("string")); - Assertions.assertTrue(result.hasProperty("dat")); - Assertions.assertNull(result.getProperty("dat")); + assertThat(result.getProperty("string")).isEqualTo("Hi"); + assertThat(result.hasProperty("dat")).isTrue(); + assertThat(result.getProperty("dat")).isNull(); }); } @@ -237,7 +241,7 @@ public void testRequiredValidationSQL() { database.command("sql", "create property Validation.int INTEGER (mandatory true)"); - Assertions.assertTrue(clazz.getProperty("int").isMandatory()); + assertThat(clazz.getProperty("int").isMandatory()).isTrue(); final MutableDocument d = database.newDocument("Validation"); d.set("int", 10); @@ -265,7 +269,7 @@ public void testRequiredValidationEdge() { } final MutableEdge e = v1.newEdge("E", v2, true, "id", "12345"); - Assertions.assertEquals("12345", e.getString("id")); + assertThat(e.getString("id")).isEqualTo("12345"); }); } @@ -303,9 +307,9 @@ public void testRequiredValidationEdgeSQL() { } final Edge e = database.command("sql", "create edge E from ? to ? set a = '12345', b = '4444', c = '2222'", v1, v2).nextIfAvailable().getEdge().get(); - Assertions.assertEquals("12345", e.getString("a")); - Assertions.assertEquals("4444", e.getString("b")); - Assertions.assertEquals("2222", e.getString("c")); + assertThat(e.getString("a")).isEqualTo("12345"); + assertThat(e.getString("b")).isEqualTo("4444"); + assertThat(e.getString("c")).isEqualTo("2222"); }); } @@ -327,9 +331,9 @@ public void testValidationNotValidEmbedded() { embedded.set("test", "test"); try { d.validate(); - Assertions.fail("Validation doesn't throw exception"); + fail("Validation doesn't throw exception"); } catch (final ValidationException e) { - Assertions.assertTrue(e.toString().contains("int")); + assertThat(e.toString().contains("int")).isTrue(); } } @@ -360,9 +364,9 @@ public void testValidationNotValidEmbeddedList() { try { d.validate(); - Assertions.fail("Validation doesn't throw exception"); + fail("Validation doesn't throw exception"); } catch (final ValidationException e) { - Assertions.assertTrue(e.toString().contains("long")); + assertThat(e.toString().contains("long")).isTrue(); } } @@ -394,9 +398,9 @@ public void testValidationNotValidEmbeddedMap() { try { d.validate(); - Assertions.fail("Validation doesn't throw exception"); + fail("Validation doesn't throw exception"); } catch (final ValidationException e) { - Assertions.assertTrue(e.toString().contains("long")); + assertThat(e.toString().contains("long")).isTrue(); } } @@ -705,9 +709,9 @@ public void testPropertyMetadataAreSavedAndReloadded() { final DocumentType clazzLoaded = database.getSchema().getType("Validation"); final Property property = clazzLoaded.getPropertyIfExists("string"); - Assertions.assertTrue(property.isMandatory()); - Assertions.assertTrue(property.isReadonly()); - Assertions.assertTrue(property.isNotNull()); + assertThat(property.isMandatory()).isTrue(); + assertThat(property.isReadonly()).isTrue(); + assertThat(property.isNotNull()).isTrue(); } @Test @@ -715,14 +719,14 @@ public void testMinMaxNotApplicable() { final DocumentType clazz = database.getSchema().getOrCreateDocumentType("Validation"); try { clazz.createProperty("invString", Type.STRING).setMin("-1"); - Assertions.fail(); + fail(""); } catch (IllegalArgumentException e) { // EXPECTED } try { clazz.createProperty("invBinary", Type.LIST).setMax("-1"); - Assertions.fail(); + fail(""); } catch (IllegalArgumentException e) { // EXPECTED } @@ -733,7 +737,7 @@ private void checkFieldValue(final Document toCheck, final String field, final O final MutableDocument newD = database.newDocument(toCheck.getTypeName()).fromMap(toCheck.toMap()); newD.set(field, newValue); newD.validate(); - Assertions.fail(); + fail(""); } catch (final ValidationException v) { } } @@ -743,7 +747,7 @@ private void checkRequireField(final MutableDocument toCheck, final String field final MutableDocument newD = database.newDocument(toCheck.getTypeName()).fromMap(toCheck.toMap()); newD.remove(fieldName); newD.validate(); - Assertions.fail(); + fail(""); } catch (final ValidationException v) { } } @@ -752,7 +756,7 @@ private void checkReadOnlyField(final MutableDocument toCheck, final String fiel try { toCheck.remove(fieldName); toCheck.validate(); - Assertions.fail(); + fail(""); } catch (final ValidationException v) { } } diff --git a/engine/src/test/java/com/arcadedb/schema/DropBucketTest.java b/engine/src/test/java/com/arcadedb/schema/DropBucketTest.java index e5b4c94c31..bc55ef4912 100644 --- a/engine/src/test/java/com/arcadedb/schema/DropBucketTest.java +++ b/engine/src/test/java/com/arcadedb/schema/DropBucketTest.java @@ -1,16 +1,17 @@ package com.arcadedb.schema; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class DropBucketTest extends TestHelper { @Test public void createDropCluster() { database.getSchema().createBucket("test"); - Assertions.assertNotNull(database.getSchema().getBucketByName("test")); + assertThat(database.getSchema().getBucketByName("test")).isNotNull(); database.getSchema().dropBucket("test"); - Assertions.assertFalse(database.getSchema().existsBucket("test")); + assertThat(database.getSchema().existsBucket("test")).isFalse(); } } diff --git a/engine/src/test/java/com/arcadedb/schema/DropTypeTest.java b/engine/src/test/java/com/arcadedb/schema/DropTypeTest.java index 8c23a77d22..4ee8321061 100644 --- a/engine/src/test/java/com/arcadedb/schema/DropTypeTest.java +++ b/engine/src/test/java/com/arcadedb/schema/DropTypeTest.java @@ -22,11 +22,14 @@ import com.arcadedb.database.MutableDocument; import com.arcadedb.engine.Bucket; import com.arcadedb.exception.SchemaException; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + public class DropTypeTest extends TestHelper { private static final int TOT = 10; private static final String TYPE_NAME = "V"; @@ -36,7 +39,7 @@ public class DropTypeTest extends TestHelper { @Test public void testDropAndRecreateType() { database.transaction(() -> { - Assertions.assertFalse(database.getSchema().existsType(TYPE_NAME)); + assertThat(database.getSchema().existsType(TYPE_NAME)).isFalse(); final DocumentType type = database.getSchema().buildDocumentType().withName(TYPE_NAME).withTotalBuckets(3).create(); @@ -71,57 +74,57 @@ public void testDropAndRecreateType() { for (final Bucket b : buckets) { try { database.getSchema().getBucketById(b.getFileId()); - Assertions.fail(); + fail(); } catch (final SchemaException e) { } try { database.getSchema().getBucketByName(b.getName()); - Assertions.fail(); + fail(); } catch (final SchemaException e) { } try { database.getSchema().getFileById(b.getFileId()); - Assertions.fail(); + fail(); } catch (final SchemaException e) { } } // CHECK TYPE HAS BEEN REMOVED FROM INHERITANCE for (final DocumentType parent : type2.getSuperTypes()) - Assertions.assertFalse(parent.getSubTypes().contains(type2)); + assertThat(parent.getSubTypes().contains(type2)).isFalse(); for (final DocumentType sub : type2.getSubTypes()) { - Assertions.assertFalse(sub.getSuperTypes().contains(type2)); - Assertions.assertTrue(sub.getSuperTypes().contains(type)); + assertThat(sub.getSuperTypes().contains(type2)).isFalse(); + assertThat(sub.getSuperTypes().contains(type)).isTrue(); } // CHECK INHERITANCE CHAIN IS CONSISTENT - Assertions.assertTrue(type.getSuperTypes().isEmpty()); + assertThat(type.getSuperTypes().isEmpty()).isTrue(); for (final DocumentType sub : type.getSubTypes()) - Assertions.assertTrue(sub.getSuperTypes().contains(type)); + assertThat(sub.getSuperTypes().contains(type)).isTrue(); - Assertions.assertEquals(1, database.countType(TYPE_NAME, true)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(1); final DocumentType newType = database.getSchema().getOrCreateDocumentType(TYPE_NAME2); - Assertions.assertEquals(1, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(0, database.countType(TYPE_NAME2, true)); - Assertions.assertEquals(0, database.countType(TYPE_NAME2, false)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(1); + assertThat(database.countType(TYPE_NAME2, true)).isEqualTo(0); + assertThat(database.countType(TYPE_NAME2, false)).isEqualTo(0); newType.addSuperType(TYPE_NAME); // CHECK INHERITANCE CHAIN IS CONSISTENT AGAIN for (final DocumentType parent : newType.getSuperTypes()) - Assertions.assertTrue(parent.getSubTypes().contains(newType)); + assertThat(parent.getSubTypes().contains(newType)).isTrue(); for (final DocumentType sub : newType.getSubTypes()) - Assertions.assertTrue(sub.getSuperTypes().contains(newType)); + assertThat(sub.getSuperTypes().contains(newType)).isTrue(); - Assertions.assertEquals(1, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(0, database.countType(TYPE_NAME2, true)); - Assertions.assertEquals(0, database.countType(TYPE_NAME2, false)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(1); + assertThat(database.countType(TYPE_NAME2, true)).isEqualTo(0); + assertThat(database.countType(TYPE_NAME2, false)).isEqualTo(0); database.begin(); @@ -137,9 +140,9 @@ public void testDropAndRecreateType() { v3.set("id", TOT); v3.save(); - Assertions.assertEquals(TOT + 2, database.countType(TYPE_NAME, true)); - Assertions.assertEquals(TOT, database.countType(TYPE_NAME2, false)); - Assertions.assertEquals(2, database.countType(TYPE_NAME, false)); + assertThat(database.countType(TYPE_NAME, true)).isEqualTo(TOT + 2); + assertThat(database.countType(TYPE_NAME2, false)).isEqualTo(TOT); + assertThat(database.countType(TYPE_NAME, false)).isEqualTo(2); }); } } diff --git a/engine/src/test/java/com/arcadedb/schema/SchemaTest.java b/engine/src/test/java/com/arcadedb/schema/SchemaTest.java index 228b77b74d..2a089c39cb 100644 --- a/engine/src/test/java/com/arcadedb/schema/SchemaTest.java +++ b/engine/src/test/java/com/arcadedb/schema/SchemaTest.java @@ -19,41 +19,44 @@ package com.arcadedb.schema; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.time.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class SchemaTest extends TestHelper { @Test public void tesSchemaSettings() { database.transaction(() -> { final ZoneId zoneId = database.getSchema().getZoneId(); - Assertions.assertNotNull(zoneId); + assertThat(zoneId).isNotNull(); database.getSchema().setZoneId(ZoneId.of("America/New_York")); - Assertions.assertEquals(ZoneId.of("America/New_York"), database.getSchema().getZoneId()); + assertThat(database.getSchema().getZoneId()).isEqualTo(ZoneId.of("America/New_York")); final TimeZone timeZone = database.getSchema().getTimeZone(); - Assertions.assertNotNull(timeZone); + assertThat(timeZone).isNotNull(); database.getSchema().setTimeZone(TimeZone.getTimeZone("UK")); - Assertions.assertEquals(TimeZone.getTimeZone("UK"), database.getSchema().getTimeZone()); + assertThat(database.getSchema().getTimeZone()).isEqualTo(TimeZone.getTimeZone("UK")); final String dateFormat = database.getSchema().getDateFormat(); - Assertions.assertNotNull(dateFormat); + assertThat(dateFormat).isNotNull(); database.getSchema().setDateFormat("yyyy-MMM-dd"); - Assertions.assertEquals("yyyy-MMM-dd", database.getSchema().getDateFormat()); + assertThat(database.getSchema().getDateFormat()).isEqualTo("yyyy-MMM-dd"); final String dateTimeFormat = database.getSchema().getDateTimeFormat(); - Assertions.assertNotNull(dateTimeFormat); + assertThat(dateTimeFormat).isNotNull(); database.getSchema().setDateTimeFormat("yyyy-MMM-dd HH:mm:ss"); - Assertions.assertEquals("yyyy-MMM-dd HH:mm:ss", database.getSchema().getDateTimeFormat()); + assertThat(database.getSchema().getDateTimeFormat()).isEqualTo("yyyy-MMM-dd HH:mm:ss"); final String encoding = database.getSchema().getEncoding(); - Assertions.assertNotNull(encoding); + assertThat(encoding).isNotNull(); database.getSchema().setEncoding("UTF-8"); - Assertions.assertEquals("UTF-8", database.getSchema().getEncoding()); + assertThat(database.getSchema().getEncoding()).isEqualTo("UTF-8"); }); } } diff --git a/engine/src/test/java/com/arcadedb/serializer/JavaBinarySerializerTest.java b/engine/src/test/java/com/arcadedb/serializer/JavaBinarySerializerTest.java index ec4f875000..2f1684288c 100644 --- a/engine/src/test/java/com/arcadedb/serializer/JavaBinarySerializerTest.java +++ b/engine/src/test/java/com/arcadedb/serializer/JavaBinarySerializerTest.java @@ -26,11 +26,12 @@ import com.arcadedb.schema.EdgeType; import com.arcadedb.schema.Type; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class JavaBinarySerializerTest extends TestHelper { @Test @@ -43,14 +44,14 @@ public void testDocumentTransient() throws IOException, ClassNotFoundException { doc1.writeExternal(buffer); buffer.flush(); - Assertions.assertTrue(arrayOut.size() > 0); + assertThat(arrayOut.size() > 0).isTrue(); final MutableDocument doc2 = database.newDocument("Doc"); try (final ByteArrayInputStream arrayIn = new ByteArrayInputStream(arrayOut.toByteArray()); final ObjectInput in = new ObjectInputStream(arrayIn)) { doc2.readExternal(in); - Assertions.assertEquals(doc1, doc2); - Assertions.assertEquals(doc1.toMap(), doc2.toMap()); + assertThat(doc2).isEqualTo(doc1); + assertThat(doc2.toMap()).isEqualTo(doc1.toMap()); } } } @@ -68,14 +69,14 @@ public void testDocumentPersistent() throws IOException, ClassNotFoundException doc1.writeExternal(buffer); buffer.flush(); - Assertions.assertTrue(arrayOut.size() > 0); + assertThat(arrayOut.size() > 0).isTrue(); final MutableDocument doc2 = database.newDocument("Doc"); try (final ByteArrayInputStream arrayIn = new ByteArrayInputStream(arrayOut.toByteArray()); final ObjectInput in = new ObjectInputStream(arrayIn)) { doc2.readExternal(in); - Assertions.assertEquals(doc1, doc2); - Assertions.assertEquals(doc1.toMap(), doc2.toMap()); + assertThat(doc2).isEqualTo(doc1); + assertThat(doc2.toMap()).isEqualTo(doc1.toMap()); } } } @@ -90,14 +91,14 @@ public void testVertexTransient() throws IOException, ClassNotFoundException { doc1.writeExternal(buffer); buffer.flush(); - Assertions.assertTrue(arrayOut.size() > 0); + assertThat(arrayOut.size() > 0).isTrue(); final MutableVertex docTest = database.newVertex("Doc"); try (final ByteArrayInputStream arrayIn = new ByteArrayInputStream(arrayOut.toByteArray()); final ObjectInput in = new ObjectInputStream(arrayIn)) { docTest.readExternal(in); - Assertions.assertEquals(doc1, docTest); - Assertions.assertEquals(doc1.toMap(), docTest.toMap()); + assertThat(docTest).isEqualTo(doc1); + assertThat(docTest.toMap()).isEqualTo(doc1.toMap()); } } } @@ -119,16 +120,16 @@ public void testVertexPersistent() throws IOException, ClassNotFoundException { v1.writeExternal(buffer); buffer.flush(); - Assertions.assertTrue(arrayOut.size() > 0); + assertThat(arrayOut.size() > 0).isTrue(); final MutableVertex vTest = database.newVertex("Doc"); try (final ByteArrayInputStream arrayIn = new ByteArrayInputStream(arrayOut.toByteArray()); final ObjectInput in = new ObjectInputStream(arrayIn)) { vTest.readExternal(in); - Assertions.assertEquals(v1, vTest); - Assertions.assertEquals(v1.toMap(), vTest.toMap()); - Assertions.assertEquals(v1.getOutEdgesHeadChunk(), vTest.getOutEdgesHeadChunk()); - Assertions.assertEquals(v1.getInEdgesHeadChunk(), vTest.getInEdgesHeadChunk()); + assertThat(vTest).isEqualTo(v1); + assertThat(vTest.toMap()).isEqualTo(v1.toMap()); + assertThat(vTest.getOutEdgesHeadChunk()).isEqualTo(v1.getOutEdgesHeadChunk()); + assertThat(vTest.getInEdgesHeadChunk()).isEqualTo(v1.getInEdgesHeadChunk()); } } } @@ -149,16 +150,16 @@ public void testEdgePersistent() throws IOException, ClassNotFoundException { edge1.writeExternal(buffer); buffer.flush(); - Assertions.assertTrue(arrayOut.size() > 0); + assertThat(arrayOut.size() > 0).isTrue(); final MutableEdge edgeTest = new MutableEdge(database, type, null); try (final ByteArrayInputStream arrayIn = new ByteArrayInputStream(arrayOut.toByteArray()); final ObjectInput in = new ObjectInputStream(arrayIn)) { edgeTest.readExternal(in); - Assertions.assertEquals(edge1, edgeTest); - Assertions.assertEquals(edge1.toMap(), edgeTest.toMap()); - Assertions.assertEquals(edge1.getOut(), edgeTest.getOut()); - Assertions.assertEquals(edge1.getIn(), edgeTest.getIn()); + assertThat(edgeTest).isEqualTo(edge1); + assertThat(edgeTest.toMap()).isEqualTo(edge1.toMap()); + assertThat(edgeTest.getOut()).isEqualTo(edge1.getOut()); + assertThat(edgeTest.getIn()).isEqualTo(edge1.getIn()); } } } diff --git a/engine/src/test/java/com/arcadedb/serializer/SerializerTest.java b/engine/src/test/java/com/arcadedb/serializer/SerializerTest.java index f0349ad036..2bc1f88eb0 100644 --- a/engine/src/test/java/com/arcadedb/serializer/SerializerTest.java +++ b/engine/src/test/java/com/arcadedb/serializer/SerializerTest.java @@ -29,13 +29,15 @@ import com.arcadedb.database.MutableEmbeddedDocument; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Type; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.math.*; import java.nio.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class SerializerTest extends TestHelper { @Test @@ -80,66 +82,66 @@ public void testVarNumber() { binary.rewind(); buffer.rewind(); - Assertions.assertEquals(0, binary.getUnsignedNumber()); - Assertions.assertEquals(0, buffer.getUnsignedNumber()); - Assertions.assertEquals(3, binary.getUnsignedNumber()); - Assertions.assertEquals(3, buffer.getUnsignedNumber()); - Assertions.assertEquals(Short.MIN_VALUE, binary.getUnsignedNumber()); - Assertions.assertEquals(Short.MIN_VALUE, buffer.getUnsignedNumber()); - Assertions.assertEquals(Short.MAX_VALUE, binary.getUnsignedNumber()); - Assertions.assertEquals(Short.MAX_VALUE, buffer.getUnsignedNumber()); - Assertions.assertEquals(Integer.MIN_VALUE, binary.getUnsignedNumber()); - Assertions.assertEquals(Integer.MIN_VALUE, buffer.getUnsignedNumber()); - Assertions.assertEquals(Integer.MAX_VALUE, binary.getUnsignedNumber()); - Assertions.assertEquals(Integer.MAX_VALUE, buffer.getUnsignedNumber()); - Assertions.assertEquals(Long.MIN_VALUE, binary.getUnsignedNumber()); - Assertions.assertEquals(Long.MIN_VALUE, buffer.getUnsignedNumber()); - Assertions.assertEquals(Long.MAX_VALUE, binary.getUnsignedNumber()); - Assertions.assertEquals(Long.MAX_VALUE, buffer.getUnsignedNumber()); - - Assertions.assertEquals(0, binary.getNumber()); - Assertions.assertEquals(0, buffer.getNumber()); - Assertions.assertEquals(3, binary.getNumber()); - Assertions.assertEquals(3, buffer.getNumber()); - Assertions.assertEquals(Short.MIN_VALUE, binary.getNumber()); - Assertions.assertEquals(Short.MIN_VALUE, buffer.getNumber()); - Assertions.assertEquals(Short.MAX_VALUE, binary.getNumber()); - Assertions.assertEquals(Short.MAX_VALUE, buffer.getNumber()); - Assertions.assertEquals(Integer.MIN_VALUE, binary.getNumber()); - Assertions.assertEquals(Integer.MIN_VALUE, buffer.getNumber()); - Assertions.assertEquals(Integer.MAX_VALUE, binary.getNumber()); - Assertions.assertEquals(Integer.MAX_VALUE, buffer.getNumber()); - Assertions.assertEquals(Long.MIN_VALUE, binary.getNumber()); - Assertions.assertEquals(Long.MIN_VALUE, buffer.getNumber()); - Assertions.assertEquals(Long.MAX_VALUE, binary.getNumber()); - Assertions.assertEquals(Long.MAX_VALUE, buffer.getNumber()); - - Assertions.assertEquals(0, binary.getShort()); - Assertions.assertEquals(0, buffer.getShort()); - - Assertions.assertEquals(Short.MIN_VALUE, binary.getShort()); - Assertions.assertEquals(Short.MIN_VALUE, buffer.getShort()); - - Assertions.assertEquals(Short.MAX_VALUE, binary.getShort()); - Assertions.assertEquals(Short.MAX_VALUE, buffer.getShort()); - - Assertions.assertEquals(0, binary.getInt()); - Assertions.assertEquals(0, buffer.getInt()); - - Assertions.assertEquals(Integer.MIN_VALUE, binary.getInt()); - Assertions.assertEquals(Integer.MIN_VALUE, buffer.getInt()); - - Assertions.assertEquals(Integer.MAX_VALUE, binary.getInt()); - Assertions.assertEquals(Integer.MAX_VALUE, buffer.getInt()); - - Assertions.assertEquals(0l, binary.getLong()); - Assertions.assertEquals(0l, buffer.getLong()); - - Assertions.assertEquals(Long.MIN_VALUE, binary.getLong()); - Assertions.assertEquals(Long.MIN_VALUE, buffer.getLong()); - - Assertions.assertEquals(Long.MAX_VALUE, binary.getLong()); - Assertions.assertEquals(Long.MAX_VALUE, buffer.getLong()); + assertThat(binary.getUnsignedNumber()).isEqualTo(0); + assertThat(buffer.getUnsignedNumber()).isEqualTo(0); + assertThat(binary.getUnsignedNumber()).isEqualTo(3); + assertThat(buffer.getUnsignedNumber()).isEqualTo(3); + assertThat(binary.getUnsignedNumber()).isEqualTo(Short.MIN_VALUE); + assertThat(buffer.getUnsignedNumber()).isEqualTo(Short.MIN_VALUE); + assertThat(binary.getUnsignedNumber()).isEqualTo(Short.MAX_VALUE); + assertThat(buffer.getUnsignedNumber()).isEqualTo(Short.MAX_VALUE); + assertThat(binary.getUnsignedNumber()).isEqualTo(Integer.MIN_VALUE); + assertThat(buffer.getUnsignedNumber()).isEqualTo(Integer.MIN_VALUE); + assertThat(binary.getUnsignedNumber()).isEqualTo(Integer.MAX_VALUE); + assertThat(buffer.getUnsignedNumber()).isEqualTo(Integer.MAX_VALUE); + assertThat(binary.getUnsignedNumber()).isEqualTo(Long.MIN_VALUE); + assertThat(buffer.getUnsignedNumber()).isEqualTo(Long.MIN_VALUE); + assertThat(binary.getUnsignedNumber()).isEqualTo(Long.MAX_VALUE); + assertThat(buffer.getUnsignedNumber()).isEqualTo(Long.MAX_VALUE); + + assertThat(binary.getNumber()).isEqualTo(0); + assertThat(buffer.getNumber()).isEqualTo(0); + assertThat(binary.getNumber()).isEqualTo(3); + assertThat(buffer.getNumber()).isEqualTo(3); + assertThat(binary.getNumber()).isEqualTo(Short.MIN_VALUE); + assertThat(buffer.getNumber()).isEqualTo(Short.MIN_VALUE); + assertThat(binary.getNumber()).isEqualTo(Short.MAX_VALUE); + assertThat(buffer.getNumber()).isEqualTo(Short.MAX_VALUE); + assertThat(binary.getNumber()).isEqualTo(Integer.MIN_VALUE); + assertThat(buffer.getNumber()).isEqualTo(Integer.MIN_VALUE); + assertThat(binary.getNumber()).isEqualTo(Integer.MAX_VALUE); + assertThat(buffer.getNumber()).isEqualTo(Integer.MAX_VALUE); + assertThat(binary.getNumber()).isEqualTo(Long.MIN_VALUE); + assertThat(buffer.getNumber()).isEqualTo(Long.MIN_VALUE); + assertThat(binary.getNumber()).isEqualTo(Long.MAX_VALUE); + assertThat(buffer.getNumber()).isEqualTo(Long.MAX_VALUE); + + assertThat(binary.getShort()).isEqualTo((short) 0); + assertThat(buffer.getShort()).isEqualTo((short) 0); + + assertThat(binary.getShort()).isEqualTo(Short.MIN_VALUE); + assertThat(buffer.getShort()).isEqualTo(Short.MIN_VALUE); + + assertThat(binary.getShort()).isEqualTo(Short.MAX_VALUE); + assertThat(buffer.getShort()).isEqualTo(Short.MAX_VALUE); + + assertThat(binary.getInt()).isEqualTo(0); + assertThat(buffer.getInt()).isEqualTo(0); + + assertThat(binary.getInt()).isEqualTo(Integer.MIN_VALUE); + assertThat(buffer.getInt()).isEqualTo(Integer.MIN_VALUE); + + assertThat(binary.getInt()).isEqualTo(Integer.MAX_VALUE); + assertThat(buffer.getInt()).isEqualTo(Integer.MAX_VALUE); + + assertThat(binary.getLong()).isEqualTo(0l); + assertThat(buffer.getLong()).isEqualTo(0l); + + assertThat(binary.getLong()).isEqualTo(Long.MIN_VALUE); + assertThat(buffer.getLong()).isEqualTo(Long.MIN_VALUE); + + assertThat(binary.getLong()).isEqualTo(Long.MAX_VALUE); + assertThat(buffer.getLong()).isEqualTo(Long.MAX_VALUE); } @Test @@ -174,21 +176,21 @@ public void testLiteralPropertiesInDocument() throws ClassNotFoundException { buffer3.getByte(); // SKIP RECORD TYPE final Map record2 = serializer.deserializeProperties(database, buffer3, null, null); - Assertions.assertEquals(Integer.MIN_VALUE, record2.get("minInt")); - Assertions.assertEquals(Integer.MAX_VALUE, record2.get("maxInt")); + assertThat(record2.get("minInt")).isEqualTo(Integer.MIN_VALUE); + assertThat(record2.get("maxInt")).isEqualTo(Integer.MAX_VALUE); - Assertions.assertEquals(Long.MIN_VALUE, record2.get("minLong")); - Assertions.assertEquals(Long.MAX_VALUE, record2.get("maxLong")); + assertThat(record2.get("minLong")).isEqualTo(Long.MIN_VALUE); + assertThat(record2.get("maxLong")).isEqualTo(Long.MAX_VALUE); - Assertions.assertEquals(Short.MIN_VALUE, record2.get("minShort")); - Assertions.assertEquals(Short.MAX_VALUE, record2.get("maxShort")); + assertThat(record2.get("minShort")).isEqualTo(Short.MIN_VALUE); + assertThat(record2.get("maxShort")).isEqualTo(Short.MAX_VALUE); - Assertions.assertEquals(Byte.MIN_VALUE, record2.get("minByte")); - Assertions.assertEquals(Byte.MAX_VALUE, record2.get("maxByte")); + assertThat(record2.get("minByte")).isEqualTo(Byte.MIN_VALUE); + assertThat(record2.get("maxByte")).isEqualTo(Byte.MAX_VALUE); - Assertions.assertTrue(record2.get("decimal") instanceof BigDecimal); - Assertions.assertEquals(new BigDecimal("9876543210.0123456789"), record2.get("decimal")); - Assertions.assertEquals("Miner", record2.get("string")); + assertThat(record2.get("decimal") instanceof BigDecimal).isTrue(); + assertThat(record2.get("decimal")).isEqualTo(new BigDecimal("9876543210.0123456789")); + assertThat(record2.get("string")).isEqualTo("Miner"); }); } @@ -271,29 +273,29 @@ public void testListPropertiesInDocument() throws ClassNotFoundException { buffer3.getByte(); // SKIP RECORD TYPE final Map record2 = serializer.deserializeProperties(database, buffer3, null, null); - Assertions.assertIterableEquals(listOfBooleans, (Iterable) record2.get("listOfBooleans")); - Assertions.assertIterableEquals(listOfBooleans, (Iterable) record2.get("arrayOfBooleans")); + assertThat(record2.get("listOfBooleans")).isEqualTo(listOfBooleans); + assertThat(record2.get("arrayOfBooleans")).isEqualTo(listOfBooleans); - Assertions.assertIterableEquals(listOfIntegers, (Iterable) record2.get("listOfIntegers")); - Assertions.assertIterableEquals(listOfIntegers, (Iterable) record2.get("arrayOfIntegers")); + assertThat(record2.get("listOfIntegers")).isEqualTo(listOfIntegers); + assertThat(record2.get("arrayOfIntegers")).isEqualTo(listOfIntegers); - Assertions.assertIterableEquals(listOfLongs, (Iterable) record2.get("listOfLongs")); - Assertions.assertIterableEquals(listOfLongs, (Iterable) record2.get("arrayOfLongs")); + assertThat(record2.get("listOfLongs")).isEqualTo(listOfLongs); + assertThat(record2.get("arrayOfLongs")).isEqualTo(listOfLongs); - Assertions.assertIterableEquals(listOfShorts, (Iterable) record2.get("listOfShorts")); - Assertions.assertIterableEquals(listOfShorts, (Iterable) record2.get("arrayOfShorts")); + assertThat(record2.get("listOfShorts")).isEqualTo(listOfShorts); + assertThat(record2.get("arrayOfShorts")).isEqualTo(listOfShorts); - Assertions.assertIterableEquals(listOfFloats, (Iterable) record2.get("listOfFloats")); - Assertions.assertIterableEquals(listOfFloats, (Iterable) record2.get("arrayOfFloats")); + assertThat(record2.get("listOfFloats")).isEqualTo(listOfFloats); + assertThat(record2.get("arrayOfFloats")).isEqualTo(listOfFloats); - Assertions.assertIterableEquals(listOfDoubles, (Iterable) record2.get("listOfDoubles")); - Assertions.assertIterableEquals(listOfDoubles, (Iterable) record2.get("arrayOfDoubles")); + assertThat(record2.get("listOfDoubles")).isEqualTo(listOfDoubles); + assertThat(record2.get("arrayOfDoubles")).isEqualTo(listOfDoubles); - Assertions.assertIterableEquals(listOfStrings, (Iterable) record2.get("listOfStrings")); - Assertions.assertIterableEquals(listOfStrings, (Iterable) record2.get("arrayOfStrings")); + assertThat(record2.get("listOfStrings")).isEqualTo(listOfStrings); + assertThat(record2.get("arrayOfStrings")).isEqualTo(listOfStrings); - Assertions.assertIterableEquals(listOfMixed, (Iterable) record2.get("listOfMixed")); - Assertions.assertIterableEquals(listOfMixed, (Iterable) record2.get("arrayOfMixed")); + assertThat(record2.get("listOfMixed")).isEqualTo(listOfMixed); + assertThat(record2.get("arrayOfMixed")).isEqualTo(listOfMixed); }); } @@ -344,11 +346,11 @@ public void testArraysOfPrimitive() throws ClassNotFoundException { buffer3.getByte(); // SKIP RECORD TYPE final Map record2 = serializer.deserializeProperties(database, buffer3, null, null); - Assertions.assertArrayEquals(arrayOfIntegers, (int[]) record2.get("arrayOfIntegers")); - Assertions.assertArrayEquals(arrayOfLongs, (long[]) record2.get("arrayOfLongs")); - Assertions.assertArrayEquals(arrayOfShorts, (short[]) record2.get("arrayOfShorts")); - Assertions.assertArrayEquals(arrayOfFloats, (float[]) record2.get("arrayOfFloats")); - Assertions.assertArrayEquals(arrayOfDoubles, (double[]) record2.get("arrayOfDoubles")); + assertThat((int[]) record2.get("arrayOfIntegers")).isEqualTo(arrayOfIntegers); + assertThat((long[]) record2.get("arrayOfLongs")).isEqualTo(arrayOfLongs); + assertThat((short[]) record2.get("arrayOfShorts")).isEqualTo(arrayOfShorts); + assertThat((float[]) record2.get("arrayOfFloats")).isEqualTo(arrayOfFloats); + assertThat((double[]) record2.get("arrayOfDoubles")).isEqualTo(arrayOfDoubles); }); } @@ -416,14 +418,14 @@ public void testMapPropertiesInDocument() throws ClassNotFoundException { buffer3.getByte(); // SKIP RECORD TYPE final Map record2 = serializer.deserializeProperties(database, buffer3, null, null); - Assertions.assertEquals(mapOfStringsBooleans, record2.get("mapOfStringsBooleans")); - Assertions.assertEquals(mapOfIntegers, record2.get("mapOfIntegers")); - Assertions.assertEquals(mapOfLongs, record2.get("mapOfLongs")); - Assertions.assertEquals(mapOfShorts, record2.get("mapOfShorts")); - Assertions.assertEquals(mapOfFloats, record2.get("mapOfFloats")); - Assertions.assertEquals(mapOfDoubles, record2.get("mapOfDoubles")); - Assertions.assertEquals(mapOfStrings, record2.get("mapOfStrings")); - Assertions.assertEquals(mapOfMixed, record2.get("mapOfMixed")); + assertThat(record2.get("mapOfStringsBooleans")).isEqualTo(mapOfStringsBooleans); + assertThat(record2.get("mapOfIntegers")).isEqualTo(mapOfIntegers); + assertThat(record2.get("mapOfLongs")).isEqualTo(mapOfLongs); + assertThat(record2.get("mapOfShorts")).isEqualTo(mapOfShorts); + assertThat(record2.get("mapOfFloats")).isEqualTo(mapOfFloats); + assertThat(record2.get("mapOfDoubles")).isEqualTo(mapOfDoubles); + assertThat(record2.get("mapOfStrings")).isEqualTo(mapOfStrings); + assertThat(record2.get("mapOfMixed")).isEqualTo(mapOfMixed); }); } @@ -456,11 +458,11 @@ public void testEmbedded() throws ClassNotFoundException { buffer3.getByte(); // SKIP RECORD TYPE final Map record2 = serializer.deserializeProperties(database, buffer3, new EmbeddedModifierProperty(testDocument, "embedded"), null); - Assertions.assertEquals(0, record2.get("id")); + assertThat(record2.get("id")).isEqualTo(0); final EmbeddedDocument embeddedDoc = (EmbeddedDocument) record2.get("embedded"); - Assertions.assertEquals(1, embeddedDoc.get("id")); + assertThat(embeddedDoc.get("id")).isEqualTo(1); }); } @@ -500,14 +502,14 @@ public void testListOfEmbedded() throws ClassNotFoundException { buffer3.getByte(); // SKIP RECORD TYPE final Map record2 = serializer.deserializeProperties(database, buffer3, new EmbeddedModifierProperty(testDocument, "embedded"), null); - Assertions.assertEquals(0, record2.get("id")); + assertThat(record2.get("id")).isEqualTo(0); final List embeddedList2 = (List) record2.get("embedded"); - Assertions.assertIterableEquals(embeddedList, embeddedList2); + assertThat(embeddedList).isEqualTo(embeddedList2); for (final Document d : embeddedList2) - Assertions.assertTrue(d instanceof EmbeddedDocument); + assertThat(d instanceof EmbeddedDocument).isTrue(); }); } @@ -550,15 +552,16 @@ public void testMapOfEmbedded() throws ClassNotFoundException { buffer3.getByte(); // SKIP RECORD TYPE final Map record2 = serializer.deserializeProperties(database, buffer3, null, null); - Assertions.assertEquals(0, record2.get("id")); + assertThat(record2.get("id")).isEqualTo(0); final Map embeddedMap2 = (Map) record2.get("embedded"); - Assertions.assertIterableEquals(embeddedMap.entrySet(), embeddedMap2.entrySet()); + assertThat(embeddedMap).isEqualTo(embeddedMap2); +// Assertions.assertIterableEquals(embeddedMap.entrySet(), embeddedMap2.entrySet()); for (final Map.Entry d : embeddedMap2.entrySet()) { - Assertions.assertTrue(d.getKey() instanceof Integer); - Assertions.assertTrue(d.getValue() instanceof EmbeddedDocument); + assertThat(d.getKey() instanceof Integer).isTrue(); + assertThat(d.getValue() instanceof EmbeddedDocument).isTrue(); } }); } diff --git a/engine/src/test/java/com/arcadedb/serializer/json/JSONTest.java b/engine/src/test/java/com/arcadedb/serializer/json/JSONTest.java index f851dab06f..bfba13b384 100644 --- a/engine/src/test/java/com/arcadedb/serializer/json/JSONTest.java +++ b/engine/src/test/java/com/arcadedb/serializer/json/JSONTest.java @@ -19,11 +19,12 @@ package com.arcadedb.serializer.json; import com.arcadedb.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test JSON parser and it support for types. * @@ -36,7 +37,7 @@ public void testDates() { JSONObject json = new JSONObject().put("date", date); final String serialized = json.toString(); JSONObject deserialized = new JSONObject(serialized); - Assertions.assertEquals(json, deserialized); + assertThat(deserialized).isEqualTo(json); } @Test @@ -44,7 +45,7 @@ public void testLists() { JSONObject json = new JSONObject().put("list", Collections.unmodifiableList(List.of(1, 2, 3))); final String serialized = json.toString(); JSONObject deserialized = new JSONObject(serialized); - Assertions.assertEquals(json, deserialized); + assertThat(deserialized).isEqualTo(json); } @Test @@ -54,7 +55,7 @@ public void testListsOfLists() { JSONObject json = new JSONObject().put("list", list); final String serialized = json.toString(); JSONObject deserialized = new JSONObject(serialized); - Assertions.assertEquals(json, deserialized); + assertThat(deserialized).isEqualTo(json); } @Test @@ -65,7 +66,7 @@ public void testDatesWithFormat() { final String serialized = json.toString(); JSONObject deserialized = new JSONObject(serialized); - Assertions.assertEquals(json, deserialized); + assertThat(deserialized).isEqualTo(json); } @Test @@ -78,19 +79,19 @@ public void testEmbeddedMaps() { final String serialized = json.toString(); JSONObject deserialized = new JSONObject(serialized); - Assertions.assertEquals(json, deserialized); + assertThat(deserialized).isEqualTo(json); } @Test public void testMalformedTrailingCommas() { JSONObject json = new JSONObject("{'array':[1,2,3,]}"); - Assertions.assertEquals(4, json.getJSONArray("array").length()); + assertThat(json.getJSONArray("array").length()).isEqualTo(4); json = new JSONObject("{'array':[{'a':3},]}"); - Assertions.assertEquals(2, json.getJSONArray("array").length()); + assertThat(json.getJSONArray("array").length()).isEqualTo(2); // NOT SUPPORTED BY GSON LIBRARY // json = new JSONObject("{'map':{'a':3,}"); -// Assertions.assertEquals(2, json.getJSONArray("map").length()); +// Assertions.assertThat(json.getJSONArray("map").length()).isEqualTo(2); } @Test @@ -100,9 +101,9 @@ public void testNaN() { json.put("arrayNan", new JSONArray().put(0).put(Double.NaN).put(5)); json.validate(); - Assertions.assertEquals(json.getInt("nan"), 0); - Assertions.assertEquals(json.getJSONArray("arrayNan").get(0), 0); - Assertions.assertEquals(json.getJSONArray("arrayNan").get(1), 0); - Assertions.assertEquals(json.getJSONArray("arrayNan").get(2), 5); + assertThat(json.getInt("nan")).isEqualTo(0); + assertThat(json.getJSONArray("arrayNan").get(0)).isEqualTo(0); + assertThat(json.getJSONArray("arrayNan").get(1)).isEqualTo(0); + assertThat(json.getJSONArray("arrayNan").get(2)).isEqualTo(5); } } diff --git a/engine/src/test/java/performance/LocalDatabaseBenchmark.java b/engine/src/test/java/performance/LocalDatabaseBenchmark.java index fad727fd12..adacd3efc1 100644 --- a/engine/src/test/java/performance/LocalDatabaseBenchmark.java +++ b/engine/src/test/java/performance/LocalDatabaseBenchmark.java @@ -26,11 +26,12 @@ import com.arcadedb.exception.ConcurrentModificationException; import com.arcadedb.graph.MutableVertex; import com.arcadedb.query.select.SelectCompiled; -import org.junit.jupiter.api.Assertions; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + public class LocalDatabaseBenchmark { private static final int TOTAL = 1_000; private static final int BATCH_TX = 200; @@ -115,11 +116,11 @@ public void run() { List allIds = checkRecordSequence(database); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, allIds.size()); + assertThat(allIds.size()).isEqualTo(TOTAL * CONCURRENT_THREADS); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, totalRecordsOnClusters); + assertThat(totalRecordsOnClusters).isEqualTo(TOTAL * CONCURRENT_THREADS); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, database.countType("User", true)); + assertThat(database.countType("User", true)).isEqualTo(TOTAL * CONCURRENT_THREADS); // queryNative(); // querySQL(); @@ -143,7 +144,7 @@ private void queryNative() { .property("id").eq().parameter("id")// .compile(); for (int i = 0; i < TOTAL * CONCURRENT_THREADS; i++) { - Assertions.assertEquals(1, cached.parameter("id", i).vertices().toList().size()); + assertThat(cached.parameter("id", i).vertices().toList().size()).isEqualTo(1); } System.out.println("NATIVE " + (System.currentTimeMillis() - begin) + "ms"); } @@ -151,9 +152,9 @@ private void queryNative() { private void querySQL() { long begin = System.currentTimeMillis(); for (int i = 0; i < TOTAL * CONCURRENT_THREADS; i++) { - Assertions.assertEquals(1, database.query("sql", - "select from User where id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ?", - i, i, i, i, i, i, i, i, i, i).toVertices().size()); + assertThat(database.query("sql", + "select from User where id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ? and id = ?", + i, i, i, i, i, i, i, i, i, i).toVertices().size()).isEqualTo(1); } System.out.println("SQL " + (System.currentTimeMillis() - begin) + "ms"); } diff --git a/engine/src/test/java/performance/PerformanceComplexIndexTest.java b/engine/src/test/java/performance/PerformanceComplexIndexTest.java index ed7e67b740..b08fbdfecf 100644 --- a/engine/src/test/java/performance/PerformanceComplexIndexTest.java +++ b/engine/src/test/java/performance/PerformanceComplexIndexTest.java @@ -114,11 +114,11 @@ private void run() { // System.out.println("Lookup all the keys..."); // for (long id = 0; id < TOT; ++id) { // final Cursor records = database.lookupByKey(TYPE_NAME, new String[] { "id" }, new Object[] { id }); -// Assertions.assertNotNull(records); -// Assertions.assertEquals(1, records.size(), "Wrong result for lookup of key " + id); +// Assertions.assertThat(records).isNotNull(); +// Assertions.assertThat(records.size().isEqualTo(1), "Wrong result for lookup of key " + id); // // final Document record = (Document) records.next().getRecord(); -// Assertions.assertEquals(id, record.get("id")); +// Assertions.assertThat(record.get("id")).isEqualTo(id); // // if (id % 100000 == 0) // System.out.println("Checked " + id + " lookups in " + (System.currentTimeMillis() - begin) + "ms"); diff --git a/engine/src/test/java/performance/PerformanceIndexCompaction.java b/engine/src/test/java/performance/PerformanceIndexCompaction.java index 86de3b9be8..87bb2215ec 100644 --- a/engine/src/test/java/performance/PerformanceIndexCompaction.java +++ b/engine/src/test/java/performance/PerformanceIndexCompaction.java @@ -27,11 +27,12 @@ import com.arcadedb.index.IndexInternal; import com.arcadedb.index.RangeIndex; import com.arcadedb.log.LogManager; -import org.junit.jupiter.api.Assertions; import java.io.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class PerformanceIndexCompaction { public static void main(final String[] args) throws Exception { new PerformanceIndexCompaction().run(); @@ -51,12 +52,12 @@ private void run() throws IOException, InterruptedException { LogManager.instance().log(this, Level.INFO, "Total indexes items %d", totalIndexed); for (final Index index : database.getSchema().getIndexes()) - Assertions.assertTrue(((IndexInternal) index).compact()); + assertThat(((IndexInternal) index).compact()).isTrue(); final long totalIndexed2 = countIndexedItems(database); - Assertions.assertEquals(total, totalIndexed); - Assertions.assertEquals(totalIndexed, totalIndexed2); + assertThat(totalIndexed).isEqualTo(total); + assertThat(totalIndexed2).isEqualTo(totalIndexed); System.out.println("Compaction done"); diff --git a/engine/src/test/java/performance/PerformanceInsertGraphIndexTest.java b/engine/src/test/java/performance/PerformanceInsertGraphIndexTest.java index 887f1513d5..29d1a3ec82 100644 --- a/engine/src/test/java/performance/PerformanceInsertGraphIndexTest.java +++ b/engine/src/test/java/performance/PerformanceInsertGraphIndexTest.java @@ -33,12 +33,13 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.VertexType; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import java.io.*; import java.util.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Inserts a graph. Configurations: * - 100M edges on 10,000 vertices with respectively 10,000 to all the other nodes and itself. 10,000 * 10,000 = 100M edges @@ -261,10 +262,10 @@ private void checkEdgeIds() { int j = 0; for (; j < expectedTotalEdges; j++) { final IndexCursor edgeCursor = index.get(new Object[] { j }); - Assertions.assertTrue(edgeCursor.hasNext()); + assertThat(edgeCursor.hasNext()).isTrue(); final Edge e = edgeCursor.next().asEdge(true); - Assertions.assertNotNull(e); - Assertions.assertEquals(j, e.get("id")); + assertThat(e).isNotNull(); + assertThat(e.get("id")).isEqualTo(j); if (j % 1_000_000 == 0) { final long elapsed = System.currentTimeMillis() - begin; @@ -294,13 +295,13 @@ private void countEdges(final Vertex[] cachedVertices) { for (; i < VERTICES; ++i) { for (final Edge e : cachedVertices[i].getEdges(Vertex.DIRECTION.OUT, EDGE_TYPE_NAME)) { if (EDGE_IDS) - Assertions.assertNotNull(e.get("id")); + assertThat(e.get("id")).isNotNull(); ++outEdges; } for (final Edge e : cachedVertices[i].getEdges(Vertex.DIRECTION.IN, EDGE_TYPE_NAME)) { if (EDGE_IDS) - Assertions.assertNotNull(e.get("id")); + assertThat(e.get("id")).isNotNull(); ++inEdges; } @@ -322,8 +323,8 @@ private void countEdges(final Vertex[] cachedVertices) { final int expectedTotalEdges = VERTICES * EDGES_PER_VERTEX; - Assertions.assertEquals(expectedTotalEdges, inEdges); - Assertions.assertEquals(expectedTotalEdges, outEdges); + assertThat(inEdges).isEqualTo(expectedTotalEdges); + assertThat(outEdges).isEqualTo(expectedTotalEdges); } finally { database.commit(); diff --git a/engine/src/test/java/performance/PerformanceParsing.java b/engine/src/test/java/performance/PerformanceParsing.java index c33ae273ae..897856d72d 100644 --- a/engine/src/test/java/performance/PerformanceParsing.java +++ b/engine/src/test/java/performance/PerformanceParsing.java @@ -24,10 +24,12 @@ import com.arcadedb.graph.MutableVertex; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + public class PerformanceParsing { private static final String TYPE_NAME = "Person"; private static final int MAX_LOOPS = 10000000; @@ -64,7 +66,7 @@ public void onComplete(final ResultSet rs) { while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); + assertThat(record).isNotNull(); } } @@ -80,8 +82,8 @@ public void onError(final Exception exception) { } finally { database.close(); - Assertions.assertEquals(MAX_LOOPS, ok.get()); - Assertions.assertEquals(0, error.get()); + assertThat(ok.get()).isEqualTo(MAX_LOOPS); + assertThat(error.get()).isEqualTo(0); } } } diff --git a/engine/src/test/java/performance/PerformanceSQLSelect.java b/engine/src/test/java/performance/PerformanceSQLSelect.java index d16c8fc161..966ea2fe46 100644 --- a/engine/src/test/java/performance/PerformanceSQLSelect.java +++ b/engine/src/test/java/performance/PerformanceSQLSelect.java @@ -21,10 +21,11 @@ import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + public class PerformanceSQLSelect extends TestHelper { private static final String TYPE_NAME = "Person"; private static final int MAX_LOOPS = 10; @@ -50,8 +51,8 @@ private void run() { final ResultSet rs = database.command("SQL", "select from " + TYPE_NAME + " where id < 1l"); while (rs.hasNext()) { final Result record = rs.next(); - Assertions.assertNotNull(record); - Assertions.assertTrue((long) record.getProperty("id") < 1); + assertThat(record).isNotNull(); + assertThat((long) record.getProperty("id") < 1).isTrue(); row.incrementAndGet(); } diff --git a/engine/src/test/java/performance/PerformanceVertexIndexTest.java b/engine/src/test/java/performance/PerformanceVertexIndexTest.java index 8d70b00e37..7bbc34d401 100644 --- a/engine/src/test/java/performance/PerformanceVertexIndexTest.java +++ b/engine/src/test/java/performance/PerformanceVertexIndexTest.java @@ -32,12 +32,15 @@ import com.arcadedb.log.LogManager; import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; -import org.junit.jupiter.api.Assertions; + import java.io.*; import java.util.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Fail.fail; + public class PerformanceVertexIndexTest { private static final int TOT = 10_000_000; private static final int COMPACTION_RAM_MB = 1024; // 1GB @@ -59,7 +62,7 @@ public void run() { try { compaction(); } catch (final Exception e) { - Assertions.fail(e); + fail(e); } } }, 0); @@ -70,7 +73,7 @@ public void run() { private void compaction() throws IOException, InterruptedException { try (final Database database = new DatabaseFactory(PerformanceTest.DATABASE_PATH).open()) { for (final Index index : database.getSchema().getIndexes()) - Assertions.assertTrue(((IndexInternal) index).compact()); + assertThat(((IndexInternal) index).compact()).isTrue(); } } @@ -133,7 +136,7 @@ private void insertData() { public void call(final Throwable exception) { LogManager.instance().log(this, Level.INFO, "TEST: ERROR: " + exception); exception.printStackTrace(); - Assertions.fail(exception); + fail(exception); } }); @@ -198,11 +201,12 @@ private void checkLookups(final int step) { for (long id = 0; id < TOT; id += step) { final IndexCursor records = database.lookupByKey(TYPE_NAME, new String[] { "id" }, new Object[] { id }); - Assertions.assertNotNull(records); - Assertions.assertTrue(records.hasNext(), "Wrong result for lookup of key " + id); + assertThat(records.hasNext()) + .as("Wrong result for lookup of key " + id) + .isTrue(); final Document record = (Document) records.next().getRecord(); - Assertions.assertEquals("" + id, record.get("id")); + assertThat(record.get("id")).isEqualTo("" + id); checked++; diff --git a/graphql/src/test/java/com/arcadedb/graphql/AbstractGraphQLNativeLanguageDirectivesTest.java b/graphql/src/test/java/com/arcadedb/graphql/AbstractGraphQLNativeLanguageDirectivesTest.java index 6d1862db65..b4d8b36af2 100644 --- a/graphql/src/test/java/com/arcadedb/graphql/AbstractGraphQLNativeLanguageDirectivesTest.java +++ b/graphql/src/test/java/com/arcadedb/graphql/AbstractGraphQLNativeLanguageDirectivesTest.java @@ -20,11 +20,12 @@ import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public abstract class AbstractGraphQLNativeLanguageDirectivesTest extends AbstractGraphQLTest { protected int getExpectedPropertiesMetadata() { return 3; @@ -35,22 +36,23 @@ public void testUseTypeDefinitionForReturn() { executeTest((database) -> { defineTypes(database); - try (final ResultSet resultSet = database.query("graphql", "{ bookByName(bookNameParameter: \"Harry Potter and the Philosopher's Stone\")}")) { - Assertions.assertTrue(resultSet.hasNext()); + try (final ResultSet resultSet = database.query("graphql", + "{ bookByName(bookNameParameter: \"Harry Potter and the Philosopher's Stone\")}")) { + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); - Assertions.assertEquals(4 + getExpectedPropertiesMetadata(), record.getPropertyNames().size()); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); - Assertions.assertEquals("Harry Potter and the Philosopher's Stone", record.getProperty("name")); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(record.getPropertyNames().size()).isEqualTo(4 + getExpectedPropertiesMetadata()); + assertThat(record.>getProperty("authors")).hasSize(1); + assertThat(record.getProperty("name")).isEqualTo("Harry Potter and the Philosopher's Stone"); + assertThat(resultSet.hasNext()).isFalse(); } try (final ResultSet resultSet = database.query("graphql", "{ bookByName(bookNameParameter: \"Mr. brain\") }")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); - Assertions.assertEquals(4 + getExpectedPropertiesMetadata(), record.getPropertyNames().size()); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); - Assertions.assertEquals("Mr. brain", record.getProperty("name")); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(record.getPropertyNames().size()).isEqualTo(4 + getExpectedPropertiesMetadata()); + assertThat(record.>getProperty("authors")).hasSize(1); + assertThat(record.getProperty("name")).isEqualTo("Mr. brain"); + assertThat(resultSet.hasNext()).isFalse(); } return null; @@ -64,19 +66,20 @@ public void testCustomDefinitionForReturn() { try (final ResultSet resultSet = database.query("graphql", "{ bookByName(bookNameParameter: \"Harry Potter and the Philosopher's Stone\"){ id name pageCount } }")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); - Assertions.assertEquals(3 + getExpectedPropertiesMetadata(), record.getPropertyNames().size()); - Assertions.assertEquals("Harry Potter and the Philosopher's Stone", record.getProperty("name")); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(record.getPropertyNames().size()).isEqualTo(3 + getExpectedPropertiesMetadata()); + assertThat(record.getProperty("name")).isEqualTo("Harry Potter and the Philosopher's Stone"); + assertThat(resultSet.hasNext()).isFalse(); } - try (final ResultSet resultSet = database.query("graphql", "{ bookByName(bookNameParameter: \"Mr. brain\"){ id name pageCount } }")) { - Assertions.assertTrue(resultSet.hasNext()); + try (final ResultSet resultSet = database.query("graphql", + "{ bookByName(bookNameParameter: \"Mr. brain\"){ id name pageCount } }")) { + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); - Assertions.assertEquals(3 + getExpectedPropertiesMetadata(), record.getPropertyNames().size()); - Assertions.assertEquals("Mr. brain", record.getProperty("name")); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(record.getPropertyNames().size()).isEqualTo(3 + getExpectedPropertiesMetadata()); + assertThat(record.getProperty("name")).isEqualTo("Mr. brain"); + assertThat(resultSet.hasNext()).isFalse(); } return null; diff --git a/graphql/src/test/java/com/arcadedb/graphql/GraphQLBasicTest.java b/graphql/src/test/java/com/arcadedb/graphql/GraphQLBasicTest.java index 21af07d9de..86ceb2e92d 100644 --- a/graphql/src/test/java/com/arcadedb/graphql/GraphQLBasicTest.java +++ b/graphql/src/test/java/com/arcadedb/graphql/GraphQLBasicTest.java @@ -22,11 +22,14 @@ import com.arcadedb.exception.CommandParsingException; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.*; + public class GraphQLBasicTest extends AbstractGraphQLTest { @Test @@ -61,18 +64,18 @@ public void ridMapping() { " }" +// "}" +// "}")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); record.toJSON(); rid = record.getIdentity().get(); - Assertions.assertNotNull(rid); + assertThat(rid).isNotNull(); - Assertions.assertEquals(8, record.getPropertyNames().size()); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); + assertThat(record.getPropertyNames()).hasSize(8); + assertThat(((Collection) record.getProperty("authors"))).hasSize(1); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); } return null; @@ -85,21 +88,21 @@ public void bookByName() { defineTypes(database); try (final ResultSet resultSet = database.query("graphql", "{ bookByName(name: \"Harry Potter and the Philosopher's Stone\")}")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); - Assertions.assertEquals(7, record.getPropertyNames().size()); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); - Assertions.assertEquals("Harry Potter and the Philosopher's Stone", record.getProperty("name")); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(record.getPropertyNames()).hasSize(7); + assertThat(((Collection) record.getProperty("authors"))).hasSize(1); + assertThat(record.getProperty("name")).isEqualTo("Harry Potter and the Philosopher's Stone"); + assertThat(resultSet.hasNext()).isFalse(); } try (final ResultSet resultSet = database.query("graphql", "{ bookByName(name: \"Mr. brain\") }")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); - Assertions.assertEquals(7, record.getPropertyNames().size()); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); - Assertions.assertEquals("Mr. brain", record.getProperty("name")); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(record.getPropertyNames()).hasSize(7); + assertThat(((Collection) record.getProperty("authors"))).hasSize(1); + assertThat(record.getProperty("name")).isEqualTo("Mr. brain"); + assertThat(resultSet.hasNext()).isFalse(); } return null; @@ -113,7 +116,7 @@ public void bookByNameWrongParams() { try { database.query("graphql", "{ bookByName(wrong: \"Mr. brain\") }"); - Assertions.fail(); + fail(); } catch (final CommandParsingException e) { // EXPECTED } @@ -144,17 +147,17 @@ public void allBooks() { database.command("graphql", types); try (final ResultSet resultSet = database.query("graphql", "{ books }")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); Result record = resultSet.next(); - Assertions.assertEquals(7, record.getPropertyNames().size()); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); + assertThat(record.getPropertyNames()).hasSize(7); + assertThat(((Collection) record.getProperty("authors"))).hasSize(1); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); record = resultSet.next(); - Assertions.assertEquals(7, record.getPropertyNames().size()); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); + assertThat(record.getPropertyNames()).hasSize(7); + assertThat(((Collection) record.getProperty("authors"))).hasSize(1); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); } return null; @@ -183,17 +186,17 @@ public void allBooksWrongRelationshipDirective() { database.command("graphql", types); try (final ResultSet resultSet = database.query("graphql", "{ books { id\n name\n pageCount\n authors @relationship(type: \"WRONG\", direction: IN)} }")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); Result record = resultSet.next(); - Assertions.assertEquals(7, record.getPropertyNames().size()); - Assertions.assertEquals(0, countIterable(record.getProperty("authors"))); + assertThat(record.getPropertyNames()).hasSize(7); + assertThat(countIterable(record.getProperty("authors"))).isEqualTo(0); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); record = resultSet.next(); - Assertions.assertEquals(7, record.getPropertyNames().size()); - Assertions.assertEquals(0, countIterable(record.getProperty("authors"))); + assertThat(record.getPropertyNames()).hasSize(7); + assertThat(countIterable(record.getProperty("authors"))).isEqualTo(0); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); } return null; @@ -222,17 +225,17 @@ public void queryWhereCondition() { database.command("graphql", types); try (final ResultSet resultSet = database.query("graphql", "{ books( where: \"name = 'Mr. brain'\" ) }")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result record = resultSet.next(); - Assertions.assertEquals(7, record.getPropertyNames().size()); + assertThat(record.getPropertyNames()).hasSize(7); - Assertions.assertEquals("book-2", record.getProperty("id")); - Assertions.assertEquals("Mr. brain", record.getProperty("name")); - Assertions.assertEquals(422, (Integer) record.getProperty("pageCount")); + assertThat(record.getProperty("id")).isEqualTo("book-2"); + assertThat(record.getProperty("name")).isEqualTo("Mr. brain"); + assertThat((Integer) record.getProperty("pageCount")).isEqualTo(422); - Assertions.assertEquals(1, ((Collection) record.getProperty("authors")).size()); + assertThat(((Collection) record.getProperty("authors"))).hasSize(1); - Assertions.assertFalse(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isFalse(); } return null; diff --git a/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserSchemaTest.java b/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserSchemaTest.java index 380401c563..454876925e 100755 --- a/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserSchemaTest.java +++ b/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserSchemaTest.java @@ -18,9 +18,11 @@ */ package com.arcadedb.graphql.parser; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class GraphQLParserSchemaTest { @Test public void testTypes() throws ParseException { @@ -40,7 +42,7 @@ public void testTypes() throws ParseException { " lastName: String\n" +// "}"); - Assertions.assertTrue(ast.children.length > 0); + assertThat(ast.children.length > 0).isTrue(); } @Test @@ -62,7 +64,7 @@ public void errorInvalidCharacters() { " lastName: String\n" +// " wrote: [Book] @relationship(type: \"IS_AUTHOR_OF\", direction: OUT)\n" +// "} dsfjsd fjsdkjf sdk"); - Assertions.fail(ast.treeToString("")); + fail(ast.treeToString("")); } catch (final ParseException e) { // EXPECTED } @@ -87,7 +89,7 @@ public void errorInvalidCharactersWithDirective() { " lastName: String\n" +// " wrote: [Book] @relationship(type: \"IS_AUTHOR_OF\", direction: OUT)\n" +// "} dsfjsd fjsdkjf sdk"); - Assertions.fail(ast.treeToString("")); + fail(ast.treeToString("")); } catch (final ParseException e) { // EXPECTED } diff --git a/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserTest.java b/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserTest.java index 4e399b0e5a..e8bf2e845d 100755 --- a/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserTest.java +++ b/graphql/src/test/java/com/arcadedb/graphql/parser/GraphQLParserTest.java @@ -18,9 +18,10 @@ */ package com.arcadedb.graphql.parser; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class GraphQLParserTest { @Test public void testBasic() throws ParseException { @@ -40,7 +41,7 @@ public void testLookup() throws ParseException { "}" +// "}"); - Assertions.assertTrue(ast.children.length > 0); + assertThat(ast.children.length > 0).isTrue(); //ast.dump("-"); } diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/CypherQueryEngineTest.java b/gremlin/src/test/java/com/arcadedb/gremlin/CypherQueryEngineTest.java index 9a5c02894f..6a7f650a2b 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/CypherQueryEngineTest.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/CypherQueryEngineTest.java @@ -30,10 +30,7 @@ import org.apache.commons.collections.IteratorUtils; import org.apache.commons.configuration2.BaseConfiguration; import org.apache.commons.configuration2.Configuration; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.structure.Vertex; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,12 +38,8 @@ import java.util.*; import java.util.stream.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.notNullValue; +import static org.assertj.core.api.Assertions.assertThat; + public class CypherQueryEngineTest { private static final String DB_PATH = "./target/testsql"; @@ -75,12 +68,12 @@ public void verifyProjectionWithCollectFunction() { // Ensure that the result (set) has the desired format final List results = IteratorUtils.toList(query, 1); - assertThat(results, hasSize(1)); + assertThat(results).hasSize(1); final Result result = results.get(0); - assertThat(result, notNullValue()); - assertThat(result.isProjection(), equalTo(true)); - assertThat(result.getPropertyNames(), hasItems("parent", "children")); + assertThat(result).isNotNull(); + assertThat(result.isProjection()).isTrue(); + assertThat(result.getPropertyNames()).contains("parent", "children"); // Transform rid from result to string as in vertex final Result parentAsResult = result.getProperty("parent"); @@ -88,7 +81,7 @@ public void verifyProjectionWithCollectFunction() { parent.computeIfPresent("@rid", (k, v) -> Objects.toString(v)); parent.put("@cat", "v"); final Map vertexMap = v1.toJSON().toMap(); - assertThat(parent, equalTo(vertexMap)); + assertThat(parent).isEqualTo(vertexMap); // Transform rid from result to string as in vertex final List childrenAsResult = result.getProperty("children"); @@ -97,7 +90,8 @@ public void verifyProjectionWithCollectFunction() { children.forEach(c -> c.put("@cat", "v")); final List> childVertices = Stream.of(v2, v3).map(MutableVertex::toJSON).map(JSONObject::toMap) .collect(Collectors.toList()); - assertThat(children, containsInAnyOrder(childVertices.toArray())); + + assertThat(children).containsExactlyInAnyOrderElementsOf(childVertices); } }); } @@ -114,19 +108,19 @@ public void returnPath() { database.command("cypher", "CREATE (n:Transaction {id:'T1'}) RETURN n"); database.command("cypher", "CREATE (n:City {id:'C1'}) RETURN n"); database.command("cypher", - "MATCH (t:Transaction), (c:City) WHERE t.id = 'T1' AND c.id = 'C1' CREATE path = (t)-[r:IS_IN]->(c) RETURN type(r)"); + "MATCH (t:Transaction), (c:City) WHERE t.id = 'T1' AND c.id = 'C1' CREATE path = (t)-[r:IS_IN]->(c) RETURN type(r)"); try (final ResultSet query = database.query("cypher", - "MATCH path = (t:City{id:'C1'})-[r]-(c:Transaction{id:'T1'}) RETURN path")) { - Assertions.assertTrue(query.hasNext()); + "MATCH path = (t:City{id:'C1'})-[r]-(c:Transaction{id:'T1'}) RETURN path")) { + assertThat(query.hasNext()).isTrue(); final Result r1 = query.next(); - Assertions.assertTrue(query.hasNext()); + assertThat(query.hasNext()).isTrue(); final Result r2 = query.next(); - Assertions.assertTrue(query.hasNext()); + assertThat(query.hasNext()).isTrue(); final Result r3 = query.next(); - Assertions.assertFalse(query.hasNext()); - } + assertThat(query.hasNext()).isFalse(); + } }); } finally { graph.drop(); @@ -146,12 +140,12 @@ public void inheritance() { database.command("sql", "INSERT INTO Transaction set id = 'A'"); try (final ResultSet query = database.query("cypher", "MATCH (n:Transaction) WHERE n.id = 'A' RETURN n")) { - Assertions.assertTrue(query.hasNext()); + assertThat(query.hasNext()).isTrue(); final Result r1 = query.next(); } try (final ResultSet query = database.query("cypher", "MATCH (n:Node) WHERE n.id = 'A' RETURN n")) { - Assertions.assertTrue(query.hasNext()); + assertThat(query.hasNext()).isTrue(); final Result r1 = query.next(); } }); @@ -169,9 +163,9 @@ public void testNullReturn() { try (final BasicDatabase database = graph.getDatabase()) { database.transaction(() -> { try (final ResultSet query = database.command("cypher", "CREATE (n:Person) return n.name")) { - Assertions.assertTrue(query.hasNext()); + assertThat(query.hasNext()).isTrue(); final Result r1 = query.next(); - Assertions.assertNull(r1.getProperty("n.name")); + assertThat(r1.getProperty("n.name")).isNull();; } }); } finally { @@ -189,13 +183,13 @@ public void testReturnOrder() { database.transaction(() -> { database.command("cypher", "CREATE (foo:Order {name: \"hi\", field1: \"value1\", field2: \"value2\"}) RETURN foo;\n"); try (final ResultSet query = database.command("cypher", "MATCH (foo:Order) RETURN foo.name, foo.field2, foo.field1;")) { - Assertions.assertTrue(query.hasNext()); + assertThat(query.hasNext()).isTrue(); final Result r1 = query.next(); final List columns = new ArrayList<>(r1.toMap().keySet()); - Assertions.assertEquals("foo.name", columns.get(0)); - Assertions.assertEquals("foo.field2", columns.get(1)); - Assertions.assertEquals("foo.field1", columns.get(2)); + assertThat(columns.get(0)).isEqualTo("foo.name"); + assertThat(columns.get(1)).isEqualTo("foo.field2"); + assertThat(columns.get(2)).isEqualTo("foo.field1"); } }); } finally { diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/CypherTest.java b/gremlin/src/test/java/com/arcadedb/gremlin/CypherTest.java index aff007e90d..5ee3811d60 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/CypherTest.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/CypherTest.java @@ -29,12 +29,15 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -58,19 +61,19 @@ public void testCypher() { int lastAge = 0; for (; result.hasNext(); ++i) { final Result row = result.next(); - Assertions.assertEquals("Jay", row.getProperty("p.name")); - Assertions.assertTrue(row.getProperty("p.age") instanceof Number); - Assertions.assertTrue((int) row.getProperty("p.age") > lastAge); + assertThat(row.getProperty("p.name")).isEqualTo("Jay"); + assertThat(row.getProperty("p.age") instanceof Number).isTrue(); + assertThat((int) row.getProperty("p.age") > lastAge).isTrue(); lastAge = row.getProperty("p.age"); } - Assertions.assertEquals(25, i); + assertThat(i).isEqualTo(25); } finally { graph.drop(); - Assertions.assertNull(graph.getGremlinJavaEngine()); - Assertions.assertNull(graph.getGremlinGroovyEngine()); + assertThat(graph.getGremlinJavaEngine()).isNull(); + assertThat(graph.getGremlinGroovyEngine()).isNull(); } } @@ -84,15 +87,15 @@ public void testCypherSyntaxError() { try { graph.cypher("MATCH (p::Person) WHERE p.age >= $p1 RETURN p.name, p.age ORDER BY p.age")// .setParameter("p1", 25).execute(); - Assertions.fail(); + fail(""); } catch (final CommandParsingException e) { // EXPECTED } } finally { graph.drop(); - Assertions.assertNull(graph.getGremlinJavaEngine()); - Assertions.assertNull(graph.getGremlinGroovyEngine()); + assertThat(graph.getGremlinJavaEngine()).isNull(); + assertThat(graph.getGremlinGroovyEngine()).isNull(); } } @@ -115,14 +118,14 @@ public void testCypherFromDatabase() { int lastAge = 0; for (; result.hasNext(); ++i) { final Result row = result.next(); - Assertions.assertEquals("Jay", row.getProperty("p.name")); - Assertions.assertTrue(row.getProperty("p.age") instanceof Number); - Assertions.assertTrue((int) row.getProperty("p.age") > lastAge); + assertThat(row.getProperty("p.name")).isEqualTo("Jay"); + assertThat(row.getProperty("p.age") instanceof Number).isTrue(); + assertThat((int) row.getProperty("p.age") > lastAge).isTrue(); lastAge = row.getProperty("p.age"); } - Assertions.assertEquals(25, i); + assertThat(i).isEqualTo(25); } finally { if (database.isTransactionActive()) @@ -139,18 +142,18 @@ public void testCypherParse() { final ArcadeCypher cypherReadOnly = graph.cypher("MATCH (p:Person) WHERE p.age >= 25 RETURN p.name, p.age ORDER BY p.age"); - Assertions.assertTrue(cypherReadOnly.parse().isIdempotent()); - Assertions.assertFalse(cypherReadOnly.parse().isDDL()); + assertThat(cypherReadOnly.parse().isIdempotent()).isTrue(); + assertThat(cypherReadOnly.parse().isDDL()).isFalse(); final ArcadeGremlin cypherWrite = graph.cypher("CREATE (n:Person)"); - Assertions.assertFalse(cypherWrite.parse().isIdempotent()); - Assertions.assertFalse(cypherWrite.parse().isDDL()); + assertThat(cypherWrite.parse().isIdempotent()).isFalse(); + assertThat(cypherWrite.parse().isDDL()).isFalse(); } finally { graph.drop(); - Assertions.assertNull(graph.getGremlinJavaEngine()); - Assertions.assertNull(graph.getGremlinGroovyEngine()); + assertThat(graph.getGremlinJavaEngine()).isNull(); + assertThat(graph.getGremlinGroovyEngine()).isNull(); } } @@ -161,19 +164,19 @@ public void testVertexCreationIdentity() { final ArcadeCypher cypherReadOnly = graph.cypher("CREATE (i:User {name: 'RAMS'}) return i"); - Assertions.assertFalse(cypherReadOnly.parse().isIdempotent()); - Assertions.assertFalse(cypherReadOnly.parse().isDDL()); + assertThat(cypherReadOnly.parse().isIdempotent()).isFalse(); + assertThat(cypherReadOnly.parse().isDDL()).isFalse(); final ResultSet result = cypherReadOnly.execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result row = result.next(); - Assertions.assertNotNull(row.getIdentity().get()); + assertThat(row.getIdentity().get()).isNotNull(); } finally { graph.drop(); - Assertions.assertNull(graph.getGremlinJavaEngine()); - Assertions.assertNull(graph.getGremlinGroovyEngine()); + assertThat(graph.getGremlinJavaEngine()).isNull(); + assertThat(graph.getGremlinGroovyEngine()).isNull(); } } @@ -188,27 +191,27 @@ public void testIssue314() { graph.getDatabase().getSchema().getOrCreateVertexType("Person"); final ResultSet p1 = graph.cypher("CREATE (p:Person {label:\"First\"}) return p").execute(); - Assertions.assertTrue(p1.hasNext()); + assertThat(p1.hasNext()).isTrue(); final RID p1RID = p1.next().getIdentity().get(); final ResultSet p2 = graph.cypher("CREATE (p:Person {label:\"Second\"}) return p").execute(); - Assertions.assertTrue(p2.hasNext()); + assertThat(p2.hasNext()).isTrue(); final RID p2RID = p2.next().getIdentity().get(); final ArcadeCypher query = graph.cypher("MATCH (a),(b) WHERE a.label = \"First\" AND b.label = \"Second\" RETURN a,b"); final ResultSet result = query.execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result row = result.next(); - Assertions.assertNotNull(row.getProperty("a")); - Assertions.assertEquals(p1RID, ((Result) row.getProperty("a")).getIdentity().get()); - Assertions.assertNotNull(row.getProperty("b")); - Assertions.assertEquals(p2RID, ((Result) row.getProperty("b")).getIdentity().get()); + assertThat(row.getProperty("a")).isNotNull(); + assertThat(((Result) row.getProperty("a")).getIdentity().get()).isEqualTo(p1RID); + assertThat(row.getProperty("b")).isNotNull(); + assertThat(((Result) row.getProperty("b")).getIdentity().get()).isEqualTo(p2RID); } finally { graph.drop(); - Assertions.assertNull(graph.getGremlinJavaEngine()); - Assertions.assertNull(graph.getGremlinGroovyEngine()); + assertThat(graph.getGremlinJavaEngine()).isNull(); + assertThat(graph.getGremlinGroovyEngine()).isNull(); } } @@ -222,15 +225,15 @@ public void testIssue734() { try { final ResultSet p1 = graph.cypher("CREATE (p:Person) RETURN p").execute(); - Assertions.assertTrue(p1.hasNext()); + assertThat(p1.hasNext()).isTrue(); p1.next().getIdentity().get(); graph.cypher("MATCH (p) DELETE p").execute(); } finally { graph.drop(); - Assertions.assertNull(graph.getGremlinJavaEngine()); - Assertions.assertNull(graph.getGremlinGroovyEngine()); + assertThat(graph.getGremlinJavaEngine()).isNull(); + assertThat(graph.getGremlinGroovyEngine()).isNull(); } } diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/GremlinTest.java b/gremlin/src/test/java/com/arcadedb/gremlin/GremlinTest.java index c5778df63f..2b6b6907c6 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/GremlinTest.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/GremlinTest.java @@ -35,14 +35,18 @@ import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import java.io.*; -import java.math.*; -import java.util.*; +import java.io.File; +import java.io.PrintStream; +import java.math.BigInteger; +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Tests execution of gremlin queries as text. @@ -74,14 +78,14 @@ public void testGremlin() { int lastAge = 0; for (; result.hasNext(); ++i) { final Result row = result.next(); - Assertions.assertEquals("Jay", row.getProperty("p.name")); - Assertions.assertTrue(row.getProperty("p.age") instanceof Number); - Assertions.assertTrue((int) row.getProperty("p.age") > lastAge); + assertThat(row.getProperty("p.name")).isEqualTo("Jay"); + assertThat(row.getProperty("p.age") instanceof Number).isTrue(); + assertThat((int) row.getProperty("p.age") > lastAge).isTrue(); lastAge = row.getProperty("p.age"); } - Assertions.assertEquals(25, i); + assertThat(i).isEqualTo(25); } finally { graph.drop(); @@ -120,13 +124,13 @@ public void testGremlinTargetingBuckets() { int total = 0; for (; result.hasNext(); ++total) result.next(); - Assertions.assertEquals(10, total); + assertThat(total).isEqualTo(10); result = graph.gremlin("g.E().hasLabel('bucket:LinkedTo_1')").execute(); total = 0; for (; result.hasNext(); ++total) result.next(); - Assertions.assertEquals(9, total); + assertThat(total).isEqualTo(9); } finally { graph.drop(); @@ -137,11 +141,9 @@ public void testGremlinTargetingBuckets() { public void testGremlinCountNotDefinedTypes() { final ArcadeGraph graph = ArcadeGraph.open("./target/testgremlin"); try { - Assertions.assertEquals(0, - (Long) graph.gremlin("g.V().hasLabel ( 'foo-label' ).count ()").execute().nextIfAvailable().getProperty("result")); + assertThat((Long) graph.gremlin("g.V().hasLabel ( 'foo-label' ).count ()").execute().nextIfAvailable().getProperty("result")).isEqualTo(0); - Assertions.assertEquals(0, - (Long) graph.gremlin("g.E().hasLabel ( 'foo-label' ).count ()").execute().nextIfAvailable().getProperty("result")); + assertThat((Long) graph.gremlin("g.E().hasLabel ( 'foo-label' ).count ()").execute().nextIfAvailable().getProperty("result")).isEqualTo(0); } finally { graph.drop(); @@ -171,11 +173,11 @@ public void testGremlinEmbeddedDocument() { int total = 0; for (; result.hasNext(); ++total) { EmbeddedDocument address = result.next().getProperty("residence"); - Assertions.assertEquals("Via Roma, 10", address.getString("street")); - Assertions.assertEquals("Rome", address.getString("city")); - Assertions.assertEquals("Italy", address.getString("country")); + assertThat(address.getString("street")).isEqualTo("Via Roma, 10"); + assertThat(address.getString("city")).isEqualTo("Rome"); + assertThat(address.getString("country")).isEqualTo("Italy"); } - Assertions.assertEquals(10, total); + assertThat(total).isEqualTo(10); } finally { graph.drop(); @@ -195,14 +197,14 @@ public void testGremlinIssue500() { graph.addVertex("vl3").property("vp1", 1); ResultSet result = graph.gremlin("g.V().has('vl1','vp1',lt(2)).count()").execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result row = result.next(); - Assertions.assertEquals(1L, (Long) row.getProperty("result")); + assertThat((Long) row.getProperty("result")).isEqualTo(1L); result = graph.gremlin("g.V().has('vl1','vp1',lt(2)).hasLabel('vl1','vl2','vl3').count()").execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); row = result.next(); - Assertions.assertEquals(1L, (Long) row.getProperty("result")); + assertThat((Long) row.getProperty("result")).isEqualTo(1L); } finally { graph.drop(); @@ -218,15 +220,15 @@ public void testGremlinLoadByRID() { ArcadeVertex v2 = graph.addVertex("vl2"); ResultSet result = graph.gremlin("g.V('" + v1.id() + "').addE('FriendOf').to( V('" + v2.id() + "') )").execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); Result row = result.next(); - Assertions.assertTrue(row.isEdge()); + assertThat(row.isEdge()).isTrue(); final Edge edge = row.getEdge().get(); - Assertions.assertEquals(v1.id(), edge.getOut().getIdentity().toString()); - Assertions.assertEquals(v2.id(), edge.getIn().getIdentity().toString()); + assertThat(edge.getOut().getIdentity().toString()).isEqualTo(v1.id()); + assertThat(edge.getIn().getIdentity().toString()).isEqualTo(v2.id()); } finally { graph.drop(); @@ -253,15 +255,15 @@ public void testGremlinFromDatabase() { int lastAge = 0; for (; result.hasNext(); ++i) { final Result row = result.next(); - Assertions.assertFalse(row.isElement()); - Assertions.assertEquals("Jay", row.getProperty("p.name")); - Assertions.assertTrue(row.getProperty("p.age") instanceof Number); - Assertions.assertTrue((int) row.getProperty("p.age") > lastAge); + assertThat(row.isElement()).isFalse(); + assertThat(row.getProperty("p.name")).isEqualTo("Jay"); + assertThat(row.getProperty("p.age") instanceof Number).isTrue(); + assertThat((int) row.getProperty("p.age") > lastAge).isTrue(); lastAge = row.getProperty("p.age"); } - Assertions.assertEquals(25, i); + assertThat(i).isEqualTo(25); } finally { if (database.isTransactionActive()) @@ -281,7 +283,7 @@ public void testCypherSyntaxError() { graph.getDatabase().query("gremlin", "g.V().as('p').hasLabel22222('Person').where(__.choose(__.constant(p1), __.constant(p1), __.constant(' cypher.null')).is(neq(' cypher.null')).as(' GENERATED1').select('p').values('age').where(gte(' GENERATED1'))).select('p').project('p.name', 'p.age').by(__.choose(neq(' cypher.null'), __.choose(__.values('name'), __.values('name'), __.constant(' cypher.null')))).by(__.choose(neq(' cypher.null'), __.choose(__.values('age'), __.values('age'), __.constant(' cypher.null')))).order().by(__.select('p.age'), asc)", "p1", 25); - Assertions.fail(); + fail(""); } catch (final CommandParsingException e) { // EXPECTED } @@ -299,13 +301,13 @@ public void testGremlinParse() { final ArcadeGremlin gremlinReadOnly = graph.gremlin( "g.V().as('p').hasLabel('Person').where(__.choose(__.constant(25), __.constant(25), __.constant(' cypher.null')).is(neq(' cypher.null')).as(' GENERATED1').select('p').values('age').where(gte(' GENERATED1'))).select('p').project('p.name', 'p.age').by(__.choose(neq(' cypher.null'), __.choose(__.values('name'), __.values('name'), __.constant(' cypher.null')))).by(__.choose(neq(' cypher.null'), __.choose(__.values('age'), __.values('age'), __.constant(' cypher.null')))).order().by(__.select('p.age'), asc)"); - Assertions.assertTrue(gremlinReadOnly.parse().isIdempotent()); - Assertions.assertFalse(gremlinReadOnly.parse().isDDL()); + assertThat(gremlinReadOnly.parse().isIdempotent()).isTrue(); + assertThat(gremlinReadOnly.parse().isDDL()).isFalse(); final ArcadeGremlin gremlinWrite = graph.gremlin("g.V().addV('Person')"); - Assertions.assertFalse(gremlinWrite.parse().isIdempotent()); - Assertions.assertFalse(gremlinWrite.parse().isDDL()); + assertThat(gremlinWrite.parse().isIdempotent()).isFalse(); + assertThat(gremlinWrite.parse().isDDL()).isFalse(); } finally { graph.drop(); @@ -318,13 +320,13 @@ public void testGremlinLists() { try { final ResultSet result = graph.gremlin("g.addV('Person').property( 'list', ['a', 'b'] )").execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result v = result.next(); - Assertions.assertTrue(v.isVertex()); + assertThat(v.isVertex()).isTrue(); final List list = (List) v.getVertex().get().get("list"); - Assertions.assertEquals(2, list.size()); - Assertions.assertTrue(list.contains("a")); - Assertions.assertTrue(list.contains("b")); + assertThat(list.size()).isEqualTo(2); + assertThat(list.contains("a")).isTrue(); + assertThat(list.contains("b")).isTrue(); } finally { graph.drop(); @@ -345,7 +347,7 @@ public void testUseIndex() { final ArcadeGremlin gremlinReadOnly = graph.gremlin("g.V().as('p').hasLabel('Person').has( 'id', eq('" + uuid + "'))"); final ResultSet result = gremlinReadOnly.execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); } finally { graph.drop(); } @@ -376,7 +378,7 @@ public void infinityValue() { final ArcadeGremlin gremlinReadOnly = graph.gremlin("g.V().has('hair', 500.00)"); final ResultSet result = gremlinReadOnly.execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); } finally { graph.drop(); @@ -395,7 +397,7 @@ public void testVertexConstraints() { final ArcadeGremlin gremlinReadOnly = graph.gremlin("g.addV('ChipID').property('name', 'a').property('uid', 'b')"); final ResultSet result = gremlinReadOnly.execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); } finally { graph.drop(); @@ -421,7 +423,7 @@ public void sort() { final ArcadeGremlin gremlinReadOnly = graph.gremlin("g.V().order().by('name', asc)"); final ResultSet result = gremlinReadOnly.execute(); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); } finally { graph.drop(); @@ -434,14 +436,13 @@ public void testLongOverflow() { final ArcadeGraph graph = ArcadeGraph.open("./target/testgremlin"); try { Result value = graph.gremlin("g.inject(Long.MAX_VALUE, 0).sum()").execute().nextIfAvailable(); - Assertions.assertEquals(Long.MAX_VALUE, (long) value.getProperty("result")); + assertThat((long) value.getProperty("result")).isEqualTo(Long.MAX_VALUE); value = graph.gremlin("g.inject(Long.MAX_VALUE, 1).sum()").execute().nextIfAvailable(); - Assertions.assertEquals(Long.MAX_VALUE + 1, (long) value.getProperty("result")); + assertThat((long) value.getProperty("result")).isEqualTo(Long.MAX_VALUE + 1); value = graph.gremlin("g.inject(BigInteger.valueOf(Long.MAX_VALUE), 1).sum()").execute().nextIfAvailable(); - Assertions.assertEquals(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1L)), - (BigInteger) value.getProperty("result")); + assertThat((BigInteger) value.getProperty("result")).isEqualTo(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1L))); } finally { graph.drop(); } @@ -453,7 +454,7 @@ public void testNumberConversion() { final ArcadeGraph graph = ArcadeGraph.open("./target/testgremlin"); try { Result value = graph.gremlin("g.inject(1).size()").execute().nextIfAvailable(); - Assertions.assertEquals(1, (int) value.getProperty("result")); + assertThat((int) value.getProperty("result")).isEqualTo(1); } finally { graph.drop(); } @@ -476,9 +477,9 @@ public void testGroupBy() { ResultSet resultSet = graph.gremlin("g.V().hasLabel('Person').group().by('name')").execute(); Result result = resultSet.nextIfAvailable(); - Assertions.assertNotNull(result.getProperty("Alice")); - Assertions.assertNotNull(result.getProperty("Bob")); - Assertions.assertNotNull(result.getProperty("Steve")); + assertThat(result.getProperty("Alice")).isNotNull(); + assertThat(result.getProperty("Bob")).isNotNull(); + assertThat(result.getProperty("Steve")).isNotNull(); } finally { graph.drop(); } @@ -515,10 +516,9 @@ public void testBooleanProperties() { graph.gremlin("g.addV('A').property('b', true)").execute().nextIfAvailable(); graph.gremlin("g.addV('A').property('b', false)").execute().nextIfAvailable(); graph.gremlin("g.addV('A')").execute().nextIfAvailable(); - Assertions.assertEquals(4, graph.gremlin("g.V().hasLabel('A')").execute().toVertices().size()); - Assertions.assertEquals(2, graph.gremlin("g.V().hasLabel('A').has('b',true)").execute().toVertices().size()); - Assertions.assertEquals(2, - (Long) graph.gremlin("g.V().hasLabel('A').has('b',true).count()").execute().nextIfAvailable().getProperty("result")); + assertThat(graph.gremlin("g.V().hasLabel('A')").execute().toVertices().size()).isEqualTo(4); + assertThat(graph.gremlin("g.V().hasLabel('A').has('b',true)").execute().toVertices().size()).isEqualTo(2); + assertThat((Long) graph.gremlin("g.V().hasLabel('A').has('b',true).count()").execute().nextIfAvailable().getProperty("result")).isEqualTo(2); } finally { graph.drop(); diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/SQLFromGremlinTest.java b/gremlin/src/test/java/com/arcadedb/gremlin/SQLFromGremlinTest.java index 03417d1179..dd8d5a7de2 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/SQLFromGremlinTest.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/SQLFromGremlinTest.java @@ -24,12 +24,13 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Luca Garulli (l.garulli@arcadedata.com) */ @@ -53,14 +54,14 @@ public void testSQL() { int lastAge = 0; for (; result.hasNext(); ++i) { final Result row = result.next(); - Assertions.assertEquals("Jay", row.getProperty("p.name")); - Assertions.assertTrue(row.getProperty("p.age") instanceof Number); - Assertions.assertTrue((int) row.getProperty("p.age") > lastAge); + assertThat(row.getProperty("p.name")).isEqualTo("Jay"); + assertThat(row.getProperty("p.age") instanceof Number).isTrue(); + assertThat((int) row.getProperty("p.age") > lastAge).isTrue(); lastAge = row.getProperty("p.age"); } - Assertions.assertEquals(25, i); + assertThat(i).isEqualTo(25); } finally { graph.drop(); diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/VectorGremlinIT.java b/gremlin/src/test/java/com/arcadedb/gremlin/VectorGremlinIT.java index 0a7e9cd93d..125dff3725 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/VectorGremlinIT.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/VectorGremlinIT.java @@ -21,16 +21,19 @@ import com.arcadedb.database.Database; import com.arcadedb.database.DatabaseFactory; import com.arcadedb.database.Identifiable; +import com.arcadedb.database.RID; +import com.arcadedb.graph.ImmutableVertex; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.FileUtils; import com.arcadedb.utility.Pair; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class VectorGremlinIT { @Test public void importDocuments() { @@ -49,38 +52,44 @@ public void importDocuments() { + "vertexType = Word, edgeType = Proximity, vectorProperty = vector, idProperty = name" // ); - Assertions.assertEquals(10, db.countType("Word", true)); + assertThat(db.countType("Word", true)).isEqualTo(10); final float[] vector = new float[100]; ResultSet resultSet = db.query("sql", "select vectorNeighbors('Word[name,vector]', ?,?) as neighbors", vector, 10); - Assertions.assertTrue(resultSet.hasNext()); - final List> approximateResults = new ArrayList<>(); + assertThat(resultSet.hasNext()).isTrue(); + final List approximateResults = new ArrayList<>(); while (resultSet.hasNext()) { final Result row = resultSet.next(); final List> neighbors = row.getProperty("neighbors"); - for (Map neighbor : neighbors) - approximateResults.add(new Pair<>((Identifiable) neighbor.get("vertex"), ((Number) neighbor.get("distance")).floatValue())); + for (Map neighbor : neighbors) { + ImmutableVertex vertex = (ImmutableVertex) neighbor.get("vertex"); + approximateResults.add(vertex.getIdentity()); + + } } - Assertions.assertEquals(10, approximateResults.size()); + assertThat(approximateResults).hasSize(10); - resultSet = db.query("gremlin", "g.call('arcadedb#vectorNeighbors', [ 'indexName': 'Word[name,vector]', 'vector': vector, 'limit': 10 ] )", "vector", + resultSet = db.query("gremlin", + "g.call('arcadedb#vectorNeighbors', [ 'indexName': 'Word[name,vector]', 'vector': vector, 'limit': 10 ] )", "vector", vector); - Assertions.assertTrue(resultSet.hasNext()); - final List approximateResultsFromGremlin = new ArrayList<>(); + assertThat(resultSet.hasNext()).isTrue(); + final List approximateResultsFromGremlin = new ArrayList<>(); while (resultSet.hasNext()) { final Result row = resultSet.next(); final List> neighbors = row.getProperty("result"); - for (Map neighbor : neighbors) - approximateResultsFromGremlin.add(new Pair<>((Identifiable) neighbor.get("vertex"), ((Number) neighbor.get("distance")).floatValue())); + for (Map neighbor : neighbors) { + ArcadeVertex vertex = (ArcadeVertex) neighbor.get("vertex"); + approximateResultsFromGremlin.add(vertex.getIdentity()); + } } - Assertions.assertEquals(10, approximateResultsFromGremlin.size()); + assertThat(approximateResultsFromGremlin).hasSize(10); - Assertions.assertEquals(approximateResults, approximateResultsFromGremlin); + assertThat(approximateResultsFromGremlin).isEqualTo(approximateResults); } finally { db.drop(); diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphMLExporterIT.java b/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphMLExporterIT.java index 94be9050a7..e79c6b9ce8 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphMLExporterIT.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphMLExporterIT.java @@ -31,7 +31,6 @@ import com.arcadedb.utility.FileUtils; import org.apache.tinkerpop.gremlin.structure.io.IoCore; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,6 +38,8 @@ import java.util.stream.*; import java.util.zip.*; +import static org.assertj.core.api.Assertions.assertThat; + public class GraphMLExporterIT { private final static String DATABASE_PATH = "target/databases/performance"; private final static String FILE = "target/arcadedb-export.graphml.tgz"; @@ -54,30 +55,26 @@ public void testExportOK() throws Exception { final var importer = new OrientDBImporter(("-i " + inputFile.getFile() + " -d " + DATABASE_PATH + " -o").split(" ")); importer.run().close(); - Assertions.assertFalse(importer.isError()); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(importer.isError()).isFalse(); + assertThat(databaseDirectory.exists()).isTrue(); new Exporter(("-f " + FILE + " -d " + DATABASE_PATH + " -o -format graphml").split(" ")).exportDatabase(); - Assertions.assertTrue(file.exists()); - Assertions.assertTrue(file.length() > 0); + assertThat(file.exists()).isTrue(); + assertThat(file.length() > 0).isTrue(); try (final ArcadeGraph graph = ArcadeGraph.open(importedDatabaseDirectory.getAbsolutePath())) { try (final GZIPInputStream is = new GZIPInputStream(new FileInputStream(file))) { graph.io(IoCore.graphml()).reader().create().readGraph(is, graph); } - Assertions.assertTrue(importedDatabaseDirectory.exists()); + assertThat(importedDatabaseDirectory.exists()).isTrue(); try (final Database originalDatabase = new DatabaseFactory(DATABASE_PATH).open(ComponentFile.MODE.READ_ONLY)) { - Assertions.assertEquals(// - originalDatabase.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet()),// - graph.getDatabase().getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(graph.getDatabase().getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(originalDatabase.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); for (final DocumentType type : originalDatabase.getSchema().getTypes()) { - Assertions.assertEquals(// - originalDatabase.countType(type.getName(), true),// - graph.getDatabase().countType(type.getName(), true)); + assertThat(graph.getDatabase().countType(type.getName(), true)).isEqualTo(originalDatabase.countType(type.getName(), true)); } } } diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphSONExporterIT.java b/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphSONExporterIT.java index 049a0c14d8..658b4a90db 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphSONExporterIT.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/integration/exporter/GraphSONExporterIT.java @@ -31,7 +31,6 @@ import com.arcadedb.utility.FileUtils; import org.apache.tinkerpop.gremlin.structure.io.IoCore; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,6 +38,8 @@ import java.util.stream.*; import java.util.zip.*; +import static org.assertj.core.api.Assertions.assertThat; + public class GraphSONExporterIT { private final static String DATABASE_PATH = "target/databases/performance"; private final static String FILE = "target/arcadedb-export.graphson.tgz"; @@ -54,30 +55,26 @@ public void testExportOK() throws Exception { final var importer = new OrientDBImporter(("-i " + inputFile.getFile() + " -d " + DATABASE_PATH + " -o").split(" ")); importer.run().close(); - Assertions.assertFalse(importer.isError()); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(importer.isError()).isFalse(); + assertThat(databaseDirectory.exists()).isTrue(); new Exporter(("-f " + FILE + " -d " + DATABASE_PATH + " -o -format graphson").split(" ")).exportDatabase(); - Assertions.assertTrue(file.exists()); - Assertions.assertTrue(file.length() > 0); + assertThat(file.exists()).isTrue(); + assertThat(file.length() > 0).isTrue(); try (final ArcadeGraph graph = ArcadeGraph.open(importedDatabaseDirectory.getAbsolutePath())) { try (final GZIPInputStream is = new GZIPInputStream(new FileInputStream(file))) { graph.io(IoCore.graphson()).reader().create().readGraph(is, graph); } - Assertions.assertTrue(importedDatabaseDirectory.exists()); + assertThat(importedDatabaseDirectory.exists()).isTrue(); try (final Database originalDatabase = new DatabaseFactory(DATABASE_PATH).open(ComponentFile.MODE.READ_ONLY)) { - Assertions.assertEquals(// - originalDatabase.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet()),// - graph.getDatabase().getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(graph.getDatabase().getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(originalDatabase.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); for (final DocumentType type : originalDatabase.getSchema().getTypes()) { - Assertions.assertEquals(// - originalDatabase.countType(type.getName(), true),// - graph.getDatabase().countType(type.getName(), true)); + assertThat(graph.getDatabase().countType(type.getName(), true)).isEqualTo(originalDatabase.countType(type.getName(), true)); } } } diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphMLImporterIT.java b/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphMLImporterIT.java index e54a6248de..025d2892be 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphMLImporterIT.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphMLImporterIT.java @@ -27,7 +27,6 @@ import com.arcadedb.server.TestServerHelper; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,6 +36,8 @@ import java.util.stream.*; import java.util.zip.*; +import static org.assertj.core.api.Assertions.assertThat; + public class GraphMLImporterIT { private final static String DATABASE_PATH = "target/databases/performance"; private final static String FILE = "arcadedb-export.graphml.tgz"; @@ -53,14 +54,12 @@ public void testImportCompressedOK() { final Importer importer = new Importer(database, inputFile.getFile()); importer.load(); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); - Assertions.assertEquals(// - new HashSet<>(Arrays.asList("Friend", "Person")),// - database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(new HashSet<>(Arrays.asList("Friend", "Person"))); for (final DocumentType type : database.getSchema().getTypes()) { - Assertions.assertTrue(database.countType(type.getName(), true) > 0); + assertThat(database.countType(type.getName(), true) > 0).isTrue(); } } } @@ -83,14 +82,12 @@ public void testImportNotCompressedOK() throws IOException { final Importer importer = new Importer(database, UNCOMPRESSED_FILE); importer.load(); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); - Assertions.assertEquals(// - new HashSet<>(Arrays.asList("Friend", "Person")),// - database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(new HashSet<>(Arrays.asList("Friend", "Person"))); for (final DocumentType type : database.getSchema().getTypes()) { - Assertions.assertTrue(database.countType(type.getName(), true) > 0); + assertThat(database.countType(type.getName(), true) > 0).isTrue(); } } } @@ -103,17 +100,15 @@ public void testImportFromSQL() { database.command("sql", "import database file://" + inputFile.getFile() + " WITH commitEvery = 1000"); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); - Assertions.assertEquals(// - new HashSet<>(Arrays.asList("Friend", "Person")),// - database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(new HashSet<>(Arrays.asList("Friend", "Person"))); for (final DocumentType type : database.getSchema().getTypes()) { - Assertions.assertTrue(database.countType(type.getName(), true) > 0); + assertThat(database.countType(type.getName(), true) > 0).isTrue(); } } - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(DATABASE_PATH)); + assertThat(DatabaseFactory.getActiveDatabaseInstance(DATABASE_PATH)).isNull(); } @BeforeEach diff --git a/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphSONImporterIT.java b/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphSONImporterIT.java index 81122047a6..d70ec15556 100644 --- a/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphSONImporterIT.java +++ b/gremlin/src/test/java/com/arcadedb/gremlin/integration/importer/GraphSONImporterIT.java @@ -27,7 +27,6 @@ import com.arcadedb.server.TestServerHelper; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,6 +36,8 @@ import java.util.stream.*; import java.util.zip.*; +import static org.assertj.core.api.Assertions.assertThat; + public class GraphSONImporterIT { private final static String DATABASE_PATH = "target/databases/performance"; private final static String FILE = "arcadedb-export.graphson.tgz"; @@ -53,14 +54,12 @@ public void testImportCompressedOK() { final Importer importer = new Importer(database, inputFile.getFile()); importer.load(); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); - Assertions.assertEquals(// - new HashSet<>(Arrays.asList("Friend", "Person")),// - database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(new HashSet<>(Arrays.asList("Friend", "Person"))); for (final DocumentType type : database.getSchema().getTypes()) { - Assertions.assertTrue(database.countType(type.getName(), true) > 0); + assertThat(database.countType(type.getName(), true) > 0).isTrue(); } } } @@ -83,14 +82,12 @@ public void testImportNotCompressedOK() throws IOException { final Importer importer = new Importer(database, UNCOMPRESSED_FILE); importer.load(); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); - Assertions.assertEquals(// - new HashSet<>(Arrays.asList("Friend", "Person")),// - database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(new HashSet<>(Arrays.asList("Friend", "Person"))); for (final DocumentType type : database.getSchema().getTypes()) { - Assertions.assertTrue(database.countType(type.getName(), true) > 0); + assertThat(database.countType(type.getName(), true) > 0).isTrue(); } } } @@ -103,17 +100,15 @@ public void testImportFromSQL() { database.command("sql", "import database file://" + inputFile.getFile() + " WITH commitEvery = 1000"); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); - Assertions.assertEquals(// - new HashSet<>(Arrays.asList("Friend", "Person")),// - database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())); + assertThat(database.getSchema().getTypes().stream().map(DocumentType::getName).collect(Collectors.toSet())).isEqualTo(new HashSet<>(Arrays.asList("Friend", "Person"))); for (final DocumentType type : database.getSchema().getTypes()) { - Assertions.assertTrue(database.countType(type.getName(), true) > 0); + assertThat(database.countType(type.getName(), true) > 0).isTrue(); } } - Assertions.assertNull(DatabaseFactory.getActiveDatabaseInstance(DATABASE_PATH)); + assertThat(DatabaseFactory.getActiveDatabaseInstance(DATABASE_PATH)).isNull(); } @BeforeEach diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/AbstractGremlinServerIT.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/AbstractGremlinServerIT.java index f78091c325..171dadc1e5 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/AbstractGremlinServerIT.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/AbstractGremlinServerIT.java @@ -21,21 +21,19 @@ package com.arcadedb.server.gremlin; import com.arcadedb.GlobalConfiguration; -import com.arcadedb.gremlin.ArcadeGraph; -import com.arcadedb.query.sql.executor.ResultSet; -import com.arcadedb.remote.RemoteDatabase; import com.arcadedb.remote.RemoteServer; import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.File; +import java.io.IOException; -import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in; -import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select; +import static org.assertj.core.api.Assertions.fail; +import java.io.IOException; + +import static org.assertj.core.api.Assertions.fail; public abstract class AbstractGremlinServerIT extends BaseGraphServerTest { @@ -59,7 +57,7 @@ public void setTestConfiguration() { GlobalConfiguration.SERVER_PLUGINS.setValue("GremlinServer:com.arcadedb.server.gremlin.GremlinServerPlugin"); } catch (final IOException e) { - Assertions.fail(e); + fail("", e); } } diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/ConnectRemoteGremlinServerIT.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/ConnectRemoteGremlinServerIT.java index 234a015897..9852af03d5 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/ConnectRemoteGremlinServerIT.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/ConnectRemoteGremlinServerIT.java @@ -27,12 +27,13 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.WithOptions; import org.apache.tinkerpop.gremlin.structure.io.binary.TypeSerializerRegistry; import org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV1; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Manual test against a Gremlin Server. */ @@ -47,7 +48,7 @@ public void getAllVertices() { final List> vertices = g.V().valueMap().with(WithOptions.tokens) .toList(); // verifies that the vertex created with properties is returned - Assertions.assertFalse(vertices.isEmpty()); + assertThat(vertices.isEmpty()).isFalse(); } private Cluster createCluster() { diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerSecurityTest.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerSecurityTest.java index 9d2a3479db..ac316bf830 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerSecurityTest.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerSecurityTest.java @@ -18,34 +18,20 @@ */ package com.arcadedb.server.gremlin; -import com.arcadedb.GlobalConfiguration; -import com.arcadedb.gremlin.ArcadeGraph; -import com.arcadedb.gremlin.io.ArcadeIoRegistry; import com.arcadedb.remote.RemoteDatabase; -import com.arcadedb.server.BaseGraphServerTest; -import com.arcadedb.server.security.ServerSecurityException; -import com.arcadedb.utility.CodeUtils; -import com.arcadedb.utility.FileUtils; -import org.apache.tinkerpop.gremlin.driver.Cluster; -import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection; -import org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.structure.io.binary.TypeSerializerRegistry; -import org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV1; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class GremlinServerSecurityTest extends AbstractGremlinServerIT { @Test public void getAllVertices() { try (final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480, getDatabaseName(), "root", "test")) { - Assertions.fail("Expected security exception"); + fail("Expected security exception"); } catch (final SecurityException e) { - Assertions.assertTrue(e.getMessage().contains("User/Password")); + assertThat(e.getMessage().contains("User/Password")).isTrue(); } } diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerTest.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerTest.java index dbcebecf89..169bff7aaa 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerTest.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/GremlinServerTest.java @@ -29,18 +29,19 @@ import org.apache.tinkerpop.gremlin.structure.io.binary.TypeSerializerRegistry; import org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV1; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class GremlinServerTest extends AbstractGremlinServerIT { @Test public void getAllVertices() { final GraphTraversalSource g = traversal(); final var vertices = g.V().limit(3).toList(); - Assertions.assertEquals(3, vertices.size()); + assertThat(vertices.size()).isEqualTo(3); } @AfterEach diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/LocalGremlinFactoryIT.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/LocalGremlinFactoryIT.java index 666d4f3688..1e062de64c 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/LocalGremlinFactoryIT.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/LocalGremlinFactoryIT.java @@ -28,11 +28,14 @@ import com.arcadedb.server.BaseGraphServerTest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class LocalGremlinFactoryIT { private static final String DATABASE_NAME = "local-database-factory"; @@ -41,11 +44,11 @@ public void okPoolRelease() { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withLocal(DATABASE_NAME)) { for (int i = 0; i < 1_000; i++) { final ArcadeGraph instance = pool.get(); - Assertions.assertNotNull(instance); + assertThat(instance).isNotNull(); instance.close(); } - Assertions.assertEquals(1, pool.getTotalInstancesCreated()); + assertThat(pool.getTotalInstancesCreated()).isEqualTo(1); } } @@ -54,17 +57,17 @@ public void errorPoolRelease() { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withLocal(DATABASE_NAME)) { for (int i = 0; i < pool.getMaxInstances(); i++) { final ArcadeGraph instance = pool.get(); - Assertions.assertNotNull(instance); + assertThat(instance).isNotNull(); } try { pool.get(); - Assertions.fail(); + fail(""); } catch (IllegalArgumentException e) { // EXPECTED } - Assertions.assertEquals(pool.getMaxInstances(), pool.getTotalInstancesCreated()); + assertThat(pool.getTotalInstancesCreated()).isEqualTo(pool.getMaxInstances()); } } diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGraphOrderIT.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGraphOrderIT.java index 944f2d6d63..24562305f8 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGraphOrderIT.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGraphOrderIT.java @@ -25,17 +25,22 @@ import com.arcadedb.remote.RemoteDatabase; import com.arcadedb.remote.RemoteServer; import com.arcadedb.server.BaseGraphServerTest; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; + public class RemoteGraphOrderIT extends AbstractGremlinServerIT { @Test public void testOrder() throws Exception { testEachServer((serverIndex) -> { - Assertions.assertTrue( + assertThat( new RemoteServer("127.0.0.1", 2480 + serverIndex, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).exists( - getDatabaseName())); + getDatabaseName())).isTrue(); try (final RemoteDatabase db = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, getDatabaseName(), "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { @@ -66,21 +71,30 @@ public void testOrder() throws Exception { Edge edgType1 = rootVtx.newEdge("EdgType1", connectedVtx1, true); //Correct result - Returns one vertex/edge - for (Vertex v : rootVtx.getVertices(Vertex.DIRECTION.OUT, "EdgType0")) - Assertions.assertEquals("ConnectedVtx", v.getTypeName()); - for (Edge e : rootVtx.getEdges(Vertex.DIRECTION.OUT, "EdgType0")) - Assertions.assertEquals("EdgType0", e.getTypeName()); +// Vertices with outgoing "EdgType0" edge + Iterable connectedVertices = rootVtx.getVertices(Vertex.DIRECTION.OUT, "EdgType0"); + + assertThat(connectedVertices) + .extracting(Vertex::getTypeName) // extract type names of vertices + .containsExactly("ConnectedVtx"); // assert all extracted names are "ConnectedVtx" + + // Edges with type "EdgType0" + Iterable outgoingEdges = rootVtx.getEdges(Vertex.DIRECTION.OUT, "EdgType0"); + + assertThat(outgoingEdges) + .extracting(Edge::getTypeName) // extract edge types + .containsExactly("EdgType0"); // assert all extracted types are "EdgType0" - Assertions.assertEquals(0, rootVtx.countEdges(Vertex.DIRECTION.IN, "EdgType0")); - Assertions.assertEquals(0, rootVtx.countEdges(Vertex.DIRECTION.IN, "EdgType1")); - Assertions.assertEquals(1, rootVtx.countEdges(Vertex.DIRECTION.OUT, "EdgType0")); - Assertions.assertEquals(1, rootVtx.countEdges(Vertex.DIRECTION.OUT, "EdgType1")); + // Incoming edge counts + assertThat(rootVtx.countEdges(Vertex.DIRECTION.IN, "EdgType0")).isEqualTo(0); + assertThat(rootVtx.countEdges(Vertex.DIRECTION.IN, "EdgType1")).isEqualTo(0); + assertThat(rootVtx.countEdges(Vertex.DIRECTION.OUT, "EdgType0")).isEqualTo(1); + assertThat(rootVtx.countEdges(Vertex.DIRECTION.OUT, "EdgType1")).isEqualTo(1); - int count = 0; - for (Vertex v : rootVtx.getVertices(Vertex.DIRECTION.OUT, "EdgType1")) - ++count; - Assertions.assertEquals(1, count); + // Counting outgoing "EdgType1" edges + Iterable vertices = rootVtx.getVertices(Vertex.DIRECTION.OUT, "EdgType1"); + assertThat(vertices).hasSize(1); } }); } diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinFactoryIT.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinFactoryIT.java index 6d5b260a21..9f5062692f 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinFactoryIT.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinFactoryIT.java @@ -23,13 +23,16 @@ import com.arcadedb.gremlin.ArcadeGraph; import com.arcadedb.gremlin.ArcadeGraphFactory; import com.arcadedb.query.sql.executor.ResultSet; -import com.arcadedb.server.BaseGraphServerTest; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.junit.jupiter.api.Assertions; + +import org.apache.tinkerpop.gremlin.structure.Transaction; import org.junit.jupiter.api.Test; import java.util.concurrent.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class RemoteGremlinFactoryIT extends AbstractGremlinServerIT { @Override @@ -40,54 +43,54 @@ protected boolean isCreateDatabases() { @Test public void okPoolRelease() { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { for (int i = 0; i < 1_000; i++) { final ArcadeGraph instance = pool.get(); - Assertions.assertNotNull(instance); + assertThat(instance).isNotNull(); instance.close(); } - Assertions.assertEquals(1, pool.getTotalInstancesCreated()); + assertThat(pool.getTotalInstancesCreated()).isEqualTo(1); } } @Test public void errorPoolRelease() { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { for (int i = 0; i < pool.getMaxInstances(); i++) { final ArcadeGraph instance = pool.get(); - Assertions.assertNotNull(instance); + assertThat(instance).isNotNull(); } try { pool.get(); - Assertions.fail(); + fail(""); } catch (IllegalArgumentException e) { // EXPECTED } - Assertions.assertEquals(pool.getMaxInstances(), pool.getTotalInstancesCreated()); + assertThat(pool.getTotalInstancesCreated()).isEqualTo(pool.getMaxInstances()); } } @Test public void executeTraversalSeparateTransactions() { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { try (final ArcadeGraph graph = pool.get()) { for (int i = 0; i < 1_000; i++) graph.addVertex(org.apache.tinkerpop.gremlin.structure.T.label, "inputstructure", "json", "{\"name\": \"Elon\"}"); // THIS IS IN THE SAME SCOPE, SO IT CAN SEE THE PENDING VERTICES ADDED EARLIER try (final ResultSet list = graph.gremlin("g.V().hasLabel(\"inputstructure\").count()").execute()) { - Assertions.assertEquals(1_000, (Integer) list.nextIfAvailable().getProperty("result")); + assertThat((Integer) list.nextIfAvailable().getProperty("result")).isEqualTo(1_000); } graph.tx().commit(); // <-- WITHOUT THIS COMMIT THE NEXT 2 TRAVERSALS WOULD NOT SEE THE ADDED VERTICES - Assertions.assertEquals(1_000, graph.traversal().V().hasLabel("inputstructure").count().next()); - Assertions.assertEquals(1_000, graph.traversal().V().hasLabel("inputstructure").count().toList().get(0)); + assertThat(graph.traversal().V().hasLabel("inputstructure").count().next()).isEqualTo(1_000); + assertThat(graph.traversal().V().hasLabel("inputstructure").count().toList().get(0)).isEqualTo(1_000); } } } @@ -95,7 +98,7 @@ public void executeTraversalSeparateTransactions() { @Test public void executeTraversalTxMgmtMultiThreads() throws InterruptedException { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { try (final ArcadeGraph graph = pool.get()) { graph.getDatabase().getSchema().createVertexType("Country"); @@ -106,10 +109,20 @@ public void executeTraversalTxMgmtMultiThreads() throws InterruptedException { for (int i = 0; i < 1000; i++) { final int id = i; executorService.submit(() -> { + try (final ArcadeGraph graph = pool.get()) { - GraphTraversalSource g = graph.tx().begin(); - g.addV("Country").property("id", id).property("country", "USA").property("code", id).iterate(); - g.tx().commit(); + + Transaction tx = graph.tx(); + GraphTraversalSource gtx = tx.begin(); + gtx.addV("Country") + .property("id", id) + .property("country", "USA") + .property("code", id) + .iterate(); + tx.commit(); + + } catch (Exception e) { + //do nothing } }); } @@ -118,15 +131,18 @@ public void executeTraversalTxMgmtMultiThreads() throws InterruptedException { executorService.awaitTermination(60, TimeUnit.SECONDS); try (final ArcadeGraph graph = pool.get()) { - Assertions.assertTrue(graph.traversal().V().hasLabel("Country").count().toList().get(0) > 800); + Long country = graph.traversal().V().hasLabel("Country").count().toList().get(0); + assertThat(country > 800).isTrue(); } + } catch (Exception e) { + //do nothing } } @Test public void executeTraversalNoTxMgmtMultiThreads() throws InterruptedException { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { try (final ArcadeGraph graph = pool.get()) { graph.getDatabase().getSchema().createVertexType("Country"); @@ -145,7 +161,7 @@ public void executeTraversalNoTxMgmtMultiThreads() throws InterruptedException { executorService.awaitTermination(60, TimeUnit.SECONDS); try (final ArcadeGraph graph = pool.get()) { - Assertions.assertTrue(graph.traversal().V().hasLabel("Country").count().toList().get(0) > 800); + assertThat(graph.traversal().V().hasLabel("Country").count().toList().get(0) > 800).isTrue(); } } } @@ -153,7 +169,7 @@ public void executeTraversalNoTxMgmtMultiThreads() throws InterruptedException { @Test public void executeTraversalTxMgmtHttp() throws InterruptedException { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { for (int i = 0; i < 1000; i++) { final int id = i; @@ -165,7 +181,7 @@ public void executeTraversalTxMgmtHttp() throws InterruptedException { } try (final ArcadeGraph graph = pool.get()) { - Assertions.assertEquals(1000, graph.traversal().V().hasLabel("Country").count().toList().get(0)); + assertThat(graph.traversal().V().hasLabel("Country").count().toList().get(0)).isEqualTo(1000); } } } @@ -173,7 +189,7 @@ public void executeTraversalTxMgmtHttp() throws InterruptedException { @Test public void executeTraversalTxMgmt() { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { for (int i = 0; i < 1000; i++) { final int id = i; @@ -186,7 +202,7 @@ public void executeTraversalTxMgmt() { } try (final ArcadeGraph graph = pool.get()) { - Assertions.assertEquals(1000, graph.traversal().V().hasLabel("Country").count().toList().get(0)); + assertThat(graph.traversal().V().hasLabel("Country").count().toList().get(0)).isEqualTo(1000); } } } @@ -194,7 +210,7 @@ public void executeTraversalTxMgmt() { @Test public void executeTraversalNoTxMgmt() { try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("127.0.0.1", 2480, getDatabaseName(), "root", - BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + DEFAULT_PASSWORD_FOR_TESTS)) { for (int i = 0; i < 1000; i++) { final int id = i; @@ -204,7 +220,7 @@ public void executeTraversalNoTxMgmt() { } try (final ArcadeGraph graph = pool.get()) { - Assertions.assertEquals(1000, graph.traversal().V().hasLabel("Country").count().toList().get(0)); + assertThat(graph.traversal().V().hasLabel("Country").count().toList().get(0)).isEqualTo(1000); } } } diff --git a/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinIT.java b/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinIT.java index a6dcc1ce67..3248dbe14a 100644 --- a/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinIT.java +++ b/gremlin/src/test/java/com/arcadedb/server/gremlin/RemoteGremlinIT.java @@ -25,20 +25,22 @@ import com.arcadedb.remote.RemoteDatabase; import com.arcadedb.remote.RemoteServer; import com.arcadedb.server.BaseGraphServerTest; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in; import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select; +import static org.assertj.core.api.Assertions.assertThat; public class RemoteGremlinIT extends AbstractGremlinServerIT { @Test public void insert() throws Exception { testEachServer((serverIndex) -> { - Assertions.assertTrue( + assertThat( new RemoteServer("127.0.0.1", 2480 + serverIndex, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).exists( - getDatabaseName())); + getDatabaseName())).isTrue(); final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, getDatabaseName(), "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); @@ -50,16 +52,17 @@ public void insert() throws Exception { graph.addVertex(org.apache.tinkerpop.gremlin.structure.T.label, "inputstructure", "json", "{\"name\": \"Elon\"}"); try (final ResultSet list = graph.gremlin("g.V().hasLabel(\"inputstructure\")").execute()) { - Assertions.assertEquals(1_000, list.stream().count()); + assertThat(list.stream().count()).isEqualTo(1_000); } try (final ResultSet list = graph.gremlin("g.V().hasLabel(\"inputstructure\").count()").execute()) { - Assertions.assertEquals(1_000, (Integer) list.nextIfAvailable().getProperty("result")); + assertThat(list.nextIfAvailable().getProperty("result")).isEqualTo(1_000); } graph.tx().commit(); - Assertions.assertEquals(1_000L, graph.traversal().V().hasLabel("inputstructure").count().next()); + assertThat(graph.traversal().V().hasLabel("inputstructure").count().next()).isEqualTo(1_000L); + } }); } diff --git a/integration/src/test/java/com/arcadedb/integration/TestHelper.java b/integration/src/test/java/com/arcadedb/integration/TestHelper.java index 604dc8b0bd..1f0e5ec41a 100644 --- a/integration/src/test/java/com/arcadedb/integration/TestHelper.java +++ b/integration/src/test/java/com/arcadedb/integration/TestHelper.java @@ -3,11 +3,12 @@ import com.arcadedb.database.Database; import com.arcadedb.database.DatabaseFactory; import com.arcadedb.log.LogManager; -import org.junit.jupiter.api.Assertions; import java.util.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public abstract class TestHelper { public static void checkActiveDatabases() { final Collection activeDatabases = DatabaseFactory.getActiveDatabaseInstances(); @@ -18,6 +19,6 @@ public static void checkActiveDatabases() { for (final Database db : activeDatabases) db.close(); - Assertions.assertTrue(activeDatabases.isEmpty(), "Found active databases: " + activeDatabases); + assertThat(activeDatabases.isEmpty()).as("Found active databases: " + activeDatabases).isTrue(); } } diff --git a/integration/src/test/java/com/arcadedb/integration/backup/FullBackupIT.java b/integration/src/test/java/com/arcadedb/integration/backup/FullBackupIT.java index 6b7f5b37e1..a5d2c69f95 100644 --- a/integration/src/test/java/com/arcadedb/integration/backup/FullBackupIT.java +++ b/integration/src/test/java/com/arcadedb/integration/backup/FullBackupIT.java @@ -35,13 +35,16 @@ import com.arcadedb.schema.VertexType; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.*; -import java.net.*; -import java.util.concurrent.atomic.*; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class FullBackupIT { private final static String DATABASE_PATH = "target/databases/performance"; @@ -56,8 +59,8 @@ public void testFullBackupCommandLineOK() throws Exception { new Backup(("-f " + FILE + " -d " + DATABASE_PATH + " -o").split(" ")).backupDatabase(); - Assertions.assertTrue(file.exists()); - Assertions.assertTrue(file.length() > 0); + assertThat(file.exists()).isTrue(); + assertThat(file.length() > 0).isTrue(); new Restore(("-f " + FILE + " -d " + restoredDirectory + " -o").split(" ")).restoreDatabase(); @@ -76,8 +79,8 @@ public void testFullBackupAPIOK() throws Exception { new Backup(importedDatabase, FILE).backupDatabase(); - Assertions.assertTrue(file.exists()); - Assertions.assertTrue(file.length() > 0); + assertThat(file.exists()).isTrue(); + assertThat(file.length() > 0).isTrue(); new Restore(FILE, restoredDirectory.getAbsolutePath()).restoreDatabase(); @@ -137,7 +140,7 @@ public void run() { for (int k = 0; k < 500; k++) { final MutableVertex v = importedDatabase.newVertex("BackupTest").set("thread", threadId) .set("id", totalPerThread.getAndIncrement()).save(); - Assertions.assertEquals(threadBucket.getFileId(), v.getIdentity().getBucketId()); + assertThat(v.getIdentity().getBucketId()).isEqualTo(threadBucket.getFileId()); if (k + 1 % 100 == 0) { importedDatabase.commit(); @@ -159,7 +162,7 @@ public void run() { // EXECUTE 10 BACKUPS EVERY SECOND for (int i = 0; i < CONCURRENT_THREADS; i++) { - Assertions.assertFalse(importedDatabase.isTransactionActive()); + assertThat(importedDatabase.isTransactionActive()).isFalse(); final long totalVertices = importedDatabase.countType("BackupTest", true); new Backup(importedDatabase, FILE + "_" + i).setVerboseLevel(1).backupDatabase(); Thread.sleep(1000); @@ -170,8 +173,8 @@ public void run() { for (int i = 0; i < CONCURRENT_THREADS; i++) { final File file = new File(FILE + "_" + i); - Assertions.assertTrue(file.exists()); - Assertions.assertTrue(file.length() > 0); + assertThat(file.exists()).isTrue(); + assertThat(file.length() > 0).isTrue(); final String databasePath = DATABASE_PATH + "_restored_" + i; @@ -179,7 +182,7 @@ public void run() { try (final Database restoredDatabase = new DatabaseFactory(databasePath).open(ComponentFile.MODE.READ_ONLY)) { // VERIFY ONLY WHOLE TRANSACTION ARE WRITTEN - Assertions.assertTrue(restoredDatabase.countType("BackupTest", true) % 500 == 0); + assertThat(restoredDatabase.countType("BackupTest", true) % 500).isEqualTo(0); } } @@ -199,7 +202,7 @@ public void testFormatError() { try { emptyDatabase().close(); new Backup(("-f " + FILE + " -d " + DATABASE_PATH + " -o -format unknown").split(" ")).backupDatabase(); - Assertions.fail(); + fail(""); } catch (final BackupException e) { // EXPECTED } @@ -211,7 +214,7 @@ public void testFileCannotBeOverwrittenError() throws IOException { emptyDatabase().close(); new File(FILE).createNewFile(); new Backup(("-f " + FILE + " -d " + DATABASE_PATH).split(" ")).backupDatabase(); - Assertions.fail(); + fail(""); } catch (final BackupException e) { // EXPECTED } @@ -224,8 +227,8 @@ private Database importDatabase() throws Exception { ("-i " + inputFile.getFile() + " -d " + DATABASE_PATH + " -o").split(" ")); final Database importedDatabase = importer.run(); - Assertions.assertFalse(importer.isError()); - Assertions.assertTrue(new File(DATABASE_PATH).exists()); + assertThat(importer.isError()).isFalse(); + assertThat(new File(DATABASE_PATH).exists()).isTrue(); return importedDatabase; } diff --git a/integration/src/test/java/com/arcadedb/integration/exporter/JsonlExporterIT.java b/integration/src/test/java/com/arcadedb/integration/exporter/JsonlExporterIT.java index a6108d2b0d..88289b67bd 100644 --- a/integration/src/test/java/com/arcadedb/integration/exporter/JsonlExporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/exporter/JsonlExporterIT.java @@ -26,13 +26,15 @@ import com.arcadedb.utility.FileUtils; import com.arcadedb.serializer.json.JSONObject; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.*; -import java.net.*; -import java.util.zip.*; +import java.net.URL; +import java.util.zip.GZIPInputStream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class JsonlExporterIT { private final static String DATABASE_PATH = "target/databases/performance"; @@ -50,13 +52,13 @@ public void testExportOK() throws Exception { final OrientDBImporter importer = new OrientDBImporter(("-i " + inputFile.getFile() + " -d " + DATABASE_PATH + " -o").split(" ")); importer.run().close(); - Assertions.assertFalse(importer.isError()); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(importer.isError()).isFalse(); + assertThat(databaseDirectory.exists()).isTrue(); new Exporter(("-f " + FILE + " -d " + DATABASE_PATH + " -o -format jsonl").split(" ")).exportDatabase(); - Assertions.assertTrue(file.exists()); - Assertions.assertTrue(file.length() > 0); + assertThat(file.exists()).isTrue(); + assertThat(file.length() > 0).isTrue(); int lines = 0; try (final BufferedReader in = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))))) { @@ -67,7 +69,7 @@ public void testExportOK() throws Exception { } } - Assertions.assertTrue(lines > 10); + assertThat(lines > 10).isTrue(); } finally { FileUtils.deleteRecursively(databaseDirectory); @@ -80,7 +82,7 @@ public void testFormatError() { try { emptyDatabase().close(); new Exporter(("-f " + FILE + " -d " + DATABASE_PATH + " -o -format unknown").split(" ")).exportDatabase(); - Assertions.fail(); + fail(""); } catch (final ExportException e) { // EXPECTED } @@ -92,7 +94,7 @@ public void testFileCannotBeOverwrittenError() throws IOException { emptyDatabase().close(); new File(FILE).createNewFile(); new Exporter(("-f " + FILE + " -d " + DATABASE_PATH + " -format jsonl").split(" ")).exportDatabase(); - Assertions.fail(); + fail(""); } catch (final ExportException e) { // EXPECTED } diff --git a/integration/src/test/java/com/arcadedb/integration/exporter/SQLLocalExporterTest.java b/integration/src/test/java/com/arcadedb/integration/exporter/SQLLocalExporterTest.java index 3b36afde50..151d10077e 100644 --- a/integration/src/test/java/com/arcadedb/integration/exporter/SQLLocalExporterTest.java +++ b/integration/src/test/java/com/arcadedb/integration/exporter/SQLLocalExporterTest.java @@ -26,12 +26,13 @@ import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import java.net.*; +import static org.assertj.core.api.Assertions.assertThat; + public class SQLLocalExporterTest { @Test public void importAndExportDatabase() { @@ -45,19 +46,19 @@ public void importAndExportDatabase() { database.command("sql", "import database file://" + inputFile.getFile()); - Assertions.assertEquals(500, database.countType("Person", false)); - Assertions.assertEquals(10000, database.countType("Friend", false)); + assertThat(database.countType("Person", false)).isEqualTo(500); + assertThat(database.countType("Friend", false)).isEqualTo(10000); final ResultSet result = database.command("sql", "export database file://export.jsonl.tgz with `overwrite` = true"); final Result stats = result.next(); - Assertions.assertEquals(500L, (long) stats.getProperty("vertices")); - Assertions.assertEquals(10000L, (long) stats.getProperty("edges")); - Assertions.assertNull(stats.getProperty("documents")); + assertThat((long) stats.getProperty("vertices")).isEqualTo(500L); + assertThat((long) stats.getProperty("edges")).isEqualTo(10000L); + assertThat(stats.getProperty("documents")).isNull(); final File exportFile = new File("./exports/export.jsonl.tgz"); - Assertions.assertTrue(exportFile.exists()); - Assertions.assertTrue(exportFile.length() > 50_000); + assertThat(exportFile.exists()).isTrue(); + assertThat(exportFile.length() > 50_000).isTrue(); exportFile.delete(); } @@ -78,19 +79,19 @@ public void importAndExportPartialDatabase() { database.command("sql", "import database file://" + inputFile.getFile()); - Assertions.assertEquals(500, database.countType("Person", false)); - Assertions.assertEquals(10000, database.countType("Friend", false)); + assertThat(database.countType("Person", false)).isEqualTo(500); + assertThat(database.countType("Friend", false)).isEqualTo(10000); final ResultSet result = database.command("sql", "export database file://export.jsonl.tgz with `overwrite` = true, includeTypes = Person"); final Result stats = result.next(); - Assertions.assertEquals(500L, (long) stats.getProperty("vertices")); - Assertions.assertNull(stats.getProperty("edges")); - Assertions.assertNull(stats.getProperty("documents")); + assertThat((long) stats.getProperty("vertices")).isEqualTo(500L); + assertThat(stats.getProperty("edges")).isNull(); + assertThat(stats.getProperty("documents")).isNull(); final File exportFile = new File("./exports/export.jsonl.tgz"); - Assertions.assertTrue(exportFile.exists()); - Assertions.assertTrue(exportFile.length() > 50_000); + assertThat(exportFile.exists()).isTrue(); + assertThat(exportFile.length() > 50_000).isTrue(); exportFile.delete(); } diff --git a/integration/src/test/java/com/arcadedb/integration/importer/CSVImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/CSVImporterIT.java index 6d80658c70..708bba2d35 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/CSVImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/CSVImporterIT.java @@ -21,9 +21,10 @@ import com.arcadedb.database.Database; import com.arcadedb.database.DatabaseFactory; import com.arcadedb.integration.TestHelper; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class CSVImporterIT { @Test public void importDocuments() { @@ -36,7 +37,7 @@ public void importDocuments() { final Database db = databaseFactory.create(); try { db.command("sql", "import database file://src/test/resources/importer-vertices.csv"); - Assertions.assertEquals(6, db.countType("Document", true)); + assertThat(db.countType("Document", true)).isEqualTo(6); } finally { db.drop(); } @@ -56,7 +57,7 @@ public void importGraph() { importer.load(); try (final Database db = databaseFactory.open()) { - Assertions.assertEquals(6, db.countType("Node", true)); + assertThat(db.countType("Node", true)).isEqualTo(6); } importer = new Importer(("-edges src/test/resources/importer-edges.csv -database " + databasePath @@ -64,8 +65,8 @@ public void importGraph() { importer.load(); try (final Database db = databaseFactory.open()) { - Assertions.assertEquals(6, db.countType("Node", true)); - Assertions.assertEquals("Jay", db.lookupByKey("Node", "Id", 0).next().getRecord().asVertex().get("First Name")); + assertThat(db.countType("Node", true)).isEqualTo(6); + assertThat(db.lookupByKey("Node", "Id", 0).next().getRecord().asVertex().get("First Name")).isEqualTo("Jay"); } databaseFactory.open().drop(); diff --git a/integration/src/test/java/com/arcadedb/integration/importer/GloVeImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/GloVeImporterIT.java index bc79cfcdf4..54bd8a6264 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/GloVeImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/GloVeImporterIT.java @@ -26,12 +26,13 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.FileUtils; import com.arcadedb.utility.Pair; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; + public class GloVeImporterIT { @Test public void importDocuments() { @@ -50,12 +51,12 @@ public void importDocuments() { + "vertexType = Word, edgeType = Proximity, vectorProperty = vector, idProperty = name" // ); - Assertions.assertEquals(10, db.countType("Word", true)); + assertThat(db.countType("Word", true)).isEqualTo(10); final float[] key = new float[100]; ResultSet resultSet = db.query("sql", "select vectorNeighbors('Word[name,vector]', ?,?) as neighbors", key, 10); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final List> approximateResults = new ArrayList<>(); while (resultSet.hasNext()) { final Result row = resultSet.next(); diff --git a/integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java index d19202b1be..41bacc0cb8 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java @@ -26,11 +26,14 @@ import com.arcadedb.integration.TestHelper; import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.IOException; +import java.util.Iterator; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class JSONImporterIT { @Test @@ -43,13 +46,13 @@ public void importSingleObject() throws IOException { importer.load(); try (final Database db = new DatabaseFactory(databasePath).open()) { - Assertions.assertEquals(1, db.countType("Food", true)); + assertThat(db.countType("Food", true)).isEqualTo(1); final Document food = db.iterateType("Food", true).next().asDocument(true); JSONObject json = new JSONObject(FileUtils.readFileAsString(new File("src/test/resources/importer-one-object.json"))); for (Object name : json.names()) - Assertions.assertTrue(food.has(name.toString())); + assertThat(food.has(name.toString())).isTrue(); } TestHelper.checkActiveDatabases(); @@ -64,7 +67,7 @@ public void importTwoObjects() throws IOException { importer.load(); try (final Database db = new DatabaseFactory(databasePath).open()) { - Assertions.assertEquals(2, db.countType("Food", true)); + assertThat(db.countType("Food", true)).isEqualTo(2); } TestHelper.checkActiveDatabases(); @@ -115,26 +118,26 @@ public void importEmployees() throws IOException { final String name = vertex.getString("Name"); if ("Marcus".equalsIgnoreCase(name)) { - Assertions.assertEquals("1234", vertex.getString("id")); - Assertions.assertEquals(0, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")); - Assertions.assertEquals(2, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")); + assertThat(vertex.getString("id")).isEqualTo("1234"); + assertThat(vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")).isEqualTo(0); + assertThat(vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")).isEqualTo(2); } else if ("Win".equals(name)) { - Assertions.assertEquals("1230", vertex.getString("id")); - Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")); - Assertions.assertEquals(0, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")); + assertThat(vertex.getString("id")).isEqualTo("1230"); + assertThat(vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")).isEqualTo(1); + assertThat(vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")).isEqualTo(0); } else if ("Dave".equals(name)) { - Assertions.assertEquals("1232", vertex.getString("id")); - Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")); - Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")); + assertThat(vertex.getString("id")).isEqualTo("1232"); + assertThat(vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")).isEqualTo(1); + assertThat(vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")).isEqualTo(1); } else if ("Albert".equals(name)) { - Assertions.assertEquals("1239", vertex.getString("id")); - Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")); - Assertions.assertEquals(0, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")); + assertThat(vertex.getString("id")).isEqualTo("1239"); + assertThat(vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER")).isEqualTo(1); + assertThat(vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER")).isEqualTo(0); } else - Assertions.fail(); + fail(""); } - Assertions.assertEquals(4, db.countType("User", true)); + assertThat(db.countType("User", true)).isEqualTo(4); } TestHelper.checkActiveDatabases(); diff --git a/integration/src/test/java/com/arcadedb/integration/importer/Neo4jImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/Neo4jImporterIT.java index 15ac96dae5..d769ec4f0e 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/Neo4jImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/Neo4jImporterIT.java @@ -30,7 +30,7 @@ import com.arcadedb.log.LogManager; import com.arcadedb.schema.DocumentType; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; @@ -40,6 +40,9 @@ import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class Neo4jImporterIT { private final static String DATABASE_PATH = "target/databases/neo4j"; @@ -54,38 +57,38 @@ public void testImportNeo4jDirectOK() throws IOException { ("-i " + inputFile.getFile() + " -d " + DATABASE_PATH + " -o -decimalType double").split(" ")); importer.run(); - Assertions.assertFalse(importer.isError()); + assertThat(importer.isError()).isFalse(); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); try (final DatabaseFactory factory = new DatabaseFactory(DATABASE_PATH)) { try (final Database database = factory.open()) { final DocumentType personType = database.getSchema().getType("User"); - Assertions.assertNotNull(personType); - Assertions.assertEquals(3, database.countType("User", true)); + assertThat(personType).isNotNull(); + assertThat(database.countType("User", true)).isEqualTo(3); final IndexCursor cursor = database.lookupByKey("User", "id", "0"); - Assertions.assertTrue(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); final Vertex v = cursor.next().asVertex(); - Assertions.assertEquals("Adam", v.get("name")); - Assertions.assertEquals("2015-07-04T19:32:24", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(v.getLong("born"))); + assertThat(v.get("name")).isEqualTo("Adam"); + assertThat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(v.getLong("born"))).isEqualTo("2015-07-04T19:32:24"); final Map place = (Map) v.get("place"); - Assertions.assertEquals(33.46789, place.get("latitude")); - Assertions.assertNull(place.get("height")); + assertThat(place.get("latitude")).isEqualTo(33.46789); + assertThat(place.get("height")).isNull(); - Assertions.assertEquals(Arrays.asList("Sam", "Anna", "Grace"), v.get("kids")); + assertThat(v.get("kids")).isEqualTo(Arrays.asList("Sam", "Anna", "Grace")); final DocumentType friendType = database.getSchema().getType("KNOWS"); - Assertions.assertNotNull(friendType); - Assertions.assertEquals(1, database.countType("KNOWS", true)); + assertThat(friendType).isNotNull(); + assertThat(database.countType("KNOWS", true)).isEqualTo(1); final Iterator relationships = v.getEdges(Vertex.DIRECTION.OUT, "KNOWS").iterator(); - Assertions.assertTrue(relationships.hasNext()); + assertThat(relationships.hasNext()).isTrue(); final Edge e = relationships.next(); - Assertions.assertEquals(1993, e.get("since")); - Assertions.assertEquals("P5M1DT12H", e.get("bffSince")); + assertThat(e.get("since")).isEqualTo(1993); + assertThat(e.get("bffSince")).isEqualTo("P5M1DT12H"); } } TestHelper.checkActiveDatabases(); @@ -100,10 +103,10 @@ public void testImportNoFile() throws IOException { final Neo4jImporter importer = new Neo4jImporter(("-i " + inputFile.getFile() + "2 -d " + DATABASE_PATH + " -o").split(" ")); try { importer.run(); - Assertions.fail("Expected File Not Found Exception"); + fail("Expected File Not Found Exception"); } catch (final IllegalArgumentException e) { } - Assertions.assertTrue(importer.isError()); + assertThat(importer.isError()).isTrue(); } @Test @@ -170,38 +173,38 @@ public void testConcurrentCompact() throws IOException, InterruptedException { t.get().join(); - Assertions.assertFalse(importer.isError()); + assertThat(importer.isError()).isFalse(); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); try (final DatabaseFactory factory = new DatabaseFactory(DATABASE_PATH)) { try (final Database database = factory.open()) { final DocumentType personType = database.getSchema().getType("User"); - Assertions.assertNotNull(personType); - Assertions.assertEquals(TOTAL, database.countType("User", true)); + assertThat(personType).isNotNull(); + assertThat(database.countType("User", true)).isEqualTo(TOTAL); final IndexCursor cursor = database.lookupByKey("User", "id", "0"); - Assertions.assertTrue(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); final Vertex v = cursor.next().asVertex(); - Assertions.assertEquals("Adam", v.get("name")); - Assertions.assertEquals("2015-07-04T19:32:24", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(v.getLong("born"))); + assertThat(v.get("name")).isEqualTo("Adam"); + assertThat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(v.getLong("born"))).isEqualTo("2015-07-04T19:32:24"); final Map place = (Map) v.get("place"); - Assertions.assertEquals(33.46789, place.get("latitude")); - Assertions.assertNull(place.get("height")); + assertThat(place.get("latitude")).isEqualTo(33.46789); + assertThat(place.get("height")).isNull(); - Assertions.assertEquals(Arrays.asList("Sam", "Anna", "Grace"), v.get("kids")); + assertThat(v.get("kids")).isEqualTo(Arrays.asList("Sam", "Anna", "Grace")); final DocumentType friendType = database.getSchema().getType("KNOWS"); - Assertions.assertNotNull(friendType); - Assertions.assertEquals(TOTAL / 2, database.countType("KNOWS", true)); + assertThat(friendType).isNotNull(); + assertThat(database.countType("KNOWS", true)).isEqualTo(TOTAL / 2); final Iterator relationships = v.getEdges(Vertex.DIRECTION.OUT, "KNOWS").iterator(); - Assertions.assertTrue(relationships.hasNext()); + assertThat(relationships.hasNext()).isTrue(); final Edge e = relationships.next(); - Assertions.assertEquals(1993, e.get("since")); - Assertions.assertEquals("P5M1DT12H", e.get("bffSince")); + assertThat(e.get("since")).isEqualTo(1993); + assertThat(e.get("bffSince")).isEqualTo("P5M1DT12H"); } } TestHelper.checkActiveDatabases(); @@ -223,24 +226,24 @@ public void testImportNeo4jMultiTypes() throws IOException { final Neo4jImporter importer = new Neo4jImporter(("-i " + inputFile.getFile() + " -d " + DATABASE_PATH).split(" ")); importer.run(); - Assertions.assertFalse(importer.isError()); + assertThat(importer.isError()).isFalse(); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(databaseDirectory.exists()).isTrue(); try (final DatabaseFactory factory = new DatabaseFactory(DATABASE_PATH)) { try (final Database database = factory.open()) { final DocumentType placeType = database.getSchema().getType("Place"); - Assertions.assertNotNull(placeType); - Assertions.assertEquals(1, database.countType("Place", true)); + assertThat(placeType).isNotNull(); + assertThat(database.countType("Place", true)).isEqualTo(1); final DocumentType cityType = database.getSchema().getType("City"); - Assertions.assertNotNull(cityType); - Assertions.assertEquals(1, database.countType("City", true)); + assertThat(cityType).isNotNull(); + assertThat(database.countType("City", true)).isEqualTo(1); IndexCursor cursor = database.lookupByKey("City_Place", "id", "0"); - Assertions.assertTrue(cursor.hasNext()); + assertThat(cursor.hasNext()).isTrue(); Vertex v = cursor.next().asVertex(); - Assertions.assertEquals("Test", v.get("name")); + assertThat(v.get("name")).isEqualTo("Test"); } } TestHelper.checkActiveDatabases(); diff --git a/integration/src/test/java/com/arcadedb/integration/importer/OrientDBImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/OrientDBImporterIT.java index 526e6a9e4e..62a84d02d7 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/OrientDBImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/OrientDBImporterIT.java @@ -26,12 +26,15 @@ import com.arcadedb.schema.Type; import com.arcadedb.utility.FileUtils; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; import java.net.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class OrientDBImporterIT { private final static String DATABASE_PATH = "target/databases/performance"; @@ -45,29 +48,29 @@ public void testImportOK() throws Exception { final OrientDBImporter importer = new OrientDBImporter(("-i " + inputFile.getFile() + " -d " + DATABASE_PATH + " -s -o").split(" ")); importer.run().close(); - Assertions.assertFalse(importer.isError()); - Assertions.assertTrue(databaseDirectory.exists()); + assertThat(importer.isError()).isFalse(); + assertThat(databaseDirectory.exists()).isTrue(); try (final DatabaseFactory factory = new DatabaseFactory(DATABASE_PATH)) { try (final Database database = factory.open()) { final DocumentType personType = database.getSchema().getType("Person"); - Assertions.assertNotNull(personType); - Assertions.assertEquals(Type.INTEGER, personType.getProperty("id").getType()); - Assertions.assertEquals(500, database.countType("Person", true)); - Assertions.assertEquals(Schema.INDEX_TYPE.LSM_TREE, database.getSchema().getIndexByName("Person[id]").getType()); + assertThat(personType).isNotNull(); + assertThat(personType.getProperty("id").getType()).isEqualTo(Type.INTEGER); + assertThat(database.countType("Person", true)).isEqualTo(500); + assertThat(database.getSchema().getIndexByName("Person[id]").getType()).isEqualTo(Schema.INDEX_TYPE.LSM_TREE); final DocumentType friendType = database.getSchema().getType("Friend"); - Assertions.assertNotNull(friendType); - Assertions.assertEquals(Type.INTEGER, friendType.getProperty("id").getType()); - Assertions.assertEquals(10_000, database.countType("Friend", true)); - Assertions.assertEquals(Schema.INDEX_TYPE.LSM_TREE, database.getSchema().getIndexByName("Friend[id]").getType()); + assertThat(friendType).isNotNull(); + assertThat(friendType.getProperty("id").getType()).isEqualTo(Type.INTEGER); + assertThat(database.countType("Friend", true)).isEqualTo(10_000); + assertThat(database.getSchema().getIndexByName("Friend[id]").getType()).isEqualTo(Schema.INDEX_TYPE.LSM_TREE); final File securityFile = new File("./server-users.jsonl"); - Assertions.assertTrue(securityFile.exists()); + assertThat(securityFile.exists()).isTrue(); final String fileContent = FileUtils.readFileAsString(securityFile); final JSONObject security = new JSONObject(fileContent.substring(0, fileContent.indexOf("\n"))); - Assertions.assertEquals("admin", security.getString("name")); + assertThat(security.getString("name")).isEqualTo("admin"); } } } finally { @@ -82,9 +85,9 @@ public void testImportNoFile() throws Exception { final OrientDBImporter importer = new OrientDBImporter(("-i " + inputFile.getFile() + "2 -d " + DATABASE_PATH + " -s -o").split(" ")); try { importer.run(); - Assertions.fail("Expected File Not Found Exception"); + fail("Expected File Not Found Exception"); } catch (final IllegalArgumentException e) { } - Assertions.assertTrue(importer.isError()); + assertThat(importer.isError()).isTrue(); } } diff --git a/integration/src/test/java/com/arcadedb/integration/importer/SQLLocalImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/SQLLocalImporterIT.java index e74a6dbdd5..92e46a540e 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/SQLLocalImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/SQLLocalImporterIT.java @@ -23,12 +23,13 @@ import com.arcadedb.database.DatabaseFactory; import com.arcadedb.integration.TestHelper; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import java.net.*; +import static org.assertj.core.api.Assertions.assertThat; + public class SQLLocalImporterIT { @Test public void importOrientDB() { @@ -43,8 +44,8 @@ public void importOrientDB() { //database.command("sql", "import database " + "file:///Users/luca/Downloads/Reactome.gz"); database.command("sql", "import database file://" + inputFile.getFile()); - Assertions.assertEquals(500, database.countType("Person", false)); - Assertions.assertEquals(10000, database.countType("Friend", false)); + assertThat(database.countType("Person", false)).isEqualTo(500); + assertThat(database.countType("Friend", false)).isEqualTo(10000); } TestHelper.checkActiveDatabases(); diff --git a/integration/src/test/java/com/arcadedb/integration/importer/SQLRemoteImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/SQLRemoteImporterIT.java index 4f9d9d6b28..97350a904a 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/SQLRemoteImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/SQLRemoteImporterIT.java @@ -22,11 +22,12 @@ import com.arcadedb.database.DatabaseFactory; import com.arcadedb.integration.TestHelper; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class SQLRemoteImporterIT { @Test public void importOrientDB() { @@ -37,10 +38,10 @@ public void importOrientDB() { //database.command("sql", "import database https://github.com/ArcadeData/arcadedb-datasets/raw/main/orientdb/MovieRatings.gz"); database.command("sql", "import database https://github.com/ArcadeData/arcadedb-datasets/raw/main/orientdb/GratefulDeadConcerts.gz"); - Assertions.assertEquals(809, database.countType("V", false)); - Assertions.assertEquals(7047, database.countType("followed_by", false)); - Assertions.assertEquals(501, database.countType("sung_by", false)); - Assertions.assertEquals(501, database.countType("written_by", false)); + assertThat(database.countType("V", false)).isEqualTo(809); + assertThat(database.countType("followed_by", false)).isEqualTo(7047); + assertThat(database.countType("sung_by", false)).isEqualTo(501); + assertThat(database.countType("written_by", false)).isEqualTo(501); } TestHelper.checkActiveDatabases(); diff --git a/integration/src/test/java/com/arcadedb/integration/importer/Word2VecImporterIT.java b/integration/src/test/java/com/arcadedb/integration/importer/Word2VecImporterIT.java index 6055c24389..8bbdeed6a6 100644 --- a/integration/src/test/java/com/arcadedb/integration/importer/Word2VecImporterIT.java +++ b/integration/src/test/java/com/arcadedb/integration/importer/Word2VecImporterIT.java @@ -22,11 +22,12 @@ import com.arcadedb.database.DatabaseFactory; import com.arcadedb.integration.TestHelper; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class Word2VecImporterIT { @Test public void importDocuments() { @@ -44,7 +45,7 @@ public void importDocuments() { + "with distanceFunction = cosine, m = 16, ef = 128, efConstruction = 128, " // + "vertexType = Word, edgeType = Proximity, vectorProperty = vector, idProperty = name" // ); - Assertions.assertEquals(10, db.countType("Word", true)); + assertThat(db.countType("Word", true)).isEqualTo(10); } finally { db.drop(); TestHelper.checkActiveDatabases(); diff --git a/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBQueryTest.java b/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBQueryTest.java index fbdecc1155..9a203f832d 100644 --- a/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBQueryTest.java +++ b/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBQueryTest.java @@ -30,7 +30,7 @@ import java.io.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class MongoDBQueryTest { @@ -65,14 +65,14 @@ public void testOrderBy() { for (final ResultSet resultset = database.query("mongo", "{ collection: 'MongoDBCollection', query: { $and: [ { name: { $eq: 'Jay' } }, { lastName: { $exists: true } }, { lastName: { $eq: 'Miner' } }, { lastName: { $ne: 'Miner22' } } ], $orderBy: { id: 1 } } }"); resultset.hasNext(); ++i) { final Result doc = resultset.next(); - assertEquals(i, (Integer) doc.getProperty("id")); + assertThat((Integer) doc.getProperty("id")).isEqualTo(i); } i = 9; for (final ResultSet resultset = database.query("mongo", "{ collection: 'MongoDBCollection', query: { $and: [ { name: { $eq: 'Jay' } }, { lastName: { $exists: true } }, { lastName: { $eq: 'Miner' } }, { lastName: { $ne: 'Miner22' } } ], $orderBy: { id: -1 } } }"); resultset.hasNext(); --i) { final Result doc = resultset.next(); - assertEquals(i, (Integer) doc.getProperty("id")); + assertThat((Integer) doc.getProperty("id")).isEqualTo(i); } } } diff --git a/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBServerTest.java b/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBServerTest.java index bd0e14cd12..b21004ca0b 100644 --- a/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBServerTest.java +++ b/mongodbw/src/test/java/com/arcadedb/mongo/MongoDBServerTest.java @@ -36,8 +36,7 @@ import static com.mongodb.client.model.Filters.gt; import static com.mongodb.client.model.Filters.lte; import static com.mongodb.client.model.Filters.ne; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; public class MongoDBServerTest extends BaseGraphServerTest { @@ -63,7 +62,7 @@ public void beginTest() { client.getDatabase(getDatabaseName()).createCollection("MongoDBCollection"); collection = client.getDatabase(getDatabaseName()).getCollection("MongoDBCollection"); - assertEquals(0, collection.countDocuments()); + assertThat(collection.countDocuments()).isEqualTo(0); obj = new Document("id", 0).append("name", "Jay").append("lastName", "Miner").append("id", 0); collection.insertOne(obj); @@ -88,24 +87,24 @@ private Document stripMetadata(Document doc) { @Test public void testSimpleInsertQuery() { - assertEquals(10, collection.countDocuments()); - assertEquals(obj, stripMetadata(collection.find().first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: \"Jay\" } ")).first())); - assertNull(collection.find(BsonDocument.parse("{ name: \"Jay2\" } ")).first()); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $eq: \"Jay\" } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $ne: \"Jay2\" } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $in: [ \"Jay\", \"John\" ] } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $nin: [ \"Jay2\", \"John\" ] } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $lt: \"Jay2\" } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $lte: \"Jay2\" } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $gt: \"A\" } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ name: { $gte: \"A\" } } ")).first())); - assertEquals(obj, stripMetadata(collection.find(and(gt("name", "A"), lte("name", "Jay"))).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ $or: [ { name: { $eq: 'Jay' } }, { lastName: 'Miner222'} ] }")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse("{ $not: { name: { $eq: 'Jay2' } } }")).first())); - assertEquals(obj, stripMetadata(collection.find(BsonDocument.parse( - "{ $and: [ { name: { $eq: 'Jay' } }, { lastName: { $exists: true } }, { lastName: { $eq: 'Miner' } }, { lastName: { $ne: 'Miner22' } } ] }")).first())); - assertEquals(obj, stripMetadata(collection.find(and(eq("name", "Jay"), exists("lastName"), eq("lastName", "Miner"), ne("lastName", "Miner22"))).first())); + assertThat(collection.countDocuments()).isEqualTo(10); + assertThat(stripMetadata(collection.find().first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: \"Jay\" } ")).first())).isEqualTo(obj); + assertThat(collection.find(BsonDocument.parse("{ name: \"Jay2\" } ")).first()).isNull(); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $eq: \"Jay\" } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $ne: \"Jay2\" } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $in: [ \"Jay\", \"John\" ] } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $nin: [ \"Jay2\", \"John\" ] } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $lt: \"Jay2\" } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $lte: \"Jay2\" } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $gt: \"A\" } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ name: { $gte: \"A\" } } ")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(and(gt("name", "A"), lte("name", "Jay"))).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ $or: [ { name: { $eq: 'Jay' } }, { lastName: 'Miner222'} ] }")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse("{ $not: { name: { $eq: 'Jay2' } } }")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(BsonDocument.parse( + "{ $and: [ { name: { $eq: 'Jay' } }, { lastName: { $exists: true } }, { lastName: { $eq: 'Miner' } }, { lastName: { $ne: 'Miner22' } } ] }")).first())).isEqualTo(obj); + assertThat(stripMetadata(collection.find(and(eq("name", "Jay"), exists("lastName"), eq("lastName", "Miner"), ne("lastName", "Miner22"))).first())).isEqualTo(obj); } @Test @@ -115,7 +114,7 @@ public void testOrderBy() { "{ $and: [ { name: { $eq: 'Jay' } }, { lastName: { $exists: true } }, { lastName: { $eq: 'Miner' } }, { lastName: { $ne: 'Miner22' } } ], $orderBy: { id: 1 } }")) .iterator(); it.hasNext(); ++i) { final Document doc = it.next(); - assertEquals(i, doc.get("id")); + assertThat(doc.get("id")).isEqualTo(i); } i = 9; @@ -123,7 +122,7 @@ public void testOrderBy() { "{ $and: [ { name: { $eq: 'Jay' } }, { lastName: { $exists: true } }, { lastName: { $eq: 'Miner' } }, { lastName: { $ne: 'Miner22' } } ], $orderBy: { id: -1 } }")) .iterator(); it.hasNext(); --i) { final Document doc = it.next(); - assertEquals(i, doc.get("id")); + assertThat(doc.get("id")).isEqualTo(i); } } } diff --git a/network/src/test/java/com/arcadedb/remote/RemoteDatabaseHttpIT.java b/network/src/test/java/com/arcadedb/remote/RemoteDatabaseHttpIT.java index d7a2e687a3..9652206cb7 100644 --- a/network/src/test/java/com/arcadedb/remote/RemoteDatabaseHttpIT.java +++ b/network/src/test/java/com/arcadedb/remote/RemoteDatabaseHttpIT.java @@ -11,9 +11,8 @@ import java.nio.charset.*; import java.util.*; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; @@ -58,7 +57,7 @@ void testBegin() throws Exception { verify(outputStream).write(payloadAsByteArray, 0, payloadAsByteArray.length); verify(connection).getHeaderField(RemoteDatabase.ARCADEDB_SESSION_ID); - assertTrue(database.isTransactionActive()); + assertThat(database.isTransactionActive()).isTrue(); } @Test @@ -103,7 +102,7 @@ void testTransactionNotJoined() throws Exception { }, false, 1); verify(database).begin(); verify(database).commit(); - assertTrue(createdNewTx); + assertThat(createdNewTx).isTrue(); } @Test @@ -115,7 +114,7 @@ void testTransactionJoined() throws Exception { }, true, 1); verify(database, never()).begin(); verify(database, never()).commit(); - assertFalse(createdNewTx); + assertThat(createdNewTx).isFalse(); } @Test @@ -124,7 +123,7 @@ void testTransactionRollback() throws Exception { doNothing().when(database).begin(); doThrow(new RuntimeException()).when(database).commit(); - assertThrows(RuntimeException.class, () -> database.transaction(() -> { + assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> database.transaction(() -> { }, false, 1)); verify(database).begin(); } diff --git a/pom.xml b/pom.xml index 7fafde8b16..3eed9e5ba6 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,7 @@ 3.26.3 5.11.2 + 4.2.2 true @@ -355,6 +356,12 @@ ${mockito-core.version} test + + org.awaitility + awaitility + ${awaitility.version} + test + diff --git a/postgresw/pom.xml b/postgresw/pom.xml index 00f65ca681..dced04f574 100644 --- a/postgresw/pom.xml +++ b/postgresw/pom.xml @@ -67,6 +67,8 @@ com.arcadedb arcadedb-gremlin ${project.parent.version} + shaded + test diff --git a/postgresw/src/test/java/com/arcadedb/postgres/PostgresWJdbcTest.java b/postgresw/src/test/java/com/arcadedb/postgres/PostgresWJdbcTest.java index c984916400..993da17690 100644 --- a/postgresw/src/test/java/com/arcadedb/postgres/PostgresWJdbcTest.java +++ b/postgresw/src/test/java/com/arcadedb/postgres/PostgresWJdbcTest.java @@ -20,19 +20,17 @@ import com.arcadedb.GlobalConfiguration; import com.arcadedb.server.BaseGraphServerTest; -import com.arcadedb.utility.DateUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.postgresql.util.PSQLException; import java.sql.*; -import java.time.*; -import java.time.temporal.*; -import java.util.*; +import java.time.LocalDate; +import java.util.Properties; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class PostgresWJdbcTest extends BaseGraphServerTest { @Override @@ -55,7 +53,7 @@ public void testTypeNotExistsErrorManagement() throws Exception { try (final Statement st = conn.createStatement()) { try { st.executeQuery("SELECT * FROM V"); - Assertions.fail("The query should go in error"); + fail("The query should go in error"); } catch (final PSQLException e) { } } @@ -68,9 +66,9 @@ public void testParsingErrorMgmt() throws Exception { try (final Statement st = conn.createStatement()) { try { st.executeQuery("SELECT 'abc \\u30 def';"); - Assertions.fail("The query should go in error"); + fail("The query should go in error"); } catch (final PSQLException e) { - Assertions.assertTrue(e.toString().contains("Syntax error")); + assertThat(e.toString().contains("Syntax error")).isTrue(); } } } @@ -121,51 +119,51 @@ public void queryVertices() throws Exception { ResultSet rs = st.executeQuery( "SELECT name, lastName, short, int, long, float, double, boolean, date, timestamp FROM V order by id"); - Assertions.assertTrue(!rs.isAfterLast()); + assertThat(rs.isAfterLast()).isFalse(); int i = 0; while (rs.next()) { if (rs.getString(1).equalsIgnoreCase("Jay")) { - Assertions.assertEquals("Jay", rs.getString(1)); - Assertions.assertEquals("Miner", rs.getString(2)); + assertThat(rs.getString(1)).isEqualTo("Jay"); + assertThat(rs.getString(2)).isEqualTo("Miner"); ++i; } else if (rs.getString(1).equalsIgnoreCase("Rocky")) { - Assertions.assertEquals("Balboa", rs.getString(2)); - Assertions.assertEquals((short) 3, rs.getShort(3)); - Assertions.assertEquals(4, rs.getInt(4)); - Assertions.assertEquals(5L, rs.getLong(5)); - Assertions.assertEquals(6F, rs.getFloat(6)); - Assertions.assertEquals(7D, rs.getDouble(7)); - Assertions.assertEquals(false, rs.getBoolean(8)); - Assertions.assertEquals(LocalDate.now(), rs.getDate(9).toLocalDate()); - Assertions.assertEquals(now, rs.getTimestamp(10).getTime()); + assertThat(rs.getString(2)).isEqualTo("Balboa"); + assertThat(rs.getShort(3)).isEqualTo((short) 3); + assertThat(rs.getInt(4)).isEqualTo(4); + assertThat(rs.getLong(5)).isEqualTo(5L); + assertThat(rs.getFloat(6)).isEqualTo(6F); + assertThat(rs.getDouble(7)).isEqualTo(7D); + assertThat(rs.getBoolean(8)).isFalse(); + assertThat(rs.getDate(9).toLocalDate()).isEqualTo(LocalDate.now()); + assertThat(rs.getTimestamp(10).getTime()).isEqualTo(now); ++i; } else - Assertions.fail("Unknown value"); + fail("Unknown value"); } - Assertions.assertEquals(TOTAL + 1, i); + assertThat(i).isEqualTo(TOTAL + 1); rs.close(); rs = st.executeQuery("SELECT FROM V order by id"); - Assertions.assertTrue(!rs.isAfterLast()); + assertThat(rs.isAfterLast()).isFalse(); i = 0; while (rs.next()) { - Assertions.assertTrue(rs.findColumn("@rid") > -1); - Assertions.assertTrue(rs.findColumn("@type") > -1); - Assertions.assertTrue(rs.findColumn("@cat") > -1); + assertThat(rs.findColumn("@rid") > -1).isTrue(); + assertThat(rs.findColumn("@type") > -1).isTrue(); + assertThat(rs.findColumn("@cat") > -1).isTrue(); - Assertions.assertTrue(rs.getString(rs.findColumn("@rid")).startsWith("#")); - Assertions.assertEquals("V", rs.getString(rs.findColumn("@type"))); - Assertions.assertEquals("v", rs.getString(rs.findColumn("@cat"))); + assertThat(rs.getString(rs.findColumn("@rid")).startsWith("#")).isTrue(); + assertThat(rs.getString(rs.findColumn("@type"))).isEqualTo("V"); + assertThat(rs.getString(rs.findColumn("@cat"))).isEqualTo("v"); ++i; } - Assertions.assertEquals(TOTAL + 1, i); + assertThat(i).isEqualTo(TOTAL + 1); } } @@ -188,25 +186,25 @@ public void queryTransaction() throws Exception { final ResultSet rs = st.executeQuery("SELECT * FROM V"); - Assertions.assertTrue(!rs.isAfterLast()); + assertThat(rs.isAfterLast()).isFalse(); int i = 0; while (rs.next()) { if (rs.getString(1).equalsIgnoreCase("Jay")) { - Assertions.assertEquals("Jay", rs.getString(1)); - Assertions.assertEquals("Miner", rs.getString(2)); + assertThat(rs.getString(1)).isEqualTo("Jay"); + assertThat(rs.getString(2)).isEqualTo("Miner"); ++i; } else if (rs.getString(1).equalsIgnoreCase("Rocky")) { - Assertions.assertEquals("Rocky", rs.getString(1)); - Assertions.assertEquals("Balboa", rs.getString(2)); + assertThat(rs.getString(1)).isEqualTo("Rocky"); + assertThat(rs.getString(2)).isEqualTo("Balboa"); ++i; } else - Assertions.fail("Unknown value"); + fail("Unknown value"); } st.execute("commit"); - Assertions.assertEquals(2, i); + assertThat(i).isEqualTo(2); rs.close(); } @@ -230,19 +228,19 @@ void testCypher() throws Exception { int numberOfPeople = 0; while (rs.next()) { - Assertions.assertNotNull(rs.getString(1)); + assertThat(rs.getString(1)).isNotNull(); if (rs.getString(1).equals("James")) - Assertions.assertEquals(1.9F, rs.getFloat(2)); + assertThat(rs.getFloat(2)).isEqualTo(1.9F); else if (rs.getString(1).equals("Henry")) - Assertions.assertNull(rs.getString(2)); + assertThat(rs.getString(2)).isNull(); else - Assertions.fail(); + fail(""); ++numberOfPeople; } - Assertions.assertEquals(2, numberOfPeople); + assertThat(numberOfPeople).isEqualTo(2); st.execute("commit"); } } diff --git a/postgresw/src/test/java/com/arcadedb/postgres/TomcatConnectionPoolPostgresWJdbcTest.java b/postgresw/src/test/java/com/arcadedb/postgres/TomcatConnectionPoolPostgresWJdbcTest.java index 7261326ccc..71ef8645de 100644 --- a/postgresw/src/test/java/com/arcadedb/postgres/TomcatConnectionPoolPostgresWJdbcTest.java +++ b/postgresw/src/test/java/com/arcadedb/postgres/TomcatConnectionPoolPostgresWJdbcTest.java @@ -23,13 +23,14 @@ import org.apache.tomcat.jdbc.pool.DataSource; import org.apache.tomcat.jdbc.pool.PoolProperties; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.postgresql.util.PSQLException; import java.sql.*; -import java.util.*; +import java.util.Properties; + +import static org.assertj.core.api.Assertions.fail; public class TomcatConnectionPoolPostgresWJdbcTest extends BaseGraphServerTest { @Override @@ -99,7 +100,7 @@ public void testTypeNotExistsErrorManagement() throws Exception { try (final Statement st = conn.createStatement()) { try { st.executeQuery("SELECT * FROM V"); - Assertions.fail("The query should go in error"); + fail("The query should go in error"); } catch (final PSQLException e) { } } diff --git a/redisw/src/test/java/com/arcadedb/redis/RedisWTest.java b/redisw/src/test/java/com/arcadedb/redis/RedisWTest.java index 212d39d470..1bbdf49c72 100644 --- a/redisw/src/test/java/com/arcadedb/redis/RedisWTest.java +++ b/redisw/src/test/java/com/arcadedb/redis/RedisWTest.java @@ -24,12 +24,15 @@ import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.serializer.json.JSONObject; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import redis.clients.jedis.Jedis; import redis.clients.jedis.exceptions.JedisDataException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class RedisWTest extends BaseGraphServerTest { @@ -42,8 +45,8 @@ public void testRAMCommands() { final Jedis jedis = new Jedis("localhost", DEF_PORT); // PING - Assertions.assertEquals("PONG", jedis.ping()); - Assertions.assertEquals("This is a test", jedis.ping("This is a test")); + assertThat(jedis.ping()).isEqualTo("PONG"); + assertThat(jedis.ping("This is a test")).isEqualTo("This is a test"); // SET long beginTime = System.currentTimeMillis(); @@ -52,14 +55,14 @@ public void testRAMCommands() { System.out.println("SET " + TOTAL_RAM + " items in the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); // EXISTS - Assertions.assertFalse(jedis.exists("fooNotFound")); + assertThat(jedis.exists("fooNotFound")).isFalse(); beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertTrue(jedis.exists("foo" + i)); + assertThat(jedis.exists("foo" + i)).isTrue(); System.out.println("EXISTS " + TOTAL_RAM + " items in the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); - Assertions.assertEquals(0, jedis.exists("fooNotFound", "eitherThis")); + assertThat(jedis.exists("fooNotFound", "eitherThis")).isEqualTo(0); beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; i += 10) { @@ -67,7 +70,7 @@ public void testRAMCommands() { for (int k = 0; k < 10; ++k) keyChunk[k] = "foo" + (i + k); final Long result = jedis.exists(keyChunk); - Assertions.assertEquals(10, result); + assertThat(result).isEqualTo(10); } System.out.println( "MULTI EXISTS (chunk of 10 keys) " + TOTAL_RAM + " items in the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); @@ -75,47 +78,47 @@ public void testRAMCommands() { // GET beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertEquals(String.valueOf(i), jedis.get("foo" + i)); + assertThat(jedis.get("foo" + i)).isEqualTo(String.valueOf(i)); System.out.println("GET " + TOTAL_RAM + " items from the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); // INCR beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertEquals(i + 1L, jedis.incr("foo" + i)); + assertThat(jedis.incr("foo" + i)).isEqualTo(i + 1L); System.out.println("INCR " + TOTAL_RAM + " items from the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); // DECR beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertEquals(i, jedis.decr("foo" + i)); + assertThat(jedis.decr("foo" + i)).isEqualTo(i); System.out.println("DECR " + TOTAL_RAM + " items from the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); // INCRBY beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertEquals(i + 3L, jedis.incrBy("foo" + i, 3)); + assertThat(jedis.incrBy("foo" + i, 3)).isEqualTo(i + 3L); System.out.println("INCRBY " + TOTAL_RAM + " items from the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); // DECRBY beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertEquals(i, jedis.decrBy("foo" + i, 3)); + assertThat(jedis.decrBy("foo" + i, 3)).isEqualTo(i); System.out.println("DECRBY " + TOTAL_RAM + " items from the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); // INCRBYFLOAT beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertEquals(i + 3.3D, jedis.incrByFloat("foo" + i, 3.3)); + assertThat(jedis.incrByFloat("foo" + i, 3.3)).isEqualTo(i + 3.3D); System.out.println("INCRBYFLOAT " + TOTAL_RAM + " items from the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); // GETDEL beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertEquals(String.valueOf(i + 3.3D), jedis.getDel("foo" + i)); + assertThat(jedis.getDel("foo" + i)).isEqualTo(String.valueOf(i + 3.3D)); System.out.println("GETDEL " + TOTAL_RAM + " items from the default bucket. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); for (int i = 0; i < TOTAL_RAM; ++i) - Assertions.assertNull(jedis.get("foo" + i)); + assertThat(jedis.get("foo" + i)).isNull(); } @Test @@ -140,8 +143,8 @@ public void testPersistentCommands() { beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_PERSISTENT; ++i) { // RETRIEVE BY ID (LONG) - Assertions.assertTrue(jedis.hexists(getDatabaseName() + ".Account[id]", String.valueOf(i))); - Assertions.assertTrue(jedis.hexists(getDatabaseName() + ".Account[email]", "jay.miner" + i + "@commodore.com")); + assertThat(jedis.hexists(getDatabaseName() + ".Account[id]", String.valueOf(i))).isTrue(); + assertThat(jedis.hexists(getDatabaseName() + ".Account[email]", "jay.miner" + i + "@commodore.com")).isTrue(); } System.out.println("HEXISTS " + TOTAL_PERSISTENT + " items to the database. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); @@ -157,28 +160,28 @@ public void testPersistentCommands() { // RETRIEVE BY ID (LONG) JSONObject doc = new JSONObject(jedis.hget(getDatabaseName() + ".Account[id]", String.valueOf(i))); - Assertions.assertNotNull(doc.getString("@rid")); - Assertions.assertEquals("Account", doc.getString("@type")); + assertThat(doc.getString("@rid")).isNotNull(); + assertThat(doc.getString("@type")).isEqualTo("Account"); doc.remove("@type"); doc.remove("@rid"); doc.remove("@cat"); - Assertions.assertEquals(expectedJson.toMap(), doc.toMap()); + assertThat(doc.toMap()).isEqualTo(expectedJson.toMap()); // RETRIEVE BY EMAIL (STRING) doc = new JSONObject(jedis.hget(getDatabaseName() + ".Account[email]", "jay.miner" + i + "@commodore.com")); - Assertions.assertNotNull(doc.getString("@rid")); - Assertions.assertEquals("Account", doc.getString("@type")); + assertThat(doc.getString("@rid")).isNotNull(); + assertThat(doc.getString("@type")).isEqualTo("Account"); doc.remove("@type"); doc.remove("@rid"); doc.remove("@cat"); - Assertions.assertEquals(expectedJson.toMap(), doc.toMap()); + assertThat(doc.toMap()).isEqualTo(expectedJson.toMap()); // RETRIEVE BY EMAIL (STRING) doc = new JSONObject(jedis.hget(getDatabaseName() + ".Account[email]", "jay.miner" + i + "@commodore.com")); - Assertions.assertNotNull(doc.getString("@rid")); - Assertions.assertEquals("Account", doc.getString("@type")); + assertThat(doc.getString("@rid")).isNotNull(); + assertThat(doc.getString("@type")).isEqualTo("Account"); doc.remove("@type"); doc.remove("@cat"); @@ -186,21 +189,21 @@ public void testPersistentCommands() { final Object rid = doc.remove("@rid"); rids.add(new RID(database, rid.toString())); - Assertions.assertEquals(expectedJson.toMap(), doc.toMap()); + assertThat(doc.toMap()).isEqualTo(expectedJson.toMap()); // RETRIEVE BY RID doc = new JSONObject(jedis.hget(getDatabaseName(), rid.toString())); - Assertions.assertNotNull(doc.getString("@rid")); - Assertions.assertEquals("Account", doc.getString("@type")); + assertThat(doc.getString("@rid")).isNotNull(); + assertThat(doc.getString("@type")).isEqualTo("Account"); doc.remove("@rid"); doc.remove("@type"); doc.remove("@cat"); - Assertions.assertEquals(expectedJson.toMap(), doc.toMap()); + assertThat(doc.toMap()).isEqualTo(expectedJson.toMap()); } System.out.println("HGET " + TOTAL_PERSISTENT + " items by 2 keys + rid from the database. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); - Assertions.assertEquals(TOTAL_PERSISTENT, rids.size()); + assertThat(rids.size()).isEqualTo(TOTAL_PERSISTENT); beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_PERSISTENT; i += 10) { @@ -211,11 +214,11 @@ public void testPersistentCommands() { // RETRIEVE BY CHUNK OF 10 RIDS final List result = jedis.hmget(getDatabaseName(), ridChunk); - Assertions.assertEquals(10, result.size()); + assertThat(result.size()).isEqualTo(10); for (int k = 0; k < 10; ++k) { final JSONObject doc = new JSONObject(result.get(k)); - Assertions.assertEquals("Account", doc.getString("@type")); + assertThat(doc.getString("@type")).isEqualTo("Account"); } } @@ -226,7 +229,7 @@ public void testPersistentCommands() { beginTime = System.currentTimeMillis(); for (int i = 0; i < TOTAL_PERSISTENT; i += 2) { // DELETE BY ID (LONG) - Assertions.assertEquals(2, jedis.hdel(getDatabaseName() + ".Account[id]", String.valueOf(i), String.valueOf(i + 1))); + assertThat(jedis.hdel(getDatabaseName() + ".Account[id]", String.valueOf(i), String.valueOf(i + 1))).isEqualTo(2); } System.out.println("HDEL " + TOTAL_PERSISTENT + " items from the database. Elapsed " + (System.currentTimeMillis() - beginTime) + "ms"); } @@ -236,10 +239,10 @@ public void testCommandNotSupported() { final Jedis jedis = new Jedis("localhost", DEF_PORT); try { jedis.aclList(); - Assertions.fail(); + fail(""); } catch (final JedisDataException e) { // EXPECTED - Assertions.assertEquals("Command not found", e.getMessage()); + assertThat(e.getMessage()).isEqualTo("Command not found"); } } diff --git a/server/src/test/java/com/arcadedb/remote/RemoteDatabaseIT.java b/server/src/test/java/com/arcadedb/remote/RemoteDatabaseIT.java index 81414af934..41b1803cb4 100644 --- a/server/src/test/java/com/arcadedb/remote/RemoteDatabaseIT.java +++ b/server/src/test/java/com/arcadedb/remote/RemoteDatabaseIT.java @@ -35,6 +35,7 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.BaseGraphServerTest; import org.junit.jupiter.api.AfterEach; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,6 +43,8 @@ import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.*; + public class RemoteDatabaseIT extends BaseGraphServerTest { private static final String DATABASE_NAME = "remote-database"; @@ -53,9 +56,9 @@ protected boolean isCreateDatabases() { @Test public void simpleTxDocuments() throws Exception { testEachServer((serverIndex) -> { - Assertions.assertTrue( + assertThat( new RemoteServer("127.0.0.1", 2480 + serverIndex, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).exists( - DATABASE_NAME)); + DATABASE_NAME)).isTrue(); final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); @@ -66,44 +69,44 @@ public void simpleTxDocuments() throws Exception { database.transaction(() -> { // CREATE DOCUMENT VIA API final MutableDocument jay = database.newDocument("Person").set("name", "Jay").save(); - Assertions.assertNotNull(jay); - Assertions.assertEquals("Jay", jay.getString("name")); - Assertions.assertNotNull(jay.getIdentity()); + assertThat(jay).isNotNull(); + assertThat(jay.getString("name")).isEqualTo("Jay"); + assertThat(jay.getIdentity()).isNotNull(); jay.save(); // TEST DELETION AND LOOKUP jay.delete(); try { jay.reload(); - Assertions.fail(); + fail(); } catch (RecordNotFoundException e) { // EXPECTED } // CREATE DOCUMENT VIA SQL ResultSet result = database.command("SQL", "insert into Person set name = 'Elon'"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat((Iterator) result).isNotNull(); + assertThat(result.hasNext()).isTrue(); final Result rec = result.next(); - Assertions.assertTrue(rec.toJSON().toString().contains("Elon")); - Assertions.assertEquals("Elon", rec.toElement().toMap().get("name")); + assertThat(rec.toJSON().toString().contains("Elon")).isTrue(); + assertThat(rec.toElement().toMap().get("name")).isEqualTo("Elon"); final RID rid = rec.toElement().getIdentity(); // RETRIEVE DOCUMENT WITH QUERY result = database.query("SQL", "select from Person where name = 'Elon'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); // UPDATE DOCUMENT WITH COMMAND result = database.command("SQL", "update Person set lastName = 'Musk' where name = 'Elon'"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(1, result.next().toJSON().getInt("count")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().toJSON().getInt("count")).isEqualTo(1); final Document record = (Document) database.lookupByRID(rid); - Assertions.assertNotNull(result); - Assertions.assertEquals("Musk", record.getString("lastName")); + assertThat((Iterator) result).isNotNull(); + assertThat(record.getString("lastName")).isEqualTo("Musk"); - Assertions.assertEquals(1L, database.countType("Person", true)); - Assertions.assertEquals(1L, database.countType("Person", false)); + assertThat(database.countType("Person", true)).isEqualTo(1L); + assertThat(database.countType("Person", false)).isEqualTo(1L); long totalInBuckets = 0L; for (int i = 0; i < 100; i++) { @@ -114,13 +117,13 @@ public void simpleTxDocuments() throws Exception { break; } } - Assertions.assertEquals(1L, totalInBuckets); + assertThat(totalInBuckets).isEqualTo(1L); }); // RETRIEVE DOCUMENT WITH QUERY AFTER COMMIT final ResultSet result = database.query("SQL", "select from Person where name = 'Elon'"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("Musk", result.next().getProperty("lastName")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("lastName")).isEqualTo("Musk"); }); } @@ -142,91 +145,91 @@ public void simpleTxGraph() throws Exception { database.transaction(() -> { // CREATE VERTEX TYPE ResultSet result = database.command("SQL", "create vertex type Character"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat((Iterator) result).isNotNull(); + assertThat(result.hasNext()).isTrue(); // CREATE DOCUMENT VIA API final MutableVertex jay = database.newVertex("Character").set("name", "Jay").save(); - Assertions.assertTrue(jay instanceof RemoteMutableVertex); + assertThat(jay instanceof RemoteMutableVertex).isTrue(); - Assertions.assertNotNull(jay); - Assertions.assertEquals("Jay", jay.getString("name")); - Assertions.assertNotNull(jay.getIdentity()); + assertThat(jay).isNotNull(); + assertThat(jay.getString("name")).isEqualTo("Jay"); + assertThat(jay.getIdentity()).isNotNull(); jay.save(); - Assertions.assertNotNull(jay); - Assertions.assertEquals("Jay", jay.getString("name")); - Assertions.assertNotNull(jay.getIdentity()); + assertThat(jay).isNotNull(); + assertThat(jay.getString("name")).isEqualTo("Jay"); + assertThat(jay.getIdentity()).isNotNull(); jay.save(); // CREATE DOCUMENT VIA API final Map map = Map.of("on", "today", "for", "5 days"); Edge edge = jay.newEdge(EDGE1_TYPE_NAME, jay, true, map).save(); - Assertions.assertTrue(edge instanceof RemoteMutableEdge); - Assertions.assertEquals("today", edge.get("on")); - Assertions.assertEquals("5 days", edge.get("for")); + assertThat(edge instanceof RemoteMutableEdge).isTrue(); + assertThat(edge.get("on")).isEqualTo("today"); + assertThat(edge.get("for")).isEqualTo("5 days"); // TEST DELETION AND LOOKUP jay.delete(); try { jay.reload(); - Assertions.fail(); + fail(); } catch (RecordNotFoundException e) { // EXPECTED } // CREATE VERTEX 1 result = database.command("SQL", "insert into Character set name = 'Elon'"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat((Iterator) result).isNotNull(); + assertThat(result.hasNext()).isTrue(); Result rec = result.next(); - Assertions.assertTrue(rec.toJSON().toString().contains("Elon")); - Assertions.assertEquals("Elon", rec.toElement().toMap().get("name")); + assertThat(rec.toJSON().toString().contains("Elon")).isTrue(); + assertThat(rec.toElement().toMap().get("name")).isEqualTo("Elon"); final RID rid1 = rec.getIdentity().get(); // CREATE VERTEX 2 result = database.command("SQL", "create vertex Character set name = 'Kimbal'"); - Assertions.assertNotNull(result); - Assertions.assertTrue(result.hasNext()); + assertThat((Iterator) result).isNotNull(); + assertThat(result.hasNext()).isTrue(); rec = result.next(); - Assertions.assertTrue(rec.toJSON().toString().contains("Kimbal")); - Assertions.assertEquals("Kimbal", rec.toElement().toMap().get("name")); + assertThat(rec.toJSON().toString().contains("Kimbal")).isTrue(); + assertThat(rec.toElement().toMap().get("name")).isEqualTo("Kimbal"); final RID rid2 = rec.getIdentity().get(); // RETRIEVE VERTEX WITH QUERY result = database.query("SQL", "select from Character where name = 'Elon'"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertTrue(result.next().isVertex()); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().isVertex()).isTrue(); // UPDATE VERTEX WITH COMMAND result = database.command("SQL", "update Character set lastName = 'Musk' where name = 'Elon' or name = 'Kimbal'"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(2, result.next().toJSON().getInt("count")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().toJSON().getInt("count")).isEqualTo(2); // CREATE EDGE WITH COMMAND result = database.command("SQL", "create edge " + EDGE1_TYPE_NAME + " from " + rid1 + " to " + rid2); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); edge = result.next().getEdge().get(); edge.toMap(); edge.toJSON(); - Assertions.assertEquals(EDGE1_TYPE_NAME, edge.getTypeName()); - Assertions.assertEquals(rid1, edge.getOut()); - Assertions.assertEquals(rid2, edge.getIn()); + assertThat(edge.getTypeName()).isEqualTo(EDGE1_TYPE_NAME); + assertThat(edge.getOut()).isEqualTo(rid1); + assertThat(edge.getIn()).isEqualTo(rid2); Vertex record = (Vertex) database.lookupByRID(rid1); - Assertions.assertNotNull(record); - Assertions.assertEquals("Elon", record.getString("name")); - Assertions.assertEquals("Musk", record.getString("lastName")); + assertThat(record).isNotNull(); + assertThat(record.getString("name")).isEqualTo("Elon"); + assertThat(record.getString("lastName")).isEqualTo("Musk"); record.toMap(); record.toJSON(); record = (Vertex) database.lookupByRID(rid2); - Assertions.assertNotNull(record); - Assertions.assertEquals("Kimbal", record.getString("name")); - Assertions.assertEquals("Musk", record.getString("lastName")); + assertThat(record).isNotNull(); + assertThat(record.getString("name")).isEqualTo("Kimbal"); + assertThat(record.getString("lastName")).isEqualTo("Musk"); final MutableDocument mutable = record.modify(); mutable.set("extra", 100); @@ -235,81 +238,81 @@ record = (Vertex) database.lookupByRID(rid2); // RETRIEVE VERTEX WITH QUERY AFTER COMMIT final ResultSet result = database.query("SQL", "select from Character where name = 'Kimbal'"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result record = result.next(); - Assertions.assertTrue(record.isVertex()); + assertThat(record.isVertex()).isTrue(); final Vertex kimbal = record.getVertex().get(); - Assertions.assertEquals("Musk", kimbal.getString("lastName")); - Assertions.assertEquals(100, kimbal.getInteger("extra")); + assertThat(kimbal.getString("lastName")).isEqualTo("Musk"); + assertThat(kimbal.getInteger("extra")).isEqualTo(100); - Assertions.assertTrue(kimbal.toMap().containsKey("@cat")); - Assertions.assertTrue(kimbal.toMap().containsKey("@type")); - Assertions.assertFalse(kimbal.toMap().containsKey("@out")); - Assertions.assertFalse(kimbal.toMap().containsKey("@in")); + assertThat(kimbal.toMap().containsKey("@cat")).isTrue(); + assertThat(kimbal.toMap().containsKey("@type")).isTrue(); + assertThat(kimbal.toMap().containsKey("@out")).isFalse(); + assertThat(kimbal.toMap().containsKey("@in")).isFalse(); kimbal.toJSON(); final Iterator connected = kimbal.getVertices(Vertex.DIRECTION.IN).iterator(); - Assertions.assertTrue(connected.hasNext()); + assertThat(connected.hasNext()).isTrue(); final Vertex elon = connected.next(); - Assertions.assertEquals("Musk", elon.getString("lastName")); - - Assertions.assertEquals(1L, kimbal.countEdges(Vertex.DIRECTION.IN, null)); - Assertions.assertEquals(1L, kimbal.countEdges(Vertex.DIRECTION.IN, EDGE1_TYPE_NAME)); - Assertions.assertEquals(0L, kimbal.countEdges(Vertex.DIRECTION.IN, EDGE2_TYPE_NAME)); - Assertions.assertEquals(0, kimbal.countEdges(Vertex.DIRECTION.OUT, null)); - Assertions.assertEquals(0, kimbal.countEdges(Vertex.DIRECTION.OUT, EDGE1_TYPE_NAME)); - Assertions.assertEquals(0L, kimbal.countEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME)); - - Assertions.assertEquals(1L, elon.countEdges(Vertex.DIRECTION.OUT, null)); - Assertions.assertEquals(1L, elon.countEdges(Vertex.DIRECTION.OUT, EDGE1_TYPE_NAME)); - Assertions.assertEquals(0L, elon.countEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME)); - Assertions.assertEquals(0, elon.countEdges(Vertex.DIRECTION.IN, null)); - Assertions.assertEquals(0, elon.countEdges(Vertex.DIRECTION.IN, EDGE1_TYPE_NAME)); - Assertions.assertEquals(0L, elon.countEdges(Vertex.DIRECTION.IN, EDGE2_TYPE_NAME)); - - Assertions.assertTrue(kimbal.isConnectedTo(elon.getIdentity())); - Assertions.assertTrue(kimbal.isConnectedTo(elon.getIdentity(), Vertex.DIRECTION.IN)); - Assertions.assertFalse(kimbal.isConnectedTo(elon.getIdentity(), Vertex.DIRECTION.OUT)); - - Assertions.assertTrue(elon.isConnectedTo(kimbal.getIdentity())); - Assertions.assertTrue(elon.isConnectedTo(kimbal.getIdentity(), Vertex.DIRECTION.OUT)); - Assertions.assertFalse(elon.isConnectedTo(kimbal.getIdentity(), Vertex.DIRECTION.IN)); + assertThat(elon.getString("lastName")).isEqualTo("Musk"); + + assertThat(kimbal.countEdges(Vertex.DIRECTION.IN, null)).isEqualTo(1L); + assertThat(kimbal.countEdges(Vertex.DIRECTION.IN, EDGE1_TYPE_NAME)).isEqualTo(1L); + assertThat(kimbal.countEdges(Vertex.DIRECTION.IN, EDGE2_TYPE_NAME)).isEqualTo(0L); + assertThat(kimbal.countEdges(Vertex.DIRECTION.OUT, null)).isEqualTo(0); + assertThat(kimbal.countEdges(Vertex.DIRECTION.OUT, EDGE1_TYPE_NAME)).isEqualTo(0); + assertThat(kimbal.countEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME)).isEqualTo(0L); + + assertThat(elon.countEdges(Vertex.DIRECTION.OUT, null)).isEqualTo(1L); + assertThat(elon.countEdges(Vertex.DIRECTION.OUT, EDGE1_TYPE_NAME)).isEqualTo(1L); + assertThat(elon.countEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME)).isEqualTo(0L); + assertThat(elon.countEdges(Vertex.DIRECTION.IN, null)).isEqualTo(0); + assertThat(elon.countEdges(Vertex.DIRECTION.IN, EDGE1_TYPE_NAME)).isEqualTo(0); + assertThat(elon.countEdges(Vertex.DIRECTION.IN, EDGE2_TYPE_NAME)).isEqualTo(0); + + assertThat(kimbal.isConnectedTo(elon.getIdentity())).isTrue(); + assertThat(kimbal.isConnectedTo(elon.getIdentity(), Vertex.DIRECTION.IN)).isTrue(); + assertThat(kimbal.isConnectedTo(elon.getIdentity(), Vertex.DIRECTION.OUT)).isFalse(); + + assertThat(elon.isConnectedTo(kimbal.getIdentity())).isTrue(); + assertThat(elon.isConnectedTo(kimbal.getIdentity(), Vertex.DIRECTION.OUT)).isTrue(); + assertThat(elon.isConnectedTo(kimbal.getIdentity(), Vertex.DIRECTION.IN)).isFalse(); final MutableEdge newEdge = elon.newEdge(EDGE2_TYPE_NAME, kimbal, true, "since", "today"); - Assertions.assertEquals(newEdge.getOut(), elon.getIdentity()); - Assertions.assertEquals(newEdge.getOutVertex(), elon); - Assertions.assertEquals(newEdge.getIn(), kimbal.getIdentity()); - Assertions.assertEquals(newEdge.getInVertex(), kimbal); + assertThat(elon.getIdentity()).isEqualTo(newEdge.getOut()); + assertThat(elon).isEqualTo(newEdge.getOutVertex()); + assertThat(kimbal.getIdentity()).isEqualTo(newEdge.getIn()); + assertThat(kimbal).isEqualTo(newEdge.getInVertex()); newEdge.set("updated", true); newEdge.save(); // SAME BUT FROM A MUTABLE INSTANCE final MutableEdge newEdge2 = elon.modify().newEdge(EDGE2_TYPE_NAME, kimbal, true, "since", "today"); - Assertions.assertEquals(newEdge2.getOut(), elon.getIdentity()); - Assertions.assertEquals(newEdge2.getOutVertex(), elon); - Assertions.assertEquals(newEdge2.getIn(), kimbal.getIdentity()); - Assertions.assertEquals(newEdge2.getInVertex(), kimbal); + assertThat(elon.getIdentity()).isEqualTo(newEdge2.getOut()); + assertThat(elon).isEqualTo(newEdge2.getOutVertex()); + assertThat(kimbal.getIdentity()).isEqualTo(newEdge2.getIn()); + assertThat(kimbal).isEqualTo(newEdge2.getInVertex()); newEdge2.delete(); final Edge edge = elon.getEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME).iterator().next(); - Assertions.assertEquals(edge.getOut(), elon.getIdentity()); - Assertions.assertEquals(edge.getOutVertex(), elon); - Assertions.assertEquals(edge.getIn(), kimbal.getIdentity()); - Assertions.assertEquals(edge.getInVertex(), kimbal); - Assertions.assertTrue(edge.getBoolean("updated")); + assertThat(elon.getIdentity()).isEqualTo(edge.getOut()); + assertThat(elon).isEqualTo(edge.getOutVertex()); + assertThat(kimbal.getIdentity()).isEqualTo(edge.getIn()); + assertThat(kimbal).isEqualTo(edge.getInVertex()); + assertThat(edge.getBoolean("updated")).isTrue(); // DELETE THE EDGE edge.delete(); - Assertions.assertFalse(elon.getEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME).iterator().hasNext()); + assertThat(elon.getEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME).iterator().hasNext()).isFalse(); // DELETE ONE VERTEX elon.delete(); try { database.lookupByRID(elon.getIdentity()); - Assertions.fail(); + fail(); } catch (final RecordNotFoundException e) { // EXPECTED } @@ -322,9 +325,9 @@ public void testTransactionIsolation() throws Exception { final int TOTAL_TRANSACTIONS = 100; final int BATCH_SIZE = 100; - Assertions.assertTrue( + assertThat( new RemoteServer("127.0.0.1", 2480 + serverIndex, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).exists( - DATABASE_NAME)); + DATABASE_NAME)).isTrue(); final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); @@ -341,10 +344,10 @@ public void testTransactionIsolation() throws Exception { while (checkThreadRunning.get()) { Thread.sleep(1000); ResultSet result = database.query("SQL", "select from Person"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); int total = 0; while (result.hasNext()) { - Assertions.assertNotNull(result.next().getProperty("name")); + assertThat(result.next().getProperty("name")).isNotNull(); ++total; } //System.out.println("Parallel thread browsed " + total + " records (limit 20,000)"); @@ -362,22 +365,22 @@ public void testTransactionIsolation() throws Exception { database.transaction(() -> { for (int j = 0; j < BATCH_SIZE; j++) { final MutableDocument jay = database.newDocument("Person").set("name", "Jay").save(); - Assertions.assertNotNull(jay); - Assertions.assertEquals("Jay", jay.getString("name")); - Assertions.assertNotNull(jay.getIdentity()); + assertThat(jay).isNotNull(); + assertThat(jay.getString("name")).isEqualTo("Jay"); + assertThat(jay.getIdentity()).isNotNull(); jay.save(); } // TEST ISOLATION: COUNT SHOULD SEE THE MOST RECENT CHANGES BEFORE THE COMMIT ResultSet result = database.query("SQL", "select count(*) as total from Person"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(executedBatches * BATCH_SIZE, (int) result.next().getProperty("total")); + assertThat(result.hasNext()).isTrue(); + assertThat((int) result.next().getProperty("total")).isEqualTo(executedBatches * BATCH_SIZE); // CHECK ON A PARALLEL CONNECTION THE TX ISOLATION (RECORDS LESS THEN INSERTED) result = database2.query("SQL", "select count(*) as total from Person"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final int totalRecord = result.next().getProperty("total"); - Assertions.assertTrue(totalRecord < executedBatches * BATCH_SIZE, + assertThat(totalRecord).isLessThan(executedBatches * BATCH_SIZE).withFailMessage( "Found total " + totalRecord + " records but should be less than " + (executedBatches * BATCH_SIZE)); //System.out.println("BATCH " + executedBatches + "/" + TOTAL_TRANSACTIONS); @@ -394,17 +397,17 @@ public void testTransactionIsolation() throws Exception { // RETRIEVE DOCUMENT WITH QUERY AFTER COMMIT final ResultSet result = database.query("SQL", "select count(*) as total from Person"); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals(TOTAL_TRANSACTIONS * BATCH_SIZE, (int) result.next().getProperty("total")); + assertThat(result.hasNext()).isTrue(); + assertThat((int) result.next().getProperty("total")).isEqualTo(TOTAL_TRANSACTIONS * BATCH_SIZE); }); } @Test public void testRIDAsParametersInSQL() throws Exception { testEachServer((serverIndex) -> { - Assertions.assertTrue( + assertThat( new RemoteServer("127.0.0.1", 2480 + serverIndex, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).exists( - DATABASE_NAME)); + DATABASE_NAME)).isTrue(); final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); @@ -446,9 +449,9 @@ public void testDropRemoteInheritanceBroken() throws Exception { @Test public void testTransactionWrongSessionId() throws Exception { testEachServer((serverIndex) -> { - Assertions.assertTrue( + assertThat( new RemoteServer("127.0.0.1", 2480 + serverIndex, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).exists( - DATABASE_NAME)); + DATABASE_NAME)).isTrue(); final RemoteDatabase database1 = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); @@ -458,9 +461,9 @@ public void testTransactionWrongSessionId() throws Exception { database1.begin(); final MutableDocument jay = database1.newDocument("Person").set("name", "Jay").save(); - Assertions.assertNotNull(jay); - Assertions.assertEquals("Jay", jay.getString("name")); - Assertions.assertNotNull(jay.getIdentity()); + assertThat(jay).isNotNull(); + assertThat(jay.getString("name")).isEqualTo("Jay"); + assertThat(jay.getIdentity()).isNotNull(); jay.save(); final String sessionId = database1.getSessionId(); @@ -468,7 +471,7 @@ public void testTransactionWrongSessionId() throws Exception { try { final MutableDocument elon = database1.newDocument("Person").set("name", "Elon").save(); - Assertions.fail(); + fail(); } catch (TransactionException e) { // EXPECTED } @@ -484,12 +487,12 @@ public void testDatabaseClose() throws Exception { testEachServer((serverIndex) -> { final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); - Assertions.assertTrue(database.isOpen()); + assertThat(database.isOpen()).isTrue(); database.close(); - Assertions.assertFalse(database.isOpen()); + assertThat(database.isOpen()).isFalse(); try { database.countType("aaa", true); - Assertions.fail(); + fail(); } catch (DatabaseIsClosedException e) { //EXPECTED } diff --git a/server/src/test/java/com/arcadedb/remote/RemoteSchemaIT.java b/server/src/test/java/com/arcadedb/remote/RemoteSchemaIT.java index 01a95456bc..05725cfa2e 100644 --- a/server/src/test/java/com/arcadedb/remote/RemoteSchemaIT.java +++ b/server/src/test/java/com/arcadedb/remote/RemoteSchemaIT.java @@ -26,11 +26,14 @@ import com.arcadedb.schema.Type; import com.arcadedb.schema.VertexType; import com.arcadedb.server.BaseGraphServerTest; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class RemoteSchemaIT extends BaseGraphServerTest { private static final String DATABASE_NAME = "remote-database"; @@ -45,18 +48,18 @@ public void documentType() throws Exception { final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); - Assertions.assertFalse(database.getSchema().existsType("Document")); + assertThat(database.getSchema().existsType("Document")).isFalse(); DocumentType type = database.getSchema().createDocumentType("Document"); - Assertions.assertNotNull(type); - Assertions.assertEquals(type.getName(), "Document"); - Assertions.assertTrue(database.getSchema().existsType("Document")); + assertThat(type).isNotNull(); + assertThat(type.getName()).isEqualTo("Document"); + assertThat(database.getSchema().existsType("Document")).isTrue(); type.createProperty("a", Type.STRING); - Assertions.assertTrue(type.existsProperty("a")); - Assertions.assertFalse(type.existsProperty("zz")); + assertThat(type.existsProperty("a")).isTrue(); + assertThat(type.existsProperty("zz")).isFalse(); type.createProperty("b", Type.LIST, "STRING"); - Assertions.assertTrue(type.existsProperty("b")); + assertThat(type.existsProperty("b")).isTrue(); database.getSchema().dropType("Document"); }); @@ -68,37 +71,37 @@ public void vertexType() throws Exception { final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); - Assertions.assertFalse(database.getSchema().existsType("Vertex")); + assertThat(database.getSchema().existsType("Vertex")).isFalse(); VertexType type = database.getSchema().createVertexType("Vertex"); - Assertions.assertNotNull(type); - Assertions.assertEquals(type.getName(), "Vertex"); - Assertions.assertTrue(database.getSchema().existsType("Vertex")); + assertThat(type).isNotNull(); + assertThat(type.getName()).isEqualTo("Vertex"); + assertThat(database.getSchema().existsType("Vertex")).isTrue(); VertexType type2 = database.getSchema().createVertexType("Vertex2"); Property prop2 = type2.createProperty("b", Type.LIST, "STRING"); - Assertions.assertEquals("b", prop2.getName()); - Assertions.assertEquals(Type.LIST, prop2.getType()); - Assertions.assertEquals("STRING", prop2.getOfType()); + assertThat(prop2.getName()).isEqualTo("b"); + assertThat(prop2.getType()).isEqualTo(Type.LIST); + assertThat(prop2.getOfType()).isEqualTo("STRING"); type2.addSuperType("Vertex"); - Assertions.assertTrue(type2.isSubTypeOf("Vertex")); + assertThat(type2.isSubTypeOf("Vertex")).isTrue(); VertexType type3 = database.getSchema().createVertexType("Vertex3"); Property prop3 = type3.createProperty("c", Type.LIST, "INTEGER"); - Assertions.assertEquals("c", prop3.getName()); - Assertions.assertEquals(Type.LIST, prop3.getType()); - Assertions.assertEquals("INTEGER", prop3.getOfType()); + assertThat(prop3.getName()).isEqualTo("c"); + assertThat(prop3.getType()).isEqualTo(Type.LIST); + assertThat(prop3.getOfType()).isEqualTo("INTEGER"); type3.addSuperType("Vertex2"); - Assertions.assertTrue(type3.isSubTypeOf("Vertex")); - Assertions.assertTrue(type3.isSubTypeOf("Vertex2")); + assertThat(type3.isSubTypeOf("Vertex")).isTrue(); + assertThat(type3.isSubTypeOf("Vertex2")).isTrue(); - Assertions.assertEquals(3, database.getSchema().getTypes().size()); + assertThat(database.getSchema().getTypes()).hasSize(3); - Assertions.assertNotNull(database.getSchema().getType("Vertex")); - Assertions.assertNotNull(database.getSchema().getType("Vertex2")); - Assertions.assertNotNull(database.getSchema().getType("Vertex3")); + assertThat(database.getSchema().getType("Vertex")).isNotNull(); + assertThat(database.getSchema().getType("Vertex2")).isNotNull(); + assertThat(database.getSchema().getType("Vertex3")).isNotNull(); database.getSchema().dropType("Vertex3"); database.getSchema().dropType("Vertex2"); @@ -112,11 +115,11 @@ public void edgeType() throws Exception { final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); - Assertions.assertFalse(database.getSchema().existsType("Edge")); + assertThat(database.getSchema().existsType("Edge")).isFalse(); EdgeType type = database.getSchema().createEdgeType("Edge"); - Assertions.assertNotNull(type); - Assertions.assertEquals(type.getName(), "Edge"); - Assertions.assertTrue(database.getSchema().existsType("Edge")); + assertThat(type).isNotNull(); + assertThat(type.getName()).isEqualTo("Edge"); + assertThat(database.getSchema().existsType("Edge")).isTrue(); database.getSchema().dropType("Edge"); }); } diff --git a/server/src/test/java/com/arcadedb/server/AsyncInsertTest.java b/server/src/test/java/com/arcadedb/server/AsyncInsertTest.java index 3694b779ed..5498a3cc97 100644 --- a/server/src/test/java/com/arcadedb/server/AsyncInsertTest.java +++ b/server/src/test/java/com/arcadedb/server/AsyncInsertTest.java @@ -35,7 +35,6 @@ import com.arcadedb.schema.Type; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,6 +43,7 @@ import java.util.concurrent.atomic.*; import static com.arcadedb.server.BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.assertThat; /** * From Issue https://github.com/ArcadeData/arcadedb/issues/1126 @@ -78,8 +78,7 @@ public void testBulkAsyncInsertConflict() { database.async().onError(exception -> errCount.incrementAndGet()); - Assertions.assertNotEquals(database.async().getParallelLevel(), - database.getSchema().getType("Product").getBuckets(false).size()); + assertThat(database.getSchema().getType("Product").getBuckets(false).size()).isNotEqualTo(database.async().getParallelLevel()); for (int i = 0; i < N; i++) { name = UUID.randomUUID().toString(); database.async().command("sql", sqlString, new AsyncResultsetCallback() { @@ -95,14 +94,14 @@ public void onError(final Exception exception) { }, name, name); } - Assertions.assertTrue(database.async().waitCompletion(3000)); + assertThat(database.async().waitCompletion(3000)).isTrue(); - Assertions.assertEquals(N, okCount.get()); - Assertions.assertNotEquals(0, errCount.get()); + assertThat(okCount.get()).isEqualTo(N); + assertThat(errCount.get()).isNotEqualTo(0); try (ResultSet resultSet = database.query("sql", "SELECT count(*) as total FROM Product")) { Result result = resultSet.next(); - Assertions.assertNotEquals(N, (Long) result.getProperty("total")); + assertThat((Long) result.getProperty("total")).isNotEqualTo(N); } } @@ -131,7 +130,7 @@ public void testBulkAsyncInsertOk() { database.async().setParallelLevel(4); database.async().onError(exception -> errCount.incrementAndGet()); - Assertions.assertEquals(database.async().getParallelLevel(), database.getSchema().getType("Product").getBuckets(false).size()); + assertThat(database.getSchema().getType("Product").getBuckets(false).size()).isEqualTo(database.async().getParallelLevel()); for (int i = 0; i < N; i++) { name = UUID.randomUUID().toString(); database.async().command("sql", sqlString, new AsyncResultsetCallback() { @@ -147,14 +146,14 @@ public void onError(final Exception exception) { }, name, name); } - Assertions.assertTrue(database.async().waitCompletion(3000)); + assertThat(database.async().waitCompletion(3000)).isTrue(); - Assertions.assertEquals(N, okCount.get()); - Assertions.assertEquals(0, errCount.get()); + assertThat(okCount.get()).isEqualTo(N); + assertThat(errCount.get()).isEqualTo(0); try (ResultSet resultSet = database.query("sql", "SELECT count(*) as total FROM Product")) { Result result = resultSet.next(); - Assertions.assertEquals(N, (Long) result.getProperty("total")); + assertThat((Long) result.getProperty("total")).isEqualTo(N); } } diff --git a/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java b/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java index e00c9cb763..cddea0e280 100644 --- a/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java +++ b/server/src/test/java/com/arcadedb/server/BaseGraphServerTest.java @@ -35,7 +35,6 @@ import com.arcadedb.server.ha.HAServer; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import java.io.*; @@ -45,6 +44,8 @@ import java.util.concurrent.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * This class has been copied under Console project to avoid complex dependencies. */ @@ -111,14 +112,14 @@ protected void populateDatabase() { final Database database = databases[0]; database.transaction(() -> { final Schema schema = database.getSchema(); - Assertions.assertFalse(schema.existsType(VERTEX1_TYPE_NAME)); + assertThat(schema.existsType(VERTEX1_TYPE_NAME)).isFalse(); final VertexType v = schema.buildVertexType().withName(VERTEX1_TYPE_NAME).withTotalBuckets(3).create(); v.createProperty("id", Long.class); schema.createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, VERTEX1_TYPE_NAME, "id"); - Assertions.assertFalse(schema.existsType(VERTEX2_TYPE_NAME)); + assertThat(schema.existsType(VERTEX2_TYPE_NAME)).isFalse(); schema.buildVertexType().withName(VERTEX2_TYPE_NAME).withTotalBuckets(3).create(); schema.createEdgeType(EDGE1_TYPE_NAME); @@ -141,8 +142,8 @@ protected void populateDatabase() { // CREATION OF EDGE PASSING PARAMS AS VARARGS final MutableEdge e1 = v1.newEdge(EDGE1_TYPE_NAME, v2, true, "name", "E1"); - Assertions.assertEquals(e1.getOut(), v1); - Assertions.assertEquals(e1.getIn(), v2); + assertThat(v1).isEqualTo(e1.getOut()); + assertThat(v2).isEqualTo(e1.getIn()); final MutableVertex v3 = db.newVertex(VERTEX2_TYPE_NAME); v3.set("name", "V3"); @@ -153,12 +154,12 @@ protected void populateDatabase() { // CREATION OF EDGE PASSING PARAMS AS MAP final MutableEdge e2 = v2.newEdge(EDGE2_TYPE_NAME, v3, true, params); - Assertions.assertEquals(e2.getOut(), v2); - Assertions.assertEquals(e2.getIn(), v3); + assertThat(v2).isEqualTo(e2.getOut()); + assertThat(v3).isEqualTo(e2.getIn()); final MutableEdge e3 = v1.newEdge(EDGE2_TYPE_NAME, v3, true); - Assertions.assertEquals(e3.getOut(), v1); - Assertions.assertEquals(e3.getIn(), v3); + assertThat(v1).isEqualTo(e3.getOut()); + assertThat(v3).isEqualTo(e3.getIn()); db.commit(); @@ -168,7 +169,7 @@ protected void populateDatabase() { protected void waitForReplicationIsCompleted(final int serverNumber) { while (getServer(serverNumber).getHA().getMessagesInQueue() > 0) { try { - Thread.sleep(500); + Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -205,7 +206,7 @@ public void endTest() { } } finally { try { - LogManager.instance().log(this, Level.FINE, "END OF THE TEST: Check DBS are identical..."); + LogManager.instance().log(this, Level.INFO, "END OF THE TEST: Check DBS are identical..."); checkDatabasesAreIdentical(); } finally { GlobalConfiguration.resetAll(); @@ -236,9 +237,9 @@ protected void checkArcadeIsTotallyDown() { if (servers != null) for (final ArcadeDBServer server : servers) { if (server != null) { - Assertions.assertFalse(server.isStarted()); - Assertions.assertEquals(ArcadeDBServer.STATUS.OFFLINE, server.getStatus()); - Assertions.assertEquals(0, server.getHttpServer().getSessionManager().getActiveSessions()); + assertThat(server.isStarted()).isFalse(); + assertThat(server.getStatus()).isEqualTo(ArcadeDBServer.STATUS.OFFLINE); + assertThat(server.getHttpServer().getSessionManager().getActiveSessions()).isEqualTo(0); } } @@ -247,7 +248,7 @@ protected void checkArcadeIsTotallyDown() { new Exception().printStackTrace(output); output.flush(); final String out = os.toString(); - Assertions.assertFalse(out.contains("ArcadeDB"), "Some thread is still up & running: \n" + out); + assertThat(out.contains("ArcadeDB")).as("Some thread is still up & running: \n" + out).isFalse(); } protected String getServerAddresses() { @@ -315,11 +316,11 @@ protected void waitAllReplicasAreConnected() { LogManager.instance().log(this, Level.WARNING, "All %d replicas are online", lastTotalConnectedReplica); return; } else - Thread.sleep(300); + Thread.sleep(500); } } else // WAIT FOR HA COMPONENT TO BE ONLINE - Thread.sleep(300); + Thread.sleep(500); } } } catch (InterruptedException e) { @@ -560,7 +561,7 @@ private void checkForActiveDatabases() { LogManager.instance() .log(this, Level.SEVERE, "Found active databases: " + activeDatabases + ". Forced close before starting a new test"); - //Assertions.assertTrue(activeDatabases.isEmpty(), "Found active databases: " + activeDatabases); + //Assertions.assertThat(activeDatabases.isEmpty().isTrue(), "Found active databases: " + activeDatabases); } protected String command(final int serverIndex, final String command) throws Exception { @@ -577,8 +578,8 @@ protected String command(final int serverIndex, final String command) throws Exc final String response = readResponse(initialConnection); LogManager.instance().log(this, Level.FINE, "Response: %s", response); - Assertions.assertEquals(200, initialConnection.getResponseCode()); - Assertions.assertEquals("OK", initialConnection.getResponseMessage()); + assertThat(initialConnection.getResponseCode()).isEqualTo(200); + assertThat(initialConnection.getResponseMessage()).isEqualTo("OK"); return response; } catch (final Exception e) { @@ -602,8 +603,8 @@ protected JSONObject executeCommand(final int serverIndex, final String language try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); return new JSONObject(response); diff --git a/server/src/test/java/com/arcadedb/server/BatchInsertUpdateTest.java b/server/src/test/java/com/arcadedb/server/BatchInsertUpdateTest.java index 75271efe2f..b891321f6c 100644 --- a/server/src/test/java/com/arcadedb/server/BatchInsertUpdateTest.java +++ b/server/src/test/java/com/arcadedb/server/BatchInsertUpdateTest.java @@ -35,7 +35,6 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,6 +44,7 @@ import java.util.concurrent.atomic.*; import static com.arcadedb.server.BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.assertThat; /** * From Issue https://github.com/ArcadeData/arcadedb/discussion/1129 @@ -131,8 +131,8 @@ public void testBatchAsyncInsertUpdate() { else if (status.equals("updated")) ++updated; } - Assertions.assertEquals(TOTAL, created); - Assertions.assertEquals(TOTAL / 2, updated); + assertThat(created).isEqualTo(TOTAL); + assertThat(updated).isEqualTo(TOTAL / 2); } finally { arcadeDBServer.stop(); diff --git a/server/src/test/java/com/arcadedb/server/CompositeIndexTest.java b/server/src/test/java/com/arcadedb/server/CompositeIndexTest.java index de35cbf148..ba57531c41 100644 --- a/server/src/test/java/com/arcadedb/server/CompositeIndexTest.java +++ b/server/src/test/java/com/arcadedb/server/CompositeIndexTest.java @@ -34,7 +34,6 @@ import com.arcadedb.schema.Type; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -43,6 +42,7 @@ import java.time.format.*; import static com.arcadedb.server.BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.assertThat; /** * From Issue https://github.com/ArcadeData/arcadedb/issues/741 @@ -91,14 +91,14 @@ public void testWhereAfterUpdate() { vstop = LocalDateTime.parse("2019-05-05T00:07:57.423797", DateTimeFormatter.ofPattern(dateTimePattern)); try (ResultSet resultSet = database.command("sql", sqlString, 1, processor, vstart, vstop, status, processor, vstart, vstop)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); resultSet.next().toJSON(); } vstart = LocalDateTime.parse("2019-05-05T00:10:37.288211", DateTimeFormatter.ofPattern(dateTimePattern)); vstop = LocalDateTime.parse("2019-05-05T00:12:38.236835", DateTimeFormatter.ofPattern(dateTimePattern)); try (ResultSet resultSet = database.command("sql", sqlString, 2, processor, vstart, vstop, status, processor, vstart, vstop)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); resultSet.next().toJSON(); } database.commit(); @@ -113,17 +113,17 @@ public void testWhereAfterUpdate() { // select orders sqlString = "SELECT FROM Order WHERE status = ?"; try (ResultSet resultSet = database.query("sql", sqlString, "COMPLETED")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); resultSet.next().toJSON(); } try (ResultSet resultSet = database.query("sql", "SELECT FROM Order WHERE id = 2")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); Result result = resultSet.next(); - Assertions.assertTrue(result.getProperty("status").equals("PENDING")); + assertThat(result.getProperty("status")).isEqualTo("PENDING"); result.toJSON(); } try (ResultSet resultSet = database.query("sql", sqlString, "PENDING")) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); resultSet.next().toJSON(); } } catch (Exception e) { diff --git a/server/src/test/java/com/arcadedb/server/HTTPDocumentIT.java b/server/src/test/java/com/arcadedb/server/HTTPDocumentIT.java index dce08578a4..7f20ad0478 100644 --- a/server/src/test/java/com/arcadedb/server/HTTPDocumentIT.java +++ b/server/src/test/java/com/arcadedb/server/HTTPDocumentIT.java @@ -24,14 +24,19 @@ import com.arcadedb.schema.DocumentType; import com.arcadedb.schema.Schema; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; +import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; import java.io.*; import java.net.*; import java.util.*; +import java.util.concurrent.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.*; + public class HTTPDocumentIT extends BaseGraphServerTest { private final static String DATABASE_NAME = "httpDocument"; @@ -44,7 +49,7 @@ protected String getDatabaseName() { public void testServerInfo() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/server").openConnection(); + "http://localhost:248" + serverIndex + "/api/v1/server").openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", @@ -53,8 +58,8 @@ public void testServerInfo() throws Exception { connection.connect(); final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); } finally { connection.disconnect(); } @@ -65,7 +70,7 @@ public void testServerInfo() throws Exception { public void testServerClusterInfo() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/server?mode=cluster").openConnection(); + "http://localhost:248" + serverIndex + "/api/v1/server?mode=cluster").openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", @@ -74,13 +79,13 @@ public void testServerClusterInfo() throws Exception { connection.connect(); final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); final JSONObject responseJson = new JSONObject(response); - Assertions.assertEquals("root", responseJson.getString("user")); - Assertions.assertEquals(Constants.getVersion(), responseJson.getString("version")); - Assertions.assertEquals(getServer(serverIndex).getServerName(), responseJson.getString("serverName")); + assertThat(responseJson.getString("user")).isEqualTo("root"); + assertThat(responseJson.getString("version")).isEqualTo(Constants.getVersion()); + assertThat(responseJson.getString("serverName")).isEqualTo(getServer(serverIndex).getServerName()); } finally { connection.disconnect(); @@ -92,13 +97,13 @@ public void testServerClusterInfo() throws Exception { public void testServerReady() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/ready").openConnection(); + "http://localhost:248" + serverIndex + "/api/v1/ready").openConnection(); connection.setRequestMethod("GET"); try { connection.connect(); final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(204, connection.getResponseCode()); + assertThat(connection.getResponseCode()).isEqualTo(204); } finally { connection.disconnect(); } @@ -109,7 +114,7 @@ public void testServerReady() throws Exception { public void checkAuthenticationError() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "http://localhost:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "/sql/select%20from%20Person%20limit%201").openConnection(); connection.setRequestMethod("GET"); @@ -117,9 +122,9 @@ public void checkAuthenticationError() throws Exception { try { connection.connect(); readResponse(connection); - Assertions.fail("Authentication was bypassed!"); + fail("Authentication was bypassed!"); } catch (final IOException e) { - Assertions.assertTrue(e.toString().contains("403")); + assertThat(e.toString().contains("403")).isTrue(); } finally { connection.disconnect(); } @@ -130,7 +135,7 @@ public void checkAuthenticationError() throws Exception { public void checkQueryInGet() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "http://localhost:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "/sql/select%20from%20Person%20limit%201").openConnection(); connection.setRequestMethod("GET"); @@ -141,9 +146,9 @@ public void checkQueryInGet() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("Person")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("Person")).isTrue(); } finally { connection.disconnect(); @@ -151,12 +156,11 @@ public void checkQueryInGet() throws Exception { }); } - @Test public void checkQueryInGetWithSqlScript() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "http://localhost:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "/sqlscript/select%20from%20Person%20limit%201").openConnection(); connection.setRequestMethod("GET"); @@ -167,9 +171,9 @@ public void checkQueryInGetWithSqlScript() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("Person")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("Person")).isTrue(); } finally { connection.disconnect(); @@ -181,7 +185,7 @@ public void checkQueryInGetWithSqlScript() throws Exception { public void checkQueryCommandEncoding() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "http://localhost:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "/sql/select%201%20%2B%201%20as%20result").openConnection(); connection.setRequestMethod("GET"); @@ -192,9 +196,9 @@ public void checkQueryCommandEncoding() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "TEST: Response: %s", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("result")).isTrue(); } finally { connection.disconnect(); @@ -206,7 +210,7 @@ public void checkQueryCommandEncoding() throws Exception { public void checkQueryInPost() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME).openConnection(); + "http://localhost:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME).openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", @@ -217,9 +221,9 @@ public void checkQueryInPost() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("Person")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("Person")).isTrue(); } finally { connection.disconnect(); } @@ -230,7 +234,7 @@ public void checkQueryInPost() throws Exception { public void checkCommand() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); + "http://localhost:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", @@ -241,9 +245,9 @@ public void checkCommand() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("Person")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("Person")).isTrue(); } finally { connection.disconnect(); } @@ -253,38 +257,44 @@ public void checkCommand() throws Exception { @Test public void checkAsyncCommand() throws Exception { testEachServer((serverIndex) -> { - HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); + HttpURLConnection post = (HttpURLConnection) new URL( + "http://localhost:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Authorization", + post.setRequestMethod("POST"); + post.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString(("root:" + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).getBytes())); - formatPayload(connection, new JSONObject().put("language","sql").put("command", "create document type doc;").put("awaitResponse",false)); - connection.connect(); + formatPayload(post, new JSONObject() + .put("language", "sql") + .put("command", "create document type doc;") + .put("awaitResponse", false)); + post.connect(); try { - Assertions.assertEquals(202, connection.getResponseCode()); + assertThat(post.getResponseCode()).isEqualTo(202); } finally { - connection.disconnect(); + post.disconnect(); } - connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + final HttpURLConnection get = (HttpURLConnection) new URL( + "http://localhost:248" + serverIndex + "/api/v1/query/" + DATABASE_NAME + "/sql/select%20name%20from%20schema%3Atypes").openConnection(); - - connection.setRequestMethod("GET"); - connection.setRequestProperty("Authorization", + get.setRequestMethod("GET"); + get.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString(("root:" + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS).getBytes())); - connection.connect(); + get.connect(); try { - final String response = readResponse(connection); + Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> { + get.connect(); + return get.getResponseCode() == 200; + }); + final String response = readResponse(get); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("doc")); + assertThat(get.getResponseCode()).isEqualTo(200); + assertThat(get.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("doc")).isTrue(); } finally { - connection.disconnect(); + get.disconnect(); } }); } @@ -293,7 +303,7 @@ public void checkAsyncCommand() throws Exception { public void checkCommandNoDuplication() throws Exception { testEachServer((serverIndex) -> { final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); + "http://localhost:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", @@ -304,15 +314,15 @@ public void checkCommandNoDuplication() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); final JSONObject responseAsJson = new JSONObject(response); final List records = responseAsJson.getJSONObject("result").getJSONArray("records").toList(); - Assertions.assertEquals(100, records.size()); + assertThat(records).hasSize(100); for (final Object o : records) - Assertions.assertTrue(((Map) o).get("@type").equals("Person")); + assertThat(((Map) o).get("@type")).isEqualTo("Person"); } finally { connection.disconnect(); } @@ -324,7 +334,7 @@ public void checkRecordCreate() throws Exception { testEachServer((serverIndex) -> { // CREATE DOCUMENT final HttpURLConnection connection = (HttpURLConnection) new URL( - "http://127.0.0.1:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); + "http://localhost:248" + serverIndex + "/api/v1/command/" + DATABASE_NAME).openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", @@ -338,13 +348,13 @@ public void checkRecordCreate() throws Exception { try { final String response = readResponse(connection); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); final JSONObject responseAsJson = new JSONObject(response); - Assertions.assertTrue(responseAsJson.has("result")); + assertThat(responseAsJson.has("result")).isTrue(); rid = responseAsJson.getJSONArray("result").getJSONObject(0).getString("@rid"); - Assertions.assertTrue(rid.contains("#")); + assertThat(rid.contains("#")).isTrue(); } finally { connection.disconnect(); } @@ -359,7 +369,7 @@ protected void populateDatabase() { final Database database = getDatabase(0); database.transaction(() -> { final Schema schema = database.getSchema(); - Assertions.assertFalse(schema.existsType("Person")); + assertThat(schema.existsType("Person")).isFalse(); final DocumentType v = schema.buildDocumentType().withName("Person").withTotalBuckets(3).create(); v.createProperty("id", Long.class); schema.createTypeIndex(Schema.INDEX_TYPE.LSM_TREE, true, "Person", "id"); diff --git a/server/src/test/java/com/arcadedb/server/HTTPGraphIT.java b/server/src/test/java/com/arcadedb/server/HTTPGraphIT.java index 666e82ba75..d67400a2ec 100644 --- a/server/src/test/java/com/arcadedb/server/HTTPGraphIT.java +++ b/server/src/test/java/com/arcadedb/server/HTTPGraphIT.java @@ -3,7 +3,7 @@ import com.arcadedb.log.LogManager; import com.arcadedb.serializer.json.JSONArray; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; @@ -12,6 +12,10 @@ import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.as; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class HTTPGraphIT extends BaseGraphServerTest { @Test public void checkAuthenticationError() throws Exception { @@ -24,9 +28,9 @@ public void checkAuthenticationError() throws Exception { try { connection.connect(); readResponse(connection); - Assertions.fail("Authentication was bypassed!"); + fail("Authentication was bypassed!"); } catch (final IOException e) { - Assertions.assertTrue(e.toString().contains("403")); + assertThat(e.toString()).contains("403"); } finally { connection.disconnect(); } @@ -43,9 +47,9 @@ public void checkNoAuthentication() throws Exception { try { connection.connect(); readResponse(connection); - Assertions.fail("Authentication was bypassed!"); + fail("Authentication was bypassed!"); } catch (final IOException e) { - Assertions.assertTrue(e.toString().contains("401")); + assertThat(e.toString()).contains("401"); } finally { connection.disconnect(); } @@ -66,9 +70,9 @@ public void checkQueryInGet() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("V1")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("V1")).isTrue(); } finally { connection.disconnect(); @@ -91,9 +95,9 @@ public void checkQueryInPost() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("V1")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("V1")).isTrue(); } finally { connection.disconnect(); } @@ -115,9 +119,9 @@ public void checkCommand() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("V1")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("V1")).isTrue(); } finally { connection.disconnect(); } @@ -139,9 +143,9 @@ public void checkCommandLoadByRIDWithParameters() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("V1")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("V1")).isTrue(); } finally { connection.disconnect(); } @@ -164,9 +168,9 @@ public void checkCommandLoadByRIDInWhereWithParameters() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("V1")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("V1")).isTrue(); } finally { connection.disconnect(); } @@ -191,9 +195,9 @@ public void checkCommandLoadByRIDIn() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("V1")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("V1")).isTrue(); } finally { connection.disconnect(); } @@ -220,9 +224,9 @@ public void checkCommandLet() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("#1:0"), response); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response).contains("#1:0"); } finally { connection.disconnect(); } @@ -235,20 +239,22 @@ public void checkCommandNoDuplication() throws Exception { final JSONObject responseAsJson = executeCommand(serverIndex, "sql", "SELECT FROM E1"); final List vertices = responseAsJson.getJSONObject("result").getJSONArray("vertices").toList(); - Assertions.assertEquals(2, vertices.size()); + assertThat(vertices).hasSize(2); for (final Object o : vertices) - Assertions.assertTrue(((Map) o).get("t").equals("V1") || ((Map) o).get("t").equals("V2")); + assertThat(((Map) o).get("t").equals("V1") || ((Map) o).get("t").equals("V2")).isTrue(); final List records = responseAsJson.getJSONObject("result").getJSONArray("records").toList(); - Assertions.assertEquals(1, records.size()); + assertThat(records).hasSize(1); for (final Object o : records) - Assertions.assertTrue( - ((Map) o).get("@type").equals("V1") || ((Map) o).get("@type").equals("V2") || ((Map) o).get("@type").equals("E1")); +// Assertions.assertTrue( +// ((Map) o).get("@type").equals("V1") || ((Map) o).get("@type").equals("V2") || ((Map) o).get("@type").equals("E1")); + assertThat(((Map) o).get("@type").equals("V1") || ((Map) o).get("@type").equals("V2") || ((Map) o).get("@type") + .equals("E1")).isTrue(); final List edges = responseAsJson.getJSONObject("result").getJSONArray("edges").toList(); - Assertions.assertEquals(1, edges.size()); + assertThat(edges).hasSize(1); for (final Object o : edges) - Assertions.assertTrue(((Map) o).get("t").equals("E1")); + assertThat(((Map) o).get("t")).isEqualTo("E1"); }); } @@ -266,9 +272,9 @@ public void checkDatabaseExists() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(new JSONObject(response).getBoolean("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getBoolean("result")).isTrue(); } finally { connection.disconnect(); } @@ -289,10 +295,10 @@ public void checkDatabaseList() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); final JSONArray databases = new JSONObject(response).getJSONArray("result"); - Assertions.assertEquals(1, databases.length(), "Found the following databases: " + databases); + assertThat(databases.length()).isEqualTo(1).withFailMessage("Found the following databases: " + databases); } finally { connection.disconnect(); } @@ -314,9 +320,9 @@ public void createAndDropDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertEquals("ok", new JSONObject(response).getString("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getString("result")).isEqualTo("ok"); } finally { connection.disconnect(); @@ -332,9 +338,9 @@ public void createAndDropDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(new JSONObject(response).getBoolean("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getBoolean("result")).isTrue(); } finally { connection.disconnect(); @@ -351,9 +357,9 @@ public void createAndDropDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertEquals("ok", new JSONObject(response).getString("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getString("result")).isEqualTo("ok"); } finally { connection.disconnect(); @@ -369,9 +375,9 @@ public void createAndDropDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertFalse(new JSONObject(response).getBoolean("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getBoolean("result")).isFalse(); } finally { connection.disconnect(); @@ -394,9 +400,9 @@ public void closeAndReopenDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertEquals("ok", new JSONObject(response).getString("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getString("result")).isEqualTo("ok"); } finally { connection.disconnect(); @@ -413,9 +419,9 @@ public void closeAndReopenDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertEquals("ok", new JSONObject(response).getString("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getString("result")).isEqualTo("ok"); } finally { connection.disconnect(); @@ -432,9 +438,9 @@ public void closeAndReopenDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertEquals("ok", new JSONObject(response).getString("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getString("result")).isEqualTo("ok"); } finally { connection.disconnect(); @@ -451,9 +457,9 @@ public void closeAndReopenDatabase() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(new JSONObject(response).getBoolean("result")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(new JSONObject(response).getBoolean("result")).isTrue(); } finally { connection.disconnect(); @@ -475,9 +481,9 @@ public void testEmptyDatabaseName() throws Exception { try { readResponse(connection); - Assertions.fail("Empty database should be an error"); + fail("Empty database should be an error"); } catch (final Exception e) { - Assertions.assertEquals(400, connection.getResponseCode()); + assertThat(connection.getResponseCode()).isEqualTo(400); } finally { connection.disconnect(); @@ -515,7 +521,7 @@ public void testOneEdgePerTx() throws Exception { final JSONObject responseAsJsonSelect = executeCommand(serverIndex, "sql", // "SELECT id FROM ( SELECT expand( outE('HasUploaded') ) FROM Users WHERE id = \"u1111\" )"); - Assertions.assertEquals(3, responseAsJsonSelect.getJSONObject("result").getJSONArray("records").length()); + assertThat(responseAsJsonSelect.getJSONObject("result").getJSONArray("records").length()).isEqualTo(3); }); } @@ -549,7 +555,7 @@ public void testOneEdgePerTxMultiThreads() throws Exception { continue; } - Assertions.assertNotNull(responseAsJson.getJSONObject("result").getJSONArray("records")); + assertThat(responseAsJson.getJSONObject("result").getJSONArray("records")).isNotNull(); } catch (Exception e) { throw new RuntimeException(e); @@ -562,12 +568,12 @@ public void testOneEdgePerTxMultiThreads() throws Exception { for (int i = 0; i < THREADS; i++) threads[i].join(60 * 1_000); - Assertions.assertEquals(THREADS * SCRIPTS, atomic.get()); + assertThat(atomic.get()).isEqualTo(THREADS * SCRIPTS); final JSONObject responseAsJsonSelect = executeCommand(serverIndex, "sql", // "SELECT id FROM ( SELECT expand( outE('HasUploaded') ) FROM Users WHERE id = \"u1111\" )"); - Assertions.assertEquals(THREADS * SCRIPTS, responseAsJsonSelect.getJSONObject("result").getJSONArray("records").length()); + assertThat(responseAsJsonSelect.getJSONObject("result").getJSONArray("records").length()).isEqualTo(THREADS * SCRIPTS); }); } } diff --git a/server/src/test/java/com/arcadedb/server/HTTPSSLIT.java b/server/src/test/java/com/arcadedb/server/HTTPSSLIT.java index 06c0df0d08..793b1d5bb8 100644 --- a/server/src/test/java/com/arcadedb/server/HTTPSSLIT.java +++ b/server/src/test/java/com/arcadedb/server/HTTPSSLIT.java @@ -21,7 +21,8 @@ import com.arcadedb.ContextConfiguration; import com.arcadedb.GlobalConfiguration; import com.arcadedb.log.LogManager; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import javax.net.ssl.HttpsURLConnection; @@ -76,8 +77,8 @@ public void testServerInfo() throws Exception { connection.connect(); final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + Assertions.assertThat(connection.getResponseCode()).isEqualTo(200); + Assertions.assertThat(connection.getResponseMessage()).isEqualTo("OK"); } finally { connection.disconnect(); } diff --git a/server/src/test/java/com/arcadedb/server/HTTPTransactionIT.java b/server/src/test/java/com/arcadedb/server/HTTPTransactionIT.java index 4529463ab2..b6703925c7 100644 --- a/server/src/test/java/com/arcadedb/server/HTTPTransactionIT.java +++ b/server/src/test/java/com/arcadedb/server/HTTPTransactionIT.java @@ -20,7 +20,8 @@ import com.arcadedb.log.LogManager; import com.arcadedb.serializer.json.JSONObject; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; @@ -29,6 +30,8 @@ import java.util.logging.*; import static com.arcadedb.server.http.HttpSessionManager.ARCADEDB_SESSION_ID; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; public class HTTPTransactionIT extends BaseGraphServerTest { @@ -50,10 +53,10 @@ public void simpleTx() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(204, connection.getResponseCode()); + assertThat(connection.getResponseCode()).isEqualTo(204); sessionId = connection.getHeaderField(ARCADEDB_SESSION_ID).trim(); - Assertions.assertNotNull(sessionId); + assertThat(sessionId).isNotNull(); } finally { connection.disconnect(); @@ -75,13 +78,13 @@ public void simpleTx() throws Exception { try { final String response = readResponse(connection); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); final JSONObject responseAsJson = new JSONObject(response); - Assertions.assertTrue(responseAsJson.has("result")); + assertThat(responseAsJson.has("result")).isTrue(); rid = responseAsJson.getJSONArray("result").getJSONObject(0).getString("@rid"); - Assertions.assertTrue(rid.contains("#")); + assertThat(rid.contains("#")).isTrue(); } finally { connection.disconnect(); } @@ -89,7 +92,7 @@ public void simpleTx() throws Exception { // CANNOT RETRIEVE DOCUMENT OUTSIDE A TX try { checkDocumentWasCreated(DATABASE_NAME, serverIndex, payload, rid, null); - Assertions.fail(); + fail(); } catch (final Exception e) { // EXPECTED } @@ -110,9 +113,9 @@ public void simpleTx() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("Person")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("Person")).isTrue(); } finally { connection.disconnect(); @@ -131,9 +134,9 @@ public void simpleTx() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("Person")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("Person")).isTrue(); } finally { connection.disconnect(); } @@ -150,8 +153,8 @@ public void simpleTx() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(204, connection.getResponseCode()); - Assertions.assertNull(connection.getHeaderField(ARCADEDB_SESSION_ID)); + assertThat(connection.getResponseCode()).isEqualTo(204); + assertThat(connection.getHeaderField(ARCADEDB_SESSION_ID)).isNull(); } finally { connection.disconnect(); @@ -178,10 +181,10 @@ public void checkUnique() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(204, connection.getResponseCode()); + assertThat(connection.getResponseCode()).isEqualTo(204); sessionId = connection.getHeaderField(ARCADEDB_SESSION_ID).trim(); - Assertions.assertNotNull(sessionId); + assertThat(sessionId).isNotNull(); } finally { connection.disconnect(); @@ -215,12 +218,12 @@ public void checkUnique() throws Exception { String response = null; try { response = readResponse(connection); - Assertions.fail(); + fail(); } catch (final IOException e) { response = readError(connection); - Assertions.assertEquals(503, connection.getResponseCode()); + assertThat(connection.getResponseCode()).isEqualTo(503); connection.disconnect(); - Assertions.assertTrue(response.contains("DuplicatedKeyException")); + assertThat(response.contains("DuplicatedKeyException")).isTrue(); } }); } @@ -243,13 +246,13 @@ public static void checkDocumentWasCreated(final String databaseName, final int try { final String response = readResponse(connection); final JSONObject responseAsJson = new JSONObject(response); - Assertions.assertTrue(responseAsJson.has("result")); + assertThat(responseAsJson.has("result")).isTrue(); final JSONObject object = responseAsJson.getJSONArray("result").getJSONObject(0); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertEquals(rid, object.remove("@rid").toString()); - Assertions.assertEquals("d", object.remove("@cat")); - Assertions.assertEquals(payload.toMap(), object.toMap()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(object.remove("@rid").toString()).isEqualTo(rid); + assertThat(object.remove("@cat")).isEqualTo("d"); + assertThat(object.toMap()).isEqualTo(payload.toMap()); } finally { connection.disconnect(); @@ -272,10 +275,10 @@ public void errorMissingIsolationLevel() throws Exception { try { readResponse(connection); - Assertions.fail(); + fail(); } catch (Exception e) { - Assertions.assertTrue(e.getMessage().contains("400")); + assertThat(e.getMessage().contains("400")).isTrue(); } finally { connection.disconnect(); } diff --git a/server/src/test/java/com/arcadedb/server/RemoteDateIT.java b/server/src/test/java/com/arcadedb/server/RemoteDateIT.java index e484cc991c..ff3cb51eb7 100644 --- a/server/src/test/java/com/arcadedb/server/RemoteDateIT.java +++ b/server/src/test/java/com/arcadedb/server/RemoteDateIT.java @@ -34,7 +34,6 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.utility.DateUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,6 +41,7 @@ import java.time.temporal.*; import static com.arcadedb.server.BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests dates by using server and/or remote connection. @@ -77,17 +77,16 @@ public void testDateTimeMicros1() { database.begin(); sqlString = "INSERT INTO Order SET vstart = ?"; try (ResultSet resultSet = database.command("sql", sqlString, vstart)) { - Assertions.assertEquals(DateUtils.dateTimeToTimestamp(vstart, ChronoUnit.MICROS), - resultSet.next().toJSON().getLong("vstart")); + assertThat(resultSet.next().toJSON().getLong("vstart")).isEqualTo(DateUtils.dateTimeToTimestamp(vstart, ChronoUnit.MICROS)); } sqlString = "select from Order"; System.out.println(sqlString); Result result = null; try (ResultSet resultSet = database.query("sql", sqlString)) { result = resultSet.next(); - Assertions.assertEquals(vstart, result.toElement().get("vstart")); + assertThat(result.toElement().get("vstart")).isEqualTo(vstart); } - Assertions.assertNotNull(result); + assertThat(result).isNotNull(); database.commit(); @@ -96,9 +95,9 @@ public void testDateTimeMicros1() { result = null; try (ResultSet resultSet = remote.query("sql", sqlString)) { result = resultSet.next(); - Assertions.assertEquals(vstart.toString(), result.toElement().get("vstart")); + assertThat(result.toElement().get("vstart")).isEqualTo(vstart.toString()); } - Assertions.assertNotNull(result); + assertThat(result).isNotNull(); } finally { arcadeDBServer.stop(); diff --git a/server/src/test/java/com/arcadedb/server/RemoteQueriesIT.java b/server/src/test/java/com/arcadedb/server/RemoteQueriesIT.java index 9dc665d39f..9cc0865448 100644 --- a/server/src/test/java/com/arcadedb/server/RemoteQueriesIT.java +++ b/server/src/test/java/com/arcadedb/server/RemoteQueriesIT.java @@ -36,7 +36,7 @@ import com.arcadedb.schema.Type; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,6 +45,7 @@ import java.time.format.*; import static com.arcadedb.server.BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Luca Garulli (l.garulli@arcadedata.com) @@ -85,10 +86,10 @@ public void testEdgeDirection() { Vertex toVtx = database.command("sql", "CREATE VERTEX ToVtx").next().getVertex().get(); Edge conEdg = fromVtx.newEdge("ConEdge", toVtx, true); - Assertions.assertEquals(1, fromVtx.countEdges(Vertex.DIRECTION.OUT, "ConEdge")); - Assertions.assertEquals(0, fromVtx.countEdges(Vertex.DIRECTION.IN, "ConEdge")); - Assertions.assertTrue(fromVtx.getEdges(Vertex.DIRECTION.OUT, "ConEdge").iterator().hasNext()); - Assertions.assertFalse(fromVtx.getEdges(Vertex.DIRECTION.IN, "ConEdge").iterator().hasNext()); + assertThat(fromVtx.countEdges(Vertex.DIRECTION.OUT, "ConEdge")).isEqualTo(1); + assertThat(fromVtx.countEdges(Vertex.DIRECTION.IN, "ConEdge")).isEqualTo(0); + assertThat(fromVtx.getEdges(Vertex.DIRECTION.OUT, "ConEdge").iterator().hasNext()).isTrue(); + assertThat(fromVtx.getEdges(Vertex.DIRECTION.IN, "ConEdge").iterator().hasNext()).isFalse(); } @Test @@ -128,7 +129,7 @@ public void testWhereEqualsAfterUpdate() { database.transaction(() -> { String sqlString = "INSERT INTO Order SET id = ?, status = ?, processor = ?"; try (ResultSet resultSet1 = database.command("sql", sqlString, id, status, processor)) { - Assertions.assertEquals("" + id, resultSet1.next().getProperty("id")); + assertThat(resultSet1.next().getProperty("id")).isEqualTo("" + id); } }); } @@ -137,7 +138,7 @@ public void testWhereEqualsAfterUpdate() { Object[] parameters2 = { "ERROR", 1 }; String sqlString = "UPDATE Order SET status = ? RETURN AFTER WHERE id = ?"; try (ResultSet resultSet1 = database.command("sql", sqlString, parameters2)) { - Assertions.assertEquals("1", resultSet1.next().getProperty("id")); + assertThat(resultSet1.next().getProperty("id")).isEqualTo("1"); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); @@ -151,7 +152,7 @@ public void testWhereEqualsAfterUpdate() { Object[] parameters2 = { "PENDING" }; String sqlString = "SELECT id, processor, status FROM Order WHERE status = ?"; try (ResultSet resultSet1 = database.query("sql", sqlString, parameters2)) { - Assertions.assertEquals("PENDING", resultSet1.next().getProperty("status")); + assertThat(resultSet1.next().getProperty("status")).isEqualTo("PENDING"); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); @@ -165,7 +166,7 @@ public void testWhereEqualsAfterUpdate() { Object[] parameters2 = { "PENDING" }; String sqlString = "SELECT id, processor, status FROM Order WHERE status = ?"; try (ResultSet resultSet1 = database.query("sql", sqlString, parameters2)) { - Assertions.assertEquals("PENDING", resultSet1.next().getProperty("status")); + assertThat(resultSet1.next().getProperty("status")).isEqualTo("PENDING"); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); @@ -194,7 +195,7 @@ public void testLocalDateTimeOrderBy() { ContextConfiguration configuration = new ContextConfiguration(); GlobalConfiguration.DATE_TIME_IMPLEMENTATION.setValue(java.time.LocalDateTime.class); GlobalConfiguration.DATE_TIME_FORMAT.setValue("yyyy-MM-dd'T'HH:mm:ss.SSSSSS"); - Assertions.assertTrue(configuration.getValue(GlobalConfiguration.DATE_TIME_IMPLEMENTATION) == java.time.LocalDateTime.class); + assertThat(configuration.getValue(GlobalConfiguration.DATE_TIME_IMPLEMENTATION) == java.time.LocalDateTime.class).isTrue(); arcadeDBServer = new ArcadeDBServer(configuration); arcadeDBServer.start(); @@ -211,9 +212,9 @@ public void testLocalDateTimeOrderBy() { stop = LocalDateTime.parse("20220320T002323", FILENAME_TIME_FORMAT); Object[] parameters1 = { name, type, start, stop }; try (ResultSet resultSet = database.command("sql", sqlString, parameters1)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); - Assertions.assertTrue(result.getProperty("start").equals(start), "start value retrieved does not match start value inserted"); + assertThat(start).as("start value retrieved does not match start value inserted").isEqualTo(result.getProperty("start")); } catch (Exception e) { e.printStackTrace(); } @@ -223,10 +224,10 @@ public void testLocalDateTimeOrderBy() { stop = LocalDateTime.parse("2022-03-19T00:28:26.525650", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS")); Object[] parameters2 = { type, start, stop }; try (ResultSet resultSet = database.query("sql", sqlString, parameters2)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) { result = resultSet.next(); - //Assertions.assertTrue(result.getProperty("start").equals(start), "start value retrieved does not match start value inserted"); + //Assertions.assertThat(result.getProperty("start").equals(start)).as("start value retrieved does not match start value inserted").isTrue(); } } } diff --git a/server/src/test/java/com/arcadedb/server/SelectOrderTest.java b/server/src/test/java/com/arcadedb/server/SelectOrderTest.java index 2a0a474415..9cac4781f8 100644 --- a/server/src/test/java/com/arcadedb/server/SelectOrderTest.java +++ b/server/src/test/java/com/arcadedb/server/SelectOrderTest.java @@ -34,8 +34,9 @@ import com.arcadedb.schema.Schema; import com.arcadedb.schema.Type; import com.arcadedb.utility.FileUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,6 +45,8 @@ import java.time.format.*; import static com.arcadedb.server.BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; /** * From Issue https://github.com/ArcadeData/arcadedb/issues/741 @@ -109,7 +112,7 @@ public void testRIDOrdering() { database.begin(); try (ResultSet resultSet = database.query("sql", sqlString, parameter)) { while (resultSet.hasNext()) { - Assertions.assertEquals(rids[0], resultSet.next().getIdentity().get()); + assertThat(resultSet.next().getIdentity().get()).isEqualTo(rids[0]); } } database.commit(); @@ -120,7 +123,7 @@ public void testRIDOrdering() { database.begin(); try (ResultSet resultSet = database.query("sql", sqlString, parameter)) { while (resultSet.hasNext()) { - Assertions.assertEquals(rids[1], resultSet.next().getIdentity().get()); + assertThat(resultSet.next().getIdentity().get()).isEqualTo(rids[1]); } } database.commit(); @@ -131,7 +134,7 @@ public void testRIDOrdering() { database.begin(); try (ResultSet resultSet = database.query("sql", sqlString, parameter)) { while (resultSet.hasNext()) { - Assertions.assertEquals(rids[0], resultSet.next().getIdentity().get()); + assertThat(resultSet.next().getIdentity().get()).isEqualTo(rids[0]); } } database.commit(); @@ -141,7 +144,7 @@ public void testRIDOrdering() { database.begin(); try (ResultSet resultSet = database.query("sql", sqlString)) { while (resultSet.hasNext()) { - Assertions.assertEquals(rids[0], resultSet.next().getIdentity().get()); + assertThat(resultSet.next().getIdentity().get()).isEqualTo(rids[0]); } } database.commit(); @@ -151,7 +154,7 @@ public void testRIDOrdering() { database.begin(); try (ResultSet resultSet = database.query("sql", sqlString)) { while (resultSet.hasNext()) { - Assertions.assertEquals(rids[0], resultSet.next().getIdentity().get()); + assertThat(resultSet.next().getIdentity().get()).isEqualTo(rids[0]); } } database.commit(); @@ -162,7 +165,7 @@ public void testRIDOrdering() { database.begin(); try (ResultSet resultSet = database.query("sql", sqlString, parameter)) { while (resultSet.hasNext()) { - Assertions.assertEquals(rids[0], resultSet.next().getIdentity().get()); + assertThat(resultSet.next().getIdentity().get()).isEqualTo(rids[0]); } } database.commit(); @@ -216,7 +219,8 @@ public void testLocalDateTimeOrderBy() { stop = LocalDateTime.parse("20220320T002323", FILENAME_TIME_FORMAT); Object[] parameters1 = { name, type, start, stop }; try (ResultSet resultSet = database.command("sql", sqlString, parameters1)) { - Assertions.assertTrue(resultSet.hasNext()); + + assertThat(resultSet.hasNext()).isTrue(); result = resultSet.next(); } catch (Exception e) { System.out.println(e.getMessage()); @@ -233,7 +237,7 @@ public void testLocalDateTimeOrderBy() { try (ResultSet resultSet = database.query("sql", sqlString, parameters3)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) { result = resultSet.next(); @@ -241,7 +245,8 @@ public void testLocalDateTimeOrderBy() { start = result.getProperty("start"); if (lastStart != null) - Assertions.assertTrue(start.compareTo(lastStart) <= 0, "" + start + " is greater than " + lastStart); + assertThat(start.compareTo(lastStart)).isLessThanOrEqualTo(0) + .withFailMessage("" + start + " is greater than " + lastStart); lastStart = start; } @@ -251,7 +256,7 @@ public void testLocalDateTimeOrderBy() { sqlString = "SELECT name, start, stop FROM Product WHERE type = ? AND start <= ? AND stop >= ? ORDER BY start ASC"; try (ResultSet resultSet = database.query("sql", sqlString, parameters3)) { - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); while (resultSet.hasNext()) { result = resultSet.next(); @@ -259,7 +264,8 @@ public void testLocalDateTimeOrderBy() { start = result.getProperty("start"); if (lastStart != null) - Assertions.assertTrue(start.compareTo(lastStart) >= 0, "" + start + " is smaller than " + lastStart); + assertThat(start.compareTo(lastStart)).isGreaterThanOrEqualTo(0) + .withFailMessage("" + start + " is smaller than " + lastStart); lastStart = start; } diff --git a/server/src/test/java/com/arcadedb/server/ServerBackupDatabaseIT.java b/server/src/test/java/com/arcadedb/server/ServerBackupDatabaseIT.java index e4d1faad80..8a17b73427 100644 --- a/server/src/test/java/com/arcadedb/server/ServerBackupDatabaseIT.java +++ b/server/src/test/java/com/arcadedb/server/ServerBackupDatabaseIT.java @@ -19,11 +19,12 @@ package com.arcadedb.server; import com.arcadedb.database.Database; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ServerBackupDatabaseIT extends BaseGraphServerTest { @Override @@ -40,7 +41,7 @@ public void backupDatabase() { final Database database = getServer(0).getDatabase(getDatabaseName()); database.command("sql", "backup database file://" + backupFile.getName()); - Assertions.assertTrue(backupFile.exists()); + assertThat(backupFile.exists()).isTrue(); backupFile.delete(); } } diff --git a/server/src/test/java/com/arcadedb/server/ServerConfigurationIT.java b/server/src/test/java/com/arcadedb/server/ServerConfigurationIT.java index ad1a7880b3..b01019e3d3 100644 --- a/server/src/test/java/com/arcadedb/server/ServerConfigurationIT.java +++ b/server/src/test/java/com/arcadedb/server/ServerConfigurationIT.java @@ -20,23 +20,23 @@ import com.arcadedb.ContextConfiguration; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import static com.arcadedb.GlobalConfiguration.TX_WAL; +import static org.assertj.core.api.Assertions.assertThat; public class ServerConfigurationIT extends BaseGraphServerTest { @Test public void testServerLoadConfiguration() throws IOException { final ContextConfiguration cfg = new ContextConfiguration(); - Assertions.assertTrue(cfg.getValueAsBoolean(TX_WAL)); + assertThat(cfg.getValueAsBoolean(TX_WAL)).isTrue(); cfg.setValue(TX_WAL, false); - Assertions.assertFalse(cfg.getValueAsBoolean(TX_WAL)); + assertThat(cfg.getValueAsBoolean(TX_WAL)).isFalse(); final File file = new File(getServer(0).getRootPath() + File.separator + ArcadeDBServer.CONFIG_SERVER_CONFIGURATION_FILENAME); if (file.exists()) @@ -49,7 +49,7 @@ public void testServerLoadConfiguration() throws IOException { try { server.start(); - Assertions.assertFalse(server.getConfiguration().getValueAsBoolean(TX_WAL)); + assertThat(server.getConfiguration().getValueAsBoolean(TX_WAL)).isFalse(); } finally { if (file.exists()) file.delete(); diff --git a/server/src/test/java/com/arcadedb/server/ServerDefaultDatabasesIT.java b/server/src/test/java/com/arcadedb/server/ServerDefaultDatabasesIT.java index 00752a5204..a890fdbd26 100644 --- a/server/src/test/java/com/arcadedb/server/ServerDefaultDatabasesIT.java +++ b/server/src/test/java/com/arcadedb/server/ServerDefaultDatabasesIT.java @@ -22,12 +22,14 @@ import com.arcadedb.GlobalConfiguration; import com.arcadedb.database.DatabaseInternal; import com.arcadedb.server.security.ServerSecurityException; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; import static com.arcadedb.engine.ComponentFile.MODE.READ_WRITE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class ServerDefaultDatabasesIT extends BaseGraphServerTest { @@ -57,30 +59,30 @@ public void checkDefaultDatabases() throws IOException { try { getServer(0).getSecurity().authenticate("elon", "musk", "Amiga"); - Assertions.fail(); + fail(""); } catch (final ServerSecurityException e) { // EXPECTED } try { getServer(0).getSecurity().authenticate("Jack", "Tramiel", "Universe"); - Assertions.fail(); + fail(""); } catch (final ServerSecurityException e) { // EXPECTED } try { getServer(0).getSecurity().authenticate("Jack", "Tramiel", "RandomName"); - Assertions.fail(); + fail(""); } catch (final ServerSecurityException e) { // EXPECTED } - Assertions.assertTrue(getServer(0).existsDatabase("Universe")); - Assertions.assertTrue(getServer(0).existsDatabase("Amiga")); + assertThat(getServer(0).existsDatabase("Universe")).isTrue(); + assertThat(getServer(0).existsDatabase("Amiga")).isTrue(); - Assertions.assertTrue(READ_WRITE.equals(getServer(0).getDatabase("Universe").getMode())); - Assertions.assertTrue(READ_WRITE.equals(getServer(0).getDatabase("Amiga").getMode())); + assertThat(getServer(0).getDatabase("Universe").getMode()).isEqualTo(READ_WRITE); + assertThat(getServer(0).getDatabase("Amiga").getMode()).isEqualTo(READ_WRITE); ((DatabaseInternal) getServer(0).getDatabase("Universe")).getEmbedded().drop(); ((DatabaseInternal) getServer(0).getDatabase("Amiga")).getEmbedded().drop(); diff --git a/server/src/test/java/com/arcadedb/server/ServerImportDatabaseIT.java b/server/src/test/java/com/arcadedb/server/ServerImportDatabaseIT.java index 99090ca975..87cdfa86b8 100644 --- a/server/src/test/java/com/arcadedb/server/ServerImportDatabaseIT.java +++ b/server/src/test/java/com/arcadedb/server/ServerImportDatabaseIT.java @@ -23,11 +23,12 @@ import com.arcadedb.database.Database; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ServerImportDatabaseIT extends BaseGraphServerTest { public ServerImportDatabaseIT() { FileUtils.deleteRecursively(new File("./target/config")); @@ -61,7 +62,7 @@ protected void onServerConfiguration(final ContextConfiguration config) { public void checkDefaultDatabases() { getServer(0).getSecurity().authenticate("elon", "musk", "Movies"); final Database database = getServer(0).getDatabase("Movies"); - Assertions.assertEquals(500, database.countType("Person", true)); + assertThat(database.countType("Person", true)).isEqualTo(500); FileUtils.deleteRecursively(new File(GlobalConfiguration.SERVER_DATABASE_DIRECTORY.getValueAsString() + "0/Movies")); } } diff --git a/server/src/test/java/com/arcadedb/server/ServerReadOnlyDatabasesIT.java b/server/src/test/java/com/arcadedb/server/ServerReadOnlyDatabasesIT.java index 910080e29f..2da77f5cad 100644 --- a/server/src/test/java/com/arcadedb/server/ServerReadOnlyDatabasesIT.java +++ b/server/src/test/java/com/arcadedb/server/ServerReadOnlyDatabasesIT.java @@ -20,12 +20,12 @@ import com.arcadedb.ContextConfiguration; import com.arcadedb.GlobalConfiguration; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; import static com.arcadedb.engine.ComponentFile.MODE.READ_ONLY; +import static org.assertj.core.api.Assertions.assertThat; public class ServerReadOnlyDatabasesIT extends BaseGraphServerTest { @@ -50,10 +50,10 @@ protected void onServerConfiguration(final ContextConfiguration config) { @Test public void checkDefaultDatabases() throws IOException { - Assertions.assertTrue(getServer(0).existsDatabase("Universe")); - Assertions.assertTrue(getServer(0).existsDatabase("Amiga")); + assertThat(getServer(0).existsDatabase("Universe")).isTrue(); + assertThat(getServer(0).existsDatabase("Amiga")).isTrue(); - Assertions.assertTrue(READ_ONLY.equals(getServer(0).getDatabase("Universe").getMode())); - Assertions.assertTrue(READ_ONLY.equals(getServer(0).getDatabase("Amiga").getMode())); + assertThat(getServer(0).getDatabase("Universe").getMode()).isEqualTo(READ_ONLY); + assertThat(getServer(0).getDatabase("Amiga").getMode()).isEqualTo(READ_ONLY); } } diff --git a/server/src/test/java/com/arcadedb/server/ServerRestoreDatabaseIT.java b/server/src/test/java/com/arcadedb/server/ServerRestoreDatabaseIT.java index 1dba7f0463..8c1ded22db 100644 --- a/server/src/test/java/com/arcadedb/server/ServerRestoreDatabaseIT.java +++ b/server/src/test/java/com/arcadedb/server/ServerRestoreDatabaseIT.java @@ -24,12 +24,15 @@ import com.arcadedb.database.DatabaseFactory; import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.utility.FileUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ServerRestoreDatabaseIT extends BaseGraphServerTest { public ServerRestoreDatabaseIT() { FileUtils.deleteRecursively(new File("./target/config")); @@ -65,25 +68,26 @@ protected void onServerConfiguration(final ContextConfiguration config) { database.newDocument("testDoc").set("prop", "value").save(); // COUNT INSIDE TX - Assertions.assertEquals(1, database.countType("testDoc", true)); + assertThat(database.countType("testDoc", true)).isEqualTo(1); }); // COUNT OUTSIDE TX - Assertions.assertEquals(1, database.countType("testDoc", true)); + assertThat(database.countType("testDoc", true)).isEqualTo(1); - Assertions.assertFalse(database.isTransactionActive()); + assertThat(database.isTransactionActive()).isFalse(); } try (final Database database2 = factory.open()) { final ResultSet result = database2.command("sql", "backup database file://" + backupFile.getName()); - Assertions.assertTrue(result.hasNext()); - Assertions.assertEquals("OK", result.next().getProperty("result")); + assertThat(result.hasNext()).isTrue(); + assertThat(result.next().getProperty("result")).isEqualTo("OK"); - Assertions.assertTrue(backupFile.exists()); + assertThat(backupFile.exists()).isTrue(); database2.drop(); - config.setValue(GlobalConfiguration.SERVER_DEFAULT_DATABASES, "graph[elon:musk:admin]{restore:file://" + backupFile.getPath() + "}"); + config.setValue(GlobalConfiguration.SERVER_DEFAULT_DATABASES, + "graph[elon:musk:admin]{restore:file://" + backupFile.getPath() + "}"); } } } @@ -92,7 +96,7 @@ protected void onServerConfiguration(final ContextConfiguration config) { public void defaultDatabases() { getServer(0).getSecurity().authenticate("elon", "musk", "graph"); final Database database = getServer(0).getDatabase("graph"); - Assertions.assertEquals(1, database.countType("testDoc", true)); + assertThat(database.countType("testDoc", true)).isEqualTo(1); FileUtils.deleteRecursively(new File(GlobalConfiguration.SERVER_DATABASE_DIRECTORY.getValueAsString() + "0/Movies")); } } diff --git a/server/src/test/java/com/arcadedb/server/TestServerHelper.java b/server/src/test/java/com/arcadedb/server/TestServerHelper.java index fd1731cac1..83b1e7ad87 100644 --- a/server/src/test/java/com/arcadedb/server/TestServerHelper.java +++ b/server/src/test/java/com/arcadedb/server/TestServerHelper.java @@ -28,11 +28,13 @@ import com.arcadedb.utility.CallableNoReturn; import com.arcadedb.utility.CallableParameterNoReturn; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; -import java.io.*; -import java.util.*; -import java.util.logging.*; +import java.io.File; +import java.util.Collection; +import java.util.logging.Level; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Executes all the tests while the server is up and running. @@ -106,7 +108,7 @@ public static void expectException(final CallableNoReturn callback, final Class< throws Exception { try { callback.call(); - Assertions.fail(); + fail(""); } catch (final Throwable e) { if (e.getClass().equals(expectedException)) // EXPECTED @@ -139,7 +141,7 @@ public static void checkActiveDatabases(final boolean drop) { } else db.close(); - Assertions.assertTrue(activeDatabases.isEmpty(), "Found active databases: " + activeDatabases); + assertThat(activeDatabases.isEmpty()).as("Found active databases: " + activeDatabases).isTrue(); } public static void deleteDatabaseFolders(final int totalServers) { diff --git a/server/src/test/java/com/arcadedb/server/ha/HAConfigurationIT.java b/server/src/test/java/com/arcadedb/server/ha/HAConfigurationIT.java index 8cba7190b8..569fe2e1df 100644 --- a/server/src/test/java/com/arcadedb/server/ha/HAConfigurationIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/HAConfigurationIT.java @@ -20,9 +20,11 @@ import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.server.ServerException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class HAConfigurationIT extends BaseGraphServerTest { protected int getServerCount() { return 3; @@ -40,10 +42,10 @@ public void beginTest() { public void testReplication() { try { super.beginTest(); - Assertions.fail(); + fail(""); } catch (ServerException e) { // EXPECTED - Assertions.assertTrue(e.getMessage().contains("Found a localhost")); + assertThat(e.getMessage().contains("Found a localhost")).isTrue(); } } } diff --git a/server/src/test/java/com/arcadedb/server/ha/HARandomCrashIT.java b/server/src/test/java/com/arcadedb/server/ha/HARandomCrashIT.java index 10e1cac917..9ccaeb51a9 100644 --- a/server/src/test/java/com/arcadedb/server/ha/HARandomCrashIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/HARandomCrashIT.java @@ -31,12 +31,13 @@ import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.utility.CodeUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class HARandomCrashIT extends ReplicationServerIT { private int restarts = 0; private volatile long delay = 0; @@ -151,15 +152,15 @@ public void run() { final ResultSet resultSet = db.command("SQL", "CREATE VERTEX " + VERTEX1_TYPE_NAME + " SET id = ?, name = ?", ++counter, "distributed-test"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result result = resultSet.next(); - Assertions.assertNotNull(result); + assertThat(result).isNotNull(); final Set props = result.getPropertyNames(); - Assertions.assertEquals(2, props.size(), "Found the following properties " + props); - Assertions.assertTrue(props.contains("id")); - Assertions.assertEquals(counter, (int) result.getProperty("id")); - Assertions.assertTrue(props.contains("name")); - Assertions.assertEquals("distributed-test", result.getProperty("name")); + assertThat(props.size()).as("Found the following properties " + props).isEqualTo(2); + assertThat(props.contains("id")).isTrue(); + assertThat((int) result.getProperty("id")).isEqualTo(counter); + assertThat(props.contains("name")).isTrue(); + assertThat(result.getProperty("name")).isEqualTo("distributed-test"); } CodeUtils.sleep(delay); @@ -222,7 +223,7 @@ public void run() { onAfterTest(); - Assertions.assertTrue(restarts >= getServerCount(), "Restarts " + restarts + " times"); + assertThat(restarts >= getServerCount()).as("Restarts " + restarts + " times").isTrue(); } private static Level getLogLevel() { diff --git a/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java b/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java index b755d4a6f7..aea5084332 100644 --- a/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/HASplitBrainIT.java @@ -23,13 +23,14 @@ import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.ReplicationCallback; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import java.io.*; import java.util.*; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + /** * Simulates a split brain on 5 nodes, by isolating nodes 4th and 5th in a separate network. After 10 seconds, allows the 2 networks to see * each other and hoping for a rejoin in only one network where the leaser is still the original one. @@ -55,7 +56,7 @@ public void endTest() { @Override protected void onAfterTest() { timer.cancel(); - Assertions.assertEquals(firstLeader, getLeaderServer().getServerName()); + assertThat(getLeaderServer().getServerName()).isEqualTo(firstLeader); } @Override diff --git a/server/src/test/java/com/arcadedb/server/ha/HTTP2ServersIT.java b/server/src/test/java/com/arcadedb/server/ha/HTTP2ServersIT.java index a54bbece1c..e1234f5f47 100644 --- a/server/src/test/java/com/arcadedb/server/ha/HTTP2ServersIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/HTTP2ServersIT.java @@ -23,7 +23,8 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.BaseGraphServerTest; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; @@ -31,6 +32,9 @@ import java.util.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + public class HTTP2ServersIT extends BaseGraphServerTest { @Override protected int getServerCount() { @@ -50,8 +54,8 @@ public void testServerInfo() throws Exception { connection.connect(); final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "Response: ", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); } finally { connection.disconnect(); } @@ -63,8 +67,9 @@ public void propagationOfSchema() throws Exception { testEachServer((serverIndex) -> { // CREATE THE SCHEMA ON BOTH SERVER, ONE TYPE PER SERVER final String response = command(serverIndex, "create vertex type VertexType" + serverIndex); - Assertions.assertTrue(response.contains("VertexType" + serverIndex), - "Type " + (("VertexType" + serverIndex) + " not found on server " + serverIndex)); + assertThat(response).contains("VertexType" + serverIndex) + .withFailMessage("Type " + (("VertexType" + serverIndex) + " not found on server " + serverIndex)); + }); Thread.sleep(300); @@ -87,9 +92,9 @@ public void checkQuery() throws Exception { try { final String response = readResponse(connection); LogManager.instance().log(this, Level.FINE, "TEST: Response: %s", null, response); - Assertions.assertEquals(200, connection.getResponseCode()); - Assertions.assertEquals("OK", connection.getResponseMessage()); - Assertions.assertTrue(response.contains("V1")); + assertThat(connection.getResponseCode()).isEqualTo(200); + assertThat(connection.getResponseMessage()).isEqualTo("OK"); + assertThat(response.contains("V1")).isTrue(); } finally { connection.disconnect(); @@ -114,8 +119,8 @@ public void checkDeleteGraphElements() throws Exception { testEachServer((checkServer) -> { try { - Assertions.assertFalse(new JSONObject(command(checkServer, "select from " + v1)).getJSONArray("result").isEmpty(), - "executed on server " + serverIndex + " checking on server " + serverIndex); + assertThat(new JSONObject(command(checkServer, "select from " + v1)).getJSONArray("result")).isNotEmpty(). + withFailMessage("executed on server " + serverIndex + " checking on server " + serverIndex); } catch (final Exception e) { LogManager.instance().log(this, Level.SEVERE, "Error on checking for V1 on server " + checkServer); throw e; @@ -131,8 +136,9 @@ public void checkDeleteGraphElements() throws Exception { testEachServer((checkServer) -> { try { - Assertions.assertFalse(new JSONObject(command(checkServer, "select from " + v2)).getJSONArray("result").isEmpty(), - "executed on server " + serverIndex + " checking on server " + serverIndex); + + assertThat(new JSONObject(command(checkServer, "select from " + v2)).getJSONArray("result")).isNotEmpty() + .withFailMessage("executed on server " + serverIndex + " checking on server " + serverIndex); } catch (final Exception e) { LogManager.instance().log(this, Level.SEVERE, "Error on checking for V2 on server " + checkServer); throw e; @@ -147,8 +153,8 @@ public void checkDeleteGraphElements() throws Exception { testEachServer((checkServer) -> { try { - Assertions.assertFalse(new JSONObject(command(checkServer, "select from " + e1)).getJSONArray("result").isEmpty(), - "executed on server " + serverIndex + " checking on server " + serverIndex); + assertThat(new JSONObject(command(checkServer, "select from " + e1)).getJSONArray("result")).isNotEmpty() + .withFailMessage("executed on server " + serverIndex + " checking on server " + serverIndex); } catch (final Exception e) { LogManager.instance().log(this, Level.SEVERE, "Error on checking on E1 on server " + checkServer); throw e; @@ -164,8 +170,8 @@ public void checkDeleteGraphElements() throws Exception { testEachServer((checkServer) -> { try { - Assertions.assertFalse(new JSONObject(command(checkServer, "select from " + v3)).getJSONArray("result").isEmpty(), - "executed on server " + serverIndex + " checking on server " + serverIndex); + assertThat(new JSONObject(command(checkServer, "select from " + v3)).getJSONArray("result")).isNotEmpty() + .withFailMessage("executed on server " + serverIndex + " checking on server " + serverIndex); } catch (final Exception e) { LogManager.instance().log(this, Level.SEVERE, "Error on checking for V3 on server " + checkServer); throw e; @@ -180,8 +186,8 @@ public void checkDeleteGraphElements() throws Exception { testEachServer((checkServer) -> { try { - Assertions.assertFalse(new JSONObject(command(checkServer, "select from " + e2)).getJSONArray("result").isEmpty(), - "executed on server " + serverIndex + " checking on server " + serverIndex); + assertThat(new JSONObject(command(checkServer, "select from " + e2)).getJSONArray("result")).isNotEmpty() + .withFailMessage("executed on server " + serverIndex + " checking on server " + serverIndex); } catch (final Exception e) { LogManager.instance().log(this, Level.SEVERE, "Error on checking for E2 on server " + checkServer); throw e; @@ -196,14 +202,14 @@ public void checkDeleteGraphElements() throws Exception { testEachServer((checkServer) -> { try { new JSONObject(command(checkServer, "select from " + v1)).getJSONArray("result"); - Assertions.fail("executed on server " + serverIndex + " checking on server " + serverIndex); + fail("executed on server " + serverIndex + " checking on server " + serverIndex); } catch (FileNotFoundException e) { // EXPECTED } try { new JSONObject(command(checkServer, "select from " + e1)).getJSONArray("result"); - Assertions.fail("executed on server " + serverIndex + " checking on server " + serverIndex); + fail("executed on server " + serverIndex + " checking on server " + serverIndex); } catch (FileNotFoundException e) { // EXPECTED } @@ -216,8 +222,8 @@ public void testHAConfiguration() { for (ArcadeDBServer server : getServers()) { final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480, getDatabaseName(), "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); - Assertions.assertNotNull(database.getLeaderAddress()); - Assertions.assertFalse(database.getReplicaAddresses().isEmpty()); + assertThat(database.getLeaderAddress()).isNotNull(); + assertThat(database.getReplicaAddresses().isEmpty()).isFalse(); } } } diff --git a/server/src/test/java/com/arcadedb/server/ha/HTTPGraphConcurrentIT.java b/server/src/test/java/com/arcadedb/server/ha/HTTPGraphConcurrentIT.java index 4c1d51d266..7710c652a9 100644 --- a/server/src/test/java/com/arcadedb/server/ha/HTTPGraphConcurrentIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/HTTPGraphConcurrentIT.java @@ -21,12 +21,15 @@ import com.arcadedb.log.LogManager; import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.BaseGraphServerTest; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.*; + public class HTTPGraphConcurrentIT extends BaseGraphServerTest { @Override protected int getServerCount() { @@ -70,10 +73,10 @@ public void testOneEdgePerTxMultiThreads() throws Exception { continue; } - Assertions.assertNotNull(responseAsJson.getJSONObject("result").getJSONArray("records")); + assertThat(responseAsJson.getJSONObject("result").getJSONArray("records")).isNotNull(); } catch (Exception e) { - Assertions.fail(e); + fail(e); } } }); @@ -83,14 +86,15 @@ public void testOneEdgePerTxMultiThreads() throws Exception { for (int i = 0; i < THREADS; i++) threads[i].join(60 * 1_000); - Assertions.assertEquals(THREADS * SCRIPTS, atomic.get()); + assertThat(atomic.get()).isEqualTo(THREADS * SCRIPTS); final JSONObject responseAsJsonSelect = executeCommand(serverIndex, "sql", // "SELECT id FROM ( SELECT expand( outE('HasUploaded" + serverIndex + "') ) FROM Users" + serverIndex + " WHERE id = \"u1111\" )"); - Assertions.assertEquals(THREADS * SCRIPTS, responseAsJsonSelect.getJSONObject("result").getJSONArray("records").length(), - "Some edges was missing when executing from server " + serverIndex); + assertThat(responseAsJsonSelect.getJSONObject("result").getJSONArray("records").length()) + .isEqualTo(THREADS * SCRIPTS) + .withFailMessage("Some edges was missing when executing from server " + serverIndex); }); } } diff --git a/server/src/test/java/com/arcadedb/server/ha/IndexOperations3ServersIT.java b/server/src/test/java/com/arcadedb/server/ha/IndexOperations3ServersIT.java index 4551dbb18b..4a8b37e617 100644 --- a/server/src/test/java/com/arcadedb/server/ha/IndexOperations3ServersIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/IndexOperations3ServersIT.java @@ -28,6 +28,7 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.server.TestServerHelper; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationChangeSchemaIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationChangeSchemaIT.java index 3b65a2fda7..40f71d0100 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationChangeSchemaIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationChangeSchemaIT.java @@ -30,11 +30,15 @@ import com.arcadedb.schema.VertexType; import com.arcadedb.utility.Callable; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; -import java.io.*; -import java.util.*; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class ReplicationChangeSchemaIT extends ReplicationServerIT { private final Database[] databases = new Database[getServerCount()]; @@ -61,7 +65,7 @@ public void testReplication() throws Exception { // CREATE NEW BUCKET final Bucket newBucket = databases[0].getSchema().createBucket("newBucket"); for (final Database database : databases) - Assertions.assertTrue(database.getSchema().existsBucket("newBucket")); + assertThat(database.getSchema().existsBucket("newBucket")).isTrue(); type1.addBucket(newBucket); testOnAllServers((database) -> isInSchemaFile(database, "newBucket")); @@ -69,7 +73,7 @@ public void testReplication() throws Exception { // CHANGE SCHEMA FROM A REPLICA (ERROR EXPECTED) try { databases[1].getSchema().createVertexType("RuntimeVertex1"); - Assertions.fail(); + fail(""); } catch (final ServerIsNotTheLeaderException e) { // EXPECTED } @@ -89,7 +93,7 @@ public void testReplication() throws Exception { databases[0].getSchema().getType("RuntimeVertex0").removeBucket(databases[0].getSchema().getBucketByName("newBucket")); for (final Database database : databases) - Assertions.assertFalse(database.getSchema().getType("RuntimeVertex0").hasBucket("newBucket")); + assertThat(database.getSchema().getType("RuntimeVertex0").hasBucket("newBucket")).isFalse(); databases[0].getSchema().dropBucket("newBucket"); testOnAllServers((database) -> isNotInSchemaFile(database, "newBucket")); @@ -120,7 +124,7 @@ public void testReplication() throws Exception { for (int i = 0; i < 10; i++) databases[1].newVertex("IndexedVertex0").set("propertyIndexed", i).save(); }); - Assertions.fail(); + fail(""); } catch (final TransactionException e) { // EXPECTED } @@ -133,7 +137,7 @@ public void testReplication() throws Exception { try { databases[0].getSchema().createVertexType("RuntimeVertexTx0"); } catch (final Exception e) { - Assertions.fail(e); + fail(e); } }); @@ -148,7 +152,7 @@ private void testOnAllServers(final Callable callback) { final String result = callback.call(database); schemaFiles.put(database.getDatabasePath(), result); } catch (final Exception e) { - Assertions.fail(e); + fail("", e); } } checkSchemaFilesAreTheSameOnAllServers(); @@ -157,10 +161,10 @@ private void testOnAllServers(final Callable callback) { private String isInSchemaFile(final Database database, final String match) { try { final String content = FileUtils.readFileAsString(database.getSchema().getEmbedded().getConfigurationFile()); - Assertions.assertTrue(content.contains(match)); + assertThat(content.contains(match)).isTrue(); return content; } catch (final IOException e) { - Assertions.fail(e); + fail("", e); return null; } } @@ -168,24 +172,23 @@ private String isInSchemaFile(final Database database, final String match) { private String isNotInSchemaFile(final Database database, final String match) { try { final String content = FileUtils.readFileAsString(database.getSchema().getEmbedded().getConfigurationFile()); - Assertions.assertFalse(content.contains(match)); + assertThat(content.contains(match)).isFalse(); return content; } catch (final IOException e) { - Assertions.fail(e); + fail("", e); return null; } } private void checkSchemaFilesAreTheSameOnAllServers() { - Assertions.assertEquals(getServerCount(), schemaFiles.size()); + assertThat(schemaFiles.size()).isEqualTo(getServerCount()); String first = null; for (final Map.Entry entry : schemaFiles.entrySet()) { if (first == null) first = entry.getValue(); else - Assertions.assertEquals(first, entry.getValue(), - "Server " + entry.getKey() + " has different schema saved:\nFIRST SERVER:\n" + first + "\n" + entry.getKey() - + " SERVER:\n" + entry.getValue()); + assertThat(entry.getValue()).as("Server " + entry.getKey() + " has different schema saved:\nFIRST SERVER:\n" + first + "\n" + entry.getKey() + + " SERVER:\n" + entry.getValue()).isEqualTo(first); } } diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java index 331bbc65f4..97f61af469 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerIT.java @@ -32,11 +32,14 @@ import com.arcadedb.index.TypeIndex; import com.arcadedb.log.LogManager; import com.arcadedb.server.BaseGraphServerTest; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.util.*; -import java.util.logging.*; +import java.util.logging.Level; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public abstract class ReplicationServerIT extends BaseGraphServerTest { private static final int DEFAULT_MAX_RETRIES = 30; @@ -66,7 +69,7 @@ public void testReplication(final int serverId) { db.begin(); - Assertions.assertEquals(1, db.countType(VERTEX1_TYPE_NAME, true), "TEST: Check for vertex count for server" + 0); + assertThat(db.countType(VERTEX1_TYPE_NAME, true)).as("TEST: Check for vertex count for server" + 0).isEqualTo(1); LogManager.instance() .log(this, Level.FINE, "TEST: Executing %s transactions with %d vertices each...", null, getTxs(), getVerticesPerTx()); @@ -115,8 +118,8 @@ public void testReplication(final int serverId) { for (int i = 0; i < getServerCount(); i++) waitForReplicationIsCompleted(i); - Assertions.assertEquals(1 + (long) getTxs() * getVerticesPerTx(), db.countType(VERTEX1_TYPE_NAME, true), - "Check for vertex count for server" + 0); + assertThat(db.countType(VERTEX1_TYPE_NAME, true)).as("Check for vertex count for server" + 0) + .isEqualTo(1 + (long) getTxs() * getVerticesPerTx()); // CHECK INDEXES ARE REPLICATED CORRECTLY for (final int s : getServerToCheck()) @@ -134,15 +137,15 @@ protected void checkDatabases() { final Database db = getServerDatabase(s, getDatabaseName()); db.begin(); try { - Assertions.assertEquals(1, db.countType(VERTEX1_TYPE_NAME, true), "Check for vertex count for server" + s); - Assertions.assertEquals(2, db.countType(VERTEX2_TYPE_NAME, true), "Check for vertex count for server" + s); + assertThat(db.countType(VERTEX1_TYPE_NAME, true)).as("Check for vertex count for server" + s).isEqualTo(1); + assertThat(db.countType(VERTEX2_TYPE_NAME, true)).as("Check for vertex count for server" + s).isEqualTo(2); - Assertions.assertEquals(1, db.countType(EDGE1_TYPE_NAME, true), "Check for edge count for server" + s); - Assertions.assertEquals(2, db.countType(EDGE2_TYPE_NAME, true), "Check for edge count for server" + s); + assertThat(db.countType(EDGE1_TYPE_NAME, true)).as("Check for edge count for server" + s).isEqualTo(1); + assertThat(db.countType(EDGE2_TYPE_NAME, true)).as("Check for edge count for server" + s).isEqualTo(2); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail("Error on checking on server" + s); + fail("Error on checking on server" + s); } } } @@ -163,9 +166,11 @@ protected void checkEntriesOnServer(final int serverIndex) { db.transaction(() -> { try { final long recordInDb = db.countType(VERTEX1_TYPE_NAME, true); - Assertions.assertTrue(recordInDb <= 1 + getTxs() * getVerticesPerTx(), - "TEST: Check for vertex count for server" + serverIndex + " found " + recordInDb + " not less than " + (1 - + getTxs() * getVerticesPerTx())); + assertThat(recordInDb).isLessThanOrEqualTo(1 + getTxs() * getVerticesPerTx()) + .withFailMessage( + "TEST: Check for vertex count for server" + serverIndex + " found " + recordInDb + " not less than " + (1 + + getTxs() * getVerticesPerTx())); + final TypeIndex index = db.getSchema().getType(VERTEX1_TYPE_NAME).getPolymorphicIndexByProperties("id"); long total = 0; @@ -209,14 +214,15 @@ record = rid.getRecord(true); } } - Assertions.assertEquals(recordInDb, ridsFoundInIndex.size(), - "TEST: Found " + missingsCount + " missing records on server " + serverIndex); - Assertions.assertEquals(0, missingsCount); - Assertions.assertEquals(total, total2); + assertThat(ridsFoundInIndex.size()) + .withFailMessage("TEST: Found " + missingsCount + " missing records on server " + serverIndex) + .isEqualTo(recordInDb); + assertThat(missingsCount).isZero(); + assertThat(total).isEqualTo(total2); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail("TEST: Error on checking on server" + serverIndex + ": " + e.getMessage()); + fail("TEST: Error on checking on server" + serverIndex + ": " + e.getMessage()); } }); } diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderChanges3TimesIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderChanges3TimesIT.java index 25e3e919dd..38b6f041e4 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderChanges3TimesIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderChanges3TimesIT.java @@ -33,7 +33,6 @@ import com.arcadedb.server.ha.message.TxRequest; import com.arcadedb.utility.CodeUtils; import com.arcadedb.utility.Pair; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; @@ -41,6 +40,8 @@ import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ReplicationServerLeaderChanges3TimesIT extends ReplicationServerIT { private final AtomicInteger messagesInTotal = new AtomicInteger(); private final AtomicInteger messagesPerRestart = new AtomicInteger(); @@ -82,15 +83,15 @@ public void testReplication() { final ResultSet resultSet = db.command("SQL", "CREATE VERTEX " + VERTEX1_TYPE_NAME + " SET id = ?, name = ?", ++counter, "distributed-test"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result result = resultSet.next(); - Assertions.assertNotNull(result); + assertThat(result).isNotNull(); final Set props = result.getPropertyNames(); - Assertions.assertEquals(2, props.size(), "Found the following properties " + props); - Assertions.assertTrue(props.contains("id")); - Assertions.assertEquals(counter, (int) result.getProperty("id")); - Assertions.assertTrue(props.contains("name")); - Assertions.assertEquals("distributed-test", result.getProperty("name")); + assertThat(props.size()).as("Found the following properties " + props).isEqualTo(2); + assertThat(props.contains("id")).isTrue(); + assertThat((int) result.getProperty("id")).isEqualTo(counter); + assertThat(props.contains("name")).isTrue(); + assertThat(result.getProperty("name")).isEqualTo("distributed-test"); if (counter % 100 == 0) { LogManager.instance().log(this, Level.SEVERE, "- Progress %d/%d", null, counter, (getTxs() * getVerticesPerTx())); @@ -135,7 +136,7 @@ public void testReplication() { onAfterTest(); LogManager.instance().log(this, Level.FINE, "TEST Restart = %d", null, restarts); - Assertions.assertTrue(restarts.get() >= getServerCount(), "Restarted " + restarts.get() + " times"); + assertThat(restarts.get() >= getServerCount()).as("Restarted " + restarts.get() + " times").isTrue(); } @Override diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownIT.java index b27131a58a..ce524d987e 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownIT.java @@ -28,13 +28,14 @@ import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.server.ReplicationCallback; import com.arcadedb.utility.CodeUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ReplicationServerLeaderDownIT extends ReplicationServerIT { private final AtomicInteger messages = new AtomicInteger(); @@ -76,15 +77,15 @@ public void testReplication() { final ResultSet resultSet = db.command("SQL", "CREATE VERTEX " + VERTEX1_TYPE_NAME + " SET id = ?, name = ?", ++counter, "distributed-test"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result result = resultSet.next(); - Assertions.assertNotNull(result); + assertThat(result).isNotNull(); final Set props = result.getPropertyNames(); - Assertions.assertEquals(2, props.size(), "Found the following properties " + props); - Assertions.assertTrue(props.contains("id")); - Assertions.assertEquals(counter, (int) result.getProperty("id")); - Assertions.assertTrue(props.contains("name")); - Assertions.assertEquals("distributed-test", result.getProperty("name")); + assertThat(props.size()).as("Found the following properties " + props).isEqualTo(2); + assertThat(props.contains("id")).isTrue(); + assertThat((int) result.getProperty("id")).isEqualTo(counter); + assertThat(props.contains("name")).isTrue(); + assertThat(result.getProperty("name")).isEqualTo("distributed-test"); break; } catch (final RemoteException e) { // IGNORE IT diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownNoTransactionsToForwardIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownNoTransactionsToForwardIT.java index 796765f691..84e57172d1 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownNoTransactionsToForwardIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerLeaderDownNoTransactionsToForwardIT.java @@ -28,13 +28,14 @@ import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.server.ReplicationCallback; import com.arcadedb.utility.CodeUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.*; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ReplicationServerLeaderDownNoTransactionsToForwardIT extends ReplicationServerIT { private final AtomicInteger messages = new AtomicInteger(); @@ -73,15 +74,15 @@ public void testReplication() { final ResultSet resultSet = db.command("SQL", "CREATE VERTEX " + VERTEX1_TYPE_NAME + " SET id = ?, name = ?", ++counter, "distributed-test"); - Assertions.assertTrue(resultSet.hasNext()); + assertThat(resultSet.hasNext()).isTrue(); final Result result = resultSet.next(); - Assertions.assertNotNull(result); + assertThat(result).isNotNull(); final Set props = result.getPropertyNames(); - Assertions.assertEquals(2, props.size(), "Found the following properties " + props); - Assertions.assertTrue(props.contains("id")); - Assertions.assertEquals(counter, (int) result.getProperty("id")); - Assertions.assertTrue(props.contains("name")); - Assertions.assertEquals("distributed-test", result.getProperty("name")); + assertThat(props.size()).as("Found the following properties " + props).isEqualTo(2); + assertThat(props.contains("id")).isTrue(); + assertThat((int) result.getProperty("id")).isEqualTo(counter); + assertThat(props.contains("name")).isTrue(); + assertThat(result.getProperty("name")).isEqualTo("distributed-test"); break; } catch (final RemoteException e) { // IGNORE IT diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerQuorumMajority2ServersOutIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerQuorumMajority2ServersOutIT.java index 019c38c2de..327ed2d825 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerQuorumMajority2ServersOutIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerQuorumMajority2ServersOutIT.java @@ -24,11 +24,13 @@ import com.arcadedb.network.binary.QuorumNotReachedException; import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.ReplicationCallback; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.concurrent.atomic.*; -import java.util.logging.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class ReplicationServerQuorumMajority2ServersOutIT extends ReplicationServerIT { private final AtomicInteger messages = new AtomicInteger(); @@ -70,7 +72,7 @@ public void onEvent(final TYPE type, final Object object, final ArcadeDBServer s public void testReplication() throws Exception { try { super.testReplication(); - Assertions.fail("Replication is supposed to fail without enough online servers"); + fail("Replication is supposed to fail without enough online servers"); } catch (final QuorumNotReachedException e) { // CATCH IT } @@ -84,11 +86,11 @@ protected void checkEntriesOnServer(final int serverIndex) { final Database db = getServerDatabase(serverIndex, getDatabaseName()); db.begin(); try { - Assertions.assertTrue(1 + getTxs() * getVerticesPerTx() > db.countType(VERTEX1_TYPE_NAME, true), "Check for vertex count for server" + serverIndex); + assertThat(1 + getTxs() * getVerticesPerTx() > db.countType(VERTEX1_TYPE_NAME, true)).as("Check for vertex count for server" + serverIndex).isTrue(); } catch (final Exception e) { e.printStackTrace(); - Assertions.fail("Error on checking on server" + serverIndex); + fail("Error on checking on server" + serverIndex); } } diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaHotResyncIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaHotResyncIT.java index 2c35ca9103..75c67b9964 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaHotResyncIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaHotResyncIT.java @@ -23,11 +23,12 @@ import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.ReplicationCallback; import com.arcadedb.utility.CodeUtils; -import org.junit.jupiter.api.Assertions; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ReplicationServerReplicaHotResyncIT extends ReplicationServerIT { private final AtomicLong totalMessages = new AtomicLong(); private volatile boolean slowDown = true; @@ -42,12 +43,13 @@ public void setTestConfiguration() { @Override protected void onAfterTest() { - Assertions.assertTrue(hotResync); - Assertions.assertFalse(fullResync); + assertThat(hotResync).isTrue(); + assertThat(fullResync).isFalse(); } @Override protected void onBeforeStarting(final ArcadeDBServer server) { + if (server.getServerName().equals("ArcadeDB_2")) server.registerTestEventListener(new ReplicationCallback() { @Override @@ -58,15 +60,15 @@ public void onEvent(final TYPE type, final Object object, final ArcadeDBServer s if (slowDown) { // SLOW DOWN A SERVER AFTER 5TH MESSAGE if (totalMessages.incrementAndGet() > 5) { - LogManager.instance().log(this, Level.FINE, "TEST: Slowing down response from replica server 2..."); - CodeUtils.sleep(10_000); + LogManager.instance().log(this, Level.INFO, "TEST: Slowing down response from replica server 2..."); + CodeUtils.sleep(5_000); } } else { if (type == TYPE.REPLICA_HOT_RESYNC) { - LogManager.instance().log(this, Level.FINE, "TEST: Received hot resync request"); + LogManager.instance().log(this, Level.INFO, "TEST: Received hot resync request"); hotResync = true; } else if (type == TYPE.REPLICA_FULL_RESYNC) { - LogManager.instance().log(this, Level.FINE, "TEST: Received full resync request"); + LogManager.instance().log(this, Level.INFO, "TEST: Received full resync request"); fullResync = true; } } @@ -82,7 +84,7 @@ public void onEvent(final TYPE type, final Object object, final ArcadeDBServer s return; if ("ArcadeDB_2".equals(object) && type == TYPE.REPLICA_OFFLINE) { - LogManager.instance().log(this, Level.FINE, "TEST: Replica 2 is offline removing latency..."); + LogManager.instance().log(this, Level.INFO, "TEST: Replica 2 is offline removing latency..."); slowDown = false; } } diff --git a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaRestartForceDbInstallIT.java b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaRestartForceDbInstallIT.java index 3529f54330..f33007e006 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaRestartForceDbInstallIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ReplicationServerReplicaRestartForceDbInstallIT.java @@ -22,12 +22,14 @@ import com.arcadedb.log.LogManager; import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.ReplicationCallback; -import org.junit.jupiter.api.Assertions; + import java.io.*; import java.util.concurrent.atomic.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ReplicationServerReplicaRestartForceDbInstallIT extends ReplicationServerIT { private final AtomicLong totalMessages = new AtomicLong(); private volatile boolean firstTimeServerShutdown = true; @@ -41,8 +43,8 @@ public ReplicationServerReplicaRestartForceDbInstallIT() { @Override protected void onAfterTest() { - Assertions.assertFalse(hotResync); - Assertions.assertTrue(fullResync); + assertThat(hotResync).isFalse(); + assertThat(fullResync).isTrue(); } @Override @@ -97,7 +99,7 @@ public void onEvent(final TYPE type, final Object object, final ArcadeDBServer s getServer(2).stop(); GlobalConfiguration.HA_REPLICATION_QUEUE_SIZE.reset(); - Assertions.assertTrue(new File("./target/replication/replication_ArcadeDB_2.rlog.0").exists()); + assertThat(new File("./target/replication/replication_ArcadeDB_2.rlog.0").exists()).isTrue(); new File("./target/replication/replication_ArcadeDB_2.rlog.0").delete(); LogManager.instance().log(this, Level.SEVERE, "TEST: Restarting Replica 2..."); diff --git a/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseAlignIT.java b/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseAlignIT.java index 1596b09391..d195afbaf8 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseAlignIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseAlignIT.java @@ -28,11 +28,14 @@ import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.*; -import java.util.*; +import java.io.File; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; public class ServerDatabaseAlignIT extends BaseGraphServerTest { @Override @@ -65,19 +68,19 @@ public void alignNotNecessary() throws InterruptedException { database.deleteRecord(edge); }); - final ResultSet resultset = getServer(0).getDatabase(getDatabaseName()).command("sql", "align database"); - - Assertions.assertTrue(resultset.hasNext()); - final Result result = resultset.next(); - - Assertions.assertFalse(result.hasProperty("ArcadeDB_0")); - Assertions.assertTrue(result.hasProperty("ArcadeDB_1")); - Assertions.assertEquals(0, ((List) result.getProperty("ArcadeDB_1")).size()); - Assertions.assertTrue(result.hasProperty("ArcadeDB_2")); - Assertions.assertEquals(0, ((List) result.getProperty("ArcadeDB_2")).size()); + final Result result; + try (ResultSet resultset = getServer(0).getDatabase(getDatabaseName()) + .command("sql", "align database")) { + + assertThat(resultset.hasNext()).isTrue(); + result = resultset.next(); + assertThat(result.hasProperty("ArcadeDB_0")).isFalse(); + assertThat(result.hasProperty("ArcadeDB_1")).isTrue(); + assertThat(result.>getProperty("ArcadeDB_1")).hasSize(0); + assertThat(result.hasProperty("ArcadeDB_2")).isTrue(); + assertThat(result.>getProperty("ArcadeDB_2")).hasSize(0); + } - // WAIT THE ALIGN IS COMPLETE BEFORE CHECKING THE DATABASES - Thread.sleep(3000); } @Test @@ -90,25 +93,20 @@ public void alignNecessary() throws InterruptedException { edge.delete(); database.commit(); - try { - checkDatabasesAreIdentical(); - Assertions.fail(); - } catch (final DatabaseComparator.DatabaseAreNotIdentical e) { - // EXPECTED - } - - final ResultSet resultset = getServer(0).getDatabase(getDatabaseName()).command("sql", "align database"); + assertThatThrownBy(() -> checkDatabasesAreIdentical()) + .isInstanceOf(DatabaseComparator.DatabaseAreNotIdentical.class); - Assertions.assertTrue(resultset.hasNext()); - final Result result = resultset.next(); + final Result result; + try (ResultSet resultset = getServer(0).getDatabase(getDatabaseName()).command("sql", "align database")) { + assertThat(resultset.hasNext()).isTrue(); + result = resultset.next(); - Assertions.assertFalse(result.hasProperty("ArcadeDB_0")); - Assertions.assertTrue(result.hasProperty("ArcadeDB_1"), "Missing response from server ArcadeDB_1: " + result.toJSON()); - Assertions.assertEquals(3, ((List) result.getProperty("ArcadeDB_1")).size()); - Assertions.assertTrue(result.hasProperty("ArcadeDB_2"), "Missing response from server ArcadeDB_2: " + result.toJSON()); - Assertions.assertEquals(3, ((List) result.getProperty("ArcadeDB_2")).size()); + assertThat(result.hasProperty("ArcadeDB_0")).isFalse(); + assertThat(result.hasProperty("ArcadeDB_1")).isTrue(); + assertThat(result.>getProperty("ArcadeDB_1")).hasSize(3); + assertThat(result.hasProperty("ArcadeDB_2")).isTrue(); + assertThat(result.>getProperty("ArcadeDB_2")).hasSize(3); - // WAIT THE ALIGN IS COMPLETE BEFORE CHECKING THE DATABASES - Thread.sleep(3000); + } } } diff --git a/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseBackupIT.java b/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseBackupIT.java index 99a8615714..9e90062f93 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseBackupIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseBackupIT.java @@ -25,11 +25,12 @@ import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ServerDatabaseBackupIT extends BaseGraphServerTest { @Override protected int getServerCount() { @@ -57,14 +58,14 @@ public void sqlBackup() { final Database database = getServer(i).getDatabase(getDatabaseName()); final ResultSet result = database.command("sql", "backup database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result response = result.next(); final String backupFile = response.getProperty("backupFile"); - Assertions.assertNotNull(backupFile); + assertThat(backupFile).isNotNull(); final File file = new File("target/backups/graph/" + backupFile); - Assertions.assertTrue(file.exists()); + assertThat(file.exists()).isTrue(); file.delete(); } } @@ -75,14 +76,14 @@ public void sqlScriptBackup() { final Database database = getServer(i).getDatabase(getDatabaseName()); final ResultSet result = database.command("sqlscript", "backup database"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result response = result.next(); final String backupFile = response.getProperty("backupFile"); - Assertions.assertNotNull(backupFile); + assertThat(backupFile).isNotNull(); final File file = new File("target/backups/graph/" + backupFile); - Assertions.assertTrue(file.exists()); + assertThat(file.exists()).isTrue(); file.delete(); } } diff --git a/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseSqlScriptIT.java b/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseSqlScriptIT.java index f3e53609db..f94cd563a2 100644 --- a/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseSqlScriptIT.java +++ b/server/src/test/java/com/arcadedb/server/ha/ServerDatabaseSqlScriptIT.java @@ -24,12 +24,15 @@ import com.arcadedb.query.sql.executor.ResultSet; import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.utility.FileUtils; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.Test; import java.io.*; +import static org.assertj.core.api.Assertions.*; + public class ServerDatabaseSqlScriptIT extends BaseGraphServerTest { @Override protected int getServerCount() { @@ -64,9 +67,9 @@ public void executeSqlScript() { "LET photo1 = CREATE vertex Photos SET id = \"3778f235a52d\", name = \"beach.jpg\", status = \"\";\n" + "LET photo2 = CREATE vertex Photos SET id = \"23kfkd23223\", name = \"luca.jpg\", status = \"\";\n" + "LET connected = Create edge Connected FROM $photo1 to $photo2 set type = \"User_Photos\";return $photo1;"); - Assertions.assertTrue(result.hasNext()); + assertThat(result.hasNext()).isTrue(); final Result response = result.next(); - Assertions.assertEquals("beach.jpg", response.getProperty("name")); + assertThat(response.getProperty("name")).isEqualTo("beach.jpg"); }); } } diff --git a/server/src/test/java/com/arcadedb/server/security/ServerProfilingIT.java b/server/src/test/java/com/arcadedb/server/security/ServerProfilingIT.java index 023d546682..04b8a705e1 100644 --- a/server/src/test/java/com/arcadedb/server/security/ServerProfilingIT.java +++ b/server/src/test/java/com/arcadedb/server/security/ServerProfilingIT.java @@ -39,7 +39,7 @@ import com.arcadedb.utility.CallableNoReturn; import com.arcadedb.utility.FileUtils; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,6 +49,9 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + public class ServerProfilingIT { private static ArcadeDBServer SERVER; private static ServerSecurity SECURITY; @@ -351,13 +354,13 @@ void deleteOnlyAccess() throws Throwable { final ServerSecurityUser elon = setCurrentUser("elon", database); checkElonUser(elon); - Assertions.assertTrue(elon.getAuthorizedDatabases().contains(database.getName())); + assertThat(elon.getAuthorizedDatabases().contains(database.getName())).isTrue(); createSchemaNotAllowed(database); // SWITCH TO ROOT TO CREATE SOME TYPES FOR FURTHER TESTS final ServerSecurityUser root = setCurrentUser("root", database); - Assertions.assertTrue(root.getAuthorizedDatabases().contains("*")); + assertThat(root.getAuthorizedDatabases().contains("*")).isTrue(); createSchema(database); @@ -417,7 +420,7 @@ void testResultSetLimit() throws Throwable { ++count; } - Assertions.assertEquals(10, count); + assertThat(count).isEqualTo(10); count = 0; for (final ResultSet iter = database.query("sql", "select from Document1"); iter.hasNext(); ) { @@ -425,7 +428,7 @@ void testResultSetLimit() throws Throwable { ++count; } - Assertions.assertEquals(10, count); + assertThat(count).isEqualTo(10); // SWITCH TO ROOT TO DROP THE SCHEMA setCurrentUser("root", database); @@ -469,7 +472,7 @@ void testReadTimeout() throws Throwable { for (final Iterator iter = database.iterateType("Document1", true); iter.hasNext(); ) { iter.next(); } - Assertions.fail(); + fail(""); } catch (final TimeoutException e) { // EXPECTED } @@ -478,7 +481,7 @@ void testReadTimeout() throws Throwable { for (final ResultSet iter = database.query("sql", "select from Document1"); iter.hasNext(); ) { iter.next(); } - Assertions.fail(); + fail(""); } catch (final TimeoutException e) { // EXPECTED } @@ -495,7 +498,7 @@ void testReadTimeout() throws Throwable { @Test void testGroupsReload() throws Throwable { final File file = new File("./target/config/" + SecurityGroupFileRepository.FILE_NAME); - Assertions.assertTrue(file.exists()); + assertThat(file.exists()).isTrue(); final JSONObject json = new JSONObject(FileUtils.readFileAsString(file)); @@ -508,7 +511,7 @@ void testGroupsReload() throws Throwable { Thread.sleep(300); - Assertions.assertTrue(SECURITY.getDatabaseGroupsConfiguration("*").getBoolean("reloaded")); + assertThat(SECURITY.getDatabaseGroupsConfiguration("*").getBoolean("reloaded")).isTrue(); } finally { // RESTORE THE ORIGINAL FILE AND WAIT FOR TO RELOAD FileUtils.writeContentToStream(file, original); @@ -535,7 +538,7 @@ public void reloadWhileUsingDatabase() throws Throwable { final Thread cfgUpdaterThread = new Thread(() -> { final File file = new File("./target/config/" + SecurityGroupFileRepository.FILE_NAME); - Assertions.assertTrue(file.exists()); + assertThat(file.exists()).isTrue(); try { for (int i = 0; i < CYCLES; i++) { @@ -543,14 +546,14 @@ public void reloadWhileUsingDatabase() throws Throwable { json.getJSONObject("databases").getJSONObject("*").getJSONObject("groups").put("reloaded", i); FileUtils.writeContentToStream(file, json.toString(2).getBytes()); Thread.sleep(150); - Assertions.assertEquals(i, SECURITY.getDatabaseGroupsConfiguration("*").getInt("reloaded")); + assertThat(SECURITY.getDatabaseGroupsConfiguration("*").getInt("reloaded")).isEqualTo(i); semaphore.countDown(); } } catch (Exception e) { e.printStackTrace(); - Assertions.fail(e); + fail("", e); } }); @@ -562,7 +565,7 @@ public void reloadWhileUsingDatabase() throws Throwable { cfgUpdaterThread.join(); - Assertions.assertEquals(CYCLES - 1, SECURITY.getDatabaseGroupsConfiguration("*").getInt("reloaded")); + assertThat(SECURITY.getDatabaseGroupsConfiguration("*").getInt("reloaded")).isEqualTo(CYCLES - 1); dropSchema(database); @@ -592,29 +595,29 @@ private void createSchemaNotAllowed(final DatabaseInternal database) throws Thro private void expectedSecurityException(final CallableNoReturn callback) throws Throwable { try { callback.call(); - Assertions.fail(); + fail(""); } catch (final SecurityException e) { // EXPECTED } } private void checkElonUser(final ServerSecurityUser elon) { - Assertions.assertNotNull(elon); + assertThat(elon).isNotNull(); final ServerSecurityUser authElon = SECURITY.authenticate("elon", "musk", null); - Assertions.assertNotNull(authElon); - Assertions.assertEquals(elon.getName(), authElon.getName()); + assertThat(authElon).isNotNull(); + assertThat(authElon.getName()).isEqualTo(elon.getName()); final SecurityUserFileRepository repository = new SecurityUserFileRepository("./target/config"); - Assertions.assertEquals(2, repository.getUsers().size()); - Assertions.assertEquals("elon", repository.getUsers().get(1).getString("name")); + assertThat(repository.getUsers().size()).isEqualTo(2); + assertThat(repository.getUsers().get(1).getString("name")).isEqualTo("elon"); } private ServerSecurityUser setCurrentUser(final String userName, final DatabaseInternal database) { final ServerSecurityUser user = SECURITY.getUser(userName); final SecurityDatabaseUser dbUser = user.getDatabaseUser(database); DatabaseContext.INSTANCE.init(database).setCurrentUser(dbUser); - Assertions.assertEquals(dbUser, DatabaseContext.INSTANCE.getContext(database.getDatabasePath()).getCurrentUser()); - Assertions.assertEquals(userName, dbUser.getName()); + assertThat(DatabaseContext.INSTANCE.getContext(database.getDatabasePath()).getCurrentUser()).isEqualTo(dbUser); + assertThat(dbUser.getName()).isEqualTo(userName); return user; } diff --git a/server/src/test/java/com/arcadedb/server/security/ServerSecurityIT.java b/server/src/test/java/com/arcadedb/server/security/ServerSecurityIT.java index fc9e4c702d..ed3fdd18d0 100644 --- a/server/src/test/java/com/arcadedb/server/security/ServerSecurityIT.java +++ b/server/src/test/java/com/arcadedb/server/security/ServerSecurityIT.java @@ -23,14 +23,19 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.TestServerHelper; import com.arcadedb.utility.FileUtils; +import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.*; import java.nio.file.*; import java.util.*; +import java.util.concurrent.*; + +import static java.util.concurrent.TimeUnit.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; public class ServerSecurityIT { @@ -47,14 +52,14 @@ void shouldCreateDefaultRootUserAndPersistsSecurityConfigurationFromSetting() th final Path securityConfPath = Paths.get("./target", SecurityUserFileRepository.FILE_NAME); final File securityConf = securityConfPath.toFile(); - Assertions.assertTrue(securityConf.exists()); + assertThat(securityConf.exists()).isTrue(); final SecurityUserFileRepository repository = new SecurityUserFileRepository("./target"); final List jsonl = repository.load(); - Assertions.assertEquals(1, jsonl.size()); - Assertions.assertEquals("root", jsonl.get(0).getString("name")); + assertThat(jsonl.size()).isEqualTo(1); + assertThat(jsonl.get(0).getString("name")).isEqualTo("root"); passwordShouldMatch(security, PASSWORD, jsonl.get(0).getString("password")); } @@ -78,14 +83,14 @@ void shouldCreateDefaultRootUserAndPersistsSecurityConfigurationFromUserInput() final File securityConf = securityConfPath.toFile(); - Assertions.assertTrue(securityConf.exists()); + assertThat(securityConf.exists()).isTrue(); final SecurityUserFileRepository repository = new SecurityUserFileRepository("./target"); final List jsonl = repository.load(); - Assertions.assertEquals(1, jsonl.size()); - Assertions.assertEquals("root", jsonl.get(0).getString("name")); + assertThat(jsonl.size()).isEqualTo(1); + assertThat(jsonl.get(0).getString("name")).isEqualTo("root"); passwordShouldMatch(security, PASSWORD, jsonl.get(0).getString("password")); } @@ -106,8 +111,8 @@ void shouldLoadProvidedSecurityConfiguration() throws IOException { security.startService(); security.loadUsers(); - Assertions.assertTrue(security.existsUser("providedUser")); - Assertions.assertFalse(security.existsUser("root")); + assertThat(security.existsUser("providedUser")).isTrue(); + assertThat(security.existsUser("root")).isFalse(); passwordShouldMatch(security, "MyPassword12345", security.getUser("providedUser").getPassword()); } @@ -131,24 +136,19 @@ void shouldReloadSecurityConfiguration() throws IOException { security.startService(); security.loadUsers(); - Assertions.assertTrue(security.existsUser("providedUser")); + assertThat(security.existsUser("providedUser")).isTrue(); ServerSecurityUser user2 = security.getUser("providedUser"); - Assertions.assertEquals("providedUser", user2.getName()); + assertThat(user2.getName()).isEqualTo("providedUser"); - Assertions.assertFalse(security.existsUser("root")); + assertThat(security.existsUser("root")).isFalse(); passwordShouldMatch(security, "MyPassword12345", security.getUser("providedUser").getPassword()); // RESET USERS ACCESSING DIRECTLY TO THE FILE repository.save(SecurityUserFileRepository.createDefault()); - try { - Thread.sleep(220); - } catch (final InterruptedException e) { - e.printStackTrace(); - } + await().atMost(10, SECONDS).until(()-> !security.existsUser("providedUser")); - Assertions.assertFalse(security.existsUser("providedUser")); } @Test @@ -156,20 +156,18 @@ public void checkPasswordHash() { final ServerSecurity security = new ServerSecurity(null, new ContextConfiguration(), "./target"); security.startService(); - Assertions.assertEquals("PBKDF2WithHmacSHA256$65536$ThisIsTheSalt$wIKUzWYH72cKJRnFZ0PTSevERtwZTNdN+W4/Fd7xBvw=", - security.encodePassword("ThisIsATest", "ThisIsTheSalt")); - Assertions.assertEquals("PBKDF2WithHmacSHA256$65536$ThisIsTheSalt$wIKUzWYH72cKJRnFZ0PTSevERtwZTNdN+W4/Fd7xBvw=", - security.encodePassword("ThisIsATest", "ThisIsTheSalt")); + assertThat(security.encodePassword("ThisIsATest", "ThisIsTheSalt")).isEqualTo("PBKDF2WithHmacSHA256$65536$ThisIsTheSalt$wIKUzWYH72cKJRnFZ0PTSevERtwZTNdN+W4/Fd7xBvw="); + assertThat(security.encodePassword("ThisIsATest", "ThisIsTheSalt")).isEqualTo("PBKDF2WithHmacSHA256$65536$ThisIsTheSalt$wIKUzWYH72cKJRnFZ0PTSevERtwZTNdN+W4/Fd7xBvw="); for (int i = 0; i < 1000000; ++i) { - Assertions.assertFalse(ServerSecurity.generateRandomSalt().contains("$")); + assertThat(ServerSecurity.generateRandomSalt().contains("$")).isFalse(); } security.stopService(); } private void passwordShouldMatch(final ServerSecurity security, final String password, final String expectedHash) { - Assertions.assertTrue(security.passwordMatch(password, expectedHash)); + assertThat(security.passwordMatch(password, expectedHash)).isTrue(); } @BeforeEach diff --git a/server/src/test/java/com/arcadedb/server/ws/WebSocketClientHelper.java b/server/src/test/java/com/arcadedb/server/ws/WebSocketClientHelper.java index 110f195507..77ec92fc9e 100644 --- a/server/src/test/java/com/arcadedb/server/ws/WebSocketClientHelper.java +++ b/server/src/test/java/com/arcadedb/server/ws/WebSocketClientHelper.java @@ -32,7 +32,8 @@ import io.undertow.websockets.core.WebSocketChannel; import io.undertow.websockets.core.WebSocketFrameType; import io.undertow.websockets.core.WebSockets; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.xnio.OptionMap; import org.xnio.Options; import org.xnio.Xnio; @@ -45,6 +46,7 @@ import java.util.logging.*; import static org.apache.lucene.store.BufferedIndexInput.BUFFER_SIZE; +import static org.assertj.core.api.Assertions.fail; public class WebSocketClientHelper implements AutoCloseable { private final XnioWorker worker; @@ -84,7 +86,7 @@ protected void onFullTextMessage(final WebSocketChannel channel, final BufferedT protected void onError(final WebSocketChannel channel, final Throwable error) { LogManager.instance().log(this, Level.SEVERE, "WS client error: " + error); super.onError(channel, error); - Assertions.fail(error.getMessage()); + fail(error.getMessage()); } }); this.channel.resumeReceives(); diff --git a/server/src/test/java/com/arcadedb/server/ws/WebSocketEventBusIT.java b/server/src/test/java/com/arcadedb/server/ws/WebSocketEventBusIT.java index 6eb20840c3..e1ba7ba32f 100644 --- a/server/src/test/java/com/arcadedb/server/ws/WebSocketEventBusIT.java +++ b/server/src/test/java/com/arcadedb/server/ws/WebSocketEventBusIT.java @@ -23,26 +23,31 @@ import com.arcadedb.serializer.json.JSONObject; import com.arcadedb.server.BaseGraphServerTest; import com.arcadedb.utility.CallableNoReturn; -import org.junit.jupiter.api.Assertions; + +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.xnio.http.UpgradeFailedException; import java.util.logging.*; +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + public class WebSocketEventBusIT extends BaseGraphServerTest { private static final int DELAY_MS = 1000; @Test public void closeUnsubscribesAll() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { var result = new JSONObject(client.send(buildActionMessage("subscribe", "graph", "V1"))); - Assertions.assertEquals("ok", result.get("result")); + assertThat(result.get("result")).isEqualTo("ok"); result = new JSONObject(client.send(buildActionMessage("subscribe", "graph", "V2"))); - Assertions.assertEquals("ok", result.get("result")); + assertThat(result.get("result")).isEqualTo("ok"); } Thread.sleep(DELAY_MS); - Assertions.assertEquals(0, getServer(0).getHttpServer().getWebSocketEventBus().getDatabaseSubscriptions("graph").size()); + assertThat(getServer(0).getHttpServer().getWebSocketEventBus().getDatabaseSubscriptions("graph")).isEmpty(); }, "closeUnsubscribesAll"); } @@ -50,37 +55,41 @@ public void closeUnsubscribesAll() throws Throwable { public void badCloseIsCleanedUp() throws Throwable { execute(() -> { { - final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); + final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS); final var result = new JSONObject(client.send(buildActionMessage("subscribe", "graph", "V1"))); - Assertions.assertEquals("ok", result.get("result")); + assertThat(result.get("result")).isEqualTo("ok"); client.breakConnection(); } - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final JSONObject result = new JSONObject(client.send(buildActionMessage("subscribe", "graph", "V1"))); - Assertions.assertEquals("ok", result.get("result")); + assertThat(result.get("result")).isEqualTo("ok"); getServerDatabase(0, "graph").newVertex("V1").set("name", "test").save(); final var json = getJsonMessageOrFail(client); - Assertions.assertEquals("create", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("create"); // The sending thread should have detected and removed the zombie connection. Thread.sleep(DELAY_MS); - Assertions.assertEquals(1, getServer(0).getHttpServer().getWebSocketEventBus().getDatabaseSubscriptions("graph").size()); + assertThat(getServer(0).getHttpServer().getWebSocketEventBus().getDatabaseSubscriptions("graph")).hasSize(1); } Thread.sleep(DELAY_MS); - Assertions.assertTrue(getServer(0).getHttpServer().getWebSocketEventBus().getDatabaseSubscriptions(getDatabaseName()).isEmpty()); + assertThat( + getServer(0).getHttpServer().getWebSocketEventBus().getDatabaseSubscriptions(getDatabaseName()).isEmpty()).isTrue(); }, "badCloseIsCleanedUp"); } @Test public void invalidJsonReturnsError() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = new JSONObject(client.send("42")); - Assertions.assertEquals("error", result.get("result")); - Assertions.assertEquals("com.arcadedb.serializer.json.JSONException", result.get("exception")); + assertThat(result.get("result")).isEqualTo("error"); + assertThat(result.get("exception")).isEqualTo("com.arcadedb.serializer.json.JSONException"); } }, "invalidJsonReturnsError"); } @@ -88,18 +97,22 @@ public void invalidJsonReturnsError() throws Throwable { @Test public void authenticationFailureReturns403() throws Throwable { execute(() -> { - final var thrown = Assertions.assertThrows(UpgradeFailedException.class, () -> new WebSocketClientHelper("ws://localhost:2480/ws", "root", "bad")); - Assertions.assertTrue(thrown.getMessage().contains("403")); + assertThatThrownBy(() -> { + new WebSocketClientHelper("ws://localhost:2480/ws", "root", "bad"); + }).isInstanceOf(UpgradeFailedException.class) + .hasMessageContaining("403"); + }, "authenticationFailureReturns403"); } @Test public void invalidDatabaseReturnsError() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = new JSONObject(client.send(buildActionMessage("subscribe", "invalid"))); - Assertions.assertEquals("error", result.get("result")); - Assertions.assertEquals("com.arcadedb.exception.DatabaseOperationException", result.get("exception")); + assertThat(result.get("result")).isEqualTo("error"); + assertThat(result.get("exception")).isEqualTo("com.arcadedb.exception.DatabaseOperationException"); } }, "invalidDatabaseReturnsError"); } @@ -107,9 +120,10 @@ public void invalidDatabaseReturnsError() throws Throwable { @Test public void unsubscribeWithoutSubscribeDoesNothing() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = new JSONObject(client.send(buildActionMessage("unsubscribe", "graph"))); - Assertions.assertEquals("ok", result.get("result")); + assertThat(result.get("result")).isEqualTo("ok"); } }, "unsubscribeWithoutSubscribeDoesNothing"); } @@ -117,10 +131,11 @@ public void unsubscribeWithoutSubscribeDoesNothing() throws Throwable { @Test public void invalidActionReturnsError() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = new JSONObject(client.send(buildActionMessage("invalid", "graph"))); - Assertions.assertEquals("error", result.get("result")); - Assertions.assertEquals("invalid is not a valid action.", result.get("detail")); + assertThat(result.get("result")).isEqualTo("error"); + assertThat(result.get("detail")).isEqualTo("invalid is not a valid action."); } }, "invalidActionReturnsError"); } @@ -128,10 +143,11 @@ public void invalidActionReturnsError() throws Throwable { @Test public void missingActionReturnsError() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = new JSONObject(client.send("{\"database\": \"graph\"}")); - Assertions.assertEquals("error", result.get("result")); - Assertions.assertEquals("Property 'action' is required.", result.get("detail")); + assertThat(result.get("result")).isEqualTo("error"); + assertThat(result.get("detail")).isEqualTo("Property 'action' is required."); } }, "missingActionReturnsError"); } @@ -139,17 +155,18 @@ public void missingActionReturnsError() throws Throwable { @Test public void subscribeDatabaseWorks() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = client.send(buildActionMessage("subscribe", "graph")); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); final MutableVertex v = getServerDatabase(0, "graph").newVertex("V1").set("name", "test").save(); final var json = getJsonMessageOrFail(client); - Assertions.assertEquals("create", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("create"); final var record = json.getJSONObject("record"); - Assertions.assertEquals("test", record.get("name")); - Assertions.assertEquals("V1", record.get("@type")); + assertThat(record.get("name")).isEqualTo("test"); + assertThat(record.get("@type")).isEqualTo("V1"); } }, "subscribeDatabaseWorks"); } @@ -163,17 +180,17 @@ public void twoSubscribersAreServiced() throws Throwable { for (final var client : clients) { final var result = client.send(buildActionMessage("subscribe", "graph")); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); } getServerDatabase(0, "graph").newVertex("V1").set("name", "test").save(); for (final var client : clients) { final var json = getJsonMessageOrFail(client); - Assertions.assertEquals("create", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("create"); final var record = json.getJSONObject("record"); - Assertions.assertEquals("test", record.get("name")); - Assertions.assertEquals("V1", record.get("@type")); + assertThat(record.get("name")).isEqualTo("test"); + assertThat(record.get("@type")).isEqualTo("V1"); client.close(); } @@ -183,17 +200,18 @@ final var record = json.getJSONObject("record"); @Test public void subscribeTypeWorks() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = client.send(buildActionMessage("subscribe", "graph", "V1")); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); getServerDatabase(0, "graph").newVertex("V1").set("name", "test").save(); final var json = getJsonMessageOrFail(client); - Assertions.assertEquals("create", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("create"); final var record = json.getJSONObject("record"); - Assertions.assertEquals("test", record.get("name")); - Assertions.assertEquals("V1", record.get("@type")); + assertThat(record.get("name")).isEqualTo("test"); + assertThat(record.get("@type")).isEqualTo("V1"); } }, "subscribeTypeWorks"); } @@ -201,17 +219,18 @@ final var record = json.getJSONObject("record"); @Test public void subscribeChangeTypeWorks() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = client.send(buildActionMessage("subscribe", "graph", null, new String[] { "create" })); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); getServerDatabase(0, "graph").newVertex("V1").set("name", "test").save(); final var json = getJsonMessageOrFail(client); - Assertions.assertEquals("create", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("create"); final var record = json.getJSONObject("record"); - Assertions.assertEquals("test", record.get("name")); - Assertions.assertEquals("V1", record.get("@type")); + assertThat(record.get("name")).isEqualTo("test"); + assertThat(record.get("@type")).isEqualTo("V1"); } }, "subscribeChangeTypeWorks"); } @@ -219,33 +238,35 @@ final var record = json.getJSONObject("record"); @Test public void subscribeMultipleChangeTypesWorks() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { - final var result = client.send(buildActionMessage("subscribe", "graph", null, new String[] { "create", "update", "delete" })); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + final var result = client.send( + buildActionMessage("subscribe", "graph", null, new String[] { "create", "update", "delete" })); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); final var v1 = getServerDatabase(0, "graph").newVertex("V1").set("name", "test").save(); var json = getJsonMessageOrFail(client); - Assertions.assertEquals("create", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("create"); var record = json.getJSONObject("record"); - Assertions.assertEquals("test", record.get("name")); - Assertions.assertEquals("V1", record.get("@type")); + assertThat(record.get("name")).isEqualTo("test"); + assertThat(record.get("@type")).isEqualTo("V1"); v1.set("updated", true).save(); json = getJsonMessageOrFail(client); - Assertions.assertEquals("update", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("update"); record = json.getJSONObject("record"); - Assertions.assertEquals(v1.getIdentity().toString(), record.get("@rid")); - Assertions.assertTrue(record.getBoolean("updated")); + assertThat(record.get("@rid")).isEqualTo(v1.getIdentity().toString()); + assertThat(record.getBoolean("updated")).isTrue(); v1.delete(); json = getJsonMessageOrFail(client); - Assertions.assertEquals("delete", json.get("changeType")); + assertThat(json.get("changeType")).isEqualTo("delete"); record = json.getJSONObject("record"); - Assertions.assertEquals("test", record.get("name")); - Assertions.assertEquals("V1", record.get("@type")); + assertThat(record.get("name")).isEqualTo("test"); + assertThat(record.get("@type")).isEqualTo("V1"); } }, "subscribeMultipleChangeTypesWorks"); } @@ -253,13 +274,14 @@ record = json.getJSONObject("record"); @Test public void subscribeChangeTypeDoesNotPushOtherChangeTypes() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = client.send(buildActionMessage("subscribe", "graph", null, new String[] { "update" })); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); getServerDatabase(0, "graph").newVertex("V2").save(); - Assertions.assertNull(client.popMessage(500)); + assertThat(client.popMessage(500)).isNull(); } }, "subscribeChangeTypeDoesNotPushOtherChangeTypes"); } @@ -267,13 +289,14 @@ public void subscribeChangeTypeDoesNotPushOtherChangeTypes() throws Throwable { @Test public void subscribeTypeDoesNotPushOtherTypes() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { final var result = client.send(buildActionMessage("subscribe", "graph", "V1")); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); getServerDatabase(0, "graph").newVertex("V2").save(); - Assertions.assertNull(client.popMessage(500)); + assertThat(client.popMessage(500)).isNull(); } }, "subscribeTypeDoesNotPushOtherTypes"); } @@ -281,16 +304,17 @@ public void subscribeTypeDoesNotPushOtherTypes() throws Throwable { @Test public void unsubscribeDatabaseWorks() throws Throwable { execute(() -> { - try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { + try (final var client = new WebSocketClientHelper("ws://localhost:2480/ws", "root", + BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS)) { var result = client.send(buildActionMessage("subscribe", "graph")); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); result = client.send(buildActionMessage("unsubscribe", "graph")); - Assertions.assertEquals("ok", new JSONObject(result).get("result")); + assertThat(new JSONObject(result).get("result")).isEqualTo("ok"); getServerDatabase(0, "graph").newVertex("V1").save(); - Assertions.assertNull(client.popMessage(500)); + assertThat(client.popMessage(500)).isNull(); } }, "unsubscribeDatabaseWorks"); } @@ -305,11 +329,12 @@ private static String buildActionMessage(final String action, final String datab private static JSONObject getJsonMessageOrFail(final WebSocketClientHelper client) { final var message = client.popMessage(); - Assertions.assertNotNull(message, "No message received from the server."); + assertThat(message).as("No message received from the server.").isNotNull(); return new JSONObject(message); } - private static String buildActionMessage(final String action, final String database, final String type, final String[] changeTypes) { + private static String buildActionMessage(final String action, final String database, final String type, + final String[] changeTypes) { final var obj = new JSONObject(); obj.put("action", action); obj.put("database", database); diff --git a/server/src/test/java/performance/BasePerformanceTest.java b/server/src/test/java/performance/BasePerformanceTest.java index 1ba6250f88..fe06e95455 100644 --- a/server/src/test/java/performance/BasePerformanceTest.java +++ b/server/src/test/java/performance/BasePerformanceTest.java @@ -28,12 +28,12 @@ import com.arcadedb.server.ArcadeDBServer; import com.arcadedb.server.TestServerHelper; import com.arcadedb.utility.FileUtils; -import org.junit.jupiter.api.Assertions; import java.io.*; import java.util.logging.*; import static com.arcadedb.server.BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS; +import static org.assertj.core.api.Assertions.assertThat; public abstract class BasePerformanceTest { protected static RID root; @@ -82,7 +82,7 @@ protected void checkArcadeIsTotallyDown() { new Exception().printStackTrace(output); output.flush(); final String out = os.toString(); - Assertions.assertFalse(out.contains("ArcadeDB"), "Some thread is still up & running: \n" + out); + assertThat(out.contains("ArcadeDB")).as("Some thread is still up & running: \n" + out).isFalse(); } protected void startServers() { diff --git a/server/src/test/java/performance/RemoteDatabaseBenchmark.java b/server/src/test/java/performance/RemoteDatabaseBenchmark.java index 01e0a99798..b4d166b861 100644 --- a/server/src/test/java/performance/RemoteDatabaseBenchmark.java +++ b/server/src/test/java/performance/RemoteDatabaseBenchmark.java @@ -25,11 +25,12 @@ import com.arcadedb.remote.RemoteDatabase; import com.arcadedb.remote.RemoteServer; import com.arcadedb.server.BaseGraphServerTest; -import org.junit.jupiter.api.Assertions; import java.util.*; import java.util.concurrent.atomic.*; +import static org.assertj.core.api.Assertions.assertThat; + public class RemoteDatabaseBenchmark extends BaseGraphServerTest { private static final int TOTAL = 10_000; private static final int BATCH_TX = 1; @@ -107,11 +108,11 @@ public void run() { last = allIds.get(i); } - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, allIds.size()); + assertThat(allIds.size()).isEqualTo(TOTAL * CONCURRENT_THREADS); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, totalRecordsOnClusters); + assertThat(totalRecordsOnClusters).isEqualTo(TOTAL * CONCURRENT_THREADS); - Assertions.assertEquals(TOTAL * CONCURRENT_THREADS, database.countType("User", true)); + assertThat(database.countType("User", true)).isEqualTo(TOTAL * CONCURRENT_THREADS); database.close(); } diff --git a/server/src/test/java/performance/ReplicationSpeedQuorumMajorityIT.java b/server/src/test/java/performance/ReplicationSpeedQuorumMajorityIT.java index 8e47846201..92ee59515a 100644 --- a/server/src/test/java/performance/ReplicationSpeedQuorumMajorityIT.java +++ b/server/src/test/java/performance/ReplicationSpeedQuorumMajorityIT.java @@ -26,11 +26,12 @@ import com.arcadedb.log.LogManager; import com.arcadedb.schema.Schema; import com.arcadedb.schema.VertexType; -import org.junit.jupiter.api.Assertions; import java.util.*; import java.util.logging.*; +import static org.assertj.core.api.Assertions.assertThat; + public class ReplicationSpeedQuorumMajorityIT extends BasePerformanceTest { public static void main(final String[] args) { new ReplicationSpeedQuorumMajorityIT().run(); @@ -158,7 +159,7 @@ public void run() { } protected void populateDatabase(final int parallel, final Database database) { - Assertions.assertFalse(database.getSchema().existsType("Device")); + assertThat(database.getSchema().existsType("Device")).isFalse(); final VertexType v = database.getSchema().buildVertexType().withName("Device").withTotalBuckets(parallel).create(); From 4be48606da3c269a4157f2169020126a79a721bf Mon Sep 17 00:00:00 2001 From: lvca Date: Sun, 20 Oct 2024 13:58:45 -0400 Subject: [PATCH 45/45] minor: changed log level from severe to warning when permissions are missing on disabling close of channel upon Interruption --- .../java/com/arcadedb/engine/PaginatedComponentFile.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java b/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java index b93a5b13ae..e1943ecd00 100644 --- a/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java +++ b/engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java @@ -211,15 +211,15 @@ protected void open(final String filePath, final MODE mode) throws FileNotFoundE private void doNotCloseOnInterrupt(final FileChannel fc) { try { - Field field = AbstractInterruptibleChannel.class.getDeclaredField("interruptor"); - Class interruptibleClass = field.getType(); + final Field field = AbstractInterruptibleChannel.class.getDeclaredField("interruptor"); + final Class interruptibleClass = field.getType(); field.setAccessible(true); field.set(fc, Proxy.newProxyInstance( interruptibleClass.getClassLoader(), new Class[] { interruptibleClass }, new InterruptibleInvocationHandler())); } catch (final Exception e) { - LogManager.instance().log(this, Level.SEVERE, "Couldn't disable close on interrupt", e); + LogManager.instance().log(this, Level.WARNING, "Unable to disable channel close on interrupt: %s", e.getMessage()); } } }