-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For #76: Exec register error tests. #79
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
61291e3
For #76: Exec register error tests.
paulodamaso 4c46002
For #76: Todo text correction.
paulodamaso 4580642
For #76: Added todo for as xembly and delete implementation.
paulodamaso 3426ed0
Merge remote-tracking branch 'remotes/upstream/master' into 76
paulodamaso f2ce7b9
For #76: Exception removal.
paulodamaso 9470856
For #76: Merging master.
paulodamaso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import com.jcabi.log.Logger; | ||
import com.jcabi.manifests.Manifests; | ||
import io.sentry.Sentry; | ||
import io.wring.model.Errors; | ||
import io.wring.model.Events; | ||
import io.wring.model.Pipe; | ||
import java.io.ByteArrayOutputStream; | ||
|
@@ -52,14 +53,20 @@ | |
* One execution. | ||
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @author Paulo Lobo ([email protected]) | ||
* @version $Id$ | ||
* @since 0.13 | ||
* @todo #72:30min Errors occurred during execution must be saved and later | ||
* @todo #76:30min Errors occurred during execution must be saved and later | ||
* listed to user in a page. User should be able to mark errors as `read` | ||
* in this page. Wire Error and Errors implementations in Exec flow so | ||
* these errors are properly saved once they happen. Cover this with tests. | ||
* these errors are properly saved once they happen and remove | ||
* Exec(final Agent agt, final Events evt, final Pipe ppe) constructor so | ||
* errors is injected in Exec every time. Then remove Singularfield and | ||
* UnusedPrivateField check ignores below and uncomment tests for error | ||
* registering in ExecTest.registerErrors. | ||
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines) | ||
*/ | ||
@SuppressWarnings({"PMD.SingularField", "PMD.UnusedPrivateField"}) | ||
final class Exec { | ||
|
||
/** | ||
|
@@ -77,16 +84,34 @@ final class Exec { | |
*/ | ||
private final transient Pipe pipe; | ||
|
||
/** | ||
* Errors. | ||
*/ | ||
private final Errors errors; | ||
|
||
/** | ||
* Ctor. | ||
* @param agt Agent | ||
* @param evt Events | ||
* @param ppe Pipe | ||
*/ | ||
Exec(final Agent agt, final Events evt, final Pipe ppe) { | ||
this(agt, evt, ppe, new Errors.Simple()); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param agt Agent | ||
* @param evt Events | ||
* @param ppe Pipe | ||
* @param err Errors | ||
* @checkstyle ParameterNumberCheck (2 lines) | ||
*/ | ||
Exec(final Agent agt, final Events evt, final Pipe ppe, final Errors err) { | ||
this.agent = agt; | ||
this.events = evt; | ||
this.pipe = ppe; | ||
this.errors = err; | ||
} | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -53,4 +53,40 @@ public interface Error { | |
* @throws IOException If fails | ||
*/ | ||
void delete() throws IOException; | ||
|
||
/** | ||
* Simple Error implementation. | ||
*/ | ||
final class Simple implements Error { | ||
|
||
/** | ||
* Error title. | ||
*/ | ||
private final String title; | ||
|
||
/** | ||
* Error description. | ||
*/ | ||
private final String description; | ||
|
||
/** | ||
* Constructor. | ||
* @param title Title | ||
* @param description Description | ||
*/ | ||
public Simple(final String title, final String description) { | ||
this.title = title; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public Iterable<Directive> asXembly() throws IOException { | ||
throw new UnsupportedOperationException("not implemented"); | ||
} | ||
|
||
@Override | ||
public void delete() throws IOException { | ||
throw new UnsupportedOperationException("delete() not implemented"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulodamaso let's add a puzzle for the implementation of this method |
||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
package io.wring.model; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Errors. | ||
|
@@ -57,4 +59,32 @@ public interface Errors { | |
* @throws IOException If fails | ||
*/ | ||
void register(String title, String description); | ||
|
||
/** | ||
* Simple implementation of Error repo. | ||
*/ | ||
final class Simple implements Errors { | ||
|
||
/** | ||
* Errors. | ||
*/ | ||
private final Collection<Error> errors; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public Simple() { | ||
this.errors = new ArrayList<>(0); | ||
} | ||
|
||
@Override | ||
public Iterable<Error> iterate() throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulodamaso let's remove the exception here |
||
return this.errors; | ||
} | ||
|
||
@Override | ||
public void register(final String title, final String description) { | ||
this.errors.add(new Error.Simple(title, description)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -30,16 +30,22 @@ | |
package io.wring.agents; | ||
|
||
import io.wring.fake.FkPipe; | ||
import io.wring.model.Errors; | ||
import io.wring.model.Events; | ||
import java.io.IOException; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.hamcrest.collection.IsIterableWithSize; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.mockito.hamcrest.MockitoHamcrest; | ||
|
||
/** | ||
* Test case for {@link Exec}. | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @author Paulo Lobo ([email protected]) | ||
* @version $Id$ | ||
* @since 0.13 | ||
*/ | ||
|
@@ -69,4 +75,25 @@ public void catchesExceptions() throws Exception { | |
); | ||
} | ||
|
||
/** | ||
* Exec can register an error. | ||
* @throws Exception If some problem inside | ||
*/ | ||
@Test | ||
@Ignore | ||
public void registerErrors() throws Exception { | ||
final Agent agent = Mockito.mock(Agent.class); | ||
final Events events = Mockito.mock(Events.class); | ||
final Errors errors = new Errors.Simple(); | ||
Mockito.doThrow(new IOException("<error>")).when(agent).push(events); | ||
new Exec(agent, events, new FkPipe(), errors).run(); | ||
MatcherAssert.assertThat( | ||
"Could not register error", | ||
errors.iterate(), | ||
new IsIterableWithSize<>( | ||
new IsEqual<>(1) | ||
) | ||
); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@paulodamaso let's add a puzzle for the implementation of this method