private void setIdIfNeeded(DbUser user) { if (Guid.isNullOrEmpty(user.getId())) { user.setId(Guid.newGuid()); } }
public VmHostDevice(Guid vmId, HostDevice device) { this(); setDeviceId(Guid.newGuid()); setVmId(vmId); setDevice(device.getDeviceName()); }
protected MapSqlParameterSource createNumaNodeCpusParametersMapper(NumaNode node, Integer cpuId) { return getCustomMapSqlParameterSource() .addValue("id", Guid.newGuid()) .addValue("numa_node_id", node.getId()) .addValue("cpu_core_id", cpuId); } }
@Override public void save(FenceAgent agent) { MapSqlParameterSource params = getInsertOrUpdateParams(agent); Guid id = Guid.newGuid(); params.addValue("id", id); // create random ID for the new agent. agent.setId(id); getCallsHandler().executeModification("InsertFenceAgent", params); }
@Test public void testGetByNameReturnsItemOfThatName() { String itemName = "name"; TestItem item = new TestItem(Guid.newGuid(), itemName); BusinessEntityMap<TestItem> map = new BusinessEntityMap<>(Collections.singletonList(item)); assertThat(map.get(itemName), is(item)); }
@Test public void testContainsKeyReturnsTrueForExistingId() { Guid itemId = Guid.newGuid(); List<TestItem> testItems = Collections.singletonList(new TestItem(itemId, null)); BusinessEntityMap<TestItem> map = new BusinessEntityMap<>(testItems); assertThat(map.containsKey(itemId), is(true)); }
@Test public void testGetByIdOrNameWhenIdIsNotSpecified() { TestItem testItem = new TestItem(Guid.newGuid(), "name"); List<TestItem> testItems = Collections.singletonList(testItem); BusinessEntityMap<TestItem> map = new BusinessEntityMap<>(testItems); assertThat(map.get(null, "name"), is(testItem)); }
/** * Ensures that nothing is returned when the VM is invalid. */ @Test public void testGetAllForVmWithInvalidVm() { List<DbUser> result = dao.getAllForVm(Guid.newGuid()); assertTrue(result.isEmpty()); }
/** Tests {@link AuditLogDao#getAllByVMTemplateId(Guid)} with a an ID of a VM Template that doesn't exist */ @Test public void testGetAllByVMTemplateIdInvalidId() { assertGetByNameInvalidResults(dao.getAllByVMTemplateId(Guid.newGuid())); }
@Test public void testGetAllIdsForNonExistingStoragePoolId() { List<Guid> result = dao.getAllIds(Guid.newGuid(), StorageDomainStatus.Active); assertNotNull(result); assertTrue(result.isEmpty()); }
/** * Ensures that getting a permission with a bad id fails. */ @Test public void testGetWithInvalidId() { Permission result = dao.get(Guid.newGuid()); assertNull(result); }
/** * Ensures that an empty collection is returned. */ @Test public void testGetAllForAdElementWithInvalidId() { List<Permission> result = dao.getAllForAdElement(Guid.newGuid()); assertInvalidGetPermissionList(result); }
/** * Ensures that an empty collection is returned. */ @Test public void testGetAllForAdElementOnlyWithInvalidId() { List<Permission> result = dao.getAllDirectPermissionsForAdElement(Guid.newGuid()); assertInvalidGetPermissionList(result); }
/** * Ensures that an empty collection is returned. */ @Test public void testGetAllForRoleWithInvalidRole() { List<Permission> result = dao.getAllForRole(Guid.newGuid()); assertInvalidGetPermissionList(result); }
/** * Ensures that an empty collection is returned if the specified role doesn't have any permissions with the * specified ad element. */ @Test public void testGetAllForRoleAndAdElementWithInvalidRole() { List<Permission> result = dao.getAllForRoleAndAdElement( Guid.newGuid(), AD_ELEMENT_ID); assertInvalidGetPermissionList(result); }
/** * Ensures that trying to get a user using an invalid id fails. */ @Test public void testGetWithInvalidId() { DbUser result = dao.get(Guid.newGuid()); assertNull(result); }
@Test public void testGetImagesWithNoDiskReturnsEmptyList() { List<DiskImage> result = dao.getImagesWithNoDisk(Guid.newGuid()); assertNotNull(result); assertTrue(result.isEmpty()); }
/** * Ensures that if the id is invalid then no EngineSession is returned. */ @Test public void testGetWithInvalidId() { EngineSession result = dao.getBySessionId(Guid.newGuid().toString()); assertNull(result); }