Package org.drools.util.codec

Examples of org.drools.util.codec.Base64


        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

    @Test @RunAsClient
    public void testPackageNotExists(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL(baseURL, "rest/packages/restNotExistingPackage");
        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(404, connection.getResponseCode());
    }
View Full Code Here

    @Test @RunAsClient
    public void testGetPackageSource(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL(baseURL, "rest/packages/restPackage1/source");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", MediaType.WILDCARD);
        connection.connect();

        assertEquals (200, connection.getResponseCode());
View Full Code Here

    public void testGetPackageBinary (@ArquillianResource URL baseURL) throws Exception {
        // restPackageCompilationFailure build fails due to: ClassNotFoundException
        URL url = new URL(baseURL, "rest/packages/restPackageCompilationFailure/binary");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", MediaType.APPLICATION_OCTET_STREAM);
        connection.connect();

        assertEquals(500, connection.getResponseCode());
       
        //restPackage2 should build ok.
        URL url2 = new URL(baseURL, "rest/packages/restPackage2/binary");
        HttpURLConnection connection2 = (HttpURLConnection) url2.openConnection();
        connection2.setRequestProperty("Authorization",
                "Basic " + new Base64().encodeToString(( "admin:admin".getBytes() )));
        connection2.setRequestMethod("GET");
        connection2.setRequestProperty("Accept", MediaType.APPLICATION_OCTET_STREAM);
        connection2.connect();

        assertEquals(200, connection2.getResponseCode());
View Full Code Here

    public void testGetAssetsByCategoryAsJson(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL( baseURL,
                           "rest/categories/Home%20Mortgage/assets" );
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty( "Authorization",
                                       "Basic " + new Base64().encodeToString( ("admin:admin".getBytes()) ) );
        connection.setRequestMethod( "GET" );
        connection.setRequestProperty( "Accept",
                                       MediaType.APPLICATION_JSON );
        connection.connect();
        assertEquals( 200,
View Full Code Here

    public void testGetAssetsByCategoryAsJaxb(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL( baseURL,
                           "rest/categories/Home%20Mortgage/assets" );
        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,
View Full Code Here

    public void testGetAssetsByCategoryAndPageAsAtom(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL( baseURL,
                           "rest/categories/Home%20Mortgage/assets//page/0" );
        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,
View Full Code Here

    public void testGetAssetsByCategoryAndPageAsJson(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL( baseURL,
                           "rest/categories/Home%20Mortgage/assets//page/0" );
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty( "Authorization",
                                       "Basic " + new Base64().encodeToString( ("admin:admin".getBytes()) ) );
        connection.setRequestMethod( "GET" );
        connection.setRequestProperty( "Accept",
                                       MediaType.APPLICATION_JSON );
        connection.connect();
        assertEquals( 200,
View Full Code Here

    public void testGetAssetsByCategoryAndPageAsJaxb(@ArquillianResource URL baseURL) throws Exception {
        URL url = new URL( baseURL,
                           "rest/categories/Home%20Mortgage/assets//page/0" );
        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,
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.