use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class CatalogCategoryTest method testFindByLabel.
@Test
public void testFindByLabel() throws Exception {
_logger.info("Starting FindByLabel test");
ModelClient modelClient = getModelClient();
CatalogCategory root = createWithLabel("root");
CatalogCategory catalogCategory = createWithLabel("foo");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
catalogCategory = createWithLabel("barOne");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
catalogCategory = createWithLabel("barTwo");
catalogCategory.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(catalogCategory);
modelClient.save(root);
List<CatalogCategory> results = modelClient.catalogCategories().findByLabel(DEFAULT_TENANT, "fo");
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = modelClient.catalogCategories().findByLabel(DEFAULT_TENANT, "bar");
Assert.assertNotNull(results);
Assert.assertEquals(2, results.size());
results = modelClient.catalogCategories().findByLabel(DEFAULT_TENANT, "foobar");
Assert.assertNotNull(results);
Assert.assertEquals(0, results.size());
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class CatalogServiceTest method testFindByCatalogCategory.
@Test
public void testFindByCatalogCategory() {
_logger.info("Starting FindByCatalogCategory test");
ModelClient modelClient = getModelClient();
CatalogCategory root = createCategoryWithLabel("rooty");
modelClient.save(root);
CatalogService s1 = createWithLabel("s1");
s1.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(s1);
CatalogCategory c1 = createCategoryWithLabel("asdf");
c1.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(c1);
CatalogService s2 = createWithLabel("s2");
s2.setCatalogCategoryId(new NamedURI(c1.getId(), c1.getLabel()));
modelClient.save(s2);
CatalogService s3 = createWithLabel("s3");
s3.setCatalogCategoryId(new NamedURI(c1.getId(), c1.getLabel()));
modelClient.save(s3);
CatalogCategory c2 = createCategoryWithLabel("asdf2");
c2.setCatalogCategoryId(new NamedURI(root.getId(), root.getLabel()));
modelClient.save(c2);
CatalogService s4 = createWithLabel("s4");
s4.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
modelClient.save(s4);
CatalogService s5 = createWithLabel("s5");
s5.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
modelClient.save(s5);
CatalogService s6 = createWithLabel("s6");
s6.setCatalogCategoryId(new NamedURI(c2.getId(), c2.getLabel()));
modelClient.save(s6);
List<CatalogService> results = modelClient.catalogServices().findByCatalogCategory(root.getId());
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
results = modelClient.catalogServices().findByCatalogCategory(c1.getId());
Assert.assertNotNull(results);
Assert.assertEquals(2, results.size());
results = modelClient.catalogServices().findByCatalogCategory(c2.getId());
Assert.assertNotNull(results);
Assert.assertEquals(3, results.size());
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class OrderTest method testFindByOrderStatus.
@Test
public void testFindByOrderStatus() {
_logger.info("Starting findByOrderStatus test");
ModelClient modelClient = getModelClient();
Order o1 = create("t1", OrderStatus.APPROVAL);
modelClient.save(o1);
Order o2 = create("t1", OrderStatus.APPROVAL);
modelClient.save(o2);
Order o3 = create("t1", OrderStatus.PENDING);
modelClient.save(o3);
Order o4 = create("t2", OrderStatus.APPROVAL);
modelClient.save(o4);
Order o5 = create("t2", OrderStatus.PENDING);
modelClient.save(o5);
Order o6 = create("t3", OrderStatus.PENDING);
modelClient.save(o6);
List<Order> orders = modelClient.orders().findByOrderStatus("t1", OrderStatus.APPROVAL);
Assert.assertNotNull(orders);
Assert.assertEquals(2, orders.size());
orders = modelClient.orders().findByOrderStatus("t1", OrderStatus.PENDING);
Assert.assertNotNull(orders);
Assert.assertEquals(1, orders.size());
orders = modelClient.orders().findByOrderStatus("t1", OrderStatus.SCHEDULED);
Assert.assertNotNull(orders);
Assert.assertEquals(0, orders.size());
orders = modelClient.orders().findByOrderStatus("t2", OrderStatus.APPROVAL);
Assert.assertNotNull(orders);
Assert.assertEquals(1, orders.size());
orders = modelClient.orders().findByOrderStatus("t2", OrderStatus.PENDING);
Assert.assertNotNull(orders);
Assert.assertEquals(1, orders.size());
orders = modelClient.orders().findByOrderStatus("t2", OrderStatus.SCHEDULED);
Assert.assertNotNull(orders);
Assert.assertEquals(0, orders.size());
orders = modelClient.orders().findByOrderStatus("t3", OrderStatus.APPROVAL);
Assert.assertNotNull(orders);
Assert.assertEquals(0, orders.size());
orders = modelClient.orders().findByOrderStatus("t3", OrderStatus.PENDING);
Assert.assertNotNull(orders);
Assert.assertEquals(1, orders.size());
orders = modelClient.orders().findByOrderStatus("t3", OrderStatus.SCHEDULED);
Assert.assertNotNull(orders);
Assert.assertEquals(0, orders.size());
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class OrderTest method testSaveOrderAndExecutionState.
@Test
public void testSaveOrderAndExecutionState() throws Exception {
_logger.info("Starting save Order and Execution State test");
ModelClient modelClient = getModelClient();
Order model = new Order();
model.setLabel("foo");
URI catalogServiceId = new URI("urn:CatalogService:1");
model.setCatalogServiceId(catalogServiceId);
Date d = new Date();
model.setDateCompleted(d);
model.setMessage("my message");
model.setOrderStatus(OrderStatus.CANCELLED.name());
model.setSubmittedByUserId("urn:User:1");
model.setSummary("my summary");
ExecutionState executionState = new ExecutionState();
executionState.setExecutionStatus(ExecutionStatus.NONE.name());
executionState.setStartDate(d);
executionState.setCurrentTask("my task");
modelClient.save(executionState);
model.setExecutionStateId(executionState.getId());
ExecutionLog executionLog1 = new ExecutionLog();
executionLog1.setLevel(LogLevel.DEBUG.name());
executionLog1.setMessage("my message 1");
modelClient.save(executionLog1);
executionState.addExecutionLog(executionLog1);
ExecutionLog executionLog2 = new ExecutionLog();
executionLog2.setLevel(LogLevel.ERROR.name());
executionLog2.setMessage("my message 2");
modelClient.save(executionLog2);
executionState.addExecutionLog(executionLog2);
modelClient.save(executionState);
save(model);
Order order = findById(model.getId());
Assert.assertNotNull(order);
Assert.assertEquals("foo", order.getLabel());
Assert.assertEquals(catalogServiceId, order.getCatalogServiceId());
Assert.assertEquals(d, order.getDateCompleted());
Assert.assertEquals(executionState.getId(), order.getExecutionStateId());
Assert.assertEquals("my message", order.getMessage());
Assert.assertEquals(OrderStatus.CANCELLED.name(), order.getOrderStatus());
Assert.assertEquals("urn:User:1", order.getSubmittedByUserId());
Assert.assertEquals("my summary", order.getSummary());
ExecutionState exeState = modelClient.executionStates().findById(order.getExecutionStateId());
Assert.assertNotNull(exeState);
Assert.assertEquals(ExecutionStatus.NONE.name(), exeState.getExecutionStatus());
Assert.assertEquals(d, exeState.getStartDate());
Assert.assertEquals(2, exeState.getLogIds().size());
List<ExecutionLog> logs = modelClient.executionLogs().findByIds(exeState.getLogIds());
Assert.assertNotNull(logs);
Assert.assertEquals(2, logs.size());
}
use of com.emc.sa.model.dao.ModelClient in project coprhd-controller by CoprHD.
the class VirtualMachineTest method testFindByDatacenter.
@Test
public void testFindByDatacenter() throws Exception {
_logger.info("Starting findByDatacenter test");
ModelClient modelClient = getModelClient();
Vcenter v2 = createVCenterWithLabel("v2");
modelClient.save(v2);
VcenterDataCenter dc2 = createDatacenterWithLabel("dc2");
dc2.setVcenter(v2.getId());
modelClient.save(dc2);
VirtualMachine vm1 = createWithLabel("vm1");
vm1.setDatacenterId(new NamedURI(dc2.getId(), dc2.getLabel()));
modelClient.save(vm1);
VcenterDataCenter dc3 = createDatacenterWithLabel("dc3");
dc3.setVcenter(v2.getId());
modelClient.save(dc3);
VirtualMachine vm2 = createWithLabel("vm2");
vm2.setDatacenterId(new NamedURI(dc3.getId(), dc3.getLabel()));
modelClient.save(vm2);
VirtualMachine vm3 = createWithLabel("vm3");
vm3.setDatacenterId(new NamedURI(dc3.getId(), dc3.getLabel()));
modelClient.save(vm3);
List<VirtualMachine> virtualMachines = modelClient.virtualMachines().findByDatacenter(dc2.getId());
Assert.assertNotNull(virtualMachines);
Assert.assertEquals(1, virtualMachines.size());
virtualMachines = modelClient.virtualMachines().findByDatacenter(dc3.getId());
Assert.assertNotNull(virtualMachines);
Assert.assertEquals(2, virtualMachines.size());
}
Aggregations