Commit 485f341b authored by Greg Messner's avatar Greg Messner
Browse files

Added stopEnvironment()

No related merge requests found
Showing with 28 additions and 10 deletions
+28 -10
...@@ -129,6 +129,22 @@ public class EnvironmentsApi extends AbstractApi { ...@@ -129,6 +129,22 @@ public class EnvironmentsApi extends AbstractApi {
return (response.readEntity(Environment.class)); return (response.readEntity(Environment.class));
} }
/**
* Stop an environment.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/environments/:environment_id/stop</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param environmentId the ID of the environment to stop
* @return the stopped Environment instance
* @throws GitLabApiException if any exception occurs
*/
public Environment stopEnvironment(Object projectIdOrPath, Integer environmentId) throws GitLabApiException {
Response response = post(Response.Status.OK, (GitLabApiForm) null,
"projects", getProjectIdOrPath(projectIdOrPath), "environments", environmentId, "stop");
return (response.readEntity(Environment.class));
}
/** /**
* Delete an environment. * Delete an environment.
* *
......
...@@ -67,11 +67,14 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest { ...@@ -67,11 +67,14 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
for (Environment env : envs) { for (Environment env : envs) {
if (env.getName().startsWith(ENVIRONMENT_NAME)) { if (env.getName().startsWith(ENVIRONMENT_NAME)) {
gitLabApi.getEnvironmentsApi().stopEnvironment(testProject, env.getId());
gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId()); gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId());
} }
} }
} }
} catch (GitLabApiException ignore) { } catch (GitLabApiException ignore) {
System.out.println("ERROR");
} }
} }
} }
...@@ -91,23 +94,21 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest { ...@@ -91,23 +94,21 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment( final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment(
testProject, getUniqueName(), EXTERNAL_URL); testProject, getUniqueName(), EXTERNAL_URL);
try { List<Environment> envs = gitLabApi.getEnvironmentsApi().getEnvironments(testProject);
List<Environment> envs = gitLabApi.getEnvironmentsApi().getEnvironments(testProject); assertTrue(envs.size() > 0);
assertTrue(envs.size() > 0); Environment foundEnv = envs.stream().filter(
Environment foundEnv = envs.stream().filter(
e -> e.getName().equals(env.getName())).findFirst().orElse(null); e -> e.getName().equals(env.getName())).findFirst().orElse(null);
assertNotNull(foundEnv); assertNotNull(foundEnv);
assertEquals(env.getName(), foundEnv.getName()); assertEquals(env.getName(), foundEnv.getName());
} catch (Exception e) {
gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId());
}
} }
@Test @Test
public void testDeleteEnvironment() throws GitLabApiException { public void testStopAndDeleteEnvironment() throws GitLabApiException {
final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment( final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment(
testProject, getUniqueName(), EXTERNAL_URL); testProject, getUniqueName(), EXTERNAL_URL);
gitLabApi.getEnvironmentsApi().stopEnvironment(testProject, env.getId());
gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId()); gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId());
Stream<Environment> envs = gitLabApi.getEnvironmentsApi().getEnvironmentsStream(testProject); Stream<Environment> envs = gitLabApi.getEnvironmentsApi().getEnvironmentsStream(testProject);
...@@ -125,6 +126,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest { ...@@ -125,6 +126,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
assertTrue(optionalEnv.isPresent()); assertTrue(optionalEnv.isPresent());
assertEquals(env.getName(), optionalEnv.get().getName()); assertEquals(env.getName(), optionalEnv.get().getName());
gitLabApi.getEnvironmentsApi().stopEnvironment(testProject, env.getId());
gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId()); gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId());
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment