Search in sources :

Example 6 with Content

use of com.cloudbees.jenkins.support.api.Content in project support-core-plugin by jenkinsci.

the class SupportTestUtils method invokeComponentToString.

/**
 * Invoke a component, and return the component contents as a String.
 */
public static String invokeComponentToString(final Component component) {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    component.addContents(new Container() {

        @Override
        public void add(@CheckForNull Content content) {
            try {
                content.writeTo(baos);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    return baos.toString();
}
Also used : Container(com.cloudbees.jenkins.support.api.Container) Content(com.cloudbees.jenkins.support.api.Content) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 7 with Content

use of com.cloudbees.jenkins.support.api.Content in project support-core-plugin by jenkinsci.

the class AgentsConfigFileTest method agentsConfigFile.

@Test
public void agentsConfigFile() throws Exception {
    j.createSlave("node1", "node1", new EnvVars());
    AgentsConfigFile comp = new AgentsConfigFile();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    comp.addContents(new Container() {

        @Override
        public void add(@CheckForNull Content content) {
            try {
                content.writeTo(baos);
            } catch (IOException e) {
                Assert.fail(e.getMessage());
            }
        }
    });
    String fileContent = baos.toString();
    Assert.assertTrue(fileContent.contains("<name>node1</name>"));
}
Also used : Container(com.cloudbees.jenkins.support.api.Container) EnvVars(hudson.EnvVars) Content(com.cloudbees.jenkins.support.api.Content) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Content (com.cloudbees.jenkins.support.api.Content)7 IOException (java.io.IOException)7 Container (com.cloudbees.jenkins.support.api.Container)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintWriter (java.io.PrintWriter)4 BufferedWriter (java.io.BufferedWriter)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 StringContent (com.cloudbees.jenkins.support.api.StringContent)2 Computer (hudson.model.Computer)2 StringWriter (java.io.StringWriter)2 Jenkins (jenkins.model.Jenkins)2 Test (org.junit.Test)2 Component (com.cloudbees.jenkins.support.api.Component)1 SupportProvider (com.cloudbees.jenkins.support.api.SupportProvider)1 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)1 EnvVars (hudson.EnvVars)1 Node (hudson.model.Node)1 SlaveComputer (hudson.slaves.SlaveComputer)1 BufferedOutputStream (java.io.BufferedOutputStream)1