import java.util.List;
public class TestHCatSchema extends TestCase {
public void testCannotAddFieldMoreThanOnce() throws HCatException {
List<HCatFieldSchema> fieldSchemaList = new ArrayList<HCatFieldSchema>();
fieldSchemaList.add(new HCatFieldSchema("name", HCatFieldSchema.Type.STRING, "What's your handle?"));
fieldSchemaList.add(new HCatFieldSchema("age", HCatFieldSchema.Type.INT, "So very old"));
HCatSchema schema = new HCatSchema(fieldSchemaList);
assertTrue(schema.getFieldNames().contains("age"));
assertEquals(2, schema.getFields().size());
try {
schema.append(new HCatFieldSchema("age", HCatFieldSchema.Type.INT, "So very old"));
fail("Was able to append field schema with same name");
} catch(HCatException he) {
assertTrue(he.getMessage().contains("Attempt to append HCatFieldSchema with already existing name: age."));
}
assertTrue(schema.getFieldNames().contains("age"));
assertEquals(2, schema.getFields().size());
// Should also not be able to add fields of different types with same name
try {
schema.append(new HCatFieldSchema("age", HCatFieldSchema.Type.STRING, "Maybe spelled out?"));
fail("Was able to append field schema with same name");
} catch(HCatException he) {
assertTrue(he.getMessage().contains("Attempt to append HCatFieldSchema with already existing name: age."));
}