X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fresources%2FDR_SubResourceTest.java;h=13b89ea8d57bbffdef9b8de046cde794cea559dd;hb=18eaae524174fac4f21d83c94bb8347a29d9f879;hp=f9513a6060cbc2b38064c8d17aa1c31a29aa2445;hpb=ed283717c1d63873fd93cb5c5446cf44ca93d018;p=dmaap%2Fdbcapi.git diff --git a/src/test/java/org/onap/dmaap/dbcapi/resources/DR_SubResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resources/DR_SubResourceTest.java index f9513a6..13b89ea 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/resources/DR_SubResourceTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/resources/DR_SubResourceTest.java @@ -25,11 +25,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.test.JerseyTest; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -51,19 +49,19 @@ public class DR_SubResourceTest { private static final String LOG_URL = "https://dr-prov/sublog/id"; private static final String DELIVERY_URL_TEMPLATE = "https://subscriber.onap.org/delivery/"; private static final String LOG_URL_TEMPLATE = "https://dr-prov/sublog/"; - private static FastJerseyTest testContainer; + private static FastJerseyTestContainer testContainer; + private static TestFeedCreator testFeedCreator; @BeforeClass public static void setUpClass() throws Exception { //TODO: init is still needed here to assure that dmaap is not null DatabaseClass.getDmaap().init(DMAAP_OBJECT_FACTORY.genDmaap()); - DatabaseClass.getDmaap().update(DMAAP_OBJECT_FACTORY.genDmaap()); - testContainer = new FastJerseyTest(new ResourceConfig() + testContainer = new FastJerseyTestContainer(new ResourceConfig() .register(DR_SubResource.class) - .register(FeedResource.class) - .register(DmaapResource.class)); + .register(FeedResource.class)); testContainer.init(); + testFeedCreator = new TestFeedCreator(testContainer); } @AfterClass @@ -76,7 +74,7 @@ public class DR_SubResourceTest { } @Before - public void cleanupDatabase() throws Exception { + public void cleanupDatabase() { DatabaseClass.clearDatabase(); } @@ -86,7 +84,7 @@ public class DR_SubResourceTest { Response resp = testContainer.target("dr_subs").request().get(Response.class); System.out.println("GET dr_subs resp=" + resp.getStatus()); - assertTrue(resp.getStatus() == 200); + assertEquals(200, resp.getStatus()); assertTrue(resp.hasEntity()); } @@ -193,7 +191,7 @@ public class DR_SubResourceTest { public void addDr_Sub_shallExecuteSuccessfully_whenValidFeedNameProvided() { //given String feedName = "testFeed"; - addFeed(feedName, "test feed"); + testFeedCreator.addFeed(feedName, "test feed"); DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, null, DELIVERY_URL, LOG_URL, true); drSub.setFeedName(feedName); Entity requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON); @@ -394,17 +392,6 @@ public class DR_SubResourceTest { assertNotNull(resp.readEntity(ApiError.class)); } - private Feed addFeed(String name, String desc) { - Feed feed = new Feed(name, "1.0", desc, "dgl", "unrestricted"); - Entity reqEntity = Entity.entity(feed, MediaType.APPLICATION_JSON); - Response resp = testContainer.target("feeds").request().post(reqEntity, Response.class); - int rc = resp.getStatus(); - System.out.println("POST feed resp=" + rc); - assertTrue(rc == 200 || rc == 409); - feed = resp.readEntity(Feed.class); - return feed; - } - private DR_Sub addSub(String d, String un, String up, String feedId) { DR_Sub dr_sub = new DR_Sub(d, un, up, feedId, "https://subscriber.onap.org/foo", "https://dr-prov/sublog", true); @@ -412,14 +399,14 @@ public class DR_SubResourceTest { Entity reqEntity2 = Entity.entity(dr_sub, MediaType.APPLICATION_JSON); Response resp = testContainer.target("dr_subs").request().post(reqEntity2, Response.class); System.out.println("POST dr_subs resp=" + resp.getStatus()); - assertTrue(resp.getStatus() == 201); + assertEquals(201, resp.getStatus()); dr_sub = resp.readEntity(DR_Sub.class); return dr_sub; } private String assureFeedIsInDB() { - Feed feed = addFeed("SubscriberTestFeed", "feed for DR_Sub testing"); + Feed feed = testFeedCreator.addFeed("SubscriberTestFeed", "feed for DR_Sub testing"); assertNotNull("Feed shall be added into DB properly", feed); return feed.getFeedId(); } @@ -442,22 +429,6 @@ public class DR_SubResourceTest { assertTrue(response.hasEntity()); assertEquals(sub, response.readEntity(DR_Sub.class)); } - - //TODO: move it outside class and use in other Resource integration tests - private static class FastJerseyTest extends JerseyTest { - - FastJerseyTest(Application jaxrsApplication) { - super(jaxrsApplication); - } - - void init() throws Exception { - this.setUp(); - } - - void destroy() throws Exception { - this.tearDown(); - } - } }