Skip to content

Commit 5b8568b

Browse files
committed
refactor(dispatcher): extract testsupport classes & move current suites to match associated classes in main
1 parent e2a35f1 commit 5b8568b

13 files changed

Lines changed: 51 additions & 38 deletions

hub/dispatcher/src/test/java/com/hubsante/hub/service/HubApplicationTests.java renamed to hub/dispatcher/src/test/java/com/hubsante/hub/HubApplicationTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.hubsante.hub.service;
16+
package com.hubsante.hub;
1717

18-
import com.hubsante.hub.HubApplication;
1918
import lombok.val;
19+
import org.junit.jupiter.api.DisplayName;
2020
import org.junit.jupiter.api.Test;
2121
import org.springframework.boot.SpringBootConfiguration;
2222
import org.springframework.boot.test.context.SpringBootTest;
@@ -29,10 +29,11 @@
2929
@SpringBootConfiguration
3030
@ContextConfiguration(
3131
classes = HubApplication.class,
32-
initializers = HubApplicationTests.Initializer.class)
33-
class HubApplicationTests {
32+
initializers = HubApplicationTest.Initializer.class)
33+
class HubApplicationTest {
3434
@Test
35-
void contextLoads() {}
35+
@DisplayName("should start the Spring application context")
36+
void shouldStartApplicationContext() {}
3637

3738
public static class Initializer
3839
implements ApplicationContextInitializer<ConfigurableApplicationContext> {

hub/dispatcher/src/test/java/com/hubsante/hub/service/HubConfigurationTest.java renamed to hub/dispatcher/src/test/java/com/hubsante/hub/config/HubConfigurationTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.hubsante.hub.service;
16+
package com.hubsante.hub.config;
1717

18-
import com.hubsante.hub.config.HubConfiguration;
1918
import java.io.File;
2019
import java.io.FileWriter;
2120
import java.nio.charset.StandardCharsets;
2221
import java.util.List;
2322
import org.junit.jupiter.api.Assertions;
2423
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.DisplayName;
2525
import org.junit.jupiter.api.Test;
2626
import org.springframework.test.util.ReflectionTestUtils;
2727

@@ -44,7 +44,8 @@ void setUp() throws Exception {
4444
}
4545

4646
@Test
47-
void testGetSupportedMessages_host1() throws Exception {
47+
@DisplayName("should load the common messages and the messages specific to the vhost")
48+
void shouldLoadCommonAndVhostSpecificMessages() throws Exception {
4849
List<String> supportedMessages = hubConfig.loadSupportedMessages("host_1");
4950

5051
Assertions.assertEquals(4, supportedMessages.size());
@@ -55,7 +56,8 @@ void testGetSupportedMessages_host1() throws Exception {
5556
}
5657

5758
@Test
58-
void testGetSupportedMessages_host2() throws Exception {
59+
@DisplayName("should load a different message list for a different vhost")
60+
void shouldLoadMessagesForAnotherVhost() throws Exception {
5961
List<String> supportedMessages = hubConfig.loadSupportedMessages("host_2");
6062

6163
Assertions.assertEquals(4, supportedMessages.size());
@@ -66,7 +68,8 @@ void testGetSupportedMessages_host2() throws Exception {
6668
}
6769

6870
@Test
69-
void testGetSupportedMessages_unknownHost() throws Exception {
71+
@DisplayName("should fall back to the common messages only for an unknown vhost")
72+
void shouldLoadCommonMessagesOnlyForUnknownVhost() throws Exception {
7073
List<String> supportedMessages = hubConfig.loadSupportedMessages("unknown");
7174

7275
Assertions.assertEquals(2, supportedMessages.size());

hub/dispatcher/src/test/java/com/hubsante/hub/service/ClientPropertiesRegistryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public void shouldLoadClientConfiguration() {
7070
}
7171

7272
@Test
73-
void should_fail_when_loading_invalid_yaml() {
73+
@DisplayName("should fail when loading an invalid clients YAML")
74+
void shouldFailWhenLoadingInvalidYaml() {
7475
String exceptionPrefix = "Invalid clients configuration:\n\n";
7576

7677
// perimeter wth no name

hub/dispatcher/src/test/java/com/hubsante/hub/service/DispatcherTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import static com.hubsante.hub.config.AmqpConfiguration.*;
1919
import static com.hubsante.hub.config.Constants.*;
20-
import static com.hubsante.hub.service.utils.MessageTestUtils.*;
21-
import static com.hubsante.hub.service.utils.MetricsUtils.*;
20+
import static com.hubsante.hub.testsupport.MessageTestUtils.*;
21+
import static com.hubsante.hub.testsupport.MetricsUtils.*;
2222
import static org.junit.jupiter.api.Assertions.*;
2323
import static org.mockito.ArgumentMatchers.any;
2424
import static org.mockito.ArgumentMatchers.anyString;
@@ -478,7 +478,7 @@ public void shouldCallConversionServiceForCISUVersionConvertedMessagesFromNexsis
478478
@ParameterizedTest
479479
@ValueSource(strings = {"15-sas_v1.0", "15-smur_v1.7", "15-gps_v2.0", "15-notexisting_v1.0"})
480480
@DisplayName("should send message to current vhost")
481-
public void testSendMessageToCurrentVhost(String vhost) throws IOException {
481+
public void shouldSendMessageToCurrentVhost(String vhost) throws IOException {
482482
Message message = createMessage("EDXL-DE", JSON, SAMU_A_ROUTING_KEY, SAMU_V3_ROUTING_KEY);
483483

484484
doReturn(vhost).when(hubConfig).getVhost();
@@ -626,7 +626,7 @@ public void handleDLQInfo() throws Exception {
626626

627627
@Test
628628
@DisplayName("malformed message should throw an exception")
629-
public void malformedMessagefailed() throws IOException {
629+
public void shouldRejectMalformedMessage() throws IOException {
630630

631631
// we test that the message has been rejected if we can't parse it
632632
Message receivedMessage =
@@ -970,8 +970,7 @@ public void shouldHandleConversionServiceError() throws IOException {
970970
assertEquals(receivedMessage, handledMessage);
971971
}
972972

973-
// disabling until we restore info message sending to outer hubex
974-
@Disabled
973+
@Disabled("Re-enable when info message sending to outer hubex is restored")
975974
@Test
976975
@DisplayName("should reject message if no health actor is involved")
977976
public void shouldRejectMessageIfNoHealthActorIsInvolved() throws IOException {
@@ -1378,7 +1377,7 @@ public void shouldNotCallPersistenceServiceForDirectDispatch() throws Exception
13781377

13791378
@Test
13801379
@DisplayName("should transfer all messages received from converter as array")
1381-
public void transferMultipleMessagedFromConverter() throws IOException {
1380+
public void shouldTransferEveryMessageReturnedByConverter() throws IOException {
13821381
Message message = createMessage("EDXL-DE", JSON, SAMU_A_ROUTING_KEY, SAMU_V1_ROUTING_KEY);
13831382
String exchangeName = "transfer_15-15_v2.1_to_15-15_v1.5";
13841383

hub/dispatcher/src/test/java/com/hubsante/hub/service/LogIntegrityTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.nio.file.Path;
3737
import java.nio.file.Paths;
3838
import java.util.Objects;
39+
import org.junit.jupiter.api.DisplayName;
3940
import org.junit.jupiter.api.Test;
4041
import org.slf4j.LoggerFactory;
4142
import org.springframework.amqp.core.Message;
@@ -170,7 +171,8 @@ void setup() throws Exception {
170171
}
171172

172173
@Test
173-
void dispatchLogsHashWhenReceivingMessage() {
174+
@DisplayName("should log the hash of the received body on reception")
175+
void shouldLogHashOfReceivedBody() {
174176
// Arrange: set up MessageHandler with a ListAppender to capture logs
175177
Logger logger = (Logger) LoggerFactory.getLogger(MessageHandler.class);
176178
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
@@ -191,7 +193,8 @@ void dispatchLogsHashWhenReceivingMessage() {
191193
}
192194

193195
@Test
194-
void dispatchLogsHashBeforeSendingMessage() {
196+
@DisplayName("should log the hash of the forwarded body before sending")
197+
void shouldLogHashOfForwardedBody() {
195198
// Arrange: set up MessageHandler with a ListAppender to capture logs
196199
Logger logger = (Logger) LoggerFactory.getLogger(MessageHandler.class);
197200
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();

hub/dispatcher/src/test/java/com/hubsante/hub/service/RabbitIntegrationAbstract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.hubsante.hub.service;
1717

1818
import com.hubsante.hub.HubApplication;
19-
import com.hubsante.hub.service.utils.SSLTestUtils;
19+
import com.hubsante.hub.testsupport.SSLTestUtils;
2020
import com.hubsante.model.EdxlHandler;
2121
import com.rabbitmq.client.DefaultSaslConfig;
2222
import java.io.IOException;

hub/dispatcher/src/test/java/com/hubsante/hub/service/RabbitIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package com.hubsante.hub.service;
1717

18-
import static com.hubsante.hub.service.utils.MessageTestUtils.createInvalidMessage;
19-
import static com.hubsante.hub.service.utils.MessageTestUtils.createMessage;
18+
import static com.hubsante.hub.testsupport.MessageTestUtils.createInvalidMessage;
19+
import static com.hubsante.hub.testsupport.MessageTestUtils.createMessage;
2020
import static org.junit.jupiter.api.Assertions.*;
2121

2222
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -45,7 +45,7 @@ public class RabbitIntegrationTest extends RabbitIntegrationAbstract {
4545
@Test
4646
@DisplayName(
4747
"message dispatched to exchange is received by a consumer listening to the right queue")
48-
public void dispatchTest() throws Exception {
48+
public void shouldDeliverToRecipientQueue() throws Exception {
4949
Message published = createMessage("EDXL-DE", JSON);
5050
RabbitTemplate samuA_publisher =
5151
getCustomRabbitTemplate(

hub/dispatcher/src/test/java/com/hubsante/hub/service/RabbitMQBatchTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package com.hubsante.hub.service;
1717

18-
import static com.hubsante.hub.service.utils.MessageTestUtils.createInvalidMessage;
19-
import static com.hubsante.hub.service.utils.MessageTestUtils.createMessage;
18+
import static com.hubsante.hub.testsupport.MessageTestUtils.createInvalidMessage;
19+
import static com.hubsante.hub.testsupport.MessageTestUtils.createMessage;
2020
import static org.junit.jupiter.api.Assertions.*;
2121

2222
import java.io.IOException;
@@ -62,7 +62,7 @@ public void setUp() throws IOException, InterruptedException {
6262
"queues");
6363
}
6464

65-
@Disabled
65+
@Disabled("Wall-clock performance test, run manually; excluded test task")
6666
@Test
6767
@DisplayName("publish and consume batch of 1000 messages")
6868
public void consumeBatch() throws IOException, InterruptedException {

hub/dispatcher/src/test/java/com/hubsante/hub/service/utils/MessageTestUtils.java renamed to hub/dispatcher/src/test/java/com/hubsante/hub/testsupport/MessageTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.hubsante.hub.service.utils;
16+
package com.hubsante.hub.testsupport;
1717

1818
import static com.hubsante.hub.config.AmqpConfiguration.*;
1919

hub/dispatcher/src/test/java/com/hubsante/hub/service/utils/MetricsUtils.java renamed to hub/dispatcher/src/test/java/com/hubsante/hub/testsupport/MetricsUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.hubsante.hub.service.utils;
16+
package com.hubsante.hub.testsupport;
1717

1818
import static com.hubsante.hub.config.Constants.*;
1919

0 commit comments

Comments
 (0)