use of org.hisp.dhis.android.core.data.server.Dhis2MockServer 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));
}
use of org.hisp.dhis.android.core.data.server.Dhis2MockServer 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);
}
use of org.hisp.dhis.android.core.data.server.Dhis2MockServer 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);
}
use of org.hisp.dhis.android.core.data.server.Dhis2MockServer in project dhis2-android-sdk by dhis2.
the class ProgramCallMockIntegrationShould method setUp.
@Override
@Before
public void setUp() throws IOException {
super.setUp();
dhis2MockServer = new Dhis2MockServer(new AssetsFileReader());
D2 d2 = D2Factory.create(dhis2MockServer.getBaseEndpoint(), databaseAdapter());
dhis2MockServer.enqueueMockResponse("programs_complete.json");
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(BaseIdentifiableObject.DATE_FORMAT.raw());
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
TrackedEntityAttributeStore trackedEntityAttributeStore = new TrackedEntityAttributeStoreImpl(databaseAdapter());
ProgramTrackedEntityAttributeStore programTrackedEntityAttributeStore = new ProgramTrackedEntityAttributeStoreImpl(databaseAdapter());
ProgramRuleVariableStore programRuleVariableStore = new ProgramRuleVariableStoreImpl(databaseAdapter());
ProgramIndicatorStore programIndicatorStore = new ProgramIndicatorStoreImpl(databaseAdapter());
ProgramStageSectionProgramIndicatorLinkStore programStageSectionProgramIndicatorLinkStore = new ProgramStageSectionProgramIndicatorLinkStoreImpl(databaseAdapter());
ProgramRuleActionStore programRuleActionStore = new ProgramRuleActionStoreImpl(databaseAdapter());
ProgramRuleStore programRuleStore = new ProgramRuleStoreImpl(databaseAdapter());
GenericHandler<ObjectStyle, ObjectStyleModel> styleHandler = ObjectStyleHandler.create(databaseAdapter());
DictionaryTableHandler<ValueTypeRendering> renderTypeHandler = ValueTypeRenderingHandler.create(databaseAdapter());
RelationshipTypeStore relationshipStore = new RelationshipTypeStoreImpl(databaseAdapter());
ProgramService programService = d2.retrofit().create(ProgramService.class);
ProgramStore programStore = new ProgramStoreImpl(databaseAdapter());
ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter());
Set<String> uids = new HashSet<>();
uids.add("uid1");
uids.add("uids2");
ContentValues categoryCombo = CreateCategoryComboUtils.create(1L, "nM3u9s5a52V");
database().insert(CategoryComboModel.TABLE, null, categoryCombo);
ContentValues categoryCombo2 = CreateCategoryComboUtils.create(2L, "x31y45jvIQL");
database().insert(CategoryComboModel.TABLE, null, categoryCombo2);
// inserting tracked entity
ContentValues trackedEntity = CreateTrackedEntityUtils.create(1L, "nEenWmSyUEp");
database().insert(TrackedEntityModel.TABLE, null, trackedEntity);
programCall = new ProgramCall(programService, databaseAdapter(), resourceStore, uids, programStore, new Date(), trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, relationshipStore, styleHandler, renderTypeHandler);
}
use of org.hisp.dhis.android.core.data.server.Dhis2MockServer in project dhis2-android-sdk by dhis2.
the class EventEndPointCallMockIntegrationShould method setUp.
@Override
@Before
public void setUp() throws IOException {
super.setUp();
dhis2MockServer = new Dhis2MockServer(new AssetsFileReader());
d2 = D2Factory.create(dhis2MockServer.getBaseEndpoint(), databaseAdapter());
}
Aggregations