ResourceGeneratorFactory { public Optional<AbstractResourceGenerator> create(GeneratorContext context, WorkflowProcess process, String modelfqcn, String processfqcn, String appCanonicalName) { return GeneratorType .from(context) .map(type -> { switch (type) { case SPRING: return new SpringResourceGenerator(context, process, modelfqcn, processfqcn, appCanonicalName); case QUARKUS: return new ResourceGenerator(context, process, modelfqcn, processfqcn, appCanonicalName); case QUARKUS_REACTIVE: return new ReactiveResourceGenerator(context, process, modelfqcn, processfqcn, appCanonicalName); default: throw new NoSuchElementException("No Resource Generator for: " + type); } }); }  Optional<AbstractResourceGenerator> create(GeneratorContext context,
                                                      WorkflowProcess process,
                                                      String modelfqcn,
                                                      String processfqcn,
                                                      String appCanonicalName);  }
@Test void testCreateQuarkus(@Mock GeneratorContext generatorContext) { when(generatorContext.getBuildContext()).thenReturn(new QuarkusKogitoBuildContext(p -> true)); Optional<AbstractResourceGenerator> context = tested.create(generatorContext, process, MODEL_FQCN, PROCESS_FQCN, APP_CANONICAL_NAME); assertThat(context.isPresent()).isTrue(); assertThat(context.get()).isExactlyInstanceOf(ResourceGenerator.class); }
@Test void testCreateQuarkusReactive(@Mock GeneratorContext generatorContext) { when(generatorContext.getApplicationProperty(GeneratorConfig.KOGITO_REST_RESOURCE_TYPE_PROP)).thenReturn(Optional.of("reactive")); when(generatorContext.getBuildContext()).thenReturn(new QuarkusKogitoBuildContext(p -> true)); Optional<AbstractResourceGenerator> context = tested.create(generatorContext, process, MODEL_FQCN, PROCESS_FQCN, APP_CANONICAL_NAME); assertThat(context.isPresent()).isTrue(); assertThat(context.get()).isExactlyInstanceOf(ReactiveResourceGenerator.class); }
@Test void testCreateSpring(@Mock GeneratorContext generatorContext) { when(generatorContext.getBuildContext()).thenReturn(new SpringBootKogitoBuildContext(p -> true)); Optional<AbstractResourceGenerator> context = tested.create(generatorContext, process, MODEL_FQCN, PROCESS_FQCN, APP_CANONICAL_NAME); assertThat(context.isPresent()).isTrue(); assertThat(context.get()).isExactlyInstanceOf(SpringResourceGenerator.class); }
@Test void testCreateSpringReactive(@Mock GeneratorContext generatorContext) { when(generatorContext.getApplicationProperty(GeneratorConfig.KOGITO_REST_RESOURCE_TYPE_PROP)).thenReturn(Optional.of("reactive")); when(generatorContext.getBuildContext()).thenReturn(new SpringBootKogitoBuildContext(p -> true)); assertThrows(NoSuchElementException.class, () -> tested.create(generatorContext, process, MODEL_FQCN, PROCESS_FQCN, APP_CANONICAL_NAME)); }