@Test public void testGetAssetSourceByPath() throws Exception { Repository repository = new VFSRepository(fileSystem, producer.getIoService(), producer.getActiveFileSystems()); ((VFSRepository) repository).init(); profile.setRepository(repository); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder .content("custom editors content") .type("bpmn2") .name("testprocess") .location("/defaultPackage"); String id = repository.createAsset(builder.getAsset()); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("profile", "jbpm"); params.put("action", "getassetsource"); params.put("assetlocation", "/defaultPackage/testprocess.bpmn2"); params.put("loadoption", "optionbypath"); boolean assetExists = repository.assetExists(id); assertTrue(assetExists); AssetServiceServlet assetServiceServlet = new AssetServiceServlet(); assetServiceServlet.setProfile(profile); assetServiceServlet.init(new TestServletConfig(new TestServletContext(repository))); TestHttpServletResponse response = new TestHttpServletResponse(); assetServiceServlet.doPost(new TestHttpServletRequest(params), response); String jsonResponse = new String(response.getContent()); assertNotNull(jsonResponse); assertEquals(jsonResponse, "custom editors content\n"); }
@Test public void testListDirectories() throws Exception { Repository repository = new VFSRepository(fileSystem, producer.getIoService(), producer.getActiveFileSystems()); ((VFSRepository) repository).init(); profile.setRepository(repository); repository.createDirectory("/defaultPackage"); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("profile", "jbpm"); params.put("action", "listdirs"); params.put("assetlocation", "/"); params.put("", ""); AssetServiceServlet assetServiceServlet = new AssetServiceServlet(); assetServiceServlet.setProfile(profile); assetServiceServlet.init(new TestServletConfig(new TestServletContext(repository))); TestHttpServletResponse response = new TestHttpServletResponse(); assetServiceServlet.doPost(new TestHttpServletRequest(params), response); String jsonResponse = new String(response.getContent()); assertNotNull(jsonResponse); System.out.println(jsonResponse); assertTrue(jsonResponse.indexOf("\"answer\":[{\"name\":\"defaultPackage\"}]") != -1); }
@Test public void testCreateAsset() throws Exception { Repository repository = new VFSRepository(fileSystem, producer.getIoService(), producer.getActiveFileSystems()); ((VFSRepository) repository).init(); profile.setRepository(repository); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("profile", "jbpm"); params.put("action", "createasset"); params.put("assettype", "bpmn2"); params.put("assetname", "testprocess"); params.put("assetlocation", "/defaultPackage"); params.put("", ""); boolean processAssetExists = repository.assetExists("/defaultPackage/testprocess.bpmn2"); assertFalse(processAssetExists); AssetServiceServlet assetServiceServlet = new AssetServiceServlet(); assetServiceServlet.setProfile(profile); assetServiceServlet.init(new TestServletConfig(new TestServletContext(repository))); TestHttpServletResponse response = new TestHttpServletResponse(); assetServiceServlet.doPost(new TestHttpServletRequest(params), response); String jsonResponse = new String(response.getContent()); assertNotNull(jsonResponse); processAssetExists = repository.assetExists("/defaultPackage/testprocess.bpmn2"); assertTrue(processAssetExists); }
@Test public void testDirectoryDoesNotExist() throws Exception { Repository repository = new VFSRepository(fileSystem, producer.getIoService(), producer.getActiveFileSystems()); ((VFSRepository) repository).init(); profile.setRepository(repository); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("profile", "jbpm"); params.put("action", "existsdir"); params.put("assetlocation", "/defaultPackage"); params.put("", ""); boolean directoryExits = repository.directoryExists("/defaultPackage"); assertFalse(directoryExits); AssetServiceServlet assetServiceServlet = new AssetServiceServlet(); assetServiceServlet.setProfile(profile); assetServiceServlet.init(new TestServletConfig(new TestServletContext(repository))); TestHttpServletResponse response = new TestHttpServletResponse(); assetServiceServlet.doPost(new TestHttpServletRequest(params), response); String jsonResponse = new String(response.getContent()); assertNotNull(jsonResponse); assertTrue(jsonResponse.indexOf("\"answer\":\"false\"") != -1); }
@Test public void testGetAssetInfoById() throws Exception { Repository repository = new VFSRepository(fileSystem, producer.getIoService(), producer.getActiveFileSystems()); ((VFSRepository) repository).init(); profile.setRepository(repository); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder .content("custom editors content") .type("bpmn2") .name("testprocess") .location("/defaultPackage"); String id = repository.createAsset(builder.getAsset()); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("profile", "jbpm"); params.put("action", "getassetinfo"); params.put("assetid", id); params.put("loadoption", "optionbyid"); boolean assetExists = repository.assetExists(id); assertTrue(assetExists); AssetServiceServlet assetServiceServlet = new AssetServiceServlet(); assetServiceServlet.setProfile(profile); assetServiceServlet.init(new TestServletConfig(new TestServletContext(repository))); TestHttpServletResponse response = new TestHttpServletResponse(); assetServiceServlet.doPost(new TestHttpServletRequest(params), response); String jsonResponse = new String(response.getContent()); assertNotNull(jsonResponse); assertTrue( jsonResponse.indexOf( "\"location\":\"/defaultPackage\",\"description\":\"\",\"name\":\"testprocess\",\"owner\":\"\",\"type\":\"bpmn2\",\"fullname\":\"testprocess.bpmn2\"") != -1); }