@Override protected Question createQuestion() { // no reason for this to be the default but we must instantiate with something return new SpecifiersQuestion(QueryType.IP_SPACE); } }
@Test public void testGetLocationSpecifier_defaultFactory() { LocationSpecifier locationSpecifier = new SpecifiersQuestion(QueryType.LOCATION).getLocationSpecifier(); assertThat(locationSpecifier, equalTo(AllInterfacesLocationSpecifier.INSTANCE)); }
@Test public void testGetIpSpaceSpecifier_defaultInput() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.IP_SPACE); question.setIpSpaceSpecifierFactory(new TestIpSpaceSpecifierFactory().getName()); IpSpaceSpecifier ipSpaceSpecifier = question.getIpSpaceSpecifier(); assertThat(ipSpaceSpecifier, instanceOf(TestIpSpaceSpecifier.class)); TestIpSpaceSpecifier testIpSpaceSpecifier = (TestIpSpaceSpecifier) ipSpaceSpecifier; assertThat(testIpSpaceSpecifier.getInput(), nullValue()); }
@Test public void testGetIpSpaceSpecifier() { String input = "input"; SpecifiersQuestion question = new SpecifiersQuestion(QueryType.IP_SPACE); question.setIpSpaceSpecifierFactory(new TestIpSpaceSpecifierFactory().getName()); question.setIpSpaceSpecifierInput(input); IpSpaceSpecifier ipSpaceSpecifier = question.getIpSpaceSpecifier(); assertThat(ipSpaceSpecifier, instanceOf(TestIpSpaceSpecifier.class)); TestIpSpaceSpecifier testIpSpaceSpecifier = (TestIpSpaceSpecifier) ipSpaceSpecifier; assertThat(testIpSpaceSpecifier.getInput(), equalTo(input)); }
@Test public void testGetIpSpaceSpecifier_inputWithoutFactory() { exception.expect(NullPointerException.class); SpecifiersQuestion question = new SpecifiersQuestion(QueryType.IP_SPACE); question.setIpSpaceSpecifierFactory(null); question.setIpSpaceSpecifierInput("foo"); question.getIpSpaceSpecifier(); }
@Test public void testGetLocationSpecifier_inputWithoutFactory() { exception.expect(NullPointerException.class); SpecifiersQuestion question = new SpecifiersQuestion(QueryType.LOCATION); question.setLocationSpecifierFactory(null); question.setLocationSpecifierInput("foo"); question.getLocationSpecifier(); } }
@Test public void resolveNodeTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.NODE); question.setNodeSpecifierInput(_c1.getHostname()); // only c1 should be present assertThat( resolveNode(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of(Row.of(COL_NODE, new Node(_c1.getHostname()))))); } }
@Test public void resolveFilterTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.FILTER); question.setFilterSpecifierInput(_filter1.getName()); // only filter1 should be present (with a node specifier all nodes are included) assertThat( resolveFilter(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_NODE, new Node(_c1.getHostname()), COL_FILTER_NAME, _filter1.getName())))); // nothing should match since the node specifier does not match anything question.setNodeSpecifierInput("foofoo"); assertThat( resolveFilter(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of())); }
@Test public void resolveLocationTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.LOCATION); question.setLocationSpecifierInput(_c1.getHostname()); // only c1:iface1 should be present assertThat( resolveLocation(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATION, new InterfaceLocation(_c1.getHostname(), _iface1.getName()).toString())))); }
@Test public void resolveInterfaceTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.INTERFACE); question.setInterfaceSpecifierInput(_iface1.getName()); // only iface1 should be present (with a node specifier all nodes are included) assertThat( resolveInterface(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_INTERFACE, new NodeInterfacePair(_c1.getHostname(), _iface1.getName()))))); // nothing should match since the node specifier does not match anything question.setNodeSpecifierInput("foofoo"); assertThat( resolveInterface(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of())); }
@Test public void resolveIpSpaceTest() { String prefix = "3.3.3.3/24"; SpecifiersQuestion questionWithIp = new SpecifiersQuestion(QueryType.LOCATION); questionWithIp.setIpSpaceSpecifierInput(prefix); // both interfacelocations should be mapped to 3.3.3.3/24 assertThat( resolveIpSpace(questionWithIp, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_IP_SPACE, IpWildcardSetIpSpace.builder() .including(new IpWildcard(prefix)) .build() .toString())))); }
@Test public void resolveIpSpaceOfLocationTest() { SpecifiersQuestion questionWithLocation = new SpecifiersQuestion(QueryType.IP_SPACE_OF_LOCATION); questionWithLocation.setLocationSpecifierInput(_c1.getHostname()); // only c1:iface1 should be present assertThat( resolveIpSpaceOfLocation(questionWithLocation, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName())) .toString(), COL_IP_SPACE, _iface1.getAddress().getIp().toIpSpace().toString())))); }
@Test public void resolveIpSpaceOfLocationTestDefault() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.IP_SPACE); assertThat( resolveIpSpaceOfLocation(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName())) .toString(), COL_IP_SPACE, _iface1.getAddress().getIp().toIpSpace().toString()), Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c2.getHostname(), _iface2.getName())) .toString(), COL_IP_SPACE, _iface2.getAddress().getIp().toIpSpace().toString())))); }