forked from ngs-doo/dsl-compiler-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RegisterUser and CreateProject to core requests.
- Loading branch information
Marin Vila
committed
Mar 7, 2014
1 parent
f1c51e9
commit 047ad80
Showing
8 changed files
with
277 additions
and
33 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
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
62 changes: 62 additions & 0 deletions
62
.../java/com/dslplatform/compiler/client/api/core/mock/processor/CreateProjectProcessor.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,62 @@ | ||
package com.dslplatform.compiler.client.api.core.mock.processor; | ||
|
||
import com.dslplatform.compiler.client.api.core.HttpRequest; | ||
import com.dslplatform.compiler.client.api.core.HttpRequest.Method; | ||
import com.dslplatform.compiler.client.api.core.HttpResponse; | ||
import com.dslplatform.compiler.client.api.core.impl.JsonReader; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.Charset; | ||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CreateProjectProcessor implements MockProcessor { | ||
@Override | ||
public boolean isDefinedAt(final HttpRequest request) { | ||
return request.method == Method.POST && request.path.equals("Domain.svc/submit/Client.CreteProject"); | ||
} | ||
|
||
private static final Charset ENCODING = Charset.forName("UTF-8"); | ||
|
||
@Override | ||
public HttpResponse apply(final HttpRequest request) throws IOException { | ||
final Map<String, String> map; | ||
{ | ||
final JsonReader jr = | ||
new JsonReader(new InputStreamReader(new ByteArrayInputStream(request.body), ENCODING)); | ||
map = jr.readMap(); | ||
} | ||
|
||
final String projectNick = map.get("ProjectNick"); | ||
|
||
final int code; | ||
final byte[] body; | ||
|
||
final boolean nameingFailure = | ||
!projectNick.contains("!"); | ||
final boolean abstence = | ||
projectNick.equals(""); | ||
|
||
final Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>(); | ||
|
||
if (abstence) { | ||
code = 400; | ||
body = "Project name not provided.".getBytes(ENCODING); | ||
headers.put("Content-Type", Arrays.asList("text/plain; charset=\"utf-8\"")); | ||
} else if (nameingFailure) { | ||
code = 403; | ||
body = "Parse error - encountered an exclamation mark!".getBytes(ENCODING); | ||
headers.put("Content-Type", Arrays.asList("text/plain; charset=\"utf-8\"")); | ||
} else { | ||
code = 200; | ||
body = new byte[0]; | ||
} | ||
|
||
headers.put("Content-Length", Arrays.asList(String.valueOf(body.length))); | ||
return new HttpResponse(code, headers, body); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...t/java/com/dslplatform/compiler/client/api/core/mock/processor/RegisterUserProcessor.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,62 @@ | ||
package com.dslplatform.compiler.client.api.core.mock.processor; | ||
|
||
import com.dslplatform.compiler.client.api.core.HttpRequest; | ||
import com.dslplatform.compiler.client.api.core.HttpRequest.Method; | ||
import com.dslplatform.compiler.client.api.core.HttpResponse; | ||
import com.dslplatform.compiler.client.api.core.impl.JsonReader; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.Charset; | ||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RegisterUserProcessor implements MockProcessor { | ||
@Override | ||
public boolean isDefinedAt(final HttpRequest request) { | ||
return request.method == Method.POST && request.path.equals("Domain.svc/submit/Client.RegisterUser"); | ||
} | ||
|
||
private static final Charset ENCODING = Charset.forName("UTF-8"); | ||
|
||
@Override | ||
public HttpResponse apply(final HttpRequest request) throws IOException { | ||
final Map<String, String> map; | ||
{ | ||
final JsonReader jr = | ||
new JsonReader(new InputStreamReader(new ByteArrayInputStream(request.body), ENCODING)); | ||
map = jr.readMap(); | ||
} | ||
|
||
final String email = map.get("Email"); | ||
|
||
final int code; | ||
final byte[] body; | ||
|
||
final boolean notPermitted = | ||
!email.equals("super@user.org"); | ||
final boolean abstence = | ||
email.equals(""); | ||
|
||
final Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>(); | ||
|
||
if (abstence) { | ||
code = 400; | ||
body = "Project name not provided.".getBytes(ENCODING); | ||
headers.put("Content-Type", Arrays.asList("text/plain; charset=\"utf-8\"")); | ||
} else if (notPermitted) { | ||
code = 403; | ||
body = "You don't have authorization to perform requested action: Missing permission for user registration".getBytes(ENCODING); | ||
headers.put("Content-Type", Arrays.asList("text/plain; charset=\"utf-8\"")); | ||
} else { | ||
code = 200; | ||
body = new byte[0]; | ||
} | ||
|
||
headers.put("Content-Length", Arrays.asList(String.valueOf(body.length))); | ||
return new HttpResponse(code, headers, body); | ||
} | ||
} |
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
Oops, something went wrong.