@Test public void testLoadDictionary() throws Exception { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); profile.setRepository(repository); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder .content("test dictionary content") .type("json") .name("processdictionary") .location("/global"); repository.createAsset(builder.getAsset()); // setup parameters Map<String, String> params = new HashMap<String, String>(); params.put("action", "load"); params.put("profile", "jbpm"); 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 dictionaryContent = new String(response.getContent()); assertNotNull(dictionaryContent); assertEquals("test dictionary content", dictionaryContent); }
@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()); }