use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class TableResolverImplTest method when_createsDuplicateMappingWithIfNotExists_then_succeeds.
@Test
public void when_createsDuplicateMappingWithIfNotExists_then_succeeds() {
// given
Mapping mapping = mapping();
given(connectorCache.forType(mapping.type())).willReturn(connector);
given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willReturn(singletonList(new MappingField("field_name", INT)));
given(tableStorage.putIfAbsent(eq(mapping.name()), isA(Mapping.class))).willReturn(false);
// when
catalog.createMapping(mapping, false, true);
// then
verifyNoInteractions(listener);
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class TableResolverImplTest method when_replacesMapping_then_succeeds.
@Test
public void when_replacesMapping_then_succeeds() {
// given
Mapping mapping = mapping();
given(connectorCache.forType(mapping.type())).willReturn(connector);
given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willReturn(singletonList(new MappingField("field_name", INT)));
// when
catalog.createMapping(mapping, true, false);
// then
verify(tableStorage).put(eq(mapping.name()), isA(Mapping.class));
verify(listener).onTableChanged();
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class TableResolverImplTest method when_createsInvalidMapping_then_throws.
// region mapping storage tests
@Test
public void when_createsInvalidMapping_then_throws() {
// given
Mapping mapping = mapping();
given(connectorCache.forType(mapping.type())).willReturn(connector);
given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willThrow(new RuntimeException("expected test exception"));
// when
// then
assertThatThrownBy(() -> catalog.createMapping(mapping, true, true)).hasMessageContaining("expected test exception");
verify(tableStorage, never()).putIfAbsent(anyString(), (Mapping) any());
verify(tableStorage, never()).put(anyString(), (Mapping) any());
verifyNoInteractions(listener);
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class TableResolverImplTest method when_createsDuplicateMapping_then_throws.
@Test
public void when_createsDuplicateMapping_then_throws() {
// given
Mapping mapping = mapping();
given(connectorCache.forType(mapping.type())).willReturn(connector);
given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willReturn(singletonList(new MappingField("field_name", INT)));
given(tableStorage.putIfAbsent(eq(mapping.name()), isA(Mapping.class))).willReturn(false);
// when
// then
assertThatThrownBy(() -> catalog.createMapping(mapping, false, false)).isInstanceOf(QueryException.class).hasMessageContaining("Mapping or view already exists: name");
verifyNoInteractions(listener);
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class MappingColumnsTableTest method test_rows.
@Test
public void test_rows() {
// given
Mapping mapping = new Mapping("table-name", "table-external-name", "table-type", singletonList(new MappingField("table-field-name", INT, "table-field-external-name")), emptyMap());
View view = new View("view-name", "select * from table-name", false, singletonList("col1"), singletonList(INT));
MappingColumnsTable mappingColumnsTable = new MappingColumnsTable("catalog", null, "schema", singletonList(mapping), singletonList(view));
// when
List<Object[]> rows = mappingColumnsTable.rows();
// then
assertThat(rows).containsExactlyInAnyOrder(new Object[] { "catalog", "schema", "table-name", "table-field-name", "table-field-external-name", 1, "true", "INTEGER" }, new Object[] { "catalog", "schema", "view-name", "col1", null, 1, "true", "INTEGER" });
}
Aggregations