Skip to content

Commit

Permalink
Merge pull request #34 from thomasgrassauer/openkitconstants
Browse files Browse the repository at this point in the history
OpenKitConstants
  • Loading branch information
thomasgrassauer authored Dec 20, 2017
2 parents 36171c0 + 2646e05 commit 1a84ba1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 31 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/dynatrace/openkit/api/OpenKitConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dynatrace.openkit.api;

/**
* Defines constant values used in OpenKit
*/
public class OpenKitConstants {

// default values used in configuration
public static final String DEFAULT_APPLICATION_VERSION = "0.4";
public static final String DEFAULT_OPERATING_SYSTEM = "OpenKit " + DEFAULT_APPLICATION_VERSION;
public static final String DEFAULT_MANUFACTURER = "Dynatrace";
public static final String DEFAULT_DEVICE_ID = "OpenKitDevice";

}
11 changes: 4 additions & 7 deletions src/main/java/com/dynatrace/openkit/core/DeviceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
package com.dynatrace.openkit.core;

import com.dynatrace.openkit.api.Device;
import com.dynatrace.openkit.api.OpenKitConstants;

/**
* Actual implementation of the {@link Device} interface.
*/
public class DeviceImpl implements Device {

public static final String DEFAULT_OPERATING_SYSTEM = "OpenKit 0.3"; // 'OpenKit 0.3'
public static final String DEFAULT_MANUFACTURER = "Dynatrace"; // default: 'Dynatrace'
public static final String DEFAULT_DEVICE_ID = "OpenKitDevice"; // default: 'OpenKitDevice'

// platform information
private String operatingSystem = DEFAULT_OPERATING_SYSTEM;
private String manufacturer = DEFAULT_MANUFACTURER;
private String modelID = DEFAULT_DEVICE_ID;
private String operatingSystem = OpenKitConstants.DEFAULT_OPERATING_SYSTEM;
private String manufacturer = OpenKitConstants.DEFAULT_MANUFACTURER;
private String modelID = OpenKitConstants.DEFAULT_DEVICE_ID;

// *** Device interface methods ***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import com.dynatrace.openkit.api.OpenKitConstants;
import com.dynatrace.openkit.core.DeviceImpl;
import com.dynatrace.openkit.protocol.StatusResponse;

Expand All @@ -21,7 +22,6 @@ public abstract class AbstractConfiguration {
private static final int DEFAULT_MAX_BEACON_SIZE = 30 * 1024; // default: max 30KB (in B) to send in one beacon
private static final boolean DEFAULT_CAPTURE_ERRORS = true; // default: capture errors on
private static final boolean DEFAULT_CAPTURE_CRASHES = true; // default: capture crashes on
private static final String DEFAULT_APPLICATION_VERSION = "0.3"; // default: '0.3'

// immutable settings
private final String applicationName;
Expand Down Expand Up @@ -68,7 +68,7 @@ protected AbstractConfiguration(OpenKitType openKitType, String applicationName,
captureCrashes = new AtomicBoolean(DEFAULT_CAPTURE_CRASHES);

device = new DeviceImpl();
applicationVersion = DEFAULT_APPLICATION_VERSION;
applicationVersion = OpenKitConstants.DEFAULT_APPLICATION_VERSION;
httpClientConfiguration = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.ArrayList;

import com.dynatrace.openkit.api.OpenKitConstants;
import org.junit.Assert;

import com.dynatrace.openkit.protocol.HTTPClient.RequestType;
Expand All @@ -18,10 +19,10 @@ public abstract class AbstractAppMonTest extends AbstractTest {
public static final String TEST_APPLICATION_ID = "TestApplicationID";
public static final String TEST_ENDPOINT = "http://localhost/";
public static final String TEST_IP = "123.45.67.89";
public static final String TEST_OPENKIT_DEFAULT_VERSION = "0.3";
public static final String TEST_OPENKIT_DEFAULT_VERSION = OpenKitConstants.DEFAULT_APPLICATION_VERSION;
public static final String TEST_DEVICE_TYPE = "OpenKitDevice";
public static final String TEST_MANUFACTURER = "Dynatrace";
public static final String TEST_OS = "OpenKit+0.3";
public static final String TEST_OS = "OpenKit+" + OpenKitConstants.DEFAULT_APPLICATION_VERSION;

protected String getDefaultEndpoint() {
return TEST_ENDPOINT + "dynaTraceMonitor?type=m&srvid=1&app=" + TEST_APPLICATION_NAME + "&va=7.0.0000&pt=1";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dynatrace.openkit.test;

import com.dynatrace.openkit.api.OpenKitConstants;
import com.dynatrace.openkit.core.configuration.AbstractConfiguration;
import com.dynatrace.openkit.core.configuration.AppMonConfiguration;
import com.dynatrace.openkit.core.configuration.DynatraceConfiguration;
Expand All @@ -15,7 +16,6 @@ public class ConfigurationTest {
private static final String host = "localhost:9999";
private static final String tenantId = "asdf";
private static final String applicationName = "testApp";
private static final String applicationVersion = "0.3";

@Test
public void saasURLIsCorrect() {
Expand Down Expand Up @@ -64,6 +64,6 @@ public void applicationIdAndApplicationNameIdenticalForAppMonConfig() {
public void defaultApplicationVersionIsCorrect() {
AbstractConfiguration configuration = new AppMonConfiguration(applicationName, 17, "", false, new SSLStrictTrustManager());

assertThat(applicationVersion, is(configuration.getApplicationVersion()));
assertThat(configuration.getApplicationVersion(), is(OpenKitConstants.DEFAULT_APPLICATION_VERSION));
}
}
37 changes: 19 additions & 18 deletions src/test/java/com/dynatrace/openkit/test/DeviceImplTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dynatrace.openkit.test;

import com.dynatrace.openkit.api.OpenKitConstants;
import com.dynatrace.openkit.core.DeviceImpl;
import org.junit.Test;

Expand All @@ -12,14 +13,14 @@ public class DeviceImplTest {
public void defaultValueForModelIdIsCorrect() {
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_DEVICE_ID, is(device.getModelID()));
assertThat(OpenKitConstants.DEFAULT_DEVICE_ID, is(device.getModelID()));
}

@Test
public void settingModelIdUsingValidValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_DEVICE_ID, is(device.getModelID()));
assertThat(OpenKitConstants.DEFAULT_DEVICE_ID, is(device.getModelID()));

String validModelId = "testDevice";
device.setModelID(validModelId);
Expand All @@ -31,38 +32,38 @@ public void settingModelIdUsingValidValue(){
public void settingModelIdUsingEmptyValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_DEVICE_ID, is(device.getModelID()));
assertThat(OpenKitConstants.DEFAULT_DEVICE_ID, is(device.getModelID()));

String emptyModelId = "";
device.setModelID(emptyModelId);

assertThat(DeviceImpl.DEFAULT_DEVICE_ID, is(device.getModelID()));
assertThat(OpenKitConstants.DEFAULT_DEVICE_ID, is(device.getModelID()));
}

@Test
public void settingModelIdUsingUndefinedValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_DEVICE_ID, is(device.getModelID()));
assertThat(OpenKitConstants.DEFAULT_DEVICE_ID, is(device.getModelID()));

String undefinedModelId = null;
device.setModelID(undefinedModelId);

assertThat(DeviceImpl.DEFAULT_DEVICE_ID, is(device.getModelID()));
assertThat(OpenKitConstants.DEFAULT_DEVICE_ID, is(device.getModelID()));
}

@Test
public void defaultValueForOperatingSystemIsCorrect() {
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
assertThat(OpenKitConstants.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
}

@Test
public void settingOperatingSystemUsingValidValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
assertThat(OpenKitConstants.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));

String validModelId = "testDevice";
device.setOperatingSystem(validModelId);
Expand All @@ -74,38 +75,38 @@ public void settingOperatingSystemUsingValidValue(){
public void settingOperatingSystemUsingEmptyValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
assertThat(OpenKitConstants.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));

String emptyOperatingSystem = "";
device.setOperatingSystem(emptyOperatingSystem);

assertThat(DeviceImpl.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
assertThat(OpenKitConstants.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
}

@Test
public void settingOperatingSystemUsingUndefinedValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
assertThat(OpenKitConstants.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));

String undefinedOperatingSystem = null;
device.setOperatingSystem(undefinedOperatingSystem);

assertThat(DeviceImpl.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
assertThat(OpenKitConstants.DEFAULT_OPERATING_SYSTEM, is(device.getOperatingSystem()));
}

@Test
public void defaultValueForMancufacturerModelIdIsCorrect() {
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
assertThat(OpenKitConstants.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
}

@Test
public void settingManufacturerUsingValidValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
assertThat(OpenKitConstants.DEFAULT_MANUFACTURER, is(device.getManufacturer()));

String validManufacturer = "testManufacturer";
device.setManufacturer(validManufacturer);
Expand All @@ -117,23 +118,23 @@ public void settingManufacturerUsingValidValue(){
public void settingManufacturerUsingEmptyValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
assertThat(OpenKitConstants.DEFAULT_MANUFACTURER, is(device.getManufacturer()));

String emptyManufacturer = "";
device.setManufacturer(emptyManufacturer);

assertThat(DeviceImpl.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
assertThat(OpenKitConstants.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
}

@Test
public void settingManufacturerUsingUndefinedValue(){
DeviceImpl device = new DeviceImpl();

assertThat(DeviceImpl.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
assertThat(OpenKitConstants.DEFAULT_MANUFACTURER, is(device.getManufacturer()));

String undefinedManufacturer = null;
device.setManufacturer(undefinedManufacturer);

assertThat(DeviceImpl.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
assertThat(OpenKitConstants.DEFAULT_MANUFACTURER, is(device.getManufacturer()));
}
}

0 comments on commit 1a84ba1

Please sign in to comment.