From 8d5db9494bc02cd529fe1e42c7f8a75c1359f979 Mon Sep 17 00:00:00 2001 From: Alok Shukla Date: Sat, 2 Jun 2018 07:36:19 +0530 Subject: [PATCH 1/3] Added required models and API entry-point #189 --- src/main/java/org/gitlab4j/api/GitLabApi.java | 36 +++- src/main/java/org/gitlab4j/api/WikisApi.java | 200 ++++++++++++++++++ .../org/gitlab4j/api/models/WikiPage.java | 88 ++++++++ 3 files changed, 315 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/gitlab4j/api/WikisApi.java create mode 100644 src/main/java/org/gitlab4j/api/models/WikiPage.java diff --git a/src/main/java/org/gitlab4j/api/GitLabApi.java b/src/main/java/org/gitlab4j/api/GitLabApi.java index c7e765ed9..f8aff9312 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApi.java +++ b/src/main/java/org/gitlab4j/api/GitLabApi.java @@ -1,14 +1,5 @@ package org.gitlab4j.api; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; -import java.util.WeakHashMap; -import java.util.logging.Logger; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - import org.gitlab4j.api.Constants.TokenType; import org.gitlab4j.api.models.OauthTokenResponse; import org.gitlab4j.api.models.Session; @@ -17,6 +8,14 @@ import org.gitlab4j.api.utils.Oauth2LoginStreamingOutput; import org.gitlab4j.api.utils.SecretString; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.WeakHashMap; +import java.util.logging.Logger; + /** * This class is provides a simplified interface to a GitLab API server, and divides the API up into * a separate API class for each concern. @@ -72,6 +71,7 @@ public String getApiNamespace() { private NotesApi notesApi; private EventsApi eventsApi; private SnippetsApi snippetsApi; + private WikisApi wikisApi; /** * Get the GitLab4J shared Logger instance. @@ -1295,4 +1295,22 @@ public SnippetsApi getSnippetApi() { return snippetsApi; } + + /** + * Gets the WikisApi instance owned by this GitLabApi instance. The WikisApi is used to perform all snippet related + * API calls. + * + * @return the WikisApi instance owned by this GitLabApi instance + */ + public WikisApi getWikisApi() { + if (wikisApi == null) { + synchronized (this) { + if (wikisApi == null) { + wikisApi = new WikisApi(this); + } + } + } + + return wikisApi; + } } diff --git a/src/main/java/org/gitlab4j/api/WikisApi.java b/src/main/java/org/gitlab4j/api/WikisApi.java new file mode 100644 index 000000000..fcebaf2fe --- /dev/null +++ b/src/main/java/org/gitlab4j/api/WikisApi.java @@ -0,0 +1,200 @@ +package org.gitlab4j.api; + +import org.gitlab4j.api.models.WikiPage; + +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; +import java.util.List; +import java.util.Optional; + +/** + * This class provides an entry point to all the GitLab Wikis API project calls. + * + * @author shuklaalok7 + * @since v4.8.21 2018-06-02 7:08 AM IST + */ +public class WikisApi extends AbstractApi { + + public WikisApi(GitLabApi gitLabApi) { + super(gitLabApi); + } + + /** + * Get a Pager of the authenticated user's wiki pages. + * + * GET /wikis + * + * @param itemsPerPage the number of wiki-pages per page + * @return the Pager of wiki-pages + * @throws GitLabApiException if any exception occurs + */ + public Pager getPages(int itemsPerPage) throws GitLabApiException { + return (new Pager<>(this, WikiPage.class, itemsPerPage, null, "wikis")); + } + + /** + * Get a list of the authenticated user's wikis. + * + * GET /wikis + * + * @param downloadContent indicating whether to download the page content + * @return a list of authenticated user's wiki pages + * @throws GitLabApiException if any exception occurs + */ + public List getPages(boolean downloadContent) throws GitLabApiException { + + Response response = get(Response.Status.OK, getDefaultPerPageParam(), "wikis"); + List pages = (response.readEntity(new GenericType>(){})); + + if (downloadContent) { + for (WikiPage page : pages) { + page.setContent(getPageContent(page.getSlug())); + } + } + + return pages; + } + + /** + * Get a list of the authenticated user's wikis. + * + * GET /wikis + * + * @return a list of authenticated user's wikis + * @throws GitLabApiException if any exception occurs + */ + public List getPages() throws GitLabApiException { + return getPages(false); + } + + /** + * Get the content of a Wiki page. + * + * GET /wikis/:slug + * + * @param slug the slug to fetch + * @return the content of wiki page + * @throws GitLabApiException if any exception occurs + */ + public String getPageContent(String slug) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "wikis", slug); + return (response.readEntity(String.class)); + } + + /** + * Get a specific Wiki page. + * + * @param slug the slug to get + * @param downloadContent indicating whether to download the page content + * @return the Wiki page with the given slug + * @throws GitLabApiException if any exception occurs + */ + public WikiPage getPage(String slug, boolean downloadContent) throws GitLabApiException { + if (slug == null) { + throw new RuntimeException("slug can't be null"); + } + + Response response = get(Response.Status.OK, null, "wikis", slug); + WikiPage page = response.readEntity(WikiPage.class); + + if (downloadContent) { + page.setContent(getPageContent(slug)); + } + + return page; + } + + /** + * Get a specific Page. + * + * @param slug the slug to get + * @return the Wiki page with the given slug + * @throws GitLabApiException if any exception occurs + */ + public WikiPage getPage(String slug) throws GitLabApiException { + return getPage(slug, false); + } + + /** + * Get a specific wiki page as an Optional instance. + * + * GET /wikis/:slug + * + * @param slug the slug of the wiki page to get the Optional instance for + * @return the specified WikiPage as an Optional instance + */ + public Optional getOptionalPage( String slug) { + return (getOptionalPage(slug, false)); + } + + /** + * Get a specific wiki page as an Optional instance. + * + * GET /wikis/:slug + * + * @param slug the slug of the wiki page to get the Optional instance for + * @param downloadContent indicating whether to download the page content + * @return the specified WikiPage as an Optional instance + */ + public Optional getOptionalPage(String slug, boolean downloadContent) { + try { + return (Optional.ofNullable(getPage(slug, downloadContent))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } + + /** + * Create a new WikiPage. + * + * @param title the title of the page + * @param slug the slug of the page + * @param content the content of the page + * @return the created Wiki page + * @throws GitLabApiException if any exception occurs + */ + public WikiPage createPage(String title, String slug, String content) throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm() + .withParam("title", title) + .withParam("slug", slug, true) + .withParam("content", content); + Response response = post(Response.Status.CREATED, formData, "wikis"); + return (response.readEntity(WikiPage.class)); + } + + /** + * Create a new Wiki page. + * + * @param title the title of the wiki page + * @param slug slug of the page + * @param content the content of the page + * @param format {@code markdown}, {@code rdoc}, or {@code ansidoc} + * @return the created WikiPage + * @throws GitLabApiException if any exception occurs + */ + public WikiPage createPage(String title, String slug, String content, String format) throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm() + .withParam("title", title) + .withParam("slug", slug, true) + .withParam("content", content) + .withParam("format", format); + Response response = post(Response.Status.CREATED, formData, "wikis"); + return (response.readEntity(WikiPage.class)); + } + + /** + * Removes Wiki page. + * + * DELETE /wikis/:slug + * + * @param slug the slug of the page to remove + * @throws GitLabApiException if any exception occurs + */ + public void deletePage(String slug) throws GitLabApiException { + if (slug == null) { + throw new RuntimeException("slug can't be null"); + } + + delete(Response.Status.NO_CONTENT, null, "wikis", slug); + } +} diff --git a/src/main/java/org/gitlab4j/api/models/WikiPage.java b/src/main/java/org/gitlab4j/api/models/WikiPage.java new file mode 100644 index 000000000..04f25f812 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/models/WikiPage.java @@ -0,0 +1,88 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Greg Messner + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.gitlab4j.api.models; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class WikiPage { + + private Integer id; + private String title; + private String content; + private String slug; + private String format; + + public WikiPage() { + } + + public WikiPage(String title, String slug, String content) { + this.title = title; + this.slug = slug; + this.content = content; + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getSlug() { + return slug; + } + + public void setSlug(String slug) { + this.slug = slug; + } + + public String getFormat() { + return format; + } + + public void setFormat(String format) { + this.format = format; + } +} From 3331a72a82615eb9487ff6e421a55564ac202e56 Mon Sep 17 00:00:00 2001 From: Alok Shukla Date: Sat, 2 Jun 2018 09:15:33 +0530 Subject: [PATCH 2/3] Added project wikis API in ProjectApi class #189 Added tests Removed separate API class --- src/main/java/org/gitlab4j/api/GitLabApi.java | 36 +--- .../java/org/gitlab4j/api/ProjectApi.java | 145 ++++++++++++- src/main/java/org/gitlab4j/api/WikisApi.java | 200 ------------------ .../org/gitlab4j/api/models/WikiPage.java | 9 - .../org/gitlab4j/api/TestProjectApiWikis.java | 190 +++++++++++++++++ 5 files changed, 333 insertions(+), 247 deletions(-) delete mode 100644 src/main/java/org/gitlab4j/api/WikisApi.java create mode 100644 src/test/java/org/gitlab4j/api/TestProjectApiWikis.java diff --git a/src/main/java/org/gitlab4j/api/GitLabApi.java b/src/main/java/org/gitlab4j/api/GitLabApi.java index f8aff9312..c7e765ed9 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApi.java +++ b/src/main/java/org/gitlab4j/api/GitLabApi.java @@ -1,5 +1,14 @@ package org.gitlab4j.api; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.WeakHashMap; +import java.util.logging.Logger; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.gitlab4j.api.Constants.TokenType; import org.gitlab4j.api.models.OauthTokenResponse; import org.gitlab4j.api.models.Session; @@ -8,14 +17,6 @@ import org.gitlab4j.api.utils.Oauth2LoginStreamingOutput; import org.gitlab4j.api.utils.SecretString; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; -import java.util.WeakHashMap; -import java.util.logging.Logger; - /** * This class is provides a simplified interface to a GitLab API server, and divides the API up into * a separate API class for each concern. @@ -71,7 +72,6 @@ public String getApiNamespace() { private NotesApi notesApi; private EventsApi eventsApi; private SnippetsApi snippetsApi; - private WikisApi wikisApi; /** * Get the GitLab4J shared Logger instance. @@ -1295,22 +1295,4 @@ public SnippetsApi getSnippetApi() { return snippetsApi; } - - /** - * Gets the WikisApi instance owned by this GitLabApi instance. The WikisApi is used to perform all snippet related - * API calls. - * - * @return the WikisApi instance owned by this GitLabApi instance - */ - public WikisApi getWikisApi() { - if (wikisApi == null) { - synchronized (this) { - if (wikisApi == null) { - wikisApi = new WikisApi(this); - } - } - } - - return wikisApi; - } } diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index d2dce47fb..13e60d89e 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -35,17 +35,7 @@ import javax.ws.rs.core.Response; import org.gitlab4j.api.GitLabApi.ApiVersion; -import org.gitlab4j.api.models.AccessLevel; -import org.gitlab4j.api.models.Event; -import org.gitlab4j.api.models.FileUpload; -import org.gitlab4j.api.models.Issue; -import org.gitlab4j.api.models.Member; -import org.gitlab4j.api.models.Project; -import org.gitlab4j.api.models.ProjectHook; -import org.gitlab4j.api.models.ProjectUser; -import org.gitlab4j.api.models.PushRules; -import org.gitlab4j.api.models.Snippet; -import org.gitlab4j.api.models.Visibility; +import org.gitlab4j.api.models.*; /** * This class provides an entry point to all the GitLab API project calls. @@ -1843,6 +1833,139 @@ public Optional getOptionalRawSnippetContent(Integer projectId, Integer } } + /** + * Get a list of pages in project wiki. This only returns the first page of wiki-pages. + * + * GET /projects/:id/wikis + * + * @param projectId the project ID to get the wiki-pages for + * @return a list of pages in the project's wiki + * @throws GitLabApiException if any exception occurs + */ + public List getWikiPages(Integer projectId) throws GitLabApiException { + return getWikiPages(projectId, 1, this.getDefaultPerPage()); + } + + /** + * Get a list of project snippets. This only returns the first page of snippets. + * + * GET /projects/:id/wikis + * + * @param projectId the project ID to get the wiki pages for + * @param page the page to get + * @param perPage the number of wiki-pages per page + * @return a list of pages in project's wiki for the specified range + * @throws GitLabApiException if any exception occurs + */ + public List getWikiPages(Integer projectId, int page, int perPage) throws GitLabApiException { + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "wikis"); + return response.readEntity(new GenericType>() {}); + } + + /** + * Get a Pager of project's wiki pages. + * + * GET /projects/:id/wikis + * + * @param projectId the project ID to get the wiki-pages for + * @param itemsPerPage the number of wiki-pages per page + * @return the Pager of wiki-pages + * @throws GitLabApiException if any exception occurs + */ + public Pager getWikiPages(Integer projectId, int itemsPerPage) throws GitLabApiException { + return (new Pager<>(this, WikiPage.class, itemsPerPage, null, "projects", projectId, "wikis")); + } + + /** + * Get a single page of project wiki. + * + * GET /projects/:id/wikis/:slug + * + * @param projectId the project ID to get the wiki page for + * @param slug the slug of the project's wiki page + * @return the specified project Snippet + * @throws GitLabApiException if any exception occurs + */ + public WikiPage getWikiPage(Integer projectId, String slug) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "projects", projectId, "wikis", slug); + return (response.readEntity(WikiPage.class)); + } + + /** + * Get a single page of project wiki as an Optional instance. + * + * GET /projects/:id/wikis/:slug + * + * @param projectId the project ID to get the snippet for + * @param slug the slug of the project's wiki page + * @return the specified project Snippet as an Optional instance + */ + public Optional getOptionalWikiPage(Integer projectId, String slug) { + try { + return (Optional.ofNullable(getWikiPage(projectId, slug))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } + + /** + * Creates a new project wiki page. The user must have permission to create new wiki page. + * + * POST /projects/:id/wikis + * + * @param projectId the ID of the project owned by the authenticated user, required + * @param title the title of a snippet, required + * @param content the content of a wiki page, required + * @return a WikiPage instance with info on the created page + * @throws GitLabApiException if any exception occurs + */ + public WikiPage createWikiPage(Integer projectId, String title, String content) throws GitLabApiException { + // one of title or content is required + GitLabApiForm formData = new GitLabApiForm() + .withParam("title", title) + .withParam("content", content); + + Response response = post(Response.Status.CREATED, formData, "projects", projectId, "wikis"); + return (response.readEntity(WikiPage.class)); + } + + /** + * Updates an existing project wiki page. The user must have permission to change an existing wiki page. + * + * PUT /projects/:id/wikis/:slug + * + * @param projectId the ID of the project owned by the authenticated user, required + * @param slug the slug of the project's wiki page, required + * @param title the title of a snippet, optional + * @param content the content of a page, optional. Either title or content must be supplied. + * @return a WikiPage instance with info on the updated page + * @throws GitLabApiException if any exception occurs + */ + public WikiPage updateWikiPage(Integer projectId, String slug, String title, String content) throws GitLabApiException { + + GitLabApiForm formData = new GitLabApiForm() + .withParam("title", title) + .withParam("slug", slug, true) + .withParam("content", content); + + Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "wikis", slug); + return (response.readEntity(WikiPage.class)); + } + + /** + * Deletes an existing project wiki page. This is an idempotent function and deleting a non-existent page does + * not cause an error. + * + * DELETE /projects/:id/wikis/:slug + * + * @param projectId the project ID + * @param slug the slug of the project's wiki page + * @throws GitLabApiException if any exception occurs + */ + public void deleteWikiPage(Integer projectId, String slug) throws GitLabApiException { + delete(Response.Status.NO_CONTENT, null, "projects", projectId, "wikis", slug); + } + /** * Share a project with the specified group. * diff --git a/src/main/java/org/gitlab4j/api/WikisApi.java b/src/main/java/org/gitlab4j/api/WikisApi.java deleted file mode 100644 index fcebaf2fe..000000000 --- a/src/main/java/org/gitlab4j/api/WikisApi.java +++ /dev/null @@ -1,200 +0,0 @@ -package org.gitlab4j.api; - -import org.gitlab4j.api.models.WikiPage; - -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.Response; -import java.util.List; -import java.util.Optional; - -/** - * This class provides an entry point to all the GitLab Wikis API project calls. - * - * @author shuklaalok7 - * @since v4.8.21 2018-06-02 7:08 AM IST - */ -public class WikisApi extends AbstractApi { - - public WikisApi(GitLabApi gitLabApi) { - super(gitLabApi); - } - - /** - * Get a Pager of the authenticated user's wiki pages. - * - * GET /wikis - * - * @param itemsPerPage the number of wiki-pages per page - * @return the Pager of wiki-pages - * @throws GitLabApiException if any exception occurs - */ - public Pager getPages(int itemsPerPage) throws GitLabApiException { - return (new Pager<>(this, WikiPage.class, itemsPerPage, null, "wikis")); - } - - /** - * Get a list of the authenticated user's wikis. - * - * GET /wikis - * - * @param downloadContent indicating whether to download the page content - * @return a list of authenticated user's wiki pages - * @throws GitLabApiException if any exception occurs - */ - public List getPages(boolean downloadContent) throws GitLabApiException { - - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "wikis"); - List pages = (response.readEntity(new GenericType>(){})); - - if (downloadContent) { - for (WikiPage page : pages) { - page.setContent(getPageContent(page.getSlug())); - } - } - - return pages; - } - - /** - * Get a list of the authenticated user's wikis. - * - * GET /wikis - * - * @return a list of authenticated user's wikis - * @throws GitLabApiException if any exception occurs - */ - public List getPages() throws GitLabApiException { - return getPages(false); - } - - /** - * Get the content of a Wiki page. - * - * GET /wikis/:slug - * - * @param slug the slug to fetch - * @return the content of wiki page - * @throws GitLabApiException if any exception occurs - */ - public String getPageContent(String slug) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "wikis", slug); - return (response.readEntity(String.class)); - } - - /** - * Get a specific Wiki page. - * - * @param slug the slug to get - * @param downloadContent indicating whether to download the page content - * @return the Wiki page with the given slug - * @throws GitLabApiException if any exception occurs - */ - public WikiPage getPage(String slug, boolean downloadContent) throws GitLabApiException { - if (slug == null) { - throw new RuntimeException("slug can't be null"); - } - - Response response = get(Response.Status.OK, null, "wikis", slug); - WikiPage page = response.readEntity(WikiPage.class); - - if (downloadContent) { - page.setContent(getPageContent(slug)); - } - - return page; - } - - /** - * Get a specific Page. - * - * @param slug the slug to get - * @return the Wiki page with the given slug - * @throws GitLabApiException if any exception occurs - */ - public WikiPage getPage(String slug) throws GitLabApiException { - return getPage(slug, false); - } - - /** - * Get a specific wiki page as an Optional instance. - * - * GET /wikis/:slug - * - * @param slug the slug of the wiki page to get the Optional instance for - * @return the specified WikiPage as an Optional instance - */ - public Optional getOptionalPage( String slug) { - return (getOptionalPage(slug, false)); - } - - /** - * Get a specific wiki page as an Optional instance. - * - * GET /wikis/:slug - * - * @param slug the slug of the wiki page to get the Optional instance for - * @param downloadContent indicating whether to download the page content - * @return the specified WikiPage as an Optional instance - */ - public Optional getOptionalPage(String slug, boolean downloadContent) { - try { - return (Optional.ofNullable(getPage(slug, downloadContent))); - } catch (GitLabApiException glae) { - return (GitLabApi.createOptionalFromException(glae)); - } - } - - /** - * Create a new WikiPage. - * - * @param title the title of the page - * @param slug the slug of the page - * @param content the content of the page - * @return the created Wiki page - * @throws GitLabApiException if any exception occurs - */ - public WikiPage createPage(String title, String slug, String content) throws GitLabApiException { - GitLabApiForm formData = new GitLabApiForm() - .withParam("title", title) - .withParam("slug", slug, true) - .withParam("content", content); - Response response = post(Response.Status.CREATED, formData, "wikis"); - return (response.readEntity(WikiPage.class)); - } - - /** - * Create a new Wiki page. - * - * @param title the title of the wiki page - * @param slug slug of the page - * @param content the content of the page - * @param format {@code markdown}, {@code rdoc}, or {@code ansidoc} - * @return the created WikiPage - * @throws GitLabApiException if any exception occurs - */ - public WikiPage createPage(String title, String slug, String content, String format) throws GitLabApiException { - GitLabApiForm formData = new GitLabApiForm() - .withParam("title", title) - .withParam("slug", slug, true) - .withParam("content", content) - .withParam("format", format); - Response response = post(Response.Status.CREATED, formData, "wikis"); - return (response.readEntity(WikiPage.class)); - } - - /** - * Removes Wiki page. - * - * DELETE /wikis/:slug - * - * @param slug the slug of the page to remove - * @throws GitLabApiException if any exception occurs - */ - public void deletePage(String slug) throws GitLabApiException { - if (slug == null) { - throw new RuntimeException("slug can't be null"); - } - - delete(Response.Status.NO_CONTENT, null, "wikis", slug); - } -} diff --git a/src/main/java/org/gitlab4j/api/models/WikiPage.java b/src/main/java/org/gitlab4j/api/models/WikiPage.java index 04f25f812..686d01a52 100644 --- a/src/main/java/org/gitlab4j/api/models/WikiPage.java +++ b/src/main/java/org/gitlab4j/api/models/WikiPage.java @@ -31,7 +31,6 @@ @XmlAccessorType(XmlAccessType.FIELD) public class WikiPage { - private Integer id; private String title; private String content; private String slug; @@ -46,14 +45,6 @@ public WikiPage(String title, String slug, String content) { this.content = content; } - public Integer getId() { - return this.id; - } - - public void setId(Integer id) { - this.id = id; - } - public String getTitle() { return this.title; } diff --git a/src/test/java/org/gitlab4j/api/TestProjectApiWikis.java b/src/test/java/org/gitlab4j/api/TestProjectApiWikis.java new file mode 100644 index 000000000..b485716ef --- /dev/null +++ b/src/test/java/org/gitlab4j/api/TestProjectApiWikis.java @@ -0,0 +1,190 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2017 Greg Messner + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.gitlab4j.api; + +import org.gitlab4j.api.GitLabApi.ApiVersion; +import org.gitlab4j.api.models.Project; +import org.gitlab4j.api.models.WikiPage; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; +import static org.junit.Assume.assumeTrue; + +/** + * In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties + *

+ * TEST_NAMESPACE + * TEST_PROJECT_NAME + * TEST_HOST_URL + * TEST_PRIVATE_TOKEN + *

+ * If any of the above are NULL, all tests in this class will be skipped. + */ +public class TestProjectApiWikis { + + // The following needs to be set to your test repository + private static final String TEST_NAMESPACE; + private static final String TEST_PROJECT_NAME; + private static final String TEST_HOST_URL; + private static final String TEST_PRIVATE_TOKEN; + private static final String TEST_WIKI_TITLE_PREFIX = "Test Wiki: "; + private static GitLabApi gitLabApi; + private static Integer testProjectId; + private static String testContent; + + static { + TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); + TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); + TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); + TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); + } + + public TestProjectApiWikis() { + super(); + } + + @BeforeClass + public static void setup() { + + String problems = ""; + if (TEST_NAMESPACE == null || TEST_NAMESPACE.trim().isEmpty()) { + problems += "TEST_NAMESPACE cannot be empty\n"; + } + + if (TEST_HOST_URL == null || TEST_HOST_URL.trim().isEmpty()) { + problems += "TEST_HOST_URL cannot be empty\n"; + } + + if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().isEmpty()) { + problems += "TEST_PRIVATE_TOKEN cannot be empty\n"; + } + + if (problems.isEmpty()) { + gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); + } else { + System.err.print(problems); + } + + if (gitLabApi != null) { + try { + Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); + testProjectId = project.getId(); + } catch (Exception e) { + System.err.print(e.getMessage()); + gitLabApi = null; + } + } + + testContent = "This is a test content and must be deleted after testing."; + + deleteAllTestWikiPages(); + } + + @AfterClass + public static void teardown() throws GitLabApiException { + deleteAllTestWikiPages(); + } + + private static void deleteAllTestWikiPages() { + if (gitLabApi != null) { + try { + List wikiPages = gitLabApi.getProjectApi().getWikiPages(testProjectId); + wikiPages.stream().filter(wp -> wp.getTitle().startsWith(TEST_WIKI_TITLE_PREFIX)).map(WikiPage::getSlug).forEach(slug -> { + try { + gitLabApi.getProjectApi().deleteWikiPage(testProjectId, slug); + } catch (GitLabApiException ignored) { + } + }); + } catch (GitLabApiException ignore) { + + } + } + } + + @Before + public void beforeMethod() { + assumeTrue(gitLabApi != null); + } + + private WikiPage createWikiPage(String title, String content) throws GitLabApiException { + return (gitLabApi.getProjectApi().createWikiPage(testProjectId, title, content)); + } + + @Test + public void testCreate() throws GitLabApiException { + String title = TEST_WIKI_TITLE_PREFIX + "Test createWikiPage()"; + WikiPage wikiPage = createWikiPage(title, testContent); + assertNotNull(wikiPage); + assertEquals(title, wikiPage.getTitle()); + assertEquals(testContent, wikiPage.getContent()); + } + + @Test + public void testUpdate() throws GitLabApiException { + String title = TEST_WIKI_TITLE_PREFIX + "Test createWikiPage()"; + WikiPage wikiPage = createWikiPage(title, testContent); + assertNotNull(wikiPage); + + title = TEST_WIKI_TITLE_PREFIX + "Test updateWikiPage()"; + wikiPage = gitLabApi.getProjectApi().updateWikiPage(testProjectId, wikiPage.getSlug(), title, "some content"); + assertEquals(title, wikiPage.getTitle()); + assertEquals("some content", wikiPage.getContent()); + } + + @Test + public void testListWikiPages() throws GitLabApiException { + String title = TEST_WIKI_TITLE_PREFIX + "Test listWikiPages()"; + WikiPage newWikiPage = createWikiPage(title, testContent); + assertNotNull(newWikiPage); + + String wikiPageSlug = newWikiPage.getSlug(); + List wikiPages = gitLabApi.getProjectApi().getWikiPages(testProjectId); + assertNotNull(wikiPages); + + wikiPages.stream().filter(wp -> wp.getSlug().equals(wikiPageSlug)).forEach(wp -> { + assertEquals(title, wp.getTitle()); + assertEquals(wikiPageSlug, wp.getSlug()); + }); + } + + @Test + public void testDeleteWikiPage() throws GitLabApiException { + String title = TEST_WIKI_TITLE_PREFIX + "Test listWikiPages()"; + WikiPage createdWikiPage = createWikiPage(title, testContent); + assertNotNull(createdWikiPage); + + String wikiPageSlug = createdWikiPage.getSlug(); + gitLabApi.getProjectApi().deleteWikiPage(testProjectId, wikiPageSlug); + List wikiPages = gitLabApi.getProjectApi().getWikiPages(testProjectId); + if (wikiPages.stream().anyMatch(wp -> wp.getSlug().equals(wikiPageSlug))) { + fail("WikiPage was not deleted."); + } + } + +} From 927ebc836743247d325c43b86af787c9def2e14a Mon Sep 17 00:00:00 2001 From: Alok Shukla Date: Tue, 5 Jun 2018 01:46:31 +0530 Subject: [PATCH 3/3] Separate WikisApi class for Wikis support #189 #191 --- src/main/java/org/gitlab4j/api/GitLabApi.java | 19 ++ .../java/org/gitlab4j/api/ProjectApi.java | 145 ++------------ src/main/java/org/gitlab4j/api/WikisApi.java | 177 ++++++++++++++++++ ...ProjectApiWikis.java => TestWikisApi.java} | 18 +- 4 files changed, 216 insertions(+), 143 deletions(-) create mode 100644 src/main/java/org/gitlab4j/api/WikisApi.java rename src/test/java/org/gitlab4j/api/{TestProjectApiWikis.java => TestWikisApi.java} (89%) diff --git a/src/main/java/org/gitlab4j/api/GitLabApi.java b/src/main/java/org/gitlab4j/api/GitLabApi.java index c7e765ed9..dc6450d0b 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApi.java +++ b/src/main/java/org/gitlab4j/api/GitLabApi.java @@ -72,6 +72,7 @@ public String getApiNamespace() { private NotesApi notesApi; private EventsApi eventsApi; private SnippetsApi snippetsApi; + private WikisApi wikisApi; /** * Get the GitLab4J shared Logger instance. @@ -1295,4 +1296,22 @@ public SnippetsApi getSnippetApi() { return snippetsApi; } + + /** + * Gets the WikisApi instance owned by this GitLabApi instance. The WikisApi is used to perform all wiki related API calls. + * + * @return the WikisApi instance owned by this GitLabApi instance + */ + public WikisApi getWikisApi() { + if (wikisApi == null) { + synchronized (this) { + if (wikisApi == null) { + wikisApi = new WikisApi(this); + } + } + } + + return wikisApi; + } + } diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index 13e60d89e..d2dce47fb 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -35,7 +35,17 @@ import javax.ws.rs.core.Response; import org.gitlab4j.api.GitLabApi.ApiVersion; -import org.gitlab4j.api.models.*; +import org.gitlab4j.api.models.AccessLevel; +import org.gitlab4j.api.models.Event; +import org.gitlab4j.api.models.FileUpload; +import org.gitlab4j.api.models.Issue; +import org.gitlab4j.api.models.Member; +import org.gitlab4j.api.models.Project; +import org.gitlab4j.api.models.ProjectHook; +import org.gitlab4j.api.models.ProjectUser; +import org.gitlab4j.api.models.PushRules; +import org.gitlab4j.api.models.Snippet; +import org.gitlab4j.api.models.Visibility; /** * This class provides an entry point to all the GitLab API project calls. @@ -1833,139 +1843,6 @@ public Optional getOptionalRawSnippetContent(Integer projectId, Integer } } - /** - * Get a list of pages in project wiki. This only returns the first page of wiki-pages. - * - * GET /projects/:id/wikis - * - * @param projectId the project ID to get the wiki-pages for - * @return a list of pages in the project's wiki - * @throws GitLabApiException if any exception occurs - */ - public List getWikiPages(Integer projectId) throws GitLabApiException { - return getWikiPages(projectId, 1, this.getDefaultPerPage()); - } - - /** - * Get a list of project snippets. This only returns the first page of snippets. - * - * GET /projects/:id/wikis - * - * @param projectId the project ID to get the wiki pages for - * @param page the page to get - * @param perPage the number of wiki-pages per page - * @return a list of pages in project's wiki for the specified range - * @throws GitLabApiException if any exception occurs - */ - public List getWikiPages(Integer projectId, int page, int perPage) throws GitLabApiException { - Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "wikis"); - return response.readEntity(new GenericType>() {}); - } - - /** - * Get a Pager of project's wiki pages. - * - * GET /projects/:id/wikis - * - * @param projectId the project ID to get the wiki-pages for - * @param itemsPerPage the number of wiki-pages per page - * @return the Pager of wiki-pages - * @throws GitLabApiException if any exception occurs - */ - public Pager getWikiPages(Integer projectId, int itemsPerPage) throws GitLabApiException { - return (new Pager<>(this, WikiPage.class, itemsPerPage, null, "projects", projectId, "wikis")); - } - - /** - * Get a single page of project wiki. - * - * GET /projects/:id/wikis/:slug - * - * @param projectId the project ID to get the wiki page for - * @param slug the slug of the project's wiki page - * @return the specified project Snippet - * @throws GitLabApiException if any exception occurs - */ - public WikiPage getWikiPage(Integer projectId, String slug) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "projects", projectId, "wikis", slug); - return (response.readEntity(WikiPage.class)); - } - - /** - * Get a single page of project wiki as an Optional instance. - * - * GET /projects/:id/wikis/:slug - * - * @param projectId the project ID to get the snippet for - * @param slug the slug of the project's wiki page - * @return the specified project Snippet as an Optional instance - */ - public Optional getOptionalWikiPage(Integer projectId, String slug) { - try { - return (Optional.ofNullable(getWikiPage(projectId, slug))); - } catch (GitLabApiException glae) { - return (GitLabApi.createOptionalFromException(glae)); - } - } - - /** - * Creates a new project wiki page. The user must have permission to create new wiki page. - * - * POST /projects/:id/wikis - * - * @param projectId the ID of the project owned by the authenticated user, required - * @param title the title of a snippet, required - * @param content the content of a wiki page, required - * @return a WikiPage instance with info on the created page - * @throws GitLabApiException if any exception occurs - */ - public WikiPage createWikiPage(Integer projectId, String title, String content) throws GitLabApiException { - // one of title or content is required - GitLabApiForm formData = new GitLabApiForm() - .withParam("title", title) - .withParam("content", content); - - Response response = post(Response.Status.CREATED, formData, "projects", projectId, "wikis"); - return (response.readEntity(WikiPage.class)); - } - - /** - * Updates an existing project wiki page. The user must have permission to change an existing wiki page. - * - * PUT /projects/:id/wikis/:slug - * - * @param projectId the ID of the project owned by the authenticated user, required - * @param slug the slug of the project's wiki page, required - * @param title the title of a snippet, optional - * @param content the content of a page, optional. Either title or content must be supplied. - * @return a WikiPage instance with info on the updated page - * @throws GitLabApiException if any exception occurs - */ - public WikiPage updateWikiPage(Integer projectId, String slug, String title, String content) throws GitLabApiException { - - GitLabApiForm formData = new GitLabApiForm() - .withParam("title", title) - .withParam("slug", slug, true) - .withParam("content", content); - - Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "wikis", slug); - return (response.readEntity(WikiPage.class)); - } - - /** - * Deletes an existing project wiki page. This is an idempotent function and deleting a non-existent page does - * not cause an error. - * - * DELETE /projects/:id/wikis/:slug - * - * @param projectId the project ID - * @param slug the slug of the project's wiki page - * @throws GitLabApiException if any exception occurs - */ - public void deleteWikiPage(Integer projectId, String slug) throws GitLabApiException { - delete(Response.Status.NO_CONTENT, null, "projects", projectId, "wikis", slug); - } - /** * Share a project with the specified group. * diff --git a/src/main/java/org/gitlab4j/api/WikisApi.java b/src/main/java/org/gitlab4j/api/WikisApi.java new file mode 100644 index 000000000..7c6f2c620 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/WikisApi.java @@ -0,0 +1,177 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2017 Greg Messner + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.gitlab4j.api; + +import org.gitlab4j.api.models.WikiPage; + +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; +import java.util.List; +import java.util.Optional; + +/** + * @author shuklaalok7 (alok@clay.fish) + * @since v4.8.21 2018-06-5 1:26 AM IST + */ +public class WikisApi extends AbstractApi { + + + public WikisApi(GitLabApi gitLabApi) { + super(gitLabApi); + } + + /** + * Get a list of pages in project wiki. This only returns the first page of wiki-pages. + * + * GET /projects/:id/wikis + * + * @param projectId the project ID to get the wiki-pages for + * @return a list of pages in the project's wiki + * @throws GitLabApiException if any exception occurs + */ + public List getPages(Integer projectId) throws GitLabApiException { + return getPages(projectId, 1, this.getDefaultPerPage()); + } + + /** + * Get a list of project snippets. This only returns the first page of snippets. + * + * GET /projects/:id/wikis + * + * @param projectId the project ID to get the wiki pages for + * @param page the page to get + * @param perPage the number of wiki-pages per page + * @return a list of pages in project's wiki for the specified range + * @throws GitLabApiException if any exception occurs + */ + public List getPages(Integer projectId, int page, int perPage) throws GitLabApiException { + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "wikis"); + return response.readEntity(new GenericType>() {}); + } + + /** + * Get a Pager of project's wiki pages. + * + * GET /projects/:id/wikis + * + * @param projectId the project ID to get the wiki-pages for + * @param itemsPerPage the number of wiki-pages per page + * @return the Pager of wiki-pages + * @throws GitLabApiException if any exception occurs + */ + public Pager getPages(Integer projectId, int itemsPerPage) throws GitLabApiException { + return (new Pager<>(this, WikiPage.class, itemsPerPage, null, "projects", projectId, "wikis")); + } + + /** + * Get a single page of project wiki. + * + * GET /projects/:id/wikis/:slug + * + * @param projectId the project ID to get the wiki page for + * @param slug the slug of the project's wiki page + * @return the specified project Snippet + * @throws GitLabApiException if any exception occurs + */ + public WikiPage getPage(Integer projectId, String slug) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "projects", projectId, "wikis", slug); + return (response.readEntity(WikiPage.class)); + } + + /** + * Get a single page of project wiki as an Optional instance. + * + * GET /projects/:id/wikis/:slug + * + * @param projectId the project ID to get the snippet for + * @param slug the slug of the project's wiki page + * @return the specified project Snippet as an Optional instance + */ + public Optional getOptionalPage(Integer projectId, String slug) { + try { + return (Optional.ofNullable(getPage(projectId, slug))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } + + /** + * Creates a new project wiki page. The user must have permission to create new wiki page. + * + * POST /projects/:id/wikis + * + * @param projectId the ID of the project owned by the authenticated user, required + * @param title the title of a snippet, required + * @param content the content of a wiki page, required + * @return a WikiPage instance with info on the created page + * @throws GitLabApiException if any exception occurs + */ + public WikiPage createPage(Integer projectId, String title, String content) throws GitLabApiException { + // one of title or content is required + GitLabApiForm formData = new GitLabApiForm() + .withParam("title", title) + .withParam("content", content); + + Response response = post(Response.Status.CREATED, formData, "projects", projectId, "wikis"); + return (response.readEntity(WikiPage.class)); + } + + /** + * Updates an existing project wiki page. The user must have permission to change an existing wiki page. + * + * PUT /projects/:id/wikis/:slug + * + * @param projectId the ID of the project owned by the authenticated user, required + * @param slug the slug of the project's wiki page, required + * @param title the title of a snippet, optional + * @param content the content of a page, optional. Either title or content must be supplied. + * @return a WikiPage instance with info on the updated page + * @throws GitLabApiException if any exception occurs + */ + public WikiPage updatePage(Integer projectId, String slug, String title, String content) throws GitLabApiException { + + GitLabApiForm formData = new GitLabApiForm() + .withParam("title", title) + .withParam("slug", slug, true) + .withParam("content", content); + + Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "wikis", slug); + return (response.readEntity(WikiPage.class)); + } + + /** + * Deletes an existing project wiki page. This is an idempotent function and deleting a non-existent page does + * not cause an error. + * + * DELETE /projects/:id/wikis/:slug + * + * @param projectId the project ID + * @param slug the slug of the project's wiki page + * @throws GitLabApiException if any exception occurs + */ + public void deletePage(Integer projectId, String slug) throws GitLabApiException { + delete(Response.Status.NO_CONTENT, null, "projects", projectId, "wikis", slug); + } + +} diff --git a/src/test/java/org/gitlab4j/api/TestProjectApiWikis.java b/src/test/java/org/gitlab4j/api/TestWikisApi.java similarity index 89% rename from src/test/java/org/gitlab4j/api/TestProjectApiWikis.java rename to src/test/java/org/gitlab4j/api/TestWikisApi.java index b485716ef..b159da730 100644 --- a/src/test/java/org/gitlab4j/api/TestProjectApiWikis.java +++ b/src/test/java/org/gitlab4j/api/TestWikisApi.java @@ -46,7 +46,7 @@ *

* If any of the above are NULL, all tests in this class will be skipped. */ -public class TestProjectApiWikis { +public class TestWikisApi { // The following needs to be set to your test repository private static final String TEST_NAMESPACE; @@ -65,7 +65,7 @@ public class TestProjectApiWikis { TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); } - public TestProjectApiWikis() { + public TestWikisApi() { super(); } @@ -114,10 +114,10 @@ public static void teardown() throws GitLabApiException { private static void deleteAllTestWikiPages() { if (gitLabApi != null) { try { - List wikiPages = gitLabApi.getProjectApi().getWikiPages(testProjectId); + List wikiPages = gitLabApi.getWikisApi().getPages(testProjectId); wikiPages.stream().filter(wp -> wp.getTitle().startsWith(TEST_WIKI_TITLE_PREFIX)).map(WikiPage::getSlug).forEach(slug -> { try { - gitLabApi.getProjectApi().deleteWikiPage(testProjectId, slug); + gitLabApi.getWikisApi().deletePage(testProjectId, slug); } catch (GitLabApiException ignored) { } }); @@ -133,7 +133,7 @@ public void beforeMethod() { } private WikiPage createWikiPage(String title, String content) throws GitLabApiException { - return (gitLabApi.getProjectApi().createWikiPage(testProjectId, title, content)); + return (gitLabApi.getWikisApi().createPage(testProjectId, title, content)); } @Test @@ -152,7 +152,7 @@ public void testUpdate() throws GitLabApiException { assertNotNull(wikiPage); title = TEST_WIKI_TITLE_PREFIX + "Test updateWikiPage()"; - wikiPage = gitLabApi.getProjectApi().updateWikiPage(testProjectId, wikiPage.getSlug(), title, "some content"); + wikiPage = gitLabApi.getWikisApi().updatePage(testProjectId, wikiPage.getSlug(), title, "some content"); assertEquals(title, wikiPage.getTitle()); assertEquals("some content", wikiPage.getContent()); } @@ -164,7 +164,7 @@ public void testListWikiPages() throws GitLabApiException { assertNotNull(newWikiPage); String wikiPageSlug = newWikiPage.getSlug(); - List wikiPages = gitLabApi.getProjectApi().getWikiPages(testProjectId); + List wikiPages = gitLabApi.getWikisApi().getPages(testProjectId); assertNotNull(wikiPages); wikiPages.stream().filter(wp -> wp.getSlug().equals(wikiPageSlug)).forEach(wp -> { @@ -180,8 +180,8 @@ public void testDeleteWikiPage() throws GitLabApiException { assertNotNull(createdWikiPage); String wikiPageSlug = createdWikiPage.getSlug(); - gitLabApi.getProjectApi().deleteWikiPage(testProjectId, wikiPageSlug); - List wikiPages = gitLabApi.getProjectApi().getWikiPages(testProjectId); + gitLabApi.getWikisApi().deletePage(testProjectId, wikiPageSlug); + List wikiPages = gitLabApi.getWikisApi().getPages(testProjectId); if (wikiPages.stream().anyMatch(wp -> wp.getSlug().equals(wikiPageSlug))) { fail("WikiPage was not deleted."); }