-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Welcome to the dhis2-android-sdk wiki!
The first step for all the calls is create the d2 object
ConfigurationModel config = ConfigurationModel.builder()
.serverUrl(HttpUrl.parse("https://play.dhis2.org/dev/api/"))
.build();
d2 = new D2.Builder()
.configuration(config)
.databaseAdapter(databaseAdapter())
.okHttpClient(
new OkHttpClient.Builder()
.addInterceptor(BasicAuthenticatorFactory.create(databaseAdapter()))
.build()
).build();
- Login
d2.logIn("user", "password").call();
- Pull metadata
d2.syncMetaData().call();
- Sync events
d2.syncSingleEvents().call();
- Sync tracked entity instances
d2.syncTrackedEntityInstances().call();
- Logout
d2.logOut().call();
- Program rule functions already implemented
- Ceil
- Rounds the input argument up to the nearest whole number.
- DaysBetween
- Produces the number of days between the first and second argument. If the second argument date is before the first argument the return value will be the negative number of days between the two dates. The static date format is 'yyyy-MM-dd'.
- Floor
- Rounds the input argument down to the nearest whole number.
- HasValue
- Evaluates to true of the argument source field contains a value, false if no value is entered.
- WeeksBetween
- Produces the number of full weeks between two data elements/attributes of type date. The static date format is 'yyyy-MM-dd'.
Not implemented at the moment of the creation of this wiki: addDays, condition, zpvc, addControlDigits, checkControlDigits, concatenate, count, countIfValue, countIfZeroPos, lastEventDate, left, length, modulus, monthsBetween, oizp, right, round, split, substring, validatePattern, yearsBetween, zing.
Steps:
Add a .gitmodules file with the follow content:
[submodule "sdk"]
path = sdk
url = https://github.com/EyeSeeTea/dhis2-android-sdk
branch = development
then run:
git submodule update
This should clone the repository in a "sdk"folder and "development" branch in the root path of your project.
Add in your settings.gradle the follow lines:
include ':app', ':core'
project(':core').projectDir = new File(settingsDir, 'sdk/core')
And add in app/build.gradle:
dependencies {
compile project(':core')
}
Before run tests
The instrumental tests needs a real android device, or a android emulator connected.
The instrumental tests are placed in the folder androidTest, and the unit test in the folder test.
How run tests
- Using android studio
You can select Whole project in android studio ide to run all the tests. Or select a specify test, class, package, or module, clicking with the right button of the mouse and selecting "run test".
For the instrumental test you need open a virtual machine. (Click on tool, android, and open AVD manager, to configure and launch a android emulator).
- Using gradle command
./gradlew test --info
or run only tests of a specific project:
./gradlew core:test --info
Some used these test libraries:
Mockserver
MockServer can be used for mocking any system you integrate with via HTTP or HTTPS (i.e. services, web sites, etc).
- MockServer can
return a "mock" response when a request matches an expectation
forward a request when the request matches an expectation (i.e. a dynamic port forwarding proxy)
execute a callback when a request matches an expectation, allowing the response to be created dynamically
verify requests have been sent (i.e. as a test assertion)
- How use mock server
Mockito:
- What is mockito?
Mockito is a mocking framework for Java. Mockito allows convenient creation of substitutes of real objects for testing purposes. Enjoy clean tests with mock objects, improved TDD experience and beautiful mocking API.
This is util to mock android components not present during the unit tests.
- How use mockito?
In that test the mockito is used to mock a user object, and added what should return this class for every method.
Mockito is used to mock the android framework components in our tests to run it without android emulator like a unit tests.
In the follow tests mockito is used to verify what methods are executed, in the example mocks the store response using when()thenReturn(), and after that verify the follow calls. Example
- How extract DB
In the case of the test, you need add a database name, replacing the null parameter by a string in the line: Example
Add a breakpoint before database changes for example in this line: Example
and pull the database using adb, enter on terminal:
adb pull /data/user/0/org.hisp.dhis.android.test/databases/databasename.db /your/path/
In some android versions could be permissions problem, you can try this sequence of commands:
adb pull
su
adb cp /data/user/0/org.hisp.dhis.android.test/databases/databasename.db /mnt/sdcard/databasename.db
exit
exit
adb pull /mnt/sdcard/databasename.db /your/path/
The sdk is developed using the Test-Driven Development methodology.
The team is following a standard naming test methods and classes.
The most important points are:
The class and test name should be read as a full sentence.
The class should express what the class should be able to do.
And the test should start with a verb.
You can read more about this standards reading the article codurance article.
The internal structure of the test is simple and have three blocks: Given, When, Then.
The sdk is developed using the Test-Driven Development methodology.