@Test public void testStoreDictionary() throws Exception { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); profile.setRepository(repository); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("action", "save"); params.put("profile", "jbpm"); params.put("dvalue", "this is dictionary"); DictionaryServlet dictionaryServlet = new DictionaryServlet(); dictionaryServlet.setProfile(profile); dictionaryServlet.init(new TestServletConfig(new TestServletContext(repository))); TestHttpServletResponse response = new TestHttpServletResponse(); dictionaryServlet.doPost(new TestHttpServletRequest(params), response); String responseText = new String(response.getContent()); assertNotNull(responseText); assertEquals("saved", responseText); Collection<Asset> dictionary = repository.listAssets("/global", new FilterByExtension("json")); assertNotNull(dictionary); assertEquals(1, dictionary.size()); Asset<String> dictionaryAsset = repository.loadAsset(dictionary.iterator().next().getUniqueId()); assertNotNull(dictionaryAsset); assertEquals("this is dictionary", dictionaryAsset.getAssetContent()); }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter("action"); String uuid = Utils.getUUID(req); String profileName = req.getParameter("profile"); String taskName = req.getParameter("taskname"); String taskFormValue = req.getParameter("tfvalue"); String formType = req.getParameter("formtype"); if (profile == null) { profile = _profileService.findProfile(req, profileName); } Repository repository = profile.getRepository(); Asset<String> processAsset = null; try { processAsset = repository.loadAsset(uuid); if (action != null && action.equals(ACTION_LOAD)) { resp.setContentType("text/html"); resp.setCharacterEncoding("UTF-8"); PrintWriter pw = resp.getWriter(); String taskResponse = getTaskFormFromRepository( formType, taskName, processAsset.getAssetLocation(), repository); pw.write(taskResponse); } else if (action != null && action.equals(ACTION_SAVE)) { resp.setContentType("application/json"); resp.setCharacterEncoding("UTF-8"); PrintWriter pw = resp.getWriter(); try { pw.write( storeTaskFormInRepository( formType, taskName, processAsset.getAssetLocation(), taskFormValue, repository) .toString()); } catch (Exception e) { e.printStackTrace(); pw.write(new JSONObject().toString()); } } } catch (Exception e) { PrintWriter pw = resp.getWriter(); pw.write("error: " + e.getMessage()); } }
@Test public void testUpdateAsset() 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", "updateasset"); params.put("assetid", id); params.put("assetcontent", "testprocess"); params.put("", ""); boolean processAssetExists = repository.assetExists("/defaultPackage/testprocess.bpmn2"); assertTrue(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(id); assertTrue(processAssetExists); Asset<String> processAsset = repository.loadAsset(id); assertEquals("testprocess\n", processAsset.getAssetContent()); }
@Test public void testSaveFormAsset() 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("bpmn2 content").type("bpmn2").name("testprocess").location("/defaultPackage"); String uniqueId = repository.createAsset(builder.getAsset()); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("uuid", uniqueId); params.put("action", "save"); params.put("profile", "jbpm"); params.put("taskname", "evaluate"); params.put("tfvalue", "this is simple task content"); TaskFormsEditorServlet taskFormsEditorServlet = new TaskFormsEditorServlet(); taskFormsEditorServlet.setProfile(profile); taskFormsEditorServlet.init(new TestServletConfig(new TestServletContext(repository))); taskFormsEditorServlet.doPost( new TestHttpServletRequest(params), new TestHttpServletResponse()); Collection<Asset> forms = repository.listAssets("/defaultPackage", new FilterByExtension("flt")); assertNotNull(forms); assertEquals(1, forms.size()); Iterator<Asset> assets = forms.iterator(); Asset asset1 = assets.next(); assertEquals("evaluate-taskform", asset1.getName()); assertEquals("/defaultPackage", asset1.getAssetLocation()); Asset<String> form1 = repository.loadAsset(asset1.getUniqueId()); assertNotNull(form1.getAssetContent()); assertEquals("this is simple task content\n", form1.getAssetContent()); }