2 * Copyright (c) 2015 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.controller.cluster.schema.provider.impl;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertTrue;
15 import akka.dispatch.ExecutionContexts;
16 import akka.dispatch.Futures;
17 import com.google.common.io.ByteSource;
18 import com.google.common.util.concurrent.CheckedFuture;
19 import com.google.common.util.concurrent.MoreExecutors;
20 import java.io.IOException;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.Mockito;
24 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
25 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
26 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
27 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
29 public class RemoteSchemaProviderTest {
31 private static final SourceIdentifier ID = new SourceIdentifier("Test", "2015-10-30");
33 private RemoteSchemaProvider remoteSchemaProvider;
34 private RemoteYangTextSourceProvider mockedRemoteSchemaRepository;
38 mockedRemoteSchemaRepository = Mockito.mock(RemoteYangTextSourceProvider.class);
39 ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService());
40 remoteSchemaProvider = new RemoteSchemaProvider(mockedRemoteSchemaRepository,
41 ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService()));
45 public void getExistingYangTextSchemaSource() throws IOException, SchemaSourceException {
46 String source = "Test";
47 YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(ID, ByteSource.wrap(source.getBytes()));
48 YangTextSchemaSourceSerializationProxy sourceProxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
49 Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(Futures.successful(sourceProxy));
51 YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).checkedGet();
52 assertEquals(providedSource.getIdentifier(), ID);
53 assertArrayEquals(providedSource.read(), schemaSource.read());
56 @Test(expected = SchemaSourceException.class)
57 public void getNonExistingSchemaSource() throws Exception {
58 Futures.failed(new Exception("halo"));
60 Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(
61 Futures.<YangTextSchemaSourceSerializationProxy>failed(new SchemaSourceException("Source not provided")));
63 CheckedFuture sourceFuture = remoteSchemaProvider.getSource(ID);
64 assertTrue(sourceFuture.isDone());
65 sourceFuture.checkedGet();