@Ignore // git based vfs does not yet support move @Test public void testMoveDirectory() throws NoSuchFileException { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); Directory sourceDir = repository.createDirectory("/source"); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder.content("simple content").type("bpmn2").name("process").location("/source"); String id = repository.createAsset(builder.getAsset()); Collection<Asset> foundAsset = repository.listAssets("/source", new FilterByExtension("bpmn2")); assertNotNull(foundAsset); assertEquals(1, foundAsset.size()); boolean assetExistsBeforeDelete = repository.assetExists(id); assertTrue(assetExistsBeforeDelete); boolean copied = repository.moveDirectory("/source", "/target", null); assertTrue(copied); foundAsset = repository.listAssets("/target/source", new FilterByExtension("bpmn2")); assertNotNull(foundAsset); assertEquals(1, foundAsset.size()); boolean assetExists = repository.assetExists("/target/source/process.bpmn2"); assertTrue(assetExists); boolean movedDirectoryExists = repository.directoryExists("/source"); assertFalse(movedDirectoryExists); }
@Test public void testUpdateAsset() throws NoSuchFileException { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder.content("simple content").type("bpmn2").name("process").location("/"); String id = repository.createAsset(builder.getAsset()); Collection<Asset> foundAsset = repository.listAssets("/", new FilterByExtension("bpmn2")); assertNotNull(foundAsset); assertEquals(1, foundAsset.size()); builder.content("updated content").uniqueId(id); id = repository.updateAsset(builder.getAsset(), "", ""); foundAsset = repository.listAssetsRecursively("/", new FilterByFileName("process.bpmn2")); assertNotNull(foundAsset); assertEquals(1, foundAsset.size()); String content = ((Asset<String>) repository.loadAsset(id)).getAssetContent(); assertNotNull(content); assertEquals("updated content", content); }
@Test public void testDirectoryExists() { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); boolean rootFolderExists = repository.directoryExists("/test"); assertFalse(rootFolderExists); Directory directoryId = repository.createDirectory("/test"); assertNotNull(directoryId); assertEquals("test", directoryId.getName()); assertEquals("/", directoryId.getLocation()); assertNotNull(directoryId.getUniqueId()); rootFolderExists = repository.directoryExists("/test"); assertTrue(rootFolderExists); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Byte); builder.content("simple content".getBytes()).type("png").name("test").location("/test"); String id = repository.createAsset(builder.getAsset()); assertNotNull(id); boolean assetPathShouldNotExists = repository.directoryExists("/test/test.png"); assertFalse(assetPathShouldNotExists); }
@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 testListAssetsRecursively() { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder.content("simple content").type("bpmn2").name("process").location("/1/2/3/4/5/6"); String id = repository.createAsset(builder.getAsset()); Collection<Asset> foundAsset = repository.listAssetsRecursively("/", new FilterByExtension("bpmn2")); assertNotNull(foundAsset); assertEquals(4, foundAsset.size()); }
@Test public void testAssetExists() throws NoSuchFileException { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); Collection<Asset> assets = repository.listAssets("/"); assertNotNull(assets); for (Asset aset : assets) { System.out.println(aset.getAssetLocation() + " " + aset.getFullName()); } assertEquals(0, assets.size()); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder.content("simple content").type("txt").name("test").location("/"); String id = repository.createAsset(builder.getAsset()); assertNotNull(id); boolean assetExists = repository.assetExists(id); assertTrue(assetExists); }
@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); }
@Test public void testDeleteAssetFromPath() throws NoSuchFileException { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder.content("simple content").type("bpmn2").name("process").location("/"); String id = repository.createAsset(builder.getAsset()); Collection<Asset> foundAsset = repository.listAssets("/", new FilterByExtension("bpmn2")); assertNotNull(foundAsset); assertEquals(1, foundAsset.size()); boolean assetExistsBeforeDelete = repository.assetExists(id); assertTrue(assetExistsBeforeDelete); boolean deleted = repository.deleteAssetFromPath("/process.bpmn2"); assertTrue(deleted); boolean assetExists = repository.assetExists(id); assertFalse(assetExists); }
@Test public void testStoreSingleTextAsset() throws NoSuchFileException { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); Collection<Asset> assets = repository.listAssets("/"); assertNotNull(assets); assertEquals(0, assets.size()); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text); builder.content("simple content").type("txt").name("test").location("/"); String id = repository.createAsset(builder.getAsset()); assertNotNull(id); Asset<String> asset = repository.loadAsset(id); assertEquals("txt", asset.getAssetType()); assertEquals("test", asset.getName()); assertEquals("test.txt", asset.getFullName()); assertEquals("/", asset.getAssetLocation()); assertEquals("simple content", asset.getAssetContent()); }
@Test public void testStoreSingleBinaryAssetSpaceInName() throws NoSuchFileException { Repository repository = new VFSRepository(producer.getIoService()); ((VFSRepository) repository).setDescriptor(descriptor); Collection<Asset> assets = repository.listAssets("/"); assertNotNull(assets); assertEquals(0, assets.size()); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Byte); builder.content("simple content".getBytes()).type("png").name("test asset").location("/"); String id = repository.createAsset(builder.getAsset()); assertNotNull(id); Asset<byte[]> asset = repository.loadAsset(id); assertEquals("png", asset.getAssetType()); assertEquals("test asset", asset.getName()); assertEquals("test asset.png", asset.getFullName()); assertEquals("/", asset.getAssetLocation()); assertFalse(asset.getAssetContent().length == 0); }