Skip to content

Commit

Permalink
Issue102 auditable default result (deliveredtechnologies#103)
Browse files Browse the repository at this point in the history
* added updated dsl to allow a default result with auditor

* updated gradle build

* Update README.md
  • Loading branch information
Clayton7510 authored Oct 11, 2017
1 parent 8ccb903 commit 238fe63
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 155 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ cd RuleBook

### 1.3 Latest Sonatype SNAPSHOT (Development) Release

* rulebook-core    [![Sonatype Nexus](https://img.shields.io/badge/SNAPSHOT-0.10-green.svg)](https://oss.sonatype.org/content/repositories/snapshots/)
* rulebook-spring [![Sonatype Nexus](https://img.shields.io/badge/SNAPSHOT-0.10-green.svg)](https://oss.sonatype.org/content/repositories/snapshots/)
* rulebook-core    [![Sonatype Nexus](https://img.shields.io/badge/SNAPSHOT-0.9.1-green.svg)](https://oss.sonatype.org/content/repositories/snapshots/)
* rulebook-spring [![Sonatype Nexus](https://img.shields.io/badge/SNAPSHOT-0.9.1-green.svg)](https://oss.sonatype.org/content/repositories/snapshots/)

### 1.4 Adding RuleBook to Your Maven Project

Expand Down
158 changes: 158 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,167 @@ subprojects {
build.dependsOn jacocoTestReport, checkstyleMainHtml, checkstyleTestHtml
}

project("rulebook-core") {
modifyPom {
project {
name 'RuleBook'
description 'A simple and intuitive rules abstraction for Java'
url "${projectUrl}"
inceptionYear "${projectYear}"

scm {
url "${projectScmUrl}"
connection "${projectScmConnection}"
developerConnection "${projectScmConnection}"
}

distributionManagement {
site {
id "${projectDistMgmtId}"
url "${projectDistMgmtUrl}"
}
}

issueManagement {
system "${projectIssueMgmtSystem}"
url "${projectIssueMgmtUrl}"
}

licenses {
license {
name "${projectLicenseName}"
url "${projectLicenseUrl}"
distribution "${projectLicenseDistro}"
}
}

developers {
developer {
id 'Clayton7510'
name 'Clayton Long'
url 'https://github.com/Clayton7510'
email '[email protected]'
roles {
role 'Author'
}
}
}

contributors {
contributor {
name 'Nicholas Lambert'
url 'https://github.com/NicolasLambert'
roles {
role 'code contributor for v0.2.1'
role 'raised dsl enhancement for v0.8'
}
}
contributor {
name 'wheezymustafa'
url 'https://github.com/wheezymustafa'
roles {
role 'raised bugs and enhancement suggestions for v0.3 and v0.3.1'
}
}
contributor {
name 'Alessandro Torrisi'
url 'https://github.com/typhoon1978'
roles {
role 'raised bug for v0.5.1'
}
}
contributor {
name 'Marc Seeger'
url 'https://github.com/Gersee'
roles {
role 'raised bug for v0.5.1'
}
}
contributor {
name 'abhineet27'
url 'https://github.com/abhineet27'
roles {
role 'raised bug for v0.6.1'
role 'raised bug for v0.6.2'
}
}
contributor {
name 'Darrell Merryweather'
url 'https://github.com/darrellme'
roles {
role 'raised rule chain enhancement for v0.8'
}
}
contributor {
name 'Kent Jones'
url 'https://github.com/kentjones'
roles {
role 'raised bug for v0.8.1'
}
}
contributor {
name 'Ivan Portugal'
url 'https://github.com/ivanbportugal'
roles {
role 'raised bug for v0.8.1'
}
}
contributor {
name 'Brad Egler'
url 'https://github.com/bradegler'
roles {
rule 'upgraded gradle build for v0.9.1'
}
}
}
}
}
}

project("rulebook-spring") {
modifyPom {
project {
name 'RuleBook Spring'
description 'Spring support for RuleBook'
url "${projectUrl}"
inceptionYear "${projectYear}"

scm {
url "${projectScmUrl}"
connection "${projectScmConnection}"
developerConnection "${projectScmConnection}"
}

distributionManagement {
site {
id "${projectDistMgmtId}"
url "${projectDistMgmtUrl}"
}
}

issueManagement {
system "${projectIssueMgmtSystem}"
url "${projectIssueMgmtUrl}"
}

licenses {
license {
name "${projectLicenseName}"
url "${projectLicenseUrl}"
distribution "${projectLicenseDistro}"
}
}

developers {
developer {
id 'Clayton7510'
name 'Clayton Long'
email '[email protected]'
}
}
}
}
}

task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn subprojects.test
Expand Down
5 changes: 1 addition & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# project specific settings
project.group=com.deliveredtechnologies
project.version=0.10-SNAPSHOT
project.version=0.9.1-SNAPSHOT
project.compatibility=1.8
project.url=http://www.deliveredtechnologies.com
project.inceptionYear=2017
Expand All @@ -13,6 +13,3 @@ project.distributionmgmt.site.url=http://www.deliveredtechnologies.com
project.license.name=The Apache Software License, Version 2.0
project.license.url=http://www.apache.org/licenses/LICENSE-2.0.txt
project.license.distribution=repo

# spring settings
spring.version=4.3.6.RELEASE
106 changes: 0 additions & 106 deletions rulebook-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,107 +1 @@
modifyPom {
project {
name 'RuleBook'
description 'A simple and intuitive rules abstraction for Java'
url "${projectUrl}"
inceptionYear "${projectYear}"

scm {
url "${projectScmUrl}"
connection "${projectScmConnection}"
developerConnection "${projectScmConnection}"
}

distributionManagement {
site {
id "${projectDistMgmtId}"
url "${projectDistMgmtUrl}"
}
}

issueManagement {
system "${projectIssueMgmtSystem}"
url "${projectIssueMgmtUrl}"
}

licenses {
license {
name "${projectLicenseName}"
url "${projectLicenseUrl}"
distribution "${projectLicenseDistro}"
}
}

developers {
developer {
id 'Clayton7510'
name 'Clayton Long'
url 'https://github.com/Clayton7510'
email '[email protected]'
roles {
role 'Author'
}
}
}

contributors {
contributor {
name 'Nicholas Lambert'
url 'https://github.com/NicolasLambert'
roles {
role 'code contributor for v0.2.1'
role 'raised dsl enhancement for v0.8'
}
}
contributor {
name 'wheezymustafa'
url 'https://github.com/wheezymustafa'
roles {
role 'raised bugs and enhancement suggestions for v0.3 and v0.3.1'
}
}
contributor {
name 'Alessandro Torrisi'
url 'https://github.com/typhoon1978'
roles {
role 'raised bug for v0.5.1'
}
}
contributor {
name 'Marc Seeger'
url 'https://github.com/Gersee'
roles {
role 'raised bug for v0.5.1'
}
}
contributor {
name 'abhineet27'
url 'https://github.com/abhineet27'
roles {
role 'raised bug for v0.6.1'
role 'raised bug for v0.6.2'
}
}
contributor {
name 'Darrell Merryweather'
url 'https://github.com/darrellme'
roles {
role 'raised rule chain enhancement for v0.8'
}
}
contributor {
name 'Kent Jones'
url 'https://github.com/kentjones'
roles {
role 'raised bug for v0.8.1'
}
}
contributor {
name 'Ivan Portugal'
url 'https://github.com/ivanbportugal'
roles {
role 'raised bug for v0.8.1'
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.deliveredtechnologies.rulebook.lang;

import com.deliveredtechnologies.rulebook.model.Auditor;
import com.deliveredtechnologies.rulebook.model.Rule;
import com.deliveredtechnologies.rulebook.model.RuleBook;
import com.deliveredtechnologies.rulebook.model.RuleBookAuditor;

import java.util.function.Consumer;

Expand Down Expand Up @@ -35,6 +37,14 @@ public <U> RuleBookAddRuleBuilder<T> addRule(Rule<U, T> rule) {
return new RuleBookAddRuleBuilder<>(_ruleBook, rule);
}

/**
* Decorates the RuleBook with {@link Auditor} functionality for rules auditing.
* @return a builder that can add rules
*/
public RuleBookAddRuleBuilder<T> asAuditor() {
return new RuleBookAddRuleBuilder<>(new RuleBookAuditor<>(_ruleBook));
}

@Override
public RuleBook<T> build() {
return _ruleBook;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.deliveredtechnologies.rulebook.model;

import com.deliveredtechnologies.rulebook.FactMap;
import com.deliveredtechnologies.rulebook.Result;
import com.deliveredtechnologies.rulebook.lang.RuleBookBuilder;
import com.deliveredtechnologies.rulebook.lang.RuleBuilder;
import org.junit.Assert;
Expand Down Expand Up @@ -31,4 +32,27 @@ public void ruleBookAuditorCanAuditRules() {
Assert.assertEquals(auditor.getRuleStatus("Rule2"), RuleStatus.SKIPPED);
Assert.assertEquals(auditor.getRuleStatus("Rule3"), RuleStatus.EXECUTED);
}

@Test
public void ruleBookAuditorCanHaveDefaultResult() {
RuleBook rulebook = RuleBookBuilder.create().withResultType(String.class).withDefaultResult("foo").asAuditor()
.addRule(rule -> rule.withName("Rule1").withFactType(String.class)
.when(facts -> true)
.then(facts -> { } ))
.addRule(rule -> rule.withName("Rule2").withNoSpecifiedFactType()
.when(facts -> false)
.then(facts -> { } ))
.addRule(rule -> rule.withName("Rule3").withFactType(String.class)
.when(facts -> true)
.then(facts -> { } ).build())
.build();

rulebook.run(new FactMap());
Auditor auditor = (Auditor)rulebook;

Assert.assertEquals(auditor.getRuleStatus("Rule1"), RuleStatus.EXECUTED);
Assert.assertEquals(auditor.getRuleStatus("Rule2"), RuleStatus.SKIPPED);
Assert.assertEquals(auditor.getRuleStatus("Rule3"), RuleStatus.EXECUTED);
Assert.assertEquals("foo", ((Result<String>)rulebook.getResult().get()).getValue());
}
}
Loading

0 comments on commit 238fe63

Please sign in to comment.