Package org.drools.guvnor.server.files

Examples of org.drools.guvnor.server.files.RestAPI


    }

    @Test
    public void testPostNewPackage() throws Exception {
        RulesRepository repo = RepositorySessionUtil.getRepository();
        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        api.post("/packages/testPostNewPackage/.package", new ByteArrayInputStream("qaz".getBytes()), "This is a new package");
        ModuleItem pkg = repo.loadModule("testPostNewPackage");
        assertEquals("qaz", pkg.getStringProperty(ModuleItem.HEADER_PROPERTY_NAME));

        assertEquals("This is a new package", pkg.getCheckinComment());
    }
View Full Code Here


        ByteArrayInputStream in = new ByteArrayInputStream("abc".getBytes());
        asset2.updateBinaryContentAttachment(in);
        asset2.updateFormat("xls");
        asset2.checkin("");

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        Thread.sleep(42);
        api.put("packages/testRestPut/asset1.drl", Calendar.getInstance(), new ByteArrayInputStream("qaz".getBytes()), "a new comment");

        AssetItem asset1_ = pkg.loadAsset("asset1");
        assertEquals("qaz", asset1_.getContent());
        assertEquals("a new comment", asset1_.getCheckinComment());
        assertTrue(asset1_.getLastModified().after(cd));

        api.put("packages/testRestPut/asset2.xls", Calendar.getInstance(), new ByteArrayInputStream("def".getBytes()), "a new comment");
        AssetItem asset2_ = pkg.loadAsset("asset2");
        assertEquals("def", new String(asset2_.getBinaryContentAsBytes()));
        assertEquals("a new comment", asset2_.getCheckinComment());
        assertTrue(asset2_.getLastModified().after(cd));

        //now check updating the package header
        api.put("packages/testRestPut/.package", Calendar.getInstance(), new ByteArrayInputStream("whee".getBytes()), "hey");
        pkg = repo.loadModule("testRestPut");
        assertEquals("whee", pkg.getStringProperty(ModuleItem.HEADER_PROPERTY_NAME));

        try {
            api.put("packages/testRestPut/asset1.drl", cd, new ByteArrayInputStream("qaz".getBytes()), "a new comment");
            fail("should not be able to do this as it is stale timestamp.");
        } catch (Exception e) {
            assertNotNull(e.getMessage());
        }

        try {
            api.put("packages/testRestPut/.package", cd, new ByteArrayInputStream("whee".getBytes()), "hey");
            fail("should not be able to do this as it is stale timestamp.");
        } catch (Exception e) {
            assertNotNull(e.getMessage());
        }
View Full Code Here

        AssetItem asset1 = pkg.addAsset("asset1", "");
        asset1.updateContent("this is content");
        asset1.updateFormat("drl");
        asset1.checkin("");

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        api.delete("packages/testRestDelete/asset1.drl");

        List l = RulesRepositoryTest.iteratorToList(pkg.listAssetsByFormat(new String[] {"drl"}));
        assertEquals(0, l.size());

        l = RulesRepositoryTest.iteratorToList(pkg.listArchivedAssets());
        assertEquals(1, l.size());


        //now test it back from the dead
        api.post("packages/testRestDelete/asset1.drl", new ByteArrayInputStream("123".getBytes()), "new comment");
        AssetItem ass = pkg.loadAsset("asset1");
        assertEquals("123", ass.getContent());
        assertEquals("new comment", ass.getCheckinComment());
        assertFalse(ass.isArchived());
        l = RulesRepositoryTest.iteratorToList(pkg.listAssetsByFormat(new String[] {"drl"}));
        assertEquals(1, l.size());

        try {
            api.post("packages/testRestDelete/asset1.drl", new ByteArrayInputStream("123".getBytes())"new comment");
            fail("this should be rejected as its not archived.");
        } catch (RulesRepositoryException e) {
            assertNotNull(e.getMessage());
        }
View Full Code Here

    }

    @Test
    public void testSplit() throws Exception {
        RestAPI a = new RestAPI(null);
        String[] x = a.split("packages/foo/bar");
        assertEquals(3, x.length);
        assertEquals("packages", x[0]);
        assertEquals("foo", x[1]);
        assertEquals("bar", x[2]);

        x = a.split("/packages/foo/bar");
        assertEquals(3, x.length);
        assertEquals("packages", x[0]);
        assertEquals("foo", x[1]);
        assertEquals("bar", x[2]);

        String p = URLEncoder.encode("some package", "UTF-8");
        String asset = URLEncoder.encode("some asset", "UTF-8");
        x = a.split("packages/" + p + "/" + asset);
        assertEquals("packages", x[0]);
        assertEquals("some package", x[1]);
        assertEquals("some asset", x[2]);


        x = a.split("http://localhost:8080/guvnor-webapp/org.dooby.doo.X.html/api/packages/foo/bar.drl");
        assertEquals(3, x.length);
        assertEquals("packages", x[0]);
        assertEquals("foo", x[1]);
        assertEquals("bar.drl", x[2]);
View Full Code Here

TOP

Related Classes of org.drools.guvnor.server.files.RestAPI

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.