Skip to content
Permalink
Browse files

Release v1.2.1

Resolves #56
  • Loading branch information...
bertilmuth committed Jul 6, 2019
1 parent b1860ac commit db9a72a0b8fc4e6b9a38a35dd8a9d57086c07015
@@ -28,14 +28,14 @@ If you are using Maven, include the following in your POM, to use the core:
<dependency>
<groupId>org.requirementsascode</groupId>
<artifactId>requirementsascodecore</artifactId>
<version>1.2</version>
<version>1.2.1</version>
</dependency>
```

If you are using Gradle, include the following in your build.gradle, to use the core:

```
compile 'org.requirementsascode:requirementsascodecore:1.2'
compile 'org.requirementsascode:requirementsascodecore:1.2.1'
```
# how to use requirements as code
Here's what you need to do as a developer:
@@ -146,7 +146,7 @@ But you can also publish events with `systemPublish()`, like so:
.on(String.class).system(this::displayNameString)
.build();
new ModelRunner().run(model)
Optional<Object> userName = new ModelRunner().run(model)
.reactTo(new EnterName("Joe"));
}
@@ -159,9 +159,11 @@ But you can also publish events with `systemPublish()`, like so:
}
```

As you can see, the publishing method has a command object as input parameter, and returns an event to be published (in this case, a String).
By default, as in the example, the model runner takes the returned event and sends it to its own `reactTo()` method.
This behavior can be overriden by specifying a custom event handler with `publishWith()`.
As you can see, `publishNameAsString()` takes a command object as input parameter, and returns an event to be published. In this case, a String.
By default, the model runner takes the returned event and publishes it to the model.
In the example, this will print "Welcome, Joe."

This behavior can be overriden by specifying a custom event handler on the ModelRunner with `publishWith()`.
For example, you can use `modelRunner.publishWith(queue::put)` to publish events to an event queue.

# documentation
@@ -1,6 +1,6 @@
allprojects{
group = 'org.requirementsascode'
version = '1.2'
version = '1.2.1'

apply plugin: 'java'
apply plugin: 'eclipse'
@@ -192,6 +192,7 @@ public void stop() {
public Optional<Object> reactTo(Object... messages) {
Objects.requireNonNull(messages);

latestPublishedEvent = null;
for (Object message : messages) {
handleMessage(message);
}
@@ -463,7 +463,7 @@ public void publishEnteredTextAsStringAfterMultipleEvents() {
.on(EntersNumber.class).system(new IgnoresIt<>())
.build();

String actualText = (String)modelRunner.run(model).reactTo(entersText(), entersNumber()).get();
String actualText = (String)modelRunner.run(model).reactTo(entersNumber(), entersText()).get();
assertEquals(TEXT, actualText);
}

@@ -501,4 +501,28 @@ public void dontPublishConstantTextAsStringWhenConditionFalse() {
Optional<Object> optionalEventObject = modelRunner.run(model).reactTo(entersNumber());
assertFalse(optionalEventObject.isPresent());
}

@Test
public void dontPublishFirstEnteredTextWhenReactToIsCalledTheSecondTime() {
Model model = modelBuilder.useCase(USE_CASE)
.user(EntersText.class).systemPublish(super::publishEnteredTextAsString)
.on(String.class).system(new IgnoresIt<>())
.build();

modelRunner.run(model).reactTo(entersText());
Optional<Object> publishedEvent = modelRunner.reactTo(TEXT);
assertFalse(publishedEvent.isPresent());
}

@Test
public void dontPublishOneOfTheEnteredTextsWhenReactToIsCalledTheSecondTime() {
Model model = modelBuilder.useCase(USE_CASE)
.user(EntersText.class).systemPublish(super::publishEnteredTextAsString)
.on(String.class).system(new IgnoresIt<>())
.build();

modelRunner.run(model).reactTo(entersNumber(), entersText());
Optional<Object> publishedEvent = modelRunner.reactTo(entersNumber(), entersNumber());
assertFalse(publishedEvent.isPresent());
}
}
@@ -0,0 +1,43 @@
package publish;

import java.util.Optional;

import org.requirementsascode.Model;
import org.requirementsascode.ModelRunner;

public class Publish {
public static void main(String[] args) {
new Publish().buildAndRunModel();
}

private void buildAndRunModel() {
Model model = Model.builder()
.on(EnterName.class).systemPublish(this::publishNameAsString)
.on(String.class).system(this::displayNameString)
.build();

Optional<Object> userName = new ModelRunner().run(model)
.reactTo(new EnterName("Joe"));
System.out.println("Your name is: " + userName.get() + ".");
}

private String publishNameAsString(EnterName enterName) {
return enterName.getUserName();
}

public void displayNameString(String nameString) {
System.out.println("Welcome, " + nameString + ".");
}

class EnterName {
private String userName;

public EnterName(String userName) {
this.userName = userName;
}

public String getUserName() {
return userName;
}
}
}
@@ -9,14 +9,14 @@ If you are using Maven, include the following in your POM:
<dependency>
<groupId>org.requirementsascode</groupId>
<artifactId>requirementsascodeextract</artifactId>
<version>1.2</version>
<version>1.2.1</version>
</dependency>
```

If you are using Gradle, include the following in your build.gradle:

```
compile 'org.requirementsascode:requirementsascodeextract:1.2'
compile 'org.requirementsascode:requirementsascodeextract:1.2.1'
```

This will put the following libraries on the classpath:

0 comments on commit db9a72a

Please sign in to comment.
You can’t perform that action at this time.