-
Notifications
You must be signed in to change notification settings - Fork 254
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
8735230
commit 0167a69
Showing
21 changed files
with
237 additions
and
111 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,25 @@ | ||
package net.csdn.bootstrap.loader.impl; | ||
|
||
import net.csdn.bootstrap.loader.Loader; | ||
import net.csdn.common.env.Environment; | ||
import net.csdn.common.settings.Settings; | ||
import org.apache.velocity.app.Velocity; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* 6/29/13 WilliamZhu([email protected]) | ||
*/ | ||
public class TemplateLoader implements Loader { | ||
@Override | ||
public void load(Settings settings) throws Exception { | ||
Environment environment = new Environment(settings); | ||
if (settings.getAsBoolean("application.template.engine.enable", false)) { | ||
Properties properties = new Properties(); | ||
properties.setProperty("file.resource.loader.path", environment.templateDirFile().getPath()); | ||
properties.setProperty("input.encoding", "utf-8"); | ||
properties.setProperty("output.encoding", "utf-8"); | ||
Velocity.init(properties); | ||
} | ||
} | ||
} |
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,104 @@ | ||
package net.csdn.junit; | ||
|
||
import net.csdn.common.exception.RenderFinish; | ||
import net.csdn.modules.http.RestController; | ||
import net.csdn.modules.http.RestRequest; | ||
import net.csdn.modules.http.RestResponse; | ||
import net.csdn.modules.mock.MockRestRequest; | ||
import net.csdn.modules.mock.MockRestResponse; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static net.csdn.common.collections.WowCollections.map; | ||
|
||
/** | ||
* 6/28/13 WilliamZhu([email protected]) | ||
*/ | ||
public class BaseControllerTest extends IocTest { | ||
|
||
public RestResponse runAction(String path, Map params, RestRequest.Method method) throws Exception { | ||
RestResponse response = new MockRestResponse(); | ||
RestController controller = injector.getInstance(RestController.class); | ||
try { | ||
controller.dispatchRequest(new MockRestRequest(path, params, method, null), response); | ||
} catch (Exception e) { | ||
catchRenderFinish(e); | ||
} | ||
return response; | ||
} | ||
|
||
private void catchRenderFinish(Exception e) throws Exception { | ||
if (e instanceof RenderFinish) { | ||
} else if (e instanceof InvocationTargetException) { | ||
if (((InvocationTargetException) e).getTargetException() instanceof RenderFinish) { | ||
|
||
} else { | ||
throw e; | ||
} | ||
|
||
} else { | ||
throw e; | ||
} | ||
} | ||
|
||
public RestResponse runAction(String path, String rawParamsStr, RestRequest.Method method) throws Exception { | ||
RestResponse response = new MockRestResponse(); | ||
RestController controller = injector.getInstance(RestController.class); | ||
try { | ||
controller.dispatchRequest(new MockRestRequest(path, map(), method, rawParamsStr), response); | ||
} catch (Exception e) { | ||
catchRenderFinish(e); | ||
} | ||
return response; | ||
} | ||
|
||
public Map<RestRequest.Method, RestResponse> each(List<RestRequest.Method> methods, String path, Map params) throws Exception { | ||
Map<RestRequest.Method, RestResponse> maps = map(); | ||
for (RestRequest.Method method : methods) { | ||
maps.put(method, runAction(path, params, method)); | ||
} | ||
return maps; | ||
} | ||
|
||
public Map<RestRequest.Method, RestResponse> each(List<RestRequest.Method> methods, String path, String rawParamStr) throws Exception { | ||
Map<RestRequest.Method, RestResponse> maps = map(); | ||
for (RestRequest.Method method : methods) { | ||
maps.put(method, runAction(path, rawParamStr, method)); | ||
} | ||
return maps; | ||
} | ||
|
||
public RestResponse get(String path, Map params) throws Exception { | ||
return runAction(path, params, RestRequest.Method.GET); | ||
} | ||
|
||
public RestResponse post(String path, Map params) throws Exception { | ||
return runAction(path, params, RestRequest.Method.POST); | ||
} | ||
|
||
public RestResponse delete(String path, Map params) throws Exception { | ||
return runAction(path, params, RestRequest.Method.DELETE); | ||
} | ||
|
||
public RestResponse put(String path, Map params) throws Exception { | ||
return runAction(path, params, RestRequest.Method.PUT); | ||
} | ||
|
||
public RestResponse get(String path, String rawParamsStr) throws Exception { | ||
return runAction(path, rawParamsStr, RestRequest.Method.GET); | ||
} | ||
|
||
public RestResponse post(String path, String rawParamsStr) throws Exception { | ||
return runAction(path, rawParamsStr, RestRequest.Method.POST); | ||
} | ||
|
||
public RestResponse delete(String path, String rawParamsStr) throws Exception { | ||
return runAction(path, rawParamsStr, RestRequest.Method.DELETE); | ||
} | ||
|
||
public RestResponse put(String path, String rawParamsStr) throws Exception { | ||
return runAction(path, rawParamsStr, RestRequest.Method.PUT); | ||
} | ||
} |
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,7 @@ | ||
package net.csdn.junit; | ||
|
||
/** | ||
* 6/28/13 WilliamZhu([email protected]) | ||
*/ | ||
public class BaseServiceTest extends IocTest { | ||
} |
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
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
Oops, something went wrong.