Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MYFACES-4590: Ensure default will be used when an expression resolved… #555

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.List;
import java.util.Map;

import jakarta.el.ValueExpression;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.PhaseEvent;
import jakarta.faces.event.PhaseId;
import jakarta.faces.event.PhaseListener;
import org.apache.myfaces.test.el.MockValueExpression;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -48,7 +50,8 @@ public String getFamily()
private enum PropertyKeys
{
testProperty1,
testProperty2
testProperty2,
testPropertyWithDefault
}

public String getTestProperty1()
Expand All @@ -71,6 +74,16 @@ public void setTestProperty2(String testProperty2)
getStateHelper().put(PropertyKeys.testProperty2, testProperty2);
}

public Long getTestPropertyWithDefault()
{
return (Long) getStateHelper().eval(PropertyKeys.testPropertyWithDefault, Long.MAX_VALUE);
}

public void setTestPropertyWithDefault(Long testPropertyWithDefault)
{
getStateHelper().put(PropertyKeys.testPropertyWithDefault, testPropertyWithDefault);
}

/*
private StateHelper _stateHelper = null;

Expand Down Expand Up @@ -100,7 +113,7 @@ public void restoreState(FacesContext context, Object state)
@Override
public Object saveState(FacesContext context)
{
Object[] values = new Object[2];
Object[] values = new Object[3];
values[0] = super.saveState(context);
//values[1] = _stateHelper == null ? null : _stateHelper.saveState(context);
return values;
Expand Down Expand Up @@ -210,6 +223,34 @@ public void testPutPropertyStateHelper1()

Assertions.assertEquals("someOtherOtherValue",retValue);
}

@Test
// https://issues.apache.org/jira/browse/MYFACES-4590
public void testPropertyWithDefault()
{
UITestComponent a = new UITestComponent();

Assertions.assertEquals(Long.MAX_VALUE, a.getTestPropertyWithDefault(),
"Property should be Long.MAX_VALUE from default)");

ValueExpression valueExpression = new MockValueExpression("#{testPropertyWithDefault}", Object.class);
a.setValueExpression("testPropertyWithDefault", valueExpression);
Map applicationMap = externalContext.getApplicationMap();
applicationMap.put("testPropertyWithDefault", 100L);

Assertions.assertEquals(100L, a.getTestPropertyWithDefault(),
"Property should be 100L from expression");

applicationMap.remove("testPropertyWithDefault");

Assertions.assertEquals(Long.MAX_VALUE, a.getStateHelper().eval("testPropertyWithDefault", Long.MAX_VALUE),
"Value from stateHelper should be Long.MAX_VALUE from default");
Assertions.assertEquals(Long.MAX_VALUE, a.getStateHelper().eval("testPropertyWithDefault", () -> Long.MAX_VALUE),
"Value from stateHelper should be Long.MAX_VALUE from default");
Assertions.assertEquals(Long.MAX_VALUE, a.getTestPropertyWithDefault(),
"Property should be Long.MAX_VALUE from default");

}

@Test
public void testPutPropertyStateHelper2()
Expand Down