diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api')
7 files changed, 307 insertions, 73 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/pom.xml b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/pom.xml index 8e1c293e16..8eac54e53f 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/pom.xml @@ -16,5 +16,11 @@ <artifactId>openecomp-nosqldb-core</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>${testng.version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntity.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntity.java index d6e717d1b3..bdd2ad4fad 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntity.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntity.java @@ -1,9 +1,6 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2017 European Support Limited + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END========================================================= */ package org.openecomp.sdc.notification.dao.types; @@ -38,7 +34,13 @@ public class LastSeenNotificationEntity { @Column(name = "event_id") private UUID lastEventId; + /** + * Every entity class must have a default constructor according to + * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/"> + * Definition of mapped classes</a>. + */ public LastSeenNotificationEntity() { + // Don't delete! Default constructor is required by DataStax driver } /** @@ -69,29 +71,17 @@ public class LastSeenNotificationEntity { } @Override - public boolean equals(Object other) { - if (Objects.equals(this, other)) { - return true; - } - - if (Objects.equals(getClass(), other.getClass())) { - return false; - } - - LastSeenNotificationEntity that = (LastSeenNotificationEntity) other; - - if (Objects.equals(ownerId, that.ownerId)) { - return false; - } - - return !Objects.equals(lastEventId, that.lastEventId); + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LastSeenNotificationEntity that = (LastSeenNotificationEntity) o; + return Objects.equals(ownerId, that.ownerId) && + Objects.equals(lastEventId, that.lastEventId); } @Override public int hashCode() { - int result = ownerId != null ? ownerId.hashCode() : 0; - result = 31 * result + (lastEventId != null ? lastEventId.hashCode() : 0); - return result; + return Objects.hash(ownerId, lastEventId); } @Override diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/NotificationEntity.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/NotificationEntity.java index cc9309be97..85af302205 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/NotificationEntity.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/NotificationEntity.java @@ -1,9 +1,6 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2017 European Support Limited + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END========================================================= */ package org.openecomp.sdc.notification.dao.types; @@ -53,7 +49,13 @@ public class NotificationEntity { @Column(name = "originator_id") private String originatorId; + /** + * Every entity class must have a default constructor according to + * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/"> + * Definition of mapped classes</a>. + */ public NotificationEntity() { + // Don't delete! Default constructor is required by DataStax driver } public NotificationEntity(String ownerId) { @@ -68,7 +70,8 @@ public class NotificationEntity { * @param eventType the event type * @param originatorId the originator id */ - public NotificationEntity(String ownerId, UUID eventId, String eventType, String originatorId, boolean read, String eventAttributes) { + public NotificationEntity(String ownerId, UUID eventId, String eventType, String originatorId, boolean read, + String eventAttributes) { this.ownerId = ownerId; this.read = read; this.eventId = eventId; @@ -133,49 +136,23 @@ public class NotificationEntity { this.originatorId = originatorId; } + @Override - public boolean equals(Object other) { - if (Objects.equals(this, other)) { - return true; - } - - if (other == null){ - return false; - } - - if (Objects.equals(getClass(), other.getClass())) { - return false; - } - - NotificationEntity that = (NotificationEntity) other; - - if (Objects.equals(ownerId, that.ownerId)) { - return false; - } - if (read != that.read) { - return false; - } - if (Objects.equals(eventId, that.eventId)) { - return false; - } - if (Objects.equals(eventType, that.eventType)) { - return false; - } - if (Objects.equals(eventAttributes, that.eventAttributes)) { - return false; - } - if (Objects.equals(originatorId, that.originatorId)) { - return false; - } - - return true; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + NotificationEntity that = (NotificationEntity) o; + return read == that.read && + Objects.equals(ownerId, that.ownerId) && + Objects.equals(eventId, that.eventId) && + Objects.equals(eventType, that.eventType) && + Objects.equals(eventAttributes, that.eventAttributes) && + Objects.equals(originatorId, that.originatorId); } @Override public int hashCode() { - int result = ownerId != null ? ownerId.hashCode() : 0; - result = 31 * result + (eventId != null ? eventId.hashCode() : 0); - return result; + return Objects.hash(ownerId, read, eventId, eventType, eventAttributes, originatorId); } @Override diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/SubscribersEntity.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/SubscribersEntity.java index d858cbd9eb..1f3d04ab0d 100644 --- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/SubscribersEntity.java +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/SubscribersEntity.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openecomp.sdc.notification.dao.types; import com.datastax.driver.mapping.annotations.Column; @@ -19,8 +35,13 @@ public class SubscribersEntity { @Column(name = "subscribers") private Set<String> subscribers; - + /** + * Every entity class must have a default constructor according to + * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/"> + * Definition of mapped classes</a>. + */ public SubscribersEntity() { + // Don't delete! Default constructor is required by DataStax driver } public SubscribersEntity(String entityId, Set<String> subscribers) { diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntityTest.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntityTest.java new file mode 100644 index 0000000000..823a7f2166 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntityTest.java @@ -0,0 +1,65 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.notification.dao.types; + +import org.testng.annotations.Test; + +import java.util.UUID; + +import static org.testng.Assert.*; + +/** + * @author EVITALIY + * @since 31 Dec 17 + */ +public class LastSeenNotificationEntityTest { + + @Test + public void testEquals() { + UUID uuid = UUID.randomUUID(); + String owner = "owner-" + uuid.toString(); + assertEquals(new LastSeenNotificationEntity(owner, uuid), new LastSeenNotificationEntity(owner, uuid)); + } + + @Test + public void testUninitializedEquals() { + assertEquals(new LastSeenNotificationEntity(), new LastSeenNotificationEntity()); + } + + @Test + public void testUuidNotEqual() { + String owner = "owner"; + assertNotEquals(new LastSeenNotificationEntity(owner, UUID.randomUUID()), + new LastSeenNotificationEntity(owner, UUID.randomUUID())); + } + + @Test + public void testOwnerNotEqual() { + UUID uuid = UUID.randomUUID(); + assertNotEquals(new LastSeenNotificationEntity(UUID.randomUUID().toString(), uuid), + new LastSeenNotificationEntity(UUID.randomUUID().toString(), uuid)); + } + + @Test + public void testHashCode() { + UUID uuid = UUID.randomUUID(); + String owner = uuid.toString(); + assertEquals( + new LastSeenNotificationEntity(owner, uuid).hashCode(), + new LastSeenNotificationEntity(owner, uuid).hashCode()); + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/NotificationEntityTest.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/NotificationEntityTest.java new file mode 100644 index 0000000000..fc5792b4d4 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/NotificationEntityTest.java @@ -0,0 +1,100 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.notification.dao.types; + +import org.testng.annotations.Test; + +import java.util.UUID; + +import static org.testng.Assert.*; + +/** + * @author EVITALIY + * @since 31 Dec 17 + */ +public class NotificationEntityTest { + + @Test + public void testUninitializedEquals() { + assertEquals(new NotificationEntity(), new NotificationEntity()); + } + + @Test + public void testEquals() { + UUID random = UUID.randomUUID(); + assertEquals(createNotificationEntity(random), createNotificationEntity(random)); + } + + @Test + public void testOwnerNotEquals() { + UUID random = UUID.randomUUID(); + NotificationEntity mutant = createNotificationEntity(random); + mutant.setOwnerId(UUID.randomUUID().toString()); + assertNotEquals(mutant, createNotificationEntity(random)); + } + + @Test + public void testEventIdNotEquals() { + UUID random = UUID.randomUUID(); + NotificationEntity mutant = createNotificationEntity(random); + mutant.setEventId(UUID.randomUUID()); + assertNotEquals(mutant, createNotificationEntity(random)); + } + + @Test + public void testEventTypeNotEquals() { + UUID random = UUID.randomUUID(); + NotificationEntity mutant = createNotificationEntity(random); + mutant.setEventType(UUID.randomUUID().toString()); + assertNotEquals(mutant, createNotificationEntity(random)); + } + + @Test + public void testOriginatorNotEquals() { + UUID random = UUID.randomUUID(); + NotificationEntity mutant = createNotificationEntity(random); + mutant.setOriginatorId(UUID.randomUUID().toString()); + assertNotEquals(mutant, createNotificationEntity(random)); + } + + @Test + public void testReadNotEquals() { + UUID random = UUID.randomUUID(); + NotificationEntity mutant = createNotificationEntity(random); + mutant.setRead(false); + assertNotEquals(mutant, createNotificationEntity(random)); + } + + @Test + public void testAttributesNotEquals() { + UUID random = UUID.randomUUID(); + NotificationEntity mutant = createNotificationEntity(random); + mutant.setEventAttributes(UUID.randomUUID().toString()); + assertNotEquals(mutant, createNotificationEntity(random)); + } + + @Test + public void testHashCode() { + UUID random = UUID.randomUUID(); + assertEquals(createNotificationEntity(random).hashCode(), createNotificationEntity(random).hashCode()); + } + + private NotificationEntity createNotificationEntity(UUID random) { + return new NotificationEntity("owner-" + random, random, "type-" + random, + "originator-" + random, true, "attributes-" + random); + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/SubscribersEntityTest.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/SubscribersEntityTest.java new file mode 100644 index 0000000000..b5761dcc72 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/SubscribersEntityTest.java @@ -0,0 +1,75 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.notification.dao.types; + +import org.testng.annotations.Test; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; + +/** + * @author EVITALIY + * @since 31 Dec 17 + */ +public class SubscribersEntityTest { + + private static final Set<String> SUBSCRIBERS; + + static { + Set<String> subs = new HashSet<>(2); + subs.add(UUID.randomUUID().toString()); + subs.add(UUID.randomUUID().toString()); + SUBSCRIBERS = Collections.unmodifiableSet(subs); + } + + @Test + public void testUninitializedEquals() { + assertEquals(new SubscribersEntity(), new SubscribersEntity()); + } + + @Test + public void testEquals() { + String entity = UUID.randomUUID().toString(); + assertEquals(new SubscribersEntity(entity, SUBSCRIBERS), new SubscribersEntity(entity, SUBSCRIBERS)); + } + + @Test + public void testEntityNotEquals() { + assertNotEquals(new SubscribersEntity(UUID.randomUUID().toString(), SUBSCRIBERS), + new SubscribersEntity(UUID.randomUUID().toString(), SUBSCRIBERS)); + } + + @Test + public void testSubscribersNotEquals() { + String entity = UUID.randomUUID().toString(); + assertNotEquals(new SubscribersEntity(entity, SUBSCRIBERS), + // not using Collections.emptySet() to use the the same implementation class + new SubscribersEntity(entity, Collections.unmodifiableSet(new HashSet<>(0)))); + } + + @Test + public void testHashCode() { + String entity = UUID.randomUUID().toString(); + assertEquals(new SubscribersEntity(entity, SUBSCRIBERS).hashCode(), + new SubscribersEntity(entity, SUBSCRIBERS).hashCode()); + } +}
\ No newline at end of file |