@Test public void noEnvironment() { when(configurationHolder.isInitialized()).thenReturn(false); job.setEnvironment(null); job.run(); verify(instrumentationService, times(1)).removeInstrumentationPoints(); verify(configurationHolder, times(1)).update(null, PLATFORM_ID); verifyNoMoreInteractions(instrumentationService, eventPublisher); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void yesEnvironment() { when(configurationHolder.isInitialized()).thenReturn(true); when(configurationHolder.getAgentConfiguration()).thenReturn(updateConfiguration); doReturn(Collections.singletonList(classType)).when(instrumentationService).addInstrumentationPoints(any(AgentConfig.class), any(Collection.class)); job.setEnvironment(updateEnvironment); job.run(); verify(instrumentationService, times(1)).removeInstrumentationPoints(); verify(configurationHolder, times(1)).update(updateEnvironment, PLATFORM_ID); Collection<IInstrumentationApplier> appliers = configurationHolder.getInstrumentationAppliers(); verify(instrumentationService, times(1)).addInstrumentationPoints(updateConfiguration, appliers); ArgumentCaptor<Collection> typeCaptor = ArgumentCaptor.forClass(Collection.class); verify(instrumentationService).getInstrumentationResults(typeCaptor.capture()); assertThat((Collection<Type>) typeCaptor.getValue(), hasItems((Type) classType)); verify(eventPublisher).publishEvent(any(ClassInstrumentationChangedEvent.class)); verifyNoMoreInteractions(instrumentationService, updateConfiguration, updateEnvironment, eventPublisher); } }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void successful() throws BusinessException, InterruptedException, ExecutionException, TimeoutException { cacheMap.put(1L, cacheEntry); when(cacheEntry.getId()).thenReturn(10L); when(configurationResolver.getEnvironmentForAgent(any(List.class), any(String.class))).thenReturn(newEnvironment); when(cachedEnvironment.getId()).thenReturn("id"); when(newEnvironment.getId()).thenReturn("newId"); when(objectFactory.getObject()).thenReturn(updateJob); when(executor.submit(updateJob)).thenReturn((Future) future); eventListener.onApplicationEvent(event); verify(nextGenInstrumentationManager).getAgentCacheMap(); verify(cacheEntry).getConfigurationHolder(); verify(cacheEntry).getId(); verify(configurationHolder).getEnvironment(); verify(platformIdentDao).load(10L); verify(platformIdent).getAgentName(); verify(platformIdent).getDefinedIPs(); verify(configurationResolver).getEnvironmentForAgent(any(List.class), any(String.class)); verify(cachedEnvironment).getId(); verify(newEnvironment).getId(); verify(objectFactory).getObject(); verify(updateJob).setAgentCacheEntry(cacheEntry); verify(updateJob).setEnvironment(newEnvironment); verify(executor).submit(updateJob); verify(future).get(1L, TimeUnit.MINUTES); verifyNoMoreInteractions(nextGenInstrumentationManager, cacheEntry, configurationHolder, platformIdentDao, platformIdent, configurationResolver, cachedEnvironment, newEnvironment, event, objectFactory, updateJob, executor, future); }
mappingUpdateJob.setEnvironment(environment); mappingUpdateJob.setAgentCacheEntry(agentCacheEntry);