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_createsDuplicateMapping_then_throws() {
        // given
        Mapping mapping = mapping();

        given(connectorCache.forType(mapping.connectorType())).willReturn(connector);
        given(connector.resolveAndValidateFields(nodeEngine,
                new SqlExternalResource(mapping.externalName(), mapping.dataConnection(), "Dummy", null, mapping.options()),
                mapping.fields()
        ))
                .willReturn(singletonList(new MappingField("field_name", INT)));
        given(connector.typeName()).willReturn("Dummy");
        given(connector.defaultObjectType()).willReturn("Dummy");
        given(relationsStorage.putIfAbsent(eq(mapping.name()), isA(Mapping.class))).willReturn(false);

        // when
        // then
        assertThatThrownBy(() -> catalog.createMapping(mapping, false, false, null))
                .isInstanceOf(QueryException.class)
                .hasMessageContaining("Mapping or view already exists: name");
        verifyNoInteractions(listener);
    }