Java Code Examples for com.google.common.collect.ImmutableMultimap#of()
The following examples show how to use
com.google.common.collect.ImmutableMultimap#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestLocalDynamicFilterConsumer.java From presto with Apache License 2.0 | 6 votes |
@Test public void testMultipleColumns() throws ExecutionException, InterruptedException { LocalDynamicFilterConsumer filter = new LocalDynamicFilterConsumer( ImmutableMultimap.of(new DynamicFilterId("123"), new Symbol("a"), new DynamicFilterId("456"), new Symbol("b")), ImmutableMap.of(new DynamicFilterId("123"), 0, new DynamicFilterId("456"), 1), ImmutableMap.of(new DynamicFilterId("123"), INTEGER, new DynamicFilterId("456"), INTEGER), 1); assertEquals(filter.getBuildChannels(), ImmutableMap.of(new DynamicFilterId("123"), 0, new DynamicFilterId("456"), 1)); Consumer<TupleDomain<DynamicFilterId>> consumer = filter.getTupleDomainConsumer(); ListenableFuture<Map<Symbol, Domain>> result = filter.getNodeLocalDynamicFilterForSymbols(); assertFalse(result.isDone()); consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of( new DynamicFilterId("123"), Domain.singleValue(INTEGER, 10L), new DynamicFilterId("456"), Domain.singleValue(INTEGER, 20L)))); assertEquals(result.get(), ImmutableMap.of( new Symbol("a"), Domain.singleValue(INTEGER, 10L), new Symbol("b"), Domain.singleValue(INTEGER, 20L))); }
Example 2
Source File: MapUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
public static <K, V> Multimap<K, V> combine(Iterable<Multimap<K, V>> maps) { Multimap<K, V> singleton = null; ImmutableMultimap.Builder<K, V> builder = null; for(Multimap<K, V> map : maps) { if(!map.isEmpty()) { if(singleton == null) { singleton = map; } else { if(builder == null) { builder = ImmutableMultimap.builder(); } builder.putAll(singleton); builder.putAll(map); } } } if(builder != null) { return builder.build(); } else if(singleton != null) { return singleton; } else { return ImmutableMultimap.of(); } }
Example 3
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelXREF() { List<Attribute> attributeList = singletonList(attr3); List<String> refAttributeList = singletonList("refAttr"); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attributeName3")).thenReturn(refEntity); when(objectEntity.getEntity("attributeName3")).thenReturn(refEntity); when(refEntity.getEntityType()).thenReturn(refEntityType); when(refEntityType.getAttributeNames()).thenReturn(refAttributeList); when(refEntity.getIdValue()).thenReturn("refID"); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attr3.getName()).thenReturn("attributeName3"); when(attr3.getDataType()).thenReturn(AttributeType.XREF); LabeledResource tag3 = new LabeledResource("http://IRI3.nl", "labelTag3"); Multimap<Relation, LabeledResource> tags3 = ImmutableMultimap.of(Relation.isAssociatedWith, tag3); when(tagService.getTagsForAttribute(entityType, attr3)).thenReturn(tags3); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI3.nl, http://molgenis01.gcc.rug.nl/fdp/catolog/test/this/refID) [null]", results.next().toString()); }
Example 4
Source File: UploadDirectoryToCDN.java From jclouds-examples with Apache License 2.0 | 5 votes |
/** * This method will put your container on a Content Distribution Network and * make it available as a static website. */ private void enableCdnContainer(String container) { System.out.format("Enable CDN%n"); Multimap<String, String> enableStaticWebHeaders = ImmutableMultimap.of(STATIC_WEB_INDEX, "index.html", STATIC_WEB_ERROR, "error.html"); UpdateContainerOptions opts = new UpdateContainerOptions().headers(enableStaticWebHeaders); cloudFiles.getContainerApi(REGION).update(container, opts); // enable the CDN container URI cdnURI = cloudFiles.getCDNApi(REGION).enable(container); System.out.format(" Go to %s/%n", cdnURI); }
Example 5
Source File: GraphTest.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Test public void testDependencyCycle() { Multimap<String, String> graph = ImmutableMultimap.of("1", "2", "2", "3", "3", "1"); try { Graph.create(graph).sort(); fail(); } catch (IllegalStateException e) { assertTrue(true); // NOPMD } }
Example 6
Source File: DropwizardInvalidationTaskTest.java From emodb with Apache License 2.0 | 5 votes |
@Test public void testGlobalKeys() throws Exception { ImmutableMultimap<String, String> request = ImmutableMultimap.of( "cache", "tables", "scope", "local", "key", "123", "key", "456"); verifyInvalidate(request, "tables", InvalidationScope.LOCAL, Arrays.asList("123", "456")); }
Example 7
Source File: DropwizardInvalidationTaskTest.java From emodb with Apache License 2.0 | 5 votes |
@Test public void testLocalKey() throws Exception { ImmutableMultimap<String, String> request = ImmutableMultimap.of( "cache", "tables", "scope", "local", "key", "123"); verifyInvalidate(request, "tables", InvalidationScope.LOCAL, Arrays.asList("123")); }
Example 8
Source File: AbstractMethodExtractorTest.java From RetroFacebook with Apache License 2.0 | 5 votes |
public void testNested() { String source = "package com.example;\n" + "import retrofacebook.RetroFacebook;\n" + "import java.util.Map;\n" + "abstract class Foo {\n" + " @RetroFacebook\n" + " abstract class Baz {\n" + " abstract <T extends Number & Comparable<T>> T complicated();\n" + " abstract int simple();\n" + " abstract class Irrelevant {\n" + " void distraction() {\n" + " abstract class FurtherDistraction {\n" + " abstract int buh();\n" + " }\n" + " }\n" + " }\n" + " }\n" + " @RetroFacebook\n" + " abstract class Bar {\n" + " abstract String whatever();\n" + " }\n" + " abstract class AlsoIrrelevant {\n" + " void distraction() {}\n" + " }\n" + "}\n"; JavaTokenizer tokenizer = new JavaTokenizer(new StringReader(source)); AbstractMethodExtractor extractor = new AbstractMethodExtractor(); ImmutableMultimap<String, String> expected = ImmutableMultimap.of( "com.example.Foo.Baz", "complicated", "com.example.Foo.Baz", "simple", "com.example.Foo.Bar", "whatever"); ImmutableMultimap<String, String> actual = extractor.abstractMethods(tokenizer, "com.example"); assertEquals(expected, actual); }
Example 9
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelSTRINGKeywords() { Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); String value = "molgenis,genetics,fair"; when(objectEntity.get("attributeName")).thenReturn(value); when(objectEntity.getString("attributeName")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.STRING); LabeledResource tag = new LabeledResource("http://www.w3.org/ns/dcat#keyword", "keywords"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(3, result.size()); List<String> statements = result.stream().map(Statement::toString).collect(toList()); assertEquals( asList( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://www.w3.org/ns/dcat#keyword, \"molgenis\"^^<http://www.w3.org/2001/XMLSchema#string>) [null]", "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://www.w3.org/ns/dcat#keyword, \"genetics\"^^<http://www.w3.org/2001/XMLSchema#string>) [null]", "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://www.w3.org/ns/dcat#keyword, \"fair\"^^<http://www.w3.org/2001/XMLSchema#string>) [null]"), statements); }
Example 10
Source File: CompilationErrorsTest.java From SimpleWeibo with Apache License 2.0 | 5 votes |
public void testAbstractVoid() throws Exception { String testSourceCode = "package foo.bar;\n" + "import retroweibo.RetroWeibo;\n" + "@RetroWeibo\n" + "public abstract class Baz {\n" + " public abstract void foo();\n" + "}\n"; ImmutableMultimap<Diagnostic.Kind, Pattern> expectedDiagnostics = ImmutableMultimap.of( Diagnostic.Kind.WARNING, CANNOT_HAVE_NON_PROPERTIES, Diagnostic.Kind.ERROR, Pattern.compile("RetroWeibo_Baz") ); assertCompilationResultIs(expectedDiagnostics, ImmutableList.of(testSourceCode)); }
Example 11
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelNullValuePlusHyperlink() { // Model createRdfModel(String subjectIRI, Entity objectEntity) Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute1 = mock(Attribute.class); Attribute attribute2 = mock(Attribute.class); List<Attribute> attributeList = Arrays.asList(attribute1, attribute2); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attribute1Name")).thenReturn(null); String value = "http://molgenis.org/index.html"; doReturn(value).when(objectEntity).get("attribute2Name"); when(objectEntity.getString("attribute2Name")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute1.getName()).thenReturn("attribute1Name"); when(attribute2.getName()).thenReturn("attribute2Name"); when(attribute2.getDataType()).thenReturn(AttributeType.HYPERLINK); LabeledResource tag2 = new LabeledResource("http://IRI1.nl", "tag1 label"); Multimap<Relation, LabeledResource> tags2 = ImmutableMultimap.of(Relation.isAssociatedWith, tag2); doReturn(tags2).when(tagService).getTagsForAttribute(entityType, attribute2); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI1.nl, http://molgenis.org/index.html) [null]", results.next().toString()); }
Example 12
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelDECIMAL() { // Model createRdfModel(String subjectIRI, Entity objectEntity) Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); double value = 10.0; when(objectEntity.get("attributeName")).thenReturn(value); when(objectEntity.getDouble("attributeName")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.DECIMAL); LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"10.0\"^^<http://www.w3.org/2001/XMLSchema#double>) [null]", results.next().toString()); }
Example 13
Source File: SchemaResolutionException.java From yangtools with Eclipse Public License 1.0 | 4 votes |
public SchemaResolutionException(final @NonNull String message, final Throwable cause) { this(message, null, cause, ImmutableList.of(), ImmutableMultimap.of()); }
Example 14
Source File: MapStreamTest.java From Strata with Apache License 2.0 | 4 votes |
@Test public void ofMultimap() { ImmutableMultimap<String, Integer> input = ImmutableMultimap.of("one", 1, "two", 2, "one", 3); assertThat(MapStream.of(input)).containsExactlyInAnyOrder(entry("one", 1), entry("two", 2), entry("one", 3)); assertThat(MapStream.of(input).toMap(Integer::sum)).containsOnly(entry("one", 4), entry("two", 2)); }
Example 15
Source File: SplitZipStepTest.java From buck with Apache License 2.0 | 4 votes |
@Test public void testRequiredInPrimaryZipPredicate() throws IOException { Path primaryDexClassesFile = Paths.get("the/manifest.txt"); List<String> linesInManifestFile = ImmutableList.of( "com/google/common/collect/ImmutableSortedSet", " com/google/common/collect/ImmutableSet", "# com/google/common/collect/ImmutableMap"); ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(); projectFilesystem.writeLinesToPath(linesInManifestFile, primaryDexClassesFile); SplitZipStep splitZipStep = new SplitZipStep( projectFilesystem, /* inputPathsToSplit */ ImmutableSet.of(), /* secondaryJarMetaPath */ Paths.get(""), /* primaryJarPath */ Paths.get(""), /* secondaryJarDir */ Paths.get(""), /* secondaryJarPattern */ "", /* additionalDexStoreJarMetaPath */ Paths.get(""), /* additionalDexStoreJarDir */ Paths.get(""), /* proguardFullConfigFile */ Optional.empty(), /* proguardMappingFile */ Optional.empty(), false, new DexSplitMode( /* shouldSplitDex */ true, ZipSplitter.DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE, DexStore.JAR, /* linearAllocHardLimit */ 4 * 1024 * 1024, /* primaryDexPatterns */ ImmutableSet.of("List"), Optional.of(FakeSourcePath.of("the/manifest.txt")), /* primaryDexScenarioFile */ Optional.empty(), /* isPrimaryDexScenarioOverflowAllowed */ false, /* secondaryDexHeadClassesFile */ Optional.empty(), /* secondaryDexTailClassesFile */ Optional.empty(), /* allowRDotJavaInSecondaryDex */ false), Optional.empty(), Optional.of(Paths.get("the/manifest.txt")), Optional.empty(), Optional.empty(), /* additionalDexStoreToJarPathMap */ ImmutableMultimap.of(), /* pathToReportDir */ ImmutableSortedMap.of(), null, Paths.get("")); Predicate<String> requiredInPrimaryZipPredicate = splitZipStep.createRequiredInPrimaryZipPredicate( ProguardTranslatorFactory.createForTest(Optional.empty()), Suppliers.ofInstance(ImmutableList.of())); assertTrue( "com/google/common/collect/ImmutableSortedSet.class is listed in the manifest verbatim.", requiredInPrimaryZipPredicate.test("com/google/common/collect/ImmutableSortedSet.class")); assertTrue( "com/google/common/collect/ImmutableSet.class is in the manifest with whitespace.", requiredInPrimaryZipPredicate.test("com/google/common/collect/ImmutableSet.class")); assertFalse( "com/google/common/collect/ImmutableSet.class cannot have whitespace as param.", requiredInPrimaryZipPredicate.test(" com/google/common/collect/ImmutableSet.class")); assertFalse( "com/google/common/collect/ImmutableMap.class is commented out.", requiredInPrimaryZipPredicate.test("com/google/common/collect/ImmutableMap.class")); assertFalse( "com/google/common/collect/Iterables.class is not even mentioned.", requiredInPrimaryZipPredicate.test("com/google/common/collect/Iterables.class")); assertTrue( "java/awt/List.class matches the substring 'List'.", requiredInPrimaryZipPredicate.test("java/awt/List.class")); assertFalse( "Substring matching is case-sensitive.", requiredInPrimaryZipPredicate.test("shiny/Glistener.class")); }
Example 16
Source File: HepRelMetadataProvider.java From Quicksql with MIT License | 4 votes |
public <M extends Metadata> Multimap<Method, MetadataHandler<M>> handlers( MetadataDef<M> def) { return ImmutableMultimap.of(); }
Example 17
Source File: AbstractMemento.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected <K,V> Multimap<K,V> fromPersistedMultimap(Multimap<K,V> m) { if (m==null) return ImmutableMultimap.of(); return ImmutableMultimap.copyOf(m); }
Example 18
Source File: SplitZipStepTest.java From buck with Apache License 2.0 | 4 votes |
@Test public void testNonObfuscatedBuild() throws IOException { Path proguardConfigFile = Paths.get("the/configuration.txt"); Path proguardMappingFile = Paths.get("the/mapping.txt"); ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(); projectFilesystem.writeLinesToPath(ImmutableList.of("-dontobfuscate"), proguardConfigFile); SplitZipStep splitZipStep = new SplitZipStep( projectFilesystem, /* inputPathsToSplit */ ImmutableSet.of(), /* secondaryJarMetaPath */ Paths.get(""), /* primaryJarPath */ Paths.get(""), /* secondaryJarDir */ Paths.get(""), /* secondaryJarPattern */ "", /* additionalDexStoreJarMetaPath */ Paths.get(""), /* additionalDexStoreJarDir */ Paths.get(""), /* proguardFullConfigFile */ Optional.of(proguardConfigFile), /* proguardMappingFile */ Optional.of(proguardMappingFile), false, new DexSplitMode( /* shouldSplitDex */ true, ZipSplitter.DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE, DexStore.JAR, /* linearAllocHardLimit */ 4 * 1024 * 1024, /* primaryDexPatterns */ ImmutableSet.of("primary"), /* primaryDexClassesFile */ Optional.empty(), /* primaryDexScenarioFile */ Optional.empty(), /* isPrimaryDexScenarioOverflowAllowed */ false, /* secondaryDexHeadClassesFile */ Optional.empty(), /* secondaryDexTailClassesFile */ Optional.empty(), /* allowRDotJavaInSecondaryDex */ false), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), /* additionalDexStoreToJarPathMap */ ImmutableMultimap.of(), /* pathToReportDir */ ImmutableSortedMap.of(), null, Paths.get("")); ProguardTranslatorFactory translatorFactory = ProguardTranslatorFactory.create( projectFilesystem, Optional.of(proguardConfigFile), Optional.of(proguardMappingFile), false); Predicate<String> requiredInPrimaryZipPredicate = splitZipStep.createRequiredInPrimaryZipPredicate( translatorFactory, Suppliers.ofInstance(ImmutableList.of())); assertTrue( "Primary class should be in primary.", requiredInPrimaryZipPredicate.test("primary.class")); assertFalse( "Secondary class should be in secondary.", requiredInPrimaryZipPredicate.test("secondary.class")); }
Example 19
Source File: SplitZipStepTest.java From buck with Apache License 2.0 | 4 votes |
@Test public void testRequiredInPrimaryZipPredicateWithProguard() throws IOException { List<String> linesInMappingFile = ImmutableList.of( "foo.bar.MappedPrimary -> foo.bar.a:", "foo.bar.MappedSecondary -> foo.bar.b:", "foo.bar.UnmappedPrimary -> foo.bar.UnmappedPrimary:", "foo.bar.UnmappedSecondary -> foo.bar.UnmappedSecondary:", "foo.primary.MappedPackage -> x.a:", "foo.secondary.MappedPackage -> x.b:", "foo.primary.UnmappedPackage -> foo.primary.UnmappedPackage:"); List<String> linesInManifestFile = ImmutableList.of( // Actual primary dex classes. "foo/bar/MappedPrimary", "foo/bar/UnmappedPrimary", // Red herrings! "foo/bar/b", "x/b"); Path proguardConfigFile = Paths.get("the/configuration.txt"); Path proguardMappingFile = Paths.get("the/mapping.txt"); Path primaryDexClassesFile = Paths.get("the/manifest.txt"); ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(); projectFilesystem.writeLinesToPath(linesInManifestFile, primaryDexClassesFile); projectFilesystem.writeLinesToPath(ImmutableList.of(), proguardConfigFile); projectFilesystem.writeLinesToPath(linesInMappingFile, proguardMappingFile); SplitZipStep splitZipStep = new SplitZipStep( projectFilesystem, /* inputPathsToSplit */ ImmutableSet.of(), /* secondaryJarMetaPath */ Paths.get(""), /* primaryJarPath */ Paths.get(""), /* secondaryJarDir */ Paths.get(""), /* secondaryJarPattern */ "", /* additionalDexStoreJarMetaPath */ Paths.get(""), /* additionalDexStoreJarDir */ Paths.get(""), /* proguardFullConfigFile */ Optional.of(proguardConfigFile), /* proguardMappingFile */ Optional.of(proguardMappingFile), false, new DexSplitMode( /* shouldSplitDex */ true, ZipSplitter.DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE, DexStore.JAR, /* linearAllocHardLimit */ 4 * 1024 * 1024, /* primaryDexPatterns */ ImmutableSet.of("/primary/", "x/"), Optional.of(FakeSourcePath.of("the/manifest.txt")), /* primaryDexScenarioFile */ Optional.empty(), /* isPrimaryDexScenarioOverflowAllowed */ false, /* secondaryDexHeadClassesFile */ Optional.empty(), /* secondaryDexTailClassesFile */ Optional.empty(), /* allowRDotJavaInSecondaryDex */ false), Optional.empty(), Optional.of(Paths.get("the/manifest.txt")), Optional.empty(), Optional.empty(), /* additionalDexStoreToJarPathMap */ ImmutableMultimap.of(), /* pathToReportDir */ ImmutableSortedMap.of(), null, Paths.get("")); ProguardTranslatorFactory translatorFactory = ProguardTranslatorFactory.create( projectFilesystem, Optional.of(proguardConfigFile), Optional.of(proguardMappingFile), false); Predicate<String> requiredInPrimaryZipPredicate = splitZipStep.createRequiredInPrimaryZipPredicate( translatorFactory, Suppliers.ofInstance(ImmutableList.of())); assertTrue( "Mapped class from primary list should be in primary.", requiredInPrimaryZipPredicate.test("foo/bar/a.class")); assertTrue( "Unmapped class from primary list should be in primary.", requiredInPrimaryZipPredicate.test("foo/bar/UnmappedPrimary.class")); assertTrue( "Mapped class from substring should be in primary.", requiredInPrimaryZipPredicate.test("x/a.class")); assertTrue( "Unmapped class from substring should be in primary.", requiredInPrimaryZipPredicate.test("foo/primary/UnmappedPackage.class")); assertFalse( "Mapped class with obfuscated name match should not be in primary.", requiredInPrimaryZipPredicate.test("foo/bar/b.class")); assertFalse( "Unmapped class name should not randomly be in primary.", requiredInPrimaryZipPredicate.test("foo/bar/UnmappedSecondary.class")); assertFalse( "Map class with obfuscated name substring should not be in primary.", requiredInPrimaryZipPredicate.test("x/b.class")); }
Example 20
Source File: TracerouteUtilsTest.java From batfish with Apache License 2.0 | 4 votes |
@Test public void testBuildSessionsByIngressInterface() { Flow flow = Flow.builder() .setIngressNode("n1") .setIngressInterface("i1") .setIpProtocol(IpProtocol.TCP) .setSrcPort(22) .setDstPort(22) .setSrcIp(Ip.parse("1.1.1.1")) .setDstIp(Ip.parse("2.2.2.2")) .build(); SessionMatchExpr matchExpr = matchSessionReturnFlow(flow); SessionScope incomingI1 = new IncomingSessionScope(ImmutableSet.of("i1")); // need two different actions to differentiate two sessions with same node and ingress interface SessionAction action1 = new ForwardOutInterface("i1", null); SessionAction action2 = new ForwardOutInterface("i2", null); // Incoming interface based sessions: should appear in sessions by ingress interface map FirewallSessionTraceInfo n1i1Session = new FirewallSessionTraceInfo("n1", action1, incomingI1, matchExpr, null); FirewallSessionTraceInfo n1i1i2Session = new FirewallSessionTraceInfo( "n1", action2, new IncomingSessionScope(ImmutableSet.of("i1", "i2")), matchExpr, null); FirewallSessionTraceInfo n2i1Session = new FirewallSessionTraceInfo("n2", action1, incomingI1, matchExpr, null); // VRF-originated session: should not affect ingress interfaces map FirewallSessionTraceInfo originatingVrfSession = new FirewallSessionTraceInfo( "n1", action1, new OriginatingSessionScope("vrf"), matchExpr, null); Set<FirewallSessionTraceInfo> sessions = ImmutableSet.of(n1i1Session, n1i1i2Session, n2i1Session, originatingVrfSession); Multimap<NodeInterfacePair, FirewallSessionTraceInfo> ifaceSessionsMap = buildSessionsByIngressInterface(sessions); NodeInterfacePair n1i1 = NodeInterfacePair.of("n1", "i1"); NodeInterfacePair n1i2 = NodeInterfacePair.of("n1", "i2"); NodeInterfacePair n2i1 = NodeInterfacePair.of("n2", "i1"); Multimap<NodeInterfacePair, FirewallSessionTraceInfo> expected = ImmutableMultimap.of( n1i1, n1i1Session, n1i1, n1i1i2Session, n1i2, n1i1i2Session, n2i1, n2i1Session); assertEquals(ifaceSessionsMap, expected); }