diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-02-02 09:25:14 -0500 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2018-02-02 09:34:58 -0500 |
commit | 4aadab035016ebc675698961f410583eee86ebc7 (patch) | |
tree | a96b13db115d15eb6260e708542b2794d3d95175 /integrity-audit | |
parent | c23099a762c165ca8d1fd064902e91191952f678 (diff) |
Removed commented code and add JUnit tests
* Useless assignments
* Commented out code
* Unused imports
* Add simple JUnit for exception classes
Issue-ID: POLICY-456
Change-Id: I012c2b6bdaf1b5803b2f1c37fd4d9514055e4ef0
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'integrity-audit')
-rw-r--r-- | integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java | 4 | ||||
-rw-r--r-- | integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java | 22 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditExceptionTest.java | 41 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTransactionExceptionTest.java | 41 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditExceptionTest.java | 41 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditPropertiesExceptionTest.java | 41 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java | 24 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/IaTestEntity.java | 8 | ||||
-rw-r--r-- | integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/PersonSample.java (renamed from integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/PersonTest.java) | 4 |
9 files changed, 197 insertions, 29 deletions
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java index e3cada9d..78ff4d3a 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java @@ -20,17 +20,15 @@ package org.onap.policy.common.ia; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Properties; - import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; import org.onap.policy.common.logging.eelf.MessageCodes; -import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; /** diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java index 424e603d..4f7a15af 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java @@ -122,53 +122,53 @@ public class IntegrityAudit { boolean parmsAreBad = false; if(resourceName == null || resourceName.isEmpty()){ - badparams = badparams.append("resourceName "); + badparams.append("resourceName "); parmsAreBad = true; } if(persistenceUnit == null || persistenceUnit.isEmpty()){ - badparams = badparams.append("persistenceUnit "); + badparams.append("persistenceUnit "); parmsAreBad = true; } if(properties == null || properties.isEmpty()){ - badparams = badparams.append("properties "); + badparams.append("properties "); parmsAreBad = true; } else{ String dbDriver = properties.getProperty(IntegrityAuditProperties.DB_DRIVER); if(dbDriver == null || dbDriver.isEmpty()){ - badparams = badparams.append("dbDriver "); + badparams.append("dbDriver "); parmsAreBad = true; } String dbUrl = properties.getProperty(IntegrityAuditProperties.DB_URL); if(dbUrl == null || dbUrl.isEmpty()){ - badparams = badparams.append("dbUrl "); + badparams.append("dbUrl "); parmsAreBad = true; } String dbUser = properties.getProperty(IntegrityAuditProperties.DB_USER); if(dbUser == null || dbUser.isEmpty()){ - badparams = badparams.append("dbUser "); + badparams.append("dbUser "); parmsAreBad = true; } String dbPwd = properties.getProperty(IntegrityAuditProperties.DB_PWD); if(dbPwd == null){ //may be empty - badparams = badparams.append("dbPwd "); + badparams.append("dbPwd "); parmsAreBad = true; } String siteName = properties.getProperty(IntegrityAuditProperties.SITE_NAME); if(siteName == null || siteName.isEmpty()){ - badparams = badparams.append("siteName "); + badparams.append("siteName "); parmsAreBad = true; } String nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE); if(nodeType == null || nodeType.isEmpty()){ - badparams = badparams.append("nodeType "); + badparams.append("nodeType "); parmsAreBad = true; } else { nodeType = nodeType.trim(); @@ -177,7 +177,7 @@ public class IntegrityAudit { for (NodeTypeEnum n : NodeTypeEnum.values()) { nodetypes = nodetypes.concat(n.toString() + " "); } - badparams = badparams.append(nodetypes + "] "); + badparams.append(nodetypes + "] "); parmsAreBad = true; } } @@ -185,7 +185,7 @@ public class IntegrityAudit { try{ Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim()); }catch(NumberFormatException nfe){ - badparams = badparams.append(", auditPeriodSeconds=" + badparams.append(", auditPeriodSeconds=" + properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim()); parmsAreBad = true; } diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditExceptionTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditExceptionTest.java new file mode 100644 index 00000000..005a9f15 --- /dev/null +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditExceptionTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * Integrity Audit + * ================================================================================ + * Copyright (C) 2018 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. + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.common.ia; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class DbAuditExceptionTest { + + @Test + public void test() { + DbAuditException e = new DbAuditException(); + assertNull(e.getMessage()); + e = new DbAuditException(""); + assertNotNull(e.getMessage()); + e = new DbAuditException(new Throwable()); + assertNotNull(e.getCause()); + e = new DbAuditException("", new Throwable()); + assertNotNull(e.getMessage()); + assertNotNull(e.getCause()); + } + +} diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTransactionExceptionTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTransactionExceptionTest.java new file mode 100644 index 00000000..d93576e0 --- /dev/null +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTransactionExceptionTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * Integrity Audit + * ================================================================================ + * Copyright (C) 2018 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. + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.common.ia; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class DbDaoTransactionExceptionTest { + + @Test + public void test() { + DbDaoTransactionException e = new DbDaoTransactionException(); + assertNull(e.getMessage()); + e = new DbDaoTransactionException(""); + assertNotNull(e.getMessage()); + e = new DbDaoTransactionException(new Throwable()); + assertNotNull(e.getCause()); + e = new DbDaoTransactionException("", new Throwable()); + assertNotNull(e.getMessage()); + assertNotNull(e.getCause()); + } + +} diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditExceptionTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditExceptionTest.java new file mode 100644 index 00000000..b39e3986 --- /dev/null +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditExceptionTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * Integrity Audit + * ================================================================================ + * Copyright (C) 2018 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. + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.common.ia; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class IntegrityAuditExceptionTest { + + @Test + public void test() { + IntegrityAuditException e = new IntegrityAuditException(); + assertNull(e.getMessage()); + e = new IntegrityAuditException(""); + assertNotNull(e.getMessage()); + e = new IntegrityAuditException(new Throwable()); + assertNotNull(e.getCause()); + e = new IntegrityAuditException("", new Throwable()); + assertNotNull(e.getMessage()); + assertNotNull(e.getCause()); + } + +} diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditPropertiesExceptionTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditPropertiesExceptionTest.java new file mode 100644 index 00000000..9c2b1196 --- /dev/null +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditPropertiesExceptionTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * Integrity Audit + * ================================================================================ + * Copyright (C) 2018 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. + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.common.ia; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class IntegrityAuditPropertiesExceptionTest { + + @Test + public void test() { + IntegrityAuditPropertiesException e = new IntegrityAuditPropertiesException(); + assertNull(e.getMessage()); + e = new IntegrityAuditPropertiesException(""); + assertNotNull(e.getMessage()); + e = new IntegrityAuditPropertiesException(new Throwable()); + assertNotNull(e.getCause()); + e = new IntegrityAuditPropertiesException("", new Throwable()); + assertNotNull(e.getMessage()); + assertNotNull(e.getCause()); + } + +} diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java index 3bedcb0b..76f54019 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java @@ -35,22 +35,18 @@ import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; - -//import org.apache.commons.logging.Log; -//import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; - import org.onap.policy.common.ia.DbAudit; import org.onap.policy.common.ia.DbDAO; import org.onap.policy.common.ia.IntegrityAudit; import org.onap.policy.common.ia.IntegrityAuditProperties; import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; import org.onap.policy.common.ia.test.jpa.IaTestEntity; -import org.onap.policy.common.ia.test.jpa.PersonTest; -import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.ia.test.jpa.PersonSample; +import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; /* @@ -586,10 +582,22 @@ public class DbAuditCompareEntriesTest { Date date = new Date(); - PersonTest person = new PersonTest("Ford", "Prefect", 21); - PersonTest person2 = new PersonTest("Zaphod", "Beeblebrox", 25); + PersonSample person = new PersonSample("Ford", "Prefect", 21); + PersonSample person2 = new PersonSample("Zaphod", "Beeblebrox", 25); /* + * Silly tests to bump coverage stats, not sure why + * they are counting PersonSample to begin with. Will have to + * look into that at some point. + */ + assertNotEquals(person.getAge(), person2.getAge()); + assertNotEquals(person.getFirstName(), person2.getFirstName()); + assertNotEquals(person.getLasttName(), person2.getLasttName()); + PersonSample personTest = new PersonSample(null, null, 0); + personTest.setAge(person.getAge()); + personTest.setFirstName(person.getFirstName()); + personTest.setLastName(person.getLasttName()); + /* * Two entries, 1 mismatch */ iate.setCreatedBy("Ford"); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/IaTestEntity.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/IaTestEntity.java index 53289e50..9c34dc4a 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/IaTestEntity.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/IaTestEntity.java @@ -42,13 +42,11 @@ import javax.persistence.TemporalType; @NamedQuery(name=" IaTestEntity.findAll", query="SELECT e FROM IaTestEntity e "), @NamedQuery(name="IaTestEntity.deleteAll", query="DELETE FROM IaTestEntity WHERE 1=1") }) -//@SequenceGenerator(name="seqImTest", initialValue=1, allocationSize=1) public class IaTestEntity implements Serializable { private static final long serialVersionUID = 1L; @Id - //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seqImTest") @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="ImTestId") private long imTestId; @@ -57,7 +55,7 @@ public class IaTestEntity implements Serializable { private String createdBy = "guest"; @Column(name="person", nullable=false, length=255) - private PersonTest person; + private PersonSample person; @Temporal(TemporalType.TIMESTAMP) @Column(name="created_date", updatable=false) @@ -144,14 +142,14 @@ public class IaTestEntity implements Serializable { /** * @param the person to set */ - public void setPersonTest(PersonTest p) { + public void setPersonTest(PersonSample p) { this.person = p; } /** * @return the person */ - public PersonTest getPersonTest() { + public PersonSample getPersonTest() { return person; } } diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/PersonTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/PersonSample.java index 0ca986bc..eb777e7f 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/PersonTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/jpa/PersonSample.java @@ -22,7 +22,7 @@ package org.onap.policy.common.ia.test.jpa; import java.io.Serializable; -public class PersonTest implements Serializable { +public class PersonSample implements Serializable { /** * */ @@ -31,7 +31,7 @@ public class PersonTest implements Serializable { private String lastName; private int age; - public PersonTest(String first, String last, int age) { + public PersonSample(String first, String last, int age) { this.firstName = first; this.lastName = last; this.age = age; |