@VisibleForTesting public static Set<String> getAddressGroups(ReferenceLibrary referenceLibrary) { ImmutableSet.Builder<String> addressGroups = ImmutableSet.builder(); referenceLibrary .getReferenceBooks() .forEach( referenceBook -> referenceBook.getAddressGroups().stream() .map(AddressGroup::getName) .forEach(addressGroups::add)); return addressGroups.build(); }
public ReferenceBookBean(ReferenceBook book) { name = book.getName(); addressGroups = book.getAddressGroups().stream() .map(ag -> new AddressGroupBean(ag)) .collect(Collectors.toSet()); filterGroups = book.getFilterGroups().stream() .map(fg -> new FilterGroupBean(fg)) .collect(Collectors.toSet()); interfaceGroups = book.getInterfaceGroups().stream() .map(ig -> new InterfaceGroupBean(ig)) .collect(Collectors.toSet()); serviceEndpoints = book.getServiceEndpoints().stream() .map(se -> new ServiceEndpointBean(se)) .collect(Collectors.toSet()); serviceObjectGroups = book.getServiceObjectGroups().stream() .map(sog -> new ServiceObjectGroupBean(sog)) .collect(Collectors.toSet()); serviceObjects = book.getServiceObjects().stream() .map(so -> new ServiceObjectBean(so)) .collect(Collectors.toSet()); }
private static void beanBookMatch(ReferenceBookBean bean, ReferenceBook book) { assertThat(bean.name, equalTo(book.getName())); assertThat( bean.addressGroups, equalTo( book.getAddressGroups().stream() .map(ag -> new AddressGroupBean(ag)) .collect(Collectors.toSet()))); assertThat( bean.serviceEndpoints, equalTo( book.getServiceEndpoints().stream() .map(se -> new ServiceEndpointBean(se)) .collect(Collectors.toSet()))); assertThat( bean.serviceObjectGroups, equalTo( book.getServiceObjectGroups().stream() .map(sog -> new ServiceObjectGroupBean(sog)) .collect(Collectors.toSet()))); assertThat( bean.serviceObjects, equalTo( book.getServiceObjects().stream() .map(so -> new ServiceObjectBean(so)) .collect(Collectors.toSet()))); }
/** check that we deserialize a basic object correctly */ @Test public void bookDeserializationBasic() throws IOException { ReferenceBook book = BatfishObjectMapper.mapper() .readValue( CommonUtil.readResource("org/batfish/referencelibrary/bookBasic.json"), ReferenceBook.class); assertThat(book.getAddressGroups(), hasSize(2)); assertThat(book.getFilterGroups(), hasSize(2)); assertThat(book.getInterfaceGroups(), hasSize(2)); assertThat(book.getServiceEndpoints(), hasSize(2)); assertThat(book.getServiceObjects(), hasSize(2)); assertThat(book.getServiceObjectGroups(), hasSize(2)); }