rspec-openhab-scripting 0.0.15-java → 0.0.16-java
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5dd7ea9915aa3edecf86f75d7331bfe77ad3fbbbee4c278fd130895e4bc1e6c
|
4
|
+
data.tar.gz: 489db2879bf94009c027fcbb87572ae5b3834d31fab17f473cddc2fdecfebdfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 967d33cd26a809179324637df7ebb9243ec901ae6c75aaa97a1615a6f699082bb83050727502c326bcf85732f86521f93ce253877306d8e6cf86b4ed84030708
|
7
|
+
data.tar.gz: 375c3ebb1c64176b3da00a8489b8b9574e5636d767a2cb981100dc3b6b3128cbf23fc8b7ab9998ed3b7154a9d0754be6f349d3711ef326e7714ec360cac89732
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module OpenHAB
|
5
|
+
module Core
|
6
|
+
module Mocks
|
7
|
+
class PersistenceService
|
8
|
+
include org.openhab.core.persistence.ModifiablePersistenceService
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
class HistoricItem
|
12
|
+
include org.openhab.core.persistence.HistoricItem
|
13
|
+
|
14
|
+
attr_reader :timestamp, :state, :name
|
15
|
+
|
16
|
+
def initialize(timestamp, state, name)
|
17
|
+
@timestamp = timestamp
|
18
|
+
@state = state
|
19
|
+
@name = name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :id
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@id = "default"
|
27
|
+
reset
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
31
|
+
@data = Hash.new { |h, k| h[k] = [] }
|
32
|
+
end
|
33
|
+
|
34
|
+
def store(item, date = nil, state = nil)
|
35
|
+
date = nil if date.is_a?(String) # alias overload
|
36
|
+
state ||= item.state
|
37
|
+
date ||= ZonedDateTime.now
|
38
|
+
|
39
|
+
new_item = HistoricItem.new(date, state, item.name)
|
40
|
+
|
41
|
+
item_history = @data[item.name]
|
42
|
+
|
43
|
+
insert_index = item_history.bsearch_index do |i|
|
44
|
+
i.timestamp.compare_to(date).positive?
|
45
|
+
end
|
46
|
+
|
47
|
+
return item_history << new_item unless insert_index
|
48
|
+
|
49
|
+
return item_history[insert_index].state = state if item_history[insert_index].timestamp == date
|
50
|
+
|
51
|
+
item_history.insert(insert_index, new_item)
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove(filter)
|
55
|
+
query_internal(filter) do |item_history, index|
|
56
|
+
historic_item = item_history.delete_at(index)
|
57
|
+
@data.delete(historic_item.name) if item_history.empty?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def query(filter)
|
62
|
+
result = []
|
63
|
+
|
64
|
+
query_internal(filter) do |item_history, index|
|
65
|
+
result << item_history[index]
|
66
|
+
|
67
|
+
return result if filter.page_number.zero? && result.length == filter.page_size && filter.item_name
|
68
|
+
end
|
69
|
+
|
70
|
+
result.sort_by! { |hi| hi.timestamp.to_instant.to_epoch_milli } unless filter.item_name
|
71
|
+
|
72
|
+
unless filter.page_number.zero?
|
73
|
+
result = result.slice(filter.page_number * filter.page_size, filter.page_size)
|
74
|
+
end
|
75
|
+
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_item_info # rubocop:disable Naming/AccessorMethodName must match Java interface
|
80
|
+
@data.map do |(n, entries)|
|
81
|
+
[n, entries.length, entries.first.timestamp, entries.last.timestamp]
|
82
|
+
end.to_set
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_default_strategies # rubocop:disable Naming/AccessorMethodName must match Java interface
|
86
|
+
[org.openhab.core.persistence.strategy.PersistenceStrategy::Globals::CHANGE]
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def query_internal(filter, &block)
|
92
|
+
if filter.item_name
|
93
|
+
return unless @data.key?(filter.item_name)
|
94
|
+
|
95
|
+
query_item_internal(@data[filter.item_name], filter, &block)
|
96
|
+
else
|
97
|
+
@data.each_value do |item_history|
|
98
|
+
query_item_internal(item_history, filter, &block)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def query_item_internal(item_history, filter)
|
104
|
+
first_index = 0
|
105
|
+
last_index = item_history.length
|
106
|
+
|
107
|
+
if filter.begin_date
|
108
|
+
first_index = item_history.bsearch_index do |i|
|
109
|
+
i.timestamp.compare_to(filter.begin_date).positive?
|
110
|
+
end
|
111
|
+
return if first_index.nil?
|
112
|
+
end
|
113
|
+
|
114
|
+
if filter.end_date
|
115
|
+
last_index = item_history.bsearch_index do |i|
|
116
|
+
i.timestamp.compare_to(filter.end_date).positive?
|
117
|
+
end
|
118
|
+
return if last_index.zero?
|
119
|
+
|
120
|
+
last_index ||= item_history.length
|
121
|
+
end
|
122
|
+
|
123
|
+
range = first_index...last_index
|
124
|
+
|
125
|
+
operator = filter.operator.symbol
|
126
|
+
operator = "==" if operator == "="
|
127
|
+
|
128
|
+
block = lambda do |i|
|
129
|
+
next if filter.state && !item_history[i].state.send(operator, filter.state)
|
130
|
+
|
131
|
+
yield(item_history, i)
|
132
|
+
end
|
133
|
+
|
134
|
+
if filter.ordering == filter.class::Ordering::DESCENDING
|
135
|
+
range.reverse_each(&block)
|
136
|
+
else
|
137
|
+
range.each(&block)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -400,6 +400,17 @@ module OpenHAB
|
|
400
400
|
el = org.openhab.core.io.monitor.internal.EventLogger.new(rs)
|
401
401
|
em.add_event_subscriber(el)
|
402
402
|
el.on_ready_marker_added(nil)
|
403
|
+
|
404
|
+
# set up persistence
|
405
|
+
psr = org.openhab.core.persistence.internal.PersistenceServiceRegistryImpl.new
|
406
|
+
org.openhab.core.persistence.extensions.PersistenceExtensions.new(psr)
|
407
|
+
psr.activate("default" => "default")
|
408
|
+
ps = RSpec::OpenHAB::Core::Mocks::PersistenceService.instance
|
409
|
+
psr.add_persistence_service(ps)
|
410
|
+
|
411
|
+
pm = org.openhab.core.persistence.internal.PersistenceManagerImpl.new(nil, ir, sc, rs)
|
412
|
+
pm.add_persistence_service(ps)
|
413
|
+
pm.on_ready_marker_added(nil)
|
403
414
|
end
|
404
415
|
end
|
405
416
|
end
|
data/lib/rspec/openhab/hooks.rb
CHANGED
@@ -42,9 +42,11 @@ maven_require do
|
|
42
42
|
require "jar org.openhab.core.bundles, org.openhab.core.model.core, #{openhab_version}"
|
43
43
|
require "jar org.openhab.core.bundles, org.openhab.core.model.item, #{openhab_version}"
|
44
44
|
require "jar org.openhab.core.bundles, org.openhab.core.model.script, #{openhab_version}"
|
45
|
+
require "jar org.openhab.core.bundles, org.openhab.core.persistence, #{openhab_version}"
|
45
46
|
require "jar org.openhab.core.bundles, org.openhab.core.semantics, #{openhab_version}"
|
46
47
|
require "jar org.openhab.core.bundles, org.openhab.core.thing, #{openhab_version}"
|
47
48
|
end
|
49
|
+
java_import org.openhab.core.persistence.extensions.PersistenceExtensions
|
48
50
|
|
49
51
|
require "openhab/version"
|
50
52
|
|
@@ -64,6 +66,7 @@ require "rspec/openhab/core/logger"
|
|
64
66
|
# during testing, we don't want "regular" output from rules
|
65
67
|
OpenHAB::Log.logger("org.openhab.automation.jruby.runtime").level = :warn
|
66
68
|
OpenHAB::Log.logger("org.openhab.automation.jruby.logger").level = :warn
|
69
|
+
require "rspec/openhab/core/mocks/persistence_service"
|
67
70
|
require "openhab/dsl/imports"
|
68
71
|
OpenHAB::DSL::Imports.api = api
|
69
72
|
OpenHAB::DSL::Imports.import_presets
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-openhab-scripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- lib/rspec/openhab/core/item_proxy.rb
|
193
193
|
- lib/rspec/openhab/core/load_path.rb
|
194
194
|
- lib/rspec/openhab/core/logger.rb
|
195
|
+
- lib/rspec/openhab/core/mocks/persistence_service.rb
|
195
196
|
- lib/rspec/openhab/core/openhab_setup.rb
|
196
197
|
- lib/rspec/openhab/core/osgi.rb
|
197
198
|
- lib/rspec/openhab/core/script_handling.rb
|
@@ -244,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
245
|
version: '0'
|
245
246
|
requirements:
|
246
247
|
- jar ch.qos.logback, logback-classic, 1.2.9
|
247
|
-
rubygems_version: 3.
|
248
|
+
rubygems_version: 3.2.29
|
248
249
|
signing_key:
|
249
250
|
specification_version: 4
|
250
251
|
summary: Library testing OpenHAB ruby rules with rspec.
|