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"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-dmf-rabbitmq-test</artifactId>
|
||||
<name>hawkBit :: DMF :: RabbitMq Test module</name>
|
||||
<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>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-dmf-rabbitmq-test</artifactId>
|
||||
<name>hawkBit :: DMF :: RabbitMq Test module</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-jpa</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-junit</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rabbitmq</groupId>
|
||||
<artifactId>http-client</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-test</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-jpa</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-dmf-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-junit</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rabbitmq</groupId>
|
||||
<artifactId>http-client</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-test</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
@Slf4j
|
||||
@RabbitAvailable
|
||||
@ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, AmqpTestConfiguration.class,
|
||||
TestConfiguration.class})
|
||||
TestConfiguration.class })
|
||||
@Import(TestChannelBinderConfiguration.class)
|
||||
// Dirty context is necessary to create a new vhost and recreate all necessary
|
||||
// beans after every test class.
|
||||
@@ -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();
|
||||
@@ -79,17 +89,7 @@ public class AmqpTestConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
RabbitMqSetupService rabbitMqSetupService(){
|
||||
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