GatewayReceiverConfigValidator implements ConfigurationValidator<GatewayReceiver> { @Override public void validate(CacheElementOperation operation, GatewayReceiver config) throws IllegalArgumentException { if (operation == CacheElementOperation.CREATE) { if (config.getStartPort() == null) { config.setStartPort(DEFAULT_START_PORT); } if (config.getEndPort() == null) { config.setEndPort(DEFAULT_END_PORT); } if (config.getStartPort() > config.getEndPort()) { throw new IllegalArgumentException("Start port " + config.getStartPort() + " must be less than the end port " + config.getEndPort() + "."); } } }  @Override void validate(CacheElementOperation operation, GatewayReceiver config);  }
@Test public void startPort() throws Exception { receiver.setStartPort(6000); assertThatThrownBy(() -> validator.validate(CacheElementOperation.CREATE, receiver)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Start port 6000 must be less than the end port 5500"); }
@Test public void endPort() throws Exception { receiver.setEndPort(4000); assertThatThrownBy(() -> validator.validate(CacheElementOperation.CREATE, receiver)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Start port 5000 must be less than the end port 4000"); }
@Test public void startPortEndPort() throws Exception { receiver.setStartPort(2000); receiver.setEndPort(1900); assertThatThrownBy(() -> validator.validate(CacheElementOperation.CREATE, receiver)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Start port 2000 must be less than the end port 1900"); }