Feature add missing entity events (#640)
* introduce CRD event interfaces and add missing events for entities Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * extend EntityIdEvent by TenantAwareEvent Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * add tests for additional events and skip test preperation events Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * add missing expected events to tests Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * add target filter query CUD events Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * fix order imports Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * fix javadoc link Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com> * add neccessary EventType mapping for serialization Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import org.junit.Assert;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.event.ApplicationEventMulticaster;
|
||||
@@ -47,6 +48,25 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
|
||||
private EventCaptor eventCaptor;
|
||||
|
||||
/**
|
||||
* Publishes a reset counter marker event on the context to reset the
|
||||
* current counted events. This allows test to prepare a setup such in
|
||||
* {@code @Before} annotations which are actually counted to the executed
|
||||
* test-method and maybe fire events which are not covered / recognized by
|
||||
* the test-method itself and reset the counter again.
|
||||
*
|
||||
* Note that this approach is only working when using a single-thread
|
||||
* executor in the ApplicationEventMultiCaster, so the order of the events
|
||||
* keep the same.
|
||||
*
|
||||
* @param publisher
|
||||
* the {@link ApplicationEventPublisher} to publish the marker
|
||||
* event to
|
||||
*/
|
||||
public static void publishResetMarkerEvent(final ApplicationEventPublisher publisher) {
|
||||
publisher.publishEvent(new ResetCounterMarkerEvent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTestMethod(final TestContext testContext) throws Exception {
|
||||
final Optional<Expect[]> expectedEvents = getExpectationsFrom(testContext.getTestMethod());
|
||||
@@ -123,6 +143,12 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
public void onApplicationEvent(final RemoteApplicationEvent event) {
|
||||
LOGGER.debug("Received event {}", event.getClass().getSimpleName());
|
||||
|
||||
if (ResetCounterMarkerEvent.class.isAssignableFrom(event.getClass())) {
|
||||
LOGGER.debug("Retrieving reset counter marker event - resetting counters");
|
||||
capturedEvents.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof RemoteTenantAwareEvent) {
|
||||
assertThat(((RemoteTenantAwareEvent) event).getTenant()).isNotEmpty();
|
||||
}
|
||||
@@ -150,4 +176,12 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
|
||||
}
|
||||
|
||||
private static final class ResetCounterMarkerEvent extends RemoteApplicationEvent {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ResetCounterMarkerEvent() {
|
||||
super(new Object(), "resetcounter");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.auditing.AuditingHandler;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -196,6 +197,9 @@ public abstract class AbstractIntegrationTest {
|
||||
@Autowired
|
||||
protected ServiceMatcher serviceMatcher;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
@Rule
|
||||
public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule();
|
||||
|
||||
@@ -263,6 +267,7 @@ public abstract class AbstractIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
|
||||
final String description = "Updated description.";
|
||||
|
||||
osType = securityRule
|
||||
@@ -281,6 +286,15 @@ public abstract class AbstractIntegrationTest {
|
||||
.update(entityFactory.softwareModuleType().update(runtimeType.getId()).description(description)));
|
||||
|
||||
standardDsType = securityRule.runAsPrivileged(() -> testdataFactory.findOrCreateDefaultTestDsType());
|
||||
|
||||
// publish the reset counter market event to reset the counters after
|
||||
// setup. The setup is transparent by the test and its @ExpectedEvent
|
||||
// counting so we reset the counter here after the setup. Note that this
|
||||
// approach is only working when using a single-thread executor in the
|
||||
// ApplicationEventMultiCaster which the TestConfiguration is doing so
|
||||
// the order of the events keep the same.
|
||||
EventVerifier.publishResetMarkerEvent(eventPublisher);
|
||||
|
||||
}
|
||||
|
||||
private static String artifactDirectory = "./artifactrepo/" + RandomStringUtils.randomAlphanumeric(20);
|
||||
|
||||
Reference in New Issue
Block a user