aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorDominic Lunanuova <dgl@research.att.com>2019-03-25 13:17:55 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-25 13:17:55 +0000
commit072b8c23fdfd43f1d2f5e7d0c4653f77fffed824 (patch)
tree715bd8f20e6b43d31f5eff60c51a16b1d9ae331d /src/test
parentd2e4071456ec1d8b64aa18fdeeeb30f85e173d9a (diff)
parented283717c1d63873fd93cb5c5446cf44ca93d018 (diff)
Merge "Fix Resources Jersey tests"
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java9
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/resources/DR_SubResourceTest.java636
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResourceTest.java9
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java6
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java9
5 files changed, 449 insertions, 220 deletions
diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java
index fb83fe9..c0f3bef 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/model/DmaapTest.java
@@ -19,17 +19,14 @@
*/
package org.onap.dmaap.dbcapi.model;
-import static org.junit.Assert.*;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+
public class DmaapTest {
- String ver, tnr, dn, dpu, lu, bat, nk, ako;
+ private String ver, tnr, dn, dpu, lu, bat, nk, ako;
@Before
public void setUp() throws Exception {
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 9ba5776..f9513a6 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
@@ -1,9 +1,8 @@
-
/*-
* ============LICENSE_START=======================================================
* org.onap.dmaap
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,211 +18,446 @@
* ============LICENSE_END=========================================================
*/
package org.onap.dmaap.dbcapi.resources;
-import org.onap.dmaap.dbcapi.model.*;
-import org.onap.dmaap.dbcapi.service.*;
-import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
-import static org.junit.Assert.*;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import java.util.*;
-import java.sql.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import org.glassfish.jersey.test.JerseyTest;
-import org.glassfish.jersey.server.ResourceConfig;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.Path;
-import javax.ws.rs.GET;
-
-public class DR_SubResourceTest extends JerseyTest{
-
- static DmaapObjectFactory factory = new DmaapObjectFactory();
-
- @Override
- protected Application configure() {
- return new ResourceConfig()
- .register( DR_SubResource.class )
- .register( FeedResource.class )
- .register( DcaeLocationResource.class )
- .register( DmaapResource.class );
- }
-
- String d, un, up, f, p;
-
- @Before
- public void preTest() throws Exception {
- try {
-
- Dmaap dmaap = factory.genDmaap();
- Entity<Dmaap> reqEntity = Entity.entity( dmaap, MediaType.APPLICATION_JSON );
- Response resp = target( "dmaap").request().post( reqEntity, Response.class );
- System.out.println( resp.getStatus() );
- assertTrue( resp.getStatus() == 200 );
- }catch (Exception e ) {
- }
- try {
- DcaeLocation loc = factory.genDcaeLocation( "central" );
- Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
- Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
- System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ));
- if ( resp.getStatus() != 409 ) {
- assertTrue( resp.getStatus() == 201 );
- }
- } catch (Exception e ) {
- }
-
-
- }
-/*
- @Before
- public void setUp() throws Exception {
- d = "central-onap";
- un = "user1";
- up = "secretW0rd";
- f = "234";
- p = "678";
- }
-
- @After
- public void tearDown() throws Exception {
- }
-*/
-
-
-
-/* may conflict with test framework!
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-*/
-
- private Feed addFeed( String name, String desc ) {
- Feed feed = new Feed( name, "1.0", desc, "dgl", "unrestricted" );
- Entity<Feed> reqEntity = Entity.entity( feed, MediaType.APPLICATION_JSON );
- Response resp = 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 );
-
- Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
- Response resp = target( "dr_subs").request().post( reqEntity2, Response.class);
- System.out.println( "POST dr_subs resp=" + resp.getStatus() );
- assertTrue( resp.getStatus() == 201 );
- dr_sub = resp.readEntity( DR_Sub.class );
-
- return dr_sub;
- }
- private DR_Sub addSubByName( String d, String un, String up, String feedName ) {
- DR_Sub dr_sub = new DR_Sub( d, un, up, null,
- "https://subscriber.onap.org/foo", "https://dr-prov/sublog", true );
-
- dr_sub.setFeedName(feedName);
-
- Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
- Response resp = target( "dr_subs").request().post( reqEntity2, Response.class);
- System.out.println( "POST dr_subs resp=" + resp.getStatus() );
- assertTrue( resp.getStatus() == 201 );
- dr_sub = resp.readEntity( DR_Sub.class );
-
- return dr_sub;
- }
-
- @Test
- public void GetTest() {
- Response resp = target( "dr_subs").request().get( Response.class );
- System.out.println( "GET dr_subs resp=" + resp.getStatus() );
-
- assertTrue( resp.getStatus() == 200 );
- }
-
- @Test
- public void PostTest() {
-
- Feed feed = addFeed( "subPostTest", "post unit test" );
- System.out.println( "subPostTest: feedId=" + feed.getFeedId());
-
- String d, un, up;
- d = "central-onap";
- un = "user1";
- up = "secretW0rd";
-
- DR_Sub dr_pub = addSub( d, un, up, feed.getFeedId() );
- }
-
- @Test
- public void PostTestByName() {
-
- Feed feed = addFeed( "subPostTest2", "post unit test" );
- System.out.println( "subPostTest2: feedId=" + feed.getFeedId());
-
- String d, un, up;
- d = "central-onap";
- un = "user1";
- up = "secretW0rd";
-
- DR_Sub dr_pub = addSubByName( d, un, up, feed.getFeedName() );
- }
-
- @Test
- public void PutTest() {
-
- Feed feed = addFeed( "subPutTest", "put unit test");
- String d, un, up;
- d = "central-onap";
- un = "user1";
- up = "secretW0rd";
-
- DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
-
- dr_sub.setUserpwd("newSecret");
- Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
- Response resp = target( "dr_subs")
- .path( dr_sub.getSubId() )
- .request()
- .put( reqEntity2, Response.class);
- System.out.println( "PUT dr_subs resp=" + resp.getStatus() );
- assertTrue( resp.getStatus() == 200 );
- }
-
-
-// TODO: figure out how to check delete() response
- @Test
- public void DelTest() {
-
- Feed feed = addFeed( "subDelTest", "del unit test");
- String d, un, up;
- d = "central-onap";
- un = "user1";
- up = "secretW0rd";
-
- DR_Sub dr_sub = addSub( d, un, up, feed.getFeedId() );
-
- Entity<DR_Sub> reqEntity2 = Entity.entity( dr_sub, MediaType.APPLICATION_JSON);
- Response resp = target( "dr_subs")
- .path( dr_sub.getSubId() )
- .request()
- .delete();
- System.out.println( "DEL dr_subs resp=" + resp.getStatus() );
- assertTrue( resp.getStatus() == 204 );
- }
-
+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;
+import org.junit.Test;
+import org.onap.dmaap.dbcapi.database.DatabaseClass;
+import org.onap.dmaap.dbcapi.model.ApiError;
+import org.onap.dmaap.dbcapi.model.DR_Sub;
+import org.onap.dmaap.dbcapi.model.Feed;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+public class DR_SubResourceTest {
+
+ private static final DmaapObjectFactory DMAAP_OBJECT_FACTORY = new DmaapObjectFactory();
+
+ private static final String DCAE_LOCATION_NAME = "central-onap";
+ private static final String USERNAME = "user1";
+ private static final String USRPWD = "secretW0rd";
+ private static final String DELIVERY_URL = "https://subscriber.onap.org/delivery/id";
+ 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;
+
+ @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()
+ .register(DR_SubResource.class)
+ .register(FeedResource.class)
+ .register(DmaapResource.class));
+ testContainer.init();
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ testContainer.destroy();
+ /*TODO: Cannot cleanup yet until still other Resources tests depends on the static DB content
+
+ DatabaseClass.clearDatabase();
+ DatabaseClass.getDmaap().remove();*/
+ }
+
+ @Before
+ public void cleanupDatabase() throws Exception {
+ DatabaseClass.clearDatabase();
+ }
+
+ //TODO: figure out generic entity list unmarshall to check the entity list
+ @Test
+ public void getDr_Subs_test() {
+ Response resp = testContainer.target("dr_subs").request().get(Response.class);
+ System.out.println("GET dr_subs resp=" + resp.getStatus());
+
+ assertTrue(resp.getStatus() == 200);
+ assertTrue(resp.hasEntity());
+ }
+
+ @Test
+ public void addDr_Sub_shallReturnError_whenNoFeedIdAndFeedNameInSubProvided() {
+ //given
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, null, DELIVERY_URL, LOG_URL, true);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .request()
+ .post(requestedEntity, Response.class);
+
+ //then
+ assertEquals(400, resp.getStatus());
+ ApiError responseError = resp.readEntity(ApiError.class);
+ assertNotNull(responseError);
+ assertEquals("feedName", responseError.getFields());
+ }
+
+ @Test
+ public void addDr_Sub_shallReturnError_whenFeedNameProvided_butFeedNotExist() {
+ //given
+ String notExistingFeedName = "notRealFead";
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, null, DELIVERY_URL, LOG_URL, true);
+ drSub.setFeedName(notExistingFeedName);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .request()
+ .post(requestedEntity, Response.class);
+
+ //then
+ assertEquals(404, resp.getStatus());
+ ApiError responseError = resp.readEntity(ApiError.class);
+ assertNotNull(responseError);
+ assertEquals("feedName", responseError.getFields());
+ }
+
+ @Test
+ public void addDr_Sub_shallReturnError_whenFeedNameProvided_andManyFeedsWithTheSameNameInDB() {
+ //given
+ String notDistinctFeedName = "notDistinctFeedName";
+ Feed feed1 = new Feed(notDistinctFeedName, "1.0", "description", "dgl", "unrestricted");
+ Feed feed2 = new Feed(notDistinctFeedName, "2.0", "description", "dgl", "unrestricted");
+ DatabaseClass.getFeeds().put("1", feed1);
+ DatabaseClass.getFeeds().put("2", feed2);
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, null, DELIVERY_URL, LOG_URL, true);
+ drSub.setFeedName(notDistinctFeedName);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .request()
+ .post(requestedEntity, Response.class);
+
+ //then
+ assertEquals(409, resp.getStatus());
+ ApiError responseError = resp.readEntity(ApiError.class);
+ assertNotNull(responseError);
+ assertEquals("feedName", responseError.getFields());
+ }
+
+ @Test
+ public void addDr_Sub_shallReturnError_whenFeedIdProvided_butFeedNotExist() {
+ //given
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, "someFakeFeedId", DELIVERY_URL, LOG_URL, true);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .request()
+ .post(requestedEntity, Response.class);
+
+ //then
+ assertEquals(404, resp.getStatus());
+ ApiError responseError = resp.readEntity(ApiError.class);
+ assertNotNull(responseError);
+ assertTrue(responseError.getFields().contains("feedId"));
+ }
+
+ @Test
+ public void addDr_Sub_shallExecuteSuccessfully_whenValidFeedIdProvided() {
+ //given
+ String feedId = assureFeedIsInDB();
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, feedId, DELIVERY_URL, LOG_URL, true);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .request()
+ .post(requestedEntity, Response.class);
+
+ //then
+ assertEquals(201, resp.getStatus());
+ assertTrue(resp.hasEntity());
+ DR_Sub created = resp.readEntity(DR_Sub.class);
+ assertSubscriptionExistInDB(created);
+ }
+
+ @Test
+ public void addDr_Sub_shallExecuteSuccessfully_whenValidFeedNameProvided() {
+ //given
+ String feedName = "testFeed";
+ 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<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .request()
+ .post(requestedEntity, Response.class);
+
+ //then
+ assertEquals(201, resp.getStatus());
+ assertTrue(resp.hasEntity());
+ DR_Sub created = resp.readEntity(DR_Sub.class);
+ assertSubscriptionExistInDB(created);
+ }
+
+
+ @Test
+ public void updateDr_Sub_shallReturnError_whenNoFeedIdInSubProvided() {
+ //given
+ String subId = "1234";
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, null, DELIVERY_URL, LOG_URL, true);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(subId)
+ .request()
+ .put(requestedEntity, Response.class);
+
+ //then
+ assertEquals(400, resp.getStatus());
+ ApiError responseError = resp.readEntity(ApiError.class);
+ assertNotNull(responseError);
+ assertEquals("feedId", responseError.getFields());
+ }
+
+ @Test
+ public void updateDr_Sub_shallReturnError_whenNoDCAELocationInSubProvided() {
+ //given
+ String subId = "1234";
+ DR_Sub drSub = new DR_Sub(null, USERNAME, USRPWD, "someFeedId", DELIVERY_URL, LOG_URL, true);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(subId)
+ .request()
+ .put(requestedEntity, Response.class);
+
+ //then
+ assertEquals(400, resp.getStatus());
+ ApiError responseError = resp.readEntity(ApiError.class);
+ assertNotNull(responseError);
+ assertEquals("dcaeLocationName", responseError.getFields());
+ }
+
+ @Test
+ public void updateDr_Sub_shallReturnError_whenFeedWithGivenIdInSubNotExists() {
+ //given
+ String subId = "1234";
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, "someFeedId", DELIVERY_URL, LOG_URL, true);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(subId)
+ .request()
+ .put(requestedEntity, Response.class);
+
+ //then
+ assertEquals(404, resp.getStatus());
+ assertNotNull(resp.readEntity(ApiError.class));
+ }
+
+ @Test
+ public void updateDr_Sub_shallReturnSuccess_whenAddingNewSubscription() {
+ //given
+ String subId = "31";
+ String feedId = assureFeedIsInDB();
+ DR_Sub drSub = new DR_Sub(DCAE_LOCATION_NAME, USERNAME, USRPWD, feedId, null, null, true);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSub, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(subId)
+ .request()
+ .put(requestedEntity, Response.class);
+
+ //then
+ assertEquals(200, resp.getStatus());
+
+ DR_Sub createdDrSub = resp.readEntity(DR_Sub.class);
+ assertNotNull(createdDrSub.getLastMod());
+ assertEquals(subId, createdDrSub.getSubId());
+ assertEquals(DCAE_LOCATION_NAME, createdDrSub.getDcaeLocationName());
+ assertEquals(USERNAME, createdDrSub.getUsername());
+ assertEquals(USRPWD, createdDrSub.getUserpwd());
+ assertEquals(DELIVERY_URL_TEMPLATE + subId, createdDrSub.getDeliveryURL());
+ assertEquals(LOG_URL_TEMPLATE + subId, createdDrSub.getLogURL());
+
+ assertSubscriptionExistInDB(createdDrSub);
+ }
+
+ @Test
+ public void updateDr_Sub_shallReturnSuccess_whenUpdatingExistingSubscription() {
+ //given
+ String feedId = assureFeedIsInDB();
+ DR_Sub existingDrSub = addSub(DCAE_LOCATION_NAME, USERNAME, USRPWD, feedId);
+ DR_Sub drSubUpdate = new DR_Sub("newDcaeLocationName", "newUserName", "newUserPwd", feedId, null, null, false);
+ Entity<DR_Sub> requestedEntity = Entity.entity(drSubUpdate, MediaType.APPLICATION_JSON);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(existingDrSub.getSubId())
+ .request()
+ .put(requestedEntity, Response.class);
+
+ //then
+ assertEquals(200, resp.getStatus());
+
+ DR_Sub updatedDrSub = resp.readEntity(DR_Sub.class);
+ assertNotNull(updatedDrSub.getLastMod());
+ assertEquals(existingDrSub.getSubId(), updatedDrSub.getSubId());
+ assertEquals(drSubUpdate.getDcaeLocationName(), updatedDrSub.getDcaeLocationName());
+ assertEquals(drSubUpdate.getUsername(), updatedDrSub.getUsername());
+ assertEquals(drSubUpdate.getUserpwd(), updatedDrSub.getUserpwd());
+ assertEquals(DELIVERY_URL_TEMPLATE + existingDrSub.getSubId(), updatedDrSub.getDeliveryURL());
+ assertEquals(LOG_URL_TEMPLATE + existingDrSub.getSubId(), updatedDrSub.getLogURL());
+
+ assertSubscriptionExistInDB(updatedDrSub);
+ }
+
+ @Test
+ public void deleteDr_Sub_shouldDeleteSubscriptionWithSuccess() {
+ //given
+ String feedId = assureFeedIsInDB();
+ DR_Sub dr_sub = addSub(DCAE_LOCATION_NAME, USERNAME, USRPWD, feedId);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(dr_sub.getSubId())
+ .request()
+ .delete();
+
+ //then
+ assertEquals("Shall delete subscription with success", 204, resp.getStatus());
+ assertFalse("No entity object shall be returned",resp.hasEntity());
+ assertSubscriptionNotExistInDB(dr_sub.getSubId());
+ }
+
+ @Test
+ public void deleteDr_Sub_shouldReturnErrorResponse_whenGivenSubIdNotFound() {
+ //given
+ String notExistingSubId = "6789";
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(notExistingSubId)
+ .request()
+ .delete();
+
+ //then
+ assertEquals("Shall return error, when trying to delete not existing subscription", 404, resp.getStatus());
+ assertNotNull(resp.readEntity(ApiError.class));
+ }
+
+ @Test
+ public void get_shallReturnExistingObject() {
+ //given
+ String feedId = assureFeedIsInDB();
+ DR_Sub dr_sub = addSub(DCAE_LOCATION_NAME, USERNAME, USRPWD, feedId);
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(dr_sub.getSubId())
+ .request()
+ .get();
+
+ //ten
+ assertEquals("Subscription shall be found",200, resp.getStatus());
+ assertEquals("Retrieved object shall be equal to eh one put into DB", dr_sub, resp.readEntity(DR_Sub.class));
+ }
+
+ @Test
+ public void get_shouldReturnError_whenSubWithIdNotFound() {
+ //given
+ String notExistingSubId = "1234";
+
+ //when
+ Response resp = testContainer.target("dr_subs")
+ .path(notExistingSubId)
+ .request()
+ .get();
+
+ //then
+ assertEquals("Subscription shall not be found", 404, resp.getStatus());
+ assertNotNull(resp.readEntity(ApiError.class));
+ }
+
+ private Feed addFeed(String name, String desc) {
+ Feed feed = new Feed(name, "1.0", desc, "dgl", "unrestricted");
+ Entity<Feed> 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);
+
+ Entity<DR_Sub> 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);
+ dr_sub = resp.readEntity(DR_Sub.class);
+
+ return dr_sub;
+ }
+
+ private String assureFeedIsInDB() {
+ Feed feed = addFeed("SubscriberTestFeed", "feed for DR_Sub testing");
+ assertNotNull("Feed shall be added into DB properly", feed);
+ return feed.getFeedId();
+ }
+
+
+ private void assertSubscriptionNotExistInDB(String subId) {
+ assertEquals(404, testContainer.target("dr_subs")
+ .path(subId)
+ .request()
+ .get()
+ .getStatus());
+ }
+
+ private void assertSubscriptionExistInDB(DR_Sub sub) {
+ Response response = testContainer.target("dr_subs")
+ .path(sub.getSubId())
+ .request()
+ .get();
+ assertEquals(200, response.getStatus());
+ 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();
+ }
+ }
}
diff --git a/src/test/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResourceTest.java
index 05bdeea..7367471 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResourceTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResourceTest.java
@@ -28,7 +28,9 @@ import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Before;
import org.junit.Test;
+import org.onap.dmaap.dbcapi.database.DatabaseClass;
import org.onap.dmaap.dbcapi.model.DcaeLocation;
import org.onap.dmaap.dbcapi.model.MR_Cluster;
import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
@@ -50,11 +52,12 @@ public class MR_ClusterResourceTest extends JerseyTest {
-/* may conflict with test framework!
+
@Before
- public void preTest() throws Exception {
+ public void init() throws Exception {
+ DatabaseClass.clearDatabase();
}
-
+/*
@After
public void tearDown() throws Exception {
}
diff --git a/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
index ac22e17..88840fe 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
@@ -30,6 +30,7 @@ import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Before;
import org.junit.Test;
+import org.onap.dmaap.dbcapi.database.DatabaseClass;
import org.onap.dmaap.dbcapi.model.DcaeLocation;
import org.onap.dmaap.dbcapi.model.Dmaap;
import org.onap.dmaap.dbcapi.model.MR_Cluster;
@@ -54,15 +55,14 @@ public class TopicResourceTest extends JerseyTest {
private static final String fmt = "%24s: %s%n";
-
-
@Before
public void preTest() throws Exception {
+ DatabaseClass.clearDatabase();
try {
Dmaap dmaap = factory.genDmaap();
Entity<Dmaap> reqEntity = Entity.entity( dmaap, MediaType.APPLICATION_JSON );
- Response resp = target( "dmaap").request().post( reqEntity, Response.class );
+ Response resp = target( "dmaap").request().put( reqEntity, Response.class );
System.out.println( resp.getStatus() );
assertTrue( resp.getStatus() == 200 );
}catch (Exception e ) {
diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java
index 7029bd2..c1fa0fd 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java
@@ -19,16 +19,11 @@
*/
package org.onap.dmaap.dbcapi.service;
-import org.onap.dmaap.dbcapi.model.*;
-import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
-import org.onap.dmaap.dbcapi.aaf.*;
-
-import static org.junit.Assert.*;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import java.util.List;
+import org.onap.dmaap.dbcapi.model.Dmaap;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
public class DmaapServiceTest {