Search in sources :

Example 1 with DiscoveredObject

use of jetbrains.buildServer.serverSide.discovery.DiscoveredObject 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 DiscoveredObject

use of jetbrains.buildServer.serverSide.discovery.DiscoveredObject 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 DiscoveredObject

use of jetbrains.buildServer.serverSide.discovery.DiscoveredObject 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 DiscoveredObject

use of jetbrains.buildServer.serverSide.discovery.DiscoveredObject 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)

Example 5 with DiscoveredObject

use of jetbrains.buildServer.serverSide.discovery.DiscoveredObject in project teamcity-powershell by JetBrains.

the class PowerShellRunnerDiscovererTest method testDiscover_NoSuitableFiles.

@Test
public void testDiscover_NoSuitableFiles() {
    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");
    final Element dir2 = m.mock(Element.class, "dir2");
    final List<Element> topLevel = new ArrayList<>(Arrays.asList(file1, dir1));
    final List<Element> bottomLevel;
    bottomLevel = new ArrayList<>(Arrays.asList(file2, dir2));
    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));
            oneOf(file2).getName();
            will(returnValue("file2"));
        }
    });
    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)

Aggregations

DiscoveredObject (jetbrains.buildServer.serverSide.discovery.DiscoveredObject)6 Element (jetbrains.buildServer.util.browser.Element)6 Expectations (org.jmock.Expectations)5 Test (org.testng.annotations.Test)5 SBuildRunnerDescriptor (jetbrains.buildServer.serverSide.SBuildRunnerDescriptor)1 NotNull (org.jetbrains.annotations.NotNull)1