Search in sources :

Example 1 with CategoryService

use of org.hisp.dhis.android.core.category.CategoryService 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 CategoryService

use of org.hisp.dhis.android.core.category.CategoryService in project dhis2-android-sdk by dhis2.

the class CategoryCallFactory method create.

@NonNull
public static CategoryEndpointCall create(Retrofit retrofit, DatabaseAdapter databaseAdapter) {
    CategoryService categoryService = retrofit.create(CategoryService.class);
    ResponseValidator<Category> categoryResponseValidator = new ResponseValidator<>();
    CategoryHandler categoryHandler = HandlerFactory.createCategoryHandler(databaseAdapter);
    ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter);
    CategoryQuery categoryQuery = CategoryQuery.defaultQuery();
    CategoryEndpointCall categoryEndpointCall = new CategoryEndpointCall(categoryQuery, categoryService, categoryResponseValidator, categoryHandler, resourceHandler, databaseAdapter, new Date());
    return categoryEndpointCall;
}
Also used : Category(org.hisp.dhis.android.core.category.Category) ResponseValidator(org.hisp.dhis.android.core.category.ResponseValidator) CategoryQuery(org.hisp.dhis.android.core.category.CategoryQuery) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) CategoryService(org.hisp.dhis.android.core.category.CategoryService) CategoryEndpointCall(org.hisp.dhis.android.core.category.CategoryEndpointCall) CategoryHandler(org.hisp.dhis.android.core.category.CategoryHandler) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

Aggregations

CategoryService (org.hisp.dhis.android.core.category.CategoryService)2 NonNull (android.support.annotation.NonNull)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Set (java.util.Set)1 MediaType (okhttp3.MediaType)1 MetadataCall (org.hisp.dhis.android.core.calls.MetadataCall)1 Category (org.hisp.dhis.android.core.category.Category)1 CategoryComboService (org.hisp.dhis.android.core.category.CategoryComboService)1 CategoryEndpointCall (org.hisp.dhis.android.core.category.CategoryEndpointCall)1 CategoryHandler (org.hisp.dhis.android.core.category.CategoryHandler)1 CategoryQuery (org.hisp.dhis.android.core.category.CategoryQuery)1 ResponseValidator (org.hisp.dhis.android.core.category.ResponseValidator)1 Fields (org.hisp.dhis.android.core.data.api.Fields)1 Filter (org.hisp.dhis.android.core.data.api.Filter)1 ResourcesFileReader (org.hisp.dhis.android.core.data.file.ResourcesFileReader)1 Dhis2MockServer (org.hisp.dhis.android.core.data.server.Dhis2MockServer)1 OptionSet (org.hisp.dhis.android.core.option.OptionSet)1