Search in sources :

Example 6 with Element

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

the class PowerShellRunnerDiscovererTest method setUp.

@Override
@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    m = new Mockery();
    myBrowser = m.mock(Browser.class);
    myRootElement = m.mock(Element.class, "root-element");
    myDiscoverer = new PowerShellRunnerDiscoverer();
    myBuildTypeSettings = m.mock(BuildTypeSettings.class);
}
Also used : Element(jetbrains.buildServer.util.browser.Element) Mockery(org.jmock.Mockery) Browser(jetbrains.buildServer.util.browser.Browser) BuildTypeSettings(jetbrains.buildServer.serverSide.BuildTypeSettings) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with Element

use of jetbrains.buildServer.util.browser.Element 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)

Example 8 with Element

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

the class PowerShellRunnerDiscoverer method discoverRunnersInDirectory.

@NotNull
@Override
protected List<DiscoveredObject> discoverRunnersInDirectory(@NotNull final Element dir, @NotNull final List<Element> filesAndDirs) {
    final List<DiscoveredObject> runners = new ArrayList<>();
    for (Element e : filesAndDirs) {
        if (e.isLeaf() && PS_EXT.equals(FileUtil.getExtension(e.getName()))) {
            final Map<String, String> parameters = new HashMap<>();
            parameters.put(PowerShellConstants.RUNNER_SCRIPT_FILE, e.getFullName());
            parameters.put(PowerShellConstants.RUNNER_EXECUTION_MODE, PowerShellExecutionMode.PS1.getValue());
            parameters.put(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
            runners.add(new DiscoveredObject(PowerShellConstants.RUN_TYPE, parameters));
        }
    }
    return runners;
}
Also used : Element(jetbrains.buildServer.util.browser.Element) DiscoveredObject(jetbrains.buildServer.serverSide.discovery.DiscoveredObject) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Element

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

the class FilesSubResource method getChildren.

@GET
@Path(FilesSubResource.CHILDREN + "{path:(/.*)?}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "getChildren", hidden = true)
public Files getChildren(@PathParam("path") @DefaultValue("") final String path, @QueryParam("basePath") final String basePath, @QueryParam("locator") final String locator, @QueryParam("fields") String fields) {
    if (!myArchiveBrowsingSupported && locator != null) {
        final Boolean browseArchives = new Locator(locator).getSingleDimensionValueAsBoolean(BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME);
        if (browseArchives != null && browseArchives) {
            throw new BadRequestException("Archive browsing is not supported for this request, remove '" + BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME + "' dimension");
        }
    }
    final FileApiUrlBuilder builder = fileApiUrlBuilder(locator, myUrlPrefix);
    final Element rootElement = myProvider.getElement(myProvider.preprocess(StringUtil.removeLeadingSlash(path)));
    return new Files(null, new Files.DefaultFilesProvider(builder, myBeanContext) {

        @Override
        @NotNull
        public List<? extends Element> getItems() {
            return BuildArtifactsFinder.getItems(rootElement, myProvider.preprocess(basePath), locator, builder, myBeanContext.getServiceLocator());
        }
    }, new Fields(fields), myBeanContext);
}
Also used : Locator(jetbrains.buildServer.server.rest.data.Locator) FileApiUrlBuilder(jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder) Fields(jetbrains.buildServer.server.rest.model.Fields) ArchiveElement(jetbrains.buildServer.server.rest.data.ArchiveElement) Element(jetbrains.buildServer.util.browser.Element) ArtifactElement(jetbrains.buildServer.web.artifacts.browser.ArtifactElement) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) List(java.util.List) Files(jetbrains.buildServer.server.rest.model.files.Files) NotNull(org.jetbrains.annotations.NotNull) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with Element

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

the class FilesSubResource method getContent.

@GET
@Path(FilesSubResource.CONTENT + "{path:(/.*)?}")
@Produces({ MediaType.WILDCARD })
@ApiOperation(value = "getContent", hidden = true)
public Response getContent(@PathParam("path") final String path, @QueryParam("responseBuilder") final String responseBuilder, @Context HttpServletRequest request, @Context HttpServletResponse response) {
    final String preprocessedPath = myProvider.preprocess(StringUtil.removeLeadingSlash(path));
    final Element initialElement = myProvider.getElement(preprocessedPath);
    if (!initialElement.isContentAvailable()) {
        throw new NotFoundException("Cannot provide content for '" + initialElement.getFullName() + "'. To get children use '" + fileApiUrlBuilder(null, myUrlPrefix).getChildrenHref(initialElement) + "'.");
    }
    String contentResponseBuilder = getSetting("rest.files.contentResponseBuilder", "coreWithDownloadProcessor", "responseBuilder", responseBuilder, true, "rest", "core", "coreWithDownloadProcessor");
    if ("rest".equals(contentResponseBuilder)) {
        // pre-2017.1 way of downloading files
        final Response.ResponseBuilder builder = getContent(initialElement, request);
        myProvider.fileContentServed(preprocessedPath, request);
        setCacheControl(request, response);
        return builder.build();
    } else if ("core".equals(contentResponseBuilder)) {
        processCoreDownload(initialElement, request, response);
    } else if ("coreWithDownloadProcessor".equals(contentResponseBuilder)) {
        if (!(myProvider instanceof DownloadProcessor) || !((DownloadProcessor) myProvider).processDownload(initialElement, request, response)) {
            processCoreDownload(initialElement, request, response);
        }
    } else {
        throw new BadRequestException("Unknown responseBuilder: '" + contentResponseBuilder + "'. Supported values are: '" + "rest" + "', '" + "core" + "', '" + "coreWithDownloadProcessor" + "'");
    }
    // todo: register only if no errors occurred?
    myProvider.fileContentServed(preprocessedPath, request);
    if (!response.isCommitted()) {
        // let Jersey know what the response should be, otherwise 304 responses can turn to 204
        return Response.status(response.getStatus()).build();
    }
    return null;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpDownloadProcessor(jetbrains.buildServer.controllers.HttpDownloadProcessor) ArchiveElement(jetbrains.buildServer.server.rest.data.ArchiveElement) Element(jetbrains.buildServer.util.browser.Element) ArtifactElement(jetbrains.buildServer.web.artifacts.browser.ArtifactElement) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation)

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