Search in sources :

Example 56 with TrinoPrincipal

use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.

the class TestMemoryMetadata method testCreateViewWithoutReplace.

@Test
public void testCreateViewWithoutReplace() {
    SchemaTableName test = new SchemaTableName("test", "test_view");
    metadata.createSchema(SESSION, "test", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
    try {
        metadata.createView(SESSION, test, testingViewDefinition("test"), false);
    } catch (Exception e) {
        fail("should have succeeded");
    }
    assertThatThrownBy(() -> metadata.createView(SESSION, test, testingViewDefinition("test"), false)).isInstanceOf(TrinoException.class).hasMessageMatching("View already exists: test\\.test_view");
}
Also used : TrinoException(io.trino.spi.TrinoException) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTableName(io.trino.spi.connector.SchemaTableName) SchemaNotFoundException(io.trino.spi.connector.SchemaNotFoundException) TrinoException(io.trino.spi.TrinoException) Test(org.testng.annotations.Test)

Example 57 with TrinoPrincipal

use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.

the class TestMemoryMetadata method testCreateSchema.

@Test
public void testCreateSchema() {
    assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default"));
    metadata.createSchema(SESSION, "test", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
    assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default", "test"));
    assertEquals(metadata.listTables(SESSION, Optional.of("test")), ImmutableList.of());
    SchemaTableName tableName = new SchemaTableName("test", "first_table");
    metadata.createTable(SESSION, new ConnectorTableMetadata(tableName, ImmutableList.of(), ImmutableMap.of()), false);
    assertEquals(metadata.listTables(SESSION, Optional.empty()), ImmutableList.of(tableName));
    assertEquals(metadata.listTables(SESSION, Optional.of("test")), ImmutableList.of(tableName));
    assertEquals(metadata.listTables(SESSION, Optional.of("default")), ImmutableList.of());
}
Also used : TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Aggregations

TrinoPrincipal (io.trino.spi.security.TrinoPrincipal)57 Test (org.testng.annotations.Test)44 SchemaTableName (io.trino.spi.connector.SchemaTableName)20 Session (io.trino.Session)15 SystemAccessControl (io.trino.spi.security.SystemAccessControl)12 CatalogSchemaName (io.trino.spi.connector.CatalogSchemaName)11 USER (io.trino.spi.security.PrincipalType.USER)9 Optional (java.util.Optional)9 MockConnectorFactory (io.trino.connector.MockConnectorFactory)8 Identity (io.trino.spi.security.Identity)8 ImmutableList (com.google.common.collect.ImmutableList)7 Privilege (io.trino.spi.security.Privilege)7 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 MockConnectorPlugin (io.trino.connector.MockConnectorPlugin)6 WarningCollector (io.trino.execution.warnings.WarningCollector)6 Metadata (io.trino.metadata.Metadata)6 AccessControl (io.trino.security.AccessControl)6 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)6 RoleGrant (io.trino.spi.security.RoleGrant)6