use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testCreationTime.
@Test
public void testCreationTime() throws Exception {
_logger.info("Starting testCreationTime");
DbClient dbClient = _dbClient;
StorageSystem system = new StorageSystem();
system.setId(URIUtil.createId(StorageSystem.class));
dbClient.createObject(system);
Thread.sleep(100);
StorageSystem hit = dbClient.queryObject(StorageSystem.class, system.getId());
Calendar now = Calendar.getInstance();
Calendar then = hit.getCreationTime();
Assert.assertNotNull(then);
Assert.assertTrue(String.format("then(%s) is not before now(%s), should be %s", then.toString(), now.toString(), system.getCreationTime().toString()), then.before(now));
system.setLabel("Update");
dbClient.persistObject(system);
hit = dbClient.queryObject(StorageSystem.class, system.getId());
Calendar thenAgain = hit.getCreationTime();
Assert.assertNotNull(thenAgain);
Assert.assertEquals(thenAgain, then);
_logger.info("Finished testing CreationTime");
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testAlternateIdFromStringSet.
/**
* Tests object lookup by alias
*
* @throws IOException
*/
@Test
public void testAlternateIdFromStringSet() throws IOException {
_logger.info("Starting testAlternateIdFromStringSet");
DbClient dbClient = _dbClient;
String altId = UUID.randomUUID().toString();
// persist
AuthnProvider provider = new AuthnProvider();
provider.setId(URIUtil.createId(AuthnProvider.class));
provider.setLabel("test-provider");
provider.setDescription("test provider");
StringSet domains = new StringSet();
domains.add("test1.com");
domains.add("test2.com");
provider.setDomains(domains);
dbClient.persistObject(provider);
// verify
AuthnProvider stdQueryResult = dbClient.queryObject(AuthnProvider.class, provider.getId());
Assert.assertTrue(stdQueryResult.getId().equals(provider.getId()));
Assert.assertTrue(stdQueryResult.getLabel().equals(provider.getLabel()));
Assert.assertEquals(stdQueryResult.getDomains().size(), provider.getDomains().size());
for (String domain : domains) {
Assert.assertTrue(stdQueryResult.getDomains().contains(domain));
}
// query by altid
for (String domain : domains) {
URIQueryResultList altIdResult = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(domain), altIdResult);
Assert.assertTrue(altIdResult.iterator().hasNext());
}
stdQueryResult.getDomains().remove("test2.com");
domains.remove("test2.com");
domains.add("test3.com");
stdQueryResult.getDomains().add("test3.com");
dbClient.persistObject(stdQueryResult);
stdQueryResult = dbClient.queryObject(AuthnProvider.class, provider.getId());
Assert.assertTrue(stdQueryResult.getId().equals(provider.getId()));
Assert.assertTrue(stdQueryResult.getLabel().equals(provider.getLabel()));
// query by altid
for (String domain : domains) {
URIQueryResultList altIdResult = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(domain), altIdResult);
Assert.assertTrue(altIdResult.iterator().hasNext());
}
URIQueryResultList altIdResult = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint("test-subtenant"), altIdResult);
Assert.assertFalse(altIdResult.iterator().hasNext());
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testQueryField.
@Test
public void testQueryField() throws Exception {
DbClient dbClient = _dbClient;
OpStatusMap status = new OpStatusMap();
String taskname = "task1";
Operation op = new Operation(Operation.Status.pending.toString(), "test");
op.setDescription("descr");
status.createTaskStatus(taskname, op);
String label = "test system";
StorageSystem system1 = new StorageSystem();
system1.setId(URIUtil.createId(StorageSystem.class));
system1.setLabel(label);
system1.setInactive(true);
system1.setOpStatus(status);
StorageSystem system2 = new StorageSystem();
system2.setId(URIUtil.createId(StorageSystem.class));
system2.setLabel(label);
system2.setInactive(true);
system2.setOpStatus(status);
dbClient.persistObject(system1, system2);
List<URI> uris = new ArrayList<URI>();
uris.add(system1.getId());
uris.add(system2.getId());
List<StorageSystem> systems = dbClient.queryObjectField(StorageSystem.class, "label", uris);
Assert.assertEquals(2, systems.size());
Assert.assertTrue(systems.get(0).getLabel().equals(label));
Assert.assertTrue(systems.get(1).getLabel().equals(label));
Iterator<StorageSystem> it = dbClient.queryIterativeObjectField(StorageSystem.class, "label", uris);
int count = 0;
while (it.hasNext()) {
count++;
StorageSystem obj = it.next();
Assert.assertTrue(obj.getLabel().equals(label));
}
Assert.assertEquals(2, count);
systems = dbClient.queryObjectField(StorageSystem.class, "inactive", uris);
Assert.assertEquals(2, systems.size());
Assert.assertTrue(systems.get(0).getInactive());
Assert.assertTrue(systems.get(1).getInactive());
systems = dbClient.queryObjectField(StorageSystem.class, "status", uris);
Assert.assertEquals(2, systems.size());
Assert.assertNotNull(systems.get(0).getOpStatus().get(taskname));
Assert.assertNotNull(systems.get(1).getOpStatus().get(taskname));
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testStringSetMapReplace.
@Test
public void testStringSetMapReplace() throws Exception {
// shows behavior of AbstractChangeTrackingMapSet.clear()
_logger.info("Starting StringSetMapReplace test");
DbClient dbClient = _dbClient;
ProtectionSystem ps = new ProtectionSystem();
ps.setId(URIUtil.createId(ProtectionSystem.class));
StringSet set1 = new StringSet();
set1.add("test1");
set1.add("test2");
set1.add("test3");
set1.add("test4");
StringSet set2 = new StringSet();
set2.add("test5");
set2.add("test6");
set2.add("test7");
set2.add("test8");
String key1 = "key1";
String key2 = "key2";
StringSetMap sMap = new StringSetMap();
sMap.put(key1, set1);
sMap.put(key2, set2);
ps.setSiteInitiators(sMap);
dbClient.createObject(ps);
ProtectionSystem ps1 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
StringSet set3 = new StringSet();
set3.add("test9");
set3.add("test10");
set3.add("test11");
set3.add("test12");
StringSet set4 = new StringSet();
set4.add("test13");
set4.add("test14");
set4.add("test15");
set4.add("test16");
String key4 = "key4";
String key3 = "key3";
StringSetMap sMap2 = new StringSetMap();
sMap2.put(key3, set3);
sMap2.put(key4, set4);
ps1.getSiteInitiators().replace(sMap2);
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key1));
Assert.assertTrue(ps1.getSiteInitiators().get(key1).isEmpty());
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key2));
Assert.assertTrue(ps1.getSiteInitiators().get(key2).isEmpty());
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key3));
Assert.assertFalse(ps1.getSiteInitiators().get(key3).isEmpty());
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key4));
Assert.assertFalse(ps1.getSiteInitiators().get(key4).isEmpty());
dbClient.persistObject(ps1);
ProtectionSystem ps2 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
Assert.assertFalse(ps2.getSiteInitiators().containsKey(key1));
Assert.assertFalse(ps2.getSiteInitiators().containsKey(key2));
Assert.assertTrue(ps2.getSiteInitiators().containsKey(key3));
Assert.assertFalse(ps2.getSiteInitiators().get(key3).isEmpty());
Assert.assertTrue(ps2.getSiteInitiators().containsKey(key4));
Assert.assertFalse(ps2.getSiteInitiators().get(key4).isEmpty());
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testStringSetMapRemove.
@Test
public void testStringSetMapRemove() throws Exception {
// shows behavior of AbstractChangeTrackingMapSet.clear()
_logger.info("Starting StringSetMap3 test");
DbClient dbClient = _dbClient;
ProtectionSystem ps = new ProtectionSystem();
ps.setId(URIUtil.createId(ProtectionSystem.class));
StringSet set1 = new StringSet();
set1.add("test1");
set1.add("test2");
set1.add("test3");
set1.add("test4");
StringSet set2 = new StringSet();
set2.add("test5");
set2.add("test6");
set2.add("test7");
set2.add("test8");
String key1 = "key1";
String key2 = "key2";
StringSetMap sMap = new StringSetMap();
sMap.put(key1, set1);
sMap.put(key2, set2);
ps.setSiteInitiators(sMap);
dbClient.createObject(ps);
ProtectionSystem ps1 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
StringSet set3 = new StringSet();
set3.add("test9");
set3.add("test10");
set3.add("test11");
set3.add("test12");
StringSet set4 = new StringSet();
set4.add("test13");
set4.add("test14");
set4.add("test15");
set4.add("test16");
String key4 = "key4";
String key3 = "key3";
StringSetMap sMap2 = new StringSetMap();
sMap2.put(key3, set3);
sMap2.put(key4, set4);
ps1.getSiteInitiators().remove(key1);
ps1.getSiteInitiators().remove(key2);
ps1.getSiteInitiators().putAll(sMap2);
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key1));
Assert.assertTrue(ps1.getSiteInitiators().get(key1).isEmpty());
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key2));
Assert.assertTrue(ps1.getSiteInitiators().get(key2).isEmpty());
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key3));
Assert.assertFalse(ps1.getSiteInitiators().get(key3).isEmpty());
Assert.assertTrue(ps1.getSiteInitiators().containsKey(key4));
Assert.assertFalse(ps1.getSiteInitiators().get(key4).isEmpty());
dbClient.persistObject(ps1);
ProtectionSystem ps2 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
Assert.assertFalse(ps2.getSiteInitiators().containsKey(key1));
Assert.assertFalse(ps2.getSiteInitiators().containsKey(key2));
Assert.assertTrue(ps2.getSiteInitiators().containsKey(key3));
Assert.assertFalse(ps2.getSiteInitiators().get(key3).isEmpty());
Assert.assertTrue(ps2.getSiteInitiators().containsKey(key4));
Assert.assertFalse(ps2.getSiteInitiators().get(key4).isEmpty());
}
Aggregations