コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
  @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);
  }
コード例 #4
0
  @Ignore // git based vfs does not yet support move
  @Test
  public void testMoveEmptyDirectory() throws NoSuchFileException {
    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    Directory sourceDir = repository.createDirectory("/source");

    boolean directoryExists =
        repository.directoryExists(sourceDir.getLocation() + sourceDir.getName());
    assertTrue(directoryExists);
    Collection<Asset> foundAsset = repository.listAssets("/source", new FilterByExtension("bpmn2"));

    assertNotNull(foundAsset);
    assertEquals(0, foundAsset.size());

    boolean copied = repository.moveDirectory("/source", "/", "target");
    assertTrue(copied);

    boolean movedDirectoryExists = repository.directoryExists("/source");
    assertFalse(movedDirectoryExists);
    movedDirectoryExists = repository.directoryExists("/target");
    assertTrue(movedDirectoryExists);

    foundAsset = repository.listAssets("/target", new FilterByExtension("bpmn2"));

    assertNotNull(foundAsset);
    assertEquals(0, foundAsset.size());
  }
コード例 #5
0
  @Test
  public void testListAsset() {

    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    boolean rootFolderExists = repository.directoryExists("/processes");
    assertTrue(rootFolderExists);

    Collection<Asset> assets = repository.listAssets("/processes");
    assertNotNull(assets);
    assertEquals(2, assets.size());
  }
コード例 #6
0
  @Test
  public void testCreateGlobalDirOnNewProject() throws FileAlreadyExistsException {
    VFSRepository repository = new VFSRepository(producer.getIoService());
    repository.setDescriptor(descriptor);

    Directory testProjectDir = repository.createDirectory("/mytestproject");

    final KieProject mockProject = mock(KieProject.class);
    when(mockProject.getRootPath())
        .thenReturn(
            Paths.convert(
                producer
                    .getIoService()
                    .get(URI.create(decodeUniqueId(testProjectDir.getUniqueId())))));

    NewProjectEvent event = mock(NewProjectEvent.class);
    when(event.getProject()).thenReturn(mockProject);

    repository.createGlobalDirOnNewProject(event);

    boolean globalDirectoryExists = repository.directoryExists("/mytestproject/global");
    assertTrue(globalDirectoryExists);

    Collection<Asset> foundFormTemplates =
        repository.listAssets("/mytestproject/global", new FilterByExtension("fw"));
    assertNotNull(foundFormTemplates);
    assertEquals(25, foundFormTemplates.size());

    // call again to try to trigger FileAlreadyExistsException
    repository.createGlobalDirOnNewProject(event);

    boolean globalDirectoryStillExists = repository.directoryExists("/mytestproject/global");
    assertTrue(globalDirectoryStillExists);

    // no new files or copies were added
    Collection<Asset> foundFormTemplatesAfterSecondCall =
        repository.listAssets("/mytestproject/global", new FilterByExtension("fw"));
    assertNotNull(foundFormTemplatesAfterSecondCall);
    assertEquals(25, foundFormTemplatesAfterSecondCall.size());
  }
コード例 #7
0
  @Test
  public void testLoadAssetFromPath() throws NoSuchFileException {

    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    Asset<String> asset = repository.loadAssetFromPath("/processes/BPMN2-ScriptTask.bpmn2");

    assertEquals("bpmn2", asset.getAssetType());
    assertEquals("BPMN2-ScriptTask", asset.getName());
    assertEquals("BPMN2-ScriptTask.bpmn2", asset.getFullName());
    assertEquals("/processes", asset.getAssetLocation());
    assertNotNull(asset.getAssetContent());
    System.out.print(asset.getUniqueId());
  }
コード例 #8
0
  @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());
  }
コード例 #9
0
  @Test
  public void testCreateDirectory() {

    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);
  }
コード例 #10
0
  @Test
  public void testListNestedSingleTextAsset() {

    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    boolean rootFolderExists = repository.directoryExists("/processes/nested");
    assertTrue(rootFolderExists);

    Collection<Asset> assets = repository.listAssets("/processes/nested");
    assertNotNull(assets);
    assertEquals(1, assets.size());
    Asset<String> asset = assets.iterator().next();

    assertEquals("bpmn2", asset.getAssetType());
    assertEquals("BPMN2-UserTask.bpmn2", asset.getFullName());
    assertEquals("BPMN2-UserTask", asset.getName());
    assertEquals("/processes/nested", asset.getAssetLocation());
  }
コード例 #11
0
  @Test
  public void testListSingleBinaryAsset() {

    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    boolean rootFolderExists = repository.directoryExists("/images");
    assertTrue(rootFolderExists);

    Collection<Asset> assets = repository.listAssets("/images");
    assertNotNull(assets);
    assertEquals(1, assets.size());
    Asset<String> asset = assets.iterator().next();

    assertEquals("png", asset.getAssetType());
    assertEquals("release-process.png", asset.getFullName());
    assertEquals("release-process", asset.getName());
    assertEquals("/images", asset.getAssetLocation());
  }
コード例 #12
0
  @Test
  public void testDeleteDirectory() {
    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    boolean rootFolderExists = repository.directoryExists("/test");
    assertFalse(rootFolderExists);

    Directory directoryId = repository.createDirectory("/test");
    assertNotNull(directoryId);

    rootFolderExists = repository.directoryExists("/test");
    assertTrue(rootFolderExists);

    boolean deleted = repository.deleteDirectory("/test", true);
    assertTrue(deleted);

    rootFolderExists = repository.directoryExists("/test");
    assertFalse(rootFolderExists);
  }
コード例 #13
0
  @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);
  }
コード例 #14
0
  @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);
  }
コード例 #15
0
  @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());
  }
コード例 #16
0
  @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);
  }
コード例 #17
0
  @Test
  public void testProprocess() {
    Repository repository = new VFSRepository(producer.getIoService());
    ((VFSRepository) repository).setDescriptor(descriptor);
    profile.setRepository(repository);
    // prepare folders that will be used
    repository.createDirectory("/myprocesses");
    repository.createDirectory("/global");

    // prepare process asset that will be used to preprocess
    AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Text);
    builder.content("bpmn2 content").type("bpmn2").name("process").location("/myprocesses");
    String uniqueId = repository.createAsset(builder.getAsset());

    // create instance of preprocessing unit
    JbpmPreprocessingUnit preprocessingUnitVFS =
        new JbpmPreprocessingUnit(new TestServletContext(), "/", null);

    // setup parameters
    Map<String, String> params = new HashMap<String, String>();
    params.put("uuid", uniqueId);

    // run preprocess
    preprocessingUnitVFS.preprocess(
        new TestHttpServletRequest(params), null, new TestIDiagramProfile(repository), null);

    // validate results
    Collection<Asset> globalAssets = repository.listAssets("/global");
    assertNotNull(globalAssets);
    assertEquals(30, globalAssets.size());
    repository.assetExists("/global/backboneformsinclude.fw");
    repository.assetExists("/global/backbonejsinclude.fw");
    repository.assetExists("/global/cancelbutton.fw");
    repository.assetExists("/global/checkbox.fw");
    repository.assetExists("/global/customeditors.json");
    repository.assetExists("/global/div.fw");
    repository.assetExists("/global/dropdownmenu.fw");
    repository.assetExists("/global/fieldset.fw");
    repository.assetExists("/global/form.fw");
    repository.assetExists("/global/handlebarsinclude.fw");
    repository.assetExists("/global/htmlbasepage.fw");
    repository.assetExists("/global/image.fw");
    repository.assetExists("/global/jqueryinclude.fw");
    repository.assetExists("/global/jquerymobileinclude.fw");
    repository.assetExists("/global/link.fw");
    repository.assetExists("/global/mobilebasepage.fw");
    repository.assetExists("/global/orderedlist.fw");
    repository.assetExists("/global/passwordfield.fw");
    repository.assetExists("/global/radiobutton.fw");
    repository.assetExists("/global/script.fw");
    repository.assetExists("/global/submitbutton.fw");
    repository.assetExists("/global/table.fw");
    repository.assetExists("/global/textarea.fw");
    repository.assetExists("/global/textfield.fw");
    repository.assetExists("/global/themes.json");
    repository.assetExists("/global/unorderedlist.fw");
    repository.assetExists("/global/defaultemailicon.gif");
    repository.assetExists("/global/defaultlogicon.gif");
    repository.assetExists("/global/defaultservicenodeicon.png");
    repository.assetExists("/global/.gitignore");

    Collection<Asset> defaultStuff = repository.listAssets("/myprocesses");
    assertNotNull(defaultStuff);
    assertEquals(3, defaultStuff.size());
    repository.assetExists("/myprocesses/WorkDefinitions.wid");
    // this is the process asset that was created for the test but let's check it anyway
    repository.assetExists("/myprocesses/process.bpmn2");
    repository.assetExists("/myprocesses/.gitignore");
  }