From bd5880e73c6a91a9e07b860583816f346e00326a Mon Sep 17 00:00:00 2001 From: Javier <10879637+javiertuya@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:04:07 +0200 Subject: [PATCH] Configure rules cache from qacover.properties --- .../Configuration.cs | 26 +++++++++---------- .../RuleServices.cs | 4 +-- .../Translated/Test4giis.Qacover/Base.cs | 2 +- .../Test4giis.Qacover/TestFaults.cs | 2 +- net/qacover.properties | 1 + qacover-core/qacover.properties | 4 +++ .../qacover/core/services/Configuration.java | 19 +++++++------- .../qacover/core/services/RuleServices.java | 4 +-- .../src/test/java/test4giis/qacover/Base.java | 4 ++- .../java/test4giis/qacover/TestFaults.java | 2 +- 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/net/QACover/Translated/Giis.Qacover.Core.Services/Configuration.cs b/net/QACover/Translated/Giis.Qacover.Core.Services/Configuration.cs index 9c4c340..458c5dd 100644 --- a/net/QACover/Translated/Giis.Qacover.Core.Services/Configuration.cs +++ b/net/QACover/Translated/Giis.Qacover.Core.Services/Configuration.cs @@ -29,7 +29,7 @@ public class Configuration private string storeRulesLocation; - private string cacheRulesLocation; + private string ruleCache; private string storeReportsLocation; @@ -91,6 +91,7 @@ public virtual Giis.Qacover.Core.Services.Configuration Reset() } ruleUrl = GetProperty("qacover.rule.url", "https://in2test.lsi.uniovi.es/tdrules/api/v4"); ruleOptions = GetProperty("qacover.rule.options", string.Empty); + ruleCache = GetProperty("qacover.rule.cache", string.Empty); optimizeRuleEvaluation = JavaCs.EqualsIgnoreCase("true", GetProperty("qacover.rule.optimize.evaluation", "false")); inferQueryParameters = JavaCs.EqualsIgnoreCase("true", GetProperty("qacover.query.infer.parameters", "false")); // Includes some predefined stack exclusions @@ -260,18 +261,6 @@ public virtual void SetStoreRulesLocation(string location) storeRulesLocation = location; } - public virtual string GetCacheRulesLocation() - { - return cacheRulesLocation; - } - - public virtual Giis.Qacover.Core.Services.Configuration SetCacheRulesLocation(string location) - { - // Ensures that location is relative to project root and not null - cacheRulesLocation = location != null && !string.Empty.Equals(location) ? FileUtil.GetPath(Parameters.GetProjectRoot(), location) : string.Empty; - return this; - } - public virtual string GetStoreReportsLocation() { return storeReportsLocation; @@ -315,6 +304,17 @@ public virtual Giis.Qacover.Core.Services.Configuration SetRuleServiceUrl(string return this; } + public virtual string GetRuleCacheFolder() + { + return ruleCache; + } + + public virtual Giis.Qacover.Core.Services.Configuration SetRuleCacheFolder(string folder) + { + ruleCache = folder; + return this; + } + public virtual bool GetOptimizeRuleEvaluation() { return optimizeRuleEvaluation; diff --git a/net/QACover/Translated/Giis.Qacover.Core.Services/RuleServices.cs b/net/QACover/Translated/Giis.Qacover.Core.Services/RuleServices.cs index 453302f..911b3a7 100644 --- a/net/QACover/Translated/Giis.Qacover.Core.Services/RuleServices.cs +++ b/net/QACover/Translated/Giis.Qacover.Core.Services/RuleServices.cs @@ -44,8 +44,8 @@ public virtual void SetErrorContext(string message) private TdRulesApi GetApi() { string uri = Configuration.GetInstance().GetRuleServiceUrl(); - string cacheLocation = Configuration.GetInstance().GetCacheRulesLocation(); - log.Debug("Call service: {}, cache: {}", uri, cacheLocation); + string cacheLocation = Configuration.GetInstance().GetRuleCacheFolder(); + log.Debug("Call service: {}, using cache: {}", uri, cacheLocation); TdRulesApi api = new TdRulesApi(uri); if (!string.Empty.Equals(cacheLocation)) { diff --git a/net/QACoverTest/Translated/Test4giis.Qacover/Base.cs b/net/QACoverTest/Translated/Test4giis.Qacover/Base.cs index 7aaa1d8..c537ed5 100644 --- a/net/QACoverTest/Translated/Test4giis.Qacover/Base.cs +++ b/net/QACoverTest/Translated/Test4giis.Qacover/Base.cs @@ -76,7 +76,7 @@ public virtual void SetUp() // Default configuration for tests public static Configuration ConfigureTestOptions() { - return Configuration.GetInstance().Reset().SetName("qacovertest").SetCacheRulesLocation(".tdrules-cache"); + return Configuration.GetInstance().Reset().SetName("qacovertest").SetRuleCacheFolder(FileUtil.GetPath(Parameters.GetProjectRoot(), ".tdrules-cache")); } /// diff --git a/net/QACoverTest/Translated/Test4giis.Qacover/TestFaults.cs b/net/QACoverTest/Translated/Test4giis.Qacover/TestFaults.cs index a0e7998..59bef3d 100644 --- a/net/QACoverTest/Translated/Test4giis.Qacover/TestFaults.cs +++ b/net/QACoverTest/Translated/Test4giis.Qacover/TestFaults.cs @@ -83,7 +83,7 @@ private bool Contains(string text, string substring) [Test] public virtual void TestFaultConnectingService() { - options.SetRuleServiceUrl("http://giis.uniovi.es/noexiste.xml").SetCacheRulesLocation(string.Empty); + options.SetRuleServiceUrl("http://giis.uniovi.es/noexiste.xml").SetRuleCacheFolder(string.Empty); // disable cache to run the actual service rs = app.ExecuteQuery("select id,num,text from test where num<9"); AssertExceptionMessage(new Variability().IsJava() ? "Error at Get query table names: ApiException" : "Error at Get query table names: Giis.Tdrules.Openapi.Client.ApiException: Error calling QueryEntitiesPost", StoreService.GetLast().GetLastGenStatus()); diff --git a/net/qacover.properties b/net/qacover.properties index b141b21..93ff550 100644 --- a/net/qacover.properties +++ b/net/qacover.properties @@ -12,3 +12,4 @@ qacover.rule.optimize.evaluation=false qacover.rule.criterion=fpc qacover.rule.url= qacover.rule.options= +qacover.rule.cache= \ No newline at end of file diff --git a/qacover-core/qacover.properties b/qacover-core/qacover.properties index b118796..57cc0f2 100644 --- a/qacover-core/qacover.properties +++ b/qacover-core/qacover.properties @@ -62,3 +62,7 @@ qacover.rule.url= # and supress rules that can be automatically detected as a tautology qacover.rule.options= +# A folder to use as a cache of the rules that are generated +# Default: empty +qacover.rule.cache= + diff --git a/qacover-core/src/main/java/giis/qacover/core/services/Configuration.java b/qacover-core/src/main/java/giis/qacover/core/services/Configuration.java index a85f7a9..5ff9bfe 100644 --- a/qacover-core/src/main/java/giis/qacover/core/services/Configuration.java +++ b/qacover-core/src/main/java/giis/qacover/core/services/Configuration.java @@ -26,7 +26,7 @@ public class Configuration { // NOSONAR singleton allowed private static Configuration instance; private String name=QACOVER_NAME; private String storeRulesLocation; - private String cacheRulesLocation; + private String ruleCache; private String storeReportsLocation; private String ruleCriterion; private String ruleUrl; @@ -69,6 +69,7 @@ public Configuration reset() { } ruleUrl = getProperty("qacover.rule.url", "https://in2test.lsi.uniovi.es/tdrules/api/v4"); ruleOptions = getProperty("qacover.rule.options", ""); + ruleCache = getProperty("qacover.rule.cache", ""); optimizeRuleEvaluation = JavaCs.equalsIgnoreCase("true", getProperty("qacover.rule.optimize.evaluation", "false")); inferQueryParameters = JavaCs.equalsIgnoreCase("true", getProperty("qacover.query.infer.parameters", "false")); @@ -206,14 +207,6 @@ public String getStoreRulesLocation() { public void setStoreRulesLocation(String location) { storeRulesLocation = location; } - public String getCacheRulesLocation() { - return cacheRulesLocation; - } - public Configuration setCacheRulesLocation(String location) { - // Ensures that location is relative to project root and not null - cacheRulesLocation = location != null && !"".equals(location) ? FileUtil.getPath(Parameters.getProjectRoot(), location) : ""; - return this; - } public String getStoreReportsLocation() { return storeReportsLocation; } @@ -243,6 +236,14 @@ public Configuration setRuleServiceUrl(String ruleUrl) { return this; } + public String getRuleCacheFolder() { + return ruleCache; + } + public Configuration setRuleCacheFolder(String folder) { + ruleCache = folder; + return this; + } + public boolean getOptimizeRuleEvaluation() { return optimizeRuleEvaluation; } diff --git a/qacover-core/src/main/java/giis/qacover/core/services/RuleServices.java b/qacover-core/src/main/java/giis/qacover/core/services/RuleServices.java index 2768865..8f2111a 100644 --- a/qacover-core/src/main/java/giis/qacover/core/services/RuleServices.java +++ b/qacover-core/src/main/java/giis/qacover/core/services/RuleServices.java @@ -43,8 +43,8 @@ public void setErrorContext(String message) { private TdRulesApi getApi() { String uri = Configuration.getInstance().getRuleServiceUrl(); - String cacheLocation = Configuration.getInstance().getCacheRulesLocation(); - log.debug("Call service: {}, cache: {}", uri, cacheLocation); + String cacheLocation = Configuration.getInstance().getRuleCacheFolder(); + log.debug("Call service: {}, using cache: {}", uri, cacheLocation); TdRulesApi api = new TdRulesApi(uri); if (!"".equals(cacheLocation)) api.setCache(cacheLocation); diff --git a/qacover-core/src/test/java/test4giis/qacover/Base.java b/qacover-core/src/test/java/test4giis/qacover/Base.java index 781a57a..927ae54 100644 --- a/qacover-core/src/test/java/test4giis/qacover/Base.java +++ b/qacover-core/src/test/java/test4giis/qacover/Base.java @@ -14,6 +14,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import giis.portable.util.FileUtil; +import giis.portable.util.Parameters; import giis.qacover.core.QueryStatement; import giis.qacover.core.services.FaultInjector; import giis.qacover.core.services.Configuration; @@ -67,7 +69,7 @@ public void setUp() throws SQLException { public static Configuration configureTestOptions() { return Configuration.getInstance().reset() .setName("qacovertest") - .setCacheRulesLocation(".tdrules-cache"); + .setRuleCacheFolder(FileUtil.getPath(Parameters.getProjectRoot(), ".tdrules-cache")); } @After diff --git a/qacover-core/src/test/java/test4giis/qacover/TestFaults.java b/qacover-core/src/test/java/test4giis/qacover/TestFaults.java index eaa987b..1028f8d 100644 --- a/qacover-core/src/test/java/test4giis/qacover/TestFaults.java +++ b/qacover-core/src/test/java/test4giis/qacover/TestFaults.java @@ -78,7 +78,7 @@ private boolean contains(String text, String substring) { @Test public void testFaultConnectingService() throws SQLException { options.setRuleServiceUrl("http://giis.uniovi.es/noexiste.xml") - .setCacheRulesLocation(""); // disable cache to run the actual service + .setRuleCacheFolder(""); // disable cache to run the actual service rs=app.executeQuery("select id,num,text from test where num<9"); assertExceptionMessage(new Variability().isJava() ? "Error at Get query table names: ApiException"