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;
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.service.types.rev190531.ConnectionType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirectionBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirectionBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NbiNotificationsListener;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationService;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationServiceBuilder;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.notification.service.ServiceAEndBuilder;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.notification.service.ServiceZEndBuilder;
32 import org.opendaylight.yangtools.yang.common.Uint32;
33 import org.slf4j.LoggerFactory;
35 public class NbiNotificationsListenerImplTest extends JerseyTest {
37 protected Application configure() {
38 enable(TestProperties.LOG_TRAFFIC);
39 enable(TestProperties.DUMP_ENTITY);
40 return new ResourceConfig(EventsApiStub.class);
44 public void onPublishNotificationServiceTest() {
45 Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
46 ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
48 logger.addAppender(listAppender);
49 NbiNotificationsListener listener = new NbiNotificationsListenerImpl("http://localhost:9998", null, null);
50 PublishNotificationService notification = new PublishNotificationServiceBuilder().setCommonId("CommonId")
51 .setMessage("Service implemented")
52 .setOperationalState(State.InService)
54 .setConnectionType(ConnectionType.Service)
55 .setServiceAEnd(new ServiceAEndBuilder()
57 .setNodeId(new org.opendaylight.yang.gen.v1.http
58 .org.openroadm.common.node.types.rev181130.NodeIdType("nodeidtype"))
59 .setServiceFormat(ServiceFormat.Ethernet)
60 .setServiceRate(Uint32.valueOf(100))
61 .setRxDirection(new RxDirectionBuilder().build())
62 .setTxDirection(new TxDirectionBuilder().build())
64 .setServiceZEnd(new ServiceZEndBuilder()
66 .setNodeId(new org.opendaylight.yang.gen.v1.http
67 .org.openroadm.common.node.types.rev181130.NodeIdType("nodeidtype"))
68 .setServiceFormat(ServiceFormat.Ethernet)
69 .setServiceRate(Uint32.valueOf(100))
70 .setRxDirection(new RxDirectionBuilder().build())
71 .setTxDirection(new TxDirectionBuilder().build())
74 listener.onPublishNotificationService(notification);
75 // as onPublishNotificationService is a void method, we check log message to be sur everything went well
76 List<ILoggingEvent> logsList = listAppender.list;
77 assertEquals("Response received CreatedEvent [serverTimeMs=1, count=1]", logsList.get(1).getFormattedMessage());