use of org.hisp.dhis.android.core.calls.MetadataCall 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));
}
Aggregations