### Question:
EnvPullMessageFilter implements PullMessageFilter { @Override public boolean match(PullRequest request, Buffer message) { return match(getFilter(request, PullFilterType.SUB_ENV_ISOLATION), request, message); }  @Override boolean isActive(PullRequest request, Buffer message); @Override boolean match(PullRequest request, Buffer message); @Override void init(DynamicConfig config);  }### Answer:
@Test public void testMatchOnMessageTagEqualsRuleTag() { String env = "test"; String subEnv = "testSub"; String subject = TestToolBox.DEFAULT_SUBJECT; String group = TestToolBox.DEFAULT_GROUP; BaseMessage message = TestToolBox.createDefaultMessage(); message.setProperty(keys.qmq_env, env); message.setProperty(keys.qmq_subEnv, subEnv); Buffer buffer = TestToolBox.messageToBuffer(message); PullRequest request = TestToolBox.createDefaultPullRequest(); request.setFilters(Lists.newArrayList(new SubEnvIsolationPullFilter(env, subEnv))); EnvPullMessageFilter filter = Mockito.spy(EnvPullMessageFilter.class); Map<String, SubEnvIsolationRule> ruleMap = Maps.newHashMap(); SubEnvIsolationRule rule = new SubEnvIsolationRule(); rule.setSubject(subject); rule.setGroup(group); rule.setSubjectEnv(env); rule.setGroupEnv(env); rule.setSubjectSubEnv(subEnv); rule.setGroupSubEnv(subEnv); ruleMap.put(subject + "_" + group, rule); Whitebox.setInternalState(filter, "enableSubEnvIsolation", true); Whitebox.setInternalState(filter, "ruleMap", ImmutableMap.copyOf(ruleMap)); boolean match = filter.match(request, buffer); assertTrue(match); }
@Test public void testMatchOnMessageTagNotEqualsRuleTag() { String env = "test"; String subEnv = "testSub"; String msgEnv = "msgTest"; String msgSubEnv = "msgTestSub"; String subject = TestToolBox.DEFAULT_SUBJECT; String group = TestToolBox.DEFAULT_GROUP; BaseMessage message = TestToolBox.createDefaultMessage(); message.setProperty(keys.qmq_env, msgEnv); message.setProperty(keys.qmq_subEnv, msgSubEnv); Buffer buffer = TestToolBox.messageToBuffer(message); PullRequest request = TestToolBox.createDefaultPullRequest(); request.setFilters(Lists.newArrayList(new SubEnvIsolationPullFilter(env, subEnv))); EnvPullMessageFilter filter = Mockito.spy(EnvPullMessageFilter.class); Map<String, SubEnvIsolationRule> ruleMap = Maps.newHashMap(); SubEnvIsolationRule rule = new SubEnvIsolationRule(); rule.setSubject(subject); rule.setGroup(group); rule.setSubjectEnv(env); rule.setGroupEnv(env); rule.setSubjectSubEnv(subEnv); rule.setGroupSubEnv(subEnv); ruleMap.put(subject + "_" + group, rule); Whitebox.setInternalState(filter, "enableSubEnvIsolation", true); Whitebox.setInternalState(filter, "ruleMap", ImmutableMap.copyOf(ruleMap)); boolean match = filter.match(request, buffer); assertFalse(match); }