|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.grid.data; |
| 19 | + |
| 20 | +import static org.assertj.core.api.Assertions.assertThat; |
| 21 | + |
| 22 | +import org.junit.Test; |
| 23 | +import org.openqa.selenium.ImmutableCapabilities; |
| 24 | +import org.openqa.selenium.Platform; |
| 25 | +import org.openqa.selenium.remote.CapabilityType; |
| 26 | + |
| 27 | +public class DefaultSlotMatcherTest { |
| 28 | + |
| 29 | + private final DefaultSlotMatcher slotMatcher = new DefaultSlotMatcher(); |
| 30 | + |
| 31 | + @Test |
| 32 | + public void fullMatch() { |
| 33 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 34 | + CapabilityType.BROWSER_NAME, "chrome", |
| 35 | + CapabilityType.BROWSER_VERSION, "80", |
| 36 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 37 | + ); |
| 38 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 39 | + CapabilityType.BROWSER_NAME, "chrome", |
| 40 | + CapabilityType.BROWSER_VERSION, "80", |
| 41 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 42 | + ); |
| 43 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isTrue(); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void matchesBrowserAndVersion() { |
| 48 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 49 | + CapabilityType.BROWSER_NAME, "chrome", |
| 50 | + CapabilityType.BROWSER_VERSION, "80", |
| 51 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 52 | + ); |
| 53 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 54 | + CapabilityType.BROWSER_NAME, "chrome", |
| 55 | + CapabilityType.BROWSER_VERSION, "80" |
| 56 | + ); |
| 57 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isTrue(); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void matchesBrowser() { |
| 62 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 63 | + CapabilityType.BROWSER_NAME, "chrome", |
| 64 | + CapabilityType.BROWSER_VERSION, "80", |
| 65 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 66 | + ); |
| 67 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 68 | + CapabilityType.BROWSER_NAME, "chrome" |
| 69 | + ); |
| 70 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isTrue(); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void platformDoesNotMatch() { |
| 75 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 76 | + CapabilityType.BROWSER_NAME, "chrome", |
| 77 | + CapabilityType.BROWSER_VERSION, "80", |
| 78 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 79 | + ); |
| 80 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 81 | + CapabilityType.BROWSER_NAME, "chrome", |
| 82 | + CapabilityType.BROWSER_VERSION, "80", |
| 83 | + CapabilityType.PLATFORM_NAME, Platform.MAC |
| 84 | + ); |
| 85 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isFalse(); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void browserDoesNotMatch() { |
| 90 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 91 | + CapabilityType.BROWSER_NAME, "chrome", |
| 92 | + CapabilityType.BROWSER_VERSION, "80", |
| 93 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 94 | + ); |
| 95 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 96 | + CapabilityType.BROWSER_NAME, "firefox", |
| 97 | + CapabilityType.BROWSER_VERSION, "80", |
| 98 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 99 | + ); |
| 100 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isFalse(); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void browserVersionDoesNotMatch() { |
| 105 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 106 | + CapabilityType.BROWSER_NAME, "chrome", |
| 107 | + CapabilityType.BROWSER_VERSION, "80", |
| 108 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 109 | + ); |
| 110 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 111 | + CapabilityType.BROWSER_NAME, "chrome", |
| 112 | + CapabilityType.BROWSER_VERSION, "84", |
| 113 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 114 | + ); |
| 115 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isFalse(); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void requestedPlatformDoesNotMatch() { |
| 120 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 121 | + CapabilityType.BROWSER_NAME, "chrome", |
| 122 | + CapabilityType.BROWSER_VERSION, "80" |
| 123 | + ); |
| 124 | + |
| 125 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 126 | + CapabilityType.BROWSER_NAME, "chrome", |
| 127 | + CapabilityType.BROWSER_VERSION, "84", |
| 128 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 129 | + ); |
| 130 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isFalse(); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void requestedBrowserVersionDoesNotMatch() { |
| 135 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 136 | + CapabilityType.BROWSER_NAME, "chrome", |
| 137 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 138 | + ); |
| 139 | + |
| 140 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 141 | + CapabilityType.BROWSER_NAME, "chrome", |
| 142 | + CapabilityType.BROWSER_VERSION, "84", |
| 143 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 144 | + ); |
| 145 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isFalse(); |
| 146 | + } |
| 147 | + |
| 148 | + @Test |
| 149 | + public void matchesWithJWPCaps() { |
| 150 | + ImmutableCapabilities stereotype = new ImmutableCapabilities( |
| 151 | + CapabilityType.BROWSER_NAME, "chrome", |
| 152 | + CapabilityType.BROWSER_VERSION, "80", |
| 153 | + CapabilityType.PLATFORM_NAME, Platform.WINDOWS |
| 154 | + ); |
| 155 | + ImmutableCapabilities capabilities = new ImmutableCapabilities( |
| 156 | + CapabilityType.BROWSER_NAME, "chrome", |
| 157 | + CapabilityType.VERSION, "80", |
| 158 | + CapabilityType.PLATFORM, Platform.WINDOWS |
| 159 | + ); |
| 160 | + assertThat(slotMatcher.matches(capabilities, stereotype)).isTrue(); |
| 161 | + } |
| 162 | +} |
0 commit comments