### Question:
OMGetDelegationTokenRequest extends OMClientRequest { @Override public OMRequest preExecute(OzoneManager ozoneManager) throws IOException { GetDelegationTokenRequestProto getDelegationTokenRequest = getOmRequest().getGetDelegationTokenRequest(); Token<OzoneTokenIdentifier> token = ozoneManager .getDelegationToken(new Text(getDelegationTokenRequest.getRenewer())); OMRequest.Builder omRequest; if (token != null) { omRequest = OMRequest.newBuilder().setUserInfo(getUserInfo()) .setUpdateGetDelegationTokenRequest( UpdateGetDelegationTokenRequest.newBuilder() .setGetDelegationTokenResponse( GetDelegationTokenResponseProto.newBuilder() .setResponse( SecurityProtos.GetDelegationTokenResponseProto .newBuilder().setToken(OMPBHelper .convertToTokenProto(token)).build()) .build()) .setTokenRenewInterval(ozoneManager.getDelegationTokenMgr() .getTokenRenewInterval())) .setCmdType(getOmRequest().getCmdType()) .setClientId(getOmRequest().getClientId()); } else { omRequest = OMRequest.newBuilder().setUserInfo(getUserInfo()) .setUpdateGetDelegationTokenRequest( UpdateGetDelegationTokenRequest.newBuilder() .setGetDelegationTokenResponse( GetDelegationTokenResponseProto.newBuilder())) .setCmdType(getOmRequest().getCmdType()) .setClientId(getOmRequest().getClientId()); } if (getOmRequest().hasTraceID()) { omRequest.setTraceID(getOmRequest().getTraceID()); } return omRequest.build(); } OMGetDelegationTokenRequest(OMRequest omRequest); @Override OMRequest preExecute(OzoneManager ozoneManager); @Override OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
      long transactionLogIndex,
      OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper);  }### Answer:
@Test public void testPreExecuteWithNonNullToken() throws Exception { when(ozoneManager.getDelegationToken(tester)).thenReturn(token); long tokenRenewInterval = 1000L; when(ozoneManager.getDelegationTokenMgr().getTokenRenewInterval()) .thenReturn(tokenRenewInterval); modifiedRequest = omGetDelegationTokenRequest.preExecute(ozoneManager); verifyUnchangedRequest(); long originalInterval = originalRequest.getUpdateGetDelegationTokenRequest() .getTokenRenewInterval(); long renewInterval = modifiedRequest.getUpdateGetDelegationTokenRequest() .getTokenRenewInterval(); Assert.assertNotEquals(originalInterval, renewInterval); Assert.assertEquals(tokenRenewInterval, renewInterval); Assert.assertNotEquals(checkResponse, modifiedRequest.getUpdateGetDelegationTokenRequest() .getGetDelegationTokenResponse() .toString()); Assert.assertNotNull(modifiedRequest .getUpdateGetDelegationTokenRequest() .getGetDelegationTokenResponse()); }
@Test public void testPreExecuteWithNullToken() throws Exception { when(ozoneManager.getDelegationToken(tester)).thenReturn(null); modifiedRequest = omGetDelegationTokenRequest.preExecute(ozoneManager); verifyUnchangedRequest(); Assert.assertEquals(checkResponse, modifiedRequest.getUpdateGetDelegationTokenRequest() .getGetDelegationTokenResponse() .toString()); }