ParamGenericValidationWorker implements DispatchWorker { @SuppressWarnings("rawtypes") @Override public void handle(final DispatchTask task) { final BaseCmd cmd = task.getCmd(); final Map params = task.getParams(); final List<String> expectedParamNames = getParamNamesForCommand(cmd); final StringBuilder errorMsg = new StringBuilder(ERROR_MSG_PREFIX); boolean foundUnknownParam = false; for (final Object actualParamName : params.keySet()) { boolean matchedCurrentParam = false; for (final String expectedName : expectedParamNames) { if (expectedName.equalsIgnoreCase((String) actualParamName)) { matchedCurrentParam = true; break; } } if (!matchedCurrentParam && !((String)actualParamName).equalsIgnoreCase("expires") && !((String)actualParamName).equalsIgnoreCase("signatureversion")) { errorMsg.append(" ").append(actualParamName); foundUnknownParam= true; } } if (foundUnknownParam) { s_logger.warn(String.format("Received unknown parameters for command %s. %s", cmd.getActualCommandName(), errorMsg)); } }  @SuppressWarnings("rawtypes") @Override void handle(final DispatchTask task);  }
@Test public void testHandle() throws ResourceAllocationException { final BaseCmd cmd = new FakeCmd(); final Map<String, String> params = new HashMap<String, String>(); params.put(ApiConstants.COMMAND, ""); params.put(ApiConstants.ACCOUNT_ID, ""); params.put(ApiConstants.CTX_START_EVENT_ID, ""); params.put(ApiConstants.COMMAND, ""); params.put(ApiConstants.CMD_EVENT_TYPE, ""); params.put(ApiConstants.USERNAME, ""); params.put(ApiConstants.USER_ID, ""); params.put(ApiConstants.PASSWORD, ""); params.put(ApiConstants.DOMAIN, ""); params.put(ApiConstants.DOMAIN_ID, ""); params.put(ApiConstants.DOMAIN__ID, ""); params.put(ApiConstants.SESSIONKEY, ""); params.put(ApiConstants.RESPONSE, ""); params.put(ApiConstants.PAGE, ""); params.put(ApiConstants.USER_API_KEY, ""); params.put(ApiConstants.API_KEY, ""); params.put(ApiConstants.PAGE_SIZE, ""); params.put(ApiConstants.HTTPMETHOD, ""); params.put(ApiConstants.SIGNATURE, ""); params.put(ApiConstants.CTX_ACCOUNT_ID, ""); params.put(ApiConstants.CTX_START_EVENT_ID, ""); params.put(ApiConstants.CTX_START_EVENT_ID, ""); params.put(ApiConstants.CTX_START_EVENT_ID.toLowerCase(), ""); params.put(ApiConstants.CTX_USER_ID.toUpperCase(), ""); params.put(ApiConstants.CTX_USER_ID, ""); params.put(ApiConstants.UUID, ""); params.put(ApiConstants.ID, ""); params.put("_", ""); params.put("addedParam", ""); Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid"); UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); CallContext.register(user, account); try { driveTest(cmd, params); } finally { CallContext.unregister(); } assertEquals("There should be no errors since there are no unknown parameters for this command class", null, loggerOutput); }