aboutsummaryrefslogtreecommitdiffstats
path: root/PolicyEngineUtils/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'PolicyEngineUtils/src/test/java')
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/AAFEnvironmentTest.java39
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/BusTest.java (renamed from PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BusTest.java)49
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/PeCryptoUtilsTest.java9
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/AAFClientTest.java46
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java52
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorExceptionTest.java61
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java4
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/DummyBackUpHandler.java26
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java74
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PEDependencyTest.java18
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java313
11 files changed, 388 insertions, 303 deletions
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/AAFEnvironmentTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/AAFEnvironmentTest.java
new file mode 100644
index 000000000..cf997251c
--- /dev/null
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/AAFEnvironmentTest.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * PolicyEngineUtils
+ * ================================================================================
+ * Copyright (C) 2019 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.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class AAFEnvironmentTest {
+
+ @Test
+ public void test() {
+ AAFEnvironment env = AAFEnvironment.DEVL;
+ assertEquals(AAFEnvironment.DEVL, env);
+ env = AAFEnvironment.PROD;
+ assertEquals(AAFEnvironment.PROD, env);
+ env = AAFEnvironment.TEST;
+ assertEquals(AAFEnvironment.TEST, env);
+ }
+
+}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BusTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/BusTest.java
index 37f0bb016..50d91c6fc 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BusTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/BusTest.java
@@ -2,14 +2,15 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications copyright (c) 2019 Nokia
* ================================================================================
* 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.
@@ -18,38 +19,50 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.utils.test;
+package org.onap.policy.utils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.net.MalformedURLException;
import java.util.Arrays;
import org.junit.Test;
import org.onap.dmaap.mr.client.MRClient.MRApiException;
-import org.onap.policy.utils.BusConsumer;
-import org.onap.policy.utils.BusPublisher;
+import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
+import org.onap.policy.utils.BusConsumer.DmaapConsumerWrapper;
public class BusTest {
-
- @Test
- public void busPublisherTest(){
+
+ @Test
+ public void busPublisherTest() {
BusPublisher bus = new BusPublisher.DmaapPublisherWrapper(Arrays.asList("test"), "test", "test", "test");
assertTrue(bus.send("test123", "Hello World!"));
- assertEquals("DmaapPublisherWrapper [publisher.getAuthDate()=null, publisher.getAuthKey()=null, publisher.getHost()=test, publisher.getProtocolFlag()=HTTPAAF, publisher.getUsername()=test, publisher.getPendingMessageCount()=1]",bus.toString());
+ assertEquals(
+ "DmaapPublisherWrapper [publisher.getAuthDate()=null, publisher.getAuthKey()=null, publisher.getHost()=test, publisher.getProtocolFlag()=HTTPAAF, publisher.getUsername()=test, publisher.getPendingMessageCount()=1]",
+ bus.toString());
bus.close();
}
-
- @Test (expected = MRApiException.class)
- public void busConsumerFailTest() throws MalformedURLException, MRApiException{
- new BusConsumer.DmaapConsumerWrapper(Arrays.asList("test"), "test", "test", "test", "test", "test", 1, 1).fetch();
+
+ @Test(expected = MRApiException.class)
+ public void busConsumerFailTest() throws Exception {
+ // given
+ MRConsumerImpl mrConsumer = mock(MRConsumerImpl.class);
+ when(mrConsumer.fetch()).thenThrow(new Exception());
+ DmaapConsumerWrapper dmaapConsumerWrapper = new DmaapConsumerWrapper(mrConsumer, "", "", "");
+
+ // when
+ dmaapConsumerWrapper.fetch();
}
-
+
@Test
- public void busConsumerTest() throws MalformedURLException, MRApiException{
- BusConsumer bus = new BusConsumer.DmaapConsumerWrapper(Arrays.asList("test"), "test", "test", "test", "test", "test", 1, 1);
- assertEquals(bus.toString(),"DmaapConsumerWrapper [consumer.getAuthDate()=null, consumer.getAuthKey()=null, consumer.getHost()=test:3904, consumer.getProtocolFlag()=HTTPAAF, consumer.getUsername()=test]");
+ public void busConsumerTest() throws MalformedURLException, MRApiException {
+ BusConsumer bus = new BusConsumer.DmaapConsumerWrapper(Arrays.asList("test"), "test", "test", "test", "test",
+ "test", 1, 1);
+ assertEquals(bus.toString(),
+ "DmaapConsumerWrapper [consumer.getAuthDate()=null, consumer.getAuthKey()=null, consumer.getHost()=test:3904, consumer.getProtocolFlag()=HTTPAAF, consumer.getUsername()=test]");
bus.close();
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/PeCryptoUtilsTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/PeCryptoUtilsTest.java
index 3765ff2e3..28b1fb4e8 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/PeCryptoUtilsTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/PeCryptoUtilsTest.java
@@ -22,12 +22,13 @@ package org.onap.policy.utils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+
import java.security.GeneralSecurityException;
+
import org.junit.Before;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
-
public class PeCryptoUtilsTest {
private final String pass = "policy_user";
private final String secretKey = "bmpybWJrbGN4dG9wbGF3Zg==";
@@ -36,7 +37,7 @@ public class PeCryptoUtilsTest {
@Before
public void reset() {
- Whitebox.setInternalState( PeCryptoUtils.class, "cryptoUtils", (PeCryptoUtils)null);
+ Whitebox.setInternalState(PeCryptoUtils.class, "cryptoUtils", (PeCryptoUtils) null);
}
@@ -55,8 +56,8 @@ public class PeCryptoUtilsTest {
PeCryptoUtils.initAesKey(null);
System.clearProperty(PROP_AES_KEY);
assertEquals(pass, PeCryptoUtils.decrypt(encryptedPass));
- Whitebox.setInternalState( PeCryptoUtils.class, "cryptoUtils", (PeCryptoUtils)null);
- Whitebox.setInternalState( PeCryptoUtils.class, "secretKey", secretKey);
+ Whitebox.setInternalState(PeCryptoUtils.class, "cryptoUtils", (PeCryptoUtils) null);
+ Whitebox.setInternalState(PeCryptoUtils.class, "secretKey", secretKey);
PeCryptoUtils.initAesKey(" ");
assertEquals(pass, PeCryptoUtils.decrypt(pass));
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/AAFClientTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/AAFClientTest.java
index 2fa822a33..23060688d 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/AAFClientTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/AAFClientTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
@@ -33,23 +33,33 @@ import org.onap.policy.utils.AAFPolicyException;
public class AAFClientTest {
AAFPolicyClient afClient;
String pass = "test";
-
+ String user = "test";
+
+ /**
+ * setUp.
+ *
+ * @throws AAFPolicyException AAFPolicyException
+ */
@Before
- public void setUp() throws AAFPolicyException{
+ public void setUp() throws AAFPolicyException {
Properties props = new Properties();
props.setProperty("ENVIRONMENT", "TEST");
props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
- afClient = AAFPolicyClient.getInstance(props);
+ afClient = AAFPolicyClient.getInstance(props);
}
-
+
@Test
- public void invalidClientTest() throws AAFPolicyException{
- assertFalse(afClient.checkAuth("test", pass));
- assertFalse(afClient.checkPerm("test", pass, "policy-engine.config", "*", "*"));
+ public void invalidClientTest() throws AAFPolicyException {
+ assertFalse(afClient.checkPerm(null, null, null, null, null));
+ assertFalse(afClient.checkPerm(user, null, null, null, null));
+ assertFalse(afClient.checkAuth(user, pass));
+ assertFalse(afClient.checkAuth(null, pass));
+ assertFalse(afClient.checkAuth(user, null));
+ assertFalse(afClient.checkPerm(user, pass, "policy-engine.config", "*", "*"));
Properties props = new Properties();
props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
- afClient = AAFPolicyClient.getInstance(props);
- assertFalse(afClient.checkAuth("test", pass));
+ afClient = AAFPolicyClient.getInstance(props);
+ assertFalse(afClient.checkAuth(user, pass));
props.setProperty("ENVIRONMENT", "PROD");
props.setProperty("aafClient.impl.className", AAFPolicyClientImpl.class.getName());
afClient.updateProperties(props);
@@ -63,14 +73,14 @@ public class AAFClientTest {
assertFalse(afClient.checkAuth("test", pass));
assertFalse(afClient.checkAuthPerm("test", pass, "decision", "*", "read"));
}
-
+
@Test(expected = AAFPolicyException.class)
- public void invalidAAFInstance() throws AAFPolicyException{
+ public void invalidAafInstance() throws AAFPolicyException {
Properties props = new Properties();
props.setProperty("aafClient.impl.className", "errorClass");
- afClient = AAFPolicyClient.getInstance(props);
+ afClient = AAFPolicyClient.getInstance(props);
}
-
+
@Test(expected = AAFPolicyException.class)
public void testPropNullException() throws AAFPolicyException {
afClient.updateProperties(null);
@@ -80,9 +90,9 @@ public class AAFClientTest {
public void testPropEmptyException() throws AAFPolicyException {
afClient.updateProperties(new Properties());
}
-
+
@Test(expected = AAFPolicyException.class)
- public void testAAFException() throws AAFPolicyException{
+ public void testAafException() throws AAFPolicyException {
new AAFPolicyException();
new AAFPolicyException("error", new Exception());
throw new AAFPolicyException("error", new Exception(), false, false);
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java
index f77fe72c9..4bbe008e3 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorEntityTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
@@ -22,31 +22,33 @@ package org.onap.policy.utils.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+
import java.util.Date;
+
import org.junit.Test;
import org.onap.policy.jpa.BackUpMonitorEntity;
public class BackUpMonitorEntityTest {
- @Test
- public void testEntity() {
- String value = "testVal";
- Date date = new Date();
-
- BackUpMonitorEntity entity = new BackUpMonitorEntity();
- assertNotNull(entity);
-
- entity.setResourceName(value);
- entity.setResourceNodeName(value);
- entity.setFlag(value);
- entity.setNotificationRecord(value);
- entity.prePersist();
- entity.preUpdate();
- entity.setTimeStamp(date);
-
- assertEquals(value, entity.getResourceName());
- assertEquals(value, entity.getResourceNodeName());
- assertEquals(value, entity.getFlag());
- assertEquals(value, entity.getNotificationRecord());
- assertEquals(date, entity.getTimeStamp());
- }
+ @Test
+ public void testEntity() {
+ String value = "testVal";
+
+ BackUpMonitorEntity entity = new BackUpMonitorEntity();
+ assertNotNull(entity);
+
+ entity.setResourceName(value);
+ entity.setResourceNodeName(value);
+ entity.setFlag(value);
+ entity.setNotificationRecord(value);
+ entity.prePersist();
+ entity.preUpdate();
+ Date date = new Date();
+ entity.setTimeStamp(date);
+
+ assertEquals(value, entity.getResourceName());
+ assertEquals(value, entity.getResourceNodeName());
+ assertEquals(value, entity.getFlag());
+ assertEquals(value, entity.getNotificationRecord());
+ assertEquals(date, entity.getTimeStamp());
+ }
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorExceptionTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorExceptionTest.java
index b9700124d..eb56c6f24 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorExceptionTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorExceptionTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
@@ -21,35 +21,36 @@
package org.onap.policy.utils.test;
import java.io.IOException;
+
import org.junit.Test;
import org.onap.policy.utils.BackUpMonitorException;
public class BackUpMonitorExceptionTest {
- @Test(expected = BackUpMonitorException.class)
- public void testException1() throws BackUpMonitorException {
- throw new BackUpMonitorException();
- }
-
- @Test(expected = BackUpMonitorException.class)
- public void testException2() throws BackUpMonitorException {
- throw new BackUpMonitorException("test");
- }
-
- @Test(expected = BackUpMonitorException.class)
- public void testException3() throws BackUpMonitorException {
- Throwable cause = new IOException();
- throw new BackUpMonitorException(cause);
- }
-
- @Test(expected = BackUpMonitorException.class)
- public void testException4() throws BackUpMonitorException {
- Throwable cause = new IOException();
- throw new BackUpMonitorException("test", cause);
- }
-
- @Test(expected = BackUpMonitorException.class)
- public void testException5() throws BackUpMonitorException {
- Throwable cause = new IOException();
- throw new BackUpMonitorException("test", cause, true, true);
- }
+ @Test(expected = BackUpMonitorException.class)
+ public void testException1() throws BackUpMonitorException {
+ throw new BackUpMonitorException();
+ }
+
+ @Test(expected = BackUpMonitorException.class)
+ public void testException2() throws BackUpMonitorException {
+ throw new BackUpMonitorException("test");
+ }
+
+ @Test(expected = BackUpMonitorException.class)
+ public void testException3() throws BackUpMonitorException {
+ Throwable cause = new IOException();
+ throw new BackUpMonitorException(cause);
+ }
+
+ @Test(expected = BackUpMonitorException.class)
+ public void testException4() throws BackUpMonitorException {
+ Throwable cause = new IOException();
+ throw new BackUpMonitorException("test", cause);
+ }
+
+ @Test(expected = BackUpMonitorException.class)
+ public void testException5() throws BackUpMonitorException {
+ Throwable cause = new IOException();
+ throw new BackUpMonitorException("test", cause, true, true);
+ }
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java
index 5182c5329..c692ab8c4 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import com.fasterxml.jackson.core.JsonProcessingException;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -34,11 +35,13 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
+
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
+
import org.apache.commons.io.FileUtils;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
@@ -56,7 +59,6 @@ import org.onap.policy.utils.BackUpMonitor.ResourceNode;
import org.onap.policy.utils.BackUpMonitorException;
import org.onap.policy.utils.PolicyUtils;
-
public class BackUpMonitorTest {
@Test(expected = PersistenceException.class)
public void backUpMonitorTestFail() throws Exception {
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/DummyBackUpHandler.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/DummyBackUpHandler.java
index 15fb33944..232652fa5 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/DummyBackUpHandler.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/DummyBackUpHandler.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
@@ -23,16 +23,16 @@ package org.onap.policy.utils.test;
import org.onap.policy.api.PDPNotification;
import org.onap.policy.utils.BackUpHandler;
-public class DummyBackUpHandler implements BackUpHandler{
+public class DummyBackUpHandler implements BackUpHandler {
- @Override
- public void notificationReceived(PDPNotification notification) {
- System.out.println("Received Notification from PDP. ");
- }
+ @Override
+ public void notificationReceived(PDPNotification notification) {
+ System.out.println("Received Notification from PDP. ");
+ }
+
+ @Override
+ public void runOnNotification(PDPNotification notification) {
+ System.out.println("Running main Notification Function. ");
+ }
- @Override
- public void runOnNotification(PDPNotification notification) {
- System.out.println("Running main Notification Function. ");
- }
-
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
index 774bf8a7e..a7e3a9478 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/NotificationStoreTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
@@ -38,16 +38,16 @@ import org.onap.policy.std.StdRemovedPolicy;
import org.onap.policy.utils.PolicyUtils;
public class NotificationStoreTest {
-
+
@Test
- public void notificationTest() throws IOException{
- // Notification Delta test first.
+ public void notificationTest() throws IOException {
+ // Notification Delta test first.
NotificationStore.recordNotification(new StdPDPNotification());
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(NotificationStore.getDeltaNotification(new StdPDPNotification())));
- // Initialize test
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(NotificationStore.getDeltaNotification(new StdPDPNotification())));
+ // Initialize test
StdPDPNotification notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.BOTH);
- List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
StdLoadedPolicy loadedPolicy = new StdLoadedPolicy();
loadedPolicy.setPolicyName("com.testing");
loadedPolicy.setUpdateType(UpdateType.UPDATE);
@@ -55,6 +55,7 @@ public class NotificationStoreTest {
Map<String, String> matches = new HashMap<>();
matches.put("test", "test");
loadedPolicy.setMatches(matches);
+ List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
List<StdRemovedPolicy> removedPolicies = new ArrayList<>();
@@ -64,8 +65,10 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- assertEquals("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"2\",\"matches\":{\"test\":\"test\"},\"updateType\":\"UPDATE\"}],\"notificationType\":\"BOTH\"}", PolicyUtils.objectToJsonString(NotificationStore.getNotificationRecord()));
- // Add new Notifications.
+ assertEquals(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"2\",\"matches\":{\"test\":\"test\"},\"updateType\":\"UPDATE\"}],\"notificationType\":\"BOTH\"}",
+ PolicyUtils.objectToJsonString(NotificationStore.getNotificationRecord()));
+ // Add new Notifications.
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.BOTH);
loadedPolicies = new ArrayList<>();
@@ -85,9 +88,12 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- StdPDPNotification check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Remove Notifications.
+ StdPDPNotification check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Remove Notifications.
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.REMOVE);
removedPolicies = new ArrayList<>();
@@ -97,9 +103,12 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Remove on remove duplicate Notifications.
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Remove on remove duplicate Notifications.
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.REMOVE);
removedPolicies = new ArrayList<>();
@@ -109,9 +118,12 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Update Notification
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"},{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[],\"notificationType\":\"REMOVE\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Update Notification
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.UPDATE);
loadedPolicies = new ArrayList<>();
@@ -125,9 +137,12 @@ public class NotificationStoreTest {
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- // Update on update duplicate Notification
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ // Update on update duplicate Notification
notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.UPDATE);
loadedPolicies = new ArrayList<>();
@@ -141,9 +156,12 @@ public class NotificationStoreTest {
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
NotificationStore.recordNotification(notification);
- check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject("{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", StdPDPNotification.class));
- assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}", PolicyUtils.objectToJsonString(check));
- //
+ check = NotificationStore.getDeltaNotification(PolicyUtils.jsonStringToObject(
+ "{\"removedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"1\"},{\"policyName\":\"com.testing\",\"versionNo\":\"2\"}],\"loadedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ StdPDPNotification.class));
+ assertEquals("{\"removedPolicies\":[],\"loadedPolicies\":[],\"notificationType\":null}",
+ PolicyUtils.objectToJsonString(check));
+ //
// Notification Delta Tests
//
notification = new StdPDPNotification();
@@ -165,7 +183,9 @@ public class NotificationStoreTest {
removedPolicies.add(removedPolicy);
notification.setRemovedPolicies(removedPolicies);
check = NotificationStore.getDeltaNotification(notification);
- assertEquals("{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}", PolicyUtils.objectToJsonString(check));
+ assertEquals(
+ "{\"removedPolicies\":[{\"policyName\":\"com.test\",\"versionNo\":\"3\"}],\"loadedPolicies\":[{\"policyName\":\"com.testing\",\"versionNo\":\"3\",\"matches\":{\"test\":\"test\"},\"updateType\":\"NEW\"}],\"notificationType\":\"BOTH\"}",
+ PolicyUtils.objectToJsonString(check));
}
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PEDependencyTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PEDependencyTest.java
index 4cc6c90f2..e3cf67f30 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PEDependencyTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PEDependencyTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
@@ -30,9 +30,9 @@ import org.junit.Test;
import org.onap.policy.api.PEDependency;
public class PEDependencyTest {
-
+
@Test
- public void pojoTests(){
+ public void pojoTests() {
PEDependency pe = new PEDependency();
pe.setArtifactId("test");
pe.setGroupId("test");
@@ -41,10 +41,10 @@ public class PEDependencyTest {
pe.setScope("test");
pe.setClassifier("pom");
List<Exclusion> exclusions = new ArrayList<>();
- Exclusion e = new Exclusion();
- e.setArtifactId("ex1");
- e.setGroupId("eG");
- exclusions.add(e);
+ Exclusion exclusion = new Exclusion();
+ exclusion.setArtifactId("ex1");
+ exclusion.setGroupId("eG");
+ exclusions.add(exclusion);
pe.setExclusions(exclusions);
pe.getDependency();
assertEquals(exclusions, pe.getExclusions());
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java
index 8445ad7c8..8d9116d32 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java
@@ -7,9 +7,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.
@@ -45,165 +45,162 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class PolicyUtilsTest {
-
- private static final String ERROR = "The Value in Required Field will allow only '{0-9}, {a-z}, {A-Z}, _' following set of Combinations";
- private static final String SUCCESS = "success";
-
- @Test
- public void testJsonConversions() throws Exception{
- StdPDPNotification notification = new StdPDPNotification();
- notification.setNotificationType(NotificationType.BOTH);
- Collection<StdRemovedPolicy> removedPolicies = new ArrayList<>();
- Collection<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
- StdRemovedPolicy removedPolicy = new StdRemovedPolicy();
- StdLoadedPolicy updatedPolicy = new StdLoadedPolicy();
- removedPolicy.setPolicyName("Test");
- removedPolicy.setVersionNo("1");
- removedPolicies.add(removedPolicy);
- updatedPolicy.setPolicyName("Testing");
- updatedPolicy.setVersionNo("1");
- updatedPolicy.setUpdateType(UpdateType.NEW);
- Map<String, String> matches = new HashMap<>();
- matches.put("key", "value");
- updatedPolicy.setMatches(matches);
- loadedPolicies.add(updatedPolicy);
- notification.setRemovedPolicies(removedPolicies);
- notification.setLoadedPolicies(loadedPolicies);
-
- String json = PolicyUtils.objectToJsonString(notification);
- PDPNotification getBackObject = PolicyUtils.jsonStringToObject(json, StdPDPNotification.class);
- assertEquals(0,getBackObject.getNotificationType().compareTo(notification.getNotificationType()));
-
- }
-
- private String encodedValue(String input){
- return new String(Base64.getEncoder().encode(input.getBytes()));
- }
-
- @Test
- public void testDecode() throws Exception{
- String value = "test";
- assertEquals(value, PolicyUtils.decode(encodedValue(value)));
- assertNull(PolicyUtils.decode(null));
- assertNull(PolicyUtils.decode(""));
- }
-
- @Test
- public void testBasicEncoding() throws Exception{
- String userName = "test";
- String key = "pass";
- String[] decodedValue = PolicyUtils.decodeBasicEncoding("Basic "+encodedValue(userName+":"+key));
- assertEquals(userName,decodedValue[0]);
- assertEquals(key,decodedValue[1]);
- assertEquals(0, PolicyUtils.decodeBasicEncoding(encodedValue(userName+":"+key)).length);
- assertEquals(0, PolicyUtils.decodeBasicEncoding(null).length);
- }
-
- @Test
- public void testSpecialCharValidator(){
- assertEquals(ERROR, PolicyUtils.policySpecialCharValidator("$TEST_"));
- assertEquals(ERROR, PolicyUtils.policySpecialCharValidator("$TEST _"));
- assertEquals(ERROR, PolicyUtils.policySpecialCharValidator(""));
- assertEquals(ERROR, PolicyUtils.policySpecialCharValidator("TæST"));
- assertEquals(SUCCESS, PolicyUtils.policySpecialCharValidator("TEST"));
- }
-
- @Test
- public void testSpecialCharWithSpaceValidator(){
- assertEquals(ERROR, PolicyUtils.policySpecialCharWithSpaceValidator(""));
- assertEquals(ERROR, PolicyUtils.policySpecialCharWithSpaceValidator("$TEST _"));
- assertEquals(SUCCESS, PolicyUtils.policySpecialCharWithSpaceValidator("TE ST"));
- }
-
- @Test
- public void testDescription() {
- assertEquals(SUCCESS, PolicyUtils.descriptionValidator("Test"));
- assertNotEquals(SUCCESS, PolicyUtils.descriptionValidator("@ModifiedBy:TesterB"));
- assertNotEquals(SUCCESS, PolicyUtils.descriptionValidator("@CreatedBy:TesterA"));
- }
-
- @Test
- public void testNonAscii(){
- assertTrue(PolicyUtils.containsNonAsciiEmptyChars(null));
- assertTrue(PolicyUtils.containsNonAsciiEmptyChars(""));
- assertTrue(PolicyUtils.containsNonAsciiEmptyChars("T æST"));
- assertTrue(PolicyUtils.containsNonAsciiEmptyChars("TæST"));
- assertFalse(PolicyUtils.containsNonAsciiEmptyChars("TEST"));
- }
-
- @Test
- public void testInteger(){
- assertFalse(PolicyUtils.isInteger(null));
- assertTrue(PolicyUtils.isInteger("123"));
- assertFalse(PolicyUtils.isInteger("1a23"));
- }
-
- @Test
- public void testEmailAddress(){
- assertEquals(SUCCESS, PolicyUtils.validateEmailAddress("test@onap.org"));
- assertNotEquals(SUCCESS, PolicyUtils.validateEmailAddress("test@onap"));
- }
-
- @Test
- public void testBRMSValidate(){
- String rule = "package com.sample;\n"
- + "import com.sample.DroolsTest.Message;\n"
- + "declare Params\n"
- + "samPoll : int\n"
- + "value : String\n"
- + "end\n"
- + "///This Rule will be generated by the UI.\n"
- + "rule \"Create parameters structure\"\n"
- + "salience 1000 \n"
- + "when\n"
- + "then\n"
- + "Params params = new Params();\n"
- + "params.setSamPoll(76);\n"
- + "params.setValue(\"test\");\n"
- + "insertLogical(params);\n"
- + "end\n"
- + "rule \"Rule 1: Check parameter structure access from when/then\"\n"
- + "when\n"
- + "$param: Params()\n"
- + "Params($param.samPoll > 50)\n"
- + "then\n"
- + "System.out.println(\"Firing rule 1\");\n"
- + "System.out.println($param);\n"
- + "end\n";
- assertEquals(PolicyUtils.brmsRawValidate(rule),"");
- assertTrue(PolicyUtils.brmsRawValidate("error").contains("[ERR"));
- assertFalse(PolicyUtils.brmsRawValidate("package com.att.ecomp.policy.controlloop.p_${unique};").contains("[ERR"));
- }
-
- @Test
- public void testiIsJsonValid(){
- assertTrue(PolicyUtils.isJSONValid("{\"test\":\"test\"}"));
- String value = "{\"test\":\"test\", \"t1\": {\"test\": 12 , \"t2\":\"34\"},\"t2\":[{\"test\":\"val\"}]}";
- assertTrue(PolicyUtils.isJSONValid(value));
- assertFalse(PolicyUtils.isJSONValid("{\"test\":\"test"));
- }
-
- @Test
- public void testIsXMLValid() throws SAXException{
- XMLErrorHandler error = new XMLErrorHandler();
+
+ private static final String ERROR =
+ "The Value in Required Field will allow only '{0-9}, {a-z}, {A-Z}, _' following set of Combinations";
+ private static final String SUCCESS = "success";
+
+ @Test
+ public void testJsonConversions() throws Exception {
+ StdPDPNotification notification = new StdPDPNotification();
+ notification.setNotificationType(NotificationType.BOTH);
+ Collection<StdRemovedPolicy> removedPolicies = new ArrayList<>();
+ StdRemovedPolicy removedPolicy = new StdRemovedPolicy();
+ removedPolicy.setPolicyName("Test");
+ removedPolicy.setVersionNo("1");
+ removedPolicies.add(removedPolicy);
+ StdLoadedPolicy updatedPolicy = new StdLoadedPolicy();
+ updatedPolicy.setPolicyName("Testing");
+ updatedPolicy.setVersionNo("1");
+ updatedPolicy.setUpdateType(UpdateType.NEW);
+ Map<String, String> matches = new HashMap<>();
+ matches.put("key", "value");
+ updatedPolicy.setMatches(matches);
+ Collection<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
+ loadedPolicies.add(updatedPolicy);
+ notification.setRemovedPolicies(removedPolicies);
+ notification.setLoadedPolicies(loadedPolicies);
+
+ String json = PolicyUtils.objectToJsonString(notification);
+ PDPNotification getBackObject = PolicyUtils.jsonStringToObject(json, StdPDPNotification.class);
+ assertEquals(0, getBackObject.getNotificationType().compareTo(notification.getNotificationType()));
+
+ }
+
+ private String encodedValue(String input) {
+ return new String(Base64.getEncoder().encode(input.getBytes()));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ String value = "test";
+ assertEquals(value, PolicyUtils.decode(encodedValue(value)));
+ assertNull(PolicyUtils.decode(null));
+ assertNull(PolicyUtils.decode(""));
+ }
+
+ @Test
+ public void testBasicEncoding() throws Exception {
+ String userName = "test";
+ String key = "pass";
+ String[] decodedValue = PolicyUtils.decodeBasicEncoding("Basic " + encodedValue(userName + ":" + key));
+ assertEquals(userName, decodedValue[0]);
+ assertEquals(key, decodedValue[1]);
+ assertEquals(0, PolicyUtils.decodeBasicEncoding(encodedValue(userName + ":" + key)).length);
+ assertEquals(0, PolicyUtils.decodeBasicEncoding(null).length);
+ }
+
+ @Test
+ public void testSpecialCharValidator() {
+ assertEquals(ERROR, PolicyUtils.policySpecialCharValidator("$TEST_"));
+ assertEquals(ERROR, PolicyUtils.policySpecialCharValidator("$TEST _"));
+ assertEquals(ERROR, PolicyUtils.policySpecialCharValidator(""));
+ assertEquals(ERROR, PolicyUtils.policySpecialCharValidator("TæST"));
+ assertEquals(SUCCESS, PolicyUtils.policySpecialCharValidator("TEST"));
+ }
+
+ @Test
+ public void testSpecialCharWithSpaceValidator() {
+ assertEquals(ERROR, PolicyUtils.policySpecialCharWithSpaceValidator(""));
+ assertEquals(ERROR, PolicyUtils.policySpecialCharWithSpaceValidator("$TEST _"));
+ assertEquals(SUCCESS, PolicyUtils.policySpecialCharWithSpaceValidator("TE ST"));
+ }
+
+ @Test
+ public void testDescription() {
+ assertEquals(SUCCESS, PolicyUtils.descriptionValidator("Test"));
+ assertNotEquals(SUCCESS, PolicyUtils.descriptionValidator("@ModifiedBy:TesterB"));
+ assertNotEquals(SUCCESS, PolicyUtils.descriptionValidator("@CreatedBy:TesterA"));
+ }
+
+ @Test
+ public void testNonAscii() {
+ assertTrue(PolicyUtils.containsNonAsciiEmptyChars(null));
+ assertTrue(PolicyUtils.containsNonAsciiEmptyChars(""));
+ assertTrue(PolicyUtils.containsNonAsciiEmptyChars("T æST"));
+ assertTrue(PolicyUtils.containsNonAsciiEmptyChars("TæST"));
+ assertFalse(PolicyUtils.containsNonAsciiEmptyChars("TEST"));
+ }
+
+ @Test
+ public void testInteger() {
+ assertFalse(PolicyUtils.isInteger(null));
+ assertTrue(PolicyUtils.isInteger("123"));
+ assertFalse(PolicyUtils.isInteger("1a23"));
+ }
+
+ @Test
+ public void testEmailAddress() {
+ assertEquals(SUCCESS, PolicyUtils.validateEmailAddress("test@onap.org"));
+ assertNotEquals(SUCCESS, PolicyUtils.validateEmailAddress("test@onap"));
+ }
+
+ @Test
+ public void testBrmsValidate() {
+ String rule = "package com.sample;\n" + "import com.sample.DroolsTest.Message;\n" + "declare Params\n"
+ + "samPoll : int\n" + "value : String\n" + "end\n" + "///This Rule will be generated by the UI.\n"
+ + "rule \"Create parameters structure\"\n" + "salience 1000 \n" + "when\n" + "then\n"
+ + "Params params = new Params();\n" + "params.setSamPoll(76);\n" + "params.setValue(\"test\");\n"
+ + "insertLogical(params);\n" + "end\n"
+ + "rule \"Rule 1: Check parameter structure access from when/then\"\n" + "when\n" + "$param: Params()\n"
+ + "Params($param.samPoll > 50)\n" + "then\n" + "System.out.println(\"Firing rule 1\");\n"
+ + "System.out.println($param);\n" + "end\n";
+ assertEquals(PolicyUtils.brmsRawValidate(rule), "");
+ assertTrue(PolicyUtils.brmsRawValidate("error").contains("[ERR"));
+ assertFalse(
+ PolicyUtils.brmsRawValidate("package com.att.ecomp.policy.controlloop.p_${unique};").contains("[ERR"));
+ }
+
+ @Test
+ public void testiIsJsonValid() {
+ assertTrue(PolicyUtils.isJSONValid("{\"test\":\"test\"}"));
+ String value = "{\"test\":\"test\", \"t1\": {\"test\": 12 , \"t2\":\"34\"},\"t2\":[{\"test\":\"val\"}]}";
+ assertTrue(PolicyUtils.isJSONValid(value));
+ assertFalse(PolicyUtils.isJSONValid("{\"test\":\"test"));
+ }
+
+ @Test
+ public void testIsXmlValid() throws SAXException {
+ assertFalse(PolicyUtils.isXMLValid(null));
+ assertFalse(PolicyUtils.isXMLValid(""));
+ XMLErrorHandler error = new XMLErrorHandler();
error.error(new SAXParseException(null, null));
error.warning(new SAXParseException(null, null));
- assertTrue(PolicyUtils.isXMLValid("<test>123</test>"));
- assertFalse(PolicyUtils.isXMLValid("<test>123</test"));
- }
-
- @Test
- public void testIsPropValid(){
+ assertTrue(PolicyUtils.isXMLValid("<test>123</test>"));
+ assertFalse(PolicyUtils.isXMLValid("<test>123</test"));
+ }
+
+ @Test
+ public void testIsPropValid() {
assertTrue(PolicyUtils.isPropValid("test=123\n\tval=123"));
assertFalse(PolicyUtils.isPropValid("test"));
assertFalse(PolicyUtils.isPropValid("test="));
assertTrue(PolicyUtils.isPropValid("#test\n\nval=123"));
- }
-
- @Test
- public void testVersionStringToArray(){
- assertTrue(PolicyUtils.versionStringToArray(null).length==0);
- assertTrue(PolicyUtils.versionStringToArray("").length==0);
- assertTrue(PolicyUtils.versionStringToArray("1.2.3").length==3);
- }
-} \ No newline at end of file
+ }
+
+ @Test
+ public void testVersionStringToArray() {
+ assertTrue(PolicyUtils.versionStringToArray(null).length == 0);
+ assertTrue(PolicyUtils.versionStringToArray("").length == 0);
+ assertTrue(PolicyUtils.versionStringToArray("1.2.3").length == 3);
+ }
+
+ @Test
+ public void testSpecialChar() {
+ assertEquals(PolicyUtils.SUCCESS, PolicyUtils.policySpecialCharWithDashValidator("test"));
+ assertEquals(PolicyUtils.SUCCESS, PolicyUtils.policySpecialCharWithDashValidator("test-"));
+ assertEquals(PolicyUtils.SUCCESS, PolicyUtils.policySpecialCharWithDashValidator("test_"));
+ assertNotEquals(PolicyUtils.SUCCESS, PolicyUtils.policySpecialCharWithDashValidator(""));
+ assertNotEquals(PolicyUtils.SUCCESS, PolicyUtils.policySpecialCharWithDashValidator("test*"));
+ }
+}