use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class VirtualMachineTest method testPersistObject.
@Test
public void testPersistObject() throws Exception {
_logger.info("Starting persist VirtualMachine test");
ModelClient modelClient = getModelClient();
VirtualMachine model = new VirtualMachine();
model.setId(URIUtil.createId(VirtualMachine.class));
model.setLabel("foo");
model.setRunning(false);
model.setTemplate(true);
URI datacenterUri = URIUtil.createId(VcenterDataCenter.class);
NamedURI datacenterId = new NamedURI(datacenterUri, "dc1");
model.setDatacenterId(datacenterId);
modelClient.save(model);
model = modelClient.virtualMachines().findById(model.getId());
Assert.assertNotNull(model);
Assert.assertEquals("foo", model.getLabel());
Assert.assertEquals(false, model.getRunning());
Assert.assertEquals(true, model.getTemplate());
Assert.assertEquals(datacenterId, model.getDatacenterId());
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class DBClientTestBase method createModelClient.
protected static ModelClient createModelClient() {
BourneDbClient bourneDbClient = new BourneDbClient();
bourneDbClient.setDbClient(createDbClient());
bourneDbClient.init();
ModelClient modelClient = new ModelClient(bourneDbClient);
return modelClient;
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class CatalogCategoryTest method testReparentCategory.
@Test
public void testReparentCategory() throws Exception {
ModelClient modelClient = getModelClient();
CatalogCategory parent1 = createCategory("Parent1");
modelClient.save(parent1);
CatalogCategory parent2 = createCategory("Parent2");
modelClient.save(parent2);
CatalogCategory child = createCategory("Child");
setParent(parent1, child);
modelClient.save(child);
List<CatalogCategory> parent1Children = modelClient.catalogCategories().findSubCatalogCategories(parent1.getId());
Assert.assertEquals(1, parent1Children.size());
Assert.assertEquals(child.getId(), parent1Children.get(0).getId());
List<CatalogCategory> parent2Children = modelClient.catalogCategories().findSubCatalogCategories(parent2.getId());
Assert.assertEquals(0, parent2Children.size());
setParent(parent2, child);
modelClient.save(child);
parent1Children = modelClient.catalogCategories().findSubCatalogCategories(parent1.getId());
Assert.assertEquals(0, parent1Children.size());
parent2Children = modelClient.catalogCategories().findSubCatalogCategories(parent2.getId());
Assert.assertEquals(1, parent2Children.size());
Assert.assertEquals(child.getId(), parent2Children.get(0).getId());
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class CatalogCategoryTest method testFindSubCatalogCategories.
@Test
public void testFindSubCatalogCategories() {
_logger.info("Starting FindByLabel test");
ModelClient modelClient = getModelClient();
CatalogCategory root = createWithLabel("rooty");
CatalogCategory catalogCategory = createWithLabel("asdf");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
catalogCategory = createWithLabel("asdf2");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
catalogCategory = createWithLabel("asdf3");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
modelClient.save(root);
List<CatalogCategory> subCatalogCategories = modelClient.catalogCategories().findSubCatalogCategories(root.getId());
Assert.assertNotNull(subCatalogCategories);
Assert.assertEquals(3, subCatalogCategories.size());
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class CatalogServiceTest method testReparent.
@Test
public void testReparent() throws Exception {
_logger.info("Starting reparent CatalogService test");
ModelClient modelClient = getModelClient();
CatalogCategory parent1 = createCategoryWithLabel("Parent 1");
modelClient.save(parent1);
CatalogCategory parent2 = createCategoryWithLabel("Parent 2");
modelClient.save(parent2);
CatalogService service = createWithLabel("Service");
setParent(parent1, service);
modelClient.save(service);
List<CatalogService> parent1Children = modelClient.catalogServices().findByCatalogCategory(parent1.getId());
Assert.assertEquals(1, parent1Children.size());
Assert.assertEquals(service.getId(), parent1Children.get(0).getId());
List<CatalogService> parent2Children = modelClient.catalogServices().findByCatalogCategory(parent2.getId());
Assert.assertEquals(0, parent2Children.size());
setParent(parent2, service);
modelClient.save(service);
parent1Children = modelClient.catalogServices().findByCatalogCategory(parent1.getId());
Assert.assertEquals(0, parent1Children.size());
parent2Children = modelClient.catalogServices().findByCatalogCategory(parent2.getId());
Assert.assertEquals(1, parent2Children.size());
Assert.assertEquals(service.getId(), parent2Children.get(0).getId());
}
Aggregations