forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAEL-802: Drools using rules from Excel Files (eugenp#2115)
* Add NDC and JBoss Logging to the demo application * NDC for Log4j, Log4j2 and JBoss Logging * Simplify NDC example by making it a single operation instead of two * Make NDC example as RestController, Use JBoss Logging only as a logging bridge * Fix merge conflicts in pull request - log-mdc pom.xml updated * BAEL-445 Update to Spring security SpEL example * BAEL-445: Change tabs to spaces in the updated code * BAEL-245: Add Enum Serialization exmaple * BAEL-245: Remove the folder jackson/src/test/java/com/baeldung/jackson/dtos/withEnum as the example is not used anymore * Add more enum serialization examples to align with previous example and prevent build fail * BAEL-611: Minor formatting changes * BAEL-611: Update Test case method names * BAEL-611 Add JAX-WS client and JUnit Test * BAEL-245: Issue 1753. Fix the typo - change from writeNumber() to writeString() * BAEL-741: Spring Security Multiple Authentication Providers * BAEL-741: Spring Security Multiple Authentication Providers * Remove unnecessary change in pom.xml * BAEL-802: Drools Excel example
- Loading branch information
1 parent
0267760
commit bfc6d48
Showing
6 changed files
with
203 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
drools/src/main/java/com/baeldung/drools/model/Customer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.baeldung.drools.model; | ||
|
||
public class Customer { | ||
|
||
private CustomerType type; | ||
|
||
private int years; | ||
|
||
private int discount; | ||
|
||
public Customer(CustomerType type, int numOfYears) { | ||
super(); | ||
this.type = type; | ||
this.years = numOfYears; | ||
} | ||
|
||
public CustomerType getType() { | ||
return type; | ||
} | ||
|
||
public void setType(CustomerType type) { | ||
this.type = type; | ||
} | ||
|
||
public int getYears() { | ||
return years; | ||
} | ||
|
||
public void setYears(int years) { | ||
this.years = years; | ||
} | ||
|
||
public int getDiscount() { | ||
return discount; | ||
} | ||
|
||
public void setDiscount(int discount) { | ||
this.discount = discount; | ||
} | ||
|
||
public enum CustomerType { | ||
INDIVIDUAL, BUSINESS; | ||
} | ||
} |
Binary file not shown.
56 changes: 56 additions & 0 deletions
56
drools/src/test/java/com/baeldung/drools/service/DiscountExcelIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.baeldung.drools.service; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.kie.api.io.Resource; | ||
import org.kie.api.runtime.KieSession; | ||
import org.kie.internal.io.ResourceFactory; | ||
|
||
import com.baeldung.drools.config.DroolsBeanFactory; | ||
import com.baeldung.drools.model.Customer; | ||
import com.baeldung.drools.model.Customer.CustomerType; | ||
|
||
public class DiscountExcelIntegrationTest { | ||
|
||
private KieSession kSession; | ||
|
||
@Before | ||
public void setup() { | ||
Resource resource = ResourceFactory.newClassPathResource("com/baeldung/drools/rules/Discount.xls", getClass()); | ||
kSession = new DroolsBeanFactory().getKieSession(resource); | ||
} | ||
|
||
@Test | ||
public void giveIndvidualLongStanding_whenFireRule_thenCorrectDiscount() throws Exception { | ||
Customer customer = new Customer(CustomerType.INDIVIDUAL, 5); | ||
kSession.insert(customer); | ||
|
||
kSession.fireAllRules(); | ||
|
||
assertEquals(customer.getDiscount(), 15); | ||
} | ||
|
||
@Test | ||
public void giveIndvidualRecent_whenFireRule_thenCorrectDiscount() throws Exception { | ||
|
||
Customer customer = new Customer(CustomerType.INDIVIDUAL, 1); | ||
kSession.insert(customer); | ||
|
||
kSession.fireAllRules(); | ||
|
||
assertEquals(customer.getDiscount(), 5); | ||
} | ||
|
||
@Test | ||
public void giveBusinessAny_whenFireRule_thenCorrectDiscount() throws Exception { | ||
Customer customer = new Customer(CustomerType.BUSINESS, 0); | ||
kSession.insert(customer); | ||
|
||
kSession.fireAllRules(); | ||
|
||
assertEquals(customer.getDiscount(), 20); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...curity-mvc-boot/src/test/java/org/baeldung/web/MultipleAuthProvidersApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.baeldung.web; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Collections; | ||
|
||
import org.baeldung.multipleauthproviders.MultipleAuthProvidersApplication; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = MultipleAuthProvidersApplication.class) | ||
public class MultipleAuthProvidersApplicationTests { | ||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
public void givenMemUsers_whenGetPingWithValidUser_thenOk() { | ||
ResponseEntity<String> result = makeRestCallToGetPing("memuser", "pass"); | ||
|
||
assertThat(result.getStatusCodeValue()).isEqualTo(200); | ||
assertThat(result.getBody()).isEqualTo("OK"); | ||
} | ||
|
||
@Test | ||
public void givenExternalUsers_whenGetPingWithValidUser_thenOK() { | ||
ResponseEntity<String> result = makeRestCallToGetPing("externaluser", "pass"); | ||
|
||
assertThat(result.getStatusCodeValue()).isEqualTo(200); | ||
assertThat(result.getBody()).isEqualTo("OK"); | ||
} | ||
|
||
@Test | ||
public void givenAuthProviders_whenGetPingWithNoCred_then401() { | ||
ResponseEntity<String> result = makeRestCallToGetPing(); | ||
|
||
assertThat(result.getStatusCodeValue()).isEqualTo(401); | ||
} | ||
|
||
@Test | ||
public void givenAuthProviders_whenGetPingWithBadCred_then401() { | ||
ResponseEntity<String> result = makeRestCallToGetPing("user", "bad_password"); | ||
|
||
assertThat(result.getStatusCodeValue()).isEqualTo(401); | ||
} | ||
|
||
private ResponseEntity<String> makeRestCallToGetPing(String username, String password) { | ||
return restTemplate.withBasicAuth(username, password) | ||
.getForEntity("/api/ping", String.class, Collections.emptyMap()); | ||
} | ||
|
||
private ResponseEntity<String> makeRestCallToGetPing() { | ||
return restTemplate.getForEntity("/api/ping", String.class, Collections.emptyMap()); | ||
} | ||
} |