/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package jakarta.el;
/** * Creates the resolver that is used for the test. All the tests use a resolver with the same configuration.
*/ private BeanNameELResolver createBeanNameELResolver() { return createBeanNameELResolver(true);
}
TesterBeanNameResolver beanNameResolver = new TesterBeanNameResolver();
beanNameResolver.setBeanValue(BEAN01_NAME, BEAN01);
beanNameResolver.setBeanValue(BEAN02_NAME, BEAN02);
beanNameResolver.setAllowCreate(allowCreate);
BeanNameELResolver beanNameELResolver = new BeanNameELResolver(beanNameResolver); return beanNameELResolver;
}
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testGetValue01() {
BeanNameELResolver resolver = createBeanNameELResolver();
resolver.getValue(null, new Object(), new Object());
}
/** * Tests that a valid bean is resolved.
*/
@Test publicvoid testGetValue02() {
BeanNameELResolver resolver = createBeanNameELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object result = resolver.getValue(context, null, BEAN01_NAME);
/** * Tests that a valid bean is not resolved if property is not a String even if it can be coerced to a valid bean * name.
*/
@Test publicvoid testGetValue04() {
BeanNameELResolver resolver = createBeanNameELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object property = new Object() {
@Override public String toString() { return BEAN01_NAME;
}
};
Object result = resolver.getValue(context, null, property);
/** * Exception during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testGetValue06() {
doThrowableTest(TesterBeanNameResolver.EXCEPTION_TRIGGER_NAME, MethodUnderTest.GET_VALUE);
}
/** * Throwable during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testGetValue07() {
doThrowableTest(TesterBeanNameResolver.THROWABLE_TRIGGER_NAME, MethodUnderTest.GET_VALUE);
}
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testSetValue01() {
BeanNameELResolver resolver = createBeanNameELResolver();
resolver.setValue(null, new Object(), new Object(), new Object());
}
/** * Test replace with create enabled.
*/
@Test publicvoid testSetValue02() {
doSetValueCreateReplaceTest(true, BEAN01_NAME);
}
/** * Test replace with create disabled.
*/
@Test publicvoid testSetValue03() {
doSetValueCreateReplaceTest(false, BEAN01_NAME);
}
/** * Test create with create enabled.
*/
@Test publicvoid testSetValue04() {
doSetValueCreateReplaceTest(true, BEAN99_NAME);
}
/** * Test create with create disabled.
*/
@Test publicvoid testSetValue05() {
doSetValueCreateReplaceTest(false, BEAN99_NAME);
}
/** * Test replacing a read-only bean with create enabled.
*/
@Test(expected = PropertyNotWritableException.class) publicvoid testSetValue06() {
doSetValueCreateReplaceTest(true, TesterBeanNameResolver.READ_ONLY_NAME);
}
/** * Test replacing a read-only bean with create disable.
*/
@Test(expected = PropertyNotWritableException.class) publicvoid testSetValue07() {
doSetValueCreateReplaceTest(false, TesterBeanNameResolver.READ_ONLY_NAME);
}
/** * Exception during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testSetValue08() {
doThrowableTest(TesterBeanNameResolver.EXCEPTION_TRIGGER_NAME, MethodUnderTest.SET_VALUE);
}
/** * Throwable during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testSetValue09() {
doThrowableTest(TesterBeanNameResolver.THROWABLE_TRIGGER_NAME, MethodUnderTest.SET_VALUE);
}
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testGetType01() {
BeanNameELResolver resolver = createBeanNameELResolver();
resolver.getType(null, new Object(), new Object());
}
/** * Tests that a valid bean is resolved.
*/
@Test publicvoid testGetType02() {
BeanNameELResolver resolver = createBeanNameELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Class<?> result = resolver.getType(context, null, BEAN01_NAME);
/** * Tests that a valid bean is not resolved if property is not a String even if it can be coerced to a valid bean * name.
*/
@Test publicvoid testGetType04() {
BeanNameELResolver resolver = createBeanNameELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object property = new Object() {
@Override public String toString() { return BEAN01_NAME;
}
};
Class<?> result = resolver.getType(context, null, property);
/** * Exception during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testGetType06() {
doThrowableTest(TesterBeanNameResolver.EXCEPTION_TRIGGER_NAME, MethodUnderTest.GET_TYPE);
}
/** * Throwable during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testGetType07() {
doThrowableTest(TesterBeanNameResolver.THROWABLE_TRIGGER_NAME, MethodUnderTest.GET_TYPE);
}
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testIsReadOnly01() {
BeanNameELResolver resolver = createBeanNameELResolver();
resolver.isReadOnly(null, new Object(), new Object());
}
/** * Tests that a writable bean is reported as writable.
*/
@Test publicvoid testIsReadOnly02() {
BeanNameELResolver resolver = createBeanNameELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
boolean result = resolver.isReadOnly(context, null, BEAN01_NAME);
/** * Tests that a valid bean is not resolved if property is not a String even if it can be coerced to a valid bean * name.
*/
@Test publicvoid testIsReadOnly05() {
BeanNameELResolver resolver = createBeanNameELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object property = new Object() {
@Override public String toString() { return BEAN01_NAME;
}
};
/** * Exception during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testIsReadOnly07() {
doThrowableTest(TesterBeanNameResolver.EXCEPTION_TRIGGER_NAME, MethodUnderTest.IS_READ_ONLY);
}
/** * Throwable during resolution should be wrapped and re-thrown.
*/
@Test publicvoid testIsReadOnly08() {
doThrowableTest(TesterBeanNameResolver.THROWABLE_TRIGGER_NAME, MethodUnderTest.IS_READ_ONLY);
}
/** * Confirm it returns null for 'valid' input.
*/
@Deprecated(forRemoval = true, since = "Tomcat 10.1.0") publicvoid testGetFeatureDescriptors01() {
BeanNameELResolver resolver = createBeanNameELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object result = resolver.getFeatureDescriptors(context, null);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.