From 771c3061226c7696b4ba272335f1e7297da428c3 Mon Sep 17 00:00:00 2001 From: Driptaroop Das Date: Sun, 20 Jan 2019 22:14:05 +0530 Subject: Junit file for coverage Junit file for coverage Files: RetryPolicyTest.java, AuthTypeTest.java, RestConfContextTest.java Issue-ID: DCAEGEN2-1083 Change-Id: I982d2602b15e71a8fe99e6b49c5900b0e268799b Signed-off-by: Driptaroop Das --- .../collectors/restconf/common/AuthTypeTest.java | 42 ++++++++++++++++ .../restconf/common/RestConfContextTest.java | 52 ++++++++++++++++++++ .../restconf/common/RetryPolicyTest.java | 57 ++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 src/test/java/org/onap/dcae/collectors/restconf/common/AuthTypeTest.java create mode 100644 src/test/java/org/onap/dcae/collectors/restconf/common/RestConfContextTest.java create mode 100644 src/test/java/org/onap/dcae/collectors/restconf/common/RetryPolicyTest.java diff --git a/src/test/java/org/onap/dcae/collectors/restconf/common/AuthTypeTest.java b/src/test/java/org/onap/dcae/collectors/restconf/common/AuthTypeTest.java new file mode 100644 index 0000000..8eaee6f --- /dev/null +++ b/src/test/java/org/onap/dcae/collectors/restconf/common/AuthTypeTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dcaegen2.collectors.restconf + * ================================================================================ + * Copyright (C) 2019 IBM. 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.dcae.collectors.restconf.common; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class AuthTypeTest { + + @Test + public void fromString() { + assertEquals(AuthType.BASIC, AuthType.fromString("basic")); + assertEquals(AuthType.DIGEST, AuthType.fromString("digest")); + assertEquals(AuthType.OAUTH, AuthType.fromString("oauth")); + assertEquals(AuthType.NONE, AuthType.fromString("none")); + assertEquals(AuthType.Unspecified, AuthType.fromString("unspecified")); + } + + @Test(expected = IllegalArgumentException.class) + public void fromStringWithException() { + AuthType.fromString("test"); + } +} \ No newline at end of file diff --git a/src/test/java/org/onap/dcae/collectors/restconf/common/RestConfContextTest.java b/src/test/java/org/onap/dcae/collectors/restconf/common/RestConfContextTest.java new file mode 100644 index 0000000..696c254 --- /dev/null +++ b/src/test/java/org/onap/dcae/collectors/restconf/common/RestConfContextTest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dcaegen2.collectors.restconf + * ================================================================================ + * Copyright (C) 2019 IBM. 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.dcae.collectors.restconf.common; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class RestConfContextTest { + + @Test + public void setAttribute() { + String key = "key"; + String value = "value"; + RestConfContext restConfContext = new RestConfContext(); + restConfContext.setAttribute(key, value); + assertEquals(value, restConfContext.getAttribute(key)); + restConfContext.setAttribute(key, null); + assertFalse(restConfContext.getAttributeKeySet().contains(key)); + } + + @Test + public void getAttributeKeySet() { + String key = "key"; + String value = "value"; + String key1 = "key1"; + String value1 = "value1"; + RestConfContext restConfContext = new RestConfContext(); + restConfContext.setAttribute(key,value); + restConfContext.setAttribute(key1,value1); + assertTrue(restConfContext.getAttributeKeySet().contains(key) && restConfContext.getAttributeKeySet().contains(key1)); + } +} \ No newline at end of file diff --git a/src/test/java/org/onap/dcae/collectors/restconf/common/RetryPolicyTest.java b/src/test/java/org/onap/dcae/collectors/restconf/common/RetryPolicyTest.java new file mode 100644 index 0000000..1b8cfcb --- /dev/null +++ b/src/test/java/org/onap/dcae/collectors/restconf/common/RetryPolicyTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dcaegen2.collectors.restconf + * ================================================================================ + * Copyright (C) 2019 IBM. 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.dcae.collectors.restconf.common; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class RetryPolicyTest { + + String[] hostnames; + Integer maximumRetries; + RetryPolicy retryPolicy; + + @Before + public void setUp() throws Exception { + hostnames = "test1.com,test2.com,test3.com,4.4.4.4".split(","); + maximumRetries = 3; + retryPolicy = new RetryPolicy(this.hostnames, this.maximumRetries); + } + + @Test + public void testGetMaximumRetries() { + assertEquals(maximumRetries, retryPolicy.getMaximumRetries()); + } + + @Test + public void testGetNextHostName() throws RetryException { + assertEquals(hostnames[2], retryPolicy.getNextHostName("http://" + hostnames[1] + "/endpoint")); + assertEquals(hostnames[0], retryPolicy.getNextHostName("http://" + hostnames[3] + "/endpoint")); + } + + @Test(expected = RetryException.class) + public void testGetNextHostNameWithException() throws RetryException { + retryPolicy.getNextHostName("abc"); + } +} \ No newline at end of file -- cgit 1.2.3-korg