コード例 #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
  @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);
  }
コード例 #3
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());
  }