Default ctors in notification-api module 77/27177/2
authorvempo <vitaliy.emporopulo@amdocs.com>
Sun, 31 Dec 2017 09:12:53 +0000 (11:12 +0200)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Sun, 31 Dec 2017 11:29:31 +0000 (11:29 +0000)
Change-Id: I823348c05a367ed876a63aaa146a98d1cb869cd8
Issue-ID: SDC-343
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/pom.xml
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntity.java
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/NotificationEntity.java
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/main/java/org/openecomp/sdc/notification/dao/types/SubscribersEntity.java
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/LastSeenNotificationEntityTest.java [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/NotificationEntityTest.java [new file with mode: 0644]
openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-api/src/test/java/org/openecomp/sdc/notification/dao/types/SubscribersEntityTest.java [new file with mode: 0644]

index 8e1c293..8eac54e 100644 (file)
             <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>
index d6e717d..bdd2ad4 100644 (file)
@@ -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
index cc9309b..85af302 100644 (file)
@@ -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
index d858cbd..1f3d04a 100644 (file)
@@ -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 (file)
index 0000000..823a7f2
--- /dev/null
@@ -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 (file)
index 0000000..fc5792b
--- /dev/null
@@ -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 (file)
index 0000000..b5761dc
--- /dev/null
@@ -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