package com.rant.config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.InjectMocks;

import com.rant.database.CouchDB;
import com.rant.database.CouchDBSetup;
import com.rant.database.DatabaseService;
import com.rant.objects.AppConfig;
import com.rant.objects.Database;

/**
 * Unit tests for Application
 * 
 * @author amdelamar
 * @since 1.0.0
 */
@RunWith(JUnit4.class)
public class ApplicationTests {

    private Application app;

    @InjectMocks
    private DatabaseService dbs;

    @Before
    public void beforeEachTest() {
        app = new Application();
    }

    @Test
    public void settingsFromFile() {

        AppConfig config = app.loadSettingsFromFile(Application.getPropFile());
        Application.setConfig(config);
        assertNotNull(Application.getConfig());

        assertNotNull(Application.getString("name"));
        assertTrue(Application.getInt("default.limit") > 0);
        assertTrue(Application.getDouble("default.manageLimit") > 0d);

        Application.setString("test", "true");
        assertEquals("true", Application.getString("test"));
    }

    @Test
    public void database() {

        Database db = app.loadDatabase();
        assertNotNull(db);

        Application.setDatabaseSetup(new CouchDBSetup(db));
        assertNotNull(Application.getDatabaseSetup());

        Application.setDatabaseService(new CouchDB(db));
        assertNotNull(Application.getDatabaseService());
    }

    @Test
    public void properties() {
        assertNotNull(Application.getPropFile());
        assertTrue(Application.getPropFile().endsWith(".properties"));
    }

    @Test
    public void init() {
        // app.contextInitialized(null);
    }

    @Test
    public void destroy() {
        app.contextDestroyed(null);
    }
}

@@ -451,16 +451,53 @@
 Config;%0A
+import com.rant.objects.AppFirewall;%0A
 import c
@@ -522,16 +522,16 @@
 tabase;%0A
-
 %0A/**%0A * 
@@ -977,16 +977,19 @@
 tion.set
+App
 Config(c
@@ -1033,16 +1033,19 @@
 tion.get
+App
 Config()
@@ -1282,16 +1282,16 @@
 true%22);%0A
-
         
@@ -1340,32 +1340,311 @@
 (%22test%22));%0A    %7D
+%0A    %0A    @Test%0A    public void firewall() %7B%0A%0A        AppFirewall fw = new AppFirewall();%0A        fw.setEnabled(true);%0A        Application.setAppFirewall(fw);%0A        assertNotNull(Application.getAppFirewall());%0A        assertTrue(Application.getAppFirewall().isEnabled());%0A    %7D
 %0A%0A    @Test%0A    

Fix firewall tests