Search in sources :

Example 1 with DefaultTemplateFactory

use of org.btrplace.btrpsl.template.DefaultTemplateFactory in project scheduler by btrplace.

the class ScriptBuilderTest method testTemplateReassignment.

@Test(expectedExceptions = { ScriptBuilderException.class })
public void testTemplateReassignment() throws ScriptBuilderException {
    Model mo = new DefaultModel();
    VM v = mo.newVM();
    VM v2 = mo.newVM();
    mo.getMapping().addReadyVM(v);
    mo.getMapping().addReadyVM(v2);
    mo.getAttributes().put(v, "template", "t1");
    mo.getAttributes().put(v2, "template", "tiny");
    NamingService<Node> nsNodes = NamingService.newNodeNS();
    NamingService<VM> nsVMs = NamingService.newVMNS();
    mo.attach(nsNodes);
    mo.attach(nsVMs);
    nsVMs.register(v, "foo.VM1");
    nsVMs.register(v2, "foo.VM2");
    ScriptBuilder b = new ScriptBuilder(100, mo);
    b.setTemplateFactory(new DefaultTemplateFactory(nsNodes, nsVMs, mo));
    b.getTemplateFactory().register(new DefaultTemplateFactoryTest.MockVMTemplate("tiny"));
    b.getTemplateFactory().register(new DefaultTemplateFactoryTest.MockVMTemplate("t1"));
    ErrorReporter r;
    try {
        Script scr = b.build("namespace foo; VM[1,2] : tiny;");
        System.out.println(scr.getVMs());
    } catch (ScriptBuilderException ex) {
        System.out.println(ex);
        r = ex.getErrorReporter();
        Assert.assertEquals(r.getErrors().size(), 1);
        throw ex;
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest) Node(org.btrplace.model.Node) DefaultTemplateFactory(org.btrplace.btrpsl.template.DefaultTemplateFactory) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest)

Aggregations

DefaultTemplateFactory (org.btrplace.btrpsl.template.DefaultTemplateFactory)1 DefaultTemplateFactoryTest (org.btrplace.btrpsl.template.DefaultTemplateFactoryTest)1 DefaultModel (org.btrplace.model.DefaultModel)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 VM (org.btrplace.model.VM)1 Test (org.testng.annotations.Test)1