diff options
author | liamfallon <liam.fallon@est.tech> | 2019-11-13 14:08:14 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-11-13 22:16:10 +0000 |
commit | 2f3ca9fc5edc5a52659b3486605e0db508143318 (patch) | |
tree | 0511aa5f0d117fa78032f5b91b2024b57dba5913 /ONAP-REST/src/test | |
parent | 0c20d1c294fe146e1018f14b07a8d861c29fe527 (diff) |
Unit/SONAR/Checkstyle in ONAP-REST
Fourth batch of JPA pojos (N-P), with JUnit added and SONAR/Checkstyle
issues addressed. In cases where a class name change caused an update in
another package, the license header on files for those knock on changes
are not updated.
Issue-ID: POLICY-2131
Change-Id: I9319b514b5c19e6837c34566dde770673d16bca3
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'ONAP-REST/src/test')
17 files changed, 963 insertions, 402 deletions
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java index 860e08d93..61a63ce0c 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/PolicyRestAdapterTest.java @@ -33,14 +33,14 @@ import org.onap.policy.rest.jpa.OnapName; public class PolicyRestAdapterTest { @Test - public void testPolicyExportAdapter(){ + public void testPolicyExportAdapter() { PolicyExportAdapter adapter = new PolicyExportAdapter(); adapter.setPolicyDatas(new ArrayList<>()); assertTrue(adapter.getPolicyDatas() != null); } @Test - public void testPolicyRestAdapter(){ + public void testPolicyRestAdapter() { PolicyRestAdapter adapter = new PolicyRestAdapter(); adapter.setData(new Object()); assertTrue(adapter.getData() != null); @@ -117,27 +117,27 @@ public class PolicyRestAdapterTest { adapter.setExistingCLName("Test"); assertTrue("Test".equals(adapter.getExistingCLName())); adapter.setOnapNameField(new OnapName()); - assertTrue(adapter.getOnapNameField()!=null); + assertTrue(adapter.getOnapNameField() != null); adapter.setJsonBodyData(new Object()); - assertTrue(adapter.getJsonBodyData()!=null); + assertTrue(adapter.getJsonBodyData() != null); adapter.setDirPath("Test"); assertTrue("Test".equals(adapter.getDirPath())); adapter.setConfigBodyPath("Test"); assertTrue("Test".equals(adapter.getConfigBodyPath())); adapter.setAttributes(new ArrayList<>()); - assertTrue(adapter.getAttributes()!=null); + assertTrue(adapter.getAttributes() != null); adapter.setSettings(new ArrayList<>()); - assertTrue(adapter.getSettings()!=null); + assertTrue(adapter.getSettings() != null); adapter.setRuleAlgorithmschoices(new ArrayList<>()); - assertTrue(adapter.getRuleAlgorithmschoices()!=null); + assertTrue(adapter.getRuleAlgorithmschoices() != null); adapter.setServiceTypePolicyName(new HashMap<>()); - assertTrue(adapter.getServiceTypePolicyName()!=null); + assertTrue(adapter.getServiceTypePolicyName() != null); adapter.setVerticaMetrics(new HashMap<>()); - assertTrue(adapter.getVerticaMetrics()!=null); + assertTrue(adapter.getVerticaMetrics() != null); adapter.setDescription(new LinkedHashMap<>()); - assertTrue(adapter.getVerticaMetrics()!=null); + assertTrue(adapter.getVerticaMetrics() != null); adapter.setAttributeFields(new LinkedHashMap<>()); - assertTrue(adapter.getAttributeFields()!=null); + assertTrue(adapter.getAttributeFields() != null); adapter.setClearTimeOut("Test"); assertTrue("Test".equals(adapter.getClearTimeOut())); adapter.setTrapMaxAge("Test"); @@ -145,15 +145,15 @@ public class PolicyRestAdapterTest { adapter.setVerificationclearTimeOut("Test"); assertTrue("Test".equals(adapter.getVerificationclearTimeOut())); adapter.setDynamicLayoutMap(new HashMap<>()); - assertTrue(adapter.getDynamicLayoutMap()!=null); + assertTrue(adapter.getDynamicLayoutMap() != null); adapter.setTrapDatas(new ClosedLoopFaultTrapDatas()); - assertTrue(adapter.getTrapDatas()!=null); + assertTrue(adapter.getTrapDatas() != null); adapter.setFaultDatas(new ClosedLoopFaultTrapDatas()); - assertTrue(adapter.getFaultDatas()!=null); + assertTrue(adapter.getFaultDatas() != null); adapter.setFwPolicyType("Test"); assertTrue("Test".equals(adapter.getFwPolicyType())); adapter.setFwattributes(new ArrayList<>()); - assertTrue(adapter.getFwattributes()!=null); + assertTrue(adapter.getFwattributes() != null); adapter.setParentForChild("Test"); assertTrue("Test".equals(adapter.getParentForChild())); adapter.setSecurityZone("Test"); @@ -161,27 +161,27 @@ public class PolicyRestAdapterTest { adapter.setRuleCombiningAlgId("Test"); assertTrue("Test".equals(adapter.getRuleCombiningAlgId())); adapter.setDynamicFieldConfigAttributes(new HashMap<>()); - assertTrue(adapter.getDynamicFieldConfigAttributes()!=null); + assertTrue(adapter.getDynamicFieldConfigAttributes() != null); adapter.setDynamicSettingsMap(new HashMap<>()); - assertTrue(adapter.getDynamicSettingsMap()!=null); + assertTrue(adapter.getDynamicSettingsMap() != null); adapter.setDropDownMap(new HashMap<>()); - assertTrue(adapter.getDropDownMap()!=null); + assertTrue(adapter.getDropDownMap() != null); adapter.setActionPerformer("Test"); assertTrue("Test".equals(adapter.getActionPerformer())); adapter.setActionAttribute("Test"); assertTrue("Test".equals(adapter.getActionAttribute())); adapter.setDynamicRuleAlgorithmLabels(new ArrayList<>()); - assertTrue(adapter.getDynamicRuleAlgorithmLabels()!=null); + assertTrue(adapter.getDynamicRuleAlgorithmLabels() != null); adapter.setDynamicRuleAlgorithmCombo(new ArrayList<>()); - assertTrue(adapter.getDynamicRuleAlgorithmCombo()!=null); + assertTrue(adapter.getDynamicRuleAlgorithmCombo() != null); adapter.setDynamicRuleAlgorithmField1(new ArrayList<>()); - assertTrue(adapter.getDynamicRuleAlgorithmField1()!=null); + assertTrue(adapter.getDynamicRuleAlgorithmField1() != null); adapter.setDynamicRuleAlgorithmField2(new ArrayList<>()); - assertTrue(adapter.getDynamicRuleAlgorithmField2()!=null); + assertTrue(adapter.getDynamicRuleAlgorithmField2() != null); adapter.setDynamicVariableList(new ArrayList<>()); - assertTrue(adapter.getDynamicVariableList()!=null); + assertTrue(adapter.getDynamicVariableList() != null); adapter.setDataTypeList(new ArrayList<>()); - assertTrue(adapter.getDataTypeList()!=null); + assertTrue(adapter.getDataTypeList() != null); adapter.setActionAttributeValue("Test"); assertTrue("Test".equals(adapter.getActionAttributeValue())); adapter.setRuleProvider("Test"); @@ -197,15 +197,15 @@ public class PolicyRestAdapterTest { adapter.setActionDictMethod("Test"); assertTrue("Test".equals(adapter.getActionDictMethod())); adapter.setYamlparams(new YAMLParams()); - assertTrue(adapter.getYamlparams()!=null); + assertTrue(adapter.getYamlparams() != null); adapter.setRainyday(new RainyDayParams()); - assertTrue(adapter.getRainyday()!=null); + assertTrue(adapter.getRainyday() != null); adapter.setRainydayMap(new HashMap<>()); - assertTrue(adapter.getRainydayMap()!=null); + assertTrue(adapter.getRainydayMap() != null); adapter.setErrorCodeList(new ArrayList<>()); - assertTrue(adapter.getErrorCodeList()!=null); + assertTrue(adapter.getErrorCodeList() != null); adapter.setTreatmentList(new ArrayList<>()); - assertTrue(adapter.getTreatmentList()!=null); + assertTrue(adapter.getTreatmentList() != null); adapter.setServiceType("Test"); assertTrue("Test".equals(adapter.getServiceType())); adapter.setUuid("Test"); @@ -221,17 +221,17 @@ public class PolicyRestAdapterTest { adapter.setRuleName("Test"); assertTrue("Test".equals(adapter.getRuleName())); adapter.setBrmsParamBody(new HashMap<>()); - assertTrue(adapter.getBrmsParamBody()!=null); + assertTrue(adapter.getBrmsParamBody() != null); adapter.setBrmsController("Test"); assertTrue("Test".equals(adapter.getBrmsController())); adapter.setBrmsDependency(new ArrayList<>()); - assertTrue(adapter.getBrmsDependency()!=null); + assertTrue(adapter.getBrmsDependency() != null); adapter.setRuleData(new LinkedHashMap<>()); - assertTrue(adapter.getRuleData()!=null); + assertTrue(adapter.getRuleData() != null); adapter.setRuleListData(new LinkedHashMap<>()); - assertTrue(adapter.getRuleListData()!=null); + assertTrue(adapter.getRuleListData() != null); adapter.setDrlRuleAndUIParams(new LinkedHashMap<>()); - assertTrue(adapter.getDrlRuleAndUIParams()!=null); + assertTrue(adapter.getDrlRuleAndUIParams() != null); adapter.setPolicyScope("Test"); assertTrue("Test".equals(adapter.getPolicyScope())); adapter.setProviderComboBox("Test"); @@ -245,11 +245,11 @@ public class PolicyRestAdapterTest { adapter.setTtlDate("Test"); assertTrue("Test".equals(adapter.getTtlDate())); adapter.setMatching(new LinkedHashMap<>()); - assertTrue(adapter.getMatching()!=null); + assertTrue(adapter.getMatching() != null); adapter.setTriggerSignatures(new ArrayList<>()); - assertTrue(adapter.getTriggerSignatures()!=null); + assertTrue(adapter.getTriggerSignatures() != null); adapter.setSymptomSignatures(new ArrayList<>()); - assertTrue(adapter.getSymptomSignatures()!=null); + assertTrue(adapter.getSymptomSignatures() != null); adapter.setLogicalConnector("Test"); assertTrue("Test".equals(adapter.getLogicalConnector())); adapter.setPolicyStatus("Test"); @@ -274,7 +274,7 @@ public class PolicyRestAdapterTest { assertEquals("risklevel", adapter.getRiskLevel()); assertEquals("guardvalue", adapter.getGuard()); assertEquals("onapvalue", adapter.getOnapName()); - assertEquals("onapvalue", adapter.getOnapNameField().getOnapName()); + assertEquals("onapvalue", adapter.getOnapNameField().getName()); assertEquals("uuidvalue", adapter.getUuid()); assertEquals("locationvalue", adapter.getLocation()); assertEquals("configvalue", adapter.getConfigName()); diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java index 4d9d1c576..47456106b 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java @@ -70,6 +70,7 @@ public class PolicyValidationDaoImplTest { /** * Set up all unit tests. + * * @throws SQLException on SQL exceptions */ @BeforeClass @@ -136,13 +137,12 @@ public class PolicyValidationDaoImplTest { userinfo.setUserName("Test"); commonClassDao.save(userinfo); OnapName onapName = new OnapName(); - onapName.setOnapName("Test"); + onapName.setName("Test"); onapName.setUserCreatedBy(userinfo); onapName.setUserModifiedBy(userinfo); onapName.setModifiedDate(new Date()); commonClassDao.save(onapName); - List<Object> list = commonClassDao.getData(OnapName.class); assertTrue(list.size() == 1); logger.debug(list.size()); @@ -160,7 +160,6 @@ public class PolicyValidationDaoImplTest { userinfo.setUserName(loginIdUserName); commonClassDao.save(userinfo); - List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings()); assertEquals(1, dataCur.size()); @@ -224,7 +223,6 @@ public class PolicyValidationDaoImplTest { params.put("scope", scope); List<Object> dataCur = commonClassDao.getDataByQuery(query, params); - assertTrue(1 == dataCur.size()); assertEquals(pv, dataCur.get(0)); } @@ -244,7 +242,6 @@ public class PolicyValidationDaoImplTest { userinfo.setUserName(loginIdUserName); commonClassDao.save(userinfo); - List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings()); assertEquals(1, dataCur.size()); @@ -254,7 +251,6 @@ public class PolicyValidationDaoImplTest { assertFalse(dataCur.isEmpty()); - watch.setPolicyName("bananaWatch"); commonClassDao.save(watch); @@ -281,7 +277,6 @@ public class PolicyValidationDaoImplTest { assertEquals(watch, dataCur.get(0)); } - @Test @Transactional @Rollback(true) @@ -326,7 +321,6 @@ public class PolicyValidationDaoImplTest { watch.setPolicyName(finalName); commonClassDao.save(watch); - // Current Implementation String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId"; SimpleBindings params = new SimpleBindings(); @@ -363,7 +357,6 @@ public class PolicyValidationDaoImplTest { // SQL Injection attempt String finalName = "banana' OR '1'='1"; - // Current Implementation String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId"; SimpleBindings params = new SimpleBindings(); @@ -394,8 +387,8 @@ public class PolicyValidationDaoImplTest { commonClassDao.update(userInfoUpdate); List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId"); assertTrue(data1.size() == 1); - UserInfo data2 = - (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestID:Test1"); + UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", + "TestID:Test1"); assertTrue("TestID".equals(data2.getUserLoginId())); List<Object> data3 = commonClassDao.checkDuplicateEntry("TestID:Test1", "userLoginId:userName", UserInfo.class); assertTrue(data3.size() == 1); @@ -408,8 +401,8 @@ public class PolicyValidationDaoImplTest { assertTrue(roles1.size() == 1); List<String> multipleData = new ArrayList<>(); multipleData.add("TestID:Test1"); - List<Object> data4 = - commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", multipleData); + List<Object> data4 = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", + multipleData); assertTrue(data4.size() == 1); commonClassDao.delete(data2); } @@ -433,7 +426,7 @@ public class PolicyValidationDaoImplTest { data = commonClassDao.getDataById(UserInfo.class, "userLoginIduserName", "TestIDTest"); assertNull(data); data = commonClassDao.getDataById(UserInfo.class, "userLoginId data2.getUserLoginId()" + ":userName", - "TestIDTest"); + "TestIDTest"); assertNull(data); commonClassDao.delete(data); } @@ -463,8 +456,8 @@ public class PolicyValidationDaoImplTest { commonClassDao.save(userInfo); List<String> multipleData = new ArrayList<>(); multipleData.add("TestID:Test1"); - List<Object> data = - commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", multipleData); + List<Object> data = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", + multipleData); assertTrue(data.size() == 0); data = commonClassDao.getMultipleDataOnAddingConjunction(null, null, null); assertNull(data); @@ -506,7 +499,6 @@ public class PolicyValidationDaoImplTest { commonClassDao.delete(data); } - @Test public void testGetEntityItemParameters() { UserInfo userInfo = new UserInfo(); @@ -520,8 +512,8 @@ public class PolicyValidationDaoImplTest { commonClassDao.update(userInfoUpdate); List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId"); assertTrue(data1.size() == 1); - UserInfo data2 = - (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestID:Test1"); + UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", + "TestID:Test1"); assertTrue("TestID".equals(data2.getUserLoginId())); data2 = (UserInfo) commonClassDao.getEntityItem(null, null, null); assertNull(data2); @@ -587,7 +579,6 @@ public class PolicyValidationDaoImplTest { commonClassDao.delete(data); } - @Test public void testGetDataByQueryParameters() { // Add data diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJpaTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJpaTest.java index a840f9d9d..3967bb48e 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJpaTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ActionDictionaryJpaTest.java @@ -23,6 +23,7 @@ package org.onap.policy.rest.jpa; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -228,13 +229,19 @@ public class ActionDictionaryJpaTest { @Test public void testObadvice() { - Obadvice data = new Obadvice(); new Obadvice(); new Obadvice("Test", "Test"); + new Obadvice(new DummyIdentifier(), "Test"); + Obadvice data = new Obadvice(); data.clone(); data.addObadviceExpression(new ObadviceExpression()); + assertNotNull(data.clone()); data.removeObadviceExpression(new ObadviceExpression()); data.removeAllExpressions(); + assertEquals(0, data.getObadviceExpressions().size()); + data.setObadviceExpressions(null); + assertNull(data.getObadviceExpressions()); + data.removeAllExpressions(); data.prePersist(); data.preUpdate(); data.setId(1); @@ -253,6 +260,7 @@ public class ActionDictionaryJpaTest { assertTrue("Test".equals(data.getType())); data.setXacmlId("Test"); assertTrue("Test".equals(data.getXacmlId())); + } @Test @@ -349,5 +357,13 @@ public class ActionDictionaryJpaTest { assertTrue("Test".equals(data.getXacmlId())); data.setIsStandard(PolicyAlgorithms.STANDARD); assertTrue(data.isStandard()); + assertFalse(data.isCustom()); + data.setIsStandard(PolicyAlgorithms.CUSTOM); + assertFalse(data.isStandard()); + assertTrue(data.isCustom()); + + DummyIdentifier identifier = new DummyIdentifier(); + assertNotNull(new PolicyAlgorithms(identifier)); + assertNotNull(new PolicyAlgorithms(identifier, 'C')); } } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJpaTest.java index 2274855e1..96a00f934 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJPATest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ClosedLoopPolicyDictionaryJpaTest.java @@ -3,13 +3,14 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. @@ -17,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.rest.jpa; import static org.junit.Assert.assertTrue; @@ -28,11 +30,19 @@ import org.junit.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -public class ClosedLoopPolicyDictionaryJPATest { +/** + * The Class ClosedLoopPolicyDictionaryJpaTest. + */ +public class ClosedLoopPolicyDictionaryJpaTest { - private static Logger logger = FlexLogger.getLogger(ClosedLoopPolicyDictionaryJPATest.class); + private static Logger logger = FlexLogger.getLogger(ClosedLoopPolicyDictionaryJpaTest.class); private UserInfo userInfo; + /** + * Sets the up. + * + * @throws Exception the exception + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); @@ -42,8 +52,11 @@ public class ClosedLoopPolicyDictionaryJPATest { logger.info("setUp: exit"); } + /** + * Test VSCL action. + */ @Test - public void testVSCLAction(){ + public void testVsclAction() { VSCLAction data = new VSCLAction(); data.preUpdate(); data.prePersist(); @@ -54,17 +67,20 @@ public class ClosedLoopPolicyDictionaryJPATest { data.setDescription("Test"); assertTrue("Test".equals(data.getDescription())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test VNF type. + */ @Test - public void testVNFType(){ + public void testVnfType() { VNFType data = new VNFType(); data.preUpdate(); data.prePersist(); @@ -75,18 +91,21 @@ public class ClosedLoopPolicyDictionaryJPATest { data.setDescription("Test"); assertTrue("Test".equals(data.getDescription())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test PEP options. + */ @Test - public void testPEPOptions(){ - PEPOptions data = new PEPOptions(); + public void testPepOptions() { + PepOptions data = new PepOptions(); data.preUpdate(); data.prePersist(); data.setId(1); @@ -96,17 +115,20 @@ public class ClosedLoopPolicyDictionaryJPATest { data.setDescription("Test"); assertTrue("Test".equals(data.getDescription())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test varbind dictionary. + */ @Test - public void testVarbindDictionary(){ + public void testVarbindDictionary() { VarbindDictionary data = new VarbindDictionary(); data.preUpdate(); data.prePersist(); @@ -119,17 +141,20 @@ public class ClosedLoopPolicyDictionaryJPATest { data.setVarbindOID("Test"); assertTrue("Test".equals(data.getVarbindOID())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test closed loop D 2 services. + */ @Test - public void testClosedLoopD2Services(){ + public void testClosedLoopD2Services() { ClosedLoopD2Services data = new ClosedLoopD2Services(); data.preUpdate(); data.prePersist(); @@ -140,17 +165,20 @@ public class ClosedLoopPolicyDictionaryJPATest { data.setDescription("Test"); assertTrue("Test".equals(data.getDescription())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test closed loop site. + */ @Test - public void testClosedLoopSite(){ + public void testClosedLoopSite() { ClosedLoopSite data = new ClosedLoopSite(); data.preUpdate(); data.prePersist(); @@ -161,12 +189,12 @@ public class ClosedLoopPolicyDictionaryJPATest { data.setDescription("Test"); assertTrue("Test".equals(data.getDescription())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); + assertTrue(data.getUserModifiedBy() != null); } } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJpaTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJpaTest.java index fa83017f2..caeb808d8 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJpaTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/CommonDictionaryJpaTest.java @@ -8,9 +8,9 @@ * 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. @@ -43,7 +43,7 @@ public class CommonDictionaryJpaTest { /** * Initiations for testing. - * + * * @throws Exception on test initiation errors */ @Before @@ -157,8 +157,8 @@ public class CommonDictionaryJpaTest { data.prePersist(); data.setId(1); assertTrue(1 == data.getId()); - data.setOnapName("Test"); - assertTrue("Test".equals(data.getOnapName())); + data.setName("Test"); + assertTrue("Test".equals(data.getName())); data.setDescription("Test"); assertTrue("Test".equals(data.getDescription())); data.setCreatedDate(new Date()); diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java index da5dd5005..a18fcbae3 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/ConfigurationDataEntityTest.java @@ -3,13 +3,14 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. @@ -25,47 +26,51 @@ import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; + import java.util.Date; + import org.junit.Test; public class ConfigurationDataEntityTest { - @Test - public void testEquals() { - // Set up test data - String value = "testVal"; - Date date = new Date(); - ConfigurationDataEntity entity = new ConfigurationDataEntity(); - entity.prePersist(); - ConfigurationDataEntity entity2 = new ConfigurationDataEntity(); - ConfigurationDataEntity entity3 = new ConfigurationDataEntity(); + @Test + public void testEquals() { + // Set up test data + String value = "testVal"; + ConfigurationDataEntity entity = new ConfigurationDataEntity(); + entity.prePersist(); + ConfigurationDataEntity entity3 = new ConfigurationDataEntity(); + + // Test set and get + entity3.preUpdate(); + entity3.setConfigBody(value); + assertEquals(value, entity3.getConfigBody()); + entity3.setCreatedBy(value); + assertEquals(value, entity3.getCreatedBy()); + entity3.setModifiedBy(value); + assertEquals(value, entity3.getModifiedBy()); + + Date date = new Date(); + entity3.setModifiedDate(date); + assertEquals(date, entity3.getModifiedDate()); + assertEquals(0, entity3.getVersion()); + assertNull(entity3.getCreatedDate()); + entity3.setDeleted(true); + assertEquals(true, entity3.isDeleted()); + entity3.setDescription(value); + assertEquals(value, entity3.getDescription()); + entity3.setConfigType(value); + assertEquals(value, entity3.getConfigType()); + entity3.setConfigurationName(value); + assertEquals(value, entity3.getConfigurationName()); + assertEquals(0, entity3.getConfigurationDataId()); - // Test set and get - entity3.preUpdate(); - entity3.setConfigBody(value); - assertEquals(value, entity3.getConfigBody()); - entity3.setCreatedBy(value); - assertEquals(value, entity3.getCreatedBy()); - entity3.setModifiedBy(value); - assertEquals(value, entity3.getModifiedBy()); - entity3.setModifiedDate(date); - assertEquals(date, entity3.getModifiedDate()); - assertEquals(0, entity3.getVersion()); - assertNull(entity3.getCreatedDate()); - entity3.setDeleted(true); - assertEquals(true, entity3.isDeleted()); - entity3.setDescription(value); - assertEquals(value, entity3.getDescription()); - entity3.setConfigType(value); - assertEquals(value, entity3.getConfigType()); - entity3.setConfigurationName(value); - assertEquals(value, entity3.getConfigurationName()); - assertEquals(0, entity3.getConfigurationDataId()); + // Test method combinations + assertEquals(false, entity.equals(null)); + assertEquals(true, entity.equals(entity)); + assertEquals(false, entity.equals(value)); - // Test method combinations - assertEquals(false, entity.equals(null)); - assertEquals(true, entity.equals(entity)); - assertEquals(false, entity.equals(value)); - assertEquals(false, entity.equals(entity2)); - assertThat(entity.hashCode(), is(not(0))); - } + ConfigurationDataEntity entity2 = new ConfigurationDataEntity(); + assertEquals(false, entity.equals(entity2)); + assertThat(entity.hashCode(), is(not(0))); + } } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJpaTest.java index b1fc69903..b664cf3ed 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJPATest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DecisionDictionaryJpaTest.java @@ -3,13 +3,14 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. @@ -17,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.rest.jpa; import static org.junit.Assert.assertTrue; @@ -28,11 +30,19 @@ import org.junit.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -public class DecisionDictionaryJPATest { +/** + * The Class DecisionDictionaryJpaTest. + */ +public class DecisionDictionaryJpaTest { - private static Logger logger = FlexLogger.getLogger(DecisionDictionaryJPATest.class); + private static Logger logger = FlexLogger.getLogger(DecisionDictionaryJpaTest.class); private UserInfo userInfo; + /** + * Sets the up. + * + * @throws Exception the exception + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); @@ -42,8 +52,11 @@ public class DecisionDictionaryJPATest { logger.info("setUp: exit"); } + /** + * Test decision settings. + */ @Test - public void testDecisionSettings(){ + public void testDecisionSettings() { DecisionSettings data = new DecisionSettings(); data.setId(1); assertTrue(1 == data.getId()); @@ -54,7 +67,7 @@ public class DecisionDictionaryJPATest { data.setXacmlId("Test"); assertTrue("Test".equals(data.getXacmlId())); data.setDatatypeBean(new Datatype()); - assertTrue(data.getDatatypeBean()!=null); + assertTrue(data.getDatatypeBean() != null); data.setIssuer("Test"); assertTrue("Test".equals(data.getIssuer())); data.setMustBePresent(true); @@ -62,17 +75,20 @@ public class DecisionDictionaryJPATest { data.setPriority("Test"); assertTrue("Test".equals(data.getPriority())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!=null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!=null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!=null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!=null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test rainy day treatments. + */ @Test - public void testRainyDayTreatments(){ + public void testRainyDayTreatments() { RainyDayTreatments data = new RainyDayTreatments(); data.setId(1); assertTrue(1 == data.getId()); diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java index 486d36442..1b4bb7114 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/DictionaryDataTest.java @@ -5,6 +5,7 @@ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +24,7 @@ package org.onap.policy.rest.jpa; import static org.junit.Assert.assertEquals; + import org.junit.Test; public class DictionaryDataTest { @@ -34,7 +36,7 @@ public class DictionaryDataTest { String value = "testData1"; // Set Data - dictData.setId(1);; + dictData.setId(1); dictData.setDictionaryDataByName(value); dictData.setDictionaryName(value); dictData.setDictionaryUrl(value); diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJpaTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJpaTest.java index 5ea92fd13..1fcc7baa6 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJpaTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroServiceDictionaryJpaTest.java @@ -21,6 +21,7 @@ package org.onap.policy.rest.jpa; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Before; @@ -88,8 +89,8 @@ public class MicroServiceDictionaryJpaTest { assertTrue(1 == data.getId()); data.setName("Test"); assertTrue("Test".equals(data.getName())); - data.setDescriptionValue("Test"); - assertTrue("Test".equals(data.getDescriptionValue())); + data.setDescription("Test"); + assertTrue("Test".equals(data.getDescription())); } /** @@ -102,8 +103,8 @@ public class MicroServiceDictionaryJpaTest { assertTrue(1 == data.getId()); data.setName("Test"); assertTrue("Test".equals(data.getName())); - data.setDescriptionValue("Test"); - assertTrue("Test".equals(data.getDescriptionValue())); + data.setDescription("Test"); + assertTrue("Test".equals(data.getDescription())); } /** @@ -126,14 +127,15 @@ public class MicroServiceDictionaryJpaTest { assertTrue("Test".equals(data.getAnnotation())); data.setAttributes("Test"); assertTrue("Test".equals(data.getAttributes())); - data.setRef_attributes("Test"); - assertTrue("Test".equals(data.getRef_attributes())); + data.setRefAttributes("Test"); + assertTrue("Test".equals(data.getRefAttributes())); data.setUserCreatedBy(userInfo); assertTrue(data.getUserCreatedBy() != null); - data.setSub_attributes("Test"); - assertTrue("Test".equals(data.getSub_attributes())); + data.setSubAttributes("Test"); + assertTrue("Test".equals(data.getSubAttributes())); data.setVersion("Test"); assertTrue("Test".equals(data.getVersion())); + assertFalse(data.isDecisionModel()); } /** @@ -162,8 +164,8 @@ public class MicroServiceDictionaryJpaTest { assertTrue(1 == data.getId()); data.setName("Test"); assertTrue("Test".equals(data.getName())); - data.setDescriptionValue("Test"); - assertTrue("Test".equals(data.getDescriptionValue())); + data.setDescription("Test"); + assertTrue("Test".equals(data.getDescription())); } /** @@ -176,8 +178,8 @@ public class MicroServiceDictionaryJpaTest { assertTrue(1 == data.getId()); data.setName("Test"); assertTrue("Test".equals(data.getName())); - data.setDescriptionValue("Test"); - assertTrue("Test".equals(data.getDescriptionValue())); + data.setDescription("Test"); + assertTrue("Test".equals(data.getDescription())); } /** @@ -190,8 +192,8 @@ public class MicroServiceDictionaryJpaTest { assertTrue(1 == data.getId()); data.setName("Test"); assertTrue("Test".equals(data.getName())); - data.setDescriptionValue("Test"); - assertTrue("Test".equals(data.getDescriptionValue())); + data.setDescription("Test"); + assertTrue("Test".equals(data.getDescription())); } /** @@ -204,8 +206,8 @@ public class MicroServiceDictionaryJpaTest { assertTrue(1 == data.getId()); data.setName("Test"); assertTrue("Test".equals(data.getName())); - data.setDescriptionValue("Test"); - assertTrue("Test".equals(data.getDescriptionValue())); + data.setDescription("Test"); + assertTrue("Test".equals(data.getDescription())); } /** diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java index 62452dcb0..cbccc3b96 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/MicroserviceHeaderdeFaultsTest.java @@ -3,13 +3,14 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. @@ -21,33 +22,34 @@ package org.onap.policy.rest.jpa; import static org.junit.Assert.assertEquals; + import org.junit.Test; public class MicroserviceHeaderdeFaultsTest { - @Test - public void testHeader() { - // Set up test data - String value = "testVal"; - MicroserviceHeaderdeFaults header = new MicroserviceHeaderdeFaults(); - header.prePersist(); - header.preUpdate(); + @Test + public void testHeader() { + // Set up test data + String value = "testVal"; + MicroserviceHeaderdeFaults header = new MicroserviceHeaderdeFaults(); + header.prePersist(); + header.preUpdate(); - // Set data - header.setGuard(value); - header.setId(1); - header.setModelName(value); - header.setOnapName(value); - header.setPriority(value); - header.setRiskLevel(value); - header.setRiskType(value); + // Set data + header.setGuard(value); + header.setId(1); + header.setModelName(value); + header.setOnapName(value); + header.setPriority(value); + header.setRiskLevel(value); + header.setRiskType(value); - // Test gets - assertEquals(value, header.getGuard()); - assertEquals(1, header.getId()); - assertEquals(value, header.getModelName()); - assertEquals(value, header.getOnapName()); - assertEquals(value, header.getPriority()); - assertEquals(value, header.getRiskLevel()); - assertEquals(value, header.getRiskType()); - } + // Test gets + assertEquals(value, header.getGuard()); + assertEquals(1, header.getId()); + assertEquals(value, header.getModelName()); + assertEquals(value, header.getOnapName()); + assertEquals(value, header.getPriority()); + assertEquals(value, header.getRiskLevel()); + assertEquals(value, header.getRiskType()); + } } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJpaTest.java index 243cb5106..81481e191 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJPATest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/OptimizationModelsJpaTest.java @@ -3,13 +3,14 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. @@ -17,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.rest.jpa; import static org.junit.Assert.assertTrue; @@ -26,11 +28,19 @@ import org.junit.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -public class OptimizationModelsJPATest { +/** + * The Class OptimizationModelsJpaTest. + */ +public class OptimizationModelsJpaTest { - private static Logger logger = FlexLogger.getLogger(OptimizationModelsJPATest.class); + private static Logger logger = FlexLogger.getLogger(OptimizationModelsJpaTest.class); private UserInfo userInfo; + /** + * Sets the up. + * + * @throws Exception the exception + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); @@ -40,8 +50,11 @@ public class OptimizationModelsJPATest { logger.info("setUp: exit"); } + /** + * Test ms models. + */ @Test - public void testMSModels(){ + public void testMsModels() { OptimizationModels data = new OptimizationModels(); data.setId(1); assertTrue(1 == data.getId()); @@ -60,12 +73,11 @@ public class OptimizationModelsJPATest { data.setRefattributes("Test"); assertTrue("Test".equals(data.getRefattributes())); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!=null); + assertTrue(data.getUserCreatedBy() != null); data.setSubattributes("Test"); assertTrue("Test".equals(data.getSubattributes())); data.setVersion("Test"); assertTrue("Test".equals(data.getVersion())); } - } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java deleted file mode 100644 index 1a4c2756b..000000000 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPConfigurationTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP-REST - * ================================================================================ - * 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.rest.jpa; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import java.util.Date; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; -import org.junit.Test; -import com.att.research.xacml.api.pip.PIPException; -import com.att.research.xacml.util.XACMLProperties; - -public class PIPConfigurationTest { - @Test - public void testConfig() throws PIPException { - String value = "testVal"; - String id = "1"; - PIPConfigParam param = new PIPConfigParam(); - param.setParamName(value); - param.setParamValue(value); - Set<PIPConfigParam> params = new HashSet<PIPConfigParam>(); - PIPResolver resolver = new PIPResolver(); - resolver.setClassname(value); - resolver.setName(value); - params.add(param); - Set<PIPResolver> resolvers = new HashSet<PIPResolver>(); - resolvers.add(resolver); - Properties props = new Properties(); - props.setProperty(id + ".classname", value); - props.setProperty(XACMLProperties.PROP_PIP_ENGINES, id); - PIPType type = new PIPType(); - Date date = new Date(); - - // Test constructors - PIPConfiguration config = new PIPConfiguration(); - assertNotNull(config); - config.setPipconfigParams(params); - config.setPipresolvers(resolvers); - PIPConfiguration config2 = new PIPConfiguration(config, value); - assertNotNull(config2); - config2.prePersist(); - config2.preUpdate(); - PIPConfiguration config3 = new PIPConfiguration(id, props); - assertNotNull(config3); - PIPConfiguration config4 = new PIPConfiguration(id, props, value); - assertNotNull(config4); - - // Test set and get - config.setId(1); - assertEquals(1, config.getId()); - config.setDescription(value); - assertEquals(value, config.getDescription()); - config.setName(id); - assertEquals(id, config.getName()); - config.setClassname(value); - assertEquals(value, config.getClassname()); - config.setIssuer(value); - assertEquals(value, config.getIssuer()); - config.setReadOnly(true); - assertEquals('1', config.getReadOnly()); - config.setReadOnly('0'); - assertEquals('0', config.getReadOnly()); - assertEquals(false, config.isReadOnly()); - config.setRequiresResolvers('t'); - assertEquals('t', config.getRequiresResolvers()); - config.setReadOnly(false); - assertEquals('0', config.getReadOnly()); - config.setPiptype(type); - assertEquals(type, config.getPiptype()); - config.setRequiresResolvers(false); - assertEquals('0', config.getRequiresResolvers()); - config.setCreatedBy(value); - assertEquals(value, config.getCreatedBy()); - config.setCreatedDate(date); - assertEquals(date, config.getCreatedDate()); - config.setModifiedBy(value); - assertEquals(value, config.getModifiedBy()); - config.setModifiedDate(date); - assertEquals(date, config.getModifiedDate()); - config.setRequiresResolvers(true); - assertEquals(true, config.requiresResolvers()); - assertEquals(8, config.getConfiguration(id).size()); - assertEquals(9, config.generateProperties(id).size()); - - // Test remove and clear - assertEquals(param, config.removePipconfigParam(param)); - config.clearConfigParams(); - assertEquals(0, config.getPipconfigParams().size()); - config.removePipresolver(resolver); - assertEquals(0, config.getPipresolvers().size()); - - // Test import - assertEquals(1, PIPConfiguration.importPIPConfigurations(props).size()); - config.readProperties(id, props); - assertEquals(id, config.getName()); - - // Test toString - String configString = config.toString().replaceAll("@[0-9a-f]*", ""); - assertEquals(323, configString.length()); - } -} diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipConfigurationTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipConfigurationTest.java new file mode 100644 index 000000000..9bc95dc5f --- /dev/null +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipConfigurationTest.java @@ -0,0 +1,196 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-REST + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.rest.jpa; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; +import com.att.research.xacml.util.XACMLProperties; + +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Properties; +import java.util.Set; + +import org.junit.Test; + +public class PipConfigurationTest { + @Test + public void testConfig() throws PIPException { + String value = "testVal"; + PipConfigParam param = new PipConfigParam(); + param.setParamName(value); + param.setParamValue(value); + Set<PipConfigParam> params = new HashSet<PipConfigParam>(); + PipResolver resolver = new PipResolver(); + resolver.setClassname(value); + resolver.setName(value); + params.add(param); + Set<PipResolver> resolvers = new HashSet<PipResolver>(); + resolvers.add(resolver); + Properties props = new Properties(); + + String id = "1"; + props.setProperty(id + ".classname", value); + props.setProperty(XACMLProperties.PROP_PIP_ENGINES, id); + + // Test constructors + PipConfiguration config = new PipConfiguration(); + assertNotNull(config); + config.setPipconfigParams(params); + config.setPipresolvers(resolvers); + PipConfiguration config2 = new PipConfiguration(config, value); + assertNotNull(config2); + config2.prePersist(); + config2.preUpdate(); + PipConfiguration config3 = new PipConfiguration(id, props); + assertNotNull(config3); + PipConfiguration config4 = new PipConfiguration(id, props, value); + assertNotNull(config4); + + // Test set and get + config.setId(1); + assertEquals(1, config.getId()); + config.setDescription(value); + assertEquals(value, config.getDescription()); + config.setName(id); + assertEquals(id, config.getName()); + config.setClassname(value); + assertEquals(value, config.getClassname()); + config.setIssuer(value); + assertEquals(value, config.getIssuer()); + config.setReadOnlyFlag(true); + assertEquals('1', config.getReadOnly()); + config.setReadOnly('0'); + assertEquals('0', config.getReadOnly()); + assertEquals(false, config.isReadOnly()); + config.setRequiresResolvers('t'); + assertEquals('t', config.getRequiresResolvers()); + config.setReadOnlyFlag(false); + assertEquals('0', config.getReadOnly()); + + PipType type = new PipType(); + config.setPiptype(type); + assertEquals(type, config.getPiptype()); + config.setRequiresResolversFlag(false); + assertEquals('0', config.getRequiresResolvers()); + config.setCreatedBy(value); + assertEquals(value, config.getCreatedBy()); + + Date date = new Date(); + config.setCreatedDate(date); + assertEquals(date, config.getCreatedDate()); + config.setModifiedBy(value); + assertEquals(value, config.getModifiedBy()); + config.setModifiedDate(date); + assertEquals(date, config.getModifiedDate()); + config.setRequiresResolversFlag(true); + assertTrue(config.requiresResolvers()); + config.setRequiresResolversFlag(false); + assertFalse(config.requiresResolvers()); + assertEquals(8, config.getConfiguration(id).size()); + assertEquals(9, config.generateProperties(id).size()); + + // Test remove and clear + assertEquals(param, config.removePipconfigParam(param)); + assertNull(config.removePipconfigParam(null)); + config.clearConfigParams(); + assertEquals(0, config.getPipconfigParams().size()); + config.removePipresolver(resolver); + assertEquals(0, config.getPipresolvers().size()); + + assertEquals(param, config.addPipconfigParam(param)); + config.clearConfigParams(); + assertEquals(0, config.getPipconfigParams().size()); + config.removePipresolver(resolver); + assertEquals(0, config.getPipresolvers().size()); + + // Test import + assertEquals(1, PipConfiguration.importPipConfigurations(props).size()); + config.readProperties(id, props); + assertEquals(id, config.getName()); + + // Test toString + String configString = config.toString().replaceAll("@[0-9a-f]*", ""); + assertEquals(322, configString.length()); + + assertEquals(0, PipConfiguration.importPipConfigurations(new Properties()).size()); + + Properties otherProperties = new Properties(); + otherProperties.put(XACMLProperties.PROP_PIP_ENGINES, ""); + assertEquals(0, PipConfiguration.importPipConfigurations(otherProperties).size()); + + otherProperties.put(XACMLProperties.PROP_PIP_ENGINES, "badvalue:evenworse"); + assertEquals(0, PipConfiguration.importPipConfigurations(otherProperties).size()); + + // Test readProperties + props.setProperty(id + "." + StdConfigurableEngine.PROP_ISSUER, "himself"); + props.setProperty(id + ".resolvers", ""); + props.setProperty(id + ".resolver", ""); + props.setProperty(id + ".anotherproperty", ""); + config.readProperties(id, props); + assertEquals("himself", config.getIssuer()); + assertEquals(49, config.getRequiresResolvers()); + + props.setProperty(id + ".resolvers", "aaa"); + assertThatThrownBy(() -> config.readProperties(id, props)).hasMessage("PIP Engine defined without a classname"); + + props.setProperty(id + ".resolver.aaa.classname", "somewhere.over.the.Rainbow"); + props.setProperty(id + ".resolver.aaa." + StdConfigurableEngine.PROP_NAME, "Dorothy"); + props.setProperty(id + ".resolver.aaa." + StdConfigurableEngine.PROP_DESCRIPTION, "Oz"); + props.setProperty(id + ".resolver.aaa." + StdConfigurableEngine.PROP_ISSUER, "Wizard"); + props.setProperty(id + ".resolver.aaa.witch", "North"); + config.readProperties(id, props); + + PipResolver pipResolver = config.getPipresolvers().iterator().next(); + + assertEquals("somewhere.over.the.Rainbow", pipResolver.getClassname()); + assertEquals("Dorothy", pipResolver.getName()); + assertEquals("Oz", pipResolver.getDescription()); + assertEquals("Wizard", pipResolver.getIssuer()); + + // Test getConfiguration + assertEquals(10, config.getConfiguration(null).size()); + assertEquals(10, config.getConfiguration("kansas").size()); + assertEquals(10, config.getConfiguration("kansas.").size()); + config.setDescription(null); + assertEquals(9, config.getConfiguration(null).size()); + config.setIssuer(null); + assertEquals(8, config.getConfiguration(null).size()); + config.setPipresolvers(new LinkedHashSet<PipResolver>()); + assertEquals(3, config.getConfiguration(null).size()); + + // Test generateProperties + assertEquals(4, config.generateProperties(null).size()); + assertEquals(4, config.generateProperties("kansas").size()); + assertEquals(4, config.generateProperties("kansas.").size()); + config.setIssuer(""); + assertEquals(4, config.generateProperties("kansas.").size()); + } +} diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipJpaTest.java index 7421d79c9..2a5dff61f 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PIPJPATest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PipJpaTest.java @@ -3,13 +3,14 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. @@ -17,25 +18,33 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.rest.jpa; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.att.research.xacml.api.pip.PIPException; import java.util.Date; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Properties; +import java.util.Set; import org.junit.Test; -import com.att.research.xacml.api.pip.PIPException; - -public class PIPJPATest { +public class PipJpaTest { @Test - public void testPIPConfigParam(){ - PIPConfigParam data = new PIPConfigParam(); - new PIPConfigParam("test"); - new PIPConfigParam(new PIPConfigParam()); + public void testPipConfigParam() { + PipConfigParam data = new PipConfigParam(); + new PipConfigParam("test"); + new PipConfigParam(new PipConfigParam()); data.setId(1); assertTrue(1 == data.getId()); data.setParamName("Test"); @@ -44,18 +53,20 @@ public class PIPJPATest { assertTrue("Test".equals(data.getParamValue())); data.setParamDefault("Test"); assertTrue("Test".equals(data.getParamDefault())); - data.setPipconfiguration(new PIPConfiguration()); - assertTrue(data.getPipconfiguration()!=null); - data.setRequired(true); + data.setPipconfiguration(new PipConfiguration()); + assertTrue(data.getPipconfiguration() != null); + data.setRequiredFlag(true); assertTrue(data.isRequired()); + data.setRequiredFlag(false); + assertFalse(data.isRequired()); data.toString(); } @Test - public void testPIPResolverParam(){ - PIPResolverParam data = new PIPResolverParam(); - new PIPResolverParam("test"); - new PIPResolverParam(new PIPResolverParam()); + public void testPipResolverParam() { + PipResolverParam data = new PipResolverParam(); + new PipResolverParam("test"); + new PipResolverParam(new PipResolverParam()); data.setId(1); assertTrue(1 == data.getId()); data.setParamName("Test"); @@ -64,40 +75,42 @@ public class PIPJPATest { assertTrue("Test".equals(data.getParamValue())); data.setParamDefault("Test"); assertTrue("Test".equals(data.getParamDefault())); - data.setPipresolver(new PIPResolver()); - assertTrue(data.getPipresolver()!=null); + data.setPipresolver(new PipResolver()); + assertTrue(data.getPipresolver() != null); data.setRequired(true); assertTrue(data.isRequired()); + data.setRequired(false); + assertFalse(data.isRequired()); data.toString(); } @Test - public void testPIPType(){ - PIPType data = new PIPType(); + public void testPipType() { + PipType data = new PipType(); data.setId(1); assertTrue(1 == data.getId()); data.setType("Test"); assertTrue("Test".equals(data.getType())); data.setPipconfigurations(new HashSet<>()); - assertTrue(data.getPipconfigurations()!=null); - data.addPipconfiguration(new PIPConfiguration()); - data.removePipconfiguration(new PIPConfiguration()); + assertTrue(data.getPipconfigurations() != null); + data.addPipconfiguration(new PipConfiguration()); + data.removePipconfiguration(new PipConfiguration()); data.setType("SQL"); - assertTrue(data.isSQL()); + assertTrue(data.isSql()); data.setType("LDAP"); - assertTrue(data.isLDAP()); + assertTrue(data.isLdap()); data.setType("CSV"); - assertTrue(data.isCSV()); + assertTrue(data.isCsv()); data.setType("Hyper-CSV"); - assertTrue(data.isHyperCSV()); + assertTrue(data.isHyperCsv()); data.setType("Custom"); assertTrue(data.isCustom()); } @Test - public void testPIPResolver(){ - PIPResolver data = new PIPResolver(); - new PIPResolver(new PIPResolver()); + public void testPipResolver() { + PipResolver data = new PipResolver(); + new PipResolver(new PipResolver()); data.prePersist(); data.preUpdate(); data.setId(1); @@ -115,32 +128,50 @@ public class PIPJPATest { data.setModifiedBy("Test"); assertTrue("Test".equals(data.getModifiedBy())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!=null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!=null); - data.setPipconfiguration(new PIPConfiguration()); - assertTrue(data.getPipconfiguration()!=null); + assertTrue(data.getModifiedDate() != null); + data.setPipconfiguration(new PipConfiguration()); + assertTrue(data.getPipconfiguration() != null); data.setPipresolverParams(new HashSet<>()); - assertTrue(data.getPipresolverParams()!=null); - data.addPipresolverParam(new PIPResolverParam()); - data.removePipresolverParam(new PIPResolverParam()); + assertTrue(data.getPipresolverParams() != null); + data.addPipresolverParam(new PipResolverParam()); + data.removePipresolverParam(new PipResolverParam()); + assertNull(data.removePipresolverParam(null)); data.clearParams(); data.getConfiguration("test"); + assertNotNull(data.getConfiguration("test.")); data.setReadOnly(true); assertTrue(data.isReadOnly()); + data.setReadOnly(false); + assertFalse(data.isReadOnly()); data.toString(); Properties properties = new Properties(); - data.generateProperties(properties,"test"); + data.generateProperties(properties, "test"); try { data.readProperties("test", properties); } catch (PIPException e) { fail(); } + data.setIssuer(""); + assertEquals(4, data.getConfiguration("test").size()); + data.generateProperties(properties, "test."); + assertEquals(4, data.getConfiguration("test").size()); + + Set<PipResolverParam> pipresolverParams = new LinkedHashSet<>(); + PipResolverParam prp = new PipResolverParam(); + prp.setParamName("Dorothy"); + prp.setParamValue("Gale"); + pipresolverParams.add(prp); + data.setPipresolverParams(pipresolverParams); + data.generateProperties(properties, "test"); + assertEquals(5, data.getConfiguration("test").size()); + assertEquals(5, new PipResolver(data).getConfiguration("test").size()); } @Test - public void testPIPConfiguration(){ - PIPConfiguration data = new PIPConfiguration(); + public void testPipConfiguration() { + PipConfiguration data = new PipConfiguration(); data.prePersist(); data.preUpdate(); data.setId(1); @@ -158,24 +189,24 @@ public class PIPJPATest { data.setModifiedBy("Test"); assertTrue("Test".equals(data.getModifiedBy())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!=null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!=null); + assertTrue(data.getModifiedDate() != null); try { data.readProperties("test", data.generateProperties("test")); } catch (PIPException e) { fail(); } - data.setPiptype(new PIPType()); - assertTrue(data.getPiptype()!=null); + data.setPiptype(new PipType()); + assertTrue(data.getPiptype() != null); data.setPipresolvers(new HashSet<>()); - assertTrue(data.getPipresolvers()!=null); - data.addPipresolver(new PIPResolver()); - data.removePipresolver(new PIPResolver()); + assertTrue(data.getPipresolvers() != null); + data.addPipresolver(new PipResolver()); + data.removePipresolver(new PipResolver()); data.getConfiguration("test"); - data.setReadOnly(true); + data.setReadOnlyFlag(true); assertTrue(data.isReadOnly()); - data.setRequiresResolvers(true); + data.setRequiresResolversFlag(true); assertTrue(data.requiresResolvers()); data.toString(); } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java index 15e28b142..1ae1cb3e2 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyAuditlogTest.java @@ -3,6 +3,7 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +22,9 @@ package org.onap.policy.rest.jpa; import static org.junit.Assert.assertEquals; + import java.text.ParseException; + import org.junit.Test; public class PolicyAuditlogTest { diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java index 224513eee..b392b6f5a 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyEntityJpaTest.java @@ -22,6 +22,7 @@ package org.onap.policy.rest.jpa; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -71,11 +72,11 @@ public class PolicyEntityJpaTest { */ @Test public void testPolicyDbDaoEntity() { - PolicyDBDaoEntity data = new PolicyDBDaoEntity(); + PolicyDbDaoEntity data = new PolicyDbDaoEntity(); data.prePersist(); data.preUpdate(); - data.setPolicyDBDaoUrl("Test"); - assertTrue("Test".equals(data.getPolicyDBDaoUrl())); + data.setPolicyDbDaoUrl("Test"); + assertTrue("Test".equals(data.getPolicyDbDaoUrl())); data.setDescription("Test"); assertTrue("Test".equals(data.getDescription())); assertTrue(data.getCreatedDate() != null); @@ -126,6 +127,259 @@ public class PolicyEntityJpaTest { assertTrue(data.isDeleted()); data.equals(new PolicyEntity()); data.hashCode(); + + PolicyEntity entity0 = new PolicyEntity(); + PolicyEntity entity1 = new PolicyEntity(); + assertTrue(entity0.equals(entity0)); + assertTrue(entity0.equals(entity1)); + assertFalse(entity0.equals(null)); + String helloString = "Hello"; + Object helloObject = helloString; + assertFalse(entity0.equals(helloObject)); + + entity0.setPolicyId(1); + assertFalse(entity0.equals(entity1)); + entity1.setPolicyId(1); + assertTrue(entity0.equals(entity1)); + entity0.setPolicyId(2); + assertFalse(entity0.equals(entity1)); + entity1.setPolicyId(2); + assertTrue(entity0.equals(entity1)); + + entity0.setPolicyName("GoToOz"); + assertFalse(entity0.equals(entity1)); + entity1.setPolicyName("GoToOz"); + assertTrue(entity0.equals(entity1)); + entity1.setPolicyName(null); + assertFalse(entity0.equals(entity1)); + entity0.setPolicyName(null); + assertTrue(entity0.equals(entity1)); + entity1.setPolicyName("GoToOz"); + assertFalse(entity0.equals(entity1)); + entity0.setPolicyName("GoToOz"); + assertTrue(entity0.equals(entity1)); + entity1.setPolicyName("GoToOzNow"); + assertFalse(entity0.equals(entity1)); + entity0.setPolicyName("GoToOzNow"); + assertTrue(entity0.equals(entity1)); + + entity0.setScope("All"); + assertFalse(entity0.equals(entity1)); + entity1.setScope("All"); + assertTrue(entity0.equals(entity1)); + entity1.setScope(null); + assertFalse(entity0.equals(entity1)); + entity0.setScope(null); + assertTrue(entity0.equals(entity1)); + entity1.setScope("All"); + assertFalse(entity0.equals(entity1)); + entity0.setScope("All"); + assertTrue(entity0.equals(entity1)); + entity1.setScope("AllIn"); + assertFalse(entity0.equals(entity1)); + entity0.setScope("AllIn"); + assertTrue(entity0.equals(entity1)); + + entity0.setVersion(1); + assertFalse(entity0.equals(entity1)); + entity1.setVersion(1); + assertTrue(entity0.equals(entity1)); + + entity0.setPolicyVersion(1); + assertFalse(entity0.equals(entity1)); + entity1.setPolicyVersion(1); + assertTrue(entity0.equals(entity1)); + entity0.setPolicyVersion(2); + assertFalse(entity0.equals(entity1)); + entity1.setPolicyVersion(2); + assertTrue(entity0.equals(entity1)); + + entity0.setPolicyData("SomeData"); + assertFalse(entity0.equals(entity1)); + entity1.setPolicyData("SomeData"); + assertTrue(entity0.equals(entity1)); + entity1.setPolicyData(null); + assertFalse(entity0.equals(entity1)); + entity0.setPolicyData(null); + assertTrue(entity0.equals(entity1)); + entity1.setPolicyData("SomeData"); + assertFalse(entity0.equals(entity1)); + entity0.setPolicyData("SomeData"); + assertTrue(entity0.equals(entity1)); + entity1.setPolicyData("SomeMoreData"); + assertFalse(entity0.equals(entity1)); + entity0.setPolicyData("SomeMoreData"); + assertTrue(entity0.equals(entity1)); + + ConfigurationDataEntity cde0 = new ConfigurationDataEntity(); + entity0.setConfigurationDataEntity(cde0); + assertFalse(entity0.equals(entity1)); + entity1.setConfigurationDataEntity(cde0); + assertTrue(entity0.equals(entity1)); + entity1.setConfigurationDataEntity(null); + assertFalse(entity0.equals(entity1)); + entity0.setConfigurationDataEntity(null); + assertTrue(entity0.equals(entity1)); + ConfigurationDataEntity cde1 = new ConfigurationDataEntity(); + entity1.setConfigurationDataEntity(cde1); + assertFalse(entity0.equals(entity1)); + entity0.setConfigurationDataEntity(cde1); + assertTrue(entity0.equals(entity1)); + + ActionBodyEntity abe0 = new ActionBodyEntity(); + entity0.setActionBodyEntity(abe0); + assertFalse(entity0.equals(entity1)); + entity1.setActionBodyEntity(abe0); + assertTrue(entity0.equals(entity1)); + entity1.setActionBodyEntity(null); + assertFalse(entity0.equals(entity1)); + entity0.setActionBodyEntity(null); + assertTrue(entity0.equals(entity1)); + entity1.setActionBodyEntity(abe0); + assertFalse(entity0.equals(entity1)); + entity0.setActionBodyEntity(abe0); + assertTrue(entity0.equals(entity1)); + ActionBodyEntity abe1 = new ActionBodyEntity(); + entity1.setActionBodyEntity(abe1); + assertFalse(entity0.equals(entity1)); + entity0.setActionBodyEntity(abe1); + assertTrue(entity0.equals(entity1)); + + entity0.setDescription("Description"); + assertFalse(entity0.equals(entity1)); + entity1.setDescription("Description"); + assertTrue(entity0.equals(entity1)); + entity1.setDescription(null); + assertFalse(entity0.equals(entity1)); + entity0.setDescription(null); + assertTrue(entity0.equals(entity1)); + entity1.setDescription("Description"); + assertFalse(entity0.equals(entity1)); + entity0.setDescription("Description"); + assertTrue(entity0.equals(entity1)); + assertTrue(entity0.equals(entity1)); + entity1.setDescription("Description Extra"); + assertFalse(entity0.equals(entity1)); + entity0.setDescription("Description Extra"); + assertTrue(entity0.equals(entity1)); + + entity0.setDeleted(true); + assertFalse(entity0.equals(entity1)); + entity1.setDeleted(true); + assertTrue(entity0.equals(entity1)); + entity0.setDeleted(false); + assertFalse(entity0.equals(entity1)); + entity1.setDeleted(false); + assertTrue(entity0.equals(entity1)); + + entity0.setDeleteReasonCode("NoReason"); + assertFalse(entity0.equals(entity1)); + entity1.setDeleteReasonCode("NoReason"); + assertTrue(entity0.equals(entity1)); + entity1.setDeleteReasonCode(null); + assertFalse(entity0.equals(entity1)); + entity0.setDeleteReasonCode(null); + assertTrue(entity0.equals(entity1)); + entity1.setDeleteReasonCode("NoReason"); + assertFalse(entity0.equals(entity1)); + entity0.setDeleteReasonCode("NoReason"); + assertTrue(entity0.equals(entity1)); + assertTrue(entity0.equals(entity1)); + entity1.setDeleteReasonCode("NoOtherReason"); + assertFalse(entity0.equals(entity1)); + entity0.setDeleteReasonCode("NoOtherReason"); + assertTrue(entity0.equals(entity1)); + + entity0.setCreatedBy("Dorothy"); + assertFalse(entity0.equals(entity1)); + entity1.setCreatedBy("Dorothy"); + assertTrue(entity0.equals(entity1)); + entity1.setCreatedBy(null); + assertFalse(entity0.equals(entity1)); + entity0.setCreatedBy(null); + assertTrue(entity0.equals(entity1)); + entity1.setCreatedBy("Dorothy"); + assertFalse(entity0.equals(entity1)); + entity0.setCreatedBy("Dorothy"); + assertTrue(entity0.equals(entity1)); + entity1.setCreatedBy("Toto"); + assertFalse(entity0.equals(entity1)); + entity0.setCreatedBy("Toto"); + assertTrue(entity0.equals(entity1)); + + entity0.setCreatedDate(new Date(12345L)); + assertFalse(entity0.equals(entity1)); + entity1.setCreatedDate(new Date(12345L)); + assertTrue(entity0.equals(entity1)); + entity1.setCreatedDate(null); + assertFalse(entity0.equals(entity1)); + entity0.setCreatedDate(null); + assertTrue(entity0.equals(entity1)); + entity1.setCreatedDate(new Date(12345L)); + assertFalse(entity0.equals(entity1)); + entity0.setCreatedDate(new Date(12345L)); + assertTrue(entity0.equals(entity1)); + assertTrue(entity0.equals(entity1)); + entity1.setCreatedDate(new Date(123456L)); + assertFalse(entity0.equals(entity1)); + entity0.setCreatedDate(new Date(123456L)); + assertTrue(entity0.equals(entity1)); + + entity0.setModifiedBy("Dorothy"); + assertFalse(entity0.equals(entity1)); + entity1.setModifiedBy("Dorothy"); + assertTrue(entity0.equals(entity1)); + entity1.setModifiedBy(null); + assertFalse(entity0.equals(entity1)); + entity0.setModifiedBy(null); + assertTrue(entity0.equals(entity1)); + entity1.setModifiedBy("Dorothy"); + assertFalse(entity0.equals(entity1)); + entity0.setModifiedBy("Dorothy"); + assertTrue(entity0.equals(entity1)); + entity1.setModifiedBy("Toto"); + assertFalse(entity0.equals(entity1)); + entity0.setModifiedBy("Toto"); + assertTrue(entity0.equals(entity1)); + + entity0.setModifiedDate(new Date(12345L)); + assertFalse(entity0.equals(entity1)); + entity1.setModifiedDate(new Date(12345L)); + assertTrue(entity0.equals(entity1)); + entity1.setModifiedDate(null); + assertFalse(entity0.equals(entity1)); + entity0.setModifiedDate(null); + assertTrue(entity0.equals(entity1)); + entity1.setModifiedDate(new Date(12345L)); + assertFalse(entity0.equals(entity1)); + entity0.setModifiedDate(new Date(12345L)); + assertTrue(entity0.equals(entity1)); + assertTrue(entity0.equals(entity1)); + entity1.setModifiedDate(new Date(123456L)); + assertFalse(entity0.equals(entity1)); + entity0.setModifiedDate(new Date(123456L)); + assertTrue(entity0.equals(entity1)); + + entity0.setDeletedBy("Dorothy"); + assertFalse(entity0.equals(entity1)); + entity1.setDeletedBy("Dorothy"); + assertTrue(entity0.equals(entity1)); + entity1.setDeletedBy(null); + assertFalse(entity0.equals(entity1)); + entity0.setDeletedBy(null); + assertTrue(entity0.equals(entity1)); + entity1.setDeletedBy("Dorothy"); + assertFalse(entity0.equals(entity1)); + entity0.setDeletedBy("Dorothy"); + assertTrue(entity0.equals(entity1)); + assertTrue(entity0.equals(entity1)); + entity1.setDeletedBy("Toto"); + assertFalse(entity0.equals(entity1)); + entity0.setDeletedBy("Toto"); + assertTrue(entity0.equals(entity1)); + + assertNotNull(entity0.hashCode()); + assertNotNull(entity1.hashCode()); } /** diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJPATest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJpaTest.java index 3ada4dfca..26d47a2fc 100644 --- a/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJPATest.java +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/jpa/PolicyUtilsJpaTest.java @@ -3,13 +3,14 @@ * ONAP-REST * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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. @@ -17,8 +18,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.rest.jpa; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.Date; @@ -28,11 +32,19 @@ import org.junit.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -public class PolicyUtilsJPATest { +/** + * The Class PolicyUtilsJpaTest. + */ +public class PolicyUtilsJpaTest { - private static Logger logger = FlexLogger.getLogger(PolicyUtilsJPATest.class); + private static Logger logger = FlexLogger.getLogger(PolicyUtilsJpaTest.class); private UserInfo userInfo; + /** + * Sets the up. + * + * @throws Exception the exception + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); @@ -42,8 +54,11 @@ public class PolicyUtilsJPATest { logger.info("setUp: exit"); } + /** + * Test watch policy notification table. + */ @Test - public void testWatchPolicyNotificationTable(){ + public void testWatchPolicyNotificationTable() { WatchPolicyNotificationTable data = new WatchPolicyNotificationTable(); data.setId(1); assertTrue(1 == data.getId()); @@ -55,8 +70,11 @@ public class PolicyUtilsJPATest { data.hashCode(); } + /** + * Test policy roles. + */ @Test - public void testPolicyRoles(){ + public void testPolicyRoles() { PolicyRoles data = new PolicyRoles(); data.setId(1); assertTrue(1 == data.getId()); @@ -68,8 +86,11 @@ public class PolicyUtilsJPATest { assertTrue("Test".equals(data.getLoginId().getUserLoginId())); } + /** + * Test policy version. + */ @Test - public void testPolicyVersion(){ + public void testPolicyVersion() { PolicyVersion data = new PolicyVersion(); new PolicyVersion("Test", "Test"); data.prePersist(); @@ -87,17 +108,105 @@ public class PolicyUtilsJPATest { data.setModifiedBy("Test"); assertTrue("Test".equals(data.getModifiedBy())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!=null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!=null); - data.equals(data); - data.hashCode(); + assertTrue(data.getModifiedDate() != null); + + assertNotNull(data.hashCode()); + + PolicyVersion version0 = new PolicyVersion(); + PolicyVersion version1 = new PolicyVersion(); + assertTrue(version0.equals(version0)); + assertTrue(version0.equals(version1)); + assertFalse(version0.equals(null)); + String helloString = "Hello"; + Object helloObject = helloString; + assertFalse(version0.equals(helloObject)); + + version0.setId(1); + assertFalse(version0.equals(version1)); + version1.setId(1); + assertTrue(version0.equals(version1)); + version0.setActiveVersion(1); + assertFalse(version0.equals(version1)); + version1.setActiveVersion(1); + assertTrue(version0.equals(version1)); + version0.setCreatedBy("Dorothy"); + assertFalse(version0.equals(version1)); + version1.setCreatedBy("Dorothy"); + assertTrue(version0.equals(version1)); + version1.setCreatedBy(null); + assertFalse(version0.equals(version1)); + version0.setCreatedBy(null); + assertTrue(version0.equals(version1)); + version1.setCreatedBy("Dorothy"); + assertFalse(version0.equals(version1)); + version0.setCreatedBy("Dorothy"); + assertTrue(version0.equals(version1)); + version0.setCreatedDate(new Date(12345L)); + assertFalse(version0.equals(version1)); + version1.setCreatedDate(new Date(12345L)); + assertTrue(version0.equals(version1)); + version1.setCreatedDate(null); + assertFalse(version0.equals(version1)); + version0.setCreatedDate(null); + assertTrue(version0.equals(version1)); + version1.setCreatedDate(new Date(12345L)); + assertFalse(version0.equals(version1)); + version0.setCreatedDate(new Date(12345L)); + assertTrue(version0.equals(version1)); + version0.setHigherVersion(1); + assertFalse(version0.equals(version1)); + version1.setHigherVersion(1); + assertTrue(version0.equals(version1)); + version0.setModifiedBy("Dorothy"); + assertFalse(version0.equals(version1)); + version1.setModifiedBy("Dorothy"); + assertTrue(version0.equals(version1)); + version1.setModifiedBy(null); + assertFalse(version0.equals(version1)); + version0.setModifiedBy(null); + assertTrue(version0.equals(version1)); + version1.setModifiedBy("Dorothy"); + assertFalse(version0.equals(version1)); + version0.setModifiedBy("Dorothy"); + assertTrue(version0.equals(version1)); + version0.setModifiedDate(new Date(12345L)); + assertFalse(version0.equals(version1)); + version1.setModifiedDate(new Date(12345L)); + assertTrue(version0.equals(version1)); + version1.setModifiedDate(null); + assertFalse(version0.equals(version1)); + version0.setModifiedDate(null); + assertTrue(version0.equals(version1)); + version1.setModifiedDate(new Date(12345L)); + assertFalse(version0.equals(version1)); + version0.setModifiedDate(new Date(12345L)); + assertTrue(version0.equals(version1)); + version0.setPolicyName("GoToOz"); + assertFalse(version0.equals(version1)); + version1.setPolicyName("GoToOz"); + assertTrue(version0.equals(version1)); + version1.setPolicyName(null); + assertFalse(version0.equals(version1)); + version0.setPolicyName(null); + assertTrue(version0.equals(version1)); + version1.setPolicyName("GoToOz"); + assertFalse(version0.equals(version1)); + version0.setPolicyName("GoToOz"); + assertTrue(version0.equals(version1)); + + assertNotNull(version0.hashCode()); + assertNotNull(version1.hashCode()); } + /** + * Test system log DB. + */ @Test - public void testSystemLogDB(){ + public void testSystemLogDB() { SystemLogDB data = new SystemLogDB(); - new SystemLogDB(1, "","","","",""); + new SystemLogDB(1, "", "", "", "", ""); data.setId(1); assertTrue(1 == data.getId()); data.setDescription("Test"); @@ -111,11 +220,14 @@ public class PolicyUtilsJPATest { data.setLogtype("Test"); assertTrue("Test".equals(data.getLogtype())); data.setDate(new Date()); - assertTrue(data.getDate()!=null); + assertTrue(data.getDate() != null); } + /** + * Test remote catalog values. + */ @Test - public void testRemoteCatalogValues(){ + public void testRemoteCatalogValues() { RemoteCatalogValues data = new RemoteCatalogValues(); data.setId(1); assertTrue(1 == data.getId()); @@ -125,8 +237,11 @@ public class PolicyUtilsJPATest { assertTrue("Test".equals(data.getValue())); } + /** + * Test policy score. + */ @Test - public void testPolicyScore(){ + public void testPolicyScore() { PolicyScore data = new PolicyScore(); data.setId(1); assertTrue(1 == data.getId()); @@ -134,12 +249,15 @@ public class PolicyUtilsJPATest { assertTrue("Test".equals(data.getPolicyName())); data.setVersionExtension("Test"); assertTrue("Test".equals(data.getVersionExtension())); - data.setPolicyScore("Test"); - assertTrue("Test".equals(data.getPolicyScore())); + data.setScore("Test"); + assertTrue("Test".equals(data.getScore())); } + /** + * Test policy editor scopes. + */ @Test - public void testPolicyEditorScopes(){ + public void testPolicyEditorScopes() { PolicyEditorScopes data = new PolicyEditorScopes(); data.prePersist(); data.preUpdate(); @@ -148,17 +266,20 @@ public class PolicyUtilsJPATest { data.setScopeName("Test"); assertTrue("Test".equals(data.getScopeName())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!=null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!=null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!=null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!=null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test descriptive scope. + */ @Test - public void testDescriptiveScope(){ + public void testDescriptiveScope() { DescriptiveScope data = new DescriptiveScope(); data.prePersist(); data.preUpdate(); @@ -169,17 +290,20 @@ public class PolicyUtilsJPATest { data.setSearch("Test"); assertTrue("Test".equals(data.getSearch())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!=null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!=null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!=null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!=null); + assertTrue(data.getUserModifiedBy() != null); } + /** + * Test global role settings. + */ @Test - public void testGlobalRoleSettings(){ + public void testGlobalRoleSettings() { GlobalRoleSettings data = new GlobalRoleSettings(); new GlobalRoleSettings(true); data.setRole("Test"); |