Skip to content

Commit f322afc

Browse files
committed
Added some simple tests
1 parent ffef5ef commit f322afc

File tree

5 files changed

+118
-24
lines changed

5 files changed

+118
-24
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.eigr.spawn;
2+
3+
import io.eigr.spawn.api.actors.annotations.NamedActor;
4+
import io.eigr.spawn.internal.Entity;
5+
import io.eigr.spawn.test.actors.JoeActor;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class EntityTest {
11+
12+
@Test
13+
public void testEntityBuilder() {
14+
NamedActor annotation = JoeActor.class.getAnnotation(NamedActor.class);
15+
final Entity entity = Entity.fromAnnotationToEntity(JoeActor.class, annotation, null, null);
16+
assertEquals(1, entity.getActions().values().size());
17+
assertEquals(0, entity.getTimerActions().values().size());
18+
assertEquals("test.channel", entity.getChannel());
19+
}
20+
}
Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
11
package io.eigr.spawn;
22

3-
import io.eigr.spawn.api.Spawn;
4-
import io.eigr.spawn.api.actors.ActorRef;
5-
import junit.framework.Test;
6-
import junit.framework.TestCase;
7-
import junit.framework.TestSuite;
3+
import org.junit.Test;
84

9-
public class SpawnTest
10-
extends TestCase {
11-
/**
12-
* Create the test case
13-
*
14-
* @param testName name of the test case
15-
*/
16-
public SpawnTest(String testName) {
17-
super(testName);
18-
}
19-
20-
/**
21-
* @return the suite of tests being tested
22-
*/
23-
public static Test suite() {
24-
return new TestSuite(SpawnTest.class);
25-
}
5+
import static org.junit.Assert.assertTrue;
266

7+
public class SpawnTest {
8+
@Test
279
public void testApp() throws Exception {
28-
Spawn spawn = new Spawn.SpawnSystem().build();
29-
ActorRef actor = spawn.createActorRef("spawn-system", "joe");
3010
assertTrue(true);
3111
}
3212
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.eigr.spawn;
2+
3+
import io.eigr.functions.protocol.Protocol;
4+
import io.eigr.spawn.api.actors.ActorRef;
5+
import io.eigr.spawn.api.actors.workflows.Broadcast;
6+
import io.eigr.spawn.api.actors.workflows.Forward;
7+
import io.eigr.spawn.api.actors.workflows.Pipe;
8+
import io.eigr.spawn.api.actors.workflows.SideEffect;
9+
import io.eigr.spawn.java.test.domain.Actor;
10+
import org.junit.Test;
11+
12+
import static org.junit.Assert.*;
13+
14+
public class WorkflowTest {
15+
16+
@Test
17+
public void testBroadcastBuilder() {
18+
Broadcast broadcast = Broadcast.to("test.channel", "hi", Actor.Request.getDefaultInstance());
19+
final Protocol.Broadcast protocolBroadcast = broadcast.build();
20+
assertEquals("hi", protocolBroadcast.getActionName());
21+
assertEquals("test.channel", protocolBroadcast.getChannelGroup());
22+
assertNotNull(protocolBroadcast.getValue());
23+
}
24+
25+
@Test
26+
public void testForwardBuilder() throws Exception {
27+
Forward forward = Forward.to(ActorRef.of(null, "spawn-system", "joe"), "hi");
28+
final Protocol.Forward protocolForward = forward.build();
29+
assertEquals("hi", protocolForward.getActionName());
30+
assertEquals("joe", protocolForward.getActor());
31+
}
32+
33+
@Test
34+
public void testPipeBuilder() throws Exception {
35+
Pipe pipe = Pipe.to(ActorRef.of(null, "spawn-system", "joe"), "hi");
36+
final Protocol.Pipe protocolPipe = pipe.build();
37+
assertEquals("hi", protocolPipe.getActionName());
38+
assertEquals("joe", protocolPipe.getActor());
39+
}
40+
41+
@Test
42+
public void testSideEffectBuilder() throws Exception {
43+
SideEffect effect = SideEffect.to(ActorRef.of(null, "spawn-system", "joe"), "hi", Actor.Request.getDefaultInstance());
44+
final Protocol.SideEffect protocolSideEffect = effect.build();
45+
Protocol.InvocationRequest request = protocolSideEffect.getRequest();
46+
assertNotNull(request);
47+
assertEquals("hi", request.getActionName());
48+
assertEquals("joe", request.getActor().getId().getName());
49+
}
50+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.eigr.spawn.test.actors;
2+
3+
import io.eigr.spawn.api.Value;
4+
import io.eigr.spawn.api.actors.ActorContext;
5+
import io.eigr.spawn.api.actors.annotations.Action;
6+
import io.eigr.spawn.api.actors.annotations.NamedActor;
7+
import io.eigr.spawn.java.test.domain.Actor;
8+
9+
@NamedActor(name = "test_joe", stateful = true, stateType = Actor.State.class, channel = "test.channel")
10+
public class JoeActor {
11+
@Action(inputType = Actor.Request.class)
12+
public Value setLanguage(Actor.Request msg, ActorContext<Actor.State> context) {
13+
if (context.getState().isPresent()) {
14+
}
15+
16+
return Value.at()
17+
.response(Actor.Reply.newBuilder()
18+
.setResponse("Hello From Java")
19+
.build())
20+
.state(updateState("java"))
21+
.reply();
22+
}
23+
24+
private Actor.State updateState(String language) {
25+
return Actor.State.newBuilder()
26+
.addLanguages(language)
27+
.build();
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
package domain;
3+
option java_package = "io.eigr.spawn.java.test.domain";
4+
5+
message State {
6+
repeated string languages = 1;
7+
}
8+
9+
message Request {
10+
string language = 1;
11+
}
12+
13+
message Reply {
14+
string response = 1;
15+
}

0 commit comments

Comments
 (0)