This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4254e1a
commit 8294c2d
Showing
9 changed files
with
502 additions
and
6 deletions.
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
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,135 @@ | ||
/** | ||
* Copyright (c) 2017, Mihai Emil Andronache | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* 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.amihaiemil.versioneye; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonArray; | ||
import javax.json.JsonArrayBuilder; | ||
import javax.json.JsonObject; | ||
import javax.json.JsonValue; | ||
|
||
/** | ||
* Mock user sign-up form. | ||
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0.0 | ||
*/ | ||
final class MkNewUser implements NewUser { | ||
|
||
/** | ||
* VersionEye server. | ||
*/ | ||
private MkServer server; | ||
|
||
/** | ||
* This user as JsonObject. | ||
*/ | ||
private JsonObject json; | ||
|
||
/** | ||
* Ctor. | ||
* @param server VersionEye server. | ||
*/ | ||
MkNewUser(final MkServer server) { | ||
this(server, Json.createObjectBuilder().build()); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param server VersionEye server. | ||
* @param newUser The new user as json. | ||
*/ | ||
MkNewUser(final MkServer server, final JsonObject newUser) { | ||
this.server = server; | ||
this.json = newUser; | ||
} | ||
|
||
@Override | ||
public String fullName() { | ||
return this.json.getString("fullname"); | ||
} | ||
|
||
@Override | ||
public String username() { | ||
return this.json.getString("username"); | ||
} | ||
|
||
@Override | ||
public JsonObject json() { | ||
return this.json; | ||
} | ||
|
||
@Override | ||
public NewUser fullName(final String fullName) { | ||
final String username = this.json.getString("username", ""); | ||
final JsonObject edited; | ||
if(username.isEmpty()) { | ||
edited = Json | ||
.createObjectBuilder() | ||
.add("fullname", fullName) | ||
.build(); | ||
} else { | ||
edited = Json | ||
.createObjectBuilder() | ||
.add("username", username) | ||
.add("fullname", fullName) | ||
.build(); | ||
} | ||
return new MkNewUser(this.server, edited); | ||
} | ||
|
||
@Override | ||
public NewUser username(final String username) { | ||
final JsonObject edited = Json | ||
.createObjectBuilder() | ||
.add("username", username) | ||
.add("fullname", this.json.getString("fullname", "")) | ||
.build(); | ||
return new MkNewUser(this.server, edited); | ||
} | ||
|
||
@Override | ||
public User signUp() { | ||
final JsonArray registered = this.server.storage().build() | ||
.getJsonArray("users"); | ||
final JsonArrayBuilder users = Json.createArrayBuilder(); | ||
for(final JsonValue user: registered) { | ||
users.add(user); | ||
} | ||
users.add( | ||
Json.createObjectBuilder() | ||
.add( | ||
this.json.getString("username"), | ||
this.json | ||
) | ||
); | ||
this.server.storage().add("users", users.build()); | ||
return new MkUser(this.server, this.json.getString("username")); | ||
} | ||
|
||
} |
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,120 @@ | ||
package com.amihaiemil.versioneye; | ||
|
||
/** | ||
* Copyright (c) 2017, Mihai Emil Andronache | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* 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. | ||
*/ | ||
import java.io.IOException; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonArray; | ||
import javax.json.JsonObject; | ||
|
||
/** | ||
* A mock VersionEye user. | ||
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0.0 | ||
* | ||
*/ | ||
final class MkUser implements User { | ||
|
||
/** | ||
* VersionEye server. | ||
*/ | ||
private MkServer server; | ||
|
||
/** | ||
* This user's username. | ||
*/ | ||
private String username; | ||
|
||
/** | ||
* Ctor. | ||
* @param server VersionEye server storage. | ||
* @param username The user's username. | ||
*/ | ||
MkUser(final MkServer server, final String username) { | ||
this.server = server; | ||
this.username = username; | ||
} | ||
|
||
@Override | ||
public UserData about() throws IOException { | ||
UserData about = null; | ||
final JsonArray online = this.server.storage().build() | ||
.getJsonArray("authenticated"); | ||
for(int idx = 0; idx < online.size(); idx++) { | ||
final JsonObject authenticated = online.getJsonObject(idx); | ||
if(authenticated.getJsonObject(this.username) != null) { | ||
about = new JsonUserData( | ||
Json.createObjectBuilder() | ||
.add( | ||
"fullname", | ||
authenticated.getJsonObject(this.username) | ||
.getString("fullname") | ||
).add( | ||
"username", | ||
authenticated.getJsonObject(this.username) | ||
.getString("username") | ||
) | ||
.build() | ||
); | ||
} | ||
} | ||
final JsonArray users = this.server.storage().build() | ||
.getJsonArray("users"); | ||
for(int idx = 0; idx < users.size(); idx++) { | ||
final JsonObject user = users.getJsonObject(idx); | ||
if(user.getJsonObject(this.username) != null) { | ||
about = new JsonUserData( | ||
user.getJsonObject(this.username) | ||
); | ||
} | ||
} | ||
if(about == null) { | ||
throw new IllegalStateException( | ||
"User " + this.username + " not found." | ||
+ " You have to register it first, " | ||
+ "or it has to be the authenticated user." | ||
); | ||
} | ||
return about; | ||
} | ||
|
||
@Override | ||
public Comments comments() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public Favorites favorites() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
} |
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,62 @@ | ||
/** | ||
* Copyright (c) 2017, Mihai Emil Andronache | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* 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.amihaiemil.versioneye; | ||
|
||
/** | ||
* Mock of VersionEye's Users API. | ||
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0.0 | ||
* | ||
*/ | ||
final class MkUsers implements Users { | ||
|
||
/** | ||
* VersionEye server. | ||
*/ | ||
private MkServer server; | ||
|
||
/** | ||
* Ctor. | ||
* @param server VersionEye server storage. | ||
*/ | ||
MkUsers(final MkServer server) { | ||
this.server = server; | ||
} | ||
|
||
@Override | ||
public User user(final String username) { | ||
return new MkUser(this.server, username); | ||
} | ||
|
||
@Override | ||
public NewUser register() { | ||
return new MkNewUser(this.server); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -39,9 +39,8 @@ | |
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 1.0.0 | ||
* @todo #13:30min/DEV Continue implementing the mock API. | ||
* Mocks for Users, Organizations Teams etc are needed. This puzzle | ||
* was readded after being removed by mistake. | ||
* @todo #72:30min/DEV Continue implementing the mock API. | ||
* Mocks for Organizations, Teams etc are needed. | ||
*/ | ||
public final class MkVersionEye implements VersionEye { | ||
|
||
|
@@ -61,6 +60,7 @@ public final class MkVersionEye implements VersionEye { | |
public MkVersionEye() { | ||
this.server = new MkJsonServer(); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param authenticated Mock Authenticated User. | ||
|
@@ -89,7 +89,7 @@ public Services services() { | |
|
||
@Override | ||
public Users users() { | ||
return null; | ||
return new MkUsers(this.server); | ||
} | ||
|
||
@Override | ||
|
@@ -107,7 +107,7 @@ public Me me() { | |
* @param authenticated The user to authenticate. | ||
*/ | ||
private void authenticate(final Authenticated authenticated) { | ||
JsonArray online = this.server.storage().build() | ||
final JsonArray online = this.server.storage().build() | ||
.getJsonArray("authenticated"); | ||
final JsonArrayBuilder users = Json.createArrayBuilder(); | ||
for(final JsonValue user: online) { | ||
|
Oops, something went wrong.
8294c2d
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.
Puzzle
13-9719886d
disappeared insrc/main/java/com/amihaiemil/versioneye/MkVersionEye.java
, that's why I closed #72.8294c2d
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.
Puzzle
72-33f7b683
discovered insrc/main/java/com/amihaiemil/versioneye/MkVersionEye.java
and submitted as #108.