@Test public void testAttributes() throws Exception { int rc; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); final String[] args1 = {"create", "keyattr1", "-provider", jceksProvider, "-attr", "foo=bar"}; rc = ks.run(args1); assertEquals(0, rc); assertTrue(outContent.toString().contains("keyattr1 has been " + "successfully created")); String listOut = listKeys(ks, true); assertTrue(listOut.contains("keyattr1")); assertTrue(listOut.contains("attributes: [foo=bar]")); outContent.reset(); final String[] args2 = {"create", "keyattr2", "-provider", jceksProvider, "-attr", "=bar"}; rc = ks.run(args2); assertEquals(1, rc); outContent.reset(); args2[5] = "foo"; rc = ks.run(args2); assertEquals(1, rc); outContent.reset(); args2[5] = "="; rc = ks.run(args2); assertEquals(1, rc); outContent.reset(); args2[5] = "a=b=c"; rc = ks.run(args2); assertEquals(0, rc); listOut = listKeys(ks, true); assertTrue(listOut.contains("keyattr2")); assertTrue(listOut.contains("attributes: [a=b=c]")); outContent.reset(); final String[] args3 = {"create", "keyattr3", "-provider", jceksProvider, "-attr", "foo = bar", "-attr", " glarch =baz ", "-attr", "abc=def"}; rc = ks.run(args3); assertEquals(0, rc); listOut = listKeys(ks, true); assertTrue(listOut.contains("keyattr3")); assertTrue(listOut.contains("[foo=bar]")); assertTrue(listOut.contains("[glarch=baz]")); assertTrue(listOut.contains("[abc=def]")); outContent.reset(); final String[] args4 = {"create", "keyattr4", "-provider", jceksProvider, "-attr", "foo=bar", "-attr", "foo=glarch"}; rc = ks.run(args4); assertEquals(1, rc); deleteKey(ks, "keyattr1"); deleteKey(ks, "keyattr2"); deleteKey(ks, "keyattr3"); }
@Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; }
KeyShell extends Configured implements Tool { @Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; } }
KeyShell extends Configured implements Tool { @Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; }  }
KeyShell extends Configured implements Tool { @Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; }  @Override int run(String[] args); static void main(String[] args); }
KeyShell extends Configured implements Tool { @Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; }  @Override int run(String[] args); static void main(String[] args); public PrintStream out; public PrintStream err; }