Search in sources :

Example 6 with ModelClient

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());
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ModelClient(com.emc.sa.model.dao.ModelClient) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

Example 7 with ModelClient

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());
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ModelClient(com.emc.sa.model.dao.ModelClient) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

Example 8 with ModelClient

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());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ModelClient(com.emc.sa.model.dao.ModelClient) Test(org.junit.Test) BaseModelTest(com.emc.sa.model.BaseModelTest)

Example 9 with ModelClient

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());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState) ExecutionLog(com.emc.storageos.db.client.model.uimodels.ExecutionLog) ModelClient(com.emc.sa.model.dao.ModelClient) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test) BaseModelTest(com.emc.sa.model.BaseModelTest)

Example 10 with ModelClient

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());
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) NamedURI(com.emc.storageos.db.client.model.NamedURI) ModelClient(com.emc.sa.model.dao.ModelClient) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VirtualMachine(com.emc.storageos.db.client.model.uimodels.VirtualMachine) Test(org.junit.Test)

Aggregations

ModelClient (com.emc.sa.model.dao.ModelClient)18 Test (org.junit.Test)15 BaseModelTest (com.emc.sa.model.BaseModelTest)12 NamedURI (com.emc.storageos.db.client.model.NamedURI)8 CatalogCategory (com.emc.storageos.db.client.model.uimodels.CatalogCategory)7 Order (com.emc.storageos.db.client.model.uimodels.Order)4 URI (java.net.URI)3 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)2 ExecutionWindow (com.emc.storageos.db.client.model.uimodels.ExecutionWindow)2 VirtualMachine (com.emc.storageos.db.client.model.uimodels.VirtualMachine)2 BourneDbClient (com.emc.sa.model.dao.BourneDbClient)1 InMemoryDbClient (com.emc.sa.model.mock.InMemoryDbClient)1 StubCoordinatorClientImpl (com.emc.sa.model.mock.StubCoordinatorClientImpl)1 Vcenter (com.emc.storageos.db.client.model.Vcenter)1 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)1 ApprovalRequest (com.emc.storageos.db.client.model.uimodels.ApprovalRequest)1 ExecutionLog (com.emc.storageos.db.client.model.uimodels.ExecutionLog)1 ExecutionState (com.emc.storageos.db.client.model.uimodels.ExecutionState)1 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)1 Date (java.util.Date)1