Skip to content

Commit a0590fa

Browse files
committed
Added tests for GraphAccessor
1 parent 60f67ef commit a0590fa

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2018 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
******************************************************************************/
19+
20+
package org.eclipse.microprofile.reactive.streams.tck;
21+
22+
import org.eclipse.microprofile.reactive.streams.GraphAccessor;
23+
import org.eclipse.microprofile.reactive.streams.ReactiveStreams;
24+
import org.eclipse.microprofile.reactive.streams.spi.Graph;
25+
import org.eclipse.microprofile.reactive.streams.spi.Stage;
26+
import org.testng.annotations.Test;
27+
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
31+
import static org.testng.Assert.assertEquals;
32+
import static org.testng.Assert.assertTrue;
33+
34+
/**
35+
* Test for the GraphAccessor class.
36+
*
37+
* This does not need an implementation of the engine to verify it.
38+
*/
39+
public class GraphAccessorVerification {
40+
41+
@Test
42+
public void buildGraphForPublisherShouldProduceTheCorrectGraph() {
43+
Graph graph = GraphAccessor.buildGraphFor(ReactiveStreams.of(1).map(i -> i * 2));
44+
assertEquals(2, graph.getStages().size());
45+
List<Stage> stages = new ArrayList<>(graph.getStages());
46+
assertInstanceOf(stages.get(0), Stage.Of.class);
47+
assertInstanceOf(stages.get(1), Stage.Map.class);
48+
}
49+
50+
@Test
51+
public void buildGraphForProcessorShouldProduceTheCorrectGraph() {
52+
Graph graph = GraphAccessor.buildGraphFor(ReactiveStreams.<Integer>builder().filter(i -> i > 10).takeWhile(i -> i < 20));
53+
assertEquals(2, graph.getStages().size());
54+
List<Stage> stages = new ArrayList<>(graph.getStages());
55+
assertInstanceOf(stages.get(0), Stage.Filter.class);
56+
assertInstanceOf(stages.get(1), Stage.TakeWhile.class);
57+
}
58+
59+
@Test
60+
public void buildGraphForSubscriberShouldProduceTheCorrectGraph() {
61+
Graph graph = GraphAccessor.buildGraphFor(ReactiveStreams.<Integer>builder().limit(10).toList());
62+
assertEquals(2, graph.getStages().size());
63+
List<Stage> stages = new ArrayList<>(graph.getStages());
64+
assertInstanceOf(stages.get(0), Stage.Limit.class);
65+
assertInstanceOf(stages.get(1), Stage.Collect.class);
66+
}
67+
68+
@Test
69+
public void buildGraphForCompletionRunnerShouldProduceTheCorrectGraph() {
70+
Graph graph = GraphAccessor.buildGraphFor(ReactiveStreams.failed(new Exception()).distinct().cancel());
71+
assertEquals(3, graph.getStages().size());
72+
List<Stage> stages = new ArrayList<>(graph.getStages());
73+
assertInstanceOf(stages.get(0), Stage.Failed.class);
74+
assertInstanceOf(stages.get(1), Stage.Distinct.class);
75+
assertEquals(Stage.Cancel.INSTANCE, stages.get(2));
76+
}
77+
78+
private static void assertInstanceOf(Object obj, Class<?> clazz) {
79+
assertTrue(clazz.isInstance(obj), obj + " is not a an instance of " + clazz);
80+
}
81+
}

streams/tck/src/main/java/org/eclipse/microprofile/reactive/streams/tck/ReactiveStreamsTck.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public Object[] allTests() {
113113
allTests.addAll(stageVerification.reactiveStreamsTckVerifiers());
114114
}
115115

116+
// Add tests that aren't dependent on the dependencies.
117+
allTests.add(new GraphAccessorVerification());
118+
116119
return allTests.stream().filter(this::isEnabled).toArray();
117120
}
118121

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2018 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
******************************************************************************/
19+
20+
package org.eclipse.microprofile.reactive.streams.tck;
21+
22+
import org.testng.annotations.Factory;
23+
24+
/**
25+
* This runs any tests that don't require an implementation to run.
26+
*/
27+
public class TckTest {
28+
29+
@Factory
30+
public Object[] independentTests() {
31+
return new Object[] {
32+
new GraphAccessorVerification()
33+
};
34+
}
35+
}

0 commit comments

Comments
 (0)