<commit_before>/*******************************************************************************
 * Copyright (c) 2017 Eurotech and/or its affiliates and others
 *
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   which accompanies this distribution, and is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.eclipse.kura.internal.wire;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

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

import org.eclipse.kura.wire.WireConfiguration;
import org.junit.Test;

public class WireServiceOptionsTest {

    @Test
    public void testGetInstanceEmpty() {
        Map<String, Object> properties = new HashMap<String, Object>();

        WireServiceOptions options = WireServiceOptions.getInstance(properties);

        assertNotNull(options.getWireConfigurations());
        assertEquals(0, options.getWireConfigurations().size());
    }

    @Test
    public void testGetInstanceNoSeparator() {
        Map<String, Object> properties = new HashMap<String, Object>();

        properties.put("testKey", "testValue");

        WireServiceOptions options = WireServiceOptions.getInstance(properties);

        assertNotNull(options.getWireConfigurations());
        assertEquals(0, options.getWireConfigurations().size());
    }

    @Test
    public void testGetInstancePartialSeparator() {
        Map<String, Object> properties = new HashMap<String, Object>();

        properties.put("1.emitter", "emitterPid");
        properties.put("1.receiver", "receiverPid");
        properties.put("1filter", "filter");

        WireServiceOptions options = WireServiceOptions.getInstance(properties);

        List<WireConfiguration> configurations = options.getWireConfigurations();
        assertNotNull(configurations);
        assertEquals(1, configurations.size());
        WireConfiguration cfg = configurations.get(0);
        assertEquals("emitterPid", cfg.getEmitterPid());
        assertEquals("receiverPid", cfg.getReceiverPid());
        assertNull(cfg.getFilter());
    }

    @Test
    public void testGetInstance() {
        Map<String, Object> properties = new HashMap<String, Object>();

        properties.put("1.emitter", "emitterPid");
        properties.put("1.receiver", "receiverPid");
        properties.put("1.filter", "filter");<commit_msg>account for localized property keys<commit_after>/*******************************************************************************
 * Copyright (c) 2017 Eurotech and/or its affiliates and others
 *
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   which accompanies this distribution, and is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.eclipse.kura.internal.wire;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

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

import org.eclipse.kura.localization.LocalizationAdapter;
import org.eclipse.kura.localization.resources.WireMessages;
import org.eclipse.kura.wire.WireConfiguration;
import org.junit.Test;

public class WireServiceOptionsTest {

    private static final WireMessages messages = LocalizationAdapter.adapt(WireMessages.class);

    @Test
    public void testGetInstanceEmpty() {
        Map<String, Object> properties = new HashMap<String, Object>();

        WireServiceOptions options = WireServiceOptions.getInstance(properties);

        assertNotNull(options.getWireConfigurations());
        assertEquals(0, options.getWireConfigurations().size());
    }

    @Test
    public void testGetInstanceNoSeparator() {
        Map<String, Object> properties = new HashMap<String, Object>();

        properties.put("testKey", "testValue");

        WireServiceOptions options = WireServiceOptions.getInstance(properties);

        assertNotNull(options.getWireConfigurations());
        assertEquals(0, options.getWireConfigurations().size());
    }

    @Test
    public void testGetInstancePartialSeparator() {
        Map<String, Object> properties = new HashMap<String, Object>();

        properties.put("1." + messages.emitter(), "emitterPid"); // 1.emitter
        properties.put("1." + messages.receiver(), "receiverPid"); // 1.receiver
        properties.put("1filter", "filter");

        WireServiceOptions options = WireServiceOptions.getInstance(properties);

        List<WireConfiguration> configurations = options.getWireConfigurations();
        assertNotNull(configurations);
        assertEquals(1, configurations.size());
        WireConfiguration cfg = configurations.get(0);
        assertEquals("emitterPid", cfg.getEmitterPid());
        assertEquals("receiverPid", cfg.getReceiverPid());
        assertNull(cfg.getFilter());
    }

    @Test
    public void testGetInstance() {

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

        properties.put("1." + messages.emitter(), "emitterPid"); // 1.emitter
        properties.put("1." + messages.receiver(), "receiverPid"); // 1.receiver
        properties.put("1." + messages.filter(), "filter"); // 1.filter
{'fraction_non_alphanumeric': 0.16580310880829016, 'fraction_numerical': 0.007325352867607647, 'mean_word_length': 4.112328767123287, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2503994', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1350, 'n_words': 317}