src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
Notification { public Set<Update> getUpdates(final Type type) { return updates.get(type); } Notification(final String email); void add(final Type type, final PreparedUpdate update, UpdateContext updateContext); String getEmail(); Set<Update> getUpdates(final Type type); boolean has(final Type type); }
@Test public void getUpdates_empty() { for (final Notification.Type type : Notification.Type.values()) { assertThat(subject.getUpdates(type), hasSize(0)); } }
Notification { public boolean has(final Type type) { return !updates.get(type).isEmpty(); } Notification(final String email); void add(final Type type, final PreparedUpdate update, UpdateContext updateContext); String getEmail(); Set<Update> getUpdates(final Type type); boolean has(final Type type); }
@Test public void has_empty() { for (final Notification.Type type : Notification.Type.values()) { assertThat(subject.has(type), is(false)); } }
UpdateResult { @Override public String toString() { final Writer writer = new StringWriter(); try { toString(writer); return writer.toString(); } catch (IOException e) { throw new IllegalStateException("Should not occur", e); } } UpdateResult(@Nullable final RpslObject originalObject, final RpslObject updatedObject, fi...
@Test public void string_representation() { final RpslObject updatedObject = RpslObject.parse("mntner: DEV-ROOT-MNT\nsource: RIPE #Filtered\ninvalid: invalid\nmnt-by: MNT2"); when(update.getType()).thenReturn(ObjectType.MNTNER); when(update.getSubmittedObject()).thenReturn(updatedObject); final ObjectMessages objectMes...
Credentials { public boolean has(final Class<? extends Credential> clazz) { return !ofType(clazz).isEmpty(); } Credentials(); Credentials(final Set<? extends Credential> credentials); Credentials add(final Collection<Credential> addedCredentials); Set<Credential> all(); T single(final Class<T> clazz); Set<T> ofType(fi...
@Test public void pgp_credentials() { final Credential credential1 = Mockito.mock(Credential.class); final Credential credential2 = Mockito.mock(Credential.class); final PgpCredential pgpCredential = Mockito.mock(PgpCredential.class); final Credentials subject = new Credentials(Sets.newHashSet(credential1, credential2,...
Update implements UpdateContainer { public boolean isSigned() { return paragraph.getCredentials().has(PgpCredential.class) || paragraph.getCredentials().has(X509Credential.class); } Update(final Paragraph paragraph, final Operation operation, @Nullable final List<String> deleteReasons, final RpslObject submittedObject)...
@Test public void is_signed_with_one_pgp_credential() { final Paragraph paragraph = new Paragraph(content, new Credentials(Sets.newHashSet(PgpCredential.createKnownCredential("PGPKEY-AAAAAAAA")))); Update subject = new Update(paragraph, Operation.UNSPECIFIED, Lists.<String>newArrayList(), rpslObject); assertThat(subjec...
Update implements UpdateContainer { public boolean isOverride() { return paragraph.getCredentials().has(OverrideCredential.class); } Update(final Paragraph paragraph, final Operation operation, @Nullable final List<String> deleteReasons, final RpslObject submittedObject); @Override Update getUpdate(); Paragraph getPara...
@Test public void is_override() { final Paragraph paragraph = new Paragraph(content, new Credentials(Sets.newHashSet(OverrideCredential.parse("username,password")))); Update subject = new Update(paragraph, Operation.UNSPECIFIED, Lists.<String>newArrayList(), rpslObject); assertThat(subject.isOverride(), is(true)); } @T...
ProxyIterable implements Iterable<R> { @Override public Iterator<R> iterator() { return new Iterator<R>() { private final Iterator<P> sourceIterator = source.iterator(); private List<R> batch = initialBatch; private int idx; @Override public boolean hasNext() { return idx < batch.size() || sourceIterator.hasNext(); } @...
@Test(expected = UnsupportedOperationException.class) public void test_remove() throws Exception { ProxyLoader<Integer, String> proxyLoader = Mockito.mock(ProxyLoader.class); subject = new ProxyIterable<>(Collections.<Integer>emptyList(), proxyLoader, 1); subject.iterator().remove(); } @Test(expected = NoSuchElementExc...
NrtmConnectionPerIpLimitHandler extends SimpleChannelUpstreamHandler { private boolean connectionsExceeded(final InetAddress remoteAddresss) { final Integer count = connectionCounter.increment(remoteAddresss); return (count != null && count > maxConnectionsPerIp); } @Autowired NrtmConnectionPerIpLimitHandler( ...
@Test public void multiple_connected_same_ip() throws Exception { final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43); when(channel.getRemoteAddress()).thenReturn(remoteAddress); final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE); subject.han...
SocketChannelFactory { public static Reader createReader(final SocketChannel socketChannel) { return new Reader(socketChannel); } private SocketChannelFactory(); static SocketChannel createSocketChannel(final String host, final int port); static Reader createReader(final SocketChannel socketChannel); static Writer cre...
@Test public void read_one_line() throws Exception { mockRead("aaa\n"); SocketChannelFactory.Reader reader = SocketChannelFactory.createReader(socketChannel); assertThat(reader.readLine(), is("aaa")); } @Test public void read_empty_line() throws Exception { mockRead("\n"); SocketChannelFactory.Reader reader = SocketCha...
SocketChannelFactory { public static Writer createWriter(final SocketChannel socketChannel) { return new Writer(socketChannel); } private SocketChannelFactory(); static SocketChannel createSocketChannel(final String host, final int port); static Reader createReader(final SocketChannel socketChannel); static Writer cre...
@Test public void write_line() throws Exception { mockWrite("aaa\n"); SocketChannelFactory.Writer writer = SocketChannelFactory.createWriter(socketChannel); writer.writeLine("aaa"); }
NrtmImporter implements EmbeddedValueResolverAware, ApplicationService { @PostConstruct void checkSources() { for (final CIString source : sources) { if (sourceContext.isVirtual(source)) { throw new IllegalArgumentException(String.format("Cannot use NRTM with virtual source: %s", source)); } JdbcRpslObjectOperations.sa...
@Test(expected = IllegalArgumentException.class) public void invalid_source() { when(sourceContext.isVirtual(CIString.ciString("1-GRS"))).thenReturn(true); subject.checkSources(); }
NrtmImporter implements EmbeddedValueResolverAware, ApplicationService { @Override public void start() { if (!enabled) { return; } final List<NrtmSource> nrtmSources = readNrtmSources(); if (nrtmSources.size() > 0) { LOGGER.info("Initializing thread pool with {} thread(s)", nrtmSources.size()); executorService = Execut...
@Test public void start() { when(valueResolver.resolveStringValue("${nrtm.import.1-GRS.source}")).thenReturn("RIPE"); when(valueResolver.resolveStringValue("${nrtm.import.1-GRS.host}")).thenReturn("localhost"); when(valueResolver.resolveStringValue("${nrtm.import.1-GRS.port}")).thenReturn("1044"); when(nrtmClientFactor...
NrtmQueryHandler extends SimpleChannelUpstreamHandler { @Override public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) { if (isKeepAlive()) { return; } final String queryString = e.getMessage().toString().trim(); nrtmLog.log(ChannelUtil.getRemoteAddress(ctx.getChannel()), queryString); LOG...
@Test public void gFlagWithVersion2Works() { when(dummifierMock.isAllowed(2, person)).thenReturn(true); when(dummifierMock.isAllowed(2, inetnum)).thenReturn(true); when(dummifierMock.dummify(2, inetnum)).thenReturn(inetnum); when(dummifierMock.dummify(2, person)).thenReturn(DummifierNrtm.getPlaceholderPersonObject()); ...
NrtmQueryHandler extends SimpleChannelUpstreamHandler { @Override public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { PendingWrites.add(ctx.getChannel()); writeMessage(ctx.getChannel(), NrtmMessages.termsAndConditions()); super.channelConnected(ctx, e); } NrtmQuer...
@Test public void channelConnected() throws Exception { subject.channelConnected(contextMock, channelStateEventMock); verify(channelMock).write(NrtmMessages.termsAndConditions() + "\n\n"); }
NrtmExceptionHandler extends SimpleChannelUpstreamHandler { @Override public void exceptionCaught(final ChannelHandlerContext ctx, final ExceptionEvent event) { final Channel channel = event.getChannel(); final Throwable exception = event.getCause(); if (!channel.isOpen()) { return; } if (exception instanceof IllegalAr...
@Test public void handle_illegal_argument_exception() { when(exceptionEventMock.getCause()).thenReturn(new IllegalArgumentException(QUERY)); subject.exceptionCaught(channelHandlerContextMock, exceptionEventMock); verify(channelMock, times(1)).write(QUERY + "\n\n"); verify(channelFutureMock, times(1)).addListener(Channe...
CollectionHelper { public static <T> T uniqueResult(final Collection<T> c) { switch (c.size()) { case 0: return null; case 1: return c.iterator().next(); default: throw new IllegalStateException("Unexpected number of elements in collection: " + c.size()); } } private CollectionHelper(); static T uniqueResult(final Col...
@Test public void uniqueResult_no_results() { final Object result = CollectionHelper.uniqueResult(Arrays.asList()); assertNull(result); } @Test public void uniqueResult_single_result() { final Integer result = CollectionHelper.uniqueResult(Arrays.asList(1)); assertThat(result, is(1)); } @Test(expected = IllegalStateExc...
GrsImporter implements DailyScheduledTask { public List<Future> grsImport(String sources, final boolean rebuild) { final Set<CIString> sourcesToImport = splitSources(sources); LOGGER.info("GRS import sources: {}", sourcesToImport); final List<Future> futures = Lists.newArrayListWithCapacity(sourcesToImport.size()); for...
@Test public void grsImport_RIPE_GRS_no_rebuild() throws Exception { await(subject.grsImport("RIPE-GRS", false)); verify(grsSourceImporter).grsImport(grsSourceRipe, false); verify(grsSourceImporter, never()).grsImport(grsSourceOther, false); } @Test public void grsImport_RIPE_GRS_rebuild() throws Exception { await(subj...
CollectionHelper { public static Iterable<ResponseObject> iterateProxy( final ProxyLoader<Identifiable, RpslObject> rpslObjectLoader, final Iterable<? extends Identifiable> identifiables) { final ProxyIterable<Identifiable, ? extends ResponseObject> rpslObjects = new ProxyIterable<>((Iterable<Identifiable>) identifiabl...
@Test public void iterateProxy_empty() { ProxyLoader<Identifiable, RpslObject> proxyLoader = Mockito.mock(ProxyLoader.class); final Iterable<ResponseObject> responseObjects = CollectionHelper.iterateProxy(proxyLoader, Collections.<Identifiable>emptyList()); verify(proxyLoader, never()).load(anyListOf(Identifiable.class...
DatabaseMaintenanceJmx extends JmxBase { @ManagedOperation(description = "Recovers a deleted object (you will need to issue an IP tree rebuild if needed)") @ManagedOperationParameters({ @ManagedOperationParameter(name = "objectId", description = "Id of the object to recover"), @ManagedOperationParameter(name = "comment...
@Test public void undeleteObject_success() { when(updateDao.undeleteObject(1)).thenReturn(new RpslObjectUpdateInfo(1, 1, ObjectType.MNTNER, "DEV-MNT")); final String response = subject.undeleteObject(1, "comment"); assertThat(response, is( "Recovered object: RpslObjectUpdateInfo{objectId=1, objectType=MNTNER, key=DEV-M...
JdbcRpslObjectOperations { public static void sanityCheck(final JdbcTemplate jdbcTemplate) { try { final String dbName = jdbcTemplate.queryForObject("SELECT database()", String.class); if (!dbName.matches("(?i).*_mirror_.+_grs.*") && !dbName.matches("(?i).*test.*")) { throw new IllegalStateException(String.format("%s h...
@Test public void sanityCheckKickingIn() { for (String dbName : ImmutableList.of("WHOIS_UPDATE_RIPE", "MAILUPDATES")) { try { when(whoisTemplate.queryForObject("SELECT database()", String.class)).thenReturn(dbName); JdbcRpslObjectOperations.sanityCheck(whoisTemplate); fail("Database name '" + dbName + "' did not trigge...
IndexStrategyAdapter implements IndexStrategy { @Override public final AttributeType getAttributeType() { return attributeType; } IndexStrategyAdapter(final AttributeType attributeType); @Override final AttributeType getAttributeType(); @Override final int addToIndex(final JdbcTemplate jdbcTemplate, final RpslObjectInf...
@Test public void getAttributeType() { assertThat(subject.getAttributeType(), is(ATTRIBUTE_TYPE)); }
IndexStrategyAdapter implements IndexStrategy { @Override public final int addToIndex(final JdbcTemplate jdbcTemplate, final RpslObjectInfo objectInfo, final RpslObject object, final CIString value) { return addToIndex(jdbcTemplate, objectInfo, object, value.toString()); } IndexStrategyAdapter(final AttributeType attri...
@Test public void addToIndex() { assertThat(subject.addToIndex(null, null, null, (String) null), is(1)); }
IndexStrategyAdapter implements IndexStrategy { @Override public final List<RpslObjectInfo> findInIndex(final JdbcTemplate jdbcTemplate, final CIString value) { return findInIndex(jdbcTemplate, value.toString()); } IndexStrategyAdapter(final AttributeType attributeType); @Override final AttributeType getAttributeType()...
@Test public void findInIndex() { assertThat(subject.findInIndex(null, (String) null), hasSize(0)); assertThat(subject.findInIndex(null, new RpslObjectInfo(1, ObjectType.AUT_NUM, "AS000")), hasSize(0)); assertThat(subject.findInIndex(null, new RpslObjectInfo(1, ObjectType.AUT_NUM, "AS000"), ObjectType.AUT_NUM), hasSize...
IndexStrategyAdapter implements IndexStrategy { @Override public void removeFromIndex(final JdbcTemplate jdbcTemplate, final RpslObjectInfo objectInfo) { } IndexStrategyAdapter(final AttributeType attributeType); @Override final AttributeType getAttributeType(); @Override final int addToIndex(final JdbcTemplate jdbcTem...
@Test public void removeFromIndex() { subject.removeFromIndex(null, null); }
IndexStrategyAdapter implements IndexStrategy { @Override public String getLookupTableName() { return null; } IndexStrategyAdapter(final AttributeType attributeType); @Override final AttributeType getAttributeType(); @Override final int addToIndex(final JdbcTemplate jdbcTemplate, final RpslObjectInfo objectInfo, final ...
@Test public void getLookupTableName() { assertNull(subject.getLookupTableName()); }
IndexStrategyAdapter implements IndexStrategy { @Override public String getLookupColumnName() { return null; } IndexStrategyAdapter(final AttributeType attributeType); @Override final AttributeType getAttributeType(); @Override final int addToIndex(final JdbcTemplate jdbcTemplate, final RpslObjectInfo objectInfo, final...
@Test public void getLookupColumnName() { assertNull(subject.getLookupColumnName()); }
IndexStrategies { public static IndexStrategy get(final AttributeType attributeType) { return INDEX_BY_ATTRIBUTE.get(attributeType); } private IndexStrategies(); static IndexStrategy get(final AttributeType attributeType); static List<IndexStrategy> getReferencing(final ObjectType objectType); }
@Test public void check_index_strategied_for_lookup_attributes() { final Set<AttributeType> attibutesWithrequiredIndex = Sets.newHashSet(); for (final ObjectType objectType : ObjectType.values()) { final ObjectTemplate objectTemplate = ObjectTemplate.getTemplate(objectType); attibutesWithrequiredIndex.addAll(objectTemp...
ObjectTypeIds { public static ObjectType getType(final int serialType) throws IllegalArgumentException { final ObjectType objectType = BY_TYPE_ID.get(serialType); if (objectType == null) { throw new IllegalArgumentException("Object type with objectTypeId " + serialType + " not found"); } return objectType; } private O...
@Test public void getBySerialType() { for (Integer objectTypeId : ImmutableList.of(0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)) { assertThat(ObjectTypeIds.getType(objectTypeId), Matchers.instanceOf(ObjectType.class)); } } @Test(expected = IllegalArgumentException.class) public void getByS...
SourceAwareDataSource extends AbstractDataSource { @Override public Connection getConnection() throws SQLException { return getActualDataSource().getConnection(); } @Autowired SourceAwareDataSource(final BasicSourceContext sourceContext); @Override Connection getConnection(); @Override Connection getConnection(final S...
@Test public void test_getConnection() throws Exception { subject.getConnection(); verify(dataSource, times(1)).getConnection(); } @Test public void test_getConnection_with_user() throws Exception { subject.getConnection("username", "password"); verify(dataSource, times(1)).getConnection("username", "password"); }
DatabaseVersionCheck { public static int compareVersions(final String v1, final String v2) { Iterator<String> i1 = VERSION_SPLITTER.split(v1).iterator(); Iterator<String> i2 = VERSION_SPLITTER.split(v2).iterator(); while (i1.hasNext() && i2.hasNext()) { int res = Integer.parseInt(i1.next()) - Integer.parseInt(i2.next()...
@Test public void testVersionNumberCheck() { assertThat(DatabaseVersionCheck.compareVersions("1.0", "2.0"), lessThan(0)); assertThat(DatabaseVersionCheck.compareVersions("1.1", "2.0"), lessThan(0)); assertThat(DatabaseVersionCheck.compareVersions("1.01", "2.0"), lessThan(0)); assertThat(DatabaseVersionCheck.compareVers...
DatabaseVersionCheck { public void checkDatabase(Iterable<String> resources, String dataSourceName, String dbVersion) { final Matcher dbVersionMatcher = RESOURCE_MATCHER.matcher(dbVersion); if (!dbVersionMatcher.matches()) { throw new IllegalStateException("Invalid version: " + dbVersion); } for (String resource : reso...
@Test public void testCheckDatabaseOK() { DatabaseVersionCheck subject = new DatabaseVersionCheck(null); subject.checkDatabase(ImmutableList.of("whois-1.51", "whois-1.4", "whois-2.15.4"), "TEST", "whois-2.16"); } @Test(expected = IllegalStateException.class) public void testCheckDatabaseFail() { DatabaseVersionCheck su...
DateUtil { public static LocalDateTime fromDate(final Date date) { return Instant.ofEpochMilli(date.getTime()) .atZone(ZoneOffset.systemDefault()) .toLocalDateTime(); } private DateUtil(); static Date toDate(final LocalDateTime localDateTime); static Date toDate(final LocalDate localDate); static LocalDateTime fromDat...
@Test public void fromDate() { assertThat(DateUtil.fromDate(new Date(EPOCH_TIMESTAMP)), is(EPOCH_LOCAL_DATE_TIME)); assertThat(DateUtil.fromDate(new Date(RECENT_TIMESTAMP)), is(RECENT_LOCAL_DATE_TIME)); }
DateUtil { public static Date toDate(final LocalDateTime localDateTime) { return Date.from(localDateTime.atZone(ZoneOffset.systemDefault()) .toInstant()); } private DateUtil(); static Date toDate(final LocalDateTime localDateTime); static Date toDate(final LocalDate localDate); static LocalDateTime fromDate(final Date...
@Test public void toDate() { assertThat(DateUtil.toDate(EPOCH_LOCAL_DATE_TIME), is(new Date(EPOCH_TIMESTAMP))); assertThat(DateUtil.toDate(RECENT_LOCAL_DATE_TIME), is(new Date(RECENT_TIMESTAMP))); }
BlockEvent { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final BlockEvent that = (BlockEvent) o; return Objects.equals(time, that.time) && Objects.equals(type, that.type); } BlockEvent(final LocalDateTime time, final int limit, final...
@Test public void equals() { final BlockEvent subject = new BlockEvent(LocalDateTime.of(2012, 2, 16, 12, 0), 1, BlockEvent.Type.BLOCK_TEMPORARY); final BlockEvent clone = new BlockEvent(LocalDateTime.of(2012, 2, 16, 12, 0), 1, BlockEvent.Type.BLOCK_TEMPORARY); final BlockEvent newDate = new BlockEvent(LocalDateTime.of(...
BlockEvents { public int getTemporaryBlockCount() { int numberOfBlocks = 0; for (final BlockEvent blockEvent : blockEvents) { switch (blockEvent.getType()) { case BLOCK_TEMPORARY: numberOfBlocks++; break; case UNBLOCK: case BLOCK_PERMANENTLY: return numberOfBlocks; default: throw new IllegalStateException("Unexpected b...
@Test(expected = NullPointerException.class) public void test_events_null() { final BlockEvents blockEvents = new BlockEvents(prefix, null); blockEvents.getTemporaryBlockCount(); } @Test public void test_number_of_blocks() { final BlockEvents blockEvents = createBlockEvents("10.0.0.0", 3); assertThat(blockEvents.getTem...
BlockEvents { public boolean isPermanentBlockRequired() { return getTemporaryBlockCount() >= NR_TEMP_BLOCKS_BEFORE_PERMANENT; } BlockEvents(final String prefix, final List<BlockEvent> blockEvents); String getPrefix(); int getTemporaryBlockCount(); boolean isPermanentBlockRequired(); static final int NR_TEMP_BLOCKS_BEFO...
@Test public void test_permanent_block_limit_reached_9() { final BlockEvents blockEvents = createBlockEvents(prefix, 9); assertThat(blockEvents.isPermanentBlockRequired(), is(false)); } @Test public void test_permanent_block_limit_reached_10() { final BlockEvents blockEvents = createBlockEvents(prefix, 10); assertThat(...
ConcurrentState { public void set(final Boolean value) { updates.add(value); } void set(final Boolean value); void waitUntil(final Boolean value); }
@Test public void set_and_unset_state() { Counter counter = new Counter(); new Thread(counter).start(); subject.set(true); waitForExpectedValue(counter, 1); subject.set(false); subject.set(false); subject.set(false); waitForExpectedValue(counter, 2); subject.set(true); waitForExpectedValue(counter, 3); } @Test public v...
IpResourceTree { public V getValue(IpInterval<?> ipInterval) { List<V> list = getTree(ipInterval).findExactOrFirstLessSpecific(ipInterval); return CollectionHelper.uniqueResult(list); } @SuppressWarnings({"unchecked", "rawtypes"}) IpResourceTree(); void add(IpInterval<?> ipInterval, V value); V getValue(IpInterval<?> ...
@Test public void test_getValue_ipv4_exact() { assertThat(subject.getValue(ipv4Resource), is(41)); } @Test public void test_getValue_ipv4_lessSpecific() { assertThat(subject.getValue(ipv4ResourceMoreSpecific), is(41)); } @Test public void test_getValue_ipv4_unknown() { assertThat(subject.getValue(ipv4ResourceUnknown), ...
ApnicGrsSource 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_...
@Test public void handleObjects() throws Exception { final File file = new File(getClass().getResource("/grs/apnic.test.gz").toURI()); subject.handleObjects(file, objectHandler); assertThat(objectHandler.getObjects(), hasSize(0)); assertThat(objectHandler.getLines(), hasSize(2)); assertThat(objectHandler.getLines(), co...
AutomaticPermanentBlocks implements DailyScheduledTask { @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocks") public void run() { final LocalDate now = dateTimeProvider.getCurrentDate(); final LocalDate checkTemporaryBlockTime = now.minusDays(30); final List<BlockEvents> temporar...
@Test public void test_date() throws Exception { subject.run(); verify(accessControlListDao, times(1)).getTemporaryBlocks(now.minusDays(30)); } @Test public void test_run_no_temporary_blocks() throws Exception { when(accessControlListDao.getTemporaryBlocks(now)).thenReturn(Collections.<BlockEvents>emptyList()); subject...
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public void put(K key, V value) { synchronized (mutex) { wrapped.put(key, value); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final Object mutex); static Interval...
@Test public void put() { subject.put(key, value); verify(wrapped, times(1)).put(key, value); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public void remove(K key) { synchronized (mutex) { wrapped.remove(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final Object mutex); static IntervalMap<K, V> ...
@Test public void remove() { subject.remove(key); verify(wrapped, times(1)).remove(key); } @Test public void remove_with_value() { subject.remove(key, value); verify(wrapped, times(1)).remove(key, value); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findFirstLessSpecific(K key) { synchronized (mutex) { return wrapped.findFirstLessSpecific(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final ...
@Test public void findFirstLessSpecific() { subject.findFirstLessSpecific(key); verify(wrapped, times(1)).findFirstLessSpecific(key); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findAllLessSpecific(K key) { synchronized (mutex) { return wrapped.findAllLessSpecific(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final Obje...
@Test public void findAllLessSpecific() { subject.findAllLessSpecific(key); verify(wrapped, times(1)).findAllLessSpecific(key); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactAndAllLessSpecific(K key) { synchronized (mutex) { return wrapped.findExactAndAllLessSpecific(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wra...
@Test public void findExactAndAllLessSpecific() { subject.findExactAndAllLessSpecific(key); verify(wrapped, times(1)).findExactAndAllLessSpecific(key); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExact(K key) { synchronized (mutex) { return wrapped.findExact(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final Object mutex); static In...
@Test public void findExact() { subject.findExact(key); verify(wrapped, times(1)).findExact(key); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactOrFirstLessSpecific(K key) { synchronized (mutex) { return wrapped.findExactOrFirstLessSpecific(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> w...
@Test public void findExactOrFirstLessSpecific() { subject.findExactOrFirstLessSpecific(key); verify(wrapped, times(1)).findExactOrFirstLessSpecific(key); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findFirstMoreSpecific(K key) { synchronized (mutex) { return wrapped.findFirstMoreSpecific(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final ...
@Test public void findFirstMoreSpecific() { subject.findFirstMoreSpecific(key); verify(wrapped, times(1)).findFirstMoreSpecific(key); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findAllMoreSpecific(K key) { synchronized (mutex) { return wrapped.findAllMoreSpecific(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final Obje...
@Test public void findAllMoreSpecific() { subject.findAllMoreSpecific(key); verify(wrapped, times(1)).findAllMoreSpecific(key); }
LacnicGrsSource 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(is, StandardCharsets.UTF_8)); handleLines(rea...
@Test public void handleObjects() throws Exception { final File file = new File(getClass().getResource("/grs/lacnic.test").toURI()); subject.handleObjects(file, objectHandler); assertThat(objectHandler.getLines(), hasSize(0)); assertThat(objectHandler.getObjects(), hasSize(3)); assertThat(objectHandler.getObjects(), co...
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactAndAllMoreSpecific(K key) { synchronized (mutex) { return wrapped.findExactAndAllMoreSpecific(key); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wra...
@Test public void findExactAndAllMoreSpecific() { subject.findExactAndAllMoreSpecific(key); verify(wrapped, times(1)).findExactAndAllMoreSpecific(key); }
SynchronizedIntervalMap implements IntervalMap<K, V> { @Override public void clear() { synchronized (mutex) { wrapped.clear(); } } private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped); private SynchronizedIntervalMap(final IntervalMap<K, V> wrapped, final Object mutex); static IntervalMap<K, V> synchroniz...
@Test public void clear() { subject.clear(); verify(wrapped, times(1)).clear(); }
InternalNode { void addChild(InternalNode<K, V> nodeToAdd) { if (interval.equals(nodeToAdd.getInterval())) { this.value = nodeToAdd.getValue(); } else if (!interval.contains(nodeToAdd.getInterval())) { throw new IllegalArgumentException(nodeToAdd.getInterval() + " not properly contained in " + interval); } else { if (c...
@Test(expected = IllegalArgumentException.class) public void test_intersect_insert_fails() { c.addChild(e); }
NestedIntervalMap implements IntervalMap<K, V> { @Override public void clear() { children.clear(); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override List<V> findFirstLessSpecific(K...
@Test public void clear() { subject.put(N1_12, N1_1); subject.clear(); assertThat(subject.findExact(N1_12), not(contains(N1_12))); assertThat(subject.findExact(N1_12), not(contains(N1_1))); }
NestedIntervalMap implements IntervalMap<K, V> { @Override public void put(K key, V value) { Validate.notNull(key); Validate.notNull(value); children.addChild(new InternalNode<>(key, value)); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override void re...
@Test public void fail_on_intersecting_siblings() { try { subject.put(new Ipv4Resource(8, 13), N1_1); fail("Exception expected"); } catch (IntersectingIntervalException expected) { assertEquals(new Ipv4Resource(8, 13), expected.getInterval()); assertEquals(asList(N1_12), expected.getIntersections()); } }
NestedIntervalMap implements IntervalMap<K, V> { @Override public void remove(K key) { Validate.notNull(key); children.removeChild(key); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Ov...
@Test public void test_remove_key_value_nonexistant() { NestedIntervalMap<Ipv4Resource, Ipv4Resource> copy = new NestedIntervalMap<>(subject); final Ipv4Resource resource = new Ipv4Resource(0, 100); subject.remove(resource, resource); assertEquals(copy, subject); } @Test public void test_remove_nonexistant() { NestedIn...
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findAllLessSpecific(K key) { Validate.notNull(key); return mapToValues(internalFindAllLessSpecific(key)); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override void remove(K key);...
@Test public void test_find_all_less_specific() { assertEquals(Collections.emptyList(), subject.findAllLessSpecific(new Ipv4Resource(0, 100))); assertEquals(Collections.emptyList(), subject.findAllLessSpecific(new Ipv4Resource(5, 13))); assertEquals(Collections.emptyList(), subject.findAllLessSpecific(N1_12)); assertEq...
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactAndAllLessSpecific(K key) { Validate.notNull(key); return mapToValues(internalFindExactAndAllLessSpecific(key)); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override voi...
@Test public void test_find_exact_and_all_less_specific() { assertEquals(Collections.emptyList(), subject.findExactAndAllLessSpecific(new Ipv4Resource(0, 100))); assertEquals(Collections.emptyList(), subject.findExactAndAllLessSpecific(new Ipv4Resource(5, 13))); assertEquals(asList(N1_12), subject.findExactAndAllLessSp...
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactOrFirstLessSpecific(K key) { Validate.notNull(key); return mapToValues(internalFindExactOrFirstLessSpecific(key)); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override v...
@Test public void test_find_exact_or_first_less_specific() { assertThat(subject.findExactOrFirstLessSpecific(new Ipv4Resource(0, 100)), hasSize(0)); assertThat(subject.findExactOrFirstLessSpecific(new Ipv4Resource(5, 13)), hasSize(0)); assertThat(subject.findExactOrFirstLessSpecific(N1_12), contains(N1_12)); assertThat...
GrsSourceImporter { void grsImport(final GrsSource grsSource, final boolean rebuild) { final AuthoritativeResource authoritativeResource = grsSource.getAuthoritativeResource(); if (sourceContext.isVirtual(grsSource.getName())) { grsSource.getLogger().info("Not updating GRS data"); } else { acquireAndUpdateGrsData(grsSo...
@Test public void run_rebuild() { when(grsSource.getName()).thenReturn(ciString("APNIC-GRS")); subject.grsImport(grsSource, true); verify(grsDao).cleanDatabase(); verify(grsDao, never()).getCurrentObjectIds(); } @Test public void run_rebuild_ripe() { when(grsSource.getName()).thenReturn(ciString("RIPE-GRS")); when(sour...
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findFirstLessSpecific(K key) { Validate.notNull(key); InternalNode<K, V> node = internalFindFirstLessSpecific(key); return mapToValues(node); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V v...
@Test public void testFindFirstLessSpecific() { assertThat(subject.findFirstLessSpecific(N1_12), hasSize(0)); assertThat(subject.findFirstLessSpecific(N6_6), contains(N5_8)); assertThat(subject.findFirstLessSpecific(N8_8), contains(N5_8)); assertThat(subject.findFirstLessSpecific(N2_2), contains(N1_4)); assertThat(subj...
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findFirstMoreSpecific(K key) { Validate.notNull(key); return mapToValues(internalFindFirstMoreSpecific(key)); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override void remove(K k...
@Test public void testFindFirstMoreSpecific() { assertEquals(asList(N5_8, N9_10), subject.findFirstMoreSpecific(N5_10)); assertEquals(asList(N1_1, N2_2, N3_4), subject.findFirstMoreSpecific(N1_4)); assertEquals(asList(N7_7, N9_9), subject.findFirstMoreSpecific(new Ipv4Resource(7, 9))); assertEquals(asList(N9_9), subjec...
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExact(K key) { Validate.notNull(key); InternalNode<K, V> node = internalFindExact(key); return mapToValues(node); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override void re...
@Test public void testFindExact() { for (Ipv4Resource n : all) { assertThat(subject.findExact(n), contains(n)); } }
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findAllMoreSpecific(K key) { Validate.notNull(key); return mapToValues(internalFindAllMoreSpecific(key)); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override void remove(K key);...
@Test public void testFindAllMoreSpecific() { assertEquals(all.subList(1, all.size()), subject.findAllMoreSpecific(N1_12)); assertEquals(asList(N3_4, N3_3, N4_4, N5_5, N6_6, N7_7), subject.findAllMoreSpecific(new Ipv4Resource(3, 7))); assertEquals(asList(N9_9), subject.findAllMoreSpecific(new Ipv4Resource(8, 9))); }
NestedIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactAndAllMoreSpecific(K key) { Validate.notNull(key); return mapToValues(internalFindExactAndAllMoreSpecific(key)); } NestedIntervalMap(); NestedIntervalMap(NestedIntervalMap<K, V> source); @Override void put(K key, V value); @Override voi...
@Test public void testFindExactAndAllMoreSpecific() { assertEquals(all, subject.findExactAndAllMoreSpecific(N1_12)); assertEquals(asList(N1_4, N1_1, N2_2, N3_4, N3_3, N4_4), subject.findExactAndAllMoreSpecific(N1_4)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExact(K key) { return unroll(wrapped.findExact(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void clear(); @Override List<V> findFirstL...
@Test public void findExact_k11() { final List<String> result = subject.findExact(k_11); assertThat(result, contains(v_11)); } @Test public void findExact_k13() { final List<String> result = subject.findExact(k_13); assertThat(result, contains(v_131, v_132, v_133)); } @Test public void findExact() { final List<String> ...
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public void remove(K key) { wrapped.remove(key); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void clear(); @Override List<V> findFirstLessSpecific(K key); @Ove...
@Test public void remove() { subject.remove(k_11); final List<String> result = subject.findExact(k_11); assertThat(result, hasSize(0)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public void clear() { wrapped.clear(); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void clear(); @Override List<V> findFirstLessSpecific(K key); @Override List...
@Test public void clear() { subject.clear(); final List<String> result = subject.findAllMoreSpecific(Ipv4Resource.MAX_RANGE); assertThat(result, hasSize(0)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findFirstLessSpecific(K key) { return unroll(wrapped.findFirstLessSpecific(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void clear(); @Ove...
@Test public void findFirstLessSpecific() { final List<String> result = subject.findFirstLessSpecific(k_11); assertThat(result, contains(v_121, v_122)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactOrFirstLessSpecific(K key) { return unroll(wrapped.findExactOrFirstLessSpecific(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void...
@Test public void findExactOrFirstLessSpecific() { final List<String> result = subject.findExactOrFirstLessSpecific(k_12); assertThat(result, contains(v_121, v_122)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findAllLessSpecific(K key) { return unroll(wrapped.findAllLessSpecific(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void clear(); @Overrid...
@Test public void findAllLessSpecific() { final List<String> result = subject.findAllLessSpecific(k_11); assertThat(result, contains(v_131, v_132, v_133, v_121, v_122)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactAndAllLessSpecific(K key) { return unroll(wrapped.findExactAndAllLessSpecific(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void c...
@Test public void findExactAndAllLessSpecific() { final List<String> result = subject.findExactAndAllLessSpecific(k_12); assertThat(result, contains(v_131, v_132, v_133, v_121, v_122)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findFirstMoreSpecific(K key) { return unroll(wrapped.findFirstMoreSpecific(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void clear(); @Ove...
@Test public void findFirstMoreSpecific() { final List<String> result = subject.findFirstMoreSpecific(k_12); assertThat(result, contains(v_11)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findAllMoreSpecific(K key) { return unroll(wrapped.findAllMoreSpecific(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void clear(); @Overrid...
@Test public void findAllMoreSpecific() { final List<String> result = subject.findAllMoreSpecific(Ipv4Resource.MAX_RANGE); assertThat(result, contains(v_131, v_132, v_133, v_121, v_122, v_11)); }
MultiValueIntervalMap implements IntervalMap<K, V> { @Override public List<V> findExactAndAllMoreSpecific(K key) { return unroll(wrapped.findExactAndAllMoreSpecific(key)); } MultiValueIntervalMap(); @Override void put(K key, V value); @Override void remove(K key); @Override void remove(K key, V value); @Override void c...
@Test public void findExactAndAllMoreSpecific() { final List<String> result = subject.findExactAndAllMoreSpecific(k_12); assertThat(result, contains(v_121, v_122, v_11)); }
AuthoritativeResourceJsonLoader extends AbstractAuthoritativeResourceLoader { public AuthoritativeResource load(final JsonNode root) { handleAllocations(root.get("asnResources"), "asn"); handleFreeResources(root.get("asnResources"), "asn"); handleReservedResources(root.get("asnResources"), "asn"); handleAssignments(roo...
@Test public void load() throws IOException { final AuthoritativeResource authoritativeResource = new AuthoritativeResourceJsonLoader(logger).load( new ObjectMapper().readValue(IOUtils.toString(getClass().getResourceAsStream("/grs/rirstats.json")), JsonNode.class) ); assertTrue(authoritativeResource.isMaintainedInRirSp...
AuthoritativeResourceDataValidator { void checkOverlaps(final Writer writer) throws IOException { for (int i1 = 0; i1 < sources.size(); i1++) { for (int i2 = i1 + 1; i2 < sources.size(); i2++) { final CIString source1 = sources.get(i1); final CIString source2 = sources.get(i2); checkOverlaps(writer, source1, authoritat...
@Test public void checkOverlaps() throws IOException { final StringWriter writer = new StringWriter(); subject.checkOverlaps(writer); final String output = writer.getBuffer().toString(); LOGGER.debug("overlaps:\n{}", output); final List<String> overlaps = Splitter.on("\n").splitToList(output); assertThat(overlaps, hasS...
AuthoritativeResourceData { public AuthoritativeResource getAuthoritativeResource(final CIString source) { final String sourceName = StringUtils.removeEnd(source.toLowerCase(), "-grs"); final AuthoritativeResource authoritativeResource = authoritativeResourceCache.get(sourceName); if (authoritativeResource == null) { t...
@Test(expected = IllegalSourceException.class) public void nonexistant_source_throws_exception() { authoritativeResourceData.getAuthoritativeResource(ciString("BLAH")); }
AuthoritativeResource { public static AuthoritativeResource loadFromFile(final Logger logger, final String name, final Path path) { try (final Scanner scanner = new Scanner(path)) { return loadFromScanner(logger, name, scanner); } catch (IOException e) { throw new IllegalArgumentException(e); } } AuthoritativeResource(...
@Test(expected = IllegalArgumentException.class) public void unknown_file() throws IOException { AuthoritativeResource.loadFromFile(logger, "unknown", folder.getRoot().toPath().resolve("unknown")); }
AuthoritativeResource { public static AuthoritativeResource loadFromScanner(final Logger logger, final String name, final Scanner scanner) { return new AuthoritativeResourceLoader(logger, name, scanner).load(); } AuthoritativeResource(final SortedRangeSet<Asn, AsnRange> autNums, final SortedRangeSet<Ipv4, Ipv4Range> in...
@Test public void test_frankenranges_using_maintained_in_rir_space_in_order() { final AuthoritativeResource resourceData = AuthoritativeResource.loadFromScanner(logger, "RIPE-GRS", new Scanner( first + second + third)); testFranken(resourceData); } @Test public void test_frankenranges_using_maintained_in_rir_space_reve...
AuthoritativeResourceDataJmx extends JmxBase { @ManagedOperation(description = "Refresh authoritative resource cache") @ManagedOperationParameters({ @ManagedOperationParameter(name = "comment", description = "Optional comment for invoking the operation") }) public String refreshCache(final String comment) { return invo...
@Test public void refreshCache() { final String msg = subject.refreshCache("comment"); assertThat(msg, is("Refreshed caches")); verify(authoritativeResourceRefreshTask).refreshGrsAuthoritativeResourceCaches(); }
AuthoritativeResourceDataJmx extends JmxBase { @ManagedOperation(description = "Check overlaps in authoritative resource definitions and output to file") @ManagedOperationParameters({ @ManagedOperationParameter(name = "outputFile", description = "The file to write overlaps to"), @ManagedOperationParameter(name = "comme...
@Test public void checkOverlaps_existing_file() throws IOException { final File file = File.createTempFile("overlaps", "test"); final String msg = subject.checkOverlaps(file.getAbsolutePath(), ""); assertThat(msg, startsWith("Abort, file already exists")); verifyZeroInteractions(authoritativeResourceDataValidator); } @...
AuthoritativeResourceImportTask extends AbstractAutoritativeResourceImportTask implements DailyScheduledTask, EmbeddedValueResolverAware { @Override @Scheduled(cron = "0 15 0 * * *") @SchedulerLock(name = TASK_NAME) public void run() { doImport(sourceNames); } @Autowired AuthoritativeResourceImportTask(@Value("${grs.s...
@Test public void init_url_not_defined() throws IOException { subject.run(); verify(resourceDataDao).store(eq("test"), resourceCaptor.capture()); assertThat(resourceCaptor.getValue().getNrAutNums(), is(0)); assertThat(resourceCaptor.getValue().getNrInet6nums(), is(0)); assertThat(resourceCaptor.getValue().getNrInetnums...
RpslObjectFilter { public static String getCertificateFromKeyCert(final RpslObject object) { if (!ObjectType.KEY_CERT.equals(object.getType())) { throw new AuthenticationException("No key cert for object: " + object.getKey()); } final StringBuilder builder = new StringBuilder(); for (RpslAttribute next : object.findAtt...
@Test(expected = AuthenticationException.class) public void getCertificateFromKeyCert() { RpslObjectFilter.getCertificateFromKeyCert(mntner); } @Test public void getCertificateOnlyOneCertifAttribute() { RpslObject keycert = RpslObject.parse( "key-cert: X509-1\n" + "certif: -----BEGIN CERTIFICATE-----\n" + " MIIHaTCCBlG...
RpslObjectFilter { public static boolean isFiltered(final RpslObject rpslObject) { final List<RpslAttribute> attributes = rpslObject.findAttributes(AttributeType.SOURCE); return !attributes.isEmpty() && attributes.get(0).getValue().contains(FILTERED); } private RpslObjectFilter(); static String getCertificateFromKeyCe...
@Test public void isFiltered() { final boolean filtered = RpslObjectFilter.isFiltered(mntner); assertThat(filtered, is(false)); }
RpslObjectFilter { public static String diff(final RpslObject original, final RpslObject revised) { final StringBuilder builder = new StringBuilder(); final List<String> originalLines = Lists.newArrayList(LINE_SPLITTER.split(original.toString())); final List<String> revisedLines = Lists.newArrayList(LINE_SPLITTER.split...
@Test public void diff_idential() { final RpslObject original = RpslObject.parse( "mntner: UPD-MNT\n" + "description: descr\n" + "mnt-by: UPD-MNT\n" + "source: TEST\n"); assertThat(RpslObjectFilter.diff(original, original), is("")); } @Test public void diff_delete_lines() throws Exception { final RpslObject original = ...
AsBlockRange { public static AsBlockRange parse(final String range) { final Matcher match = AS_BLOCK_PATTERN.matcher(range); if (match.find()) { long begin = Long.valueOf(match.group(1)); long end = Long.valueOf(match.group(2)); if (end < begin) { throw new AttributeParseException(end + " < " + begin, range); } return ...
@Test public void validAsBlockRanges() { checkAsBlockRange(AsBlockRange.parse("AS1-AS2"), 1, 2); checkAsBlockRange(AsBlockRange.parse("as1-as2"), 1, 2); checkAsBlockRange(AsBlockRange.parse("AS1 -AS2"), 1, 2); checkAsBlockRange(AsBlockRange.parse("AS1 - AS2"), 1, 2); checkAsBlockRange(AsBlockRange.parse("AS1 - AS429496...
Changed { public static Changed parse(final CIString value) { return parse(value.toString()); } Changed(final CIString email, final LocalDate date); Changed(final String email, final LocalDate date); String getEmail(); @CheckForNull LocalDate getDate(); @CheckForNull String getDateString(); @Override String toString()...
@Test(expected = AttributeParseException.class) public void empty() { Changed.parse(""); } @Test(expected = AttributeParseException.class) public void no_email() { Changed.parse("20010101"); } @Test(expected = AttributeParseException.class) public void invalid_date() { Changed.parse("a@a.a 13131313"); } @Test(expected ...
AddressPrefixRange { public static AddressPrefixRange parse(final CIString value) { return parse(value.toString()); } private AddressPrefixRange(final String value, final IpInterval ipInterval, final RangeOperation rangeOperation); IpInterval getIpInterval(); RangeOperation getRangeOperation(); @Override String toStri...
@Test(expected = AttributeParseException.class) public void empty() { AddressPrefixRange.parse(""); } @Test(expected = AttributeParseException.class) public void invalid_address() { AddressPrefixRange.parse("300.104.182.0/12"); } @Test(expected = AttributeParseException.class) public void range_too_long() { AddressPref...
NServer { public static NServer parse(final CIString value) { return parse(value.toString()); } private NServer(final CIString hostname, final IpInterval ipInterval); CIString getHostname(); @CheckForNull IpInterval getIpInterval(); @Override String toString(); static NServer parse(final CIString value); static NServe...
@Test(expected = AttributeParseException.class) public void empty() { NServer.parse(""); } @Test(expected = AttributeParseException.class) public void hostname_invalid() { NServer.parse("$"); } @Test(expected = AttributeParseException.class) public void hostname_and_ipv4_range_24() { NServer.parse("dns.comcor.ru 194.0....
Domain { public static Domain parse(final CIString value) { return parse(value.toString()); } private Domain(final CIString value, final IpInterval<?> reverseIp, final Type type, final boolean dashNotation); CIString getValue(); Type getType(); @CheckForNull IpInterval<?> getReverseIp(); boolean endsWithDomain(final C...
@Test(expected = AttributeParseException.class) public void empty() { Domain.parse(""); } @Test(expected = AttributeParseException.class) public void hostname() { Domain.parse("hostname"); } @Test(expected = AttributeParseException.class) public void ipv4_dash_invalid_position() { Domain.parse("0-127.10.10.in-addr.arpa...
ObjectMessages { public Messages getMessages() { return messages; } Messages getMessages(); Map<RpslAttribute, Messages> getAttributeMessages(); boolean contains(final Message message); void addMessage(final Message message); void addMessage(final RpslAttribute attribute, final Message message); Messages getMessages(f...
@Test public void empty() { assertThat(subject.getMessages().getAllMessages(), hasSize(0)); }
ObjectMessages { public void addAll(final ObjectMessages objectMessages) { messages.addAll(objectMessages.messages); for (final Map.Entry<RpslAttribute, Messages> entry : objectMessages.attributeMessages.entrySet()) { getMessages(entry.getKey()).addAll(entry.getValue()); } } Messages getMessages(); Map<RpslAttribute, ...
@Test public void addAll() { final RpslAttribute attribute = object.getAttributes().get(0); final ObjectMessages other = new ObjectMessages(); other.addMessage(error); other.addMessage(attribute, warning); subject.addAll(other); assertThat(subject.contains(error), is(true)); assertThat(subject.getMessages(attribute).ge...
ObjectTemplate implements Comparable<ObjectTemplate> { public static ObjectTemplate getTemplate(final ObjectType type) { final ObjectTemplate objectTemplate = TEMPLATE_MAP.get(type); if (objectTemplate == null) { throw new IllegalStateException("No template for " + type); } return objectTemplate; } private ObjectTempl...
@Test(expected = IllegalStateException.class) public void getObjectSpec_null() { ObjectTemplate.getTemplate(null); } @Test public void allObjectTypesSupported() { for (final ObjectType objectType : ObjectType.values()) { ObjectTemplate.getTemplate(objectType); } }
ObjectTemplate implements Comparable<ObjectTemplate> { public ObjectType getObjectType() { return objectType; } private ObjectTemplate(final ObjectType objectType, final int orderPosition, final AttributeTemplate... attributeTemplates); static ObjectTemplate getTemplate(final ObjectType type); static Collection<Object...
@Test public void getObjectType() { assertThat(subject.getObjectType(), is(ObjectType.MNTNER)); }
ObjectTemplate implements Comparable<ObjectTemplate> { public ObjectMessages validate(final RpslObject rpslObject) { final ObjectMessages objectMessages = new ObjectMessages(); validateStructure(rpslObject, objectMessages); validateSyntax(rpslObject, objectMessages, false); return objectMessages; } private ObjectTempl...
@Test public void validate_no_errors() { final ObjectMessages objectMessages = subject.validate(RpslObject.parse(MAINTAINER_OBJECT_STRING)); assertThat(objectMessages.hasErrors(), is(false)); } @Test public void validate_mandatory_missing() { final RpslObject rpslObject = RpslObject.parse(MAINTAINER_OBJECT_STRING.subst...
ObjectTemplate implements Comparable<ObjectTemplate> { public Set<AttributeType> getMultipleAttributes() { return multipleAttributes; } private ObjectTemplate(final ObjectType objectType, final int orderPosition, final AttributeTemplate... attributeTemplates); static ObjectTemplate getTemplate(final ObjectType type); ...
@Test public void getMultipleAttributes(){ final ObjectTemplate template = ObjectTemplate.getTemplate(ObjectType.AS_BLOCK); Set<AttributeType> multipleAttributes = template.getMultipleAttributes(); assertThat(multipleAttributes.size(), is(6)); }
ObjectTemplate implements Comparable<ObjectTemplate> { public boolean isSet() { return ObjectType.getSets().contains(objectType); } private ObjectTemplate(final ObjectType objectType, final int orderPosition, final AttributeTemplate... attributeTemplates); static ObjectTemplate getTemplate(final ObjectType type); stat...
@Test public void isSet() { for (ObjectType objectType : ObjectType.values()) { assertThat(objectType.getName().toLowerCase().contains("set"), is(ObjectTemplate.getTemplate(objectType).isSet())); } }
RpslObject implements Identifiable, ResponseObject { public static RpslObject parse(final String input) { return new RpslObject(RpslObjectBuilder.getAttributes(input)); } RpslObject(final RpslObject oldObject, final List<RpslAttribute> attributes); RpslObject(final Integer objectId, final List<RpslAttribute> attribute...
@Test(expected = IllegalArgumentException.class) public void parseNullFails() { RpslObject.parse((byte[]) null); } @Test(expected = IllegalArgumentException.class) public void parseEmptyFails() { RpslObject.parse(new byte[]{}); } @Test public void tab_continuation_equivalent_to_space_continuation() { assertThat(RpslObj...
RpslObject implements Identifiable, ResponseObject { @Override public String toString() { try { final StringWriter writer = new StringWriter(); for (final RpslAttribute attribute : getAttributes()) { attribute.writeTo(writer); } return writer.toString(); } catch (IOException e) { throw new IllegalStateException("Should...
@Test public void checkThatSpecialCharactersGetThrough() { parseAndAssign("person: New Test Person\n" + "address: Flughafenstraße 120\n" + "address: D - 40474 Düsseldorf\n" + "nic-hdl: ABC-RIPE\n"); assertThat(subject.toString(), containsString("Flughafenstraße")); assertThat(subject.toString(), containsString("Düsseld...