@Test public void anyVersionAccepted() throws IOException, ServletException, ServiceBrokerApiVersionException { String header = "header"; String version = BrokerApiVersion.API_VERSION_ANY; when(brokerApiVersion.getBrokerApiVersionHeader()).thenReturn(header); when(brokerApiVersion.getApiVersions()).thenReturn(version); when(request.getHeader(header)).thenReturn("version"); BrokerApiVersionInterceptor interceptor = new BrokerApiVersionInterceptor(brokerApiVersion); assertTrue(interceptor.preHandle(request, response, null)); verify(brokerApiVersion, atLeastOnce()).getApiVersions(); }
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServiceBrokerApiVersionException { if (version != null && !anyVersionAllowed()) { String apiVersion = request.getHeader(version.getBrokerApiVersionHeader()); boolean contains = false; for (String brokerApiVersion : version.getApiVersions().split(", ")) { if(brokerApiVersion.contains(".") && apiVersion.contains(".")){ if("x".equals(brokerApiVersion.split("[.]")[1]) && apiVersion.split("[.]")[0].equals(brokerApiVersion.split("[.]")[0])){ contains = true; break; } } if (brokerApiVersion.equals(apiVersion)){ contains = true; break; } } if (!contains) { throw new ServiceBrokerApiVersionException(version.getApiVersions(), apiVersion); } } return true; }
BrokerApiVersionInterceptor extends HandlerInterceptorAdapter { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServiceBrokerApiVersionException { if (version != null && !anyVersionAllowed()) { String apiVersion = request.getHeader(version.getBrokerApiVersionHeader()); boolean contains = false; for (String brokerApiVersion : version.getApiVersions().split(", ")) { if(brokerApiVersion.contains(".") && apiVersion.contains(".")){ if("x".equals(brokerApiVersion.split("[.]")[1]) && apiVersion.split("[.]")[0].equals(brokerApiVersion.split("[.]")[0])){ contains = true; break; } } if (brokerApiVersion.equals(apiVersion)){ contains = true; break; } } if (!contains) { throw new ServiceBrokerApiVersionException(version.getApiVersions(), apiVersion); } } return true; } }
BrokerApiVersionInterceptor extends HandlerInterceptorAdapter { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServiceBrokerApiVersionException { if (version != null && !anyVersionAllowed()) { String apiVersion = request.getHeader(version.getBrokerApiVersionHeader()); boolean contains = false; for (String brokerApiVersion : version.getApiVersions().split(", ")) { if(brokerApiVersion.contains(".") && apiVersion.contains(".")){ if("x".equals(brokerApiVersion.split("[.]")[1]) && apiVersion.split("[.]")[0].equals(brokerApiVersion.split("[.]")[0])){ contains = true; break; } } if (brokerApiVersion.equals(apiVersion)){ contains = true; break; } } if (!contains) { throw new ServiceBrokerApiVersionException(version.getApiVersions(), apiVersion); } } return true; } BrokerApiVersionInterceptor();  BrokerApiVersionInterceptor(BrokerApiVersion version); }
BrokerApiVersionInterceptor extends HandlerInterceptorAdapter { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServiceBrokerApiVersionException { if (version != null && !anyVersionAllowed()) { String apiVersion = request.getHeader(version.getBrokerApiVersionHeader()); boolean contains = false; for (String brokerApiVersion : version.getApiVersions().split(", ")) { if(brokerApiVersion.contains(".") && apiVersion.contains(".")){ if("x".equals(brokerApiVersion.split("[.]")[1]) && apiVersion.split("[.]")[0].equals(brokerApiVersion.split("[.]")[0])){ contains = true; break; } } if (brokerApiVersion.equals(apiVersion)){ contains = true; break; } } if (!contains) { throw new ServiceBrokerApiVersionException(version.getApiVersions(), apiVersion); } } return true; } BrokerApiVersionInterceptor();  BrokerApiVersionInterceptor(BrokerApiVersion version); boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object handler); }
BrokerApiVersionInterceptor extends HandlerInterceptorAdapter { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServiceBrokerApiVersionException { if (version != null && !anyVersionAllowed()) { String apiVersion = request.getHeader(version.getBrokerApiVersionHeader()); boolean contains = false; for (String brokerApiVersion : version.getApiVersions().split(", ")) { if(brokerApiVersion.contains(".") && apiVersion.contains(".")){ if("x".equals(brokerApiVersion.split("[.]")[1]) && apiVersion.split("[.]")[0].equals(brokerApiVersion.split("[.]")[0])){ contains = true; break; } } if (brokerApiVersion.equals(apiVersion)){ contains = true; break; } } if (!contains) { throw new ServiceBrokerApiVersionException(version.getApiVersions(), apiVersion); } } return true; } BrokerApiVersionInterceptor();  BrokerApiVersionInterceptor(BrokerApiVersion version); boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object handler);  }