public void createMapping(Mapping mapping, boolean replace, boolean ifNotExists, SqlSecurityContext securityContext) {
        Mapping resolved = resolveMapping(mapping, securityContext);

        String name = resolved.name();
        if (ifNotExists) {
            relationsStorage.putIfAbsent(name, resolved);
        } else if (replace) {
            relationsStorage.put(name, resolved);
            listeners.forEach(TableListener::onTableChanged);
        } else if (!relationsStorage.putIfAbsent(name, resolved)) {
            throw QueryException.error("Mapping or view already exists: " + name);
        }
    }
@Test
    public void when_createsInvalidMapping_then_throws() {
        // given
        Mapping mapping = mapping();

        given(connectorCache.forType(mapping.connectorType())).willReturn(connector);
        given(connector.typeName()).willReturn(mapping.connectorType());
        given(connector.defaultObjectType()).willReturn("Dummy");
        given(connector.resolveAndValidateFields(nodeEngine,
                new SqlExternalResource(mapping.externalName(), mapping.dataConnection(), mapping.connectorType(), "Dummy", mapping.options()),
                mapping.fields()
        ))
                .willThrow(new RuntimeException("expected test exception"));

        // when
        // then
        assertThatThrownBy(() -> catalog.createMapping(mapping, true, true, null))
                .hasMessageContaining("expected test exception");
        verify(relationsStorage, never()).putIfAbsent(anyString(), (Mapping) any());
        verify(relationsStorage, never()).put(anyString(), (Mapping) any());
        verifyNoInteractions(listener);
    }