ServerNameRequiredMatch implements PrivilegeValidator { @Override public void validate(PrivilegeValidatorContext context) throws ConfigurationException { Iterable<SqoopAuthorizable> authorizables = parsePrivilege(context.getPrivilege()); boolean match = false; for (SqoopAuthorizable authorizable : authorizables) { if (authorizable instanceof Server && authorizable.getName().equalsIgnoreCase(sqoopServerName)) { match = true; break; } } if (!match) { String msg = "server=[name] in " + context.getPrivilege() + " is required. The name is expected " + sqoopServerName; throw new ConfigurationException(msg); } } ServerNameRequiredMatch(String sqoopServerName); @Override void validate(PrivilegeValidatorContext context);  }
@Test public void testWithoutServerName() { ServerNameRequiredMatch serverNameMatch = new ServerNameRequiredMatch("server1"); try { serverNameMatch.validate(new PrivilegeValidatorContext("connector=c1->action=read")); Assert.fail("Expected ConfigurationException"); } catch (ConfigurationException ex) { } }
@Test public void testServerNameNotMatch() throws Exception { ServerNameRequiredMatch serverNameMatch = new ServerNameRequiredMatch("server1"); try { serverNameMatch.validate(new PrivilegeValidatorContext("server=server2->connector=c1->action=read")); Assert.fail("Expected ConfigurationException"); } catch (ConfigurationException ex) { } }
@Test public void testServerNameMatch() throws Exception { ServerNameRequiredMatch serverNameMatch = new ServerNameRequiredMatch("server1"); try { serverNameMatch.validate(new PrivilegeValidatorContext("server=server1->connector=c1->action=read")); } catch (ConfigurationException ex) { Assert.fail("Not expected ConfigurationException"); } }