<commit_before>package com.oculusinfo.tile.rest.config;

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

import java.io.File;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertNotNull;

public class ConfigServiceTests {

    protected ConfigServiceImpl _configService;

    @Before
    public void setUp() throws Exception {
        _configService = new ConfigServiceImpl();
        String pathToProperties = this.getClass().getClassLoader().getResource("config-service-unit-test.properties").toURI().getPath();
        Map<String,String> newEnv = new HashMap<>();
        newEnv.put("TILE_CONFIG_PROPERTIES", pathToProperties);
        setEnv(newEnv);
    }

    @Test
    public void testReplaceProperties() throws Exception {
        File configFile = new File(this.getClass().getClassLoader().getResource("config-service-unit-test.json").toURI());
        String result = _configService.replaceProperties(configFile);
        System.out.println(result);
        assertNotNull(result);
    }

    // ONLY FOR UNIT TESTING
    // http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java
    private void setEnv(Map<String, String> newenv) {
        try {
            Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
            Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
            theEnvironmentField.setAccessible(true);<commit_msg>unit test happy path for properties replacement<commit_after>package com.oculusinfo.tile.rest.config;

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

import java.io.File;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertTrue;

public class ConfigServiceTests {

    protected ConfigServiceImpl _configService;

    @Before
    public void setUp() throws Exception {
        _configService = new ConfigServiceImpl();
        String pathToProperties = this.getClass().getClassLoader().getResource("config-service-unit-test.properties").toURI().getPath();
        Map<String,String> newEnv = new HashMap<>();
        newEnv.put("TILE_CONFIG_PROPERTIES", pathToProperties);
        setEnv(newEnv);
    }

    @Test
    public void testReplaceProperties() throws Exception {
        File configFile = new File(this.getClass().getClassLoader().getResource("config-service-unit-test.json").toURI());
        String replaced = _configService.replaceProperties(configFile);
        assertTrue(replaced.contains("\"foo.zookeeper.quorum\": \"bar.test.local\""));
        assertTrue(replaced.contains("\"foo.zookeeper.port\": \"2222\""));
        assertTrue(replaced.contains("\"foo.master\": \"bar.test.local:33333\""));
    }

    // ONLY FOR UNIT TESTING
    // http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java
    private void setEnv(Map<String, String> newenv) {
        try {
            Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
            Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
            theEnvironmentField.setAccessible(true);
{'fraction_non_alphanumeric': 0.12215822976659593, 'fraction_numerical': 0.006365565322825098, 'mean_word_length': 3.831625183016105, 'pattern_counts': {'":': 3, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6081712', 'n_tokens_mistral': 911, 'n_tokens_neox': 894, 'n_words': 163}