summaryrefslogtreecommitdiffstats
path: root/dmaap-dsa/src/test
diff options
context:
space:
mode:
authorShiwei Tian <tian.shiwei@zte.com.cn>2018-03-06 08:48:24 +0800
committerShiwei Tian <tian.shiwei@zte.com.cn>2018-03-06 09:17:02 +0800
commitf831daf1d824b91697819a5d680fba87dcf91337 (patch)
treeb13ddeaf08df679c998ef1459b7dee98302a6dcf /dmaap-dsa/src/test
parent7605bdd5ca1ab64f449c930bbab5440f88b4386b (diff)
Change HTTP Requests into HTTPS Ones
Issue-ID: HOLMES-104 Change-Id: I17677ce9bcdf14548fe43408382ebaba7e861ac3 Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
Diffstat (limited to 'dmaap-dsa/src/test')
-rw-r--r--dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java56
1 files changed, 25 insertions, 31 deletions
diff --git a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
index bc6486c..e9e0849 100644
--- a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
+++ b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
@@ -15,24 +15,23 @@
*/
package org.onap.holmes.dsa.dmaappolling;
-import org.easymock.EasyMock;
+import java.util.HashMap;
+import org.apache.http.HttpResponse;
import org.glassfish.hk2.api.ServiceLocator;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Matchers;
import org.onap.holmes.common.api.stat.AlarmAdditionalField;
import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
+import org.onap.holmes.common.utils.GsonUtil;
+import org.onap.holmes.common.utils.HttpsUtils;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
-
import java.util.ArrayList;
import java.util.List;
@@ -41,8 +40,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.*;
-@PrepareForTest({ServiceLocatorHolder.class, ServiceLocator.class, ClientBuilder.class,
- WebTarget.class, Response.class, Invocation.Builder.class, Client.class})
+@PrepareForTest({ServiceLocatorHolder.class, ServiceLocator.class, HttpsUtils.class})
@RunWith(PowerMockRunner.class)
public class SubscriberTest {
@@ -50,15 +48,15 @@ public class SubscriberTest {
@Before
public void init() {
- PowerMock.mockStatic(ServiceLocatorHolder.class);
- ServiceLocator serviceLocator = PowerMock.createMock(ServiceLocator.class);
- EasyMock.expect(ServiceLocatorHolder.getLocator()).andReturn(serviceLocator);
- EasyMock.expect(serviceLocator.getService(DMaaPResponseUtil.class)).andReturn(util);
+ PowerMockito.mockStatic(ServiceLocatorHolder.class);
+ ServiceLocator serviceLocator = PowerMockito.mock(ServiceLocator.class);
+ PowerMockito.when(ServiceLocatorHolder.getLocator()).thenReturn(serviceLocator);
+ PowerMockito.when(serviceLocator.getService(DMaaPResponseUtil.class)).thenReturn(util);
}
@Test
public void subscribe() throws Exception {
-
+ PowerMock.resetAll();
VesAlarm vesAlarm = new VesAlarm();
vesAlarm.setDomain("ONAP");
vesAlarm.setEventId("123");
@@ -121,28 +119,24 @@ public class SubscriberTest {
List<String> responseList = new ArrayList<>();
responseList.add(eventString);
+ String responseJson = GsonUtil.beanToJson(responseList);
-
- PowerMock.mockStatic(ClientBuilder.class);
- Client client = PowerMock.createMock(Client.class);
- WebTarget webTarget = PowerMock.createMock(WebTarget.class);
- Response response = PowerMock.createMock(Response.class);
- Invocation.Builder builder = PowerMock.createMock(Invocation.Builder.class);
-
- EasyMock.expect(ClientBuilder.newClient()).andReturn(client);
- EasyMock.expect(client.target(EasyMock.anyObject(String.class))).andReturn(webTarget);
- EasyMock.expect(webTarget.queryParam("timeout", 15000)).andReturn(webTarget);
- EasyMock.expect(webTarget.request()).andReturn(builder);
- EasyMock.expect(builder.get()).andReturn(response);
- EasyMock.expect(response.readEntity(List.class)).andReturn(responseList);
+ PowerMockito.mockStatic(HttpsUtils.class);
+ HttpResponse httpResponse = PowerMockito.mock(HttpResponse.class);
+ PowerMockito.when(HttpsUtils.get(Matchers.eq("https://www.onap.org/group/consumer"),
+ Matchers.any(HashMap.class), Matchers.eq(15000))).thenReturn(httpResponse);
+ PowerMockito.when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn(responseJson);
PowerMock.replayAll();
- List<VesAlarm> vesAlarms = new Subscriber().subscribe();
-
- assertThat(vesAlarm, equalTo(vesAlarms.get(0)));
-
+ Subscriber subscriber = new Subscriber();
+ subscriber.setUrl("https://www.onap.org");
+ subscriber.setConsumerGroup("group");
+ subscriber.setConsumer("consumer");
+ List<VesAlarm> vesAlarms = subscriber.subscribe();
PowerMock.verifyAll();
+
+ assertThat(vesAlarm.getEventName(), equalTo(vesAlarms.get(0).getEventName()));
}
@Test