Commit 1f6fe52e authored by rahadi's avatar rahadi

Added Pemutakhiran Module

Migrate to id.ac.stis.capi
parent fb614149
{
"project_info": {
"project_number": "1043539700437",
"firebase_url": "https://capi-stis-95e29.firebaseio.com",
"project_id": "capi-stis-95e29",
"storage_bucket": "capi-stis-95e29.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1043539700437:android:5e1d7c3c296329e8",
"android_client_info": {
"package_name": "org.odk.collect.android"
}
},
"oauth_client": [
{
"client_id": "1043539700437-q0vjmegkorlp8enhq26eahj2p0f5dil8.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyC8ocyCpQ_khywwxxF_SHd7aBqW1ME5pbY"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
package id.ac.stis.capi.tasks;
import org.junit.Test;
import id.ac.stis.capi.MockedServerTest;
import id.ac.stis.capi.logic.FormDetails;
import org.ac.stis.capi.test.MockedServerTest;
import java.util.Map;
import okhttp3.mockwebserver.RecordedRequest;
import static id.ac.stis.capi.TestUtils.assertMatches;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.ac.stis.capi.test.TestUtils.assertMatches;
public class DownloadFormListTaskTest extends MockedServerTest {
......@@ -26,7 +27,7 @@ public class DownloadFormListTaskTest extends MockedServerTest {
RecordedRequest r = nextRequest();
assertEquals("GET", r.getMethod());
assertEquals("/formList", r.getPath());
assertMatches("Dalvik/.* org.odk.collect.android/.*", r.getHeader("User-Agent"));
assertMatches("Dalvik/.* id.ac.stis.capi/.*", r.getHeader("User-Agent"));
assertEquals("1.0", r.getHeader("X-OpenRosa-Version"));
assertEquals("gzip", r.getHeader("Accept-Encoding"));
......
......@@ -7,20 +7,21 @@ import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import id.ac.stis.capi.MockedServerTest;
import id.ac.stis.capi.dao.InstancesDao;
import id.ac.stis.capi.dto.Instance;
import id.ac.stis.capi.provider.InstanceProviderAPI;
import id.ac.stis.capi.tasks.InstanceUploaderTask.Outcome;
import org.ac.stis.capi.test.MockedServerTest;
import okhttp3.mockwebserver.RecordedRequest;
import static id.ac.stis.capi.TestUtils.assertMatches;
import static id.ac.stis.capi.TestUtils.cleanUpTempFiles;
import static id.ac.stis.capi.TestUtils.createTempFile;
import static id.ac.stis.capi.TestUtils.resetInstancesContentProvider;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.ac.stis.capi.test.TestUtils.assertMatches;
import static org.ac.stis.capi.test.TestUtils.cleanUpTempFiles;
import static org.ac.stis.capi.test.TestUtils.createTempFile;
import static org.ac.stis.capi.test.TestUtils.resetInstancesContentProvider;
public class InstanceUploaderTest extends MockedServerTest {
private InstancesDao dao;
......@@ -56,7 +57,7 @@ public class InstanceUploaderTest extends MockedServerTest {
RecordedRequest r = nextRequest();
assertEquals("HEAD", r.getMethod());
assertMatches("/submission\\?deviceID=\\w+%3A\\w+", r.getPath());
assertMatches("Dalvik/.* org.odk.collect.android/.*", r.getHeader("User-Agent"));
assertMatches("Dalvik/.* id.ac.stis.capi/.*", r.getHeader("User-Agent"));
assertEquals("1.0", r.getHeader("X-OpenRosa-Version"));
assertEquals("gzip,deflate", r.getHeader("Accept-Encoding"));
}
......@@ -66,7 +67,7 @@ public class InstanceUploaderTest extends MockedServerTest {
RecordedRequest r = nextRequest();
assertEquals("POST", r.getMethod());
assertEquals("/submission", r.getPath());
assertMatches("Dalvik/.* org.odk.collect.android/.*", r.getHeader("User-Agent"));
assertMatches("Dalvik/.* id.ac.stis.capi/.*", r.getHeader("User-Agent"));
assertEquals("1.0", r.getHeader("X-OpenRosa-Version"));
assertEquals("gzip,deflate", r.getHeader("Accept-Encoding"));
assertMatches("multipart/form-data; boundary=.*", r.getHeader("Content-Type"));
......
......@@ -2,8 +2,9 @@ package id.ac.stis.capi.utilities;
import org.junit.Before;
import org.junit.Test;
import id.ac.stis.capi.MockedServerTest;
import id.ac.stis.capi.application.Collect;
import org.ac.stis.capi.test.MockedServerTest;
import org.opendatakit.httpclientandroidlib.client.HttpClient;
import org.opendatakit.httpclientandroidlib.client.methods.HttpGet;
import org.opendatakit.httpclientandroidlib.protocol.HttpContext;
......@@ -13,10 +14,10 @@ import java.net.URI;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.RecordedRequest;
import static id.ac.stis.capi.TestUtils.assertMatches;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.ac.stis.capi.test.TestUtils.assertMatches;
public class WebUtilsTest extends MockedServerTest {
@Before
......@@ -33,7 +34,7 @@ public class WebUtilsTest extends MockedServerTest {
// then
RecordedRequest r = nextRequest();
assertEquals("GET /some-path HTTP/1.1", r.getRequestLine());
assertTrue(r.getHeader("User-Agent").matches("Dalvik/.* org.odk.collect.android/.*"));
assertTrue(r.getHeader("User-Agent").matches("Dalvik/.* id.ac.stis.capi/.*"));
}
@Test
......@@ -42,7 +43,7 @@ public class WebUtilsTest extends MockedServerTest {
WebUtils.getXmlDocument(url("/list-forms"), httpContext(), httpClient());
// then
assertMatches("Dalvik/.* org.odk.collect.android/.*",
assertMatches("Dalvik/.* id.ac.stis.capi/.*",
nextRequest().getHeader("User-Agent"));
}
......
package org.ac.stis.capi;
import android.app.Instrumentation.ActivityResult;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.filters.Suppress;
import android.support.test.runner.AndroidJUnit4;
import net.bytebuddy.utility.RandomString;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import id.ac.stis.capi.activities.BearingActivity;
import id.ac.stis.capi.activities.FormEntryActivity;
import id.ac.stis.capi.utilities.ActivityAvailability;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.Random;
import static android.app.Activity.RESULT_CANCELED;
import static android.app.Activity.RESULT_OK;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.swipeLeft;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.Intents.intending;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasData;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtra;
import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.startsWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static id.ac.stis.capi.activities.FormEntryActivity.BEARING_RESULT;
import static id.ac.stis.capi.activities.FormEntryActivity.EXTRA_TESTING_PATH;
@RunWith(AndroidJUnit4.class)
@Suppress
public class AllFormsWidgetTest {
private static final String ALL_WIDGETS_FORM = "all_widgets.xml";
private static final String FORMS_DIRECTORY = "/odk/forms/";
private final Random random = new Random();
private ActivityResult okResult = new ActivityResult(RESULT_OK, new Intent());
@Rule
public FormEntryActivityTestRule activityTestRule = new FormEntryActivityTestRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private ActivityAvailability activityAvailability;
//region Test prep.
@BeforeClass
public static void copyFormToSdCard() throws IOException {
String pathname = formPath();
if (new File(pathname).exists()) {
return;
}
AssetManager assetManager = InstrumentationRegistry.getContext().getAssets();
InputStream inputStream = assetManager.open(ALL_WIDGETS_FORM);
File outFile = new File(pathname);
OutputStream outputStream = new FileOutputStream(outFile);
IOUtils.copy(inputStream, outputStream);
}
@Before
public void prepareDependencies() {
FormEntryActivity activity = activityTestRule.getActivity();
activity.setActivityAvailability(activityAvailability);
activity.setShouldOverrideAnimations(true);
}
//endregion
//region Main test block.
@Test
public void testActivityOpen() {
skipInitialLabel();
testStringWidget();
testStringNumberWidget();
testUrlWidget();
testExStringWidget();
testExPrinterWidget();
testIntegerWidget();
testExIntegerWidget();
testDecimalWidget();
testExDecimalWidget();
testBearingWidget();
testImageWidget();
testSelfieWidget();
testDrawWidget();
testAnnotateWidget();
testSignatureWidget();
testWebViewImageWidget();
testAlignImageWidget();
testBarcodeWidget();
testAudioWidget();
testVideoWidget();
testDateNoAppearanceWidget();
testDateNoCalendarAppearance();
testDateMonthYearAppearance();
testDateYearAppearance();
testTimeNoAppearance();
testDateTimeNoAppearance();
testDateTimeNoCalendarAppearance();
testGeopointNoAppearance();
testGeopointPlacementMapApperance();
testGeopointMapsAppearance();
testGeotraceWidget();
testGeoshapeWidget();
testOSMIntegrationOSMType();
testOSMIntegrationBuildingType();
testSelectOneNoAppearance();
testSpinnerWidget();
testSelectOneAutoAdvance();
testSelectOneSearchAppearance();
testSelectOneSearchAutoAdvance();
testGridSelectNoAppearance();
testGridSelectCompactAppearance();
testGridSelectCompact2Appearance();
testGridSelectQuickCompactAppearance();
testGridSelectQuickCompact2Appearance();
testMultiSelectWidget();
testGridSelectMultipleCompact();
testGridSelectCompact2();
testSpinnerSelectMultiple();
testLabelWidget();
testTriggerWidget();
}
//endregion
//region Widget tests.
public void skipInitialLabel() {
onView(withText(startsWith("This form"))).perform(swipeLeft());
}
public void testStringWidget() {
String stringWidgetText = randomString();
onVisibleEditText().perform(replaceText(stringWidgetText));
openWidgetList();
onView(withText("String widget")).perform(click());
onVisibleEditText().check(matches(withText(stringWidgetText)));
onView(withText("String widget")).perform(swipeLeft());
}
public void testStringNumberWidget() {
String stringNumberWidgetText = randomIntegerString();
onVisibleEditText().perform(replaceText(stringNumberWidgetText));
openWidgetList();
onView(withText("String number widget")).perform(click());
onVisibleEditText().check(matches(withText(stringNumberWidgetText)));
onView(withText("String number widget")).perform(swipeLeft());
}
public void testUrlWidget() {
Uri uri = Uri.parse("http://opendatakit.org/");
intending(allOf(hasAction(Intent.ACTION_VIEW), hasData(uri)))
.respondWith(okResult);
onView(withId(R.id.simple_button)).perform(click());
onView(withText("URL widget")).perform(swipeLeft());
}
public void testExStringWidget() {
// Manually input the value:
String exStringWidgetFirstText = randomString();
when(activityAvailability.isActivityAvailable(any(Intent.class)))
.thenReturn(false);
onView(withText("Launch")).perform(click());
onVisibleEditText().perform(replaceText(exStringWidgetFirstText));
openWidgetList();
onView(withText("Ex string widget")).perform(click());
onVisibleEditText().check(matches(withText(exStringWidgetFirstText)));
// Replace with Intent value:
String exStringWidgetSecondText = randomString();
Intent stringIntent = new Intent();
stringIntent.putExtra("value", exStringWidgetSecondText);
ActivityResult exStringResult = new ActivityResult(RESULT_OK, stringIntent);
intending(allOf(
hasAction("change.uw.android.BREATHCOUNT"),
hasExtra("value", exStringWidgetFirstText)
)).respondWith(exStringResult);
when(activityAvailability.isActivityAvailable(any(Intent.class)))
.thenReturn(true);
onView(withText("Launch")).perform(click());
onView(withText(exStringWidgetSecondText))
.check(matches(isDisplayed()));
openWidgetList();
onView(withText("Ex string widget")).perform(click());
onVisibleEditText().check(matches(withText(exStringWidgetSecondText)));
onView(withText("Ex string widget")).perform(swipeLeft());
}
public void testExPrinterWidget() {
onView(withText("Initiate Printing")).perform(click());
intending(hasAction("org.opendatakit.sensors.ZebraPrinter"));
intended(hasAction("org.opendatakit.sensors.ZebraPrinter"));
// There is also a BroadcastIntent that sends the data but we don't
// have a way to test that currently.
// Will probably move that out to a helper class we can Unit test in Robolectric and
// inject here.
onView(withText("Ex printer widget")).perform(swipeLeft());
}
public void testIntegerWidget() {
String integerString = randomIntegerString();
onVisibleEditText().perform(replaceText(integerString));
openWidgetList();
onView(withText("Integer widget")).perform(click());
onVisibleEditText().check(matches(withText(integerString)));
onView(withText("Integer widget")).perform(swipeLeft());
}
public void testExIntegerWidget() {
// Manually input the value:
String exIntegerFirstValue = randomIntegerString();
when(activityAvailability.isActivityAvailable(any(Intent.class)))
.thenReturn(false);
onView(withText("Launch")).perform(click());
onVisibleEditText().perform(replaceText(exIntegerFirstValue));
openWidgetList();
onView(withText("Ex integer widget")).perform(click());
onVisibleEditText().check(matches(withText(exIntegerFirstValue)));
// Replace with Intent value:
String exIntegerSecondValue = randomIntegerString();
Intent stringIntent = new Intent();
stringIntent.putExtra("value", Integer.parseInt(exIntegerSecondValue));
ActivityResult exStringResult = new ActivityResult(RESULT_OK, stringIntent);
intending(allOf(
hasAction("change.uw.android.BREATHCOUNT"),
hasExtra("value", Integer.parseInt(exIntegerFirstValue))
)).respondWith(exStringResult);
when(activityAvailability.isActivityAvailable(any(Intent.class)))
.thenReturn(true);
onView(withText("Launch")).perform(click());
onView(withText(exIntegerSecondValue))
.check(matches(isDisplayed()));
openWidgetList();
onView(withText("Ex integer widget")).perform(click());
onVisibleEditText().check(matches(withText(exIntegerSecondValue)));
onView(withText("Ex integer widget")).perform(swipeLeft());
}
public void testDecimalWidget() {
String decimalString = randomDecimalString();
onVisibleEditText().perform(replaceText(decimalString));
openWidgetList();
onView(withText("Decimal widget")).perform(click());
onVisibleEditText().check(matches(withText(decimalString)));
onView(withText("Decimal widget")).perform(swipeLeft());
}
public void testExDecimalWidget() {
// Manually input the value:
String exDecimalFirstValue = randomDecimalString();
when(activityAvailability.isActivityAvailable(any(Intent.class)))
.thenReturn(false);
onView(withText("Launch")).perform(click());
onVisibleEditText().perform(replaceText(exDecimalFirstValue));
openWidgetList();
onView(withText("Ex decimal widget")).perform(click());
onVisibleEditText().check(matches(withText(exDecimalFirstValue)));
// Replace with Intent value:
String exDecimalSecondValue = randomDecimalString();
Intent stringIntent = new Intent();
stringIntent.putExtra("value", Double.parseDouble(exDecimalSecondValue));
ActivityResult exStringResult = new ActivityResult(RESULT_OK, stringIntent);
intending(allOf(
hasAction("change.uw.android.BREATHCOUNT"),
hasExtra("value", Double.parseDouble(exDecimalFirstValue))
)).respondWith(exStringResult);
when(activityAvailability.isActivityAvailable(any(Intent.class)))
.thenReturn(true);
onView(withText("Launch")).perform(click());
onView(withText(exDecimalSecondValue))
.check(matches(isDisplayed()));
openWidgetList();
onView(withText("Ex decimal widget")).perform(click());
onVisibleEditText().check(matches(withText(exDecimalSecondValue)));
onView(withText("Ex decimal widget")).perform(swipeLeft());
}
public void testBearingWidget() {
intending(hasComponent(BearingActivity.class.getName()))
.respondWith(cancelledResult());
onView(withText("Record Bearing")).perform(click());
onView(withId(R.id.answer_text)).check(matches(withText("")));
double degrees = BearingActivity.normalizeDegrees(randomDecimal());
String bearing = BearingActivity.formatDegrees(degrees);
Intent data = new Intent();
data.putExtra(BEARING_RESULT, bearing);
intending(hasComponent(BearingActivity.class.getName()))
.respondWith(okResult(data));
onView(withText("Record Bearing")).perform(click());
onView(withId(R.id.answer_text))
.check(matches(allOf(isDisplayed(), withText(bearing))));
openWidgetList();
onView(withText("Bearing widget")).perform(click());
onView(withId(R.id.answer_text)).check(matches(withText(bearing)));
onView(withText("Bearing widget")).perform(swipeLeft());
}
public void testImageWidget() {
onView(withText("Image widget")).perform(swipeLeft());
}
public void testSelfieWidget() {
onView(withText("Selfie widget")).perform(swipeLeft());
}
public void testDrawWidget() {
onView(withText("Draw widget")).perform(swipeLeft());
}
public void testAnnotateWidget() {
onView(withText("Annotate widget")).perform(swipeLeft());
}
public void testSignatureWidget() {
onView(withText("Signature widget")).perform(swipeLeft());
}
public void testWebViewImageWidget() {
onView(withText("Web view image widget")).perform(swipeLeft());
}
public void testAlignImageWidget() {
onView(withText("Align image widget")).perform(swipeLeft());
}
public void testBarcodeWidget() {
onView(withText("Barcode widget")).perform(swipeLeft());
}
public void testAudioWidget() {
onView(withText("Audio widget")).perform(swipeLeft());
}
public void testVideoWidget() {
onView(withText("Video widget")).perform(swipeLeft());
}
public void testDateNoAppearanceWidget() {
onView(withText("Date widget")).perform(swipeLeft());
}
public void testDateNoCalendarAppearance() {
onView(withText("Date Widget")).perform(swipeLeft());
}
public void testDateMonthYearAppearance() {
onView(withText("Date widget")).perform(swipeLeft());
}
public void testDateYearAppearance() {
onView(withText("Date widget")).perform(swipeLeft());
}
public void testTimeNoAppearance() {
onView(withText("Time widget")).perform(swipeLeft());
}
public void testDateTimeNoAppearance() {
onView(allOf(withText("Date time widget"), withEffectiveVisibility(VISIBLE)))
.perform(swipeLeft());
}
public void testDateTimeNoCalendarAppearance() {
onView(allOf(withText("Date time widget"), withEffectiveVisibility(VISIBLE)))
.perform(swipeLeft());
}
public void testGeopointNoAppearance() {
onView(withText("Geopoint widget")).perform(swipeLeft());
}
public void testGeopointPlacementMapApperance() {
onView(withText("Geopoint widget")).perform(swipeLeft());
}
public void testGeopointMapsAppearance() {
onView(withText("Geopoint widget")).perform(swipeLeft());
}
public void testGeotraceWidget() {
onView(withText("Geotrace widget")).perform(swipeLeft());
}
public void testGeoshapeWidget() {
onView(withText("Geoshape widget")).perform(swipeLeft());
}
public void testOSMIntegrationOSMType()