AMQPSettings { public final AMQPSettings fromURI(final String queueURI) { final Matcher matcher = URI_PATTERN.matcher(queueURI); if (!matcher.matches()) { throw new IllegalArgumentException("Queue URI doesn't matches the expected regexp"); } logger.info("Queue URI:{}", queueURI); queueOrExchangeName = matcher.group("name"); eventName = queueURI; if (matcher.groupCount() > 1) { final String queryParams = matcher.group("params"); if (StringUtils.isNotEmpty(queryParams)) { Arrays.stream(queryParams.split("\\s*\\&\\s*")).forEach(param -> { final String[] kv = param.split("\\s*=\\s*"); if (kv.length == 2) { if (kv[0].equalsIgnoreCase(String.valueOf(PARAM_EXCHANGE_TYPE))) { String value = kv[1]; if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("The provided exchange type is empty"); } exchangeType = value; } if (kv[0].equalsIgnoreCase((String.valueOf(PARAM_ROUTING_KEY)))) { String value = kv[1]; if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("The provided routing key is empty"); } routingKey = value; } if (kv[0].equalsIgnoreCase((String.valueOf(PARAM_DURABLE)))) { durable = Boolean.valueOf(kv[1]); } if (kv[0].equalsIgnoreCase((String.valueOf(PARAM_EXCLUSIVE)))) { exclusive = Boolean.valueOf(kv[1]); } if (kv[0].equalsIgnoreCase((String.valueOf(PARAM_AUTO_DELETE)))) { autoDelete = Boolean.valueOf(kv[1]); } if (kv[0].equalsIgnoreCase((String.valueOf(PARAM_DELIVERY_MODE)))) { setDeliveryMode(Integer.valueOf(kv[1])); } if (kv[0].equalsIgnoreCase((String.valueOf(PARAM_MAX_PRIORITY)))) { arguments.put("x-max-priority", Integer.valueOf(kv[1])); } } }); } } return this; } AMQPSettings(final Configuration config); final boolean isDurable(); final boolean isExclusive(); final boolean autoDelete(); final Map<String, Object> getArguments(); final String getContentEncoding(); void setQueue(String queueName); String getQueueOrExchangeName(); String getExchangeType(); String getRoutingKey(); int getDeliveryMode(); AMQPSettings setDeliveryMode(int deliveryMode); String getContentType(); final AMQPSettings fromURI(final String queueURI); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); String getEventName();  }
@Test(expected=IllegalArgumentException.class) public void testAMQPSettings_exchange_fromuri_wrongdeliverymode() { String exchangestring = "amqp_exchange:myExchangeName?exchangeType=topic&routingKey=test&deliveryMode=3"; Mockito.when(config.getProperty(Mockito.anyString(), Mockito.anyString())) .thenAnswer(invocation -> invocation.getArgument(1)); Mockito.when(config.getBooleanProperty(Mockito.anyString(), Mockito.anyBoolean())) .thenAnswer(invocation -> invocation.getArgument(1)); Mockito.when(config.getIntProperty(Mockito.anyString(), Mockito.anyInt())) .thenAnswer(invocation -> invocation.getArgument(1)); AMQPSettings settings = new AMQPSettings(config); settings = settings.fromURI(exchangestring); }