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.ToStringHelper;
18 import com.google.common.util.concurrent.Futures;
19 import com.google.common.util.concurrent.ListenableFuture;
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.common.Revision;
25 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
26 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
27 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
28 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
29 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
31 public class YangLibServiceImplTest {
33 private static final String TEST_OUTPUT_STRING = "hello world";
36 public void testSchema() throws SchemaSourceException {
38 final SchemaRepository schemaRepository = mock(SchemaRepository.class);
39 final YangLibServiceImpl yangLibService = new YangLibServiceImpl(schemaRepository);
41 final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("name", Revision.of("2016-01-01"));
43 final YangTextSchemaSource yangTextSchemaSource = new YangTextSchemaSource(sourceIdentifier) {
45 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
50 public InputStream openStream() throws IOException {
51 return new ByteArrayInputStream(TEST_OUTPUT_STRING.getBytes());
55 final ListenableFuture<YangTextSchemaSource> sourceFuture = Futures.immediateFuture(yangTextSchemaSource);
56 doReturn(sourceFuture).when(schemaRepository).getSchemaSource(any(SourceIdentifier.class),
57 eq(YangTextSchemaSource.class));
59 final String outputStream = yangLibService.getSchema("name", "2016-01-01");
60 assertEquals(TEST_OUTPUT_STRING, outputStream);