*/
package org.opendaylight.yangtools.yang.stmt;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.Matchers.isA;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import com.google.common.base.Throwables;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public class YangParserNegativeTest {
fail("SomeModifiersUnresolvedException should be thrown");
} catch (final SomeModifiersUnresolvedException e) {
final Throwable rootCause = Throwables.getRootCause(e);
- assertTrue(rootCause instanceof InferenceException);
- assertTrue(rootCause.getMessage().startsWith("Imported module"));
- assertTrue(rootCause.getMessage().contains("was not found."));
+ assertThat(rootCause, isA(InferenceException.class));
+ assertThat(rootCause.getMessage(), startsWith("Imported module"));
+ assertThat(rootCause.getMessage(), containsString("was not found."));
}
}
fail("InferenceException should be thrown");
} catch (final SomeModifiersUnresolvedException e) {
final Throwable rootCause = Throwables.getRootCause(e);
- assertTrue(rootCause instanceof InferenceException);
- assertTrue(rootCause.getMessage()
- .startsWith("Type [(urn:simple.types.data.demo?revision=2013-02-27)int-ext] was not found."));
+ assertThat(rootCause, isA(InferenceException.class));
+ assertThat(rootCause.getMessage(),
+ startsWith("Type [(urn:simple.types.data.demo?revision=2013-02-27)int-ext] was not found."));
}
}
fail("SomeModifiersUnresolvedException should be thrown");
} catch (final SomeModifiersUnresolvedException e) {
final Throwable rootCause = Throwables.getRootCause(e);
- assertTrue(rootCause instanceof InferenceException);
- assertTrue(rootCause.getMessage().startsWith(
+ assertThat(rootCause, isA(InferenceException.class));
+ assertThat(rootCause.getMessage(), startsWith(
"Augment target 'Absolute{path=[(urn:simple.container.demo)unknown]}' not found"));
}
}
TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile4.yang");
fail("ReactorException should be thrown");
} catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().contains("Error in module 'test4' in the refine of uses "
+ assertThat(e.getCause().getMessage(), containsString("Error in module 'test4' in the refine of uses "
+ "'Relative{path=[(urn:simple.container.demo)node]}': can not perform refine of 'PRESENCE' for"
+ " the target 'LEAF_LIST'."));
}
TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile5.yang");
fail("ReactorException should be thrown");
} catch (final ReactorException e) {
- final String message = e.getCause().getMessage();
-
- assertTrue(message.contains("Invalid length constraint [4..10]"));
+ assertThat(e.getCause().getMessage(), containsString("Invalid length constraint [4..10]"));
}
}
TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile6.yang");
fail("ReactorException should be thrown");
} catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith("Invalid range constraint: [[5..20]]"));
+ assertThat(e.getCause().getMessage(), startsWith("Invalid range constraint: [[5..20]]"));
}
}
} catch (final ReactorException e) {
final String expected = "Error in module 'container': cannot add '(urn:simple.container.demo)foo'. "
+ "Node name collision: '(urn:simple.container.demo)foo' already declared";
- assertTrue(e.getCause().getMessage().contains(expected));
+ assertThat(e.getCause().getMessage(), containsString(expected));
}
}
} catch (final ReactorException e) {
final String expected = "Error in module 'container-list': cannot add '(urn:simple.container.demo)foo'. "
+ "Node name collision: '(urn:simple.container.demo)foo' already declared";
- assertTrue(e.getCause().getMessage().contains(expected));
+ assertThat(e.getCause().getMessage(), containsString(expected));
}
}
} catch (final ReactorException e) {
final String expected = "Error in module 'container-leaf': cannot add '(urn:simple.container.demo)foo'. "
+ "Node name collision: '(urn:simple.container.demo)foo' already declared";
- assertTrue(e.getCause().getMessage().contains(expected));
+ assertThat(e.getCause().getMessage(), containsString(expected));
}
}
TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/typedef.yang");
fail("SourceException should be thrown");
} catch (final ReactorException e) {
- assertTrue(e.getCause().getMessage().startsWith(
+ assertThat(e.getCause().getMessage(), startsWith(
"Duplicate name for typedef (urn:simple.container.demo)int-ext [at"));
}
}
"/negative-scenario/duplicity/augment0.yang",
"/negative-scenario/duplicity/augment1.yang");
testLog = output.toString();
- assertTrue(testLog.contains(
+ assertThat(testLog, containsString(
"An augment cannot add node named 'id' because this name is already used in target"));
}
@Test
public void testDuplicityInAugmentTarget2() throws IOException, ReactorException, YangSyntaxErrorException {
- TestUtils.loadModuleResources(getClass(),
- "/negative-scenario/duplicity/augment0.yang",
- "/negative-scenario/duplicity/augment2.yang");
- testLog = output.toString();
- assertTrue(testLog.contains(
- "An augment cannot add node named 'delta' because this name is already used in target"));
+ try {
+ TestUtils.loadModuleResources(getClass(),
+ "/negative-scenario/duplicity/augment0.yang",
+ "/negative-scenario/duplicity/augment2.yang");
+ fail("Duplicate leaf not detected");
+ } catch (SomeModifiersUnresolvedException e) {
+ final Throwable rootCause = Throwables.getRootCause(e);
+ assertThat(rootCause, isA(SourceException.class));
+ assertThat(rootCause.getMessage(), containsString("Cannot add schema tree child with name "
+ + "(urn:simple.augment2.demo?revision=2014-06-02)delta, a conflicting child already exists"));
+
+ }
}
@Test
"/negative-scenario/testfile8.yang",
"/negative-scenario/testfile7.yang");
testLog = output.toString();
- assertTrue(testLog.contains(
+ assertThat(testLog, containsString(
"An augment cannot add node 'linkleaf' because it is mandatory and in module different than target"));
}
TestUtils.loadModuleResources(getClass(), "/negative-scenario/invalid-list-key-def.yang");
fail("InferenceException should be thrown");
} catch (final ReactorException e) {
- final String expected = "Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def)application-map'";
- assertTrue(e.getCause().getMessage().startsWith(expected));
+ assertThat(e.getCause().getMessage(),
+ startsWith("Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def)application-map'"));
}
}
}