Skip to content

Commit

Permalink
Notify the customer about the upcoming license expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
v-rudkovskiy authored Dec 11, 2023
1 parent afe8eb5 commit f64b478
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.util.Arrays;

public enum Event {
CREATE_LICENSEE, CREATE_LICENSE;
LICENSEE_CREATED,
LICENSE_CREATED,
WARNING_LEVEL_CHANGED;

public static Event parseString(final String value) {
return Arrays.stream(Event.values()).filter((e) -> e.name().equalsIgnoreCase(value)).findFirst().orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testCreate() throws Exception {
newNotification.setActive(true);

final Set<Event> events = new HashSet<>();
events.add(Event.CREATE_LICENSEE);
events.add(Event.LICENSEE_CREATED);

newNotification.setEvents(events);
newNotification.setProtocol(NotificationProtocol.WEBHOOK);
Expand All @@ -89,7 +89,7 @@ public void testCreate() throws Exception {
@Test
public void testNameIsRequired() throws Exception {
final Notification newNotification = new NotificationImpl();
newNotification.addEvent(Event.CREATE_LICENSEE);
newNotification.addEvent(Event.LICENSEE_CREATED);
newNotification.setProtocol(NotificationProtocol.WEBHOOK);
newNotification.addProperty(Constants.Notification.ENDPOINT, "http://www.test.test");

Expand Down Expand Up @@ -118,7 +118,7 @@ public void testEventsIsRequired() throws Exception {
public void testTypeIsRequired() throws Exception {
final Notification newNotification = new NotificationImpl();
newNotification.setName("Notification 1");
newNotification.addEvent(Event.CREATE_LICENSEE);
newNotification.addEvent(Event.LICENSEE_CREATED);
newNotification.addProperty(Constants.Notification.ENDPOINT, "http://www.test.test");
newNotification.setPayload("${event}");

Expand All @@ -133,7 +133,7 @@ public void testTypeIsRequired() throws Exception {
public void testEndpointIsRequired() throws Exception {
final Notification newNotification = new NotificationImpl();
newNotification.setName("Notification 1");
newNotification.addEvent(Event.CREATE_LICENSEE);
newNotification.addEvent(Event.LICENSEE_CREATED);
newNotification.setProtocol(NotificationProtocol.WEBHOOK);

final Exception e = assertThrows(ServiceException.class, () -> {
Expand All @@ -151,8 +151,9 @@ public void testGet() throws Exception {
assertEquals("Notification 14", notification.getName());

final Set<Event> expectedEvents = new HashSet<>();
expectedEvents.add(Event.CREATE_LICENSEE);
expectedEvents.add(Event.CREATE_LICENSE);
expectedEvents.add(Event.LICENSEE_CREATED);
expectedEvents.add(Event.LICENSE_CREATED);
expectedEvents.add(Event.WARNING_LEVEL_CHANGED);

assertEquals(expectedEvents, notification.getEvents());
assertEquals(NotificationProtocol.WEBHOOK, notification.getProtocol());
Expand All @@ -170,7 +171,7 @@ public void testList() throws Exception {
assertEquals(3, notifications.getItemsNumber());
assertEquals("N001-TEST", notifications.getContent().get(0).getNumber());
assertEquals("Notification 2", notifications.getContent().get(1).getName());
assertEquals(Event.CREATE_LICENSEE.name(), notifications.getContent().get(2).getEvents().stream().map(Enum::name).collect(Collectors.joining(",")));
assertEquals(Event.LICENSEE_CREATED.name(), notifications.getContent().get(2).getEvents().stream().map(Enum::name).collect(Collectors.joining(",")));
}

@Test
Expand All @@ -181,7 +182,7 @@ public void testUpdate() throws Exception {
notification.addProperty(NOTIFICATION_CUSTOM_PROPERTY, "Test Value");

final Set<Event> events = new HashSet<>();
events.add(Event.CREATE_LICENSE);
events.add(Event.LICENSE_CREATED);

notification.setEvents(events);

Expand All @@ -191,7 +192,7 @@ public void testUpdate() throws Exception {
assertEquals("Notification 2", updatedNotification.getName());
assertEquals("N002-TEST", updatedNotification.getNumber());
assertEquals(false, updatedNotification.getActive());
assertEquals(Event.CREATE_LICENSE.name(), updatedNotification.getEvents().stream().map(Enum::name).collect(Collectors.joining(",")));
assertEquals(Event.LICENSE_CREATED.name(), updatedNotification.getEvents().stream().map(Enum::name).collect(Collectors.joining(",")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<property name="number">N014-TEST</property>
<property name="active">true</property>
<property name="name">Notification 14</property>
<property name="events">CREATE_LICENSEE,CREATE_LICENSE</property>
<property name="events">LICENSEE_CREATED,LICENSE_CREATED,WARNING_LEVEL_CHANGED</property>
<property name="protocol">WEBHOOK</property>
<property name="endpoint">http://www.test.test</property>
<property name="payload">${event}</property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<property name="number">N001-TEST</property>
<property name="active">true</property>
<property name="name">Notification 1</property>
<property name="events">CREATE_LICENSEE</property>
<property name="events">LICENSEE_CREATED</property>
<property name="protocol">WEBHOOK</property>
<property name="endpoint">http://www.test1.test</property>
<property name="payload">${event}</property>
Expand All @@ -16,7 +16,7 @@
<property name="number">N002-TEST</property>
<property name="active">true</property>
<property name="name">Notification 2</property>
<property name="events">CREATE_LICENSE</property>
<property name="events">LICENSE_CREATED</property>
<property name="protocol">WEBHOOK</property>
<property name="endpoint">http://www.test2.test</property>
<property name="payload">${event.timestamp}</property>
Expand All @@ -25,7 +25,7 @@
<property name="number">N003-TEST</property>
<property name="active">true</property>
<property name="name">Notification 3</property>
<property name="events">CREATE_LICENSEE</property>
<property name="events">LICENSEE_CREATED</property>
<property name="protocol">WEBHOOK</property>
<property name="endpoint">http://www.test3.test</property>
<property name="payload">${event.data}</property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<property name="number">N002-TEST</property>
<property name="active">false</property>
<property name="name">Notification 2</property>
<property name="events">CREATE_LICENSEE</property>
<property name="events">LICENSEE_CREATED</property>
<property name="protocol">WEBHOOK</property>
<property name="endpoint">http://www.test.test</property>
<property name="payload">${event}</property>
Expand Down

0 comments on commit f64b478

Please sign in to comment.