@Test @SuppressWarnings("unchecked") void testDecorate() { when(entityType.getId()).thenReturn("entityTypeId"); when(repository.getEntityType()).thenReturn(entityType); DynamicDecorator dynamicDecorator = mock(DynamicDecorator.class); DecoratorParameters parameters = mock(DecoratorParameters.class); when(parameters.getDecorator()).thenReturn(dynamicDecorator); Repository<Entity> decoratedRepository = mock(Repository.class); when(decoratedRepository.getName()).thenReturn("decoratedRepositoryName"); when(decoratorConfiguration.getDecoratorParameters()) .thenAnswer((Answer<Stream>) invocation -> Stream.of(parameters)); when(dynamicDecorator.getId()).thenReturn("dynamicDecoratorId"); when(dynamicRepositoryDecoratorFactory.getId()).thenReturn("dynamicDecoratorId"); when(dynamicRepositoryDecoratorFactory.createDecoratedRepository( eq(repository), any(Map.class))) .thenReturn(decoratedRepository); Query query = mock(Query.class, RETURNS_SELF); when(dataService.query(DECORATOR_CONFIGURATION, DecoratorConfiguration.class)) .thenReturn(query); when(query.eq(ENTITY_TYPE_ID, "entityTypeId").findOne()).thenReturn(decoratorConfiguration); registry.addFactory(dynamicRepositoryDecoratorFactory); assertEquals("decoratedRepositoryName", registry.decorate(repository).getName()); }
@Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { String entityTypeId = repository.getEntityType().getId(); if (!entityTypeId.equals(DECORATOR_CONFIGURATION) && bootstrappingDone) { DecoratorConfiguration config = dataService .query(DECORATOR_CONFIGURATION, DecoratorConfiguration.class) .eq(ENTITY_TYPE_ID, entityTypeId) .findOne(); if (config != null) { repository = decorateRepository(repository, config); } } return repository; }
DynamicRepositoryDecoratorRegistryImpl implements DynamicRepositoryDecoratorRegistry { @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { String entityTypeId = repository.getEntityType().getId(); if (!entityTypeId.equals(DECORATOR_CONFIGURATION) && bootstrappingDone) { DecoratorConfiguration config = dataService .query(DECORATOR_CONFIGURATION, DecoratorConfiguration.class) .eq(ENTITY_TYPE_ID, entityTypeId) .findOne(); if (config != null) { repository = decorateRepository(repository, config); } } return repository; } }
DynamicRepositoryDecoratorRegistryImpl implements DynamicRepositoryDecoratorRegistry { @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { String entityTypeId = repository.getEntityType().getId(); if (!entityTypeId.equals(DECORATOR_CONFIGURATION) && bootstrappingDone) { DecoratorConfiguration config = dataService .query(DECORATOR_CONFIGURATION, DecoratorConfiguration.class) .eq(ENTITY_TYPE_ID, entityTypeId) .findOne(); if (config != null) { repository = decorateRepository(repository, config); } } return repository; } DynamicRepositoryDecoratorRegistryImpl(DataService dataService, Gson gson); }
DynamicRepositoryDecoratorRegistryImpl implements DynamicRepositoryDecoratorRegistry { @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { String entityTypeId = repository.getEntityType().getId(); if (!entityTypeId.equals(DECORATOR_CONFIGURATION) && bootstrappingDone) { DecoratorConfiguration config = dataService .query(DECORATOR_CONFIGURATION, DecoratorConfiguration.class) .eq(ENTITY_TYPE_ID, entityTypeId) .findOne(); if (config != null) { repository = decorateRepository(repository, config); } } return repository; } DynamicRepositoryDecoratorRegistryImpl(DataService dataService, Gson gson); @Override synchronized void addFactory(DynamicRepositoryDecoratorFactory factory); @Override Stream<String> getFactoryIds(); @Override DynamicRepositoryDecoratorFactory getFactory(String id); @Override synchronized Repository<Entity> decorate(Repository<Entity> repository); @EventListener void onApplicationEvent(BootstrappingEvent bootstrappingEvent); }
DynamicRepositoryDecoratorRegistryImpl implements DynamicRepositoryDecoratorRegistry { @Override public synchronized Repository<Entity> decorate(Repository<Entity> repository) { String entityTypeId = repository.getEntityType().getId(); if (!entityTypeId.equals(DECORATOR_CONFIGURATION) && bootstrappingDone) { DecoratorConfiguration config = dataService .query(DECORATOR_CONFIGURATION, DecoratorConfiguration.class) .eq(ENTITY_TYPE_ID, entityTypeId) .findOne(); if (config != null) { repository = decorateRepository(repository, config); } } return repository; } DynamicRepositoryDecoratorRegistryImpl(DataService dataService, Gson gson); @Override synchronized void addFactory(DynamicRepositoryDecoratorFactory factory); @Override Stream<String> getFactoryIds(); @Override DynamicRepositoryDecoratorFactory getFactory(String id); @Override synchronized Repository<Entity> decorate(Repository<Entity> repository); @EventListener void onApplicationEvent(BootstrappingEvent bootstrappingEvent);  }