コード例 #1
0
  @Test
  public void testDeleteProjectObserverBridge() throws URISyntaxException {
    final URI fs = new URI("git://test");
    try {
      FileSystems.getFileSystem(fs);
    } catch (FileSystemNotFoundException e) {
      FileSystems.newFileSystem(fs, new HashMap<String, Object>());
    }

    final Path path = mock(Path.class);
    final org.uberfire.java.nio.file.Path nioPath = mock(org.uberfire.java.nio.file.Path.class);
    when(path.getFileName()).thenReturn("pom.xml");
    when(path.toURI()).thenReturn("git://test/p0/pom.xml");
    when(nioPath.getParent()).thenReturn(nioPath);
    when(nioPath.resolve(any(String.class))).thenReturn(nioPath);
    when(nioPath.toUri()).thenReturn(URI.create("git://test/p0/pom.xml"));
    when(nioPath.getFileSystem()).thenReturn(FileSystems.getFileSystem(fs));
    when(ioService.get(any(URI.class))).thenReturn(nioPath);

    final SessionInfo sessionInfo = mock(SessionInfo.class);
    final Event<DeleteProjectEvent> deleteProjectEvent = mock(Event.class);
    final AbstractProjectService projectServiceSpy = spy(projectService);

    final DeleteProjectObserverBridge bridge =
        new DeleteProjectObserverBridge(ioService, projectServiceSpy, deleteProjectEvent);

    bridge.onBatchResourceChanges(new ResourceDeletedEvent(path, "message", sessionInfo));

    verify(deleteProjectEvent, times(1)).fire(any(DeleteProjectEvent.class));

    verify(projectServiceSpy, times(0))
        .newProject(any(Repository.class), any(String.class), any(POM.class), any(String.class));
    verify(projectServiceSpy, times(1))
        .simpleProjectInstance(any(org.uberfire.java.nio.file.Path.class));
  }
コード例 #2
0
  @Test
  public void testNewProjectCreation() throws URISyntaxException {
    final URI fs = new URI("git://test");
    try {
      FileSystems.getFileSystem(fs);
    } catch (FileSystemNotFoundException e) {
      FileSystems.newFileSystem(fs, new HashMap<String, Object>());
    }

    final Repository repository = mock(Repository.class);
    final String name = "p0";
    final POM pom = new POM();
    final String baseURL = "/";

    final Path repositoryRootPath = mock(Path.class);
    when(repository.getRoot()).thenReturn(repositoryRootPath);
    when(repositoryRootPath.toURI()).thenReturn("git://test");

    pom.getGav().setGroupId("org.kie.workbench.services");
    pom.getGav().setArtifactId("kie-wb-common-services-test");
    pom.getGav().setVersion("1.0.0-SNAPSHOT");

    when(pomService.load(any(Path.class))).thenReturn(pom);

    final AbstractProjectService projectServiceSpy = spy(projectService);

    final Project project = projectServiceSpy.newProject(repository, name, pom, baseURL);

    verify(projectServiceSpy, times(1))
        .simpleProjectInstance(any(org.uberfire.java.nio.file.Path.class));

    assertEquals(pom, project.getPom());
  }
コード例 #3
0
  @Test
  public void testPackageNameWhiteList() throws URISyntaxException {
    final URI fs = new URI("git://test");
    try {
      FileSystems.getFileSystem(fs);
    } catch (FileSystemNotFoundException e) {
      FileSystems.newFileSystem(fs, new HashMap<String, Object>());
    }

    final Map<String, String> writes = new HashMap<String, String>();

    final Repository repository = mock(Repository.class);
    final String name = "p0";
    final POM pom = new POM();
    final String baseURL = "/";

    final Path repositoryRootPath = mock(Path.class);
    when(repository.getRoot()).thenReturn(repositoryRootPath);
    when(repositoryRootPath.toURI()).thenReturn("git://test");

    when(ioService.write(any(org.uberfire.java.nio.file.Path.class), anyString()))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(final InvocationOnMock invocation) throws Throwable {
                if (invocation.getArguments().length == 2) {
                  final String path =
                      ((org.uberfire.java.nio.file.Path) invocation.getArguments()[0])
                          .toUri()
                          .getPath();
                  final String content = ((String) invocation.getArguments()[1]);
                  writes.put(path, content);
                }
                return invocation.getArguments()[0];
              }
            });

    pom.getGav().setGroupId("org.kie.workbench.services");
    pom.getGav().setArtifactId("kie-wb-common-services-test");
    pom.getGav().setVersion("1.0.0-SNAPSHOT");

    projectService.newProject(repository, name, pom, baseURL);

    assertTrue(writes.containsKey("/p0/package-names-white-list"));
    assertEquals(
        "org.kie.workbench.services.kie_wb_common_services_test.**",
        writes.get("/p0/package-names-white-list"));
  }