target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void length() { assertThat(ciString("").length(), is(0)); assertThat(ciString("abcdef").length(), is(6)); } | @Override public int length() { return value.length(); } | CIString implements Comparable<CIString>, CharSequence { @Override public int length() { return value.length(); } } | CIString implements Comparable<CIString>, CharSequence { @Override public int length() { return value.length(); } private CIString(final String value); } | CIString implements Comparable<CIString>, CharSequence { @Override public int length() { return value.length(); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } | CIString implements Comparable<CIString>, CharSequence { @Override public int length() { return value.length(); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } |
@Test public void startsWith() { assertThat(ciString("").startsWith(ciString("")), is(true)); assertThat(ciString("ab").startsWith(ciString("AB")), is(true)); assertThat(ciString("ab").startsWith(ciString("ab")), is(true)); assertThat(ciString("abcdef").startsWith(ciString("AB")), is(true)); assertThat(ciString("ABCDEF").startsWith(ciString("aB")), is(true)); assertThat(ciString("ABCDEF").startsWith(ciString("def")), is(false)); assertThat(ciString("").startsWith(""), is(true)); assertThat(ciString("ab").startsWith("AB"), is(true)); assertThat(ciString("ab").startsWith("ab"), is(true)); assertThat(ciString("abcdef").startsWith("AB"), is(true)); assertThat(ciString("ABCDEF").startsWith("aB"), is(true)); assertThat(ciString("ABCDEF").startsWith("def"), is(false)); } | public boolean startsWith(final CIString value) { return lcValue.startsWith(value.lcValue); } | CIString implements Comparable<CIString>, CharSequence { public boolean startsWith(final CIString value) { return lcValue.startsWith(value.lcValue); } } | CIString implements Comparable<CIString>, CharSequence { public boolean startsWith(final CIString value) { return lcValue.startsWith(value.lcValue); } private CIString(final String value); } | CIString implements Comparable<CIString>, CharSequence { public boolean startsWith(final CIString value) { return lcValue.startsWith(value.lcValue); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } | CIString implements Comparable<CIString>, CharSequence { public boolean startsWith(final CIString value) { return lcValue.startsWith(value.lcValue); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } |
@Test public void contains() { assertThat(ciString("ABCDEF").contains(ciString("abcdef")), is(true)); assertThat(ciString("ABCDEF").contains(ciString("cd")), is(true)); assertThat(ciString("ABCDEF").contains(ciString("CD")), is(true)); assertThat(ciString("ABCDEF").contains("abcdef"), is(true)); assertThat(ciString("ABCDEF").contains("cd"), is(true)); assertThat(ciString("ABCDEF").contains("CD"), is(true)); } | public boolean contains(final CIString value) { return lcValue.contains(value.lcValue); } | CIString implements Comparable<CIString>, CharSequence { public boolean contains(final CIString value) { return lcValue.contains(value.lcValue); } } | CIString implements Comparable<CIString>, CharSequence { public boolean contains(final CIString value) { return lcValue.contains(value.lcValue); } private CIString(final String value); } | CIString implements Comparable<CIString>, CharSequence { public boolean contains(final CIString value) { return lcValue.contains(value.lcValue); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } | CIString implements Comparable<CIString>, CharSequence { public boolean contains(final CIString value) { return lcValue.contains(value.lcValue); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } |
@Test public void endsWith() { assertThat(ciString("ABCDEF").endsWith(ciString("def")), is(true)); assertThat(ciString("ABCDEF").endsWith(ciString("DEF")), is(true)); assertThat(ciString("ABCDEF").endsWith(ciString("ABC")), is(false)); assertThat(ciString("ABCDEF").endsWith("def"), is(true)); assertThat(ciString("ABCDEF").endsWith("DEF"), is(true)); assertThat(ciString("ABCDEF").endsWith("ABC"), is(false)); } | public boolean endsWith(final CIString value) { return lcValue.endsWith(value.lcValue); } | CIString implements Comparable<CIString>, CharSequence { public boolean endsWith(final CIString value) { return lcValue.endsWith(value.lcValue); } } | CIString implements Comparable<CIString>, CharSequence { public boolean endsWith(final CIString value) { return lcValue.endsWith(value.lcValue); } private CIString(final String value); } | CIString implements Comparable<CIString>, CharSequence { public boolean endsWith(final CIString value) { return lcValue.endsWith(value.lcValue); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } | CIString implements Comparable<CIString>, CharSequence { public boolean endsWith(final CIString value) { return lcValue.endsWith(value.lcValue); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } |
@Test public void append() { assertThat(ciString("").append(ciString("")), is(ciString(""))); assertThat(ciString("a").append(ciString("b")), is(ciString("ab"))); assertThat(ciString("a").append(ciString("b")), is(ciString("AB"))); } | public CIString append(final CIString other) { return ciString(value + other.value); } | CIString implements Comparable<CIString>, CharSequence { public CIString append(final CIString other) { return ciString(value + other.value); } } | CIString implements Comparable<CIString>, CharSequence { public CIString append(final CIString other) { return ciString(value + other.value); } private CIString(final String value); } | CIString implements Comparable<CIString>, CharSequence { public CIString append(final CIString other) { return ciString(value + other.value); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } | CIString implements Comparable<CIString>, CharSequence { public CIString append(final CIString other) { return ciString(value + other.value); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } |
@Test public void toInt() { assertThat(ciString("1").toInt(), is(1)); assertThat(ciString("312").toInt(), is(312)); } | public int toInt() { return Integer.parseInt(value); } | CIString implements Comparable<CIString>, CharSequence { public int toInt() { return Integer.parseInt(value); } } | CIString implements Comparable<CIString>, CharSequence { public int toInt() { return Integer.parseInt(value); } private CIString(final String value); } | CIString implements Comparable<CIString>, CharSequence { public int toInt() { return Integer.parseInt(value); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } | CIString implements Comparable<CIString>, CharSequence { public int toInt() { return Integer.parseInt(value); } private CIString(final String value); @Nullable static CIString ciString(final String value); static Set<CIString> ciSet(final String... values); static Set<CIString> ciImmutableSet(final String... values); static Set<CIString> ciSet(final Iterable<String> values); static Set<CIString> ciImmutableSet(final Iterable<String> values); static boolean isBlank(final CIString ciString); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override int compareTo(@Nonnull final CIString o); @Override @Nonnull String toString(); String toLowerCase(); String toUpperCase(); int toInt(); @Override int length(); @Override char charAt(final int index); @Override CharSequence subSequence(final int start, final int end); boolean startsWith(final CIString value); boolean startsWith(final String value); boolean contains(final CIString value); boolean contains(final String value); boolean endsWith(final CIString value); boolean endsWith(final String value); CIString append(final CIString other); } |
@Test public void handleLines_rpsl_object() throws IOException { final BufferedReader reader = new BufferedReader(new StringReader("" + "person: John Smith\n" + "address: Example LTD\n" + " High street 12\n" + " St.Mery Mead\n" + " Essex, UK\n" + "phone: +44 1737 892 004\n" + "e-mail: [email protected]\n" + "nic-hdl: JS1-TEST\n" + "remarks: *******************************\n" + "remarks: This object is only an example!\n" + "remarks: *******************************\n" + "mnt-by: EXAMPLE-MNT\n" + "abuse-mailbox: [email protected]\n" + "changed: [email protected] 20051104\n" + "changed: [email protected] 20051105\n" + "source: TEST\n" + "\n" + "mntner: TEST-ROOT-MNT\n")); final List<List<String>> handledLines = Lists.newArrayList(); subject.handleLines(reader, new GrsSource.LineHandler() { @Override public void handleLines(final List<String> lines) { handledLines.add(lines); } }); assertThat(handledLines, hasSize(2)); assertThat(handledLines.get(0), is((List<String>) Lists.newArrayList( "person: John Smith\n", "" + "address: Example LTD\n" + " High street 12\n" + " St.Mery Mead\n" + " Essex, UK\n", "phone: +44 1737 892 004\n", "e-mail: [email protected]\n", "nic-hdl: JS1-TEST\n", "remarks: *******************************\n", "remarks: This object is only an example!\n", "remarks: *******************************\n", "mnt-by: EXAMPLE-MNT\n", "abuse-mailbox: [email protected]\n", "changed: [email protected] 20051104\n", "changed: [email protected] 20051105\n", "source: TEST\n"))); assertThat(handledLines.get(1), is((List<String>) Lists.newArrayList( "mntner: TEST-ROOT-MNT\n"))); } | void handleLines(final BufferedReader reader, final LineHandler lineHandler) throws IOException { List<String> lines = Lists.newArrayList(); StringBuilder lineBuilder = new StringBuilder(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.length() == 0) { lineBuilder = addLine(lines, lineBuilder); handleLines(lineHandler, lines); lines = Lists.newArrayList(); continue; } final char firstChar = line.charAt(0); if (firstChar == '#' || firstChar == '%') { continue; } if (firstChar != ' ' && firstChar != '+') { lineBuilder = addLine(lines, lineBuilder); } lineBuilder.append(line).append('\n'); } addLine(lines, lineBuilder); handleLines(lineHandler, lines); } | GrsSource implements InitializingBean { void handleLines(final BufferedReader reader, final LineHandler lineHandler) throws IOException { List<String> lines = Lists.newArrayList(); StringBuilder lineBuilder = new StringBuilder(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.length() == 0) { lineBuilder = addLine(lines, lineBuilder); handleLines(lineHandler, lines); lines = Lists.newArrayList(); continue; } final char firstChar = line.charAt(0); if (firstChar == '#' || firstChar == '%') { continue; } if (firstChar != ' ' && firstChar != '+') { lineBuilder = addLine(lines, lineBuilder); } lineBuilder.append(line).append('\n'); } addLine(lines, lineBuilder); handleLines(lineHandler, lines); } } | GrsSource implements InitializingBean { void handleLines(final BufferedReader reader, final LineHandler lineHandler) throws IOException { List<String> lines = Lists.newArrayList(); StringBuilder lineBuilder = new StringBuilder(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.length() == 0) { lineBuilder = addLine(lines, lineBuilder); handleLines(lineHandler, lines); lines = Lists.newArrayList(); continue; } final char firstChar = line.charAt(0); if (firstChar == '#' || firstChar == '%') { continue; } if (firstChar != ' ' && firstChar != '+') { lineBuilder = addLine(lines, lineBuilder); } lineBuilder.append(line).append('\n'); } addLine(lines, lineBuilder); handleLines(lineHandler, lines); } GrsSource(final String name, final SourceContext sourceContext, final DateTimeProvider dateTimeProvider, final AuthoritativeResourceData authoritativeResourceData, final Downloader downloader); } | GrsSource implements InitializingBean { void handleLines(final BufferedReader reader, final LineHandler lineHandler) throws IOException { List<String> lines = Lists.newArrayList(); StringBuilder lineBuilder = new StringBuilder(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.length() == 0) { lineBuilder = addLine(lines, lineBuilder); handleLines(lineHandler, lines); lines = Lists.newArrayList(); continue; } final char firstChar = line.charAt(0); if (firstChar == '#' || firstChar == '%') { continue; } if (firstChar != ' ' && firstChar != '+') { lineBuilder = addLine(lines, lineBuilder); } lineBuilder.append(line).append('\n'); } addLine(lines, lineBuilder); handleLines(lineHandler, lines); } GrsSource(final String name, final SourceContext sourceContext, final DateTimeProvider dateTimeProvider, final AuthoritativeResourceData authoritativeResourceData, final Downloader downloader); @Override void afterPropertiesSet(); Logger getLogger(); @Override String toString(); } | GrsSource implements InitializingBean { void handleLines(final BufferedReader reader, final LineHandler lineHandler) throws IOException { List<String> lines = Lists.newArrayList(); StringBuilder lineBuilder = new StringBuilder(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { if (line.length() == 0) { lineBuilder = addLine(lines, lineBuilder); handleLines(lineHandler, lines); lines = Lists.newArrayList(); continue; } final char firstChar = line.charAt(0); if (firstChar == '#' || firstChar == '%') { continue; } if (firstChar != ' ' && firstChar != '+') { lineBuilder = addLine(lines, lineBuilder); } lineBuilder.append(line).append('\n'); } addLine(lines, lineBuilder); handleLines(lineHandler, lines); } GrsSource(final String name, final SourceContext sourceContext, final DateTimeProvider dateTimeProvider, final AuthoritativeResourceData authoritativeResourceData, final Downloader downloader); @Override void afterPropertiesSet(); Logger getLogger(); @Override String toString(); } |
@Test public void headerShouldContainLinkToTermsAndConditions() { assertThat(QueryMessages.termsAndConditions().toString(), containsString("http: } | public static Message termsAndConditions() { return new Message(Type.INFO, "" + "% This is the RIPE Database query service.\n" + "% The objects are in RPSL format.\n" + "%\n" + "% The RIPE Database is subject to Terms and Conditions.\n" + "% See http: } | QueryMessages { public static Message termsAndConditions() { return new Message(Type.INFO, "" + "% This is the RIPE Database query service.\n" + "% The objects are in RPSL format.\n" + "%\n" + "% The RIPE Database is subject to Terms and Conditions.\n" + "% See http: } } | QueryMessages { public static Message termsAndConditions() { return new Message(Type.INFO, "" + "% This is the RIPE Database query service.\n" + "% The objects are in RPSL format.\n" + "%\n" + "% The RIPE Database is subject to Terms and Conditions.\n" + "% See http: } private QueryMessages(); } | QueryMessages { public static Message termsAndConditions() { return new Message(Type.INFO, "" + "% This is the RIPE Database query service.\n" + "% The objects are in RPSL format.\n" + "%\n" + "% The RIPE Database is subject to Terms and Conditions.\n" + "% See http: } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message termsAndConditions() { return new Message(Type.INFO, "" + "% This is the RIPE Database query service.\n" + "% The objects are in RPSL format.\n" + "%\n" + "% The RIPE Database is subject to Terms and Conditions.\n" + "% See http: } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void duplicateIpFlagsPassedShouldContainError() { assertThat(QueryMessages.duplicateIpFlagsPassed().toString(), containsString("%ERROR:901:")); } | public static Message duplicateIpFlagsPassed() { return new QueryMessage(Type.ERROR, "" + "ERROR:901: duplicate IP flags passed\n" + "\n" + "More than one IP flag (-l, -L, -m, -M or -x) passed to the server."); } | QueryMessages { public static Message duplicateIpFlagsPassed() { return new QueryMessage(Type.ERROR, "" + "ERROR:901: duplicate IP flags passed\n" + "\n" + "More than one IP flag (-l, -L, -m, -M or -x) passed to the server."); } } | QueryMessages { public static Message duplicateIpFlagsPassed() { return new QueryMessage(Type.ERROR, "" + "ERROR:901: duplicate IP flags passed\n" + "\n" + "More than one IP flag (-l, -L, -m, -M or -x) passed to the server."); } private QueryMessages(); } | QueryMessages { public static Message duplicateIpFlagsPassed() { return new QueryMessage(Type.ERROR, "" + "ERROR:901: duplicate IP flags passed\n" + "\n" + "More than one IP flag (-l, -L, -m, -M or -x) passed to the server."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message duplicateIpFlagsPassed() { return new QueryMessage(Type.ERROR, "" + "ERROR:901: duplicate IP flags passed\n" + "\n" + "More than one IP flag (-l, -L, -m, -M or -x) passed to the server."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void restApiExpectsAbuseContactsInSpecificFormat() { assertThat(QueryMessages.abuseCShown("193.0.0.0 - 193.0.7.255", "[email protected]").toString(), is("% Abuse contact for '193.0.0.0 - 193.0.7.255' is '[email protected]'\n")); } | public static Message abuseCShown(final CharSequence key, final CharSequence value) { return new QueryMessage(Type.INFO, "Abuse contact for '%s' is '%s'", key, value); } | QueryMessages { public static Message abuseCShown(final CharSequence key, final CharSequence value) { return new QueryMessage(Type.INFO, "Abuse contact for '%s' is '%s'", key, value); } } | QueryMessages { public static Message abuseCShown(final CharSequence key, final CharSequence value) { return new QueryMessage(Type.INFO, "Abuse contact for '%s' is '%s'", key, value); } private QueryMessages(); } | QueryMessages { public static Message abuseCShown(final CharSequence key, final CharSequence value) { return new QueryMessage(Type.INFO, "Abuse contact for '%s' is '%s'", key, value); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message abuseCShown(final CharSequence key, final CharSequence value) { return new QueryMessage(Type.INFO, "Abuse contact for '%s' is '%s'", key, value); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void internalErrorMessageShouldContainErrorCode() { assertThat(QueryMessages.internalErroroccurred().toString(), containsString("%ERROR:100:")); } | public static Message internalErroroccurred() { return new QueryMessage(Type.ERROR, "" + "ERROR:100: internal software error\n" + "\n" + "Please contact [email protected] if the problem persists."); } | QueryMessages { public static Message internalErroroccurred() { return new QueryMessage(Type.ERROR, "" + "ERROR:100: internal software error\n" + "\n" + "Please contact [email protected] if the problem persists."); } } | QueryMessages { public static Message internalErroroccurred() { return new QueryMessage(Type.ERROR, "" + "ERROR:100: internal software error\n" + "\n" + "Please contact [email protected] if the problem persists."); } private QueryMessages(); } | QueryMessages { public static Message internalErroroccurred() { return new QueryMessage(Type.ERROR, "" + "ERROR:100: internal software error\n" + "\n" + "Please contact [email protected] if the problem persists."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message internalErroroccurred() { return new QueryMessage(Type.ERROR, "" + "ERROR:100: internal software error\n" + "\n" + "Please contact [email protected] if the problem persists."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void noSearchKeySpecifiedShouldContainError() { assertThat(QueryMessages.noSearchKeySpecified().toString(), containsString("%ERROR:106:")); } | public static Message noSearchKeySpecified() { return new QueryMessage(Type.ERROR, "" + "ERROR:106: no search key specified\n" + "\n" + "No search key specified"); } | QueryMessages { public static Message noSearchKeySpecified() { return new QueryMessage(Type.ERROR, "" + "ERROR:106: no search key specified\n" + "\n" + "No search key specified"); } } | QueryMessages { public static Message noSearchKeySpecified() { return new QueryMessage(Type.ERROR, "" + "ERROR:106: no search key specified\n" + "\n" + "No search key specified"); } private QueryMessages(); } | QueryMessages { public static Message noSearchKeySpecified() { return new QueryMessage(Type.ERROR, "" + "ERROR:106: no search key specified\n" + "\n" + "No search key specified"); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message noSearchKeySpecified() { return new QueryMessage(Type.ERROR, "" + "ERROR:106: no search key specified\n" + "\n" + "No search key specified"); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void noResultsMessageShouldContainErrorCode() { assertThat(QueryMessages.noResults("RIPE").toString(), containsString("%ERROR:101:")); } | public static Message noResults(final CharSequence source) { return new QueryMessage(Type.ERROR, "" + "ERROR:101: no entries found\n" + "\n" + "No entries found in source %s.", source); } | QueryMessages { public static Message noResults(final CharSequence source) { return new QueryMessage(Type.ERROR, "" + "ERROR:101: no entries found\n" + "\n" + "No entries found in source %s.", source); } } | QueryMessages { public static Message noResults(final CharSequence source) { return new QueryMessage(Type.ERROR, "" + "ERROR:101: no entries found\n" + "\n" + "No entries found in source %s.", source); } private QueryMessages(); } | QueryMessages { public static Message noResults(final CharSequence source) { return new QueryMessage(Type.ERROR, "" + "ERROR:101: no entries found\n" + "\n" + "No entries found in source %s.", source); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message noResults(final CharSequence source) { return new QueryMessage(Type.ERROR, "" + "ERROR:101: no entries found\n" + "\n" + "No entries found in source %s.", source); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void accessDeniedPermanentlyShouldContainErrorCode() throws UnknownHostException { assertThat(QueryMessages.accessDeniedPermanently(InetAddress.getLocalHost()).toString(), containsString("%ERROR:201:")); } | public static Message accessDeniedPermanently(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Sorry, access from your host has been permanently\n" + "denied because of a repeated excessive querying.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } | QueryMessages { public static Message accessDeniedPermanently(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Sorry, access from your host has been permanently\n" + "denied because of a repeated excessive querying.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } } | QueryMessages { public static Message accessDeniedPermanently(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Sorry, access from your host has been permanently\n" + "denied because of a repeated excessive querying.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } private QueryMessages(); } | QueryMessages { public static Message accessDeniedPermanently(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Sorry, access from your host has been permanently\n" + "denied because of a repeated excessive querying.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message accessDeniedPermanently(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Sorry, access from your host has been permanently\n" + "denied because of a repeated excessive querying.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void accessDeniedTemporarilyMessageShouldContainErrorCode() throws UnknownHostException { assertThat(QueryMessages.accessDeniedTemporarily(InetAddress.getLocalHost()).toString(), containsString("%ERROR:201:")); } | public static Message accessDeniedTemporarily(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Queries from your IP address have passed the daily limit of controlled objects.\n" + "Access from your host has been temporarily denied.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } | QueryMessages { public static Message accessDeniedTemporarily(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Queries from your IP address have passed the daily limit of controlled objects.\n" + "Access from your host has been temporarily denied.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } } | QueryMessages { public static Message accessDeniedTemporarily(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Queries from your IP address have passed the daily limit of controlled objects.\n" + "Access from your host has been temporarily denied.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } private QueryMessages(); } | QueryMessages { public static Message accessDeniedTemporarily(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Queries from your IP address have passed the daily limit of controlled objects.\n" + "Access from your host has been temporarily denied.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message accessDeniedTemporarily(final InetAddress remoteAddress) { return new QueryMessage(Type.ERROR, "" + "ERROR:201: access denied for %s\n" + "\n" + "Queries from your IP address have passed the daily limit of controlled objects.\n" + "Access from your host has been temporarily denied.\n" + "For more information, see\n" + "http: remoteAddress.getHostAddress()); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void tooLongInputStringShouldContainErrorCode() { assertThat(QueryMessages.inputTooLong().toString(), containsString("%ERROR:107:")); } | public static Message inputTooLong() { return new QueryMessage(Type.ERROR, "" + "ERROR:107: input line too long\n" + "\n" + "Input exceeds the maximum line length."); } | QueryMessages { public static Message inputTooLong() { return new QueryMessage(Type.ERROR, "" + "ERROR:107: input line too long\n" + "\n" + "Input exceeds the maximum line length."); } } | QueryMessages { public static Message inputTooLong() { return new QueryMessage(Type.ERROR, "" + "ERROR:107: input line too long\n" + "\n" + "Input exceeds the maximum line length."); } private QueryMessages(); } | QueryMessages { public static Message inputTooLong() { return new QueryMessage(Type.ERROR, "" + "ERROR:107: input line too long\n" + "\n" + "Input exceeds the maximum line length."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message inputTooLong() { return new QueryMessage(Type.ERROR, "" + "ERROR:107: input line too long\n" + "\n" + "Input exceeds the maximum line length."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void invalidObjectTypeShouldContainErrorCode() { assertThat(QueryMessages.invalidObjectType("").toString(), containsString("%ERROR:103:")); } | public static Message invalidObjectType(final CharSequence type) { return new QueryMessage(Type.ERROR, "ERROR:103: unknown object type '%s'", type); } | QueryMessages { public static Message invalidObjectType(final CharSequence type) { return new QueryMessage(Type.ERROR, "ERROR:103: unknown object type '%s'", type); } } | QueryMessages { public static Message invalidObjectType(final CharSequence type) { return new QueryMessage(Type.ERROR, "ERROR:103: unknown object type '%s'", type); } private QueryMessages(); } | QueryMessages { public static Message invalidObjectType(final CharSequence type) { return new QueryMessage(Type.ERROR, "ERROR:103: unknown object type '%s'", type); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message invalidObjectType(final CharSequence type) { return new QueryMessage(Type.ERROR, "ERROR:103: unknown object type '%s'", type); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void handleObjects() throws Exception { final File file = new File(getClass().getResource("/grs/jpirr.test.gz").toURI()); subject.handleObjects(file, objectHandler); assertThat(objectHandler.getObjects(), hasSize(0)); assertThat(objectHandler.getLines(), hasSize(2)); assertThat(objectHandler.getLines(), contains((List<String>) Lists.newArrayList("" + "route: 219.23.0.0/16\n", "descr: Description\n", "origin: AS76\n", "mnt-by: MNT-AS76\n", "changed: [email protected] 20061016\n", "changed: [email protected] 20070402\n", "changed: [email protected] 20070718\n", "source: JPIRR\n"), Lists.newArrayList("" + "as-set: AS-BOGUS\n", "descr: Description\n", "members: AS74\n", "notify: [email protected]\n", "mnt-by: MNT-AS18\n", "changed: [email protected] 20130109\n", "source: JPIRR\n") )); } | @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { if (!lines.isEmpty() && !lines.get(0).startsWith("*xx")) { handler.handle(lines); } } }); } finally { IOUtils.closeQuietly(is); } } | JpirrGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { if (!lines.isEmpty() && !lines.get(0).startsWith("*xx")) { handler.handle(lines); } } }); } finally { IOUtils.closeQuietly(is); } } } | JpirrGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { if (!lines.isEmpty() && !lines.get(0).startsWith("*xx")) { handler.handle(lines); } } }); } finally { IOUtils.closeQuietly(is); } } @Autowired JpirrGrsSource(
@Value("${grs.import.jpirr.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.jpirr.download:}") final String download); } | JpirrGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { if (!lines.isEmpty() && !lines.get(0).startsWith("*xx")) { handler.handle(lines); } } }); } finally { IOUtils.closeQuietly(is); } } @Autowired JpirrGrsSource(
@Value("${grs.import.jpirr.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.jpirr.download:}") final String download); @Override void acquireDump(final Path path); @Override void handleObjects(final File file, final ObjectHandler handler); } | JpirrGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { if (!lines.isEmpty() && !lines.get(0).startsWith("*xx")) { handler.handle(lines); } } }); } finally { IOUtils.closeQuietly(is); } } @Autowired JpirrGrsSource(
@Value("${grs.import.jpirr.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.jpirr.download:}") final String download); @Override void acquireDump(final Path path); @Override void handleObjects(final File file, final ObjectHandler handler); } |
@Test public void invalidInetnumMessageShouldContainErrorCode() { assertThat(QueryMessages.uselessIpFlagPassed().toString(), containsString("%WARNING:902:")); } | public static Message uselessIpFlagPassed() { return new QueryMessage(Type.WARNING, "" + "WARNING:902: useless IP flag passed\n" + "\n" + "An IP flag (-l, -L, -m, -M, -x, -d or -b) used without an IP key."); } | QueryMessages { public static Message uselessIpFlagPassed() { return new QueryMessage(Type.WARNING, "" + "WARNING:902: useless IP flag passed\n" + "\n" + "An IP flag (-l, -L, -m, -M, -x, -d or -b) used without an IP key."); } } | QueryMessages { public static Message uselessIpFlagPassed() { return new QueryMessage(Type.WARNING, "" + "WARNING:902: useless IP flag passed\n" + "\n" + "An IP flag (-l, -L, -m, -M, -x, -d or -b) used without an IP key."); } private QueryMessages(); } | QueryMessages { public static Message uselessIpFlagPassed() { return new QueryMessage(Type.WARNING, "" + "WARNING:902: useless IP flag passed\n" + "\n" + "An IP flag (-l, -L, -m, -M, -x, -d or -b) used without an IP key."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message uselessIpFlagPassed() { return new QueryMessage(Type.WARNING, "" + "WARNING:902: useless IP flag passed\n" + "\n" + "An IP flag (-l, -L, -m, -M, -x, -d or -b) used without an IP key."); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void malformedQueryShouldContainError() { assertThat(QueryMessages.malformedQuery().toString(), containsString("%ERROR:111:")); } | public static Message malformedQuery() { return malformedQuery(null); } | QueryMessages { public static Message malformedQuery() { return malformedQuery(null); } } | QueryMessages { public static Message malformedQuery() { return malformedQuery(null); } private QueryMessages(); } | QueryMessages { public static Message malformedQuery() { return malformedQuery(null); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message malformedQuery() { return malformedQuery(null); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void notAllowedToProxyShouldContainError() { assertThat(QueryMessages.notAllowedToProxy().toString(), containsString("%ERROR:203:")); } | public static Message notAllowedToProxy() { return new QueryMessage(Type.ERROR, "ERROR:203: you are not allowed to act as a proxy"); } | QueryMessages { public static Message notAllowedToProxy() { return new QueryMessage(Type.ERROR, "ERROR:203: you are not allowed to act as a proxy"); } } | QueryMessages { public static Message notAllowedToProxy() { return new QueryMessage(Type.ERROR, "ERROR:203: you are not allowed to act as a proxy"); } private QueryMessages(); } | QueryMessages { public static Message notAllowedToProxy() { return new QueryMessage(Type.ERROR, "ERROR:203: you are not allowed to act as a proxy"); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } | QueryMessages { public static Message notAllowedToProxy() { return new QueryMessage(Type.ERROR, "ERROR:203: you are not allowed to act as a proxy"); } private QueryMessages(); static Message termsAndConditions(); static Message servedByNotice(final CharSequence version); static Message termsAndConditionsDump(); static Message relatedTo(final CharSequence key); static Message noPersonal(); static Message abuseCShown(final CharSequence key, final CharSequence value); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value, final CharSequence orgId); static Message unvalidatedAbuseCShown(final CharSequence key, final CharSequence value); static Message abuseCNotRegistered(final CharSequence key); static Message outputFilterNotice(); static Message primaryKeysOnlyNotice(); static Message versionListStart(final CharSequence type, final CharSequence key); static Message versionInformation(final int version, final boolean isCurrentVersion, final CIString key, final String operation, final String timestamp); static Message versionDifferenceHeader(final int earlierVersion, final int laterVersion, final CIString key); static Message versionDeleted(final CharSequence deletionTime); static Message versionPersonRole(final CharSequence type, final CharSequence key); static Message internalErroroccurred(); static Message noResults(final CharSequence source); static Message unknownSource(final CharSequence source); static Message invalidObjectType(final CharSequence type); static Message invalidAttributeType(final CharSequence type); static Message attributeNotSearchable(final CharSequence type); static Message noSearchKeySpecified(); static Message inputTooLong(); static Message invalidCombinationOfFlags(final CharSequence flag, final CharSequence otherFlag); static Message invalidMultipleFlags(final CharSequence flag); static Message malformedQuery(); static Message malformedQuery(final String reason); static Message illegalRange(); static Message unsupportedQuery(); static Message invalidSearchKey(); static Message unsupportedVersionObjectType(); static Message versionOutOfRange(final int max); static Message tooManyArguments(); static Message accessDeniedPermanently(final InetAddress remoteAddress); static Message accessDeniedTemporarily(final InetAddress remoteAddress); static Message notAllowedToProxy(); static Message timeout(); static Message connectionsExceeded(final int connectionLimit); static Message duplicateIpFlagsPassed(); static Message uselessIpFlagPassed(); static Message tagInfoStart(final CharSequence pkey); static Message tagInfo(final CharSequence tagType, final CharSequence tagValue); static Message unreferencedTagInfo(final CharSequence pkey, final CharSequence value); static Message filterTagNote(final Set<? extends CharSequence> includeArgs, final Set<? extends CharSequence> excludeArgs); static Message invalidSyntax(final CharSequence objectKey); static Message validSyntax(final CharSequence objectKey); static Message inverseSearchNotAllowed(); static Message valueChangedDueToLatin1Conversion(); } |
@Test public void hasflags() { assertThat(QueryParser.hasFlags("--abuse-contact 193.0.0.1"), is(true)); assertThat(QueryParser.hasFlags("-L 193.0.0.1"), is(true)); assertThat(QueryParser.hasFlags("193.0.0.1"), is(false)); } | public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } QueryParser(final String query); } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } QueryParser(final String query); String getSearchKey(); boolean hasOptions(); boolean hasOption(final QueryFlag queryFlag); String getOptionValue(final QueryFlag queryFlag); Set<String> getOptionValues(final QueryFlag queryFlag); Set<CIString> getOptionValuesCI(final QueryFlag queryFlag); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); boolean hasOnlyQueryFlag(final QueryFlag queryFlag); static boolean hasFlags(final String queryString); boolean hasSubstitutions(); } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } QueryParser(final String query); String getSearchKey(); boolean hasOptions(); boolean hasOption(final QueryFlag queryFlag); String getOptionValue(final QueryFlag queryFlag); Set<String> getOptionValues(final QueryFlag queryFlag); Set<CIString> getOptionValuesCI(final QueryFlag queryFlag); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); boolean hasOnlyQueryFlag(final QueryFlag queryFlag); static boolean hasFlags(final String queryString); boolean hasSubstitutions(); static final Pattern FLAG_PATTERN; } |
@Test public void hasflags_invalid_option_supplied() { try { QueryParser.hasFlags("--this-is-an-invalid-flag"); fail(); } catch (IllegalArgumentExceptionMessage e) { assertThat(e.getExceptionMessage(), is(QueryMessages.malformedQuery("Invalid option: --this-is-an-invalid-flag"))); } } | public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } QueryParser(final String query); } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } QueryParser(final String query); String getSearchKey(); boolean hasOptions(); boolean hasOption(final QueryFlag queryFlag); String getOptionValue(final QueryFlag queryFlag); Set<String> getOptionValues(final QueryFlag queryFlag); Set<CIString> getOptionValuesCI(final QueryFlag queryFlag); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); boolean hasOnlyQueryFlag(final QueryFlag queryFlag); static boolean hasFlags(final String queryString); boolean hasSubstitutions(); } | QueryParser { public static boolean hasFlags(final String queryString) { return PARSER.parse(Iterables.toArray(SPACE_SPLITTER.split(queryString), String.class)).hasOptions(); } QueryParser(final String query); String getSearchKey(); boolean hasOptions(); boolean hasOption(final QueryFlag queryFlag); String getOptionValue(final QueryFlag queryFlag); Set<String> getOptionValues(final QueryFlag queryFlag); Set<CIString> getOptionValuesCI(final QueryFlag queryFlag); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); boolean hasOnlyQueryFlag(final QueryFlag queryFlag); static boolean hasFlags(final String queryString); boolean hasSubstitutions(); static final Pattern FLAG_PATTERN; } |
@Test public void map_rpsl_mntner() throws Exception { final RpslObject rpslObject = RpslObject.parse( "mntner: TST-MNT\n" + "descr: MNTNER for test\n" + "admin-c: TP1-TEST\n" + "upd-to: [email protected]\n" + "auth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/ # test\n" + "auth: PGPKEY-28F6CD6C\n" + "mnt-by: TST-MNT\n" + "source: TEST\n"); final WhoisObject whoisObject = mapper.map(rpslObject, FormattedClientAttributeMapper.class); assertThat(whoisObject.getType(), is("mntner")); assertThat(whoisObject.getSource().getId(), is("test")); assertThat(whoisObject.getLink().getType(), is("locator")); assertThat(whoisObject.getLink().getHref(), is("http: assertThat(whoisObject.getPrimaryKey(), hasSize(1)); final Attribute primaryKeyAttribute = whoisObject.getPrimaryKey().get(0); assertThat(primaryKeyAttribute.getName(), is("mntner")); assertThat(primaryKeyAttribute.getValue(), is("TST-MNT")); assertThat(whoisObject.getAttributes(), contains( new Attribute("mntner", "TST-MNT", null, null, null, null), new Attribute("descr", "MNTNER for test", null, null, null, null), new Attribute("admin-c", "TP1-TEST", null, null, null, null), new Attribute("upd-to", "[email protected]", null, null, null, null), new Attribute("auth", "MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/", "test", null, null, null), new Attribute("auth", "PGPKEY-28F6CD6C", null, null, null, null), new Attribute("mnt-by", "TST-MNT", null, null, null, null), new Attribute("source", "TEST", null, null, null, null) )); } | public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } @Autowired WhoisObjectMapper(@Value("${api.rest.baseurl}") final String baseUrl,
final AttributeMapper[] objectMapperFunctions); } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } @Autowired WhoisObjectMapper(@Value("${api.rest.baseurl}") final String baseUrl,
final AttributeMapper[] objectMapperFunctions); RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction); List<RpslObject> mapWhoisObjects(final Iterable<WhoisObject> whoisObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<?> mapFunction, final RpslObject... rpslObjects); WhoisResources mapRpslObjects(final Iterable<RpslObject> rpslObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<? extends AttributeMapper> mapFunction, final ActionRequest ... requests); WhoisObject map(final RpslObject rpslObject, final Class<?> mapFunction); } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } @Autowired WhoisObjectMapper(@Value("${api.rest.baseurl}") final String baseUrl,
final AttributeMapper[] objectMapperFunctions); RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction); List<RpslObject> mapWhoisObjects(final Iterable<WhoisObject> whoisObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<?> mapFunction, final RpslObject... rpslObjects); WhoisResources mapRpslObjects(final Iterable<RpslObject> rpslObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<? extends AttributeMapper> mapFunction, final ActionRequest ... requests); WhoisObject map(final RpslObject rpslObject, final Class<?> mapFunction); } |
@Test public void map_rpsl_as_set_members_multiple_values() throws Exception { final RpslObject rpslObject = RpslObject.parse("" + "as-set: AS-set-attendees\n" + "descr: AS-set containing all attendees' ASNs.\n" + "tech-c: TS1-TEST\n" + "admin-c: TS1-TEST\n" + "members: as1,as2,as3,\n" + "mnt-by: TS1-MNT\n" + "source: TEST"); final WhoisObject whoisObject = mapper.map(rpslObject, FormattedClientAttributeMapper.class); assertThat(whoisObject.getType(), is("as-set")); assertThat(whoisObject.getSource().getId(), is("test")); assertThat(whoisObject.getLink().getType(), is("locator")); assertThat(whoisObject.getLink().getHref(), is("http: assertThat(whoisObject.getPrimaryKey(), hasSize(1)); final Attribute primaryKeyAttribute = whoisObject.getPrimaryKey().get(0); assertThat(primaryKeyAttribute.getName(), is("as-set")); assertThat(primaryKeyAttribute.getValue(), is("AS-set-attendees")); assertThat(whoisObject.getAttributes(), containsInAnyOrder( new Attribute("as-set", "AS-set-attendees", null, null, null, null), new Attribute("descr", "AS-set containing all attendees' ASNs.", null, null, null, null), new Attribute("tech-c", "TS1-TEST", null, null, null, null), new Attribute("admin-c", "TS1-TEST", null, null, null, null), new Attribute("members", "as1", null, null, null, null), new Attribute("members", "as2", null, null, null, null), new Attribute("members", "as3", null, null, null, null), new Attribute("members", "", null, null, null, null), new Attribute("mnt-by", "TS1-MNT", null, null, null, null), new Attribute("source", "TEST", null, null, null, null) )); } | public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } @Autowired WhoisObjectMapper(@Value("${api.rest.baseurl}") final String baseUrl,
final AttributeMapper[] objectMapperFunctions); } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } @Autowired WhoisObjectMapper(@Value("${api.rest.baseurl}") final String baseUrl,
final AttributeMapper[] objectMapperFunctions); RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction); List<RpslObject> mapWhoisObjects(final Iterable<WhoisObject> whoisObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<?> mapFunction, final RpslObject... rpslObjects); WhoisResources mapRpslObjects(final Iterable<RpslObject> rpslObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<? extends AttributeMapper> mapFunction, final ActionRequest ... requests); WhoisObject map(final RpslObject rpslObject, final Class<?> mapFunction); } | WhoisObjectMapper { public RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction) { final List<RpslAttribute> rpslAttributes = Lists.newArrayList(); final AttributeMapper attributeMapper = objectMapperFunctions.get(mapFunction); for (final Attribute attribute : whoisObject.getAttributes()) { rpslAttributes.addAll(attributeMapper.map(attribute)); } return new RpslObject(rpslAttributes); } @Autowired WhoisObjectMapper(@Value("${api.rest.baseurl}") final String baseUrl,
final AttributeMapper[] objectMapperFunctions); RpslObject map(final WhoisObject whoisObject, final Class<?> mapFunction); List<RpslObject> mapWhoisObjects(final Iterable<WhoisObject> whoisObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<?> mapFunction, final RpslObject... rpslObjects); WhoisResources mapRpslObjects(final Iterable<RpslObject> rpslObjects, final Class<?> mapFunction); WhoisResources mapRpslObjects(final Class<? extends AttributeMapper> mapFunction, final ActionRequest ... requests); WhoisObject map(final RpslObject rpslObject, final Class<?> mapFunction); } |
@Test public void read_error_response() { final WhoisResources whoisResources = StreamingRestClient.unMarshalError( new ByteArrayInputStream(( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<whois-resources xmlns:xlink=\"http: "<link xlink:type=\"locator\" xlink:href=\"http: "<errormessages><errormessage severity=\"Error\" text=\"Query param 'query-string' cannot be empty\"/></errormessages>" + "<terms-and-conditions xlink:type=\"locator\" xlink:href=\"http: "</whois-resources>\n").getBytes())); assertThat(whoisResources.getErrorMessages(), hasSize(1)); assertThat(whoisResources.getErrorMessages().get(0).getText(), is("Query param 'query-string' cannot be empty")); } | public static WhoisResources unMarshalError(final InputStream inputStream) { return (WhoisResources) (new StreamingRestClient(inputStream)).unmarshal(); } | StreamingRestClient implements Iterator<WhoisObject>, Closeable { public static WhoisResources unMarshalError(final InputStream inputStream) { return (WhoisResources) (new StreamingRestClient(inputStream)).unmarshal(); } } | StreamingRestClient implements Iterator<WhoisObject>, Closeable { public static WhoisResources unMarshalError(final InputStream inputStream) { return (WhoisResources) (new StreamingRestClient(inputStream)).unmarshal(); } StreamingRestClient(final InputStream inputStream); } | StreamingRestClient implements Iterator<WhoisObject>, Closeable { public static WhoisResources unMarshalError(final InputStream inputStream) { return (WhoisResources) (new StreamingRestClient(inputStream)).unmarshal(); } StreamingRestClient(final InputStream inputStream); @Override boolean hasNext(); @Override WhoisObject next(); @Override void remove(); @Override void close(); static WhoisResources unMarshalError(final InputStream inputStream); } | StreamingRestClient implements Iterator<WhoisObject>, Closeable { public static WhoisResources unMarshalError(final InputStream inputStream) { return (WhoisResources) (new StreamingRestClient(inputStream)).unmarshal(); } StreamingRestClient(final InputStream inputStream); @Override boolean hasNext(); @Override WhoisObject next(); @Override void remove(); @Override void close(); static WhoisResources unMarshalError(final InputStream inputStream); } |
@Test public void to_string_no_arguments() { assertThat(new ErrorMessage(new Message(Messages.Type.INFO, "message")).toString(), is("message")); } | @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } |
@Test public void to_string_with_single_argument() { assertThat(new ErrorMessage(new Message(Messages.Type.INFO, "message with %s", "argument")).toString(), is("message with argument")); } | @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } |
@Test public void getGrsDefaultSources() { final String defaultSources = subject.getGrsDefaultSources(); assertThat(defaultSources, is("ARIN-GRS,APNIC-GRS")); } | @ManagedAttribute(description = "Comma separated list of default GRS sources") public String getGrsDefaultSources() { return grsDefaultSources; } | GrsImporterJmx extends JmxBase { @ManagedAttribute(description = "Comma separated list of default GRS sources") public String getGrsDefaultSources() { return grsDefaultSources; } } | GrsImporterJmx extends JmxBase { @ManagedAttribute(description = "Comma separated list of default GRS sources") public String getGrsDefaultSources() { return grsDefaultSources; } @Autowired GrsImporterJmx(final GrsImporter grsImporter); } | GrsImporterJmx extends JmxBase { @ManagedAttribute(description = "Comma separated list of default GRS sources") public String getGrsDefaultSources() { return grsDefaultSources; } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } | GrsImporterJmx extends JmxBase { @ManagedAttribute(description = "Comma separated list of default GRS sources") public String getGrsDefaultSources() { return grsDefaultSources; } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } |
@Test public void to_string_with_multiple_arguments() { assertThat(new ErrorMessage(new Message(Messages.Type.INFO, "message with %s %s", "argument", "ending")).toString(), is("message with argument ending")); } | @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } |
@Test public void to_string_default_constructor() { assertThat(new ErrorMessage().toString(), is(nullValue())); } | @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public String toString() { return (args == null || args.isEmpty() || text == null) ? text : String.format(text, args.toArray()); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } |
@Test public void equals() { final ErrorMessage errorMessage1 = new ErrorMessage("Error", new Attribute("name", "value"), "text", Lists.newArrayList(new Arg("value"))); assertThat(errorMessage1.equals(null), is(false)); assertThat(errorMessage1.equals("String"), is(false)); assertThat(errorMessage1.equals(errorMessage1), is(true)); assertThat(errorMessage1.equals(new ErrorMessage("Error", new Attribute("name", "value"), "text", Lists.newArrayList(new Arg("value")))), is(true)); final ErrorMessage errorMessage2 = new ErrorMessage(new Message(Messages.Type.ERROR, "text")); assertThat(errorMessage2.equals(null), is(false)); assertThat(errorMessage2.equals("String"), is(false)); assertThat(errorMessage2.equals(errorMessage2), is(true)); assertThat(errorMessage2.equals(new ErrorMessage(new Message(Messages.Type.ERROR, "text"))), is(true)); final ErrorMessage errorMessage3 = new ErrorMessage(new Message(Messages.Type.ERROR, "text"), new RpslAttribute("key", "value")); assertThat(errorMessage3.equals(null), is(false)); assertThat(errorMessage3.equals("String"), is(false)); assertThat(errorMessage3.equals(errorMessage3), is(true)); assertThat(errorMessage3.equals(new ErrorMessage(new Message(Messages.Type.ERROR, "text"), new RpslAttribute("key", "value"))), is(true)); assertThat(errorMessage1.equals(errorMessage2), is(false)); assertThat(errorMessage1.equals(errorMessage3), is(false)); } | @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || (o.getClass() != getClass())) { return false; } final ErrorMessage errorMessage = (ErrorMessage)o; return (Objects.equals(severity, errorMessage.getSeverity()) && Objects.equals(attribute, errorMessage.getAttribute()) && Objects.equals(text, errorMessage.getText()) && Objects.equals(args, errorMessage.getArgs())); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || (o.getClass() != getClass())) { return false; } final ErrorMessage errorMessage = (ErrorMessage)o; return (Objects.equals(severity, errorMessage.getSeverity()) && Objects.equals(attribute, errorMessage.getAttribute()) && Objects.equals(text, errorMessage.getText()) && Objects.equals(args, errorMessage.getArgs())); } } | ErrorMessage implements Comparable<ErrorMessage> { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || (o.getClass() != getClass())) { return false; } final ErrorMessage errorMessage = (ErrorMessage)o; return (Objects.equals(severity, errorMessage.getSeverity()) && Objects.equals(attribute, errorMessage.getAttribute()) && Objects.equals(text, errorMessage.getText()) && Objects.equals(args, errorMessage.getArgs())); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || (o.getClass() != getClass())) { return false; } final ErrorMessage errorMessage = (ErrorMessage)o; return (Objects.equals(severity, errorMessage.getSeverity()) && Objects.equals(attribute, errorMessage.getAttribute()) && Objects.equals(text, errorMessage.getText()) && Objects.equals(args, errorMessage.getArgs())); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } | ErrorMessage implements Comparable<ErrorMessage> { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || (o.getClass() != getClass())) { return false; } final ErrorMessage errorMessage = (ErrorMessage)o; return (Objects.equals(severity, errorMessage.getSeverity()) && Objects.equals(attribute, errorMessage.getAttribute()) && Objects.equals(text, errorMessage.getText()) && Objects.equals(args, errorMessage.getArgs())); } ErrorMessage(final String severity, final Attribute attribute, final String text, final List<Arg> args); ErrorMessage(final Message message); ErrorMessage(final Message message, final RpslAttribute attribute); ErrorMessage(); @Nullable String getSeverity(); @Nullable Attribute getAttribute(); @Nullable String getText(); @Nullable List<Arg> getArgs(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override int compareTo(final ErrorMessage errorMessage); } |
@Test public void encode() { assertThat(SyncUpdateUtils.encode(""), is("")); assertThat(SyncUpdateUtils.encode("123"), is("123")); assertThat(SyncUpdateUtils.encode("{}"), is("%7B%7D")); assertThat(SyncUpdateUtils.encode("{"), is("%7B")); assertThat(SyncUpdateUtils.encode("{%7D"), is("%7B%257D")); assertThat(SyncUpdateUtils.encode("a b c"), is("a+b+c")); assertThat(SyncUpdateUtils.encode("a+b+c"), is("a%2Bb%2Bc")); } | public static String encode(final String value) { return encode(value, StandardCharsets.UTF_8); } | SyncUpdateUtils { public static String encode(final String value) { return encode(value, StandardCharsets.UTF_8); } } | SyncUpdateUtils { public static String encode(final String value) { return encode(value, StandardCharsets.UTF_8); } private SyncUpdateUtils(); } | SyncUpdateUtils { public static String encode(final String value) { return encode(value, StandardCharsets.UTF_8); } private SyncUpdateUtils(); static String encode(final String value); static String encode(final String value, final Charset charset); } | SyncUpdateUtils { public static String encode(final String value) { return encode(value, StandardCharsets.UTF_8); } private SyncUpdateUtils(); static String encode(final String value); static String encode(final String value, final Charset charset); } |
@Test public void login_success() { final String token = "xyz"; when(builder.<CrowdSession>post(any(Entity.class), any(Class.class))).then( invocation -> new CrowdSession(new CrowdUser("[email protected]", "Test User", true), token, "2033-01-30T16:38:27.369+11:00") ); assertThat(subject.login("[email protected]", "password"), is(token)); } | public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void login_not_authorized() { when(builder.<CrowdSession>post(any(Entity.class), any(Class.class))).then( invocation -> { when(response.getStatus()).thenReturn(401); when(response.getStatusInfo()).thenReturn(Response.Status.UNAUTHORIZED); when(response.readEntity(CrowdClient.CrowdError.class)).thenReturn(new CrowdClient.CrowdError("reason", "message")); throw new NotAuthorizedException(response); }); try { subject.login("[email protected]", "password"); fail(); } catch (CrowdClientException expected) { assertThat(expected.getMessage(), is("message")); } } | public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String login(final String username, final String password) throws CrowdClientException { final CrowdAuthenticationContext crowdAuth = new CrowdAuthenticationContext(username, password); try { final CrowdSession session = client.target(restUrl) .path(CROWD_SESSION_PATH) .request(MediaType.APPLICATION_XML) .post(Entity.entity(crowdAuth, MediaType.APPLICATION_XML), CrowdSession.class); return session.getToken(); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void get_user_session_bad_request() { when(builder.<CrowdSession>post(any(Entity.class), any(Class.class))).then(invocation -> {throw new BadRequestException("Not valid sso");}); try { subject.getUserSession("token"); fail(); } catch (CrowdClientException expected) { assertThat(expected.getMessage(), is("Unknown RIPE NCC Access token: token")); } } | public UserSession getUserSession(final String token) throws CrowdClientException { try { final CrowdSession crowdSession = client.target(restUrl) .path(CROWD_SESSION_PATH) .path(token) .queryParam("validate-password", "false") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .post(Entity.xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><validation-factors/>"), CrowdSession.class); final CrowdUser user = crowdSession.getUser(); return new UserSession(user.getName(), user.getDisplayName(), user.getActive(), crowdSession.getExpiryDate()); } catch (BadRequestException e) { throw new CrowdClientException("Unknown RIPE NCC Access token: " + token); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new CrowdClientException(e); } } | CrowdClient { public UserSession getUserSession(final String token) throws CrowdClientException { try { final CrowdSession crowdSession = client.target(restUrl) .path(CROWD_SESSION_PATH) .path(token) .queryParam("validate-password", "false") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .post(Entity.xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><validation-factors/>"), CrowdSession.class); final CrowdUser user = crowdSession.getUser(); return new UserSession(user.getName(), user.getDisplayName(), user.getActive(), crowdSession.getExpiryDate()); } catch (BadRequestException e) { throw new CrowdClientException("Unknown RIPE NCC Access token: " + token); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new CrowdClientException(e); } } } | CrowdClient { public UserSession getUserSession(final String token) throws CrowdClientException { try { final CrowdSession crowdSession = client.target(restUrl) .path(CROWD_SESSION_PATH) .path(token) .queryParam("validate-password", "false") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .post(Entity.xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><validation-factors/>"), CrowdSession.class); final CrowdUser user = crowdSession.getUser(); return new UserSession(user.getName(), user.getDisplayName(), user.getActive(), crowdSession.getExpiryDate()); } catch (BadRequestException e) { throw new CrowdClientException("Unknown RIPE NCC Access token: " + token); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public UserSession getUserSession(final String token) throws CrowdClientException { try { final CrowdSession crowdSession = client.target(restUrl) .path(CROWD_SESSION_PATH) .path(token) .queryParam("validate-password", "false") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .post(Entity.xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><validation-factors/>"), CrowdSession.class); final CrowdUser user = crowdSession.getUser(); return new UserSession(user.getName(), user.getDisplayName(), user.getActive(), crowdSession.getExpiryDate()); } catch (BadRequestException e) { throw new CrowdClientException("Unknown RIPE NCC Access token: " + token); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public UserSession getUserSession(final String token) throws CrowdClientException { try { final CrowdSession crowdSession = client.target(restUrl) .path(CROWD_SESSION_PATH) .path(token) .queryParam("validate-password", "false") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .post(Entity.xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><validation-factors/>"), CrowdSession.class); final CrowdUser user = crowdSession.getUser(); return new UserSession(user.getName(), user.getDisplayName(), user.getActive(), crowdSession.getExpiryDate()); } catch (BadRequestException e) { throw new CrowdClientException("Unknown RIPE NCC Access token: " + token); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void get_username_success() { when(builder.get(CrowdClient.CrowdUsers.class)) .then(invocation -> new CrowdClient.CrowdUsers( Arrays.asList(new CrowdClient.CrowdUser("[email protected]", "Test User", true))) ); assertThat(subject.getUsername("uuid"), is("[email protected]")); } | public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void get_username_not_found() { when(builder.get(CrowdClient.CrowdUsers.class)).then(invocation -> {throw new NotFoundException("message");}); try { subject.getUsername("madeup-uuid"); fail(); } catch (CrowdClientException expected) { assertThat(expected.getMessage(), is("Unknown RIPE NCC Access uuid: madeup-uuid")); } } | public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String getUsername(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void get_display_name_success() { when(builder.get(CrowdClient.CrowdUsers.class)) .then(invocation -> new CrowdClient.CrowdUsers( Arrays.asList(new CrowdClient.CrowdUser("[email protected]", "Test User", true))) ); assertThat(subject.getDisplayName("uuid"), is("Test User")); } | public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void grsImport() { final String result = subject.grsImport("ARIN-GRS,APNIC-GRS", "comment"); verify(grsImporter).grsImport("ARIN-GRS,APNIC-GRS", false); assertThat(result, is("GRS import started")); } | @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } |
@Test public void nic_hdl_is_auto1() { final RpslObject object = RpslObject.parse("person: test person\nnic-hdl: AUTO-1"); try { subject.checkForReservedNicHandle(object); fail(); } catch (ClaimException e) { assertThat(e.getErrorMessage().getText(), is("AUTO-1 in nic-hdl is not available in Bootstrap/LoadDump mode")); } } | public void checkForReservedNicHandle(final RpslObject object) throws ClaimException { if (object.getType() != ObjectType.PERSON && object.getType() != ObjectType.ROLE) { return; } final CIString pkey = object.getKey(); if (pkey.equals("AUTO-1")){ throw new ClaimException(new Message(Messages.Type.ERROR, "AUTO-1 in nic-hdl is not available in Bootstrap/LoadDump mode")); } if (!nicHandleFactory.isAvailable(object.getKey().toString())){ throw new ClaimException(UpdateMessages.nicHandleNotAvailable(object.getKey())); } } | ObjectLoader { public void checkForReservedNicHandle(final RpslObject object) throws ClaimException { if (object.getType() != ObjectType.PERSON && object.getType() != ObjectType.ROLE) { return; } final CIString pkey = object.getKey(); if (pkey.equals("AUTO-1")){ throw new ClaimException(new Message(Messages.Type.ERROR, "AUTO-1 in nic-hdl is not available in Bootstrap/LoadDump mode")); } if (!nicHandleFactory.isAvailable(object.getKey().toString())){ throw new ClaimException(UpdateMessages.nicHandleNotAvailable(object.getKey())); } } } | ObjectLoader { public void checkForReservedNicHandle(final RpslObject object) throws ClaimException { if (object.getType() != ObjectType.PERSON && object.getType() != ObjectType.ROLE) { return; } final CIString pkey = object.getKey(); if (pkey.equals("AUTO-1")){ throw new ClaimException(new Message(Messages.Type.ERROR, "AUTO-1 in nic-hdl is not available in Bootstrap/LoadDump mode")); } if (!nicHandleFactory.isAvailable(object.getKey().toString())){ throw new ClaimException(UpdateMessages.nicHandleNotAvailable(object.getKey())); } } @Autowired ObjectLoader(RpslObjectDao rpslObjectDao,
RpslObjectUpdateDao rpslObjectUpdateDao,
AttributeSanitizer attributeSanitizer,
NicHandleFactory nicHandleFactory,
OrganisationIdRepository organisationIdRepository,
X509Repository x509Repository); } | ObjectLoader { public void checkForReservedNicHandle(final RpslObject object) throws ClaimException { if (object.getType() != ObjectType.PERSON && object.getType() != ObjectType.ROLE) { return; } final CIString pkey = object.getKey(); if (pkey.equals("AUTO-1")){ throw new ClaimException(new Message(Messages.Type.ERROR, "AUTO-1 in nic-hdl is not available in Bootstrap/LoadDump mode")); } if (!nicHandleFactory.isAvailable(object.getKey().toString())){ throw new ClaimException(UpdateMessages.nicHandleNotAvailable(object.getKey())); } } @Autowired ObjectLoader(RpslObjectDao rpslObjectDao,
RpslObjectUpdateDao rpslObjectUpdateDao,
AttributeSanitizer attributeSanitizer,
NicHandleFactory nicHandleFactory,
OrganisationIdRepository organisationIdRepository,
X509Repository x509Repository); void processObject(final String fullObject,
final Result result,
final int pass,
final LoaderMode loaderMode); @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW) void addObjectRisky(RpslObject rpslObject, Result result, int pass); void checkForReservedNicHandle(final RpslObject object); void claimIds(RpslObject rpslObject); } | ObjectLoader { public void checkForReservedNicHandle(final RpslObject object) throws ClaimException { if (object.getType() != ObjectType.PERSON && object.getType() != ObjectType.ROLE) { return; } final CIString pkey = object.getKey(); if (pkey.equals("AUTO-1")){ throw new ClaimException(new Message(Messages.Type.ERROR, "AUTO-1 in nic-hdl is not available in Bootstrap/LoadDump mode")); } if (!nicHandleFactory.isAvailable(object.getKey().toString())){ throw new ClaimException(UpdateMessages.nicHandleNotAvailable(object.getKey())); } } @Autowired ObjectLoader(RpslObjectDao rpslObjectDao,
RpslObjectUpdateDao rpslObjectUpdateDao,
AttributeSanitizer attributeSanitizer,
NicHandleFactory nicHandleFactory,
OrganisationIdRepository organisationIdRepository,
X509Repository x509Repository); void processObject(final String fullObject,
final Result result,
final int pass,
final LoaderMode loaderMode); @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW) void addObjectRisky(RpslObject rpslObject, Result result, int pass); void checkForReservedNicHandle(final RpslObject object); void claimIds(RpslObject rpslObject); } |
@Test public void get_display_name_not_found() { when(builder.get(CrowdClient.CrowdUsers.class)).then(invocation -> {throw new NotFoundException("message");}); try { subject.getDisplayName("madeup-uuid"); fail(); } catch (CrowdClientException expected) { assertThat(expected.getMessage(), is("Unknown RIPE NCC Access uuid: madeup-uuid")); } } | public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String getDisplayName(final String uuid) throws CrowdClientException { try { final List<CrowdUser> users = client.target(restUrl) .path(CROWD_UUID_SEARCH_PATH) .queryParam("restriction", "uuid=" + uuid) .queryParam("entity-type", "user") .queryParam("expand", "user") .request(MediaType.APPLICATION_XML) .get(CrowdUsers.class).getUsers(); if(users == null || users.isEmpty()) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } return users.get(0).getDisplayName(); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access uuid: " + uuid); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void get_uuid_success() { when(builder.get(CrowdResponse.class)).then(invocation -> new CrowdResponse(Lists.newArrayList( new CrowdClient.CrowdAttribute(Lists.newArrayList( new CrowdClient.CrowdValue("1-2-3-4")), "uuid")))); assertThat(subject.getUuid("[email protected]"), is("1-2-3-4")); } | public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void get_uuid_not_found() { when(builder.get(CrowdResponse.class)).then(invocation -> {throw new NotFoundException("message");}); try { subject.getUuid("[email protected]"); fail(); } catch (CrowdClientException expected) { assertThat(expected.getMessage(), is("Unknown RIPE NCC Access user: [email protected]")); } } | public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void get_uuid_no_attribute() { final CrowdResponse crowdResponse = mock(CrowdResponse.class); when(crowdResponse.getUUID()).then(invocation -> {throw new NoSuchElementException();}); when(builder.get(CrowdResponse.class)).thenReturn(crowdResponse); try { subject.getUuid("[email protected]"); fail(); } catch (CrowdClientException expected) { assertThat(expected.getMessage(), is("Cannot find UUID for: [email protected]")); } } | public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } | CrowdClient { public String getUuid(final String username) throws CrowdClientException { try { return client.target(restUrl) .path(CROWD_USER_ATTRIBUTE_PATH) .queryParam("username", username) .request(MediaType.APPLICATION_XML) .get(CrowdResponse.class) .getUUID(); } catch (NoSuchElementException e) { throw new CrowdClientException("Cannot find UUID for: " + username); } catch (NotFoundException e) { throw new CrowdClientException("Unknown RIPE NCC Access user: " + username); } catch (WebApplicationException | ProcessingException e) { throw new CrowdClientException(e); } } @Autowired CrowdClient(@Value("${crowd.rest.url}") final String translatorUrl,
@Value("${crowd.rest.user}") final String crowdAuthUser,
@Value("${crowd.rest.password}") final String crowdAuthPassword); String login(final String username, final String password); void logout(final String username); void invalidateToken(final String token); String getUuid(final String username); String getUsername(final String uuid); String getDisplayName(final String uuid); UserSession getUserSession(final String token); } |
@Test public void translateSsoToken() { final String ssotoken = "ssotoken"; final String username = "username"; final String displayName = "Test User"; final String uuid = "uuid"; when(crowdClient.getUserSession(ssotoken)).thenReturn(new UserSession(username, displayName, true, "2033-01-30T16:38:27.369+11:00")); when(crowdClient.getUuid(username)).thenReturn(uuid); final UserSession userSession = subject.translateSsoToken(ssotoken); assertThat(userSession.getUsername(), is(username)); assertThat(userSession.getUuid(), is(uuid)); assertThat(userSession.isActive(), is(true)); } | public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); UserSession translateSsoToken(final String ssoToken); } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); UserSession translateSsoToken(final String ssoToken); } |
@Test(expected = CrowdClientException.class) public void translateSsoToken_invalid_session() { final String ssotoken = "ssotoken"; when(crowdClient.getUserSession(ssotoken)).thenThrow(new CrowdClientException("Unknown RIPE NCC Access token: " + ssotoken)); subject.translateSsoToken(ssotoken); } | public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); UserSession translateSsoToken(final String ssoToken); } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); UserSession translateSsoToken(final String ssoToken); } |
@Test(expected = CrowdClientException.class) public void translateSsoToken_invalid_username() { final String ssotoken = "ssotoken"; final String username = "username"; final String displayName = "Test User"; when(crowdClient.getUserSession(ssotoken)).thenReturn(new UserSession(username, displayName, true, "2033-01-30T16:38:27.369+11:00")); when(crowdClient.getUuid(username)).thenThrow(new CrowdClientException("Unknown RIPE NCC Access user: " + username)); subject.translateSsoToken(ssotoken); } | public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); UserSession translateSsoToken(final String ssoToken); } | SsoTokenTranslator { public UserSession translateSsoToken(final String ssoToken) throws CrowdClientException { final UserSession userSession = crowdClient.getUserSession(ssoToken); userSession.setUuid(crowdClient.getUuid(userSession.getUsername())); return userSession; } @Autowired SsoTokenTranslator(final CrowdClient crowdClient); UserSession translateSsoToken(final String ssoToken); } |
@Test public void translate_no_auth_attribute() { final RpslObject object = RpslObject.parse("" + "person: Test Person\n" + "nic-hdl: TP1.TEST\n" + "mnt-by: TEST-MNT\n" + "source: TEST"); final RpslObject result = SsoHelper.translateAuth( object, authTranslator); assertThat(result, is(object)); } | public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } |
@Test public void translate_no_sso_auth_attribute() { final RpslObject object = RpslObject.parse("" + "mntner: TEST-MNT\n" + "mnt-by: TEST-MNT\n" + "auth: MD5-PW aadf\n"); final RpslObject result = SsoHelper.translateAuth(object, authTranslator); assertThat(result, is(object)); } | public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } |
@Test public void translate_sso_auth_attribute() { final RpslAttribute attribute = new RpslAttribute(AttributeType.AUTH, "SSO [email protected]"); final RpslAttribute translated = new RpslAttribute(AttributeType.AUTH, "SSO bbbb-aaaa-cccc-dddd"); when(authTranslator.translate("SSO", "[email protected]", attribute)).thenReturn(translated); final RpslObject object = RpslObject.parse("" + "mntner: TEST-MNT\n" + "mnt-by: TEST-MNT\n" + "auth: SSO [email protected]\n"); final RpslObject result = SsoHelper.translateAuth(object, authTranslator); assertThat(result.toString(), is("" + "mntner: TEST-MNT\n" + "mnt-by: TEST-MNT\n" + "auth: SSO bbbb-aaaa-cccc-dddd\n")); } | public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } |
@Test public void grsImport_throws_exception() { doThrow(new RuntimeException("Oops")).when(grsImporter).grsImport(anyString(), anyBoolean()); final String result = subject.grsImport("ARIN-GRS,APNIC-GRS", "comment"); verify(grsImporter).grsImport("ARIN-GRS,APNIC-GRS", false); assertNull(result); } | @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsImport(final String sources, final String comment) { return invokeOperation("GRS import sources", comment, new Callable<String>() { @Override public String call() { grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, false); return "GRS import started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } |
@Test public void translate_many_sso_attributes() { final RpslAttribute attribute = new RpslAttribute(AttributeType.AUTH, "SSO [email protected]"); final RpslAttribute attribute2 = new RpslAttribute(AttributeType.AUTH, "SSO [email protected]"); final RpslAttribute translated1 = new RpslAttribute(AttributeType.AUTH, "SSO bbbb-aaaa-cccc-dddd"); final RpslAttribute translated2 = new RpslAttribute(AttributeType.AUTH, "SSO eeee-ffff-eeee-ffff"); when(authTranslator.translate("SSO", "[email protected]", attribute)).thenReturn(translated1); when(authTranslator.translate("SSO", "[email protected]", attribute2)).thenReturn(translated2); final RpslObject object = RpslObject.parse("" + "mntner: TEST-MNT\n" + "mnt-by: TEST-MNT\n" + "auth: SSO [email protected]\n" + "auth: SSO [email protected]\n"); final RpslObject result = SsoHelper.translateAuth(object, authTranslator); assertThat(result.toString(), is("" + "mntner: TEST-MNT\n" + "mnt-by: TEST-MNT\n" + "auth: SSO bbbb-aaaa-cccc-dddd\n" + "auth: SSO eeee-ffff-eeee-ffff\n")); } | public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } | SsoHelper { public static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator) { if (!rpslObject.containsAttribute(AttributeType.AUTH)) { return rpslObject; } final Map<RpslAttribute, RpslAttribute> replace = Maps.newHashMap(); for (RpslAttribute authAttribute : rpslObject.findAttributes(AttributeType.AUTH)) { final Iterator<String> authIterator = SPACE_SPLITTER.split(authAttribute.getCleanValue()).iterator(); final String authType = authIterator.next().toUpperCase(); if (authIterator.hasNext()) { final String authToken = authIterator.next(); final RpslAttribute result = authTranslator.translate(authType, authToken, authAttribute); if (result != null) { replace.put(authAttribute, result); } } } if (replace.isEmpty()) { return rpslObject; } else { return new RpslObjectBuilder(rpslObject).replaceAttributes(replace).get(); } } static RpslObject translateAuth(final RpslObject rpslObject, final AuthTranslator authTranslator); } |
@Test public void testTimestampParsingNoMillis() { UserSession userSession = new UserSession("username", "displayName", true, "2019-09-19T14:51:05+02:00"); assertThat(userSession.getExpiryDate().getYear(), is(2019)); assertThat(userSession.getExpiryDate().getMonth(), is(Month.SEPTEMBER)); assertThat(userSession.getExpiryDate().getDayOfMonth(), is(19)); assertThat(userSession.getExpiryDate().getHour(), is(14)); assertThat(userSession.getExpiryDate().getMinute(), is(51)); assertThat(userSession.getExpiryDate().getSecond(), is(5)); } | public LocalDateTime getExpiryDate() { return expiryDate; } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); String getDisplayName(); String getUsername(); boolean isActive(); LocalDateTime getExpiryDate(); String getUuid(); void setUuid(final String uuid); @Override String toString(); } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); String getDisplayName(); String getUsername(); boolean isActive(); LocalDateTime getExpiryDate(); String getUuid(); void setUuid(final String uuid); @Override String toString(); } |
@Test public void testTimestampParsingWithMillis() { UserSession userSession = new UserSession("username", "displayName", true, "2019-09-19T20:16:43.835+02:00"); assertThat(userSession.getExpiryDate().getYear(), is(2019)); assertThat(userSession.getExpiryDate().getMonth(), is(Month.SEPTEMBER)); assertThat(userSession.getExpiryDate().getDayOfMonth(), is(19)); assertThat(userSession.getExpiryDate().getHour(), is(20)); assertThat(userSession.getExpiryDate().getMinute(), is(16)); assertThat(userSession.getExpiryDate().getSecond(), is(43)); assertThat(userSession.getExpiryDate().get(ChronoField.MILLI_OF_SECOND), is(835)); } | public LocalDateTime getExpiryDate() { return expiryDate; } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); String getDisplayName(); String getUsername(); boolean isActive(); LocalDateTime getExpiryDate(); String getUuid(); void setUuid(final String uuid); @Override String toString(); } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); String getDisplayName(); String getUsername(); boolean isActive(); LocalDateTime getExpiryDate(); String getUuid(); void setUuid(final String uuid); @Override String toString(); } |
@Test public void testTimestampParsingNoOffset() { UserSession userSession = new UserSession("username", "displayName", true, "2019-09-19T20:16:43.835Z"); assertThat(userSession.getExpiryDate().getYear(), is(2019)); assertThat(userSession.getExpiryDate().getMonth(), is(Month.SEPTEMBER)); assertThat(userSession.getExpiryDate().getDayOfMonth(), is(19)); assertThat(userSession.getExpiryDate().getHour(), is(20)); assertThat(userSession.getExpiryDate().getMinute(), is(16)); assertThat(userSession.getExpiryDate().getSecond(), is(43)); assertThat(userSession.getExpiryDate().get(ChronoField.MILLI_OF_SECOND), is(835)); } | public LocalDateTime getExpiryDate() { return expiryDate; } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); String getDisplayName(); String getUsername(); boolean isActive(); LocalDateTime getExpiryDate(); String getUuid(); void setUuid(final String uuid); @Override String toString(); } | UserSession { public LocalDateTime getExpiryDate() { return expiryDate; } UserSession(final String username, final String displayName, final boolean isActive, final String expiryDate); String getDisplayName(); String getUsername(); boolean isActive(); LocalDateTime getExpiryDate(); String getUuid(); void setUuid(final String uuid); @Override String toString(); } |
@Test public void inetnum_without_org_reference() { final RpslObject inetnum = RpslObject.parse("inetnum: 10.0.0.0\nsource: RIPE"); assertThat(subject.getAbuseContact(inetnum).isPresent(), is(false)); } | public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } @Autowired AbuseCFinder(@Qualifier("jdbcRpslObjectSlaveDao") final RpslObjectDao objectDao,
@Value("${whois.source}") final String mainSource,
@Value("${whois.nonauth.source}") final String nonAuthSource,
@Value("${grs.sources}") final String grsSource,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers,
final AbuseValidationStatusDao abuseValidationStatusDao); } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } @Autowired AbuseCFinder(@Qualifier("jdbcRpslObjectSlaveDao") final RpslObjectDao objectDao,
@Value("${whois.source}") final String mainSource,
@Value("${whois.nonauth.source}") final String nonAuthSource,
@Value("${grs.sources}") final String grsSource,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers,
final AbuseValidationStatusDao abuseValidationStatusDao); Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject); } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } @Autowired AbuseCFinder(@Qualifier("jdbcRpslObjectSlaveDao") final RpslObjectDao objectDao,
@Value("${whois.source}") final String mainSource,
@Value("${whois.nonauth.source}") final String nonAuthSource,
@Value("${grs.sources}") final String grsSource,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers,
final AbuseValidationStatusDao abuseValidationStatusDao); Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject); } |
@Test public void getAbuseContacts_rootObject() { final RpslObject inetnum = RpslObject.parse("inetnum: 10.0.0.0\nsource: RIPE"); assertThat(subject.getAbuseContact(inetnum).isPresent(), is(false)); verifyZeroInteractions(maintainers); } | public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } @Autowired AbuseCFinder(@Qualifier("jdbcRpslObjectSlaveDao") final RpslObjectDao objectDao,
@Value("${whois.source}") final String mainSource,
@Value("${whois.nonauth.source}") final String nonAuthSource,
@Value("${grs.sources}") final String grsSource,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers,
final AbuseValidationStatusDao abuseValidationStatusDao); } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } @Autowired AbuseCFinder(@Qualifier("jdbcRpslObjectSlaveDao") final RpslObjectDao objectDao,
@Value("${whois.source}") final String mainSource,
@Value("${whois.nonauth.source}") final String nonAuthSource,
@Value("${grs.sources}") final String grsSource,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers,
final AbuseValidationStatusDao abuseValidationStatusDao); Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject); } | AbuseCFinder { public Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject) { final RpslObject role = getAbuseContactRole(rpslObject); if (role == null) { return Optional.empty(); } final boolean suspect = abuseValidationStatusDao.isSuspect(role.getValueForAttribute(AttributeType.ABUSE_MAILBOX)); return Optional.of(new AbuseContact( role, suspect, getOrgToContact(rpslObject, suspect) )); } @Autowired AbuseCFinder(@Qualifier("jdbcRpslObjectSlaveDao") final RpslObjectDao objectDao,
@Value("${whois.source}") final String mainSource,
@Value("${whois.nonauth.source}") final String nonAuthSource,
@Value("${grs.sources}") final String grsSource,
final Ipv4Tree ipv4Tree,
final Ipv6Tree ipv6Tree,
final Maintainers maintainers,
final AbuseValidationStatusDao abuseValidationStatusDao); Optional<AbuseContact> getAbuseContact(final RpslObject rpslObject); } |
@Test public void notApplicable() { final RpslObject object = RpslObject.parse("person: Someone\nnic-hdl: NIC-TEST"); final Iterator<? extends ResponseObject> iterator = subject.decorate(Query.parse("--abuse-contact AS3333"), Collections.singletonList(object)).iterator(); final ResponseObject result = iterator.next(); assertThat(result, is(object)); assertThat(iterator.hasNext(), is(false)); } | @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); @Override Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input); } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); @Override Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input); } |
@Test public void inet6num_with_abuse_contact() { final RpslObject object = RpslObject.parse("inet6num: ffc::0/64\norg: ORG-TEST"); final RpslObject abuseRole = RpslObject.parse("role: Abuse Role\n" + "nic-hdl: AA1-TEST\n" + "abuse-mailbox: [email protected]" ); when(abuseCFinder.getAbuseContact(object)).thenReturn(Optional.of(new AbuseContact(abuseRole, false, ciString("")))); when(sourceContext.isMain()).thenReturn(true); final Iterator<? extends ResponseObject> iterator = subject.decorate(Query.parse("AS3333"), Collections.singletonList(object)).iterator(); final MessageObject result = (MessageObject) iterator.next(); assertThat(result.toString(), is("% Abuse contact for 'ffc::0/64' is '[email protected]'\n")); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.next(), is(instanceOf(ResponseObject.class))); assertThat(iterator.hasNext(), is(false)); } | @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); @Override Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input); } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); @Override Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input); } |
@Test public void autnum_without_abuse_contact() { final RpslObject autnum = RpslObject.parse("aut-num: AS333\nas-name: TEST-NAME\norg: ORG-TOL1-TEST"); when(abuseCFinder.getAbuseContact(autnum)).thenReturn(Optional.empty()); when(sourceContext.isMain()).thenReturn(true); final Iterator<? extends ResponseObject> iterator = subject.decorate(Query.parse("AS3333"), Collections.singletonList(autnum)).iterator(); final MessageObject result = (MessageObject) iterator.next(); assertThat(result.toString(), is(QueryMessages.abuseCNotRegistered("AS333").getFormattedText())); } | @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); @Override Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input); } | AbuseCInfoDecorator implements ResponseDecorator { @Override public Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input) { if (query.via(Query.Origin.REST) || query.isBriefAbuseContact() || !sourceContext.isMain()) { return input; } return new IterableTransformer<ResponseObject>(input) { @Override public void apply(ResponseObject input, Deque<ResponseObject> result) { if (!(input instanceof RpslObject)) { result.add(input); return; } final RpslObject object = (RpslObject) input; if (!ABUSE_LOOKUP_OBJECT_TYPES.contains(object.getType())) { result.add(input); return; } final Optional<AbuseContact> optionalAbuseContact = abuseCFinder.getAbuseContact(object); if (optionalAbuseContact.isPresent()) { optionalAbuseContact.ifPresent(abuseContact -> { if (abuseContact.isSuspect()) { if (abuseContact.getOrgId() != null) { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox(), abuseContact.getOrgId()))); } else { result.add(new MessageObject(QueryMessages.unvalidatedAbuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } } else { result.add(new MessageObject(QueryMessages.abuseCShown(object.getKey(), abuseContact.getAbuseMailbox()))); } }); } else { result.add(new MessageObject(QueryMessages.abuseCNotRegistered(object.getKey()))); } result.add(input); } }; } @Autowired AbuseCInfoDecorator(final AbuseCFinder abuseCFinder, SourceContext sourceContext); @Override Iterable<? extends ResponseObject> decorate(Query query, Iterable<? extends ResponseObject> input); } |
@Test public void apply_resonseObject() { final ResponseObject object = new MessageObject("text"); final ResponseObject response = subject.apply(object); assertThat(response, is(object)); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void grsRebuild() { final String result = subject.grsRebuild("ARIN-GRS,APNIC-GRS", "grsrebuildnow", "comment"); verify(grsImporter).grsImport("ARIN-GRS,APNIC-GRS", true); assertThat(result, is("GRS rebuild started")); } | @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } |
@Test public void apply_inetnum() { RpslObject rpslObject = RpslObject.parse("" + "inetnum: 10.0.0.0\n" + "mnt-by: BAR\n" + "source: QUX\n" + "abuse-mailbox: [email protected]"); when(abuseCFinder.getAbuseContact(rpslObject)).thenReturn(Optional.empty()); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "inetnum: 10.0.0.0\n" + "abuse-mailbox: [email protected]\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void apply_inet6num() { RpslObject rpslObject = RpslObject.parse("" + "inet6num: ::0\n" + "mnt-by: BAR\n" + "source: QUX\n" + "abuse-mailbox: [email protected]"); when(abuseCFinder.getAbuseContact(rpslObject)).thenReturn(Optional.empty()); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "inet6num: ::0\n" + "abuse-mailbox: [email protected]\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void apply_person() { RpslObject rpslObject = RpslObject.parse("" + "person: FOO\n" + "mnt-by: BAR\n" + "nic-hdl: FOO-QUX\n" + "source: QUX\n" + "abuse-mailbox: [email protected]"); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "abuse-mailbox: [email protected]\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void apply_person_nothing_remains() { RpslObject rpslObject = RpslObject.parse("" + "person: FOO\n" + "nic-hdl: FOO-QUX\n" + "source: QUX"); final ResponseObject response = subject.apply(rpslObject); assertNull(response); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void apply_inet6num_abusec() { RpslObject rpslObject = RpslObject.parse("" + "inet6num: ::0\n" + "mnt-by: BAR\n" + "source: RIPE\n" + "abuse-mailbox: [email protected]"); final RpslObject abuseRole = RpslObject.parse("role: Abuse Role\n" + "nic-hdl: AA1-TEST\n" + "abuse-mailbox: [email protected]" ); when(abuseCFinder.getAbuseContact(rpslObject)).thenReturn(Optional.of(new AbuseContact(abuseRole, false, ciString("")))); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "inet6num: ::0\n" + "abuse-mailbox: [email protected]\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void apply_inetnum_abusec() { RpslObject rpslObject = RpslObject.parse("" + "inetnum: 10.0.0.0\n" + "mnt-by: BAR\n" + "source: RIPE\n" + "abuse-mailbox: [email protected]"); final RpslObject abuseRole = RpslObject.parse("role: Abuse Role\n" + "nic-hdl: AA1-TEST\n" + "abuse-mailbox: [email protected]" ); when(abuseCFinder.getAbuseContact(rpslObject)).thenReturn(Optional.of(new AbuseContact(abuseRole, false, ciString("")))); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "inetnum: 10.0.0.0\n" + "abuse-mailbox: [email protected]\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void apply_rootobject_abusec() { RpslObject rpslObject = RpslObject.parse("" + "inetnum: 0.0.0.0\n" + "mnt-by: BAR\n" + "source: QUX\n" + "abuse-mailbox: [email protected]"); when(abuseCFinder.getAbuseContact(rpslObject)).thenReturn(Optional.empty()); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "inetnum: 0.0.0.0\n" + "abuse-mailbox: [email protected]\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } | BriefAbuseCFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; if (Query.ABUSE_CONTACT_OBJECT_TYPES.contains(rpslObject.getType())) { final Optional<AbuseContact> abuseContact = abuseCFinder.getAbuseContact(rpslObject); if (abuseContact.isPresent()) { final List<RpslAttribute> abuseCAttributes = new ArrayList<>(2); abuseCAttributes.add(rpslObject.getTypeAttribute()); abuseCAttributes.add(new RpslAttribute(AttributeType.ABUSE_MAILBOX, abuseContact.get().getAbuseMailbox())); return new RpslAttributes(abuseCAttributes); } } final List<RpslAttribute> newAttributes = new ArrayList<>(2); for (final RpslAttribute attribute : rpslObject.getAttributes()) { if (BRIEF_ATTRIBUTES.contains(attribute.getType())) { newAttributes.add(attribute); } } if (newAttributes.isEmpty()) { return null; } return new RpslAttributes(newAttributes); } BriefAbuseCFunction(final AbuseCFinder abuseCFinder); @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void appliesToQuery_empty() { assertThat(subject.appliesToQuery(Query.parse("foo")), is(true)); } | @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void appliesToQuery_related() { assertThat(subject.appliesToQuery(Query.parse("-T inetnum 10.0.0.0")), is(true)); } | @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void appliesToQuery_not_related() { assertThat(subject.appliesToQuery(Query.parse("-r -T inetnum 10.0.0.0")), is(false)); } | @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningReferencedObjects(); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void grsRebuild_invalid_passphrase() { final String result = subject.grsRebuild("ARIN-GRS,APNIC-GRS", "??", "comment"); assertThat(result, containsString("passphrase: grsrebuildnow")); } | @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } | GrsImporterJmx extends JmxBase { @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String grsRebuild(final String sources, final String passphrase, final String comment) { return invokeOperation("GRS rebuild sources", comment, new Callable<String>() { @Override public String call() { final String validPassphrase = "grsrebuildnow"; if (!passphrase.equals(validPassphrase)) { return String.format("" + "Warning:\n\n" + "Rebuild will delete all content in the specified\n" + "sources, when unsure use the grsImport() operation,\n" + "which will update the sources using diff.\n\n" + "When you are absolutely sure, specify the\n" + "passphrase: %s", validPassphrase); } grsImporter.grsImport("all".equals(sources) ? grsDefaultSources : sources, true); return "GRS rebuild started"; } }); } @Autowired GrsImporterJmx(final GrsImporter grsImporter); @ManagedAttribute(description = "Comma separated list of default GRS sources") String getGrsDefaultSources(); @ManagedOperation(description = "Download new dumps and update GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsImport(final String sources, final String comment); @ManagedOperation(description = "Download new dumps and rebuild GRS sources") @ManagedOperationParameters({ @ManagedOperationParameter(name = "sources", description = "Comma separated list of GRS sources to import (or 'all')"), @ManagedOperationParameter(name = "passphrase", description = "The passphrase to prevent accidental invocation"), @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) String grsRebuild(final String sources, final String passphrase, final String comment); } |
@Test public void decorate() { RpslObject rpslObject = RpslObject.parse("mntner: DEV-MNT"); subject.decorate(Query.parse("DEV-MNT"), rpslObject); verify(rpslObjectDao, times(1)).relatedTo(rpslObject, Collections.<ObjectType>emptySet()); } | @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void decorate_no_personal() { RpslObject rpslObject = RpslObject.parse("mntner: DEV-MNT"); subject.decorate(Query.parse("--no-personal DEV-MNT"), rpslObject); verify(rpslObjectDao, times(1)).relatedTo(rpslObject, Sets.newEnumSet(Lists.newArrayList(ObjectType.PERSON, ObjectType.ROLE), ObjectType.class)); } | @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedToDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { final Set<ObjectType> excludeObjectTypes = query.hasOption(QueryFlag.NO_PERSONAL) ? NO_PERSONAL_EXCLUDES : Collections.<ObjectType>emptySet(); return rpslObjectDao.relatedTo(rpslObject, excludeObjectTypes); } @Autowired RelatedToDecorator(final RpslObjectDao rpslObjectDao); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void getSupportedType() { assertThat(subject.getSupportedType(), is(ObjectType.INET6NUM)); } | @Override public ObjectType getSupportedType() { return ObjectType.INET6NUM; } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INET6NUM; } } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INET6NUM; } @Autowired HierarchyLookupIpv6(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INET6NUM; } @Autowired HierarchyLookupIpv6(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv6Resource createResource(final String key); } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INET6NUM; } @Autowired HierarchyLookupIpv6(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv6Resource createResource(final String key); } |
@Test public void createResource() { final String resource = "::0"; assertThat(subject.createResource(resource), is(Ipv6Resource.parse(resource))); } | @Override public Ipv6Resource createResource(final String key) { return Ipv6Resource.parse(key); } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public Ipv6Resource createResource(final String key) { return Ipv6Resource.parse(key); } } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public Ipv6Resource createResource(final String key) { return Ipv6Resource.parse(key); } @Autowired HierarchyLookupIpv6(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public Ipv6Resource createResource(final String key) { return Ipv6Resource.parse(key); } @Autowired HierarchyLookupIpv6(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv6Resource createResource(final String key); } | HierarchyLookupIpv6 extends HierarchyLookup<Ipv6Resource, Ipv6Entry> { @Override public Ipv6Resource createResource(final String key) { return Ipv6Resource.parse(key); } @Autowired HierarchyLookupIpv6(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv6Resource createResource(final String key); } |
@Test public void getAttributeKeysInHierarchyMostSpecific_noMatch() { final RpslObject rpslObject = RpslObject.parse("inetnum: 10.0.0.0"); when(ipv4Tree.findAllLessSpecific(any(Ipv4Resource.class))).thenReturn(Collections.<Ipv4Entry>emptyList()); final Collection<RpslObjectInfo> result = subject.getReferencedIrtsInHierarchy(rpslObject); assertThat(result, hasSize(0)); } | public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } |
@Test public void getAttributeKeysInHierarchyMostSpecific_match_in_object() { final RpslObject rpslObject = RpslObject.parse("inetnum: 10.0.0.0\nmnt-irt: IRT"); final RpslObjectInfo rpslObjectInfo = new RpslObjectInfo(1, ObjectType.IRT, "IRT"); when(rpslObjectDao.findByKey(ObjectType.IRT, "IRT")).thenReturn(rpslObjectInfo); final Collection<RpslObjectInfo> result = subject.getReferencedIrtsInHierarchy(rpslObject); assertThat(result, contains(rpslObjectInfo)); verifyZeroInteractions(ipv4Tree); } | public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } |
@Test public void getAttributeKeysInHierarchyMostSpecific_match_in_hierarchy() { final Ipv4Entry ipv4Entry2 = new Ipv4Entry(Ipv4Resource.parse("193.0.0/24"), 2); final RpslObjectInfo rpslObjectInfo = new RpslObjectInfo(2, ObjectType.IRT, "IRT"); final Ipv4Entry ipv4Entry3 = new Ipv4Entry(Ipv4Resource.parse("193.0/16"), 3); when(ipv4Tree.findAllLessSpecific(Ipv4Resource.parse("193.0.0.10"))).thenReturn(Lists.newArrayList(ipv4Entry2, ipv4Entry3)); when(rpslObjectDao.getById(ipv4Entry2.getObjectId())).thenReturn(RpslObject.parse("inetnum: 193.0.0.0-193.0.0.255\nmnt-irt: IRT")); when(rpslObjectDao.findByKey(ObjectType.IRT, "IRT")).thenReturn(rpslObjectInfo); final Collection<RpslObjectInfo> result = subject.getReferencedIrtsInHierarchy(RpslObject.parse("inetnum: 193.0.0.10")); assertThat(result, contains(rpslObjectInfo)); verify(rpslObjectDao, never()).getById(ipv4Entry3.getObjectId()); } | public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } |
@Test public void getAttributeKeysInHierarchyMostSpecific_none_in_hierarchy() { final Ipv4Entry ipv4Entry2 = new Ipv4Entry(Ipv4Resource.parse("193.0.0/24"), 2); final Ipv4Entry ipv4Entry3 = new Ipv4Entry(Ipv4Resource.parse("193.0/16"), 3); when(ipv4Tree.findAllLessSpecific(Ipv4Resource.parse("193.0.0.10"))).thenReturn(Lists.newArrayList(ipv4Entry2, ipv4Entry3)); when(rpslObjectDao.getById(ipv4Entry2.getObjectId())).thenReturn(RpslObject.parse("inetnum: 193.0.0.0-193.0.0.255")); when(rpslObjectDao.getById(ipv4Entry3.getObjectId())).thenReturn(RpslObject.parse("inetnum: 193.0.0.0-193.0.255.255")); final Collection<RpslObjectInfo> result = subject.getReferencedIrtsInHierarchy(RpslObject.parse("inetnum: 193.0.0.10")); assertThat(result, hasSize(0)); } | public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } | HierarchyLookup { public Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject) { final Collection<RpslObjectInfo> irts = getReferencedIrts(rpslObject); if (!irts.isEmpty()) { return irts; } final K resource = createResource(rpslObject.getKey()); final List<V> entries = ipTree.findAllLessSpecific(resource); for (final V entry : entries) { final RpslObject object = rpslObjectDao.getById(entry.getObjectId()); final Collection<RpslObjectInfo> referencedIrts = getReferencedIrts(object); if (!referencedIrts.isEmpty()) { return referencedIrts; } } return Collections.emptyList(); } protected HierarchyLookup(final IpTree<K, V> ipTree, final RpslObjectDao rpslObjectDao); boolean supports(final RpslObject rpslObject); Collection<RpslObjectInfo> getReferencedIrtsInHierarchy(final RpslObject rpslObject); } |
@Test public void apply_resonseObject() { final ResponseObject object = new MessageObject("text"); final ResponseObject response = subject.apply(object); assertThat(response, is(object)); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void apply_inetnum() { RpslObject rpslObject = RpslObject.parse("" + "inetnum: 10.0.0.0\n" + "mnt-by: BAR\n" + "source: QUX\n" + "abuse-mailbox: [email protected]"); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "inetnum: 10.0.0.0\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void handleObjects() throws Exception { final File file = new File(getClass().getResource("/grs/ripe.test.gz").toURI()); subject.handleObjects(file, objectHandler); assertThat(objectHandler.getObjects(), hasSize(0)); assertThat(objectHandler.getLines(), hasSize(2)); assertThat(objectHandler.getLines(), contains((List<String>) Lists.newArrayList( "as-block: AS1877 - AS1901\n", "descr: RIPE NCC ASN block\n", "remarks: These AS Numbers are further assigned to network\n", "remarks: operators in the RIPE NCC service region. AS\n", "remarks: assignment policy is documented in:\n", "remarks: <http: "remarks: RIPE NCC members can request AS Numbers using the\n", "remarks: form available in the LIR Portal or at:\n", "remarks: <http: "org: ORG-NCC1-RIPE\n", "admin-c: DUMY-RIPE\n", "tech-c: DUMY-RIPE\n", "mnt-by: RIPE-DBM-MNT\n", "mnt-lower: RIPE-NCC-HM-MNT\n", "changed: [email protected] 20090529\n", "source: RIPE\n", "remarks: ****************************\n", "remarks: * THIS OBJECT IS MODIFIED\n", "remarks: * Please note that all data that is generally regarded as personal\n", "remarks: * data has been removed from this object.\n", "remarks: * To view the original object, please query the RIPE Database at:\n", "remarks: * http: "remarks: ****************************\n"), Lists.newArrayList( "as-block: AS2043 - AS2043\n", "descr: RIPE NCC ASN block\n", "remarks: These AS Numbers are further assigned to network\n", "remarks: operators in the RIPE NCC service region. AS\n", "remarks: assignment policy is documented in:\n", "remarks: <http: "remarks: RIPE NCC members can request AS Numbers using the\n", "remarks: form available in the LIR Portal or at:\n", "remarks: <http: "org: ORG-NCC1-RIPE\n", "admin-c: DUMY-RIPE\n", "tech-c: DUMY-RIPE\n", "mnt-by: RIPE-DBM-MNT\n", "mnt-lower: RIPE-NCC-HM-MNT\n", "changed: [email protected] 20090529\n", "source: RIPE\n", "remarks: ****************************\n", "remarks: * THIS OBJECT IS MODIFIED\n", "remarks: * Please note that all data that is generally regarded as personal\n", "remarks: * data has been removed from this object.\n", "remarks: * To view the original object, please query the RIPE Database at:\n", "remarks: * http: "remarks: ****************************\n") )); } | @Override void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } | RipeGrsSource extends GrsSource { @Override void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } } | RipeGrsSource extends GrsSource { @Override void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } @Autowired RipeGrsSource(
@Value("${grs.import.ripe.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.ripe.download:}") final String download); } | RipeGrsSource extends GrsSource { @Override void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } @Autowired RipeGrsSource(
@Value("${grs.import.ripe.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.ripe.download:}") final String download); } | RipeGrsSource extends GrsSource { @Override void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } @Autowired RipeGrsSource(
@Value("${grs.import.ripe.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.ripe.download:}") final String download); } |
@Test public void keys_route() { RpslObject rpslObject = RpslObject.parse("" + "route: 193.0.0.0/21\n" + "descr: RIPE-NCC\n" + "origin: AS3333\n" + "mnt-by: RIPE-NCC-MNT\n" + "source: RIPE # Filtered"); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "route: 193.0.0.0/21\n" + "origin: AS3333\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void keys_as_set() { RpslObject rpslObject = RpslObject.parse("" + "as-set: AS-TEST\n" + "descr: Description\n" + "members: AS2602, AS42909, AS51966\n" + "tech-c: PN-RIPE\n" + "admin-c: PN-RIPE\n" + "mnt-by: TEST-MNT\n" + "source: RIPE # Filtered"); final ResponseObject response = subject.apply(rpslObject); assertThat(response.toString(), is("" + "as-set: AS-TEST\n" + "members: AS2602, AS42909, AS51966\n")); } | @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } | ToKeysFunction implements Function<ResponseObject, ResponseObject> { @Override public ResponseObject apply(final @Nullable ResponseObject input) { if (!(input instanceof RpslObject)) { return input; } final RpslObject rpslObject = (RpslObject) input; final List<RpslAttribute> attributes = rpslObject.getAttributes(); final List<RpslAttribute> newAttributes = new ArrayList<>(attributes.size()); final ObjectTemplate template = ObjectTemplate.getTemplate(rpslObject.getType()); final RpslAttribute typeAttribute = rpslObject.getTypeAttribute(); final Set<AttributeType> keyAttributes = template.getKeyAttributes(); if (keyAttributes.size() == 1 && keyAttributes.contains(typeAttribute.getType()) && !template.isSet()) { newAttributes.add(typeAttribute); } else { for (final RpslAttribute attribute : attributes) { final AttributeType attributeType = attribute.getType(); if (keyAttributes.contains(attributeType) || (template.isSet() && (AttributeType.MEMBERS.equals(attributeType) || AttributeType.MP_MEMBERS.equals(attributeType)))) { newAttributes.add(attribute); } } } return new RpslAttributes(newAttributes); } @Override ResponseObject apply(final @Nullable ResponseObject input); } |
@Test public void appliesToQuery_empty() { assertThat(subject.appliesToQuery(Query.parse("foo")), is(false)); } | @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void appliesToQuery_no_irt() { assertThat(subject.appliesToQuery(Query.parse("-T inetnum 10.0.0.0")), is(false)); } | @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void appliesToQuery_capital_C() { assertThat(subject.appliesToQuery(Query.parse("-C -T inetnum 10.0.0.0")), is(false)); } | @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void appliesToQuery_irt() { assertThat(subject.appliesToQuery(Query.parse("-c -T inetnum 10.0.0.0")), is(true)); } | @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public boolean appliesToQuery(final Query query) { return query.isReturningIrt(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void decorate_not_supported() { final RpslObject rpslObject = RpslObject.parse("poem:RIPE"); final Collection<RpslObjectInfo> infos = subject.decorate(Query.parse("RIPE"), rpslObject); verify(hierarchyLookupIpv4, times(1)).supports(rpslObject); verify(hierarchyLookupIpv6, times(1)).supports(rpslObject); assertThat(infos, hasSize(0)); } | @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void decorate_inetnum() { final RpslObject rpslObject = RpslObject.parse("inetnum:0.0.0.0"); final RpslObjectInfo rpslObjectInfo = new RpslObjectInfo(0, ObjectType.IRT, "IRT"); final List<RpslObjectInfo> result = Arrays.asList(rpslObjectInfo); when(hierarchyLookupIpv4.supports(rpslObject)).thenReturn(true); when(hierarchyLookupIpv4.getReferencedIrtsInHierarchy(rpslObject)).thenReturn(result); final Collection<RpslObjectInfo> infos = subject.decorate(Query.parse("0.0.0.0"), rpslObject); verify(hierarchyLookupIpv4, times(1)).supports(rpslObject); assertThat(infos, contains(rpslObjectInfo)); } | @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void decorate_inet6num() { final RpslObject rpslObject = RpslObject.parse("inetnum: ::0"); final RpslObjectInfo rpslObjectInfo = new RpslObjectInfo(0, ObjectType.IRT, "IRT"); final List<RpslObjectInfo> result = Arrays.asList(rpslObjectInfo); when(hierarchyLookupIpv6.supports(rpslObject)).thenReturn(true); when(hierarchyLookupIpv6.getReferencedIrtsInHierarchy(rpslObject)).thenReturn(result); final Collection<RpslObjectInfo> infos = subject.decorate(Query.parse("::0"), rpslObject); verify(hierarchyLookupIpv6, times(1)).supports(rpslObject); assertThat(infos, contains(rpslObjectInfo)); } | @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } | RelatedIrtDecorator implements PrimaryObjectDecorator { @Override public Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject) { for (final HierarchyLookup hierarchyLookup : hierarchyLookups) { if (hierarchyLookup.supports(rpslObject)) { return hierarchyLookup.getReferencedIrtsInHierarchy(rpslObject); } } return Collections.emptyList(); } @Autowired RelatedIrtDecorator(final HierarchyLookupIpv4 hierarchyLookupIpv4, final HierarchyLookupIpv6 hierarchyLookupIpv6); @Override boolean appliesToQuery(final Query query); @Override Collection<RpslObjectInfo> decorate(final Query query, final RpslObject rpslObject); } |
@Test public void getSupportedType() { assertThat(subject.getSupportedType(), is(ObjectType.INETNUM)); } | @Override public ObjectType getSupportedType() { return ObjectType.INETNUM; } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INETNUM; } } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INETNUM; } @Autowired HierarchyLookupIpv4(final Ipv4Tree ipv4Tree, final RpslObjectDao rpslObjectDao); } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INETNUM; } @Autowired HierarchyLookupIpv4(final Ipv4Tree ipv4Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv4Resource createResource(final String key); } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public ObjectType getSupportedType() { return ObjectType.INETNUM; } @Autowired HierarchyLookupIpv4(final Ipv4Tree ipv4Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv4Resource createResource(final String key); } |
@Test public void handleObjects() throws Exception { final File file = new File(getClass().getResource("/grs/afrinic.test.gz").toURI()); subject.handleObjects(file, objectHandler); assertThat(objectHandler.getObjects(), hasSize(0)); assertThat(objectHandler.getLines(), hasSize(5)); assertThat(objectHandler.getLines().get(0), contains( "as-block: AS30980 - AS30980\n", "descr: AfriNIC ASN block\n", "remarks: These AS Numbers are further assigned to network\n" + " operators in the AfriNIC service region. AS\n" + " assignment policy is documented in:\n" + " <http: " AfriNIC members can request AS Numbers using the\n" + " form located at:\n" + " http: "org: ORG-AFNC1-AFRINIC\n", "admin-c: TEAM-AFRINIC\n", "tech-c: TEAM-AFRINIC\n", "mnt-by: AFRINIC-HM-MNT\n", "mnt-lower: AFRINIC-HM-MNT\n", "changed: [email protected] 20050101\n", "changed: [email protected] 20050205\n", "remarks: data has been transferred from RIPE Whois Database 20050221\n", "source: AFRINIC\n")); assertThat(objectHandler.getLines().get(1), hasItem("inetnum: 196.207.3.172 - 196.207.3.175\n")); assertThat(objectHandler.getLines().get(2), hasItem("inetnum: 196.204.208.1 - 196.204.208.255\n")); assertThat(objectHandler.getLines().get(3), hasItem("as-block: AS30720 - AS30979\n")); assertThat(objectHandler.getLines().get(4), hasItem("as-block: AS31000 - AS31743\n")); } | @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } | AfrinicGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } } | AfrinicGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } @Autowired AfrinicGrsSource(
@Value("${grs.import.afrinic.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.afrinic.download:}") final String download); } | AfrinicGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } @Autowired AfrinicGrsSource(
@Value("${grs.import.afrinic.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.afrinic.download:}") final String download); @Override void acquireDump(final Path path); @Override void handleObjects(final File file, final ObjectHandler handler); } | AfrinicGrsSource extends GrsSource { @Override public void handleObjects(final File file, final ObjectHandler handler) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); final BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8)); handleLines(reader, new LineHandler() { @Override public void handleLines(final List<String> lines) { handler.handle(lines); } }); } finally { IOUtils.closeQuietly(is); } } @Autowired AfrinicGrsSource(
@Value("${grs.import.afrinic.source:}") final String source,
final SourceContext sourceContext,
final DateTimeProvider dateTimeProvider,
final AuthoritativeResourceData authoritativeResourceData,
final Downloader downloader,
@Value("${grs.import.afrinic.download:}") final String download); @Override void acquireDump(final Path path); @Override void handleObjects(final File file, final ObjectHandler handler); } |
@Test public void createResource() { final String resource = "0.0.0.0"; assertThat(subject.createResource(resource), is(Ipv4Resource.parse(resource))); } | @Override public Ipv4Resource createResource(final String key) { return Ipv4Resource.parse(key); } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public Ipv4Resource createResource(final String key) { return Ipv4Resource.parse(key); } } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public Ipv4Resource createResource(final String key) { return Ipv4Resource.parse(key); } @Autowired HierarchyLookupIpv4(final Ipv4Tree ipv4Tree, final RpslObjectDao rpslObjectDao); } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public Ipv4Resource createResource(final String key) { return Ipv4Resource.parse(key); } @Autowired HierarchyLookupIpv4(final Ipv4Tree ipv4Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv4Resource createResource(final String key); } | HierarchyLookupIpv4 extends HierarchyLookup<Ipv4Resource, Ipv4Entry> { @Override public Ipv4Resource createResource(final String key) { return Ipv4Resource.parse(key); } @Autowired HierarchyLookupIpv4(final Ipv4Tree ipv4Tree, final RpslObjectDao rpslObjectDao); @Override ObjectType getSupportedType(); @Override Ipv4Resource createResource(final String key); } |
@Test public void validSyntax_valid_flag() { final RpslObject object = RpslObject.parse("" + "mntner: TST-MNT\n" + "descr: description\n" + "admin-c: TEST-RIPE\n" + "mnt-by: TST-MNT\n" + "upd-to: [email protected]\n" + "auth: MD5-PW $1$fU9ZMQN9$QQtm3kRqZXWAuLpeOiLN7. # update\n" + "source: TEST"); final Iterable<? extends ResponseObject> result = validSyntaxFilterFunction.apply(object); final ResponseObject responseObject = Iterables.find(result, input -> input instanceof RpslObject); assertThat(responseObject, is(not(nullValue()))); } | @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); @Override Iterable<? extends ResponseObject> apply(final ResponseObject input); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); @Override Iterable<? extends ResponseObject> apply(final ResponseObject input); } |
@Test public void invalidSyntax_valid_flag() { final RpslObject object = RpslObject.parse("" + "person: Admin Person\n" + "address: Admin Road\n" + "address: Town\n" + "address: UK\n" + "phone: [email protected]\n" + "nic-hdl: tst-ripe\n" + "mnt-by: TST-MNT\n" + "source: TEST"); final Iterable<? extends ResponseObject> result = validSyntaxFilterFunction.apply(object); assertThat(Iterables.size(result), is(1)); assertThat(Iterables.getFirst(result, null), is(new MessageObject(QueryMessages.invalidSyntax("tst-ripe")))); } | @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); @Override Iterable<? extends ResponseObject> apply(final ResponseObject input); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); @Override Iterable<? extends ResponseObject> apply(final ResponseObject input); } |
@Test public void invalidSyntax_novalid_flag() { final RpslObject object = RpslObject.parse("" + "person: Admin Person\n" + "address: Admin Road\n" + "address: Town\n" + "address: UK\n" + "phone: [email protected]\n" + "nic-hdl: tst-ripe\n" + "mnt-by: TST-MNT\n" + "source: TEST"); final Iterable<? extends ResponseObject> result = novalidSyntaxFilterFunction.apply(object); final ResponseObject responseObject = Iterables.find(result, input -> input instanceof RpslObject); assertThat(responseObject, is(not(nullValue()))); } | @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); @Override Iterable<? extends ResponseObject> apply(final ResponseObject input); } | SyntaxFilterFunction implements Function<ResponseObject, Iterable<? extends ResponseObject>> { @Override public Iterable<? extends ResponseObject> apply(final ResponseObject input) { if (input instanceof RpslObject) { final RpslObject object = (RpslObject) input; if (!validSyntax(object) && isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.invalidSyntax(object.getKey()))); } else if (validSyntax(object) && !isValidSyntaxQuery) { return Arrays.asList(new MessageObject(QueryMessages.validSyntax(object.getKey()))); } } return Collections.singletonList(input); } SyntaxFilterFunction(final boolean validSyntaxQuery); @Override Iterable<? extends ResponseObject> apply(final ResponseObject input); } |
Subsets and Splits