Commons/src/test/java/eu/univento/commons/CommonsTest.java

76 lines
1.9 KiB
Java

/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.commons;
import eu.univento.commons.database.DatabaseManager;
import eu.univento.commons.player.user.UserInformation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author joethei
* @version 1.0
*/
public class CommonsTest {
private Commons commons;
@Before
public void init() {
commons = new Commons();
}
@After
public void close() {
commons.shutdown();
}
@Test
public void testUserInformationName() {
try {
assertTrue(UserInformation.get("069a79f444e94726a5befca90e38aaf5").get().getUsername().equals("Notch"));
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
@Test
public void testCommons() {
assertNotNull(commons);
assertNotNull(commons.getDatabaseManager());
assertNotNull(commons.getConfigurationHandler());
}
@Test
public void testDatabaseManager() {
DatabaseManager db = commons.getDatabaseManager();
assertNotNull(db.getMongoDB());
assertNotNull(db.getMySQL());
assertNotNull(db.getRedis());
}
@Test
public void testRedis() {
AtomicReference<String> result = new AtomicReference<>();
commons.getDatabaseManager().getRedis().getClient().get("test", event -> {
if(event.failed()) event.cause().printStackTrace();
result.set(event.result());
});
await().until(() -> result.get() != null);
assertTrue(result.get().equals("nope"));
}
}