Skip to content

Commit

Permalink
#1253 EnableRepoIssues implemented and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 16, 2021
1 parent c596aaa commit 5af1fe2
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core.managers;

import com.selfxdsd.api.Event;
import com.selfxdsd.api.Project;
import com.selfxdsd.api.pm.Intermediary;
import com.selfxdsd.api.pm.Step;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Enable Issues in the Project's Repo. We will move on to the next Step even
* if the operation fails, because most Repos have the Issues enabled anyway.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.95
*/
public final class EnableRepoIssues extends Intermediary {

/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(
EnableRepoIssues.class
);

/**
* Ctor.
* @param next The next step to perform.
*/
public EnableRepoIssues(final Step next) {
super(next);
}

@Override
public void perform(final Event event) {
final Project project = event.project();
final String repoFullName = project.repoFullName();
final String provider = project.provider();
LOG.debug(
"Enabling Issues for Repo " + repoFullName
+ " at " + provider + "... "
);
try {
project.repo().enableIssues();
LOG.debug("Issues successfully enabled.");
} catch (final IllegalStateException ex) {
LOG.error(
"Could not enable Issues for Repo " + repoFullName + " at "
+ provider + ". Exception is: " + ex.getMessage()
);
}
this.next().perform(event);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.13
* @todo #1246:60min Implement an Intermediary Step used to enable Issues for
* a Repo, when it is being activated.
*/
public final class InvitePm extends Intermediary {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core.managers;

import com.selfxdsd.api.Event;
import com.selfxdsd.api.Issues;
import com.selfxdsd.api.Project;
import com.selfxdsd.api.Repo;
import com.selfxdsd.api.pm.Step;
import org.junit.Test;
import org.mockito.Mockito;

/**
* Unit tests for {@link EnableRepoIssues}.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.95
*/
public final class EnableRepoIssuesTestCase {

/**
* EnableRepoIssues enables the Issues without problems and moves on to
* the next Step.
*/
@Test
public void enablesIssuesOk() {
final Project project = Mockito.mock(Project.class);
final Event event = Mockito.mock(Event.class);
Mockito.when(event.project()).thenReturn(project);

final Repo repo = Mockito.mock(Repo.class);
Mockito.when(repo.enableIssues()).thenReturn(
Mockito.mock(Issues.class)
);
Mockito.when(project.repo()).thenReturn(repo);

final Step next = Mockito.mock(Step.class);
final Step setup = new EnableRepoIssues(next);
setup.perform(event);

Mockito.verify(repo, Mockito.times(1))
.enableIssues();
Mockito.verify(next, Mockito.times(1))
.perform(event);
}

/**
* EnableRepoIssues moves on to the next Step even if Repo.enableIssues()
* throws an IllegalStateException.
*/
@Test
public void enableIssuesThrowsIllegalStateException() {
final Project project = Mockito.mock(Project.class);
final Event event = Mockito.mock(Event.class);
Mockito.when(event.project()).thenReturn(project);

final Repo repo = Mockito.mock(Repo.class);
Mockito.when(repo.enableIssues()).thenThrow(
new IllegalStateException("Enabling of Issues failed.")
);
Mockito.when(project.repo()).thenReturn(repo);

final Step next = Mockito.mock(Step.class);
final Step setup = new EnableRepoIssues(next);
setup.perform(event);

Mockito.verify(repo, Mockito.times(1))
.enableIssues();
Mockito.verify(next, Mockito.times(1))
.perform(event);
}
}

1 comment on commit 5af1fe2

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amihaiemil I've closed the Issues [#1253] since their to-dos disappeared from the code.

The to-dos may have been removed in an earlier commit, but I've found it just now.

Please sign in to comment.