From 670af60beaa64795b425e5f76b98cd66281dc5ce Mon Sep 17 00:00:00 2001 From: Marco Rizzi Date: Tue, 21 Jan 2020 10:43:13 +0100 Subject: [PATCH] MIGENG-328 Added 'ReasonableDefaults' rules (#37) * MIGENG-328 Added 'ReasonableDefaults' rules * MIGENG-328 Refactored tests * MIGENG-328 removed distributionManagement (#4) * MIGENG-328 Refactored tests Co-authored-by: Jonathan Vila --- pom.xml | 17 - .../WorkloadInventoryReportModel.java | 4 + .../rules/workload/inventory/BasicFields.drl | 11 +- .../workload/inventory/ReasonableDefaults.drl | 34 ++ .../analytics/rules/BaseIntegrationTest.java | 17 +- .../xavier/analytics/rules/BaseTest.java | 27 +- .../initialcostsaving/EnvironmentTest.java | 22 +- .../InitialSavingsEstimationReportTest.java | 38 +- .../rules/initialcostsaving/PricingTest.java | 28 +- .../RHVAdditionalContainerCapacityTest.java | 18 +- .../initialcostsaving/RHVRampUpCostsTest.java | 62 +-- .../initialcostsaving/RHVSavingsTest.java | 18 +- .../RHVYearByYearCostsTest.java | 17 +- .../initialcostsaving/SourceCostsTest.java | 45 +-- .../SourceRampDownCostsTest.java | 18 +- .../workload/inventory/BasicFieldsTest.java | 70 ++-- .../workload/inventory/ComplexityTest.java | 146 +------ .../rules/workload/inventory/FlagsTest.java | 104 +---- .../inventory/ReasonableDefaultsTest.java | 95 +++++ .../rules/workload/inventory/TargetsTest.java | 104 +---- .../WorkloadInventoryReportTest.java | 86 +---- .../workload/inventory/WorkloadsTest.java | 357 +++--------------- .../summary/WorkloadSummaryReportTest.java | 10 +- .../jboss/xavier/analytics/test/Utils.java | 11 +- 24 files changed, 417 insertions(+), 942 deletions(-) create mode 100644 src/main/resources/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaults.drl create mode 100644 src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaultsTest.java 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 objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/InitialSavingsEstimationReportTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/InitialSavingsEstimationReportTest.java index 247f12b8..9f046bd3 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/InitialSavingsEstimationReportTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/InitialSavingsEstimationReportTest.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.instanceOf; @@ -32,15 +31,12 @@ public class InitialSavingsEstimationReportTest extends BaseIntegrationTest { public InitialSavingsEstimationReportTest() { - super("InitialCostSavingKSession0"); + super("InitialCostSavingKSession0", "org.jboss.xavier.analytics.rules.initialcostsaving", 26); } @Test public void test_SourceNewELAIndicator_0() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 26); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -122,11 +118,7 @@ public void test_SourceNewELAIndicator_0() Assert.assertEquals(true, environmentModel.getOpenStackIndicator()); // Pricing - List objects = (List) results.get((GET_OBJECTS_KEY)); - List pricingDataModelList = objects.stream() - .filter(object -> object instanceof PricingDataModel) - .map(object -> (PricingDataModel) object) - .collect(Collectors.toList()); + List pricingDataModelList = Utils.extractModels(GET_OBJECTS_KEY, results, PricingDataModel.class); Assert.assertEquals(1, pricingDataModelList.size()); PricingDataModel pricingDataModel = pricingDataModelList.get(0); @@ -286,9 +278,6 @@ public void test_SourceNewELAIndicator_0() @Test @Ignore public void test_SourceNewELAIndicator_1() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules", 23); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -333,13 +322,9 @@ public void test_SourceNewELAIndicator_1() // check the names of the rules fired are what you expect Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "SourceCostsRules_0", "SourceCostsRules_sourceNewELAIndicator_1"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); @@ -379,9 +364,6 @@ public void test_SourceNewELAIndicator_1() @Test @Ignore public void test_SourceNewELAIndicator_2() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules", 23); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -426,13 +408,9 @@ public void test_SourceNewELAIndicator_2() // check the names of the rules fired are what you expect Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "SourceCostsRules_0", "SourceCostsRules_sourceNewELAIndicator_2"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/PricingTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/PricingTest.java index c7a329ff..0421772d 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/PricingTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/PricingTest.java @@ -8,18 +8,14 @@ import org.junit.Assert; import org.junit.Test; import org.kie.api.builder.KieBuilder; -import org.kie.api.command.Command; import org.kie.api.io.ResourceType; -import org.kie.internal.command.CommandFactory; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.net.URL; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class PricingTest extends BaseTest { @@ -27,7 +23,8 @@ public class PricingTest extends BaseTest public PricingTest() { - super("/org/jboss/xavier/analytics/rules/initialcostsaving/PricingRule.xlsx", ResourceType.DTABLE); + super("/org/jboss/xavier/analytics/rules/initialcostsaving/PricingRule.xlsx", ResourceType.DTABLE, + "org.jboss.xavier.analytics.rules.initialcostsaving", 15); } @Override @@ -60,8 +57,6 @@ protected KieBuilder createAndBuildKieBuilder(URL resource) @Test public void test() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 15); - EnvironmentModel environmentModel = new EnvironmentModel(); environmentModel.setSourceProductIndicator(DEFAULT_SOURCE_PRODUCT_INDICATOR); environmentModel.setDealIndicator(1); @@ -72,29 +67,16 @@ public void test() facts.put("reportModel", reportModel); facts.put("agendaGroup", "Pricing"); - 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(14, results.get(NUMBER_OF_FIRED_RULE_KEY)); - List objects = (List) results.get((GET_OBJECTS_KEY)); - - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // just one InitialSavingsEstimationReportModel has to be available Assert.assertEquals(1, reports.size()); - List pricingDataModelList = objects.stream() - .filter(object -> object instanceof PricingDataModel) - .map(object -> (PricingDataModel) object) - .collect(Collectors.toList()); + List pricingDataModelList = Utils.extractModels(GET_OBJECTS_KEY, results, PricingDataModel.class); // just one PricingDataModel has to be created Assert.assertEquals(1, pricingDataModelList.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVAdditionalContainerCapacityTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVAdditionalContainerCapacityTest.java index 9609d1bb..8cee5f40 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVAdditionalContainerCapacityTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVAdditionalContainerCapacityTest.java @@ -4,7 +4,6 @@ import org.jboss.xavier.analytics.pojo.output.RHVAdditionalContainerCapacityModel; import org.jboss.xavier.analytics.pojo.output.RHVSavingsModel; import org.jboss.xavier.analytics.pojo.support.initialcostsaving.PricingDataModel; - import org.jboss.xavier.analytics.rules.BaseTest; import org.jboss.xavier.analytics.test.Utils; import org.junit.Assert; @@ -17,22 +16,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class RHVAdditionalContainerCapacityTest extends BaseTest { public RHVAdditionalContainerCapacityTest() { // provide the name of the DRL file you want to test - super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVAdditionalContainerCapacity.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVAdditionalContainerCapacity.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.initialcostsaving", 1); } @Test public void test() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -72,13 +68,9 @@ public void test() Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "RHVAdditionalContainerCapacity"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVRampUpCostsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVRampUpCostsTest.java index af8ae307..a97b103e 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVRampUpCostsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVRampUpCostsTest.java @@ -1,8 +1,10 @@ package org.jboss.xavier.analytics.rules.initialcostsaving; -import org.jboss.xavier.analytics.pojo.output.*; +import org.jboss.xavier.analytics.pojo.output.EnvironmentModel; +import org.jboss.xavier.analytics.pojo.output.InitialSavingsEstimationReportModel; +import org.jboss.xavier.analytics.pojo.output.RHVRampUpCostsModel; +import org.jboss.xavier.analytics.pojo.output.SourceRampDownCostsModel; import org.jboss.xavier.analytics.pojo.support.initialcostsaving.PricingDataModel; - import org.jboss.xavier.analytics.rules.BaseTest; import org.jboss.xavier.analytics.test.Utils; import org.junit.Assert; @@ -15,22 +17,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class RHVRampUpCostsTest extends BaseTest { public RHVRampUpCostsTest() { // provide the name of the DRL file you want to test - super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVRampUpCosts.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVRampUpCosts.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.initialcostsaving", 1); } @Test public void testVSphereNoFreeSubs() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -85,13 +84,9 @@ public void testVSphereNoFreeSubs() // check that the number of rules fired is what you expect Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); @@ -142,9 +137,6 @@ public void testVSphereNoFreeSubs() @Test public void testVSphereWithFreeSubs() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -199,13 +191,9 @@ public void testVSphereWithFreeSubs() // check that the number of rules fired is what you expect Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); @@ -255,9 +243,6 @@ public void testVSphereWithFreeSubs() @Test public void testVCloudNoFreeSubs() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -312,13 +297,9 @@ public void testVCloudNoFreeSubs() // check that the number of rules fired is what you expect Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); @@ -369,9 +350,6 @@ public void testVCloudNoFreeSubs() @Test public void testVCloudWithFreeSubs() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -426,13 +404,9 @@ public void testVCloudWithFreeSubs() // check that the number of rules fired is what you expect Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVSavingsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVSavingsTest.java index 389ce2b2..b93daf28 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVSavingsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVSavingsTest.java @@ -1,7 +1,6 @@ package org.jboss.xavier.analytics.rules.initialcostsaving; - import org.jboss.xavier.analytics.pojo.output.InitialSavingsEstimationReportModel; import org.jboss.xavier.analytics.pojo.output.RHVSavingsModel; import org.jboss.xavier.analytics.pojo.output.RHVYearByYearCostsModel; @@ -17,22 +16,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class RHVSavingsTest extends BaseTest { public RHVSavingsTest() { // provide the name of the DRL file you want to test - super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVSavings.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVSavings.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.initialcostsaving", 1); } @Test public void test() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -72,13 +68,9 @@ public void test() // check that the number of rules fired is what you expect Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVYearByYearCostsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVYearByYearCostsTest.java index bb60d9b8..ead9c662 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVYearByYearCostsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/RHVYearByYearCostsTest.java @@ -17,22 +17,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class RHVYearByYearCostsTest extends BaseTest { public RHVYearByYearCostsTest() { // provide the name of the DRL file you want to test - super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVYearByYearCosts.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/initialcostsaving/RHVYearByYearCosts.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.initialcostsaving", 1); } @Test public void test() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -84,13 +81,9 @@ public void test() Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "RHVYearByYearCostsRules"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceCostsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceCostsTest.java index 77aa241b..bc9285e9 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceCostsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceCostsTest.java @@ -16,24 +16,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; - -import static org.hamcrest.core.Is.is; public class SourceCostsTest extends BaseTest { public SourceCostsTest() { // provide the name of the DRL file you want to test - super("/org/jboss/xavier/analytics/rules/initialcostsaving/SourceCosts.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/initialcostsaving/SourceCosts.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.initialcostsaving", 4); } @Test public void test_SourceNewELAIndicator_0() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 4); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -78,13 +73,9 @@ public void test_SourceNewELAIndicator_0() // check the names of the rules fired are what you expect Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "SourceCostsRules_0", "SourceCostsRules_sourceNewELAIndicator_0"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); @@ -124,9 +115,6 @@ public void test_SourceNewELAIndicator_0() @Test public void test_SourceNewELAIndicator_1() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 4); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -171,13 +159,9 @@ public void test_SourceNewELAIndicator_1() // check the names of the rules fired are what you expect Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "SourceCostsRules_0", "SourceCostsRules_sourceNewELAIndicator_1"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); @@ -217,9 +201,6 @@ public void test_SourceNewELAIndicator_1() @Test public void test_SourceNewELAIndicator_2() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 4); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -264,13 +245,9 @@ public void test_SourceNewELAIndicator_2() // check the names of the rules fired are what you expect Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "SourceCostsRules_0", "SourceCostsRules_sourceNewELAIndicator_2"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceRampDownCostsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceRampDownCostsTest.java index 617ffb7d..6670869b 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceRampDownCostsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/initialcostsaving/SourceRampDownCostsTest.java @@ -5,7 +5,6 @@ import org.jboss.xavier.analytics.pojo.output.SourceCostsModel; import org.jboss.xavier.analytics.pojo.output.SourceRampDownCostsModel; import org.jboss.xavier.analytics.pojo.support.initialcostsaving.PricingDataModel; - import org.jboss.xavier.analytics.rules.BaseTest; import org.jboss.xavier.analytics.test.Utils; import org.junit.Assert; @@ -18,22 +17,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class SourceRampDownCostsTest extends BaseTest { public SourceRampDownCostsTest() { // provide the name of the DRL file you want to test - super("/org/jboss/xavier/analytics/rules/initialcostsaving/SourceRampDownCosts.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/initialcostsaving/SourceRampDownCosts.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.initialcostsaving", 1); } @Test public void test() { - // check that the numbers of rule from the DRL file is the number of rules loaded - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.initialcostsaving", 1); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") @@ -81,13 +77,9 @@ public void test() Assert.assertEquals(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "SourceRampDownCostsRules"); - // retrieve the List of Objects that were available in the working memory from the results - List objects = (List) results.get((GET_OBJECTS_KEY)); - // filter the type of object you're interested in checking (e.g. InitialSavingsEstimationReportModel) - List reports = objects.stream() - .filter(object -> object instanceof InitialSavingsEstimationReportModel) - .map(object -> (InitialSavingsEstimationReportModel) object) - .collect(Collectors.toList()); + // this method retrieves the List of Objects that were available in the working memory from the results + // and filters the type of object you're interested in retrieving (e.g. InitialSavingsEstimationReportModel) + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, InitialSavingsEstimationReportModel.class); // Check that the number of object is the right one (in this case, there must be just one report) Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/BasicFieldsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/BasicFieldsTest.java index c1d7dfad..ca7a1b32 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/BasicFieldsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/BasicFieldsTest.java @@ -6,29 +6,24 @@ 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.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class BasicFieldsTest extends BaseTest { public BasicFieldsTest() { - super("/org/jboss/xavier/analytics/rules/workload/inventory/BasicFields.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/workload/inventory/BasicFields.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.workload.inventory", 1); } @Test - public void test() throws ParseException { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 1); - + public void testWithAllInputFields() throws ParseException { Map facts = new HashMap<>(); VMWorkloadInventoryModel vmWorkloadInventoryModel = new VMWorkloadInventoryModel(); @@ -36,8 +31,8 @@ public void test() throws ParseException { vmWorkloadInventoryModel.setDatacenter("V2V-DC"); vmWorkloadInventoryModel.setCluster("Cluster 1"); vmWorkloadInventoryModel.setVmName("vm tests"); - vmWorkloadInventoryModel.setDiskSpace(new Long(100000001)); - vmWorkloadInventoryModel.setMemory(new Long(4096)); + vmWorkloadInventoryModel.setDiskSpace(100000001L); + vmWorkloadInventoryModel.setMemory(4096L); vmWorkloadInventoryModel.setCpuCores(4); vmWorkloadInventoryModel.setGuestOSFullName("Red Hat Enterprise Linux Server release 7.6 (Maipo)"); vmWorkloadInventoryModel.setOsProductName("RHEL"); @@ -47,21 +42,12 @@ public void test() throws ParseException { vmWorkloadInventoryModel.setScanRunDate(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z")); facts.put("vmWorkloadInventoryModel", vmWorkloadInventoryModel); - 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 basic fields and agenda controller"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -80,4 +66,46 @@ public void test() throws ParseException { Assert.assertEquals("esx13.v2v.bos.redhat.com", report.getHost_name()); Assert.assertEquals(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z"), report.getCreationDate()); } + + @Test + public void testWithoutOptionalInputFields() throws ParseException { + Map facts = new HashMap<>(); + + VMWorkloadInventoryModel vmWorkloadInventoryModel = new VMWorkloadInventoryModel(); + vmWorkloadInventoryModel.setProvider("IMS vCenter"); + vmWorkloadInventoryModel.setVmName("vm tests"); + vmWorkloadInventoryModel.setDiskSpace(100000001L); + vmWorkloadInventoryModel.setMemory(4096L); + vmWorkloadInventoryModel.setCpuCores(4); + vmWorkloadInventoryModel.setGuestOSFullName("Red Hat Enterprise Linux Server release 7.6 (Maipo)"); + vmWorkloadInventoryModel.setOsProductName("RHEL"); + vmWorkloadInventoryModel.setProduct("VMware vCenter"); + vmWorkloadInventoryModel.setVersion("6.5"); + vmWorkloadInventoryModel.setScanRunDate(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z")); + facts.put("vmWorkloadInventoryModel", vmWorkloadInventoryModel); + + Map results = createAndExecuteCommandsAndGetResults(facts); + + Assert.assertEquals(1, results.get(NUMBER_OF_FIRED_RULE_KEY)); + Utils.verifyRulesFiredNames(this.agendaEventListener, "Copy basic fields and agenda controller"); + + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); + + // just one report has to be created + Assert.assertEquals(1, reports.size()); + WorkloadInventoryReportModel report = reports.get(0); + Assert.assertEquals("IMS vCenter",report.getProvider()); + Assert.assertNull(report.getDatacenter()); + Assert.assertNull(report.getCluster()); + Assert.assertEquals("vm tests",report.getVmName()); + Assert.assertEquals(new BigDecimal(100000001).intValue(),report.getDiskSpace().intValue()); + Assert.assertEquals(4096,report.getMemory().intValue()); + Assert.assertEquals(4,report.getCpuCores().intValue()); + Assert.assertEquals("Red Hat Enterprise Linux Server release 7.6 (Maipo)",report.getOsDescription()); + Assert.assertEquals("RHEL",report.getOsName()); + Assert.assertEquals("VMware vCenter", report.getProduct()); + Assert.assertEquals("6.5", report.getVersion()); + Assert.assertNull(report.getHost_name()); + Assert.assertEquals(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z"), report.getCreationDate()); + } } diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ComplexityTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ComplexityTest.java index 42abbd53..e7fea81a 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ComplexityTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ComplexityTest.java @@ -5,26 +5,21 @@ 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 ComplexityTest extends BaseTest { public ComplexityTest() { - super("/org/jboss/xavier/analytics/rules/workload/inventory/Complexity.drl", ResourceType.DRL); + super("/org/jboss/xavier/analytics/rules/workload/inventory/Complexity.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.workload.inventory", 6); } @Test public void testNoFlagSupportedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -35,21 +30,12 @@ public void testNoFlagSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "No_Flag_Supported_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -60,8 +46,6 @@ public void testNoFlagSupportedOS() { @Test public void testOneFlagSupportedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -72,21 +56,12 @@ public void testOneFlagSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "One_Flag_Supported_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -97,8 +72,6 @@ public void testOneFlagSupportedOS() { @Test public void testMoreThanOneFlagSupportedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -110,21 +83,12 @@ public void testMoreThanOneFlagSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "More_Than_One_Flag_Supported_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -135,8 +99,6 @@ public void testMoreThanOneFlagSupportedOS() { @Test public void testNoFlagsUnSupportedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -147,21 +109,12 @@ public void testNoFlagsUnSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "No_Flags_Not_Supported_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -172,8 +125,6 @@ public void testNoFlagsUnSupportedOS() { @Test public void testOneFlagUnSupportedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -184,21 +135,12 @@ public void testOneFlagUnSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "One_Or_More_Flags_Not_Supported_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -209,8 +151,6 @@ public void testOneFlagUnSupportedOS() { @Test public void testOneOrMoreFlagsUnSupportedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -222,21 +162,12 @@ public void testOneOrMoreFlagsUnSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "One_Or_More_Flags_Not_Supported_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -247,8 +178,6 @@ public void testOneOrMoreFlagsUnSupportedOS() { @Test public void testNoFlagUndetectedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -259,21 +188,12 @@ public void testNoFlagUndetectedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Not_Detected_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -284,8 +204,6 @@ public void testNoFlagUndetectedOS() { @Test public void testOneFlagUndetectedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -296,21 +214,12 @@ public void testOneFlagUndetectedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Not_Detected_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -319,12 +228,8 @@ public void testOneFlagUndetectedOS() { } - - @Test public void testMoreThanOneFlagUndetectedOS() { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 6); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Complexity"); @@ -336,21 +241,12 @@ public void testMoreThanOneFlagUndetectedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Not_Detected_OS"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -358,7 +254,5 @@ public void testMoreThanOneFlagUndetectedOS() { Assert.assertEquals(WorkloadInventoryReportModel.COMPLEXITY_UNKNOWN,report.getComplexity()); } - - } diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/FlagsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/FlagsTest.java index f43e8268..a3636c81 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/FlagsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/FlagsTest.java @@ -4,36 +4,24 @@ import org.jboss.xavier.analytics.pojo.output.workload.inventory.WorkloadInventoryReportModel; import org.jboss.xavier.analytics.rules.BaseTest; 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.Set; -import java.util.stream.Collectors; public class FlagsTest extends BaseTest { public FlagsTest() { - super("/org/jboss/xavier/analytics/rules/workload/inventory/Flags.drl", ResourceType.DRL); - } - - private void checkLoadedRulesNumber() - { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 2); + super("/org/jboss/xavier/analytics/rules/workload/inventory/Flags.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.workload.inventory", 2); } @Test public void test_NicsAndRdmDiskFlags() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Flags"); @@ -47,21 +35,12 @@ public void test_NicsAndRdmDiskFlags() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Flag_Nics", "Flag_Rdm_Disk"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -76,8 +55,6 @@ public void test_NicsAndRdmDiskFlags() { @Test public void test_NoFlags() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Flags"); @@ -88,21 +65,12 @@ public void test_NoFlags() { WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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, "AgendaFocusForTest"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -114,8 +82,6 @@ public void test_NoFlags() { @Test public void test_OnlyNicsFlag() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Flags"); @@ -127,21 +93,12 @@ public void test_OnlyNicsFlag() WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Flag_Nics"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -156,8 +113,6 @@ public void test_OnlyNicsFlag() @Test public void test_OnlyRdmDiskFlag() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Flags"); @@ -169,21 +124,12 @@ public void test_OnlyRdmDiskFlag() WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Flag_Rdm_Disk"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -198,8 +144,6 @@ public void test_OnlyRdmDiskFlag() @Test public void test_NotEnoughNics() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Flags"); @@ -211,21 +155,12 @@ public void test_NotEnoughNics() WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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, "AgendaFocusForTest"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -237,8 +172,6 @@ public void test_NotEnoughNics() @Test public void test_RdmDiskFalse() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Flags"); @@ -250,22 +183,13 @@ public void test_RdmDiskFalse() WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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, "AgendaFocusForTest"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaultsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaultsTest.java new file mode 100644 index 00000000..7432814e --- /dev/null +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaultsTest.java @@ -0,0 +1,95 @@ +package org.jboss.xavier.analytics.rules.workload.inventory; + +import org.jboss.xavier.analytics.pojo.output.workload.inventory.WorkloadInventoryReportModel; +import org.jboss.xavier.analytics.rules.BaseTest; +import org.jboss.xavier.analytics.test.Utils; +import org.junit.Assert; +import org.junit.Test; +import org.kie.api.io.ResourceType; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ReasonableDefaultsTest extends BaseTest { + + public ReasonableDefaultsTest() + { + super("/org/jboss/xavier/analytics/rules/workload/inventory/ReasonableDefaults.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.workload.inventory", 3); + } + + @Test + public void testDatacenterFieldNullValueShouldFireRule() { + WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); + workloadInventoryReportModel.setCluster("cluster"); + workloadInventoryReportModel.setHost_name("host"); + + Map facts = new HashMap<>(); + facts.put("vmWorkloadInventoryModel", workloadInventoryReportModel); + Map results = createAndExecuteCommandsAndGetResults(facts); + + Assert.assertEquals(1, results.get(NUMBER_OF_FIRED_RULE_KEY)); + Utils.verifyRulesFiredNames(this.agendaEventListener, "Fill 'datacenter' field with reasonable default"); + + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); + + Assert.assertEquals(1, reports.size()); + WorkloadInventoryReportModel report = reports.get(0); + Assert.assertEquals(WorkloadInventoryReportModel.DATACENTER_DEFAULT_VALUE, report.getDatacenter()); + } + + @Test + public void testClusterFieldNullValueShouldFireRule() { + WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); + workloadInventoryReportModel.setDatacenter("datacenter"); + workloadInventoryReportModel.setHost_name("host"); + + Map facts = new HashMap<>(); + facts.put("vmWorkloadInventoryModel", workloadInventoryReportModel); + Map results = createAndExecuteCommandsAndGetResults(facts); + + Assert.assertEquals(1, results.get(NUMBER_OF_FIRED_RULE_KEY)); + Utils.verifyRulesFiredNames(this.agendaEventListener, "Fill 'cluster' field with reasonable default"); + + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); + + Assert.assertEquals(1, reports.size()); + WorkloadInventoryReportModel report = reports.get(0); + Assert.assertEquals(WorkloadInventoryReportModel.CLUSTER_DEFAULT_VALUE, report.getCluster()); + } + + @Test + public void testHostNameFieldNullValueShouldFireRule() { + WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); + workloadInventoryReportModel.setCluster("cluster"); + workloadInventoryReportModel.setDatacenter("datacenter"); + + Map facts = new HashMap<>(); + facts.put("vmWorkloadInventoryModel", workloadInventoryReportModel); + Map results = createAndExecuteCommandsAndGetResults(facts); + + Assert.assertEquals(1, results.get(NUMBER_OF_FIRED_RULE_KEY)); + Utils.verifyRulesFiredNames(this.agendaEventListener, "Fill 'host_name' field with reasonable default"); + + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); + + Assert.assertEquals(1, reports.size()); + WorkloadInventoryReportModel report = reports.get(0); + Assert.assertEquals(WorkloadInventoryReportModel.HOST_NAME_DEFAULT_VALUE, report.getHost_name()); + } + + @Test + public void testFieldsValidValuesShouldNotFireRules() { + WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); + workloadInventoryReportModel.setDatacenter("whatever"); + workloadInventoryReportModel.setCluster("cluster"); + workloadInventoryReportModel.setHost_name("host"); + + Map facts = new HashMap<>(); + facts.put("vmWorkloadInventoryModel", workloadInventoryReportModel); + Map results = createAndExecuteCommandsAndGetResults(facts); + + Assert.assertEquals(0, results.get(NUMBER_OF_FIRED_RULE_KEY)); + } +} diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/TargetsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/TargetsTest.java index 00a8690a..e97dcebe 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/TargetsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/TargetsTest.java @@ -1,37 +1,25 @@ package org.jboss.xavier.analytics.rules.workload.inventory; -import org.jboss.xavier.analytics.functions.HelperFunctions; -import org.jboss.xavier.analytics.pojo.input.workload.inventory.VMWorkloadInventoryModel; import org.jboss.xavier.analytics.pojo.output.workload.inventory.WorkloadInventoryReportModel; import org.jboss.xavier.analytics.rules.BaseTest; 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 TargetsTest extends BaseTest { public TargetsTest() { - super("/org/jboss/xavier/analytics/rules/workload/inventory/Targets.drl", ResourceType.DRL); - } - - private void checkLoadedRulesNumber() - { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 3); + super("/org/jboss/xavier/analytics/rules/workload/inventory/Targets.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.workload.inventory", 3); } @Test public void testTargetsFlagsExistSupportedOS() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Targets"); @@ -42,21 +30,12 @@ public void testTargetsFlagsExistSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Target_RHV"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -68,8 +47,6 @@ public void testTargetsFlagsExistSupportedOS() { @Test public void testTargetsFlagsExistUnSupportedOS() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Targets"); @@ -81,21 +58,12 @@ public void testTargetsFlagsExistUnSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Target_RHV"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -107,8 +75,6 @@ public void testTargetsFlagsExistUnSupportedOS() { @Test public void testTargetsNoFlagsSupportedOS() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Targets"); @@ -119,21 +85,12 @@ public void testTargetsNoFlagsSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Target_RHV", "Target_OSP"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -146,8 +103,6 @@ public void testTargetsNoFlagsSupportedOS() { @Test public void testTargetsNoFlagsUnSupportedOS() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Targets"); @@ -158,21 +113,12 @@ public void testTargetsNoFlagsUnSupportedOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Target_RHV", "Target_OSP"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -185,8 +131,6 @@ public void testTargetsNoFlagsUnSupportedOS() { @Test public void testTargetsCentOS() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Targets"); @@ -197,21 +141,12 @@ public void testTargetsCentOS() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Target_RHV", "Target_Convert2RHEL"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -224,8 +159,6 @@ public void testTargetsCentOS() { @Test public void testTargetsOracle() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Targets"); @@ -235,21 +168,12 @@ public void testTargetsOracle() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(4, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Target_RHV", "Target_OSP","Target_Convert2RHEL"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadInventoryReportTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadInventoryReportTest.java index 5ea7a750..a442fc3e 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadInventoryReportTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadInventoryReportTest.java @@ -25,19 +25,11 @@ public class WorkloadInventoryReportTest extends BaseIntegrationTest { public WorkloadInventoryReportTest() { - super("WorkloadInventoryKSession0"); - } - - private void checkLoadedRulesNumber() - { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 23); + super("WorkloadInventoryKSession0", "org.jboss.xavier.analytics.rules.workload.inventory", 26); } @Test public void testNoFlagsSupportedOS() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -141,9 +133,6 @@ public void testNoFlagsSupportedOS() throws ParseException { @Test public void testOneFlagSupportedOS() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -247,9 +236,6 @@ public void testOneFlagSupportedOS() throws ParseException { @Test public void testMoreThanOneFlagSupportedOS() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -357,9 +343,6 @@ public void testMoreThanOneFlagSupportedOS() throws ParseException { @Test public void testNoFlagsUnSupportedOS() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -465,9 +448,6 @@ public void testNoFlagsUnSupportedOS() throws ParseException { @Test public void testFlagsCentOS() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -572,17 +552,12 @@ public void testFlagsCentOS() throws ParseException { @Test public void testOneOrMoreFlagsUnsupported_OS() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); //Basic Fields VMWorkloadInventoryModel vmWorkloadInventoryModel = new VMWorkloadInventoryModel(); vmWorkloadInventoryModel.setProvider("IMS vCenter"); - vmWorkloadInventoryModel.setDatacenter("V2V-DC"); - vmWorkloadInventoryModel.setCluster("Cluster 1"); vmWorkloadInventoryModel.setVmName("vm tests"); vmWorkloadInventoryModel.setDiskSpace(100000001L); vmWorkloadInventoryModel.setMemory(4096L); @@ -592,7 +567,6 @@ public void testOneOrMoreFlagsUnsupported_OS() throws ParseException { vmWorkloadInventoryModel.setOsProductName("debian"); vmWorkloadInventoryModel.setProduct("VMware vCenter"); vmWorkloadInventoryModel.setVersion("6.5"); - vmWorkloadInventoryModel.setHost_name("esx13.v2v.bos.redhat.com"); vmWorkloadInventoryModel.setScanRunDate(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z")); //Flags @@ -620,11 +594,13 @@ public void testOneOrMoreFlagsUnsupported_OS() throws ParseException { Map results = Utils.executeCommandsAndGetResults(kieSession, commands); // check that the number of rules fired is what you expect - Assert.assertEquals(5, results.get(NUMBER_OF_FIRED_RULE_KEY)); + Assert.assertEquals(8, results.get(NUMBER_OF_FIRED_RULE_KEY)); // check the names of the rules fired are what you expect Utils.verifyRulesFiredNames(this.agendaEventListener, // BasicFields "Copy basic fields and agenda controller", + // ReasonableDefaults + "Fill 'datacenter' field with reasonable default", "Fill 'cluster' field with reasonable default", "Fill 'host_name' field with reasonable default", // Flags "Flag_Nics", // Target @@ -649,8 +625,6 @@ public void testOneOrMoreFlagsUnsupported_OS() throws ParseException { WorkloadInventoryReportModel workloadInventoryReportModel = (WorkloadInventoryReportModel) queryResultsRow.get("report"); // BasicFields Assert.assertEquals("IMS vCenter",workloadInventoryReportModel.getProvider()); - Assert.assertEquals("V2V-DC",workloadInventoryReportModel.getDatacenter()); - Assert.assertEquals("Cluster 1",workloadInventoryReportModel.getCluster()); Assert.assertEquals("vm tests",workloadInventoryReportModel.getVmName()); Assert.assertEquals(100000001L,workloadInventoryReportModel.getDiskSpace(), 0); Assert.assertEquals(4096,workloadInventoryReportModel.getMemory().intValue()); @@ -659,8 +633,11 @@ public void testOneOrMoreFlagsUnsupported_OS() throws ParseException { Assert.assertEquals("debian",workloadInventoryReportModel.getOsName()); Assert.assertEquals("VMware vCenter", workloadInventoryReportModel.getProduct()); Assert.assertEquals("6.5", workloadInventoryReportModel.getVersion()); - Assert.assertEquals("esx13.v2v.bos.redhat.com", workloadInventoryReportModel.getHost_name()); Assert.assertEquals(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z"), workloadInventoryReportModel.getCreationDate()); + // ReasonableDefaults + Assert.assertEquals(WorkloadInventoryReportModel.DATACENTER_DEFAULT_VALUE,workloadInventoryReportModel.getDatacenter()); + Assert.assertEquals(WorkloadInventoryReportModel.CLUSTER_DEFAULT_VALUE,workloadInventoryReportModel.getCluster()); + Assert.assertEquals(WorkloadInventoryReportModel.HOST_NAME_DEFAULT_VALUE, workloadInventoryReportModel.getHost_name()); // Flags Set flagsIMS = workloadInventoryReportModel.getFlagsIMS(); Assert.assertNotNull(flagsIMS); @@ -678,9 +655,6 @@ public void testOneOrMoreFlagsUnsupported_OS() throws ParseException { @Test public void testUndetectedOS() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -779,9 +753,6 @@ public void testUndetectedOS() throws ParseException { @Test public void testTomcatWorkload() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -890,9 +861,6 @@ public void testTomcatWorkload() throws ParseException { @Test public void testEAPWorkload() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -988,9 +956,6 @@ public void testEAPWorkload() throws ParseException { @Test public void testWebsphereWorkload() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -1086,9 +1051,6 @@ public void testWebsphereWorkload() throws ParseException { @Test public void testWeblogicWorkload() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -1184,9 +1146,6 @@ public void testWeblogicWorkload() throws ParseException { @Test public void testOracleDBWorkload() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -1282,9 +1241,6 @@ public void testOracleDBWorkload() throws ParseException { @Test public void testSAP_HANA_Workload() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -1380,9 +1336,6 @@ public void testSAP_HANA_Workload() throws ParseException { @Test public void testSQLServerOnLinux() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -1478,9 +1431,6 @@ public void testSQLServerOnLinux() throws ParseException { @Test public void testSQLServerOnWindows() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); @@ -1580,17 +1530,12 @@ public void testSQLServerOnWindows() throws ParseException { @Test public void testSQLServerOnWindows2() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); //Basic Fields VMWorkloadInventoryModel vmWorkloadInventoryModel = new VMWorkloadInventoryModel(); vmWorkloadInventoryModel.setProvider("IMS vCenter"); - vmWorkloadInventoryModel.setDatacenter("V2V-DC"); - vmWorkloadInventoryModel.setCluster("Cluster 1"); vmWorkloadInventoryModel.setVmName("vm tests"); vmWorkloadInventoryModel.setDiskSpace(100000001L); vmWorkloadInventoryModel.setMemory(4096L); @@ -1600,7 +1545,6 @@ public void testSQLServerOnWindows2() throws ParseException { vmWorkloadInventoryModel.setOsProductName("rhel"); vmWorkloadInventoryModel.setProduct("VMware vCenter"); vmWorkloadInventoryModel.setVersion("6.5"); - vmWorkloadInventoryModel.setHost_name("esx13.v2v.bos.redhat.com"); vmWorkloadInventoryModel.setScanRunDate(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z")); List vmDiskFilenames = new ArrayList<>(); @@ -1628,11 +1572,13 @@ public void testSQLServerOnWindows2() throws ParseException { Map results = Utils.executeCommandsAndGetResults(kieSession, commands); // check that the number of rules fired is what you expect - Assert.assertEquals(6, results.get(NUMBER_OF_FIRED_RULE_KEY)); + Assert.assertEquals(9, results.get(NUMBER_OF_FIRED_RULE_KEY)); // check the names of the rules fired are what you expect Utils.verifyRulesFiredNames(this.agendaEventListener, // BasicFields "Copy basic fields and agenda controller", + // ReasonableDefaults + "Fill 'datacenter' field with reasonable default", "Fill 'cluster' field with reasonable default", "Fill 'host_name' field with reasonable default", // Flags // Target "Target_RHV", "Target_OSP", @@ -1656,8 +1602,6 @@ public void testSQLServerOnWindows2() throws ParseException { WorkloadInventoryReportModel workloadInventoryReportModel = (WorkloadInventoryReportModel) queryResultsRow.get("report"); // BasicFields Assert.assertEquals("IMS vCenter",workloadInventoryReportModel.getProvider()); - Assert.assertEquals("V2V-DC",workloadInventoryReportModel.getDatacenter()); - Assert.assertEquals("Cluster 1",workloadInventoryReportModel.getCluster()); Assert.assertEquals("vm tests",workloadInventoryReportModel.getVmName()); Assert.assertEquals(100000001L,workloadInventoryReportModel.getDiskSpace(), 0); Assert.assertEquals(4096,workloadInventoryReportModel.getMemory().intValue()); @@ -1666,8 +1610,11 @@ public void testSQLServerOnWindows2() throws ParseException { Assert.assertEquals("rhel",workloadInventoryReportModel.getOsName()); Assert.assertEquals("VMware vCenter", workloadInventoryReportModel.getProduct()); Assert.assertEquals("6.5", workloadInventoryReportModel.getVersion()); - Assert.assertEquals("esx13.v2v.bos.redhat.com", workloadInventoryReportModel.getHost_name()); Assert.assertEquals(new SimpleDateFormat("yyyy-M-dd'T'hh:mm:ss.S").parse("2019-09-18T14:52:45.871Z"), workloadInventoryReportModel.getCreationDate()); + // ReasonableDefaults + Assert.assertEquals(WorkloadInventoryReportModel.DATACENTER_DEFAULT_VALUE,workloadInventoryReportModel.getDatacenter()); + Assert.assertEquals(WorkloadInventoryReportModel.CLUSTER_DEFAULT_VALUE,workloadInventoryReportModel.getCluster()); + Assert.assertEquals(WorkloadInventoryReportModel.HOST_NAME_DEFAULT_VALUE, workloadInventoryReportModel.getHost_name()); // Flags // Targets // Complexity @@ -1680,9 +1627,6 @@ public void testSQLServerOnWindows2() throws ParseException { @Test public void testNoServicesAndNoFiles() throws ParseException { - // check that the numbers of rule from the DRL file is the number of rules loaded - checkLoadedRulesNumber(); - // create a Map with the facts (i.e. Objects) you want to put in the working memory Map facts = new HashMap<>(); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadsTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadsTest.java index 0ec2d6b2..7eadd0b6 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadsTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/inventory/WorkloadsTest.java @@ -6,32 +6,22 @@ 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.Set; -import java.util.stream.Collectors; public class WorkloadsTest extends BaseTest { public WorkloadsTest() { - super("/org/jboss/xavier/analytics/rules/workload/inventory/Workloads.drl", ResourceType.DRL); - } - - private void checkLoadedRulesNumber() - { - Utils.checkLoadedRulesNumber(kieSession, "org.jboss.xavier.analytics.rules.workload.inventory", 10); + super("/org/jboss/xavier/analytics/rules/workload/inventory/Workloads.drl", ResourceType.DRL, + "org.jboss.xavier.analytics.rules.workload.inventory", 10); } @Test public void testTomcat() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -50,21 +40,12 @@ public void testTomcat() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Tomcat", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -77,8 +58,6 @@ public void testTomcat() { @Test public void testEAP_1() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -97,21 +76,12 @@ public void testEAP_1() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_EAP", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -124,8 +94,6 @@ public void testEAP_1() { @Test public void testEAP_2() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -144,21 +112,12 @@ public void testEAP_2() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_EAP", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -171,8 +130,6 @@ public void testEAP_2() { @Test public void testEAP_3() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -191,21 +148,12 @@ public void testEAP_3() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_EAP", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -218,8 +166,6 @@ public void testEAP_3() { @Test public void testEAP_4() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -238,21 +184,12 @@ public void testEAP_4() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_EAP", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -265,8 +202,6 @@ public void testEAP_4() { @Test public void testEAP_5() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -285,21 +220,12 @@ public void testEAP_5() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_EAP", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -312,8 +238,6 @@ public void testEAP_5() { @Test public void testEAP_6() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -332,21 +256,12 @@ public void testEAP_6() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_EAP", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -359,8 +274,6 @@ public void testEAP_6() { @Test public void testEAP_7() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -379,21 +292,12 @@ public void testEAP_7() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_EAP", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -406,8 +310,6 @@ public void testEAP_7() { @Test public void testWebsphere_1() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -426,21 +328,12 @@ public void testWebsphere_1() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Websphere", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -453,8 +346,6 @@ public void testWebsphere_1() { @Test public void testWebsphere_2() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -473,21 +364,12 @@ public void testWebsphere_2() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Websphere", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -500,8 +382,6 @@ public void testWebsphere_2() { @Test public void testWebsphere_3() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -520,21 +400,12 @@ public void testWebsphere_3() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Websphere", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -549,8 +420,6 @@ public void testWebsphere_3() { @Test public void testWebsphere_4() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -569,21 +438,12 @@ public void testWebsphere_4() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Websphere","SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -597,8 +457,6 @@ public void testWebsphere_4() { @Test public void testWebsphere_5() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -617,21 +475,12 @@ public void testWebsphere_5() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Websphere", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -643,8 +492,6 @@ public void testWebsphere_5() { @Test public void testWeblogic_1() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -663,21 +510,12 @@ public void testWeblogic_1() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Weblogic", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -690,8 +528,6 @@ public void testWeblogic_1() { @Test public void testWeblogic_2() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -710,21 +546,12 @@ public void testWeblogic_2() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Weblogic", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -737,8 +564,6 @@ public void testWeblogic_2() { @Test public void testWeblogic_3() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -757,21 +582,12 @@ public void testWeblogic_3() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Weblogic", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -784,8 +600,6 @@ public void testWeblogic_3() { @Test public void testWeblogic_4() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -804,21 +618,12 @@ public void testWeblogic_4() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Weblogic", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -831,8 +636,6 @@ public void testWeblogic_4() { @Test public void testOracleDB() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -851,21 +654,12 @@ public void testOracleDB() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Oracle_DB", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -878,8 +672,6 @@ public void testOracleDB() { @Test public void testSAP_HANA() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -898,21 +690,12 @@ public void testSAP_HANA() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_SAP_HANA", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -925,8 +708,6 @@ public void testSAP_HANA() { @Test public void testMSSQLServerOnLinux() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -945,21 +726,12 @@ public void testMSSQLServerOnLinux() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Microsoft_SQL_Server_On_Linux", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -972,8 +744,6 @@ public void testMSSQLServerOnLinux() { @Test public void testMSSQLServerOnWindows() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -991,21 +761,12 @@ public void testMSSQLServerOnWindows() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Microsoft_SQL_Server_On_Windows", "SsaEnabled_System_Services_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -1020,8 +781,6 @@ public void testMSSQLServerOnWindows() { @Test public void testMSSQLServerOnWindows2() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -1036,21 +795,12 @@ public void testMSSQLServerOnWindows2() { facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(3, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "Workloads_Microsoft_SQL_Server_On_Windows","SsaDisabled_System_Services_Not_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); @@ -1062,8 +812,6 @@ public void testMSSQLServerOnWindows2() { @Test public void testFileWithNullContent() { - checkLoadedRulesNumber(); - Map facts = new HashMap<>(); // always add a String fact with the name of the agenda group defined in the DRL file (e.g. "SourceCosts") facts.put("agendaGroup", "Workloads"); @@ -1077,21 +825,12 @@ public void testFileWithNullContent() { WorkloadInventoryReportModel workloadInventoryReportModel = new WorkloadInventoryReportModel(); facts.put("workloadInventoryReportModel",workloadInventoryReportModel); - 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(2, results.get(NUMBER_OF_FIRED_RULE_KEY)); Utils.verifyRulesFiredNames(this.agendaEventListener, "AgendaFocusForTest", "SsaDisabled_System_Services_Not_Present"); - List objects = (List) results.get((GET_OBJECTS_KEY)); - List reports = objects.stream() - .filter(object -> object instanceof WorkloadInventoryReportModel) - .map(object -> (WorkloadInventoryReportModel) object) - .collect(Collectors.toList()); + List reports = Utils.extractModels(GET_OBJECTS_KEY, results, WorkloadInventoryReportModel.class); // just one report has to be created Assert.assertEquals(1, reports.size()); diff --git a/src/test/java/org/jboss/xavier/analytics/rules/workload/summary/WorkloadSummaryReportTest.java b/src/test/java/org/jboss/xavier/analytics/rules/workload/summary/WorkloadSummaryReportTest.java index 6d72deac..69aff2fe 100644 --- a/src/test/java/org/jboss/xavier/analytics/rules/workload/summary/WorkloadSummaryReportTest.java +++ b/src/test/java/org/jboss/xavier/analytics/rules/workload/summary/WorkloadSummaryReportTest.java @@ -9,7 +9,15 @@ public class WorkloadSummaryReportTest extends BaseIntegrationTest public WorkloadSummaryReportTest() { - super("WorkloadSummaryKSession0"); + super("WorkloadSummaryKSession0", "org.jboss.xavier.analytics.rules.workload.summary", 0); + } + + @Override + @Test + // TODO Remove this method once WorkloadSummaryReportTest will be testing new Workload Summary rules + public void checkLoadedRulesNumber() + { + Assert.assertTrue(true); } @Test diff --git a/src/test/java/org/jboss/xavier/analytics/test/Utils.java b/src/test/java/org/jboss/xavier/analytics/test/Utils.java index 4e1b44e6..88c6d1a4 100644 --- a/src/test/java/org/jboss/xavier/analytics/test/Utils.java +++ b/src/test/java/org/jboss/xavier/analytics/test/Utils.java @@ -64,14 +64,13 @@ public static Map executeCommandsAndGetResults(CommandExecutor k return results; } - public static List getListOf(Class t, Map results, String objectKey) + public static List extractModels(String objectKeyInResults, Map results, Class model) { - List objects = (List) results.get((objectKey)); - List tList = objects.stream() - .filter(object -> t.isAssignableFrom(object.getClass())) - .map(object -> (T) object) + final List objects = (List) results.get(objectKeyInResults); + return objects.stream() + .filter(model::isInstance) + .map(model::cast) .collect(Collectors.toList()); - return tList; } public static void verifyRulesFiredNames(AgendaEventListener agendaEventListener, String ... rulesNames)