package com.stevesoltys.owl.config;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author Steve Soltys
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class OwlConfigurationTests {

    @Autowired
    private OwlConfiguration owlConfiguration;

    /**
     * Tests failing of {@link OwlConfiguration#initialize(Map)} when the given configuration is invalid.
     */
    @Test(expected = Exception.class)
    public void testInvalidConfiguration() throws Exception {
        Map<String, Object> configuration = new HashMap<>();
        configuration.put("wrong", "config");

        owlConfiguration.initialize(configuration);
    }

    /**
     * Tests {@link OwlConfiguration#initialize(Map)} when the configuration is valid.
     */
    @Test
    public void testValidConfiguration() throws Exception {

        Map<String, Object> configuration = new HashMap<>();

        configuration.put("agent", true);

        List<Map<String, String>> componentTypeList = new LinkedList<>();

        Map<String, String> componentType = new HashMap<>();
        componentType.put("identifier", "cpu_load");
        componentType.put("classpath", "com.stevesoltys.owl.model.component.CPULoadComponent");
        componentType.put("controller_classpath", "com.stevesoltys.owl.controller.component.CPULoadComponentController");

        componentTypeList.add(componentType);
        configuration.put("component_types", componentTypeList);

        owlConfiguration.initialize(configuration);
    }

}

@@ -1203,24 +1203,46 @@
 shMap%3C%3E();%0A%0A
+        // Agent flag%0A
         conf
@@ -1268,24 +1268,51 @@
 t%22, true);%0A%0A
+        // Component types%0A
         List
@@ -1815,24 +1815,365 @@
 TypeList);%0A%0A
+        // Component instances%0A        List%3CMap%3CString, String%3E%3E components = new LinkedList%3C%3E();%0A        Map%3CString, String%3E component = new HashMap%3C%3E();%0A        component.put(%22identifier%22, %22cpu_load%22);%0A        component.put(%22update_interval%22, %221%22);%0A        components.add(component);%0A%0A        configuration.put(%22components%22, components);%0A%0A
         owlC

Update OwlConfigurationTests