Java Code Examples for org.apache.tools.ant.filters.StringInputStream

The following examples show how to use org.apache.tools.ant.filters.StringInputStream. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void checkCustomSection() throws Exception {
    String yaml = "agent: any\n" +
            "\n" +
            "stages:\n" +
            "  - name: stage1\n" +
            "    agent: any\n" +
            "    steps:\n" +
            "      - sh: \"scripts/hello.sh\"\n" +
            "\n" +
            "configuration:\n" +
            "  sections:\n" +
            "    - name: foo\n" +
            "      data:\n" +
            "        field1: hello\n" +
            "        field2: world\n" +
            "\n";

    StringInputStream yamlInputStream = new StringInputStream(yaml);
    String generatedPipeline = new YamlToPipeline().generatePipeline(yamlInputStream, null,
            j.createTaskListener());
    Assert.assertThat(generatedPipeline, CoreMatchers.containsString("foo('hello','world')"));
}
 
Example 2
Source Project: configuration-as-code-plugin   Source File: MailExtTest.java    License: MIT License 6 votes vote down vote up
@Test
@Issue("SECURITY-1446")
public void shouldProperlyRoundTripTokenMacro() throws Exception {
    final String defaultBody = "${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}:\n" +
            "Check console output at $BUILD_URL to view the results.";
    // This string contains extra escaping
    final String defaultSubject = "^^^${PROJECT_NAME} - Build # ^^${BUILD_NUMBER} - ^${BUILD_STATUS}!";

    ExtendedEmailPublisherDescriptor descriptor = ExtendedEmailPublisher.descriptor();
    descriptor.setDefaultBody(defaultBody);
    descriptor.setDefaultSubject(defaultSubject);

    // Verify that the variables get exported properly
    String exportedConfig = j.exportToString(false);
    assertThat("PROJECT_NAME should be escaped", exportedConfig, containsString("^${PROJECT_NAME}"));
    assertThat("BUILD_NUMBER should be escaped", exportedConfig, containsString("^${BUILD_NUMBER}"));
    assertThat("BUILD_STATUS should be escaped", exportedConfig, containsString("^${BUILD_STATUS}"));

    // Reimport the configuration
    ConfigurationAsCode.get().configureWith(YamlSource.of(new StringInputStream(exportedConfig)));
    assertLogContains(logging, "defaultBody =");
    assertLogContains(logging, "defaultSubject =");
    assertThat(ExtendedEmailPublisher.descriptor().getDefaultBody(), equalTo(defaultBody));
    assertThat(ExtendedEmailPublisher.descriptor().getDefaultSubject(), equalTo(defaultSubject));
}
 
Example 3
@Test
public void testRunCommandWithLogging_badProcessOutput()
    throws IOException, InterruptedException {
  List<String> command = Arrays.asList("someCommand", "someOption");

  InputStream processOutput = new StringInputStream("");
  processOutput.close();
  when(processMock.getInputStream()).thenReturn(processOutput);

  new CommandExecutor()
      .setLogger(loggerMock)
      .setProcessBuilderFactory(processBuilderFactoryMock)
      .run(command);

  loggerInOrder.verify(loggerMock).warn("IO Exception reading process output");
}
 
Example 4
@Test
public void readXML() throws Exception {
    SourceMatcher sm = new SourceMatcher(fileName);

    String xml = writeXMLAndGetStringOutput(sm, false);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "\n<FindBugsFilter>"
            + "\n<Match>"
            + "\n" + xml
            + "\n</Match>"
            + "\n</FindBugsFilter>\n";

    Filter filter = new Filter(new StringInputStream(xml));

    assertFalse(filter.match(bug));

    bug.addClass("bla", fileName);
    assertTrue(filter.match(bug));
}
 
Example 5
Source Project: onetwo   Source File: SmbFileTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteFile(){
	String path = "smb://administrator:[email protected]/install/ftp/email-attachements";
	String fn = NiceDate.New().formatAsDate()+"test.txt";
	String content = "test中文";
	InputStream in = new StringInputStream(content);
	FileUtils.writeInputStreamTo(in, path, fn);
	
	in = FileUtils.newSmbInputStream("administrator", "Admin123456", "192.168.104.217/install/ftp/email-attachements/"+fn);
	List<String> list = FileUtils.readAsList(in);
	System.out.println("list0: " + list.get(0));
	Assert.assertEquals(content, list.get(0));
	
	String smbPath = path+"\\"+fn;
	String data = FileUtils.readAsString(smbPath);
	Assert.assertEquals(content, data);
	
	String srcDir = "D:/fileutil-test/smb";
	File localFile = SmbFileUtils.copyFileToDir(SmbFileUtils.newSmbFile(smbPath), srcDir);
	data = FileUtils.readAsString(localFile);
	Assert.assertEquals(content, data);
}
 
Example 6
Source Project: gateway-android-sdk   Source File: GatewayTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInputStreamToStringWorksAsExpected() {
    String expectedResult = "here is some string data";
    InputStream testInputStream = new StringInputStream(expectedResult);

    try {
        String result = gateway.inputStreamToString(testInputStream);
        assertEquals(expectedResult, result);
    } catch (IOException e) {
        fail(e.getMessage());
    }
}
 
Example 7
@Test
public void testLoadJsonReader() {
    JsonReader reader = JsonReader.of(buffer(source(new StringInputStream(JSON))));
    LottieResult<LottieComposition> result = LottieCompositionFactory.fromJsonReaderSync(reader, "json");
    assertNull(result.getException());
    assertNotNull(result.getValue());
}
 
Example 8
@Test
public void testLoadInvalidJsonReader() {
    JsonReader reader = JsonReader.of(buffer(source(new StringInputStream(NOT_JSON))));
    LottieResult<LottieComposition> result = LottieCompositionFactory.fromJsonReaderSync(reader, "json");
    assertNotNull(result.getException());
    assertNull(result.getValue());
}
 
Example 9
Source Project: Kylin   Source File: DeployUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void overrideFactTableData(String factTableContent, String factTableName) throws IOException {
    // Write to resource store
    ResourceStore store = ResourceStore.getStore(config());

    InputStream in = new StringInputStream(factTableContent);
    String factTablePath = "/data/" + factTableName + ".csv";
    store.deleteResource(factTablePath);
    store.putResource(factTablePath, in, System.currentTimeMillis());
    in.close();
}
 
Example 10
private InputStream extractHtml(HttpServletRequest request) throws IOException {
	AjaxPageRenderer crowler = new AjaxPageRenderer(serverUrl);
	String pageData = crowler.crawlPage(AjaxPageFilter.rewriteQueryString(request.getQueryString()));
	String cacheFileName = this.getCacheFileName(request.getParameter(QUERY_PARAM_ESCAPED_FRAGMENT));
	if (cacheFileName != null) {
		File cacheFile = new File(cacheFileName);
		cacheFile.getParentFile().mkdirs();
		PrintWriter out = new PrintWriter(cacheFile);
		out.print(pageData);
		out.close();

		return new FileInputStream(cacheFile);
	}
	return new StringInputStream(pageData);
}
 
Example 11
Source Project: Connect-SDK-Android-Core   Source File: TestUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static URL getMockUrl(final String content, String applicationUrl) throws IOException {
    final URLConnection mockConnection = Mockito.mock(URLConnection.class);
    Mockito.when(mockConnection.getInputStream()).thenReturn(new StringInputStream(content));
    Mockito.when(mockConnection.getHeaderField("Application-URL")).thenReturn(applicationUrl);

    final URLStreamHandler handler = new URLStreamHandler() {

        @Override
        protected URLConnection openConnection(final URL arg0)
                throws IOException {
            return mockConnection;
        }
    };
    return new URL("http", "hostname", 80, "", handler);
}
 
Example 12
@Test
public void yamlToPipelineTest() throws ConversionException {
    String yaml = "agent: any\n" +
            "\n" +
            "stages:\n" +
            "  - name: stage1\n" +
            "    agent: any\n" +
            "    steps:\n" +
            "      - sh: \"scripts/hello.sh\"\n" +
            "      - sh:\n" +
            "          script: \"scripts/hello.sh\"" +
            "\n" +
            "configuration:\n" +
            "  archiveArtifacts:\n" +
            "      - Jenkinsfile.yaml\n" +
            "      - scripts/hello.sh\n" +
            "\n";

    String pipelineScriptLinuxExpected = "pipeline {\n" +
            "\tagent any\n" +
            "\tstages {\n" +
            "\t\tstage('stage1') {\n" +
            "\t\t\tsteps {\n" +
            "\t\t\t\tsh 'scripts/hello.sh'\n" +
            "\t\t\t\tsh 'scripts/hello.sh'\n" +
            "\t\t\t}\n" +
            "\t\t}\n" +
            "\t\tstage('Archive artifacts') {\n" +
            "\t\t\tsteps {\n" +
            "\t\t\t\tarchiveArtifacts artifacts: 'Jenkinsfile.yaml'\n" +
            "\t\t\t\tarchiveArtifacts artifacts: 'scripts/hello.sh'\n" +
            "\t\t\t}\n" +
            "\t\t}\n" +
            "\t}\n" +
            "}\n";

    StringInputStream yamlInputStream = new StringInputStream(yaml);
    String pipelineScriptActual = new YamlToPipeline().generatePipeline(yamlInputStream,
            new GitConfig(), jenkinsRule.createTaskListener());

    assertEquals(pipelineScriptLinuxExpected, pipelineScriptActual);
}
 
Example 13
private void setProcessMockOutput(List<String> expectedOutput) {
  when(processMock.getInputStream())
      .thenReturn(new StringInputStream(String.join("\n", expectedOutput)));
}