| /** |
| * Copyright (c) 2014 Codetrails GmbH. |
| * 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 |
| * |
| * Contributors: |
| * Daniel Haftstein - initial tests. |
| */ |
| package org.eclipse.epp.internal.logging.aeri.ide; |
| |
| import static org.eclipse.epp.logging.aeri.core.IModelPackage.Literals.SYSTEM_SETTINGS__SEND_MODE; |
| import static org.eclipse.epp.logging.aeri.core.ResetSendMode.HOURS_24; |
| import static org.eclipse.epp.logging.aeri.core.SendMode.*; |
| import static org.hamcrest.Matchers.*; |
| import static org.junit.Assert.assertThat; |
| |
| import org.eclipse.core.runtime.preferences.InstanceScope; |
| import org.eclipse.epp.internal.logging.aeri.ide.utils.IDEConstants; |
| import org.eclipse.epp.logging.aeri.core.IModelFactory; |
| import org.eclipse.epp.logging.aeri.core.ISystemSettings; |
| import org.eclipse.epp.logging.aeri.core.SystemControl; |
| import org.eclipse.ui.preferences.ScopedPreferenceStore; |
| import org.junit.Before; |
| import org.junit.Ignore; |
| import org.junit.Test; |
| |
| public class PreferencesAndSettingsTest { |
| |
| private ISystemSettings settings; |
| private ScopedPreferenceStore store; |
| |
| @Before |
| public void setUp() { |
| settings = SystemControl.getSystemSettings(); |
| store = new ScopedPreferenceStore(InstanceScope.INSTANCE, IDEConstants.BUNDLE_ID); |
| } |
| |
| @Test |
| public void testDefaultActions() { |
| ISystemSettings settings = IModelFactory.eINSTANCE.createSystemSettings(); |
| assertThat(settings.getSendMode(), is(NOTIFY)); |
| assertThat(settings.getResetSendMode(), is(HOURS_24)); |
| } |
| |
| @Test |
| @Ignore |
| public void testSettingsUpdateStore() { |
| String prefValue = "any other value"; |
| String prefKey = SYSTEM_SETTINGS__SEND_MODE.getName(); |
| store.putValue(prefKey, prefValue); |
| settings.setSendMode(NEVER); |
| |
| String actual = store.getString(prefKey); |
| assertThat(actual, not(is(prefValue))); |
| } |
| |
| @Test |
| @Ignore |
| public void testStoreUpdateSettings() { |
| settings.setSendMode(BACKGROUND); |
| store.setValue(SYSTEM_SETTINGS__SEND_MODE.getName(), NEVER.name()); |
| assertThat(settings.getSendMode(), is(NEVER)); |
| } |
| |
| @Test |
| public void test24hReset() throws Exception { |
| settings.setSendMode(NEVER); |
| settings.setResetSendMode(HOURS_24); |
| settings.setResetSendModeOn(System.currentTimeMillis() + 300); |
| |
| // time not elapsed |
| assertThat(SystemControl.isActive(), is(false)); |
| assertThat(settings.getSendMode(), is(NEVER)); |
| |
| // now wait for reset-time |
| Thread.sleep(500); |
| assertThat(SystemControl.isActive(), is(true)); |
| assertThat(settings.getSendMode(), is(NOTIFY)); |
| } |
| } |