Do not use RevisionSourceIdentifier 77/101077/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 11 May 2022 13:48:36 +0000 (15:48 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 11 May 2022 16:16:55 +0000 (18:16 +0200)
We only have a plain SourceIdentifier, adjust codebase to that.

Change-Id: Ib981bb8955c4e29f14e29a8f461daf02616b694a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteSchemaProvider.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/schema/provider/impl/YangTextSchemaSourceSerializationProxy.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteSchemaProviderTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/RemoteYangTextSourceProviderImplTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/schema/provider/impl/YangTextSourceSerializationProxyTest.java

index 4a4416d..c9e5078 100644 (file)
@@ -38,7 +38,7 @@ public class RemoteSchemaProvider implements SchemaSourceProvider<YangTextSchema
 
     @Override
     public ListenableFuture<YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
-        LOG.trace("Getting yang schema source for {}", sourceIdentifier.getName());
+        LOG.trace("Getting yang schema source for {}", sourceIdentifier.name().getLocalName());
 
         Future<YangTextSchemaSourceSerializationProxy> result = remoteRepo.getYangTextSchemaSource(sourceIdentifier);
 
index 202de58..e2b55c0 100644 (file)
@@ -5,7 +5,6 @@
  * 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 com.google.common.annotations.Beta;
@@ -13,7 +12,8 @@ import com.google.common.io.ByteSource;
 import java.io.IOException;
 import java.io.Serializable;
 import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 
 /**
@@ -28,13 +28,14 @@ public class YangTextSchemaSourceSerializationProxy implements Serializable {
     private final String name;
 
     public YangTextSchemaSourceSerializationProxy(final YangTextSchemaSource source) throws IOException {
-        this.revision = source.getIdentifier().getRevision().orElse(null);
-        this.name = source.getIdentifier().getName();
-        this.schemaSource = source.read();
+        final var id = source.getIdentifier();
+        revision = id.revision();
+        name = id.name().getLocalName();
+        schemaSource = source.read();
     }
 
     public YangTextSchemaSource getRepresentation() {
-        return YangTextSchemaSource.delegateForByteSource(
-                RevisionSourceIdentifier.create(name, revision), ByteSource.wrap(schemaSource));
+        return YangTextSchemaSource.delegateForByteSource(new SourceIdentifier(Unqualified.of(name), revision),
+            ByteSource.wrap(schemaSource));
     }
 }
index 2a8ddd2..771c130 100644 (file)
@@ -7,12 +7,11 @@
  */
 package org.opendaylight.controller.cluster.schema.provider.impl;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
 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.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
@@ -27,14 +26,12 @@ import java.util.concurrent.ExecutionException;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 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 = RevisionSourceIdentifier.create("Test", Revision.of("2015-10-30"));
+    private static final SourceIdentifier ID = new SourceIdentifier("Test", "2015-10-30");
 
     private RemoteSchemaProvider remoteSchemaProvider;
     private RemoteYangTextSourceProvider mockedRemoteSchemaRepository;
@@ -60,16 +57,13 @@ public class RemoteSchemaProviderTest {
 
     @Test
     public void getNonExistingSchemaSource() throws InterruptedException {
-        doReturn(Futures.failed(new SchemaSourceException("Source not provided")))
-            .when(mockedRemoteSchemaRepository).getYangTextSchemaSource(ID);
+        final var exception = new SchemaSourceException("Source not provided");
+        doReturn(Futures.failed(exception)).when(mockedRemoteSchemaRepository).getYangTextSchemaSource(ID);
 
         ListenableFuture<YangTextSchemaSource> sourceFuture = remoteSchemaProvider.getSource(ID);
         assertTrue(sourceFuture.isDone());
-        try {
-            sourceFuture.get();
-            fail("Expected a failure to occur");
-        } catch (ExecutionException e) {
-            assertThat(e.getCause(), instanceOf(SchemaSourceException.class));
-        }
+
+        final var cause = assertThrows(ExecutionException.class, sourceFuture::get).getCause();
+        assertSame(exception, cause);
     }
 }
index 1fda858..7f60216 100644 (file)
@@ -9,7 +9,10 @@ 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 com.google.common.io.ByteSource;
 import com.google.common.util.concurrent.Futures;
@@ -17,65 +20,63 @@ import java.util.Collections;
 import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
 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;
 import scala.concurrent.Await;
-import scala.concurrent.Future;
 import scala.concurrent.duration.FiniteDuration;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class RemoteYangTextSourceProviderImplTest {
+    private static final SourceIdentifier ID = new SourceIdentifier("Test", "2015-10-30");
 
-    private static final SourceIdentifier ID = RevisionSourceIdentifier.create("Test", Revision.of("2015-10-30"));
+    @Mock
+    private SchemaRepository mockedLocalRepository;
 
     private RemoteYangTextSourceProviderImpl remoteRepository;
-    private SchemaRepository mockedLocalRepository;
     private final Set<SourceIdentifier> providedSources = Collections.singleton(ID);
 
     @Before
     public void setUp() {
-        mockedLocalRepository = Mockito.mock(SchemaRepository.class);
-
         remoteRepository = new RemoteYangTextSourceProviderImpl(mockedLocalRepository, providedSources);
     }
 
     @Test
     public void testGetExistingYangTextSchemaSource() throws Exception {
-        String source = "Test source.";
-        YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(
-                ID, ByteSource.wrap(source.getBytes()));
-        Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(
-                Futures.immediateFuture(schemaSource));
+        var schemaSource = YangTextSchemaSource.delegateForByteSource(ID, ByteSource.wrap("Test source.".getBytes()));
+
+        doReturn(Futures.immediateFuture(schemaSource)).when(mockedLocalRepository)
+            .getSchemaSource(ID, YangTextSchemaSource.class);
 
-        Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture =
-                remoteRepository.getYangTextSchemaSource(ID);
+        var retrievedSourceFuture = remoteRepository.getYangTextSchemaSource(ID);
         assertTrue(retrievedSourceFuture.isCompleted());
-        YangTextSchemaSource resultSchemaSource = Await.result(retrievedSourceFuture,
-                FiniteDuration.Zero()).getRepresentation();
+        var resultSchemaSource = Await.result(retrievedSourceFuture, FiniteDuration.Zero()).getRepresentation();
         assertEquals(resultSchemaSource.getIdentifier(), schemaSource.getIdentifier());
         assertArrayEquals(resultSchemaSource.read(), schemaSource.read());
     }
 
-    @Test(expected = SchemaSourceException.class)
+    @Test
     public void testGetNonExistentYangTextSchemaSource() throws Exception {
-        Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(
-                Futures.immediateFailedFuture(new SchemaSourceException("Source is not provided")));
+        final var exception = new SchemaSourceException("Source is not provided");
+
+        doReturn(Futures.immediateFailedFuture(exception)).when(mockedLocalRepository)
+            .getSchemaSource(ID, YangTextSchemaSource.class);
 
-        Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture =
-                remoteRepository.getYangTextSchemaSource(ID);
+        var retrievedSourceFuture = remoteRepository.getYangTextSchemaSource(ID);
         assertTrue(retrievedSourceFuture.isCompleted());
-        Await.result(retrievedSourceFuture, FiniteDuration.Zero());
+
+        final var ex = assertThrows(SchemaSourceException.class,
+            () -> Await.result(retrievedSourceFuture, FiniteDuration.Zero()));
+        assertSame(ex, exception);
     }
 
     @Test
     public void testGetProvidedSources() throws Exception {
-        Set<SourceIdentifier> remoteProvidedSources = Await.result(remoteRepository
-                .getProvidedSources(), FiniteDuration.Zero());
+        var remoteProvidedSources = Await.result(remoteRepository.getProvidedSources(), FiniteDuration.Zero());
         assertEquals(providedSources, remoteProvidedSources);
     }
-
 }
index 084fd52..c943451 100644 (file)
@@ -20,20 +20,17 @@ import java.io.ObjectOutputStream;
 import java.nio.charset.StandardCharsets;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 
 public class YangTextSourceSerializationProxyTest {
-
     private YangTextSchemaSource schemaSource;
 
     @Before
     public void setUp() {
         String source = "Test source.";
-        schemaSource = YangTextSchemaSource.delegateForByteSource(
-                RevisionSourceIdentifier.create("test", Revision.of("2015-10-30")),
-                ByteSource.wrap(source.getBytes(StandardCharsets.UTF_8)));
+        schemaSource = YangTextSchemaSource.delegateForByteSource(new SourceIdentifier("test", "2015-10-30"),
+            ByteSource.wrap(source.getBytes(StandardCharsets.UTF_8)));
     }