Search in sources :

Example 6 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class CertificateServiceTest method testListCertificates.

/**
     * Test the listCertificates method.
     */
public void testListCertificates() {
    final CertificateDao certificateDao = context.mock(CertificateDao.class);
    final Long certificateId = 7L;
    final int maxResults = 7;
    final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
    context.checking(new Expectations() {

        {
            oneOf(certificateDao).list((String) null);
            will(returnValue(Collections.<Certificate>emptyList()));
        }
    });
    CertificateServiceImpl service = new CertificateServiceImpl();
    service.setDao(certificateDao);
    try {
        Collection<Certificate> output = service.listCertificates(certificateId, maxResults, certificateOptions);
        assertNotNull("Output is null when using valid params", output);
        assertEquals("Output does not match mocked return value when using valid params", Collections.<Certificate>emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateGetOptions(org.nhindirect.config.service.impl.CertificateGetOptions) CertificateDao(org.nhindirect.config.store.dao.CertificateDao) CertificateServiceImpl(org.nhindirect.config.service.impl.CertificateServiceImpl) Certificate(org.nhindirect.config.store.Certificate)

Example 7 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class CertificateServiceTest method testAddCertificates.

/**
     * Test the addCertificates method.
     */
public void testAddCertificates() {
    final CertificateDao certificateDao = context.mock(CertificateDao.class);
    final Collection<Certificate> certificates = Arrays.asList(new Certificate());
    context.checking(new Expectations() {

        {
            oneOf(certificateDao).save(certificates.iterator().next());
        }
    });
    CertificateServiceImpl service = new CertificateServiceImpl();
    service.setDao(certificateDao);
    try {
        service.addCertificates(certificates);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateDao(org.nhindirect.config.store.dao.CertificateDao) CertificateServiceImpl(org.nhindirect.config.service.impl.CertificateServiceImpl) Certificate(org.nhindirect.config.store.Certificate)

Example 8 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class CertificateServiceTest method testGetCertificate.

/**
     * Test the getCertificate method.
     */
public void testGetCertificate() {
    final CertificateDao certificateDao = context.mock(CertificateDao.class);
    final String owner = "beau";
    final String thumbprint = "thumbprint";
    CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
    context.checking(new Expectations() {

        {
            oneOf(certificateDao).load(owner, thumbprint);
        }
    });
    CertificateServiceImpl service = new CertificateServiceImpl();
    service.setDao(certificateDao);
    try {
        Certificate output = service.getCertificate(owner, thumbprint, certificateOptions);
        assertEquals("Output does not match expected", null, output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateGetOptions(org.nhindirect.config.service.impl.CertificateGetOptions) CertificateDao(org.nhindirect.config.store.dao.CertificateDao) CertificateServiceImpl(org.nhindirect.config.service.impl.CertificateServiceImpl) Certificate(org.nhindirect.config.store.Certificate)

Example 9 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class CertificateServiceTest method testGetCertificatesForOwner.

/**
     * Test the getCertificatesForOwner method.
     */
public void testGetCertificatesForOwner() {
    final CertificateDao certificateDao = context.mock(CertificateDao.class);
    final String owner = "beau";
    final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
    context.checking(new Expectations() {

        {
            oneOf(certificateDao).list(owner);
            will(returnValue(Collections.<Certificate>emptyList()));
        }
    });
    CertificateServiceImpl service = new CertificateServiceImpl();
    service.setDao(certificateDao);
    try {
        Collection<Certificate> output = service.getCertificatesForOwner(owner, certificateOptions);
        assertNotNull("Output is null when using valid params", output);
        assertEquals("Output does not match mocked return value when using valid params", Collections.<Certificate>emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateGetOptions(org.nhindirect.config.service.impl.CertificateGetOptions) CertificateDao(org.nhindirect.config.store.dao.CertificateDao) CertificateServiceImpl(org.nhindirect.config.service.impl.CertificateServiceImpl) Certificate(org.nhindirect.config.store.Certificate)

Example 10 with Certificate

use of org.nhindirect.config.store.Certificate in project nhin-d by DirectProject.

the class ConfigurationServiceTest method testAddCertificate.

/**
     * Test the addCertificate method.
     */
public void testAddCertificate() throws Exception {
    final CertificateService certificateService = context.mock(CertificateService.class);
    final Collection<Certificate> collection = Arrays.asList(new Certificate());
    context.checking(new Expectations() {

        {
            oneOf(certificateService).addCertificates(collection);
        }
    });
    ConfigurationServiceImpl service = new ConfigurationServiceImpl();
    service.setCertSvc(certificateService);
    try {
        service.addCertificates(collection);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) ConfigurationServiceImpl(org.nhindirect.config.service.impl.ConfigurationServiceImpl) Certificate(org.nhindirect.config.store.Certificate)

Aggregations

Certificate (org.nhindirect.config.store.Certificate)19 X509Certificate (java.security.cert.X509Certificate)10 Expectations (org.jmock.Expectations)7 CertificateDao (org.nhindirect.config.store.dao.CertificateDao)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)5 CertificateServiceImpl (org.nhindirect.config.service.impl.CertificateServiceImpl)5 List (java.util.List)4 CertificateGetOptions (org.nhindirect.config.service.impl.CertificateGetOptions)4 Query (javax.persistence.Query)3 DNSRecord (org.nhindirect.config.store.DNSRecord)3 Setting (org.nhindirect.config.store.Setting)3 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)2 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicy (org.nhindirect.config.store.CertPolicy)2 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 CertContainer (org.nhindirect.config.store.Certificate.CertContainer)2 Domain (org.nhindirect.config.store.Domain)2