• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / contract-management / #13

26 Sep 2023 05:55AM UTC coverage: 1.63%. First build
#13

Pull #1

pulledtim
Tests and docu
Pull Request #1: init

143 of 143 new or added lines in 11 files covered. (100.0%)

241 of 14788 relevant lines covered (1.63%)

0.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.67
/src/main/java/org/fiware/iam/tmforum/NotificationSubscriber.java
1
package org.fiware.iam.tmforum;
2

3
import io.micronaut.context.annotation.Value;
4
import io.micronaut.context.event.ApplicationEventListener;
5
import io.micronaut.http.HttpResponse;
6
import io.micronaut.http.client.exceptions.HttpClientException;
7
import io.micronaut.runtime.server.event.ServerStartupEvent;
8
import io.micronaut.scheduling.TaskScheduler;
9
import jakarta.inject.Singleton;
10
import lombok.RequiredArgsConstructor;
11
import lombok.extern.slf4j.Slf4j;
12
import org.fiware.iam.tmforum.product.client.api.EventsSubscriptionApiClient;
13
import org.fiware.iam.tmforum.product.client.model.EventSubscriptionInputVO;
14
import org.fiware.iam.tmforum.product.client.model.EventSubscriptionVO;
15

16
import java.time.Duration;
17

18
import static org.fiware.iam.tmforum.product.server.api.NotificationListenersClientSideApi.PATH_LISTEN_TO_PRODUCT_ORDER_CREATE_EVENT;
19

20
@Singleton
21
@RequiredArgsConstructor
1✔
22
@Slf4j
1✔
23
public class NotificationSubscriber implements ApplicationEventListener<ServerStartupEvent> {
24

25
    private static final String QUERY_PRODUCT_ORDER_CREATED = "eventType=ProductOrderCreateEvent";
26

27
    private final EventsSubscriptionApiClient eventsSubscriptionApi;
28

29
    private final TaskScheduler taskScheduler;
30

31
    @Value("${general.basepath:}")
32
    private String controllerPath;
33

34
    @Value("${micronaut.server.port:8080}")
35
    private String servicePort;
36

37
    @Value("${general.name:contract-management}")
38
    private String serviceUrl;
39

40
    /**
41
     * Register a subscription at the TM Forum API service after startup. Using the
42
     * {@link io.micronaut.scheduling.annotation.Scheduled} annotation resulted in start
43
     * failure like https://stackoverflow.com/q/77075901/4341660
44
     * @param event
45
     */
46
    @Override
47
    public void onApplicationEvent(ServerStartupEvent event) {
48
        //Using fixed rate since we don't have an option to check if the subscription (still) exists
49
        taskScheduler.scheduleAtFixedRate(Duration.ofSeconds(10),Duration.ofSeconds(30), () -> {
1✔
50
            try {
51
                String callbackUrl = String.format("http://%s:%s%s%s", serviceUrl, servicePort, controllerPath, PATH_LISTEN_TO_PRODUCT_ORDER_CREATE_EVENT);
×
52
                log.info("Attempting to register subscription with callback {}", callbackUrl);
×
53

54
                EventSubscriptionInputVO subscription = new EventSubscriptionInputVO()
×
55
                        .callback(callbackUrl)
×
56
                        .query(QUERY_PRODUCT_ORDER_CREATED);
×
57
                HttpResponse<EventSubscriptionVO> eventSubscriptionVOHttpResponse = eventsSubscriptionApi.registerListener(subscription);
×
58
                log.info("Got reply {} and status {}", eventSubscriptionVOHttpResponse.body(), eventSubscriptionVOHttpResponse.getStatus());
×
59
            } catch (HttpClientException e) {
×
60
                log.error("Could not create subscription in TM Forum API", e);
×
61
            }
×
62
        });
×
63
    }
1✔
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc