Commits

Jonghyouk Yun  committed 660d0e0

tests

  • Participants
  • Parent commits ace0e42

Comments (0)

Files changed (4)

 
 
 * jersey unit-test?
-	- http://jersey.java.net/nonav/documentation/latest/test-framework.html
-	- TODO: destination url via app-configs + junit w/injected jersey-connection.
-	- TODO: Plus
+	CANCEL - http://jersey.java.net/nonav/documentation/latest/test-framework.html
+	DONE - TODO: destination url via app-configs + junit w/injected jersey-connection.
+	DONE - Plus
 	- TODO: Transactions
 
 

File src/main/resources/app-config.xml

 			jhyun.mybatis_with_guice.controllers.HelloController
 		</jersey-modules>
 	</app>
+	<test>
+		<api-url-prefix>http://localhost:8080</api-url-prefix>
+	</test>
 </config>

File src/test/java/jhyun/mybatis_with_guice/tests/helpers/JerseyTestingClient.java

+package jhyun.mybatis_with_guice.tests.helpers;
+
+import jhyun.mybatis_with_guice.config.AppConfig;
+
+import org.apache.commons.configuration.Configuration;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
+
+public class JerseyTestingClient {
+
+	public static WebResource webResource() {
+		//
+		final Configuration config = AppConfig.load();
+		final String apiUrlPrefix = config.getString("test.api-url-prefix");
+		//
+		ClientConfig clientConfig = new DefaultClientConfig();
+		clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
+				Boolean.TRUE);
+		Client client = Client.create(clientConfig);
+		WebResource webResource = client.resource(apiUrlPrefix);
+		return webResource;
+	}
+}

File src/test/java/jhyun/mybatis_with_guice/tests/test_cases/PlusWithJsonJerseyClientTestCase.java

 package jhyun.mybatis_with_guice.tests.test_cases;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import javax.ws.rs.core.MediaType;
-import static org.junit.Assert.*;
 
 import jhyun.mybatis_with_guice.controllers.hello.plus.PlusParams;
 import jhyun.mybatis_with_guice.controllers.hello.plus.PlusResult;
+import jhyun.mybatis_with_guice.tests.helpers.JerseyTestingClient;
 
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
-
 public class PlusWithJsonJerseyClientTestCase {
 
 	private static Logger logger = LoggerFactory
 			.getLogger(PlusWithJsonJerseyClientTestCase.class);
 
-	private WebResource prepareWebResource() {
-		ClientConfig clientConfig = new DefaultClientConfig();
-		clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
-				Boolean.TRUE);
-		Client client = Client.create(clientConfig);
-		WebResource webResource = client.resource("http://localhost:8080");
-		return webResource;
-	}
-
 	@Test
 	public void testPlusWithJson() {
 		PlusParams params = new PlusParams(3, 4);
-		PlusResult result = prepareWebResource().path("hello")
-				.path("plusWithJson").accept(MediaType.APPLICATION_JSON)
+		PlusResult result = JerseyTestingClient.webResource()
+				.path("/hello/plusWithJson").accept(MediaType.APPLICATION_JSON)
 				.type(MediaType.APPLICATION_JSON)
 				.post(PlusResult.class, params);
 		logger.debug(String.format("%s -> %s", params, result));