Example usage for org.hibernate.boot.model.naming DatabaseIdentifier toIdentifier

List of usage examples for org.hibernate.boot.model.naming DatabaseIdentifier toIdentifier

Introduction

In this page you can find the example usage for org.hibernate.boot.model.naming DatabaseIdentifier toIdentifier.

Prototype

public static DatabaseIdentifier toIdentifier(String text) 

Source Link

Usage

From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImplTest.java

License:MIT License

@Test
void determineUniqueKeyName() {
    final var source = Mockito.mock(ImplicitUniqueKeyNameSource.class);
    mockContext(source);//w  ww .  ja va 2  s.c o m
    Mockito.when(source.getTableName()).thenReturn(DatabaseIdentifier.toIdentifier("MyTa_ble"));
    final List<Identifier> columnsIdentifier = new ArrayList<>();
    columnsIdentifier.add(DatabaseIdentifier.toIdentifier("MyCol_umn1"));
    columnsIdentifier.add(DatabaseIdentifier.toIdentifier("MyCol_umn2"));
    Mockito.when(source.getColumnNames()).thenReturn(columnsIdentifier);
    final var identifier = new ImplicitNamingStrategyNiceJpaImpl().determineUniqueKeyName(source);

    Assertions.assertEquals("UK_bdj7f5p3skrieson5es1km8t9", identifier.getText());
}

From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImplTest.java

License:MIT License

private void mockContext(final ImplicitNameSource source) {
    final var context = Mockito.mock(MetadataBuildingContext.class);
    final var collector = Mockito.mock(InFlightMetadataCollector.class);
    final var database = Mockito.mock(Database.class);
    final var jdbcEnvironment = Mockito.mock(JdbcEnvironment.class);
    final var identifierHelper = Mockito.mock(IdentifierHelper.class);
    Mockito.when(identifierHelper.toIdentifier(ArgumentMatchers.anyString()))
            .then((Answer<Identifier>) invocation -> 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);
}

From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImplTest.java

License:MIT License

@Test
void determineJoinColumnNameCollection() {
    final var source = Mockito.mock(ImplicitJoinColumnNameSource.class);
    mockContext(source);/*from   www  . java2  s  . c  om*/
    Mockito.when(source.getNature()).thenReturn(ImplicitJoinColumnNameSource.Nature.ELEMENT_COLLECTION);
    Mockito.when(source.getReferencedTableName()).thenReturn(DatabaseIdentifier.toIdentifier("MyTa_ble"));
    final var identifier = new ImplicitNamingStrategyNiceJpaImpl().determineJoinColumnName(source);
    Assertions.assertEquals("MyTa_ble", identifier.getText());
}

From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImplTest.java

License:MIT License

@Test
void determineJoinColumnNameNoAttribute() {
    final var source = Mockito.mock(ImplicitJoinColumnNameSource.class);
    mockContext(source);/*w w  w  .ja  va  2 s . c o  m*/
    Mockito.when(source.getNature()).thenReturn(ImplicitJoinColumnNameSource.Nature.ENTITY);
    Mockito.when(source.getReferencedTableName()).thenReturn(DatabaseIdentifier.toIdentifier("MyTa_ble"));
    final var identifier = new ImplicitNamingStrategyNiceJpaImpl().determineJoinColumnName(source);
    Assertions.assertEquals("MyTa_ble", identifier.getText());
}

From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImplTest.java

License:MIT License

@Test
void determineJoinColumnName() {
    final var source = Mockito.mock(ImplicitJoinColumnNameSource.class);
    mockContext(source);//from   w  w  w  . j  av  a 2  s.  c o  m
    Mockito.when(source.getNature()).thenReturn(ImplicitJoinColumnNameSource.Nature.ENTITY);
    final var attributePath = Mockito.mock(AttributePath.class);
    Mockito.when(attributePath.getProperty()).thenReturn("myProperty");
    Mockito.when(source.getAttributePath()).thenReturn(attributePath);
    Mockito.when(source.getReferencedTableName()).thenReturn(DatabaseIdentifier.toIdentifier("MyTa_ble"));
    final var identifier = new ImplicitNamingStrategyNiceJpaImpl().determineJoinColumnName(source);
    Assertions.assertEquals("my_property", identifier.getText());
}

From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImplTest.java

License:MIT License

@Test
void determineForeignKeyName() {
    final var source = Mockito.mock(ImplicitForeignKeyNameSource.class);
    mockContext(source);//  w  w w  . j  a v a 2 s  .  c o  m
    Mockito.when(source.getTableName()).thenReturn(DatabaseIdentifier.toIdentifier("MyTa_ble"));
    final List<Identifier> columnsIdentifier = new ArrayList<>();
    columnsIdentifier.add(DatabaseIdentifier.toIdentifier("MyCol_umn1"));
    columnsIdentifier.add(DatabaseIdentifier.toIdentifier("MyCol_umn2"));
    Mockito.when(source.getColumnNames()).thenReturn(columnsIdentifier);
    final var identifier = new ImplicitNamingStrategyNiceJpaImpl().determineForeignKeyName(source);
    Assertions.assertEquals("FK_bdj7f5p3skrieson5es1km8t9", identifier.getText());
}