2 * Copyright (c) 2013 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
8 package org.opendaylight.controller.netconf.it;
10 import static org.junit.Assert.assertNotNull;
12 import java.io.ByteArrayInputStream;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashSet;
18 import java.util.List;
20 import org.apache.commons.io.IOUtils;
21 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException;
22 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreService;
23 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreServiceImpl;
24 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
27 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
29 public class HardcodedYangStoreService implements YangStoreService {
31 private final List<InputStream> byteArrayInputStreams;
33 public HardcodedYangStoreService(
34 Collection<? extends InputStream> inputStreams)
35 throws YangStoreException, IOException {
36 byteArrayInputStreams = new ArrayList<>();
37 for (InputStream inputStream : inputStreams) {
38 assertNotNull(inputStream);
39 byte[] content = IOUtils.toByteArray(inputStream);
40 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
42 byteArrayInputStreams.add(byteArrayInputStream);
47 public YangStoreSnapshot getYangStoreSnapshot() throws YangStoreException {
48 for (InputStream inputStream : byteArrayInputStreams) {
51 } catch (IOException e) {
52 throw new RuntimeException(e);
56 YangParserImpl yangParser = new YangParserImpl();
57 final SchemaContext schemaContext = yangParser.resolveSchemaContext(new HashSet<>(yangParser.parseYangModelsFromStreamsMapped(byteArrayInputStreams).values()));
58 YangStoreServiceImpl yangStoreService = new YangStoreServiceImpl(new SchemaContextProvider() {
60 public SchemaContext getSchemaContext() {
61 return schemaContext ;
64 return yangStoreService.getYangStoreSnapshot();