ConfigurableTokenLifecycleStrategy implements TokenLifecycleStrategy { @Override public void afterTokenCall(TokenLifecycleStrategyCallback callback, TokenWrapper tokenWrapper, OutputMessage outputMessage) { if(addErrorOnAgentError) { if(outputMessage!=null && outputMessage.getAgentError()!=null) { if(concernedAgentErrors == null || concernedAgentErrors.isEmpty() || concernedAgentErrors.contains(outputMessage.getAgentError().getErrorCode())) { addTokenError(callback, "Error while calling agent", null); } } } } ConfigurableTokenLifecycleStrategy(boolean addErrorOnTokenReleaseError,
			boolean addErrorOnTokenReservationError, boolean addErrorOnTokenCallError, boolean addErrorOnAgentError,
			Set<AgentErrorCode> concernedAgentErrors); boolean isAddErrorOnTokenReleaseError(); void setAddErrorOnTokenReleaseError(boolean addErrorOnTokenReleaseError); boolean isAddErrorOnTokenReservationError(); void setAddErrorOnTokenReservationError(boolean addErrorOnTokenReservationError); boolean isAddErrorOnTokenCallError(); void setAddErrorOnTokenCallError(boolean addErrorOnTokenCallError); boolean isAddErrorOnAgentError(); void setAddErrorOnAgentError(boolean addErrorOnAgentError); Set<AgentErrorCode> getConcernedAgentErrors(); void setConcernedAgentErrors(Set<AgentErrorCode> concernedAgentErrors); @Override void afterTokenReleaseError(TokenLifecycleStrategyCallback callback, TokenWrapper tokenWrapper,
			Exception e); @Override void afterTokenReservationError(TokenLifecycleStrategyCallback callback, TokenWrapper tokenWrapper,
			Exception e); @Override void afterTokenCallError(TokenLifecycleStrategyCallback callback, TokenWrapper tokenWrapper, Exception e); @Override void afterTokenCall(TokenLifecycleStrategyCallback callback, TokenWrapper tokenWrapper,
			OutputMessage outputMessage); boolean registerTokenErrorListener(TokenErrorListener e);  }
@Test public void testAddErrorOnAgentErrorFalse() { AtomicBoolean callBackCalled = new AtomicBoolean(false); HashSet<AgentErrorCode> concernedAgentErrors = new HashSet<>(); concernedAgentErrors.add(AgentErrorCode.UNEXPECTED); OutputMessage out = new OutputMessage(); AgentError agentError = new AgentError(AgentErrorCode.CONTEXT_BUILDER); out.setAgentError(agentError); TokenLifecycleStrategy s = new ConfigurableTokenLifecycleStrategy(true, true, true, true, concernedAgentErrors); s.afterTokenCall(new TokenLifecycleStrategyCallback(null, null) { @Override public void addTokenError(String errorMessage, Exception exception) { Assert.assertEquals("my message", exception.getMessage()); callBackCalled.set(true); } }, new TokenWrapper(), out); Assert.assertFalse(callBackCalled.get()); }
@Test public void testAddErrorOnAgentErrorTrue() { AtomicBoolean callBackCalled = new AtomicBoolean(false); HashSet<AgentErrorCode> concernedAgentErrors = new HashSet<>(); concernedAgentErrors.add(AgentErrorCode.UNEXPECTED); OutputMessage out = new OutputMessage(); AgentError agentError = new AgentError(AgentErrorCode.UNEXPECTED); out.setAgentError(agentError); TokenLifecycleStrategy s = new ConfigurableTokenLifecycleStrategy(true, true, true, true, concernedAgentErrors); s.afterTokenCall(new TokenLifecycleStrategyCallback(null, null) { @Override public void addTokenError(String errorMessage, Exception exception) { callBackCalled.set(true); } }, new TokenWrapper(), out); Assert.assertTrue(callBackCalled.get()); }