@Test public void readTest() { String insertKey = "user0"; Map<String, ByteIterator> insertMap = insertRow(insertKey); HashSet<String> readFields = new HashSet<>(); HashMap<String, ByteIterator> readResultMap = new HashMap<>(); // Test reading a single field readFields.add("FIELD0"); orientDBClient.read(CLASS, insertKey, readFields, readResultMap); assertEquals( "Assert that result has correct number of fields", readFields.size(), readResultMap.size()); for (String field : readFields) { assertEquals( "Assert " + field + " was read correctly", insertMap.get(field).toString(), readResultMap.get(field).toString()); } readResultMap = new HashMap<>(); // Test reading all fields readFields.add("FIELD1"); readFields.add("FIELD2"); orientDBClient.read(CLASS, insertKey, readFields, readResultMap); assertEquals( "Assert that result has correct number of fields", readFields.size(), readResultMap.size()); for (String field : readFields) { assertEquals( "Assert " + field + " was read correctly", insertMap.get(field).toString(), readResultMap.get(field).toString()); } }
@Test public void scanTest() { Map<String, Map<String, ByteIterator>> keyMap = new HashMap<>(); for (int i = 0; i < 5; i++) { String insertKey = KEY_PREFIX + i; keyMap.put(insertKey, insertRow(insertKey)); } Set<String> fieldSet = new HashSet<>(); fieldSet.add("FIELD0"); fieldSet.add("FIELD1"); int startIndex = 1; int resultRows = 3; Vector<HashMap<String, ByteIterator>> resultVector = new Vector<>(); orientDBClient.scan(CLASS, KEY_PREFIX + startIndex, resultRows, fieldSet, resultVector); // Check the resultVector is the correct size assertEquals( "Assert the correct number of results rows were returned", resultRows, resultVector.size()); // Check each vector row to make sure we have the correct fields int testIndex = startIndex; for (HashMap<String, ByteIterator> result : resultVector) { assertEquals( "Assert that this row has the correct number of fields", fieldSet.size(), result.size()); for (String field : fieldSet) { assertEquals( "Assert this field is correct in this row", keyMap.get(KEY_PREFIX + testIndex).get(field).toString(), result.get(field).toString()); } testIndex++; } }