Package org.drools.util.codec

Examples of org.drools.util.codec.Base64


    @Test @RunAsClient
    public void testGetPackageForXML(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL(baseURL, "rest/packages/restPackage1");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
        connection.connect();
        assertEquals (200, connection.getResponseCode());
        assertEquals(MediaType.APPLICATION_XML, connection.getContentType());
View Full Code Here


    @Test @RunAsClient
    public void testGetPackageForAtom(@ArquillianResource URL baseURL) throws MalformedURLException, IOException {
        URL url = new URL(baseURL, "rest/packages/restPackage1");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        connection.connect();
        assertEquals (200, connection.getResponseCode());
        assertEquals(MediaType.APPLICATION_ATOM_XML, connection.getContentType());
View Full Code Here

        marshaller.marshal(p, sw);
        String xml = sw.toString();
        URL url = new URL(baseURL, "rest/packages");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_XML);
        connection.setRequestProperty("Content-Length", Integer.toString(xml.getBytes().length));
        connection.setUseCaches (false);
View Full Code Here

    @Test @RunAsClient
    public void testCreatePackageFromDRLAsEntry(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL(baseURL, "rest/packages");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
        connection.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        connection.setDoOutput(true);
View Full Code Here

    @Test @RunAsClient
    public void testCreatePackageFromDRLAsJson(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL(baseURL, "rest/packages");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
        connection.setRequestProperty("Accept", MediaType.APPLICATION_JSON);
        connection.setDoOutput(true);
View Full Code Here

    @Test @RunAsClient
    public void testCreatePackageFromDRLAsJaxB(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL(baseURL, "rest/packages");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
        connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
        connection.setDoOutput(true);
View Full Code Here

        conn.disconnect(); */
        URL url1 = new URL(baseURL, "rest/packages/testCreatePackageFromAtom");
        HttpURLConnection conn1 = (HttpURLConnection)url1.openConnection();
        conn1.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn1.setRequestMethod("GET");
        conn1.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn1.connect();
        //System.out.println(GetContent(conn));
        assertEquals (200, conn1.getResponseCode());
        assertEquals(MediaType.APPLICATION_ATOM_XML, conn1.getContentType());
       
        InputStream in = conn1.getInputStream();
        assertNotNull(in);
    doc = abdera.getParser().parse(in);
    entry = doc.getRoot();
    assertEquals(baseURL.getPath() + "rest/packages/testCreatePackageFromAtom", entry.getBaseUri().getPath());
    assertEquals("testCreatePackageFromAtom", entry.getTitle());
    assertNotNull(entry.getPublished());
      assertNotNull(entry.getAuthor().getName());    
    assertEquals("updated desc for testCreatePackageFromAtom", entry.getSummary());
        metadataExtension  = entry.getExtension(Translator.METADATA);
        checkinCommentExtension = metadataExtension.getExtension(Translator.CHECKIN_COMMENT)
        assertEquals("checkin comment:updated desc for testCreatePackageFromAtom", checkinCommentExtension.getSimpleExtension(Translator.VALUE));
       
    //Roll back changes.
    resp = client.delete(new URL(baseURL, "rest/packages/testCreatePackageFromAtom").toExternalForm());
    assertEquals(ResponseType.SUCCESS, resp.getType());

    //Verify the package is indeed deleted
    URL url2 = new URL(baseURL, "rest/packages/testCreatePackageFromAtom");
    HttpURLConnection conn2 = (HttpURLConnection)url2.openConnection();
        conn2.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn2.setRequestMethod("GET");
        conn2.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn2.connect();
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        assertEquals (404, conn2.getResponseCode());
View Full Code Here

       
        //Verify new package is available after renaming
        URL url1 = new URL(baseURL, "rest/packages/testRenamePackageFromAtomNew");
        HttpURLConnection conn1 = (HttpURLConnection)url1.openConnection();
        conn1.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn1.setRequestMethod("GET");
        conn1.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn1.connect();
        //System.out.println(GetContent(conn));
        assertEquals (200, conn1.getResponseCode());
        assertEquals(MediaType.APPLICATION_ATOM_XML, conn1.getContentType());
       
        InputStream in = conn1.getInputStream();
        assertNotNull(in);
        doc = abdera.getParser().parse(in);
        entry = doc.getRoot();
        assertEquals(baseURL.getPath() + "rest/packages/testRenamePackageFromAtomNew", entry.getBaseUri().getPath());
        assertEquals("testRenamePackageFromAtomNew", entry.getTitle());
        assertTrue(entry.getPublished() != null);
        assertEquals("renamed package testRenamePackageFromAtom", entry.getSummary());
       
       
        //Verify the old package does not exist after renaming
        URL url2 = new URL(baseURL, "rest/packages/testRenamePackageFromAtom");
        HttpURLConnection conn2 = (HttpURLConnection)url2.openConnection();
        conn2.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn2.setRequestMethod("GET");
        conn2.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn2.connect();
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        assertEquals (404, conn2.getResponseCode());
       
       
        //Roll back changes.
        resp = client.delete(new URL(baseURL, "rest/packages/testRenamePackageFromAtomNew").toExternalForm());
        assertEquals(ResponseType.SUCCESS, resp.getType());

       
        //Verify the package is indeed deleted
        URL url3 = new URL(baseURL, "rest/packages/testRenamePackageFromAtomNew");
        HttpURLConnection conn3 = (HttpURLConnection)url3.openConnection();
        conn3.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn3.setRequestMethod("GET");
        conn3.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn3.connect();
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        assertEquals (404, conn3.getResponseCode());
View Full Code Here

        marshaller.marshal(p, sw);
        String xml = sw.toString();
        URL url = new URL(baseURL, "rest/packages");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_XML);
        connection.setRequestProperty("Content-Length", Integer.toString(xml.getBytes().length));
        connection.setUseCaches (false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
       
        DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
        wr.writeBytes (xml);
        wr.flush ();
        wr.close ();

        assertEquals (200, connection.getResponseCode());
        assertEquals(MediaType.APPLICATION_XML, connection.getContentType());
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        Package result = unmarshalPackageXML(connection.getInputStream());
        assertEquals("testRenamePackageFromXML", result.getTitle());
        assertEquals("desc for testRenamePackageFromXML", result.getDescription());
        assertNotNull(result.getPublished());
        assertEquals(new URL(baseURL, "rest/packages/testRenamePackageFromXML/source").toExternalForm(), result.getSourceLink().toString());
        assertEquals(new URL(baseURL, "rest/packages/testRenamePackageFromXML/binary").toExternalForm(), result.getBinaryLink().toString());
        PackageMetadata pm = result.getMetadata();
        assertFalse(pm.isArchived());
        assertNotNull(pm.getCreated());
        assertNotNull(pm.getUuid());
        
       
        //Test rename package     
        p.setDescription("renamed package testRenamePackageFromXML");
        p.setTitle("testRenamePackageFromXMLNew");
        JAXBContext context2 = JAXBContext.newInstance(p.getClass());
        Marshaller marshaller2 = context2.createMarshaller();
        StringWriter sw2 = new StringWriter();
        marshaller2.marshal(p, sw2);
        String xml2 = sw2.toString();
        URL url2 = new URL(baseURL, "rest/packages/testRenamePackageFromXML");
        HttpURLConnection connection2 = (HttpURLConnection)url2.openConnection();
        connection2.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection2.setRequestMethod("PUT");
        connection2.setRequestProperty("Content-Type", MediaType.APPLICATION_XML);
        connection2.setRequestProperty("Content-Length", Integer.toString(xml2.getBytes().length));
        connection2.setUseCaches (false);
        //connection2.setDoInput(true);
        connection2.setDoOutput(true);

        OutputStreamWriter out = new OutputStreamWriter(connection2.getOutputStream());
        out.write(xml2);
        out.close();
        connection2.getInputStream();
        //assertEquals (200, connection2.getResponseCode());
       
        //Verify the new package is available after renaming
        URL url3 = new URL(baseURL, "rest/packages/testRenamePackageFromXMLNew");
        HttpURLConnection conn3 = (HttpURLConnection)url3.openConnection();
        conn3.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn3.setRequestMethod("GET");
        conn3.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn3.connect();
        //System.out.println(GetContent(conn));
        assertEquals (200, conn3.getResponseCode());
        assertEquals(MediaType.APPLICATION_ATOM_XML, conn3.getContentType());
       
        InputStream in = conn3.getInputStream();
        assertNotNull(in);
        Document<Entry> doc = abdera.getParser().parse(in);
        Entry entry = doc.getRoot();
        assertEquals(baseURL.getPath() + "rest/packages/testRenamePackageFromXMLNew", entry.getBaseUri().getPath());
        assertEquals("testRenamePackageFromXMLNew", entry.getTitle());
        assertTrue(entry.getPublished() != null);
        assertEquals("renamed package testRenamePackageFromXML", entry.getSummary());
       
       
        //Verify the old package does not exist after renaming
        URL url4 = new URL(baseURL, "rest/packages/testRenamePackageFromXML");
        HttpURLConnection conn4 = (HttpURLConnection)url4.openConnection();
        conn4.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn4.setRequestMethod("GET");
        conn4.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn4.connect();
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        assertEquals (404, conn4.getResponseCode());
       
       
        //Roll back changes.
        Abdera abdera = new Abdera();
        AbderaClient client = new AbderaClient(abdera);    
        client.addCredentials(baseURL.toExternalForm(), null, null,
                new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));
        ClientResponse resp = client.delete(new URL(baseURL, "rest/packages/testRenamePackageFromXMLNew").toExternalForm());
        assertEquals(ResponseType.SUCCESS, resp.getType());

       
        //Verify the package is indeed deleted
        URL url5 = new URL(baseURL, "rest/packages/testRenamePackageFromXMLNew");
        HttpURLConnection conn5 = (HttpURLConnection)url5.openConnection();
        conn5.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        conn5.setRequestMethod("GET");
        conn5.setRequestProperty("Accept", MediaType.APPLICATION_ATOM_XML);
        conn5.connect();
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        assertEquals (404, conn5.getResponseCode());
View Full Code Here

    @Test @RunAsClient
    public void testCreatePackageSnapshot(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL(baseURL, "rest/packages/restPackage1/snapshot/testsnapshot");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("POST");
        connection.setUseCaches (false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
View Full Code Here

TOP

Related Classes of org.drools.util.codec.Base64

Copyright © 2018 www.massapicom. 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.