Skip to content
Snippets Groups Projects
Verified Commit 4d4bc51d authored by Martin Weise's avatar Martin Weise
Browse files

Fixed more tests with new vhost

parent 828f5af2
No related branches found
No related tags found
2 merge requests!163Relase 1.3.0,!159Large update
...@@ -23,6 +23,7 @@ logging.level.at.tuwien.=trace ...@@ -23,6 +23,7 @@ logging.level.at.tuwien.=trace
# broker service # broker service
spring.rabbitmq.host=dbrepo-broker-service spring.rabbitmq.host=dbrepo-broker-service
spring.rabbitmq.virtual-host=/
spring.rabbitmq.username=guest spring.rabbitmq.username=guest
spring.rabbitmq.password=guest spring.rabbitmq.password=guest
......
...@@ -10,6 +10,8 @@ import at.tuwien.repository.elastic.TableColumnIdxRepository; ...@@ -10,6 +10,8 @@ import at.tuwien.repository.elastic.TableColumnIdxRepository;
import at.tuwien.repository.elastic.TableIdxRepository; import at.tuwien.repository.elastic.TableIdxRepository;
import at.tuwien.repository.jpa.TableRepository; import at.tuwien.repository.jpa.TableRepository;
import at.tuwien.utils.AmqpUtils; import at.tuwien.utils.AmqpUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
...@@ -20,6 +22,7 @@ import org.springframework.boot.test.context.SpringBootTest; ...@@ -20,6 +22,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.io.IOException;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
...@@ -48,6 +51,9 @@ public class MessageQueueServiceIntegrationTest extends BaseUnitTest { ...@@ -48,6 +51,9 @@ public class MessageQueueServiceIntegrationTest extends BaseUnitTest {
@Autowired @Autowired
private AmqpUtils amqpUtils; private AmqpUtils amqpUtils;
@Autowired
private Channel channel;
@Autowired @Autowired
private MessageQueueService messageQueueService; private MessageQueueService messageQueueService;
...@@ -69,12 +75,12 @@ public class MessageQueueServiceIntegrationTest extends BaseUnitTest { ...@@ -69,12 +75,12 @@ public class MessageQueueServiceIntegrationTest extends BaseUnitTest {
} }
@Test @Test
public void init_succeeds() throws AmqpException { public void init_succeeds() throws AmqpException, IOException {
/* mock */ /* mock */
channel.exchangeDeclare(DATABASE_1_EXCHANGE, BuiltinExchangeType.FANOUT, true, false, null);
when(tableRepository.findAll()) when(tableRepository.findAll())
.thenReturn(List.of(TABLE_1, TABLE_2)); .thenReturn(List.of(TABLE_1, TABLE_2));
amqpUtils.createExchange(DATABASE_1_EXCHANGE);
/* test */ /* test */
assertTrue(amqpUtils.exchangeExists(DATABASE_1_EXCHANGE)); assertTrue(amqpUtils.exchangeExists(DATABASE_1_EXCHANGE));
......
package at.tuwien.utils; package at.tuwien.utils;
import at.tuwien.api.amqp.CreateExchangeDto;
import at.tuwien.api.amqp.ExchangeDto; import at.tuwien.api.amqp.ExchangeDto;
import at.tuwien.api.amqp.QueueDto; import at.tuwien.api.amqp.QueueDto;
import at.tuwien.config.AmqpConfig; import at.tuwien.config.AmqpConfig;
...@@ -32,22 +31,6 @@ public class AmqpUtils { ...@@ -32,22 +31,6 @@ public class AmqpUtils {
this.amqpConfig = amqpConfig; this.amqpConfig = amqpConfig;
} }
public void createExchange(String exchange) {
exchange = exchange.replace("/", "%2F");
final URI uri = URI.create("http://" + amqpConfig.getAmpqHost() + ":15672/api/exchanges/dbrepo/" + exchange);
final CreateExchangeDto payload = CreateExchangeDto.builder()
.type("fanout")
.autoDelete(false)
.durable(true)
.internal(false)
.build();
final ResponseEntity<Void> response = restTemplate.exchange(uri, HttpMethod.PUT, new HttpEntity<>(payload), Void.class);
if (!response.getStatusCode().equals(HttpStatus.CREATED)) {
log.error("Failed to create exchange, code is {}", response.getStatusCode());
throw new RuntimeException("Failed to create exchange");
}
}
public boolean exchangeExists(String exchange) { public boolean exchangeExists(String exchange) {
final ResponseEntity<ExchangeDto[]> response = restTemplate.exchange("/api/exchanges", HttpMethod.GET, null, ExchangeDto[].class); final ResponseEntity<ExchangeDto[]> response = restTemplate.exchange("/api/exchanges", HttpMethod.GET, null, ExchangeDto[].class);
if (!response.getStatusCode().equals(HttpStatus.OK)) { if (!response.getStatusCode().equals(HttpStatus.OK)) {
...@@ -67,7 +50,7 @@ public class AmqpUtils { ...@@ -67,7 +50,7 @@ public class AmqpUtils {
} }
public boolean queueExists(String queue) { public boolean queueExists(String queue) {
final URI uri = URI.create("http://" + amqpConfig.getAmpqHost() + ":15672/api/queues/dbrepo/"); final URI uri = URI.create("http://" + amqpConfig.getAmpqHost() + ":15672/api/queues/%2F/");
final ResponseEntity<QueueDto[]> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(null), QueueDto[].class); final ResponseEntity<QueueDto[]> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(null), QueueDto[].class);
if (!response.getStatusCode().equals(HttpStatus.OK)) { if (!response.getStatusCode().equals(HttpStatus.OK)) {
log.error("Failed to find queue, code is {}", response.getStatusCode()); log.error("Failed to find queue, code is {}", response.getStatusCode());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment