Search in sources :

Example 61 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldNotDownloadMetadataVersion.

@Test
public void testShouldNotDownloadMetadataVersion() throws Exception {
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
    String url = "http://localhost:9080/api/metadata/version/testVersion/data.gz";
    when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(url);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    PowerMockito.when(HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(null);
    String actualMetadataVersionSnapshot = metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion);
    assertEquals(null, actualMetadataVersionSnapshot);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 62 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenServerNotAvailable.

@Test
public void testShouldThrowExceptionWhenServerNotAvailable() throws Exception {
    String url = "http://localhost:9080/api/metadata/version?versionName=Version_Name";
    when(metadataSystemSettingService.getVersionDetailsUrl("testversion")).thenReturn(url);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(false, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    expectedException.expect(RemoteServerUnavailableException.class);
    expectedException.expectMessage("test_message");
    metadataVersionDelegate.getRemoteMetadataVersion("testVersion");
}
Also used : AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 63 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldDownloadMetadataVersion.

@Test
public void testShouldDownloadMetadataVersion() throws Exception {
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
    String url = "http://localhost:9080/api/metadata/version/testVersion/data.gz";
    String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(url);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    PowerMockito.when(HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(dhisHttpResponse);
    String actualVersionSnapShot = metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion);
    assertEquals(response, actualVersionSnapShot);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 64 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class ObjectBundleServiceUserTest method testUpdateUsers.

@Test
public void testUpdateUsers() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsByCode(UserAuthorityGroup.class, ErrorCode.E5003).size());
    objectBundleService.commit(bundle);
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users_update.json").getInputStream(), RenderFormat.JSON);
    params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    bundle = objectBundleService.create(params);
    validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsByCode(UserAuthorityGroup.class, ErrorCode.E5001).size());
    objectBundleService.commit(bundle);
    List<User> users = manager.getAll(User.class);
    assertEquals(4, users.size());
    User userA = manager.get(User.class, "sPWjoHSY03y");
    User userB = manager.get(User.class, "MwhEJUnTHkn");
    assertNotNull(userA);
    assertNotNull(userB);
    assertNotNull(userA.getUserCredentials().getUserInfo());
    assertNotNull(userB.getUserCredentials().getUserInfo());
    assertNotNull(userA.getUserCredentials().getUserInfo().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUserInfo().getUserCredentials());
    assertEquals("UserAA", userA.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertEquals("UserBB", userB.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertNotNull(userA.getUserCredentials().getUser());
    assertNotNull(userB.getUserCredentials().getUser());
    assertNotNull(userA.getUserCredentials().getUser().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUser().getUserCredentials());
    assertEquals("admin", userA.getUserCredentials().getUser().getUserCredentials().getUsername());
    assertEquals("admin", userB.getUserCredentials().getUser().getUserCredentials().getUsername());
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 65 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.

the class ObjectBundleServiceUserTest method testCreateUsers.

@Test
public void testCreateUsers() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsByCode(UserAuthorityGroup.class, ErrorCode.E5003).size());
    objectBundleService.commit(bundle);
    List<User> users = manager.getAll(User.class);
    assertEquals(4, users.size());
    User userA = manager.get(User.class, "sPWjoHSY03y");
    User userB = manager.get(User.class, "MwhEJUnTHkn");
    assertNotNull(userA);
    assertNotNull(userB);
    assertNotNull(userA.getUserCredentials().getUserInfo());
    assertNotNull(userB.getUserCredentials().getUserInfo());
    assertNotNull(userA.getUserCredentials().getUserInfo().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUserInfo().getUserCredentials());
    assertEquals("UserA", userA.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertEquals("UserB", userB.getUserCredentials().getUserInfo().getUserCredentials().getUsername());
    assertNotNull(userA.getUserCredentials().getUser());
    assertNotNull(userB.getUserCredentials().getUser());
    assertNotNull(userA.getUserCredentials().getUser().getUserCredentials());
    assertNotNull(userB.getUserCredentials().getUser().getUserCredentials());
    assertEquals("admin", userA.getUserCredentials().getUser().getUserCredentials().getUsername());
    assertEquals("admin", userB.getUserCredentials().getUser().getUserCredentials().getUsername());
    assertEquals(1, userA.getOrganisationUnits().size());
    assertEquals(1, userB.getOrganisationUnits().size());
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DhisSpringTest (org.hisp.dhis.DhisSpringTest)55 Test (org.junit.Test)55 List (java.util.List)46 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)46 ClassPathResource (org.springframework.core.io.ClassPathResource)42 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 DataElement (org.hisp.dhis.dataelement.DataElement)25 User (org.hisp.dhis.user.User)20 Metadata (com.google.android.exoplayer2.metadata.Metadata)19 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)19 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 DataSet (org.hisp.dhis.dataset.DataSet)15 ArrayList (java.util.ArrayList)14 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 IOException (java.io.IOException)10 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 IntegrationTest (org.hisp.dhis.IntegrationTest)9