alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (ConfigurationTest.java)

This example Play Framework source code file (ConfigurationTest.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

config, configuration, configurationtest, configvalue, list, override, play, play framework, string, test

The ConfigurationTest.java Play Framework example source code

/*
 * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
 */
package play;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValue;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;

public class ConfigurationTest {

    @Test
    public void beAccessibleAsAMap() {
        assertThat(exampleConfig().asMap()).hasSize(2).includes(
                entry("foo", ImmutableMap.of("bar1", "value1", "bar2", "value2")),
                entry("blah", "value3"));
    }

    @Test
    public void beAccessibleAsAnEntrySet() {
        Set<Map.Entry<String, ConfigValue>> entrySet = exampleConfig().entrySet();
        assertThat(entrySet).hasSize(3);
        List<String> keys = Lists.transform(Lists.newArrayList(entrySet), new Function<Map.Entry<String, ConfigValue>, String>() {
            @Override
            public String apply(Map.Entry<String, ConfigValue> input) {
                return input.getKey();
            }
        });
        assertThat(keys).containsOnly("foo.bar1", "foo.bar2", "blah");
    }

    @Test
    public void makesUnderlyingAccessible() {
        Config underlying
            = ConfigFactory.parseMap(ImmutableMap.of("foo.bar1", "value1"));
        Configuration config = new Configuration(underlying);
        Assert.assertEquals(underlying, config.underlying());
    }

    public Configuration exampleConfig() {
        return new Configuration(ConfigFactory.parseMap(ImmutableMap.of("foo.bar1", "value1",
                "foo.bar2", "value2",
                "blah", "value3")));
    }
}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework ConfigurationTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.