Add change notification functionality to yang-store.
[controller.git] / opendaylight / config / yang-store-impl / src / test / java / org / opendaylight / controller / config / yang / store / impl / HardcodedYangStoreService.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.yang.store.impl;
9
10 import static org.junit.Assert.assertNotNull;
11
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
18 import org.apache.commons.io.IOUtils;
19 import org.opendaylight.controller.config.yang.store.api.YangStoreException;
20 import org.opendaylight.controller.config.yang.store.api.YangStoreListenerRegistration;
21 import org.opendaylight.controller.config.yang.store.api.YangStoreService;
22 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
23 import org.opendaylight.controller.config.yang.store.spi.YangStoreListener;
24
25 public class HardcodedYangStoreService implements YangStoreService {
26
27     private final Collection<ByteArrayInputStream> byteArrayInputStreams;
28
29     public HardcodedYangStoreService(
30             Collection<? extends InputStream> inputStreams)
31             throws YangStoreException, IOException {
32         byteArrayInputStreams = new ArrayList<>();
33         for (InputStream inputStream : inputStreams) {
34             assertNotNull(inputStream);
35             byte[] content = IOUtils.toByteArray(inputStream);
36             ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
37                     content);
38             byteArrayInputStreams.add(byteArrayInputStream);
39         }
40     }
41
42     @Override
43     public YangStoreSnapshot getYangStoreSnapshot() throws YangStoreException {
44         for (InputStream inputStream : byteArrayInputStreams) {
45             try {
46                 inputStream.reset();
47             } catch (IOException e) {
48                 throw new RuntimeException(e);
49             }
50         }
51         return new MbeParser().parseYangFiles(byteArrayInputStreams);
52     }
53
54     @Override
55     public YangStoreListenerRegistration registerListener(YangStoreListener listener){
56         throw new UnsupportedOperationException("Cannot register for changes on this service");
57     }
58 }