Search in sources :

Example 36 with ObjectBundleParams

use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams 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 37 with ObjectBundleParams

use of org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams 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)

Example 38 with ObjectBundleParams

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

the class ObjectBundleServiceUserTest method testCreateUsersWithInvalidPasswords.

@Test
public void testCreateUsersWithInvalidPasswords() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/users_passwords.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsByCode(User.class, ErrorCode.E4005).size());
}
Also used : 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

ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 List (java.util.List)36 DhisSpringTest (org.hisp.dhis.DhisSpringTest)36 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)36 Test (org.junit.Test)36 ClassPathResource (org.springframework.core.io.ClassPathResource)36 DataElement (org.hisp.dhis.dataelement.DataElement)20 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)14 User (org.hisp.dhis.user.User)14 DataSet (org.hisp.dhis.dataset.DataSet)11 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 ObjectReport (org.hisp.dhis.feedback.ObjectReport)6 Section (org.hisp.dhis.dataset.Section)4 ValidationRule (org.hisp.dhis.validation.ValidationRule)4 Program (org.hisp.dhis.program.Program)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)3 Chart (org.hisp.dhis.chart.Chart)2 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)2 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)2