Code format hawkbit-dmf-rabbitmq-test (#1937)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
||||
@@ -93,6 +93,14 @@ public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTes
|
||||
return rabbitAdmin;
|
||||
}
|
||||
|
||||
protected String getVirtualHost() {
|
||||
return connectionFactory.getVirtualHost();
|
||||
}
|
||||
|
||||
protected int getPort() {
|
||||
return connectionFactory.getPort();
|
||||
}
|
||||
|
||||
private RabbitTemplate createDmfClient() {
|
||||
final RabbitTemplate template = new RabbitTemplate(connectionFactory);
|
||||
template.setMessageConverter(new Jackson2JsonMessageConverter());
|
||||
@@ -102,12 +110,4 @@ public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTes
|
||||
return template;
|
||||
}
|
||||
|
||||
protected String getVirtualHost() {
|
||||
return connectionFactory.getVirtualHost();
|
||||
}
|
||||
|
||||
protected int getPort() {
|
||||
return connectionFactory.getPort();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,16 @@ import org.springframework.security.concurrent.DelegatingSecurityContextExecutor
|
||||
@Configuration
|
||||
public class AmqpTestConfiguration {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public RabbitTemplate rabbitTemplateForTest(final ConnectionFactory connectionFactory) {
|
||||
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
||||
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
|
||||
rabbitTemplate.setReplyTimeout(TimeUnit.SECONDS.toMillis(3));
|
||||
rabbitTemplate.setReceiveTimeout(TimeUnit.SECONDS.toMillis(3));
|
||||
return rabbitTemplate;
|
||||
}
|
||||
|
||||
@Bean
|
||||
SystemSecurityContextHolder systemSecurityContextHolder() {
|
||||
return SystemSecurityContextHolder.getInstance();
|
||||
@@ -82,14 +92,4 @@ public class AmqpTestConfiguration {
|
||||
RabbitMqSetupService rabbitMqSetupService() {
|
||||
return new RabbitMqSetupService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public RabbitTemplate rabbitTemplateForTest(final ConnectionFactory connectionFactory) {
|
||||
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
||||
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
|
||||
rabbitTemplate.setReplyTimeout(TimeUnit.SECONDS.toMillis(3));
|
||||
rabbitTemplate.setReceiveTimeout(TimeUnit.SECONDS.toMillis(3));
|
||||
return rabbitTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,13 @@ import java.util.UUID;
|
||||
|
||||
import jakarta.annotation.PreDestroy;
|
||||
|
||||
import com.rabbitmq.http.client.Client;
|
||||
import com.rabbitmq.http.client.domain.UserPermissions;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.junit.BrokerRunningSupport;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.rabbitmq.http.client.Client;
|
||||
import com.rabbitmq.http.client.domain.UserPermissions;
|
||||
|
||||
/**
|
||||
* Creates and deletes a new virtual host if the rabbit mq management api is
|
||||
* available.
|
||||
@@ -32,17 +31,12 @@ import com.rabbitmq.http.client.domain.UserPermissions;
|
||||
@SuppressWarnings("squid:S2068")
|
||||
public class RabbitMqSetupService {
|
||||
|
||||
private Client rabbitmqHttpClient;
|
||||
|
||||
private final com.rabbitmq.client.ConnectionFactory connectionFactory;
|
||||
|
||||
private String virtualHost;
|
||||
|
||||
private final String hostname;
|
||||
|
||||
private final String username;
|
||||
|
||||
private final String password;
|
||||
private Client rabbitmqHttpClient;
|
||||
private String virtualHost;
|
||||
|
||||
public RabbitMqSetupService() {
|
||||
|
||||
@@ -53,18 +47,6 @@ public class RabbitMqSetupService {
|
||||
password = brokerSupport.getPassword();
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S112")
|
||||
private synchronized Client getRabbitmqHttpClient() {
|
||||
if (rabbitmqHttpClient == null) {
|
||||
try {
|
||||
rabbitmqHttpClient = new Client(new URL(getHttpApiUrl()), getUsername(), getPassword());
|
||||
} catch (final MalformedURLException | URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return rabbitmqHttpClient;
|
||||
}
|
||||
|
||||
public String getHttpApiUrl() {
|
||||
return "http://" + getHostname() + ":15672/api/";
|
||||
}
|
||||
@@ -85,6 +67,18 @@ public class RabbitMqSetupService {
|
||||
getRabbitmqHttpClient().deleteVhost(virtualHost);
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S112")
|
||||
private synchronized Client getRabbitmqHttpClient() {
|
||||
if (rabbitmqHttpClient == null) {
|
||||
try {
|
||||
rabbitmqHttpClient = new Client(new URL(getHttpApiUrl()), getUsername(), getPassword());
|
||||
} catch (final MalformedURLException | URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return rabbitmqHttpClient;
|
||||
}
|
||||
|
||||
private String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ public interface TestRabbitListener {
|
||||
/**
|
||||
* handle incoming message
|
||||
*
|
||||
* @param message
|
||||
* the message
|
||||
* @param message the message
|
||||
*/
|
||||
void handleMessage(Message message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user