DBModelAuthorizables { public static DBModelAuthorizable from(KeyValue keyValue) { String prefix = keyValue.getKey().toLowerCase(); String name = keyValue.getValue(); for(AuthorizableType type : AuthorizableType.values()) { if(prefix.equalsIgnoreCase(type.name())) { if (prefix.equalsIgnoreCase(AuthorizableType.URI.toString())) { return from(type, name); } else { return from(type, name.toLowerCase()); } } } return null; }  static DBModelAuthorizable from(KeyValue keyValue); static DBModelAuthorizable from(String s);  }
@Test(expected=IllegalArgumentException.class) public void testEmptyValue() throws Exception { System.out.println(DBModelAuthorizables.from("k=")); }
@Test public void testNotAuthorizable() throws Exception { assertNull(DBModelAuthorizables.from("k=v")); }
@Test public void testServer() throws Exception { Server server = (Server)DBModelAuthorizables.from("SeRvEr=server1"); assertEquals("server1", server.getName()); }
@Test public void testDb() throws Exception { Database db = (Database)DBModelAuthorizables.from("dB=db1"); assertEquals("db1", db.getName()); }
@Test public void testTable() throws Exception { Table table = (Table)DBModelAuthorizables.from("tAbLe=t1"); assertEquals("t1", table.getName()); }
@Test public void testView() throws Exception { View view = (View)DBModelAuthorizables.from("vIeW=v1"); assertEquals("v1", view.getName()); }
@Test public void testURI() throws Exception { AccessURI uri = (AccessURI)DBModelAuthorizables.from("UrI=hdfs: assertEquals("hdfs: }
@Test(expected=IllegalArgumentException.class) public void testNoKV() throws Exception { System.out.println(DBModelAuthorizables.from("nonsense")); }
@Test(expected=IllegalArgumentException.class) public void testEmptyKey() throws Exception { System.out.println(DBModelAuthorizables.from("=v")); }