package com.specmate.connectors.test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;

import org.junit.Test;
import org.mockito.Mockito;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.log.LogService;

import com.specmate.common.SpecmateException;
import com.specmate.common.SpecmateValidationException;
import com.specmate.config.api.IConfigService;
import com.specmate.connectors.internal.config.ConnectorServiceConfig;

public class ConnectorServiceTest {

	@Test
	public void testConnectorServiceDisabling()
			throws SpecmateException, SpecmateValidationException, InterruptedException {
		ConnectorServiceConfig connectorConfig = new ConnectorServiceConfig();
		connectorConfig.setLogService(mock(LogService.class));

		IConfigService configServiceMock = mock(IConfigService.class);
		when(configServiceMock.getConfigurationProperty(ConnectorServiceConfig.KEY_POLL_TIME, "20")).thenReturn("-1");
		connectorConfig.setConfigurationService(configServiceMock);

		ConfigurationAdmin configAdminMock = mock(ConfigurationAdmin.class);
		connectorConfig.setConfigurationAdmin(configAdminMock);

		connectorConfig.configureConnectorService();

		verifyZeroInteractions(configAdminMock);
	}

	@Test
	public void testConnectorServiceEnabling()
			throws SpecmateException, SpecmateValidationException, InterruptedException {
		ConnectorServiceConfig connectorConfig = new ConnectorServiceConfig();
		connectorConfig.setLogService(mock(LogService.class));

		IConfigService configServiceMock = mock(IConfigService.class);
		when(configServiceMock.getConfigurationProperty(ConnectorServiceConfig.KEY_POLL_TIME, "20")).thenReturn("20");
		connectorConfig.setConfigurationService(configServiceMock);

		ConfigurationAdmin configAdminMock = mock(ConfigurationAdmin.class);
		connectorConfig.setConfigurationAdmin(configAdminMock);

		connectorConfig.configureConnectorService();

		verify(configAdminMock, Mockito.atLeastOnce());
	}
}

@@ -231,51 +231,155 @@
 ort 
-org.junit.Test;%0D%0Aimport org.mockito.Mockito
+java.io.IOException;%0D%0Aimport java.util.Dictionary;%0D%0A%0D%0Aimport org.junit.Test;%0D%0Aimport org.mockito.Mockito;%0D%0Aimport org.osgi.service.cm.Configuration
 ;%0D%0Ai
@@ -1604,32 +1604,45 @@
 rruptedException
+, IOException
  %7B%0D%0A%09%09ConnectorS
@@ -2072,32 +2072,196 @@
 nAdmin.class);%0D%0A
+%09%09Configuration configurationMock = mock(Configuration.class);%0D%0A%09%09when(configAdminMock.getConfiguration(Mockito.any(String.class))).thenReturn(configurationMock);%0D%0A
 %09%09connectorConfi
@@ -2366,28 +2366,30 @@
 erify(config
-Admi
+uratio
 nMock, Mocki
@@ -2405,16 +2405,54 @@
 tOnce())
+.update(Mockito.any(Dictionary.class))
 ;%0D%0A%09%7D%0D%0A%7D

fix connectors service unit tests