IDEMPIERE-4695 Add document factory base class backed by Map and Lambda functional object (#576)
MappedDocumentFactoryTest fail when running idempiere.unit.test due to document factory cache.
This commit is contained in:
parent
5e31c1fdb0
commit
c757fbaab7
|
@ -47,6 +47,8 @@ import org.compiere.util.ValueNamePair;
|
||||||
*/
|
*/
|
||||||
public class DocManager {
|
public class DocManager {
|
||||||
|
|
||||||
|
public static final String IDOC_FACTORY_CACHE_TABLE_NAME = "_IDocFactory_Cache";
|
||||||
|
|
||||||
private final static CLogger s_log = CLogger.getCLogger(DocManager.class);
|
private final static CLogger s_log = CLogger.getCLogger(DocManager.class);
|
||||||
|
|
||||||
/** AD_Table_ID's of documents */
|
/** AD_Table_ID's of documents */
|
||||||
|
@ -110,7 +112,7 @@ public class DocManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final CCache<String, IServiceReferenceHolder<IDocFactory>> s_DocFactoryCache = new CCache<>(null, "IDocFactory", 100, false);
|
private static final CCache<String, IServiceReferenceHolder<IDocFactory>> s_DocFactoryCache = new CCache<>(IDOC_FACTORY_CACHE_TABLE_NAME, "IDocFactory", 100, false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Posting document
|
* Create Posting document
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.compiere.acct.Doc_InOut;
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
import org.compiere.model.MClientInfo;
|
import org.compiere.model.MClientInfo;
|
||||||
import org.compiere.model.MInOut;
|
import org.compiere.model.MInOut;
|
||||||
|
import org.compiere.util.CacheMgt;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.idempiere.test.AbstractTestCase;
|
import org.idempiere.test.AbstractTestCase;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -55,6 +56,9 @@ public class MappedDocumentFactoryTest extends AbstractTestCase {
|
||||||
IMappedDocumentFactory factory = Core.getMappedDocumentFactory();
|
IMappedDocumentFactory factory = Core.getMappedDocumentFactory();
|
||||||
factory.addMapping(null, MInOut.Table_Name, (p) -> new MyDocInOut(p.as, p.rs, p.trxName));
|
factory.addMapping(null, MInOut.Table_Name, (p) -> new MyDocInOut(p.as, p.rs, p.trxName));
|
||||||
|
|
||||||
|
//need to reset cache if you are replacing doc classes from core
|
||||||
|
CacheMgt.get().reset(DocManager.IDOC_FACTORY_CACHE_TABLE_NAME);
|
||||||
|
|
||||||
int C_AcctSchema_ID = MClientInfo.get().getC_AcctSchema1_ID();
|
int C_AcctSchema_ID = MClientInfo.get().getC_AcctSchema1_ID();
|
||||||
MAcctSchema as = new MAcctSchema(Env.getCtx(), C_AcctSchema_ID, getTrxName());
|
MAcctSchema as = new MAcctSchema(Env.getCtx(), C_AcctSchema_ID, getTrxName());
|
||||||
Doc doc = DocManager.getDocument(as, MInOut.Table_ID, 100, getTrxName());
|
Doc doc = DocManager.getDocument(as, MInOut.Table_ID, 100, getTrxName());
|
||||||
|
|
|
@ -687,7 +687,7 @@ public class CacheTest extends AbstractTestCase {
|
||||||
if (ci instanceof CCache<?, ?>) {
|
if (ci instanceof CCache<?, ?>) {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
CCache ccache = (CCache) ci;
|
CCache ccache = (CCache) ci;
|
||||||
if (ccache.getTableName() == null && ccache.getName().equals(name)) {
|
if (ccache.getName().equals(name)) {
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
if (ccache.containsKey(key)) {
|
if (ccache.containsKey(key)) {
|
||||||
return ccache;
|
return ccache;
|
||||||
|
|
Loading…
Reference in New Issue