/** * Copyright (c) 2012 - 2018 Data In Motion Consulting. * 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: * Data In Motion Consulting - initial API and implementation */ package org.gecko.runtime.tests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import org.gecko.core.api.GeckoConstants; import org.gecko.core.resources.ResourceConstants; import org.gecko.core.tests.AbstractOSGiTest; import org.gecko.core.tests.ServiceChecker; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; /** * Integration test to test handling of the folder watcher in OSGi environments * @author Mark Hoffmann * */ @RunWith(MockitoJUnitRunner.class) public class ConfigIntegrationTest extends AbstractOSGiTest { public ConfigIntegrationTest() { super(FrameworkUtil.getBundle(ConfigIntegrationTest.class).getBundleContext()); } private File configFolder; @Override public void doBefore() { String tmp = System.getProperty(GeckoConstants.PROP_GECKO_CONFIG_DIR); configFolder = new File(tmp); if (!configFolder.exists()) { configFolder.mkdirs(); } assertTrue(configFolder.exists()); } @Override public void doAfter() { assertTrue(configFolder.exists()); if (configFolder.listFiles().length > 0) { for (File f : configFolder.listFiles()) { assertTrue(f.delete()); } } assertTrue(configFolder.delete()); } @Test public void testConfigFolderExists() throws InvalidSyntaxException { ServiceChecker configFileChecker = createTrackedChecker("(" + ResourceConstants.RESOURCE_FILE + "=true)", false); createTrackedChecker("(" + GeckoConstants.PROP_GECKO_CONFIG_DIR + "=true)", true).assertCreations(1, true); assertEquals(0, configFolder.listFiles().length); configFileChecker.assertCreations(0, true); } @Test public void testConfigFolderAddFile() throws InvalidSyntaxException, IOException { ServiceChecker configFileChecker = createTrackedChecker("(&(" + ResourceConstants.RESOURCE_FILE + "=true)(" + ResourceConstants.RESOURCE_FILE_NAME + "=test.conf))", false); ServiceChecker configUrlChecker = createTrackedChecker("(" + GeckoConstants.PROP_GECKO_CONFIG_DIR + "=true)", true); configUrlChecker.assertCreations(1, false); assertEquals(0, configFolder.listFiles().length); configFileChecker.assertCreations(0, false); File test = new File(configFolder, "test.conf"); assertTrue(test.createNewFile()); configFileChecker.assertCreations(1, true); assertTrue(test.delete()); configFileChecker.assertCreations(1, false).assertRemovals(1, true).immediate(true); } }