<commit_before>/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2011 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2011 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <<EMAIL>>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

package org.opennms.netmgt;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.opennms.test.mock.MockLogAppender;

@RunWith(Parameterized.class)
public class EventConstantsTest {

    // Test Parameters
    private Locale m_testLocale;
    private String m_gmtText;
    private String m_cetText;
    private Long m_timestamp;

    @Parameters
    public static Collection<Object[]> data() {
            return Arrays.asList(new Object[][] {
                            {
                                new Locale("en", "US"),
                                "Thursday, March 10, 2011 10:40:37 PM GMT",
                                "Thursday, March 10, 2011 11:40:37 PM CET",
                                Long.valueOf(1299796837 * 1000L)
                            },
                            {
                                new Locale("it", "IT"),
                                "gioved\u00EC 10 marzo 2011 22.40.37 GMT",
                                "gioved\u00EC 10 marzo 2011 23.40.37 CET",
                                Long.valueOf(1299796837 * 1000L)
                            },
                            {
                                new Locale("fr", "FR"),
                                "jeudi 10 mars 2011 22:40:37 GMT",
                                "jeudi 10 mars 2011 23:40:37 CET",
                                Long.valueOf(1299796837 * 1000L)
                            },
                            {
                                new Locale("de", "DE"),
                                "Donnerstag, 10. M\u00E4rz 2011 22:40:37 GMT",
                                "Donnerstag, 10. M\u00E4rz 2011 23:40:37 MEZ",
                                Long.valueOf(1299796837 * 1000L)
                            }
            });
    }

    public EventConstantsTest(final Locale locale, final String gmtText, final String cetText, final Long timestamp) {
        m_testLocale = locale;
        m_gmtText = gmtText;
        m_cetText = cetText;
        m_timestamp = timestamp;
    }

    // Initialized Inside the Tests
    private Locale m_defaultLocale;

    @Before
    public void setUp() {
        MockLogAppender.setupLogging();

        m_defaultLocale = Locale.getDefault();
        TimeZone.setDefault(TimeZone.getTimeZone("CET"));
        Locale.setDefault(m_testLocale);
        
        // since formatters are thread-local, we need to reset them so they will re-initialize based on the current locale
        EventConstants.FORMATTER_FULL.remove();
        EventConstants.FORMATTER_LONG.remove();
        EventConstants.FORMATTER_FULL_GMT.remove();
        EventConstants.FORMATTER_LONG_GMT.remove();
        EventConstants.FORMATTER_CUSTOM.remove();
        EventConstants.FORMATTER_DEFAULT.remove();
    }

    @After
    public void tearDown() {
        Locale.setDefault(m_defaultLocale);
    }

    @Test
    public void testEventDateParse() throws Exception {
        final Date date = EventConstants.parseToDate(m_cetText);
        assertEquals(m_testLocale + ": time should equal " + m_timestamp, m_timestamp.longValue(), date.getTime());
    }

    @Test
    public void testFormatToString() throws Exception {
        final String formatted = EventConstants.formatToString(new Date(m_timestamp));
        assertEquals(m_testLocale + ": formatted string should equal " + m_gmtText, m_gmtText, formatted);
    }
}
<commit_msg>NMS-4810 store and restore time zones as well<commit_after>/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2011 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2011 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <<EMAIL>>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

package org.opennms.netmgt;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.opennms.test.mock.MockLogAppender;

@RunWith(Parameterized.class)
public class EventConstantsTest {

    // Test Parameters
    private Locale m_testLocale;
    private TimeZone m_testTimeZone;
    private String m_gmtText;
    private String m_zoneText;
    private Long m_timestamp;

    @Parameters
    public static Collection<Object[]> data() {
            return Arrays.asList(new Object[][] {
                            {
                                new Locale("en", "US"),
                                TimeZone.getTimeZone("CET"),
                                "Thursday, March 10, 2011 10:40:37 PM GMT",
                                "Thursday, March 10, 2011 11:40:37 PM CET",
                                Long.valueOf(1299796837 * 1000L)
                            },
                            {
                                new Locale("it", "IT"),
                                TimeZone.getTimeZone("CET"),
                                "gioved\u00EC 10 marzo 2011 22.40.37 GMT",
                                "gioved\u00EC 10 marzo 2011 23.40.37 CET",
                                Long.valueOf(1299796837 * 1000L)
                            },
                            {
                                new Locale("fr", "FR"),
                                TimeZone.getTimeZone("CET"),
                                "jeudi 10 mars 2011 22:40:37 GMT",
                                "jeudi 10 mars 2011 23:40:37 CET",
                                Long.valueOf(1299796837 * 1000L)
                            },
                            {
                                new Locale("de", "DE"),
                                TimeZone.getTimeZone("CET"),
                                "Donnerstag, 10. M\u00E4rz 2011 22:40:37 GMT",
                                "Donnerstag, 10. M\u00E4rz 2011 23:40:37 MEZ",
                                Long.valueOf(1299796837 * 1000L)
                            }
            });
    }

    public EventConstantsTest(final Locale locale, final TimeZone timeZone, final String gmtText, final String zoneText, final Long timestamp) {
        m_testLocale = locale;
        m_testTimeZone = timeZone;
        m_gmtText = gmtText;
        m_zoneText = zoneText;
        m_timestamp = timestamp;
    }

    // Initialized Inside the Tests
    private Locale m_defaultLocale;
    private TimeZone m_defaultTimeZone;

    @Before
    public void setUp() {
        MockLogAppender.setupLogging();

        m_defaultLocale = Locale.getDefault();
        m_defaultTimeZone = TimeZone.getDefault();
        Locale.setDefault(m_testLocale);
        TimeZone.setDefault(m_testTimeZone);
        
        // since formatters are thread-local, we need to reset them so they will re-initialize based on the current locale
        EventConstants.FORMATTER_FULL.remove();
        EventConstants.FORMATTER_LONG.remove();
        EventConstants.FORMATTER_FULL_GMT.remove();
        EventConstants.FORMATTER_LONG_GMT.remove();
        EventConstants.FORMATTER_CUSTOM.remove();
        EventConstants.FORMATTER_DEFAULT.remove();
    }

    @After
    public void tearDown() {
        Locale.setDefault(m_defaultLocale);
        TimeZone.setDefault(m_defaultTimeZone);
    }

    @Test
    public void testEventDateParse() throws Exception {
        final Date date = EventConstants.parseToDate(m_zoneText);
        assertEquals(m_testLocale + ": time should equal " + m_timestamp, m_timestamp.longValue(), date.getTime());
    }

    @Test
    public void testFormatToString() throws Exception {
        final String formatted = EventConstants.formatToString(new Date(m_timestamp));
        assertEquals(m_testLocale + ": formatted string should equal " + m_gmtText, m_gmtText, formatted);
    }
}

{'fraction_non_alphanumeric': 0.11558567279767668, 'fraction_numerical': 0.03426911907066796, 'mean_word_length': 1.9910248986682109, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347299', 'n_tokens_mistral': 3059, 'n_tokens_neox': 2711, 'n_words': 755}