How to migrate from TypeRegistryConfigurer? #2249
Replies: 3 comments 9 replies
-
Currently there is no support for that. Parameter types are ultimately matched against feature files. And the assumption is that feature files are known at compile time. This doesn't seem to be the case in your situation. Could you elaborate on that? Alternatively would it be possible to use a regex that matches superset of all possible values and then at run time restrict which values are actually valid? |
Beta Was this translation helpful? Give feedback.
-
I set up the backend as you outlined above and it looks like the parameter type is not being picked up # src\main\resources\META-INF\services\io.cucumber.core.runtime.BackendSupplier
alfredo.AlfredoBackendSupplier // src\main\java\alfredo\AlfredoBackendSupplier.java
package alfredo;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import alfredo.pages.reporting.report.WindchillReportType;
import alfredo.pages.reporting.report.WindchillReportTypeRegistratorService;
import alfredo.type.WindchillType;
import alfredo.type.WindchillTypeRegistratorService;
import alfredo.user.DriverUser;
import alfredo.user.UserTypeRegistratorService;
import io.cucumber.core.backend.Backend;
import io.cucumber.core.backend.DataTableTypeDefinition;
import io.cucumber.core.backend.Glue;
import io.cucumber.core.backend.ParameterTypeDefinition;
import io.cucumber.core.backend.Snippet;
import io.cucumber.core.runtime.BackendSupplier;
import io.cucumber.cucumberexpressions.ParameterType;
import io.cucumber.datatable.DataTableType;
public class AlfredoBackendSupplier implements BackendSupplier {
/**
* Class logger
*/
private static final Logger LOGGER = LogManager.getLogger(AlfredoBackendSupplier.class);
@Override
public Collection<? extends Backend> get() {
return Collections.singletonList(new AlfredoBackend());
}
private class AlfredoBackend implements Backend {
private UserTypeRegistratorService userService;
private WindchillTypeRegistratorService typeService;
private WindchillReportTypeRegistratorService reportService;
/**
* Retrieve the userService bean, allowing for lazy instantiation
* also avoids trouble of worrying about how this class is actually instantiated
* and creating it there
*
* @return
*/
private UserTypeRegistratorService getUserService() {
if (this.userService == null) {
synchronized (this) {
if (this.userService == null) {
this.instantiateUserService();
}
}
}
return this.userService;
}
/**
* Instantiates the user service bean for the class
*/
private void instantiateUserService() {
final AbstractApplicationContext userContext = new AnnotationConfigApplicationContext("alfredo.user");
try {
this.userService = userContext.getBean(UserTypeRegistratorService.class);
} catch (final BeansException e) {
LOGGER.error(() -> "Error occured while retrieving user type registrator bean", e);
} finally {
userContext.close();
}
}
/**
* Instantiates the user service bean for the class
*/
private void instantiateTypeService() {
final AbstractApplicationContext typeContext = new AnnotationConfigApplicationContext("alfredo.type");
try {
this.typeService = typeContext.getBean(WindchillTypeRegistratorService.class);
} catch (final BeansException e) {
LOGGER.error(() -> "Error occured while retrieving user type registrator bean", e);
} finally {
typeContext.close();
}
}
/**
* Retrieve the userService bean, allowing for lazy instantiation
* also avoids trouble of worrying about how this class is actually instantiated
* and creating it there
*
* @return
*/
private WindchillTypeRegistratorService getTypeService() {
if (this.typeService == null) {
synchronized (this) {
if (this.typeService == null) {
this.instantiateTypeService();
}
}
}
return this.typeService;
}
private void instantiateReportService() {
final AbstractApplicationContext reportContext = new AnnotationConfigApplicationContext(
"alfredo.pages.reporting.report");
try {
this.reportService = reportContext.getBean(WindchillReportTypeRegistratorService.class);
} catch (final BeansException e) {
LOGGER.error(() -> "Error occured while retrieving report type registrator bean", e);
} finally {
reportContext.close();
}
}
/**
* Retrieve the userService bean, allowing for lazy instantiation
* also avoids trouble of worrying about how this class is actually instantiated
* and creating it there
*
* @return
*/
private WindchillReportTypeRegistratorService getReportService() {
if (this.reportService == null) {
synchronized (this) {
if (this.reportService == null) {
this.instantiateReportService();
}
}
}
return this.reportService;
}
@Override
public void loadGlue(Glue glue, List<URI> list) {
final UserTypeRegistratorService userService = this.getUserService();
final WindchillTypeRegistratorService typeService = this.getTypeService();
final WindchillReportTypeRegistratorService reportService = this.getReportService();
glue.addParameterType(new AlfredoParameterType(
new ParameterType<>("user", userService.getCombinedTypeString(), DriverUser.class,
userService.getCaptureGroupTranformer())));
glue.addDataTableType(new AlfredoDataTableType(
new DataTableType(DriverUser.class, userService::getUserFromString)));
glue.addParameterType(new AlfredoParameterType(
new ParameterType<WindchillType>("type", typeService.getCombinedTypeString(), WindchillType.class,
typeService.getCaptureGroupTransformer())));
glue.addDataTableType(new AlfredoDataTableType(
new DataTableType(WindchillType.class, typeService::getTypeFromString)));
glue.addParameterType(new AlfredoParameterType(
new ParameterType<WindchillReportType>("report", reportService.getCombinedReportString(),
WindchillReportType.class, reportService.getCaptureGroupTransformer())));
glue.addDataTableType(new AlfredoDataTableType(
new DataTableType(WindchillReportType.class, reportService::getReportFromString)));
}
@Override
public void buildWorld() {
// no-op
}
@Override
public void disposeWorld() {
// no-op
}
@Override
public Snippet getSnippet() {
return null;
}
}
private class AlfredoParameterType implements ParameterTypeDefinition {
private final ParameterType<?> parameterType;
protected AlfredoParameterType(ParameterType<?> parameterType) {
this.parameterType = parameterType;
}
@Override
public String getLocation() {
return null;
}
@Override
public boolean isDefinedAt(StackTraceElement stackTraceElement) {
return false;
}
@Override
public ParameterType<?> parameterType() {
return this.parameterType;
}
}
private class AlfredoDataTableType implements DataTableTypeDefinition {
private final DataTableType dataTableType;
protected AlfredoDataTableType(DataTableType dataTableType) {
this.dataTableType = dataTableType;
}
@Override
public String getLocation() {
return null;
}
@Override
public boolean isDefinedAt(StackTraceElement stackTraceElement) {
return false;
}
@Override
public DataTableType dataTableType() {
return this.dataTableType;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
@mpkorstanje Could you give an example of what |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Right now we are on cucumber v6.11 and we would like to upgrade to v7. We cannot use the @ParameterType annotation because our regex is derived from a collection of constants at runtime. TypeRegistryConfigurer allowed us to use the derived value as a parameter type like so:
How can we approach this in v7?
Beta Was this translation helpful? Give feedback.
All reactions