Search in sources :

Example 1 with Element

use of jetbrains.buildServer.util.browser.Element in project teamcity-powershell by JetBrains.

the class PowerShellRunnerDiscovererTest method testExcludeAlreadyUsedFiles.

@Test
public void testExcludeAlreadyUsedFiles() {
    final SBuildRunnerDescriptor definedRunner = m.mock(SBuildRunnerDescriptor.class, "already-defined-descriptor");
    final String scriptFileName = "file1.ps1";
    final Map<String, String> definedRunnerParams = new HashMap<String, String>() {

        {
            put(PowerShellConstants.RUNNER_SCRIPT_FILE, scriptFileName);
            put(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
        }
    };
    final Element file1 = m.mock(Element.class, "file1.ps1");
    final String file2Name = "file2.ps1";
    final Element file2 = m.mock(Element.class, file2Name);
    m.checking(new Expectations() {

        {
            oneOf(myBrowser).getRoot();
            will(returnValue(myRootElement));
            oneOf(myRootElement).getChildren();
            will(returnValue(Arrays.asList(file1, file2)));
            atLeast(1).of(file1).isLeaf();
            will(returnValue(true));
            atLeast(1).of(file2).isLeaf();
            will(returnValue(true));
            atLeast(1).of(file1).getName();
            will(returnValue(scriptFileName));
            atLeast(1).of(file2).getName();
            will(returnValue(file2Name));
            atLeast(1).of(file1).getFullName();
            will(returnValue(scriptFileName));
            atLeast(1).of(file2).getFullName();
            will(returnValue(file2Name));
            atLeast(1).of(myBuildTypeSettings).getBuildRunners();
            will(returnValue(Collections.singletonList(definedRunner)));
            oneOf(definedRunner).getType();
            will(returnValue(PowerShellConstants.RUN_TYPE));
            allowing(definedRunner).getParameters();
            will(returnValue(definedRunnerParams));
        }
    });
    final List<DiscoveredObject> runners = myDiscoverer.discover(myBuildTypeSettings, myBrowser);
    assertNotNull(runners);
    assertEquals(1, runners.size());
    validateRunner(runners.get(0), file2Name);
}
Also used : Expectations(org.jmock.Expectations) SBuildRunnerDescriptor(jetbrains.buildServer.serverSide.SBuildRunnerDescriptor) Element(jetbrains.buildServer.util.browser.Element) DiscoveredObject(jetbrains.buildServer.serverSide.discovery.DiscoveredObject) Test(org.testng.annotations.Test)

Example 2 with Element

use of jetbrains.buildServer.util.browser.Element in project teamcity-powershell by JetBrains.

the class PowerShellRunnerDiscovererTest method testDiscover_Deep.

@Test
public void testDiscover_Deep() {
    final Element file1 = m.mock(Element.class, "file1.txt");
    final Element dir1 = m.mock(Element.class, "dir1");
    final Element file2 = m.mock(Element.class, "file2.ps1");
    final Element dir2 = m.mock(Element.class, "dir2");
    final List<Element> topLevel = new ArrayList<>(Arrays.asList(file1, dir1));
    final List<Element> bottomLevel = new ArrayList<>(Arrays.asList(file2, dir2));
    final String fullName = "dir1/fil2.ps1";
    m.checking(new Expectations() {

        {
            oneOf(myBrowser).getRoot();
            will(returnValue(myRootElement));
            oneOf(myRootElement).getChildren();
            will(returnValue(topLevel));
            atLeast(1).of(file1).isLeaf();
            will(returnValue(true));
            atLeast(1).of(dir1).isLeaf();
            will(returnValue(false));
            oneOf(file1).getName();
            will(returnValue("file1.txt"));
            oneOf(dir1).getChildren();
            will(returnValue(bottomLevel));
            atLeast(1).of(file2).isLeaf();
            will(returnValue(true));
            atLeast(1).of(dir2).isLeaf();
            will(returnValue(false));
            atLeast(1).of(file2).getName();
            will(returnValue("file2.ps1"));
            atLeast(1).of(file2).getFullName();
            will(returnValue(fullName));
            allowing(myBuildTypeSettings).getBuildRunners();
            will(returnValue(Collections.emptyList()));
        }
    });
    final List<DiscoveredObject> runners = myDiscoverer.discover(myBuildTypeSettings, myBrowser);
    assertNotNull(runners);
    assertEquals(1, runners.size());
    final DiscoveredObject runner = runners.get(0);
    validateRunner(runner, fullName);
}
Also used : Expectations(org.jmock.Expectations) Element(jetbrains.buildServer.util.browser.Element) DiscoveredObject(jetbrains.buildServer.serverSide.discovery.DiscoveredObject) Test(org.testng.annotations.Test)

Example 3 with Element

use of jetbrains.buildServer.util.browser.Element in project teamcity-powershell by JetBrains.

the class PowerShellRunnerDiscovererTest method testDiscover_NoFiles.

@Test
public void testDiscover_NoFiles() {
    final List<Element> children = Collections.emptyList();
    m.checking(new Expectations() {

        {
            oneOf(myBrowser).getRoot();
            will(returnValue(myRootElement));
            oneOf(myRootElement).getChildren();
            will(returnValue(children));
        }
    });
    final List<DiscoveredObject> runners = myDiscoverer.discover(myBuildTypeSettings, myBrowser);
    assertNotNull(runners);
    assertEquals(0, runners.size());
}
Also used : Expectations(org.jmock.Expectations) Element(jetbrains.buildServer.util.browser.Element) DiscoveredObject(jetbrains.buildServer.serverSide.discovery.DiscoveredObject) Test(org.testng.annotations.Test)

Example 4 with Element

use of jetbrains.buildServer.util.browser.Element in project teamcity-rest by JetBrains.

the class AggregatedBuildArtifactsElementBuilder method getBuildAggregatedArtifactElement.

@NotNull
public static Element getBuildAggregatedArtifactElement(@NotNull final String path, @NotNull final List<BuildPromotion> builds, @NotNull final ServiceLocator serviceLocator) {
    final AggregatedBuildArtifactsElementBuilder result = new AggregatedBuildArtifactsElementBuilder();
    int i = 0;
    for (BuildPromotion buildPromotion : builds) {
        try {
            final Element artifactElement = BuildArtifactsFinder.getArtifactElement(buildPromotion, path, serviceLocator);
            LOG.debug("Found artifact file with path '" + path + "' in " + i + "/" + builds.size() + " build: " + LogUtil.describe(buildPromotion));
            result.add(artifactElement);
        } catch (NotFoundException e) {
            LOG.debug("Ignoring not found error in artifacts aggregation request: " + e.toString());
        } catch (AuthorizationFailedException e) {
            LOG.debug("Ignoring authentication error in artifacts aggregation request: " + e.toString());
        }
        i++;
    }
    return result.get();
}
Also used : BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) Element(jetbrains.buildServer.util.browser.Element) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Element

use of jetbrains.buildServer.util.browser.Element in project teamcity-powershell by JetBrains.

the class PowerShellRunnerDiscovererTest method testDiscover_Shallow.

@Test
public void testDiscover_Shallow() {
    final Element file1 = m.mock(Element.class, "file1.ps1");
    final Element dir1 = m.mock(Element.class, "dir1");
    final List<Element> topLevel = new ArrayList<>(Arrays.asList(file1, dir1));
    final String fullName = "file1.ps1";
    m.checking(new Expectations() {

        {
            oneOf(myBrowser).getRoot();
            will(returnValue(myRootElement));
            oneOf(myRootElement).getChildren();
            will(returnValue(topLevel));
            atLeast(1).of(file1).isLeaf();
            will(returnValue(true));
            atLeast(1).of(dir1).isLeaf();
            will(returnValue(false));
            atLeast(1).of(file1).getName();
            will(returnValue("file1.ps1"));
            atLeast(1).of(file1).getFullName();
            will(returnValue(fullName));
            allowing(myBuildTypeSettings).getBuildRunners();
            will(returnValue(Collections.emptyList()));
        }
    });
    final List<DiscoveredObject> runners = myDiscoverer.discover(myBuildTypeSettings, myBrowser);
    assertNotNull(runners);
    assertEquals(1, runners.size());
    validateRunner(runners.get(0), fullName);
}
Also used : Expectations(org.jmock.Expectations) Element(jetbrains.buildServer.util.browser.Element) DiscoveredObject(jetbrains.buildServer.serverSide.discovery.DiscoveredObject) Test(org.testng.annotations.Test)

Aggregations

Element (jetbrains.buildServer.util.browser.Element)10 DiscoveredObject (jetbrains.buildServer.serverSide.discovery.DiscoveredObject)6 Expectations (org.jmock.Expectations)5 Test (org.testng.annotations.Test)5 NotNull (org.jetbrains.annotations.NotNull)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ArchiveElement (jetbrains.buildServer.server.rest.data.ArchiveElement)2 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)2 ArtifactElement (jetbrains.buildServer.web.artifacts.browser.ArtifactElement)2 ArtifactTreeElement (jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement)2 List (java.util.List)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpDownloadProcessor (jetbrains.buildServer.controllers.HttpDownloadProcessor)1 Locator (jetbrains.buildServer.server.rest.data.Locator)1 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)1 Fields (jetbrains.buildServer.server.rest.model.Fields)1 FileApiUrlBuilder (jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder)1 Files (jetbrains.buildServer.server.rest.model.files.Files)1 BuildPromotion (jetbrains.buildServer.serverSide.BuildPromotion)1