Skip to content

Commit

Permalink
Merge branch 'staging' into create_feedback_module
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis authored Sep 27, 2023
2 parents 238b90b + f122322 commit 1b04598
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Countly Java SDK

This repository contains the Countly Java SDK, which can be integrated into Java applications. The Countly Java SDK is intended to be used with [Countly Community Edition](https://github.com/Countly/countly-server) or [Countly Enterprise Edition](https://count.ly/product).
This repository contains the Countly Java SDK, which can be integrated into Java applications. The Countly Java SDK is intended to be used with [Countly Lite](https://countly.com/lite), [Countly Flex](https://countly.com/flex), [Countly Enterprise](https://countly.com/enterprise).

## What is Countly?

Expand All @@ -12,16 +12,16 @@ and [desktop](https://count.ly/desktop-analytics) applications. [Ensuring privac
Track, measure, and take action - all without leaving Countly.

* **Questions or feature requests?** [Join the Countly Community on Discord](https://discord.gg/countly)
* **Looking for the Countly Server?** [Countly Community Edition repository](https://github.com/Countly/countly-server)
* **Looking for the Countly Server?** [Countly Server repository](https://github.com/Countly/countly-server)
* **Looking for other Countly SDKs?** [An overview of all Countly SDKs for mobile, web and desktop](https://support.count.ly/hc/en-us/articles/360037236571-Downloading-and-Installing-SDKs#officially-supported-sdks)

## Integrating Countly SDK in your projects

For a detailed description on how to use this SDK [check out our documentation](https://support.count.ly/hc/en-us/articles/360037813891-Java).

For information about how to add the SDK to your project, please check [this section of the documentation](https://support.count.ly/hc/en-us/articles/360037813891-Java#adding-sdk-to-the-project).
For information about how to add the SDK to your project, please check [this section of the documentation](https://support.count.ly/hc/en-us/articles/360037813891-Java#h_01HABV0K6BZ251ANK02RZK3Z5H).

You can find minimal SDK integration information for your project in [this section of the documentation](https://support.count.ly/hc/en-us/articles/360037813891-Java#minimal-setup).
You can find minimal SDK integration information for your project in [this section of the documentation](https://support.count.ly/hc/en-us/articles/360037813891-Java#h_01HABV0K6C4H1G71VV85BDXV91).

For an example integration of this SDK, you can have a look [here](https://github.com/Countly/countly-sdk-java/tree/master/app-java/src/main/java/ly/count/java/demo).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private JSONObject doInBackground(String requestData, String customEndpoint, Tra
try {
connection = cp.connection(request, null);
} catch (IOException e) {
L.e("[ImmediateRequestMaker] IOException while preparing remote config update request :[" + e.toString() + "]");
L.e("[ImmediateRequestMaker] IOException while preparing remote config update request :[" + e + "]");
return null;
}
//connecting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,4 @@ private int getHourFromTimeStamp(long timeStamp) {

return calendar.get(Calendar.HOUR_OF_DAY);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package ly.count.sdk.java.internal;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import ly.count.sdk.java.Countly;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static org.mockito.Mockito.mock;

@RunWith(JUnit4.class)
public class ImmediateRequestTest {
Log L = mock(Log.class);

@After
public void stop() {
Countly.stop(true);
}

/**
* Immediate request maker "doWork" function
* Immediate Request Generator is default and endpoint and data are not valid, and app key, server url is default
* should return null because response is not okay
*
* @throws InterruptedException if thread is interrupted
*/
@Test
public void doWork_null() throws InterruptedException {
Countly.instance().init(TestUtils.getBaseConfig());
AtomicReference<Boolean> callbackResult = new AtomicReference<>(true);

ImmediateRequestMaker immediateRequestMaker = new ImmediateRequestMaker();
immediateRequestMaker.doWork("test_event", "/o?", SDKCore.instance.networking.getTransport(), false, true,
(result) -> {
if (result == null) {
callbackResult.set(false);
}
}, L);

Thread.sleep(2000); // wait for background thread to finish
Assert.assertFalse(callbackResult.get()); // check if callback was called and response is null
}

/**
* Immediate request maker "doWork" function
* Immediate Request Generator is override and returns desired value
* should return desired value
*
* @throws InterruptedException if thread is interrupted
*/
@Test
public void doWork() throws InterruptedException {
Countly.instance().init(TestUtils.getBaseConfig());

JSONObject requestResult = new JSONObject();
requestResult.put("result", "Success");
requestResult.put("count", 6);

ImmediateRequestI requestMaker = (requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log) -> {
Assert.assertEquals("test_event", requestData);
Assert.assertEquals("/o?", customEndpoint);
Assert.assertTrue(networkingIsEnabled);
Assert.assertFalse(requestShouldBeDelayed);
callback.callback(requestResult);
};

SDKCore.instance.config.immediateRequestGenerator = () -> requestMaker;
ImmediateRequestI requestMakerGenerated = SDKCore.instance.config.immediateRequestGenerator.createImmediateRequestMaker();

AtomicInteger reqValidator = new AtomicInteger(0);
requestMakerGenerated.doWork("test_event", "/o?", SDKCore.instance.networking.getTransport(), false, true,
(result) -> {
Assert.assertEquals(requestResult, result);
reqValidator.set(requestResult.getInt("count"));
}, L);

Thread.sleep(2000); // wait for background thread to finish
Assert.assertEquals(6, reqValidator.get()); // check if callback was called and response is null
}
}
16 changes: 15 additions & 1 deletion sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class TestUtils {

static String DELIMETER = ":::";
static String SERVER_URL = "https://try.count.ly";
static String SERVER_URL = "https://test.count.ly";
static String SERVER_APP_KEY = "COUNTLY_APP_KEY";
static String DEVICE_ID = "some_random_test_device_id";

Expand Down Expand Up @@ -205,4 +205,18 @@ public static Map<String, String> parseQueryParams(String data) {
}
return paramMap;
}

static File getSdkStorageRootDirectory() {
// System specific folder structure
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
return new File(String.join(File.separator, sdkStorageRootPath));
}

static void checkSdkStorageRootDirectoryExist(File directory) {
if (!(directory.exists() && directory.isDirectory())) {
if (!directory.mkdirs()) {
throw new RuntimeException("Directory creation failed");
}
}
}
}

0 comments on commit 1b04598

Please sign in to comment.