summaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src/test')
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java77
-rwxr-xr-xdatarouter-prov/src/test/resources/create.sql3
2 files changed, 76 insertions, 4 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java
index 907aa93b..dcab5410 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java
@@ -25,6 +25,7 @@ package org.onap.dmaap.datarouter.provisioning.beans;
import org.json.JSONObject;
import org.junit.*;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -32,8 +33,13 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.io.InvalidObjectException;
+import java.sql.Connection;
import java.sql.SQLException;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+
+import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
public class FeedTest {
@@ -101,17 +107,80 @@ public class FeedTest {
}
@Test
- public void Validate_ChaneOwnerShip_Returns_True()
- {
+ public void Validate_ChaneOwnerShip_Returns_True() {
Boolean bool = feed.changeOwnerShip();
Assert.assertEquals(true, bool);
}
@Test
- public void Given_Feeds_Are_Equal_Then_Equals_Returns_True()
- {
+ public void Given_Feeds_Are_Equal_Then_Equals_Returns_True() {
Feed feed2 = feed;
Boolean bool = feed.equals(feed2);
Assert.assertEquals(true, bool);
}
+
+ @Test
+ public void Validate_getFeedByNameVersion_Returns_Valid_Feed() {
+ feed = Feed.getFeedByNameVersion("Feed1","v0.1");
+ Assert.assertEquals(feed.toString(), "FEED: feedid=1, name=Feed1, version=v0.1");
+ }
+
+ @Test
+ public void Given_doDelete_Throws_SQLException_Then_Returns_False() throws SQLException {
+ Connection spyConnection = CreateSpyForDbConnection();
+ Mockito.doThrow(new SQLException()).when(spyConnection).prepareStatement(anyString());
+ Assert.assertEquals(feed.doDelete(spyConnection), false);
+ }
+
+ @Test
+ public void Given_doInsert_Throws_SQLException_Then_Returns_False() throws SQLException {
+ Connection connection = db.getConnection();
+ FeedAuthorization fa = new FeedAuthorization();
+ Set setA = new HashSet();
+ setA.add(new FeedEndpointID("1", "Name"));
+ Set setB = new HashSet();
+ setB.add("172.0.0.1");
+ fa.setEndpoint_ids(setA);
+ fa.setEndpoint_addrs(setB);
+ feed.setAuthorization(fa);
+ Assert.assertEquals(feed.doInsert(connection), false);
+
+ }
+
+ @Test
+ public void Given_doUpdate_Throws_SQLException_Then_Returns_False() throws SQLException {
+ Connection spyConnection = CreateSpyForDbConnection();
+ Mockito.doThrow(new SQLException()).when(spyConnection).prepareStatement(anyString());
+ Assert.assertEquals(feed.doUpdate(spyConnection), false);
+
+ }
+
+ @Test
+ public void Validate_Set_Get_Methods_Return_Correct_Values(){
+ feed.setName("testName");
+ feed.setVersion("v1.0");
+ feed.setGroupid(1);
+ feed.setDescription("test feed");
+ feed.setBusiness_description("test feed");
+ feed.setSuspended(false);
+ feed.setPublisher("publish");
+
+ Assert.assertEquals(feed.getName(), "testName");
+ Assert.assertEquals(feed.getVersion(), "v1.0");
+ Assert.assertEquals(feed.getGroupid(), 1);
+ Assert.assertEquals(feed.getDescription(), "test feed");
+ Assert.assertEquals(feed.getBusiness_description(), "test feed");
+ Assert.assertEquals(feed.isSuspended(), false);
+ Assert.assertEquals(feed.getPublisher(), "publish");
+ }
+
+ @Test
+ public void Given_IsFeedValid_Called_And_Feed_Exists_Returns_True(){
+ Assert.assertEquals(feed.isFeedValid(1), true);
+ }
+
+ private Connection CreateSpyForDbConnection() throws SQLException {
+ Connection conn = db.getConnection();
+ return Mockito.spy(conn);
+ }
} \ No newline at end of file
diff --git a/datarouter-prov/src/test/resources/create.sql b/datarouter-prov/src/test/resources/create.sql
index 887b06a3..9412adf2 100755
--- a/datarouter-prov/src/test/resources/create.sql
+++ b/datarouter-prov/src/test/resources/create.sql
@@ -158,6 +158,9 @@ VALUES (23, 1, 'http://delivery_url', 'user1', 'somepassword', 'sub123', 'selfli
INSERT INTO FEED_ENDPOINT_IDS(FEEDID, USERID, PASSWORD)
VALUES (1, 'USER', 'PASSWORD');
+INSERT INTO FEED_ENDPOINT_ADDRS(FEEDID, ADDR)
+VALUES (1, '172.0.0.1');
+
INSERT INTO FEEDS(FEEDID, GROUPID, NAME, VERSION, DESCRIPTION, BUSINESS_DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK)
VALUES (1, 1,'Feed1','v0.1', 'First Feed for testing', 'First Feed for testing', 'auth_class', 'pub','self_link','publish_link','subscribe_link','log_link');