package org.ovirt.engine.core.dal.dbbroker.generic;

import java.lang.reflect.Field;

import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;

import org.ovirt.engine.core.common.config.Config;
import org.ovirt.engine.core.common.config.ConfigValues;
import org.ovirt.engine.core.common.config.OptionBehaviour;
import org.ovirt.engine.core.common.config.OptionBehaviourAttribute;
import org.ovirt.engine.core.common.config.TypeConverterAttribute;

public class DBConfigUtilsTest {
    private DBConfigUtils config;

    @Before
    public void setup() {
        config = new DBConfigUtils(false);
    }

    @Test
    public void testDefaultValues() {
        ConfigValues[] values = ConfigValues.values();

        for (ConfigValues curConfig : values) {
            if (curConfig == ConfigValues.Invalid)
                continue;

            Field configField = null;
            try {
                configField = ConfigValues.class.getField(curConfig.name());
            } catch (Exception e) {
                Assert.fail("Failed to look up" + curConfig.name());
                e.printStackTrace();
            }

            OptionBehaviourAttribute behaviourAttr = configField.getAnnotation(OptionBehaviourAttribute.class);
            if (behaviourAttr != null
                    && (behaviourAttr.behaviour() == OptionBehaviour.Password ||
                            behaviourAttr.behaviour() == OptionBehaviour.DomainsPasswordMap)) {
                continue; // no cert available for password decrypt
            }

            TypeConverterAttribute typeAttr = configField.getAnnotation(TypeConverterAttribute.class);
            Class<?> c = typeAttr.value();

            Object obj = config.GetValue(curConfig, Config.DefaultConfigurationVersion);

            Assert.assertTrue("null return for " + curConfig.name(), obj != null);
            Assert.assertTrue(
                    curConfig.name() + " is a " + obj.getClass().getName() + " but should be a " + c.getName(),
                    c.isInstance(obj));
        }
    }
}

@@ -46,16 +46,63 @@
 neric;%0A%0A
+import static org.junit.Assert.assertNotNull;%0A%0A
 import j
@@ -143,22 +143,22 @@
 g.junit.
-Before
+Assert
 ;%0Aimport
@@ -168,20 +168,22 @@
 g.junit.
-Test
+Before
 ;%0Aimport
@@ -197,17 +197,14 @@
 nit.
-Asser
+Tes
 t;%0A
-%0A
 impo
@@ -1685,32 +1685,212 @@
 tribute.class);%0A
+            assertNotNull(%22The following field is missing the %22 + TypeConverterAttribute.class.getSimpleName()%0A                    + %22 annotation: %22 + curConfig.name(), typeAttr);%0A
             Clas

Improve unit-test output for ConfigValues