From dc101c2ad5e27d5a0afd4e2feeb8885f24728806 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 24 Aug 2021 13:20:26 -0400 Subject: Use CompareToBuilder Also added lombok to test classes. Issue-ID: POLICY-3391 Change-Id: I9ecf479f3861a2e5211b037e885029d1719b6a56 Signed-off-by: Jim Hahn --- .../restclient/SupportApexEventReceiver.java | 20 +--- .../restserver/SupportApexEventReceiver.java | 20 +--- .../event/protocol/xml/XmlEventGenerator.java | 12 +-- .../entities/ArtifactKeyTestEntity.java | 101 +++------------------ .../entities/ReferenceKeyTestEntity.java | 101 +++------------------ 5 files changed, 37 insertions(+), 217 deletions(-) (limited to 'plugins') diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java index f2201379d..49135f5d4 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +23,7 @@ package org.onap.policy.apex.plugins.event.carrier.restclient; import java.util.Properties; +import lombok.Getter; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventReceiver; @@ -29,6 +31,7 @@ import org.onap.policy.apex.service.engine.event.ApexEventReceiver; * Support Apex event reveiver for unit test. * */ +@Getter public class SupportApexEventReceiver implements ApexEventReceiver { private long lastExecutionId; private Object lastEvent; @@ -53,21 +56,4 @@ public class SupportApexEventReceiver implements ApexEventReceiver { this.lastEvent = event; this.eventCount++; } - - public long getLastExecutionId() { - return lastExecutionId; - } - - public Object getLastEvent() { - return lastEvent; - } - - /** - * Get the number of events received. - * - * @return the number of events received - */ - public int getEventCount() { - return eventCount; - } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java index cd60c220d..773ecafb2 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.apex.plugins.event.carrier.restserver; import java.util.Properties; +import lombok.Getter; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventReceiver; @@ -28,6 +30,7 @@ import org.onap.policy.apex.service.engine.event.ApexEventReceiver; * Support Apex event reveiver for unit test. * */ +@Getter public class SupportApexEventReceiver implements ApexEventReceiver { private long lastExecutionId; private Object lastEvent; @@ -52,21 +55,4 @@ public class SupportApexEventReceiver implements ApexEventReceiver { this.lastEvent = event; this.eventCount++; } - - public long getLastExecutionId() { - return lastExecutionId; - } - - public Object getLastEvent() { - return lastEvent; - } - - /** - * Get the number of events received. - * - * @return the number of events received - */ - public int getEventCount() { - return eventCount; - } } diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventGenerator.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventGenerator.java index f85d9119e..9c8696c6c 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventGenerator.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventGenerator.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,11 +22,13 @@ package org.onap.policy.apex.plugins.event.protocol.xml; import java.util.Random; +import lombok.Getter; /** * The Class XmlEventGenerator. */ public class XmlEventGenerator { + @Getter private static int nextEventNo = 0; /** @@ -113,13 +116,4 @@ public class XmlEventGenerator { System.out.println(xmlEvents(eventCount)); } - - /** - * Gets the next event no. - * - * @return the next event no - */ - public static int getNextEventNo() { - return nextEventNo; - } } diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ArtifactKeyTestEntity.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ArtifactKeyTestEntity.java index f1561c2b8..98a4c5738 100644 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ArtifactKeyTestEntity.java +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ArtifactKeyTestEntity.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +27,11 @@ import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; import javax.xml.bind.annotation.XmlElement; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.apache.commons.lang3.builder.CompareToBuilder; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; @@ -36,6 +42,10 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; */ @Entity @Table(name = "ArtifactKeyTestEntity") +@Getter +@Setter +@ToString +@EqualsAndHashCode(callSuper = false) public class ArtifactKeyTestEntity extends AxConcept { private static final long serialVersionUID = -2962570563281067896L; @@ -74,14 +84,6 @@ public class ArtifactKeyTestEntity extends AxConcept { this.doubleValue = doubleValue; } - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - /** * {@inheritDoc}. */ @@ -90,15 +92,6 @@ public class ArtifactKeyTestEntity extends AxConcept { return Arrays.asList((AxKey) getKey()); } - /** - * Sets the key. - * - * @param key the new key - */ - public void setKey(final AxArtifactKey key) { - this.key = key; - } - /** * Check set key. * @@ -108,24 +101,6 @@ public class ArtifactKeyTestEntity extends AxConcept { return (this.key != null); } - /** - * Gets the double value. - * - * @return the double value - */ - public double getDoubleValue() { - return doubleValue; - } - - /** - * Sets the double value. - * - * @param doubleValue the new double value - */ - public void setDoubleValue(final double doubleValue) { - this.doubleValue = doubleValue; - } - /** * {@inheritDoc}. */ @@ -142,14 +117,6 @@ public class ArtifactKeyTestEntity extends AxConcept { key.clean(); } - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - return "ArtifactKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]"; - } - /** * {@inheritDoc}. */ @@ -170,42 +137,6 @@ public class ArtifactKeyTestEntity extends AxConcept { } } - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - return (Double.compare(doubleValue, other.doubleValue) == 0); - } - /** * {@inheritDoc}. */ @@ -221,13 +152,9 @@ public class ArtifactKeyTestEntity extends AxConcept { return -1; } final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) otherObj; - if (key == null) { - if (other.key != null) { - return 1; - } - } else if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - return Double.compare(doubleValue, other.doubleValue); + return new CompareToBuilder() + .append(key, other.key) + .append(doubleValue, other.doubleValue) + .toComparison(); } } diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ReferenceKeyTestEntity.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ReferenceKeyTestEntity.java index afeeb84fd..cadc9b8db 100644 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ReferenceKeyTestEntity.java +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ReferenceKeyTestEntity.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +28,11 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.apache.commons.lang3.builder.CompareToBuilder; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; @@ -38,6 +44,10 @@ import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter; */ @Entity @Table(name = "ReferenceKeyTestEntity") +@Getter +@Setter +@ToString +@EqualsAndHashCode(callSuper = false) public class ReferenceKeyTestEntity extends AxConcept { private static final long serialVersionUID = -2962570563281067895L; @@ -77,14 +87,6 @@ public class ReferenceKeyTestEntity extends AxConcept { this.doubleValue = doubleValue; } - /** - * {@inheritDoc}. - */ - @Override - public AxReferenceKey getKey() { - return key; - } - /** * {@inheritDoc}. */ @@ -93,15 +95,6 @@ public class ReferenceKeyTestEntity extends AxConcept { return Arrays.asList((AxKey) getKey()); } - /** - * Sets the key. - * - * @param key the new key - */ - public void setKey(final AxReferenceKey key) { - this.key = key; - } - /** * Check set key. * @@ -111,24 +104,6 @@ public class ReferenceKeyTestEntity extends AxConcept { return (this.key != null); } - /** - * Gets the double value. - * - * @return the double value - */ - public double getDoubleValue() { - return doubleValue; - } - - /** - * Sets the double value. - * - * @param doubleValue the new double value - */ - public void setDoubleValue(final double doubleValue) { - this.doubleValue = doubleValue; - } - /** * {@inheritDoc}. */ @@ -145,14 +120,6 @@ public class ReferenceKeyTestEntity extends AxConcept { key.clean(); } - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]"; - } - /** * {@inheritDoc}. */ @@ -173,42 +140,6 @@ public class ReferenceKeyTestEntity extends AxConcept { } } - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - return (Double.compare(doubleValue, other.doubleValue) == 0); - } - /** * {@inheritDoc}. */ @@ -224,13 +155,9 @@ public class ReferenceKeyTestEntity extends AxConcept { return -1; } final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj; - if (key == null) { - if (other.key != null) { - return 1; - } - } else if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - return Double.compare(doubleValue, other.doubleValue); + return new CompareToBuilder() + .append(key, other.key) + .append(doubleValue, other.doubleValue) + .toComparison(); } } -- cgit 1.2.3-korg