Added negative Test case to check that Invalid Vertices give a useful error
@@ -106,6 +106,25 @@ public class ProtobufTest {
BayesianNetwork net = reader.loadNetwork(new ByteArrayInputStream(writer.toByteArray()));
}
+ @Test
+ public void loadFailsIfInvalidVertexSpecified() throws IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Unknown Vertex Type Specified: made.up.vertex.NonExistentVertex");
+
+ KeanuSavedBayesNet.Vertex constantVertex = KeanuSavedBayesNet.Vertex.newBuilder()
+ .setId(KeanuSavedBayesNet.VertexID.newBuilder().setId("1"))
+ .setVertexType("made.up.vertex.NonExistentVertex")
+ .build();
+
+ KeanuSavedBayesNet.BayesianNetwork savedNet = KeanuSavedBayesNet.BayesianNetwork.newBuilder()
+ .addVertices(constantVertex).build();
+
+ ByteArrayOutputStream writer = new ByteArrayOutputStream();
+ savedNet.writeTo(writer);
+ ProtobufReader reader = new ProtobufReader();
+ BayesianNetwork readNet = reader.loadNetwork(new ByteArrayInputStream(writer.toByteArray()));
+ }
+
@Test
public void loadFailsIfNoConstantSpecified() throws IOException {
expectedException.expect(IllegalArgumentException.class);
@@ -113,7 +132,6 @@ public class ProtobufTest {
KeanuSavedBayesNet.Vertex constantVertex = KeanuSavedBayesNet.Vertex.newBuilder()
.setId(KeanuSavedBayesNet.VertexID.newBuilder().setId("1"))
- .setLabel("MU VERTEX")
.setVertexType(ConstantDoubleVertex.class.getCanonicalName())
.build();
@@ -127,7 +145,7 @@ public class ProtobufTest {
}
@Test
- public void loadFailsIfWrongTypeConstantSpecified() throws IOException {
+ public void loadFailsIfWrongArgumentTypeSpecified() throws IOException {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Incorrect Parameter Type specified. Got: "
+ "class io.improbable.keanu.tensor.intgr.ScalarIntegerTensor, "
@@ -135,7 +153,6 @@ public class ProtobufTest {
KeanuSavedBayesNet.Vertex constantVertex = KeanuSavedBayesNet.Vertex.newBuilder()
.setId(KeanuSavedBayesNet.VertexID.newBuilder().setId("1"))
- .setLabel("MU VERTEX")
.setVertexType(ConstantDoubleVertex.class.getCanonicalName())
.setConstantValue(KeanuSavedBayesNet.VertexValue.newBuilder()
.setIntVal(KeanuSavedBayesNet.IntegerTensor.newBuilder()
