Search in sources :

Example 6 with ModelView

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);
}
Also used : ModelView(org.btrplace.model.view.ModelView) Test(org.testng.annotations.Test)

Example 7 with ModelView

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;
}
Also used : ModelView(org.btrplace.model.view.ModelView)

Example 8 with ModelView

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();
}
Also used : ModelView(org.btrplace.model.view.ModelView)

Example 9 with ModelView

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());
}
Also used : ModelView(org.btrplace.model.view.ModelView) Test(org.testng.annotations.Test)

Example 10 with ModelView

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);
}
Also used : ModelView(org.btrplace.model.view.ModelView) Test(org.testng.annotations.Test)

Aggregations

ModelView (org.btrplace.model.view.ModelView)11 Test (org.testng.annotations.Test)6 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringJoiner (java.util.StringJoiner)1 JSONArray (net.minidev.json.JSONArray)1 JSONObject (net.minidev.json.JSONObject)1