@Test public void nullEnvironment() { Collection<ExcludeRule> rules = configurationResolver.getAllExcludeRules(null); assertThat(rules, is(empty())); verifyZeroInteractions(configurationInterfaceManager); }
@Test public void noProfile() { when(environment.getProfileIds()).thenReturn(Collections.<String> emptySet()); Collection<ExcludeRule> rules = configurationResolver.getAllExcludeRules(environment); assertThat(rules, is(empty())); }
@Test public void excludeRule() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(excludeRulesProfileData).when(profile).getProfileData(); when(excludeRulesProfileData.getData(ExcludeRulesProfileData.class)).thenReturn(Collections.singletonList(excludeRule)); when(profile.isActive()).thenReturn(true); Collection<ExcludeRule> rules = configurationResolver.getAllExcludeRules(environment); assertThat(rules, hasSize(1)); assertThat(rules, hasItem(excludeRule)); }
@Test public void profileDoesNotExists() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenThrow(new BusinessException(null)); Collection<ExcludeRule> rules = configurationResolver.getAllExcludeRules(environment); assertThat(rules, is(empty())); }
@Test public void profileNotActive() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(excludeRulesProfileData).when(profile).getProfileData(); when(excludeRulesProfileData.getData(ExcludeRulesProfileData.class)).thenReturn(Collections.singletonList(excludeRule)); when(profile.isActive()).thenReturn(false); Collection<ExcludeRule> rules = configurationResolver.getAllExcludeRules(environment); assertThat(rules, is(empty())); }
@Test public void wrongProfileData() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(new SensorAssignmentProfileData()).when(profile).getProfileData(); when(profile.isActive()).thenReturn(true); Collection<ExcludeRule> rules = configurationResolver.getAllExcludeRules(environment); assertThat(rules, is(empty())); }
@Test public void excludeRules() throws Exception { ExcludeRule er1 = new ExcludeRule("excludeRule1"); ExcludeRule er2 = new ExcludeRule("wildCard*"); when(configurationResolver.getAllExcludeRules(environment)).thenReturn(Arrays.asList(new ExcludeRule[] { er1, er2 })); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, 0); Collection<IMatchPattern> excludeClassesPatterns = agentConfiguration.getExcludeClassesPatterns(); assertThat(excludeClassesPatterns, hasSize(2)); assertThat(excludeClassesPatterns, hasItem(new EqualsMatchPattern(er1.getClassName()))); assertThat(excludeClassesPatterns, hasItem(new WildcardMatchPattern(er2.getClassName()))); }
Collection<ExcludeRule> excludeRules = configurationResolver.getAllExcludeRules(environment); if (CollectionUtils.isNotEmpty(excludeRules)) { Collection<IMatchPattern> excludeClassesPatterns = new ArrayList<>();