/** * Assumes that the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. * <p> * These are necessary to use strong encryption algorithms. */ public static void javaCryptographyExtensionInstalled() { boolean javaCryptographyExtensionInstalled = JuUtils.getJuPropertyChain().get( "ju-testing.javaCryptographyExtension.isInstalled", Boolean.class, true); Assume.assumeTrue(javaCryptographyExtensionInstalled); } }
@Override public void cleanupTestRun(TestRunnerAnnotationHandler handler, SystemPropertyTempSetter tempSetter) { try (ContainerTestContextSetter s = handler.new ContainerTestContextSetter(true)) { tempSetter.close(); // Clear property chain if clearing property is set if (JuUtils.getJuPropertyChain().get("ju-testing-ee.clearPropertyChainAfterEachTest", Boolean.class, "false")) { JuUtils.clearPropertyChain(); } } }
private void handleEncryptedPassword() { this.decryptedPassword = JuSecurityUtils.decryptTaggedValueIfNecessary(this.password, JuUtils.getDefaultEncryptor()); }
@Before public void clearPropertyChain_beforeTests() { JuUtils.clearPropertyChain(); }
@Test public void canInterpolate_value() { PropertyChain pc = PropertyChainTest.createPropertiesChain(false, "p1", "World"); Assert.assertEquals("Hello World", JuUtils.interpolate("Hello ${p1}", pc)); }
@BeforeClass public static void clearPropertyChain_afterTests() { JuUtils.clearPropertyChain(); }
@Test public void canInterpolate_envValue() { try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) { ts.setEnv("MY_ENV", "World"); Assert.assertEquals("Hello World", JuUtils.interpolate("Hello ${env.MY_ENV}")); } } }
/** * Assumes the Chrome browser is available. */ public static void chromeIsAvailable() { boolean chromeIsAvailable = JuUtils.getJuPropertyChain().get("ju-testing-ee.selenium.chrome.isAvailable", Boolean.class, true); Assume.assumeTrue("Chrome is not available", chromeIsAvailable); }
@Override public void cleanupTestRun(TestRunnerAnnotationHandler handler, SystemPropertyTempSetter tempSetter) { try (ContainerTestContextSetter s = handler.new ContainerTestContextSetter(true)) { tempSetter.close(); // Clear property chain if clearing property is set if (JuUtils.getJuPropertyChain().get("ju-testing-ee.clearPropertyChainAfterEachTest", Boolean.class, "false")) { JuUtils.clearPropertyChain(); } } }
@Before public void clearPropertyChain_beforeTests() { JuUtils.clearPropertyChain(); }
@Test public void defaultDecryptor_isNull_whenPassword_isNotSet() { try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) { ts.setProperty("ju-util.propertyChain.encryption.password", null); Assert.assertNull(JuUtils.getDefaultEncryptor()); } }
/** * Assumes Internet access is available. */ public static void internetIsAvailable() { boolean chromeIsAvailable = JuUtils.getJuPropertyChain().get("ju-testing-ee.internet.isAvailable", Boolean.class, true); Assume.assumeTrue("Internet is not available", chromeIsAvailable); }
@Test public void defaultDecryptor_isAvailable_whenPassword_isSet() { try (SystemPropertyTempSetter ts = new SystemPropertyTempSetter()) { ts.setProperty("ju-util.propertyChain.encryption.password", "secretPassword"); Assert.assertEquals("secretVal", JuUtils.getDefaultEncryptor().decrypt("cCULeUjKiLfBwEgCOKC1g3BasxVDF85c")); } }
/** * Gets the full page URL for an URL specified without host and port, * e.g. <code>web-app/page.jsf</code>. Host name and port will be resolved from the * JU properties, e.g. <code>http://localhost:8080/web-app/page.jsf</code> * * @param subPageUrl * Page URL without host an port */ public static String getPageUrl(String subPageUrl) { PropertyChain pc = JuUtils.getJuPropertyChain(); String host = pc.get("ju-testing-ee.web.host"); Integer port = pc.get("ju-testing-ee.web.port", Integer.class) + pc.get("ju-util-ee.portOffset", Integer.class); String url = String.format("http://%s:%d/%s", host, port, subPageUrl); return url; } }
String tagName = JuUtils.getJuPropertyChain().get(clazz.getName(), false); String defaultTagName = JuUtils.getJuPropertyChain().get("ju.ee.cdi.defaultDynamicCdiTag", "-");
String tagName = JuUtils.getJuPropertyChain().get(clazz.getName(), false); String defaultTagName = JuUtils.getJuPropertyChain().get("ju.ee.cdi.defaultDynamicCdiTag", "-");
/** * Loads connection info by PropertyChain profile. * <p> * This will look for the following properties: * <ul> * <li>ju-dbutil-test.[profileName].connectionUrl</li> * <li>ju-dbutil-test.[profileName].user</li> * <li>ju-dbutil-test.[profileName].password</li> * </ul> * @param profileName * @return */ public JuConnUtilBuilder profile(String profileName) { PropertyChain pc = JuUtils.getJuPropertyChain(); return this.url(pc.get(String.format("ju-dbutil-test.%s.connectionUrl", profileName))) .user(pc.get(String.format("ju-dbutil-test.%s.user", profileName))) .password(pc.get(String.format("ju-dbutil-test.%s.password", profileName))); }
private void prepareSchemaByProfile() { String profile = JuUtils.getJuPropertyChain().get("ju-dbutil-test.profile", true); String adminPassword = JuUtils.getJuPropertyChain().get(String.format("ju-dbutil-test.%sAdmin.password", profile), false); String schemaName = JuUtils.getJuPropertyChain().get(String.format("ju-dbutil-test.%s.schema", profile), false); String userName = JuUtils.getJuPropertyChain().get(String.format("ju-dbutil-test.%s.user", profile), false); if (StringUtils.isEmpty(schemaName)) { schemaName = userName; boolean dropExistingSchema = JuUtils.getJuPropertyChain().get( String.format("ju-dbutil-test.%s.dropExistingSchema", adminProfile), Boolean.class, "false"); logger.info("Creating Schema {}", schemaName); String schemaPassword = JuUtils.getJuPropertyChain().get(String.format("ju-dbutil-test.%s.password", profile), false); boolean jtaRecoveryGrants = JuUtils.getJuPropertyChain().get( String.format("ju-dbutil-test.%s.jtaRecoveryGrants", profile), Boolean.class, "false");
if (!JuUtils.getJuPropertyChain().get("ju-testing.export.compareToResource", Boolean.class) && this.dataSetConfigInfo.isLoadImportResourcesFromFileSystem() && !StringUtils.isEmpty(resourceDir)) {
@Test public void multiplePropertyFiles_areFound() { Assert.assertEquals("testing", JuUtils.getJuPropertyChain().get("ju-testing.property")); } }