use of org.btrplace.btrpsl.includes.PathBasedIncludes in project scheduler by btrplace.
the class ExamplesTest method testExample.
@Test
public void testExample() throws ScriptBuilderException {
// Set the environment
Model mo = new DefaultModel();
// Make the builder and add the sources location to the include path
ScriptBuilder scrBuilder = new ScriptBuilder(mo);
((PathBasedIncludes) scrBuilder.getIncludes()).addPath(new File("src/test/resources/org/btrplace/btrpsl/examples"));
// Parse myApp.btrp
Script myApp = scrBuilder.build(new File("src/test/resources/org/btrplace/btrpsl/examples/myApp.btrp"));
Assert.assertEquals(myApp.getVMs().size(), 24);
Assert.assertEquals(myApp.getNodes().size(), 0);
Assert.assertEquals(myApp.getConstraints().size(), 5);
// Check the resulting mapping
Mapping map = mo.getMapping();
Assert.assertEquals(map.getReadyVMs().size(), 24);
Assert.assertEquals(map.getOfflineNodes().size(), 251);
}
use of org.btrplace.btrpsl.includes.PathBasedIncludes in project scheduler by btrplace.
the class ScriptBuilderTest method textExportRestrictions.
public void textExportRestrictions() {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
PathBasedIncludes includes = new PathBasedIncludes(b);
includes.addPath(new File(RC_ROOT));
b.setIncludes(includes);
try {
b.build("namespace zog; import testExport; for $n in $testExport.racks { }");
b.build("namespace toto; import testExport; for $n in $testExport.nodes { }");
b.build("namespace testExport.bla; import testExport; for $n in $testExport.nodes { } for $r in $testExport.racks {}");
b.build("namespace sysadmin; import testExport; for $n in $testExport.nodes { } for $r in $testExport.racks {} for $n in $testExport {}");
} catch (ScriptBuilderException x) {
Assert.fail(x.getMessage(), x);
}
// Now, with bad restrictions
try {
b.build("namespace zog; import testExport; for $n in $nodes { }");
Assert.fail();
} catch (@SuppressWarnings("unused") ScriptBuilderException x) {
}
try {
b.build("namespace sysadmin.foo; import testExport; for $n in $nodes { }");
Assert.fail();
} catch (@SuppressWarnings("unused") ScriptBuilderException x) {
}
try {
b.build("namespace sysadmin.foo; import testExport; for $v in $testExport { }");
Assert.fail();
} catch (@SuppressWarnings("unused") ScriptBuilderException x) {
}
}
use of org.btrplace.btrpsl.includes.PathBasedIncludes in project scheduler by btrplace.
the class ScriptBuilderTest method testDependencies.
public void testDependencies() throws Exception {
//
// a
// |- b
// \– c
// \-d
//
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
PathBasedIncludes includes = new PathBasedIncludes(b);
includes.addPath(new File(RC_ROOT + "deps"));
b.setIncludes(includes);
Script v = b.build(new File(RC_ROOT + "deps/a.btrp"));
Assert.assertEquals(v.getDependencies().size(), 2);
for (Script s : v.getDependencies()) {
if (s.getlocalName().equals("c")) {
for (Script s2 : s.getDependencies()) {
Assert.assertTrue(s2.getlocalName().equals("foo") || s2.getlocalName().equals("bar"));
}
} else if (s.getlocalName().equals("b")) {
for (Script s2 : s.getDependencies()) {
Assert.assertTrue(s2.getlocalName().equals("toto") || s2.getlocalName().equals("titi"));
}
} else {
Assert.fail();
}
}
System.out.println(v.prettyDependencies());
}
Aggregations