-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#976): Disable/Override standard Citrus reporters
- Loading branch information
Thorsten Schlathoelter
committed
Sep 16, 2023
1 parent
a9026ea
commit c82eea8
Showing
4 changed files
with
236 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../citrus-spring/src/test/java/org/citrusframework/reporter/OverrideReporterConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.citrusframework.reporter; | ||
|
||
import org.citrusframework.UnitTestSupport; | ||
import org.citrusframework.report.HtmlReporter; | ||
import org.citrusframework.report.JUnitReporter; | ||
import org.citrusframework.report.LoggingReporter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.citrusframework.reporter.ReporterConfig.CITRUS_HTML_REPORTER; | ||
import static org.citrusframework.reporter.ReporterConfig.CITRUS_JUNIT_REPORTER; | ||
import static org.citrusframework.reporter.ReporterConfig.CITRUS_LOGGING_REPORTER; | ||
|
||
@ContextConfiguration(classes = OverrideReporterConfigTest.OverrideReporterConfiguration.class) | ||
public class OverrideReporterConfigTest extends UnitTestSupport { | ||
|
||
@Test | ||
public void testOverridesLoggingReporter() { | ||
Assert.assertTrue(applicationContext.getBean(CITRUS_LOGGING_REPORTER) instanceof OverrideLoggingReporter); | ||
} | ||
|
||
@Test | ||
public void testOverridesJunitReporter() { | ||
Assert.assertTrue(applicationContext.getBean(CITRUS_JUNIT_REPORTER) instanceof OverrideJUnitReporter); | ||
} | ||
|
||
@Test | ||
public void testOverridesHtmlReporter() { | ||
Assert.assertTrue(applicationContext.getBean(CITRUS_HTML_REPORTER) instanceof OverrideHtmlReporter); | ||
} | ||
|
||
@Configuration | ||
public static class OverrideReporterConfiguration { | ||
|
||
@Bean | ||
public LoggingReporter citrusLoggingReporter() { | ||
return new OverrideLoggingReporter(); | ||
} | ||
|
||
@Bean | ||
public JUnitReporter citrusJunitReporter() { | ||
return new OverrideJUnitReporter(); | ||
} | ||
|
||
@Bean | ||
public HtmlReporter citrusHtmlReporter() { | ||
return new OverrideHtmlReporter(); | ||
} | ||
|
||
} | ||
|
||
private static class OverrideLoggingReporter extends LoggingReporter { | ||
} | ||
|
||
private static class OverrideJUnitReporter extends JUnitReporter { | ||
} | ||
|
||
private static class OverrideHtmlReporter extends HtmlReporter { | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
core/citrus-spring/src/test/java/org/citrusframework/reporter/ReporterConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.citrusframework.reporter; | ||
|
||
import org.citrusframework.UnitTestSupport; | ||
import org.citrusframework.report.HtmlReporter; | ||
import org.citrusframework.report.JUnitReporter; | ||
import org.citrusframework.report.LoggingReporter; | ||
import org.citrusframework.reporter.ReporterConfig.HtmlReporterEnablementCondition; | ||
import org.citrusframework.reporter.ReporterConfig.JunitReporterEnablementCondition; | ||
import org.citrusframework.reporter.ReporterConfig.LoggingReporterEnablementCondition; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.citrusframework.reporter.ReporterConfig.CITRUS_HTML_REPORTER; | ||
import static org.citrusframework.reporter.ReporterConfig.CITRUS_JUNIT_REPORTER; | ||
import static org.citrusframework.reporter.ReporterConfig.CITRUS_LOGGING_REPORTER; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class ReporterConfigTest extends UnitTestSupport { | ||
|
||
@Test | ||
public void testDefaultLoggingReporter() { | ||
Assert.assertTrue(applicationContext.getBean(CITRUS_LOGGING_REPORTER) instanceof LoggingReporter); | ||
} | ||
|
||
@Test | ||
public void testDefaultJunitReporter() { | ||
Assert.assertTrue(applicationContext.getBean(CITRUS_JUNIT_REPORTER) instanceof JUnitReporter); | ||
} | ||
|
||
@Test | ||
public void testDefaultHtmlReporter() { | ||
Assert.assertTrue(applicationContext.getBean(CITRUS_HTML_REPORTER) instanceof HtmlReporter); | ||
} | ||
@Test | ||
public void testLoggerReporterConditionDisabled() { | ||
|
||
Environment environmentMock = mock(Environment.class); | ||
ConfigurableListableBeanFactory beanFactoryMock = mock(ConfigurableListableBeanFactory.class); | ||
ConditionContext conditionContextMock = mock(ConditionContext.class); | ||
doReturn(environmentMock).when(conditionContextMock).getEnvironment(); | ||
doReturn(beanFactoryMock).when(conditionContextMock).getBeanFactory(); | ||
doReturn(new LoggingReporter()).when(beanFactoryMock).getBean(CITRUS_LOGGING_REPORTER); | ||
|
||
LoggingReporterEnablementCondition condition = new LoggingReporterEnablementCondition(); | ||
AnnotatedTypeMetadata annotatedTypeMetadataMock = mock(AnnotatedTypeMetadata.class); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
doReturn(null).when(beanFactoryMock).getBean(CITRUS_LOGGING_REPORTER); | ||
doReturn("false").when(environmentMock).getProperty(ReporterConfig.DEFAULT_LOGGING_REPORTER_ENABLED_PROPERTY, "true"); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
} | ||
|
||
@Test | ||
public void testJunitReporterConditionDisabledByOtherBean() { | ||
|
||
Environment environmentMock = mock(Environment.class); | ||
ConfigurableListableBeanFactory beanFactoryMock = mock(ConfigurableListableBeanFactory.class); | ||
ConditionContext conditionContextMock = mock(ConditionContext.class); | ||
doReturn(environmentMock).when(conditionContextMock).getEnvironment(); | ||
doReturn(beanFactoryMock).when(conditionContextMock).getBeanFactory(); | ||
doReturn(new LoggingReporter()).when(beanFactoryMock).getBean(CITRUS_JUNIT_REPORTER); | ||
|
||
JunitReporterEnablementCondition condition = new JunitReporterEnablementCondition(); | ||
AnnotatedTypeMetadata annotatedTypeMetadataMock = mock(AnnotatedTypeMetadata.class); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
doReturn(null).when(beanFactoryMock).getBean(CITRUS_JUNIT_REPORTER); | ||
doReturn("false").when(environmentMock).getProperty(ReporterConfig.DEFAULT_JUNIT_REPORTER_ENABLED_PROPERTY, "true"); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
} | ||
|
||
@Test | ||
public void testHtmlReporterConditionDisabledByOtherBean() { | ||
|
||
Environment environmentMock = mock(Environment.class); | ||
ConfigurableListableBeanFactory beanFactoryMock = mock(ConfigurableListableBeanFactory.class); | ||
ConditionContext conditionContextMock = mock(ConditionContext.class); | ||
doReturn(environmentMock).when(conditionContextMock).getEnvironment(); | ||
doReturn(beanFactoryMock).when(conditionContextMock).getBeanFactory(); | ||
doReturn(new LoggingReporter()).when(beanFactoryMock).getBean(CITRUS_HTML_REPORTER); | ||
|
||
HtmlReporterEnablementCondition condition = new HtmlReporterEnablementCondition(); | ||
AnnotatedTypeMetadata annotatedTypeMetadataMock = mock(AnnotatedTypeMetadata.class); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
doReturn(null).when(beanFactoryMock).getBean(CITRUS_HTML_REPORTER); | ||
doReturn("false").when(environmentMock).getProperty(ReporterConfig.DEFAULT_HTML_REPORTER_ENABLED_PROPERTY, "true"); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters