IDEMPIERE-4704 Add base interface and class that uses generic type and lambda function for osgi factory that create new instance by class name or a string key (#595)
Fix unit test error when running through maven/jenkin (mvn verify -DskipTests=false)
This commit is contained in:
parent
5ca8d44d48
commit
4ebf81b1d2
|
@ -67,9 +67,35 @@ import org.idempiere.process.IMappedProcessFactory;
|
|||
*/
|
||||
public class Core {
|
||||
|
||||
public static final String SCRIPT_ENGINE_FACTORY_CACHE_TABLE_NAME = "_ScriptEngineFactory_Cache";
|
||||
|
||||
public static final String IPROCESS_FACTORY_CACHE_TABLE_NAME = "_IProcessFactory_Cache";
|
||||
|
||||
public static final String IRESOURCE_FINDER_CACHE_TABLE_NAME = "_IResourceFinder_Cache";
|
||||
|
||||
public static final String IDEPRECIATION_METHOD_FACTORY_CACHE_TABLE_NAME = "_IDepreciationMethodFactory_Cache";
|
||||
|
||||
public static final String IPAYMENT_EXPORTER_FACTORY_CACHE_TABLE_NAME = "_IPaymentExporterFactory_Cache";
|
||||
|
||||
public static final String IREPLENISH_FACTORY_CACHE_TABLE_NAME = "_IReplenishFactory_Cache";
|
||||
|
||||
public static final String ITAX_PROVIDER_FACTORY_CACHE_TABLE_NAME = "_ITaxProviderFactory_Cache";
|
||||
|
||||
public static final String IADDRESS_VALIDATION_FACTORY_CACHE_TABLE_NAME = "_IAddressValidationFactory_Cache";
|
||||
|
||||
public static final String IBANK_STATEMENT_MATCHER_FACTORY_CACHE_TABLE_NAME = "_IBankStatementMatcherFactory_Cache";
|
||||
|
||||
public static final String IBANK_STATEMENT_LOADER_FACTORY_CACHE_TABLE_NAME = "_IBankStatementLoaderFactory_Cache";
|
||||
|
||||
public static final String IMODEL_VALIDATOR_FACTORY_CACHE_TABLE_NAME = "_IModelValidatorFactory_Cache";
|
||||
|
||||
public static final String ISHIPMENT_PROCESSOR_FACTORY_CACHE_TABLE_NAME = "_IShipmentProcessorFactory_Cache";
|
||||
|
||||
public static final String IPAYMENT_PROCESSOR_FACTORY_CACHE_TABLE_NAME = "_IPaymentProcessorFactory_Cache";
|
||||
|
||||
private final static CLogger s_log = CLogger.getCLogger(Core.class);
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IResourceFinder>> s_resourceFinderCache = new CCache<>(null, "IResourceFinder", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IResourceFinder>> s_resourceFinderCache = new CCache<>(IRESOURCE_FINDER_CACHE_TABLE_NAME, "IResourceFinder", 100, false);
|
||||
|
||||
/**
|
||||
* @return list of active resource finder
|
||||
|
@ -124,7 +150,7 @@ public class Core {
|
|||
return ColumnCalloutManager.getCallout(className, methodName);
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IProcessFactory>> s_processFactoryCache = new CCache<>(null, "IProcessFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IProcessFactory>> s_processFactoryCache = new CCache<>(IPROCESS_FACTORY_CACHE_TABLE_NAME, "IProcessFactory", 100, false);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -193,7 +219,7 @@ public class Core {
|
|||
return factories;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IModelValidatorFactory>> s_modelValidatorFactoryCache = new CCache<>(null, "IModelValidatorFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IModelValidatorFactory>> s_modelValidatorFactoryCache = new CCache<>(IMODEL_VALIDATOR_FACTORY_CACHE_TABLE_NAME, "IModelValidatorFactory", 100, false);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -249,7 +275,7 @@ public class Core {
|
|||
return keystoreService;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IPaymentProcessorFactory>> s_paymentProcessorFactoryCache = new CCache<>(null, "IPaymentProcessorFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IPaymentProcessorFactory>> s_paymentProcessorFactoryCache = new CCache<>(IPAYMENT_PROCESSOR_FACTORY_CACHE_TABLE_NAME, "IPaymentProcessorFactory", 100, false);
|
||||
|
||||
/**
|
||||
* Get payment processor instance
|
||||
|
@ -308,7 +334,7 @@ public class Core {
|
|||
return myProcessor;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IBankStatementLoaderFactory>> s_bankStatementLoaderFactoryCache = new CCache<>(null, "IBankStatementLoaderFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IBankStatementLoaderFactory>> s_bankStatementLoaderFactoryCache = new CCache<>(IBANK_STATEMENT_LOADER_FACTORY_CACHE_TABLE_NAME, "IBankStatementLoaderFactory", 100, false);
|
||||
|
||||
/**
|
||||
* get BankStatementLoader instance
|
||||
|
@ -359,7 +385,7 @@ public class Core {
|
|||
return myBankStatementLoader;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IBankStatementMatcherFactory>> s_bankStatementMatcherFactoryCache = new CCache<>(null, "IBankStatementMatcherFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IBankStatementMatcherFactory>> s_bankStatementMatcherFactoryCache = new CCache<>(IBANK_STATEMENT_MATCHER_FACTORY_CACHE_TABLE_NAME, "IBankStatementMatcherFactory", 100, false);
|
||||
|
||||
/**
|
||||
* get BankStatementMatcher instance
|
||||
|
@ -410,7 +436,7 @@ public class Core {
|
|||
return myBankStatementMatcher;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IShipmentProcessorFactory>> s_shipmentProcessorFactoryCache = new CCache<>(null, "IShipmentProcessorFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IShipmentProcessorFactory>> s_shipmentProcessorFactoryCache = new CCache<>(ISHIPMENT_PROCESSOR_FACTORY_CACHE_TABLE_NAME, "IShipmentProcessorFactory", 100, false);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -456,7 +482,7 @@ public class Core {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IAddressValidationFactory>> s_addressValidationFactoryCache = new CCache<>(null, "IAddressValidationFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IAddressValidationFactory>> s_addressValidationFactoryCache = new CCache<>(IADDRESS_VALIDATION_FACTORY_CACHE_TABLE_NAME, "IAddressValidationFactory", 100, false);
|
||||
|
||||
/**
|
||||
* Get address validation instance
|
||||
|
@ -500,7 +526,7 @@ public class Core {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<ITaxProviderFactory>> s_taxProviderFactoryCache = new CCache<>(null, "ITaxProviderFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<ITaxProviderFactory>> s_taxProviderFactoryCache = new CCache<>(ITAX_PROVIDER_FACTORY_CACHE_TABLE_NAME, "ITaxProviderFactory", 100, false);
|
||||
|
||||
/**
|
||||
* Get tax provider instance
|
||||
|
@ -557,7 +583,7 @@ public class Core {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IReplenishFactory>> s_replenishFactoryCache = new CCache<>(null, "IReplenishFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IReplenishFactory>> s_replenishFactoryCache = new CCache<>(IREPLENISH_FACTORY_CACHE_TABLE_NAME, "IReplenishFactory", 100, false);
|
||||
|
||||
/**
|
||||
* get Custom Replenish instance
|
||||
|
@ -608,7 +634,7 @@ public class Core {
|
|||
return myReplenishInstance;
|
||||
}
|
||||
|
||||
private final static CCache<String, IServiceReferenceHolder<ScriptEngineFactory>> s_scriptEngineFactoryCache = new CCache<>(null, "ScriptEngineFactory", 100, false);
|
||||
private final static CCache<String, IServiceReferenceHolder<ScriptEngineFactory>> s_scriptEngineFactoryCache = new CCache<>(SCRIPT_ENGINE_FACTORY_CACHE_TABLE_NAME, "ScriptEngineFactory", 100, false);
|
||||
|
||||
/** Get script engine
|
||||
*
|
||||
|
@ -647,7 +673,7 @@ public class Core {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static final CCache<String, IServiceReferenceHolder<IPaymentExporterFactory>> s_paymentExporterFactory = new CCache<>(null, "IPaymentExporterFactory", 100, false);
|
||||
private static final CCache<String, IServiceReferenceHolder<IPaymentExporterFactory>> s_paymentExporterFactory = new CCache<>(IPAYMENT_EXPORTER_FACTORY_CACHE_TABLE_NAME, "IPaymentExporterFactory", 100, false);
|
||||
|
||||
/**
|
||||
* get PaymentExporter instance
|
||||
|
@ -730,7 +756,7 @@ public class Core {
|
|||
return null;
|
||||
}
|
||||
|
||||
private final static CCache<String, IServiceReferenceHolder<IDepreciationMethodFactory>> s_depreciationMethodFactoryCache = new CCache<>(null, "IDepreciationMethodFactory", 100, false);
|
||||
private final static CCache<String, IServiceReferenceHolder<IDepreciationMethodFactory>> s_depreciationMethodFactoryCache = new CCache<>(IDEPRECIATION_METHOD_FACTORY_CACHE_TABLE_NAME, "IDepreciationMethodFactory", 100, false);
|
||||
|
||||
/**
|
||||
* lookup implement {@link IDepreciationMethod}
|
||||
|
|
|
@ -2,4 +2,4 @@ source.. = src/
|
|||
output.. = target/classes/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
OSGI-INF/org.idempiere.test.event.MyComponent.xml
|
||||
OSGI-INF/
|
||||
|
|
|
@ -73,6 +73,7 @@ import org.compiere.model.X_C_AddressValidationCfg;
|
|||
import org.compiere.model.X_C_TaxProviderCfg;
|
||||
import org.compiere.model.X_I_BankStatement;
|
||||
import org.compiere.model.X_T_Replenish;
|
||||
import org.compiere.util.CacheMgt;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.GenericPaymentExport;
|
||||
import org.compiere.util.PaymentExport;
|
||||
|
@ -145,7 +146,7 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
|
||||
var validator = Core.getModelValidator(MyModelValidator.class.getName());
|
||||
assertNotNull(validator);
|
||||
assertTrue(validator instanceof MyModelValidator);
|
||||
assertTrue(validator instanceof MyModelValidator, "validator not instanceof MyModelValidator. validator="+validator.getClass().getName());
|
||||
}
|
||||
|
||||
private final static class MyPaymentProcessor extends PaymentProcessor {
|
||||
|
@ -180,13 +181,15 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
properties.put("service.ranking", Integer.valueOf(1));
|
||||
ServiceRegistration<IPaymentProcessorFactory> registration = bc.registerService(IPaymentProcessorFactory.class, new MyPaymentProcessFactory(), properties);
|
||||
|
||||
CacheMgt.get().reset(Core.IPAYMENT_PROCESSOR_FACTORY_CACHE_TABLE_NAME);
|
||||
|
||||
PaymentInterface mp = null;
|
||||
MBankAccountProcessor mbap;
|
||||
Query query = new Query(Env.getCtx(), MBankAccountProcessor.Table_Name, MTable.getUUIDColumnName(MBankAccountProcessor.Table_Name)+"=?", null);
|
||||
mbap = query.setParameters("f4a64026-bf68-4c8c-b238-8cdf006aae04").first();
|
||||
var pp = Core.getPaymentProcessor(mbap, mp);
|
||||
assertNotNull(pp);
|
||||
assertTrue(pp instanceof MyPaymentProcessor);
|
||||
assertTrue(pp instanceof MyPaymentProcessor, "pp not instanceof MyPaymentProcessor. pp="+pp.getClass().getName());
|
||||
|
||||
registration.unregister();
|
||||
}
|
||||
|
@ -352,7 +355,7 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
bc.registerService(IBankStatementLoaderFactory.class, new MyBankStatementLoaderFactory(), properties);
|
||||
var loader = Core.getBankStatementLoader(MyBankStatementLoader.class.getName());
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyBankStatementLoader);
|
||||
assertTrue(loader instanceof MyBankStatementLoader, "loader not instanceof MyBankStatementLoader. loader="+loader.getClass().getName());
|
||||
}
|
||||
|
||||
private static final class MyBankStatementMatcher implements BankStatementMatcherInterface {
|
||||
|
@ -387,7 +390,7 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
bc.registerService(IBankStatementMatcherFactory.class, new MyBankStatementMatcherFactory(), properties);
|
||||
var loader = Core.getBankStatementMatcher(MyBankStatementMatcher.class.getName());
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyBankStatementMatcher);
|
||||
assertTrue(loader instanceof MyBankStatementMatcher, "loader not instanceof MyBankStatementMatcher. loader="+loader.getClass().getName());
|
||||
}
|
||||
|
||||
private final static class MyShipmentProcessor extends MFreightShipmentProcessor {
|
||||
|
@ -411,11 +414,14 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
Dictionary<String, Object> properties = new Hashtable<String, Object>();
|
||||
properties.put("service.ranking", Integer.valueOf(1));
|
||||
ServiceRegistration<IShipmentProcessorFactory> sr = bc.registerService(IShipmentProcessorFactory.class, new MyShipmentProcessorFactory(), properties);
|
||||
|
||||
CacheMgt.get().reset(Core.ISHIPMENT_PROCESSOR_FACTORY_CACHE_TABLE_NAME);
|
||||
|
||||
MShipper shipper = new MShipper(Env.getCtx(), 100, getTrxName());
|
||||
MShipperFacade sf = new MShipperFacade(shipper);
|
||||
var loader = Core.getShipmentProcessor(sf);
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyShipmentProcessor);
|
||||
assertTrue(loader instanceof MyShipmentProcessor, "loader not instanceof MyShipmentProcessor. loader="+loader.getClass().getName());
|
||||
sr.unregister();
|
||||
}
|
||||
|
||||
|
@ -458,7 +464,7 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
adv.setName("testAddressVallidation");
|
||||
var loader = Core.getAddressValidation(adv);
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyAddressValidation);
|
||||
assertTrue(loader instanceof MyAddressValidation, "loader not instanceof MyAddressValidation. loader="+loader.getClass().getName());
|
||||
sr.unregister();
|
||||
}
|
||||
|
||||
|
@ -493,7 +499,7 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
tp.saveEx();
|
||||
var loader = Core.getTaxProvider(tp);
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyTaxProvider);
|
||||
assertTrue(loader instanceof MyTaxProvider, "loader not instanceof MyTaxProvider. loader="+loader.getClass().getName());
|
||||
sr.unregister();
|
||||
}
|
||||
|
||||
|
@ -524,7 +530,7 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
bc.registerService(IReplenishFactory.class, new MyReplenishInterfaceFactory(), properties);
|
||||
var loader = Core.getReplenish(MyReplenishInterface.class.getName());
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyReplenishInterface);
|
||||
assertTrue(loader instanceof MyReplenishInterface, "loader not instanceof MyReplenishInterface. loader="+loader.getClass().getName());
|
||||
}
|
||||
|
||||
private final static class MyPaymentExport extends GenericPaymentExport {
|
||||
|
@ -550,7 +556,7 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
bc.registerService(IPaymentExporterFactory.class, new MyPaymentExportFactory(), properties);
|
||||
var loader = Core.getPaymentExporter(MyPaymentExport.class.getName());
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyPaymentExport);
|
||||
assertTrue(loader instanceof MyPaymentExport, "loader not instanceof MyPaymentExport loader="+loader.getClass().getName());
|
||||
}
|
||||
|
||||
private final static class MyDepreciationMethod implements IDepreciationMethod {
|
||||
|
@ -592,6 +598,6 @@ public class MappedByNameFactoryTest extends AbstractTestCase {
|
|||
dto.depreciationType = "MyDepreciationMethod";
|
||||
var loader = Core.getDepreciationMethod(dto);
|
||||
assertNotNull(loader);
|
||||
assertTrue(loader instanceof MyDepreciationMethod);
|
||||
assertTrue(loader instanceof MyDepreciationMethod, "loader not instanceof MyDepreciationMethod. loader="+loader.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue