Skip to content

Commit

Permalink
Merge pull request #216 from dhis2/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dhis2-android authored May 7, 2018
2 parents 55416b5 + d57b6c9 commit 8598f45
Show file tree
Hide file tree
Showing 721 changed files with 5,889 additions and 2,069 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 : 70,
versionName : "0.7.0-SNAPSHOT"
versionCode : 75,
versionName : "0.7.5-SNAPSHOT"
]

libraries = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.hisp.dhis.rules.models;

import com.google.auto.value.AutoValue;

import javax.annotation.Nonnull;

@AutoValue
public abstract class RuleActionHideProgramStage extends RuleAction {

@Nonnull
public abstract String programStage();

@Nonnull
public static AutoValue_RuleActionHideProgramStage create(@Nonnull String programStage) {
return new AutoValue_RuleActionHideProgramStage(programStage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ 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());

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

Expand All @@ -175,6 +176,7 @@ private void givenALoginInDatabase() throws Exception {

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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.List;

import retrofit2.Response;

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

public class TrackedEntityInstanceQueryCallRealIntegrationShould 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).program("IpHINAT79UW");
}

//@Test
public void query_tracked_entity_instances_no_filter() throws Exception {
login();
List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(queryBuilder.build()).call();
assertThat(queryResponse).isNotEmpty();
}

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

TrackedEntityInstanceQuery query = queryBuilder.query("jorge").build();
List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
assertThat(queryResponse).isNotEmpty();
}

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

List<String> attributeList = new ArrayList<>(1);
attributeList.add("w75KJ2mc4zz:like:jorge");

TrackedEntityInstanceQuery query = queryBuilder.attribute(attributeList).build();
List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
assertThat(queryResponse).isNotEmpty();
}

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

List<String> attributeList = new ArrayList<>(2);
attributeList.add("w75KJ2mc4zz:like:Filona");
attributeList.add("zDhUuAYrxNC:like:Ryder");

TrackedEntityInstanceQuery query = queryBuilder.attribute(attributeList).build();
List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
assertThat(queryResponse).isNotEmpty();
}

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

List<String> attributeList = new ArrayList<>(1);
attributeList.add("w75KJ2mc4zz");

TrackedEntityInstanceQuery query = queryBuilder.attribute(attributeList).build();
List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
assertThat(queryResponse).isNotEmpty();
}

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

List<String> filterList = new ArrayList<>(1);
filterList.add("w75KJ2mc4zz:like:jorge");

TrackedEntityInstanceQuery query = queryBuilder.filter(filterList).build();
List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
assertThat(queryResponse).isNotEmpty();
}

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

List<String> filterList = new ArrayList<>(2);
filterList.add("w75KJ2mc4zz:like:Filona");
filterList.add("zDhUuAYrxNC:like:Ryder");

TrackedEntityInstanceQuery query = queryBuilder.filter(filterList).build();
List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
assertThat(queryResponse).isNotEmpty();
}

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 @@ -100,7 +100,6 @@ public void only_download_synced_tracked_entity_instance_that_exists_in_database
TrackedEntityInstance syncedTrackedEntityInstance =
givenASyncedTrackedEntityInstanceInDatabase();

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

Response response = d2.syncTrackerData().call();
Expand All @@ -118,7 +117,6 @@ public void download_all_synced_tracked_entity_instances_that_exists_in_database
List<TrackedEntityInstance> trackedEntityInstances =
givenASyncedTrackedEntityInstancesInDatabase();

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

Expand All @@ -144,7 +142,7 @@ private void verifyHaveSynchronized(Response response,

assertThat(response.isSuccessful(), is(true));
assertThat(syncedInDatabase.size(), is(syncedExpected.size()));
assertThat(lastUpdated, is(notNullValue()));
assertThat(lastUpdated, is(nullValue()));
assertThat(toPostInDatabase.size(), is(toPostExpected.size()));

for (TrackedEntityInstance trackedEntityInstance : syncedExpected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.Before;

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

Expand Down Expand Up @@ -45,7 +46,7 @@ public void download_categories_combos_and_relatives() throws Exception {

Call<Response<Payload<CategoryCombo>>> categoryComboEndpointCall =
CategoryComboEndpointCall.FACTORY.create(
GenericCallData.create(databaseAdapter(), d2.retrofit()));
GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date()));
Response<Payload<CategoryCombo>> responseCategory = categoryComboEndpointCall.call();

assertResponseIsCorrect(responseCategory);
Expand All @@ -68,7 +69,7 @@ private void assertDataIsProperlyParsedAndInsertedInTheDB() {
private void downloadCategories() throws Exception {
Call<Response<Payload<Category>>> categoryEndpointCall =
CategoryEndpointCall.FACTORY.create(
GenericCallData.create(databaseAdapter(), d2.retrofit()));
GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date()));
categoryEndpointCall.call();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.Test;

import java.io.IOException;
import java.util.Date;

import retrofit2.Response;

Expand All @@ -36,7 +37,7 @@ public void call_categories_endpoint() throws Exception {
Truth.assertThat(responseLogIn.isSuccessful()).isTrue();

Call<Response<Payload<Category>>> categoryEndpointCall = CategoryEndpointCall.FACTORY.create(
GenericCallData.create(databaseAdapter(), d2.retrofit())
GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date())
);
Response<Payload<Category>> responseCategory = categoryEndpointCall.call();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.hisp.dhis.android.core.event.EventEndPointCall;
import org.hisp.dhis.android.core.event.EventQuery;

import java.util.Date;

import retrofit2.Retrofit;

public class EventCallFactory {
Expand All @@ -18,8 +20,8 @@ public static EventEndPointCall create(Retrofit retrofit,
.withPageLimit(pageLimit)
.build();

GenericCallData data = GenericCallData.create(databaseAdapter, retrofit);
return EventEndPointCall.create(data, data.serverDate(), eventQuery);
GenericCallData data = GenericCallData.create(databaseAdapter, retrofit, new Date());
return EventEndPointCall.create(data, eventQuery);
}

public static EventEndPointCall create(Retrofit retrofit,
Expand All @@ -43,7 +45,7 @@ public static EventEndPointCall create(Retrofit retrofit,
.withCategoryComboAndCategoryOption(categoryCombo, categoryOption)
.build();

GenericCallData data = GenericCallData.create(databaseAdapter, retrofit);
return EventEndPointCall.create(data, data.serverDate(), eventQuery);
GenericCallData data = GenericCallData.create(databaseAdapter, retrofit, new Date());
return EventEndPointCall.create(data, eventQuery);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import org.hisp.dhis.android.core.utils.ColumnsAsserts;
import org.junit.Test;

public abstract class IdentifiableModelAbstractShould<P extends BaseIdentifiableObject,
M extends BaseIdentifiableObjectModel> extends ModelAbstractShould<P, M> {
public abstract class IdentifiableModelAbstractShould<M extends BaseIdentifiableObjectModel>
extends ModelAbstractShould<M> {

public IdentifiableModelAbstractShould(String[] columns, int columnsLength, ModelBuilder<P, M> modelBuilder) {
super(columns, columnsLength, modelBuilder);
public IdentifiableModelAbstractShould(String[] columns, int columnsLength) {
super(columns, columnsLength);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public void setUp() throws IOException {
this.model = StoreMocks.generateOptionSetModel();
this.updatedModel = StoreMocks.generateUpdatedOptionSetModel();
this.store = StoreFactory.identifiableStore(databaseAdapter(),
OptionSetModel.TABLE, OptionSetModel.Columns.all());
OptionSetModel.TABLE, new OptionSetModel.Columns().all());
}

private Cursor getCursor() {
return getCursor(OptionSetModel.TABLE, OptionSetModel.Columns.all());
return getCursor(OptionSetModel.TABLE, new OptionSetModel.Columns().all());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,12 @@

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

import org.junit.Test;

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

public abstract class ModelAbstractShould<P, M extends BaseModel> extends LinkModelAbstractShould<M> {
public abstract class ModelAbstractShould<M extends BaseModel> extends LinkModelAbstractShould<M> {

protected final M model;
private final P pojo;
private final ModelBuilder<P, M> modelBuilder;

public ModelAbstractShould(String[] columns, int columnsLength, ModelBuilder<P, M> modelBuilder) {
public ModelAbstractShould(String[] columns, int columnsLength) {
super(columns, columnsLength);
this.model = buildModel();
this.pojo = buildPojo();
this.modelBuilder = modelBuilder;
}

protected abstract P buildPojo();

@Test
public void create_model_from_pojo() {
assertThat(modelBuilder.buildModel(pojo)).isEqualTo(model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import org.hisp.dhis.android.core.utils.ColumnsAsserts;
import org.junit.Test;

public abstract class NameableModelAbstractShould<P extends BaseNameableObject,
M extends BaseNameableObjectModel> extends IdentifiableModelAbstractShould<P, M> {
public abstract class NameableModelAbstractShould<
M extends BaseNameableObjectModel> extends IdentifiableModelAbstractShould<M> {

public NameableModelAbstractShould(String[] columns, int columnsLength, ModelBuilder<P, M> modelBuilder) {
super(columns, columnsLength, modelBuilder);
public NameableModelAbstractShould(String[] columns, int columnsLength) {
super(columns, columnsLength);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public void setUp() throws IOException {
super.setUp();
this.model = StoreMocks.generateOptionSetModel();
this.store = StoreFactory.objectStore(databaseAdapter(),
OptionSetModel.TABLE, OptionSetModel.Columns.all());
OptionSetModel.TABLE, new OptionSetModel.Columns().all());
}

@Test
public void insert_model() {
store.insert(model);
Cursor cursor = getCursor(OptionSetModel.TABLE, OptionSetModel.Columns.all());
Cursor cursor = getCursor(OptionSetModel.TABLE, new OptionSetModel.Columns().all());
optionSetCursorAssert(cursor, model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
public class ValueTypeDeviceRenderingModelShould extends LinkModelAbstractShould<ValueTypeDeviceRenderingModel> {

public ValueTypeDeviceRenderingModelShould() {
super(Columns.all(), 8);
super(new Columns().all(), 8);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import org.hisp.dhis.android.core.common.GenericCallData;
import org.hisp.dhis.android.core.common.Payload;
import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.resource.ResourceHandler;
import org.hisp.dhis.android.core.resource.ResourceStoreImpl;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -40,9 +39,7 @@ public void setUp() throws IOException {
}

private Call<Response<Payload<DataElement>>> createCall() {
ResourceHandler resourceHandler =
new ResourceHandler(new ResourceStoreImpl(databaseAdapter()));
GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit());
GenericCallData data = GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date());

Set<String> uids = new HashSet<>();

Expand Down
Loading

0 comments on commit 8598f45

Please sign in to comment.