Skip to content

Commit 0b80b7a

Browse files
committed
add javadoc for solace-broker-api test classes
1 parent 1c38e52 commit 0b80b7a

8 files changed

Lines changed: 67 additions & 0 deletions

File tree

solace-broker-api/src/test/java/org/orgname/solace/broker/api/SolaceBrokerAPIApplicationTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import static org.junit.jupiter.api.Assertions.assertNotNull;
66

7+
/**
8+
* Unit test for {@link SolaceBrokerAPIApplication}.
9+
* Verifies that the main application class can be instantiated.
10+
*/
711
class SolaceBrokerAPIApplicationTest {
812

913
@Test

solace-broker-api/src/test/java/org/orgname/solace/broker/api/controller/MessageApiContractIntegrationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
3737
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
3838

39+
/**
40+
* Integration tests for the Message API contract.
41+
* This class verifies the full flow from the REST controller through the service layer
42+
* to the database, ensuring that the API contract is respected and that messages
43+
* are correctly persisted and retrieved. It uses an in-memory database and mocks
44+
* the Solace broker integration.
45+
*/
3946
@SpringBootTest(properties = {
4047
"spring.datasource.url=jdbc:h2:mem:message-api-contract-test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false",
4148
"spring.datasource.driver-class-name=org.h2.Driver",

solace-broker-api/src/test/java/org/orgname/solace/broker/api/controller/MessageControllerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
4242
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4343

44+
/**
45+
* Unit tests for {@link MessageController}.
46+
* This class uses a {@link MockMvc} setup with {@link StubDatabase} and {@link StubDirectPublisherService}
47+
* to verify the controller's behavior, including message retrieval, filtering, and publishing flow.
48+
*/
4449
class MessageControllerTest {
4550

4651
private StubDatabase database;
@@ -612,6 +617,10 @@ private static Message storedMessage(String innerMessageId, String destination,
612617
return message;
613618
}
614619

620+
/**
621+
* Stub implementation of {@link DirectPublisherService} for testing.
622+
* Allows simulating successful or failed message publication to a Solace broker.
623+
*/
615624
private static final class StubDirectPublisherService implements DirectPublisherService {
616625
private PublishMessageResponseDTO response;
617626
private IllegalArgumentException illegalArgumentException;
@@ -629,6 +638,9 @@ public PublishMessageResponseDTO sendMessage(String topicName, String content, D
629638
}
630639
}
631640

641+
/**
642+
* In-memory database stub for testing the controller's logic without a real database.
643+
*/
632644
private static final class StubDatabase implements Database {
633645
private final List<Message> storedMessages = new ArrayList<>();
634646
private Message lastSavedMessage;

solace-broker-api/src/test/java/org/orgname/solace/broker/api/controller/MessageControllerWebMvcTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
4545
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4646

47+
/**
48+
* Web MVC tests for {@link MessageController}.
49+
* This class uses {@link WebMvcTest} to perform integration tests on the web layer,
50+
* mocking the service dependencies to verify request mapping, validation, and JSON serialization.
51+
*/
4752
@WebMvcTest(controllers = MessageController.class)
4853
@Import(ApiExceptionHandler.class)
4954
class MessageControllerWebMvcTest {

solace-broker-api/src/test/java/org/orgname/solace/broker/api/repository/MessageRepositoryDataJpaTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

20+
/**
21+
* Data JPA tests for {@link MessageRepository}.
22+
* This class tests the persistence layer and filtering capabilities of the message repository
23+
* using an in-memory H2 database configured to mimic MySQL behavior.
24+
*/
2025
@DataJpaTest(properties = {
2126
"spring.datasource.url=jdbc:h2:mem:message-repository-test;MODE=MySQL;DB_CLOSE_DELAY=-1",
2227
"spring.datasource.driver-class-name=org.h2.Driver",
@@ -168,6 +173,9 @@ void shouldFilterMessagesByStalePendingOnly() {
168173
assertEquals(true, response.getItems().getFirst().isStalePending());
169174
}
170175

176+
/**
177+
* Persists a message with default payload type (BINARY) and status (PUBLISHED).
178+
*/
171179
private void persistMessage(
172180
String innerMessageId,
173181
String destination,
@@ -177,6 +185,9 @@ private void persistMessage(
177185
persistMessage(innerMessageId, destination, deliveryMode, PayloadType.BINARY, priority, PublishStatus.PUBLISHED, createdAt);
178186
}
179187

188+
/**
189+
* Persists a message with the default payload type (BINARY).
190+
*/
180191
private void persistMessage(
181192
String innerMessageId,
182193
String destination,
@@ -187,6 +198,19 @@ private void persistMessage(
187198
persistMessage(innerMessageId, destination, deliveryMode, PayloadType.BINARY, priority, publishStatus, createdAt);
188199
}
189200

201+
/**
202+
* Persists a message to the database for testing purposes.
203+
* This method directly interacts with the {@link EntityManager} to ensure that timestamps
204+
* are correctly set, as they are often handled by JPA/Hibernate lifecycle events.
205+
*
206+
* @param innerMessageId the unique identifier for the message
207+
* @param destination the Solace topic destination
208+
* @param deliveryMode the delivery mode (e.g., PERSISTENT, DIRECT)
209+
* @param payloadType the type of payload (e.g., TEXT, JSON, BINARY)
210+
* @param priority the message priority
211+
* @param publishStatus the current publish status
212+
* @param createdAt the creation timestamp
213+
*/
190214
private void persistMessage(
191215
String innerMessageId,
192216
String destination,

solace-broker-api/src/test/java/org/orgname/solace/broker/api/service/AccessPropertiesImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
import static org.junit.jupiter.api.Assertions.assertEquals;
1414
import static org.junit.jupiter.api.Assertions.assertNotNull;
1515

16+
/**
17+
* Unit tests for {@link AccessPropertiesImpl}.
18+
* Verifies that broker connection properties are correctly extracted from environment variables
19+
* or provided parameters.
20+
*/
1621
class AccessPropertiesImplTest {
1722

1823
private static final String HOST = "test-host";

solace-broker-api/src/test/java/org/orgname/solace/broker/api/service/DatabaseImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
import static org.mockito.Mockito.mock;
2929
import static org.mockito.Mockito.when;
3030

31+
/**
32+
* Unit tests for {@link DatabaseImpl}.
33+
* This class verifies the business logic for message persistence, status updates,
34+
* and filtering, mocking the {@link MessageRepository}.
35+
*/
3136
class DatabaseImplTest {
3237

3338
private MessageRepository messageRepository;

solace-broker-api/src/test/java/org/orgname/solace/broker/api/service/DirectPublisherServiceImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
import static org.junit.jupiter.api.Assertions.assertThrows;
1414
import static org.orgname.solace.broker.api.constants.Constants.ERROR_EMPTY_MESSAGE_OR_TOPIC_NAME;
1515

16+
/**
17+
* Unit tests for {@link DirectPublisherServiceImpl}.
18+
* Verifies message publishing logic, input validation, and configuration handling
19+
* for the Solace broker integration.
20+
*/
1621
class DirectPublisherServiceImplTest {
1722

1823
private final DirectPublisherServiceImpl directPublisherService = new DirectPublisherServiceImpl(new StubAccessProperties());

0 commit comments

Comments
 (0)