@Test public void testGenerateQuery() { SearchFiltersQuestion question = new SearchFiltersQuestion(); assertThat(question.getQuery(), is(PermitQuery.INSTANCE)); question = SearchFiltersQuestion.builder().setAction("permit").build(); assertThat(question.getQuery(), is(PermitQuery.INSTANCE)); question = SearchFiltersQuestion.builder().setAction("PermIT").build(); assertThat(question.getQuery(), is(PermitQuery.INSTANCE)); question = SearchFiltersQuestion.builder().setAction("deny").build(); assertThat(question.getQuery(), is(DenyQuery.INSTANCE)); question = SearchFiltersQuestion.builder().setAction("DenY").build(); assertThat(question.getQuery(), is(DenyQuery.INSTANCE)); question = SearchFiltersQuestion.builder().setAction("matchLine 5").build(); SearchFiltersQuery query = question.getQuery(); assertThat(query, instanceOf(MatchLineQuery.class)); assertThat(((MatchLineQuery) query).getLineNum(), is(5)); question = SearchFiltersQuestion.builder().setAction("maTChLine 5").build(); query = question.getQuery(); assertThat(query, instanceOf(MatchLineQuery.class)); assertThat(((MatchLineQuery) query).getLineNum(), is(5)); exception.expect(BatfishException.class); exception.expectMessage("Unrecognized action 'foo'"); SearchFiltersQuestion.builder().setAction("foo").build(); }
private SearchFiltersQuery generateQuery(String type) { if (type.equalsIgnoreCase("permit")) { return PermitQuery.INSTANCE; } else if (type.equalsIgnoreCase("deny")) { return DenyQuery.INSTANCE; } else if (type.toLowerCase().startsWith("matchline")) { int lineNum = Integer.parseInt(type.toLowerCase().substring("matchLine".length()).trim()); if (lineNum < 0) { throw new BatfishException("Line index for matchLine must be zero or higher"); } return new MatchLineQuery(lineNum); } else { throw new BatfishException( String.format( "Unrecognized action '%s'. Must be one of 'permit', 'deny', or 'matchLine <line index>'.", type)); } }
SearchFiltersQuestion extends Question { private SearchFiltersQuery generateQuery(String type) { if (type.equalsIgnoreCase("permit")) { return PermitQuery.INSTANCE; } else if (type.equalsIgnoreCase("deny")) { return DenyQuery.INSTANCE; } else if (type.toLowerCase().startsWith("matchline")) { int lineNum = Integer.parseInt(type.toLowerCase().substring("matchLine".length()).trim()); if (lineNum < 0) { throw new BatfishException("Line index for matchLine must be zero or higher"); } return new MatchLineQuery(lineNum); } else { throw new BatfishException( String.format( "Unrecognized action '%s'. Must be one of 'permit', 'deny', or 'matchLine <line index>'.", type)); } } }
SearchFiltersQuestion extends Question { private SearchFiltersQuery generateQuery(String type) { if (type.equalsIgnoreCase("permit")) { return PermitQuery.INSTANCE; } else if (type.equalsIgnoreCase("deny")) { return DenyQuery.INSTANCE; } else if (type.toLowerCase().startsWith("matchline")) { int lineNum = Integer.parseInt(type.toLowerCase().substring("matchLine".length()).trim()); if (lineNum < 0) { throw new BatfishException("Line index for matchLine must be zero or higher"); } return new MatchLineQuery(lineNum); } else { throw new BatfishException( String.format( "Unrecognized action '%s'. Must be one of 'permit', 'deny', or 'matchLine <line index>'.", type)); } } private  SearchFiltersQuestion(
      boolean complementHeaderSpace,
      @Nullable String filters,
      @Nonnull PacketHeaderConstraints headerConstraints,
      @Nullable String nodes,
      @Nullable String start,
      @Nonnull String action);   SearchFiltersQuestion(); }
SearchFiltersQuestion extends Question { private SearchFiltersQuery generateQuery(String type) { if (type.equalsIgnoreCase("permit")) { return PermitQuery.INSTANCE; } else if (type.equalsIgnoreCase("deny")) { return DenyQuery.INSTANCE; } else if (type.toLowerCase().startsWith("matchline")) { int lineNum = Integer.parseInt(type.toLowerCase().substring("matchLine".length()).trim()); if (lineNum < 0) { throw new BatfishException("Line index for matchLine must be zero or higher"); } return new MatchLineQuery(lineNum); } else { throw new BatfishException( String.format( "Unrecognized action '%s'. Must be one of 'permit', 'deny', or 'matchLine <line index>'.", type)); } } private  SearchFiltersQuestion(
      boolean complementHeaderSpace,
      @Nullable String filters,
      @Nonnull PacketHeaderConstraints headerConstraints,
      @Nullable String nodes,
      @Nullable String start,
      @Nonnull String action);   SearchFiltersQuestion(); @Override boolean getDataPlane(); @Override String getName(); @JsonProperty(PROP_COMPLEMENT_HEADERSPACE) boolean getComplementHeaderSpace(); @Nullable @JsonProperty(PROP_FILTERS) String getFilters(); @JsonProperty(PROP_HEADERS) @Nonnull PacketHeaderConstraints getHeaderConstraints(); @JsonProperty(PROP_NODES) @Nullable String getNodes(); @JsonProperty(PROP_START_LOCATION) @Nullable String getStartLocation(); @Nonnull @JsonIgnore SearchFiltersQuery getQuery(); static Builder builder(); }
SearchFiltersQuestion extends Question { private SearchFiltersQuery generateQuery(String type) { if (type.equalsIgnoreCase("permit")) { return PermitQuery.INSTANCE; } else if (type.equalsIgnoreCase("deny")) { return DenyQuery.INSTANCE; } else if (type.toLowerCase().startsWith("matchline")) { int lineNum = Integer.parseInt(type.toLowerCase().substring("matchLine".length()).trim()); if (lineNum < 0) { throw new BatfishException("Line index for matchLine must be zero or higher"); } return new MatchLineQuery(lineNum); } else { throw new BatfishException( String.format( "Unrecognized action '%s'. Must be one of 'permit', 'deny', or 'matchLine <line index>'.", type)); } } private  SearchFiltersQuestion(
      boolean complementHeaderSpace,
      @Nullable String filters,
      @Nonnull PacketHeaderConstraints headerConstraints,
      @Nullable String nodes,
      @Nullable String start,
      @Nonnull String action);   SearchFiltersQuestion(); @Override boolean getDataPlane(); @Override String getName(); @JsonProperty(PROP_COMPLEMENT_HEADERSPACE) boolean getComplementHeaderSpace(); @Nullable @JsonProperty(PROP_FILTERS) String getFilters(); @JsonProperty(PROP_HEADERS) @Nonnull PacketHeaderConstraints getHeaderConstraints(); @JsonProperty(PROP_NODES) @Nullable String getNodes(); @JsonProperty(PROP_START_LOCATION) @Nullable String getStartLocation(); @Nonnull @JsonIgnore SearchFiltersQuery getQuery(); static Builder builder();  }