X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fschema%2Fprovider%2Fimpl%2FRemoteSchemaProviderTest.java;fp=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fschema%2Fprovider%2Fimpl%2FRemoteSchemaProviderTest.java;h=2c48b2c6c6da4f102dd66f93d437ac8594152c22;hb=f2aa0c3d35d7ec7b61fafe614128042c1a0251d8;hp=0000000000000000000000000000000000000000;hpb=6e744645da016deeaa4d6791161e760a3edc7fe0;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteSchemaProviderTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteSchemaProviderTest.java new file mode 100644 index 0000000000..2c48b2c6c6 --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteSchemaProviderTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.cluster.schema.provider.impl; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import akka.dispatch.ExecutionContexts; +import akka.dispatch.Futures; +import com.google.common.io.ByteSource; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.io.IOException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider; +import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException; +import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; +import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; + +public class RemoteSchemaProviderTest { + + private static final SourceIdentifier ID = new SourceIdentifier("Test", "2015-10-30"); + + private RemoteSchemaProvider remoteSchemaProvider; + private RemoteYangTextSourceProvider mockedRemoteSchemaRepository; + + @Before + public void setUp() { + mockedRemoteSchemaRepository = Mockito.mock(RemoteYangTextSourceProvider.class); + ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService()); + remoteSchemaProvider = new RemoteSchemaProvider(mockedRemoteSchemaRepository, + ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService())); + } + + @Test + public void getExistingYangTextSchemaSource() throws IOException, SchemaSourceException { + String source = "Test"; + YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(ID, ByteSource.wrap(source.getBytes())); + YangTextSchemaSourceSerializationProxy sourceProxy = new YangTextSchemaSourceSerializationProxy(schemaSource); + Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(Futures.successful(sourceProxy)); + + YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).checkedGet(); + assertEquals(providedSource.getIdentifier(), ID); + assertArrayEquals(providedSource.read(), schemaSource.read()); + } + + @Test(expected = SchemaSourceException.class) + public void getNonExistingSchemaSource() throws Exception { + Futures.failed(new Exception("halo")); + + Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn( + Futures.failed(new SchemaSourceException("Source not provided"))); + + CheckedFuture sourceFuture = remoteSchemaProvider.getSource(ID); + assertTrue(sourceFuture.isDone()); + sourceFuture.checkedGet(); + } +} \ No newline at end of file