@Test public void testAddConfigElementUnknownKeyNonList() throws IOException { JsonNode json = BatfishObjectMapper.mapper().readTree("{ \"stranger\" : {} }"); ParseVendorConfigurationAnswerElement pvcae = new ParseVendorConfigurationAnswerElement(); Region region = new Region("r1"); region.addConfigElement(json, null, pvcae); Warning warning = Iterables.getOnlyElement( Iterables.getOnlyElement(pvcae.getWarnings().values()).getUnimplementedWarnings()); assertTrue(warning.getText().startsWith("Unrecognized element")); }
void addConfigElement( JsonNode json, String sourceFileName, ParseVendorConfigurationAnswerElement pvcae) { Iterator<?> keys = json.fieldNames(); while (keys.hasNext()) { String key = (String) keys.next(); if (ignoreElement(key)) { continue; } ThrowingConsumer<JsonNode, IOException> integratorFunction = getChildConsumer(key); if (integratorFunction == null) { if (json.get(key).isArray() && json.get(key).size() == 0) { continue; } pvcae.addUnimplementedWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format("Unrecognized element '%s' in AWS file %s", key, sourceFileName), "AWS")); continue; } if (!json.get(key).isArray()) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Unexpected JSON for element '%s' in AWS file %s. Expected a list.", key, sourceFileName), "AWS")); } ArrayNode array = (ArrayNode) json.get(key); for (int index = 0; index < array.size(); index++) { try { integratorFunction.accept(array.get(index)); } catch (IOException | IllegalArgumentException e) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Exception while parsing '%s' in AWS file %s: %s", key, sourceFileName, e.getMessage()), "AWS")); } } } }
Region implements Serializable { void addConfigElement( JsonNode json, String sourceFileName, ParseVendorConfigurationAnswerElement pvcae) { Iterator<?> keys = json.fieldNames(); while (keys.hasNext()) { String key = (String) keys.next(); if (ignoreElement(key)) { continue; } ThrowingConsumer<JsonNode, IOException> integratorFunction = getChildConsumer(key); if (integratorFunction == null) { if (json.get(key).isArray() && json.get(key).size() == 0) { continue; } pvcae.addUnimplementedWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format("Unrecognized element '%s' in AWS file %s", key, sourceFileName), "AWS")); continue; } if (!json.get(key).isArray()) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Unexpected JSON for element '%s' in AWS file %s. Expected a list.", key, sourceFileName), "AWS")); } ArrayNode array = (ArrayNode) json.get(key); for (int index = 0; index < array.size(); index++) { try { integratorFunction.accept(array.get(index)); } catch (IOException | IllegalArgumentException e) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Exception while parsing '%s' in AWS file %s: %s", key, sourceFileName, e.getMessage()), "AWS")); } } } } }
Region implements Serializable { void addConfigElement( JsonNode json, String sourceFileName, ParseVendorConfigurationAnswerElement pvcae) { Iterator<?> keys = json.fieldNames(); while (keys.hasNext()) { String key = (String) keys.next(); if (ignoreElement(key)) { continue; } ThrowingConsumer<JsonNode, IOException> integratorFunction = getChildConsumer(key); if (integratorFunction == null) { if (json.get(key).isArray() && json.get(key).size() == 0) { continue; } pvcae.addUnimplementedWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format("Unrecognized element '%s' in AWS file %s", key, sourceFileName), "AWS")); continue; } if (!json.get(key).isArray()) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Unexpected JSON for element '%s' in AWS file %s. Expected a list.", key, sourceFileName), "AWS")); } ArrayNode array = (ArrayNode) json.get(key); for (int index = 0; index < array.size(); index++) { try { integratorFunction.accept(array.get(index)); } catch (IOException | IllegalArgumentException e) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Exception while parsing '%s' in AWS file %s: %s", key, sourceFileName, e.getMessage()), "AWS")); } } } } Region(String name); private  Region(
      String name,
      Map<String, Address> addresses,
      Map<String, CustomerGateway> customerGateways,
      Map<String, ElasticsearchDomain> elasticsearchDomains,
      Map<String, Instance> instances,
      Map<String, InternetGateway> internetGateways,
      Map<String, LoadBalancer> loadBalancers,
      Map<String, LoadBalancerAttributes> loadBalancerAttributes,
      Map<String, LoadBalancerListener> loadBalancerListeners,
      Map<String, LoadBalancerTargetHealth> loadBalancerTargetHealths,
      Map<String, NatGateway> natGateways,
      Map<String, NetworkAcl> networkAcls,
      Map<String, NetworkInterface> networkInterfaces,
      Map<String, PrefixList> prefixLists,
      Map<String, RdsInstance> rdsInstances,
      Map<String, RouteTable> routeTables,
      Map<String, SecurityGroup> securityGroups,
      Map<String, Subnet> subnets,
      Map<String, TargetGroup> targetGroups,
      Map<String, TransitGatewayAttachment> transitGatewayAttachments,
      Map<String, TransitGatewayPropagations> transitGatewayPropagations,
      Map<String, TransitGatewayRouteTable> transitGatewayRouteTables,
      Map<String, TransitGatewayStaticRoutes> transitGatewayStaticRoutes,
      Map<String, TransitGatewayVpcAttachment> transitGatewayVpcAttachments,
      Map<String, TransitGateway> transitGateways,
      Map<String, VpcEndpoint> vpcEndpoints,
      Map<String, VpcPeeringConnection> vpcPeerings,
      Map<String, Vpc> vpcs,
      Map<String, VpnConnection> vpnConnections,
      Map<String, VpnGateway> vpnGateways); }
Region implements Serializable { void addConfigElement( JsonNode json, String sourceFileName, ParseVendorConfigurationAnswerElement pvcae) { Iterator<?> keys = json.fieldNames(); while (keys.hasNext()) { String key = (String) keys.next(); if (ignoreElement(key)) { continue; } ThrowingConsumer<JsonNode, IOException> integratorFunction = getChildConsumer(key); if (integratorFunction == null) { if (json.get(key).isArray() && json.get(key).size() == 0) { continue; } pvcae.addUnimplementedWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format("Unrecognized element '%s' in AWS file %s", key, sourceFileName), "AWS")); continue; } if (!json.get(key).isArray()) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Unexpected JSON for element '%s' in AWS file %s. Expected a list.", key, sourceFileName), "AWS")); } ArrayNode array = (ArrayNode) json.get(key); for (int index = 0; index < array.size(); index++) { try { integratorFunction.accept(array.get(index)); } catch (IOException | IllegalArgumentException e) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Exception while parsing '%s' in AWS file %s: %s", key, sourceFileName, e.getMessage()), "AWS")); } } } } Region(String name); private  Region(
      String name,
      Map<String, Address> addresses,
      Map<String, CustomerGateway> customerGateways,
      Map<String, ElasticsearchDomain> elasticsearchDomains,
      Map<String, Instance> instances,
      Map<String, InternetGateway> internetGateways,
      Map<String, LoadBalancer> loadBalancers,
      Map<String, LoadBalancerAttributes> loadBalancerAttributes,
      Map<String, LoadBalancerListener> loadBalancerListeners,
      Map<String, LoadBalancerTargetHealth> loadBalancerTargetHealths,
      Map<String, NatGateway> natGateways,
      Map<String, NetworkAcl> networkAcls,
      Map<String, NetworkInterface> networkInterfaces,
      Map<String, PrefixList> prefixLists,
      Map<String, RdsInstance> rdsInstances,
      Map<String, RouteTable> routeTables,
      Map<String, SecurityGroup> securityGroups,
      Map<String, Subnet> subnets,
      Map<String, TargetGroup> targetGroups,
      Map<String, TransitGatewayAttachment> transitGatewayAttachments,
      Map<String, TransitGatewayPropagations> transitGatewayPropagations,
      Map<String, TransitGatewayRouteTable> transitGatewayRouteTables,
      Map<String, TransitGatewayStaticRoutes> transitGatewayStaticRoutes,
      Map<String, TransitGatewayVpcAttachment> transitGatewayVpcAttachments,
      Map<String, TransitGateway> transitGateways,
      Map<String, VpcEndpoint> vpcEndpoints,
      Map<String, VpcPeeringConnection> vpcPeerings,
      Map<String, Vpc> vpcs,
      Map<String, VpnConnection> vpnConnections,
      Map<String, VpnGateway> vpnGateways); static RegionBuilder builder(String name); @Nonnull Set<Address> getAddresses(); @Nonnull Map<String, Instance> getInstances(); @Nonnull Set<LoadBalancer> getLoadBalancers(); @Nullable LoadBalancerListener getLoadBalancerListener(String loadBalancerArn); @Nullable LoadBalancerTargetHealth getLoadBalancerTargetHealth(String targetGroupArn); @Nonnull String getName(); @Nonnull Map<String, NetworkAcl> getNetworkAcls(); @Nonnull Map<String, PrefixList> getPrefixLists(); @Nonnull Map<String, NetworkInterface> getNetworkInterfaces(); @Nonnull Map<String, SecurityGroup> getSecurityGroups(); @Nonnull Map<String, Subnet> getSubnets(); @Nullable TargetGroup getTargetGroup(String targetGroupArn); @Nonnull Map<String, VpcEndpoint> getVpcEndpoints(); void applyAclsToInterfaceBasedOnSecurityGroups(
      Iterable<String> groups, Configuration c, Interface i); }
Region implements Serializable { void addConfigElement( JsonNode json, String sourceFileName, ParseVendorConfigurationAnswerElement pvcae) { Iterator<?> keys = json.fieldNames(); while (keys.hasNext()) { String key = (String) keys.next(); if (ignoreElement(key)) { continue; } ThrowingConsumer<JsonNode, IOException> integratorFunction = getChildConsumer(key); if (integratorFunction == null) { if (json.get(key).isArray() && json.get(key).size() == 0) { continue; } pvcae.addUnimplementedWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format("Unrecognized element '%s' in AWS file %s", key, sourceFileName), "AWS")); continue; } if (!json.get(key).isArray()) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Unexpected JSON for element '%s' in AWS file %s. Expected a list.", key, sourceFileName), "AWS")); } ArrayNode array = (ArrayNode) json.get(key); for (int index = 0; index < array.size(); index++) { try { integratorFunction.accept(array.get(index)); } catch (IOException | IllegalArgumentException e) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning( String.format( "Exception while parsing '%s' in AWS file %s: %s", key, sourceFileName, e.getMessage()), "AWS")); } } } } Region(String name); private  Region(
      String name,
      Map<String, Address> addresses,
      Map<String, CustomerGateway> customerGateways,
      Map<String, ElasticsearchDomain> elasticsearchDomains,
      Map<String, Instance> instances,
      Map<String, InternetGateway> internetGateways,
      Map<String, LoadBalancer> loadBalancers,
      Map<String, LoadBalancerAttributes> loadBalancerAttributes,
      Map<String, LoadBalancerListener> loadBalancerListeners,
      Map<String, LoadBalancerTargetHealth> loadBalancerTargetHealths,
      Map<String, NatGateway> natGateways,
      Map<String, NetworkAcl> networkAcls,
      Map<String, NetworkInterface> networkInterfaces,
      Map<String, PrefixList> prefixLists,
      Map<String, RdsInstance> rdsInstances,
      Map<String, RouteTable> routeTables,
      Map<String, SecurityGroup> securityGroups,
      Map<String, Subnet> subnets,
      Map<String, TargetGroup> targetGroups,
      Map<String, TransitGatewayAttachment> transitGatewayAttachments,
      Map<String, TransitGatewayPropagations> transitGatewayPropagations,
      Map<String, TransitGatewayRouteTable> transitGatewayRouteTables,
      Map<String, TransitGatewayStaticRoutes> transitGatewayStaticRoutes,
      Map<String, TransitGatewayVpcAttachment> transitGatewayVpcAttachments,
      Map<String, TransitGateway> transitGateways,
      Map<String, VpcEndpoint> vpcEndpoints,
      Map<String, VpcPeeringConnection> vpcPeerings,
      Map<String, Vpc> vpcs,
      Map<String, VpnConnection> vpnConnections,
      Map<String, VpnGateway> vpnGateways); static RegionBuilder builder(String name); @Nonnull Set<Address> getAddresses(); @Nonnull Map<String, Instance> getInstances(); @Nonnull Set<LoadBalancer> getLoadBalancers(); @Nullable LoadBalancerListener getLoadBalancerListener(String loadBalancerArn); @Nullable LoadBalancerTargetHealth getLoadBalancerTargetHealth(String targetGroupArn); @Nonnull String getName(); @Nonnull Map<String, NetworkAcl> getNetworkAcls(); @Nonnull Map<String, PrefixList> getPrefixLists(); @Nonnull Map<String, NetworkInterface> getNetworkInterfaces(); @Nonnull Map<String, SecurityGroup> getSecurityGroups(); @Nonnull Map<String, Subnet> getSubnets(); @Nullable TargetGroup getTargetGroup(String targetGroupArn); @Nonnull Map<String, VpcEndpoint> getVpcEndpoints(); void applyAclsToInterfaceBasedOnSecurityGroups(
      Iterable<String> groups, Configuration c, Interface i);  }