[DMAAP-CLIENT] First sonar issues review part2
[dmaap/messagerouter/dmaapclient.git] / src / test / java / org / onap / dmaap / mr / client / impl / MRSimplerBatchConsumerTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  *  ================================================================================
7  *  Modifications Copyright © 2021 Orange.
8  *  ================================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
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  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  *
23  *******************************************************************************/
24
25 package org.onap.dmaap.mr.client.impl;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.dmaap.mr.client.MRClientFactory;
30 import org.onap.dmaap.mr.client.MRConsumer;
31
32 import java.io.File;
33 import java.io.FileOutputStream;
34 import java.io.IOException;
35 import java.util.Properties;
36
37 import static org.junit.Assert.assertNotNull;
38
39 public class MRSimplerBatchConsumerTest {
40
41     File outFile;
42
43     @Before
44     public void setUp() throws Exception {
45         Properties properties = new Properties();
46         properties.load(MRSimplerBatchConsumerTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
47
48         String routeFilePath = "dme2/preferredRoute.txt";
49
50         File file = new File(MRSimplerBatchConsumerTest.class.getClassLoader().getResource(routeFilePath).getFile());
51         properties.put("DME2preferredRouterFilePath", MRSimplerBatchConsumerTest.class.getClassLoader().getResource(routeFilePath).getFile());
52
53         outFile = new File(file.getParent() + "/consumer_tmp.properties");
54         properties.store(new FileOutputStream(outFile), "");
55     }
56
57     @Test
58     public void testSend() throws IOException, InterruptedException {
59
60         final MRConsumer cc = MRClientFactory.createConsumer(outFile.getPath());
61
62         try {
63             for (String msg : cc.fetch()) {
64                 System.out.println(msg);
65             }
66         } catch (Exception e) {
67             System.err.println(e.getClass().getName() + ": " + e.getMessage());
68         }
69         assertNotNull(cc);
70
71     }
72
73
74 }