/** * {@inheritDoc} */ @Override public String readScript() { FileHandler fileHandler = new DefaultFileHandler(); String customScript = fileHandler.readTextFile(resourcePath, "UTF-8"); return customScript; }
/** * {@inheritDoc} */ @Override public String readScript() { FileHandler fileHandler = new DefaultFileHandler(); String customScript = fileHandler.readTextFile(resourcePath, "UTF-8"); return customScript; }
/** * Read a file. * @param file Name of file to read. * @return Contents of <code>file</code>. */ protected String readFile(File file) { return configuration.getFileHandler().readTextFile(getAbsolutePath(file), "UTF-8"); }
this.getPropertyValue(GlassFishPropertySet.DOMAIN_NAME) + "/config/domain.xml"); String domainXml = getFileHandler().readTextFile(domainXmlPath, "UTF-8");
this.getPropertyValue(GlassFishPropertySet.DOMAIN_NAME) + "/config/domain.xml"); String domainXml = getFileHandler().readTextFile(domainXmlPath, "UTF-8");
/** * Test that the file system manager can insert an XML element deep in the XML tree into a file. * This also involves a lookup. * @throws Exception If anything goes wrong */ public void testManagerCanInsertAnElementIntoFileThreeLevelsDeep() throws Exception { Document document = builder.newDocument(); Element application = document.createElement("Application"); document.appendChild(application); Element foo = document.createElement("foo"); application.appendChild(foo); Element bar = document.createElement("bar"); foo.appendChild(bar); util.saveXml(document, TEST_FILE); fileHandler.createFile(TEST_FILE); manager.setFile(TEST_FILE); manager.loadFile(); manager.insertElementsUnderXPath("<subnode property='hello' />", "//Application/foo/bar"); manager.writeFile(); String xml = fileHandler.readTextFile(TEST_FILE, "UTF-8"); XMLAssert.assertXpathEvaluatesTo("hello", "//Application/foo/bar/subnode/@property", xml); }
/** * Test non-existing XML attribute replacement */ public void testNonExistingXmlAttributeReplacement() { final String file = "target/jboss-standalone-nonexisting-xml-attribute.xml"; final String nonExistingAttribute = "nonexisting"; final String test = "nonexisting=\"test\""; this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true); XmlReplacement xmlReplacement = new XmlReplacement(file, "//server/socket-binding-group/socket-binding[@name='http']", nonExistingAttribute, XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test"); this.fileHandler.replaceInXmlFile(xmlReplacement); String read = this.fileHandler.readTextFile(file, "UTF-8"); assertTrue("File " + file + " does not contain: " + test, read.contains(test)); }
/** * Test valid XML replacement */ public void testValidXmlReplacement() { final String file = "target/jboss-standalone-valid.xml"; final String old = "<socket-binding name=\"http\" port=\"@cargo.servlet.port@\"/>"; final String new1 = "<socket-binding name=\"http\" port=\"test1\"/>"; final String new2 = "<socket-binding name=\"http\" port=\"test1\">test2</socket-binding>"; this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true); String read = this.fileHandler.readTextFile(file, "UTF-8"); assertTrue("File " + file + " does not contain: " + old, read.contains(old)); XmlReplacement xmlReplacement = new XmlReplacement(file, "//server/socket-binding-group/socket-binding[@name='http']", "port", XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test1"); this.fileHandler.replaceInXmlFile(xmlReplacement); read = this.fileHandler.readTextFile(file, "UTF-8"); assertFalse("File " + file + " still contains: " + old, read.contains(old)); assertTrue("File " + file + " does not contain: " + new1, read.contains(new1)); xmlReplacement.setAttributeName(null); xmlReplacement.setValue("test2"); this.fileHandler.replaceInXmlFile(xmlReplacement); read = this.fileHandler.readTextFile(file, "UTF-8"); assertFalse("File " + file + " still contains: " + old, read.contains(old)); assertFalse("File " + file + " still contains: " + new1, read.contains(new1)); assertTrue("File " + file + " does not contain: " + new2, read.contains(new2)); }
/** * Test valid XML replacement for replacing a neighbor */ public void testXmlNeighborReplacement() { final String file = "target/bindings-jboss-beans.xml"; final String old = "<property name=\"port\">@cargo.rmi.port@</property>"; final String permanent = "<property name=\"port\">@cargo.jboss.naming.port@</property>"; final String new1 = "<property name=\"port\">test1</property>"; this.fileHandler.copyFile("src/test/resources/bindings-jboss-beans.xml", file, true); String read = this.fileHandler.readTextFile(file, "UTF-8"); assertTrue("File " + file + " does not contain: " + old, read.contains(old)); assertTrue("File " + file + " does not contain: " + permanent, read.contains(permanent)); XmlReplacement xmlReplacement = new XmlReplacement(file, "//deployment/bean[@name='StandardBindings']/constructor/parameter/set/bean" + "/property[@name='serviceName' and text()='jboss:service=Naming']/.." + "/property[@name='bindingName' and text()='Port']/.." + "/property[@name='port']", null, XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test1"); this.fileHandler.replaceInXmlFile(xmlReplacement); read = this.fileHandler.readTextFile(file, "UTF-8"); assertFalse("File " + file + " still contains: " + old, read.contains(old)); assertTrue("File " + file + " does not contain: " + new1, read.contains(new1)); assertTrue("File " + file + " does not contain anymore: " + permanent, read.contains(permanent)); }
/** * Test that the file system manager can insert an XML element with a namespace. * @throws Exception If anything goes wrong */ public void testManagerCanInsertAnElementIntoFileWithNamespace() throws Exception { Document document = builder.newDocument(); Element domain = document.createElement("domain"); domain.setAttribute("xmlns", "http://www.bea.com/ns/weblogic/920/domain"); domain.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); domain.setAttribute("xsi:schemaLocation", "http://www.bea.com/ns/weblogic/920/domain " + "http://www.bea.com/ns/weblogic/920/domain.xsd"); document.appendChild(domain); util.saveXml(document, TEST_FILE); fileHandler.createFile(TEST_FILE); manager.setNamespaces(namespaces); manager.setFile(TEST_FILE); manager.loadFile(); manager.insertElementsUnderXPath("<subnode property='hello' />", "//weblogic:domain"); manager.writeFile(); String xml = fileHandler.readTextFile(TEST_FILE, "UTF-8"); XMLAssert.assertXpathEvaluatesTo("hello", "//weblogic:domain/weblogic:subnode/@property", xml); }
/** * Configure datasource and retrieve the configuration file. * @param fixture Datasource fixture. * @return Configuration file for <code>fixture</code>. * @throws Exception If anything goes wrong. */ protected String configureDataSourceAndRetrieveConfigurationFile(DataSourceFixture fixture) throws Exception { DataSource ds = fixture.buildDataSource(); ((DataSourceSupport) configuration).configure(ds, container); return configuration.getFileHandler().readTextFile( getDataSourceConfigurationFile(fixture), "UTF-8"); }
/** * Test that the file system manager can insert an XML element into a file. * @throws Exception If anything goes wrong */ public void testManagerCanInsertAnElementIntoFile() throws Exception { Document document = builder.newDocument(); Element application = document.createElement("Application"); document.appendChild(application); util.saveXml(document, TEST_FILE); fileHandler.createFile(TEST_FILE); manager.setFile(TEST_FILE); manager.loadFile(); manager.insertElementsUnderXPath("<subnode property='hello' />", "//Application"); manager.writeFile(); String xml = fileHandler.readTextFile(TEST_FILE, "UTF-8"); XMLAssert.assertXpathEvaluatesTo("hello", "//Application/subnode/@property", xml); }
/** * Configure resource and retrieve the configuration file. * @param fixture Resource fixture. * @return Configuration file for <code>fixture</code>. * @throws Exception If anything goes wrong. */ protected String configureResourceAndRetrieveConfigurationFile(ResourceFixture fixture) throws Exception { Resource resource = fixture.buildResource(); ((ResourceSupport) configuration).configure(resource, container); return configuration.getFileHandler().readTextFile(getResourceConfigurationFile(fixture), "UTF-8"); }
temporaryDriver, getFileHandler(), filterChain, "UTF-8"); drivers.append("\n"); drivers.append(getFileHandler().readTextFile(temporaryDriver, "UTF-8")); temporaryDatasource, getFileHandler(), filterChain, "UTF-8"); datasources.append("\n"); datasources.append(getFileHandler().readTextFile(temporaryDatasource, "UTF-8"));
temporaryDriver, getFileHandler(), filterChain, "UTF-8"); drivers.append("\n"); drivers.append(getFileHandler().readTextFile(temporaryDriver, "UTF-8")); temporaryDatasource, getFileHandler(), filterChain, "UTF-8"); datasources.append("\n"); datasources.append(getFileHandler().readTextFile(temporaryDatasource, "UTF-8"));
/** * Configure resource via property and retrieve the configuration file. * @param fixture Resource fixture. * @return Configuration file for <code>fixture</code>. * @throws Exception If anything goes wrong. */ protected String configureResourceViaPropertyAndRetrieveConfigurationFile( ResourceFixture fixture) throws Exception { configuration.setProperty(ResourcePropertySet.RESOURCE, fixture .buildResourcePropertyString()); ((AbstractStandaloneLocalConfigurationWithXMLConfigurationBuilder) configuration) .parsePropertiesForPendingConfiguration(); ((ResourceSupport) configuration).configureResources(container); return configuration.getFileHandler().readTextFile(getResourceConfigurationFile(fixture), "UTF-8"); }
temporaryDriver, getFileHandler(), filterChain, "UTF-8"); drivers.append("\n"); drivers.append(getFileHandler().readTextFile(temporaryDriver, "UTF-8")); temporaryDatasource, getFileHandler(), filterChain, "UTF-8"); datasources.append("\n"); datasources.append(getFileHandler().readTextFile(temporaryDatasource, "UTF-8"));
/** * Configure datasource via property and retrieve the configuration file. * @param fixture Datasource fixture. * @return Configuration file for <code>fixture</code>. * @throws Exception If anything goes wrong. */ protected String configureDataSourceViaPropertyAndRetrieveConfigurationFile( DataSourceFixture fixture) throws Exception { configuration.setProperty(DatasourcePropertySet.DATASOURCE, fixture .buildDataSourcePropertyString()); ((AbstractStandaloneLocalConfigurationWithXMLConfigurationBuilder) configuration) .parsePropertiesForPendingConfiguration(); ((DataSourceSupport) configuration).configureDataSources(container); return configuration.getFileHandler().readTextFile( getDataSourceConfigurationFile(fixture), "UTF-8"); }
temporaryDriver, getFileHandler(), filterChain, "UTF-8"); drivers.append("\n"); drivers.append(getFileHandler().readTextFile(temporaryDriver, "UTF-8")); temporaryDatasource, getFileHandler(), filterChain, "UTF-8"); datasources.append("\n"); datasources.append(getFileHandler().readTextFile(temporaryDatasource, "UTF-8"));