import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
@Immutable
public class YangStatementParserListenerImpl extends YangStatementParserBaseListener {
- private static final Logger LOG = LoggerFactory.getLogger(YangStatementParserListenerImpl.class);
-
private final List<String> toBeSkipped = new ArrayList<>();
private final String sourceName;
private QNameToStatementDefinition stmtDef;
final StatementSourceReference ref = DeclarationInTextSource.atPosition(
sourceName, ctx.getStart().getLine(), ctx.getStart().getCharPositionInLine());
- try {
- KeywordContext keyword = ctx.getChild(KeywordContext.class, 0);
- String statementName = keyword.getText();
- QName identifier = QName.create(YangConstants.RFC6020_YIN_MODULE, statementName);
- if (stmtDef != null && Utils.getValidStatementDefinition(prefixes, stmtDef, identifier) != null
- && toBeSkipped.isEmpty()) {
- writer.endStatement(ref);
- }
-
- // No-op if the statement is not on the list
- toBeSkipped.remove(statementName);
- } catch (SourceException e) {
- LOG.warn(e.getMessage(), e);
+ KeywordContext keyword = ctx.getChild(KeywordContext.class, 0);
+ String statementName = keyword.getText();
+ QName identifier = QName.create(YangConstants.RFC6020_YIN_MODULE, statementName);
+ if (stmtDef != null && Utils.getValidStatementDefinition(prefixes, stmtDef, identifier) != null
+ && toBeSkipped.isEmpty()) {
+ writer.endStatement(ref);
}
+
+ // No-op if the statement is not on the list
+ toBeSkipped.remove(statementName);
}
}
@Test
public void shouldFailOnDuplicateTypedefs() {
try {
- final SchemaContext schemaContext = StmtTestUtils.parseYangSources(
- new YangStatementSourceImpl("/bugs/bug6410/bar.yang", false));
+ StmtTestUtils.parseYangSources(new YangStatementSourceImpl("/bugs/bug6410/bar.yang", false));
fail("A ReactorException should have been thrown.");
} catch (ReactorException ex) {
- assertTrue(ex.getCause() instanceof SourceException);
- assertTrue(ex.getCause().getMessage().contains("Node name collision"));
+ final Throwable cause = ex.getCause();
+ assertTrue(cause instanceof SourceException);
+ assertTrue(cause.getMessage().contains("Duplicate name for typedef"));
}
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.google.common.base.VerifyException;
import java.io.ByteArrayOutputStream;
import org.junit.rules.ExpectedException;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
public class SubstatementValidatorTest {
}
@Test
- public void undesirableElementException() throws URISyntaxException, ReactorException {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource(
- "/substatement-validator/undesirable-element").toURI());
- testLog = output.toString();
- assertTrue(testLog.contains("TYPE is not valid for REVISION"));
+ public void undesirableElementException() throws URISyntaxException {
+ try {
+ TestUtils.loadModules(getClass().getResource("/substatement-validator/undesirable-element").toURI());
+ fail("Unexpected success");
+ } catch (ReactorException ex) {
+ assertNotNull(ex.getCause());
+ assertTrue(ex.getCause().getMessage().contains("TYPE is not valid for REVISION"));
+ }
}
@Test
public void maximalElementCountException() throws URISyntaxException, ReactorException {
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource(
- "/substatement-validator/maximal-element").toURI());
- testLog = output.toString();
- assertTrue(testLog.contains("Maximal count of DESCRIPTION for AUGMENT is 1"));
+ try {
+ TestUtils.loadModules(getClass().getResource("/substatement-validator/maximal-element").toURI());
+ fail("Unexpected success");
+ } catch (ReactorException ex) {
+ assertNotNull(ex.getCause());
+ assertTrue(ex.getCause().getMessage().contains("Maximal count of DESCRIPTION for AUGMENT is 1"));
+ }
}
@Test
public void missingElementException() throws URISyntaxException, ReactorException {
expectedEx.expect(VerifyException.class);
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource(
- "/substatement-validator/missing-element").toURI());
+ TestUtils.loadModules(getClass().getResource("/substatement-validator/missing-element").toURI());
}
@Test
@Test
public void bug4310test() throws URISyntaxException, ReactorException {
- expectedEx.expect(IllegalArgumentException.class);
-
- final Set<Module> modules = TestUtils.loadModules(getClass().getResource("/substatement-validator/bug-4310")
- .toURI());
+ expectedEx.expect(SomeModifiersUnresolvedException.class);
+ TestUtils.loadModules(getClass().getResource("/substatement-validator/bug-4310").toURI());
}
}
\ No newline at end of file
fail("SourceException should be thrown");
}
} catch (final ReactorException e) {
- final String expected = "Error in module 'typedef': cannot add '(urn:simple.container" +
- ".demo?revision=1970-01-01)int-ext'. Node name collision: '(urn:simple.container" +
- ".demo?revision=1970-01-01)int-ext' already declared.";
- assertTrue(e.getCause().getMessage().startsWith(expected));
+ assertTrue(e.getCause().getMessage().startsWith(
+ "Duplicate name for typedef (urn:simple.container.demo?revision=1970-01-01)int-ext [at"));
}
}