Separated Endpoint related objects from bigger PR#25
Conversation
MoonBow-1
left a comment
There was a problem hiding this comment.
Besides the comments, endpoint tests seem to be extending AbstractNotebookServerTest, abstracting a lot of behavior behind the inheritance.
Also the tests seem to be integration tests, where the AbstractNotebookServerTest makes actual HTTP requests to the endpoints, instead of creating HTTPRequest parameters to the methods that are tested.
| import java.util.Objects; | ||
|
|
||
| // Finds a given Directory and returns its own name and the names of its children in JSON format based on a given Identifier. | ||
| public final class FindDirectoryEndPoint implements HTTPEndPoint { |
There was a problem hiding this comment.
Typo in the class/file name, should be FindDirectoryEndpoint
| // Interface for a Delegate, that inspects a Request object, and returns either a true or a false value according to implementation details. | ||
| public abstract interface Delegate { | ||
|
|
||
| public abstract boolean resolve(HTTPRequest request); |
| import com.teragrep.nbs_01.protocols.http.HTTPResponse; | ||
|
|
||
| // Endpoint that delegates the request to one of a collection of Endpoints based on the result of a Delegate | ||
| public class DelegatingEndpoint implements HTTPEndPoint { |
| public DoAllKeysExistDelegate(final String key) { | ||
| this.keys = Arrays.asList(key); | ||
| } | ||
|
|
||
| public DoAllKeysExistDelegate(final List<String> keys) { | ||
| this.keys = keys; | ||
| } |
There was a problem hiding this comment.
This should be the primary constructor:
public DoAllKeysExistDelegate(final List<String> keys) {
this.keys = keys;
}Secondary constructor be changed from:
public DoAllKeysExistDelegate(final String key) {
this.keys = Arrays.asList(key);
}to:
public DoAllKeysExistDelegate(final String key) {
this(
Collections.singletonList(key)
);
}This also changes the static method used to create the List from Arrays.asList to Collections.singletonList. The singletonList method returns an immutable List instead of an modifiable List that the asList method returns.
| try { | ||
| title = request.title(); | ||
| } | ||
| catch (MalformedRequestException e) { |
This PR is separated from #4 to make code review more manageable.
Note that this PR by itself will likely contain references to objects that are not present in this PR. Please refer to PR #4, which contains all objects, in case you need to see how some objects interact.
This PR contains endpoint objects, which define what procedures nbs_01 executes when a request for some operation is received.
closes #19