Skip to content

Commit

Permalink
Merge pull request #230 from dhis2/develop
Browse files Browse the repository at this point in the history
Develop (0.9)
  • Loading branch information
dhis2-android authored May 23, 2018
2 parents e3f6e07 + 4a6280d commit 35dc707
Show file tree
Hide file tree
Showing 208 changed files with 6,489 additions and 7,250 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ ext {
buildToolsVersion: "25.0.2",
minSdkVersion : 15,
targetSdkVersion : 25,
versionCode : 751,
versionName : "0.7.5.1-SNAPSHOT"
versionCode : 90,
versionName : "0.9-SNAPSHOT"
]

libraries = [
Expand Down
7 changes: 7 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ dependencies {
compile "com.squareup.retrofit2:retrofit:${libraries.retrofit}"
compile "com.squareup.retrofit2:converter-jackson:${libraries.retrofit}"

// Apache libraries
compile group: 'org.apache.commons', name: 'commons-jexl', version: '2.1.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'

// Joda time
compile group: 'joda-time', name: 'joda-time', version: '2.9.9'

// Extension which generates mappers for work with cursor and content values
compile "com.gabrielittner.auto.value:auto-value-cursor-annotations:${libraries.autovaluecursor}"
annotationProcessor "com.gabrielittner.auto.value:auto-value-cursor:${libraries.autovaluecursor}"
Expand Down
12 changes: 0 additions & 12 deletions core/src/androidTest/assets/data_sets_with_access.json

This file was deleted.

12 changes: 0 additions & 12 deletions core/src/androidTest/assets/programs_with_access.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,8 @@ public void complete_login_and_sync_metadata_successfully_after_logout()
}

private void givenALoginInDatabase() throws Exception {
dhis2MockServer.enqueueMockResponse("login.json", new Date());
dhis2MockServer.enqueueMockResponse("system_info.json", new Date());

dhis2MockServer.enqueueLoginResponses();
Response<User> response = d2.logIn("user", "password").call();

assertThat(response.isSuccessful(), is(true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import org.hisp.dhis.android.core.common.D2Factory;
import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.data.server.RealServerMother;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.android.core.user.User;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

import retrofit2.Response;

Expand All @@ -33,7 +36,8 @@ public void download_tracked_entity_instances() throws Exception {
Response metadataResponse = d2.syncMetaData().call();
assertThat(metadataResponse.isSuccessful()).isTrue();

Response teiResponse = d2.downloadTrackedEntityInstances(5).call();
assertThat(teiResponse.isSuccessful()).isTrue();
List<TrackedEntityInstance> trackedEntityInstances =
d2.downloadTrackedEntityInstances(5, false).call();
assertThat(trackedEntityInstances.size() == 5).isTrue();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.hisp.dhis.android.core;

import org.hisp.dhis.android.core.common.D2Factory;
import org.hisp.dhis.android.core.data.api.OuMode;
import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.data.server.RealServerMother;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQuery;
import org.hisp.dhis.android.core.user.User;
import org.junit.Before;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import retrofit2.Response;

import static com.google.common.truth.Truth.assertThat;

public class TrackedEntityInstanceQueryAndDownloadRealIntegrationShould extends AbsStoreTestCase {
private D2 d2;
private TrackedEntityInstanceQuery.Builder queryBuilder;

@Before
@Override
public void setUp() throws IOException {
super.setUp();

d2 = D2Factory.create(RealServerMother.url, databaseAdapter());


List<String> orgUnits = new ArrayList<>();
orgUnits.add("O6uvpzGd5pu");

queryBuilder = TrackedEntityInstanceQuery.builder()
.paging(true).page(1).pageSize(50)
.orgUnits(orgUnits).orgUnitMode(OuMode.ACCESSIBLE);
}

//@Test
public void query_and_download_tracked_entity_instances() throws Exception {
login();

d2.syncMetaData().call();

TrackedEntityInstanceQuery query = queryBuilder.build();
List<TrackedEntityInstance> queriedTeis = d2.queryTrackedEntityInstances(query).call();
assertThat(queriedTeis).isNotEmpty();

Set<String> uids = new HashSet<>(queriedTeis.size());

for(TrackedEntityInstance tei: queriedTeis) {
uids.add(tei.uid());
}

List<TrackedEntityInstance> downloadedTeis = d2.downloadTrackedEntityInstancesByUid(uids).call();
assertThat(queriedTeis.size()).isEqualTo(downloadedTeis.size());
}

private void login() throws Exception {
d2.logout().call();
Response<User> loginResponse = d2.logIn("android", "Android123").call();
assertThat(loginResponse.isSuccessful()).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.util.List;
import java.util.Map;

import retrofit2.Response;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
Expand All @@ -38,9 +36,9 @@ public class TrackerDataCallMockIntegrationShould extends AbsStoreTestCase {

private Dhis2MockServer dhis2MockServer;
private D2 d2;
TrackedEntityInstanceStore trackedEntityInstanceStore;
ResourceStore resourceStore;
EnrollmentStore enrollmentStore;
private TrackedEntityInstanceStore trackedEntityInstanceStore;
private ResourceStore resourceStore;
private EnrollmentStore enrollmentStore;

@Override
@Before
Expand Down Expand Up @@ -70,9 +68,9 @@ public void not_download_tracked_entity_instances_if_does_not_exists_nothing_in_

givenAMetadataInDatabase();

Response response = d2.syncTrackerData().call();
d2.syncTrackerData().call();

verifyHaveNotSynchronized(response, Collections.EMPTY_LIST);
verifyHaveNotSynchronized(Collections.EMPTY_LIST);
}

@Test
Expand All @@ -84,9 +82,9 @@ public void not_download_tracked_entity_instances_if_does_not_exists_synced_in_d
TrackedEntityInstance toPostTrackedEntityInstance =
givenAToPostTrackedEntityInstanceInDatabase();

Response response = d2.syncTrackerData().call();
d2.syncTrackerData().call();

verifyHaveNotSynchronized(response, Arrays.asList(toPostTrackedEntityInstance));
verifyHaveNotSynchronized(Arrays.asList(toPostTrackedEntityInstance));
}

@Test
Expand All @@ -102,10 +100,9 @@ public void only_download_synced_tracked_entity_instance_that_exists_in_database

dhis2MockServer.enqueueMockResponse("tracked_entity_instance.json");

Response response = d2.syncTrackerData().call();
d2.syncTrackerData().call();

verifyHaveSynchronized(response,
Arrays.asList(syncedTrackedEntityInstance),
verifyHaveSynchronized(Arrays.asList(syncedTrackedEntityInstance),
Arrays.asList(toPostTrackedEntityInstance));
}

Expand All @@ -114,20 +111,18 @@ public void download_all_synced_tracked_entity_instances_that_exists_in_database
throws Exception {
givenAMetadataInDatabase();

List<TrackedEntityInstance> trackedEntityInstances =
givenASyncedTrackedEntityInstancesInDatabase();
List<TrackedEntityInstance> trackedEntityInstances = givenASyncedTrackedEntityInstancesInDatabase();

dhis2MockServer.enqueueMockResponse("tracked_entity_instance.json");
dhis2MockServer.enqueueMockResponse("tracked_entity_instance_2.json");

Response response = d2.syncTrackerData().call();
d2.syncTrackerData().call();

verifyHaveSynchronized(response, trackedEntityInstances, Collections.EMPTY_LIST);
verifyHaveSynchronized(trackedEntityInstances, Collections.EMPTY_LIST);
}

private void verifyHaveSynchronized(Response response,
List<TrackedEntityInstance> syncedExpected,
List<TrackedEntityInstance> toPostExpected) {
private void verifyHaveSynchronized(List<TrackedEntityInstance> syncedExpected,
List<TrackedEntityInstance> toPostExpected) {

Map<String, TrackedEntityInstance> toPostInDatabase =
trackedEntityInstanceStore.queryToPost();
Expand All @@ -140,7 +135,6 @@ private void verifyHaveSynchronized(Response response,

Map<String, List<Enrollment>> enrollmentsMap = enrollmentStore.queryAll();

assertThat(response.isSuccessful(), is(true));
assertThat(syncedInDatabase.size(), is(syncedExpected.size()));
assertThat(lastUpdated, is(nullValue()));
assertThat(toPostInDatabase.size(), is(toPostExpected.size()));
Expand All @@ -156,7 +150,7 @@ private void verifyHaveSynchronized(Response response,
}
}

private void verifyHaveNotSynchronized(Response response,
private void verifyHaveNotSynchronized(
List<TrackedEntityInstance> expectedToPost) {

Map<String, TrackedEntityInstance> inDatabaseToPost =
Expand All @@ -168,7 +162,6 @@ private void verifyHaveNotSynchronized(Response response,
String lastUpdated = resourceStore.getLastUpdated(
ResourceModel.Type.TRACKED_ENTITY_INSTANCE);

assertThat(response, is(nullValue()));
assertThat(inDatabaseSynced.size(), is(0));
assertThat(lastUpdated, is(nullValue()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,82 +28,51 @@

package org.hisp.dhis.android.core.constant;

import android.content.ContentValues;
import android.database.MatrixCursor;
import android.database.Cursor;
import android.support.test.runner.AndroidJUnit4;

import org.hisp.dhis.android.core.common.BaseIdentifiableObject;
import org.hisp.dhis.android.core.common.IdentifiableModelAbstractShould;
import org.hisp.dhis.android.core.constant.ConstantModel.Columns;
import org.hisp.dhis.android.core.utils.ColumnsArrayUtils;
import org.hisp.dhis.android.core.utils.Utils;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Date;
import java.util.Arrays;
import java.util.List;

import static com.google.common.truth.Truth.assertThat;
import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.fillIdentifiableModelProperties;

@RunWith(AndroidJUnit4.class)
public class ConstantModelShould {

private static final Long ID = 11L;
private static final String UID = "test_uid";
private static final String CODE = "test_code";
private static final String NAME = "test_name";
private static final String DISPLAY_NAME = "test_display_name";
private static final String VALUE = "0.18";

private final Date date;
private final String dateString;
public class ConstantModelShould extends IdentifiableModelAbstractShould<ConstantModel> {

public ConstantModelShould() {
this.date = new Date();
this.dateString = BaseIdentifiableObject.DATE_FORMAT.format(date);
super(new Columns().all(), 7);
}

@Test
public void create_model_when_created_from_database_cursor() {
MatrixCursor cursor = new MatrixCursor(new String[]{
Columns.ID, Columns.UID, Columns.CODE, Columns.NAME,
Columns.DISPLAY_NAME, Columns.CREATED, Columns.LAST_UPDATED, Columns.VALUE
});
cursor.addRow(new Object[]{ID, UID, CODE, NAME, DISPLAY_NAME, dateString, dateString, VALUE});
cursor.moveToFirst();
@Override
protected ConstantModel buildModel() {
ConstantModel.Builder builder = ConstantModel.builder();
fillIdentifiableModelProperties(builder);
builder.value("0.18");
return builder.build();
}

ConstantModel model = ConstantModel.create(cursor);
cursor.close();
@Override
protected ConstantModel cursorToModel(Cursor cursor) {
return ConstantModel.create(cursor);
}

assertThat(model.id()).isEqualTo(ID);
assertThat(model.uid()).isEqualTo(UID);
assertThat(model.code()).isEqualTo(CODE);
assertThat(model.name()).isEqualTo(NAME);
assertThat(model.displayName()).isEqualTo(DISPLAY_NAME);
assertThat(model.created()).isEqualTo(date);
assertThat(model.lastUpdated()).isEqualTo(date);
assertThat(model.value()).isEqualTo(VALUE);
@Override
protected Object[] getModelAsObjectArray() {
return Utils.appendInNewArray(ColumnsArrayUtils.getIdentifiableModelAsObjectArray(model), model.value());
}

@Test
public void create_content_values_when_created_from_builder() {
ConstantModel model = ConstantModel.builder()
.id(ID)
.uid(UID)
.code(CODE)
.name(NAME)
.displayName(DISPLAY_NAME)
.created(date)
.lastUpdated(date)
.value(VALUE)
.build();

ContentValues contentValues = model.toContentValues();

assertThat(contentValues.getAsLong(Columns.ID)).isEqualTo(ID);
assertThat(contentValues.getAsString(Columns.UID)).isEqualTo(UID);
assertThat(contentValues.getAsString(Columns.CODE)).isEqualTo(CODE);
assertThat(contentValues.getAsString(Columns.NAME)).isEqualTo(NAME);
assertThat(contentValues.getAsString(Columns.DISPLAY_NAME)).isEqualTo(DISPLAY_NAME);
assertThat(contentValues.getAsString(Columns.CREATED)).isEqualTo(dateString);
assertThat(contentValues.getAsString(Columns.LAST_UPDATED)).isEqualTo(dateString);
assertThat(contentValues.getAsString(Columns.VALUE)).isEqualTo(VALUE); // Undeprecated in later versions of Truth
public void have_extra_legend_model_columns() {
List<String> columnsList = Arrays.asList(columns);

assertThat(columnsList.contains(Columns.VALUE)).isEqualTo(true);
}
}
Loading

0 comments on commit 35dc707

Please sign in to comment.