Package it.eng.spagobi.sdk.test

Source Code of it.eng.spagobi.sdk.test.DocumentsServiceTest

package it.eng.spagobi.sdk.test;

import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.activation.DataHandler;



import it.eng.spagobi.sdk.documents.bo.SDKDocument;
import it.eng.spagobi.sdk.documents.bo.SDKDocumentParameter;
import it.eng.spagobi.sdk.documents.bo.SDKExecutedDocumentContent;
import it.eng.spagobi.sdk.proxy.DocumentsServiceProxy;
import junit.framework.TestCase;

public class DocumentsServiceTest extends TestCase {

  String user = "biadmin";
  String password = "biadmin";
  DocumentsServiceProxy proxy = null;
  int documentId=5;
  int engineTypeId=10;// report jasper
 
  public DocumentsServiceTest(String name) {
    super(name);
    proxy = new DocumentsServiceProxy(user,password);
    proxy.setEndpoint("http://localhost:8080/SpagoBI/sdk/DocumentsService");
  }

  protected void setUp() throws Exception {
    super.setUp();
  }

  protected void tearDown() throws Exception {
    super.tearDown();
  }
 
  public void testExecuteDocument()throws Exception {


      // opening a session into SpagoBI
      SDKDocument doc=new SDKDocument();
     
      doc.setLabel("ElencoImpiegati");
      doc.setName("ElencoImpiegati");
      doc.setDescription("ElencoImpiegati");
      doc.setId(documentId);
      doc.setState("REL");
      doc.setType("REPORT");
      doc.setEngineId(engineTypeId);
     
     
      SDKDocumentParameter par=new SDKDocumentParameter();
      par.setLabel("Dipartimento");
      par.setUrlName("department");
      Object[] ob={new String("3")};
      par.setValues(ob);

     
      SDKDocumentParameter[] array={par};
           
     
      SDKExecutedDocumentContent cont=  proxy.executeDocument(doc, array, "/spagobi/admin","PDF");

      DataHandler dh=cont.getContent();
      InputStream is=dh.getInputStream();

     
     
      File file=new File("C:/ciaociao.pdf");
     
      try {
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
        int c;
        while((c = is.read()) != -1) {
          out.writeByte(c);
        }
        is.close();
        out.close();
      }
      catch(IOException e) {
        System.err.println("Error Writing/Reading Streams.");
        throw e;
      }

      assertNotNull(file);

  }

}
TOP

Related Classes of it.eng.spagobi.sdk.test.DocumentsServiceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.