<commit_before>/*
 * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.stmt;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;

import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;

public class ListKeysTest {

    @Test
    public void correctListKeysTest() throws ReactorException {
        final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
                .addSource(sourceForResource("/list-keys-test/correct-list-keys-test.yang"))
                .buildEffective();
        assertNotNull(result);
    }

    @Test
    public void incorrectListKeysTest1() {
        BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
                .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test.yang"));
        try {
            reactor.buildEffective();
            fail("effective build should fail due to list instead of leaf referenced in list key");
        } catch (ReactorException e) {
            assertTrue(e.getCause().getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
        }
    }

    @Test
    public void incorrectListKeysTest2() {
        BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
                .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test2.yang"));
        try {
            reactor.buildEffective();
            fail("effective build should fail due to missing leaf referenced in list key");
        } catch (ReactorException e) {
            assertTrue(e.getCause().getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
        }
    }

    @Test
    public void incorrectListKeysTest3() {
        BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
                .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test3.yang"));
        try {
            reactor.buildEffective();
            fail("effective build should fail due to list instead of leaf in grouping referenced in list key");
        } catch (ReactorException e) {
            assertTrue(e.getCause().getMessage().startsWith("Key 'grp_list' misses node 'grp_list'"));
        }
    }

    @Test
    public void incorrectListKeysTest4()  {
        BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
                .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test4.yang"));
        try {
            reactor.buildEffective();
            fail("effective build should fail due to list instead of leaf in grouping augmented to list referenced "
                    + "in list key");
        } catch (ReactorException e) {
            assertTrue(e.getCause().getMessage().startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
        }
    }
}
<commit_msg>Cleanup ListKeysTest<commit_after>/*
 * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.stmt;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertThrows;

import org.junit.Test;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;

public class ListKeysTest {
    @Test
    public void correctListKeysTest() throws Exception {
        StmtTestUtils.parseYangSource("/list-keys-test/correct-list-keys-test.yang");
    }

    @Test
    public void incorrectListKeysTest1() {
        final ReactorException ex = assertThrows(ReactorException.class,
            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test.yang"));
        final Throwable cause = ex.getCause();
        assertThat(cause, instanceOf(SourceException.class));
        assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
    }

    @Test
    public void incorrectListKeysTest2() {
        final ReactorException ex = assertThrows(ReactorException.class,
            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test2.yang"));
        final Throwable cause = ex.getCause();
        assertThat(cause, instanceOf(SourceException.class));
        assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
    }

    @Test
    public void incorrectListKeysTest3() {
        final ReactorException ex = assertThrows(ReactorException.class,
            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test3.yang"));
        final Throwable cause = ex.getCause();
        assertThat(cause, instanceOf(SourceException.class));
        assertThat(cause.getMessage(), startsWith("Key 'grp_list' misses node 'grp_list'"));
    }

    @Test
    public void incorrectListKeysTest4()  {
        final ReactorException ex = assertThrows(ReactorException.class,
            () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test4.yang"));
        final Throwable cause = ex.getCause();
        assertThat(cause, instanceOf(SourceException.class));
        assertThat(cause.getMessage(), startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
    }
}

{'fraction_non_alphanumeric': 0.10922213311948677, 'fraction_numerical': 0.013151563753007217, 'mean_word_length': 3.357791754018169, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2149041', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1766, 'n_words': 370}