summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'infra/translate-utils/src/test/java')
-rw-r--r--infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java35
-rw-r--r--infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java (renamed from infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/IdentifierCacheKeyFactoryTest.java)44
2 files changed, 53 insertions, 26 deletions
diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java
index 3639439ce..74aef67d0 100644
--- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java
+++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java
@@ -18,6 +18,7 @@ package io.fd.honeycomb.translate.util.read.cache;
import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.google.common.base.Optional;
@@ -35,13 +36,9 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class DumpCacheManagerTest {
- private interface DataObj extends DataObject {}
-
@Mock
private EntityDumpExecutor<IpDetailsReplyDump, Void> executor;
-
private InstanceIdentifier<DataObj> identifier;
-
private DumpCacheManager<IpDetailsReplyDump, Void> managerPositive;
private DumpCacheManager<IpDetailsReplyDump, Void> managerPositiveWithPostProcessing;
private DumpCacheManager<IpDetailsReplyDump, Void> managerNegative;
@@ -54,23 +51,26 @@ public class DumpCacheManagerTest {
managerPositive =
new DumpCacheManager.DumpCacheManagerBuilder<IpDetailsReplyDump, Void>()
.withExecutor(executor)
+ .acceptOnly(IpDetailsReplyDump.class)
.build();
managerPositiveWithPostProcessing =
new DumpCacheManager.DumpCacheManagerBuilder<IpDetailsReplyDump, Void>()
.withExecutor(executor)
+ .acceptOnly(IpDetailsReplyDump.class)
.withPostProcessingFunction(createPostProcessor())
.build();
managerNegative =
new DumpCacheManager.DumpCacheManagerBuilder<IpDetailsReplyDump, Void>()
.withExecutor(executor)
+ .acceptOnly(IpDetailsReplyDump.class)
.build();
cache = new ModificationCache();
identifier = InstanceIdentifier.create(DataObj.class);
//manager uses this implementation by default, so it can be used to test behaviour
- cacheKeyFactory = new IdentifierCacheKeyFactory();
+ cacheKeyFactory = new TypeAwareIdentifierCacheKeyFactory(IpDetailsReplyDump.class);
}
@@ -131,6 +131,28 @@ public class DumpCacheManagerTest {
assertEquals(7, optionalDump.get().ipDetails.get(0).swIfIndex);
}
+ @Test
+ public void testSameKeyDifferentTypes() throws ReadFailedException {
+ final DumpCacheManager<String, Void> stringManager =
+ new DumpCacheManager.DumpCacheManagerBuilder<String, Void>()
+ .withExecutor((InstanceIdentifier, Void) -> "value")
+ .acceptOnly(String.class)
+ .build();
+
+ final DumpCacheManager<Integer, Void> intManager = new DumpCacheManager.DumpCacheManagerBuilder<Integer, Void>()
+ .acceptOnly(Integer.class)
+ .withExecutor((InstanceIdentifier, Void) -> 3).build();
+
+ final Optional<String> stringDump = stringManager.getDump(identifier, cache, NO_PARAMS);
+ final Optional<Integer> integerDump = intManager.getDump(identifier, cache, NO_PARAMS);
+
+ assertTrue(stringDump.isPresent());
+ assertTrue(integerDump.isPresent());
+ assertEquals("value", stringDump.get());
+ assertEquals(3, integerDump.get().intValue());
+
+ }
+
private EntityDumpPostProcessingFunction<IpDetailsReplyDump> createPostProcessor() {
return ipDetailsReplyDump -> {
IpDetailsReplyDump modified = new IpDetailsReplyDump();
@@ -146,6 +168,9 @@ public class DumpCacheManagerTest {
};
}
+ private interface DataObj extends DataObject {
+ }
+
private static final class IpDetailsReplyDump {
List<IpDetails> ipDetails = new ArrayList<>();
diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/IdentifierCacheKeyFactoryTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java
index e7eae552c..305fba143 100644
--- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/IdentifierCacheKeyFactoryTest.java
+++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java
@@ -28,31 +28,15 @@ import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class IdentifierCacheKeyFactoryTest {
-
- private interface SuperDataObject extends DataObject {
- }
-
- private interface DataObjectParent extends DataObject, ChildOf<SuperDataObject>, Identifiable<DataObjectParentKey> {
- }
-
- private class DataObjectParentKey implements Identifier<DataObjectParent> {
- }
-
- private interface DataObjectChild extends DataObject, ChildOf<DataObjectParent>, Identifiable<DataObjectChildKey> {
- }
-
- private class DataObjectChildKey implements Identifier<DataObjectChild> {
- }
+public class TypeAwareIdentifierCacheKeyFactoryTest {
private DataObjectParentKey parentKey;
private DataObjectChildKey childKey;
private InstanceIdentifier<DataObjectChild> identifierBothKeyed;
private InstanceIdentifier<DataObjectChild> identifierOneMissing;
private InstanceIdentifier<DataObjectChild> identifierNoneKeyed;
-
- private IdentifierCacheKeyFactory simpleKeyFactory;
- private IdentifierCacheKeyFactory complexKeyFactory;
+ private TypeAwareIdentifierCacheKeyFactory simpleKeyFactory;
+ private TypeAwareIdentifierCacheKeyFactory complexKeyFactory;
@Before
public void init() {
@@ -64,8 +48,9 @@ public class IdentifierCacheKeyFactoryTest {
identifierNoneKeyed = InstanceIdentifier.create(SuperDataObject.class).child(DataObjectParent.class)
.child(DataObjectChild.class);
- complexKeyFactory = new IdentifierCacheKeyFactory(ImmutableSet.of(DataObjectParent.class));
- simpleKeyFactory = new IdentifierCacheKeyFactory();
+ complexKeyFactory =
+ new TypeAwareIdentifierCacheKeyFactory(String.class, ImmutableSet.of(DataObjectParent.class));
+ simpleKeyFactory = new TypeAwareIdentifierCacheKeyFactory(String.class);
}
@Test
@@ -127,6 +112,7 @@ public class IdentifierCacheKeyFactoryTest {
}
private void verifyComplexKey(final String key) {
+ assertTrue(key.contains(String.class.getTypeName()));
assertTrue(key.contains(DataObjectParent.class.getTypeName()));
assertTrue(key.contains(parentKey.toString()));
assertTrue(key.contains(DataObjectChild.class.getTypeName()));
@@ -135,10 +121,26 @@ public class IdentifierCacheKeyFactoryTest {
}
private void verifySimpleKey(final String key) {
+ assertTrue(key.contains(String.class.getTypeName()));
assertFalse(key.contains(DataObjectParent.class.getTypeName()));
assertFalse(key.contains(parentKey.toString()));
assertTrue(key.contains(DataObjectChild.class.getTypeName()));
assertFalse(key.contains(childKey.toString()));
assertFalse(key.contains(SuperDataObject.class.getTypeName()));
}
+
+ private interface SuperDataObject extends DataObject {
+ }
+
+ private interface DataObjectParent extends DataObject, ChildOf<SuperDataObject>, Identifiable<DataObjectParentKey> {
+ }
+
+ private interface DataObjectChild extends DataObject, ChildOf<DataObjectParent>, Identifiable<DataObjectChildKey> {
+ }
+
+ private class DataObjectParentKey implements Identifier<DataObjectParent> {
+ }
+
+ private class DataObjectChildKey implements Identifier<DataObjectChild> {
+ }
} \ No newline at end of file