-
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 d37056d
Showing
4 changed files
with
222 additions
and
2 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
58 changes: 58 additions & 0 deletions
58
.../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,58 @@ | ||
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; | ||
|
||
@ContextConfiguration(classes = OverrideReporterConfigTest.OverrideReporterConfiguration.class) | ||
public class OverrideReporterConfigTest extends UnitTestSupport { | ||
|
||
@Test | ||
public void testOverridesLoggingReporter() { | ||
Assert.assertTrue(applicationContext.getBean("citrusLoggingReporter") instanceof OverrideLoggingReporter); | ||
} | ||
|
||
@Test | ||
public void testOverridesJunitReporter() { | ||
Assert.assertTrue(applicationContext.getBean("citrusJunitReporter") instanceof OverrideJUnitReporter); | ||
} | ||
|
||
@Test | ||
public void testOverridesHtmlReporter() { | ||
Assert.assertTrue(applicationContext.getBean("citrusHtmlReporter") 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 { | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
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.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class ReporterConfigTest extends UnitTestSupport { | ||
|
||
@Test | ||
public void testDefaultLoggingReporter() { | ||
Assert.assertTrue(applicationContext.getBean("citrusLoggingReporter") instanceof LoggingReporter); | ||
} | ||
|
||
@Test | ||
public void testDefaultJunitReporter() { | ||
Assert.assertTrue(applicationContext.getBean("citrusJunitReporter") instanceof JUnitReporter); | ||
} | ||
|
||
@Test | ||
public void testDefaultHtmlReporter() { | ||
Assert.assertTrue(applicationContext.getBean("citrusHtmlReporter") 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("citrusLoggingReporter"); | ||
|
||
LoggingReporterEnablementCondition condition = new LoggingReporterEnablementCondition(); | ||
AnnotatedTypeMetadata annotatedTypeMetadataMock = mock(AnnotatedTypeMetadata.class); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
doReturn(null).when(beanFactoryMock).getBean("citrusLoggingReporter"); | ||
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("citrusJunitReporter"); | ||
|
||
JunitReporterEnablementCondition condition = new JunitReporterEnablementCondition(); | ||
AnnotatedTypeMetadata annotatedTypeMetadataMock = mock(AnnotatedTypeMetadata.class); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
doReturn(null).when(beanFactoryMock).getBean("citrusJunitReporter"); | ||
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("citrusHtmlReporter"); | ||
|
||
HtmlReporterEnablementCondition condition = new HtmlReporterEnablementCondition(); | ||
AnnotatedTypeMetadata annotatedTypeMetadataMock = mock(AnnotatedTypeMetadata.class); | ||
Assert.assertFalse(condition.matches(conditionContextMock, annotatedTypeMetadataMock)); | ||
|
||
doReturn(null).when(beanFactoryMock).getBean("citrusHtmlReporter"); | ||
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