From dccf19cab3e6aa58994c6131477108b3f4dcc101 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Fri, 15 Sep 2023 21:38:00 +0200 Subject: [PATCH] Sonar cloud issue fix --- CHANGELOG.md | 5 + fj-core-jvfs/pom.xml | 2 +- .../java/core/cfg/helpers/UnsafeHelper.java | 2 +- .../cfg/xml/GenericListCatalogConfig.java | 2 +- .../java/core/cfg/xml/PropertyHolder.java | 8 +- .../db/connect/ConnectionFactoryImpl.java | 52 +++----- .../db/connect/DbcpConnectionFactory.java | 42 +++---- .../org/fugerit/java/core/db/dao/OpDAO.java | 6 +- .../core/db/dao/idgen/IdGeneratorFacade.java | 2 +- .../core/db/daogen/SimpleServiceResult.java | 12 +- .../fugerit/java/core/db/helpers/DbUtils.java | 1 - .../fixed/parser/FixedFieldFileConfig.java | 116 ++++++++++-------- .../core/io/helper/CustomPrintWriter.java | 4 +- .../core/lang/annotate/DefineImplFinder.java | 4 +- .../lang/binding/BindingHelperDefault.java | 12 +- .../helpers/reflect/FacadeImplFinder.java | 6 +- .../lang/helpers/reflect/FieldHelper.java | 62 +++++++++- .../core/lang/helpers/reflect/ImplFinder.java | 4 +- .../org/fugerit/java/core/log/LogUtils.java | 7 +- .../checkpoint/CheckpointFormatHelper.java | 20 +-- .../java/core/util/collection/OptionItem.java | 14 +-- .../util/filterchain/MiniFilterConfig.java | 45 +++++-- .../filterchain/MiniFilterConfigEntry.java | 6 +- .../util/filterchain/MiniFilterDebug.java | 32 ++--- .../java/core/util/result/PagedResult.java | 4 +- .../core/util/result/VirtualPageCache.java | 2 +- .../java/core/validator/ValidatorCatalog.java | 2 +- .../xml/config/XMLSchemaCatalogConfig.java | 43 +++++-- .../core/xml/sax/dh/DefaultHandlerComp.java | 8 +- .../org/fugerit/java/core/cfg/TestConfig.java | 6 +- .../core/cfg/TestConfigRuntimeException.java | 4 +- .../db/connect/TestConnectionFactory.java | 9 +- .../fugerit/java/core/db/dao/rse/TestRSE.java | 2 +- .../core/db/helpers/MemDBTestBaseTester.java | 2 +- .../core/lang/binding/TestBindingCatalog.java | 2 +- .../lang/helpers/filter/TestPathHelper.java | 6 +- .../lang/helpers/reflect/TestFieldHelper.java | 32 +++++ .../lang/helpers/reflect/TestPathHelper.java | 12 +- .../filterchain/TestDuplicateFailOnSet.java | 2 +- .../core/util/filterchain/TestMiniFilter.java | 33 ++++- .../java/core/util/i18n/TestHelperI18N.java | 10 +- .../java/core/util/result/TestResult.java | 4 +- .../core/validator/TestValidatorCatalog.java | 2 +- .../java/core/xml/TestTransformerXML.java | 4 +- .../config/TestXMLSchemaCatalogConfig.java | 6 +- .../fugerit/java/core/xml/dom/TestDOMIO.java | 4 +- .../org/fugerit/java/tool/ToolHandler.java | 3 +- .../fugerit/java/tool/ToolHandlerHelper.java | 2 +- .../tool/fixed/ExtractFixedConfigHandler.java | 4 +- 49 files changed, 408 insertions(+), 266 deletions(-) create mode 100644 fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ab66e4e9..f5ce4fb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- fj-daogen-version set to 1.2.1 in module fj-core-jvfs +- ImplFinder interface methods does not throw any exception now + ## [8.3.1] - 2023-09-15 ### Changed diff --git a/fj-core-jvfs/pom.xml b/fj-core-jvfs/pom.xml index e930288e..724a7fd5 100644 --- a/fj-core-jvfs/pom.xml +++ b/fj-core-jvfs/pom.xml @@ -30,7 +30,7 @@ - 1.1.9 + 1.2.1 ${project.basedir} target/generated-sources/daogen diff --git a/fj-core/src/main/java/org/fugerit/java/core/cfg/helpers/UnsafeHelper.java b/fj-core/src/main/java/org/fugerit/java/core/cfg/helpers/UnsafeHelper.java index 123b6cd1..f6f8b4ae 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/cfg/helpers/UnsafeHelper.java +++ b/fj-core/src/main/java/org/fugerit/java/core/cfg/helpers/UnsafeHelper.java @@ -10,7 +10,7 @@ public class UnsafeHelper { private UnsafeHelper() {} - private final static Logger logger = LoggerFactory.getLogger( UnsafeHelper.class ); + private static final Logger logger = LoggerFactory.getLogger( UnsafeHelper.class ); public static final String UNSAFE_TRUE = BooleanUtils.BOOLEAN_TRUE; public static final String UNSAFE_FALSE = BooleanUtils.BOOLEAN_FALSE; diff --git a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java index a7a548b6..2db95af8 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java +++ b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java @@ -279,7 +279,7 @@ public GenericListCatalogConfig( String attTagDataList, String attTagData ) { * * @param the type of the elements in catalog * @param is the input stream to load from - * @param config the instance to be configured + * @param config the instance to be configured (will be configured by side effect too) * @return the configured instance * @throws ConfigRuntimeException in case of issues during loading */ diff --git a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java index e7e2ef9b..8a1454f8 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java +++ b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java @@ -25,17 +25,17 @@ public class PropertyHolder extends BasicIdConfigType { public static final String UNSAFE_FALSE = "false"; public static final String UNSAFE_WARN = "warn"; - public final static String MODE_CLASS_LOADER = "classloader"; - public final static String MODE_CL = "cl"; + public static final String MODE_CLASS_LOADER = "classloader"; + public static final String MODE_CL = "cl"; - public final static String MODE_FILE = "file"; + public static final String MODE_FILE = "file"; /** * When this mode is used, you must define in PATH reference to other holders in the same catalog, semicolon separated. * For instace if props-01 and props-02 are two holder in the same catalog : * path="props01;props-02" */ - public final static String MODE_MULTI = "multi"; + public static final String MODE_MULTI = "multi"; /** * diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java b/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java index 0941f675..ce68b94e 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java @@ -34,8 +34,10 @@ import org.fugerit.java.core.db.dao.DAOException; import org.fugerit.java.core.db.metadata.DataBaseInfo; import org.fugerit.java.core.function.UnsafeSupplier; +import org.fugerit.java.core.lang.helpers.BooleanUtils; import org.fugerit.java.core.lang.helpers.StringUtils; import org.fugerit.java.core.log.BasicLogObject; +import org.fugerit.java.core.util.PropsIO; import org.fugerit.java.core.xml.dom.DOMUtils; import org.fugerit.java.core.xml.dom.SearchDOM; import org.w3c.dom.Element; @@ -175,11 +177,11 @@ public Connection getConnection() throws DAOException { /** * Parse a configuration Element looking for ConnectionFactory configuration * - * @param cfConfig the Element - * @return the CfConfig - * @throws Exception in case of issues + * @param cfConfig the Element + * @return the CfConfig + * @throws DAOException in case of issues */ - public static CfConfig parseCfConfig( Element cfConfig ) throws Exception { + public static CfConfig parseCfConfig( Element cfConfig ) throws DAOException { CfConfig config = new CfConfig(); SearchDOM searchDOM = SearchDOM.newInstance( true , true ); List cfConfigEntryList = searchDOM.findAllTags( cfConfig , "cf-config-entry" ); @@ -215,21 +217,6 @@ public static String getDriverInfo( ConnectionFactory cf ) throws DAOException { }); } - /** - * Helper method to create a property with prefix - * - * @param prefix the prefix - * @param name the property base name - * @return the property full name ( prefix-name, or name if prefix == null) - */ - private static String getParamName( String prefix, String name ) { - String res = name; - if ( StringUtils.isNotEmpty( prefix ) ) { - res = prefix+"-"+name; - } - return res; - } - /** * Creates a ConnectionFactory from a property object * @@ -256,25 +243,24 @@ public static ConnectionFactory newInstance( Properties props, String propsPrefi } ConnectionFactory cf = null; String prefix = props.getProperty( PROP_CF_MODE_DC_PREFIX, propsPrefix ); - String mode = props.getProperty( getParamName( prefix, PROP_CF_MODE ) ); + Properties prefixProps = props; + if ( StringUtils.isNotEmpty( prefix ) ) { + prefixProps = PropsIO.subProps( props , prefix+"-" ); + log.info( "subProps : {} -> {}", prefix, prefixProps ); + } + String mode = prefixProps.getProperty( PROP_CF_MODE ); log.info( "ConnectionFactory.newInstance() mode : {}", mode ); if ( PROP_CF_MODE_DC.equalsIgnoreCase( mode ) ) { - if ( "true".equalsIgnoreCase( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED ) ) ) ) { - int sc = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_SC ), "3" ) ); - int ic = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_IC ), "10" ) ); - int mc = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_MC ), "30" ) ); - cf = new DbcpConnectionFactory( props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_DRV ) ), - props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_URL ) ), - props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_USR ) ), - props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_PWD ) ), sc, ic, mc, cl ); + if ( BooleanUtils.isTrue( prefixProps.getProperty(PROP_CF_EXT_POOLED ) ) ) { + cf = new DbcpConnectionFactory(prefixProps, cl); } else { - cf = newInstance( props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_DRV ) ), - props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_URL ) ), - props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_USR ) ), - props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_PWD ) ), cl ); + cf = newInstance( prefixProps.getProperty( PROP_CF_MODE_DC_DRV ), + prefixProps.getProperty(PROP_CF_MODE_DC_URL ), + prefixProps.getProperty(PROP_CF_MODE_DC_USR ), + prefixProps.getProperty(PROP_CF_MODE_DC_PWD ), cl ); } } else if ( PROP_CF_MODE_DS.equalsIgnoreCase( mode ) || PROP_CF_MODE_DS2.equalsIgnoreCase( mode ) ) { - String dsName = props.getProperty( PROP_CF_MODE_DS_NAME ); + String dsName = prefixProps.getProperty( PROP_CF_MODE_DS_NAME ); log.info( "dsName -> {}", dsName ); cf = newInstance( dsName ); } else { diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java b/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java index 6e11b75b..9f91c2a6 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java @@ -21,6 +21,7 @@ package org.fugerit.java.core.db.connect; import java.sql.Connection; +import java.util.Properties; import org.apache.commons.dbcp2.BasicDataSource; import org.fugerit.java.core.db.dao.DAOException; @@ -36,41 +37,30 @@ public class DbcpConnectionFactory extends ConnectionFactoryImpl { private BasicDataSource dataSource; /** - * Constructor * - * @param drv driver type - * @param url jdbc url - * @param usr user - * @param pwd password - * @param init initial connection - * @param min minimum connection - * @param max maximum connection - * @throws DAOException in case of issues + * @param cfProps connections parameters + * @throws DAOException in case of issues */ - public DbcpConnectionFactory( String drv, String url, String usr, String pwd, int init, int min, int max ) throws DAOException { - this(drv, url, usr, pwd, init, min, max, null); + public DbcpConnectionFactory( Properties cfProps ) throws DAOException { + this(cfProps, null); } /** - * Constructor * - * @param drv driver type - * @param url jdbc url - * @param usr user - * @param pwd password - * @param init initial connection - * @param min minimum connection - * @param max maximum connection - * @param cl the class loader - * @throws DAOException in case of issues + * @param cfProps connections parameters + * @param cl to use for driver class loading + * @throws DAOException in case of issues */ - public DbcpConnectionFactory( String drv, String url, String usr, String pwd, int init, int min, int max, ClassLoader cl ) throws DAOException { + public DbcpConnectionFactory( Properties cfProps, ClassLoader cl ) throws DAOException { DAOException.apply( () -> { + int init = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_SC , "3" ) ); + int min = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_IC , "10" ) ); + int max = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_MC , "30" ) ); this.dataSource = new BasicDataSource(); - this.dataSource.setDriverClassName( drv ); - this.dataSource.setUrl( url ); - this.dataSource.setUsername( usr ); - this.dataSource.setPassword( pwd ); + this.dataSource.setDriverClassName( cfProps.getProperty( PROP_CF_MODE_DC_DRV ) ); + this.dataSource.setUrl( cfProps.getProperty( PROP_CF_MODE_DC_URL ) ); + this.dataSource.setUsername( cfProps.getProperty( PROP_CF_MODE_DC_USR ) ); + this.dataSource.setPassword( cfProps.getProperty( PROP_CF_MODE_DC_PWD ) ); this.dataSource.setMaxTotal( max ); this.dataSource.setMaxIdle( min ); this.dataSource.setInitialSize( init ); diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/dao/OpDAO.java b/fj-core/src/main/java/org/fugerit/java/core/db/dao/OpDAO.java index 314c9492..1e8fa12f 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/dao/OpDAO.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/dao/OpDAO.java @@ -65,9 +65,9 @@ public static OpDAO newUpdateOp( String sql, FieldList fl ) { return op; } - public final static int TYPE_UPDATE = 0; - public final static int TYPE_QUERY = 1; - public final static int TYPE_EXECUTE = 2; + public static final int TYPE_UPDATE = 0; + public static final int TYPE_QUERY = 1; + public static final int TYPE_EXECUTE = 2; private String sql; diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/dao/idgen/IdGeneratorFacade.java b/fj-core/src/main/java/org/fugerit/java/core/db/dao/idgen/IdGeneratorFacade.java index 9de2e33d..81dfa345 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/dao/idgen/IdGeneratorFacade.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/dao/idgen/IdGeneratorFacade.java @@ -15,7 +15,7 @@ public class IdGeneratorFacade { private IdGeneratorFacade() {} - private final static Properties SEQ_TYPES = PropsIO.loadFromClassLoaderSafe( "core/dao/idgen/seq_generator.properties" ); + private static final Properties SEQ_TYPES = PropsIO.loadFromClassLoaderSafe( "core/dao/idgen/seq_generator.properties" ); public static BasicSeqIdGenerator sequenceGenerator( DAOContext context, String sequenceName ) throws DAOException { return sequenceGenerator( context.getConnection(), sequenceName ); diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/daogen/SimpleServiceResult.java b/fj-core/src/main/java/org/fugerit/java/core/db/daogen/SimpleServiceResult.java index 86b48ca4..7d92fda8 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/daogen/SimpleServiceResult.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/daogen/SimpleServiceResult.java @@ -8,14 +8,14 @@ public class SimpleServiceResult { - public final static int DEFAULT_OK = Result.RESULT_CODE_OK; - public final static int DEFAULT_KO = Result.RESULT_CODE_KO; + public static final int DEFAULT_OK = Result.RESULT_CODE_OK; + public static final int DEFAULT_KO = Result.RESULT_CODE_KO; - public final static String INFO_RESULT = "result"; - public final static String INFO_RESULT_MESSAGE = "resultMessage"; + public static final String INFO_RESULT = "result"; + public static final String INFO_RESULT_MESSAGE = "resultMessage"; - public final static String INFO_ESITO_OK_NO_DATA_FOUND = String.valueOf( 2 ); - public final static String INFO_ESITO_OK_MULTIPLE_RESULTS = String.valueOf( 3 ); + public static final String INFO_ESITO_OK_NO_DATA_FOUND = String.valueOf( 2 ); + public static final String INFO_ESITO_OK_MULTIPLE_RESULTS = String.valueOf( 3 ); public void addInfoEsito( String result, String resultMessage ) { this.getInfo().put( INFO_RESULT , result ); diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java b/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java index 541a6a4d..aa0ab331 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java +++ b/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java @@ -60,7 +60,6 @@ public static int indentifyDB( String productName ) { dbType = DB_POSTGRESQL; log.info( "IdGenerator configured for : POSTGRESQL ({}) was ({})", dbType, name ); } else { - dbType = DB_UNKNOWN; log.info( "Unknown db type ({})", dbType ); } return dbType; diff --git a/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java b/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java index 3469ef4d..37a48e88 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java +++ b/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java @@ -8,6 +8,9 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import org.fugerit.java.core.cfg.ConfigException; +import org.fugerit.java.core.cfg.ConfigRuntimeException; +import org.fugerit.java.core.function.SafeFunction; import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.core.lang.helpers.StringUtils; import org.fugerit.java.core.xml.dom.DOMIO; @@ -22,20 +25,22 @@ */ public class FixedFieldFileConfig { - private static void handleValidatorList( FixedFieldFileDescriptor fileDescriptor, Element currentFileTag ) throws Exception { - NodeList validatorListTagList = currentFileTag.getElementsByTagName( "validator-list" ); - for ( int k=0; k { + NodeList validatorListTagList = currentFileTag.getElementsByTagName( "validator-list" ); + for ( int k=0; kParse fixed filed file configuration.

+ * + *

NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.

+ * + * @see Define and throw a dedicated exception instead of using a generic one. + * + * @param is the configuration file to parse + * @return the parsed configuration + * @throws ConfigRuntimeException in case of issues + */ + public static FixedFieldFileConfig parseConfig( InputStream is ) { + return SafeFunction.get( () -> { + FixedFieldFileConfig config = new FixedFieldFileConfig(); + DocumentBuilderFactory dbf = DOMIO.newSafeDocumentBuilderFactory(); + DocumentBuilder parser = dbf.newDocumentBuilder(); + Document doc = parser.parse( is ); + Element root = doc.getDocumentElement(); + NodeList fileTagList = root.getElementsByTagName( "fixed-field-file" ); + for ( int i=0; i findImplFor(Class c) throws Exception { + public Class findImplFor(Class c) { Class ret = c; if ( this.isFinderFor( c )) { DefineImpl fug = c.getAnnotation( DefineImpl.class ); @@ -24,7 +24,7 @@ public Class findImplFor(Class c) throws Exception { } @Override - public boolean isFinderFor(Class c) throws Exception { + public boolean isFinderFor(Class c) { return c.isAnnotationPresent( DefineImpl.class ); } diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java b/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java index 4c398710..d7024ea5 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java +++ b/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java @@ -10,10 +10,10 @@ import org.fugerit.java.core.lang.helpers.StringUtils; import org.fugerit.java.core.lang.helpers.reflect.PathHelper; import org.fugerit.java.core.util.collection.KeyString; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.w3c.dom.Element; +import lombok.extern.slf4j.Slf4j; + /** * Default binding helper implementation * @@ -24,6 +24,7 @@ * @author Matteo a.k.a. Fugerit * */ +@Slf4j public class BindingHelperDefault extends XMLConfigurableObject implements Serializable, BindingHelper, IdConfigType, KeyString { public static final BindingHelper DEFAULT = new BindingHelperDefault( BindingCatalogConfig.ID_DEFAULT_HELPER ); @@ -34,15 +35,14 @@ public BindingHelperDefault() { public BindingHelperDefault( String id ) { this.setId( id ); } - - private final static Logger logger = LoggerFactory.getLogger( BindingHelperDefault.class ); - /** * */ private static final long serialVersionUID = 1342342342323L; public Object convertValue(BindingContext context, BindingConfig binding, BindingFieldConfig field, Object value) throws Exception { + log.trace( "convertValue() context {} , binding {}", context, binding ); + log.trace( "convertValue() field {} , value {}", field, value ); return value; } @@ -82,7 +82,7 @@ public void bindingWorker(BindingContext context, BindingConfig binding, Binding } } String messageTo = bindTo+" - "+bind; - logger.debug( "bindFrom {} to {}", bindFrom, messageTo ); + log.debug( "bindFrom {} to {}", bindFrom, messageTo ); } @Override diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FacadeImplFinder.java b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FacadeImplFinder.java index e65ef3b0..aeb56a62 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FacadeImplFinder.java +++ b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FacadeImplFinder.java @@ -35,7 +35,7 @@ public void removeFinder( ImplFinder finder ) { this.finderList.remove( finder ); } - public ImplFinder getFinderFor( Class c ) throws Exception { + public ImplFinder getFinderFor( Class c ) { ImplFinder finder = null; Iterator it = this.finders(); while ( finder == null && it.hasNext() ) { @@ -47,11 +47,11 @@ public ImplFinder getFinderFor( Class c ) throws Exception { return finder; } - public boolean hasFinderFor( Class c ) throws Exception { + public boolean hasFinderFor( Class c ) { return (this.getFinderFor( c ) != null); } - public Class findImpl( Class c ) throws Exception { + public Class findImpl( Class c ) { Class ret = c; ImplFinder finder = this.getFinderFor( c ); if ( finder != null ) { diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java index 2ae2f631..3bacda90 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java +++ b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java @@ -4,25 +4,72 @@ import org.fugerit.java.core.cfg.ConfigRuntimeException; +/** + *

Helper to set / get field in objects.

+ * + *

Note : use with extreme caution.

+ * + * @see Reflection should not be used to increase accessibility of classes, methods, or fields + * + */ public class FieldHelper { private FieldHelper() {} - public static void setField( Object target, String fieldName, Object value ) { + public static final boolean DEFAULT_SET_ACCESSIBLE_FALSE = Boolean.FALSE.booleanValue(); + + /** + *

Set a field on an object.

+ * + * @param target the target object + * @param fieldName the field name + * @param value the value + * @param setAccessible if the field accessibility should be overridden (use with caution, see below) + * + * @see Reflection should not be used to increase accessibility of classes, methods, or fields + */ + public static void setField( Object target, String fieldName, Object value, boolean setAccessible ) { try { Class c = target.getClass(); Field field = c.getDeclaredField( fieldName ); + if ( setAccessible ) { + field.setAccessible( Boolean.TRUE.booleanValue() ); + } field.set( target , value ); } catch (Exception e) { throw ConfigRuntimeException.convertExMethod( "setField", e ); } } - public static Object getField( Object target, String fieldName ) { + /** + *

Set a field on an object.

+ * + * @param target the target object + * @param fieldName the field name + * @param value the value + */ + public static void setField( Object target, String fieldName, Object value ) { + setField(target, fieldName, value, DEFAULT_SET_ACCESSIBLE_FALSE); + } + + /** + *

Get a field on an object.

+ * + * @param target the target object + * @param fieldName the field name + * @param setAccessible if the field accessibility should be overridden (use with caution, see below) + * @return the value of the field + * + * @see Reflection should not be used to increase accessibility of classes, methods, or fields + */ + public static Object getField( Object target, String fieldName, boolean setAccessible ) { Object res = null; try { Class c = target.getClass(); Field field = c.getDeclaredField( fieldName ); + if ( setAccessible ) { + field.setAccessible( Boolean.TRUE.booleanValue() ); + } res = field.get( target ); } catch (Exception e) { throw ConfigRuntimeException.convertExMethod( "getField", e ); @@ -30,4 +77,15 @@ public static Object getField( Object target, String fieldName ) { return res; } + /** + *

Get a field on an object.

+ * + * @param target the target object + * @param fieldName the field name + * @return the value of the field + */ + public static Object getField( Object target, String fieldName ) { + return getField(target, fieldName, DEFAULT_SET_ACCESSIBLE_FALSE); + } + } diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java index 276ff7c0..b51c36c7 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java +++ b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java @@ -2,8 +2,8 @@ public interface ImplFinder { - Class findImplFor( Class c ) throws Exception; + Class findImplFor( Class c ); - boolean isFinderFor( Class c ) throws Exception; + boolean isFinderFor( Class c ); } diff --git a/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java b/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java index 0ebb92d8..ba825ead 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java +++ b/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java @@ -41,12 +41,7 @@ public static void appendPropDefault( StringBuilder buffer, String key, String v } public static LogObject wrap( final Logger logger ) { - return new LogObject() { - @Override - public Logger getLogger() { - return logger; - } - }; + return () -> logger; } } diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java b/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java index ed7dc57b..f149df42 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java +++ b/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java @@ -27,21 +27,11 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN // code added to setup a basic conditional serialization - END - public static final StringFormat FORMAT_TIME_DEFAULT = new StringFormat() { - @Override - public String convert(Number input) { - return String.valueOf( input.longValue() ); - } - }; + public static final StringFormat FORMAT_TIME_DEFAULT = input -> String.valueOf( input.longValue() ); public static final StringFormat FORMAT_TIME_NICE = FormatTime.DEFAULT; - public static final StringFormat FORMAT_DURATION_DEFAULT = new StringFormat() { - @Override - public String convert(Number input) { - return String.valueOf( input.longValue() )+"ms"; - } - }; + public static final StringFormat FORMAT_DURATION_DEFAULT = input -> String.valueOf( input.longValue() )+"ms"; public static final StringFormat FORMAT_DURATION_NICE = MillisToSecondsFormat.INSTANCE_APPEND_SECOND; @@ -49,9 +39,9 @@ public String convert(Number input) { public static final CheckpointFormat DEFAULT_DECORATION = new CheckpointFormatHelper( FORMAT_TIME_NICE , FORMAT_DURATION_NICE ); - public final static String TOKEN_START_DEF = "["; - public final static String TOKEN_END_DEF = "]"; - public final static String TOKEN_SEPARATOR_DEF = ","; + public static final String TOKEN_START_DEF = "["; + public static final String TOKEN_END_DEF = "]"; + public static final String TOKEN_SEPARATOR_DEF = ","; public void formatDataHelperDefault( StringBuilder builder, CheckpointData data ) { builder.append( this.tokenStart() ); diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java b/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java index 6a4922cb..2dc1f585 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java +++ b/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java @@ -40,23 +40,13 @@ public class OptionItem implements KeyObject, Serializable { * Comparator to sort OptionItem by label String value * */ - public final static Comparator LABEL_SORTER = new Comparator() { - @Override - public int compare(OptionItem object1, OptionItem object2) { - return object1.getLabel().compareTo( object2.getLabel() ); - } - }; + public static final Comparator LABEL_SORTER = (object1, object2) -> object1.getLabel().compareTo( object2.getLabel() ); /** * Comparator to sort OptionItem by value String value * */ - public final static Comparator VALUE_SORTER = new Comparator() { - @Override - public int compare(OptionItem object1, OptionItem object2) { - return object1.getValue().compareTo( object2.getValue() ); - } - }; + public static final Comparator VALUE_SORTER = (object1, object2) -> object1.getValue().compareTo( object2.getValue() ); private String value; diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java index b113dfcf..10afe55b 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java +++ b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java @@ -11,6 +11,7 @@ import org.fugerit.java.core.cfg.ConfigRuntimeException; import org.fugerit.java.core.cfg.xml.CustomListCatalogConfig; import org.fugerit.java.core.cfg.xml.ListMapConfig; +import org.fugerit.java.core.function.SafeFunction; import org.fugerit.java.core.io.helper.StreamHelper; import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.core.lang.helpers.StringUtils; @@ -57,18 +58,42 @@ public MiniFilterConfig(String attTagDataList, String attTagData) { this.getGeneralProps().setProperty( ATT_TYPE , MiniFilterConfigEntry.class.getName() ); } - public static MiniFilterConfig loadConfig( InputStream is, MiniFilterConfig config ) throws Exception { - Document doc = DOMIO.loadDOMDoc( is ); - Element root = doc.getDocumentElement(); - config.configure( root ); - return config; + /** + *

Configure a MiniFilterConfig instance.

+ * + *

NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.

+ * + * @see Define and throw a dedicated exception instead of using a generic one. + * + * @param is the configuration stream + * @param config the item to configure (will be configured by side effect too) + * @return the configured item + * @throws ConfigRuntimeException in case of issues during loading + */ + public static MiniFilterConfig loadConfig( InputStream is, MiniFilterConfig config ) { + return SafeFunction.get( () -> { + Document doc = DOMIO.loadDOMDoc( is ); + Element root = doc.getDocumentElement(); + config.configure( root ); + return config; + }); + } - public static MiniFilterMap loadConfigMap( InputStream is, MiniFilterConfig config ) throws Exception { - Document doc = DOMIO.loadDOMDoc( is ); - Element root = doc.getDocumentElement(); - config.configure( root ); - return config; + /** + *

Configure a MiniFilterConfig instance as a MiniFilterMap.

+ * + *

NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.

+ * + * @see Define and throw a dedicated exception instead of using a generic one. + * + * @param is the configuration stream + * @param config the item to configure (will be configured by side effect too) + * @return the configured item + * @throws ConfigRuntimeException in case of issues during loading + */ + public static MiniFilterMap loadConfigMap( InputStream is, MiniFilterConfig config ) { + return loadConfig(is, config); } @Override diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfigEntry.java b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfigEntry.java index ea291020..18e5b6a6 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfigEntry.java +++ b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfigEntry.java @@ -14,17 +14,17 @@ public class MiniFilterConfigEntry extends BasicIdConfigType { /** * Next step will be processed */ - public final static String DEFAULT_BEHAVIOUR_CONTINUE = "CONTINUE"; + public static final String DEFAULT_BEHAVIOUR_CONTINUE = "CONTINUE"; /** * All following steps will be skipped unless some of them have "ALWAYS" behaviour */ - public final static String DEFAULT_BEHAVIOUR_SKIP = "SKIP"; + public static final String DEFAULT_BEHAVIOUR_SKIP = "SKIP"; /** * This stepp will always be processed, regardless of previous steps status. */ - public final static String DEFAULT_BEHAVIOUR_ALWAYS = "ALWAYS"; + public static final String DEFAULT_BEHAVIOUR_ALWAYS = "ALWAYS"; public int getDefaultBehaviourInt() { int res = MiniFilter.CONTINUE; diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java index 53b877a7..7d9667b3 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java +++ b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java @@ -8,31 +8,25 @@ public class MiniFilterDebug { private MiniFilterDebug() {} - public static void dumpConfig( PrintWriter writer, InputStream is ) throws Exception { + public static void dumpConfig( PrintWriter writer, InputStream is ) { MiniFilterConfig config = new MiniFilterConfig(); MiniFilterConfig.loadConfig( is , config ); dumpConfig(writer, config); } - public static void dumpConfig( PrintWriter writer, MiniFilterConfig config ) throws Exception { - try { - writer.println( "General config properties : "+config.getGeneralProps().toString() ); - Iterator itConfig = config.getIdSet().iterator(); - while ( itConfig.hasNext() ) { - String currentId = itConfig.next(); - writer.println( "***********************************************" ); - writer.println( "AnprOperationBase.getChain() id='"+currentId+"'" ); - writer.println( "***********************************************" ); - Iterator itEntry = config.getDataList( currentId ).iterator(); - while ( itEntry.hasNext() ) { - MiniFilterConfigEntry entry = itEntry.next(); - writer.println( "entry chain : "+entry.getId()+" - "+entry.getType() ); - } + public static void dumpConfig( PrintWriter writer, MiniFilterConfig config ) { + writer.println( "General config properties : "+config.getGeneralProps().toString() ); + Iterator itConfig = config.getIdSet().iterator(); + while ( itConfig.hasNext() ) { + String currentId = itConfig.next(); + writer.println( "***********************************************" ); + writer.println( "AnprOperationBase.getChain() id='"+currentId+"'" ); + writer.println( "***********************************************" ); + Iterator itEntry = config.getDataList( currentId ).iterator(); + while ( itEntry.hasNext() ) { + MiniFilterConfigEntry entry = itEntry.next(); + writer.println( "entry chain : "+entry.getId()+" - "+entry.getType() ); } - } catch (Exception e) { - writer.println( "Error dumping config "+e ); - e.printStackTrace( writer ); - throw e; } } diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/result/PagedResult.java b/fj-core/src/main/java/org/fugerit/java/core/util/result/PagedResult.java index e06ffe4c..21b0a8b2 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/util/result/PagedResult.java +++ b/fj-core/src/main/java/org/fugerit/java/core/util/result/PagedResult.java @@ -16,9 +16,9 @@ public interface PagedResult extends Result { public static final int FIRST_PAGE_INDEX = 1; /** - * The method getElementCount() returns this value if the element count is unavalable + * The method getElementCount() returns this value if the element count is unavailable */ - public final static Integer ELEMENT_COUNT_UNAVAILABLE = -1; + public static final Integer ELEMENT_COUNT_UNAVAILABLE = -1; /** *

The position of the first element of the current pages ( (currentPage-1) * perPage )

diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/result/VirtualPageCache.java b/fj-core/src/main/java/org/fugerit/java/core/util/result/VirtualPageCache.java index 1798e397..fc83c3a8 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/util/result/VirtualPageCache.java +++ b/fj-core/src/main/java/org/fugerit/java/core/util/result/VirtualPageCache.java @@ -20,7 +20,7 @@ public VirtualPageCache() { private transient HashMap> cache; // 12 hours - private final static long DEFAULT_TTL = TimeUnit.MILLISECONDS.convert( 12, TimeUnit.HOURS ); // was 12*60*60*1000L + private static final long DEFAULT_TTL = TimeUnit.MILLISECONDS.convert( 12, TimeUnit.HOURS ); // was 12*60*60*1000L // true it the wrapper is still valid private boolean checkTtl( CacheWrapper wrapper ) { diff --git a/fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorCatalog.java b/fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorCatalog.java index 620fe959..ea2de798 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorCatalog.java +++ b/fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorCatalog.java @@ -35,7 +35,7 @@ */ public class ValidatorCatalog implements Serializable { - private final static Logger logger = LoggerFactory.getLogger(ValidatorCatalog.class); + private static final Logger logger = LoggerFactory.getLogger(ValidatorCatalog.class); public static final String TAG_CUSTOM_MESSAGE = "custom-messages"; diff --git a/fj-core/src/main/java/org/fugerit/java/core/xml/config/XMLSchemaCatalogConfig.java b/fj-core/src/main/java/org/fugerit/java/core/xml/config/XMLSchemaCatalogConfig.java index c68b0068..3f1d3c23 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/xml/config/XMLSchemaCatalogConfig.java +++ b/fj-core/src/main/java/org/fugerit/java/core/xml/config/XMLSchemaCatalogConfig.java @@ -25,6 +25,7 @@ import org.fugerit.java.core.lang.helpers.StringUtils; import org.w3c.dom.Element; import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; public class XMLSchemaCatalogConfig extends DataListCatalogConfig { @@ -116,10 +117,6 @@ public void validate( ErrorHandler er, SAXSource source, String schemaListId ) t validate(er, (Source)source, schemaListId); } - public static void validateWorker( ErrorHandler er, SAXSource source, Source[] xsds ) throws Exception { - validateWorker(er, (Source)source, xsds); - } - public void validateCacheSchema( ErrorHandler er, Source source, String schemaListId ) throws Exception { Schema schema = this.schemaMapCache.get( schemaListId ); if ( schema == null ) { @@ -136,13 +133,41 @@ public void validate( ErrorHandler er, Source source, String schemaListId ) thro validateWorker( er, source, xsds ); } - public static void validateWorker( ErrorHandler er, Source source, Source[] xsds ) throws Exception { - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema schema = sf.newSchema( xsds ); - validateWorker(er, source, schema); + /** + *

Validate an XML source.

+ * + *

NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.

+ * + * @see Define and throw a dedicated exception instead of using a generic one. + * + * @param er the error handler + * @param source the XML source + * @param xsds the reference XSD + */ + public static void validateWorker( ErrorHandler er, SAXSource source, Source[] xsds ) { + validateWorker(er, (Source)source, xsds); + } + + /** + *

Validate an XML source.

+ * + *

NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.

+ * + * @see Define and throw a dedicated exception instead of using a generic one. + * + * @param er the error handler + * @param source the XML source + * @param xsds the reference XSD + */ + public static void validateWorker( ErrorHandler er, Source source, Source[] xsds ) { + SafeFunction.apply( () -> { + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema = sf.newSchema( xsds ); + validateWorker(er, source, schema); + } ); } - private static void validateWorker( ErrorHandler er, Source source, Schema schema ) throws Exception { + private static void validateWorker( ErrorHandler er, Source source, Schema schema ) throws SAXException, IOException { Validator validator = schema.newValidator(); validator.setErrorHandler( er ); validator.validate(source); diff --git a/fj-core/src/main/java/org/fugerit/java/core/xml/sax/dh/DefaultHandlerComp.java b/fj-core/src/main/java/org/fugerit/java/core/xml/sax/dh/DefaultHandlerComp.java index 054e12fe..03aee9bf 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/xml/sax/dh/DefaultHandlerComp.java +++ b/fj-core/src/main/java/org/fugerit/java/core/xml/sax/dh/DefaultHandlerComp.java @@ -24,10 +24,10 @@ */ public class DefaultHandlerComp extends DefaultHandler { - public final static ErrorHandler DEFAULT_EH = new DoNothingErrorHandler(); - public final static EntityResolver DEFAULT_ER = new DoNothingEntityResolver(); - public final static DTDHandler DEFAULT_DH = new DoNothingDTDHandler(); - public final static ContentHandler DEFAULT_CH = new DoNothingContentHandler(); + public static final ErrorHandler DEFAULT_EH = new DoNothingErrorHandler(); + public static final EntityResolver DEFAULT_ER = new DoNothingEntityResolver(); + public static final DTDHandler DEFAULT_DH = new DoNothingDTDHandler(); + public static final ContentHandler DEFAULT_CH = new DoNothingContentHandler(); public DefaultHandlerComp() { this(DEFAULT_CH, DEFAULT_DH, DEFAULT_ER, DEFAULT_EH); diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfig.java b/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfig.java index 6b18ec5f..416e6f9c 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfig.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfig.java @@ -10,6 +10,10 @@ public class TestConfig { + private static AutoCloseable newTestComposite() { + return CloseableFactory.wrap( CloseableFactory.ERROR_CLOSEABLE ); + } + @Test public void testClose() throws ConfigException { // close config exception @@ -25,7 +29,7 @@ public void testClose() throws ConfigException { CloseHelper.closeRuntimeEx( CloseableFactory.DO_NOTHING_CLOSEABLE ); Assert.assertThrows( ConfigRuntimeException.class, () -> CloseHelper.closeRuntimeEx( CloseableFactory.ERROR_CLOSEABLE ) ); CloseHelper.closeRuntimeEx( CloseableFactory.wrap( CloseableFactory.DO_NOTHING_CLOSEABLE ) ); - Assert.assertThrows( ConfigRuntimeException.class, () -> CloseHelper.closeRuntimeEx( CloseableFactory.wrap( CloseableFactory.ERROR_CLOSEABLE ) ) ); + Assert.assertThrows( ConfigRuntimeException.class, () -> CloseHelper.closeRuntimeEx( newTestComposite() ) ); // close silent CloseHelper.closeSilent( (Closeable)null ); CloseHelper.closeSilent( (AutoCloseable)null ); diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java b/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java index f6b7b8bd..3cc85353 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/cfg/TestConfigRuntimeException.java @@ -9,6 +9,8 @@ public class TestConfigRuntimeException { + private static final IOException TEST_IO_EX = new IOException( "test io ex" ); + @Test public void testEx1() { Assert.assertNotNull( new ConfigRuntimeException() ); @@ -66,7 +68,7 @@ public void testEx11() { @Test public void testEx12() throws ConfigRuntimeException { - Assert.assertThrows( ConfigRuntimeException.class, () -> ConfigRuntimeException.stadardExceptionWrapping( new IOException( "n" ) ) ); + Assert.assertThrows( ConfigRuntimeException.class, () -> ConfigRuntimeException.stadardExceptionWrapping( TEST_IO_EX ) ); } } diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java b/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java index fa73f81f..16265ddf 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java @@ -40,6 +40,7 @@ private boolean worker( ConnectionFactory wrapped ) throws Exception { try ( ConnectionFactoryCloseable cf = ConnectionFactoryImpl.wrap( wrapped ); Connection conn = cf.getConnection() ) { log.info( "db info : {}", cf.getDataBaseInfo() ); + log.info( "db info second time : {}", cf.getDataBaseInfo() ); log.info( "driver info : {}", ConnectionFactoryImpl.getDriverInfo( cf ) ); } ok = (wrapped != null); @@ -50,15 +51,15 @@ private boolean worker( ConnectionFactory wrapped ) throws Exception { public void testCFProps() throws Exception { String name = "wrapped"; Properties props= PropsIO.loadFromClassLoaderSafe( BasicDBHelper.DEFAULT_DB_CONN_PATH ); + props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_IC , "1" ); + props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_SC , "1" ); + props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_MC , "3" ); ConnectionFactory wrapped = ConnectionFactoryImpl.newInstance( props ); ConnectionFacade.registerFactory( name , wrapped ); boolean ok = this.worker( ConnectionFacade.getFactory( name ) ); Assert.assertTrue(ok); // pooled - ok = this.worker( new DbcpConnectionFactory( props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_DRV ), - props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_URL ), - props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_USR ), - props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_PWD ), 1, 1, 3 ) ); + ok = this.worker( new DbcpConnectionFactory( props ) ); Assert.assertTrue(ok); } diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/rse/TestRSE.java b/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/rse/TestRSE.java index 5615e283..409d3649 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/rse/TestRSE.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/db/dao/rse/TestRSE.java @@ -149,7 +149,7 @@ public void testPropertyCachingRSE() throws SQLException { Assert.assertEquals( TEST_USERNAME , result.getProperty( "USERNAME" ) ); } - private final static String SIMPLE_QUERY = "SELECT * FROM fugerit.user"; + private static final String SIMPLE_QUERY = "SELECT * FROM fugerit.user"; @Test public void tesConnectionFacade() throws Exception { diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/db/helpers/MemDBTestBaseTester.java b/fj-core/src/test/java/test/org/fugerit/java/core/db/helpers/MemDBTestBaseTester.java index d05f8e5a..119de0ca 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/db/helpers/MemDBTestBaseTester.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/db/helpers/MemDBTestBaseTester.java @@ -16,7 +16,7 @@ public MemDBTestBaseTester() throws Exception { super(); } - protected final static Logger logger = LoggerFactory.getLogger(RunListener.class); + protected static final Logger logger = LoggerFactory.getLogger(RunListener.class); public void execute( Statement stm, String sql ) throws Exception { logger.info( "Execute : "+sql+" START!" ); diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/lang/binding/TestBindingCatalog.java b/fj-core/src/test/java/test/org/fugerit/java/core/lang/binding/TestBindingCatalog.java index 57ad4eeb..b4f6e486 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/lang/binding/TestBindingCatalog.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/lang/binding/TestBindingCatalog.java @@ -19,7 +19,7 @@ public class TestBindingCatalog { - private final static Logger logger = LoggerFactory.getLogger( TestBindingCatalog.class ); + private static final Logger logger = LoggerFactory.getLogger( TestBindingCatalog.class ); private static BindingCatalogConfig init() { diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/filter/TestPathHelper.java b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/filter/TestPathHelper.java index 55d8c8a0..06bb6cd2 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/filter/TestPathHelper.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/filter/TestPathHelper.java @@ -18,11 +18,11 @@ public class TestPathHelper extends BasicTest { - private final static TestModelOne TEST_CASE_001 = new TestModelOne( new BigDecimal( 1 ), "value 001_1", new TestModelTwo( new BigDecimal( 2 ), "value 001_2" ) ); + private static final TestModelOne TEST_CASE_001 = new TestModelOne( new BigDecimal( 1 ), "value 001_1", new TestModelTwo( new BigDecimal( 2 ), "value 001_2" ) ); - private final static TestModelOne TEST_CASE_002 = new TestModelOne(); + private static final TestModelOne TEST_CASE_002 = new TestModelOne(); - private final static TestModelOne TEST_CASE_003 = new TestModelOne( new BigDecimal( 3 ), "value 003_1", null ); + private static final TestModelOne TEST_CASE_003 = new TestModelOne( new BigDecimal( 3 ), "value 003_1", null ); private void testFilterWorker( Object target, Collection filters, boolean expectedResult ) { try { diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java new file mode 100644 index 00000000..49f857eb --- /dev/null +++ b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java @@ -0,0 +1,32 @@ +package test.org.fugerit.java.core.lang.helpers.reflect; + +import org.fugerit.java.core.cfg.ConfigRuntimeException; +import org.fugerit.java.core.lang.helpers.reflect.FieldHelper; +import org.junit.Assert; +import org.junit.Test; + +import lombok.Getter; +import lombok.Setter; + +public class TestFieldHelper { + + private static final String TEST_VALUE = "test1"; + + public class CheckBean { + @Getter @Setter private String field1; + public String field2; + } + + @Test + public void testSetField() { + CheckBean bean = new CheckBean(); + Assert.assertNull( bean.getField1() ); + FieldHelper.setField(bean, "field1", TEST_VALUE, true); + Assert.assertEquals( TEST_VALUE , FieldHelper.getField(bean, "field1", true) ); + FieldHelper.setField(bean, "field2", TEST_VALUE); + Assert.assertEquals( TEST_VALUE , FieldHelper.getField(bean, "field2") ); + Assert.assertThrows( ConfigRuntimeException.class , () -> FieldHelper.setField(bean, "field1", TEST_VALUE) ); + Assert.assertThrows( ConfigRuntimeException.class , () -> FieldHelper.getField(bean, "field1") ); + } + +} diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestPathHelper.java b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestPathHelper.java index 53750219..16417ca6 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestPathHelper.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestPathHelper.java @@ -11,15 +11,15 @@ public class TestPathHelper extends BasicTest { - private final static int EXPECTED_RESULT_EXCEPTION = 1; - private final static int EXPECTED_RESULT_NULL = 2; - private final static int EXPECTED_RESULT_VALUE = 3; + private static final int EXPECTED_RESULT_EXCEPTION = 1; + private static final int EXPECTED_RESULT_NULL = 2; + private static final int EXPECTED_RESULT_VALUE = 3; - private final static TestModelOne TEST_CASE_001 = new TestModelOne( new BigDecimal( 1 ), "value 001_1", new TestModelTwo( new BigDecimal( 2 ), "value 001_2" ) ); + private static final TestModelOne TEST_CASE_001 = new TestModelOne( new BigDecimal( 1 ), "value 001_1", new TestModelTwo( new BigDecimal( 2 ), "value 001_2" ) ); - private final static TestModelOne TEST_CASE_002 = new TestModelOne(); + private static final TestModelOne TEST_CASE_002 = new TestModelOne(); - private final static TestModelOne TEST_CASE_003 = new TestModelOne( new BigDecimal( 3 ), "value 003_1", null ); + private static final TestModelOne TEST_CASE_003 = new TestModelOne( new BigDecimal( 3 ), "value 003_1", null ); private void testLookupWorker( Object target, String path, boolean useMethodLookup, boolean continueOnNull, int expectedResult ) { try { diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestDuplicateFailOnSet.java b/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestDuplicateFailOnSet.java index fddbdf03..6fe692f5 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestDuplicateFailOnSet.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestDuplicateFailOnSet.java @@ -10,7 +10,7 @@ public class TestDuplicateFailOnSet { - private final static Logger logger = LoggerFactory.getLogger( TestDuplicateFailOnSet.class ); + private static final Logger logger = LoggerFactory.getLogger( TestDuplicateFailOnSet.class ); private static final String CONF_PATH_DUPLICATE_FAIL_ON_SET = "core/util/filterchain/minifilter-test-duplicate-fail-on-set.xml"; diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java b/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java index f9591766..0a1c514e 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java @@ -4,13 +4,19 @@ import static org.junit.Assert.fail; import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.Iterator; +import org.fugerit.java.core.lang.helpers.ClassHelper; import org.fugerit.java.core.util.filterchain.MiniFilterChain; import org.fugerit.java.core.util.filterchain.MiniFilterConfig; import org.fugerit.java.core.util.filterchain.MiniFilterContext; import org.fugerit.java.core.util.filterchain.MiniFilterData; +import org.fugerit.java.core.util.filterchain.MiniFilterDebug; import org.fugerit.java.core.util.filterchain.MiniFilterMap; +import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +25,7 @@ public class TestMiniFilter extends BasicTest { - private final static Logger logger = LoggerFactory.getLogger( TestMiniFilter.class ); + private static final Logger logger = LoggerFactory.getLogger( TestMiniFilter.class ); private static final String CONF_PATH = "core/util/filterchain/minifilter-test-config.xml"; @@ -108,6 +114,31 @@ public void testSerialization() { } } + @Test + public void testLoadMap() { + runTestEx( () -> { + try ( InputStream is = ClassHelper.loadFromDefaultClassLoader(CONF_PATH) ) { + MiniFilterConfig config = new MiniFilterConfig(); + MiniFilterMap map = MiniFilterConfig.loadConfigMap( is , config ); + Assert.assertNotNull( map ); + } + } ); + } + + @Test + public void testDebug() { + runTestEx( () -> { + try ( InputStream is = ClassHelper.loadFromDefaultClassLoader(CONF_PATH); + StringWriter buffer = new StringWriter(); + PrintWriter writer = new PrintWriter(buffer)) { + MiniFilterDebug.dumpConfig( writer , is ); + String debugText = buffer.toString(); + Assert.assertNotEquals( 0 , debugText.length() ); + logger.info( "debug {}", debugText ); + } + } ); + } + @Test public void testPrintConfig() { logger.info( "**********************************************" ); diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/util/i18n/TestHelperI18N.java b/fj-core/src/test/java/test/org/fugerit/java/core/util/i18n/TestHelperI18N.java index 88012ba1..7e4c5af0 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/util/i18n/TestHelperI18N.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/util/i18n/TestHelperI18N.java @@ -11,15 +11,15 @@ public class TestHelperI18N { - public final static String LANG_EN = "en"; + public static final String LANG_EN = "en"; - public final static String LANG_IT = "it"; + public static final String LANG_IT = "it"; - public final static String LANG_DEF = LANG_EN; + public static final String LANG_DEF = LANG_EN; - public final static String LANG_ALT[] = { LANG_IT }; + public static final String LANG_ALT[] = { LANG_IT }; - private final static Logger logger = LoggerFactory.getLogger( TestHelperI18N.class ); + private static final Logger logger = LoggerFactory.getLogger( TestHelperI18N.class ); private static final String CONF_PATH = "core.util.i18n.test"; diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/util/result/TestResult.java b/fj-core/src/test/java/test/org/fugerit/java/core/util/result/TestResult.java index 4fe86825..b6d32aa0 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/util/result/TestResult.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/util/result/TestResult.java @@ -121,7 +121,7 @@ public void testPagedResultKo() { @Test public void testConstants() { - Assert.assertEquals( Integer.valueOf( -1 ) , PagedResult.ELEMENT_COUNT_UNAVAILABLE ); + Assert.assertEquals( PagedResult.ELEMENT_COUNT_UNAVAILABLE, Integer.valueOf( -1 ) ); Assert.assertFalse( AbstractPagedResult.DEFAULT_SUPPORT_VIRTUAL_PAGING ); } @@ -135,7 +135,7 @@ public void testVirtualFinder() { log.info( "finder.getRealPerPage : {}", finder.getRealPerPage() ); log.info( "finder.isVirtualPagingUsed : {}", finder.isVirtualPagingUsed() ); log.info( "finder : {}", finder ); - Assert.assertTrue( finder != null ); + Assert.assertNotNull( finder ); } @Test diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/validator/TestValidatorCatalog.java b/fj-core/src/test/java/test/org/fugerit/java/core/validator/TestValidatorCatalog.java index fe6b16d9..12ab0156 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/validator/TestValidatorCatalog.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/validator/TestValidatorCatalog.java @@ -17,7 +17,7 @@ public class TestValidatorCatalog extends BasicTest { - private final static String CONFIG_PATH = "cl://core/validator/validator-catalog-test.xml"; + private static final String CONFIG_PATH = "cl://core/validator/validator-catalog-test.xml"; private static ValidatorCatalog catalog = null; static { diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/xml/TestTransformerXML.java b/fj-core/src/test/java/test/org/fugerit/java/core/xml/TestTransformerXML.java index d5502790..89184801 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/xml/TestTransformerXML.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/xml/TestTransformerXML.java @@ -28,7 +28,7 @@ public class TestTransformerXML extends BasicTest { public void newSafeTransformerFactory() { TransformerFactory factory = TransformerXML.newSafeTransformerFactory(); log.info( "factory -> {}", factory ); - Assert.assertTrue( factory != null ); + Assert.assertNotNull( factory ); } @Test @@ -51,7 +51,7 @@ public void newSafeTransformerFactoryFeature() { features.setProperty( XMLConstants.FEATURE_SECURE_PROCESSING , BooleanUtils.BOOLEAN_FALSE ); TransformerFactory factory = TransformerXML.newSafeTransformerFactory( features ); log.info( "factory -> {}", factory ); - Assert.assertTrue( factory != null ); + Assert.assertNotNull( factory ); } @Test diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/xml/config/TestXMLSchemaCatalogConfig.java b/fj-core/src/test/java/test/org/fugerit/java/core/xml/config/TestXMLSchemaCatalogConfig.java index f59028da..8cf74174 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/xml/config/TestXMLSchemaCatalogConfig.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/xml/config/TestXMLSchemaCatalogConfig.java @@ -151,16 +151,14 @@ public void activateValidation() { @Test public void newInstanceException() { Assert.assertThrows( ConfigRuntimeException.class , () -> { - XMLSchemaCatalogConfig current = loadCatalogSafe( "core/xml/config/xml_schema_catalog/schema-validator-config_fail2.xml" ); - logger.info( "activateValidation() catalog loaded : {}", current ); + loadCatalogSafe( "core/xml/config/xml_schema_catalog/schema-validator-config_fail2.xml" ); }); } @Test public void newInstanceExceptionDuplicate() { Assert.assertThrows( ConfigRuntimeException.class , () -> { - XMLSchemaCatalogConfig current = loadCatalogSafe( "core/xml/config/xml_schema_catalog/schema-validator-config_fail3.xml" ); - logger.info( "activateValidation() catalog loaded : {}", current ); + loadCatalogSafe( "core/xml/config/xml_schema_catalog/schema-validator-config_fail3.xml" ); }); } diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/xml/dom/TestDOMIO.java b/fj-core/src/test/java/test/org/fugerit/java/core/xml/dom/TestDOMIO.java index 7e1d0627..e55fe1fa 100644 --- a/fj-core/src/test/java/test/org/fugerit/java/core/xml/dom/TestDOMIO.java +++ b/fj-core/src/test/java/test/org/fugerit/java/core/xml/dom/TestDOMIO.java @@ -80,7 +80,7 @@ public void testNewDocumentBuilderFactoryOk() { public void testNewUnsafeDocumentBuilderFactory() { DocumentBuilderFactory dbf = DOMIO.newDocumentBuilderFactory( true ); log.info( "DOMIO.newDocumentBuilderFactory -> {}", dbf ); - Assert.assertTrue( dbf != null ); + Assert.assertNotNull( dbf ); } @@ -88,7 +88,7 @@ public void testNewUnsafeDocumentBuilderFactory() { public void testNewSafeDocumentBuilderFactory() { DocumentBuilderFactory dbf = DOMIO.newSafeDocumentBuilderFactory(); log.info( "DOMIO.newSafeDocumentBuilderFactory -> {}", dbf ); - Assert.assertTrue( dbf != null ); + Assert.assertNotNull( dbf ); } @Test diff --git a/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandler.java b/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandler.java index b895b207..64df586f 100644 --- a/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandler.java +++ b/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandler.java @@ -20,8 +20,7 @@ public interface ToolHandler { * * @param params the params * @return the result code of the operation - * @throws Exception if issues arises */ - public int handle( Properties params ) throws Exception; + public int handle( Properties params ); } diff --git a/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandlerHelper.java b/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandlerHelper.java index 29bc0628..d886c080 100644 --- a/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandlerHelper.java +++ b/fj-tool/src/main/java/org/fugerit/java/tool/ToolHandlerHelper.java @@ -39,7 +39,7 @@ public abstract class ToolHandlerHelper implements ToolHandler { abstract public int handleWorker( Properties params ) throws RunToolException; @Override - public int handle( Properties params ) throws Exception { + public int handle( Properties params ) { int exit = EXIT_OK; try { exit = handleWorker( params ); diff --git a/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java b/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java index b7a08b2f..e7fd3b8c 100644 --- a/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java +++ b/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java @@ -52,9 +52,9 @@ public class ExtractFixedConfigHandler extends ToolHandlerHelper { private int handleRow( int start, String length, String name, List listFields, int rowCount ) { Integer len = Integer.valueOf( length ); FixedFieldDescriptor ffd = new FixedFieldDescriptor( name, start, len ); - logger.info( "field descriptor : {}", ffd ); + logger.info( "field descriptor : {}, rowCount : {}", ffd, rowCount ); listFields.add( ffd ); - return (start+= len); + return (start+len); } @Override