OtpKeyRequestProcessor extends AbstractGameBootProcessor<OtpKeyRequest> { private Response newKey(OtpKeyRequest message) throws Exception { Integer size = message.getKeySize() == null ? defaultKeySize : message.getKeySize(); SystemIdKey systemId = new SystemIdKey(message.getOtpSystemId()); log.debug("Creating new OTP key of size {} for {}", size, systemId); byte[] newKey = pad.generateKey(size); newKeyRegistry.put(systemId, newKey); return new Response(message, ResponseCode.SUCCESS, newKey); }  @Override String getType();  }
@Test public void testNewKey() throws Exception { failExpected(null, "Null message"); OtpKeyRequest r = new OtpKeyRequest(); failExpected(r, "mt message"); r.setOtpSystemId(CLEAR_CHANNEL_ID); r.setKeyFunction(KeyFunction.NEW); r.setKeySize(-32); failExpected(r, "negative size"); r.setKeySize(KEY_SIZE); r.setKeyFunction(null); failExpected(r, "No key function"); r.setKeyFunction(KeyFunction.NEW); r.setKeySize(maxKeySize + 1); failExpected(r, "> max key size"); r.setKeySize(KEY_SIZE); Response rep = processor.process(r); assertEquals(ResponseCode.SUCCESS, rep.getResponseCode()); assertNotNull(rep.getPayload()); assertEquals(1, rep.getPayload().length); assertTrue(rep.getPayload()[0] instanceof byte[]); byte[] b = (byte[]) rep.getPayload()[0]; assertEquals(KEY_SIZE.intValue(), b.length); }