();
68 | properties.put("Hometown", "Karlsruhe");
69 | ApplicationInsights.setCommonProperties(properties);
70 | ApplicationInsights.start();
71 | TelemetryClient.getInstance().trackMetric("blub", 1.0, null);
72 | }
73 |
74 | /**
75 | * Callback method from {@link ItemListFragment.Callbacks}
76 | * indicating that the item with the given ID was selected.
77 | */
78 | @Override
79 | public void onItemSelected(String id) {
80 | if (mTwoPane) {
81 | // In two-pane mode, show the detail view in this activity by
82 | // adding or replacing the detail fragment using a
83 | // fragment transaction.
84 | Bundle arguments = new Bundle();
85 | arguments.putString(ItemDetailFragment.ARG_ITEM_ID, id);
86 | ItemDetailFragment fragment = new ItemDetailFragment();
87 | fragment.setArguments(arguments);
88 | getSupportFragmentManager().beginTransaction()
89 | .replace(R.id.item_detail_container, fragment)
90 | .commit();
91 |
92 | } else {
93 | // In single-pane mode, simply start the detail activity
94 | // for the selected item ID.
95 | Intent detailIntent = new Intent(this, ItemDetailActivity.class);
96 | detailIntent.putExtra(ItemDetailFragment.ARG_ITEM_ID, id);
97 | startActivity(detailIntent);
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/app-sample/src/main/java/com/microsoft/applicationinsights/appsample/dummy/DummyContent.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.appsample.dummy;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * Helper class for providing sample content for user interfaces created by
10 | * Android template wizards.
11 | *
12 | */
13 | public class DummyContent {
14 |
15 | /**
16 | * An array of sample (dummy) items.
17 | */
18 | public static List ITEMS = new ArrayList();
19 |
20 | /**
21 | * A map of sample (dummy) items, by ID.
22 | */
23 | public static Map ITEM_MAP = new HashMap();
24 |
25 | static {
26 | addItem(new DummyItem("1", "Enable page view tracking"));
27 | addItem(new DummyItem("2", "Disable page view tracking"));
28 | addItem(new DummyItem("3", "Enable session management"));
29 | addItem(new DummyItem("4", "Disable session management"));
30 | addItem(new DummyItem("5", "Send Managed Exception"));
31 | addItem(new DummyItem("6", "Trigger Synchronize"));
32 | addItem(new DummyItem("7", "Track event"));
33 | addItem(new DummyItem("8", "Send Metric"));
34 | }
35 |
36 | private static void addItem(DummyItem item) {
37 | ITEMS.add(item);
38 | ITEM_MAP.put(item.id, item);
39 | }
40 |
41 | /**
42 | * A dummy item representing a piece of content.
43 | */
44 | public static class DummyItem {
45 | public String id;
46 | public String content;
47 |
48 | public DummyItem(String id, String content) {
49 | this.id = id;
50 | this.content = content;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return content;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/layout/activity_item_detail.xml:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/layout/activity_item_list.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/layout/activity_item_twopane.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
20 |
21 |
25 |
26 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/layout/fragment_item_detail.xml:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/ApplicationInsights-Android/54194b851acfe2af6472e9cb4e5a17a3b3fc33ec/app-sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/ApplicationInsights-Android/54194b851acfe2af6472e9cb4e5a17a3b3fc33ec/app-sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/ApplicationInsights-Android/54194b851acfe2af6472e9cb4e5a17a3b3fc33ec/app-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/ApplicationInsights-Android/54194b851acfe2af6472e9cb4e5a17a3b3fc33ec/app-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-sample/src/main/res/values-large/refs.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 | - @layout/activity_item_twopane
10 |
11 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/values-sw600dp/refs.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 | - @layout/activity_item_twopane
10 |
11 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AppSample
3 | Item Detail
4 |
5 |
--------------------------------------------------------------------------------
/app-sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/appium/device_grid_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rspec'
3 | require 'rspec/expectations'
4 | require 'appium_lib'
5 | require 'securerandom'
6 |
7 | def defaultTestRun
8 | it 'should should tap track 5 times' do
9 | list_el = text('Track event')
10 | list_el.click
11 | back
12 | list_el.click
13 | back
14 | list_el.click
15 | back
16 | list_el.click
17 | back
18 | list_el.click
19 | back
20 | end
21 |
22 | it 'should background for 3s and foreground again 3 times' do
23 | background_app(3)
24 | sleep(2)
25 | background_app(3)
26 | sleep(2)
27 | background_app(3)
28 | end
29 |
30 | it 'should should tap track 5 times' do
31 | list_el = text('Track event')
32 | list_el.click
33 | back
34 | list_el.click
35 | back
36 | list_el.click
37 | back
38 | list_el.click
39 | back
40 | list_el.click
41 | back
42 | end
43 |
44 | it 'should background for 10s and foreground again' do
45 | background_app(10)
46 | sleep(2)
47 | end
48 |
49 | it 'should trigger a sync' do
50 | list_el = text('Trigger Synchronize')
51 | list_el.click
52 | back
53 | sleep(5)
54 | list_el.click
55 | back
56 | end
57 |
58 | #end of default test run
59 | end
60 |
61 |
62 | RSpec.describe 'Run on ODL' do
63 | before(:all) do
64 | randomId = SecureRandom.uuid
65 | options = {
66 | caps: {
67 | #Appium capabilities for android app
68 | #Add
69 | app: 'URL TO APK',
70 | appPackage: 'com.microsoft.applicationinsights.sampleapp',
71 | appActivity: 'com.microsoft.applicationinsights.appsample.ItemListActivity',
72 | platform: 'WINDOWS',
73 | deviceName: 'android',
74 | platformName: 'android',
75 | #Device Lab capabilities
76 | olympusTeam: 'BingExperience',
77 | olympusSessionId: randomId,
78 | launchTimeout: 5000
79 | },
80 | appium_lib: {server_url: 'URL OF DEVICE LAB'}
81 | }
82 | # appium specific driver with helpers available
83 | @driver = Appium::Driver.new(options).start_driver
84 | @driver.manage.timeouts.implicit_wait = 10
85 | Appium.promote_appium_methods Object
86 | end
87 |
88 | after(:all) do
89 | if(@driver != nil)
90 | @driver.driver_quit
91 | end
92 | end
93 |
94 | #begin of actual tests
95 | describe 'Run default tests' do
96 | defaultTestRun
97 | it 'should crash the app' do
98 | list_el = text('Crash the App!')
99 | list_el.click
100 | end
101 | end
102 |
103 | describe 'restart' do
104 | it 'should restart the driver after a crash' do
105 | restart
106 | sleep(3)
107 | end
108 | end
109 |
110 | describe 'Run with disabled session management' do
111 | it 'Can disable session management' do
112 | list_el = text('Disable session management')
113 | list_el.click
114 | back
115 | end
116 | defaultTestRun
117 | it 'should crash the app' do
118 | list_el = text('Crash the App!')
119 | list_el.click
120 | end
121 | end
122 |
123 | describe 'restart' do
124 | it 'should restart the driver after a crash' do
125 | restart
126 | sleep(3)
127 | end
128 | end
129 |
130 | describe 'Run with re-enabled session management' do
131 | it 'Can enable session management' do
132 | list_el = text('Enable session management')
133 | list_el.click
134 | back
135 | end
136 | defaultTestRun
137 | it 'should crash the app' do
138 | list_el = text('Crash the App!')
139 | list_el.click
140 | end
141 | end
142 |
143 | describe 'restart' do
144 | it 'should restart the driver after a crash' do
145 | restart
146 | sleep(3)
147 | end
148 | end
149 |
150 | describe 'Run with disabled pageviews' do
151 | it 'Can disable pageviews' do
152 | list_el = text('Disable page view tracking')
153 | list_el.click
154 | back
155 | end
156 | defaultTestRun
157 | it 'should crash the app' do
158 | list_el = text('Crash the App!')
159 | list_el.click
160 | end
161 | end
162 |
163 | describe 'restart' do
164 | it 'should restart the driver after a crash' do
165 | restart
166 | sleep(3)
167 | end
168 | end
169 |
170 | describe 'Run with re-enabled pageviews' do
171 | it 'Can re-enable pageviews' do
172 | list_el = text('Enable page view tracking')
173 | list_el.click
174 | back
175 | end
176 | defaultTestRun
177 | it 'should crash the app' do
178 | list_el = text('Crash the App!')
179 | list_el.click
180 | end
181 | end
182 |
183 | describe 'restart' do
184 | it 'should restart the driver after a crash' do
185 | restart
186 | sleep(3)
187 | end
188 | end
189 |
190 | describe 'Run with disabled pageviews and session management' do
191 | it 'Can disable pageviews' do
192 | list_el = text('Disable page view tracking')
193 | list_el.click
194 | back
195 | end
196 | it 'Can disable session management' do
197 | list_el = text('Disable session management')
198 | list_el.click
199 | back
200 | end
201 | defaultTestRun
202 | end
203 |
204 | end
--------------------------------------------------------------------------------
/appium/local_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rspec'
3 | require 'rspec/expectations'
4 | require 'appium_lib'
5 |
6 | def defaultTestRun
7 | it 'should should tap track 5 times' do
8 | list_el = text('Track event')
9 | list_el.click
10 | back
11 | list_el.click
12 | back
13 | list_el.click
14 | back
15 | list_el.click
16 | back
17 | list_el.click
18 | back
19 | end
20 |
21 | it 'should background for 3s and foreground again 3 times' do
22 | background_app(3)
23 | sleep(2)
24 | background_app(3)
25 | sleep(2)
26 | background_app(3)
27 | end
28 |
29 | it 'should should tap track 5 times' do
30 | list_el = text('Track event')
31 | list_el.click
32 | back
33 | list_el.click
34 | back
35 | list_el.click
36 | back
37 | list_el.click
38 | back
39 | list_el.click
40 | back
41 | end
42 |
43 | it 'should background for 10s and foreground again' do
44 | background_app(10)
45 | sleep(2)
46 | end
47 |
48 | it 'should trigger a sync' do
49 | list_el = text('Trigger Synchronize')
50 | list_el.click
51 | back
52 | sleep(5)
53 | list_el.click
54 | back
55 | end
56 |
57 | #end of default test run
58 | end
59 |
60 |
61 | RSpec.describe 'Run locally' do
62 | before(:all) do
63 | options = {
64 | caps: {
65 | platformName: 'Android',
66 | app:'../app-sample/build/outputs/apk/app-sample-debug.apk',
67 | deviceName: 'appinsights-appium' #required but doesn't have to match for genymotion or android emu
68 | },
69 | launchTimeout: 5000
70 | }
71 |
72 | @driver = Appium::Driver.new(options).start_driver
73 | @driver.manage.timeouts.implicit_wait = 10
74 | Appium.promote_appium_methods Object
75 | end
76 |
77 | after(:all) do
78 | @driver.driver_quit
79 | end
80 |
81 | describe 'Run default tests' do
82 | defaultTestRun
83 | it 'should crash the app' do
84 | list_el = text('Crash the App!')
85 | list_el.click
86 | end
87 | end
88 |
89 | describe 'restart' do
90 | it 'should restart the driver after a crash' do
91 | restart
92 | sleep(3)
93 | end
94 | end
95 |
96 | describe 'Run with disabled session management' do
97 | it 'Can disable session management' do
98 | list_el = text('Disable session management')
99 | list_el.click
100 | back
101 | end
102 | defaultTestRun
103 | it 'should crash the app' do
104 | list_el = text('Crash the App!')
105 | list_el.click
106 | end
107 | end
108 |
109 | describe 'restart' do
110 | it 'should restart the driver after a crash' do
111 | restart
112 | sleep(3)
113 | end
114 | end
115 |
116 | describe 'Run with re-enabled session management' do
117 | it 'Can enable session management' do
118 | list_el = text('Enable session management')
119 | list_el.click
120 | back
121 | end
122 | defaultTestRun
123 | it 'should crash the app' do
124 | list_el = text('Crash the App!')
125 | list_el.click
126 | end
127 | end
128 |
129 | describe 'restart' do
130 | it 'should restart the driver after a crash' do
131 | restart
132 | sleep(3)
133 | end
134 | end
135 |
136 | describe 'Run with disabled pageviews' do
137 | it 'Can disable pageviews' do
138 | list_el = text('Disable page view tracking')
139 | list_el.click
140 | back
141 | end
142 | defaultTestRun
143 | it 'should crash the app' do
144 | list_el = text('Crash the App!')
145 | list_el.click
146 | end
147 | end
148 |
149 | describe 'restart' do
150 | it 'should restart the driver after a crash' do
151 | restart
152 | sleep(3)
153 | end
154 | end
155 |
156 | describe 'Run with re-enabled pageviews' do
157 | it 'Can re-enable pageviews' do
158 | list_el = text('Enable page view tracking')
159 | list_el.click
160 | back
161 | end
162 | defaultTestRun
163 | it 'should crash the app' do
164 | list_el = text('Crash the App!')
165 | list_el.click
166 | end
167 | end
168 |
169 | describe 'restart' do
170 | it 'should restart the driver after a crash' do
171 | restart
172 | sleep(3)
173 | end
174 | end
175 |
176 | describe 'Run with disabled pageviews and session management' do
177 | it 'Can disable pageviews' do
178 | list_el = text('Disable page view tracking')
179 | list_el.click
180 | back
181 | end
182 | it 'Can disable session management' do
183 | list_el = text('Disable session management')
184 | list_el.click
185 | back
186 | end
187 | defaultTestRun
188 | end
189 |
190 | end
--------------------------------------------------------------------------------
/applicationinsights-android/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/applicationinsights-android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'maven-publish'
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion "23.0.3"
8 |
9 | compileOptions {
10 | sourceCompatibility JavaVersion.VERSION_1_6
11 | targetCompatibility JavaVersion.VERSION_1_6
12 | }
13 |
14 | defaultConfig {
15 | minSdkVersion 9
16 | targetSdkVersion 23
17 | versionCode 1
18 | versionName "1.0"
19 | }
20 |
21 | buildTypes {
22 | all {
23 | manifestPlaceholders = [AI_SDK_VERSION: projectVersion]
24 | }
25 | release {
26 | minifyEnabled true
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | }
31 |
32 | // these are used by the install task to set groupId and version in the POM
33 | group = projectGroup
34 | version = projectVersion
35 | install {
36 | repositories.mavenInstaller {
37 | pom {
38 | project {
39 | packaging 'aar'
40 | name projectName
41 | description projectDesc
42 | url projectRepo
43 |
44 | licenses {
45 | license {
46 | name 'MIT'
47 | url 'http://opensource.org/licenses/MIT'
48 | }
49 | }
50 |
51 | developers {
52 | developer {
53 | id 'appinsights-android'
54 | email 'appinsights-android@microsoft.com'
55 | }
56 | }
57 |
58 | scm {
59 | connection projectRepo + '.git'
60 | developerConnection projectRepo + '.git'
61 | url projectRepo
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
68 | if (!this.hasProperty('bintray_user') ||
69 | !this.hasProperty('bintray_key') ||
70 | !this.hasProperty('bintray_gpg_passphrase') ||
71 | !this.hasProperty('sonatype_user') ||
72 | !this.hasProperty('sonatype_key')) {
73 |
74 | println 'to enable bintray set bintray_user, bintray_key, bintray_gpg_passphrase, sonatype_user, and sonatype_key'
75 | } else {
76 | bintray {
77 | user = bintray_user
78 | key = bintray_key
79 |
80 | dryRun = false // Whether to run this as dry-run, without deploying
81 | publish = true // If version should be auto published after an upload
82 |
83 | configurations = ['archives']
84 |
85 | pkg {
86 | repo = 'maven'
87 | name = projectName
88 | desc = projectDesc
89 | websiteUrl = projectRepo
90 | issueTrackerUrl = projectRepo + '/issues'
91 | vcsUrl = projectRepo + '.git'
92 | licenses = ['MIT']
93 | labels = ['Application Insights', 'AppInsights', 'Monitoring', 'Microsoft', 'Android']
94 | publicDownloadNumbers = true
95 |
96 | version {
97 | name = projectVersion
98 | vcsTag = projectVersion
99 | gpg {
100 | sign = true
101 | passphrase = bintray_gpg_passphrase
102 | }
103 | mavenCentralSync {
104 | sync = false // todo: check if this is fixed; this part can't be automated yet due to bintray preventing automation of the publish step
105 | user = sonatype_user
106 | password = sonatype_key
107 | }
108 | }
109 | }
110 | }
111 | }
112 |
113 | dependencies {
114 | compile fileTree(dir: 'libs', include: ['*.jar'])
115 |
116 | compile'com.github.microsoft.telemetry-client-for-android:SharedTelemetryContracts:2.0.0'
117 | compile 'com.github.microsoft.telemetry-client-for-android:AndroidCll:2.0.0'
118 |
119 | androidTestCompile 'org.mockito:mockito-core:2.0.17-beta'
120 | androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
121 | }
122 |
123 | task docs(type: Javadoc) {
124 | source = android.sourceSets.main.java.srcDirs
125 | options.links("http://d.android.com/reference/")
126 | }
127 |
128 | task docsJar(type: Jar) {
129 | classifier = 'javadoc'
130 | baseName = project.name
131 | from docs.destinationDir
132 | }
133 |
134 | task sourcesJar(type: Jar) {
135 | classifier = 'sources'
136 | baseName = project.name
137 | from android.sourceSets.main.java.srcDirs
138 | }
139 |
140 | artifacts {
141 | archives docsJar
142 | archives sourcesJar
143 | }
144 |
--------------------------------------------------------------------------------
/applicationinsights-android/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/applicationinsights/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | -keep public class * {
20 | public protected ;
21 | public protected ;
22 | }
23 |
24 | -keepattributes SourceFile,Signature,MethodParameters,Exceptions,LineNumberTable,LocalVariableTable,LocalVariableTypeTable
25 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class ApplicationTests.
11 | ///
12 | public class ApplicationTests extends TestCase
13 | {
14 | public void testVerPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | Application item = new Application();
18 | item.setVer(expected);
19 | String actual = item.getVer();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setVer(expected);
24 | actual = item.getVer();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testSerialize() throws IOException
29 | {
30 | Application item = new Application();
31 | item.setVer("Test string");
32 | StringWriter writer = new StringWriter();
33 | item.serialize(writer);
34 | String expected = "{\"ai.application.ver\":\"Test string\"}";
35 | Assert.assertEquals(expected, writer.toString());
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/BaseTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import com.microsoft.telemetry.Base;
4 |
5 | import junit.framework.Assert;
6 | import junit.framework.TestCase;
7 |
8 | import java.io.IOException;
9 | import java.io.StringWriter;
10 |
11 | ///
12 | /// Data contract test class BaseTests.
13 | ///
14 | public class BaseTests extends TestCase
15 | {
16 | public void testBase_typePropertyWorksAsExpected()
17 | {
18 | String expected = "Test string";
19 | Base item = new Base();
20 | item.setBaseType(expected);
21 | String actual = item.getBaseType();
22 | Assert.assertEquals(expected, actual);
23 |
24 | expected = "Other string";
25 | item.setBaseType(expected);
26 | actual = item.getBaseType();
27 | Assert.assertEquals(expected, actual);
28 | }
29 |
30 | public void testSerialize() throws IOException
31 | {
32 | Base item = new Base();
33 | item.setBaseType("Test string");
34 | StringWriter writer = new StringWriter();
35 | item.serialize(writer);
36 | String expected = "{\"baseType\":\"Test string\"}";
37 | Assert.assertEquals(expected, writer.toString());
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/CrashDataBinaryTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class CrashDataBinaryTests.
11 | ///
12 | public class CrashDataBinaryTests extends TestCase
13 | {
14 | public void testStart_addressPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | CrashDataBinary item = new CrashDataBinary();
18 | item.setStartAddress(expected);
19 | String actual = item.getStartAddress();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setStartAddress(expected);
24 | actual = item.getStartAddress();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testEnd_addressPropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | CrashDataBinary item = new CrashDataBinary();
32 | item.setEndAddress(expected);
33 | String actual = item.getEndAddress();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setEndAddress(expected);
38 | actual = item.getEndAddress();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testNamePropertyWorksAsExpected()
43 | {
44 | String expected = "Test string";
45 | CrashDataBinary item = new CrashDataBinary();
46 | item.setName(expected);
47 | String actual = item.getName();
48 | Assert.assertEquals(expected, actual);
49 |
50 | expected = "Other string";
51 | item.setName(expected);
52 | actual = item.getName();
53 | Assert.assertEquals(expected, actual);
54 | }
55 |
56 | public void testCpu_typePropertyWorksAsExpected()
57 | {
58 | long expected = 42;
59 | CrashDataBinary item = new CrashDataBinary();
60 | item.setCpuType(expected);
61 | long actual = item.getCpuType();
62 | Assert.assertEquals(expected, actual);
63 |
64 | expected = 13;
65 | item.setCpuType(expected);
66 | actual = item.getCpuType();
67 | Assert.assertEquals(expected, actual);
68 | }
69 |
70 | public void testCpu_sub_typePropertyWorksAsExpected()
71 | {
72 | long expected = 42;
73 | CrashDataBinary item = new CrashDataBinary();
74 | item.setCpuSubType(expected);
75 | long actual = item.getCpuSubType();
76 | Assert.assertEquals(expected, actual);
77 |
78 | expected = 13;
79 | item.setCpuSubType(expected);
80 | actual = item.getCpuSubType();
81 | Assert.assertEquals(expected, actual);
82 | }
83 |
84 | public void testUuidPropertyWorksAsExpected()
85 | {
86 | String expected = "Test string";
87 | CrashDataBinary item = new CrashDataBinary();
88 | item.setUuid(expected);
89 | String actual = item.getUuid();
90 | Assert.assertEquals(expected, actual);
91 |
92 | expected = "Other string";
93 | item.setUuid(expected);
94 | actual = item.getUuid();
95 | Assert.assertEquals(expected, actual);
96 | }
97 |
98 | public void testPathPropertyWorksAsExpected()
99 | {
100 | String expected = "Test string";
101 | CrashDataBinary item = new CrashDataBinary();
102 | item.setPath(expected);
103 | String actual = item.getPath();
104 | Assert.assertEquals(expected, actual);
105 |
106 | expected = "Other string";
107 | item.setPath(expected);
108 | actual = item.getPath();
109 | Assert.assertEquals(expected, actual);
110 | }
111 |
112 | public void testSerialize() throws IOException
113 | {
114 | CrashDataBinary item = new CrashDataBinary();
115 | item.setStartAddress("Test string");
116 | item.setEndAddress("Test string");
117 | item.setName("Test string");
118 | item.setCpuType(42);
119 | item.setCpuSubType(42);
120 | item.setUuid("Test string");
121 | item.setPath("Test string");
122 | StringWriter writer = new StringWriter();
123 | item.serialize(writer);
124 | String expected = "{\"startAddress\":\"Test string\",\"endAddress\":\"Test string\",\"name\":\"Test string\",\"cpuType\":42,\"cpuSubType\":42,\"uuid\":\"Test string\",\"path\":\"Test string\"}";
125 | Assert.assertEquals(expected, writer.toString());
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/CrashDataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 | import java.util.ArrayList;
9 |
10 | ///
11 | /// Data contract test class CrashDataTests.
12 | ///
13 | public class CrashDataTests extends TestCase
14 | {
15 | public void testVerPropertyWorksAsExpected()
16 | {
17 | int expected = 42;
18 | CrashData item = new CrashData();
19 | item.setVer(expected);
20 | int actual = item.getVer();
21 | Assert.assertEquals(expected, actual);
22 |
23 | expected = 13;
24 | item.setVer(expected);
25 | actual = item.getVer();
26 | Assert.assertEquals(expected, actual);
27 | }
28 |
29 | public void testHeadersPropertyWorksAsExpected()
30 | {
31 | CrashDataHeaders expected = new CrashDataHeaders();
32 | CrashData item = new CrashData();
33 | item.setHeaders(expected);
34 | CrashDataHeaders actual = item.getHeaders();
35 | Assert.assertEquals(expected, actual);
36 |
37 | expected = new CrashDataHeaders();
38 | item.setHeaders(expected);
39 | actual = item.getHeaders();
40 | Assert.assertEquals(expected, actual);
41 | }
42 |
43 | public void testThreadsPropertyWorksAsExpected()
44 | {
45 | CrashData item = new CrashData();
46 | ArrayList actual = (ArrayList)item.getThreads();
47 | Assert.assertNotNull(actual);
48 | }
49 |
50 | public void testBinariesPropertyWorksAsExpected()
51 | {
52 | CrashData item = new CrashData();
53 | ArrayList actual = (ArrayList)item.getBinaries();
54 | Assert.assertNotNull(actual);
55 | }
56 |
57 | public void testSerialize() throws IOException
58 | {
59 | CrashData item = new CrashData();
60 | item.setVer(42);
61 | item.setHeaders(new CrashDataHeaders());
62 | for (CrashDataThread entry : new ArrayList() {{add(new CrashDataThread());}})
63 | {
64 | item.getThreads().add(entry);
65 | }
66 | for (CrashDataBinary entry : new ArrayList() {{add(new CrashDataBinary());}})
67 | {
68 | item.getBinaries().add(entry);
69 | }
70 | StringWriter writer = new StringWriter();
71 | item.serialize(writer);
72 | String expected = "{\"ver\":42,\"headers\":{\"id\":null},\"threads\":[{\"id\":0}],\"binaries\":[{}]}";
73 | Assert.assertEquals(expected, writer.toString());
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/CrashDataThreadFrameTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 | import java.util.LinkedHashMap;
9 | import java.util.Map;
10 |
11 | ///
12 | /// Data contract test class CrashDataThreadFrameTests.
13 | ///
14 | public class CrashDataThreadFrameTests extends TestCase
15 | {
16 | public void testAddressPropertyWorksAsExpected()
17 | {
18 | String expected = "Test string";
19 | CrashDataThreadFrame item = new CrashDataThreadFrame();
20 | item.setAddress(expected);
21 | String actual = item.getAddress();
22 | Assert.assertEquals(expected, actual);
23 |
24 | expected = "Other string";
25 | item.setAddress(expected);
26 | actual = item.getAddress();
27 | Assert.assertEquals(expected, actual);
28 | }
29 |
30 | public void testSymbolPropertyWorksAsExpected()
31 | {
32 | String expected = "Test string";
33 | CrashDataThreadFrame item = new CrashDataThreadFrame();
34 | item.setSymbol(expected);
35 | String actual = item.getSymbol();
36 | Assert.assertEquals(expected, actual);
37 |
38 | expected = "Other string";
39 | item.setSymbol(expected);
40 | actual = item.getSymbol();
41 | Assert.assertEquals(expected, actual);
42 | }
43 |
44 | public void testRegistersPropertyWorksAsExpected()
45 | {
46 | CrashDataThreadFrame item = new CrashDataThreadFrame();
47 | LinkedHashMap actual = (LinkedHashMap)item.getRegisters();
48 | Assert.assertNotNull(actual);
49 | }
50 |
51 | public void testSerialize() throws IOException
52 | {
53 | CrashDataThreadFrame item = new CrashDataThreadFrame();
54 | item.setAddress("Test string");
55 | item.setSymbol("Test string");
56 | for (Map.Entry entry : new LinkedHashMap() {{put("key1", "test value 1"); put("key2", "test value 2"); }}.entrySet())
57 | {
58 | item.getRegisters().put(entry.getKey(), entry.getValue());
59 | }
60 | StringWriter writer = new StringWriter();
61 | item.serialize(writer);
62 | String expected = "{\"address\":\"Test string\",\"symbol\":\"Test string\",\"registers\":{\"key1\":\"test value 1\",\"key2\":\"test value 2\"}}";
63 | Assert.assertEquals(expected, writer.toString());
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/CrashDataThreadTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 | import java.util.ArrayList;
9 |
10 | ///
11 | /// Data contract test class CrashDataThreadTests.
12 | ///
13 | public class CrashDataThreadTests extends TestCase
14 | {
15 | public void testIdPropertyWorksAsExpected()
16 | {
17 | int expected = 42;
18 | CrashDataThread item = new CrashDataThread();
19 | item.setId(expected);
20 | int actual = item.getId();
21 | Assert.assertEquals(expected, actual);
22 |
23 | expected = 13;
24 | item.setId(expected);
25 | actual = item.getId();
26 | Assert.assertEquals(expected, actual);
27 | }
28 |
29 | public void testFramesPropertyWorksAsExpected()
30 | {
31 | CrashDataThread item = new CrashDataThread();
32 | ArrayList actual = (ArrayList)item.getFrames();
33 | Assert.assertNotNull(actual);
34 | }
35 |
36 | public void testSerialize() throws IOException
37 | {
38 | CrashDataThread item = new CrashDataThread();
39 | item.setId(42);
40 | for (CrashDataThreadFrame entry : new ArrayList() {{add(new CrashDataThreadFrame());}})
41 | {
42 | item.getFrames().add(entry);
43 | }
44 | StringWriter writer = new StringWriter();
45 | item.serialize(writer);
46 | String expected = "{\"id\":42,\"frames\":[{\"address\":null}]}";
47 | Assert.assertEquals(expected, writer.toString());
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/DataPointTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class DataPointTests.
11 | ///
12 | public class DataPointTests extends TestCase {
13 | public void testNamePropertyWorksAsExpected() {
14 | String expected = "Test string";
15 | DataPoint item = new DataPoint();
16 | item.setName(expected);
17 | String actual = item.getName();
18 | Assert.assertEquals(expected, actual);
19 |
20 | expected = "Other string";
21 | item.setName(expected);
22 | actual = item.getName();
23 | Assert.assertEquals(expected, actual);
24 | }
25 |
26 | public void testKindPropertyWorksAsExpected() {
27 | DataPoint item = new DataPoint();
28 | item.setKind(DataPointType.MEASUREMENT);
29 | int actual = item.getKind().getValue();
30 | Assert.assertEquals(DataPointType.MEASUREMENT.getValue(), actual);
31 |
32 | item.setKind(DataPointType.AGGREGATION);
33 | actual = item.getKind().getValue();
34 | Assert.assertEquals(DataPointType.AGGREGATION.getValue(), actual);
35 | }
36 |
37 | public void testValuePropertyWorksAsExpected() {
38 | double expected = 1.5;
39 | DataPoint item = new DataPoint();
40 | item.setValue(expected);
41 | double actual = item.getValue();
42 | Assert.assertEquals(expected, actual);
43 |
44 | expected = 4.8;
45 | item.setValue(expected);
46 | actual = item.getValue();
47 | Assert.assertEquals(expected, actual);
48 | }
49 |
50 | public void testCountPropertyWorksAsExpected() {
51 | Integer expected = 42;
52 | DataPoint item = new DataPoint();
53 | item.setCount(expected);
54 | Integer actual = item.getCount();
55 | Assert.assertEquals(expected, actual);
56 |
57 | expected = 13;
58 | item.setCount(expected);
59 | actual = item.getCount();
60 | Assert.assertEquals(expected, actual);
61 | }
62 |
63 | public void testMinPropertyWorksAsExpected() {
64 | Double expected = 1.5;
65 | DataPoint item = new DataPoint();
66 | item.setMin(expected);
67 | Double actual = item.getMin();
68 | Assert.assertEquals(expected, actual);
69 |
70 | expected = 4.8;
71 | item.setMin(expected);
72 | actual = item.getMin();
73 | Assert.assertEquals(expected, actual);
74 | }
75 |
76 | public void testMaxPropertyWorksAsExpected() {
77 | Double expected = 1.5;
78 | DataPoint item = new DataPoint();
79 | item.setMax(expected);
80 | Double actual = item.getMax();
81 | Assert.assertEquals(expected, actual);
82 |
83 | expected = 4.8;
84 | item.setMax(expected);
85 | actual = item.getMax();
86 | Assert.assertEquals(expected, actual);
87 | }
88 |
89 | public void testStd_devPropertyWorksAsExpected() {
90 | Double expected = 1.5;
91 | DataPoint item = new DataPoint();
92 | item.setStdDev(expected);
93 | Double actual = item.getStdDev();
94 | Assert.assertEquals(expected, actual);
95 |
96 | expected = 4.8;
97 | item.setStdDev(expected);
98 | actual = item.getStdDev();
99 | Assert.assertEquals(expected, actual);
100 | }
101 |
102 | public void testSerializeMeasurement() throws IOException {
103 | DataPoint item = new DataPoint();
104 | item.setName("Test string");
105 | item.setKind(DataPointType.MEASUREMENT);
106 | item.setValue(1.5);
107 | item.setCount(42);
108 | item.setMin(1.5);
109 | item.setMax(1.5);
110 | item.setStdDev(1.5);
111 | StringWriter writer = new StringWriter();
112 | item.serialize(writer);
113 | String expected = "{\"name\":\"Test string\",\"value\":1.5,\"count\":42,\"min\":1.5,\"max\":1.5,\"stdDev\":1.5}";
114 | Assert.assertEquals(expected, writer.toString());
115 | }
116 |
117 | public void testSerializeAggregation() throws IOException {
118 | DataPoint item = new DataPoint();
119 | item.setName("Test string");
120 | item.setKind(DataPointType.AGGREGATION);
121 | item.setValue(1.5);
122 | item.setCount(42);
123 | item.setMin(1.5);
124 | item.setMax(1.5);
125 | item.setStdDev(1.5);
126 | StringWriter writer = new StringWriter();
127 | item.serialize(writer);
128 | String expected = "{\"name\":\"Test string\",\"kind\":1,\"value\":1.5,\"count\":42,\"min\":1.5,\"max\":1.5,\"stdDev\":1.5}";
129 | Assert.assertEquals(expected, writer.toString());
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/DataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import com.microsoft.telemetry.Data;
4 | import com.microsoft.telemetry.Domain;
5 | import com.microsoft.telemetry.ITelemetry;
6 |
7 | import junit.framework.Assert;
8 | import junit.framework.TestCase;
9 |
10 | import java.io.IOException;
11 | import java.io.StringWriter;
12 |
13 | ///
14 | /// Data contract test class DataTests.
15 | ///
16 | public class DataTests extends TestCase {
17 | public void testBase_dataPropertyWorksAsExpected() {
18 | ITelemetry expected = new EventData();
19 | Data item = new Data();
20 | item.setBaseData(expected);
21 | Domain actual = item.getBaseData();
22 | Assert.assertEquals(expected, actual);
23 |
24 | expected = new EventData();
25 | item.setBaseData(expected);
26 | actual = item.getBaseData();
27 | Assert.assertEquals(expected, actual);
28 | }
29 |
30 | public void testSerialize() throws IOException {
31 | Data item = new Data();
32 | item.setBaseData(new EventData());
33 | StringWriter writer = new StringWriter();
34 | item.serialize(writer);
35 | String expected = "{\"baseData\":{\"ver\":2,\"name\":null}}";
36 | Assert.assertEquals(expected, writer.toString());
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/DomainTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import com.microsoft.telemetry.Domain;
4 |
5 | import junit.framework.Assert;
6 | import junit.framework.TestCase;
7 |
8 | import java.io.IOException;
9 | import java.io.StringWriter;
10 |
11 | ///
12 | /// Data contract test class DomainTests.
13 | ///
14 | public class DomainTests extends TestCase
15 | {
16 | public void testSerialize() throws IOException
17 | {
18 | Domain item = new Domain();
19 | StringWriter writer = new StringWriter();
20 | item.serialize(writer);
21 | String expected = "{}";
22 | Assert.assertEquals(expected, writer.toString());
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/EventDataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 | import java.util.LinkedHashMap;
9 | import java.util.Map;
10 |
11 | ///
12 | /// Data contract test class EventDataTests.
13 | ///
14 | public class EventDataTests extends TestCase
15 | {
16 | public void testVerPropertyWorksAsExpected()
17 | {
18 | int expected = 42;
19 | EventData item = new EventData();
20 | item.setVer(expected);
21 | int actual = item.getVer();
22 | Assert.assertEquals(expected, actual);
23 |
24 | expected = 13;
25 | item.setVer(expected);
26 | actual = item.getVer();
27 | Assert.assertEquals(expected, actual);
28 | }
29 |
30 | public void testNamePropertyWorksAsExpected()
31 | {
32 | String expected = "Test string";
33 | EventData item = new EventData();
34 | item.setName(expected);
35 | String actual = item.getName();
36 | Assert.assertEquals(expected, actual);
37 |
38 | expected = "Other string";
39 | item.setName(expected);
40 | actual = item.getName();
41 | Assert.assertEquals(expected, actual);
42 | }
43 |
44 | public void testPropertiesPropertyWorksAsExpected()
45 | {
46 | EventData item = new EventData();
47 | LinkedHashMap actual = (LinkedHashMap)item.getProperties();
48 | Assert.assertNotNull(actual);
49 | }
50 |
51 | public void testMeasurementsPropertyWorksAsExpected()
52 | {
53 | EventData item = new EventData();
54 | LinkedHashMap actual = (LinkedHashMap)item.getMeasurements();
55 | Assert.assertNotNull(actual);
56 | }
57 |
58 | public void testSerialize() throws IOException
59 | {
60 | EventData item = new EventData();
61 | item.setVer(42);
62 | item.setName("Test string");
63 | for (Map.Entry entry : new LinkedHashMap() {{put("key1", "test value 1"); put("key2", "test value 2"); }}.entrySet())
64 | {
65 | item.getProperties().put(entry.getKey(), entry.getValue());
66 | }
67 | for (Map.Entry entry : new LinkedHashMap() {{put("key1", 3.1415); put("key2", 42.2); }}.entrySet())
68 | {
69 | item.getMeasurements().put(entry.getKey(), entry.getValue());
70 | }
71 | StringWriter writer = new StringWriter();
72 | item.serialize(writer);
73 | String expected = "{\"ver\":42,\"name\":\"Test string\",\"properties\":{\"key1\":\"test value 1\",\"key2\":\"test value 2\"},\"measurements\":{\"key1\":3.1415,\"key2\":42.2}}";
74 | Assert.assertEquals(expected, writer.toString());
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/ExceptionDetailsTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 | import java.util.ArrayList;
9 |
10 | ///
11 | /// Data contract test class ExceptionDetailsTests.
12 | ///
13 | public class ExceptionDetailsTests extends TestCase
14 | {
15 | public void testIdPropertyWorksAsExpected()
16 | {
17 | int expected = 42;
18 | ExceptionDetails item = new ExceptionDetails();
19 | item.setId(expected);
20 | int actual = item.getId();
21 | Assert.assertEquals(expected, actual);
22 |
23 | expected = 13;
24 | item.setId(expected);
25 | actual = item.getId();
26 | Assert.assertEquals(expected, actual);
27 | }
28 |
29 | public void testOuter_idPropertyWorksAsExpected()
30 | {
31 | int expected = 42;
32 | ExceptionDetails item = new ExceptionDetails();
33 | item.setOuterId(expected);
34 | int actual = item.getOuterId();
35 | Assert.assertEquals(expected, actual);
36 |
37 | expected = 13;
38 | item.setOuterId(expected);
39 | actual = item.getOuterId();
40 | Assert.assertEquals(expected, actual);
41 | }
42 |
43 | public void testType_namePropertyWorksAsExpected()
44 | {
45 | String expected = "Test string";
46 | ExceptionDetails item = new ExceptionDetails();
47 | item.setTypeName(expected);
48 | String actual = item.getTypeName();
49 | Assert.assertEquals(expected, actual);
50 |
51 | expected = "Other string";
52 | item.setTypeName(expected);
53 | actual = item.getTypeName();
54 | Assert.assertEquals(expected, actual);
55 | }
56 |
57 | public void testMessagePropertyWorksAsExpected()
58 | {
59 | String expected = "Test string";
60 | ExceptionDetails item = new ExceptionDetails();
61 | item.setMessage(expected);
62 | String actual = item.getMessage();
63 | Assert.assertEquals(expected, actual);
64 |
65 | expected = "Other string";
66 | item.setMessage(expected);
67 | actual = item.getMessage();
68 | Assert.assertEquals(expected, actual);
69 | }
70 |
71 | public void testHas_full_stackPropertyWorksAsExpected()
72 | {
73 | boolean expected = true;
74 | ExceptionDetails item = new ExceptionDetails();
75 | item.setHasFullStack(expected);
76 | boolean actual = item.getHasFullStack();
77 | Assert.assertEquals(expected, actual);
78 |
79 | expected = false;
80 | item.setHasFullStack(expected);
81 | actual = item.getHasFullStack();
82 | Assert.assertEquals(expected, actual);
83 | }
84 |
85 | public void testStackPropertyWorksAsExpected()
86 | {
87 | String expected = "Test string";
88 | ExceptionDetails item = new ExceptionDetails();
89 | item.setStack(expected);
90 | String actual = item.getStack();
91 | Assert.assertEquals(expected, actual);
92 |
93 | expected = "Other string";
94 | item.setStack(expected);
95 | actual = item.getStack();
96 | Assert.assertEquals(expected, actual);
97 | }
98 |
99 | public void testParsed_stackPropertyWorksAsExpected()
100 | {
101 | ExceptionDetails item = new ExceptionDetails();
102 | ArrayList actual = (ArrayList)item.getParsedStack();
103 | Assert.assertNotNull(actual);
104 | }
105 |
106 | public void testSerialize() throws IOException
107 | {
108 | ExceptionDetails item = new ExceptionDetails();
109 | item.setId(42);
110 | item.setOuterId(42);
111 | item.setTypeName("Test string");
112 | item.setMessage("Test string");
113 | item.setHasFullStack(true);
114 | item.setStack("Test string");
115 | for (StackFrame entry : new ArrayList() {{add(new StackFrame());}})
116 | {
117 | item.getParsedStack().add(entry);
118 | }
119 | StringWriter writer = new StringWriter();
120 | item.serialize(writer);
121 | String expected = "{\"id\":42,\"outerId\":42,\"typeName\":\"Test string\",\"message\":\"Test string\",\"hasFullStack\":true,\"stack\":\"Test string\",\"parsedStack\":[{\"level\":0,\"method\":null}]}";
122 | Assert.assertEquals(expected, writer.toString());
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/InternalTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class InternalTests.
11 | ///
12 | public class InternalTests extends TestCase
13 | {
14 | public void testSdk_versionPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | Internal item = new Internal();
18 | item.setSdkVersion(expected);
19 | String actual = item.getSdkVersion();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setSdkVersion(expected);
24 | actual = item.getSdkVersion();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testAgent_versionPropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | Internal item = new Internal();
32 | item.setAgentVersion(expected);
33 | String actual = item.getAgentVersion();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setAgentVersion(expected);
38 | actual = item.getAgentVersion();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testSerialize() throws IOException
43 | {
44 | Internal item = new Internal();
45 | item.setSdkVersion("Test string");
46 | item.setAgentVersion("Test string");
47 | StringWriter writer = new StringWriter();
48 | item.serialize(writer);
49 | String expected = "{\"ai.internal.sdkVersion\":\"Test string\",\"ai.internal.agentVersion\":\"Test string\"}";
50 | Assert.assertEquals(expected, writer.toString());
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/LocationTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class LocationTests.
11 | ///
12 | public class LocationTests extends TestCase
13 | {
14 | public void testIpPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | Location item = new Location();
18 | item.setIp(expected);
19 | String actual = item.getIp();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setIp(expected);
24 | actual = item.getIp();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testSerialize() throws IOException
29 | {
30 | Location item = new Location();
31 | item.setIp("Test string");
32 | StringWriter writer = new StringWriter();
33 | item.serialize(writer);
34 | String expected = "{\"ai.location.ip\":\"Test string\"}";
35 | Assert.assertEquals(expected, writer.toString());
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/MessageDataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 | import java.util.LinkedHashMap;
9 | import java.util.Map;
10 |
11 | ///
12 | /// Data contract test class MessageDataTests.
13 | ///
14 | public class MessageDataTests extends TestCase {
15 | public void testVerPropertyWorksAsExpected() {
16 | int expected = 42;
17 | MessageData item = new MessageData();
18 | item.setVer(expected);
19 | int actual = item.getVer();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = 13;
23 | item.setVer(expected);
24 | actual = item.getVer();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testMessagePropertyWorksAsExpected() {
29 | String expected = "Test string";
30 | MessageData item = new MessageData();
31 | item.setMessage(expected);
32 | String actual = item.getMessage();
33 | Assert.assertEquals(expected, actual);
34 |
35 | expected = "Other string";
36 | item.setMessage(expected);
37 | actual = item.getMessage();
38 | Assert.assertEquals(expected, actual);
39 | }
40 |
41 | public void testSeverity_levelPropertyWorksAsExpected() {
42 | SeverityLevel expected = SeverityLevel.CRITICAL;
43 | MessageData item = new MessageData();
44 | item.setSeverityLevel(expected);
45 | SeverityLevel actual = item.getSeverityLevel();
46 | Assert.assertEquals(expected.getValue(), actual.getValue());
47 |
48 | expected = SeverityLevel.ERROR;
49 | item.setSeverityLevel(expected);
50 | actual = item.getSeverityLevel();
51 | Assert.assertEquals(expected.getValue(), actual.getValue());
52 | }
53 |
54 | public void testPropertiesPropertyWorksAsExpected() {
55 | MessageData item = new MessageData();
56 | LinkedHashMap actual = (LinkedHashMap) item.getProperties();
57 | Assert.assertNotNull(actual);
58 | }
59 |
60 | public void testSerialize() throws IOException {
61 | MessageData item = new MessageData();
62 | item.setVer(42);
63 | item.setMessage("Test string");
64 | item.setSeverityLevel(SeverityLevel.CRITICAL);
65 | for (Map.Entry entry : new LinkedHashMap() {{
66 | put("key1", "test value 1");
67 | put("key2", "test value 2");
68 | }}.entrySet()) {
69 | item.getProperties().put(entry.getKey(), entry.getValue());
70 | }
71 | StringWriter writer = new StringWriter();
72 | item.serialize(writer);
73 | String expected = "{\"ver\":42,\"message\":\"Test string\",\"severityLevel\":4,\"properties\":{\"key1\":\"test value 1\",\"key2\":\"test value 2\"}}";
74 | Assert.assertEquals(expected, writer.toString());
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/MetricDataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 | import java.util.ArrayList;
9 | import java.util.LinkedHashMap;
10 | import java.util.Map;
11 |
12 | ///
13 | /// Data contract test class MetricDataTests.
14 | ///
15 | public class MetricDataTests extends TestCase
16 | {
17 | public void testVerPropertyWorksAsExpected()
18 | {
19 | int expected = 42;
20 | MetricData item = new MetricData();
21 | item.setVer(expected);
22 | int actual = item.getVer();
23 | Assert.assertEquals(expected, actual);
24 |
25 | expected = 13;
26 | item.setVer(expected);
27 | actual = item.getVer();
28 | Assert.assertEquals(expected, actual);
29 | }
30 |
31 | public void testMetricsPropertyWorksAsExpected()
32 | {
33 | MetricData item = new MetricData();
34 | ArrayList actual = (ArrayList)item.getMetrics();
35 | Assert.assertNotNull(actual);
36 | }
37 |
38 | public void testPropertiesPropertyWorksAsExpected()
39 | {
40 | MetricData item = new MetricData();
41 | LinkedHashMap actual = (LinkedHashMap)item.getProperties();
42 | Assert.assertNotNull(actual);
43 | }
44 |
45 | public void testSerialize() throws IOException
46 | {
47 | MetricData item = new MetricData();
48 | item.setVer(42);
49 | for (DataPoint entry : new ArrayList() {{add(new DataPoint());}})
50 | {
51 | item.getMetrics().add(entry);
52 | }
53 | for (Map.Entry entry : new LinkedHashMap() {{put("key1", "test value 1"); put("key2", "test value 2"); }}.entrySet())
54 | {
55 | item.getProperties().put(entry.getKey(), entry.getValue());
56 | }
57 | StringWriter writer = new StringWriter();
58 | item.serialize(writer);
59 | String expected = "{\"ver\":42,\"metrics\":[{\"name\":null,\"value\":0.0}],\"properties\":{\"key1\":\"test value 1\",\"key2\":\"test value 2\"}}";
60 | Assert.assertEquals(expected, writer.toString());
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/OperationTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class OperationTests.
11 | ///
12 | public class OperationTests extends TestCase
13 | {
14 | public void testIdPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | Operation item = new Operation();
18 | item.setId(expected);
19 | String actual = item.getId();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setId(expected);
24 | actual = item.getId();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testNamePropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | Operation item = new Operation();
32 | item.setName(expected);
33 | String actual = item.getName();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setName(expected);
38 | actual = item.getName();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testParent_idPropertyWorksAsExpected()
43 | {
44 | String expected = "Test string";
45 | Operation item = new Operation();
46 | item.setParentId(expected);
47 | String actual = item.getParentId();
48 | Assert.assertEquals(expected, actual);
49 |
50 | expected = "Other string";
51 | item.setParentId(expected);
52 | actual = item.getParentId();
53 | Assert.assertEquals(expected, actual);
54 | }
55 |
56 | public void testRoot_idPropertyWorksAsExpected()
57 | {
58 | String expected = "Test string";
59 | Operation item = new Operation();
60 | item.setRootId(expected);
61 | String actual = item.getRootId();
62 | Assert.assertEquals(expected, actual);
63 |
64 | expected = "Other string";
65 | item.setRootId(expected);
66 | actual = item.getRootId();
67 | Assert.assertEquals(expected, actual);
68 | }
69 |
70 | public void testSerialize() throws IOException
71 | {
72 | Operation item = new Operation();
73 | item.setId("Test string");
74 | item.setName("Test string");
75 | item.setParentId("Test string");
76 | item.setRootId("Test string");
77 | StringWriter writer = new StringWriter();
78 | item.serialize(writer);
79 | String expected = "{\"ai.operation.id\":\"Test string\",\"ai.operation.name\":\"Test string\",\"ai.operation.parentId\":\"Test string\",\"ai.operation.rootId\":\"Test string\"}";
80 | Assert.assertEquals(expected, writer.toString());
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/PageViewDataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class PageViewDataTests.
11 | ///
12 | public class PageViewDataTests extends TestCase
13 | {
14 | public void testUrlPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | PageViewData item = new PageViewData();
18 | item.setUrl(expected);
19 | String actual = item.getUrl();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setUrl(expected);
24 | actual = item.getUrl();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testDurationPropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | PageViewData item = new PageViewData();
32 | item.setDuration(expected);
33 | String actual = item.getDuration();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setDuration(expected);
38 | actual = item.getDuration();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testSerialize() throws IOException
43 | {
44 | PageViewData item = new PageViewData();
45 | item.setUrl("Test string");
46 | item.setDuration("Test string");
47 | StringWriter writer = new StringWriter();
48 | item.serialize(writer);
49 | String expected = "{\"ver\":2,\"name\":null,\"url\":\"Test string\",\"duration\":\"Test string\"}";
50 | Assert.assertEquals(expected, writer.toString());
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/PageViewPerfDataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class PageViewPerfDataTests.
11 | ///
12 | public class PageViewPerfDataTests extends TestCase
13 | {
14 | public void testPerf_totalPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | PageViewPerfData item = new PageViewPerfData();
18 | item.setPerfTotal(expected);
19 | String actual = item.getPerfTotal();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setPerfTotal(expected);
24 | actual = item.getPerfTotal();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testNetwork_connectPropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | PageViewPerfData item = new PageViewPerfData();
32 | item.setNetworkConnect(expected);
33 | String actual = item.getNetworkConnect();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setNetworkConnect(expected);
38 | actual = item.getNetworkConnect();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testSent_requestPropertyWorksAsExpected()
43 | {
44 | String expected = "Test string";
45 | PageViewPerfData item = new PageViewPerfData();
46 | item.setSentRequest(expected);
47 | String actual = item.getSentRequest();
48 | Assert.assertEquals(expected, actual);
49 |
50 | expected = "Other string";
51 | item.setSentRequest(expected);
52 | actual = item.getSentRequest();
53 | Assert.assertEquals(expected, actual);
54 | }
55 |
56 | public void testReceived_responsePropertyWorksAsExpected()
57 | {
58 | String expected = "Test string";
59 | PageViewPerfData item = new PageViewPerfData();
60 | item.setReceivedResponse(expected);
61 | String actual = item.getReceivedResponse();
62 | Assert.assertEquals(expected, actual);
63 |
64 | expected = "Other string";
65 | item.setReceivedResponse(expected);
66 | actual = item.getReceivedResponse();
67 | Assert.assertEquals(expected, actual);
68 | }
69 |
70 | public void testDom_processingPropertyWorksAsExpected()
71 | {
72 | String expected = "Test string";
73 | PageViewPerfData item = new PageViewPerfData();
74 | item.setDomProcessing(expected);
75 | String actual = item.getDomProcessing();
76 | Assert.assertEquals(expected, actual);
77 |
78 | expected = "Other string";
79 | item.setDomProcessing(expected);
80 | actual = item.getDomProcessing();
81 | Assert.assertEquals(expected, actual);
82 | }
83 |
84 | public void testSerialize() throws IOException
85 | {
86 | PageViewPerfData item = new PageViewPerfData();
87 | item.setPerfTotal("Test string");
88 | item.setNetworkConnect("Test string");
89 | item.setSentRequest("Test string");
90 | item.setReceivedResponse("Test string");
91 | item.setDomProcessing("Test string");
92 | StringWriter writer = new StringWriter();
93 | item.serialize(writer);
94 | String expected = "{\"ver\":2,\"name\":null,\"perfTotal\":\"Test string\",\"networkConnect\":\"Test string\",\"sentRequest\":\"Test string\",\"receivedResponse\":\"Test string\",\"domProcessing\":\"Test string\"}";
95 | Assert.assertEquals(expected, writer.toString());
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/SessionStateDataTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class SessionStateDataTests.
11 | ///
12 | public class SessionStateDataTests extends TestCase {
13 | public void testVerPropertyWorksAsExpected() {
14 | int expected = 42;
15 | SessionStateData item = new SessionStateData();
16 | item.setVer(expected);
17 | int actual = item.getVer();
18 | Assert.assertEquals(expected, actual);
19 |
20 | expected = 13;
21 | item.setVer(expected);
22 | actual = item.getVer();
23 | Assert.assertEquals(expected, actual);
24 | }
25 |
26 | public void testStatePropertyWorksAsExpected() {
27 | SessionState expected = SessionState.START;
28 | SessionStateData item = new SessionStateData();
29 | item.setState(expected);
30 | SessionState actual = item.getState();
31 | Assert.assertEquals(expected.getValue(), actual.getValue());
32 |
33 | expected = SessionState.END;
34 | item.setState(expected);
35 | actual = item.getState();
36 | Assert.assertEquals(expected.getValue(), actual.getValue());
37 | }
38 |
39 | public void testSerialize() throws IOException {
40 | SessionStateData item = new SessionStateData();
41 | item.setVer(42);
42 | item.setState(SessionState.START);
43 | StringWriter writer = new StringWriter();
44 | item.serialize(writer);
45 | String expected = "{\"ver\":42,\"state\":0}";
46 | Assert.assertEquals(expected, writer.toString());
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/SessionTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class SessionTests.
11 | ///
12 | public class SessionTests extends TestCase
13 | {
14 | public void testIdPropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | Session item = new Session();
18 | item.setId(expected);
19 | String actual = item.getId();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setId(expected);
24 | actual = item.getId();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testIs_firstPropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | Session item = new Session();
32 | item.setIsFirst(expected);
33 | String actual = item.getIsFirst();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setIsFirst(expected);
38 | actual = item.getIsFirst();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testIs_newPropertyWorksAsExpected()
43 | {
44 | String expected = "Test string";
45 | Session item = new Session();
46 | item.setIsNew(expected);
47 | String actual = item.getIsNew();
48 | Assert.assertEquals(expected, actual);
49 |
50 | expected = "Other string";
51 | item.setIsNew(expected);
52 | actual = item.getIsNew();
53 | Assert.assertEquals(expected, actual);
54 | }
55 |
56 | public void testSerialize() throws IOException
57 | {
58 | Session item = new Session();
59 | item.setId("Test string");
60 | item.setIsFirst("Test string");
61 | item.setIsNew("Test string");
62 | StringWriter writer = new StringWriter();
63 | item.serialize(writer);
64 | String expected = "{\"ai.session.id\":\"Test string\",\"ai.session.isFirst\":\"Test string\",\"ai.session.isNew\":\"Test string\"}";
65 | Assert.assertEquals(expected, writer.toString());
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/StackFrameTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class StackFrameTests.
11 | ///
12 | public class StackFrameTests extends TestCase
13 | {
14 | public void testLevelPropertyWorksAsExpected()
15 | {
16 | int expected = 42;
17 | StackFrame item = new StackFrame();
18 | item.setLevel(expected);
19 | int actual = item.getLevel();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = 13;
23 | item.setLevel(expected);
24 | actual = item.getLevel();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testMethodPropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | StackFrame item = new StackFrame();
32 | item.setMethod(expected);
33 | String actual = item.getMethod();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setMethod(expected);
38 | actual = item.getMethod();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testAssemblyPropertyWorksAsExpected()
43 | {
44 | String expected = "Test string";
45 | StackFrame item = new StackFrame();
46 | item.setAssembly(expected);
47 | String actual = item.getAssembly();
48 | Assert.assertEquals(expected, actual);
49 |
50 | expected = "Other string";
51 | item.setAssembly(expected);
52 | actual = item.getAssembly();
53 | Assert.assertEquals(expected, actual);
54 | }
55 |
56 | public void testFile_namePropertyWorksAsExpected()
57 | {
58 | String expected = "Test string";
59 | StackFrame item = new StackFrame();
60 | item.setFileName(expected);
61 | String actual = item.getFileName();
62 | Assert.assertEquals(expected, actual);
63 |
64 | expected = "Other string";
65 | item.setFileName(expected);
66 | actual = item.getFileName();
67 | Assert.assertEquals(expected, actual);
68 | }
69 |
70 | public void testLinePropertyWorksAsExpected()
71 | {
72 | int expected = 42;
73 | StackFrame item = new StackFrame();
74 | item.setLine(expected);
75 | int actual = item.getLine();
76 | Assert.assertEquals(expected, actual);
77 |
78 | expected = 13;
79 | item.setLine(expected);
80 | actual = item.getLine();
81 | Assert.assertEquals(expected, actual);
82 | }
83 |
84 | public void testSerialize() throws IOException
85 | {
86 | StackFrame item = new StackFrame();
87 | item.setLevel(42);
88 | item.setMethod("Test string");
89 | item.setAssembly("Test string");
90 | item.setFileName("Test string");
91 | item.setLine(42);
92 | StringWriter writer = new StringWriter();
93 | item.serialize(writer);
94 | String expected = "{\"level\":42,\"method\":\"Test string\",\"assembly\":\"Test string\",\"fileName\":\"Test string\",\"line\":42}";
95 | Assert.assertEquals(expected, writer.toString());
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/contracts/UserTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.io.IOException;
7 | import java.io.StringWriter;
8 |
9 | ///
10 | /// Data contract test class UserTests.
11 | ///
12 | public class UserTests extends TestCase
13 | {
14 | public void testAccount_acquisition_datePropertyWorksAsExpected()
15 | {
16 | String expected = "Test string";
17 | User item = new User();
18 | item.setAccountAcquisitionDate(expected);
19 | String actual = item.getAccountAcquisitionDate();
20 | Assert.assertEquals(expected, actual);
21 |
22 | expected = "Other string";
23 | item.setAccountAcquisitionDate(expected);
24 | actual = item.getAccountAcquisitionDate();
25 | Assert.assertEquals(expected, actual);
26 | }
27 |
28 | public void testAccount_idPropertyWorksAsExpected()
29 | {
30 | String expected = "Test string";
31 | User item = new User();
32 | item.setAccountId(expected);
33 | String actual = item.getAccountId();
34 | Assert.assertEquals(expected, actual);
35 |
36 | expected = "Other string";
37 | item.setAccountId(expected);
38 | actual = item.getAccountId();
39 | Assert.assertEquals(expected, actual);
40 | }
41 |
42 | public void testUser_agentPropertyWorksAsExpected()
43 | {
44 | String expected = "Test string";
45 | User item = new User();
46 | item.setUserAgent(expected);
47 | String actual = item.getUserAgent();
48 | Assert.assertEquals(expected, actual);
49 |
50 | expected = "Other string";
51 | item.setUserAgent(expected);
52 | actual = item.getUserAgent();
53 | Assert.assertEquals(expected, actual);
54 | }
55 |
56 | public void testIdPropertyWorksAsExpected()
57 | {
58 | String expected = "Test string";
59 | User item = new User();
60 | item.setId(expected);
61 | String actual = item.getId();
62 | Assert.assertEquals(expected, actual);
63 |
64 | expected = "Other string";
65 | item.setId(expected);
66 | actual = item.getId();
67 | Assert.assertEquals(expected, actual);
68 | }
69 |
70 | public void testSerialize() throws IOException
71 | {
72 | User item = new User();
73 | item.setAccountAcquisitionDate("Test string");
74 | item.setAccountId("Test string");
75 | item.setUserAgent("Test string");
76 | item.setId("Test string");
77 | StringWriter writer = new StringWriter();
78 | item.serialize(writer);
79 | String expected = "{\"ai.user.accountAcquisitionDate\":\"Test string\",\"ai.user.accountId\":\"Test string\",\"ai.user.userAgent\":\"Test string\",\"ai.user.id\":\"Test string\"}";
80 | Assert.assertEquals(expected, writer.toString());
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/ChannelManagerTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | public class ChannelManagerTest extends TestCase {
7 |
8 | public void testGetSetDefaultChannelManager() {
9 | ChannelManager.initialize(ChannelType.Default);
10 | ChannelManager channelManager = ChannelManager.getInstance();
11 | Assert.assertNotNull(channelManager);
12 | }
13 |
14 | public void testGetSetTelemetryClientChannelManager() {
15 | ChannelManager.initialize(ChannelType.CommonLoggingLibraryChannel);
16 | ChannelManager channelManager = ChannelManager.getInstance();
17 | Assert.assertNotNull(channelManager);
18 | }
19 |
20 | public void testNullChannelType() {
21 | ChannelManager.initialize(null);
22 | ChannelManager channelManager = ChannelManager.getInstance();
23 |
24 | // If null is passed in we revert to using the default channel instead of throwing an exception
25 | Assert.assertNotNull(channelManager);
26 | }
27 |
28 | public void testUninitializedChannelManager() {
29 | ChannelManager.getInstance().reset();
30 | ChannelManager channelManager = ChannelManager.getInstance();
31 | Assert.assertNull(channelManager);
32 | }
33 |
34 | public void testReinitializeChannelManager() {
35 | ChannelManager.initialize(ChannelType.Default);
36 | ChannelManager defaultChannelManager = ChannelManager.getInstance();
37 | Assert.assertNotNull(defaultChannelManager);
38 |
39 | ChannelManager.initialize(ChannelType.CommonLoggingLibraryChannel);
40 | ChannelManager telemetryClientChannelManager = ChannelManager.getInstance();
41 | Assert.assertNotNull(defaultChannelManager);
42 |
43 | // You can only initialize once so the object returned should be the same.
44 | Assert.assertSame(defaultChannelManager, telemetryClientChannelManager);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/ChannelQueueTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.test.InstrumentationTestCase;
4 |
5 | import com.microsoft.applicationinsights.library.config.IQueueConfig;
6 |
7 | import junit.framework.Assert;
8 |
9 | import static org.mockito.Matchers.any;
10 | import static org.mockito.Matchers.anyBoolean;
11 | import static org.mockito.Mockito.after;
12 | import static org.mockito.Mockito.mock;
13 | import static org.mockito.Mockito.never;
14 | import static org.mockito.Mockito.verify;
15 | import static org.mockito.Mockito.when;
16 | import static org.mockito.internal.verification.VerificationModeFactory.times;
17 |
18 | public class ChannelQueueTest extends InstrumentationTestCase {
19 |
20 | private PublicChannelQueue sut;
21 | private IQueueConfig mockConfig;
22 | private PublicPersistence mockPersistence;
23 |
24 | public void setUp() throws Exception {
25 | super.setUp();
26 | System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());
27 | mockConfig = mock(IQueueConfig.class);
28 | sut = new PublicChannelQueue(mockConfig);
29 | mockPersistence = mock(PublicPersistence.class);
30 | sut.setPersistence(mockPersistence);
31 | }
32 |
33 | public void testInitialisationWorks() {
34 | Assert.assertNotNull(sut.config);
35 | Assert.assertNotNull(sut.timer);
36 | Assert.assertNotNull(sut.list);
37 | Assert.assertEquals(0, sut.list.size());
38 | Assert.assertFalse(sut.isCrashing);
39 | }
40 |
41 | public void testItemGetsEnqueued() {
42 | // Setup
43 | when(mockConfig.getMaxBatchIntervalMs()).thenReturn(10000);
44 | when(mockConfig.getMaxBatchCount()).thenReturn(3);
45 |
46 | // Test
47 | sut.enqueue("");
48 | sut.enqueue("");
49 |
50 | // Verify
51 | Assert.assertEquals(2, sut.list.size());
52 | }
53 |
54 | public void testQueueFlushedIfMaxBatchCountReached() {
55 | // Setup
56 | when(mockConfig.getMaxBatchIntervalMs()).thenReturn(10000);
57 | when(mockConfig.getMaxBatchCount()).thenReturn(3);
58 |
59 | // Test
60 | sut.enqueue("");
61 | sut.enqueue("");
62 |
63 | // Verify
64 | Assert.assertEquals(2, sut.list.size());
65 | verify(mockPersistence, never()).persist(any(String[].class), anyBoolean());
66 |
67 | sut.enqueue("");
68 |
69 | Assert.assertEquals(0, sut.list.size());
70 | verify(mockPersistence, times(1)).persist(any(String[].class), anyBoolean());
71 | }
72 |
73 | public void testQueueFlushedAfterBatchIntervalReached() {
74 | // Setup
75 | when(mockConfig.getMaxBatchIntervalMs()).thenReturn(200);
76 | when(mockConfig.getMaxBatchCount()).thenReturn(3);
77 |
78 | // Test
79 | sut.enqueue("");
80 |
81 | // Verify
82 | Assert.assertEquals(1, sut.list.size());
83 | verify(mockPersistence, never()).persist(any(String[].class), anyBoolean());
84 | verify(mockPersistence, after(250).times(1)).persist(any(String[].class), anyBoolean());
85 | Assert.assertEquals(0, sut.list.size());
86 | }
87 |
88 | public void testFlushingQueueWorks() {
89 | //Setup
90 | when(mockConfig.getMaxBatchIntervalMs()).thenReturn(200);
91 | when(mockConfig.getMaxBatchCount()).thenReturn(3);
92 |
93 | sut.enqueue("");
94 | Assert.assertEquals(1, sut.list.size());
95 | verify(mockPersistence, never()).persist(any(String[].class), anyBoolean());
96 |
97 | // Test
98 | sut.flush();
99 |
100 | // Verify
101 | Assert.assertEquals(0, sut.list.size());
102 | verify(mockPersistence, times(1)).persist(any(String[].class), anyBoolean());
103 | }
104 |
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/ChannelTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.test.InstrumentationTestCase;
4 |
5 | import static org.mockito.Mockito.mock;
6 | import static org.mockito.Mockito.times;
7 | import static org.mockito.Mockito.verify;
8 |
9 | public class ChannelTest extends InstrumentationTestCase {
10 |
11 | private Channel sut;
12 | private PublicChannelQueue mockQueue;
13 | private PublicPersistence mockPersistence;
14 |
15 | public void setUp() throws Exception {
16 | super.setUp();
17 | System.setProperty("dexmaker.dexcache",getInstrumentation().getTargetContext().getCacheDir().getPath());
18 | sut = new Channel();
19 | mockQueue = mock(PublicChannelQueue.class);
20 | sut.setQueue(mockQueue);
21 | mockPersistence = mock(PublicPersistence.class);
22 | sut.setPersistence(mockPersistence);
23 | }
24 |
25 | public void testSynchronizeFlushesQueue(){
26 | // Test
27 | sut.synchronize();
28 |
29 | // Verify
30 | verify(mockQueue, times(1)).flush();
31 | }
32 |
33 | public void testEnqueuedItemIsAddedToQueue(){
34 | // // Test
35 | // Data testItem1 = new Data();
36 | // sut.log(testItem1, null);
37 | // Data testItem2 = new Data();
38 | // sut.log(testItem2, null);
39 | //
40 | // // Verify
41 | // verify(mockQueue, times(1)).enqueue(testItem1);
42 | // verify(mockQueue, times(1)).enqueue(testItem2);
43 | }
44 |
45 | public void testProcessUnhandledExceptionIsPersistedDirectly(){
46 | // // Test
47 | // Data testItem1 = new Data();
48 | // sut.processException(testItem1);
49 | //
50 | // // Verify
51 | // verify(mockQueue, times(0)).enqueue(testItem1);
52 | // verify(mockPersistence, times(1)).persist(any(IJsonSerializable[].class), eq(true));
53 | }
54 |
55 | public void testQueueFlushesWhenProcessingCrash(){
56 | // // Setup
57 | // Data testItem1 = new Data();
58 | //
59 | // // Test
60 | // sut.processException(testItem1);
61 | //
62 | // // Verify
63 | // verify(mockQueue, times(0)).enqueue(testItem1);
64 | // verify(mockQueue, times(1)).flush();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/MockActivity.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.app.Activity;
4 |
5 | public class MockActivity extends Activity {
6 |
7 | public MockActivity() {
8 | super();
9 | }
10 | }
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/MockApplication.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.app.Application;
4 |
5 | public class MockApplication extends Application {
6 | @Override
7 | public void onCreate() {
8 | super.onCreate();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/MockChannel.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | public class MockChannel extends Channel {
4 | public MockChannel() {
5 | super();
6 | }
7 |
8 | @Override
9 | public void setQueue(ChannelQueue queue) {
10 | super.setQueue(queue);
11 | }
12 |
13 | public static MockChannel getInstance() {
14 | return (MockChannel)Channel.getInstance();
15 | }
16 | }
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/MockSender.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import com.microsoft.applicationinsights.library.config.ISenderConfig;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 | import java.io.Writer;
8 | import java.net.HttpURLConnection;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.concurrent.CountDownLatch;
12 |
13 | public class MockSender extends Sender {
14 |
15 | public int responseCode;
16 | public CountDownLatch sendSignal;
17 | public CountDownLatch responseSignal;
18 | public List payloads;
19 | public List responses;
20 | public List responseCodes;
21 |
22 | public MockSender(int count,
23 | ISenderConfig config) {
24 | super(config);
25 | this.responseCode = 0;
26 | this.sendSignal = new CountDownLatch(count);
27 | this.responseSignal = new CountDownLatch(count);
28 | this.payloads = new ArrayList();
29 | this.responses = new ArrayList();
30 | this.responseCodes = new ArrayList();
31 | this.setInstance(this);
32 | }
33 |
34 | // make singleton getter here
35 |
36 | public void flush(int count) {
37 | for(int i = 0; i < count; i++) {
38 | super.sendNextFile();
39 | }
40 | }
41 |
42 | @Override
43 | protected void sendRequestWithPayload(String payload, File fileToSend) throws IOException {
44 | super.sendRequestWithPayload(payload, fileToSend);
45 | this.payloads.add(prettyPrintJSON(payload));
46 | this.sendSignal.countDown();
47 | }
48 |
49 | @Override
50 | protected void onResponse(HttpURLConnection connection, int responseCode, String payload, File fileToSend) {
51 | super.onResponse(connection, responseCode, payload, fileToSend);
52 | this.responseCodes.add(responseCode);
53 | this.responseSignal.countDown();
54 | }
55 |
56 | @Override
57 | protected void readResponse(HttpURLConnection connection, StringBuilder builder) {
58 | super.readResponse(connection, builder);
59 | this.responses.add(prettyPrintJSON(builder.toString()));
60 | }
61 |
62 | private String prettyPrintJSON(String payload) {
63 | if (payload == null)
64 | return "";
65 |
66 | char[] chars = payload.toCharArray();
67 | StringBuilder sb = new StringBuilder();
68 | String tabs = "";
69 |
70 | // logcat doesn't like leading spaces, so add '|' to the start of each line
71 | String logCatNewLine = "\n|";
72 | sb.append(logCatNewLine);
73 | for (char c : chars) {
74 | switch (c) {
75 | case '[':
76 | case '{':
77 | tabs += "\t";
78 | sb.append(" ").append(c).append(logCatNewLine).append(tabs);
79 | break;
80 | case ']':
81 | case '}':
82 | tabs = tabs.substring(0, tabs.length() - 1);
83 | sb.append(logCatNewLine).append(tabs).append(c);
84 | break;
85 | case ',':
86 | sb.append(c).append(logCatNewLine).append(tabs);
87 | break;
88 | default:
89 | sb.append(c);
90 | }
91 | }
92 |
93 | String result = sb.toString();
94 | result.replaceAll("\t", " ");
95 |
96 | return result;
97 | }
98 |
99 | private class WriterListener extends Writer {
100 |
101 | private Writer baseWriter;
102 | private StringBuilder stringBuilder;
103 |
104 | public WriterListener(Writer baseWriter) {
105 | this.baseWriter = baseWriter;
106 | this.stringBuilder = new StringBuilder();
107 | }
108 |
109 | @Override
110 | public void close() throws IOException {
111 | baseWriter.close();
112 | }
113 |
114 | @Override
115 | public void flush() throws IOException {
116 | baseWriter.flush();
117 | }
118 |
119 | @Override
120 | public void write(char[] buf, int offset, int count) throws IOException {
121 | stringBuilder.append(buf);
122 | baseWriter.write(buf);
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/MockTelemetryClient.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import com.microsoft.telemetry.Data;
4 | import com.microsoft.telemetry.Domain;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Map;
8 |
9 | public class MockTelemetryClient extends TelemetryClient {
10 | public ArrayList> messages;
11 | public boolean mockTrackMethod;
12 |
13 | /**
14 | * Restrict access to the default constructor
15 | *
16 | * @param telemetryEnabled YES if tracking telemetry data manually should be enabled
17 | */
18 | protected MockTelemetryClient(boolean telemetryEnabled) {
19 | super(telemetryEnabled);
20 | }
21 |
22 | // private static MockTelemetryClient instance;
23 | //
24 | // /**
25 | // * Volatile boolean for double checked synchronize block
26 | // */
27 | // private static volatile boolean isTelemetryClientLoaded = false;
28 | //
29 | // /**
30 | // * Synchronization LOCK for setting static context
31 | // */
32 | // private static final Object LOCK = new Object();
33 | //
34 | // /**
35 | // * Restrict access to the default constructor
36 | // */
37 | // protected MockTelemetryClient() {
38 | // }
39 | //
40 | // /**
41 | // * Initialize the INSTANCE of the telemetryclient
42 | // */
43 | // protected static void initialize() {
44 | // // note: isPersistenceLoaded must be volatile for the double-checked LOCK to work
45 | // if (!MockTelemetryClient.isTelemetryClientLoaded) {
46 | // synchronized (MockTelemetryClient.LOCK) {
47 | // if (!MockTelemetryClient.isTelemetryClientLoaded) {
48 | // MockTelemetryClient.isTelemetryClientLoaded = true;
49 | // MockTelemetryClient.instance = new MockTelemetryClient();
50 | // }
51 | // }
52 | // }
53 | // }
54 |
55 | /**
56 | * @return the INSTANCE of persistence or null if not yet initialized
57 | */
58 | public static MockTelemetryClient getInstance() {
59 | // initialize();
60 | // if (MockTelemetryClient.instance == null) {
61 | // InternalLogging.error(TAG, "getSharedInstance was called before initialization");
62 | // }
63 | //
64 | // return MockTelemetryClient.instance;
65 | MockTelemetryClient mClient = new MockTelemetryClient(true);
66 | mClient.messages = new ArrayList>();
67 | return mClient;
68 | }
69 |
70 |
71 | //TODO fix unit tests
72 |
73 | @Override
74 | public void trackEvent(
75 | String eventName,
76 | Map properties,
77 | Map measurements) {
78 | if(this.mockTrackMethod) {
79 | messages.add(EnvelopeFactory.getInstance().createEventData(eventName, properties, measurements));
80 | }else{
81 | super.trackEvent(eventName, properties, measurements);
82 | }
83 | }
84 |
85 | @Override
86 | public void trackTrace(String message, Map properties) {
87 | if(this.mockTrackMethod) {
88 | messages.add(EnvelopeFactory.getInstance().createTraceData(message, properties));
89 | }else{
90 | super.trackTrace(message, properties);
91 | }
92 | }
93 |
94 | @Override
95 | public void trackMetric(String name, double value) {
96 | if(this.mockTrackMethod) {
97 | messages.add(EnvelopeFactory.getInstance().createMetricData(name, value, null));
98 | }else{
99 | super.trackMetric(name, value);
100 | }
101 | }
102 |
103 |
104 | @Override
105 | public void trackNewSession() {
106 | if(this.mockTrackMethod) {
107 | messages.add(EnvelopeFactory.getInstance().createNewSessionData());
108 | }else{
109 | super.trackNewSession();
110 | }
111 | }
112 |
113 | public ArrayList> getMessages()
114 | {
115 | return messages;
116 | }
117 |
118 | public void clearMessages()
119 | {
120 | messages.clear();
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/PersistenceTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.test.AndroidTestCase;
4 |
5 | import junit.framework.Assert;
6 |
7 | import java.io.File;
8 |
9 | public class PersistenceTest extends AndroidTestCase {
10 |
11 | public void setUp() throws Exception {
12 | super.setUp();
13 | Persistence.initialize(this.getContext());
14 | Persistence persistence = Persistence.getInstance();
15 |
16 | while(persistence.nextAvailableFile() != null) {
17 | File file = persistence.nextAvailableFile();
18 | persistence.deleteFile(file);
19 | }
20 |
21 | }
22 |
23 | public void testGetInstance() throws Exception {
24 | Persistence persistence = Persistence.getInstance();
25 | Assert.assertNotNull(persistence);
26 | }
27 |
28 | public void testSaveAndGetData() throws Exception {
29 | Persistence persistence = Persistence.getInstance();
30 |
31 | String data = "SAVE THIS DATA";
32 | persistence.writeToDisk(data, false);
33 | File file = persistence.nextAvailableFile();
34 | Assert.assertEquals("Data retrieved from file is equal to data saved", data, persistence.load(file));
35 | }
36 | }
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/PublicChannel.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | public class PublicChannel extends Channel {
4 |
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/PublicChannelQueue.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import com.microsoft.applicationinsights.library.config.IQueueConfig;
4 |
5 | public class PublicChannelQueue extends ChannelQueue {
6 | protected PublicChannelQueue(IQueueConfig config) {
7 | super(config);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/PublicEnvelopeFactory.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import java.util.Map;
4 |
5 | public class PublicEnvelopeFactory extends EnvelopeFactory{
6 |
7 | protected PublicEnvelopeFactory(TelemetryContext telemetryContext, Map commonProperties) {
8 | super(telemetryContext, commonProperties);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/PublicPersistence.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.content.Context;
4 |
5 | public class PublicPersistence extends Persistence {
6 | protected PublicPersistence(Context context) {
7 | super(context);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/PublicTelemetryContext.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.content.Context;
4 |
5 | import com.microsoft.applicationinsights.contracts.User;
6 |
7 | public class PublicTelemetryContext extends TelemetryContext {
8 | public PublicTelemetryContext(Context appContext, String instrumentationKey, User user) {
9 | super(appContext, instrumentationKey, user);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/SenderTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import com.microsoft.applicationinsights.library.config.Configuration;
4 |
5 | import junit.framework.Assert;
6 | import junit.framework.TestCase;
7 |
8 | public class SenderTest extends TestCase {
9 |
10 | private Sender sut;
11 |
12 | public void setUp() throws Exception {
13 | super.setUp();
14 | Configuration config = new Configuration();
15 | this.sut = new Sender(config);
16 | }
17 |
18 | public void testInitialisationWorks() {
19 | Assert.assertNotNull(sut.config);
20 | Assert.assertNotNull(sut.persistence);
21 | }
22 |
23 | public void testCallGetInstanceTwiceReturnsSameObject() {
24 |
25 | Sender.initialize(new Configuration());
26 | Sender sender1 = Sender.getInstance();
27 | Sender sender2 = Sender.getInstance();
28 |
29 | Assert.assertSame(sender1, sender2);
30 | }
31 |
32 | public void testExpectedResponseCode() {
33 | for (int statusCode = 100; statusCode <= 510; statusCode++) {
34 | if (199 < statusCode && statusCode <= 203) {
35 | assertTrue(sut.isExpected(statusCode));
36 | } else {
37 | assertFalse(sut.isExpected(statusCode));
38 | }
39 | }
40 | }
41 |
42 | public void testRecoverableResponseCode() {
43 | for (int statusCode = 100; statusCode <= 510; statusCode++) {
44 | if ((statusCode == 429) || (statusCode == 408) || (statusCode == 500) || (statusCode == 503) || (statusCode == 511)) {
45 | assertTrue(sut.isRecoverableError(statusCode));
46 | } else {
47 | assertFalse(sut.isRecoverableError(statusCode));
48 | }
49 | }
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/TelemetryClientTestE2E.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.test.ApplicationTestCase;
4 | import android.util.Log;
5 |
6 | import com.microsoft.applicationinsights.library.config.Configuration;
7 |
8 | import junit.framework.Assert;
9 |
10 | import java.util.LinkedHashMap;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | public class TelemetryClientTestE2E extends ApplicationTestCase {
14 |
15 | private static int batchCount = 10;
16 | private LinkedHashMap properties;
17 | private LinkedHashMap measurements;
18 | public TelemetryClientTestE2E() {
19 | super(MockApplication.class);
20 | }
21 |
22 | public void setUp() throws Exception {
23 | super.setUp();
24 |
25 | ApplicationInsights.setup(this.getContext(), this.getApplication());
26 | ApplicationInsights.setDeveloperMode(true);
27 |
28 | Configuration config = ApplicationInsights.getConfiguration();
29 | config.setEndpointUrl(config.getEndpointUrl().replace("https", "http"));
30 | config.setMaxBatchIntervalMs(10);
31 | config.setMaxBatchCount(batchCount);
32 |
33 | ApplicationInsights.start();
34 |
35 | this.properties = new LinkedHashMap();
36 | this.properties.put("core property", "core value");
37 | this.measurements = new LinkedHashMap();
38 | this.measurements.put("core measurement", 5.5);
39 | }
40 |
41 | public void testTrackEvent() throws Exception {
42 | TelemetryClient.getInstance().trackEvent(null);
43 | TelemetryClient.getInstance().trackEvent("event1");
44 | TelemetryClient.getInstance().trackEvent("event2", properties);
45 | TelemetryClient.getInstance().trackEvent("event3", properties, measurements);
46 | Thread.sleep(50);
47 | this.validate(1);
48 | }
49 |
50 | public void testTrackTrace() throws Exception {
51 | TelemetryClient.getInstance().trackTrace(null);
52 | TelemetryClient.getInstance().trackTrace("trace1");
53 | TelemetryClient.getInstance().trackTrace("trace2", properties);
54 | Thread.sleep(50);
55 | this.validate(1);
56 | }
57 |
58 | public void testTrackMetric() throws Exception {
59 | TelemetryClient.getInstance().trackMetric(null, 0);
60 | TelemetryClient.getInstance().trackMetric("metric1", 1.1);
61 | TelemetryClient.getInstance().trackMetric("metric2", 3);
62 | TelemetryClient.getInstance().trackMetric("metric3", 3.3);
63 | TelemetryClient.getInstance().trackMetric("metric3", 4);
64 | Thread.sleep(50);
65 | this.validate(1);
66 | }
67 |
68 | public void testTrackPageView() throws Exception {
69 | TelemetryClient.getInstance().trackPageView("android page");
70 | Thread.sleep(50);
71 | this.validate(1);
72 | }
73 |
74 | public void testTrackAllRequests() throws Exception {
75 | ((Channel) Channel.getInstance()).queue.config.setMaxBatchCount(10);
76 | for (int i = 0; i < batchCount; i++) {
77 | TelemetryClient.getInstance().trackEvent("android event");
78 | TelemetryClient.getInstance().trackTrace("android trace");
79 | TelemetryClient.getInstance().trackMetric("android metric", 0.0);
80 | TelemetryClient.getInstance().trackPageView("android page");
81 | Thread.sleep(10);
82 | }
83 |
84 | Thread.sleep(50);
85 | this.validate(1);
86 | }
87 |
88 | public void validate(int count) {
89 | try {
90 | Configuration config = new Configuration();
91 | MockSender sender = new MockSender(count, config);
92 |
93 | sender.flush(count);
94 |
95 | // wait 30 seconds for all responses
96 | sender.responseSignal.await(5, TimeUnit.SECONDS);
97 |
98 | if (sender.responseSignal.getCount() != 0) {
99 | Log.w("BACKEND_ERROR", "response count is lower than enqueue count");
100 | }
101 |
102 | for (int i = 0; i < count; i++) {
103 | if (i < sender.responseCodes.size()) {
104 | Assert.assertTrue("response is 206, some telemetry was rejected",
105 | sender.responseCodes.get(i) == 200);
106 | }
107 | }
108 |
109 | Assert.assertEquals("response was received", 0, sender.responseSignal.getCount());
110 | } catch (InterruptedException e) {
111 | Assert.fail(e.toString());
112 | }
113 | }
114 | }
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/TelemetryContextTests.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.test.AndroidTestCase;
4 | import com.microsoft.applicationinsights.contracts.User;
5 | import junit.framework.Assert;
6 |
7 | public class TelemetryContextTests extends AndroidTestCase {
8 |
9 | private TelemetryContext sut;
10 |
11 | public void setUp() throws Exception {
12 | super.setUp();
13 | TelemetryContext.initialize(getContext(), "iKey", null);
14 | sut = TelemetryContext.getSharedInstance();
15 | resetUserContext();
16 |
17 | }
18 |
19 | public void testNewUserContext(){
20 | // validate
21 | Assert.assertNull(sut.getAccountId());
22 | Assert.assertNull(sut.getUserAcqusitionDate());
23 | Assert.assertNull(sut.getUserId());
24 | Assert.assertNull(sut.getAuthenticatedUserId());
25 | Assert.assertNull(sut.getAuthenticatedUserAcquisitionDate());
26 | Assert.assertNull(sut.getAnonymousUserAcquisitionDate());
27 | }
28 |
29 | public void testSavingAndLoadingUserContextWorks(){
30 |
31 | // prepare
32 | String accountId = "accountId";
33 | String acquisitionDateString = "acqusitionDate";
34 | String userId = "userId";
35 | String authenticatedUserId = "authenticatedUserId";
36 | String authenticatedUserAcqDate = "authenticatedUserAcqDate";
37 | String anonUserAcquDate = "anonUserAcquDate";
38 |
39 | //save user context
40 | sut.setAccountId(accountId);
41 | sut.setUserAcqusitionDate(acquisitionDateString);
42 | sut.setUserId(userId);
43 | sut.setAuthenticatedUserId(authenticatedUserId);
44 | sut.setAuthenticatedUserAcquisitionDate(authenticatedUserAcqDate);
45 | sut.setAnonymousUserAcquisitionDate(anonUserAcquDate);
46 |
47 | // simulate existing user info
48 | User user = null;
49 | sut.configUserContext(user);
50 |
51 | // verify
52 | Assert.assertEquals(accountId, sut.getAccountId());
53 | Assert.assertEquals(acquisitionDateString, sut.getUserAcqusitionDate());
54 | Assert.assertEquals(userId, sut.getUserId());
55 | Assert.assertEquals(authenticatedUserId, sut.getAuthenticatedUserId());
56 | Assert.assertEquals(authenticatedUserAcqDate, sut.getAuthenticatedUserAcquisitionDate());
57 | Assert.assertEquals(anonUserAcquDate, sut.getAnonymousUserAcquisitionDate());
58 | }
59 |
60 | public void testNewInstanceGetsSetupWithSharedInstance(){
61 |
62 | // setup
63 | TelemetryContext newInstance = TelemetryContext.newInstance();
64 |
65 | // verify
66 | Assert.assertEquals(sut.getDeviceModel(), newInstance.getDeviceModel());
67 | Assert.assertEquals(sut.getAccountId(), newInstance.getAccountId());
68 | Assert.assertEquals(sut.getUserAcqusitionDate(), newInstance.getUserAcqusitionDate());
69 | Assert.assertEquals(sut.getUserId(), newInstance.getUserId());
70 | Assert.assertEquals(sut.getAuthenticatedUserId(), newInstance.getAuthenticatedUserId());
71 | Assert.assertEquals(sut.getAuthenticatedUserAcquisitionDate(), newInstance.getAuthenticatedUserAcquisitionDate());
72 | Assert.assertEquals(sut.getAnonymousUserAcquisitionDate(), newInstance.getAnonymousUserAcquisitionDate());
73 | }
74 |
75 | public void testNewInstanceWillNotChangeSharedInstance(){
76 | TelemetryContext newInstance = TelemetryContext.newInstance();
77 | newInstance.setDeviceModel("myDeviceModel");
78 | Assert.assertNotSame(sut.getDeviceModel(), newInstance.getDeviceModel());
79 | }
80 |
81 | public void testSharedInstanceWillNotChangeNewInstance(){
82 | TelemetryContext newInstance = TelemetryContext.newInstance();
83 | sut.setDeviceModel("myDeviceModel");
84 | Assert.assertNotSame(sut.getDeviceModel(), newInstance.getDeviceModel());
85 | }
86 |
87 | protected void tearDown (){
88 | // reset saved user context
89 | resetUserContext();
90 | }
91 |
92 | // helper
93 |
94 | protected void resetUserContext(){
95 | sut.setUserId(null);
96 | sut.setAccountId(null);
97 | sut.setUserAcqusitionDate(null);
98 | sut.setAuthenticatedUserId(null);
99 | sut.setAuthenticatedUserAcquisitionDate(null);
100 | sut.setAnonymousUserAcquisitionDate(null);
101 | User user = null;
102 | sut.configUserContext(user);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/UtilTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import junit.framework.Assert;
4 | import junit.framework.TestCase;
5 |
6 | import java.util.Date;
7 |
8 | public class UtilTest extends TestCase {
9 |
10 | public void setUp() throws Exception {
11 | super.setUp();
12 |
13 | }
14 |
15 | public void testDateToISO8601() throws Exception {
16 | Date now = new Date();
17 |
18 | String pattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z";
19 | Assert.assertTrue("now format", Util.dateToISO8601(now).matches(pattern));
20 | }
21 |
22 | public void testMsToTimeSpan() throws Exception {
23 | this.testMsToTimeSpanHelper(0, "00:00:00.000", "zero");
24 | this.testMsToTimeSpanHelper(1, "00:00:00.001", "milliseconds digit 1");
25 | this.testMsToTimeSpanHelper(10, "00:00:00.010", "milliseconds digit 2");
26 | this.testMsToTimeSpanHelper(100, "00:00:00.100", "milliseconds digit 3");
27 | this.testMsToTimeSpanHelper(1000, "00:00:01.000", "seconds digit 1");
28 | this.testMsToTimeSpanHelper(10 * 1000, "00:00:10.000", "seconds digit 2");
29 | this.testMsToTimeSpanHelper(60 * 1000, "00:01:00.000", "minutes digit 1");
30 | this.testMsToTimeSpanHelper(10 * 60 * 1000, "00:10:00.000", "minutes digit 2");
31 | this.testMsToTimeSpanHelper(60 * 60 * 1000, "01:00:00.000", "hours digit 1");
32 | this.testMsToTimeSpanHelper(10 * 60 * 60 * 1000, "10:00:00.000", "hours digit 2");
33 | this.testMsToTimeSpanHelper(24 * 60 * 60 * 1000, "1.00:00:00.000", "hours overflow");
34 | this.testMsToTimeSpanHelper(24 * 61 * 61 * 1010, "1.01:03:17.040", "hours overflow+");
35 | this.testMsToTimeSpanHelper((24 * 11 + 11) * 3600000 + 11 * 60000 + 11111,
36 | "11.11:11:11.111", "all digits");
37 |
38 | this.testMsToTimeSpanHelper(-1, "00:00:00.000", "invalid input");
39 | this.testMsToTimeSpanHelper(0xffffffff, "00:00:00.000", "invalid input");
40 | }
41 |
42 | private void testMsToTimeSpanHelper(long durationMs, String expected, String message) {
43 | String actual = Util.msToTimeSpan(durationMs);
44 | Assert.assertEquals(message, expected, actual);
45 | }
46 | }
--------------------------------------------------------------------------------
/applicationinsights-android/src/androidTest/java/com/microsoft/applicationinsights/library/config/ConfigurationTest.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library.config;
2 |
3 | import android.test.AndroidTestCase;
4 |
5 | import com.microsoft.applicationinsights.library.ApplicationInsights;
6 |
7 | public class ConfigurationTest extends AndroidTestCase {
8 |
9 | private Configuration sut;
10 | public void setUp() throws Exception {
11 | super.setUp();
12 | sut = new Configuration();
13 | ApplicationInsights.setDeveloperMode(false);
14 | }
15 |
16 | public void testInitializesCorrectly() throws Exception {
17 | assertEquals(Configuration.DEFAULT_MAX_BATCH_COUNT, sut.getMaxBatchCount());
18 | assertEquals(Configuration.DEFAULT_MAX_BATCH_INTERVAL_MS, sut.getMaxBatchIntervalMs());
19 | assertEquals(Configuration.DEFAULT_ENDPOINT_URL, sut.getEndpointUrl());
20 | assertEquals(Configuration.DEFAULT_SENDER_READ_TIMEOUT, sut.getSenderReadTimeout());
21 | assertEquals(Configuration.DEFAULT_SENDER_CONNECT_TIMEOUT, sut.getSenderConnectTimeout());
22 | assertEquals(Configuration.DEFAULT_SESSION_INTERVAL, sut.getSessionIntervalMs());
23 | }
24 |
25 | public void testReturnsDebugValuesInDevMode() throws Exception {
26 | int testBatchCount = 111;
27 | int testBatchInterval = 11111;
28 | sut.setMaxBatchIntervalMs(testBatchInterval);
29 | sut.setMaxBatchCount(testBatchCount);
30 |
31 | // if dev mode enabled, actual values should be ignored
32 | ApplicationInsights.setDeveloperMode(true);
33 | assertEquals(Configuration.DEBUG_MAX_BATCH_COUNT, sut.getMaxBatchCount());
34 | assertEquals(Configuration.DEBUG_MAX_BATCH_INTERVAL_MS, sut.getMaxBatchIntervalMs());
35 |
36 | // if dev mode disabled, actual values should be used
37 | ApplicationInsights.setDeveloperMode(false);
38 | assertEquals(testBatchCount, sut.getMaxBatchCount());
39 | assertEquals(testBatchInterval, sut.getMaxBatchIntervalMs());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/Application.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from ContextTagKeys.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.IJsonSerializable;
7 | import com.microsoft.telemetry.JsonHelper;
8 |
9 | import java.io.IOException;
10 | import java.io.Serializable;
11 | import java.io.Writer;
12 | import java.util.Map;
13 |
14 | /**
15 | * Data contract class Application.
16 | */
17 | public class Application implements IJsonSerializable, Serializable {
18 | /**
19 | * Backing field for property Ver.
20 | */
21 | private String ver;
22 |
23 | /**
24 | * Backing field for property Build.
25 | */
26 | private String build;
27 |
28 | /**
29 | * Backing field for property TypeId.
30 | */
31 | private String typeId;
32 |
33 | /**
34 | * Initializes a new instance of the Application class.
35 | */
36 | public Application() {
37 | this.InitializeFields();
38 | }
39 |
40 | /**
41 | * Gets the Ver property.
42 | */
43 | public String getVer() {
44 | return this.ver;
45 | }
46 |
47 | /**
48 | * Sets the Ver property.
49 | */
50 | public void setVer(String value) {
51 | this.ver = value;
52 | }
53 |
54 | /**
55 | * Gets the Build property.
56 | */
57 | public String getBuild() {
58 | return this.build;
59 | }
60 |
61 | /**
62 | * Sets the Build property.
63 | */
64 | public void setBuild(String value) {
65 | this.build = value;
66 | }
67 |
68 | /**
69 | * Gets the TypeId property.
70 | */
71 | public String getTypeId() {
72 | return this.typeId;
73 | }
74 |
75 | /**
76 | * Sets the TypeId property.
77 | */
78 | public void setTypeId(String value) {
79 | this.typeId = value;
80 | }
81 |
82 |
83 | /**
84 | * Adds all members of this class to a hashmap
85 | *
86 | * @param map to which the members of this class will be added.
87 | */
88 | public void addToHashMap(Map map) {
89 | if (!(this.ver == null)) {
90 | map.put("ai.application.ver", this.ver);
91 | }
92 | if (!(this.build == null)) {
93 | map.put("ai.application.build", this.build);
94 | }
95 | if (!(this.typeId == null)) {
96 | map.put("ai.application.typeId", this.typeId);
97 | }
98 | }
99 |
100 |
101 | /**
102 | * Serializes the beginning of this object to the passed in writer.
103 | *
104 | * @param writer The writer to serialize this object to.
105 | */
106 | @Override
107 | public void serialize(Writer writer) throws IOException {
108 | if (writer == null) {
109 | throw new IllegalArgumentException("writer");
110 | }
111 |
112 | writer.write('{');
113 | this.serializeContent(writer);
114 | writer.write('}');
115 | }
116 |
117 | /**
118 | * Serializes the beginning of this object to the passed in writer.
119 | *
120 | * @param writer The writer to serialize this object to.
121 | */
122 | protected String serializeContent(Writer writer) throws IOException {
123 | String prefix = "";
124 | if (!(this.ver == null)) {
125 | writer.write(prefix + "\"ai.application.ver\":");
126 | writer.write(JsonHelper.convert(this.ver));
127 | prefix = ",";
128 | }
129 |
130 | if (!(this.build == null)) {
131 | writer.write(prefix + "\"ai.application.build\":");
132 | writer.write(JsonHelper.convert(this.build));
133 | prefix = ",";
134 | }
135 |
136 | if (!(this.typeId == null)) {
137 | writer.write(prefix + "\"ai.application.typeId\":");
138 | writer.write(JsonHelper.convert(this.typeId));
139 | prefix = ",";
140 | }
141 |
142 | return prefix;
143 | }
144 |
145 | /**
146 | * Optionally initializes fields for the current context.
147 | */
148 | protected void InitializeFields() {
149 |
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/CrashData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from CrashData.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.JsonHelper;
7 |
8 | import java.io.IOException;
9 | import java.io.Writer;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 |
15 | /**
16 | * Data contract class CrashData.
17 | */
18 | public class CrashData extends TelemetryData {
19 | /**
20 | * Backing field for property Ver.
21 | */
22 | private int ver = 2;
23 |
24 | /**
25 | * Backing field for property Headers.
26 | */
27 | private CrashDataHeaders headers;
28 |
29 | /**
30 | * Backing field for property Threads.
31 | */
32 | private List threads;
33 |
34 | /**
35 | * Backing field for property Binaries.
36 | */
37 | private List binaries;
38 |
39 | /**
40 | * Initializes a new instance of the CrashData class.
41 | */
42 | public CrashData() {
43 | this.InitializeFields();
44 | this.SetupAttributes();
45 | }
46 |
47 | /**
48 | * Gets the Ver property.
49 | */
50 | public int getVer() {
51 | return this.ver;
52 | }
53 |
54 | /**
55 | * Sets the Ver property.
56 | */
57 | public void setVer(int value) {
58 | this.ver = value;
59 | }
60 |
61 | /**
62 | * Envelope Name for this telemetry.
63 | */
64 | public String getEnvelopeName() {
65 | return "Microsoft.ApplicationInsights.Crash";
66 | }
67 |
68 | /**
69 | * Base Type for this telemetry.
70 | */
71 | public String getBaseType() {
72 | return "Microsoft.ApplicationInsights.CrashData";
73 | }
74 |
75 | /**
76 | * Gets the Headers property.
77 | */
78 | public CrashDataHeaders getHeaders() {
79 | return this.headers;
80 | }
81 |
82 | /**
83 | * Sets the Headers property.
84 | */
85 | public void setHeaders(CrashDataHeaders value) {
86 | this.headers = value;
87 | }
88 |
89 | /**
90 | * Gets the Threads property.
91 | */
92 | public List getThreads() {
93 | if (this.threads == null) {
94 | this.threads = new ArrayList();
95 | }
96 | return this.threads;
97 | }
98 |
99 | /**
100 | * Sets the Threads property.
101 | */
102 | public void setThreads(List value) {
103 | this.threads = value;
104 | }
105 |
106 | /**
107 | * Gets the Binaries property.
108 | */
109 | public List getBinaries() {
110 | if (this.binaries == null) {
111 | this.binaries = new ArrayList();
112 | }
113 | return this.binaries;
114 | }
115 |
116 | /**
117 | * Sets the Binaries property.
118 | */
119 | public void setBinaries(List value) {
120 | this.binaries = value;
121 | }
122 |
123 |
124 | /**
125 | * Gets the Properties property.
126 | */
127 | public Map getProperties() {
128 | //Do nothing - does not currently take properties
129 | return null;
130 | }
131 |
132 | /**
133 | * Sets the Properties property.
134 | */
135 | public void setProperties(Map value) {
136 | //Do nothing - does not currently take properties
137 | }
138 |
139 | /**
140 | * Serializes the beginning of this object to the passed in writer.
141 | *
142 | * @param writer The writer to serialize this object to.
143 | */
144 | protected String serializeContent(Writer writer) throws IOException {
145 | String prefix = super.serializeContent(writer);
146 | writer.write(prefix + "\"ver\":");
147 | writer.write(JsonHelper.convert(this.ver));
148 | prefix = ",";
149 |
150 | writer.write(prefix + "\"headers\":");
151 | JsonHelper.writeJsonSerializable(writer, this.headers);
152 | prefix = ",";
153 |
154 | if (!(this.threads == null)) {
155 | writer.write(prefix + "\"threads\":");
156 | JsonHelper.writeList(writer, this.threads);
157 | prefix = ",";
158 | }
159 |
160 | if (!(this.binaries == null)) {
161 | writer.write(prefix + "\"binaries\":");
162 | JsonHelper.writeList(writer, this.binaries);
163 | prefix = ",";
164 | }
165 |
166 | return prefix;
167 | }
168 |
169 | /**
170 | * Sets up the events attributes
171 | */
172 | public void SetupAttributes() {
173 | }
174 |
175 | /**
176 | * Optionally initializes fields for the current context.
177 | */
178 | protected void InitializeFields() {
179 | QualifiedName = "com.microsoft.applicationinsights.contracts.CrashData";
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/CrashDataThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from CrashDataThread.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | import java.io.IOException;
6 | import java.io.Serializable;
7 | import java.io.Writer;
8 | import java.util.List;
9 | import java.util.ArrayList;
10 |
11 | import com.microsoft.telemetry.IJsonSerializable;
12 | import com.microsoft.telemetry.JsonHelper;
13 |
14 | /**
15 | * Data contract class CrashDataThread.
16 | */
17 | public class CrashDataThread
18 | implements IJsonSerializable, Serializable
19 | {
20 | /**
21 | * Backing field for property Id.
22 | */
23 | private int id;
24 |
25 | /**
26 | * Backing field for property Frames.
27 | */
28 | private List frames;
29 |
30 | /**
31 | * Initializes a new instance of the CrashDataThread class.
32 | */
33 | public CrashDataThread()
34 | {
35 | this.InitializeFields();
36 | }
37 |
38 | /**
39 | * Gets the Id property.
40 | */
41 | public int getId() {
42 | return this.id;
43 | }
44 |
45 | /**
46 | * Sets the Id property.
47 | */
48 | public void setId(int value) {
49 | this.id = value;
50 | }
51 |
52 | /**
53 | * Gets the Frames property.
54 | */
55 | public List getFrames() {
56 | if (this.frames == null) {
57 | this.frames = new ArrayList();
58 | }
59 | return this.frames;
60 | }
61 |
62 | /**
63 | * Sets the Frames property.
64 | */
65 | public void setFrames(List value) {
66 | this.frames = value;
67 | }
68 |
69 |
70 | /**
71 | * Serializes the beginning of this object to the passed in writer.
72 | * @param writer The writer to serialize this object to.
73 | */
74 | @Override
75 | public void serialize(Writer writer) throws IOException
76 | {
77 | if (writer == null)
78 | {
79 | throw new IllegalArgumentException("writer");
80 | }
81 |
82 | writer.write('{');
83 | this.serializeContent(writer);
84 | writer.write('}');
85 | }
86 |
87 | /**
88 | * Serializes the beginning of this object to the passed in writer.
89 | * @param writer The writer to serialize this object to.
90 | */
91 | protected String serializeContent(Writer writer) throws IOException
92 | {
93 | String prefix = "";
94 | writer.write(prefix + "\"id\":");
95 | writer.write(JsonHelper.convert(this.id));
96 | prefix = ",";
97 |
98 | if (!(this.frames == null))
99 | {
100 | writer.write(prefix + "\"frames\":");
101 | JsonHelper.writeList(writer, this.frames);
102 | prefix = ",";
103 | }
104 |
105 | return prefix;
106 | }
107 |
108 | /**
109 | * Optionally initializes fields for the current context.
110 | */
111 | protected void InitializeFields() {
112 |
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/CrashDataThreadFrame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from CrashDataThreadFrame.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | import java.io.IOException;
6 | import java.io.Serializable;
7 | import java.io.Writer;
8 | import java.util.Map;
9 | import java.util.LinkedHashMap;
10 |
11 | import com.microsoft.telemetry.IJsonSerializable;
12 | import com.microsoft.telemetry.JsonHelper;
13 |
14 | /**
15 | * Data contract class CrashDataThreadFrame.
16 | */
17 | public class CrashDataThreadFrame
18 | implements IJsonSerializable, Serializable
19 | {
20 | /**
21 | * Backing field for property Address.
22 | */
23 | private String address;
24 |
25 | /**
26 | * Backing field for property Symbol.
27 | */
28 | private String symbol;
29 |
30 | /**
31 | * Backing field for property Registers.
32 | */
33 | private Map registers;
34 |
35 | /**
36 | * Initializes a new instance of the CrashDataThreadFrame class.
37 | */
38 | public CrashDataThreadFrame()
39 | {
40 | this.InitializeFields();
41 | }
42 |
43 | /**
44 | * Gets the Address property.
45 | */
46 | public String getAddress() {
47 | return this.address;
48 | }
49 |
50 | /**
51 | * Sets the Address property.
52 | */
53 | public void setAddress(String value) {
54 | this.address = value;
55 | }
56 |
57 | /**
58 | * Gets the Symbol property.
59 | */
60 | public String getSymbol() {
61 | return this.symbol;
62 | }
63 |
64 | /**
65 | * Sets the Symbol property.
66 | */
67 | public void setSymbol(String value) {
68 | this.symbol = value;
69 | }
70 |
71 | /**
72 | * Gets the Registers property.
73 | */
74 | public Map getRegisters() {
75 | if (this.registers == null) {
76 | this.registers = new LinkedHashMap();
77 | }
78 | return this.registers;
79 | }
80 |
81 | /**
82 | * Sets the Registers property.
83 | */
84 | public void setRegisters(Map value) {
85 | this.registers = value;
86 | }
87 |
88 |
89 | /**
90 | * Serializes the beginning of this object to the passed in writer.
91 | * @param writer The writer to serialize this object to.
92 | */
93 | @Override
94 | public void serialize(Writer writer) throws IOException
95 | {
96 | if (writer == null)
97 | {
98 | throw new IllegalArgumentException("writer");
99 | }
100 |
101 | writer.write('{');
102 | this.serializeContent(writer);
103 | writer.write('}');
104 | }
105 |
106 | /**
107 | * Serializes the beginning of this object to the passed in writer.
108 | * @param writer The writer to serialize this object to.
109 | */
110 | protected String serializeContent(Writer writer) throws IOException
111 | {
112 | String prefix = "";
113 | writer.write(prefix + "\"address\":");
114 | writer.write(JsonHelper.convert(this.address));
115 | prefix = ",";
116 |
117 | if (!(this.symbol == null))
118 | {
119 | writer.write(prefix + "\"symbol\":");
120 | writer.write(JsonHelper.convert(this.symbol));
121 | prefix = ",";
122 | }
123 |
124 | if (!(this.registers == null))
125 | {
126 | writer.write(prefix + "\"registers\":");
127 | JsonHelper.writeDictionary(writer, this.registers);
128 | prefix = ",";
129 | }
130 |
131 | return prefix;
132 | }
133 |
134 | /**
135 | * Optionally initializes fields for the current context.
136 | */
137 | protected void InitializeFields() {
138 |
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/DataPointType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | /**
6 | * Enum DataPointType.
7 | */
8 | public enum DataPointType
9 | {
10 | MEASUREMENT(0), AGGREGATION(1);
11 |
12 | private final int value;
13 | private DataPointType(int value) {
14 | this.value = value;
15 | }
16 |
17 | public int getValue() {
18 | return value;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/DependencyKind.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from DependencyKind.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | /**
7 | * Enum DependencyKind.
8 | */
9 | public enum DependencyKind {
10 | SQL(0), HTTP(1), OTHER(2);
11 |
12 | private final int value;
13 |
14 | private DependencyKind(int value) {
15 | this.value = value;
16 | }
17 |
18 | public int getValue() {
19 | return value;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/DependencySourceType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | /**
7 | * Enum DependencySourceType.
8 | */
9 | public enum DependencySourceType {
10 | UNDEFINED(0), AIC(1), APMC(2);
11 |
12 | private final int value;
13 |
14 | private DependencySourceType(int value) {
15 | this.value = value;
16 | }
17 |
18 | public int getValue() {
19 | return value;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/EventData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.JsonHelper;
7 |
8 | import java.io.IOException;
9 | import java.io.Writer;
10 | import java.util.LinkedHashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * Data contract class EventData.
15 | */
16 | public class EventData extends TelemetryData {
17 | /**
18 | * Backing field for property Ver.
19 | */
20 | private int ver = 2;
21 |
22 | /**
23 | * Backing field for property Name.
24 | */
25 | private String name;
26 |
27 | /**
28 | * Backing field for property Properties.
29 | */
30 | private Map properties;
31 |
32 | /**
33 | * Backing field for property Measurements.
34 | */
35 | private Map measurements;
36 |
37 | /**
38 | * Initializes a new instance of the EventData class.
39 | */
40 | public EventData() {
41 | this.InitializeFields();
42 | this.SetupAttributes();
43 | }
44 |
45 | /**
46 | * Envelope Name for this telemetry.
47 | */
48 | public String getEnvelopeName() {
49 | return "Microsoft.ApplicationInsights.Event";
50 | }
51 |
52 | /**
53 | * Base Type for this telemetry.
54 | */
55 | public String getBaseType() {
56 | return "Microsoft.ApplicationInsights.EventData";
57 | }
58 |
59 | /**
60 | * Gets the Ver property.
61 | */
62 | public int getVer() {
63 | return this.ver;
64 | }
65 |
66 | /**
67 | * Sets the Ver property.
68 | */
69 | public void setVer(int value) {
70 | this.ver = value;
71 | }
72 |
73 | /**
74 | * Gets the Name property.
75 | */
76 | public String getName() {
77 | return this.name;
78 | }
79 |
80 | /**
81 | * Sets the Name property.
82 | */
83 | public void setName(String value) {
84 | this.name = value;
85 | }
86 |
87 | /**
88 | * Gets the Properties property.
89 | */
90 | public Map getProperties() {
91 | if (this.properties == null) {
92 | this.properties = new LinkedHashMap();
93 | }
94 | return this.properties;
95 | }
96 |
97 | /**
98 | * Sets the Properties property.
99 | */
100 | public void setProperties(Map value) {
101 | this.properties = value;
102 | }
103 |
104 | /**
105 | * Gets the Measurements property.
106 | */
107 | public Map getMeasurements() {
108 | if (this.measurements == null) {
109 | this.measurements = new LinkedHashMap();
110 | }
111 | return this.measurements;
112 | }
113 |
114 | /**
115 | * Sets the Measurements property.
116 | */
117 | public void setMeasurements(Map value) {
118 | this.measurements = value;
119 | }
120 |
121 |
122 | /**
123 | * Serializes the beginning of this object to the passed in writer.
124 | *
125 | * @param writer The writer to serialize this object to.
126 | */
127 | protected String serializeContent(Writer writer) throws IOException {
128 | String prefix = super.serializeContent(writer);
129 | writer.write(prefix + "\"ver\":");
130 | writer.write(JsonHelper.convert(this.ver));
131 | prefix = ",";
132 |
133 | writer.write(prefix + "\"name\":");
134 | writer.write(JsonHelper.convert(this.name));
135 | prefix = ",";
136 |
137 | if (!(this.properties == null)) {
138 | writer.write(prefix + "\"properties\":");
139 | JsonHelper.writeDictionary(writer, this.properties);
140 | prefix = ",";
141 | }
142 |
143 | if (!(this.measurements == null)) {
144 | writer.write(prefix + "\"measurements\":");
145 | JsonHelper.writeDictionary(writer, this.measurements);
146 | prefix = ",";
147 | }
148 |
149 | return prefix;
150 | }
151 |
152 | /**
153 | * Sets up the events attributes
154 | */
155 | public void SetupAttributes() {
156 | }
157 |
158 | /**
159 | * Optionally initializes fields for the current context.
160 | */
161 | protected void InitializeFields() {
162 | QualifiedName = "com.microsoft.applicationinsights.contracts.EventData";
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/Location.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from ContextTagKeys.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.IJsonSerializable;
7 | import com.microsoft.telemetry.JsonHelper;
8 |
9 | import java.io.IOException;
10 | import java.io.Serializable;
11 | import java.io.Writer;
12 | import java.util.Map;
13 |
14 | /**
15 | * Data contract class Location.
16 | */
17 | public class Location implements IJsonSerializable, Serializable {
18 | /**
19 | * Backing field for property Ip.
20 | */
21 | private String ip;
22 |
23 | /**
24 | * Initializes a new instance of the Location class.
25 | */
26 | public Location() {
27 | this.InitializeFields();
28 | }
29 |
30 | /**
31 | * Gets the Ip property.
32 | */
33 | public String getIp() {
34 | return this.ip;
35 | }
36 |
37 | /**
38 | * Sets the Ip property.
39 | */
40 | public void setIp(String value) {
41 | this.ip = value;
42 | }
43 |
44 |
45 | /**
46 | * Adds all members of this class to a hashmap
47 | *
48 | * @param map to which the members of this class will be added.
49 | */
50 | public void addToHashMap(Map map) {
51 | if (!(this.ip == null)) {
52 | map.put("ai.location.ip", this.ip);
53 | }
54 | }
55 |
56 |
57 | /**
58 | * Serializes the beginning of this object to the passed in writer.
59 | *
60 | * @param writer The writer to serialize this object to.
61 | */
62 | @Override
63 | public void serialize(Writer writer) throws IOException {
64 | if (writer == null) {
65 | throw new IllegalArgumentException("writer");
66 | }
67 |
68 | writer.write('{');
69 | this.serializeContent(writer);
70 | writer.write('}');
71 | }
72 |
73 | /**
74 | * Serializes the beginning of this object to the passed in writer.
75 | *
76 | * @param writer The writer to serialize this object to.
77 | */
78 | protected String serializeContent(Writer writer) throws IOException {
79 | String prefix = "";
80 | if (!(this.ip == null)) {
81 | writer.write(prefix + "\"ai.location.ip\":");
82 | writer.write(JsonHelper.convert(this.ip));
83 | prefix = ",";
84 | }
85 |
86 | return prefix;
87 | }
88 |
89 | /**
90 | * Optionally initializes fields for the current context.
91 | */
92 | protected void InitializeFields() {
93 |
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/MessageData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.JsonHelper;
7 |
8 | import java.io.IOException;
9 | import java.io.Writer;
10 | import java.util.LinkedHashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * Data contract class MessageData.
15 | */
16 | public class MessageData extends TelemetryData {
17 | /**
18 | * Backing field for property Ver.
19 | */
20 | private int ver = 2;
21 |
22 | /**
23 | * Backing field for property Message.
24 | */
25 | private String message;
26 |
27 | /**
28 | * Backing field for property SeverityLevel.
29 | */
30 | private SeverityLevel severityLevel = SeverityLevel.VERBOSE;
31 |
32 | /**
33 | * Backing field for property Properties.
34 | */
35 | private Map properties;
36 |
37 | /**
38 | * Initializes a new instance of the MessageData class.
39 | */
40 | public MessageData() {
41 | this.InitializeFields();
42 | this.SetupAttributes();
43 | }
44 |
45 | /**
46 | * Envelope Name for this telemetry.
47 | */
48 | public String getEnvelopeName() {
49 | return "Microsoft.ApplicationInsights.Message";
50 | }
51 |
52 | /**
53 | * Base Type for this telemetry.
54 | */
55 | public String getBaseType() {
56 | return "Microsoft.ApplicationInsights.MessageData";
57 | }
58 |
59 | /**
60 | * Gets the Ver property.
61 | */
62 | public int getVer() {
63 | return this.ver;
64 | }
65 |
66 | /**
67 | * Sets the Ver property.
68 | */
69 | public void setVer(int value) {
70 | this.ver = value;
71 | }
72 |
73 | /**
74 | * Gets the Message property.
75 | */
76 | public String getMessage() {
77 | return this.message;
78 | }
79 |
80 | /**
81 | * Sets the Message property.
82 | */
83 | public void setMessage(String value) {
84 | this.message = value;
85 | }
86 |
87 | /**
88 | * Gets the SeverityLevel property.
89 | */
90 | public SeverityLevel getSeverityLevel() {
91 | return this.severityLevel;
92 | }
93 |
94 | /**
95 | * Sets the SeverityLevel property.
96 | */
97 | public void setSeverityLevel(SeverityLevel value) {
98 | this.severityLevel = value;
99 | }
100 |
101 | /**
102 | * Gets the Properties property.
103 | */
104 | public Map getProperties() {
105 | if (this.properties == null) {
106 | this.properties = new LinkedHashMap();
107 | }
108 | return this.properties;
109 | }
110 |
111 | /**
112 | * Sets the Properties property.
113 | */
114 | public void setProperties(Map value) {
115 | this.properties = value;
116 | }
117 |
118 |
119 | /**
120 | * Serializes the beginning of this object to the passed in writer.
121 | *
122 | * @param writer The writer to serialize this object to.
123 | */
124 | protected String serializeContent(Writer writer) throws IOException {
125 | String prefix = super.serializeContent(writer);
126 | writer.write(prefix + "\"ver\":");
127 | writer.write(JsonHelper.convert(this.ver));
128 | prefix = ",";
129 |
130 | writer.write(prefix + "\"message\":");
131 | writer.write(JsonHelper.convert(this.message));
132 | prefix = ",";
133 |
134 | if (!(this.severityLevel == SeverityLevel.VERBOSE)) {
135 | writer.write(prefix + "\"severityLevel\":");
136 | writer.write(JsonHelper.convert(this.severityLevel.getValue()));
137 | prefix = ",";
138 | }
139 |
140 | if (!(this.properties == null)) {
141 | writer.write(prefix + "\"properties\":");
142 | JsonHelper.writeDictionary(writer, this.properties);
143 | prefix = ",";
144 | }
145 |
146 | return prefix;
147 | }
148 |
149 | /**
150 | * Sets up the events attributes
151 | */
152 | public void SetupAttributes() {
153 | }
154 |
155 | /**
156 | * Optionally initializes fields for the current context.
157 | */
158 | protected void InitializeFields() {
159 | QualifiedName = "com.microsoft.applicationinsights.contracts.MessageData";
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/MetricData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.JsonHelper;
7 |
8 | import java.io.IOException;
9 | import java.io.Writer;
10 | import java.util.ArrayList;
11 | import java.util.LinkedHashMap;
12 | import java.util.List;
13 | import java.util.Map;
14 |
15 | /**
16 | * Data contract class MetricData.
17 | */
18 | public class MetricData extends TelemetryData {
19 | /**
20 | * Backing field for property Ver.
21 | */
22 | private int ver = 2;
23 |
24 | /**
25 | * Backing field for property Metrics.
26 | */
27 | private List metrics;
28 |
29 | /**
30 | * Backing field for property Properties.
31 | */
32 | private Map properties;
33 |
34 | /**
35 | * Initializes a new instance of the MetricData class.
36 | */
37 | public MetricData() {
38 | this.InitializeFields();
39 | this.SetupAttributes();
40 | }
41 |
42 | /**
43 | * Envelope Name for this telemetry.
44 | */
45 | public String getEnvelopeName() {
46 | return "Microsoft.ApplicationInsights.Metric";
47 | }
48 |
49 | /**
50 | * Base Type for this telemetry.
51 | */
52 | public String getBaseType() {
53 | return "Microsoft.ApplicationInsights.MetricData";
54 | }
55 |
56 | /**
57 | * Gets the Ver property.
58 | */
59 | public int getVer() {
60 | return this.ver;
61 | }
62 |
63 | /**
64 | * Sets the Ver property.
65 | */
66 | public void setVer(int value) {
67 | this.ver = value;
68 | }
69 |
70 | /**
71 | * Gets the Metrics property.
72 | */
73 | public List getMetrics() {
74 | if (this.metrics == null) {
75 | this.metrics = new ArrayList();
76 | }
77 | return this.metrics;
78 | }
79 |
80 | /**
81 | * Sets the Metrics property.
82 | */
83 | public void setMetrics(List value) {
84 | this.metrics = value;
85 | }
86 |
87 | /**
88 | * Gets the Properties property.
89 | */
90 | public Map getProperties() {
91 | if (this.properties == null) {
92 | this.properties = new LinkedHashMap();
93 | }
94 | return this.properties;
95 | }
96 |
97 | /**
98 | * Sets the Properties property.
99 | */
100 | public void setProperties(Map value) {
101 | this.properties = value;
102 | }
103 |
104 |
105 | /**
106 | * Serializes the beginning of this object to the passed in writer.
107 | *
108 | * @param writer The writer to serialize this object to.
109 | */
110 | protected String serializeContent(Writer writer) throws IOException {
111 | String prefix = super.serializeContent(writer);
112 | writer.write(prefix + "\"ver\":");
113 | writer.write(JsonHelper.convert(this.ver));
114 | prefix = ",";
115 |
116 | writer.write(prefix + "\"metrics\":");
117 | JsonHelper.writeList(writer, this.metrics);
118 | prefix = ",";
119 |
120 | if (!(this.properties == null)) {
121 | writer.write(prefix + "\"properties\":");
122 | JsonHelper.writeDictionary(writer, this.properties);
123 | prefix = ",";
124 | }
125 |
126 | return prefix;
127 | }
128 |
129 | /**
130 | * Sets up the events attributes
131 | */
132 | public void SetupAttributes() {
133 | }
134 |
135 | /**
136 | * Optionally initializes fields for the current context.
137 | */
138 | protected void InitializeFields() {
139 | QualifiedName = "com.microsoft.applicationinsights.contracts.MetricData";
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/PageViewData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.JsonHelper;
7 |
8 | import java.io.IOException;
9 | import java.io.Writer;
10 |
11 | /**
12 | * Data contract class PageViewData.
13 | */
14 | public class PageViewData extends EventData {
15 | /**
16 | * Backing field for property Url.
17 | */
18 | private String url;
19 |
20 | /**
21 | * Backing field for property Duration.
22 | */
23 | private String duration;
24 |
25 | /**
26 | * Backing field for property Referrer.
27 | */
28 | private String referrer;
29 |
30 | /**
31 | * Backing field for property ReferrerData.
32 | */
33 | private String referrerData;
34 |
35 | /**
36 | * Initializes a new instance of the PageViewData class.
37 | */
38 | public PageViewData() {
39 | this.InitializeFields();
40 | this.SetupAttributes();
41 | }
42 |
43 | /**
44 | * Envelope Name for this telemetry.
45 | */
46 | public String getEnvelopeName() {
47 | return "Microsoft.ApplicationInsights.PageView";
48 | }
49 |
50 | /**
51 | * Base Type for this telemetry.
52 | */
53 | public String getBaseType() {
54 | return "Microsoft.ApplicationInsights.PageViewData";
55 | }
56 |
57 | /**
58 | * Gets the Url property.
59 | */
60 | public String getUrl() {
61 | return this.url;
62 | }
63 |
64 | /**
65 | * Sets the Url property.
66 | */
67 | public void setUrl(String value) {
68 | this.url = value;
69 | }
70 |
71 | /**
72 | * Gets the Duration property.
73 | */
74 | public String getDuration() {
75 | return this.duration;
76 | }
77 |
78 | /**
79 | * Sets the Duration property.
80 | */
81 | public void setDuration(String value) {
82 | this.duration = value;
83 | }
84 |
85 | /**
86 | * Gets the Referrer property.
87 | */
88 | public String getReferrer() {
89 | return this.referrer;
90 | }
91 |
92 | /**
93 | * Sets the Referrer property.
94 | */
95 | public void setReferrer(String value) {
96 | this.referrer = value;
97 | }
98 |
99 | /**
100 | * Gets the ReferrerData property.
101 | */
102 | public String getReferrerData() {
103 | return this.referrerData;
104 | }
105 |
106 | /**
107 | * Sets the ReferrerData property.
108 | */
109 | public void setReferrerData(String value) {
110 | this.referrerData = value;
111 | }
112 |
113 |
114 | /**
115 | * Serializes the beginning of this object to the passed in writer.
116 | *
117 | * @param writer The writer to serialize this object to.
118 | */
119 | protected String serializeContent(Writer writer) throws IOException {
120 | String prefix = super.serializeContent(writer);
121 | if (!(this.url == null)) {
122 | writer.write(prefix + "\"url\":");
123 | writer.write(JsonHelper.convert(this.url));
124 | prefix = ",";
125 | }
126 |
127 | if (!(this.duration == null)) {
128 | writer.write(prefix + "\"duration\":");
129 | writer.write(JsonHelper.convert(this.duration));
130 | prefix = ",";
131 | }
132 |
133 | if (!(this.referrer == null)) {
134 | writer.write(prefix + "\"referrer\":");
135 | writer.write(JsonHelper.convert(this.referrer));
136 | prefix = ",";
137 | }
138 |
139 | if (!(this.referrerData == null)) {
140 | writer.write(prefix + "\"referrerData\":");
141 | writer.write(JsonHelper.convert(this.referrerData));
142 | prefix = ",";
143 | }
144 |
145 | return prefix;
146 | }
147 |
148 | /**
149 | * Sets up the events attributes
150 | */
151 | public void SetupAttributes() {
152 | }
153 |
154 | /**
155 | * Optionally initializes fields for the current context.
156 | */
157 | protected void InitializeFields() {
158 | QualifiedName = "com.microsoft.applicationinsights.contracts.PageViewData";
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/Session.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from ContextTagKeys.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 |
6 | import com.microsoft.telemetry.IJsonSerializable;
7 | import com.microsoft.telemetry.JsonHelper;
8 |
9 | import java.io.IOException;
10 | import java.io.Serializable;
11 | import java.io.Writer;
12 | import java.util.Map;
13 |
14 | /**
15 | * Data contract class Session.
16 | */
17 | public class Session
18 | implements IJsonSerializable, Serializable {
19 | /**
20 | * Backing field for property Id.
21 | */
22 | private String id;
23 |
24 | /**
25 | * Backing field for property IsFirst.
26 | */
27 | private String isFirst;
28 |
29 | /**
30 | * Backing field for property IsNew.
31 | */
32 | private String isNew;
33 |
34 | /**
35 | * Initializes a new instance of the Session class.
36 | */
37 | public Session() {
38 | this.InitializeFields();
39 | }
40 |
41 | /**
42 | * Gets the Id property.
43 | */
44 | public String getId() {
45 | return this.id;
46 | }
47 |
48 | /**
49 | * Sets the Id property.
50 | */
51 | public void setId(String value) {
52 | this.id = value;
53 | }
54 |
55 | /**
56 | * Gets the IsFirst property.
57 | */
58 | public String getIsFirst() {
59 | return this.isFirst;
60 | }
61 |
62 | /**
63 | * Sets the IsFirst property.
64 | */
65 | public void setIsFirst(String value) {
66 | this.isFirst = value;
67 | }
68 |
69 | /**
70 | * Gets the IsNew property.
71 | */
72 | public String getIsNew() {
73 | return this.isNew;
74 | }
75 |
76 | /**
77 | * Sets the IsNew property.
78 | */
79 | public void setIsNew(String value) {
80 | this.isNew = value;
81 | }
82 |
83 |
84 | /**
85 | * Adds all members of this class to a hashmap
86 | *
87 | * @param map to which the members of this class will be added.
88 | */
89 | public void addToHashMap(Map map) {
90 | if (!(this.id == null)) {
91 | map.put("ai.session.id", this.id);
92 | }
93 | if (!(this.isFirst == null)) {
94 | map.put("ai.session.isFirst", this.isFirst);
95 | }
96 | if (!(this.isNew == null)) {
97 | map.put("ai.session.isNew", this.isNew);
98 | }
99 | }
100 |
101 |
102 | /**
103 | * Serializes the beginning of this object to the passed in writer.
104 | *
105 | * @param writer The writer to serialize this object to.
106 | */
107 | @Override
108 | public void serialize(Writer writer) throws IOException {
109 | if (writer == null) {
110 | throw new IllegalArgumentException("writer");
111 | }
112 |
113 | writer.write('{');
114 | this.serializeContent(writer);
115 | writer.write('}');
116 | }
117 |
118 | /**
119 | * Serializes the beginning of this object to the passed in writer.
120 | *
121 | * @param writer The writer to serialize this object to.
122 | */
123 | protected String serializeContent(Writer writer) throws IOException {
124 | String prefix = "";
125 | if (!(this.id == null)) {
126 | writer.write(prefix + "\"ai.session.id\":");
127 | writer.write(JsonHelper.convert(this.id));
128 | prefix = ",";
129 | }
130 |
131 | if (!(this.isFirst == null)) {
132 | writer.write(prefix + "\"ai.session.isFirst\":");
133 | writer.write(JsonHelper.convert(this.isFirst));
134 | prefix = ",";
135 | }
136 |
137 | if (!(this.isNew == null)) {
138 | writer.write(prefix + "\"ai.session.isNew\":");
139 | writer.write(JsonHelper.convert(this.isNew));
140 | prefix = ",";
141 | }
142 |
143 | return prefix;
144 | }
145 |
146 | /**
147 | * Optionally initializes fields for the current context.
148 | */
149 | protected void InitializeFields() {
150 |
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/SessionState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from SessionStateData.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | /**
6 | * Enum SessionState.
7 | */
8 | public enum SessionState
9 | {
10 | START(0), END(1);
11 |
12 | private final int value;
13 |
14 | private SessionState(int value) {
15 | this.value = value;
16 | }
17 |
18 | public int getValue() {
19 | return value;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/SessionStateData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from SessionStateData.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | import java.io.IOException;
6 | import java.io.Writer;
7 | import java.util.Map;
8 |
9 | import com.microsoft.telemetry.JsonHelper;
10 |
11 | /**
12 | * Data contract class SessionStateData.
13 | */
14 | public class SessionStateData extends TelemetryData
15 | {
16 | /**
17 | * Backing field for property Ver.
18 | */
19 | private int ver = 2;
20 |
21 | /**
22 | * Backing field for property State.
23 | */
24 | private SessionState state = SessionState.START;
25 |
26 | /**
27 | * Initializes a new instance of the SessionStateData class.
28 | */
29 | public SessionStateData()
30 | {
31 | this.InitializeFields();
32 | this.SetupAttributes();
33 | }
34 |
35 | /**
36 | * Envelope Name for this telemetry.
37 | */
38 | public String getEnvelopeName() {
39 | return "Microsoft.ApplicationInsights.SessionState";
40 | }
41 |
42 | /**
43 | * Base Type for this telemetry.
44 | */
45 | public String getBaseType() {
46 | return "Microsoft.ApplicationInsights.SessionStateData";
47 | }
48 |
49 |
50 | /**
51 | * Gets the Ver property.
52 | */
53 | public int getVer() {
54 | return this.ver;
55 | }
56 |
57 | /**
58 | * Sets the Ver property.
59 | */
60 | public void setVer(int value) {
61 | this.ver = value;
62 | }
63 |
64 | /**
65 | * Gets the State property.
66 | */
67 | public SessionState getState() {
68 | return this.state;
69 | }
70 |
71 | /**
72 | * Sets the State property.
73 | */
74 | public void setState(SessionState value) {
75 | this.state = value;
76 | }
77 |
78 |
79 | /**
80 | * Gets the Properties property.
81 | */
82 | public Map getProperties() {
83 | //Do nothing - does not currently take properties
84 | return null;
85 | }
86 |
87 | /**
88 | * Sets the Properties property.
89 | */
90 | public void setProperties(Map value) {
91 | //Do nothing - does not currently take properties
92 | }
93 |
94 | /**
95 | * Serializes the beginning of this object to the passed in writer.
96 | * @param writer The writer to serialize this object to.
97 | */
98 | protected String serializeContent(Writer writer) throws IOException
99 | {
100 | String prefix = super.serializeContent(writer);
101 | writer.write(prefix + "\"ver\":");
102 | writer.write(JsonHelper.convert(this.ver));
103 | prefix = ",";
104 |
105 | writer.write(prefix + "\"state\":");
106 | writer.write(JsonHelper.convert(this.state.getValue()));
107 | prefix = ",";
108 |
109 | return prefix;
110 | }
111 |
112 | /**
113 | * Sets up the events attributes
114 | */
115 | public void SetupAttributes()
116 | {
117 | }
118 |
119 | /**
120 | * Optionally initializes fields for the current context.
121 | */
122 | protected void InitializeFields() {
123 | QualifiedName = "com.microsoft.applicationinsights.contracts.SessionStateData";
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/SeverityLevel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from SeverityLevel.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | /**
6 | * Enum SeverityLevel.
7 | */
8 | public enum SeverityLevel
9 | {
10 | VERBOSE(0), INFORMATION(1), WARNING(2), ERROR(3), CRITICAL(4);
11 | private final int value;
12 |
13 | private SeverityLevel(int value) {
14 | this.value = value;
15 | }
16 |
17 | public int getValue() {
18 | return value;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/StackFrame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | import java.io.IOException;
6 | import java.io.Serializable;
7 | import java.io.Writer;
8 |
9 | import com.microsoft.telemetry.IJsonSerializable;
10 | import com.microsoft.telemetry.JsonHelper;
11 |
12 | /**
13 | * Data contract class StackFrame.
14 | */
15 | public class StackFrame
16 | implements IJsonSerializable, Serializable
17 | {
18 | /**
19 | * Backing field for property Level.
20 | */
21 | private int level;
22 |
23 | /**
24 | * Backing field for property Method.
25 | */
26 | private String method;
27 |
28 | /**
29 | * Backing field for property Assembly.
30 | */
31 | private String assembly;
32 |
33 | /**
34 | * Backing field for property FileName.
35 | */
36 | private String fileName;
37 |
38 | /**
39 | * Backing field for property Line.
40 | */
41 | private int line;
42 |
43 | /**
44 | * Initializes a new instance of the StackFrame class.
45 | */
46 | public StackFrame()
47 | {
48 | this.InitializeFields();
49 | }
50 |
51 | /**
52 | * Gets the Level property.
53 | */
54 | public int getLevel() {
55 | return this.level;
56 | }
57 |
58 | /**
59 | * Sets the Level property.
60 | */
61 | public void setLevel(int value) {
62 | this.level = value;
63 | }
64 |
65 | /**
66 | * Gets the Method property.
67 | */
68 | public String getMethod() {
69 | return this.method;
70 | }
71 |
72 | /**
73 | * Sets the Method property.
74 | */
75 | public void setMethod(String value) {
76 | this.method = value;
77 | }
78 |
79 | /**
80 | * Gets the Assembly property.
81 | */
82 | public String getAssembly() {
83 | return this.assembly;
84 | }
85 |
86 | /**
87 | * Sets the Assembly property.
88 | */
89 | public void setAssembly(String value) {
90 | this.assembly = value;
91 | }
92 |
93 | /**
94 | * Gets the FileName property.
95 | */
96 | public String getFileName() {
97 | return this.fileName;
98 | }
99 |
100 | /**
101 | * Sets the FileName property.
102 | */
103 | public void setFileName(String value) {
104 | this.fileName = value;
105 | }
106 |
107 | /**
108 | * Gets the Line property.
109 | */
110 | public int getLine() {
111 | return this.line;
112 | }
113 |
114 | /**
115 | * Sets the Line property.
116 | */
117 | public void setLine(int value) {
118 | this.line = value;
119 | }
120 |
121 |
122 | /**
123 | * Serializes the beginning of this object to the passed in writer.
124 | * @param writer The writer to serialize this object to.
125 | */
126 | @Override
127 | public void serialize(Writer writer) throws IOException
128 | {
129 | if (writer == null)
130 | {
131 | throw new IllegalArgumentException("writer");
132 | }
133 |
134 | writer.write('{');
135 | this.serializeContent(writer);
136 | writer.write('}');
137 | }
138 |
139 | /**
140 | * Serializes the beginning of this object to the passed in writer.
141 | * @param writer The writer to serialize this object to.
142 | */
143 | protected String serializeContent(Writer writer) throws IOException
144 | {
145 | String prefix = "";
146 | writer.write(prefix + "\"level\":");
147 | writer.write(JsonHelper.convert(this.level));
148 | prefix = ",";
149 |
150 | writer.write(prefix + "\"method\":");
151 | writer.write(JsonHelper.convert(this.method));
152 | prefix = ",";
153 |
154 | if (!(this.assembly == null))
155 | {
156 | writer.write(prefix + "\"assembly\":");
157 | writer.write(JsonHelper.convert(this.assembly));
158 | prefix = ",";
159 | }
160 |
161 | if (!(this.fileName == null))
162 | {
163 | writer.write(prefix + "\"fileName\":");
164 | writer.write(JsonHelper.convert(this.fileName));
165 | prefix = ",";
166 | }
167 |
168 | if (!(this.line == 0))
169 | {
170 | writer.write(prefix + "\"line\":");
171 | writer.write(JsonHelper.convert(this.line));
172 | prefix = ",";
173 | }
174 |
175 | return prefix;
176 | }
177 |
178 | /**
179 | * Optionally initializes fields for the current context.
180 | */
181 | protected void InitializeFields() {
182 |
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/TelemetryData.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.contracts;
2 |
3 | import com.microsoft.telemetry.ITelemetry;
4 |
5 | import java.io.Serializable;
6 |
7 | public abstract class TelemetryData extends ITelemetry implements Serializable {}
8 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/contracts/TestResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Generated from AppInsightsTypes.bond (https://github.com/Microsoft/bond)
3 | */
4 | package com.microsoft.applicationinsights.contracts;
5 | /**
6 | * Enum TestResult.
7 | */
8 | public enum TestResult
9 | {
10 | PASS(0), FAIL(1);
11 | private final int value;
12 | private TestResult(int value) {
13 | this.value = value;
14 | }
15 |
16 | public int getValue() {
17 | return value;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/library/ChannelManager.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import com.microsoft.applicationinsights.logging.InternalLogging;
4 |
5 | import com.microsoft.cll.android.AndroidCll;
6 |
7 | import com.microsoft.telemetry.IChannel;
8 |
9 | /**
10 | * A single class that manages the different types of channels we support
11 | */
12 | public class ChannelManager {
13 | private static final String TAG = "ChannelManager";
14 |
15 | /**
16 | * Volatile boolean for double checked synchronize block
17 | */
18 | private static volatile boolean isInitialized = false;
19 |
20 | /**
21 | * Synchronization LOCK for setting static context
22 | */
23 | private static final Object LOCK = new Object();
24 |
25 | /**
26 | * The singleton INSTANCE of this class
27 | */
28 | private static ChannelManager instance;
29 |
30 | /**
31 | * A Singleton instance of an IChannel set by default to Channel but can
32 | * be override using setChannel
33 | */
34 | private IChannel channel;
35 | /**
36 | * Instantiates a new INSTANCE of ChannelManager
37 | */
38 |
39 | protected ChannelManager(ChannelType channelType) {
40 | Channel.initialize(ApplicationInsights.getConfiguration());
41 | setChannel(channelType);
42 | }
43 |
44 | /**
45 | * Initializes the ChannelManager to it's default IChannel instance
46 | */
47 | public static void initialize(ChannelType channelType) {
48 | if (!isInitialized) {
49 | synchronized (ChannelManager.LOCK) {
50 | if (!isInitialized) {
51 | isInitialized = true;
52 | instance = new ChannelManager(channelType);
53 | }
54 | }
55 | }
56 | }
57 |
58 | /**
59 | * @return the INSTANCE of ChannelManager or null if not yet initialized
60 | */
61 | protected static ChannelManager getInstance() {
62 | if (ChannelManager.instance == null) {
63 | InternalLogging.error(TAG, "getSharedInstance was called before initialization");
64 | }
65 |
66 | return ChannelManager.instance;
67 | }
68 |
69 | /**
70 | * Returns the current channel
71 | * @return The channel that is currently in use
72 | */
73 | protected IChannel getChannel() {
74 | return channel;
75 | }
76 |
77 | /**
78 | * Sets the current channel to use
79 | * @param channelType The new channel to use
80 | */
81 | protected void setChannel(ChannelType channelType) {
82 | if(channelType == null) {
83 | InternalLogging.warn(TAG, "ChannelType is null, setting up using default channel type");
84 | this.channel = createDefaultChannel();
85 | return;
86 | }
87 |
88 | switch (channelType) {
89 | case Default:
90 | this.channel = createDefaultChannel();
91 | break;
92 | case CommonLoggingLibraryChannel:
93 | this.channel = createTelemetryClientChannel();
94 | break;
95 | }
96 | }
97 |
98 | /**
99 | * Resets this instance of the channel manager
100 | */
101 | protected void reset() {
102 | if(channel != null) {
103 | channel = null;
104 | }
105 |
106 | if(instance != null) {
107 | instance = null;
108 | }
109 |
110 | isInitialized = false;
111 | }
112 |
113 | /**
114 | * Creates a channel of default type
115 | * @return The new default channel
116 | */
117 | private IChannel createDefaultChannel() {
118 | IChannel defaultChannel = Channel.getInstance();
119 | if(defaultChannel == null) {
120 | Channel.initialize(ApplicationInsights.getConfiguration());
121 | defaultChannel = Channel.getInstance();
122 | }
123 |
124 | return defaultChannel;
125 | }
126 |
127 | /**
128 | * Creates a channel of the Telemetry Client type
129 | * @return The new Telemetry Client channel
130 | */
131 | private IChannel createTelemetryClientChannel() {
132 | String iKey = ApplicationInsights.getInstrumentationKey() == null ? "" : ApplicationInsights.getInstrumentationKey();
133 | AndroidCll cll = (AndroidCll)AndroidCll.initialize(iKey, ApplicationInsights.INSTANCE.getContext(), ApplicationInsights.getConfiguration().getEndpointUrl());
134 | cll.useLagacyCS(true);
135 | return cll;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/library/ChannelType.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | /**
4 | * An enum for the different channel types supported
5 | */
6 | public enum ChannelType {
7 | Default,
8 | CommonLoggingLibraryChannel
9 | }
10 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/library/SyncUtil.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Application;
5 | import android.content.ComponentCallbacks2;
6 | import android.content.res.Configuration;
7 | import android.os.Build;
8 |
9 | import com.microsoft.applicationinsights.logging.InternalLogging;
10 |
11 | /**
12 | * Class that triggers a sync call to the pipeline by using ComponentCallbacks2
13 | */
14 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
15 | class SyncUtil implements ComponentCallbacks2 {
16 |
17 | /**
18 | * The singleton INSTANCE of this class
19 | */
20 | private static SyncUtil instance;
21 |
22 | /**
23 | * The tag for logging
24 | */
25 | private static final String TAG = "SyncUtil";
26 |
27 | /**
28 | * @return the INSTANCE of autocollection event tracking or null if not yet initialized
29 | */
30 | protected static SyncUtil getInstance() {
31 | if (SyncUtil.instance == null) {
32 | SyncUtil.instance = new SyncUtil();
33 | }
34 |
35 | return SyncUtil.instance;
36 | }
37 |
38 |
39 | private SyncUtil() {
40 | }
41 |
42 | protected void start(Application application) {
43 | if (application != null) {
44 | application.registerComponentCallbacks(SyncUtil.instance);
45 | InternalLogging.info(TAG, "Started listening to componentcallbacks to trigger sync");
46 | }
47 | }
48 |
49 | public void onTrimMemory(int level) {
50 | if (Util.isLifecycleTrackingAvailable()) {
51 | if (level == TRIM_MEMORY_UI_HIDDEN) {
52 | InternalLogging.info(TAG, "UI of the app is hidden");
53 | InternalLogging.info(TAG, "Syncing data");
54 | Channel.getInstance().synchronize();
55 | } else if (level == TRIM_MEMORY_RUNNING_LOW) {
56 | InternalLogging.info(TAG, "Memory running low, syncing data");
57 | Channel.getInstance().synchronize();
58 | }
59 | }
60 | }
61 |
62 | @Override
63 | public void onConfigurationChanged(Configuration newConfig) {
64 | // unused but required to implement ComponentCallbacks
65 | }
66 |
67 | @Override
68 | public void onLowMemory() {
69 | // unused but required to implement ComponentCallbacks
70 | InternalLogging.warn(TAG, "Received onLowMemory()-Callback, persisting data");
71 | Channel.getInstance().synchronize();
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/library/config/IQueueConfig.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library.config;
2 |
3 | public interface IQueueConfig {
4 |
5 | /**
6 | * Gets the maximum size of a batch in bytes
7 | * @return the max batch count until we send a bundle of data to the server
8 | */
9 | int getMaxBatchCount();
10 |
11 | /**
12 | * Sets the maximum size of a batch in bytes
13 | * @param maxBatchCount the batchsize of data that will be queued until we send/writeToDisk it
14 | */
15 | void setMaxBatchCount(int maxBatchCount);
16 |
17 | /**
18 | * Gets the maximum interval allowed between calls to batchInvoke
19 | * @return the interval until we send/writeToDisk queued up data
20 | */
21 | int getMaxBatchIntervalMs();
22 |
23 | /**
24 | * Sets the maximum interval allowed between calls to batchInvoke
25 | * @param maxBatchIntervalMs the amount of MS until we want to send out a batch of data
26 | */
27 | void setMaxBatchIntervalMs(int maxBatchIntervalMs);
28 | }
29 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/library/config/ISenderConfig.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library.config;
2 |
3 | public interface ISenderConfig{
4 |
5 | /**
6 | * Gets the url to which payloads will be sent
7 | *
8 | * @return the server's endpoint URL
9 | */
10 | String getEndpointUrl();
11 |
12 | /**
13 | * Sets the url to which payloads will be sent
14 | *
15 | * @param endpointUrl url of the server that receives our data
16 | */
17 | void setEndpointUrl(String endpointUrl);
18 |
19 | /**
20 | * Gets the timeout for reading the response from the data collector endpoint
21 | *
22 | * @return configured timeout in ms for reading
23 | */
24 | int getSenderReadTimeout();
25 |
26 | /**
27 | * Set the timeout for reading the response from the data collector endpoint
28 | */
29 | void setSenderReadTimeout(int senderReadTimeout);
30 |
31 | /**
32 | * Gets the timeout for connecting to the data collector endpoint
33 | *
34 | * @return configured timeout in ms for sending
35 | */
36 | int getSenderConnectTimeout();
37 |
38 | /**
39 | * Set the timeout for connecting to the data collector endpoint
40 | */
41 | void setSenderConnectTimeout(int senderConnectTimeout);
42 | }
43 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/library/config/ISessionConfig.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.library.config;
2 |
3 | public interface ISessionConfig {
4 |
5 | /**
6 | * Gets the interval at which sessions are renewed
7 | */
8 | long getSessionIntervalMs();
9 |
10 | /**
11 | * Sets the interval at which sessions are renewed
12 | */
13 | void setSessionIntervalMs(long sessionIntervalMs);
14 | }
15 |
--------------------------------------------------------------------------------
/applicationinsights-android/src/main/java/com/microsoft/applicationinsights/logging/InternalLogging.java:
--------------------------------------------------------------------------------
1 | package com.microsoft.applicationinsights.logging;
2 |
3 | import android.util.Log;
4 |
5 | import com.microsoft.applicationinsights.library.ApplicationInsights;
6 |
7 | public class InternalLogging {
8 | private static final String PREFIX = InternalLogging.class.getPackage().getName();
9 |
10 | private InternalLogging() {
11 | // hide default constructor
12 | }
13 |
14 | /**
15 | * Inform SDK users about SDK activities. This has 3 parameters to avoid the string
16 | * concatenation when verbose mode is disabled.
17 | *
18 | * @param tag the log context
19 | * @param message the log message
20 | * @param payload the payload for the message
21 | */
22 | public static void info(String tag, String message, String payload) {
23 | if (ApplicationInsights.isDeveloperMode()) {
24 | Log.i(PREFIX + " " + tag, message + ":" + payload);
25 | }
26 | }
27 |
28 | /**
29 | * Inform SDK users about SDK activities.
30 | *
31 | * @param tag the log context
32 | * @param message the log message
33 | */
34 | public static void info(String tag, String message) {
35 | if (ApplicationInsights.isDeveloperMode()) {
36 | Log.i(PREFIX + " " + tag, message);
37 | }
38 | }
39 |
40 |
41 | /**
42 | * Warn SDK users about non-critical SDK misuse
43 | *
44 | * @param tag the log context
45 | * @param message the log message
46 | */
47 | public static void warn(String tag, String message) {
48 | if (ApplicationInsights.isDeveloperMode()) {
49 | Log.w(PREFIX + " " + tag, message);
50 | }
51 | }
52 |
53 | /**
54 | * Log critical SDK error
55 | *
56 | * @param tag the log context
57 | * @param message the log message
58 | */
59 | public static void error(String tag, String message) {
60 | Log.e(PREFIX + " " + tag, message);
61 | }
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.1.0'
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | mavenCentral()
19 | }
20 |
21 | apply plugin: 'idea'
22 | apply plugin: 'com.jfrog.bintray'
23 |
24 | bintray {
25 | user = " "
26 | key = " "
27 | dryRun = true
28 | publish = false
29 | pkg {
30 | repo=" "
31 | name=" "
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | projectGroup=com.microsoft.azure
21 | projectVersion=1.0-beta.10
22 | projectRepo=https://github.com/Microsoft/ApplicationInsights-Android
23 | projectName=ApplicationInsights-Android
24 | projectDesc=Application Insights SDK for Android
25 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/ApplicationInsights-Android/54194b851acfe2af6472e9cb4e5a17a3b3fc33ec/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 03 13:51:29 PST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app-sample', ':applicationinsights-android'
2 |
--------------------------------------------------------------------------------
/update-docs.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # generate docs
4 | gradle docs
5 |
6 | # save local.properties
7 | git add local.properties -f
8 | git stash
9 |
10 | # add docs to version control
11 | git add applicationinsights-android/build/docs/javadoc -f
12 | git stash
13 |
14 | # clear old docs
15 | git checkout gh-pages
16 | git clean -xdf
17 | git rm -rf .
18 |
19 | # add updated docs
20 | git stash pop
21 | mv applicationinsights-android/build/docs/javadoc/* ./
22 | rm -rf applicationinsights-android
23 | git add -A
24 | git commit -m "updating docs via update-docs.sh"
25 |
26 | # disable pushing from the script by default
27 | #git push origin gh-pages
28 |
29 | # restore local.properties
30 | git checkout master
31 | git stash pop
32 | git reset HEAD local.properties
33 |
--------------------------------------------------------------------------------