private void mockContext(final ImplicitNameSource source) { final MetadataBuildingContext context = Mockito.mock(MetadataBuildingContext.class); final InFlightMetadataCollector collector = Mockito.mock(InFlightMetadataCollector.class); final Database database = Mockito.mock(Database.class); final JdbcEnvironment jdbcEnvironment = Mockito.mock(JdbcEnvironment.class); final IdentifierHelper identifierHelper = Mockito.mock(IdentifierHelper.class); Mockito.when(identifierHelper.toIdentifier(ArgumentMatchers.anyString())).then(new Answer<Identifier>() { @Override public Identifier answer(final InvocationOnMock invocation) { return DatabaseIdentifier.toIdentifier((String)invocation.getArguments()[0]) ; } }); Mockito.when(jdbcEnvironment.getIdentifierHelper()).thenReturn(identifierHelper); Mockito.when(database.getJdbcEnvironment()).thenReturn(jdbcEnvironment); Mockito.when(collector.getDatabase()).thenReturn(database); Mockito.when(context.getMetadataCollector()).thenReturn(collector); Mockito.when(source.getBuildingContext()).thenReturn(context); }
/** * Check strategy configuration. */ @Test public void testConfiguration() { final Properties params = new Properties(); params.put("identity_tables", "summy.seg"); params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() { @Override protected MetadataBuildingContext getBuildingContext() { return null; } }); OptimizedSequenceStyleGenerator optimizedSequenceStyleGenerator = newStyleGenerator(); optimizedSequenceStyleGenerator.configure(StringType.INSTANCE, params, newServiceRegistry()); }
@Override public Identifier determineBasicColumnName(ImplicitBasicColumnNameSource source) { String columnName = StringHelper.toLowerCase( StringHelper.insertUnderscoreBetweenWords(source.getAttributePath().getProperty()) ); ImplicitBasicColumnNameSource newSource = new ImplicitBasicColumnNameSource() { @Override public AttributePath getAttributePath() { return AttributePath.parse(columnName); } @Override public boolean isCollectionElement() { return source.isCollectionElement(); } @Override public MetadataBuildingContext getBuildingContext() { return source.getBuildingContext(); } }; return super.determineBasicColumnName(newSource); }
@Override protected Identifier toIdentifier(String stringForm, MetadataBuildingContext buildingContext) { Identifier i = super.toIdentifier(stringForm, buildingContext); LOGGER.trace("toIdentifier {} -> {}", stringForm, i); return i; }