Search code examples
javaormlitegriffon

Griffon Ormlite plugin configuration not picking up environment settings


For my griffon desktop client application I'm trying to write some tests involving OrmLite. I have configured OrmLite with a java configuration file using the configuration section of the griffon-ormlite plugin guide. What I'm trying to do is configure OrmLite to use a different (blank) database during testing. However the application is not picking up the test configuration and is instead loading the default setting.

Things to note:

  • specifying the configuration in exactly the same way as in src/main/resources/Ormlite.groovy in the configuration guide (link above) will cause the plugin to complain about a missing "default.url" setting. So either the example is wrong (it may be outdated, but that's unlikely) or I'm missing something regarding the environments (are the configurations being transformed before they are being read? I have not found any documentation on this).
  • The application environment enum, is correctly resulting in Environment.TEST during testing and Environment.DEVELOPMENT during a run.
  • versions: griffon 2.9.1, griffon-ormlite 1.1.0

Here's the configuration file:

import java.util.Map;

import griffon.util.AbstractMapResourceBundle;

import static griffon.util.CollectionUtils.map;

public class Ormlite extends AbstractMapResourceBundle {
    @Override
    protected void initialize(Map<String, Object> entries) {
        map(entries)
            // the default database setting
            .e("database", map()
                .e("url", "jdbc:h2:internal")
            )
            .e("environments", map()
                .e("test", map()
                    // the database that should be used during testing, but is not being picked up
                    .e("database", map()
                        .e("url", "jdbc:h2:mem:internal-test")
                    )
                )
            );
    }
}

Any help is extremely appreciated.


Solution

  • I'm afraid the problem lies in that class based ResourceBundles do not offer support for the environments block (or any other conditional block for that matter) just like the Groovy scripts do. We recently added this kind of support to Properties files (see https://github.com/griffon/griffon/issues/196); leaving us with the need to add the same for class based bundles.

    If you can, switch to Groovy script configuration as a workaround, make sure to add griffon-groovy as a project dependency. this will add at least ~7M worth of dependencies.

    I've filed https://github.com/griffon/griffon/issues/212 to keep track of this feature.