/** * {@inheritDoc} */ @Override public Profile getProfile(String id) throws BusinessException { return ciManager.getProfile(id); }
@Test(expectedExceptions = BusinessException.class) public void getNotExisting() throws Exception { Profile result = manager.getProfile("someId"); } }
@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 nullDataFromProfile() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(jmxDefinitionProfileData).when(profile).getProfileData(); when(jmxDefinitionProfileData.getData(JmxDefinitionProfileData.class)).thenReturn(null); when(profile.isActive()).thenReturn(true); Collection<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, is(empty())); }
@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 profileDoesNotExists() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenThrow(new BusinessException(null)); Collection<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, 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 profileNotActive() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(jmxDefinitionProfileData).when(profile).getProfileData(); when(jmxDefinitionProfileData.getData(JmxDefinitionProfileData.class)).thenReturn(Collections.singletonList(jmxAssignment)); when(profile.isActive()).thenReturn(false); Collection<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, is(empty())); }
@Test public void applier() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(jmxDefinitionProfileData).when(profile).getProfileData(); when(jmxDefinitionProfileData.getData(JmxDefinitionProfileData.class)).thenReturn(Collections.singletonList(jmxAssignment)); when(profile.isActive()).thenReturn(true); Collection<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, hasSize(1)); assertThat(jmxMonitoringAppliers.iterator().next().getJmxSensorAssignment(), is(jmxAssignment)); }
@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 profileDoesNotExists() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenThrow(new BusinessException(null)); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, is(empty())); verify(functionalAssignmentFactory).getSpecialAssignments(environment); }
@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<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, is(empty())); }
@Test public void profileNotActive() throws BusinessException { MethodSensorAssignment assignment = mock(MethodSensorAssignment.class); when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(sensorAssignmentProfileData).when(profile).getProfileData(); doReturn(Collections.singletonList(assignment)).when(sensorAssignmentProfileData).getData(SensorAssignmentProfileData.class); when(profile.isActive()).thenReturn(false); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, is(empty())); verify(functionalAssignmentFactory).getSpecialAssignments(environment); verifyZeroInteractions(assignment); }
@Test public void invocationStartsSensorAssignment() throws BusinessException { InvocationStartMethodSensorAssignment assignment = mock(InvocationStartMethodSensorAssignment.class); when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(sensorAssignmentProfileData).when(profile).getProfileData(); doReturn(Collections.singletonList(assignment)).when(sensorAssignmentProfileData).getData(SensorAssignmentProfileData.class); when(profile.isActive()).thenReturn(true); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, hasSize(1)); IInstrumentationApplier applier = appliers.iterator().next(); assertThat(applier, is(instanceOf(InvocationStartMethodSensorInstrumentationApplier.class))); assertThat((InvocationStartMethodSensorAssignment) applier.getSensorAssignment(), is(assignment)); verify(functionalAssignmentFactory).getSpecialAssignments(environment); }
@Test public void methodSensorAssignment() throws BusinessException { MethodSensorAssignment assignment = mock(MethodSensorAssignment.class); when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(sensorAssignmentProfileData).when(profile).getProfileData(); doReturn(Collections.singletonList(assignment)).when(sensorAssignmentProfileData).getData(SensorAssignmentProfileData.class); when(profile.isActive()).thenReturn(true); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, hasSize(1)); IInstrumentationApplier applier = appliers.iterator().next(); assertThat(applier, is(instanceOf(MethodSensorInstrumentationApplier.class))); assertThat((MethodSensorAssignment) applier.getSensorAssignment(), is(assignment)); verify(functionalAssignmentFactory).getSpecialAssignments(environment); }
@Test public void wrongProfileData() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(new ExcludeRulesProfileData()).when(profile).getProfileData(); when(profile.isActive()).thenReturn(true); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, is(empty())); verify(functionalAssignmentFactory).getSpecialAssignments(environment); }
@Test public void timerSensorAssignment() throws BusinessException { TimerMethodSensorAssignment assignment = mock(TimerMethodSensorAssignment.class); when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(sensorAssignmentProfileData).when(profile).getProfileData(); doReturn(Collections.singletonList(assignment)).when(sensorAssignmentProfileData).getData(SensorAssignmentProfileData.class); when(profile.isActive()).thenReturn(true); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, hasSize(1)); IInstrumentationApplier applier = appliers.iterator().next(); assertThat(applier, is(instanceOf(TimerMethodSensorInstrumentationApplier.class))); assertThat((TimerMethodSensorAssignment) applier.getSensorAssignment(), is(assignment)); verify(functionalAssignmentFactory).getSpecialAssignments(environment); }
@Test public void exceptionSensorAssignment() throws BusinessException { ExceptionSensorAssignment assignment = mock(ExceptionSensorAssignment.class); when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenReturn(profile); doReturn(sensorAssignmentProfileData).when(profile).getProfileData(); doReturn(Collections.singletonList(assignment)).when(sensorAssignmentProfileData).getData(SensorAssignmentProfileData.class); when(profile.isActive()).thenReturn(true); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, hasSize(1)); IInstrumentationApplier applier = appliers.iterator().next(); assertThat(applier, is(instanceOf(ExceptionSensorInstrumentationApplier.class))); assertThat((ExceptionSensorAssignment) applier.getSensorAssignment(), is(assignment)); verify(functionalAssignmentFactory).getSpecialAssignments(environment); }
@Test public void get() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); profile = manager.createProfile(profile); Profile result = manager.getProfile(profile.getId()); assertThat(result.getId(), is(profile.getId())); }
@Test public void importProfileExists() throws Exception { Profile profile = new Profile(); profile.setName("test"); profile.setProfileData(new SensorAssignmentProfileData()); manager.createProfile(profile); Profile importProfile = new Profile(); importProfile.setId(profile.getId()); importProfile.setName("imported"); manager.importProfile(importProfile); assertThat(manager.getProfile(profile.getId()), is(importProfile)); }