Example: Using an optional id from a command-line parameter
In this example, we create a component that receives a unique ID via the command line, but if the ID is not specified it will generate one itself. Where the tests are performed on the build server, the ID of the build is used to identify test data.
import com.foreach.cuke.ctf.CtfEvaluationContext; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; Â @Component public class CalculatedProperties { private static final Logger LOG = LoggerFactory.getLogger( CalculatedProperties.class ); Â @Autowired private CtfEvaluationContext context; Â @Value("${buildName:}") private String buildName; Â @PostConstruct public void createProperties() { String differentiator = context.lookupString( "buildId.differentiator" ); String buildNumber = StringUtils.isBlank( buildName ) ? context.getId().getToday() : buildName; Â String buildId = "build_" + differentiator + "_" + buildNumber; Â // Binnen de Cucumber scenarios kan gebruik gemaakt worden van ${buildId} context.getProperties().put( "buildId", buildId ); LOG.info( "Current buildId value is {}", buildId ); } }