Search in sources :

Example 6 with ResourceStore

use of org.hisp.dhis.android.core.resource.ResourceStore in project dhis2-android-sdk by dhis2.

the class UserCallMockIntegrationShould method setUp.

@Override
@Before
public void setUp() throws IOException {
    super.setUp();
    mockWebServer = new MockWebServer();
    mockWebServer.start();
    MockResponse mockResponse = new MockResponse();
    mockResponse.setHeader(HeaderUtils.DATE, Calendar.getInstance().getTime());
    // JSON payload is returned from this api query:
    // https://play.dhis2.org/dev/api/me.json?fields=id,code,name,displayName,created,lastUpdated,birthday,
    // education,gender,jobTitle,surname,firstName,introduction,employer,interests,languages,email,
    // phoneNumber,nationality,teiSearchOrganisationUnits[id],organisationUnits[id,programs],
    // userCredentials[id,code,name,displayName,created,lastUpdated,username,userRoles[id,programs[id]]]
    mockResponse.setBody("{\n" + "\n" + "    \"created\": \"2015-03-31T13:31:09.324\",\n" + "    \"lastUpdated\": \"2017-02-01T14:32:33.771\",\n" + "    \"name\": \"John Barnes\",\n" + "    \"id\": \"DXyJmlo9rge\",\n" + "    \"displayName\": \"John Barnes\",\n" + "    \"firstName\": \"John\",\n" + "    \"surname\": \"Barnes\",\n" + "    \"email\": \"john@hmail.com\",\n" + "    \"userCredentials\": {\n" + "        \"lastUpdated\": \"2017-02-01T14:31:54.370\",\n" + "        \"code\": \"android\",\n" + "        \"created\": \"2015-03-31T13:31:09.206\",\n" + "        \"name\": \"John Traore\",\n" + "        \"id\": \"M0fCOxtkURr\",\n" + "        \"displayName\": \"John Traore\",\n" + "        \"username\": \"android\",\n" + "        \"userRoles\": [\n" + "            {\n" + "                \"id\": \"Ufph3mGRmMo\",\n" + "                \"programs\": [\n" + "                    {\n" + "                        \"id\": \"eBAyeGv0exc\"\n" + "                    },\n" + "                    {\n" + "                        \"id\": \"IpHINAT79UW\"\n" + "                    },\n" + "                    {\n" + "                        \"id\": \"WSGAb5XwJ3Y\"\n" + "                    },\n" + "                    {\n" + "                        \"id\": \"ur1Edk5Oe2n\"\n" + "                    }\n" + "                ]\n" + "            },\n" + "            {\n" + "                \"id\": \"Euq3XfEIEbx\",\n" + "                \"programs\": [ ]\n" + "            },\n" + "            {\n" + "                \"id\": \"cUlTcejWree\",\n" + "                \"programs\": [\n" + "                    {\n" + "                        \"id\": \"ur1Edk5Oe2n\"\n" + "                    }\n" + "                ]\n" + "            },\n" + "            {\n" + "                \"id\": \"DRdaVRtwmG5\",\n" + "                \"programs\": [\n" + "                    {\n" + "                        \"id\": \"eBAyeGv0exc\"\n" + "                    }\n" + "                ]\n" + "            },\n" + "            {\n" + "                \"id\": \"jRWSNIHdKww\",\n" + "                \"programs\": [ ]\n" + "            },\n" + "            {\n" + "                \"id\": \"txB7vu1w2Pr\",\n" + "                \"programs\": [ ]\n" + "            }\n" + "        ]\n" + "    },\n" + "    \"teiSearchOrganisationUnits\": [\n" + "        {\n" + "            \"id\": \"WAjjFMDJKcx\"\n" + "        }\n" + "    ],\n" + "    \"organisationUnits\": [\n" + "        {\n" + "            \"id\": \"DiszpKrYNg8\",\n" + "            \"programs\": [\n" + "                {\n" + "                    \"id\": \"eBAyeGv0exc\"\n" + "                },\n" + "                {\n" + "                    \"id\": \"IpHINAT79UW\"\n" + "                },\n" + "                {\n" + "                    \"id\": \"WSGAb5XwJ3Y\"\n" + "                },\n" + "                {\n" + "                    \"id\": \"ur1Edk5Oe2n\"\n" + "                },\n" + "                {\n" + "                    \"id\": \"fDd25txQckK\"\n" + "                }\n" + "            ]\n" + "        }\n" + "    ]\n" + "\n" + "}");
    mockWebServer.enqueue(mockResponse);
    // ToDo: consider moving this out
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setDateFormat(BaseIdentifiableObject.DATE_FORMAT.raw());
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    Retrofit retrofit = new Retrofit.Builder().baseUrl(mockWebServer.url("/")).addConverterFactory(JacksonConverterFactory.create(objectMapper)).addConverterFactory(FieldsConverterFactory.create()).build();
    UserService userService = retrofit.create(UserService.class);
    UserCredentialsStore userCredentialsStore = new UserCredentialsStoreImpl(databaseAdapter());
    UserRoleStore userRoleStore = new UserRoleStoreImpl(databaseAdapter());
    UserStore userStore = new UserStoreImpl(databaseAdapter());
    ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter());
    userCall = new UserCall(userService, databaseAdapter(), userStore, userCredentialsStore, userRoleStore, resourceStore, new Date());
    ContentValues program1 = CreateProgramUtils.create(1L, "eBAyeGv0exc", null, null, null);
    ContentValues program2 = CreateProgramUtils.create(2L, "ur1Edk5Oe2n", null, null, null);
    ContentValues program3 = CreateProgramUtils.create(3L, "fDd25txQckK", null, null, null);
    ContentValues program4 = CreateProgramUtils.create(4L, "WSGAb5XwJ3Y", null, null, null);
    ContentValues program5 = CreateProgramUtils.create(5L, "IpHINAT79UW", null, null, null);
    database().insert(ProgramModel.TABLE, null, program1);
    database().insert(ProgramModel.TABLE, null, program2);
    database().insert(ProgramModel.TABLE, null, program3);
    database().insert(ProgramModel.TABLE, null, program4);
    database().insert(ProgramModel.TABLE, null, program5);
}
Also used : ContentValues(android.content.ContentValues) MockResponse(okhttp3.mockwebserver.MockResponse) ResourceStore(org.hisp.dhis.android.core.resource.ResourceStore) ResourceStoreImpl(org.hisp.dhis.android.core.resource.ResourceStoreImpl) Date(java.util.Date) Retrofit(retrofit2.Retrofit) MockWebServer(okhttp3.mockwebserver.MockWebServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 7 with ResourceStore

use of org.hisp.dhis.android.core.resource.ResourceStore in project dhis2-android-sdk by dhis2.

the class OptionSetCallShould method setUp.

@Override
@Before
public void setUp() throws IOException {
    super.setUp();
    mockWebServer = new MockWebServer();
    mockWebServer.start();
    MockResponse mockResponse = new MockResponse();
    mockResponse.setBody("{\n" + "\n" + "    \"pager\": {\n" + "        \"page\": 1,\n" + "        \"pageCount\": 1,\n" + "        \"total\": 1,\n" + "        \"pageSize\": 50\n" + "    },\n" + "    \"optionSets\": [\n" + "        {\n" + "            \"lastUpdated\": \"2012-09-20T16:05:17.555\",\n" + "            \"created\": \"2012-09-20T16:05:17.555\",\n" + "            \"name\": \"MNCH PMTCT code\",\n" + "            \"id\": \"POc7DkGU3QU\",\n" + "            \"displayName\": \"MNCH PMTCT code\",\n" + "            \"valueType\": \"TEXT\",\n" + "            \"version\": 1,\n" + "            \"options\": [\n" + "                {\n" + "                    \"code\": \"C\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"C\",\n" + "                    \"id\": \"s2gIL3CEyKL\",\n" + "                    \"displayName\": \"C\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 1,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                },\n" + "                {\n" + "                    \"code\": \"TR\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"TR\",\n" + "                    \"id\": \"poM80hUlVi9\",\n" + "                    \"displayName\": \"TR\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 2,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                },\n" + "                {\n" + "                    \"code\": \"TRR\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"TRR\",\n" + "                    \"id\": \"hcvPpAy3kb2\",\n" + "                    \"displayName\": \"TRR\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 3,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                },\n" + "                {\n" + "                    \"code\": \"TRRDm\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"TRRDm\",\n" + "                    \"id\": \"u4wsy7OPQIg\",\n" + "                    \"displayName\": \"TRRDm\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 4,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                }\n" + "            ]\n" + "        }\n" + "    ]\n" + "\n" + "}");
    mockWebServer.enqueue(mockResponse);
    // ToDo: consider moving this out
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setDateFormat(BaseIdentifiableObject.DATE_FORMAT.raw());
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    Retrofit retrofit = new Retrofit.Builder().baseUrl(mockWebServer.url("/")).addConverterFactory(JacksonConverterFactory.create(objectMapper)).addConverterFactory(FieldsConverterFactory.create()).build();
    OptionSetService optionSetService = retrofit.create(OptionSetService.class);
    ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter());
    Set<String> uids = new HashSet<>();
    uids.add("POc7DkGU3QU");
    // TODO fix
    GenericCallData data = GenericCallData.create(databaseAdapter(), new ResourceHandler(resourceStore), retrofit);
    GenericHandler<OptionSet, OptionSetModel> optionSetHandler = OptionSetHandler.create(databaseAdapter());
    optionSetCall = new OptionSetCall(data, optionSetService, optionSetHandler, uids);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ResourceStore(org.hisp.dhis.android.core.resource.ResourceStore) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) GenericCallData(org.hisp.dhis.android.core.common.GenericCallData) ResourceStoreImpl(org.hisp.dhis.android.core.resource.ResourceStoreImpl) Retrofit(retrofit2.Retrofit) MockWebServer(okhttp3.mockwebserver.MockWebServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

ResourceStore (org.hisp.dhis.android.core.resource.ResourceStore)7 ResourceStoreImpl (org.hisp.dhis.android.core.resource.ResourceStoreImpl)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Before (org.junit.Before)5 Date (java.util.Date)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 MockWebServer (okhttp3.mockwebserver.MockWebServer)4 Retrofit (retrofit2.Retrofit)4 HashSet (java.util.HashSet)3 ResourceHandler (org.hisp.dhis.android.core.resource.ResourceHandler)3 ContentValues (android.content.ContentValues)2 D2 (org.hisp.dhis.android.core.D2)1 GenericCallData (org.hisp.dhis.android.core.common.GenericCallData)1 ObjectStyle (org.hisp.dhis.android.core.common.ObjectStyle)1 ObjectStyleModel (org.hisp.dhis.android.core.common.ObjectStyleModel)1 ValueTypeRendering (org.hisp.dhis.android.core.common.ValueTypeRendering)1 AssetsFileReader (org.hisp.dhis.android.core.data.file.AssetsFileReader)1 Dhis2MockServer (org.hisp.dhis.android.core.data.server.Dhis2MockServer)1 RelationshipTypeStore (org.hisp.dhis.android.core.relationship.RelationshipTypeStore)1 RelationshipTypeStoreImpl (org.hisp.dhis.android.core.relationship.RelationshipTypeStoreImpl)1