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;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
13 import ch.qos.logback.classic.Logger;
14 import ch.qos.logback.classic.spi.ILoggingEvent;
15 import ch.qos.logback.core.read.ListAppender;
16 import java.util.List;
18 import javax.ws.rs.core.Application;
19 import org.glassfish.jersey.server.ResourceConfig;
20 import org.glassfish.jersey.test.JerseyTest;
21 import org.glassfish.jersey.test.TestProperties;
22 import org.junit.jupiter.api.Test;
23 import org.opendaylight.transportpce.dmaap.client.resource.EventsApiStub;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.RxDirectionBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.RxDirectionKey;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionKey;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessServiceBuilder;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceAEndBuilder;
36 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceZEndBuilder;
37 import org.opendaylight.yangtools.yang.common.Uint32;
38 import org.opendaylight.yangtools.yang.common.Uint8;
39 import org.slf4j.LoggerFactory;
41 public class NbiNotificationsListenerImplTest extends JerseyTest {
43 protected Application configure() {
44 enable(TestProperties.LOG_TRAFFIC);
45 enable(TestProperties.DUMP_ENTITY);
46 return new ResourceConfig(EventsApiStub.class);
50 void onPublishNotificationServiceTest() {
51 Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
52 ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
54 logger.addAppender(listAppender);
55 NbiNotificationsListener listener = new NbiNotificationsListenerImpl("http://localhost:9998", null, null);
56 PublishNotificationProcessService notification = new PublishNotificationProcessServiceBuilder()
57 .setCommonId("CommonId")
58 .setMessage("Service implemented")
59 .setOperationalState(State.InService)
60 .setPublisherName("publisher")
61 .setConnectionType(ConnectionType.Service)
62 .setServiceAEnd(new ServiceAEndBuilder()
64 .setNodeId(new NodeIdType("nodeidtype"))
65 .setServiceFormat(ServiceFormat.Ethernet)
66 .setServiceRate(Uint32.valueOf(100))
67 .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO),
68 new RxDirectionBuilder().setIndex(Uint8.ZERO).build()))
69 .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO),
70 new TxDirectionBuilder().setIndex(Uint8.ZERO).build()))
72 .setServiceZEnd(new ServiceZEndBuilder()
74 .setNodeId(new NodeIdType("nodeidtype"))
75 .setServiceFormat(ServiceFormat.Ethernet)
76 .setServiceRate(Uint32.valueOf(100))
77 .setRxDirection(Map.of(new RxDirectionKey(Uint8.ZERO),
78 new RxDirectionBuilder().setIndex(Uint8.ZERO).build()))
79 .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO),
80 new TxDirectionBuilder().setIndex(Uint8.ZERO).build()))
83 listener.onPublishNotificationProcessService(notification);
84 // as onPublishNotificationService is a void method, we check log message to be sure everything went well
85 List<ILoggingEvent> logsList = listAppender.list;
86 assertEquals(logsList.get(1).getFormattedMessage(), "Response received CreatedEvent [serverTimeMs=1, count=1]");