add testcases 40/84040/1
authorsunil.unnava <sunil.unnava@att.com>
Wed, 3 Apr 2019 04:41:55 +0000 (00:41 -0400)
committersunil.unnava <sunil.unnava@att.com>
Wed, 3 Apr 2019 04:43:04 +0000 (00:43 -0400)
Issue-ID: DMAAP-1140
Change-Id: I249cf7b1b7f0692de224aee9b33aab8dbab20054
Signed-off-by: sunil.unnava <sunil.unnava@att.com>
src/main/java/org/onap/dmaap/dmf/mr/beans/DMaaPCambriaLimiter.java
src/test/java/org/onap/dmaap/mr/cambria/beans/ApiKeyBeanTest.java
src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPCambriaLimiterTest.java
src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPContextTest.java
src/test/java/org/onap/dmaap/mr/cambria/beans/TopicBeanTest.java

index 2091e5f..f645c8d 100644 (file)
@@ -52,7 +52,6 @@ import com.att.nsa.metrics.impl.CdmRateTicker;
 @Component
 public class DMaaPCambriaLimiter {
        private final HashMap<String, RateInfo> fRateInfo;
-       private final HashMap<String, RateInfoCheck> fRateInfoCheck;
        private final double fMaxEmptyPollsPerMinute;
        private final double fMaxPollsPerMinute;
        private final int fWindowLengthMins;
@@ -70,7 +69,6 @@ public class DMaaPCambriaLimiter {
        @Autowired
        public DMaaPCambriaLimiter(@Qualifier("propertyReader") rrNvReadable settings) {
                        fRateInfo = new HashMap<>();
-               fRateInfoCheck = new HashMap<>();
                fMaxEmptyPollsPerMinute = settings.getDouble(CambriaConstants.kSetting_MaxEmptyPollsPerMinute,
                                CambriaConstants.kDefault_MaxEmptyPollsPerMinute);
                fMaxPollsPerMinute = settings.getDouble(CambriaConstants.kSetting_MaxPollsPerMinute,
@@ -105,7 +103,6 @@ public class DMaaPCambriaLimiter {
         */
        public DMaaPCambriaLimiter(double maxEmptyPollsPerMinute,double maxPollsPerMinute, int windowLengthMins, long sleepMs ,long sleepMS1) {
                fRateInfo = new HashMap<>();
-               fRateInfoCheck = new HashMap<>();
                fMaxEmptyPollsPerMinute = Math.max(0, maxEmptyPollsPerMinute);
                fMaxPollsPerMinute = Math.max(0, maxPollsPerMinute);
                fWindowLengthMins = windowLengthMins;
@@ -226,42 +223,6 @@ public class DMaaPCambriaLimiter {
        
        
        
-       private static class RateInfoCheck {
-               
-               private final String fLabel;
-               private final CdmRateTicker fCallRateSinceLastMsgSend;
-               /**
-                * constructor initialzes
-                * 
-                * @param label
-                * @param windowLengthMinutes
-                */
-               public RateInfoCheck(String label, int windowLengthMinutes) {
-                       fLabel = label;
-                       fCallRateSinceLastMsgSend = new CdmRateTicker("Call rate since last msg send", 1, TimeUnit.MINUTES,
-                                       windowLengthMinutes, TimeUnit.MINUTES);
-               }
-
-               public String getLabel() {
-                       return fLabel;
-               }
-
-               /**
-                * CdmRateTicker is reset
-                */
-               public void reset() {
-                       fCallRateSinceLastMsgSend.reset();
-               }
-
-               /**
-                * 
-                * @return
-                */
-               public double onCall() {
-                       fCallRateSinceLastMsgSend.tick();
-                       return fCallRateSinceLastMsgSend.getRate();
-               }
-       }
        
        
        
index 2a79e92..beec641 100644 (file)
@@ -53,6 +53,16 @@ public class ApiKeyBeanTest {
                
        }
        
+       @Test
+       public void testApiKeyBean(){
+               ApiKeyBean bean = new ApiKeyBean();
+               bean.setDescription("description");
+               bean.setEmail("email");
+               assertEquals("description", bean.getDescription());
+               assertEquals("email", bean.getEmail());
+               
+       }
+       
        
 
 }
index 853d770..f9b2554 100644 (file)
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
- package org.onap.dmaap.mr.cambria.beans;
+package org.onap.dmaap.mr.cambria.beans;
 
 import static org.junit.Assert.*;
 
@@ -41,43 +41,57 @@ public class DMaaPCambriaLimiterTest {
 
        @Test
        public void testGetSleepMsForRate() {
-               
-       
-               double value = 3;
-               DMaaPCambriaLimiter.getSleepMsForRate(value);
-               
-               String trueValue = "True";
-               assertTrue(trueValue.equalsIgnoreCase("True"));
-               
+
+               assertEquals(1000, DMaaPCambriaLimiter.getSleepMsForRate(100));
+               assertEquals(0, DMaaPCambriaLimiter.getSleepMsForRate(0));
+
        }
-       
+
        @Test
        public void testOnCall() {
-               
-               DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(1,2, 3);
+
+               DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(1, 2, 3);
                try {
-                       limiter.onCall("testTopic", "ConsumerGroup1", "client2","remoteHost");
+                       limiter.onCall("testTopic", "ConsumerGroup1", "client2", "remoteHost");
                } catch (CambriaApiException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
-               
+
                String trueValue = "True";
                assertTrue(trueValue.equalsIgnoreCase("True"));
-               
+
+       }
+
+       @Test
+       public void testOnCallError2() {
+
+               DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(0, 2, 3, 1, 1);
+               try {
+                       limiter.onCall("testTopic", "ConsumerGroup1", "client2", "remoteHost");
+               } catch (CambriaApiException e) {
+                       assertTrue(false);
+               }
+
+       }
+
+       @Test(expected = CambriaApiException.class)
+       public void testOnCallError() throws CambriaApiException {
+
+               DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(0.9, 2, 3, 1, 1);
+               limiter.onCall("testTopic", "ConsumerGroup1", "client2", "remoteHost");
+
        }
-       
+
        @Test
        public void testOnSend() {
-               
-               DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(3,3, 3);
+
+               DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(3, 3, 3);
                limiter.onSend("testTopic", "consumerGroup1", "client1", 100);
-               
+
                String trueValue = "True";
                assertTrue(trueValue.equalsIgnoreCase("True"));
-               
+
        }
-       
-       
 
 }
index 9a67673..a945cd6 100644 (file)
@@ -27,6 +27,9 @@ import org.junit.Before;
 import org.junit.Test;
 
 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
+import org.springframework.mock.http.client.MockClientHttpRequest;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpSession;
 
 public class DMaaPContextTest {
 
@@ -48,6 +51,21 @@ public class DMaaPContextTest {
                
        }
        
+       @Test
+       public void testDMaaPContext(){
+               
+               DMaaPContext context=new DMaaPContext();
+               context.setConsumerRequestTime("consumerRequestTime");
+               assertEquals("consumerRequestTime", context.getConsumerRequestTime());
+               MockHttpServletRequest request= new MockHttpServletRequest();
+               MockHttpSession session=new MockHttpSession();
+               request.setSession(session);
+               context.setRequest(request);
+               assertNotNull(context.getSession());
+               
+               
+       }
+       
        
 
 }
index bb3af25..d88c408 100644 (file)
@@ -51,6 +51,26 @@ public class TopicBeanTest {
                
        }
        
+       @Test
+       public void testTopicBean() {
+               
+               TopicBean bean = new TopicBean("topicName", "topicDescription", 1,1,true);
+               assertNotNull(bean);
+               
+       }
+       
+       @Test
+       public void testTopicBeanStter() {
+               
+               TopicBean bean = new TopicBean();
+               bean.setPartitionCount(1);
+               bean.setReplicationCount(1);
+               bean.setTopicDescription("topicDescription");
+               bean.setTopicName("topicName");
+               bean.setTransactionEnabled(true);
+               assertNotNull(bean);
+       }
+       
        
 
 }