Coverage Summary for Class: TestPropertyCheckConstraintDistributed (org.umlg.sqlg.test.topology.propertydefinition)
Class |
Method, %
|
Branch, %
|
Line, %
|
TestPropertyCheckConstraintDistributed |
100%
(3/3)
|
30%
(3/10)
|
91.2%
(31/34)
|
TestPropertyCheckConstraintDistributed$1 |
100%
(1/1)
|
100%
(2/2)
|
TestPropertyCheckConstraintDistributed$2 |
100%
(1/1)
|
100%
(2/2)
|
TestPropertyCheckConstraintDistributed$3 |
100%
(1/1)
|
100%
(2/2)
|
Total |
100%
(6/6)
|
30%
(3/10)
|
92.5%
(37/40)
|
package org.umlg.sqlg.test.topology.propertydefinition;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.umlg.sqlg.structure.Multiplicity;
import org.umlg.sqlg.structure.PropertyDefinition;
import org.umlg.sqlg.structure.PropertyType;
import org.umlg.sqlg.structure.SqlgGraph;
import org.umlg.sqlg.structure.topology.Schema;
import org.umlg.sqlg.structure.topology.VertexLabel;
import org.umlg.sqlg.test.BaseTest;
import java.net.URL;
import java.util.HashMap;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("DuplicatedCode")
public class TestPropertyCheckConstraintDistributed extends BaseTest {
@BeforeClass
public static void beforeClass() {
URL sqlProperties = Thread.currentThread().getContextClassLoader().getResource("sqlg.properties");
try {
Configurations configs = new Configurations();
configuration = configs.properties(sqlProperties);
Assume.assumeTrue(isPostgres());
configuration.addProperty("distributed", true);
if (!configuration.containsKey("jdbc.url"))
throw new IllegalArgumentException(String.format("SqlGraph configuration requires that the %s be set", "jdbc.url"));
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
}
@Test
public void testCheckConstraintOnVertexLabel() throws InterruptedException {
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
Schema publicSchema = this.sqlgGraph.getTopology().getPublicSchema();
VertexLabel aVertexLabel = publicSchema.ensureVertexLabelExist("A", new HashMap<>() {{
put("name", PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1), null, "(name <> 'a')"));
}});
VertexLabel bVertexLabel = publicSchema.ensureVertexLabelExist("B", new HashMap<>() {{
put("name", PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1), null, "(name <> 'a')"));
}});
aVertexLabel.ensureEdgeLabelExist("ab", bVertexLabel, new HashMap<>() {{
put("name", PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1), null, "(name <> 'a')"));
}});
this.sqlgGraph.tx().commit();
Thread.sleep(3_000);
assertEquals(this.sqlgGraph.getTopology(), sqlgGraph1.getTopology());
Assert.assertEquals(
PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1), null, "(name <> 'a')"),
sqlgGraph1.getTopology().getPublicSchema().getVertexLabel("A").orElseThrow().getProperty("name").orElseThrow().getPropertyDefinition()
);
}
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
assertEquals(this.sqlgGraph.getTopology(), sqlgGraph1.getTopology());
Assert.assertEquals(
PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1), null, "(name <> 'a')"),
sqlgGraph1.getTopology().getPublicSchema().getVertexLabel("A").orElseThrow().getProperty("name").orElseThrow().getPropertyDefinition()
);
Assert.assertEquals(
PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1), null, "(name <> 'a')"),
sqlgGraph1.getTopology().getPublicSchema().getVertexLabel("B").orElseThrow().getProperty("name").orElseThrow().getPropertyDefinition()
);
Assert.assertEquals(
PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1), null, "(name <> 'a')"),
sqlgGraph1.getTopology().getPublicSchema().getEdgeLabel("ab").orElseThrow().getProperty("name").orElseThrow().getPropertyDefinition()
);
}
}
}