mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Use constructor injection and update null annotations (#1487)
* Use constructor injection and update null annotations Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
+3
-2
@@ -40,6 +40,7 @@ import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.http.HttpContext;
|
||||
import org.osgi.service.http.HttpService;
|
||||
|
||||
/**
|
||||
@@ -61,8 +62,8 @@ public class AudioServlet extends SmartHomeServlet implements AudioHTTPServer {
|
||||
private final Map<String, Long> streamTimeouts = new ConcurrentHashMap<>();
|
||||
|
||||
@Activate
|
||||
public AudioServlet(final @Reference HttpService httpService) {
|
||||
this.httpService = httpService;
|
||||
public AudioServlet(final @Reference HttpService httpService, final @Reference HttpContext httpContext) {
|
||||
super(httpService, httpContext);
|
||||
}
|
||||
|
||||
@Activate
|
||||
|
||||
+9
-2
@@ -13,7 +13,7 @@
|
||||
package org.openhab.core.audio.internal;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.mockito.Mock;
|
||||
import org.openhab.core.audio.AudioFormat;
|
||||
import org.openhab.core.audio.AudioStream;
|
||||
import org.openhab.core.audio.ByteArrayAudioStream;
|
||||
@@ -31,6 +32,7 @@ import org.openhab.core.audio.FixedLengthAudioStream;
|
||||
import org.openhab.core.test.TestPortUtil;
|
||||
import org.openhab.core.test.TestServer;
|
||||
import org.openhab.core.test.java.JavaTest;
|
||||
import org.osgi.service.http.HttpContext;
|
||||
import org.osgi.service.http.HttpService;
|
||||
|
||||
/**
|
||||
@@ -52,9 +54,14 @@ public abstract class AbstractAudioServletTest extends JavaTest {
|
||||
|
||||
private HttpClient httpClient;
|
||||
|
||||
private @Mock HttpService httpServiceMock;
|
||||
private @Mock HttpContext httpContextMock;
|
||||
|
||||
@Before
|
||||
public void setupServerAndClient() {
|
||||
audioServlet = new AudioServlet(mock(HttpService.class));
|
||||
initMocks(this);
|
||||
|
||||
audioServlet = new AudioServlet(httpServiceMock, httpContextMock);
|
||||
|
||||
ServletHolder servletHolder = new ServletHolder(audioServlet);
|
||||
|
||||
|
||||
+10
-34
@@ -21,6 +21,7 @@ import org.openhab.core.auth.client.oauth2.OAuthClientService;
|
||||
import org.openhab.core.auth.client.oauth2.OAuthException;
|
||||
import org.openhab.core.auth.client.oauth2.OAuthFactory;
|
||||
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
@@ -40,13 +41,20 @@ public class OAuthFactoryImpl implements OAuthFactory {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(OAuthFactoryImpl.class);
|
||||
|
||||
private @NonNullByDefault({}) OAuthStoreHandler oAuthStoreHandler;
|
||||
private @NonNullByDefault({}) HttpClientFactory httpClientFactory;
|
||||
private final OAuthStoreHandler oAuthStoreHandler;
|
||||
private final HttpClientFactory httpClientFactory;
|
||||
|
||||
private int tokenExpiresInBuffer = OAuthClientServiceImpl.DEFAULT_TOKEN_EXPIRES_IN_BUFFER_SECOND;
|
||||
|
||||
private final Map<String, OAuthClientService> oauthClientServiceCache = new ConcurrentHashMap<>();
|
||||
|
||||
@Activate
|
||||
public OAuthFactoryImpl(final @Reference HttpClientFactory httpClientFactory,
|
||||
final @Reference OAuthStoreHandler oAuthStoreHandler) {
|
||||
this.httpClientFactory = httpClientFactory;
|
||||
this.oAuthStoreHandler = oAuthStoreHandler;
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
// close each service
|
||||
@@ -123,38 +131,6 @@ public class OAuthFactoryImpl implements OAuthFactory {
|
||||
oAuthStoreHandler.remove(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Store handler is mandatory, but the actual storage service is not.
|
||||
* OAuthStoreHandler will handle when storage service is missing.
|
||||
*
|
||||
* Intended static mandatory 1..1 reference
|
||||
*
|
||||
* @param oAuthStoreHandler
|
||||
*/
|
||||
@Reference
|
||||
protected void setOAuthStoreHandler(OAuthStoreHandler oAuthStoreHandler) {
|
||||
this.oAuthStoreHandler = oAuthStoreHandler;
|
||||
}
|
||||
|
||||
protected void unsetOAuthStoreHandler(OAuthStoreHandler oAuthStoreHandler) {
|
||||
this.oAuthStoreHandler = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* HttpClientFactory is mandatory, and is used as a client for
|
||||
* all http(s) communications to the OAuth providers
|
||||
*
|
||||
* @param httpClientFactory
|
||||
*/
|
||||
@Reference
|
||||
protected void setHttpClientFactory(HttpClientFactory httpClientFactory) {
|
||||
this.httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
protected void unsetHttpClientFactory(HttpClientFactory httpClientFactory) {
|
||||
this.httpClientFactory = null;
|
||||
}
|
||||
|
||||
public int getTokenExpiresInBuffer() {
|
||||
return tokenExpiresInBuffer;
|
||||
}
|
||||
|
||||
+6
-11
@@ -79,13 +79,18 @@ public class OAuthStoreHandlerImpl implements OAuthStoreHandler {
|
||||
private static final String STORE_KEY_INDEX_OF_HANDLES = "INDEX_HANDLES";
|
||||
|
||||
private final Set<String> allHandles = new HashSet<>(); // must be initialized
|
||||
private @NonNullByDefault({}) StorageFacade storageFacade;
|
||||
private final StorageFacade storageFacade;
|
||||
|
||||
private final Set<StorageCipher> allAvailableStorageCiphers = new LinkedHashSet<>();
|
||||
private Optional<StorageCipher> storageCipher = Optional.empty();
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(OAuthStoreHandlerImpl.class);
|
||||
|
||||
@Activate
|
||||
public OAuthStoreHandlerImpl(final @Reference StorageService storageService) {
|
||||
storageFacade = new StorageFacade(storageService.getStorage(STORE_NAME));
|
||||
}
|
||||
|
||||
@Activate
|
||||
public void activate(Map<String, Object> properties) throws GeneralSecurityException {
|
||||
// this allows future implementations to change cipher by just setting the CIPHER_TARGET
|
||||
@@ -193,16 +198,6 @@ public class OAuthStoreHandlerImpl implements OAuthStoreHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected synchronized void setStorageService(StorageService storageService) {
|
||||
storageFacade = new StorageFacade(storageService.getStorage(STORE_NAME));
|
||||
}
|
||||
|
||||
protected synchronized void unsetStorageService(StorageService storageService) {
|
||||
storageFacade.close();
|
||||
storageFacade = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static policy -- don't want to change cipher on the fly!
|
||||
* There may be multiple storage ciphers, choose the one that matches the target (done at activate)
|
||||
|
||||
+14
-22
@@ -57,8 +57,8 @@ public class SymmetricKeyCipher implements StorageCipher {
|
||||
private static final int ENCRYPTION_KEY_SIZE_BITS = 128; // do not use high grade encryption due to export limit
|
||||
private static final int IV_BYTE_SIZE = 16;
|
||||
|
||||
private @NonNullByDefault({}) ConfigurationAdmin configurationAdmin;
|
||||
private @NonNullByDefault({}) SecretKey encryptionKey;
|
||||
private final ConfigurationAdmin configurationAdmin;
|
||||
private final SecretKey encryptionKey;
|
||||
|
||||
private final SecureRandom random = new SecureRandom();
|
||||
|
||||
@@ -70,7 +70,9 @@ public class SymmetricKeyCipher implements StorageCipher {
|
||||
* @throws IOException if access to persistent storage fails (@code org.osgi.service.cm.ConfigurationAdmin)
|
||||
*/
|
||||
@Activate
|
||||
public void activate() throws NoSuchAlgorithmException, IOException {
|
||||
public SymmetricKeyCipher(final @Reference ConfigurationAdmin configurationAdmin)
|
||||
throws NoSuchAlgorithmException, IOException {
|
||||
this.configurationAdmin = configurationAdmin;
|
||||
// load or generate the encryption key
|
||||
encryptionKey = getOrGenerateEncryptionKey();
|
||||
}
|
||||
@@ -139,32 +141,22 @@ public class SymmetricKeyCipher implements StorageCipher {
|
||||
}
|
||||
|
||||
if (properties.get(PROPERTY_KEY_ENCRYPTION_KEY_BASE64) == null) {
|
||||
encryptionKey = generateEncryptionKey();
|
||||
encryptionKeyInBase64 = new String(Base64.getEncoder().encode(encryptionKey.getEncoded()));
|
||||
SecretKey secretKey = generateEncryptionKey();
|
||||
encryptionKeyInBase64 = new String(Base64.getEncoder().encode(secretKey.getEncoded()));
|
||||
|
||||
// Put encryption key back into config
|
||||
properties.put(PROPERTY_KEY_ENCRYPTION_KEY_BASE64, encryptionKeyInBase64);
|
||||
configuration.update(properties);
|
||||
|
||||
logger.debug("Encryption key generated");
|
||||
} else {
|
||||
// encryption key already present in config
|
||||
encryptionKeyInBase64 = (String) properties.get(PROPERTY_KEY_ENCRYPTION_KEY_BASE64);
|
||||
byte[] encKeyBytes = Base64.getDecoder().decode(encryptionKeyInBase64);
|
||||
// 128 bit key/ 8 bit = 16 bytes length
|
||||
encryptionKey = new SecretKeySpec(encKeyBytes, 0, ENCRYPTION_KEY_SIZE_BITS / 8, ENCRYPTION_ALGO);
|
||||
|
||||
logger.debug("Encryption key loaded");
|
||||
return secretKey;
|
||||
}
|
||||
return encryptionKey;
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
|
||||
this.configurationAdmin = configurationAdmin;
|
||||
}
|
||||
|
||||
public void unsetConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
|
||||
this.configurationAdmin = configurationAdmin;
|
||||
// encryption key already present in config
|
||||
encryptionKeyInBase64 = (String) properties.get(PROPERTY_KEY_ENCRYPTION_KEY_BASE64);
|
||||
byte[] encKeyBytes = Base64.getDecoder().decode(encryptionKeyInBase64);
|
||||
// 128 bit key/ 8 bit = 16 bytes length
|
||||
logger.debug("Encryption key loaded");
|
||||
return new SecretKeySpec(encKeyBytes, 0, ENCRYPTION_KEY_SIZE_BITS / 8, ENCRYPTION_ALGO);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-10
@@ -35,6 +35,7 @@ import org.openhab.core.config.core.ConfigDescriptionParameter;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameterBuilder;
|
||||
import org.openhab.core.config.core.ParameterOption;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
|
||||
@@ -49,7 +50,12 @@ import org.osgi.service.component.annotations.Reference;
|
||||
@Component(immediate = true)
|
||||
public class MediaActionTypeProvider implements ModuleTypeProvider {
|
||||
|
||||
private @NonNullByDefault({}) AudioManager audioManager;
|
||||
private final AudioManager audioManager;
|
||||
|
||||
@Activate
|
||||
public MediaActionTypeProvider(final @Reference AudioManager audioManager) {
|
||||
this.audioManager = audioManager;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@@ -151,13 +157,4 @@ public class MediaActionTypeProvider implements ModuleTypeProvider {
|
||||
public void removeProviderChangeListener(ProviderChangeListener<ModuleType> listener) {
|
||||
// does nothing because this provider does not change
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setAudioManager(AudioManager audioManager) {
|
||||
this.audioManager = audioManager;
|
||||
}
|
||||
|
||||
protected void unsetAudioManager(AudioManager audioManager) {
|
||||
this.audioManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-10
@@ -26,6 +26,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.module.script.ScriptEngineContainer;
|
||||
import org.openhab.core.automation.module.script.ScriptEngineFactory;
|
||||
import org.openhab.core.automation.module.script.ScriptEngineManager;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
@@ -43,20 +44,16 @@ import org.slf4j.LoggerFactory;
|
||||
public class ScriptEngineManagerImpl implements ScriptEngineManager {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ScriptEngineManagerImpl.class);
|
||||
private final Map<String, @Nullable ScriptEngineContainer> loadedScriptEngineInstances = new HashMap<>();
|
||||
private final Map<String, @Nullable ScriptEngineFactory> customSupport = new HashMap<>();
|
||||
private final Map<String, @Nullable ScriptEngineFactory> genericSupport = new HashMap<>();
|
||||
private @NonNullByDefault({}) ScriptExtensionManager scriptExtensionManager;
|
||||
private final Map<String, ScriptEngineContainer> loadedScriptEngineInstances = new HashMap<>();
|
||||
private final Map<String, ScriptEngineFactory> customSupport = new HashMap<>();
|
||||
private final Map<String, ScriptEngineFactory> genericSupport = new HashMap<>();
|
||||
private final ScriptExtensionManager scriptExtensionManager;
|
||||
|
||||
@Reference
|
||||
public void setScriptExtensionManager(ScriptExtensionManager scriptExtensionManager) {
|
||||
@Activate
|
||||
public ScriptEngineManagerImpl(final @Reference ScriptExtensionManager scriptExtensionManager) {
|
||||
this.scriptExtensionManager = scriptExtensionManager;
|
||||
}
|
||||
|
||||
public void unsetScriptExtensionManager(ScriptExtensionManager scriptExtensionManager) {
|
||||
this.scriptExtensionManager = null;
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
|
||||
public void addScriptEngineFactory(ScriptEngineFactory engineFactory) {
|
||||
List<String> scriptTypes = engineFactory.getScriptTypes();
|
||||
|
||||
+3
-4
@@ -124,20 +124,20 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
*/
|
||||
private final long scheduleReinitializationDelay;
|
||||
|
||||
private final @NonNullByDefault({}) Map<String, WrappedRule> managedRules = new ConcurrentHashMap<>();
|
||||
private final Map<String, WrappedRule> managedRules = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* {@link Map} holding all created {@link TriggerHandlerCallback} instances, corresponding to each {@link Rule}.
|
||||
* There is only one {@link TriggerHandlerCallback} instance per {@link Rule}. The relation is
|
||||
* {@link Rule}'s UID to {@link TriggerHandlerCallback} instance.
|
||||
*/
|
||||
private final @NonNullByDefault({}) Map<String, TriggerHandlerCallbackImpl> thCallbacks = new HashMap<>();
|
||||
private final Map<String, TriggerHandlerCallbackImpl> thCallbacks = new HashMap<>();
|
||||
|
||||
/**
|
||||
* {@link Map} holding all {@link ModuleType} UIDs that are available in some rule's module definition. The relation
|
||||
* is {@link ModuleType}'s UID to {@link Set} of {@link Rule} UIDs.
|
||||
*/
|
||||
private final @NonNullByDefault({}) Map<String, Set<String>> mapModuleTypeToRules = new HashMap<>();
|
||||
private final Map<String, Set<String>> mapModuleTypeToRules = new HashMap<>();
|
||||
|
||||
/**
|
||||
* {@link Map} holding all available {@link ModuleHandlerFactory}s linked with {@link ModuleType}s that they
|
||||
@@ -1095,7 +1095,6 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
* @return copy of current context in rule engine
|
||||
*/
|
||||
private Map<String, Object> getContext(String ruleUID, @Nullable Set<Connection> connections) {
|
||||
@NonNullByDefault({})
|
||||
Map<String, Object> context = contextMap.get(ruleUID);
|
||||
if (context == null) {
|
||||
context = new HashMap<>();
|
||||
|
||||
+8
-8
@@ -43,16 +43,16 @@ import org.openhab.core.config.core.Configuration;
|
||||
@NonNullByDefault
|
||||
public class RuleImpl implements Rule {
|
||||
|
||||
protected @NonNullByDefault({}) List<Trigger> triggers;
|
||||
protected @NonNullByDefault({}) List<Condition> conditions;
|
||||
protected @NonNullByDefault({}) List<Action> actions;
|
||||
protected @NonNullByDefault({}) Configuration configuration;
|
||||
protected @NonNullByDefault({}) List<ConfigDescriptionParameter> configDescriptions;
|
||||
protected List<Trigger> triggers;
|
||||
protected List<Condition> conditions;
|
||||
protected List<Action> actions;
|
||||
protected Configuration configuration;
|
||||
protected List<ConfigDescriptionParameter> configDescriptions;
|
||||
protected @Nullable String templateUID;
|
||||
protected @NonNullByDefault({}) String uid;
|
||||
protected String uid;
|
||||
protected @Nullable String name;
|
||||
protected @NonNullByDefault({}) Set<String> tags;
|
||||
protected @NonNullByDefault({}) Visibility visibility;
|
||||
protected Set<String> tags;
|
||||
protected Visibility visibility;
|
||||
protected @Nullable String description;
|
||||
|
||||
/**
|
||||
|
||||
+7
-10
@@ -40,6 +40,7 @@ import org.openhab.core.common.registry.ProviderChangeListener;
|
||||
import org.openhab.core.config.core.ConfigConstants;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
@@ -60,7 +61,12 @@ public class AnnotatedActionModuleTypeProvider extends BaseModuleHandlerFactory
|
||||
private final Map<String, Set<ModuleInformation>> moduleInformation = new ConcurrentHashMap<>();
|
||||
private final AnnotationActionModuleTypeHelper helper = new AnnotationActionModuleTypeHelper();
|
||||
|
||||
private @NonNullByDefault({}) ModuleTypeI18nService moduleTypeI18nService;
|
||||
private final ModuleTypeI18nService moduleTypeI18nService;
|
||||
|
||||
@Activate
|
||||
public AnnotatedActionModuleTypeProvider(final @Reference ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = moduleTypeI18nService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deactivate
|
||||
@@ -220,13 +226,4 @@ public class AnnotatedActionModuleTypeProvider extends BaseModuleHandlerFactory
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setModuleTypeI18nService(ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = moduleTypeI18nService;
|
||||
}
|
||||
|
||||
protected void unsetModuleTypeI18nService(ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = null;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-11
@@ -56,7 +56,7 @@ import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
public class ModuleTypeResourceBundleProvider extends AbstractResourceBundleProvider<ModuleType>
|
||||
implements ModuleTypeProvider {
|
||||
|
||||
private @NonNullByDefault({}) ModuleTypeI18nService moduleTypeI18nService;
|
||||
private final ModuleTypeI18nService moduleTypeI18nService;
|
||||
|
||||
/**
|
||||
* This constructor is responsible for initializing the path to resources and tracking the
|
||||
@@ -64,8 +64,10 @@ public class ModuleTypeResourceBundleProvider extends AbstractResourceBundleProv
|
||||
*
|
||||
* @param context is the {@code BundleContext}, used for creating a tracker for {@link Parser} services.
|
||||
*/
|
||||
public ModuleTypeResourceBundleProvider() {
|
||||
@Activate
|
||||
public ModuleTypeResourceBundleProvider(final @Reference ModuleTypeI18nService moduleTypeI18nService) {
|
||||
super(ROOT_DIRECTORY + "/moduletypes/");
|
||||
this.moduleTypeI18nService = moduleTypeI18nService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,13 +152,4 @@ public class ModuleTypeResourceBundleProvider extends AbstractResourceBundleProv
|
||||
|
||||
return bundle != null ? moduleTypeI18nService.getModuleTypePerLocale(defModuleType, locale, bundle) : null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setModuleTypeI18nService(ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = moduleTypeI18nService;
|
||||
}
|
||||
|
||||
protected void unsetModuleTypeI18nService(ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = null;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-21
@@ -41,6 +41,7 @@ import org.openhab.core.thing.binding.ThingActionsScope;
|
||||
import org.openhab.core.thing.binding.ThingHandler;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
@@ -59,7 +60,12 @@ public class AnnotatedThingActionModuleTypeProvider extends BaseModuleHandlerFac
|
||||
private final Map<String, Set<ModuleInformation>> moduleInformation = new ConcurrentHashMap<>();
|
||||
private final AnnotationActionModuleTypeHelper helper = new AnnotationActionModuleTypeHelper();
|
||||
|
||||
private @NonNullByDefault({}) ModuleTypeI18nService moduleTypeI18nService;
|
||||
private final ModuleTypeI18nService moduleTypeI18nService;
|
||||
|
||||
@Activate
|
||||
public AnnotatedThingActionModuleTypeProvider(final @Reference ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = moduleTypeI18nService;
|
||||
}
|
||||
|
||||
@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE)
|
||||
public void addAnnotatedThingActions(ThingActions annotatedThingActions) {
|
||||
@@ -74,17 +80,17 @@ public class AnnotatedThingActionModuleTypeProvider extends BaseModuleHandlerFac
|
||||
mi.setThingUID(thingUID);
|
||||
|
||||
ModuleType oldType = null;
|
||||
if (this.moduleInformation.containsKey(mi.getUID())) {
|
||||
oldType = helper.buildModuleType(mi.getUID(), this.moduleInformation);
|
||||
Set<ModuleInformation> availableModuleConfigs = this.moduleInformation.get(mi.getUID());
|
||||
if (moduleInformation.containsKey(mi.getUID())) {
|
||||
oldType = helper.buildModuleType(mi.getUID(), moduleInformation);
|
||||
Set<ModuleInformation> availableModuleConfigs = moduleInformation.get(mi.getUID());
|
||||
availableModuleConfigs.add(mi);
|
||||
} else {
|
||||
Set<ModuleInformation> configs = ConcurrentHashMap.newKeySet();
|
||||
configs.add(mi);
|
||||
this.moduleInformation.put(mi.getUID(), configs);
|
||||
moduleInformation.put(mi.getUID(), configs);
|
||||
}
|
||||
|
||||
ModuleType mt = helper.buildModuleType(mi.getUID(), this.moduleInformation);
|
||||
ModuleType mt = helper.buildModuleType(mi.getUID(), moduleInformation);
|
||||
if (mt != null) {
|
||||
for (ProviderChangeListener<ModuleType> l : changeListeners) {
|
||||
if (oldType != null) {
|
||||
@@ -107,16 +113,16 @@ public class AnnotatedThingActionModuleTypeProvider extends BaseModuleHandlerFac
|
||||
mi.setThingUID(thingUID);
|
||||
ModuleType oldType = null;
|
||||
|
||||
Set<ModuleInformation> availableModuleConfigs = this.moduleInformation.get(mi.getUID());
|
||||
Set<ModuleInformation> availableModuleConfigs = moduleInformation.get(mi.getUID());
|
||||
if (availableModuleConfigs != null) {
|
||||
if (availableModuleConfigs.size() > 1) {
|
||||
oldType = helper.buildModuleType(mi.getUID(), this.moduleInformation);
|
||||
oldType = helper.buildModuleType(mi.getUID(), moduleInformation);
|
||||
availableModuleConfigs.remove(mi);
|
||||
} else {
|
||||
this.moduleInformation.remove(mi.getUID());
|
||||
moduleInformation.remove(mi.getUID());
|
||||
}
|
||||
|
||||
ModuleType mt = helper.buildModuleType(mi.getUID(), this.moduleInformation);
|
||||
ModuleType mt = helper.buildModuleType(mi.getUID(), moduleInformation);
|
||||
// localize moduletype -> remove from map
|
||||
for (ProviderChangeListener<ModuleType> l : changeListeners) {
|
||||
if (oldType != null) {
|
||||
@@ -138,7 +144,7 @@ public class AnnotatedThingActionModuleTypeProvider extends BaseModuleHandlerFac
|
||||
public Collection<ModuleType> getAll() {
|
||||
Collection<ModuleType> moduleTypes = new ArrayList<>();
|
||||
for (String moduleUID : moduleInformation.keySet()) {
|
||||
ModuleType mt = helper.buildModuleType(moduleUID, this.moduleInformation);
|
||||
ModuleType mt = helper.buildModuleType(moduleUID, moduleInformation);
|
||||
if (mt != null) {
|
||||
moduleTypes.add(mt);
|
||||
}
|
||||
@@ -199,7 +205,7 @@ public class AnnotatedThingActionModuleTypeProvider extends BaseModuleHandlerFac
|
||||
true);
|
||||
|
||||
if (finalMI != null) {
|
||||
ActionType moduleType = helper.buildModuleType(module.getTypeUID(), this.moduleInformation);
|
||||
ActionType moduleType = helper.buildModuleType(module.getTypeUID(), moduleInformation);
|
||||
return new AnnotationActionHandler(actionModule, moduleType, finalMI.getMethod(),
|
||||
finalMI.getActionProvider());
|
||||
}
|
||||
@@ -207,13 +213,4 @@ public class AnnotatedThingActionModuleTypeProvider extends BaseModuleHandlerFac
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setModuleTypeI18nService(ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = moduleTypeI18nService;
|
||||
}
|
||||
|
||||
protected void unsetModuleTypeI18nService(ModuleTypeI18nService moduleTypeI18nService) {
|
||||
this.moduleTypeI18nService = null;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -40,16 +40,16 @@ import org.openhab.core.config.core.Configuration;
|
||||
@NonNullByDefault
|
||||
public class RuleBuilder {
|
||||
|
||||
private @NonNullByDefault({}) List<Trigger> triggers;
|
||||
private @NonNullByDefault({}) List<Condition> conditions;
|
||||
private @NonNullByDefault({}) List<Action> actions;
|
||||
private @NonNullByDefault({}) Configuration configuration;
|
||||
private @NonNullByDefault({}) List<ConfigDescriptionParameter> configDescriptions;
|
||||
private List<Trigger> triggers;
|
||||
private List<Condition> conditions;
|
||||
private List<Action> actions;
|
||||
private Configuration configuration;
|
||||
private List<ConfigDescriptionParameter> configDescriptions;
|
||||
private @Nullable String templateUID;
|
||||
private @NonNullByDefault({}) final String uid;
|
||||
private final String uid;
|
||||
private @Nullable String name;
|
||||
private @NonNullByDefault({}) Set<String> tags;
|
||||
private @NonNullByDefault({}) Visibility visibility;
|
||||
private Set<String> tags;
|
||||
private @Nullable Visibility visibility;
|
||||
private @Nullable String description;
|
||||
|
||||
protected RuleBuilder(Rule rule) {
|
||||
|
||||
+1
-2
@@ -84,8 +84,7 @@ public class AnnotationActionModuleTypeProviderTest extends JavaTest {
|
||||
|
||||
@Test
|
||||
public void testMultiServiceAnnotationActions() {
|
||||
AnnotatedActionModuleTypeProvider prov = new AnnotatedActionModuleTypeProvider();
|
||||
prov.setModuleTypeI18nService(moduleTypeI18nService);
|
||||
AnnotatedActionModuleTypeProvider prov = new AnnotatedActionModuleTypeProvider(moduleTypeI18nService);
|
||||
|
||||
Map<String, Object> properties1 = new HashMap<>();
|
||||
properties1.put(ConfigConstants.SERVICE_CONTEXT, "conf1");
|
||||
|
||||
+5
-14
@@ -57,30 +57,21 @@ public class PollingUsbSerialScanner implements UsbSerialDiscovery {
|
||||
private static final Duration DEFAULT_PAUSE_BETWEEN_SCANS = Duration.ofSeconds(15);
|
||||
private Duration pauseBetweenScans = DEFAULT_PAUSE_BETWEEN_SCANS;
|
||||
|
||||
private @NonNullByDefault({}) DeltaUsbSerialScanner deltaUsbSerialScanner;
|
||||
|
||||
private final DeltaUsbSerialScanner deltaUsbSerialScanner;
|
||||
private final Set<UsbSerialDiscoveryListener> discoveryListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
private @NonNullByDefault({}) ScheduledExecutorService scheduler;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
|
||||
private @Nullable ScheduledFuture<?> backgroundScanningJob;
|
||||
|
||||
@Reference
|
||||
protected void setUsbSerialScanner(UsbSerialScanner usbSerialScanner) {
|
||||
deltaUsbSerialScanner = new DeltaUsbSerialScanner(usbSerialScanner);
|
||||
}
|
||||
|
||||
protected void unsetUsbSerialScanner(UsbSerialScanner usbSerialScanner) {
|
||||
deltaUsbSerialScanner = null;
|
||||
}
|
||||
|
||||
@Activate
|
||||
protected void activate(Map<String, Object> config) {
|
||||
public PollingUsbSerialScanner(Map<String, Object> config, final @Reference UsbSerialScanner usbSerialScanner) {
|
||||
if (config.containsKey(PAUSE_BETWEEN_SCANS_IN_SECONDS_ATTRIBUTE)) {
|
||||
pauseBetweenScans = Duration
|
||||
.ofSeconds(parseLong(config.get(PAUSE_BETWEEN_SCANS_IN_SECONDS_ATTRIBUTE).toString()));
|
||||
}
|
||||
|
||||
deltaUsbSerialScanner = new DeltaUsbSerialScanner(usbSerialScanner);
|
||||
|
||||
scheduler = Executors.newSingleThreadScheduledExecutor(
|
||||
ThreadFactoryBuilder.create().withName(THREAD_NAME).withDaemonThreads(true).build());
|
||||
}
|
||||
|
||||
-12
@@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.common.SafeCaller;
|
||||
import org.openhab.core.config.discovery.DiscoveryListener;
|
||||
import org.openhab.core.config.discovery.DiscoveryResult;
|
||||
import org.openhab.core.config.discovery.DiscoveryService;
|
||||
@@ -136,8 +135,6 @@ public final class DiscoveryServiceRegistryImpl implements DiscoveryServiceRegis
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(DiscoveryServiceRegistryImpl.class);
|
||||
|
||||
private @NonNullByDefault({}) SafeCaller safeCaller;
|
||||
|
||||
@Activate
|
||||
protected void activate() {
|
||||
active.set(true);
|
||||
@@ -464,13 +461,4 @@ public final class DiscoveryServiceRegistryImpl implements DiscoveryServiceRegis
|
||||
public int getMaxScanTimeout(String bindingId) {
|
||||
return getMaxScanTimeout(getDiscoveryServices(bindingId));
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = safeCaller;
|
||||
}
|
||||
|
||||
protected void unsetSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = null;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-6
@@ -42,16 +42,12 @@ public abstract class BaseSmartHomeServlet extends HttpServlet {
|
||||
/**
|
||||
* Http service.
|
||||
*/
|
||||
protected @NonNullByDefault({}) HttpService httpService;
|
||||
protected final HttpService httpService;
|
||||
|
||||
protected void setHttpService(HttpService httpService) {
|
||||
public BaseSmartHomeServlet(HttpService httpService) {
|
||||
this.httpService = httpService;
|
||||
}
|
||||
|
||||
protected void unsetHttpService(HttpService httpService) {
|
||||
this.httpService = null;
|
||||
}
|
||||
|
||||
protected void activate(String alias, HttpContext httpContext) {
|
||||
try {
|
||||
logger.debug("Starting up {} at {}", getClass().getSimpleName(), alias);
|
||||
|
||||
+6
-6
@@ -12,28 +12,28 @@
|
||||
*/
|
||||
package org.openhab.core.io.http.servlet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.io.http.HttpContextFactoryService;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.http.HttpContext;
|
||||
import org.osgi.service.http.HttpService;
|
||||
|
||||
/**
|
||||
* Base class for servlets which host resources using framework bundles.
|
||||
*
|
||||
* @author Łukasz Dywicki - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class SmartHomeBundleServlet extends BaseSmartHomeServlet {
|
||||
|
||||
protected HttpContextFactoryService httpContextFactoryService;
|
||||
protected final HttpContextFactoryService httpContextFactoryService;
|
||||
|
||||
public void setHttpContextFactoryService(HttpContextFactoryService httpContextFactoryService) {
|
||||
public SmartHomeBundleServlet(HttpService httpService, HttpContextFactoryService httpContextFactoryService) {
|
||||
super(httpService);
|
||||
this.httpContextFactoryService = httpContextFactoryService;
|
||||
}
|
||||
|
||||
public void unsetHttpContextFactoryService(HttpContextFactoryService httpContextFactoryService) {
|
||||
this.httpContextFactoryService = null;
|
||||
}
|
||||
|
||||
protected void activate(String alias, Bundle bundle) {
|
||||
super.activate(alias, createHttpContext(bundle));
|
||||
}
|
||||
|
||||
+4
-6
@@ -14,6 +14,7 @@ package org.openhab.core.io.http.servlet;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.osgi.service.http.HttpContext;
|
||||
import org.osgi.service.http.HttpService;
|
||||
|
||||
/**
|
||||
* Base class for HTTP servlets which share certain {@link HttpContext} instance.
|
||||
@@ -28,16 +29,13 @@ public abstract class SmartHomeServlet extends BaseSmartHomeServlet {
|
||||
/**
|
||||
* Http context.
|
||||
*/
|
||||
protected @NonNullByDefault({}) HttpContext httpContext;
|
||||
protected final HttpContext httpContext;
|
||||
|
||||
protected void setHttpContext(HttpContext httpContext) {
|
||||
public SmartHomeServlet(HttpService httpService, HttpContext httpContext) {
|
||||
super(httpService);
|
||||
this.httpContext = httpContext;
|
||||
}
|
||||
|
||||
protected void unsetHttpContext(HttpContext httpContext) {
|
||||
this.httpContext = null;
|
||||
}
|
||||
|
||||
protected void activate(String alias) {
|
||||
super.activate(alias, httpContext);
|
||||
}
|
||||
|
||||
+6
-10
@@ -38,11 +38,7 @@ import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
@NonNullByDefault
|
||||
public class SerialPortRegistry {
|
||||
|
||||
private @NonNullByDefault({}) final Collection<SerialPortProvider> portCreators;
|
||||
|
||||
public SerialPortRegistry() {
|
||||
this.portCreators = new HashSet<>();
|
||||
}
|
||||
private final Collection<SerialPortProvider> portCreators = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Registers a {@link SerialPortProvider}.
|
||||
@@ -51,14 +47,14 @@ public class SerialPortRegistry {
|
||||
*/
|
||||
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
|
||||
protected void registerSerialPortCreator(SerialPortProvider creator) {
|
||||
synchronized (this.portCreators) {
|
||||
this.portCreators.add(creator);
|
||||
synchronized (portCreators) {
|
||||
portCreators.add(creator);
|
||||
}
|
||||
}
|
||||
|
||||
protected void unregisterSerialPortCreator(SerialPortProvider creator) {
|
||||
synchronized (this.portCreators) {
|
||||
this.portCreators.remove(creator);
|
||||
synchronized (portCreators) {
|
||||
portCreators.remove(creator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +83,7 @@ public class SerialPortRegistry {
|
||||
}
|
||||
|
||||
public Collection<SerialPortProvider> getPortCreators() {
|
||||
synchronized (this.portCreators) {
|
||||
synchronized (portCreators) {
|
||||
return Collections.unmodifiableCollection(new HashSet<>(portCreators));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-22
@@ -47,32 +47,22 @@ public class SitemapProviderImpl implements SitemapProvider, ModelRepositoryChan
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SitemapProviderImpl.class);
|
||||
|
||||
private @NonNullByDefault({}) ModelRepository modelRepo;
|
||||
private final ModelRepository modelRepo;
|
||||
|
||||
private final Map<String, Sitemap> sitemapModelCache = new ConcurrentHashMap<>();
|
||||
|
||||
private final Set<ModelRepositoryChangeListener> modelChangeListeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
@Reference
|
||||
public void setModelRepository(ModelRepository modelRepo) {
|
||||
this.modelRepo = modelRepo;
|
||||
}
|
||||
|
||||
public void unsetModelRepository(ModelRepository modelRepo) {
|
||||
this.modelRepo = null;
|
||||
}
|
||||
|
||||
@Activate
|
||||
protected void activate() {
|
||||
public SitemapProviderImpl(final @Reference ModelRepository modelRepo) {
|
||||
this.modelRepo = modelRepo;
|
||||
refreshSitemapModels();
|
||||
modelRepo.addModelRepositoryChangeListener(this);
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
protected void deactivate() {
|
||||
if (modelRepo != null) {
|
||||
modelRepo.removeModelRepositoryChangeListener(this);
|
||||
}
|
||||
modelRepo.removeModelRepositoryChangeListener(this);
|
||||
sitemapModelCache.clear();
|
||||
}
|
||||
|
||||
@@ -80,17 +70,17 @@ public class SitemapProviderImpl implements SitemapProvider, ModelRepositoryChan
|
||||
public @Nullable Sitemap getSitemap(String sitemapName) {
|
||||
String filename = sitemapName + SITEMAP_FILEEXT;
|
||||
Sitemap sitemap = sitemapModelCache.get(filename);
|
||||
if (sitemap != null) {
|
||||
if (!sitemap.getName().equals(sitemapName)) {
|
||||
logger.warn(
|
||||
"Filename `{}` does not match the name `{}` of the sitemap - please fix this as you might see unexpected behavior otherwise.",
|
||||
filename, sitemap.getName());
|
||||
}
|
||||
return sitemap;
|
||||
} else {
|
||||
if (sitemap == null) {
|
||||
logger.trace("Sitemap {} cannot be found", sitemapName);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!sitemap.getName().equals(sitemapName)) {
|
||||
logger.warn(
|
||||
"Filename `{}` does not match the name `{}` of the sitemap - please fix this as you might see unexpected behavior otherwise.",
|
||||
filename, sitemap.getName());
|
||||
}
|
||||
return sitemap;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -47,13 +47,13 @@ public class MapDbStorageService implements DeletableStorageService {
|
||||
private static final String DB_FILE_NAME = "storage.mapdb";
|
||||
|
||||
/* holds the local instance of the MapDB database */
|
||||
private @NonNullByDefault({}) DB db;
|
||||
private final DB db;
|
||||
|
||||
/* the folder name to store mapdb databases ({@code mapdb} by default) */
|
||||
private String dbFolderName = "mapdb";
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
public MapDbStorageService() {
|
||||
dbFolderName = ConfigConstants.getUserDataFolder() + File.separator + dbFolderName;
|
||||
File folder = new File(dbFolderName);
|
||||
if (!folder.exists()) {
|
||||
|
||||
-1
@@ -143,7 +143,6 @@ public class MapDbStorageServiceTest {
|
||||
System.setProperty(ConfigConstants.USERDATA_DIR_PROG_ARGUMENT, userdata.toString());
|
||||
|
||||
storageService = new MapDbStorageService();
|
||||
storageService.activate();
|
||||
this.storage = (MapDbStorage<Object>) storageService.getStorage("TestStorage", getClass().getClassLoader());
|
||||
}
|
||||
|
||||
|
||||
+3
-11
@@ -40,12 +40,13 @@ public class MagicMetadataUsingService {
|
||||
private final Logger logger = LoggerFactory.getLogger(MagicMetadataUsingService.class);
|
||||
private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("magic");
|
||||
|
||||
private @NonNullByDefault({}) MetadataRegistry metadataRegistry;
|
||||
private final MetadataRegistry metadataRegistry;
|
||||
|
||||
private @Nullable ScheduledFuture<?> job;
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
public MagicMetadataUsingService(final @Reference MetadataRegistry metadataRegistry) {
|
||||
this.metadataRegistry = metadataRegistry;
|
||||
job = scheduler.scheduleWithFixedDelay(() -> run(), 30, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@@ -63,13 +64,4 @@ public class MagicMetadataUsingService {
|
||||
metadata.getConfiguration());
|
||||
});
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setMetadataRegistry(MetadataRegistry metadataRegistry) {
|
||||
this.metadataRegistry = metadataRegistry;
|
||||
}
|
||||
|
||||
protected void unsetMetadataRegistry(MetadataRegistry metadataRegistry) {
|
||||
this.metadataRegistry = null;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-51
@@ -65,11 +65,11 @@ public class AutoUpdateManager {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(AutoUpdateManager.class);
|
||||
|
||||
private @NonNullByDefault({}) ItemChannelLinkRegistry itemChannelLinkRegistry;
|
||||
private @NonNullByDefault({}) ThingRegistry thingRegistry;
|
||||
private @NonNullByDefault({}) EventPublisher eventPublisher;
|
||||
private @NonNullByDefault({}) MetadataRegistry metadataRegistry;
|
||||
private @NonNullByDefault({}) ChannelTypeRegistry channelTypeRegistry;
|
||||
private final ChannelTypeRegistry channelTypeRegistry;
|
||||
private final EventPublisher eventPublisher;
|
||||
private final ItemChannelLinkRegistry itemChannelLinkRegistry;
|
||||
private final MetadataRegistry metadataRegistry;
|
||||
private final ThingRegistry thingRegistry;
|
||||
|
||||
private boolean enabled = true;
|
||||
private boolean sendOptimisticUpdates = false;
|
||||
@@ -106,7 +106,18 @@ public class AutoUpdateManager {
|
||||
}
|
||||
|
||||
@Activate
|
||||
protected void activate(Map<String, @Nullable Object> configuration) {
|
||||
public AutoUpdateManager(Map<String, @Nullable Object> configuration,
|
||||
final @Reference ChannelTypeRegistry channelTypeRegistry, //
|
||||
final @Reference EventPublisher eventPublisher,
|
||||
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry,
|
||||
final @Reference MetadataRegistry metadataRegistry, //
|
||||
final @Reference ThingRegistry thingRegistry) {
|
||||
this.channelTypeRegistry = channelTypeRegistry;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
|
||||
this.metadataRegistry = metadataRegistry;
|
||||
this.thingRegistry = thingRegistry;
|
||||
|
||||
modified(configuration);
|
||||
}
|
||||
|
||||
@@ -284,49 +295,4 @@ public class AutoUpdateManager {
|
||||
}
|
||||
return isAccepted;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setItemChannelLinkRegistry(ItemChannelLinkRegistry itemChannelLinkRegistry) {
|
||||
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
|
||||
}
|
||||
|
||||
protected void unsetItemChannelLinkRegistry(ItemChannelLinkRegistry itemChannelLinkRegistry) {
|
||||
this.itemChannelLinkRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setThingRegistry(ThingRegistry thingRegistry) {
|
||||
this.thingRegistry = thingRegistry;
|
||||
}
|
||||
|
||||
protected void unsetThingRegistry(ThingRegistry thingRegistry) {
|
||||
this.thingRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
protected void unsetEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setMetadataRegistry(MetadataRegistry metadataRegistry) {
|
||||
this.metadataRegistry = metadataRegistry;
|
||||
}
|
||||
|
||||
protected void unsetMetadataRegistry(MetadataRegistry metadataRegistry) {
|
||||
this.metadataRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setChannelTypeRegistry(ChannelTypeRegistry channelTypeRegistry) {
|
||||
this.channelTypeRegistry = channelTypeRegistry;
|
||||
}
|
||||
|
||||
protected void unsetChannelTypeRegistry(ChannelTypeRegistry channelTypeRegistry) {
|
||||
this.channelTypeRegistry = null;
|
||||
}
|
||||
}
|
||||
|
||||
+31
-91
@@ -72,6 +72,7 @@ import org.openhab.core.types.Command;
|
||||
import org.openhab.core.types.State;
|
||||
import org.openhab.core.types.Type;
|
||||
import org.openhab.core.types.util.UnitUtils;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
@@ -98,15 +99,36 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(CommunicationManager.class);
|
||||
|
||||
private @NonNullByDefault({}) SystemProfileFactory defaultProfileFactory;
|
||||
private @NonNullByDefault({}) ItemChannelLinkRegistry itemChannelLinkRegistry;
|
||||
private @NonNullByDefault({}) ThingRegistry thingRegistry;
|
||||
private @NonNullByDefault({}) ItemRegistry itemRegistry;
|
||||
private @NonNullByDefault({}) EventPublisher eventPublisher;
|
||||
private @NonNullByDefault({}) SafeCaller safeCaller;
|
||||
private @NonNullByDefault({}) AutoUpdateManager autoUpdateManager;
|
||||
private @NonNullByDefault({}) ItemStateConverter itemStateConverter;
|
||||
private @NonNullByDefault({}) ChannelTypeRegistry channelTypeRegistry;
|
||||
private final AutoUpdateManager autoUpdateManager;
|
||||
private final ChannelTypeRegistry channelTypeRegistry;
|
||||
private final SystemProfileFactory defaultProfileFactory;
|
||||
private final ItemChannelLinkRegistry itemChannelLinkRegistry;
|
||||
private final ItemRegistry itemRegistry;
|
||||
private final ItemStateConverter itemStateConverter;
|
||||
private final EventPublisher eventPublisher;
|
||||
private final SafeCaller safeCaller;
|
||||
private final ThingRegistry thingRegistry;
|
||||
|
||||
@Activate
|
||||
public CommunicationManager(final @Reference AutoUpdateManager autoUpdateManager,
|
||||
final @Reference ChannelTypeRegistry channelTypeRegistry,
|
||||
final @Reference SystemProfileFactory defaultProfileFactory,
|
||||
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry,
|
||||
final @Reference ItemRegistry itemRegistry, //
|
||||
final @Reference ItemStateConverter itemStateConverter, //
|
||||
final @Reference EventPublisher eventPublisher, //
|
||||
final @Reference SafeCaller safeCaller, //
|
||||
final @Reference ThingRegistry thingRegistry) {
|
||||
this.autoUpdateManager = autoUpdateManager;
|
||||
this.channelTypeRegistry = channelTypeRegistry;
|
||||
this.defaultProfileFactory = defaultProfileFactory;
|
||||
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
|
||||
this.itemRegistry = itemRegistry;
|
||||
this.itemStateConverter = itemStateConverter;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.safeCaller = safeCaller;
|
||||
this.thingRegistry = thingRegistry;
|
||||
}
|
||||
|
||||
private final Set<ItemFactory> itemFactories = new CopyOnWriteArraySet<>();
|
||||
|
||||
@@ -514,43 +536,6 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
|
||||
cleanup(oldElement);
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setItemChannelLinkRegistry(ItemChannelLinkRegistry itemChannelLinkRegistry) {
|
||||
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
|
||||
itemChannelLinkRegistry.addRegistryChangeListener(this);
|
||||
}
|
||||
|
||||
protected void unsetItemChannelLinkRegistry(ItemChannelLinkRegistry itemChannelLinkRegistry) {
|
||||
this.itemChannelLinkRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setThingRegistry(ThingRegistry thingRegistry) {
|
||||
this.thingRegistry = thingRegistry;
|
||||
}
|
||||
|
||||
protected void unsetThingRegistry(ThingRegistry thingRegistry) {
|
||||
this.thingRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
protected void unsetEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = itemRegistry;
|
||||
}
|
||||
|
||||
protected void unsetItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = null;
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
|
||||
protected void addProfileFactory(ProfileFactory profileFactory) {
|
||||
this.profileFactories.put(profileFactory, ConcurrentHashMap.newKeySet());
|
||||
@@ -574,33 +559,6 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
|
||||
profileAdvisors.remove(profileAdvisor);
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setDefaultProfileFactory(SystemProfileFactory defaultProfileFactory) {
|
||||
this.defaultProfileFactory = defaultProfileFactory;
|
||||
}
|
||||
|
||||
protected void unsetDefaultProfileFactory(SystemProfileFactory defaultProfileFactory) {
|
||||
this.defaultProfileFactory = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = safeCaller;
|
||||
}
|
||||
|
||||
protected void unsetSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setItemStateConverter(ItemStateConverter itemStateConverter) {
|
||||
this.itemStateConverter = itemStateConverter;
|
||||
}
|
||||
|
||||
public void unsetItemStateConverter(ItemStateConverter itemStateConverter) {
|
||||
this.itemStateConverter = null;
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC)
|
||||
protected void addItemFactory(ItemFactory itemFactory) {
|
||||
itemFactories.add(itemFactory);
|
||||
@@ -629,24 +587,6 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList
|
||||
}
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setAutoUpdateManager(AutoUpdateManager autoUpdateManager) {
|
||||
this.autoUpdateManager = autoUpdateManager;
|
||||
}
|
||||
|
||||
public void unsetAutoUpdateManager(AutoUpdateManager autoUpdateManager) {
|
||||
this.autoUpdateManager = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
public void setChannelTypeRegistry(ChannelTypeRegistry channelTypeRegistry) {
|
||||
this.channelTypeRegistry = channelTypeRegistry;
|
||||
}
|
||||
|
||||
public void unsetChannelTypeRegistry(ChannelTypeRegistry channelTypeRegistry) {
|
||||
this.channelTypeRegistry = null;
|
||||
}
|
||||
|
||||
private static class NoOpProfile implements Profile {
|
||||
@Override
|
||||
public ProfileTypeUID getProfileTypeUID() {
|
||||
|
||||
+8
-25
@@ -27,6 +27,7 @@ import org.openhab.core.thing.type.ChannelType;
|
||||
import org.openhab.core.thing.type.ChannelTypeRegistry;
|
||||
import org.openhab.core.thing.type.ThingType;
|
||||
import org.openhab.core.thing.type.ThingTypeRegistry;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
|
||||
@@ -45,37 +46,19 @@ import org.osgi.service.component.annotations.Reference;
|
||||
@NonNullByDefault
|
||||
public class ThingConfigDescriptionAliasProvider implements ConfigDescriptionAliasProvider {
|
||||
|
||||
private @NonNullByDefault({}) ThingRegistry thingRegistry;
|
||||
private @NonNullByDefault({}) ThingTypeRegistry thingTypeRegistry;
|
||||
private @NonNullByDefault({}) ChannelTypeRegistry channelTypeRegistry;
|
||||
private final ThingRegistry thingRegistry;
|
||||
private final ThingTypeRegistry thingTypeRegistry;
|
||||
private final ChannelTypeRegistry channelTypeRegistry;
|
||||
|
||||
@Reference
|
||||
protected void setThingRegistry(ThingRegistry thingRegistry) {
|
||||
@Activate
|
||||
public ThingConfigDescriptionAliasProvider(final @Reference ThingRegistry thingRegistry,
|
||||
final @Reference ThingTypeRegistry thingTypeRegistry,
|
||||
final @Reference ChannelTypeRegistry channelTypeRegistry) {
|
||||
this.thingRegistry = thingRegistry;
|
||||
}
|
||||
|
||||
protected void unsetThingRegistry(ThingRegistry thingRegistry) {
|
||||
this.thingRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setThingTypeRegistry(ThingTypeRegistry thingTypeRegistry) {
|
||||
this.thingTypeRegistry = thingTypeRegistry;
|
||||
}
|
||||
|
||||
protected void unsetThingTypeRegistry(ThingTypeRegistry thingTypeRegistry) {
|
||||
this.thingTypeRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setChannelTypeRegistry(ChannelTypeRegistry channelTypeRegistry) {
|
||||
this.channelTypeRegistry = channelTypeRegistry;
|
||||
}
|
||||
|
||||
protected void unsetChannelTypeRegistry(ChannelTypeRegistry channelTypeRegistry) {
|
||||
this.channelTypeRegistry = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable URI getAlias(URI uri) {
|
||||
// If this is not a concrete thing, then return
|
||||
|
||||
+11
-17
@@ -29,6 +29,7 @@ import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.binding.firmware.Firmware;
|
||||
import org.openhab.core.thing.firmware.FirmwareProvider;
|
||||
import org.openhab.core.thing.firmware.FirmwareRegistry;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
@@ -50,7 +51,12 @@ public final class FirmwareRegistryImpl implements FirmwareRegistry {
|
||||
|
||||
private final List<FirmwareProvider> firmwareProviders = new CopyOnWriteArrayList<>();
|
||||
|
||||
private @NonNullByDefault({}) LocaleProvider localeProvider;
|
||||
private final LocaleProvider localeProvider;
|
||||
|
||||
@Activate
|
||||
public FirmwareRegistryImpl(final @Reference LocaleProvider localeProvider) {
|
||||
this.localeProvider = localeProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Firmware getFirmware(Thing thing, String firmwareVersion) {
|
||||
@@ -90,13 +96,10 @@ public final class FirmwareRegistryImpl implements FirmwareRegistry {
|
||||
Locale loc = locale != null ? locale : localeProvider.getLocale();
|
||||
Collection<Firmware> firmwares = getFirmwares(thing, loc);
|
||||
|
||||
if (firmwares != null) {
|
||||
Optional<Firmware> first = firmwares.stream().findFirst();
|
||||
|
||||
// Used as workaround for the NonNull annotation implied to .isElse()
|
||||
if (first.isPresent()) {
|
||||
return first.get();
|
||||
}
|
||||
Optional<Firmware> first = firmwares.stream().findFirst();
|
||||
// Used as workaround for the NonNull annotation implied to .isElse()
|
||||
if (first.isPresent()) {
|
||||
return first.get();
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -140,13 +143,4 @@ public final class FirmwareRegistryImpl implements FirmwareRegistry {
|
||||
protected void removeFirmwareProvider(FirmwareProvider firmwareProvider) {
|
||||
firmwareProviders.remove(firmwareProvider);
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setLocaleProvider(final LocaleProvider localeProvider) {
|
||||
this.localeProvider = localeProvider;
|
||||
}
|
||||
|
||||
protected void unsetLocaleProvider(final LocaleProvider localeProvider) {
|
||||
this.localeProvider = null;
|
||||
}
|
||||
}
|
||||
|
||||
+26
-70
@@ -101,13 +101,32 @@ public final class FirmwareUpdateServiceImpl implements FirmwareUpdateService, E
|
||||
private final Map<ThingUID, ProgressCallbackImpl> progressCallbackMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final List<FirmwareUpdateHandler> firmwareUpdateHandlers = new CopyOnWriteArrayList<>();
|
||||
private @NonNullByDefault({}) FirmwareRegistry firmwareRegistry;
|
||||
private @NonNullByDefault({}) EventPublisher eventPublisher;
|
||||
private @NonNullByDefault({}) TranslationProvider i18nProvider;
|
||||
private @NonNullByDefault({}) LocaleProvider localeProvider;
|
||||
private @NonNullByDefault({}) SafeCaller safeCaller;
|
||||
private @NonNullByDefault({}) ConfigDescriptionValidator configDescriptionValidator;
|
||||
private @NonNullByDefault({}) BundleResolver bundleResolver;
|
||||
|
||||
private final BundleResolver bundleResolver;
|
||||
private final ConfigDescriptionValidator configDescriptionValidator;
|
||||
private final EventPublisher eventPublisher;
|
||||
private final FirmwareRegistry firmwareRegistry;
|
||||
private final TranslationProvider i18nProvider;
|
||||
private final LocaleProvider localeProvider;
|
||||
private final SafeCaller safeCaller;
|
||||
|
||||
@Activate
|
||||
public FirmwareUpdateServiceImpl( //
|
||||
final @Reference BundleResolver bundleResolver,
|
||||
final @Reference ConfigDescriptionValidator configDescriptionValidator,
|
||||
final @Reference EventPublisher eventPublisher, //
|
||||
final @Reference FirmwareRegistry firmwareRegistry, //
|
||||
final @Reference TranslationProvider i18nProvider, //
|
||||
final @Reference LocaleProvider localeProvider, //
|
||||
final @Reference SafeCaller safeCaller) {
|
||||
this.bundleResolver = bundleResolver;
|
||||
this.configDescriptionValidator = configDescriptionValidator;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.firmwareRegistry = firmwareRegistry;
|
||||
this.i18nProvider = i18nProvider;
|
||||
this.localeProvider = localeProvider;
|
||||
this.safeCaller = safeCaller;
|
||||
}
|
||||
|
||||
private final Runnable firmwareStatusRunnable = new Runnable() {
|
||||
@Override
|
||||
@@ -471,67 +490,4 @@ public final class FirmwareUpdateServiceImpl implements FirmwareUpdateService, E
|
||||
}
|
||||
progressCallbackMap.remove(firmwareUpdateHandler.getThing().getUID());
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setFirmwareRegistry(FirmwareRegistry firmwareRegistry) {
|
||||
this.firmwareRegistry = firmwareRegistry;
|
||||
}
|
||||
|
||||
protected void unsetFirmwareRegistry(FirmwareRegistry firmwareRegistry) {
|
||||
this.firmwareRegistry = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
protected void unsetEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setTranslationProvider(TranslationProvider i18nProvider) {
|
||||
this.i18nProvider = i18nProvider;
|
||||
}
|
||||
|
||||
protected void unsetTranslationProvider(TranslationProvider i18nProvider) {
|
||||
this.i18nProvider = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setLocaleProvider(final LocaleProvider localeProvider) {
|
||||
this.localeProvider = localeProvider;
|
||||
}
|
||||
|
||||
protected void unsetLocaleProvider(final LocaleProvider localeProvider) {
|
||||
this.localeProvider = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = safeCaller;
|
||||
}
|
||||
|
||||
protected void unsetSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setConfigDescriptionValidator(ConfigDescriptionValidator configDescriptionValidator) {
|
||||
this.configDescriptionValidator = configDescriptionValidator;
|
||||
}
|
||||
|
||||
protected void unsetConfigDescriptionValidator(ConfigDescriptionValidator configDescriptionValidator) {
|
||||
this.configDescriptionValidator = null;
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setBundleResolver(BundleResolver bundleResolver) {
|
||||
this.bundleResolver = bundleResolver;
|
||||
}
|
||||
|
||||
protected void unsetBundleResolver(BundleResolver bundleResolver) {
|
||||
this.bundleResolver = bundleResolver;
|
||||
}
|
||||
}
|
||||
|
||||
+30
-29
@@ -66,14 +66,16 @@ public class AutoUpdateManagerTest {
|
||||
private static final ChannelUID CHANNEL_UID_HANDLER_MISSING = new ChannelUID(THING_UID_HANDLER_MISSING, "channel1");
|
||||
private ItemCommandEvent event;
|
||||
private GenericItem item;
|
||||
private @Mock EventPublisher mockEventPublisher;
|
||||
private @Mock ItemChannelLinkRegistry mockLinkRegistry;
|
||||
private @Mock ThingRegistry mockThingRegistry;
|
||||
private @Mock Thing mockThingOnline;
|
||||
private @Mock Thing mockThingOffline;
|
||||
private @Mock Thing mockThingHandlerMissing;
|
||||
private @Mock ThingHandler mockHandler;
|
||||
private @Mock MetadataRegistry mockMetadataRegistry;
|
||||
|
||||
private @Mock ChannelTypeRegistry channelTypeRegistryMock;
|
||||
private @Mock EventPublisher eventPublisherMock;
|
||||
private @Mock ItemChannelLinkRegistry iclRegistryMock;
|
||||
private @Mock ThingRegistry thingRegistryMock;
|
||||
private @Mock Thing onlineThingMock;
|
||||
private @Mock Thing offlineThingMock;
|
||||
private @Mock Thing thingMissingHandlerMock;
|
||||
private @Mock ThingHandler handlerMock;
|
||||
private @Mock MetadataRegistry metadataRegistryMock;
|
||||
|
||||
private final List<ItemChannelLink> links = new LinkedList<>();
|
||||
private AutoUpdateManager aum;
|
||||
@@ -86,36 +88,35 @@ public class AutoUpdateManagerTest {
|
||||
item = new StringItem("test");
|
||||
item.setState(new StringType("BEFORE"));
|
||||
|
||||
when(mockLinkRegistry.stream()).then(answer -> links.stream());
|
||||
when(mockLinkRegistry.getAll()).then(answer -> links);
|
||||
when(mockThingRegistry.get(eq(THING_UID_ONLINE))).thenReturn(mockThingOnline);
|
||||
when(mockThingRegistry.get(eq(THING_UID_OFFLINE))).thenReturn(mockThingOffline);
|
||||
when(mockThingRegistry.get(eq(THING_UID_HANDLER_MISSING))).thenReturn(mockThingHandlerMissing);
|
||||
when(mockThingOnline.getHandler()).thenReturn(mockHandler);
|
||||
when(mockThingOnline.getStatus()).thenReturn(ThingStatus.ONLINE);
|
||||
when(mockThingOnline.getChannel(eq(CHANNEL_UID_ONLINE_1.getId())))
|
||||
when(iclRegistryMock.stream()).then(answer -> links.stream());
|
||||
when(iclRegistryMock.getAll()).then(answer -> links);
|
||||
|
||||
when(thingRegistryMock.get(eq(THING_UID_ONLINE))).thenReturn(onlineThingMock);
|
||||
when(thingRegistryMock.get(eq(THING_UID_OFFLINE))).thenReturn(offlineThingMock);
|
||||
when(thingRegistryMock.get(eq(THING_UID_HANDLER_MISSING))).thenReturn(thingMissingHandlerMock);
|
||||
|
||||
when(onlineThingMock.getHandler()).thenReturn(handlerMock);
|
||||
when(onlineThingMock.getStatus()).thenReturn(ThingStatus.ONLINE);
|
||||
when(onlineThingMock.getChannel(eq(CHANNEL_UID_ONLINE_1.getId())))
|
||||
.thenAnswer(answer -> ChannelBuilder.create(CHANNEL_UID_ONLINE_1, "String")
|
||||
.withAutoUpdatePolicy(policies.get(CHANNEL_UID_ONLINE_1)).build());
|
||||
when(mockThingOnline.getChannel(eq(CHANNEL_UID_ONLINE_2.getId())))
|
||||
when(onlineThingMock.getChannel(eq(CHANNEL_UID_ONLINE_2.getId())))
|
||||
.thenAnswer(answer -> ChannelBuilder.create(CHANNEL_UID_ONLINE_2, "String")
|
||||
.withAutoUpdatePolicy(policies.get(CHANNEL_UID_ONLINE_2)).build());
|
||||
when(mockThingOffline.getHandler()).thenReturn(mockHandler);
|
||||
when(mockThingOffline.getStatus()).thenReturn(ThingStatus.OFFLINE);
|
||||
when(mockThingOffline.getChannel(eq(CHANNEL_UID_OFFLINE_1.getId())))
|
||||
|
||||
when(offlineThingMock.getHandler()).thenReturn(handlerMock);
|
||||
when(offlineThingMock.getStatus()).thenReturn(ThingStatus.OFFLINE);
|
||||
when(offlineThingMock.getChannel(eq(CHANNEL_UID_OFFLINE_1.getId())))
|
||||
.thenAnswer(answer -> ChannelBuilder.create(CHANNEL_UID_OFFLINE_1, "String")
|
||||
.withAutoUpdatePolicy(policies.get(CHANNEL_UID_OFFLINE_1)).build());
|
||||
|
||||
aum = new AutoUpdateManager();
|
||||
aum.setItemChannelLinkRegistry(mockLinkRegistry);
|
||||
aum.setEventPublisher(mockEventPublisher);
|
||||
aum.setThingRegistry(mockThingRegistry);
|
||||
aum.setMetadataRegistry(mockMetadataRegistry);
|
||||
aum.setChannelTypeRegistry(mock(ChannelTypeRegistry.class));
|
||||
aum = new AutoUpdateManager(new HashMap<>(), channelTypeRegistryMock, eventPublisherMock, iclRegistryMock,
|
||||
metadataRegistryMock, thingRegistryMock);
|
||||
}
|
||||
|
||||
private void assertStateEvent(String expectedContent, String extectedSource) {
|
||||
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
|
||||
verify(mockEventPublisher, atLeastOnce()).post(eventCaptor.capture());
|
||||
verify(eventPublisherMock, atLeastOnce()).post(eventCaptor.capture());
|
||||
Event event = eventCaptor.getAllValues().stream().filter(e -> e instanceof ItemStateEvent).findFirst().get();
|
||||
assertEquals(expectedContent, ((ItemStateEvent) event).getItemState().toFullString());
|
||||
assertEquals(extectedSource, event.getSource());
|
||||
@@ -124,7 +125,7 @@ public class AutoUpdateManagerTest {
|
||||
|
||||
private void assertPredictionEvent(String expectedContent, String extectedSource) {
|
||||
ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
|
||||
verify(mockEventPublisher, atLeastOnce()).post(eventCaptor.capture());
|
||||
verify(eventPublisherMock, atLeastOnce()).post(eventCaptor.capture());
|
||||
Event event = eventCaptor.getAllValues().stream().filter(e -> e instanceof ItemStatePredictedEvent).findFirst()
|
||||
.get();
|
||||
assertEquals(expectedContent, ((ItemStatePredictedEvent) event).getPredictedState().toFullString());
|
||||
@@ -143,7 +144,7 @@ public class AutoUpdateManagerTest {
|
||||
}
|
||||
|
||||
private void assertNothingHappened() {
|
||||
verifyNoMoreInteractions(mockEventPublisher);
|
||||
verifyNoMoreInteractions(eventPublisherMock);
|
||||
}
|
||||
|
||||
private void setAutoUpdatePolicy(ChannelUID channelUID, AutoUpdatePolicy policy) {
|
||||
|
||||
+4
-11
@@ -35,6 +35,7 @@ import org.osgi.service.component.annotations.Modified;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.http.HttpContext;
|
||||
import org.osgi.service.http.HttpService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -59,21 +60,13 @@ public class IconServlet extends SmartHomeServlet {
|
||||
|
||||
private long startupTime;
|
||||
|
||||
protected HttpService httpService;
|
||||
|
||||
protected String defaultIconSetId = "classic";
|
||||
|
||||
private List<IconProvider> iconProvider = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
@Reference
|
||||
public void setHttpService(HttpService httpService) {
|
||||
super.setHttpService(httpService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetHttpService(HttpService httpService) {
|
||||
super.unsetHttpService(httpService);
|
||||
@Activate
|
||||
public IconServlet(final @Reference HttpService httpService, final @Reference HttpContext httpContext) {
|
||||
super(httpService, httpContext);
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC)
|
||||
|
||||
+129
-124
@@ -35,6 +35,8 @@ import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.openhab.core.ui.icon.IconProvider;
|
||||
import org.openhab.core.ui.icon.IconSet.Format;
|
||||
import org.osgi.service.http.HttpContext;
|
||||
import org.osgi.service.http.HttpService;
|
||||
|
||||
/**
|
||||
* Tests for {@link IconServlet}.
|
||||
@@ -74,233 +76,236 @@ public class IconServletTest {
|
||||
private IconServlet servlet;
|
||||
private ByteArrayServletOutputStream responseOutputStream = new ByteArrayServletOutputStream();
|
||||
|
||||
private @Mock HttpServletRequest request;
|
||||
private @Mock HttpServletResponse response;
|
||||
private @Mock HttpContext httpContextMock;
|
||||
private @Mock HttpService httpServiceMock;
|
||||
|
||||
private @Mock IconProvider provider1;
|
||||
private @Mock IconProvider provider2;
|
||||
private @Mock HttpServletRequest requestMock;
|
||||
private @Mock HttpServletResponse responseMock;
|
||||
|
||||
private @Mock IconProvider provider1Mock;
|
||||
private @Mock IconProvider provider2Mock;
|
||||
|
||||
public @Rule MockitoRule mockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@Before
|
||||
public void before() throws IOException {
|
||||
servlet = new IconServlet();
|
||||
servlet = new IconServlet(httpServiceMock, httpContextMock);
|
||||
responseOutputStream.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOldUrlStyle() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/y-34.png");
|
||||
when(requestMock.getRequestURI()).thenReturn("/y-34.png");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("y", "classic", Format.PNG)).thenReturn(0);
|
||||
when(provider1.getIcon("y", "classic", "34", Format.PNG))
|
||||
when(provider1Mock.hasIcon("y", "classic", Format.PNG)).thenReturn(0);
|
||||
when(provider1Mock.getIcon("y", "classic", "34", Format.PNG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 1 icon: y classic 34 png".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 1 icon: y classic 34 png", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriority() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/x");
|
||||
when(request.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(request.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(request.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
when(requestMock.getRequestURI()).thenReturn("/x");
|
||||
when(requestMock.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(requestMock.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(requestMock.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("x", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1.getIcon("x", "test", "34", Format.SVG))
|
||||
when(provider1Mock.hasIcon("x", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1Mock.getIcon("x", "test", "34", Format.SVG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 1 icon: x test 34 svg".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 1 icon: x test 34 svg", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
|
||||
responseOutputStream.reset();
|
||||
|
||||
when(provider2.hasIcon("x", "test", Format.SVG)).thenReturn(1);
|
||||
when(provider2.getIcon("x", "test", "34", Format.SVG))
|
||||
when(provider2Mock.hasIcon("x", "test", Format.SVG)).thenReturn(1);
|
||||
when(provider2Mock.getIcon("x", "test", "34", Format.SVG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 2 icon: x test 34 svg".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider2);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider2Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 2 icon: x test 34 svg", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingIcon() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/icon/missing_for_test.png");
|
||||
when(requestMock.getRequestURI()).thenReturn("/icon/missing_for_test.png");
|
||||
|
||||
when(provider1.hasIcon(anyString(), anyString(), isA(Format.class))).thenReturn(null);
|
||||
when(provider1Mock.hasIcon(anyString(), anyString(), isA(Format.class))).thenReturn(null);
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("", responseOutputStream.getOutput());
|
||||
verify(response).sendError(404);
|
||||
verify(responseMock).sendError(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyFormatFalse() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/z");
|
||||
when(request.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(request.getParameter(PARAM_ANY_FORMAT)).thenReturn("false");
|
||||
when(request.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(request.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
when(requestMock.getRequestURI()).thenReturn("/z");
|
||||
when(requestMock.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(requestMock.getParameter(PARAM_ANY_FORMAT)).thenReturn("false");
|
||||
when(requestMock.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(requestMock.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1.getIcon("z", "test", "34", Format.SVG))
|
||||
when(provider1Mock.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1Mock.getIcon("z", "test", "34", Format.SVG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 1 icon: z test 34 svg".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 1 icon: z test 34 svg", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(provider1, never()).hasIcon("z", "test", Format.PNG);
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
verify(provider1Mock, never()).hasIcon("z", "test", Format.PNG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyFormatSameProviders() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/z");
|
||||
when(request.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(request.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(request.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(request.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
when(requestMock.getRequestURI()).thenReturn("/z");
|
||||
when(requestMock.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(requestMock.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(requestMock.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(requestMock.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1.getIcon("z", "test", "34", Format.SVG))
|
||||
when(provider1Mock.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1Mock.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1Mock.getIcon("z", "test", "34", Format.SVG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 1 icon: z test 34 svg".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 1 icon: z test 34 svg", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyFormatHigherPriorityOtherFormat() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/z");
|
||||
when(request.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(request.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(request.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(request.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
when(requestMock.getRequestURI()).thenReturn("/z");
|
||||
when(requestMock.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(requestMock.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(requestMock.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(requestMock.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1Mock.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1Mock.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
|
||||
when(provider2.hasIcon("z", "test", Format.PNG)).thenReturn(1);
|
||||
when(provider2.hasIcon("z", "test", Format.SVG)).thenReturn(null);
|
||||
when(provider2.getIcon("z", "test", "34", Format.PNG))
|
||||
when(provider2Mock.hasIcon("z", "test", Format.PNG)).thenReturn(1);
|
||||
when(provider2Mock.hasIcon("z", "test", Format.SVG)).thenReturn(null);
|
||||
when(provider2Mock.getIcon("z", "test", "34", Format.PNG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 2 icon: z test 34 png".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.addIconProvider(provider2);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.addIconProvider(provider2Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 2 icon: z test 34 png", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(provider2, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider2, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(provider2Mock, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider2Mock, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyFormatHigherPriorityRequestedFormat() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/z");
|
||||
when(request.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(request.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(request.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(request.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
when(requestMock.getRequestURI()).thenReturn("/z");
|
||||
when(requestMock.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(requestMock.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(requestMock.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(requestMock.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1Mock.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1Mock.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
|
||||
when(provider2.hasIcon("z", "test", Format.PNG)).thenReturn(null);
|
||||
when(provider2.hasIcon("z", "test", Format.SVG)).thenReturn(1);
|
||||
when(provider2.getIcon("z", "test", "34", Format.SVG))
|
||||
when(provider2Mock.hasIcon("z", "test", Format.PNG)).thenReturn(null);
|
||||
when(provider2Mock.hasIcon("z", "test", Format.SVG)).thenReturn(1);
|
||||
when(provider2Mock.getIcon("z", "test", "34", Format.SVG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 2 icon: z test 34 svg".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.addIconProvider(provider2);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.addIconProvider(provider2Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 2 icon: z test 34 svg", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(provider2, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider2, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(provider2Mock, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider2Mock, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyFormatNoOtherFormat() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/z");
|
||||
when(request.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(request.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(request.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(request.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
when(requestMock.getRequestURI()).thenReturn("/z");
|
||||
when(requestMock.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(requestMock.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(requestMock.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(requestMock.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("z", "test", Format.PNG)).thenReturn(null);
|
||||
when(provider1.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1.getIcon("z", "test", "34", Format.SVG))
|
||||
when(provider1Mock.hasIcon("z", "test", Format.PNG)).thenReturn(null);
|
||||
when(provider1Mock.hasIcon("z", "test", Format.SVG)).thenReturn(0);
|
||||
when(provider1Mock.getIcon("z", "test", "34", Format.SVG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 1 icon: z test 34 svg".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 1 icon: z test 34 svg", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnyFormatNoRequestedFormat() throws ServletException, IOException {
|
||||
when(request.getRequestURI()).thenReturn("/z");
|
||||
when(request.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(request.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(request.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(request.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
when(requestMock.getRequestURI()).thenReturn("/z");
|
||||
when(requestMock.getParameter(PARAM_FORMAT)).thenReturn("svg");
|
||||
when(requestMock.getParameter(PARAM_ANY_FORMAT)).thenReturn("true");
|
||||
when(requestMock.getParameter(PARAM_ICONSET)).thenReturn("test");
|
||||
when(requestMock.getParameter(PARAM_STATE)).thenReturn("34");
|
||||
|
||||
when(response.getOutputStream()).thenReturn(responseOutputStream);
|
||||
when(responseMock.getOutputStream()).thenReturn(responseOutputStream);
|
||||
|
||||
when(provider1.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1.hasIcon("z", "test", Format.SVG)).thenReturn(null);
|
||||
when(provider1.getIcon("z", "test", "34", Format.PNG))
|
||||
when(provider1Mock.hasIcon("z", "test", Format.PNG)).thenReturn(0);
|
||||
when(provider1Mock.hasIcon("z", "test", Format.SVG)).thenReturn(null);
|
||||
when(provider1Mock.getIcon("z", "test", "34", Format.PNG))
|
||||
.thenReturn(new ByteArrayInputStream("provider 1 icon: z test 34 png".getBytes()));
|
||||
|
||||
servlet.addIconProvider(provider1);
|
||||
servlet.doGet(request, response);
|
||||
servlet.addIconProvider(provider1Mock);
|
||||
servlet.doGet(requestMock, responseMock);
|
||||
|
||||
assertEquals("provider 1 icon: z test 34 png", responseOutputStream.getOutput());
|
||||
verify(response, never()).sendError(anyInt());
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
verify(responseMock, never()).sendError(anyInt());
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.PNG);
|
||||
verify(provider1Mock, atLeastOnce()).hasIcon("z", "test", Format.SVG);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -102,8 +102,7 @@ public class ChartServlet extends SmartHomeServlet {
|
||||
|
||||
@Activate
|
||||
public ChartServlet(final @Reference HttpService httpService, final @Reference HttpContext httpContext) {
|
||||
super.setHttpService(httpService);
|
||||
super.setHttpContext(httpContext);
|
||||
super(httpService, httpContext);
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
|
||||
|
||||
+4
-8
@@ -38,11 +38,11 @@ public class SafeCallerImpl implements SafeCaller {
|
||||
|
||||
private static final String SAFE_CALL_POOL_NAME = "safeCall";
|
||||
|
||||
private @NonNullByDefault({}) ScheduledExecutorService watcher;
|
||||
private @NonNullByDefault({}) SafeCallManagerImpl manager;
|
||||
private final ScheduledExecutorService watcher;
|
||||
private final SafeCallManagerImpl manager;
|
||||
|
||||
@Activate
|
||||
public void activate(@Nullable Map<String, Object> properties) {
|
||||
public SafeCallerImpl(@Nullable Map<String, Object> properties) {
|
||||
watcher = Executors.newSingleThreadScheduledExecutor();
|
||||
manager = new SafeCallManagerImpl(watcher, getScheduler(), false);
|
||||
modified(properties);
|
||||
@@ -58,11 +58,7 @@ public class SafeCallerImpl implements SafeCaller {
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
if (watcher != null) {
|
||||
watcher.shutdownNow();
|
||||
watcher = null;
|
||||
}
|
||||
manager = null;
|
||||
watcher.shutdownNow();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ public class I18nProviderImpl
|
||||
private @Nullable Locale locale;
|
||||
|
||||
// TranslationProvider
|
||||
private @NonNullByDefault({}) ResourceBundleTracker resourceBundleTracker;
|
||||
private final ResourceBundleTracker resourceBundleTracker;
|
||||
|
||||
// LocationProvider
|
||||
static final String LOCATION = "location";
|
||||
@@ -113,7 +113,7 @@ public class I18nProviderImpl
|
||||
|
||||
@Activate
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
public I18nProviderImpl(ComponentContext componentContext) {
|
||||
initDimensionMap();
|
||||
modified((Map<String, Object>) componentContext.getProperties());
|
||||
|
||||
|
||||
+8
-10
@@ -21,6 +21,7 @@ import org.openhab.core.items.ItemBuilder;
|
||||
import org.openhab.core.items.ItemBuilderFactory;
|
||||
import org.openhab.core.items.ItemFactory;
|
||||
import org.openhab.core.library.CoreItemFactory;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
@@ -36,7 +37,13 @@ import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
@Component
|
||||
public class ItemBuilderFactoryImpl implements ItemBuilderFactory {
|
||||
|
||||
private final @NonNullByDefault({}) Set<ItemFactory> itemFactories = new CopyOnWriteArraySet<>();
|
||||
private final Set<ItemFactory> itemFactories = new CopyOnWriteArraySet<>();
|
||||
|
||||
@Activate
|
||||
public ItemBuilderFactoryImpl(
|
||||
final @Reference(target = "(component.name=org.openhab.core.library.CoreItemFactory)") ItemFactory coreItemFactory) {
|
||||
itemFactories.add(coreItemFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemBuilder newItemBuilder(Item item) {
|
||||
@@ -56,13 +63,4 @@ public class ItemBuilderFactoryImpl implements ItemBuilderFactory {
|
||||
protected void removeItemFactory(ItemFactory itemFactory) {
|
||||
itemFactories.remove(itemFactory);
|
||||
}
|
||||
|
||||
@Reference(target = "(component.name=org.openhab.core.library.CoreItemFactory)")
|
||||
protected void setCoreItemFactory(ItemFactory coreItemFactory) {
|
||||
itemFactories.add(coreItemFactory);
|
||||
}
|
||||
|
||||
protected void unsetCoreItemFactory(ItemFactory coreItemFactory) {
|
||||
itemFactories.remove(coreItemFactory);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class DelegatedSchedulerImpl implements Scheduler {
|
||||
|
||||
private final Set<ScheduledCompletableFuture<?>> scheduledJobs = new HashSet<>();
|
||||
|
||||
private @NonNullByDefault({}) SchedulerImpl delegate;
|
||||
private final SchedulerImpl delegate;
|
||||
|
||||
@Activate
|
||||
public DelegatedSchedulerImpl(final @Reference SchedulerImpl scheduler) {
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.openhab.core.common.SafeCaller;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Modified;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.slf4j.Logger;
|
||||
@@ -90,7 +91,12 @@ public class NetUtil implements NetworkAddressService {
|
||||
.getScheduledPool(ThreadPoolManager.THREAD_POOL_NAME_COMMON);
|
||||
private @Nullable ScheduledFuture<?> networkInterfacePollFuture = null;
|
||||
|
||||
private @NonNullByDefault({}) SafeCaller safeCaller;
|
||||
private final SafeCaller safeCaller;
|
||||
|
||||
@Activate
|
||||
public NetUtil(final @Reference SafeCaller safeCaller) {
|
||||
this.safeCaller = safeCaller;
|
||||
}
|
||||
|
||||
@Activate
|
||||
protected void activate(Map<String, Object> props) {
|
||||
@@ -98,6 +104,7 @@ public class NetUtil implements NetworkAddressService {
|
||||
modified(props);
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
protected void deactivate() {
|
||||
lastKnownInterfaceAddresses = Collections.emptyList();
|
||||
networkAddressChangeListeners = ConcurrentHashMap.newKeySet();
|
||||
@@ -602,10 +609,6 @@ public class NetUtil implements NetworkAddressService {
|
||||
// notify each listener with a timeout of 15 seconds.
|
||||
// SafeCaller prevents bad listeners running too long or throws runtime exceptions
|
||||
for (NetworkAddressChangeListener listener : networkAddressChangeListeners) {
|
||||
if (safeCaller == null) {
|
||||
// safeCaller null must be checked between each round, in case it is deactivated
|
||||
break;
|
||||
}
|
||||
NetworkAddressChangeListener safeListener = safeCaller.create(listener, NetworkAddressChangeListener.class)
|
||||
.withTimeout(15000)
|
||||
.onException(exception -> LOGGER.debug("NetworkAddressChangeListener exception", exception))
|
||||
@@ -619,10 +622,6 @@ public class NetUtil implements NetworkAddressService {
|
||||
// notify each listener with a timeout of 15 seconds.
|
||||
// SafeCaller prevents bad listeners running too long or throws runtime exceptions
|
||||
for (NetworkAddressChangeListener listener : networkAddressChangeListeners) {
|
||||
if (safeCaller == null) {
|
||||
// safeCaller null must be checked between each round, in case it is deactivated
|
||||
break;
|
||||
}
|
||||
NetworkAddressChangeListener safeListener = safeCaller
|
||||
.create(listener, NetworkAddressChangeListener.class).withTimeout(15000)
|
||||
.onException(exception -> LOGGER.debug("NetworkAddressChangeListener exception", exception))
|
||||
@@ -649,13 +648,4 @@ public class NetUtil implements NetworkAddressService {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = safeCaller;
|
||||
}
|
||||
|
||||
protected void unsetSafeCaller(SafeCaller safeCaller) {
|
||||
this.safeCaller = null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -76,7 +76,7 @@ public class I18nProviderImplTest {
|
||||
when(componentContext.getBundleContext()).thenReturn(bundleContext);
|
||||
when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
|
||||
|
||||
i18nProviderImpl = new I18nProviderImpl();
|
||||
i18nProviderImpl = new I18nProviderImpl(componentContext);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -123,8 +123,6 @@ public class I18nProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void assertThatActivateSetsLocaleAndLocation() {
|
||||
i18nProviderImpl.activate(componentContext);
|
||||
|
||||
PointType location = i18nProviderImpl.getLocation();
|
||||
Locale setLocale = i18nProviderImpl.getLocale();
|
||||
|
||||
@@ -147,8 +145,6 @@ public class I18nProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void assertThatConfigurationChangeWorks() {
|
||||
i18nProviderImpl.activate(componentContext);
|
||||
|
||||
i18nProviderImpl.modified(buildRUConfig());
|
||||
|
||||
PointType location = i18nProviderImpl.getLocation();
|
||||
|
||||
+1
-2
@@ -43,8 +43,7 @@ public class ItemBuilderTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
initMocks(this);
|
||||
itemBuilderFactory = new ItemBuilderFactoryImpl();
|
||||
itemBuilderFactory.addItemFactory(mockFactory);
|
||||
itemBuilderFactory = new ItemBuilderFactoryImpl(mockFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-12
@@ -38,32 +38,24 @@ public class CipherTest {
|
||||
|
||||
private static final String PLAIN_TEXT = "hello world";
|
||||
|
||||
private SymmetricKeyCipher spySymmetricKeyCipher;
|
||||
private SymmetricKeyCipher symmetricKeyCipher;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException, InvalidSyntaxException, NoSuchAlgorithmException {
|
||||
spySymmetricKeyCipher = spySymmetricKeyCipher();
|
||||
symmetricKeyCipher = new SymmetricKeyCipher(mockConfigurationAdmin());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncDec() throws GeneralSecurityException {
|
||||
String cipherText = spySymmetricKeyCipher.encrypt(PLAIN_TEXT);
|
||||
String cipherText = symmetricKeyCipher.encrypt(PLAIN_TEXT);
|
||||
assertNotNull("Cipher text should not be null", cipherText);
|
||||
assertNotEquals("Cipher text should not be the same as plaintext", PLAIN_TEXT, cipherText);
|
||||
|
||||
String decryptedText = spySymmetricKeyCipher.decrypt(cipherText);
|
||||
String decryptedText = symmetricKeyCipher.decrypt(cipherText);
|
||||
assertNotNull("Decrypted text should not be null", decryptedText);
|
||||
assertEquals("Decrypted text should be same as before", PLAIN_TEXT, decryptedText);
|
||||
}
|
||||
|
||||
private SymmetricKeyCipher spySymmetricKeyCipher()
|
||||
throws IOException, InvalidSyntaxException, NoSuchAlgorithmException {
|
||||
spySymmetricKeyCipher = spy(SymmetricKeyCipher.class);
|
||||
spySymmetricKeyCipher.setConfigurationAdmin(mockConfigurationAdmin());
|
||||
spySymmetricKeyCipher.activate(); // generate encryption key
|
||||
return spySymmetricKeyCipher;
|
||||
}
|
||||
|
||||
private ConfigurationAdmin mockConfigurationAdmin() throws IOException {
|
||||
ConfigurationAdmin configurationAdmin = mock(ConfigurationAdmin.class);
|
||||
Configuration configuration = mockConfiguration();
|
||||
|
||||
+37
-38
@@ -15,6 +15,7 @@ package org.openhab.core.config.discovery.usbserial.linuxsysfs.internal;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
import static org.openhab.core.config.discovery.usbserial.linuxsysfs.internal.PollingUsbSerialScanner.PAUSE_BETWEEN_SCANS_IN_SECONDS_ATTRIBUTE;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -24,6 +25,7 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.openhab.core.config.discovery.usbserial.UsbSerialDeviceInformation;
|
||||
import org.openhab.core.config.discovery.usbserial.UsbSerialDiscoveryListener;
|
||||
import org.openhab.core.config.discovery.usbserial.linuxsysfs.testutil.UsbSerialDeviceInformationGenerator;
|
||||
@@ -37,22 +39,20 @@ public class PollingUsbSerialScannerTest {
|
||||
|
||||
private UsbSerialDeviceInformationGenerator usbDeviceInfoGenerator = new UsbSerialDeviceInformationGenerator();
|
||||
|
||||
private UsbSerialScanner usbSerialScanner;
|
||||
private PollingUsbSerialScanner pollingScanner;
|
||||
private UsbSerialDiscoveryListener discoveryListener;
|
||||
private @Mock UsbSerialDiscoveryListener discoveryListenerMock;
|
||||
private @Mock UsbSerialScanner usbSerialScannerMock;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
usbSerialScanner = mock(UsbSerialScanner.class);
|
||||
pollingScanner = new PollingUsbSerialScanner();
|
||||
pollingScanner.setUsbSerialScanner(usbSerialScanner);
|
||||
|
||||
discoveryListener = mock(UsbSerialDiscoveryListener.class);
|
||||
pollingScanner.registerDiscoveryListener(discoveryListener);
|
||||
initMocks(this);
|
||||
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
config.put(PAUSE_BETWEEN_SCANS_IN_SECONDS_ATTRIBUTE, "1");
|
||||
pollingScanner.modified(config);
|
||||
|
||||
pollingScanner = new PollingUsbSerialScanner(config, usbSerialScannerMock);
|
||||
|
||||
pollingScanner.registerDiscoveryListener(discoveryListenerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +60,7 @@ public class PollingUsbSerialScannerTest {
|
||||
// Wait a little more than one second to give background scanning a chance to kick in.
|
||||
Thread.sleep(1200);
|
||||
|
||||
verify(usbSerialScanner, never()).scan();
|
||||
verify(usbSerialScannerMock, never()).scan();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,19 +69,19 @@ public class PollingUsbSerialScannerTest {
|
||||
UsbSerialDeviceInformation usb2 = usbDeviceInfoGenerator.generate();
|
||||
UsbSerialDeviceInformation usb3 = usbDeviceInfoGenerator.generate();
|
||||
|
||||
when(usbSerialScanner.scan()).thenReturn(new HashSet<>(asList(usb1, usb2)));
|
||||
when(usbSerialScanner.canPerformScans()).thenReturn(true);
|
||||
when(usbSerialScannerMock.scan()).thenReturn(new HashSet<>(asList(usb1, usb2)));
|
||||
when(usbSerialScannerMock.canPerformScans()).thenReturn(true);
|
||||
|
||||
pollingScanner.doSingleScan();
|
||||
|
||||
// Expectation: discovery listener called with newly discovered devices usb1 and usb2; not called with removed
|
||||
// devices.
|
||||
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceDiscovered(usb1);
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceDiscovered(usb2);
|
||||
verify(discoveryListener, never()).usbSerialDeviceDiscovered(usb3);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceDiscovered(usb1);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceDiscovered(usb2);
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceDiscovered(usb3);
|
||||
|
||||
verify(discoveryListener, never()).usbSerialDeviceRemoved(any(UsbSerialDeviceInformation.class));
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceRemoved(any(UsbSerialDeviceInformation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,26 +90,26 @@ public class PollingUsbSerialScannerTest {
|
||||
UsbSerialDeviceInformation usb2 = usbDeviceInfoGenerator.generate();
|
||||
UsbSerialDeviceInformation usb3 = usbDeviceInfoGenerator.generate();
|
||||
|
||||
when(usbSerialScanner.scan()).thenReturn(new HashSet<>(asList(usb1, usb2)))
|
||||
when(usbSerialScannerMock.scan()).thenReturn(new HashSet<>(asList(usb1, usb2)))
|
||||
.thenReturn(new HashSet<>(asList(usb2, usb3)));
|
||||
when(usbSerialScanner.canPerformScans()).thenReturn(true);
|
||||
when(usbSerialScannerMock.canPerformScans()).thenReturn(true);
|
||||
|
||||
pollingScanner.unregisterDiscoveryListener(discoveryListener);
|
||||
pollingScanner.unregisterDiscoveryListener(discoveryListenerMock);
|
||||
pollingScanner.doSingleScan();
|
||||
|
||||
pollingScanner.registerDiscoveryListener(discoveryListener);
|
||||
pollingScanner.registerDiscoveryListener(discoveryListenerMock);
|
||||
pollingScanner.doSingleScan();
|
||||
|
||||
// Expectation: discovery listener called once for removing usb1, and once for adding usb2/usb3 each.
|
||||
|
||||
verify(discoveryListener, never()).usbSerialDeviceDiscovered(usb1);
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceRemoved(usb1);
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceDiscovered(usb1);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceRemoved(usb1);
|
||||
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceDiscovered(usb2);
|
||||
verify(discoveryListener, never()).usbSerialDeviceRemoved(usb2);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceDiscovered(usb2);
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceRemoved(usb2);
|
||||
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceDiscovered(usb3);
|
||||
verify(discoveryListener, never()).usbSerialDeviceRemoved(usb3);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceDiscovered(usb3);
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceRemoved(usb3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,11 +118,10 @@ public class PollingUsbSerialScannerTest {
|
||||
UsbSerialDeviceInformation usb2 = usbDeviceInfoGenerator.generate();
|
||||
UsbSerialDeviceInformation usb3 = usbDeviceInfoGenerator.generate();
|
||||
|
||||
when(usbSerialScanner.scan()).thenReturn(new HashSet<>(asList(usb1, usb2)))
|
||||
when(usbSerialScannerMock.scan()).thenReturn(new HashSet<>(asList(usb1, usb2)))
|
||||
.thenReturn(new HashSet<>(asList(usb2, usb3)));
|
||||
when(usbSerialScanner.canPerformScans()).thenReturn(true);
|
||||
when(usbSerialScannerMock.canPerformScans()).thenReturn(true);
|
||||
|
||||
pollingScanner.activate(new HashMap<>());
|
||||
pollingScanner.startBackgroundScanning();
|
||||
|
||||
Thread.sleep(1500);
|
||||
@@ -131,20 +130,20 @@ public class PollingUsbSerialScannerTest {
|
||||
|
||||
// Expectation: discovery listener called once for each discovered device, and once for removal of usb1.
|
||||
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceDiscovered(usb1);
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceRemoved(usb1);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceDiscovered(usb1);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceRemoved(usb1);
|
||||
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceDiscovered(usb2);
|
||||
verify(discoveryListener, never()).usbSerialDeviceRemoved(usb2);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceDiscovered(usb2);
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceRemoved(usb2);
|
||||
|
||||
verify(discoveryListener, times(1)).usbSerialDeviceDiscovered(usb3);
|
||||
verify(discoveryListener, never()).usbSerialDeviceRemoved(usb3);
|
||||
verify(discoveryListenerMock, times(1)).usbSerialDeviceDiscovered(usb3);
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceRemoved(usb3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoBackgroundScanningWhenNoScansPossible() throws IOException, InterruptedException {
|
||||
when(usbSerialScanner.scan()).thenReturn(new HashSet<>(asList(usbDeviceInfoGenerator.generate())));
|
||||
when(usbSerialScanner.canPerformScans()).thenReturn(false);
|
||||
when(usbSerialScannerMock.scan()).thenReturn(new HashSet<>(asList(usbDeviceInfoGenerator.generate())));
|
||||
when(usbSerialScannerMock.canPerformScans()).thenReturn(false);
|
||||
|
||||
pollingScanner.startBackgroundScanning();
|
||||
|
||||
@@ -154,6 +153,6 @@ public class PollingUsbSerialScannerTest {
|
||||
|
||||
// Expectation: discovery listener never called, as usbSerialScanner indicates that no scans possible
|
||||
|
||||
verify(discoveryListener, never()).usbSerialDeviceDiscovered(any(UsbSerialDeviceInformation.class));
|
||||
verify(discoveryListenerMock, never()).usbSerialDeviceDiscovered(any(UsbSerialDeviceInformation.class));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -95,13 +95,12 @@ public class SafeCallerImplTest extends JavaTest {
|
||||
public void setup() {
|
||||
initMocks(this);
|
||||
scheduler = QueueingThreadPoolExecutor.createInstance(name.getMethodName(), THREAD_POOL_SIZE);
|
||||
safeCaller = new SafeCallerImpl() {
|
||||
safeCaller = new SafeCallerImpl(null) {
|
||||
@Override
|
||||
protected ExecutorService getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
};
|
||||
safeCaller.activate(null);
|
||||
|
||||
assertTrue(BLOCK > TIMEOUT + GRACE);
|
||||
assertTrue(GRACE < TIMEOUT);
|
||||
|
||||
+7
-11
@@ -36,6 +36,7 @@ import org.openhab.core.events.EventPublisher;
|
||||
import org.openhab.core.i18n.UnitProvider;
|
||||
import org.openhab.core.items.Item;
|
||||
import org.openhab.core.items.ItemRegistry;
|
||||
import org.openhab.core.items.ItemStateConverter;
|
||||
import org.openhab.core.items.events.ItemCommandEvent;
|
||||
import org.openhab.core.items.events.ItemEventFactory;
|
||||
import org.openhab.core.library.CoreItemFactory;
|
||||
@@ -136,6 +137,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
||||
private @Mock @NonNullByDefault({}) ChannelTypeRegistry channelTypeRegistryMock;
|
||||
private @Mock @NonNullByDefault({}) EventPublisher eventPublisherMock;
|
||||
private @Mock @NonNullByDefault({}) ItemRegistry itemRegistryMock;
|
||||
private @Mock @NonNullByDefault({}) ItemStateConverter itemStateConverterMock;
|
||||
private @Mock @NonNullByDefault({}) ProfileAdvisor profileAdvisorMock;
|
||||
private @Mock @NonNullByDefault({}) ProfileFactory profileFactoryMock;
|
||||
private @Mock @NonNullByDefault({}) StateProfile stateProfileMock;
|
||||
@@ -146,6 +148,9 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
||||
private @NonNullByDefault({}) CommunicationManager manager;
|
||||
private @NonNullByDefault({}) SafeCaller safeCaller;
|
||||
|
||||
private ItemChannelLinkRegistryAdvanced iclRegistry = new ItemChannelLinkRegistryAdvanced(thingRegistryMock,
|
||||
itemRegistryMock);
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
initMocks(this);
|
||||
@@ -156,10 +161,8 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
||||
SystemProfileFactory profileFactory = getService(ProfileTypeProvider.class, SystemProfileFactory.class);
|
||||
assertNotNull(profileFactory);
|
||||
|
||||
manager = new CommunicationManager();
|
||||
manager.setEventPublisher(eventPublisherMock);
|
||||
manager.setDefaultProfileFactory(profileFactory);
|
||||
manager.setSafeCaller(safeCaller);
|
||||
manager = new CommunicationManager(autoUpdateManagerMock, channelTypeRegistryMock, profileFactory, iclRegistry,
|
||||
itemRegistryMock, itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock);
|
||||
|
||||
doAnswer(invocation -> {
|
||||
switch (((Channel) invocation.getArguments()[0]).getKind()) {
|
||||
@@ -187,8 +190,6 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
||||
manager.addProfileFactory(profileFactoryMock);
|
||||
manager.addProfileAdvisor(profileAdvisorMock);
|
||||
|
||||
ItemChannelLinkRegistryAdvanced iclRegistry = new ItemChannelLinkRegistryAdvanced(thingRegistryMock,
|
||||
itemRegistryMock);
|
||||
iclRegistry.addProvider(new ItemChannelLinkProvider() {
|
||||
@Override
|
||||
public void addProviderChangeListener(ProviderChangeListener<ItemChannelLink> listener) {
|
||||
@@ -204,26 +205,21 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
|
||||
LINK_4_S4);
|
||||
}
|
||||
});
|
||||
manager.setItemChannelLinkRegistry(iclRegistry);
|
||||
|
||||
when(itemRegistryMock.get(eq(ITEM_NAME_1))).thenReturn(ITEM_1);
|
||||
when(itemRegistryMock.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
|
||||
when(itemRegistryMock.get(eq(ITEM_NAME_3))).thenReturn(ITEM_3);
|
||||
when(itemRegistryMock.get(eq(ITEM_NAME_4))).thenReturn(ITEM_4);
|
||||
manager.setItemRegistry(itemRegistryMock);
|
||||
|
||||
ChannelType channelType4 = mock(ChannelType.class);
|
||||
when(channelType4.getItemType()).thenReturn("Number:Temperature");
|
||||
|
||||
when(channelTypeRegistryMock.getChannelType(CHANNEL_TYPE_UID_4)).thenReturn(channelType4);
|
||||
manager.setChannelTypeRegistry(channelTypeRegistryMock);
|
||||
|
||||
THING.setHandler(thingHandlerMock);
|
||||
|
||||
when(thingRegistryMock.get(eq(THING_UID))).thenReturn(THING);
|
||||
manager.setThingRegistry(thingRegistryMock);
|
||||
manager.addItemFactory(new CoreItemFactory());
|
||||
manager.setAutoUpdateManager(autoUpdateManagerMock);
|
||||
|
||||
UnitProvider unitProvider = mock(UnitProvider.class);
|
||||
when(unitProvider.getUnit(Temperature.class)).thenReturn(SIUnits.CELSIUS);
|
||||
|
||||
+4
-16
@@ -142,31 +142,21 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest {
|
||||
props3.put(Thing.PROPERTY_VENDOR, VENDOR2);
|
||||
thing3 = ThingBuilder.create(THING_TYPE_UID2, THING3_ID).withProperties(props3).build();
|
||||
|
||||
firmwareUpdateService = new FirmwareUpdateServiceImpl();
|
||||
|
||||
SafeCaller safeCaller = getService(SafeCaller.class);
|
||||
assertNotNull(safeCaller);
|
||||
|
||||
firmwareUpdateService.setSafeCaller(safeCaller);
|
||||
|
||||
firmwareUpdateService.setFirmwareRegistry(mockFirmwareRegistry);
|
||||
firmwareUpdateService = new FirmwareUpdateServiceImpl(bundleResolver, mockConfigDescriptionValidator,
|
||||
mockPublisher, mockFirmwareRegistry, mockTranslationProvider, mockLocaleProvider, safeCaller);
|
||||
|
||||
handler1 = addHandler(thing1);
|
||||
handler2 = addHandler(thing2);
|
||||
handler3 = addHandler(thing3);
|
||||
|
||||
firmwareUpdateService.setEventPublisher(mockPublisher);
|
||||
|
||||
when(mockLocaleProvider.getLocale()).thenReturn(Locale.ENGLISH);
|
||||
firmwareUpdateService.setLocaleProvider(mockLocaleProvider);
|
||||
|
||||
initialFirmwareRegistryMocking();
|
||||
|
||||
when(bundleResolver.resolveBundle(any())).thenReturn(mock(Bundle.class));
|
||||
firmwareUpdateService.setBundleResolver(bundleResolver);
|
||||
|
||||
firmwareUpdateService.setTranslationProvider(mockTranslationProvider);
|
||||
firmwareUpdateService.setConfigDescriptionValidator(mockConfigDescriptionValidator);
|
||||
}
|
||||
|
||||
private void initialFirmwareRegistryMocking() {
|
||||
@@ -295,8 +285,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest {
|
||||
|
||||
});
|
||||
|
||||
mockPublisher = mock(EventPublisher.class);
|
||||
firmwareUpdateService.setEventPublisher(mockPublisher);
|
||||
reset(mockPublisher);
|
||||
|
||||
// Simulate addition of extra firmware provider
|
||||
when(mockFirmwareRegistry.getFirmware(eq(thing2), eq(VALPHA))).thenReturn(null);
|
||||
@@ -321,8 +310,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest {
|
||||
assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw113);
|
||||
});
|
||||
|
||||
mockPublisher = mock(EventPublisher.class);
|
||||
firmwareUpdateService.setEventPublisher(mockPublisher);
|
||||
reset(mockPublisher);
|
||||
|
||||
// Simulate removed firmware provider - get back everything as it was initially
|
||||
initialFirmwareRegistryMocking();
|
||||
|
||||
Reference in New Issue
Block a user