Search in sources :

Example 6 with HFCAAffiliation

use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testDeleteAffiliationNoForce.

// Tests deleting an affiliation that doesn't require force option
@Test
public void testDeleteAffiliationNoForce() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAAffiliation aff = client.newHFCAAffiliation("org6");
    aff.create(admin);
    HFCAAffiliationResp resp = aff.delete(admin);
    assertEquals("Incorrect status code", new Integer(200), new Integer(resp.getStatusCode()));
    assertEquals("Failed to delete affiliation", "org6", aff.getName());
}
Also used : HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) Test(org.junit.Test)

Example 7 with HFCAAffiliation

use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testUpdateAffiliationNoForce.

// Tests updating an affiliation that doesn't require force option
@Test
public void testUpdateAffiliationNoForce() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAAffiliation aff = client.newHFCAAffiliation("org_5");
    aff.create(admin);
    aff.setUpdateName("org_6");
    HFCAAffiliationResp resp = aff.update(admin);
    assertEquals("Incorrect status code", new Integer(200), new Integer(resp.getStatusCode()));
    assertEquals("Failed to delete affiliation", "org_6", aff.getName());
}
Also used : HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) Test(org.junit.Test)

Example 8 with HFCAAffiliation

use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testGetAllAffiliation.

// Tests getting all affiliation
@Test
public void testGetAllAffiliation() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAAffiliation resp = client.getHFCAAffiliations(admin);
    ArrayList<String> expectedFirstLevelAffiliations = new ArrayList<String>(Arrays.asList("org2", "org1"));
    int found = 0;
    for (HFCAAffiliation aff : resp.getChildren()) {
        for (Iterator<String> iter = expectedFirstLevelAffiliations.iterator(); iter.hasNext(); ) {
            String element = iter.next();
            if (aff.getName().equals(element)) {
                iter.remove();
            }
        }
    }
    if (!expectedFirstLevelAffiliations.isEmpty()) {
        fail("Failed to get the correct of affiliations, affiliations not returned: %s" + expectedFirstLevelAffiliations.toString());
    }
    ArrayList<String> expectedSecondLevelAffiliations = new ArrayList<String>(Arrays.asList("org2.department1", "org1.department1", "org1.department2"));
    for (HFCAAffiliation aff : resp.getChildren()) {
        for (HFCAAffiliation aff2 : aff.getChildren()) {
            expectedSecondLevelAffiliations.removeIf(element -> aff2.getName().equals(element));
        }
    }
    if (!expectedSecondLevelAffiliations.isEmpty()) {
        fail("Failed to get the correct child affiliations, affiliations not returned: %s" + expectedSecondLevelAffiliations.toString());
    }
}
Also used : ArrayList(java.util.ArrayList) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) Test(org.junit.Test)

Example 9 with HFCAAffiliation

use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testUpdateAffiliation.

// Tests updating an affiliation
@Test
public void testUpdateAffiliation() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAAffiliation aff = client.newHFCAAffiliation("org4");
    aff.create(admin);
    HFCAIdentity ident = client.newHFCAIdentity("testuser_org4");
    ident.setAffiliation(aff.getName());
    ident.create(admin);
    HFCAAffiliation aff2 = client.newHFCAAffiliation("org4.dept1");
    aff2.create(admin);
    HFCAIdentity ident2 = client.newHFCAIdentity("testuser_org4.dept1");
    ident2.setAffiliation("org4.dept1");
    ident2.create(admin);
    HFCAAffiliation aff3 = client.newHFCAAffiliation("org4.dept1.team1");
    aff3.create(admin);
    HFCAIdentity ident3 = client.newHFCAIdentity("testuser_org4.dept1.team1");
    ident3.setAffiliation("org4.dept1.team1");
    ident3.create(admin);
    aff.setUpdateName("org5");
    // Set force option to true, since their identities associated with affiliations
    // that are getting updated
    HFCAAffiliationResp resp = aff.update(admin, true);
    int found = 0;
    int idCount = 0;
    // Should contain the affiliations affected by the update request
    HFCAAffiliation child = aff.getChild("dept1");
    assertNotNull(child);
    assertEquals("Failed to get correct child affiliation", "org5.dept1", child.getName());
    for (HFCAIdentity id : child.getIdentities()) {
        if (id.getEnrollmentId().equals("testuser_org4.dept1")) {
            idCount++;
        }
    }
    HFCAAffiliation child2 = child.getChild("team1");
    assertNotNull(child2);
    assertEquals("Failed to get correct child affiliation", "org5.dept1.team1", child2.getName());
    for (HFCAIdentity id : child2.getIdentities()) {
        if (id.getEnrollmentId().equals("testuser_org4.dept1.team1")) {
            idCount++;
        }
    }
    for (HFCAIdentity id : aff.getIdentities()) {
        if (id.getEnrollmentId().equals("testuser_org4")) {
            idCount++;
        }
    }
    if (idCount != 3) {
        fail("Incorrect number of ids returned");
    }
    assertEquals("Incorrect response for id", "org5", aff.getName());
    assertEquals("Incorrect status code", new Integer(200), new Integer(resp.getStatusCode()));
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) Test(org.junit.Test)

Example 10 with HFCAAffiliation

use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testDeleteAffiliation.

// Tests deleting an affiliation
@Test
public void testDeleteAffiliation() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    thrown.expectMessage("Affiliation has been deleted");
    HFCAAffiliation aff = client.newHFCAAffiliation("org6");
    aff.create(admin);
    HFCAIdentity ident = client.newHFCAIdentity("testuser_org6");
    ident.setAffiliation("org6");
    ident.create(admin);
    HFCAAffiliation aff2 = client.newHFCAAffiliation("org6.dept1");
    aff2.create(admin);
    HFCAIdentity ident2 = client.newHFCAIdentity("testuser_org6.dept1");
    ident2.setAffiliation("org6.dept1");
    ident2.create(admin);
    HFCAAffiliationResp resp = aff.delete(admin, true);
    int idCount = 0;
    boolean found = false;
    for (HFCAAffiliation childAff : resp.getChildren()) {
        if (childAff.getName().equals("org6.dept1")) {
            found = true;
        }
        for (HFCAIdentity id : childAff.getIdentities()) {
            if (id.getEnrollmentId().equals("testuser_org6.dept1")) {
                idCount++;
            }
        }
    }
    for (HFCAIdentity id : resp.getIdentities()) {
        if (id.getEnrollmentId().equals("testuser_org6")) {
            idCount++;
        }
    }
    if (!found) {
        fail("Incorrect response received");
    }
    if (idCount != 2) {
        fail("Incorrect number of ids returned");
    }
    assertEquals("Incorrect status code", new Integer(200), new Integer(resp.getStatusCode()));
    assertEquals("Failed to delete affiliation", "org6", aff.getName());
    aff.delete(admin);
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) Test(org.junit.Test)

Aggregations

HFCAAffiliation (org.hyperledger.fabric_ca.sdk.HFCAAffiliation)10 Test (org.junit.Test)10 HFCAAffiliationResp (org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp)8 HFCAIdentity (org.hyperledger.fabric_ca.sdk.HFCAIdentity)4 ArrayList (java.util.ArrayList)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 SampleUser (org.hyperledger.fabric.sdkintegration.SampleUser)1 HFCAClient (org.hyperledger.fabric_ca.sdk.HFCAClient)1 MockHFCAClient (org.hyperledger.fabric_ca.sdk.MockHFCAClient)1