/* * Copyright (c) 2018 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 org.junit.After; import org.junit.Before; import org.junit.Test; 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 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 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")); } }