use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.
the class ProgramStageInstanceBasicCheckTest method failOnProgramStageInstanceAndInvalidImportOption.
@Test
void failOnProgramStageInstanceAndInvalidImportOption() {
Map<String, ProgramStageInstance> programStageInstanceMap = new HashMap<>();
ProgramStageInstance psi = new ProgramStageInstance();
programStageInstanceMap.put(event.getEvent(), psi);
ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
importOptions.setImportStrategy(ImportStrategy.CREATE);
when(workContext.getImportOptions()).thenReturn(importOptions);
when(workContext.getProgramStageInstanceMap()).thenReturn(programStageInstanceMap);
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Event ID " + event.getEvent() + " was already used and/or deleted. This event can not be modified.");
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.
the class GmlImportServiceTest method setUpTest.
@Override
public void setUpTest() throws IOException {
inputStream = new ClassPathResource("gml/testGmlPayload.gml").getInputStream();
/*
* Create orgunits present in testGmlPayload.gml and set ID properties.
* Name - FeatureType - ID property Bo - Poly - Name Bonthe - Multi -
* Code Ole Johan Dahls Hus - Point - Uid Blindern - Point (pos) - Name
* Forskningsparken - Poly (list) - Name
*
* Note: some of these are included to cover different coordinate
* element schemes such as <posList>, <coordinates> and <pos>.
*/
userService = _userService;
boOrgUnit = createOrganisationUnit('A');
boOrgUnit.setName("Bo");
organisationUnitService.addOrganisationUnit(boOrgUnit);
bontheOrgUnit = createOrganisationUnit('B');
// Match on Code, therefore wrong
bontheOrgUnit.setName("AA Bonthe");
// name
bontheOrgUnit.setCode("CODE_BONTHE");
organisationUnitService.addOrganisationUnit(bontheOrgUnit);
ojdOrgUnit = createOrganisationUnit('C');
ojdOrgUnit.setUid("ImspTQPwCqd");
// Match on UID,
ojdOrgUnit.setName("AA Ole Johan Dahls Hus");
// therefore wrong name
organisationUnitService.addOrganisationUnit(ojdOrgUnit);
bliOrgUnit = createOrganisationUnit('D');
bliOrgUnit.setName("Blindern");
organisationUnitService.addOrganisationUnit(bliOrgUnit);
forskOrgUnit = createOrganisationUnit('E');
forskOrgUnit.setName("Forskningsparken");
organisationUnitService.addOrganisationUnit(forskOrgUnit);
user = createAndInjectAdminUser();
id = new JobConfiguration("gmlImportTest", JobType.METADATA_IMPORT, user.getUid(), true);
importOptions = new ImportOptions().setImportStrategy(ImportStrategy.UPDATE);
importOptions.setDryRun(false);
importOptions.setPreheatCache(true);
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.
the class GmlImportServiceTest method testImportGml.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testImportGml() {
MetadataImportParams importParams = new MetadataImportParams();
importParams.setId(id);
importParams.setUser(user);
gmlImportService.importGml(inputStream, importParams);
assertNotNull(boOrgUnit.getGeometry());
assertNotNull(bontheOrgUnit.getGeometry());
assertNotNull(ojdOrgUnit.getGeometry());
assertNotNull(bliOrgUnit.getGeometry());
assertNotNull(forskOrgUnit.getGeometry());
// Check if data is correct
assertEquals(1, getCoordinates(boOrgUnit).size());
assertEquals(18, getCoordinates(bontheOrgUnit).size());
assertEquals(1, getCoordinates(ojdOrgUnit).size());
assertEquals(1, getCoordinates(bliOrgUnit).size());
assertEquals(1, getCoordinates(forskOrgUnit).size());
assertEquals(76, getCoordinates(boOrgUnit).get(0).getNumberOfCoordinates());
assertEquals(189, getCoordinates(bontheOrgUnit).get(1).getNumberOfCoordinates());
assertEquals(1, getCoordinates(ojdOrgUnit).get(0).getNumberOfCoordinates());
assertEquals(1, getCoordinates(bliOrgUnit).get(0).getNumberOfCoordinates());
assertEquals(76, getCoordinates(forskOrgUnit).get(0).getNumberOfCoordinates());
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldDownloadMetadataVersion.
@Test
void testShouldDownloadMetadataVersion() {
when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(downloadUrl);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(new AvailabilityStatus(true, "test_message", null));
when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
mocked.when(() -> HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(dhisHttpResponse);
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
String actualVersionSnapShot = target.downloadMetadataVersionSnapshot(metadataVersion);
assertEquals(response, actualVersionSnapShot);
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.ID in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldReturnEmptyMetadataDifference.
@Test
void testShouldReturnEmptyMetadataDifference() {
when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
String url = "http://localhost:9080/api/metadata/version/history?baseline=testVersion";
when(metadataSystemSettingService.getMetaDataDifferenceURL("testVersion")).thenReturn(url);
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.BAD_REQUEST.value());
try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
mocked.when(() -> HttpUtils.httpGET(baselineUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
assertThrows(MetadataVersionServiceException.class, () -> target.getMetaDataDifference(metadataVersion), "Client Error. Http call failed with status code: 400 Caused by: " + dhisHttpResponse.getResponse());
}
}
Aggregations