From fac8c04a57b1a043362a8e92a6265613375d06eb Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Thu, 19 Oct 2023 21:11:37 +0200 Subject: [PATCH] fix(#1014): Use testcase runner provider everywhere Also fix license headers for new files --- .../TestCaseRunnerProvider.java | 19 ++++++++++++++ .../TestCaseRunnerFactory.java | 20 ++++++++++++++- .../TestCaseRunnerFactoryTest.java | 25 ++++++++++++++++--- .../cucumber/backend/CitrusObjectFactory.java | 8 +++--- .../spring/CitrusSpringObjectFactory.java | 10 ++++---- .../citrusframework/junit/JUnit4Helper.java | 4 +-- .../quarkus/CitrusTestResource.java | 4 +-- 7 files changed, 73 insertions(+), 17 deletions(-) diff --git a/core/citrus-api/src/main/java/org/citrusframework/TestCaseRunnerProvider.java b/core/citrus-api/src/main/java/org/citrusframework/TestCaseRunnerProvider.java index fb364dbffd..1c1480643a 100644 --- a/core/citrus-api/src/main/java/org/citrusframework/TestCaseRunnerProvider.java +++ b/core/citrus-api/src/main/java/org/citrusframework/TestCaseRunnerProvider.java @@ -1,3 +1,22 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.citrusframework; import org.citrusframework.context.TestContext; diff --git a/core/citrus-base/src/main/java/org/citrusframework/TestCaseRunnerFactory.java b/core/citrus-base/src/main/java/org/citrusframework/TestCaseRunnerFactory.java index f78e2255c7..419b9585c5 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/TestCaseRunnerFactory.java +++ b/core/citrus-base/src/main/java/org/citrusframework/TestCaseRunnerFactory.java @@ -1,3 +1,22 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.citrusframework; import org.citrusframework.context.TestContext; @@ -61,7 +80,6 @@ private TestCaseRunnerProvider lookupCustomOrDefault() { } } - /** * Create a runner. * @param context diff --git a/core/citrus-base/src/test/java/org/citrusframework/TestCaseRunnerFactoryTest.java b/core/citrus-base/src/test/java/org/citrusframework/TestCaseRunnerFactoryTest.java index a67750d84b..d8e289e390 100644 --- a/core/citrus-base/src/test/java/org/citrusframework/TestCaseRunnerFactoryTest.java +++ b/core/citrus-base/src/test/java/org/citrusframework/TestCaseRunnerFactoryTest.java @@ -1,7 +1,23 @@ -package org.citrusframework; +/* + * Copyright 2023 the original author or authors. + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +package org.citrusframework; import org.citrusframework.context.TestContext; import org.citrusframework.spi.ResourcePathTypeResolver; @@ -10,6 +26,9 @@ import org.testng.Assert; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + public class TestCaseRunnerFactoryTest { @Test diff --git a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusObjectFactory.java b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusObjectFactory.java index 938d7d3658..28c12d0105 100644 --- a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusObjectFactory.java +++ b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/CitrusObjectFactory.java @@ -21,13 +21,13 @@ import java.util.Map; import java.util.Optional; +import io.cucumber.core.backend.ObjectFactory; +import io.cucumber.core.exception.CucumberException; import org.citrusframework.CitrusInstanceManager; -import org.citrusframework.DefaultTestCaseRunner; import org.citrusframework.TestCaseRunner; +import org.citrusframework.TestCaseRunnerFactory; import org.citrusframework.annotations.CitrusAnnotations; import org.citrusframework.context.TestContext; -import io.cucumber.core.backend.ObjectFactory; -import io.cucumber.core.exception.CucumberException; /** * @author Christoph Deppisch @@ -57,7 +57,7 @@ public CitrusObjectFactory() { @Override public void start() { context = CitrusInstanceManager.getOrDefault().getCitrusContext().createTestContext(); - runner = new DefaultTestCaseRunner(context); + runner = TestCaseRunnerFactory.createRunner(context); } @Override diff --git a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/spring/CitrusSpringObjectFactory.java b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/spring/CitrusSpringObjectFactory.java index f2c89e9125..bc4093ce21 100644 --- a/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/spring/CitrusSpringObjectFactory.java +++ b/runtime/citrus-cucumber/src/main/java/org/citrusframework/cucumber/backend/spring/CitrusSpringObjectFactory.java @@ -16,19 +16,19 @@ package org.citrusframework.cucumber.backend.spring; +import io.cucumber.core.backend.CucumberBackendException; +import io.cucumber.core.backend.ObjectFactory; +import io.cucumber.spring.SpringFactory; import org.citrusframework.Citrus; import org.citrusframework.CitrusContext; import org.citrusframework.CitrusInstanceManager; import org.citrusframework.CitrusSpringContext; import org.citrusframework.CitrusSpringContextProvider; -import org.citrusframework.DefaultTestCaseRunner; import org.citrusframework.TestCaseRunner; +import org.citrusframework.TestCaseRunnerFactory; import org.citrusframework.annotations.CitrusAnnotations; import org.citrusframework.context.TestContext; import org.citrusframework.context.TestContextFactoryBean; -import io.cucumber.core.backend.CucumberBackendException; -import io.cucumber.core.backend.ObjectFactory; -import io.cucumber.spring.SpringFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; @@ -65,7 +65,7 @@ public CitrusSpringObjectFactory() { public void start() { delegate.start(); context = getInstance(TestContext.class); - runner = new DefaultTestCaseRunner(context); + runner = TestCaseRunnerFactory.createRunner(context); } @Override diff --git a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java index edd9a062cc..1117e23732 100644 --- a/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java +++ b/runtime/citrus-junit/src/main/java/org/citrusframework/junit/JUnit4Helper.java @@ -28,8 +28,8 @@ import org.citrusframework.CitrusSettings; import org.citrusframework.DefaultTestCase; -import org.citrusframework.DefaultTestCaseRunner; import org.citrusframework.TestCaseRunner; +import org.citrusframework.TestCaseRunnerFactory; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.ClasspathResourceResolver; @@ -73,7 +73,7 @@ public static void invokeTestMethod(Object target, CitrusFrameworkMethod framewo * @return */ public static TestCaseRunner createTestRunner(CitrusFrameworkMethod frameworkMethod, Class testClass, TestContext context) { - TestCaseRunner testCaseRunner = new DefaultTestCaseRunner(new DefaultTestCase(), context); + TestCaseRunner testCaseRunner = TestCaseRunnerFactory.createRunner(new DefaultTestCase(), context); testCaseRunner.testClass(testClass); testCaseRunner.name(frameworkMethod.getTestName()); testCaseRunner.packageName(frameworkMethod.getPackageName()); diff --git a/runtime/citrus-quarkus/citrus-quarkus-runtime/src/main/java/org/citrusframework/quarkus/CitrusTestResource.java b/runtime/citrus-quarkus/citrus-quarkus-runtime/src/main/java/org/citrusframework/quarkus/CitrusTestResource.java index 934781d3ad..82afc55c74 100644 --- a/runtime/citrus-quarkus/citrus-quarkus-runtime/src/main/java/org/citrusframework/quarkus/CitrusTestResource.java +++ b/runtime/citrus-quarkus/citrus-quarkus-runtime/src/main/java/org/citrusframework/quarkus/CitrusTestResource.java @@ -25,10 +25,10 @@ import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; import org.citrusframework.Citrus; import org.citrusframework.CitrusInstanceManager; -import org.citrusframework.DefaultTestCaseRunner; import org.citrusframework.GherkinTestActionRunner; import org.citrusframework.TestActionRunner; import org.citrusframework.TestCaseRunner; +import org.citrusframework.TestCaseRunnerFactory; import org.citrusframework.annotations.CitrusAnnotations; import org.citrusframework.annotations.CitrusFramework; import org.citrusframework.annotations.CitrusResource; @@ -77,7 +77,7 @@ public void inject(Object testInstance) { } context = citrus.getCitrusContext().createTestContext(); - runner = new DefaultTestCaseRunner(context); + runner = TestCaseRunnerFactory.createRunner(context); runner.testClass(testInstance.getClass()); runner.packageName(testInstance.getClass().getPackageName()); runner.name(testInstance.getClass().getSimpleName());