public ArquillianDescriptor resolve(ArquillianDescriptor descriptor) { final String descriptorAsString = descriptor.exportAsString(); return Descriptors.importAs(ArquillianDescriptor.class) .fromString(StringPropertyReplacer.replaceClasspath(descriptorAsString)); }
public ArquillianDescriptor resolve(ArquillianDescriptor descriptor) { final String descriptorAsString = descriptor.exportAsString(); return Descriptors.importAs(ArquillianDescriptor.class) .fromString(StringPropertyReplacer.replaceClasspath(descriptorAsString)); }
/** * Returns a new instance of {@link ArquillianDescriptor} by resolving any * sysprop EL expressions in the provided {@link ArquillianDescriptor} to real * values or defaults * * @param descriptor * The input to resolve, required * * @throws IllegalArgumentException */ private ArquillianDescriptor resolveSystemProperties(final ArquillianDescriptor descriptor) throws IllegalArgumentException { final String descriptorAsString = descriptor.exportAsString(); return Descriptors.importAs(ArquillianDescriptor.class) .fromString(StringPropertyReplacer.replaceProperties(descriptorAsString)); }
/** * Returns a new instance of {@link ArquillianDescriptor} by resolving any * sysprop EL expressions in the provided {@link ArquillianDescriptor} to real * values or defaults * * @param descriptor * The input to resolve, required * * @throws IllegalArgumentException */ private ArquillianDescriptor resolveSystemProperties(final ArquillianDescriptor descriptor) throws IllegalArgumentException { final String descriptorAsString = descriptor.exportAsString(); return Descriptors.importAs(ArquillianDescriptor.class) .fromString(StringPropertyReplacer.replaceProperties(descriptorAsString)); }
@Test public void should_replace_classpath_in_arquillian_xml() throws Exception { // when final String xml = desc.get().exportAsString(); // then AssertXPath.assertXPath(xml, "/arquillian/container/@qualifier", VALUE_EL_OVERRIDE); final URL resource = Thread.currentThread().getContextClassLoader().getResource("arquillian_sysprop.xml"); assertXPath(xml, "/arquillian/container/configuration/property", String.format("-Djavax.net.ssl.trustStore=%s", resource.toString())); }
@Test public void shouldBeAbleToGenerateEmpty() throws Exception { desc = create().exportAsString(); }
/** * Ensures that we can load an arquillian.xml and perform sysprop * EL replacement upon it. */ @Test public void syspropReplacementInArqXml() throws Exception { // when final String xml = desc.get().exportAsString(); // then AssertXPath.assertXPath(xml, "/arquillian/container/@qualifier", VALUE_EL_OVERRIDE); }
private ArquillianDescriptor create(String xml) throws Exception { validateXML(desc.exportAsString()); return Descriptors.importAs(ArquillianDescriptor.class).from(xml); }
@Test public void should_replace_properties_with_classpath_location() throws Exception { // given String element = "arquillian_sysprop.xml"; ArquillianDescriptor desc = create() .container("daemon") .property("javaVmArguments", "-Djavax.net.ssl.trustStore=${classpath(" + element + ")}"); final ClasspathConfigurationPlaceholderResolver classpathConfigurationPlaceholderResolver = new ClasspathConfigurationPlaceholderResolver(); // when desc = classpathConfigurationPlaceholderResolver.resolve(desc); // then final String descString = desc.exportAsString(); final URL resource = Thread.currentThread().getContextClassLoader().getResource(element); assertXPath(descString, "/arquillian/container/configuration/property", String.format("-Djavax.net.ssl.trustStore=%s", resource.toString())); }
@Test public void shouldReturnNullDefaultProtocolIfNotAdded() throws Exception { desc = create() .exportAsString(); ArquillianDescriptor descriptor = create(desc); Assert.assertNull(descriptor.getDefaultProtocol()); }
@Test public void should_not_replace_placeholder_if_classpath_resource_not_found() throws Exception { String element = "notfound.txt"; ArquillianDescriptor desc = create() .container("daemon") .property("javaVmArguments", "-Djavax.net.ssl.trustStore=${classpath(" + element + ")}"); final ClasspathConfigurationPlaceholderResolver classpathConfigurationPlaceholderResolver = new ClasspathConfigurationPlaceholderResolver(); // when desc = classpathConfigurationPlaceholderResolver.resolve(desc); // then final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/container/configuration/property", String.format("-Djavax.net.ssl.trustStore=${classpath(%s)}", element)); }
@Test public void should_not_replace_other_placeholders() throws Exception { ArquillianDescriptor desc = create() .container("daemon") .property("javaVmArguments", "-Djavax.net.ssl.trustStore=${env.LAUNCHER_TESTS_TRUSTSTORE_PATH}"); final ClasspathConfigurationPlaceholderResolver classpathConfigurationPlaceholderResolver = new ClasspathConfigurationPlaceholderResolver(); // when desc = classpathConfigurationPlaceholderResolver.resolve(desc); // then final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/container/configuration/property", "-Djavax.net.ssl.trustStore=${env.LAUNCHER_TESTS_TRUSTSTORE_PATH}"); }
@Test @Ignore // Dependencies not supported on container level in v. 1.0 public void shouldBeAbleToAddContainerWithDependenciesAndOverwrite() throws Exception { System.setProperty(KEY_DEPENDENCY_1, DEPENDENCY_1); desc = create() .container(CONTAINER_NAME_1) .dependency(setPropKey(KEY_DEPENDENCY_1)) .dependency(setPropKey(KEY_DEPENDENCY_1)); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/container/dependencies/dependency", DEPENDENCY_1); ArquillianDescriptor descriptor = create(descString); Assert.assertEquals(1, descriptor.getContainers().size()); Assert.assertEquals(CONTAINER_NAME_1, descriptor.getContainers().get(0).getContainerName()); Assert.assertEquals(1, descriptor.getContainers().get(0).getDependencies().size()); Assert.assertEquals(DEPENDENCY_1, descriptor.getContainers().get(0).getDependencies().get(0)); }
@Test public void shouldBeAbleToAddGroupWithContainerAndOverwriteContainer() throws Exception { System.setProperty(KEY_CONTAINER_NAME_1, CONTAINER_NAME_1); desc = create() .group(GROUP_NAME_1) .container(setPropKey(KEY_CONTAINER_NAME_1)) .container(setPropKey(KEY_CONTAINER_NAME_1)); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/group/@qualifier", GROUP_NAME_1); assertXPath(descString, "/arquillian/group/container/@qualifier", CONTAINER_NAME_1); ArquillianDescriptor descriptor = create(descString); Assert.assertEquals(1, descriptor.getGroups().size()); Assert.assertEquals(1, descriptor.getGroups().get(0).getGroupContainers().size()); Assert.assertEquals(CONTAINER_NAME_1, descriptor.getGroups().get(0).getGroupContainers().get(0).getContainerName()); }
@Test public void shouldBeAbleToRenameExtension() throws Exception { desc = create() .extension(EXTENSION_NAME_1) .property(PROPERTY_NAME_1, PROPERTY_VALUE_1) .extension(EXTENSION_NAME_1) .setExtensionName(EXTENSION_NAME_2); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/extension/@qualifier", EXTENSION_NAME_2); ArquillianDescriptor descriptor = create(descString); Assert.assertEquals(1, descriptor.getExtensions().size()); Assert.assertEquals(EXTENSION_NAME_2, descriptor.getExtensions().get(0).getExtensionName()); Assert.assertEquals(1, descriptor.getExtensions().get(0).getExtensionProperties().size()); Assert.assertEquals(PROPERTY_VALUE_1, descriptor.getExtensions().get(0).getExtensionProperties().get(PROPERTY_NAME_1)); }
@Test public void shouldBeAbleToAddContainerAndOverwrite() throws Exception { System.setProperty(KEY_CONTAINER_NAME_1, CONTAINER_NAME_1); System.setProperty(KEY_CONTAINER_NAME_2, CONTAINER_NAME_2); desc = create() .container(CONTAINER_NAME_1).setDefault() .container(CONTAINER_NAME_1).setContainerName(setPropKey(KEY_CONTAINER_NAME_2)); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/container/@qualifier", CONTAINER_NAME_2); assertXPath(descString, "/arquillian/container/@default", "true"); ArquillianDescriptor descriptor = create(descString); Assert.assertEquals(1, descriptor.getContainers().size()); Assert.assertEquals(CONTAINER_NAME_2, descriptor.getContainers().get(0).getContainerName()); Assert.assertTrue(descriptor.getContainers().get(0).isDefault()); }
@Test public void shouldBeAbleToAddContainer() throws Exception { System.setProperty(KEY_CONTAINER_NAME_1, CONTAINER_NAME_1); System.setProperty(KEY_CONTAINER_NAME_2, CONTAINER_NAME_2); desc = create() .container(setPropKey(KEY_CONTAINER_NAME_1)).setDefault() .container(setPropKey(KEY_CONTAINER_NAME_2)); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/container/@qualifier", CONTAINER_NAME_1, CONTAINER_NAME_2); assertXPath(descString, "/arquillian/container[1]/@default", "true"); ArquillianDescriptor descriptor = create(descString); Assert.assertEquals(2, descriptor.getContainers().size()); Assert.assertEquals(CONTAINER_NAME_1, descriptor.getContainers().get(0).getContainerName()); Assert.assertTrue(descriptor.getContainers().get(0).isDefault()); Assert.assertEquals(CONTAINER_NAME_2, descriptor.getContainers().get(1).getContainerName()); }
@Test public void shouldBeAbleToAddDefaultProtocol() throws Exception { System.setProperty(KEY_PROPERTY_VALUE_1, PROPERTY_VALUE_1); desc = create() .defaultProtocol(PROTOCOL_TYPE_1) .property(PROPERTY_NAME_1, setPropKey(KEY_PROPERTY_VALUE_1)); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/defaultProtocol/@type", PROTOCOL_TYPE_1); assertXPath(descString, "/arquillian/defaultProtocol/property/@name", PROPERTY_NAME_1); assertXPath(descString, "/arquillian/defaultProtocol/property/text()", PROPERTY_VALUE_1); ArquillianDescriptor descriptor = create(descString); Assert.assertNotNull(descriptor.getDefaultProtocol()); Assert.assertEquals(PROTOCOL_TYPE_1, descriptor.getDefaultProtocol().getType()); Assert.assertEquals(PROPERTY_VALUE_1, descriptor.getDefaultProtocol().getProperties().get(PROPERTY_NAME_1)); }
@Test public void shouldReturnNullOnEnginePropertiesIfNotSet() throws Exception { // add multiple times to see only one property added desc = create() .engine(); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); ArquillianDescriptor descriptor = create(descString); Assert.assertNull(descriptor.engine().getDeploymentExportPath()); Assert.assertNull(descriptor.engine().getMaxTestClassesBeforeRestart()); }
@Test public void shouldBeAbleToSetEngineProperties() throws Exception { System.setProperty(KEY_PROPERTY_VALUE_1, PROPERTY_VALUE_1); // add multiple times to see only one property added desc = create() .engine() .deploymentExportPath(setPropKey(KEY_PROPERTY_VALUE_1)) .deploymentExportPath(setPropKey(KEY_PROPERTY_VALUE_1)) .maxTestClassesBeforeRestart(PROPERTY_INT_VALUE_1) .maxTestClassesBeforeRestart(PROPERTY_INT_VALUE_1); desc = new SystemPropertiesConfigurationPlaceholderResolver().resolve(desc); final String descString = desc.exportAsString(); assertXPath(descString, "/arquillian/engine/property[@name='deploymentExportPath']/text()", PROPERTY_VALUE_1); assertXPath(descString, "/arquillian/engine/property[@name='maxTestClassesBeforeRestart']/text()", PROPERTY_INT_VALUE_1); ArquillianDescriptor descriptor = create(descString); Assert.assertEquals(PROPERTY_VALUE_1, descriptor.engine().getDeploymentExportPath()); Assert.assertEquals(PROPERTY_INT_VALUE_1, descriptor.engine().getMaxTestClassesBeforeRestart()); }