2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yanglib.impl;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.eq;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
17 import com.google.common.base.MoreObjects;
18 import com.google.common.util.concurrent.CheckedFuture;
19 import com.google.common.util.concurrent.Futures;
20 import java.io.ByteArrayInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import org.junit.Test;
24 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
25 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
26 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
27 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
28 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
30 public class YangLibServiceImplTest {
32 private static final String TEST_OUTPUT_STRING = "hello world";
35 public void testSchema() throws SchemaSourceException {
37 final SchemaRepository schemaRepository = mock(SchemaRepository.class);
38 final YangLibServiceImpl yangLibService = new YangLibServiceImpl();
39 yangLibService.setSchemaRepository(schemaRepository);
41 final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("name", "2016-01-01");
43 final YangTextSchemaSource yangTextSchemaSource = new YangTextSchemaSource(sourceIdentifier) {
45 protected MoreObjects.ToStringHelper addToStringAttributes(MoreObjects.ToStringHelper toStringHelper) {
50 public InputStream openStream() throws IOException {
51 return new ByteArrayInputStream(TEST_OUTPUT_STRING.getBytes());
55 final CheckedFuture<YangTextSchemaSource, SchemaSourceException> sourceFuture =
56 Futures.immediateCheckedFuture(yangTextSchemaSource);
57 doReturn(sourceFuture).when(schemaRepository).getSchemaSource(any(SourceIdentifier.class),
58 eq(YangTextSchemaSource.class));
60 final String outputStream = yangLibService.getSchema("name", "2016-01-01");
61 assertEquals(TEST_OUTPUT_STRING, outputStream);