/** * {@inheritDoc} */ @Override @MethodLog public InstrumentationDefinition analyze(long platformIdent, String hash, Type sentType) throws BusinessException { return nextGenInstrumentationManager.analyze(platformIdent, hash, sentType); }
@Test(expectedExceptions = BusinessException.class) public void agentNotRegistered() throws BusinessException { manager.analyze(ID, HASH, type); }
@Test(expectedExceptions = { BusinessException.class }) public void businessTransactionShouldBeThrownIfNoClassCacheIsAvailable() throws BusinessException { manager.analyze(ID, HASH, type); } }
@Test public void successful() throws Exception { Type type = mock(Type.class); agentService.analyze(10, "hash", type); verify(instrumentationManager).analyze(10L, "hash", type); verifyNoMoreInteractions(instrumentationManager); verifyZeroInteractions(messageProvider); } }
@Test public void existingNonClassType() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); ImmutableType typeFromClassCache = mock(ImmutableType.class); when(typeFromClassCache.isClass()).thenReturn(false); when(lookupService.findByHash(HASH)).thenReturn(typeFromClassCache); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(nullValue())); verifyZeroInteractions(modificationService, instrumentationService); }
@Test public void nonExistingNonClassType() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); ImmutableType typeFromClassCache = mock(ImmutableType.class); when(typeFromClassCache.isClass()).thenReturn(false); when(lookupService.findByHash(HASH)).thenReturn(null, typeFromClassCache); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(nullValue())); verify(modificationService).merge(type); verifyNoMoreInteractions(modificationService); verifyZeroInteractions(instrumentationService); }
@Test public void existingClassTypeConfigurationNotInitialized() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); ClassType classType = mock(ClassType.class); when(classType.isClass()).thenReturn(true); when(classType.castToClass()).thenReturn(classType); when(lookupService.findByHash(HASH)).thenReturn(classType); when(configurationHolder.isInitialized()).thenReturn(false); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(nullValue())); verifyZeroInteractions(modificationService, instrumentationService); }
@Test public void existingClassTypeInstrumented() throws BusinessException, ClassCacheModificationException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(registrationService.registerPlatformIdent(definedIPs, agentName, version)).thenReturn(ID); manager.register(definedIPs, agentName, version); ClassType classType = mock(ClassType.class); when(classType.isClass()).thenReturn(true); when(classType.castToClass()).thenReturn(classType); when(lookupService.findByHash(HASH)).thenReturn(classType); when(configurationHolder.isInitialized()).thenReturn(true); AgentConfig configuration = mock(AgentConfig.class); Collection<IInstrumentationApplier> appliers = mock(Collection.class); InstrumentationDefinition instrumentationResult = mock(InstrumentationDefinition.class); when(configurationHolder.getAgentConfiguration()).thenReturn(configuration); when(configurationHolder.getInstrumentationAppliers()).thenReturn(appliers); when(instrumentationService.addAndGetInstrumentationResult(classType, configuration, appliers)).thenReturn(instrumentationResult); InstrumentationDefinition result = manager.analyze(ID, HASH, type); assertThat(result, is(instrumentationResult)); verify(instrumentationService).addAndGetInstrumentationResult(classType, configuration, appliers); verifyNoMoreInteractions(instrumentationService); verifyZeroInteractions(modificationService); }