diff options
author | 2019-01-20 22:14:05 +0530 | |
---|---|---|
committer | 2019-01-20 22:15:10 +0530 | |
commit | 771c3061226c7696b4ba272335f1e7297da428c3 (patch) | |
tree | b3984988fddbf5134156b24434fa5d7dd8a2fc47 /src/test/java/org | |
parent | 1fb99ede30dc9432c6fe69fa9c62bbb59d69cca5 (diff) |
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 <driptaroop.das@in.ibm.com>
Diffstat (limited to 'src/test/java/org')
3 files changed, 151 insertions, 0 deletions
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 |