2 * Copyright © 2021 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.dmaap.client.listener;
10 import static org.junit.Assert.assertEquals;
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;
17 import javax.ws.rs.core.Application;
18 import org.glassfish.jersey.server.ResourceConfig;
19 import org.glassfish.jersey.test.JerseyTest;
20 import org.glassfish.jersey.test.TestProperties;
21 import org.junit.Test;
22 import org.opendaylight.transportpce.dmaap.client.resource.EventsApiStub;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.endpoint.RxDirectionBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.endpoint.RxDirectionKey;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.endpoint.TxDirectionBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.service.endpoint.TxDirectionKey;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsListener;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessService;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessServiceBuilder;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.notification.process.service.ServiceAEndBuilder;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.notification.process.service.ServiceZEndBuilder;
36 import org.opendaylight.yangtools.yang.common.Uint32;
37 import org.opendaylight.yangtools.yang.common.Uint8;
38 import org.slf4j.LoggerFactory;
40 public class NbiNotificationsListenerImplTest extends JerseyTest {
42 protected Application configure() {
43 enable(TestProperties.LOG_TRAFFIC);
44 enable(TestProperties.DUMP_ENTITY);
45 return new ResourceConfig(EventsApiStub.class);
49 public void onPublishNotificationServiceTest() {
50 Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
51 ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
53 logger.addAppender(listAppender);
54 NbiNotificationsListener listener = new NbiNotificationsListenerImpl("http://localhost:9998", null, null);
55 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
56 .setCommonId("CommonId")
57 .setMessage("Service implemented")
58 .setOperationalState(State.InService)
59 .setPublisherName("publisher")
60 .setConnectionType(ConnectionType.Service)
61 .setServiceAEnd(new ServiceAEndBuilder()
63 .setNodeId(new NodeIdType("nodeidtype"))
64 .setServiceFormat(ServiceFormat.Ethernet)
65 .setServiceRate(Uint32.valueOf(100))
66 .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO),
67 new RxDirectionBuilder().setIndex(Uint8.ZERO).build()))
68 .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO),
69 new TxDirectionBuilder().setIndex(Uint8.ZERO).build()))
71 .setServiceZEnd(new ServiceZEndBuilder()
73 .setNodeId(new NodeIdType("nodeidtype"))
74 .setServiceFormat(ServiceFormat.Ethernet)
75 .setServiceRate(Uint32.valueOf(100))
76 .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO),
77 new RxDirectionBuilder().setIndex(Uint8.ZERO).build()))
78 .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO),
79 new TxDirectionBuilder().setIndex(Uint8.ZERO).build()))
82 listener.onPublishNotificationProcessService(notification);
83 // as onPublishNotificationService is a void method, we check log message to be sure everything went well
84 List<ILoggingEvent> logsList = listAppender.list;
85 assertEquals("Response received CreatedEvent [serverTimeMs=1, count=1]", logsList.get(1).getFormattedMessage());