Search in sources :

Example 1 with ResourcesFileReader

use of org.hisp.dhis.android.core.data.file.ResourcesFileReader in project dhis2-android-sdk by dhis2.

the class MetadataCallShould method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    errorResponse = Response.error(HttpsURLConnection.HTTP_CLIENT_TIMEOUT, ResponseBody.create(MediaType.parse("application/json"), "{}"));
    when(systemInfoService.getSystemInfo(any(Fields.class))).thenReturn(systemInfoCall);
    when(userService.getUser(any(Fields.class))).thenReturn(userCall);
    when(programService.getProgramsForAccess(any(Fields.class), any(Filter.class), anyBoolean())).thenReturn(programWithAccessCall);
    when(programService.getPrograms(any(Fields.class), any(Filter.class), any(Filter.class), anyBoolean())).thenReturn(programCall);
    when(trackedEntityService.trackedEntities(any(Fields.class), any(Filter.class), any(Filter.class), anyBoolean())).thenReturn(trackedEntityCall);
    when(optionSetService.optionSets(anyBoolean(), any(Fields.class), any(Filter.class))).thenReturn(optionSetCall);
    List<UserRole> userRoles = new ArrayList<>();
    userRoles.add(userRole);
    when(systemInfo.serverDate()).thenReturn(serverDateTime);
    when(userCredentials.userRoles()).thenReturn(userRoles);
    when(organisationUnit.uid()).thenReturn("unit");
    when(organisationUnit.path()).thenReturn("path/to/org/unit");
    when(user.userCredentials()).thenReturn(userCredentials);
    when(user.organisationUnits()).thenReturn(Collections.singletonList(organisationUnit));
    when(organisationUnitPayload.items()).thenReturn(Collections.singletonList(organisationUnit));
    when(dataAccess.read()).thenReturn(true);
    when(access.data()).thenReturn(dataAccess);
    when(programWithAccess.access()).thenReturn(access);
    when(program.trackedEntity()).thenReturn(trackedEntity);
    when(program.access()).thenReturn(access);
    when(program.programStages()).thenReturn(Collections.singletonList(programStageWithUid));
    when(programStageWithUid.uid()).thenReturn("program_stage_uid");
    when(programWithAccessPayload.items()).thenReturn(Collections.singletonList(programWithAccess));
    when(programPayload.items()).thenReturn(Collections.singletonList(program));
    when(trackedEntityPayload.items()).thenReturn(Collections.singletonList(trackedEntity));
    when(trackedEntity.uid()).thenReturn("test_tracked_entity_uid");
    when(optionSetPayload.items()).thenReturn(Collections.singletonList(optionSet));
    when(dataElementPayload.items()).thenReturn(Collections.singletonList(dataElement));
    when(resourceStore.getLastUpdated(any(ResourceModel.Type.class))).thenReturn("2017-01-01");
    when(dataSetParentCallFactory.create(any(User.class), any(GenericCallData.class), any(List.class))).thenReturn(dataSetParentCall);
    when(organisationUnitCallFactory.create(any(GenericCallData.class), any(User.class), anySetOf(String.class))).thenReturn(organisationUnitEndpointCall);
    Response<Payload<DataElement>> dataSetParentCallResponse = Response.success(dataElementPayload);
    when(dataSetParentCall.call()).thenReturn(dataSetParentCallResponse);
    when(programStageCallFactory.create(any(GenericCallData.class), any(Set.class))).thenReturn(programStageEndpointCall);
    programStageResponse = Response.success(programStagePayload);
    when(programStageEndpointCall.call()).thenReturn(programStageResponse);
    dhis2MockServer = new Dhis2MockServer(new ResourcesFileReader());
    Retrofit retrofit = new Retrofit.Builder().baseUrl(dhis2MockServer.getBaseEndpoint()).addConverterFactory(JacksonConverterFactory.create(new ObjectMapper())).addConverterFactory(FilterConverterFactory.create()).addConverterFactory(FieldsConverterFactory.create()).build();
    CategoryService categoryService = retrofit.create(CategoryService.class);
    CategoryComboService comboService = retrofit.create(CategoryComboService.class);
    dhis2MockServer.enqueueMockResponse("categories.json");
    dhis2MockServer.enqueueMockResponse("category_combos.json");
    metadataCall = new MetadataCall(databaseAdapter, systemInfoService, userService, programService, trackedEntityService, optionSetService, systemInfoStore, resourceStore, userStore, userCredentialsStore, userRoleStore, programStore, trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, relationshipStore, trackedEntityStore, categoryQuery, categoryService, categoryHandler, CategoryComboQuery.defaultQuery(), comboService, mockCategoryComboHandler, optionSetHandler, organisationUnitCallFactory, dataSetParentCallFactory, styleHandler, renderTypeHandler, programStageCallFactory, retrofit);
    when(databaseAdapter.beginNewTransaction()).thenReturn(transaction);
    when(systemInfoCall.execute()).thenReturn(Response.success(systemInfo));
    when(userCall.execute()).thenReturn(Response.success(user));
    when(programCall.execute()).thenReturn(Response.success(programPayload));
    when(programWithAccessCall.execute()).thenReturn(Response.success(programWithAccessPayload));
    when(trackedEntityCall.execute()).thenReturn(Response.success(trackedEntityPayload));
    when(optionSetCall.execute()).thenReturn(Response.success(optionSetPayload));
    when(organisationUnitEndpointCall.call()).thenReturn(Response.success(organisationUnitPayload));
}
Also used : Dhis2MockServer(org.hisp.dhis.android.core.data.server.Dhis2MockServer) User(org.hisp.dhis.android.core.user.User) OptionSet(org.hisp.dhis.android.core.option.OptionSet) Set(java.util.Set) ArrayList(java.util.ArrayList) CategoryComboService(org.hisp.dhis.android.core.category.CategoryComboService) Retrofit(retrofit2.Retrofit) MediaType(okhttp3.MediaType) Fields(org.hisp.dhis.android.core.data.api.Fields) MetadataCall(org.hisp.dhis.android.core.calls.MetadataCall) Filter(org.hisp.dhis.android.core.data.api.Filter) UserRole(org.hisp.dhis.android.core.user.UserRole) ResourcesFileReader(org.hisp.dhis.android.core.data.file.ResourcesFileReader) List(java.util.List) ArrayList(java.util.ArrayList) CategoryService(org.hisp.dhis.android.core.category.CategoryService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 2 with ResourcesFileReader

use of org.hisp.dhis.android.core.data.file.ResourcesFileReader in project dhis2-android-sdk by dhis2.

the class EventEndPointCallShould method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws IOException {
    dhis2MockServer = new Dhis2MockServer(new ResourcesFileReader());
    retrofit = new Retrofit.Builder().baseUrl(dhis2MockServer.getBaseEndpoint()).addConverterFactory(JacksonConverterFactory.create(new ObjectMapper())).addConverterFactory(FilterConverterFactory.create()).addConverterFactory(FieldsConverterFactory.create()).build();
    MockitoAnnotations.initMocks(this);
}
Also used : Dhis2MockServer(org.hisp.dhis.android.core.data.server.Dhis2MockServer) ResourcesFileReader(org.hisp.dhis.android.core.data.file.ResourcesFileReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with ResourcesFileReader

use of org.hisp.dhis.android.core.data.file.ResourcesFileReader in project dhis2-android-sdk by dhis2.

the class TrackedEntityInstanceEndPointCallShould method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws IOException {
    dhis2MockServer = new Dhis2MockServer(new ResourcesFileReader());
    retrofit = new Retrofit.Builder().baseUrl(dhis2MockServer.getBaseEndpoint()).addConverterFactory(JacksonConverterFactory.create(new ObjectMapper())).addConverterFactory(FilterConverterFactory.create()).addConverterFactory(FieldsConverterFactory.create()).build();
    MockitoAnnotations.initMocks(this);
}
Also used : Dhis2MockServer(org.hisp.dhis.android.core.data.server.Dhis2MockServer) ResourcesFileReader(org.hisp.dhis.android.core.data.file.ResourcesFileReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ResourcesFileReader (org.hisp.dhis.android.core.data.file.ResourcesFileReader)3 Dhis2MockServer (org.hisp.dhis.android.core.data.server.Dhis2MockServer)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 MediaType (okhttp3.MediaType)1 MetadataCall (org.hisp.dhis.android.core.calls.MetadataCall)1 CategoryComboService (org.hisp.dhis.android.core.category.CategoryComboService)1 CategoryService (org.hisp.dhis.android.core.category.CategoryService)1 Fields (org.hisp.dhis.android.core.data.api.Fields)1 Filter (org.hisp.dhis.android.core.data.api.Filter)1 OptionSet (org.hisp.dhis.android.core.option.OptionSet)1 User (org.hisp.dhis.android.core.user.User)1 UserRole (org.hisp.dhis.android.core.user.UserRole)1 Retrofit (retrofit2.Retrofit)1