001// Generated by delombok at Sun Jul 30 17:21:56 UTC 2023
002package de.cuioss.test.jsf.renderer;
003
004import static org.junit.jupiter.api.Assertions.assertFalse;
005import static org.junit.jupiter.api.Assertions.fail;
006import java.io.Serializable;
007import javax.faces.component.UIComponent;
008import org.jdom2.Element;
009import de.cuioss.test.jsf.renderer.util.DomUtils;
010import de.cuioss.tools.property.PropertyUtil;
011
012/**
013 * This enum define the commonly used attributes to be tested.
014 *
015 * @author Oliver Wolff
016 */
017public enum CommonRendererAsserts implements RendererAttributeAssert {
018    /**
019     * Checks the attribute 'id', see {@link UIComponent#getId()}
020     */
021    ID("id", "traceId"), /**
022     * Checks the attribute 'rendered', see {@link UIComponent#isRendered()}. Due to
023     * its nature this test must not work all the time correctly and should
024     * therefore considered as candidate for vetoing. The actual assert checks
025     * whether the given component is {@code null} or does not contain any children.
026     */
027    RENDERED("rendered", Boolean.FALSE) {
028        @Override
029        public void assertAttributeSet(final Element element) {
030            if (null == element) {
031                return;
032            }
033            if (!element.getChildren().isEmpty()) {
034                fail("Children found, although the rendered attribute is set to \'false\'. This may be a tricky one, depending on your desired output");
035            }
036        }
037    },
038    /**
039     * Checks the attribute 'style'
040     */
041    STYLE("style", "traceStyle"), /**
042     * Checks the attribute 'style'
043     */
044    STYLE_CLASS("styleClass", "traceStyleClass") {
045        @Override
046        public void assertAttributeSet(final Element element) {
047            var found = DomUtils.filterForAttributeContainingValue(element, "class", getAttributeTraceValue().toString());
048            assertFalse(found.isEmpty(), "The expected attribute with name=\'class\' and traceValue=" + getAttributeTraceValue() + " was not found in the resulting dom-tree.");
049        }
050    },
051    /**
052     * Checks the passthrough-attributes.
053     */
054    PASSTHROUGH("data-passthrough-test", "passthroughTraceValue") {
055        @Override
056        public void applyAttribute(final UIComponent component) {
057            component.getPassThroughAttributes(true).put(getAttributeName(), getAttributeTraceValue());
058        }
059    };
060    private final String attributeName;
061    private final Serializable attributeTraceValue;
062
063    @Override
064    public void applyAttribute(final UIComponent component) {
065        PropertyUtil.writeProperty(component, attributeName, getAttributeTraceValue());
066    }
067
068    @Override
069    public void assertAttributeSet(final Element element) {
070        var found = DomUtils.filterForAttributeContainingValue(element, getAttributeName(), getAttributeTraceValue().toString());
071        assertFalse(found.isEmpty(), "The expected attribute with name=" + getAttributeName() + " and traceValue=" + getAttributeTraceValue() + " was not found in the resulting dom-tree.");
072    }
073
074    @java.lang.SuppressWarnings("all")
075    @lombok.Generated
076    private CommonRendererAsserts(final String attributeName, final Serializable attributeTraceValue) {
077        this.attributeName = attributeName;
078        this.attributeTraceValue = attributeTraceValue;
079    }
080
081    @java.lang.SuppressWarnings("all")
082    @lombok.Generated
083    public String getAttributeName() {
084        return this.attributeName;
085    }
086
087    @java.lang.SuppressWarnings("all")
088    @lombok.Generated
089    public Serializable getAttributeTraceValue() {
090        return this.attributeTraceValue;
091    }
092}