@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()); }
@Test public void testGetWithSpaces() throws Exception { RulesRepository repo = RepositorySessionUtil.getRepository(); ModuleItem pkg = repo.createModule("testRestGetSpaces", "", ModuleItem.MODULE_FORMAT); AssetItem ass = pkg.addAsset("some space", ""); ass.updateFormat("drl"); ass.checkin("hey"); RestAPI api = new RestAPI(repo); api.setAssetValidator(new AssetValidator()); String url = "packages/testRestGetSpaces"; Response res = api.get(url); ByteArrayOutputStream out = new ByteArrayOutputStream(); res.writeData(out); assertTrue(new String(out.toByteArray()).indexOf("\\ ") > -1); url = "packages/testRestGetSpaces/some space.drl"; res = api.get(url); assertNotNull(res.lastModified); }
api.setAssetValidator(new AssetValidator()); Response res = api.get("packages/testRestGetVersionHistory/asset1.drl?version=all"); ByteArrayOutputStream out = new ByteArrayOutputStream();
api.setAssetValidator(new AssetValidator());
api.setAssetValidator(new AssetValidator()); Thread.sleep(42); api.put("packages/testRestPut/asset1.drl", Calendar.getInstance(), new ByteArrayInputStream("qaz".getBytes()), "a new comment");
@Test public void testGetMisc() throws Exception { RulesRepository repo = RepositorySessionUtil.getRepository(); RestAPI api = new RestAPI(repo); api.setAssetValidator(new AssetValidator()); api.get(""); api.get("/"); api.get("packages"); api.get("snapshots"); api.get("snapshots/defaultPackage"); }
api.setAssetValidator(new AssetValidator()); Text res = (Text) api.get("packages/testVersionHistoryAndArchived"); System.err.println(res.data);
api.setAssetValidator(new AssetValidator()); api.delete("packages/testRestDelete/asset1.drl");
@Test public void testPost() throws Exception { RulesRepository repo = RepositorySessionUtil.getRepository(); ModuleItem pkg = repo.createModule("testRestPost", "", ModuleItem.MODULE_FORMAT); pkg.updateStringProperty("This is some header", ModuleItem.HEADER_PROPERTY_NAME); repo.save(); RestAPI api = new RestAPI(repo); api.setAssetValidator(new AssetValidator()); ByteArrayInputStream in = new ByteArrayInputStream("abc".getBytes()); api.post("/packages/testRestPost/asset1.drl", in, "a comment"); AssetItem a = pkg.loadAsset("asset1"); assertFalse(a.isBinary()); assertEquals("drl", a.getFormat()); assertEquals("abc", a.getContent()); assertEquals("a comment", a.getCheckinComment()); in = new ByteArrayInputStream("qed".getBytes()); api.post("/packages/testRestPost/asset2.xls", in, "a comment"); a = pkg.loadAsset("asset2"); assertTrue(a.isBinary()); String s = new String(a.getBinaryContentAsBytes()); assertEquals("qed", s); assertEquals("a comment", a.getCheckinComment()); assertEquals("xls", a.getFormat()); List<AssetItem> assets = RulesRepositoryTest.iteratorToList(repo.loadModule("testRestPost").listAssetsByFormat(new String[] {"drl", "xls"})); assertEquals(2, assets.size()); }