public HttpRequest http(String method, String url) { HttpRequest httpRequest = new HttpRequest(baseUrl + root(url), method) .header("RestxThreadLocal", Factory.LocalMachines.threadLocal().getId()) .header("RestxBlade", Blade.current()) ; if (!cookies.isEmpty()) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : cookies.entrySet()) { sb.append(entry.getKey()).append("=\"").append(entry.getValue().replace("\"", "\\\"")).append("\"; "); } sb.setLength(sb.length() - 2); httpRequest.header("Cookie", sb.toString()); } return httpRequest; }
public HttpRequest http(String method, String url) { HttpRequest httpRequest = new HttpRequest(baseUrl + root(url), method) .header("RestxThreadLocal", Factory.LocalMachines.threadLocal().getId()) .header("RestxBlade", Blade.current()) ; if (!cookies.isEmpty()) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : cookies.entrySet()) { sb.append(entry.getKey()).append("=\"").append(entry.getValue().replace("\"", "\\\"")).append("\"; "); } sb.setLength(sb.length() - 2); httpRequest.header("Cookie", sb.toString()); } return httpRequest; }
Factory.LocalMachines.threadLocal() .set("OutPrintStreamComponent", new LocalStreamComponent(out, outPrintStream)) .set("ErrPrintStreamComponent", new LocalStreamComponent(err, errPrintStream))
final Factory.LocalMachines localMachines = threadLocal(); localMachines.addMachine(customizerMachine);
Factory.LocalMachines.threadLocal() .set("OutPrintStreamComponent", new LocalStreamComponent(out, outPrintStream)) .set("ErrPrintStreamComponent", new LocalStreamComponent(err, errPrintStream))
@Override public void route(final RestxRequest restxRequest, final RestxResponse restxResponse) throws IOException { Factory.LocalMachines.threadLocal().set("RecordedSpecsRepository", repository);
@Override public void route(final RestxRequest restxRequest, final RestxResponse restxResponse) throws IOException { Factory.LocalMachines.threadLocal().set("RecordedSpecsRepository", repository);
@Override public AutoCloseable recordIn(Map<String, Given> givens) { final Tape tape = new Tape(givens); final Factory.Query<Mapper> mapperQuery = Factory.Query.byName(Name.of(Mapper.class, "Mapper")); Factory.LocalMachines.threadLocal().addMachine( new SingleNameFactoryMachine<>(0, new StdMachineEngine<ComponentCustomizerEngine>( Name.of(ComponentCustomizerEngine.class, "JongoCollectionSequenceSupplier"), BoundlessComponentBox.FACTORY) { @Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { final Mapper mapper = satisfiedBOM.getOne(mapperQuery).get().getComponent(); final ObjectIdUpdater objectIdUpdater = mapper.getObjectIdUpdater(); return new SingleComponentClassCustomizerEngine<JongoCollection>(0, JongoCollection.class) { @Override public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) { final JongoCollection collection = namedComponent.getComponent(); return new NamedComponent<>(namedComponent.getName(), new SequencingJongoCollection(tape, collection, mapper, objectIdUpdater)); } }; } @Override public BillOfMaterials getBillOfMaterial() { return BillOfMaterials.of(mapperQuery); } })); return tape; }
@Override public AutoCloseable recordIn(final Map<String, Given> givens) { final Tape tape = new Tape(givens); Factory.LocalMachines.threadLocal().addMachine( new SingleNameFactoryMachine<>(0, new NoDepsMachineEngine<ComponentCustomizerEngine>( Name.of(ComponentCustomizerEngine.class, "UUIDGeneratorSequenceSupplier"), BoundlessComponentBox.FACTORY) { @Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { return new SingleComponentClassCustomizerEngine<UUIDGenerator>(0, UUIDGenerator.class) { @Override public NamedComponent<UUIDGenerator> customize(final NamedComponent<UUIDGenerator> namedComponent) { return new NamedComponent<>(namedComponent.getName(), new UUIDGenerator() { @Override public String doGenerate() { String uuid = namedComponent.getComponent().doGenerate(); tape.recordGeneratedId(uuid); return uuid; } }); } }; } })); return tape; }
@Override public AutoCloseable recordIn(Map<String, Given> givens) { final Tape tape = new Tape(givens); final Factory.Query<Mapper> mapperQuery = Factory.Query.byName(Name.of(Mapper.class, "Mapper")); Factory.LocalMachines.threadLocal().addMachine( new SingleNameFactoryMachine<>(0, new StdMachineEngine<ComponentCustomizerEngine>( Name.of(ComponentCustomizerEngine.class, "JongoCollectionSequenceSupplier"), BoundlessComponentBox.FACTORY) { @Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { final Mapper mapper = satisfiedBOM.getOne(mapperQuery).get().getComponent(); final ObjectIdUpdater objectIdUpdater = mapper.getObjectIdUpdater(); return new SingleComponentClassCustomizerEngine<JongoCollection>(0, JongoCollection.class) { @Override public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) { final JongoCollection collection = namedComponent.getComponent(); return new NamedComponent<>(namedComponent.getName(), new SequencingJongoCollection(tape, collection, mapper, objectIdUpdater)); } }; } @Override public BillOfMaterials getBillOfMaterial() { return BillOfMaterials.of(mapperQuery); } })); return tape; }
@Override public AutoCloseable recordIn(final Map<String, Given> givens) { final Tape tape = new Tape(givens); Factory.LocalMachines.threadLocal().addMachine( new SingleNameFactoryMachine<>(0, new NoDepsMachineEngine<ComponentCustomizerEngine>( Name.of(ComponentCustomizerEngine.class, "UUIDGeneratorSequenceSupplier"), BoundlessComponentBox.FACTORY) { @Override protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) { return new SingleComponentClassCustomizerEngine<UUIDGenerator>(0, UUIDGenerator.class) { @Override public NamedComponent<UUIDGenerator> customize(final NamedComponent<UUIDGenerator> namedComponent) { return new NamedComponent<>(namedComponent.getName(), new UUIDGenerator() { @Override public String doGenerate() { String uuid = namedComponent.getComponent().doGenerate(); tape.recordGeneratedId(uuid); return uuid; } }); } }; } })); return tape; }
/** * An alias for threadLocal() which makes the intention of using it to override components clearer. * * It's usually used like this: * <code> * overrideComponents().set("componentName", "componentValue"); * </code> * * Note that it doesn't do anything special to actually override components: they will be used only in Factory * relying on threadLocal() LocalMachines is built after the call. * * @return LocalMachines associated with current thread. */ public static LocalMachines overrideComponents() { return threadLocal(); }
@Override public GivenCleaner run(GivenTime given, ImmutableMap<String, String> params) { threadLocal().set("FixedTimeComponent", new FixedTimeComponent(given.getTime().getMillis())); return NoopGivenCleaner.INSTANCE; }
private static Factory.Builder newFactoryBuilder() { return Factory.builder() .addFromServiceLoader() .addLocalMachines(Factory.LocalMachines.threadLocal()) ; }
private static Factory.Builder newFactoryBuilder() { return Factory.builder() .addFromServiceLoader() .addLocalMachines(Factory.LocalMachines.threadLocal()) ; }
public static Factory newInstance() { return Factory.builder().addFromServiceLoader() .addLocalMachines(LocalMachines.threadLocal()) .build(); }
@Override public GivenCleaner run(GivenTime given, ImmutableMap<String, String> params) { threadLocal().set("FixedTimeComponent", new FixedTimeComponent(given.getTime().getMillis())); return NoopGivenCleaner.INSTANCE; }