public Tester(int numberOfContextProperties) { TelemetryConfiguration configuration = new TelemetryConfiguration(); configuration.setInstrumentationKey(TEST_IKEY); configuration.setChannel(new InProcessTelemetryChannel()); fakeTransmissionOutput = TestThreadLocalData.getTransmissionOutput(); testResultsVerifier = fakeTransmissionOutput.getTestResultsVerifier(); telemetryClient = new TelemetryClient(configuration); TelemetryContext context = telemetryClient.getContext(); for (int i = 0; i < numberOfContextProperties; ++i) { String asStr = String.valueOf(i); context.getProperties().put(MOCK_CONTEXT_PROPERTY_BASE_NAME + asStr, MOCK_CONTEXT_PROPERTY_BASE_VALUE + asStr); } }
if (channel != null) { channel.setSampler(telemetrySampler); configuration.setChannel(channel); return true; } else { configuration.setChannel(channel); return true; } catch (Exception e) { TelemetryChannel channel = new InProcessTelemetryChannel(); channel.setSampler(telemetrySampler); configuration.setChannel(channel); return true;
private void setMinimumConfiguration(ApplicationInsightsXmlConfiguration userConfiguration, TelemetryConfiguration configuration) { setInstrumentationKey(userConfiguration, configuration); configuration.setChannel(new InProcessTelemetryChannel()); addHeartBeatModule(configuration); setContextInitializers(null, configuration); initializeComponents(configuration); }
@Test public void testMethodsOnTelemetryAreCalledWhenTracking() { TelemetryChannel mockChannel = Mockito.mock(TelemetryChannel.class); configuration.setChannel(mockChannel); TelemetryContext mockContext = new TelemetryContext(); Telemetry mockTelemetry = Mockito.mock(Telemetry.class); Mockito.doReturn(mockContext).when(mockTelemetry).getContext(); TelemetryClient telemetryClient = new TelemetryClient(configuration); telemetryClient.track(mockTelemetry); Mockito.verify(mockChannel, Mockito.times(1)).send(mockTelemetry); Mockito.verify(mockTelemetry, Mockito.times(1)).setTimestamp(any(Date.class)); }
private TelemetryConfiguration createConfiguration(final List<Telemetry> itemsToSend) { TelemetryConfiguration configuration = new TelemetryConfiguration(); configuration.setInstrumentationKey("00000000-0000-0000-0000-000000000000"); class StubBufferTelemetryChannel extends StubTelemetryChannel { @Override public void send(Telemetry item) { itemsToSend.add(item); //item.reset(); } } configuration.setChannel(new StubBufferTelemetryChannel()); return configuration; }
@Bean @DependsOn("internalLogger") public TelemetryConfiguration telemetryConfiguration(TelemetryChannel telemetryChannel) { TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.getActiveWithoutInitializingConfig(); telemetryConfiguration.setTrackingIsDisabled(!applicationInsightsProperties.isEnabled()); telemetryConfiguration.setInstrumentationKey(applicationInsightsProperties.getInstrumentationKey()); if (contextInitializers != null) { telemetryConfiguration.getContextInitializers().addAll(contextInitializers); } if (telemetryInitializers != null) { telemetryConfiguration.getTelemetryInitializers().addAll(telemetryInitializers); } if (telemetryModules != null) { telemetryConfiguration.getTelemetryModules().addAll(telemetryModules); } if (telemetryProcessors != null) { telemetryConfiguration.getTelemetryProcessors().addAll(telemetryProcessors); } telemetryConfiguration.setChannel(telemetryChannel); initializeComponents(telemetryConfiguration); initializePerformanceCounterContainer(); return telemetryConfiguration; }
@Before public void testInitialize() { configuration = new TelemetryConfiguration(); configuration.setInstrumentationKey("00000000-0000-0000-0000-000000000000"); channel = mock(TelemetryChannel.class); configuration.setChannel(channel); eventsSent = new LinkedList<Telemetry>(); // Setting the channel to add the sent telemetries to a collection, so they could be verified in tests. Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Telemetry telemetry = ((Telemetry) invocation.getArguments()[0]); eventsSent.add(telemetry); return null; } }).when(channel).send(Matchers.any(Telemetry.class)); client = new TelemetryClient(configuration); }
@Test public void testChannelSendException() { TelemetryChannel mockChannel = new TelemetryChannel() { @Override public boolean isDeveloperMode() { return false; } @Override public void setDeveloperMode(boolean value) { } @Override public void send(Telemetry item) { throw new RuntimeException(); } @Override public void stop(long timeout, TimeUnit timeUnit) { } @Override public void flush() { } @Override public void setSampler(TelemetrySampler telemetrySampler) { } }; configuration.setChannel(mockChannel); client.trackEvent("Mock"); }
private void testUseConfigurationInstrumentatonKey(String contextInstrumentationKey) { TelemetryConfiguration configuration = new TelemetryConfiguration(); TelemetryChannel mockChannel = Mockito.mock(TelemetryChannel.class); configuration.setChannel(mockChannel); configuration.setInstrumentationKey("00000000-0000-0000-0000-000000000000"); TelemetryContext mockContext = new TelemetryContext(); mockContext.setInstrumentationKey(contextInstrumentationKey); Telemetry mockTelemetry = Mockito.mock(Telemetry.class); Mockito.doReturn(mockContext).when(mockTelemetry).getContext(); TelemetryClient telemetryClient = new TelemetryClient(configuration); telemetryClient.track(mockTelemetry); Mockito.verify(mockChannel, Mockito.times(1)).send(mockTelemetry); assertEquals("00000000-0000-0000-0000-000000000000", mockContext.getInstrumentationKey()); }
@BeforeClass public static void classInitialize() throws Exception { server.start(); // Set mock channel channel = MockTelemetryChannel.INSTANCE; TelemetryConfiguration.getActive().setChannel(channel); TelemetryConfiguration.getActive().setInstrumentationKey("SOME_INT_KEY"); }
@BeforeClass public static void classInitialize() throws Exception { server.start(); // Set mock channel channel = MockTelemetryChannel.INSTANCE; TelemetryConfiguration.getActive().setChannel(channel); TelemetryConfiguration.getActive().setInstrumentationKey("SOME_INT_KEY"); }
@BeforeClass public static void classInitialize() throws Exception { server.start(); // Set mock channel channel = MockTelemetryChannel.INSTANCE; TelemetryConfiguration.getActive().setChannel(channel); TelemetryConfiguration.getActive().setInstrumentationKey("SOME_INT_KEY"); }
@BeforeClass public static void classInitialize() throws Exception { server.start(); // Set mock channel channel = MockTelemetryChannel.INSTANCE; TelemetryConfiguration.getActive().setChannel(channel); TelemetryConfiguration.getActive().setInstrumentationKey("SOME_INT_KEY"); }
@BeforeClass public static void classInitialize() throws Exception { server.start(); // Set mock channel channel = MockTelemetryChannel.INSTANCE; currentModule = getCurrentWebRequestTrackingModule(); TelemetryConfiguration.getActive().setChannel(channel); TelemetryConfiguration.getActive().setInstrumentationKey("SOME_INT_KEY"); }