[seam-commits] Seam SVN: r13737 - in modules/drools/trunk: impl/src/main/java/org/jboss/seam/drools and 4 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Sep 13 00:32:38 EDT 2010
Author: tsurdilovic
Date: 2010-09-13 00:32:37 -0400 (Mon, 13 Sep 2010)
New Revision: 13737
Added:
modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportWrapper.java
modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/
modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/Cheese.java
modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/SessionReportTest.java
modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/
modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/SessionReportTest-beans.xml
modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/sessionreporttest.drl
Modified:
modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/SessionReport.java
modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportProducer.java
Log:
SEAMDROOLS-6 - Add support for session inspector to generate reports
Modified: modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/SessionReport.java
===================================================================
--- modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/SessionReport.java 2010-09-12 16:15:25 UTC (rev 13736)
+++ modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/SessionReport.java 2010-09-13 04:32:37 UTC (rev 13737)
@@ -47,5 +47,8 @@
public @interface SessionReport
{
@Nonbinding
- String value() default "";
+ String name() default "";
+
+ @Nonbinding
+ String template() default "";
}
Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportProducer.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportProducer.java 2010-09-12 16:15:25 UTC (rev 13736)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportProducer.java 2010-09-13 04:32:37 UTC (rev 13737)
@@ -22,10 +22,20 @@
package org.jboss.seam.drools;
import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.drools.core.util.debug.SessionInspector;
+import org.drools.core.util.debug.SessionReporter;
+import org.drools.core.util.debug.StatefulKnowledgeSessionInfo;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.jboss.seam.drools.qualifiers.Scanned;
+import org.jboss.seam.drools.qualifiers.SessionReport;
+
/**
*
* @author Tihomir Surdilovic
@@ -35,4 +45,35 @@
{
private static final Logger log = LoggerFactory.getLogger(SessionReportProducer.class);
+ @Produces
+ @Default
+ @SessionReport
+ public SessionReportWrapper produceSessionReport(StatefulKnowledgeSession ksession, InjectionPoint ip) {
+ return generate(ksession, ip.getAnnotated().getAnnotation(SessionReport.class).name(), ip.getAnnotated().getAnnotation(SessionReport.class).template());
+ }
+
+ @Produces
+ @Scanned
+ @SessionReport
+ public SessionReportWrapper produceScannedSessionReport(@Scanned StatefulKnowledgeSession ksession, InjectionPoint ip) {
+ return generate(ksession, ip.getAnnotated().getAnnotation(SessionReport.class).name(), ip.getAnnotated().getAnnotation(SessionReport.class).template());
+ }
+
+ private SessionReportWrapper generate(StatefulKnowledgeSession ksession, String name, String template) {
+ if(name == null)
+ {
+ name = "simple";
+ }
+ SessionInspector inspector = new SessionInspector( ksession );
+ StatefulKnowledgeSessionInfo info = inspector.getSessionInfo();
+ if(template != null)
+ {
+ SessionReporter.addNamedTemplate( name, getClass().getResourceAsStream( template ) );
+ }
+
+ SessionReportWrapper sessionReportWrapper = new SessionReportWrapper();
+ sessionReportWrapper.setReport(SessionReporter.generateReport( name, info, null ));
+ return sessionReportWrapper;
+ }
+
}
Added: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportWrapper.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportWrapper.java (rev 0)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportWrapper.java 2010-09-13 04:32:37 UTC (rev 13737)
@@ -0,0 +1,16 @@
+package org.jboss.seam.drools;
+
+public class SessionReportWrapper
+{
+ private String report;
+
+ public String getReport()
+ {
+ return report;
+ }
+
+ public void setReport(String report)
+ {
+ this.report = report;
+ }
+}
Property changes on: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/SessionReportWrapper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/Cheese.java
===================================================================
--- modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/Cheese.java (rev 0)
+++ modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/Cheese.java 2010-09-13 04:32:37 UTC (rev 13737)
@@ -0,0 +1,43 @@
+package org.jboss.seam.drools.test.sessionreport;
+
+public class Cheese
+{
+ private String type;
+ private int price;
+
+ public Cheese(String type, int price) {
+ this.type = type;
+ this.price = price;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+ public int getPrice()
+ {
+ return price;
+ }
+ public void setPrice(int price)
+ {
+ this.price = price;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final Cheese other = (Cheese) obj;
+ if ( price != other.price ) return false;
+ if ( type == null ) {
+ if ( other.type != null ) return false;
+ } else if ( !type.equals( other.type ) ) return false;
+ return true;
+ }
+
+
+}
Property changes on: modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/Cheese.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/SessionReportTest.java
===================================================================
--- modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/SessionReportTest.java (rev 0)
+++ modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/SessionReportTest.java 2010-09-13 04:32:37 UTC (rev 13737)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.drools.test.sessionreport;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertNotSame;
+
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.drools.KnowledgeBaseProducer;
+import org.jboss.seam.drools.SessionReportWrapper;
+import org.jboss.seam.drools.qualifiers.SessionReport;
+import org.jboss.seam.drools.qualifiers.config.DefaultConfig;
+import org.jboss.seam.drools.test.DroolsModuleFilter;
+import org.jboss.seam.drools.test.query.QueryTest;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.weld.extensions.resourceLoader.ResourceProvider;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class SessionReportTest
+{
+ @Deployment
+ public static JavaArchive createTestArchive()
+ {
+ String pkgPath = QueryTest.class.getPackage().getName().replaceAll("\\.", "/");
+ JavaArchive archive = ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addPackages(true, new DroolsModuleFilter("sessionreport"), KnowledgeBaseProducer.class.getPackage())
+ .addPackages(true, ResourceProvider.class.getPackage())
+ .addClass(Cheese.class)
+ .addResource(pkgPath + "/sessionreporttest.drl", ArchivePaths.create("sessionreporttest.drl"))
+ //.addResource(pkgPath + "/kbuilderconfig.properties", ArchivePaths.create("kbuilderconfig.properties"))
+ //.addResource(pkgPath + "/kbaseconfig.properties", ArchivePaths.create("kbaseconfig.properties"))
+ .addManifestResource(pkgPath + "/SessionReportTest-beans.xml", ArchivePaths.create("beans.xml"));
+ //System.out.println(archive.toString(Formatters.VERBOSE));
+ return archive;
+ }
+
+ @Inject @Default @DefaultConfig StatefulKnowledgeSession ksession;
+
+ @Before
+ public void setupKSession() {
+ assertNotNull(ksession);
+ Cheese c1 = new Cheese("stillton", 10);
+ Cheese c2 = new Cheese("stillton", 2);
+ Cheese c3 = new Cheese("stillton", 4);
+ Cheese c4 = new Cheese("stillton", 44);
+ Cheese c5 = new Cheese("stillton", 23);
+ Cheese c6 = new Cheese("stillton", 1);
+ Cheese c7 = new Cheese("stillton", 7);
+ Cheese c8 = new Cheese("stillton", 4);
+ Cheese c9 = new Cheese("mozarella", 77);
+ Cheese c10 = new Cheese("mozarella", 53);
+ Cheese c11 = new Cheese("mozarella", 31);
+ Cheese c12 = new Cheese("mozarella", 7);
+ Cheese c13 = new Cheese("mozarella", 3);
+
+ ksession.insert(c1);
+ ksession.insert(c2);
+ ksession.insert(c3);
+ ksession.insert(c4);
+ ksession.insert(c5);
+ ksession.insert(c6);
+ ksession.insert(c7);
+ ksession.insert(c8);
+ ksession.insert(c9);
+ ksession.insert(c10);
+ ksession.insert(c11);
+ ksession.insert(c12);
+ ksession.insert(c13);
+
+ ksession.fireAllRules();
+ }
+
+ @Test
+ public void testGeneratedReport(@Default @DefaultConfig @SessionReport SessionReportWrapper wrapper) {
+ assertNotNull(wrapper);
+ assertNotNull(wrapper.getReport());
+ }
+}
Property changes on: modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/sessionreport/SessionReportTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/SessionReportTest-beans.xml
===================================================================
--- modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/SessionReportTest-beans.xml (rev 0)
+++ modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/SessionReportTest-beans.xml 2010-09-13 04:32:37 UTC (rev 13737)
@@ -0,0 +1,35 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright ${year}, Red Hat, Inc., and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site: http://www.fsf.org.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:s="urn:java:ee"
+ xmlns:d="urn:java:org.jboss.seam.drools:org.jboss.seam.drools.config"
+ xmlns:test="urn:java:org.jboss.seam.drools.test.ksession">
+
+ <d:DefaultRuleResources>
+ <s:modifies/>
+ <s:Exact>org.jboss.seam.drools.config.DefaultRuleResources</s:Exact>
+ <d:resources>
+ <s:value>classpath;sessionreporttest.drl;DRL</s:value>
+ </d:resources>
+ </d:DefaultRuleResources>
+
+</beans>
Property changes on: modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/SessionReportTest-beans.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/sessionreporttest.drl
===================================================================
--- modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/sessionreporttest.drl (rev 0)
+++ modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/sessionreport/sessionreporttest.drl 2010-09-13 04:32:37 UTC (rev 13737)
@@ -0,0 +1,10 @@
+package org.jboss.seam.drools.test.sessionreport
+
+import org.jboss.seam.drools.test.sessionreport.Cheese;
+
+rule stilltonCheeses
+ when
+ $c : Cheese( type == "stillton" )
+ then
+ System.out.println($c.getPrice());
+end
More information about the seam-commits
mailing list