import static org.opendaylight.restconf.nb.jaxrs.AbstractRestconfTest.assertEntity;
import static org.opendaylight.restconf.nb.jaxrs.AbstractRestconfTest.assertError;
-import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.Futures;
+import java.io.IOException;
import java.io.Reader;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService.YangTextSourceExtension;
+import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
+import org.opendaylight.restconf.server.mdsal.MdsalDatabindProvider;
import org.opendaylight.restconf.server.mdsal.MdsalRestconfServer;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class RestconfSchemaServiceTest {
// schema context with modules
- private static final EffectiveModelContext SCHEMA_CONTEXT =
+ private static final EffectiveModelContext MODEL_CONTEXT =
YangParserTestUtils.parseYangResourceDirectory("/modules");
@Mock
- private DOMSchemaService schemaService;
- @Mock
- private DOMYangTextSourceProvider sourceProvider;
+ private YangTextSourceExtension sourceProvider;
@Mock
private DOMDataBroker dataBroker;
@Mock
@Mock
private DOMMountPointService mountPointService;
@Mock
- private YangTextSchemaSource yangSource;
+ private YangTextSource yangSource;
@Mock
private Reader yangReader;
@Before
public void setup() throws Exception {
- doReturn(SCHEMA_CONTEXT).when(schemaService).getGlobalContext();
- doReturn(ImmutableClassToInstanceMap.of(DOMYangTextSourceProvider.class, sourceProvider)).when(schemaService)
- .getExtensions();
-
- restconf = new JaxRsRestconf(new MdsalRestconfServer(schemaService, dataBroker, rpcService, actionService,
- mountPointService));
+ restconf = new JaxRsRestconf(new MdsalRestconfServer(
+ new MdsalDatabindProvider(new FixedDOMSchemaService(() -> MODEL_CONTEXT, sourceProvider)), dataBroker,
+ rpcService, actionService, mountPointService));
}
/**
@Test
public void getSchemaTest() throws Exception {
doReturn(Futures.immediateFuture(yangSource)).when(sourceProvider)
- .getSource(new SourceIdentifier("module1", Revision.of("2014-01-01")));
+ .getYangTexttSource(new SourceIdentifier("module1", Revision.of("2014-01-01")));
doReturn(yangReader).when(yangSource).openStream();
assertSame(yangReader, assertEntity(Reader.class, 200,
}
/**
- * Try to get schema with identifier which does not contain revision catching
- * <code>RestconfDocumentedException</code>. Error type, error tag and error status code are compared to expected
- * values.
+ * Try to get schema with identifier which does not contain revision catching and check if the correct module
+ * was found.
*/
@Test
- public void getSchemaWithoutRevisionTest() {
- final var error = assertError(ar -> restconf.modulesYinGET("module", null, ar));
- assertEquals("Source module not found", error.getErrorMessage());
- assertEquals(ErrorType.APPLICATION, error.getErrorType());
- assertEquals(ErrorTag.DATA_MISSING, error.getErrorTag());
+ public void getSchemaWithoutRevisionTest() throws IOException {
+ doReturn(Futures.immediateFuture(yangSource)).when(sourceProvider)
+ .getYangTexttSource(new SourceIdentifier("module-without-revision", (Revision) null));
+ doReturn(yangReader).when(yangSource).openStream();
+ assertSame(yangReader, assertEntity(Reader.class, 200,
+ ar -> restconf.modulesYangGET("module-without-revision", null, ar)));
}
}