List of usage examples for org.apache.commons.io FileUtils writeLines
public static void writeLines(File file, Collection lines) throws IOException
toString()
value of each item in a collection to the specified File
line by line. From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testUpdateAttributeViaFileTwice_shouldUpdateTwice() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=43", "attribute.x=y")); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=42", "attribute.x=y")); connectorDeployerService.install(connectorFile); connectorDeployerService.update(connectorFile); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=43)"), nullValue()); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=42)"), not(nullValue())); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testUpdateFailure_shouldCreateBackupFile() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=original-file-value")); connectorDeployerService.install(connectorFile); String id = testConnectorId;/*from w w w . j a va 2s. c o m*/ ConnectorDescription desc = serviceManager.getAttributeValues(id); Map<String, String> attributes = ImmutableMap.of("x", "new-persistence-value"); ConnectorDescription newDesc = new ConnectorDescription("mydomain", "aconnector", attributes, desc.getProperties()); serviceManager.update(id, newDesc); FileUtils.writeLines(connectorFile, Arrays.asList("property.foo=bar", "attribute.x=new-value-value")); try { connectorDeployerService.update(connectorFile); fail("update should have failed, because of a merge-conflict"); } catch (MergeException e) { File backupFile = new File(temporaryFolder.getRoot(), TEST_FILE_NAME + "_001"); assertThat("no backup-file was created", backupFile.exists(), is(true)); } }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testUpdateFailure_shouldReplaceWithOldConfigFile() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=original-file-value")); connectorDeployerService.install(connectorFile); String id = testConnectorId;//from w w w. j a va 2 s . c om ConnectorDescription desc = serviceManager.getAttributeValues(id); Map<String, String> attributes = ImmutableMap.of("x", "new-persistence-value"); ConnectorDescription newDesc = new ConnectorDescription("mydomain", "aconnector", attributes, desc.getProperties()); serviceManager.update(id, newDesc); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=new-value-value")); try { connectorDeployerService.update(connectorFile); fail("update should have failed, because of a merge-conflict"); } catch (MergeException e) { List<String> lines = FileUtils.readLines(connectorFile); assertThat(lines, hasItems("property.foo=bar", "attribute.x=original-file-value")); } }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Test public void testUpdateTwice_shouldUpdateCachedVersion() throws Exception { File connectorFile = temporaryFolder.newFile(TEST_FILE_NAME); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar", "attribute.x=original-file-value")); connectorDeployerService.install(connectorFile); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar2", "attribute.x=original-file-value")); connectorDeployerService.update(connectorFile); FileUtils.writeLines(connectorFile, Arrays.asList("domainType=mydomain", "connectorType=aconnector", "property.foo=bar3", "attribute.x=original-file-value")); connectorDeployerService.update(connectorFile); assertThat(bundleContext.getServiceReferences(NullDomain.class.getName(), "(foo=bar3)"), not(nullValue())); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFileTest.java
@Test public void testInitialize_shouldReturnCorrectConfiguration() throws Exception { FileUtils.writeLines(connectorFile, Arrays.asList("domainType=d", "connectorType=c", "property.foo=bar", "attribute.test=42")); ConnectorFile fileObject = new ConnectorFile(connectorFile); assertThat(fileObject.getName().equals("d+c+my"), is(true)); assertThat((String) fileObject.getProperties().get("foo"), is("bar")); assertThat(fileObject.getAttributes().get("test"), is("42")); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFileTest.java
@Test public void testInitialzeWithArray_shouldReturnArrayProperty() throws Exception { FileUtils.writeLines(connectorFile, Arrays.asList("domainType=d", "connectorType=c", "property.foo=bar,42")); ConnectorFile fileObject = new ConnectorFile(connectorFile); String[] values = (String[]) fileObject.getProperties().get("foo"); assertThat(Arrays.asList(values), hasItems("bar", "42")); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFileTest.java
@Test public void testInitialzeWithUntrimedProperties_shouldTrimProperties() throws Exception { FileUtils.writeLines(connectorFile, Arrays.asList("domainType=d ", "connectorType=c ", "property.foo= bar ", "attribute.test= 42 ")); ConnectorFile fileObject = new ConnectorFile(connectorFile); assertThat(fileObject.getName().equals("d+c+my"), is(true)); assertThat((String) fileObject.getProperties().get("foo"), is("bar")); assertThat(fileObject.getAttributes().get("test"), is("42")); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFileTest.java
@Test public void testUpdateAddNewProperty_shouldShowChangedValueInResult() throws Exception { FileUtils.writeLines(connectorFile, Arrays.asList("domainType=d", "connectorType=c", "property.foo=bar,42")); ConnectorFile fileObject = new ConnectorFile(connectorFile); FileUtils.writeLines(connectorFile, Arrays.asList("property.foo=bar,42", "property.test=xxx")); ChangeSet update = fileObject.getChanges(connectorFile); update.getChangedProperties().entriesOnlyOnRight().containsKey("test"); }
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorFileTest.java
@Test public void testChangeProperty_shouldShowChangedValueInResult() throws Exception { FileUtils.writeLines(connectorFile, Arrays.asList("domainType=d", "connectorType=c", "property.foo=bar")); ConnectorFile fileObject = new ConnectorFile(connectorFile); FileUtils.writeLines(connectorFile,/*from w w w . j av a 2s . co m*/ Arrays.asList("domainType=d", "connectorType=c", "property.foo=bar,42")); ChangeSet update = fileObject.getChanges(connectorFile); update.getChangedProperties().entriesOnlyOnRight().containsKey("test"); }
From source file:org.openengsb.core.workflow.drools.deployer.WorkflowDeployerServiceTest.java
@Test public void testInstallImports_shouldImportClasses() throws Exception { File importFile = temporaryFolder.newFile("test1.import"); FileUtils.writeLines(importFile, Arrays.asList("java.util.List", "")); workflowDeployer.install(importFile); verify(ruleManager).addImport("java.util.List"); }