import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.google.common.util.concurrent.CheckedFuture;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import org.mockito.internal.util.io.IOUtil;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
assertFalse(schemaService.hasListeners());
final SchemaContextHolder actualSchemaCtx = new SchemaContextHolder();
- final SchemaContextListener listener = prepareSchemaCtxListener(actualSchemaCtx);
+ final SchemaContextListener listener = actualSchemaCtx::setSchemaContext;
final ListenerRegistration<SchemaContextListener> registerSchemaContextListener =
schemaService.registerSchemaContextListener(listener);
assertEquals(registerSchemaContextListener.getInstance(), listener);
final SchemaContextHolder actualSchemaCtx = new SchemaContextHolder();
- final SchemaContextListener schemaCtxListener = prepareSchemaCtxListener(actualSchemaCtx);
+ final SchemaContextListener schemaCtxListener = actualSchemaCtx::setSchemaContext;
final ListenerRegistration<SchemaContextListener> registerSchemaContextListener =
schemaService.registerSchemaContextListener(schemaCtxListener);
assertEquals(registerSchemaContextListener.getInstance(), schemaCtxListener);
assertTrue(baseSchemaContext.getModules().size() == 1);
final SchemaContextHolder actualSchemaCtx = new SchemaContextHolder();
- final SchemaContextListener schemaCtxListener = prepareSchemaCtxListener(actualSchemaCtx);
-
- schemaService.registerSchemaContextListener(schemaCtxListener);
+ schemaService.registerSchemaContextListener(actualSchemaCtx::setSchemaContext);
assertEquals(baseSchemaContext, actualSchemaCtx.getSchemaContext());
assertEquals(nextSchemaContext, actualSchemaCtx.getSchemaContext());
}
- @SuppressWarnings("deprecation")
@Test
public void getSourceTest() throws Exception {
- final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("odl-datastore-test", "2014-03-13");
- final CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
- schemaService.getSource(sourceIdentifier);
- final YangTextSchemaSource yangTextSchemaSource = source.checkedGet();
+ final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("odl-datastore-test",
+ Revision.of("2014-03-13"));
+ final YangTextSchemaSource yangTextSchemaSource = schemaService.getSource(sourceIdentifier).get();
final Collection<String> lines = IOUtil.readLines(yangTextSchemaSource.openStream());
assertEquals("module odl-datastore-test {", lines.iterator().next());
}
assertTrue(!registerAvailableYangs.isEmpty());
}
- private SchemaContextListener prepareSchemaCtxListener(final SchemaContextHolder actualSchemaCtx) {
- return new SchemaContextListener() {
-
- @Override
- public void onGlobalContextUpdated(final SchemaContext context) {
- actualSchemaCtx.setSchemaContext(context);
- }
- };
- }
-
private class SchemaContextHolder {
private SchemaContext schemaCtx;