use of org.apache.harmony.security.tests.support.SpiEngUtils in project robovm by robovm.
the class ExemptionMechanismTest method test_genExemptionBlob.
public void test_genExemptionBlob() throws InvalidKeyException, ExemptionMechanismException {
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
};
Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
try {
em.genExemptionBlob();
fail("IllegalStateException expected");
} catch (IllegalStateException e) {
//failed
}
em.init(key);
assertNotNull(em.genExemptionBlob());
em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
};
key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
em.init(key);
try {
em.genExemptionBlob();
fail("ExemptionMechanismException expected");
} catch (ExemptionMechanismException e) {
//failed
}
}
use of org.apache.harmony.security.tests.support.SpiEngUtils in project robovm by robovm.
the class ExemptionMechanismTest method testIsCryptoAllowed.
/**
* Test for <code>isCryptoAllowed(Key key)</code> method
*/
public void testIsCryptoAllowed() throws Exception {
//Regression for HARMONY-1029
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
};
Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
assertFalse(em.isCryptoAllowed(key));
em.init(key);
assertFalse(em.isCryptoAllowed(key));
em.genExemptionBlob();
assertTrue(em.isCryptoAllowed(key));
Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[] { 1 });
assertFalse(em.isCryptoAllowed(key1));
em.init(key1);
assertFalse(em.isCryptoAllowed(key));
}
use of org.apache.harmony.security.tests.support.SpiEngUtils in project robovm by robovm.
the class ExemptionMechanismTest method test_getInstanceLjava_lang_StringLjava_security_Provider.
public void test_getInstanceLjava_lang_StringLjava_security_Provider() throws Exception {
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
try {
ExemptionMechanism.getInstance((String) null, mProv);
fail("NullPointerException expected");
} catch (NullPointerException e) {
//expected
}
ExemptionMechanism em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
};
try {
em.getInstance("WrongAlgName", mProv);
fail("NoSuchAlgorithmException expected");
} catch (NoSuchAlgorithmException e) {
//expected
}
try {
em.getInstance("WrongAlgName", (Provider) null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
//expected
}
}
use of org.apache.harmony.security.tests.support.SpiEngUtils in project robovm by robovm.
the class ExemptionMechanismTest method test_getProvider.
public void test_getProvider() throws Exception {
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
};
Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
assertEquals(mProv, em.getProvider());
}
use of org.apache.harmony.security.tests.support.SpiEngUtils in project robovm by robovm.
the class ExemptionMechanismTest method test_getInstanceLjava_lang_String.
public void test_getInstanceLjava_lang_String() throws Exception {
try {
ExemptionMechanism.getInstance((String) null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
//expected
}
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
};
try {
em.getInstance("WrongAlgName");
fail("NoSuchAlgorithmException expected");
} catch (NoSuchAlgorithmException e) {
//expected
}
}
Aggregations