Search in sources :

Example 16 with PartialImportResults

use of org.keycloak.partialimport.PartialImportResults in project keycloak by keycloak.

the class PartialImportTest method testAddUsersWithDuplicateEmailsAllowed.

@Test
public void testAddUsersWithDuplicateEmailsAllowed() {
    RealmRepresentation realmRep = testRealmResource().toRepresentation();
    realmRep.setDuplicateEmailsAllowed(true);
    testRealmResource().update(realmRep);
    assertAdminEvents.clear();
    setFail();
    addUsers();
    doImport();
    UserRepresentation user = createUserRepresentation(USER_PREFIX + 999, USER_PREFIX + 1 + "@foo.com", "foo", "bar", true);
    piRep.setUsers(Arrays.asList(user));
    PartialImportResults results = doImport();
    assertEquals(1, results.getAdded());
}
Also used : PartialImportResults(org.keycloak.partialimport.PartialImportResults) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 17 with PartialImportResults

use of org.keycloak.partialimport.PartialImportResults in project keycloak by keycloak.

the class PartialImportTest method testOverwrite.

private void testOverwrite() {
    setOverwrite();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES, results.getAdded());
    results = doImport();
    assertEquals(NUM_ENTITIES, results.getOverwritten());
}
Also used : PartialImportResults(org.keycloak.partialimport.PartialImportResults)

Example 18 with PartialImportResults

use of org.keycloak.partialimport.PartialImportResults in project keycloak by keycloak.

the class PartialImportTest method testAddUsersWithTermsAndConditions.

@Test
public void testAddUsersWithTermsAndConditions() {
    assertAdminEvents.clear();
    setFail();
    addUsersWithTermsAndConditions();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES, results.getAdded());
    // Need to do this way as admin events from partial import are unsorted
    Set<String> userIds = new HashSet<>();
    for (int i = 0; i < NUM_ENTITIES; i++) {
        AdminEventRepresentation adminEvent = assertAdminEvents.poll();
        Assert.assertEquals(realmId, adminEvent.getRealmId());
        Assert.assertEquals(OperationType.CREATE.name(), adminEvent.getOperationType());
        Assert.assertTrue(adminEvent.getResourcePath().startsWith("users/"));
        String userId = adminEvent.getResourcePath().substring(6);
        userIds.add(userId);
    }
    assertAdminEvents.assertEmpty();
    for (PartialImportResult result : results.getResults()) {
        String id = result.getId();
        UserResource userRsc = testRealmResource().users().get(id);
        UserRepresentation user = userRsc.toRepresentation();
        assertTrue(user.getUsername().startsWith(USER_PREFIX));
        Assert.assertTrue(userIds.contains(id));
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) PartialImportResults(org.keycloak.partialimport.PartialImportResults) UserResource(org.keycloak.admin.client.resource.UserResource) HashSet(java.util.HashSet) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 19 with PartialImportResults

use of org.keycloak.partialimport.PartialImportResults in project keycloak by keycloak.

the class PartialImportTest method testAddUsers.

@Test
public void testAddUsers() {
    assertAdminEvents.clear();
    setFail();
    addUsers();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES, results.getAdded());
    // Need to do this way as admin events from partial import are unsorted
    Set<String> userIds = new HashSet<>();
    for (int i = 0; i < NUM_ENTITIES; i++) {
        AdminEventRepresentation adminEvent = assertAdminEvents.poll();
        Assert.assertEquals(realmId, adminEvent.getRealmId());
        Assert.assertEquals(OperationType.CREATE.name(), adminEvent.getOperationType());
        Assert.assertTrue(adminEvent.getResourcePath().startsWith("users/"));
        String userId = adminEvent.getResourcePath().substring(6);
        userIds.add(userId);
    }
    assertAdminEvents.assertEmpty();
    for (PartialImportResult result : results.getResults()) {
        String id = result.getId();
        UserResource userRsc = testRealmResource().users().get(id);
        UserRepresentation user = userRsc.toRepresentation();
        Assert.assertThat(user.getUsername(), startsWith(USER_PREFIX));
        Assert.assertThat(userIds, hasItem(id));
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) PartialImportResults(org.keycloak.partialimport.PartialImportResults) UserResource(org.keycloak.admin.client.resource.UserResource) HashSet(java.util.HashSet) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 20 with PartialImportResults

use of org.keycloak.partialimport.PartialImportResults in project keycloak by keycloak.

the class PartialImportTest method testAddClients.

@Test
public void testAddClients() throws IOException {
    setFail();
    addClients(false);
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES, results.getAdded());
    for (PartialImportResult result : results.getResults()) {
        String id = result.getId();
        ClientResource clientRsc = testRealmResource().clients().get(id);
        ClientRepresentation client = clientRsc.toRepresentation();
        assertTrue(client.getName().startsWith(CLIENT_PREFIX));
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) PartialImportResults(org.keycloak.partialimport.PartialImportResults) ClientResource(org.keycloak.admin.client.resource.ClientResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Aggregations

PartialImportResults (org.keycloak.partialimport.PartialImportResults)21 Test (org.junit.Test)17 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)17 PartialImportResult (org.keycloak.partialimport.PartialImportResult)6 EnableFeature (org.keycloak.testsuite.arquillian.annotation.EnableFeature)6 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)4 UserResource (org.keycloak.admin.client.resource.UserResource)3 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)3 HashSet (java.util.HashSet)2 ClientResource (org.keycloak.admin.client.resource.ClientResource)2 AdminEventRepresentation (org.keycloak.representations.idm.AdminEventRepresentation)2 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)2 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)1 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)1 RoleResource (org.keycloak.admin.client.resource.RoleResource)1 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)1 PartialImportRepresentation (org.keycloak.representations.idm.PartialImportRepresentation)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 ResourceServerRepresentation (org.keycloak.representations.idm.authorization.ResourceServerRepresentation)1