@Test public void nullEnvironment() { Collection<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(null); assertThat(jmxMonitoringAppliers, is(empty())); verifyZeroInteractions(configurationInterfaceManager); }
@Test public void noProfile() { when(environment.getProfileIds()).thenReturn(Collections.<String> emptySet()); Collection<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, is(empty())); }
/** * Updates the defined configuration in the holder with following tasks:<br> * 1. Creates the new {@link #agentConfiguration} for given environment and platform id<br> * 2. Resolves all {@link #instrumentationAppliers} for given environment<br> * 3. sets the passes environment to the holder. * <p> * If <code>null</code> is passed then everything saved in the holder will be reset to * <code>null</code> as well. * * @param environment * Environment to update the configuration and appliers with. * @param platformId * Agent id needed for resolving configuration. */ public void update(Environment environment, long platformId) { if (null != environment) { this.environment = environment; this.agentConfiguration = configurationCreator.environmentToConfiguration(environment, platformId); this.instrumentationAppliers = configurationResolver.getInstrumentationAppliers(environment); this.jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); } else { this.environment = null; // NOPMD this.agentConfiguration = null; // NOPMD this.instrumentationAppliers = null; // NOPMD this.jmxMonitoringAppliers = null; // NOPMD } }
@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 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 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<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, is(empty())); }
@Test public void updateReset() { long platformId = 11; Environment environment = mock(Environment.class); AgentConfig configuration = mock(AgentConfig.class); IInstrumentationApplier applier = mock(IInstrumentationApplier.class); JmxMonitoringApplier jmxApplier = mock(JmxMonitoringApplier.class); when(configurationCreator.environmentToConfiguration(environment, platformId)).thenReturn(configuration); when(configurationResolver.getInstrumentationAppliers(environment)).thenReturn(Collections.singleton(applier)); when(configurationResolver.getJmxMonitoringAppliers(environment)).thenReturn(Collections.singleton(jmxApplier)); holder.update(environment, platformId); holder.update(null, platformId); assertThat(holder.isInitialized(), is(false)); // only one time verifications verify(configurationCreator).environmentToConfiguration(environment, platformId); verify(configurationResolver).getInstrumentationAppliers(environment); verify(configurationResolver).getJmxMonitoringAppliers(environment); verifyNoMoreInteractions(configurationCreator, configurationResolver); } }
@Test public void update() { long platformId = 11; Environment environment = mock(Environment.class); AgentConfig configuration = mock(AgentConfig.class); IInstrumentationApplier applier = mock(IInstrumentationApplier.class); JmxMonitoringApplier jmxApplier = mock(JmxMonitoringApplier.class); when(configurationCreator.environmentToConfiguration(environment, platformId)).thenReturn(configuration); when(configurationResolver.getInstrumentationAppliers(environment)).thenReturn(Collections.singleton(applier)); when(configurationResolver.getJmxMonitoringAppliers(environment)).thenReturn(Collections.singleton(jmxApplier)); holder.update(environment, platformId); assertThat(holder.isInitialized(), is(true)); assertThat(holder.getEnvironment(), is(environment)); assertThat(holder.getAgentConfiguration(), is(configuration)); assertThat(holder.getInstrumentationAppliers(), hasSize(1)); assertThat(holder.getInstrumentationAppliers(), hasItem(applier)); assertThat(holder.getJmxMonitoringAppliers(), hasSize(1)); assertThat(holder.getJmxMonitoringAppliers(), hasItem(jmxApplier)); verify(configurationCreator).environmentToConfiguration(environment, platformId); verify(configurationResolver).getInstrumentationAppliers(environment); verify(configurationResolver).getJmxMonitoringAppliers(environment); verifyNoMoreInteractions(configurationCreator, configurationResolver); }