public void testIdentityManagement() { /* foreach */ foreach (PibDataFixture2 fixture in pibImpls) { PibImpl pib = fixture.pib; // No default identity is set. This should throw an Error. try { pib.getDefaultIdentity(); Assert.Fail("Did not throw the expected exception"); } catch (Pib.Error ex) { } catch (Exception ex_0) { Assert.Fail("Did not throw the expected exception"); } // Check for id1, which should not exist. Assert.AssertEquals(false, pib.hasIdentity(fixture.id1)); // Add id1, which should be the default. pib.addIdentity(fixture.id1); Assert.AssertEquals(true, pib.hasIdentity(fixture.id1)); try { pib.getDefaultIdentity(); } catch (Exception ex_1) { Assert.Fail("Unexpected exception: " + ex_1.Message); } Assert.AssertEquals(fixture.id1, pib.getDefaultIdentity()); // Add id2, which should not be the default. pib.addIdentity(fixture.id2); Assert.AssertEquals(true, pib.hasIdentity(fixture.id2)); Assert.AssertEquals(fixture.id1, pib.getDefaultIdentity()); // Explicitly set id2 as the default. pib.setDefaultIdentity(fixture.id2); Assert.AssertEquals(fixture.id2, pib.getDefaultIdentity()); // Remove id2. The PIB should not have a default identity. pib.removeIdentity(fixture.id2); Assert.AssertEquals(false, pib.hasIdentity(fixture.id2)); try { pib.getDefaultIdentity(); Assert.Fail("Did not throw the expected exception"); } catch (Pib.Error ex_2) { } catch (Exception ex_3) { Assert.Fail("Did not throw the expected exception"); } // Set id2 as the default. This should add id2 again. pib.setDefaultIdentity(fixture.id2); Assert.AssertEquals(fixture.id2, pib.getDefaultIdentity()); // Get all the identities, which should have id1 and id2. HashedSet <Name> idNames = pib.getIdentities(); Assert.AssertEquals(2, idNames.Count); Assert.AssertTrue(ILOG.J2CsMapping.Collections.Collections.Contains(fixture.id1, idNames)); Assert.AssertTrue(ILOG.J2CsMapping.Collections.Collections.Contains(fixture.id2, idNames)); } }
public void testClearIdentities() { /* foreach */ foreach (PibDataFixture2 fixture in pibImpls) { PibImpl pib = fixture.pib; pib.setTpmLocator("tpmLocator"); // Add id, key, and cert. pib.addCertificate(fixture.id1Key1Cert1); Assert.AssertTrue(pib.hasIdentity(fixture.id1)); Assert.AssertTrue(pib.hasKey(fixture.id1Key1Name)); Assert.AssertTrue(pib.hasCertificate(fixture.id1Key1Cert1.getName())); // Clear identities. pib.clearIdentities(); Assert.AssertEquals(0, pib.getIdentities().Count); Assert.AssertEquals(0, pib.getKeysOfIdentity(fixture.id1).Count); Assert.AssertEquals(0, pib.getCertificatesOfKey(fixture.id1Key1Name).Count); Assert.AssertEquals("tpmLocator", pib.getTpmLocator()); } }