/** Tests that testConnection gives error if pvalue is invalid. */ public void testPvalueNotInInterval() throws Exception { MockedCertificateSamplerCustomPublisher publisher; Properties config; // Profile pvalue=-0.5 (illegal) config = new Properties(); config.setProperty("outputfolder", TEMP_DIR.getAbsolutePath()); config.setProperty("default.samplingmethod", "SAMPLE_ALL"); config.setProperty("profileid." + PROFILE_A + ".samplingmethod", "SAMPLE_PROBABILISTIC"); config.setProperty("profileid." + PROFILE_A + ".pvalue", "-0.5"); publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as pvalue is not in the [0, 1] range"); } catch (PublisherConnectionException expected) { } // NOPMD // Default pvalue=-0.5 (illegal) config = new Properties(); config.setProperty("outputfolder", TEMP_DIR.getAbsolutePath()); config.setProperty("default.samplingmethod", "SAMPLE_PROBABILISTIC"); config.setProperty("default.pvalue", "-0.5"); publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as pvalue is not in the [0, 1] range"); } catch (PublisherConnectionException expected) { } // NOPMD }
/** * Tests that testConnection and storeCertificate gives error if there is an invalid sampling * method. */ public void testInvalidSamplingMethod() throws Exception { MockedCertificateSamplerCustomPublisher publisher; Properties config; // Default sampling method: INVALID config = new Properties(); config.setProperty("outputfolder", TEMP_DIR.getAbsolutePath()); config.setProperty("default.samplingmethod", "_INVALID_"); publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as '_INVALID_' is not an existing sampling method"); } catch (PublisherConnectionException expected) { } // NOPMD publisher = createMockedPublisher(config); try { storeCertificate(publisher, SecConst.CERT_ACTIVE, ANY_PROFILEID); fail("Should have failed as '_INVALID_' is not an existing sampling method"); } catch (PublisherException expected) { } // NOPMD // Profile sampling method: INVALID config = new Properties(); config.setProperty("outputfolder", TEMP_DIR.getAbsolutePath()); config.setProperty("default.samplingmethod", "SAMPLE_ALL"); config.setProperty("profileid." + PROFILE_A + ".samplingmethod", "_INVALID_"); publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as '_INVALID_' is not an existing sampling method"); } catch (PublisherConnectionException expected) { } // NOPMD publisher = createMockedPublisher(config); try { storeCertificate(publisher, SecConst.CERT_ACTIVE, PROFILE_A); fail("Should have failed as '_INVALID_' is not an existing sampling method"); } catch (PublisherException expected) { } // NOPMD }
/** Tests that testConnection gives error if there is an invalid profile key. */ public void testInvalidProfileKey() throws Exception { MockedCertificateSamplerCustomPublisher publisher; Properties config; // Profile pvalue=-0.5 (illegal) config = new Properties(); config.setProperty("outputfolder", TEMP_DIR.getAbsolutePath()); config.setProperty("default.samplingmethod", "SAMPLE_ALL"); config.setProperty("profileid.INVALID.samplingmethod", "SAMPLE_ALL"); publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as 'INVALID' is not an legal profile id"); } catch (PublisherConnectionException expected) { } // NOPMD }
/** * Tests that storeCertificate and testConnection throws Exception as the property for the default * sampling method is missing. */ public void testNoDefaultSamplingMethod() throws Exception { MockedCertificateSamplerCustomPublisher publisher; Properties config = new Properties(); config.setProperty("outputfolder", TEMP_DIR.getAbsolutePath()); // Test storeCertificate publisher = createMockedPublisher(config); try { storeCertificate(publisher, SecConst.CERT_ACTIVE, ANY_PROFILEID); fail("Should have failed as property outputfolder was missing"); } catch (PublisherException expected) { } // NOPMD // Test testConnection publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as property outputfolder was missing"); } catch (PublisherConnectionException expected) { } // NOPMD }
/** * Tests that storeCertificate and testConnection throws Exception as the property output folder * is missing. */ public void testNoOutputFolder() throws Exception { MockedCertificateSamplerCustomPublisher publisher; Properties config = new Properties(); config.setProperty("default.samplingmethod", "SAMPLE_ALL"); // Test storeCertificate publisher = createMockedPublisher(config); try { storeCertificate(publisher, SecConst.CERT_ACTIVE, ANY_PROFILEID); fail("Should have failed as property outputfolder was missing"); } catch (PublisherException expected) { } // NOPMD // Test testConnection publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as property outputfolder was missing"); } catch (PublisherConnectionException expected) { } // NOPMD }
/** * Tests that storeCertificate and testConnection throws Exception as the pvalue for a profile is * missing. */ public void testNoPValueForProfileSamplingMethod() throws Exception { MockedCertificateSamplerCustomPublisher publisher; Properties config = new Properties(); config.setProperty("outputfolder", TEMP_DIR.getAbsolutePath()); config.setProperty("default.samplingmethod", "SAMPLE_ALL"); config.setProperty("profileid." + PROFILE_A + ".samplingmethod", "SAMPLE_PROBABILISTIC"); // Test storeCertificate publisher = createMockedPublisher(config); try { storeCertificate(publisher, SecConst.CERT_ACTIVE, PROFILE_A); fail("Should have failed as no default pvalue for profile A specified"); } catch (PublisherException expected) { } // NOPMD // Test testConnection publisher = createMockedPublisher(config); try { publisher.testConnection(ANY_ADMIN); fail("Should have failed as no pvalue for a profile specified"); } catch (PublisherConnectionException expected) { } // NOPMD }