OpenTsdbProtocolConverter implements Converter<OpenTsdbProtocol> { @Override public OpenTsdbProtocol convertFrom(String value) { if (Strings.isNullOrEmpty(value)) { throw new ParameterException("Couldn't convert empty string to \"HTTP\" or \"TELNET\"."); } try { return OpenTsdbProtocol.valueOf(value.toUpperCase(Locale.ENGLISH)); } catch (Exception e) { throw new ParameterException(e.getMessage(), e); } }  @Override OpenTsdbProtocol convertFrom(String value); @Override String convertTo(OpenTsdbProtocol value);  }
@Test public void convertFromValidString() throws Exception { final OpenTsdbProtocol protocol = new OpenTsdbProtocolConverter().convertFrom("HTTP"); assertEquals(OpenTsdbProtocol.HTTP, protocol); }
@Test public void convertFromValidMixedCaseString() throws Exception { final OpenTsdbProtocol protocol = new OpenTsdbProtocolConverter().convertFrom("telNet"); assertEquals(OpenTsdbProtocol.TELNET, protocol); }
@Test public void convertFromInvalidString() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("No enum constant org.graylog.plugins.metrics.opentsdb.OpenTsdbProtocol.FOOBAR"); new OpenTsdbProtocolConverter().convertFrom("foobar"); }
@Test public void convertFromNull() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("Couldn't convert empty string to \"HTTP\" or \"TELNET\"."); new OpenTsdbProtocolConverter().convertFrom(null); }
@Test public void convertFromEmptyString() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("Couldn't convert empty string to \"HTTP\" or \"TELNET\"."); new OpenTsdbProtocolConverter().convertFrom(""); }