58262d97cd1de513327074217a2fb92ffee3ae1f
[policy/engine.git] / PolicyEngineUtils / src / test / java / org / onap / policy / utils / BusTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineUtils
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.onap.policy.utils;
23
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;
28
29 import java.net.MalformedURLException;
30 import java.util.Arrays;
31
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;
36
37 public class BusTest {
38     
39     @Test 
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());
44         bus.close();
45     }
46     
47     @Test (expected = MRApiException.class)
48     public void busConsumerFailTest() throws Exception {
49         //given
50         MRConsumerImpl mrConsumer = mock(MRConsumerImpl.class);
51         when(mrConsumer.fetch()).thenThrow(new Exception());
52         DmaapConsumerWrapper dmaapConsumerWrapper = new DmaapConsumerWrapper(mrConsumer, "", "", "");
53
54         //when
55         dmaapConsumerWrapper.fetch();
56     }
57     
58     @Test
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]");
62         bus.close();
63     }
64
65 }