Migration to TAPI 2.4 Step2
[transportpce.git] / dmaap-client / src / test / java / org / opendaylight / transportpce / dmaap / client / listener / NbiNotificationsHandlerTest.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
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12
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;
17 import java.util.Map;
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.rev230728.PublishNotificationProcessService;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.PublishNotificationProcessServiceBuilder;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.process.service.ServiceAEndBuilder;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.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;
39
40 public class NbiNotificationsHandlerTest extends JerseyTest {
41     @Override
42     protected Application configure() {
43         enable(TestProperties.LOG_TRAFFIC);
44         enable(TestProperties.DUMP_ENTITY);
45         return new ResourceConfig(EventsApiStub.class);
46     }
47
48     @Test
49     void onPublishNotificationServiceTest() {
50         Logger logger = (Logger) LoggerFactory.getLogger(NbiNotificationsHandler.class);
51         ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
52         listAppender.start();
53         logger.addAppender(listAppender);
54         NbiNotificationsHandler listener = new NbiNotificationsHandler("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()
62                         .setClli("clli")
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()))
70                         .build())
71                 .setServiceZEnd(new ServiceZEndBuilder()
72                         .setClli("clli")
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()))
80                         .build())
81                 .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(logsList.get(1).getFormattedMessage(), "Response received CreatedEvent [serverTimeMs=1, count=1]");
86     }
87 }