public class MappingTest extends TestSupport {
@Test
public void createMapping() throws HBqlException {
HConnection connection = HConnectionManager.newConnection();
assertFalse(connection.mappingExists("zzz"));
assertTrue(connection.mappingExists("system_mappings"));
String mappingName = "test1";
connection.dropMapping(mappingName);
assertFalse(connection.mappingExists(mappingName));
connection.execute("CREATE MAPPING " + mappingName + " (keyval key, f1 (val2 object alias val3))");
assertTrue(connection.mappingExists(mappingName));
HMapping mapping = connection.getMapping(mappingName);
assertTrue(mapping.getMappingName().equals(mappingName) && mapping.getTableName().equals(mappingName));
assertTrue(!mapping.isTempMapping());
connection.dropMapping(mappingName);
assertFalse(connection.mappingExists(mappingName));
mappingName = "test2";
connection.dropMapping(mappingName);
assertFalse(connection.mappingExists(mappingName));
connection.execute("CREATE TEMP MAPPING " + mappingName + " (keyval key, f1(val2 object alias val3))");
assertTrue(connection.mappingExists(mappingName));
mapping = connection.getMapping(mappingName);
assertTrue(mapping.getMappingName().equals(mappingName) && mapping.getTableName().equals(mappingName));
assertTrue(mapping.isTempMapping());
connection.dropMapping(mappingName);
assertFalse(connection.mappingExists(mappingName));
mappingName = "test3";
connection.dropMapping(mappingName);
assertFalse(connection.mappingExists(mappingName));
connection.execute("CREATE TEMP MAPPING " + mappingName + " for table unknown_table"
+ " (keyval key, "
+ "f1 (val1 int[] , val2 object[] alias val3),"
+ "f2 include unmapped(val1 int[] , val2 string alias val4 default 'test val'))");
assertTrue(connection.mappingExists(mappingName));
mapping = connection.getMapping(mappingName);
assertTrue(mapping.getMappingName().equals(mappingName) && !mapping.getTableName().equals(mappingName));
assertTrue(mapping.isTempMapping());
mapping = connection.getMapping(mappingName);
System.out.print(mapping.asString());
connection.dropMapping(mappingName);
assertFalse(connection.mappingExists(mappingName));
Set<HMapping> mappings = connection.getAllMappings();
}