Skip to content

Commit

Permalink
#1764 migrate form Junit5 Assertions to AssertJ
Browse files Browse the repository at this point in the history
  • Loading branch information
robfrank committed Oct 20, 2024
1 parent 872a1cc commit 551b1b3
Show file tree
Hide file tree
Showing 280 changed files with 7,241 additions and 6,736 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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().<String>getProperty("status")).isEqualTo("PENDING");
}

try (ResultSet resultSet = database.query("sql", "SELECT FROM Order WHERE status = 'PENDING' ORDER BY id ASC")) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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();
}
Expand All @@ -309,7 +314,7 @@ private MutableDocument resubmitOrder(Database database, int orderId) {
}
});
} catch (Exception e) {
Assertions.fail();
fail("");
}
return record[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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);
});
}
}
Expand Down Expand Up @@ -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);
});
}
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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"));
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@
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();
}

@Test
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();
}

Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit 551b1b3

Please sign in to comment.