diff --git a/pom.xml b/pom.xml
index f7961eb1..4a310dcc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -195,21 +195,4 @@
-
-
- ossrh
- https://oss.sonatype.org/content/repositories/snapshots
-
-
- ossrh
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
-
-
- scm:git:https://github.com/proj-xavier/xavier-analytics.git
- https://github.com/proj-xavier/xavier-analytics
-
-
-
diff --git a/src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java b/src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java
index ad324b21..e3fbaff5 100644
--- a/src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java
+++ b/src/main/java/org/jboss/xavier/analytics/pojo/output/workload/inventory/WorkloadInventoryReportModel.java
@@ -28,6 +28,10 @@ public class WorkloadInventoryReportModel
public static final String COMPLEXITY_HARD = "Hard";
public static final String COMPLEXITY_UNKNOWN = "Unknown";
+ public static final String DATACENTER_DEFAULT_VALUE = "No datacenter defined";
+ public static final String CLUSTER_DEFAULT_VALUE = "No cluster defined";
+ public static final String HOST_NAME_DEFAULT_VALUE = "No host defined";
+
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO, generator = "WORKLOADINVENTORYREPORTMODEL_ID_GENERATOR")
private Long id;
diff --git a/src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/BasicFields.drl b/src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/BasicFields.drl
index a33f8767..9e0c5e3f 100644
--- a/src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/BasicFields.drl
+++ b/src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/BasicFields.drl
@@ -12,8 +12,9 @@ rule "Copy basic fields and agenda controller"
when
vmWorkloadInventoryModel : VMWorkloadInventoryModel(
provider != null ,
- datacenter != null,
- cluster != null,
+ // These fields became optional in https://issues.redhat.com/browse/MIGENG-328
+ // datacenter != null,
+ // cluster != null,
vmName != null,
diskSpace != null,
memory != null,
@@ -22,12 +23,15 @@ rule "Copy basic fields and agenda controller"
osProductName != null,
product != null,
version != null,
- host_name != null,
+ // This field became optional in https://issues.redhat.com/browse/MIGENG-328
+ // host_name != null,
scanRunDate != null
)
then
WorkloadInventoryReportModel workloadInventoryReport = new WorkloadInventoryReportModel();
workloadInventoryReport.setProvider(vmWorkloadInventoryModel.getProvider());
+ // It could be that, since it's an optional input field, we are setting it to null:
+ // in such a case it will be up to 'ReasonableDefaults' rules it to the default value
workloadInventoryReport.setDatacenter(vmWorkloadInventoryModel.getDatacenter());
workloadInventoryReport.setCluster(vmWorkloadInventoryModel.getCluster());
workloadInventoryReport.setVmName(vmWorkloadInventoryModel.getVmName());
@@ -46,4 +50,5 @@ rule "Copy basic fields and agenda controller"
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Complexity").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Targets").setFocus();
kcontext.getKieRuntime().getAgenda().getAgendaGroup("Flags").setFocus();
+ kcontext.getKieRuntime().getAgenda().getAgendaGroup("ReasonableDefaults").setFocus();
end
diff --git a/src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaults.drl b/src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaults.drl
new file mode 100644
index 00000000..26322023
--- /dev/null
+++ b/src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaults.drl
@@ -0,0 +1,34 @@
+package org.jboss.xavier.analytics.rules.workload.inventory;
+
+import org.jboss.xavier.analytics.pojo.output.workload.inventory.WorkloadInventoryReportModel
+
+dialect "java"
+agenda-group "ReasonableDefaults"
+auto-focus true
+
+rule "Fill 'datacenter' field with reasonable default"
+ when
+ workloadInventoryReport : WorkloadInventoryReportModel(
+ datacenter == null
+ )
+ then
+ workloadInventoryReport.setDatacenter(WorkloadInventoryReportModel.DATACENTER_DEFAULT_VALUE);
+end
+
+rule "Fill 'cluster' field with reasonable default"
+ when
+ workloadInventoryReport : WorkloadInventoryReportModel(
+ cluster == null
+ )
+ then
+ workloadInventoryReport.setCluster(WorkloadInventoryReportModel.CLUSTER_DEFAULT_VALUE);
+end
+
+rule "Fill 'host_name' field with reasonable default"
+ when
+ workloadInventoryReport : WorkloadInventoryReportModel(
+ host_name == null
+ )
+ then
+ workloadInventoryReport.setHost_name(WorkloadInventoryReportModel.HOST_NAME_DEFAULT_VALUE);
+end
diff --git a/src/test/java/org/jboss/xavier/analytics/rules/BaseIntegrationTest.java b/src/test/java/org/jboss/xavier/analytics/rules/BaseIntegrationTest.java
index 963b159b..db11df9a 100644
--- a/src/test/java/org/jboss/xavier/analytics/rules/BaseIntegrationTest.java
+++ b/src/test/java/org/jboss/xavier/analytics/rules/BaseIntegrationTest.java
@@ -1,7 +1,8 @@
package org.jboss.xavier.analytics.rules;
-import org.junit.After;
+import org.jboss.xavier.analytics.test.Utils;
import org.junit.Before;
+import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.event.rule.AgendaEventListener;
import org.kie.api.event.rule.DebugAgendaEventListener;
@@ -22,11 +23,17 @@ public abstract class BaseIntegrationTest {
protected AgendaEventListener agendaEventListener;
- public BaseIntegrationTest(String kSessionName)
+ protected final String expectedKiePackageName;
+ protected final int expectedLoadedRules;
+
+
+ public BaseIntegrationTest(String kSessionName, String expectedKiePackageName, int expectedLoadedRules)
{
this.kSessionName = kSessionName;
// AgendaEventListeners allow one to monitor and check rules that activate, fire, etc
agendaEventListener = mock( AgendaEventListener.class );
+ this.expectedKiePackageName = expectedKiePackageName;
+ this.expectedLoadedRules = expectedLoadedRules;
}
@Before
@@ -39,8 +46,10 @@ public void setup()
kieSession.addEventListener(agendaEventListener);
}
- @After
- public void tearDown()
+ // check that the number of rule (from the DRL files) is the number of rules loaded
+ @Test
+ public void checkLoadedRulesNumber()
{
+ Utils.checkLoadedRulesNumber(kieSession, expectedKiePackageName, expectedLoadedRules);
}
}
diff --git a/src/test/java/org/jboss/xavier/analytics/rules/BaseTest.java b/src/test/java/org/jboss/xavier/analytics/rules/BaseTest.java
index 7f6eb61b..2a82d6cb 100644
--- a/src/test/java/org/jboss/xavier/analytics/rules/BaseTest.java
+++ b/src/test/java/org/jboss/xavier/analytics/rules/BaseTest.java
@@ -1,24 +1,28 @@
package org.jboss.xavier.analytics.rules;
import org.jboss.xavier.analytics.test.Utils;
-import org.junit.After;
import org.junit.Before;
+import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.builder.KieRepository;
import org.kie.api.builder.Message;
+import org.kie.api.command.Command;
import org.kie.api.event.rule.AgendaEventListener;
import org.kie.api.event.rule.DebugAgendaEventListener;
import org.kie.api.event.rule.DebugRuleRuntimeEventListener;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.StatelessKieSession;
+import org.kie.internal.command.CommandFactory;
import org.kie.internal.io.ResourceFactory;
import java.io.File;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
@@ -29,6 +33,8 @@ public abstract class BaseTest {
protected final String rulePath;
protected final ResourceType ruleResourceType;
+ protected final String expectedKiePackageName;
+ protected final int expectedLoadedRules;
protected StatelessKieSession kieSession;
protected KieFileSystem kieFileSystem;
@@ -36,12 +42,14 @@ public abstract class BaseTest {
protected AgendaEventListener agendaEventListener;
- public BaseTest(String rulePath, ResourceType resourceType)
+ public BaseTest(String rulePath, ResourceType resourceType, String expectedKiePackageName, int expectedLoadedRules)
{
this.rulePath = rulePath;
this.ruleResourceType = resourceType;
// AgendaEventListeners allow one to monitor and check rules that activate, fire, etc
agendaEventListener = mock( AgendaEventListener.class );
+ this.expectedKiePackageName = expectedKiePackageName;
+ this.expectedLoadedRules = expectedLoadedRules;
}
@Before
@@ -68,6 +76,13 @@ public void setup()
kieSession.addEventListener(agendaEventListener);
}
+ // check that the number of rule (from the DRL files) is the number of rules loaded
+ @Test
+ public void checkLoadedRulesNumber()
+ {
+ Utils.checkLoadedRulesNumber(kieSession, expectedKiePackageName, expectedLoadedRules);
+ }
+
protected KieBuilder createAndBuildKieBuilder(URL resource)
{
File ruleFile = new File(resource.getPath());
@@ -84,8 +99,12 @@ protected void addAgendaGroupRuleToKieFileSystem(KieFileSystem kieFileSystem)
kieFileSystem.write(ResourceFactory.newFileResource(agendaFocusForTestFile).setResourceType(ResourceType.DRL));
}
- @After
- public void tearDown()
+ public Map createAndExecuteCommandsAndGetResults(final Map facts)
{
+ final List commands = new ArrayList<>();
+ commands.addAll(Utils.newInsertCommands(facts));
+ commands.add(CommandFactory.newFireAllRules(NUMBER_OF_FIRED_RULE_KEY));
+ commands.add(CommandFactory.newGetObjects(GET_OBJECTS_KEY));
+ return Utils.executeCommandsAndGetResults(kieSession, commands);
}
}
diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/EnvironmentTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/EnvironmentTest.java
index 83717198..255d4ee6 100644
--- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/EnvironmentTest.java
+++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/EnvironmentTest.java
@@ -7,15 +7,11 @@
import org.jboss.xavier.analytics.test.Utils;
import org.junit.Assert;
import org.junit.Test;
-import org.kie.api.command.Command;
import org.kie.api.io.ResourceType;
-import org.kie.internal.command.CommandFactory;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
public class EnvironmentTest extends BaseTest {
private static final String CUSTOMER_ID = "123";
@@ -25,13 +21,12 @@ public class EnvironmentTest extends BaseTest {
private static final int DEFAULT_SOURCE_PRODUCT_INDICATOR = 1;
public EnvironmentTest() {
- super("/org/jboss/xavier/analytics/rules/initialcostsaving/Environment.drl", ResourceType.DRL);
+ super("/org/jboss/xavier/analytics/rules/initialcostsaving/Environment.drl", ResourceType.DRL,
+ "org.jboss.xavier.analytics.rules.initialcostsaving", 1);
}
@Test
public void test() {
- Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1);
-
Map facts = new HashMap<>();
UploadFormInputDataModel inputDataModel = new UploadFormInputDataModel();
@@ -44,21 +39,12 @@ public void test() {
inputDataModel.setFileName(FILE_NAME);
facts.put("inputDataModel", inputDataModel);
- List commands = new ArrayList<>();
- commands.addAll(Utils.newInsertCommands(facts));
- commands.add(CommandFactory.newFireAllRules(NUMBER_OF_FIRED_RULE_KEY));
- commands.add(CommandFactory.newGetObjects(GET_OBJECTS_KEY));
-
- Map results = Utils.executeCommandsAndGetResults(kieSession, commands);
+ Map results = createAndExecuteCommandsAndGetResults(facts);
Assert.assertEquals(1, results.get(NUMBER_OF_FIRED_RULE_KEY));
Utils.verifyRulesFiredNames(this.agendaEventListener, "Copy input fields and agenda controller");
- List