-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1253 EnableRepoIssues implemented and tested
- Loading branch information
1 parent
c596aaa
commit 5af1fe2
Showing
3 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
self-core-impl/src/main/java/com/selfxdsd/core/managers/EnableRepoIssues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
self-core-impl/src/test/java/com/selfxdsd/core/managers/EnableRepoIssuesTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
5af1fe2
There was a problem hiding this comment.
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.