use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testUpdateAffiliationInvalid.
// Trying to update affiliations with child affiliations and identities
// should fail if not using 'force' option.
@Test
public void testUpdateAffiliationInvalid() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
thrown.expectMessage("Need to use 'force' to remove identities and affiliation");
HFCAAffiliation aff = client.newHFCAAffiliation("org1.dept1");
aff.create(admin);
HFCAAffiliation aff2 = aff.createDecendent("team1");
aff2.create(admin);
HFCAIdentity ident = getIdentityReq("testorg1dept1", "client");
ident.setAffiliation(aff.getName());
ident.create(admin);
aff.setUpdateName("org1.dept2");
HFCAAffiliationResp resp = aff.update(admin);
assertEquals("Incorrect status code", new Integer(400), new Integer(resp.getStatusCode()));
}
use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testDeleteAffiliationNotAllowed.
// Tests deleting an affiliation on CA that does not allow affiliation removal
@Test
public void testDeleteAffiliationNotAllowed() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
thrown.expectMessage("Authorization failure");
HFCAClient client2 = HFCAClient.createNewInstance(testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCALocation(), testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCAProperties());
client2.setCryptoSuite(crypto);
// SampleUser can be any implementation that implements org.hyperledger.fabric.sdk.User Interface
SampleUser admin2 = sampleStore.getMember(TEST_ADMIN_NAME, "org2");
if (!admin2.isEnrolled()) {
// Preregistered admin only needs to be enrolled with Fabric CA.
admin2.setEnrollment(client2.enroll(admin2.getName(), TEST_ADMIN_PW));
}
HFCAAffiliation aff = client2.newHFCAAffiliation("org6");
HFCAAffiliationResp resp = aff.delete(admin2);
assertEquals("Incorrect status code", new Integer(400), new Integer(resp.getStatusCode()));
}
use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testCreateAffiliation.
// Tests adding an affiliation
@Test
public void testCreateAffiliation() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
HFCAAffiliation aff = client.newHFCAAffiliation("org3");
HFCAAffiliationResp resp = aff.create(admin);
assertEquals("Incorrect status code", new Integer(201), new Integer(resp.getStatusCode()));
assertEquals("Incorrect response for id", "org3", aff.getName());
Collection<HFCAAffiliation> children = aff.getChildren();
assertEquals("Should have no children", 0, children.size());
}
use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testGetAffiliation.
// Tests getting an affiliation
@Test
public void testGetAffiliation() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
HFCAAffiliation aff = client.newHFCAAffiliation("org2");
int resp = aff.read(admin);
assertEquals("Incorrect response for affiliation name", "org2", aff.getName());
assertEquals("Incorrect response for child affiliation name", "org2.department1", aff.getChild("department1").getName());
assertEquals("Incorrect status code", new Integer(200), new Integer(resp));
}
use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testForceDeleteAffiliationInvalid.
// Trying to delete affiliation with child affiliations and identities should result
// in an error without force option.
@Test
public void testForceDeleteAffiliationInvalid() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
thrown.expectMessage("Authorization failure");
HFCAAffiliation aff = client.newHFCAAffiliation("org1.dept3");
aff.create(admin);
HFCAAffiliation aff2 = client.newHFCAAffiliation("org1.dept3.team1");
aff2.create(admin);
HFCAIdentity ident = getIdentityReq("testorg1dept3", "client");
ident.setAffiliation("org1.dept3");
ident.create(admin);
HFCAAffiliationResp resp = aff.delete(admin);
assertEquals("Incorrect status code", new Integer(401), new Integer(resp.getStatusCode()));
}
Aggregations