Code format hawkbit-dmf-rabbitmq-test (#1937)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -10,65 +10,65 @@
|
|||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-dmf-parent</artifactId>
|
<artifactId>hawkbit-dmf-parent</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>hawkbit-dmf-rabbitmq-test</artifactId>
|
<artifactId>hawkbit-dmf-rabbitmq-test</artifactId>
|
||||||
<name>hawkBit :: DMF :: RabbitMq Test module</name>
|
<name>hawkBit :: DMF :: RabbitMq Test module</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-repository-api</artifactId>
|
<artifactId>hawkbit-repository-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-repository-core</artifactId>
|
<artifactId>hawkbit-repository-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-repository-jpa</artifactId>
|
<artifactId>hawkbit-repository-jpa</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-dmf-api</artifactId>
|
<artifactId>hawkbit-dmf-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.amqp</groupId>
|
<groupId>org.springframework.amqp</groupId>
|
||||||
<artifactId>spring-rabbit-junit</artifactId>
|
<artifactId>spring-rabbit-junit</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rabbitmq</groupId>
|
<groupId>com.rabbitmq</groupId>
|
||||||
<artifactId>http-client</artifactId>
|
<artifactId>http-client</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.amqp</groupId>
|
<groupId>org.springframework.amqp</groupId>
|
||||||
<artifactId>spring-rabbit-test</artifactId>
|
<artifactId>spring-rabbit-test</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-repository-test</artifactId>
|
<artifactId>hawkbit-repository-test</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RabbitAvailable
|
@RabbitAvailable
|
||||||
@ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class,
|
@ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class,
|
||||||
TestConfiguration.class})
|
TestConfiguration.class })
|
||||||
@Import(TestChannelBinderConfiguration.class)
|
@Import(TestChannelBinderConfiguration.class)
|
||||||
// Dirty context is necessary to create a new vhost and recreate all necessary
|
// Dirty context is necessary to create a new vhost and recreate all necessary
|
||||||
// beans after every test class.
|
// beans after every test class.
|
||||||
@@ -93,6 +93,14 @@ public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTes
|
|||||||
return rabbitAdmin;
|
return rabbitAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getVirtualHost() {
|
||||||
|
return connectionFactory.getVirtualHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getPort() {
|
||||||
|
return connectionFactory.getPort();
|
||||||
|
}
|
||||||
|
|
||||||
private RabbitTemplate createDmfClient() {
|
private RabbitTemplate createDmfClient() {
|
||||||
final RabbitTemplate template = new RabbitTemplate(connectionFactory);
|
final RabbitTemplate template = new RabbitTemplate(connectionFactory);
|
||||||
template.setMessageConverter(new Jackson2JsonMessageConverter());
|
template.setMessageConverter(new Jackson2JsonMessageConverter());
|
||||||
@@ -102,12 +110,4 @@ public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTes
|
|||||||
return template;
|
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
|
@Configuration
|
||||||
public class AmqpTestConfiguration {
|
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
|
@Bean
|
||||||
SystemSecurityContextHolder systemSecurityContextHolder() {
|
SystemSecurityContextHolder systemSecurityContextHolder() {
|
||||||
return SystemSecurityContextHolder.getInstance();
|
return SystemSecurityContextHolder.getInstance();
|
||||||
@@ -79,17 +89,7 @@ public class AmqpTestConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
RabbitMqSetupService rabbitMqSetupService(){
|
RabbitMqSetupService rabbitMqSetupService() {
|
||||||
return new 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 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.CachingConnectionFactory;
|
||||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
import org.springframework.amqp.rabbit.junit.BrokerRunningSupport;
|
import org.springframework.amqp.rabbit.junit.BrokerRunningSupport;
|
||||||
import org.springframework.util.ObjectUtils;
|
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
|
* Creates and deletes a new virtual host if the rabbit mq management api is
|
||||||
* available.
|
* available.
|
||||||
@@ -32,17 +31,12 @@ import com.rabbitmq.http.client.domain.UserPermissions;
|
|||||||
@SuppressWarnings("squid:S2068")
|
@SuppressWarnings("squid:S2068")
|
||||||
public class RabbitMqSetupService {
|
public class RabbitMqSetupService {
|
||||||
|
|
||||||
private Client rabbitmqHttpClient;
|
|
||||||
|
|
||||||
private final com.rabbitmq.client.ConnectionFactory connectionFactory;
|
private final com.rabbitmq.client.ConnectionFactory connectionFactory;
|
||||||
|
|
||||||
private String virtualHost;
|
|
||||||
|
|
||||||
private final String hostname;
|
private final String hostname;
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
|
|
||||||
private final String password;
|
private final String password;
|
||||||
|
private Client rabbitmqHttpClient;
|
||||||
|
private String virtualHost;
|
||||||
|
|
||||||
public RabbitMqSetupService() {
|
public RabbitMqSetupService() {
|
||||||
|
|
||||||
@@ -53,18 +47,6 @@ public class RabbitMqSetupService {
|
|||||||
password = brokerSupport.getPassword();
|
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() {
|
public String getHttpApiUrl() {
|
||||||
return "http://" + getHostname() + ":15672/api/";
|
return "http://" + getHostname() + ":15672/api/";
|
||||||
}
|
}
|
||||||
@@ -85,6 +67,18 @@ public class RabbitMqSetupService {
|
|||||||
getRabbitmqHttpClient().deleteVhost(virtualHost);
|
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() {
|
private String getHostname() {
|
||||||
return hostname;
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ public interface TestRabbitListener {
|
|||||||
/**
|
/**
|
||||||
* handle incoming message
|
* handle incoming message
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message the message
|
||||||
* the message
|
|
||||||
*/
|
*/
|
||||||
void handleMessage(Message message);
|
void handleMessage(Message message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user