Refactor NBINotifications and serviceHandlerImpl
[transportpce.git] / dmaap-client / src / test / java / org / opendaylight / transportpce / dmaap / client / listener / NbiNotificationsListenerImplTest.java
1 /*
2  * Copyright © 2021 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.dmaap.client.listener;
9
10 import static org.junit.Assert.assertEquals;
11
12 import ch.qos.logback.classic.Logger;
13 import ch.qos.logback.classic.spi.ILoggingEvent;
14 import ch.qos.logback.core.read.ListAppender;
15 import java.util.List;
16 import javax.ws.rs.core.Application;
17 import org.glassfish.jersey.server.ResourceConfig;
18 import org.glassfish.jersey.test.JerseyTest;
19 import org.glassfish.jersey.test.TestProperties;
20 import org.junit.Test;
21 import org.opendaylight.transportpce.dmaap.client.resource.EventsApiStub;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirectionBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirectionBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsListener;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessService;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessServiceBuilder;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.notification.process.service.ServiceAEndBuilder;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.notification.process.service.ServiceZEndBuilder;
33 import org.opendaylight.yangtools.yang.common.Uint32;
34 import org.slf4j.LoggerFactory;
35
36 public class NbiNotificationsListenerImplTest extends JerseyTest {
37     @Override
38     protected Application configure() {
39         enable(TestProperties.LOG_TRAFFIC);
40         enable(TestProperties.DUMP_ENTITY);
41         return new ResourceConfig(EventsApiStub.class);
42     }
43
44     @Test
45     public void onPublishNotificationServiceTest() {
46         Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
47         ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
48         listAppender.start();
49         logger.addAppender(listAppender);
50         NbiNotificationsListener listener = new NbiNotificationsListenerImpl("http://localhost:9998", null, null);
51         PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
52                 .setCommonId("CommonId")
53                 .setMessage("Service implemented")
54                 .setOperationalState(State.InService)
55                 .setPublisherName("publisher")
56                 .setConnectionType(ConnectionType.Service)
57                 .setServiceAEnd(new ServiceAEndBuilder()
58                         .setClli("clli")
59                         .setNodeId(new NodeIdType("nodeidtype"))
60                         .setServiceFormat(ServiceFormat.Ethernet)
61                         .setServiceRate(Uint32.valueOf(100))
62                         .setRxDirection(new RxDirectionBuilder().build())
63                         .setTxDirection(new TxDirectionBuilder().build())
64                         .build())
65                 .setServiceZEnd(new ServiceZEndBuilder()
66                         .setClli("clli")
67                         .setNodeId(new NodeIdType("nodeidtype"))
68                         .setServiceFormat(ServiceFormat.Ethernet)
69                         .setServiceRate(Uint32.valueOf(100))
70                         .setRxDirection(new RxDirectionBuilder().build())
71                         .setTxDirection(new TxDirectionBuilder().build())
72                         .build())
73                 .build();
74         listener.onPublishNotificationProcessService(notification);
75         // as onPublishNotificationService is a void method, we check log message to be sure everything went well
76         List<ILoggingEvent> logsList = listAppender.list;
77         assertEquals("Response received CreatedEvent [serverTimeMs=1, count=1]", logsList.get(1).getFormattedMessage());
78
79     }
80 }