Skip to content

Commit

Permalink
refact test-container to using junit5 and jdk17
Browse files Browse the repository at this point in the history
  • Loading branch information
significantfrank committed Apr 20, 2024
1 parent 22f6367 commit bf350e5
Show file tree
Hide file tree
Showing 12 changed files with 1,044 additions and 1,090 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public void setUp(){
fizzBuzzEngine = new DefaultRuleEngine();
}



@Test
public void test_fizz_first(){
Facts facts = new Facts();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,79 @@
package com.alibaba.cola.ruleengine;

import com.alibaba.cola.ruleengine.api.Action;
import com.alibaba.cola.ruleengine.api.Facts;
import com.alibaba.cola.ruleengine.api.Rule;
import com.alibaba.cola.ruleengine.core.AbstractRule;
import com.alibaba.cola.ruleengine.api.RuleEngine;
import com.alibaba.cola.ruleengine.core.*;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.extractProperty;

public class PriorityTest {

RuleEngine ruleEngine;

@Before
public void setUp() {
ruleEngine = new DefaultRuleEngine();
}


@Test
public void testNoPriority() {
DummyRule r1 = new DummyRule();
DummyRule r2 = new DummyRule();
DummyRule r3 = new DummyRule();
DummyRule r1 = new DummyRule(1);
DummyRule r2 = new DummyRule(2);
DummyRule r3 = new DummyRule(3);

// assertThat(rules).startsWith(r1).endsWith(r3);
}

@Test
public void testPriority(){
public void testPriority() {
DummyRule r1 = new DummyRule(10);
DummyRule r2 = new DummyRule(3);
DummyRule r3 = new DummyRule(1);


// assertThat(rules).startsWith(r3).endsWith(r1);
}

@Test
public void test_natural_rule() {
DummyRule r1 = new DummyRule(10);
DummyRule r2 = new DummyRule(3);
DummyRule r3 = new DummyRule(1);
Facts facts = new Facts();
facts.put("number", 15);

Rule naturalRules = NaturalRules.of(r1, r2, r3);
ruleEngine.fire(naturalRules, facts);
}


static class DummyRule extends AbstractRule {

public DummyRule(){
static class DummyRule extends DefaultRule {

}

public DummyRule(int priority){
super(priority);
public DummyRule(int priority) {
super("rule" + priority, null, priority, facts -> true, new ArrayList<>());
}

@Override
public boolean evaluate(Facts facts) {
return false;
return true;
}

@Override
public void execute(Facts facts) {

System.out.println(facts.getFact("number").getValue());
}

@Override
public boolean apply(Facts facts) {
return false;
System.out.println(name + ": " + facts.getFact("number").getValue());
return true;
}
}
}
Expand Down
51 changes: 17 additions & 34 deletions cola-components/cola-component-test-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,50 +56,33 @@

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>provided</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- Spring Boot Test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<scope>provided</scope>
</dependency>

<!--
support javax annotation @PostConstruct/@PostDestroy when build under java 11+
more info see https://stackoverflow.com/a/55622713/922688
-->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- Exclude JUnit 3 and JUnit 4 support -->
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<!-- override parent, reset scope to compile -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit bf350e5

Please sign in to comment.