Skip to content

Commit

Permalink
Merge pull request #295 from dhis2/develop
Browse files Browse the repository at this point in the history
Develop 0.9.7
  • Loading branch information
josemp10 authored Jul 4, 2018
2 parents 214d461 + 14b5bba commit 5f33f97
Show file tree
Hide file tree
Showing 132 changed files with 2,595 additions and 739 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ ext {
buildToolsVersion: "25.0.2",
minSdkVersion : 15,
targetSdkVersion : 25,
versionCode : 96,
versionName : "0.9.6-SNAPSHOT"
versionCode : 97,
versionName : "0.9.7-SNAPSHOT"
]

libraries = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ public void return_expected_values() throws Exception {
assertThat(duktapeEvaluator.evaluate("true")).isEqualTo("true");
assertThat(duktapeEvaluator.evaluate("\'test_string\'")).isEqualTo("test_string");
}

@Test
public void catch_duktape_exception_on_unquoted_string() {
assertThat(duktapeEvaluator.evaluate("test_string")).isEqualTo("test_string");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.support.annotation.NonNull;

import com.squareup.duktape.Duktape;
import com.squareup.duktape.DuktapeException;

import org.hisp.dhis.rules.RuleExpressionEvaluator;

Expand All @@ -28,6 +29,10 @@ public String evaluate(@Nonnull String expression) {
throw new NullPointerException("expression == null");
}

return duktape.evaluate(expression).toString();
try {
return duktape.evaluate(expression).toString();
} catch (DuktapeException e) {
return expression;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.hisp.dhis.rules.models.RuleActionDisplayKeyValuePair;
import org.hisp.dhis.rules.models.RuleActionDisplayText;
import org.hisp.dhis.rules.models.RuleActionErrorOnCompletion;
import org.hisp.dhis.rules.models.RuleActionScheduleMessage;
import org.hisp.dhis.rules.models.RuleActionSendMessage;
import org.hisp.dhis.rules.models.RuleActionShowError;
import org.hisp.dhis.rules.models.RuleActionShowWarning;
import org.hisp.dhis.rules.models.RuleActionWarningOnCompletion;
Expand All @@ -20,6 +22,11 @@

import javax.annotation.Nonnull;

@SuppressWarnings({
"PMD.CyclomaticComplexity",
"PMD.ModifiedCyclomaticComplexity",
"PMD.StdCyclomaticComplexity"
})
class RuleEngineExecution implements Callable<List<RuleEffect>> {
private static final String D2_FUNCTION_PREFIX = "d2:";

Expand Down Expand Up @@ -87,6 +94,12 @@ private RuleEffect create(@Nonnull RuleAction ruleAction) {
} else if (ruleAction instanceof RuleActionWarningOnCompletion) {
return RuleEffect.create(ruleAction,
process(((RuleActionWarningOnCompletion) ruleAction).data()));
} else if (ruleAction instanceof RuleActionSendMessage) {
return RuleEffect.create(ruleAction,
process(((RuleActionSendMessage) ruleAction).data()));
} else if (ruleAction instanceof RuleActionScheduleMessage) {
return RuleEffect.create(ruleAction,
process(((RuleActionScheduleMessage) ruleAction).data()));
}

return RuleEffect.create(ruleAction);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.hisp.dhis.rules.models;

import com.google.auto.value.AutoValue;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

@AutoValue
public abstract class RuleActionScheduleMessage extends RuleAction {

@Nonnull
public abstract String notification();

@Nonnull
public abstract String data();

@Nonnull
public static RuleActionScheduleMessage create(@Nullable String notification, @Nullable String data) {
return new AutoValue_RuleActionScheduleMessage(notification == null ? "" : notification,
data == null ? "" : data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.hisp.dhis.rules.models;

import com.google.auto.value.AutoValue;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

@AutoValue
public abstract class RuleActionSendMessage extends RuleAction {

@Nonnull
public abstract String notification();

@Nonnull
public abstract String data();

@Nonnull
public static RuleActionSendMessage create(@Nullable String notification, @Nullable String data) {
return new AutoValue_RuleActionSendMessage(notification == null ? "": notification, data == null ? "" : data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.hisp.dhis.rules.models;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static org.assertj.core.api.Java6Assertions.assertThat;

@RunWith(JUnit4.class)
public class RuleActionScheduleMessageShould {

@Test
public void substitute_empty_strings_when_create_with_null_arguments() {
RuleActionScheduleMessage ruleActionScheduleMessage = RuleActionScheduleMessage
.create("notification", "data");
RuleActionScheduleMessage ruleActionScheduleMessageNoData = RuleActionScheduleMessage
.create("notification", null);
RuleActionScheduleMessage ruleActionScheduleMessageNoNotification = RuleActionScheduleMessage
.create(null, "data");

assertThat(ruleActionScheduleMessage.notification()).isEqualTo("notification");
assertThat(ruleActionScheduleMessage.data()).isEqualTo("data");

assertThat(ruleActionScheduleMessageNoData.notification()).isEqualTo("notification");
assertThat(ruleActionScheduleMessageNoData.data()).isEqualTo("");

assertThat(ruleActionScheduleMessageNoNotification.notification()).isEqualTo("");
assertThat(ruleActionScheduleMessageNoNotification.data()).isEqualTo("data");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.hisp.dhis.rules.models;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static org.assertj.core.api.Java6Assertions.assertThat;

@RunWith(JUnit4.class)
public class RuleActionSendMessageShould {

@Test
public void substitute_empty_strings_when_create_with_null_arguments() {
RuleActionSendMessage ruleActionSendMessage = RuleActionSendMessage.create("notification", "data");
RuleActionSendMessage ruleActionSendMessageNoData = RuleActionSendMessage.create("notification", null);
RuleActionSendMessage ruleActionSendMessageNoNotification = RuleActionSendMessage.create(null, "data");

assertThat(ruleActionSendMessage.notification()).isEqualTo("notification");
assertThat(ruleActionSendMessage.data()).isEqualTo("data");

assertThat(ruleActionSendMessageNoData.notification()).isEqualTo("notification");
assertThat(ruleActionSendMessageNoData.data()).isEqualTo("");

assertThat(ruleActionSendMessageNoNotification.notification()).isEqualTo("");
assertThat(ruleActionSendMessageNoNotification.data()).isEqualTo("data");
}

}
7 changes: 7 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ dependencies {
androidTestCompile("com.google.truth:truth:${libraries.truth}") {
exclude group: 'junit' // Android has JUnit built in.
}
androidTestCompile ('com.facebook.stetho:stetho:1.5.0') {
exclude module: 'jsr305'
}
androidTestCompile('com.facebook.stetho:stetho-okhttp3:1.5.0') {
exclude module: 'okhttp'
exclude module: 'jsr305'
}
compile 'com.google.code.findbugs:annotations:3.0.0'
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/androidTest/assets/data_elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"zeroIsSignificant": false,
"url": "",
"optionSetValue": true,
"dimensionItemType": "DATA_ELEMENT"
"dimensionItemType": "DATA_ELEMENT",
"access": {
"read": true
}
}
]
}
13 changes: 11 additions & 2 deletions core/src/androidTest/assets/program_stages.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
"valueType": "BOOLEAN",
"optionSet": {
"id": "VQ2lai3OfVG"
},
"access": {
"read": true
}
}
},
Expand Down Expand Up @@ -94,7 +97,10 @@
"displayFormName": "WHOMCH Smoking cessation counselling provided ",
"zeroIsSignificant": false,
"displayShortName": "Smoking cessation counselling provided ",
"valueType": "BOOLEAN"
"valueType": "BOOLEAN",
"access": {
"read": true
}
}
},
{
Expand Down Expand Up @@ -124,7 +130,10 @@
"displayFormName": "WHOMCH Hemoglobin value",
"zeroIsSignificant": true,
"displayShortName": "Hemoglobin value",
"valueType": "NUMBER"
"valueType": "NUMBER",
"access": {
"read": true
}
}
}
],
Expand Down
9 changes: 9 additions & 0 deletions core/src/androidTest/assets/programs_complete.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
"unique": false,
"valueType": "TEXT",
"orgunitScope": false,
"access": {
"read": true
},
"renderType": {
"DESKTOP": {
"type": "SPINNER",
Expand Down Expand Up @@ -162,6 +165,9 @@
"inherit": false,
"unique": false,
"valueType": "TEXT",
"access": {
"read": true
},
"orgunitScope": false
}
},
Expand Down Expand Up @@ -201,6 +207,9 @@
"inherit": false,
"unique": false,
"valueType": "TEXT",
"access": {
"read": true
},
"orgunitScope": false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.data.server.RealServerMother;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.Date;
Expand All @@ -27,7 +26,7 @@ public void setUp() throws IOException {
d2 = D2Factory.create(RealServerMother.url, databaseAdapter());
}

@Test
//@Test
public void call_categories_endpoint() throws Exception {
d2.logIn(RealServerMother.user, RealServerMother.password).call();

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

import android.support.test.InstrumentationRegistry;

import com.facebook.stetho.okhttp3.StethoInterceptor;

import org.hisp.dhis.android.core.D2;
import org.hisp.dhis.android.core.configuration.ConfigurationModel;
import org.hisp.dhis.android.core.data.api.BasicAuthenticatorFactory;
Expand All @@ -27,6 +29,7 @@ public static D2 create(String url, DatabaseAdapter databaseAdapter) {
new OkHttpClient.Builder()
.addInterceptor(BasicAuthenticatorFactory.create(databaseAdapter))
.addInterceptor(loggingInterceptor)
.addNetworkInterceptor(new StethoInterceptor())
.build()
)
.context(InstrumentationRegistry.getTargetContext().getApplicationContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public void throw_exception_deleting_with_null_uid() {
store.delete(null);
}

@Test
public void do_not_throw_exception_safe_deleting_non_existing_model() {
store.deleteIfExists("new-id");
assertThatCursor(getCursor()).isExhausted();
}

@Test
public void update_model() {
store.insert(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import android.database.sqlite.SQLiteDatabase;
import android.support.test.InstrumentationRegistry;

import com.facebook.stetho.Stetho;

import org.junit.After;
import org.junit.Before;

Expand All @@ -50,6 +52,7 @@ public void setUp() throws IOException {
, dbName);
sqLiteDatabase = dbOpenHelper.getWritableDatabase();
databaseAdapter = new SqLiteDatabaseAdapter(dbOpenHelper);
Stetho.initializeWithDefaults(InstrumentationRegistry.getTargetContext().getApplicationContext());
}

@After
Expand Down
Loading

0 comments on commit 5f33f97

Please sign in to comment.