|
31 | 31 | * Basic test cases for {@link ChannelEventTriggerHandler} |
32 | 32 | * |
33 | 33 | * @author Thomas Weißschuh - Initial contribution |
| 34 | + * @author Jimmy Tanagra - Add test cases for wildcard channel matching and channel event matching |
34 | 35 | */ |
35 | 36 | @NonNullByDefault |
36 | 37 | class ChannelEventTriggerHandlerTest { |
@@ -61,4 +62,97 @@ public void testSubstringMatchingChannelIsNotApplied() { |
61 | 62 |
|
62 | 63 | assertFalse(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
63 | 64 | } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testWildcardAsteriskMatchingChannelIsApplied() { |
| 68 | + when(moduleMock.getConfiguration()) |
| 69 | + .thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, "foo:bar:baz:*"))); |
| 70 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 71 | + |
| 72 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testWildcardAsteriskNonMatchingChannelIsNotApplied() { |
| 77 | + when(moduleMock.getConfiguration()) |
| 78 | + .thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, "foo:bar:baz:*"))); |
| 79 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 80 | + |
| 81 | + assertFalse(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baa:quux")))); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void testWildcardQuestionMarkMatchingChannelIsApplied() { |
| 86 | + when(moduleMock.getConfiguration()) |
| 87 | + .thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, "foo:bar:baz:quu?"))); |
| 88 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 89 | + |
| 90 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void testWildcardQuestionMarkNonMatchingChannelIsNotApplied() { |
| 95 | + when(moduleMock.getConfiguration()) |
| 96 | + .thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, "foo:bar:baz:quu?"))); |
| 97 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 98 | + |
| 99 | + assertFalse( |
| 100 | + handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quuxx")))); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testMatchingChannelEventIsApplied() { |
| 105 | + when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, |
| 106 | + "foo:bar:baz:quux", ChannelEventTriggerHandler.CFG_CHANNEL_EVENT, "PRESSED"))); |
| 107 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 108 | + |
| 109 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void testNonMatchingChannelEventIsNotApplied() { |
| 114 | + when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, |
| 115 | + "foo:bar:baz:quux", ChannelEventTriggerHandler.CFG_CHANNEL_EVENT, "RELEASED"))); |
| 116 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 117 | + |
| 118 | + assertFalse(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void testBlankChannelEventMatchesAllEvents() { |
| 123 | + when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, |
| 124 | + "foo:bar:baz:quux", ChannelEventTriggerHandler.CFG_CHANNEL_EVENT, ""))); |
| 125 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 126 | + |
| 127 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 128 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("RELEASED", new ChannelUID("foo:bar:baz:quux")))); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + public void testOmittedChannelEventMatchesAllEvents() { |
| 133 | + when(moduleMock.getConfiguration()) |
| 134 | + .thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, "foo:bar:baz:quux"))); |
| 135 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 136 | + |
| 137 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 138 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("RELEASED", new ChannelUID("foo:bar:baz:quux")))); |
| 139 | + } |
| 140 | + |
| 141 | + @Test |
| 142 | + public void testWildcardChannelWithMatchingChannelEventIsApplied() { |
| 143 | + when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, |
| 144 | + "foo:bar:baz:*", ChannelEventTriggerHandler.CFG_CHANNEL_EVENT, "PRESSED"))); |
| 145 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 146 | + |
| 147 | + assertTrue(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + public void testWildcardChannelWithNonMatchingChannelEventIsNotApplied() { |
| 152 | + when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of(ChannelEventTriggerHandler.CFG_CHANNEL, |
| 153 | + "foo:bar:baz:*", ChannelEventTriggerHandler.CFG_CHANNEL_EVENT, "RELEASED"))); |
| 154 | + handler = new ChannelEventTriggerHandler(moduleMock, contextMock); |
| 155 | + |
| 156 | + assertFalse(handler.apply(ThingEventFactory.createTriggerEvent("PRESSED", new ChannelUID("foo:bar:baz:quux")))); |
| 157 | + } |
64 | 158 | } |
0 commit comments