2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications copyright (c) 2019 Nokia
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.utils;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.net.MalformedURLException;
30 import java.util.Arrays;
32 import org.junit.Test;
33 import org.onap.dmaap.mr.client.MRClient.MRApiException;
34 import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
35 import org.onap.policy.utils.BusConsumer.DmaapConsumerWrapper;
37 public class BusTest {
40 public void busPublisherTest(){
41 BusPublisher bus = new BusPublisher.DmaapPublisherWrapper(Arrays.asList("test"), "test", "test", "test");
42 assertTrue(bus.send("test123", "Hello World!"));
43 assertEquals("DmaapPublisherWrapper [publisher.getAuthDate()=null, publisher.getAuthKey()=null, publisher.getHost()=test, publisher.getProtocolFlag()=HTTPAAF, publisher.getUsername()=test, publisher.getPendingMessageCount()=1]",bus.toString());
47 @Test (expected = MRApiException.class)
48 public void busConsumerFailTest() throws Exception {
50 MRConsumerImpl mrConsumer = mock(MRConsumerImpl.class);
51 when(mrConsumer.fetch()).thenThrow(new Exception());
52 DmaapConsumerWrapper dmaapConsumerWrapper = new DmaapConsumerWrapper(mrConsumer, "", "", "");
55 dmaapConsumerWrapper.fetch();
59 public void busConsumerTest() throws MalformedURLException, MRApiException{
60 BusConsumer bus = new BusConsumer.DmaapConsumerWrapper(Arrays.asList("test"), "test", "test", "test", "test", "test", 1, 1);
61 assertEquals(bus.toString(),"DmaapConsumerWrapper [consumer.getAuthDate()=null, consumer.getAuthKey()=null, consumer.getHost()=test:3904, consumer.getProtocolFlag()=HTTPAAF, consumer.getUsername()=test]");