/** * Tests if the tag contains the given attribute. Please note that this is non case-sensitive, * because attributes in HTML may be non case-sensitive. * * @param attribute * an attribute to look for in the tag * @return <code>true</code> if the tag has the attribute, <code>false</code> if not. */ public boolean hasAttribute(String attribute) { boolean hasAttribute = false; if (getAttribute(attribute) != null) { hasAttribute = true; } return hasAttribute; }
/** * Tests if the tag contains the given attribute. Please note that this is non case-sensitive, * because attributes in HTML may be non case-sensitive. * * @param attribute * an attribute to look for in the tag * @return <code>true</code> if the tag has the attribute, <code>false</code> if not. */ public boolean hasAttribute(String attribute) { boolean hasAttribute = false; if (getAttribute(attribute) != null) { hasAttribute = true; } return hasAttribute; }
/** * Tests if the tag contains the given attribute. Please note that this is non case-sensitive, * because attributes in HTML may be non case-sensitive. * * @param attribute * an attribute to look for in the tag * @return <code>true</code> if the tag has the attribute, <code>false</code> if not. */ public boolean hasAttribute(String attribute) { boolean hasAttribute = false; if (getAttribute(attribute) != null) { hasAttribute = true; } return hasAttribute; }
/** * Tests if the tag contains the given attribute. Please note that this is non case-sensitive, * because attributes in HTML may be non case-sensitive. * * @param attribute * an attribute to look for in the tag * @return <code>true</code> if the tag has the attribute, <code>false</code> if not. */ public boolean hasAttribute(String attribute) { boolean hasAttribute = false; if (getAttribute(attribute) != null) { hasAttribute = true; } return hasAttribute; }
/** * Checks if an attribute's value is the exact same as the given value. * * @param attribute * an attribute to test * @param expected * the value which should be the same at the attribute's value * @return <code>true</code> if the attribute's value is the same as the given value */ public boolean getAttributeIs(String attribute, String expected) { boolean is = false; String val = getAttribute(attribute); if (val == null && expected == null || expected != null && expected.equals(val)) { is = true; } return is; }
/** * Checks if an attribute's value is the exact same as the given value. * * @param attribute * an attribute to test * @param expected * the value which should be the same at the attribute's value * @return <code>true</code> if the attribute's value is the same as the given value */ public boolean getAttributeIs(String attribute, String expected) { boolean is = false; String val = getAttribute(attribute); if (val == null && expected == null || expected != null && expected.equals(val)) { is = true; } return is; }
/** * Checks if an attribute's value is the exact same as the given value. * * @param attribute * an attribute to test * @param expected * the value which should be the same at the attribute's value * @return <code>true</code> if the attribute's value is the same as the given value */ public boolean getAttributeIs(String attribute, String expected) { boolean is = false; String val = getAttribute(attribute); if (val == null && expected == null || expected != null && expected.equals(val)) { is = true; } return is; }
/** * Checks if an attribute's value ends with the given parameter. * * @param attribute * an attribute to test * @param expected * the expected value * @return <code>true</code> if the attribute's value ends with the expected value */ public boolean getAttributeEndsWith(String attribute, String expected) { boolean endsWith = false; if (expected != null) { String val = getAttribute(attribute); if (val != null) { if (val.endsWith(expected)) { endsWith = true; } } } return endsWith; }
/** * Checks if an attribute's value is the exact same as the given value. * * @param attribute * an attribute to test * @param expected * the value which should be the same at the attribute's value * @return <code>true</code> if the attribute's value is the same as the given value */ public boolean getAttributeIs(String attribute, String expected) { boolean is = false; String val = getAttribute(attribute); if (val == null && expected == null || expected != null && expected.equals(val)) { is = true; } return is; }
/** * Checks if an attribute's value ends with the given parameter. * * @param attribute * an attribute to test * @param expected * the expected value * @return <code>true</code> if the attribute's value ends with the expected value */ public boolean getAttributeEndsWith(String attribute, String expected) { boolean endsWith = false; if (expected != null) { String val = getAttribute(attribute); if (val != null) { if (val.endsWith(expected)) { endsWith = true; } } } return endsWith; }
@Override protected boolean matchesSafely(TagTester tagTester, Description mismatchDescription) { final String value = tagTester.getAttribute(attribute); if (!valueMatcher.matches(value)) { mismatchDescription.appendText("attribute ").appendValue(attribute); valueMatcher.describeMismatch(value, mismatchDescription); return false; } return true; }
/** * checks if given class name is the only one that was set. * * @param tester The tag tester of tag to test * @param className The class name that must be present */ public static void assertSingleClassNamePresent(TagTester tester, String className) { assertThat(tester.getAttribute("class"), is(equalTo(className))); } }
protected List<String> extractClassNames(TagTester tagTester) { return tagTester != null ? newArrayList(Splitter.on(' ').trimResults().split(nullToEmpty(tagTester.getAttribute("class")))) : Lists.<String>newArrayList(); }
protected List<String> extractClassNames(TagTester tagTester) { return tagTester != null ? newArrayList(Splitter.on(' ').trimResults().split(nullToEmpty(tagTester.getAttribute("class")))) : Lists.<String>newArrayList(); }
private void startPageAndAssertClassNames(final String classNames) { tester().startComponentInPage(component); TagTester tester = tester().getTagByWicketId("id"); assertThat(tester.getAttribute("class"), is(equalTo(classNames))); } }
private void startPageAndAssertClassNames(final String classNames) { tester().startComponentInPage(component); TagTester tester = tester().getTagByWicketId("id"); assertThat(tester.getAttribute("class"), is(equalTo(classNames))); } }
@Test public void fluidClassIsRendered() { Navbar navbar = new Navbar("id"); navbar.fluid(); tester().startComponentInPage(navbar); TagTester tagTester = tester().getTagByWicketId("container"); Assert.assertThat(navbar.isFluid(), is(equalTo(true))); Assert.assertThat(tagTester.getAttribute("class"), is(equalTo(("container-fluid")))); }
/** * Tests removing a value for a list */ @Test public void removeCssClasses() { // add 3 classes component.add(new CssClassNameAppender("classX classY classZ")); // then remove one of them component.add(new CssClassNameRemover("classZ")); tester().startComponentInPage(component); TagTester tester = tester().getTagByWicketId("id"); // make sure the removed one is not here anymore assertThat("classX classY", is(equalTo(tester.getAttribute("class")))); }
@Test public void buttonWithIconIsAddedToLeftNavigation() { Navbar navbar = new Navbar("id"); navbar.addComponents(new INavbarComponent() { @Override public Component create(String markupId) { return new NavbarButton<Page>(Page.class, Model.of("Link Name")).setIconType(IconType.aligncenter); } @Override public Navbar.ComponentPosition getPosition() { return Navbar.ComponentPosition.LEFT; } }); tester().startComponentInPage(navbar); Assert.assertThat(tester().getTagByWicketId(Navbar.COMPONENT_ID).hasChildTag("i"), is(equalTo(true))); Assert.assertThat(tester().getTagByWicketId("icon").getAttribute("class"), containsString("icon-align-center")); } }
/** * Tests removing a value for tag that has no 'class' attribute at all. */ @Test public void removeNonExistingCssClasses() { // the component has no CSS classes // try to remove a class component.add(new CssClassNameRemover("classZ")); tester().startComponentInPage(component); TagTester tester = tester().getTagByWicketId("id"); // make sure the removed one is not here at all assertNull("The removed CSS class should not be set if the old value of 'class' is null", tester.getAttribute("class")); } }