@Test public void testGetVariableBindings() { final CommunityIndexCounter32Modifier modifier = new CommunityIndexCounter32Modifier(); modifier.init(modifierProperties); final OctetString context1 = new OctetString("20"); final OID queryOID1 = new OID(OID); final Map<OID, Variable> variableBindings1 = modifier.getVariableBindings(context1, queryOID1); assertEquals(variableBindings1.size(), 1); assertEquals(variableBindings1.get(queryOID1), new Counter32(150L)); final OctetString context2 = new OctetString("23"); final OID queryOID2 = new OID("1.3.6"); final Map<OID, Variable> variableBindings2 = modifier.getVariableBindings(context2, queryOID2); assertEquals(variableBindings2.size(), 0, "bindings with not initialized context should be empty"); final OctetString context3 = null; final OID queryOID3 = new OID("1.3.6"); final Map<OID, Variable> variableBindings3 = modifier.getVariableBindings(context3, queryOID3); assertEquals(variableBindings3.size(), 1); assertEquals(variableBindings3.get(queryOID3), new Counter32(0L), "bindings with null context should be 0"); final OctetString context4 = new OctetString(); final OID queryOID4 = new OID("1.3.6"); final Map<OID, Variable> variableBindings4 = modifier.getVariableBindings(context4, queryOID4); assertEquals(variableBindings4.size(), 1); assertEquals(variableBindings4.get(queryOID4), new Counter32(0L), "bindings with empty context should be 0"); final OctetString context5 = new OctetString("20"); final OID queryOID5 = null; final Map<OID, Variable> variableBindings5 = modifier.getVariableBindings(context5, queryOID5); assertEquals(variableBindings5.size(), 0, "bindings with null query OID should be empty"); }
@Override public Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID) { if (queryOID != null && context != null && context.getValue().length != 0) { if (!queryOID.toString().isEmpty() && !context.toString().isEmpty() && communityContextMapping.containsKey(Long.parseLong(context.toString()))) { return Collections.singletonMap(queryOID, new Counter32(communityContextMapping.get(Long.parseLong(context.toString())))); } } else if (queryOID != null) { return Collections.singletonMap(queryOID, modify(null)); } return new TreeMap<>(); }
CommunityIndexCounter32Modifier implements CommunityContextModifier<Counter32> { @Override public Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID) { if (queryOID != null && context != null && context.getValue().length != 0) { if (!queryOID.toString().isEmpty() && !context.toString().isEmpty() && communityContextMapping.containsKey(Long.parseLong(context.toString()))) { return Collections.singletonMap(queryOID, new Counter32(communityContextMapping.get(Long.parseLong(context.toString())))); } } else if (queryOID != null) { return Collections.singletonMap(queryOID, modify(null)); } return new TreeMap<>(); } }
CommunityIndexCounter32Modifier implements CommunityContextModifier<Counter32> { @Override public Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID) { if (queryOID != null && context != null && context.getValue().length != 0) { if (!queryOID.toString().isEmpty() && !context.toString().isEmpty() && communityContextMapping.containsKey(Long.parseLong(context.toString()))) { return Collections.singletonMap(queryOID, new Counter32(communityContextMapping.get(Long.parseLong(context.toString())))); } } else if (queryOID != null) { return Collections.singletonMap(queryOID, modify(null)); } return new TreeMap<>(); }  }
CommunityIndexCounter32Modifier implements CommunityContextModifier<Counter32> { @Override public Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID) { if (queryOID != null && context != null && context.getValue().length != 0) { if (!queryOID.toString().isEmpty() && !context.toString().isEmpty() && communityContextMapping.containsKey(Long.parseLong(context.toString()))) { return Collections.singletonMap(queryOID, new Counter32(communityContextMapping.get(Long.parseLong(context.toString())))); } } else if (queryOID != null) { return Collections.singletonMap(queryOID, modify(null)); } return new TreeMap<>(); }  @Override void init(final ModifierProperties properties); @Override final Counter32 modify(final Counter32 variable); @Override Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID); }
CommunityIndexCounter32Modifier implements CommunityContextModifier<Counter32> { @Override public Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID) { if (queryOID != null && context != null && context.getValue().length != 0) { if (!queryOID.toString().isEmpty() && !context.toString().isEmpty() && communityContextMapping.containsKey(Long.parseLong(context.toString()))) { return Collections.singletonMap(queryOID, new Counter32(communityContextMapping.get(Long.parseLong(context.toString())))); } } else if (queryOID != null) { return Collections.singletonMap(queryOID, modify(null)); } return new TreeMap<>(); }  @Override void init(final ModifierProperties properties); @Override final Counter32 modify(final Counter32 variable); @Override Map<OID, Variable> getVariableBindings(final OctetString context, final OID queryOID);  }