Code formatting changes

revert-70aa11f8
Sameera Wickramasekara 7 years ago
parent ba6153bf1c
commit 59ca7e1795

@ -30,6 +30,7 @@ import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
public class CertificateCacheManagerImplTests extends BaseDeviceManagementCertificateTest { public class CertificateCacheManagerImplTests extends BaseDeviceManagementCertificateTest {
private CertificateCacheManager manager; private CertificateCacheManager manager;
@BeforeClass @BeforeClass
@Override @Override
public void init() throws Exception { public void init() throws Exception {

@ -42,7 +42,12 @@ import org.wso2.carbon.certificate.mgt.core.util.CertificateManagementConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.File; import java.io.File;
import java.security.*; import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.NoSuchProviderException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.InvalidKeyException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.sql.SQLException; import java.sql.SQLException;
@ -56,7 +61,7 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behaviour when a certificate IO error occurs", @Test(description = "This test case tests behaviour when a certificate IO error occurs",
expectedExceptions = KeystoreException.class) expectedExceptions = KeystoreException.class)
public void negtiveTestGenerateCertificateFromCSR() throws Exception { public void negativeTestGenerateCertificateFromCSR() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//Prepare mock objects //Prepare mock objects
X509v3CertificateBuilder mock = Mockito.mock(X509v3CertificateBuilder.class); X509v3CertificateBuilder mock = Mockito.mock(X509v3CertificateBuilder.class);
@ -78,9 +83,8 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behaviour when Certificate Operator creation error occurs", @Test(description = "This test case tests behaviour when Certificate Operator creation error occurs",
expectedExceptions = KeystoreException.class) expectedExceptions = KeystoreException.class)
public void negtiveTestGenerateCertificateFromCSR2() throws Exception { public void negativeTestGenerateCertificateFromCSR2() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//Prepare mock objects //Prepare mock objects
JcaContentSignerBuilder mock = Mockito.mock(JcaContentSignerBuilder.class); JcaContentSignerBuilder mock = Mockito.mock(JcaContentSignerBuilder.class);
Mockito.when(mock.setProvider(Matchers.eq(CertificateManagementConstants.PROVIDER))).thenReturn(mock); Mockito.when(mock.setProvider(Matchers.eq(CertificateManagementConstants.PROVIDER))).thenReturn(mock);
@ -100,15 +104,13 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests the behaviour when certificate exception occurs when verifying" @Test(description = "This test case tests the behaviour when certificate exception occurs when verifying"
, expectedExceptions = KeystoreException.class) , expectedExceptions = KeystoreException.class)
public void negtiveTestGenerateCertificateFromCSR3() throws Exception { public void negativeTestGenerateCertificateFromCSR3() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//Prepare mock objects //Prepare mock objects
JcaX509CertificateConverter mock = Mockito.mock(JcaX509CertificateConverter.class); JcaX509CertificateConverter mock = Mockito.mock(JcaX509CertificateConverter.class);
Mockito.when(mock.setProvider(Matchers.eq(CertificateManagementConstants.PROVIDER))).thenReturn(mock); Mockito.when(mock.setProvider(Matchers.eq(CertificateManagementConstants.PROVIDER))).thenReturn(mock);
Mockito.when(mock.getCertificate(Matchers.any(X509CertificateHolder.class))).thenThrow(new CertificateException()); Mockito.when(mock.getCertificate(Matchers.any(X509CertificateHolder.class))).thenThrow(new CertificateException());
PowerMockito.whenNew(JcaX509CertificateConverter.class).withAnyArguments().thenReturn(mock); PowerMockito.whenNew(JcaX509CertificateConverter.class).withAnyArguments().thenReturn(mock);
//prepare input parameters //prepare input parameters
CSRGenerator csrGeneration = new CSRGenerator(); CSRGenerator csrGeneration = new CSRGenerator();
KeyStoreReader keyStoreReader = new KeyStoreReader(); KeyStoreReader keyStoreReader = new KeyStoreReader();
@ -124,9 +126,9 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behaviour when the Certificate provider does not exist" @Test(description = "This test case tests behaviour when the Certificate provider does not exist"
, expectedExceptions = KeystoreException.class) , expectedExceptions = KeystoreException.class)
public void negativeTestgenerateX509Certificate1() throws Exception { public void negativeTestGenerateX509Certificate1() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//prepare mock objects
X509Certificate mock = Mockito.mock(X509Certificate.class); X509Certificate mock = Mockito.mock(X509Certificate.class);
PowerMockito.doThrow(new NoSuchProviderException()).when(mock).verify(Matchers.any()); PowerMockito.doThrow(new NoSuchProviderException()).when(mock).verify(Matchers.any());
JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class); JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class);
@ -138,9 +140,9 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behaviour when the Certificate Algorithm does not exist" @Test(description = "This test case tests behaviour when the Certificate Algorithm does not exist"
, expectedExceptions = KeystoreException.class) , expectedExceptions = KeystoreException.class)
public void negativeTestgenerateX509Certificate2() throws Exception { public void negativeTestGenerateX509Certificate2() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//prepare mock objects
X509Certificate mock = Mockito.mock(X509Certificate.class); X509Certificate mock = Mockito.mock(X509Certificate.class);
PowerMockito.doThrow(new NoSuchAlgorithmException()).when(mock).verify(Matchers.any()); PowerMockito.doThrow(new NoSuchAlgorithmException()).when(mock).verify(Matchers.any());
JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class); JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class);
@ -152,9 +154,9 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behaviour when the Signature validation fails" @Test(description = "This test case tests behaviour when the Signature validation fails"
, expectedExceptions = KeystoreException.class) , expectedExceptions = KeystoreException.class)
public void negativeTestgenerateX509Certificate3() throws Exception { public void negativeTestGenerateX509Certificate3() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//prepare mock objects
X509Certificate mock = Mockito.mock(X509Certificate.class); X509Certificate mock = Mockito.mock(X509Certificate.class);
PowerMockito.doThrow(new SignatureException()).when(mock).verify(Matchers.any()); PowerMockito.doThrow(new SignatureException()).when(mock).verify(Matchers.any());
JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class); JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class);
@ -166,9 +168,9 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behaviour when the Certificate exception occurs" @Test(description = "This test case tests behaviour when the Certificate exception occurs"
, expectedExceptions = KeystoreException.class) , expectedExceptions = KeystoreException.class)
public void negativeTestgenerateX509Certificate4() throws Exception { public void negativeTestGenerateX509Certificate4() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//prepare mock objects
X509Certificate mock = Mockito.mock(X509Certificate.class); X509Certificate mock = Mockito.mock(X509Certificate.class);
PowerMockito.doThrow(new CertificateException()).when(mock).verify(Matchers.any()); PowerMockito.doThrow(new CertificateException()).when(mock).verify(Matchers.any());
JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class); JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class);
@ -180,9 +182,9 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behaviour when the Certificate key is invalid" @Test(description = "This test case tests behaviour when the Certificate key is invalid"
, expectedExceptions = KeystoreException.class) , expectedExceptions = KeystoreException.class)
public void negativeTestgenerateX509Certificate5() throws Exception { public void negativeTestGenerateX509Certificate5() throws Exception {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
//prepare mock objects
X509Certificate mock = Mockito.mock(X509Certificate.class); X509Certificate mock = Mockito.mock(X509Certificate.class);
PowerMockito.doThrow(new InvalidKeyException()).when(mock).verify(Matchers.any()); PowerMockito.doThrow(new InvalidKeyException()).when(mock).verify(Matchers.any());
JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class); JcaX509CertificateConverter conv = Mockito.mock(JcaX509CertificateConverter.class);
@ -194,14 +196,14 @@ public class CertificateGeneratorNegativeTests extends PowerMockTestCase {
@Test(description = "This test case tests behavior when the CA certificate is null" @Test(description = "This test case tests behavior when the CA certificate is null"
, expectedExceptions = KeystoreException.class) , expectedExceptions = KeystoreException.class)
public void negativeTestgetRootCertificates1() throws KeystoreException { public void negativeTestGetRootCertificates1() throws KeystoreException {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
generator.getRootCertificates(null, new byte[10]); generator.getRootCertificates(null, new byte[10]);
} }
@Test(description = "This test case tests behavior when the CA certificate is null", @Test(description = "This test case tests behavior when the CA certificate is null",
expectedExceptions = KeystoreException.class) expectedExceptions = KeystoreException.class)
public void negativeTestgetRootCertificates2() throws KeystoreException { public void negativeTestGetRootCertificates2() throws KeystoreException {
CertificateGenerator generator = new CertificateGenerator(); CertificateGenerator generator = new CertificateGenerator();
generator.getRootCertificates(new byte[10], null); generator.getRootCertificates(new byte[10], null);
} }

@ -19,7 +19,6 @@
package org.wso2.carbon.certificate.mgt.core.impl; package org.wso2.carbon.certificate.mgt.core.impl;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.mockito.Matchers;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PowerMockIgnore;
@ -32,15 +31,12 @@ import org.testng.annotations.Test;
import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory; import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException; import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import org.wso2.carbon.certificate.mgt.core.exception.TransactionManagementException; import org.wso2.carbon.certificate.mgt.core.exception.TransactionManagementException;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.File; import java.io.File;
import java.security.NoSuchProviderException;
import java.security.cert.X509Certificate;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
@ -95,7 +91,7 @@ public class CertificateManagementServiceImplNegativeTests extends PowerMockTest
@Test(description = "This test case tests behaviour when an error occurs when opening the data source" @Test(description = "This test case tests behaviour when an error occurs when opening the data source"
, expectedExceptions = CertificateManagementException.class) , expectedExceptions = CertificateManagementException.class)
public void negativeTestretrieveCertificate2() throws Exception { public void negativeTestRetrieveCertificate2() throws Exception {
PowerMockito.mockStatic(CertificateManagementDAOFactory.class); PowerMockito.mockStatic(CertificateManagementDAOFactory.class);
PowerMockito.doThrow(new SQLException()).when(CertificateManagementDAOFactory.class, "openConnection"); PowerMockito.doThrow(new SQLException()).when(CertificateManagementDAOFactory.class, "openConnection");
instance.retrieveCertificate(MOCK_SERIAL); instance.retrieveCertificate(MOCK_SERIAL);
@ -103,7 +99,7 @@ public class CertificateManagementServiceImplNegativeTests extends PowerMockTest
@Test(description = "This test case tests behaviour when an error occurs when looking for a certificate with " + @Test(description = "This test case tests behaviour when an error occurs when looking for a certificate with " +
"a serial number", expectedExceptions = CertificateManagementException.class) "a serial number", expectedExceptions = CertificateManagementException.class)
public void negativeTestretrieveCertificate() throws Exception { public void negativeTestRetrieveCertificate() throws Exception {
CertificateManagementDAOFactory.init(daoExceptionDatasource); CertificateManagementDAOFactory.init(daoExceptionDatasource);
CertificateManagementServiceImpl instance1 = CertificateManagementServiceImpl.getInstance(); CertificateManagementServiceImpl instance1 = CertificateManagementServiceImpl.getInstance();
instance1.retrieveCertificate(MOCK_SERIAL); instance1.retrieveCertificate(MOCK_SERIAL);
@ -111,7 +107,7 @@ public class CertificateManagementServiceImplNegativeTests extends PowerMockTest
@Test(description = "This test case tests behaviour when an error occurs when opening the data source", @Test(description = "This test case tests behaviour when an error occurs when opening the data source",
expectedExceptions = CertificateManagementException.class) expectedExceptions = CertificateManagementException.class)
public void negativeTestgetAllCertificates() throws Exception { public void negativeTestGetAllCertificates() throws Exception {
PowerMockito.mockStatic(CertificateManagementDAOFactory.class); PowerMockito.mockStatic(CertificateManagementDAOFactory.class);
PowerMockito.doThrow(new SQLException()).when(CertificateManagementDAOFactory.class, "openConnection"); PowerMockito.doThrow(new SQLException()).when(CertificateManagementDAOFactory.class, "openConnection");
instance.getAllCertificates(1, 2); instance.getAllCertificates(1, 2);
@ -119,7 +115,7 @@ public class CertificateManagementServiceImplNegativeTests extends PowerMockTest
@Test(description = "This test case tests behaviour when an error occurs getting the list of certificates from repository" @Test(description = "This test case tests behaviour when an error occurs getting the list of certificates from repository"
, expectedExceptions = CertificateManagementException.class) , expectedExceptions = CertificateManagementException.class)
public void negativeTestgetAllCertificates2() throws Exception { public void negativeTestGetAllCertificates2() throws Exception {
CertificateManagementDAOFactory.init(daoExceptionDatasource); CertificateManagementDAOFactory.init(daoExceptionDatasource);
CertificateManagementServiceImpl instance1 = CertificateManagementServiceImpl.getInstance(); CertificateManagementServiceImpl instance1 = CertificateManagementServiceImpl.getInstance();
instance1.getAllCertificates(1, 2); instance1.getAllCertificates(1, 2);

Loading…
Cancel
Save