X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fschema%2Fprovider%2Fimpl%2FRemoteSchemaProviderTest.java;h=771c13073693414bc2f46cc4eff8b2cbab80bbc4;hb=ea6d6a867e47ea40f97d910300bd2afdcf4e1e88;hp=34296001409dbc13f491abc7a507f39f91db87cc;hpb=38fa2a64bd6e206b2d8a6b153154104347854408;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 index 3429600140..771c130736 100644 --- 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 @@ -5,29 +5,32 @@ * 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.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; 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.io.CharSource; +import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.ExecutionException; 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; @@ -35,33 +38,32 @@ public class RemoteSchemaProviderTest { @Before public void setUp() { - mockedRemoteSchemaRepository = Mockito.mock(RemoteYangTextSourceProvider.class); - ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService()); + mockedRemoteSchemaRepository = mock(RemoteYangTextSourceProvider.class); remoteSchemaProvider = new RemoteSchemaProvider(mockedRemoteSchemaRepository, - ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService())); + ExecutionContexts.fromExecutor(MoreExecutors.directExecutor())); } @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)); + public void getExistingYangTextSchemaSource() throws IOException, InterruptedException, ExecutionException { + YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(ID, + CharSource.wrap("Test").asByteSource(StandardCharsets.UTF_8)); + doReturn(Futures.successful(new YangTextSchemaSourceSerializationProxy(schemaSource))) + .when(mockedRemoteSchemaRepository).getYangTextSchemaSource(ID); - YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).checkedGet(); - assertEquals(providedSource.getIdentifier(), ID); - assertArrayEquals(providedSource.read(), schemaSource.read()); + YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).get(); + assertEquals(ID, providedSource.getIdentifier()); + assertArrayEquals(schemaSource.read(), providedSource.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"))); + @Test + public void getNonExistingSchemaSource() throws InterruptedException { + final var exception = new SchemaSourceException("Source not provided"); + doReturn(Futures.failed(exception)).when(mockedRemoteSchemaRepository).getYangTextSchemaSource(ID); - CheckedFuture sourceFuture = remoteSchemaProvider.getSource(ID); + ListenableFuture sourceFuture = remoteSchemaProvider.getSource(ID); assertTrue(sourceFuture.isDone()); - sourceFuture.checkedGet(); + + final var cause = assertThrows(ExecutionException.class, sourceFuture::get).getCause(); + assertSame(exception, cause); } -} \ No newline at end of file +}