+ @Test
+ public void testDeviation() throws Exception {
+ // load first module
+ SchemaContext context = null;
+ String resource = "/model/types.yang";
+
+ try (InputStream stream = new FileInputStream(getClass().getResource(resource).getPath())) {
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ }
+
+ // load another modules and parse them against already existing context
+ Set<Module> modules = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/deviation-test.yang")
+ .getPath())) {
+ List<InputStream> input = Lists.newArrayList(stream);
+ modules = TestUtils.loadModulesWithContext(input, context);
+ }
+ assertNotNull(modules);
+
+ // test deviation
+ Module testModule = TestUtils.findModule(modules, "deviation-test");
+ Set<Deviation> deviations = testModule.getDeviations();
+ assertEquals(1, deviations.size());
+ Deviation dev = deviations.iterator().next();
+
+ assertEquals("system/user ref", dev.getReference());
+
+ URI expectedNS = URI.create("urn:simple.types.test");
+ DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Date expectedRev = simpleDateFormat.parse("2013-07-03");
+ List<QName> path = new ArrayList<QName>();
+ path.add(new QName(expectedNS, expectedRev, "t", "interfaces"));
+ path.add(new QName(expectedNS, expectedRev, "t", "ifEntry"));
+ SchemaPath expectedPath = new SchemaPath(path, true);
+
+ assertEquals(expectedPath, dev.getTargetPath());
+ assertEquals(Deviate.ADD, dev.getDeviate());
+ }
+