tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 1 | package org.onlab.onos.rest; |
| 2 | |
| 3 | import com.sun.jersey.api.client.WebResource; |
| 4 | import com.sun.jersey.test.framework.JerseyTest; |
| 5 | import org.junit.BeforeClass; |
| 6 | import org.junit.Test; |
| 7 | import org.onlab.onos.net.GreetService; |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 8 | import org.onlab.onos.net.trivial.impl.GreetManager; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 9 | import org.onlab.osgi.ServiceDirectory; |
| 10 | import org.onlab.osgi.TestServiceDirectory; |
| 11 | |
| 12 | import static org.junit.Assert.assertTrue; |
| 13 | |
| 14 | /** |
| 15 | * Simple example on how to write a JAX-RS unit test using Jersey test framework. |
| 16 | * A base class should/will be created to provide further assistance for testing. |
| 17 | */ |
| 18 | public class GreetResourceTest extends JerseyTest { |
| 19 | |
| 20 | public GreetResourceTest() { |
| 21 | super("org.onlab.onos.rest"); |
| 22 | } |
| 23 | |
| 24 | @BeforeClass |
| 25 | public static void classSetUp() { |
| 26 | ServiceDirectory testDirectory = |
| 27 | new TestServiceDirectory().add(GreetService.class, new GreetManager()); |
| 28 | GreetResource.setServiceDirectory(testDirectory); |
| 29 | } |
| 30 | |
| 31 | @Test |
| 32 | public void basics() { |
| 33 | WebResource rs = resource(); |
| 34 | String response = rs.path("greet").get(String.class); |
| 35 | assertTrue("incorrect response", response.contains("Whazup ")); |
| 36 | } |
| 37 | |
| 38 | } |