Skip to content

Commit

Permalink
Adding more tests for DefaultCapabilityMatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Nov 10, 2017
1 parent ec1e276 commit 26b68e6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public DefaultCapabilityMatcher() {
toConsider.add(CapabilityType.VERSION);
toConsider.add(CapabilityType.BROWSER_VERSION);
toConsider.add(CapabilityType.APPLICATION_NAME);

}

/**
Expand Down Expand Up @@ -100,7 +99,7 @@ public boolean matches(Map<String, Object> nodeCapability, Map<String, Object> r
return true;
}

Platform extractPlatform(Object o) {
private Platform extractPlatform(Object o) {
if (o == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,27 @@
import java.util.HashMap;
import java.util.Map;


public class DefaultCapabilityMatcherTest {

private DefaultCapabilityMatcher matcher = new DefaultCapabilityMatcher();


@Test
public void smokeTest() {
Map<String, Object> firefox = ImmutableMap.of(CapabilityType.BROWSER_NAME, "B", CapabilityType.PLATFORM, "XP");
Map<String, Object> firefox = ImmutableMap.of(
CapabilityType.BROWSER_NAME, "B",
CapabilityType.PLATFORM, "XP");
Map<String, Object> tl = new HashMap<String, Object>() {{
put(CapabilityType.APPLICATION_NAME, "A");
put(CapabilityType.VERSION, null);
}};

Map<String, Object> firefox2 = ImmutableMap.of(CapabilityType.BROWSER_NAME, "B", CapabilityType.PLATFORM, "Vista", CapabilityType.VERSION, "3.6");
Map<String, Object> tl2 = ImmutableMap.of(CapabilityType.APPLICATION_NAME, "A", CapabilityType.VERSION, "8.5.100.7");
Map<String, Object> firefox2 = ImmutableMap.of(
CapabilityType.BROWSER_NAME, "B",
CapabilityType.PLATFORM, "win7",
CapabilityType.VERSION, "3.6");
Map<String, Object> tl2 = ImmutableMap.of(
CapabilityType.APPLICATION_NAME, "A",
CapabilityType.VERSION, "8.5.100.7");

assertTrue(matcher.matches(tl, tl));
assertFalse(matcher.matches(tl, tl2));
Expand All @@ -55,7 +60,7 @@ public void smokeTest() {
assertTrue(matcher.matches(firefox, firefox));
assertFalse(matcher.matches(firefox, firefox2));
assertFalse(matcher.matches(firefox2, firefox));
assertFalse(matcher.matches(firefox, firefox2));
assertTrue(matcher.matches(firefox2, firefox2));

assertFalse(matcher.matches(tl, null));
assertFalse(matcher.matches(null, null));
Expand All @@ -64,19 +69,32 @@ public void smokeTest() {
}

@Test
public void platformMatchingTest() {
Platform p = Platform.WINDOWS;
public void genericPlatformMatchingTest() {
Map<String, Object> requested = ImmutableMap.of(CapabilityType.PLATFORM, Platform.WINDOWS);

assertTrue(matcher.extractPlatform("WINDOWS") == p);
assertTrue(matcher.extractPlatform("xp").is(p));
assertTrue(matcher.extractPlatform("windows VISTA").is(p));
assertTrue(matcher.extractPlatform("windows 7").is(p));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "WINDOWS"), requested));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "xp"), requested));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "windows VISTA"), requested));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "windows 7"), requested));

assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "linux"), requested));
}

@Test
public void specificPlatformMatchingTest() {
Map<String, Object> requested = ImmutableMap.of(CapabilityType.PLATFORM, Platform.XP);

assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "xp"), requested));

assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "WINDOWS"), requested));
assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "windows VISTA"), requested));
assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "windows 7"), requested));

assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "linux"), requested));
}

@Test
public void nullEmptyValues() {

Map<String, Object> requested = new HashMap<>();
requested.put(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
requested.put(CapabilityType.PLATFORM, null);
Expand All @@ -88,17 +106,28 @@ public void nullEmptyValues() {
node.put(CapabilityType.VERSION, "3.6");

assertTrue(matcher.matches(node, requested));


}

@Test
public void versionTests() {
DefaultCapabilityMatcher matcher = new DefaultCapabilityMatcher();

assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.VERSION, "50"), ImmutableMap.of(CapabilityType.VERSION, "50")));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.VERSION, "50"), ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50")));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50"), ImmutableMap.of(CapabilityType.VERSION, "50")));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50"), ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50")));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.VERSION, "50"),
ImmutableMap.of(CapabilityType.VERSION, "50")));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.VERSION, "50"),
ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50")));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50"),
ImmutableMap.of(CapabilityType.VERSION, "50")));
assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50"),
ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50")));

assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.VERSION, "50"),
ImmutableMap.of(CapabilityType.VERSION, "45")));
assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.VERSION, "50"),
ImmutableMap.of(CapabilityType.BROWSER_VERSION, "45")));
assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.BROWSER_VERSION, "45"),
ImmutableMap.of(CapabilityType.VERSION, "50")));
assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.BROWSER_VERSION, "45"),
ImmutableMap.of(CapabilityType.BROWSER_VERSION, "50")));
}
}

0 comments on commit 26b68e6

Please sign in to comment.