use of org.btrplace.model.view.ModelView in project scheduler by btrplace.
the class DefaultModelTest method testClone.
@Test(dependsOnMethods = { "testInstantiate", "testEqualsAndHashCode", "testAttachView", "testDetachView", "testAttributes" })
public void testClone() {
Model i = new DefaultModel();
ModelView v1 = mock(ModelView.class);
when(v1.getIdentifier()).thenReturn("foo");
when(v1.copy()).thenReturn(v1);
ModelView v2 = mock(ModelView.class);
when(v2.getIdentifier()).thenReturn("bar");
when(v2.copy()).thenReturn(v2);
VM u = i.newVM();
i.getAttributes().put(u, "foo", false);
i.attach(v1);
i.attach(v2);
Model c = i.copy();
Assert.assertEquals(c.hashCode(), i.hashCode());
Assert.assertTrue(c.equals(i));
i.detach(v1);
Assert.assertEquals(c.getView("foo"), v1);
c.detach(v1);
Assert.assertEquals(i.getView("bar"), v2);
Assert.assertEquals(c.getAttributes().get(u, "foo"), Boolean.FALSE);
}
use of org.btrplace.model.view.ModelView in project scheduler by btrplace.
the class SubModel method copy.
/**
* Clone this model using a {@link DefaultModel}.
*
* @return a mutable clone
*/
@Override
public Model copy() {
DefaultModel m = new DefaultModel(eb.copy());
MappingUtils.fill(sm, m.getMapping());
for (ModelView rc : parent.getViews()) {
m.attach(rc.copy());
}
m.setAttributes(this.getAttributes().copy());
return m;
}
use of org.btrplace.model.view.ModelView in project scheduler by btrplace.
the class SubModel method toString.
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("Mapping:\n");
b.append(getMapping());
b.append("\nAttributes:\n");
b.append(getAttributes());
b.append("\nViews:\n");
for (ModelView entry : parent.getViews()) {
b.append(entry.getIdentifier()).append(": ");
b.append(entry.toString()).append("\n");
}
return b.toString();
}
use of org.btrplace.model.view.ModelView in project scheduler by btrplace.
the class DefaultModelTest method testEqualsAndHashCode.
@Test(dependsOnMethods = { "testAttachView", "testInstantiate" })
public void testEqualsAndHashCode() {
Model i = new DefaultModel();
ModelView rc = mock(ModelView.class);
when(rc.getIdentifier()).thenReturn("foo");
ModelView b = mock(ModelView.class);
when(b.getIdentifier()).thenReturn("bar");
when(b.copy()).thenReturn(b);
when(rc.copy()).thenReturn(rc);
i.attach(rc);
i.attach(b);
VM vm = i.newVM();
i.getAttributes().put(vm, "foo", true);
Model j = i.copy();
j.getAttributes().put(vm, "foo", true);
j.attach(rc);
j.attach(b);
Assert.assertTrue(i.equals(i));
Assert.assertEquals(i.hashCode(), j.hashCode());
j.detach(rc);
Assert.assertFalse(i.equals(j));
j.attach(rc);
j.getMapping().addReadyVM(j.newVM());
Assert.assertFalse(i.equals(j));
j.getAttributes().put(vm, "bar", false);
Assert.assertFalse(i.equals(j));
j.setAttributes(i.getAttributes());
}
use of org.btrplace.model.view.ModelView in project scheduler by btrplace.
the class DefaultModelTest method testAttachView.
@Test
public void testAttachView() {
Model i = new DefaultModel();
ModelView v = mock(ModelView.class);
when(v.getIdentifier()).thenReturn("mock");
Assert.assertTrue(i.attach(v));
Assert.assertEquals(i.getViews().size(), 1);
Assert.assertEquals(i.getView("mock"), v);
Assert.assertEquals(i.getView("bar"), null);
Assert.assertFalse(i.attach(v));
Assert.assertEquals(i.getViews().size(), 1);
Assert.assertEquals(i.getView("mock"), v);
ModelView v2 = mock(ModelView.class);
when(v2.getIdentifier()).thenReturn("bar");
Assert.assertTrue(i.attach(v2));
Assert.assertEquals(i.getViews().size(), 2);
Assert.assertEquals(i.getView("bar"), v2);
}
Aggregations