Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OZ-669: Add WatcherInitRoute to openmrs-watcher module #66

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.openmrs.eip.mysql.watcher.route;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

/**
* This route is used to initialize the OpenMRS watcher. It is only used once when the application
* starts up.
*/
@Component
public class WatcherInitRoute extends RouteBuilder {

@Override
public void configure() {
from("scheduler:openmrs-watcher?initialDelay=500&repeatCount=1").routeId("openmrs-watcher-init-route")
.to("openmrs-watcher:init").end();
corneliouzbett marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.openmrs.eip.mysql.watcher.route;

import static org.apache.camel.builder.AdviceWith.adviceWith;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.MockEndpoints;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.test.annotation.DirtiesContext;

@MockEndpoints
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class WatcherInitRouteTest extends BaseWatcherRouteTest {

@EndpointInject("mock:init")
private MockEndpoint mockInit;

@BeforeEach
public void setup() throws Exception {
mockInit.reset();

camelContext.addRoutes(new WatcherInitRoute());

adviceWith(camelContext, "openmrs-watcher-init-route", route -> {
route.replaceFromWith("direct:start");
route.weaveByToUri("openmrs-watcher:init").replace().to("mock:init");
});
}

@Test
public void shouldInitializeOpenmrsWatcherRoute() throws Exception {
// Arrange
mockInit.expectedMessageCount(1);

// Act
ProducerTemplate template = camelContext.createProducerTemplate();
template.sendBody("direct:start", null);

// Assert
mockInit.assertIsSatisfied();
}

@Test
public void shouldRegisteredOpenmrsInitRoute() {
assertNotNull(camelContext.getRoute("openmrs-watcher-init-route"));
}
}
Loading