From 538dc09c0210c9458565b4480af009a3fbb99f6d Mon Sep 17 00:00:00 2001 From: sg481n Date: Mon, 2 Oct 2017 13:40:28 +0000 Subject: Improve code coverage for aaf cadi modules. Issie-ID: AAF-79 Change-Id: I57c757a12997a81137a71c2ce131fb3ef934ec1f Signed-off-by: sg481n --- .../java/org/onap/aaf/cadi/CadiExceptionTest.java | 125 ---------------- .../org/onap/aaf/cadi/JU_CadiExceptionTest.java | 125 ++++++++++++++++ .../java/org/onap/aaf/cadi/JU_PropAccessTest.java | 88 +++++++++++ .../test/java/org/onap/aaf/cadi/JU_UserTest.java | 161 +++++++++++++++++++++ .../java/org/onap/aaf/cadi/PropAccessTest.java | 88 ----------- core/src/test/java/org/onap/aaf/cadi/UserTest.java | 161 --------------------- .../org/onap/aaf/cadi/lur/ConfigPrincipalTest.java | 78 ---------- .../onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java | 78 ++++++++++ .../org/onap/aaf/cadi/lur/test/JU_TestAccess.java | 91 ++++++++++++ .../org/onap/aaf/cadi/lur/test/TestAccess.java | 91 ------------ .../test/java/org/onap/aaf/cadi/test/JU_Test.java | 70 +++++++++ .../src/test/java/org/onap/aaf/cadi/test/Test.java | 70 --------- core/tempkey | 54 +++---- 13 files changed, 640 insertions(+), 640 deletions(-) delete mode 100644 core/src/test/java/org/onap/aaf/cadi/CadiExceptionTest.java create mode 100644 core/src/test/java/org/onap/aaf/cadi/JU_CadiExceptionTest.java create mode 100644 core/src/test/java/org/onap/aaf/cadi/JU_PropAccessTest.java create mode 100644 core/src/test/java/org/onap/aaf/cadi/JU_UserTest.java delete mode 100644 core/src/test/java/org/onap/aaf/cadi/PropAccessTest.java delete mode 100644 core/src/test/java/org/onap/aaf/cadi/UserTest.java delete mode 100644 core/src/test/java/org/onap/aaf/cadi/lur/ConfigPrincipalTest.java create mode 100644 core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java create mode 100644 core/src/test/java/org/onap/aaf/cadi/lur/test/JU_TestAccess.java delete mode 100644 core/src/test/java/org/onap/aaf/cadi/lur/test/TestAccess.java create mode 100644 core/src/test/java/org/onap/aaf/cadi/test/JU_Test.java delete mode 100644 core/src/test/java/org/onap/aaf/cadi/test/Test.java (limited to 'core') diff --git a/core/src/test/java/org/onap/aaf/cadi/CadiExceptionTest.java b/core/src/test/java/org/onap/aaf/cadi/CadiExceptionTest.java deleted file mode 100644 index f994b60..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/CadiExceptionTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 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==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package org.onap.aaf.cadi; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import org.junit.Test; - -public class CadiExceptionTest { - - @Test - public void testCadiException() { - CadiException exception = new CadiException(); - - assertNotNull(exception); - } - - @Test - public void testCadiExceptionString() { - CadiException exception = new CadiException("New Exception"); - assertNotNull(exception); - assertThat(exception.getMessage(), is("New Exception")); - } - - @Test - public void testCadiExceptionThrowable() { - CadiException exception = new CadiException(new Throwable("New Exception")); - assertNotNull(exception); - assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception")); - } - - @Test - public void testCadiExceptionStringThrowable() { - CadiException exception = new CadiException("New Exception",new Throwable("New Exception")); - assertNotNull(exception); - assertThat(exception.getMessage(), is("New Exception")); - - } - - @Test - public void testCadiException1() { - CadiException exception = new CadiException(); - - assertNotNull(exception); - } - - @Test - public void testCadiExceptionString1() { - CadiException exception = new CadiException("New Exception"); - assertNotNull(exception); - assertThat(exception.getMessage(), is("New Exception")); - } - - @Test - public void testCadiExceptionThrowable1() { - CadiException exception = new CadiException(new Throwable("New Exception")); - assertNotNull(exception); - assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception")); - } - - @Test - public void testCadiExceptionStringThrowable1() { - CadiException exception = new CadiException("New Exception",new Throwable("New Exception")); - assertNotNull(exception); - assertThat(exception.getMessage(), is("New Exception")); - - } - - @Test - public void testCadiException2() { - CadiException exception = new CadiException(); - - assertNotNull(exception); - } - - @Test - public void testCadiExceptionString2() { - CadiException exception = new CadiException("New Exception"); - assertNotNull(exception); - assertThat(exception.getMessage(), is("New Exception")); - } - - @Test - public void testCadiExceptionThrowable2() { - CadiException exception = new CadiException(new Throwable("New Exception")); - assertNotNull(exception); - assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception")); - } - - @Test - public void testCadiExceptionStringThrowable2() { - CadiException exception = new CadiException("New Exception",new Throwable("New Exception")); - assertNotNull(exception); - assertThat(exception.getMessage(), is("New Exception")); - - } - - - -} diff --git a/core/src/test/java/org/onap/aaf/cadi/JU_CadiExceptionTest.java b/core/src/test/java/org/onap/aaf/cadi/JU_CadiExceptionTest.java new file mode 100644 index 0000000..2eae209 --- /dev/null +++ b/core/src/test/java/org/onap/aaf/cadi/JU_CadiExceptionTest.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 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==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.cadi; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +import org.junit.Test; + +public class JU_CadiExceptionTest { + + @Test + public void testCadiException() { + CadiException exception = new CadiException(); + + assertNotNull(exception); + } + + @Test + public void testCadiExceptionString() { + CadiException exception = new CadiException("New Exception"); + assertNotNull(exception); + assertThat(exception.getMessage(), is("New Exception")); + } + + @Test + public void testCadiExceptionThrowable() { + CadiException exception = new CadiException(new Throwable("New Exception")); + assertNotNull(exception); + assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception")); + } + + @Test + public void testCadiExceptionStringThrowable() { + CadiException exception = new CadiException("New Exception",new Throwable("New Exception")); + assertNotNull(exception); + assertThat(exception.getMessage(), is("New Exception")); + + } + + @Test + public void testCadiException1() { + CadiException exception = new CadiException(); + + assertNotNull(exception); + } + + @Test + public void testCadiExceptionString1() { + CadiException exception = new CadiException("New Exception"); + assertNotNull(exception); + assertThat(exception.getMessage(), is("New Exception")); + } + + @Test + public void testCadiExceptionThrowable1() { + CadiException exception = new CadiException(new Throwable("New Exception")); + assertNotNull(exception); + assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception")); + } + + @Test + public void testCadiExceptionStringThrowable1() { + CadiException exception = new CadiException("New Exception",new Throwable("New Exception")); + assertNotNull(exception); + assertThat(exception.getMessage(), is("New Exception")); + + } + + @Test + public void testCadiException2() { + CadiException exception = new CadiException(); + + assertNotNull(exception); + } + + @Test + public void testCadiExceptionString2() { + CadiException exception = new CadiException("New Exception"); + assertNotNull(exception); + assertThat(exception.getMessage(), is("New Exception")); + } + + @Test + public void testCadiExceptionThrowable2() { + CadiException exception = new CadiException(new Throwable("New Exception")); + assertNotNull(exception); + assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception")); + } + + @Test + public void testCadiExceptionStringThrowable2() { + CadiException exception = new CadiException("New Exception",new Throwable("New Exception")); + assertNotNull(exception); + assertThat(exception.getMessage(), is("New Exception")); + + } + + + +} diff --git a/core/src/test/java/org/onap/aaf/cadi/JU_PropAccessTest.java b/core/src/test/java/org/onap/aaf/cadi/JU_PropAccessTest.java new file mode 100644 index 0000000..163058a --- /dev/null +++ b/core/src/test/java/org/onap/aaf/cadi/JU_PropAccessTest.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 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==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.cadi; + + +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 java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.onap.aaf.cadi.Access.Level; +import org.onap.aaf.cadi.config.Config; + +public class JU_PropAccessTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void testPropAccess() throws IOException { + PropAccess p = new PropAccess(new Object()); + + assertNotNull(p); + assertNotNull(p.getProperties()); + assertNull(p.getProperty("anything")); + + p.setProperty("prop", "value"); + assertEquals(p.getProperty("prop"), "value"); + + p.setProperty(Config.CADI_KEYFILE, "value"); + assertEquals(p.getProperty("prop"), "value"); + + p.setLogLevel(Level.INFO); + assertTrue(p.willLog(Level.INFO)); + p.log(Level.DEBUG, new Object()); + String[] args = {"key=value","wow=wow"}; + p = new PropAccess(args); + } + + @Test + public void testPropAccessone() throws IOException { + PropAccess p = new PropAccess(new Object()); + + assertNotNull(p); + assertNotNull(p.getProperties()); + assertNull(p.getProperty("everything")); + + p.setProperty("prop1", "value1"); + assertEquals(p.getProperty("prop1"), "value1"); + + p.setProperty(Config.CADI_KEYFILE, "value1"); + assertEquals(p.getProperty("prop1"), "value1"); + + p.setLogLevel(Level.INFO); + assertTrue(p.willLog(Level.INFO)); + p.log(Level.DEBUG, new Object()); + String[] args = {"key=value1","wow=wow1"}; + p = new PropAccess(args); + } + +} + diff --git a/core/src/test/java/org/onap/aaf/cadi/JU_UserTest.java b/core/src/test/java/org/onap/aaf/cadi/JU_UserTest.java new file mode 100644 index 0000000..be2becd --- /dev/null +++ b/core/src/test/java/org/onap/aaf/cadi/JU_UserTest.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 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==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.cadi; + +import static org.junit.Assert.*; + +import org.junit.Test; + + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aaf.cadi.lur.LocalPermission; + +public class JU_UserTest { + + @Mock + private Principal principal; + + @Mock + private LocalPermission permission; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + + when(principal.getName()).thenReturn("Principal"); + + when(permission.getKey()).thenReturn("NewKey"); + when(permission.match(permission)).thenReturn(true); + } + + @Test + public void testCountCheck() { + User user = new User(principal); + user.resetCount(); + assertThat(user.count, is(0)); + user.incCount(); + assertThat(user.count, is(1)); + } + + @Test + public void testCountCheck1() { + User user = new User(principal); + user.resetCount(); + assertThat(user.count, is(0)); + user.incCount(); + assertThat(user.count, is(1)); + } + + @Test + public void testPerm() throws InterruptedException { + User user = new User(principal); + assertThat(user.permExpires(), is(Long.MAX_VALUE)); + user.renewPerm(); + Thread.sleep(1); + assertThat(user.permExpired(), is(true)); + user = new User(principal,100); + assertTrue(user.noPerms()); + user.add(permission); + assertFalse(user.noPerms()); + user.setNoPerms(); + assertThat(user.permExpired(), is(false)); + assertFalse(user.permsUnloaded()); + user.perms = null; + assertTrue(user.permsUnloaded()); + assertTrue(user.noPerms()); + } + + @Test + public void testPerm1() throws InterruptedException { + User user = new User(principal); + assertThat(user.permExpires(), is(Long.MAX_VALUE)); + user.renewPerm(); + Thread.sleep(1); + assertThat(user.permExpired(), is(true)); + user = new User(principal,100); + assertTrue(user.noPerms()); + user.add(permission); + assertFalse(user.noPerms()); + user.setNoPerms(); + assertThat(user.permExpired(), is(false)); + assertFalse(user.permsUnloaded()); + user.perms = null; + assertTrue(user.permsUnloaded()); + assertTrue(user.noPerms()); + } + + @Test + public void testAddValuesToNewMap() { + User user = new User(principal); + Map newMap = new HashMap(); + + assertFalse(user.contains(permission)); + + user.add(newMap, permission); + user.setMap(newMap); + + assertTrue(user.contains(permission)); + + List sink = new ArrayList(); + user.copyPermsTo(sink); + + assertThat(sink.size(), is(1)); + assertTrue(sink.contains(permission)); + + assertThat(user.toString(), is("Principal|:NewKey")); + } + + @Test + public void testAddValuesToNewMap1() { + User user = new User(principal); + Map newMap = new HashMap(); + + assertFalse(user.contains(permission)); + + user.add(newMap, permission); + user.setMap(newMap); + + assertTrue(user.contains(permission)); + + List sink = new ArrayList(); + user.copyPermsTo(sink); + + assertThat(sink.size(), is(1)); + assertTrue(sink.contains(permission)); + + assertThat(user.toString(), is("Principal|:NewKey")); + } +} diff --git a/core/src/test/java/org/onap/aaf/cadi/PropAccessTest.java b/core/src/test/java/org/onap/aaf/cadi/PropAccessTest.java deleted file mode 100644 index 80e3134..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/PropAccessTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 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==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package org.onap.aaf.cadi; - - -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 java.io.IOException; - -import org.junit.Before; -import org.junit.Test; -import org.onap.aaf.cadi.Access.Level; -import org.onap.aaf.cadi.config.Config; - -public class PropAccessTest { - - @Before - public void setUp() throws Exception { - } - - @Test - public void testPropAccess() throws IOException { - PropAccess p = new PropAccess(new Object()); - - assertNotNull(p); - assertNotNull(p.getProperties()); - assertNull(p.getProperty("anything")); - - p.setProperty("prop", "value"); - assertEquals(p.getProperty("prop"), "value"); - - p.setProperty(Config.CADI_KEYFILE, "value"); - assertEquals(p.getProperty("prop"), "value"); - - p.setLogLevel(Level.INFO); - assertTrue(p.willLog(Level.INFO)); - p.log(Level.DEBUG, new Object()); - String[] args = {"key=value","wow=wow"}; - p = new PropAccess(args); - } - - @Test - public void testPropAccessone() throws IOException { - PropAccess p = new PropAccess(new Object()); - - assertNotNull(p); - assertNotNull(p.getProperties()); - assertNull(p.getProperty("everything")); - - p.setProperty("prop1", "value1"); - assertEquals(p.getProperty("prop1"), "value1"); - - p.setProperty(Config.CADI_KEYFILE, "value1"); - assertEquals(p.getProperty("prop1"), "value1"); - - p.setLogLevel(Level.INFO); - assertTrue(p.willLog(Level.INFO)); - p.log(Level.DEBUG, new Object()); - String[] args = {"key=value1","wow=wow1"}; - p = new PropAccess(args); - } - -} - diff --git a/core/src/test/java/org/onap/aaf/cadi/UserTest.java b/core/src/test/java/org/onap/aaf/cadi/UserTest.java deleted file mode 100644 index f5ea6fc..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/UserTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 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==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package org.onap.aaf.cadi; - -import static org.junit.Assert.*; - -import org.junit.Test; - - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -import java.security.Principal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.aaf.cadi.lur.LocalPermission; - -public class UserTest { - - @Mock - private Principal principal; - - @Mock - private LocalPermission permission; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - - when(principal.getName()).thenReturn("Principal"); - - when(permission.getKey()).thenReturn("NewKey"); - when(permission.match(permission)).thenReturn(true); - } - - @Test - public void testCountCheck() { - User user = new User(principal); - user.resetCount(); - assertThat(user.count, is(0)); - user.incCount(); - assertThat(user.count, is(1)); - } - - @Test - public void testCountCheck1() { - User user = new User(principal); - user.resetCount(); - assertThat(user.count, is(0)); - user.incCount(); - assertThat(user.count, is(1)); - } - - @Test - public void testPerm() throws InterruptedException { - User user = new User(principal); - assertThat(user.permExpires(), is(Long.MAX_VALUE)); - user.renewPerm(); - Thread.sleep(1); - assertThat(user.permExpired(), is(true)); - user = new User(principal,100); - assertTrue(user.noPerms()); - user.add(permission); - assertFalse(user.noPerms()); - user.setNoPerms(); - assertThat(user.permExpired(), is(false)); - assertFalse(user.permsUnloaded()); - user.perms = null; - assertTrue(user.permsUnloaded()); - assertTrue(user.noPerms()); - } - - @Test - public void testPerm1() throws InterruptedException { - User user = new User(principal); - assertThat(user.permExpires(), is(Long.MAX_VALUE)); - user.renewPerm(); - Thread.sleep(1); - assertThat(user.permExpired(), is(true)); - user = new User(principal,100); - assertTrue(user.noPerms()); - user.add(permission); - assertFalse(user.noPerms()); - user.setNoPerms(); - assertThat(user.permExpired(), is(false)); - assertFalse(user.permsUnloaded()); - user.perms = null; - assertTrue(user.permsUnloaded()); - assertTrue(user.noPerms()); - } - - @Test - public void testAddValuesToNewMap() { - User user = new User(principal); - Map newMap = new HashMap(); - - assertFalse(user.contains(permission)); - - user.add(newMap, permission); - user.setMap(newMap); - - assertTrue(user.contains(permission)); - - List sink = new ArrayList(); - user.copyPermsTo(sink); - - assertThat(sink.size(), is(1)); - assertTrue(sink.contains(permission)); - - assertThat(user.toString(), is("Principal|:NewKey")); - } - - @Test - public void testAddValuesToNewMap1() { - User user = new User(principal); - Map newMap = new HashMap(); - - assertFalse(user.contains(permission)); - - user.add(newMap, permission); - user.setMap(newMap); - - assertTrue(user.contains(permission)); - - List sink = new ArrayList(); - user.copyPermsTo(sink); - - assertThat(sink.size(), is(1)); - assertTrue(sink.contains(permission)); - - assertThat(user.toString(), is("Principal|:NewKey")); - } -} diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/ConfigPrincipalTest.java b/core/src/test/java/org/onap/aaf/cadi/lur/ConfigPrincipalTest.java deleted file mode 100644 index 174686a..0000000 --- a/core/src/test/java/org/onap/aaf/cadi/lur/ConfigPrincipalTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 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==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package org.onap.aaf.cadi.lur; - -import static org.junit.Assert.*; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -public class ConfigPrincipalTest { - - @Before - public void setUp() throws Exception { - } - - @Test - public void testConfigPrincipalStringString() { - ConfigPrincipal p = new ConfigPrincipal("User", "pass"); - - assertEquals(p.getName(), "User"); - assertEquals(p.toString(), "User"); - - } - - @Test - public void testConfigPrincipalStringByteArray() throws IOException { - byte[] bytes = "pass".getBytes(); - ConfigPrincipal p = new ConfigPrincipal("User", bytes); - - assertEquals(p.getName(), "User"); - assertEquals(p.getCred(), bytes); - assertEquals(p.toString(), "User"); - assertTrue(p.getAsBasicAuthHeader().startsWith("Basic")); - } - - @Test - public void testConfigPrincipalStringString1() { - ConfigPrincipal p = new ConfigPrincipal("Demo", "password"); - - assertEquals(p.getName(), "Demo"); - assertEquals(p.toString(), "Demo"); - - } - - @Test - public void testConfigPrincipalStringByteArray1() throws IOException { - byte[] bytes = "password".getBytes(); - ConfigPrincipal p = new ConfigPrincipal("Demo", bytes); - - assertEquals(p.getName(), "Demo"); - assertEquals(p.getCred(), bytes); - assertEquals(p.toString(), "Demo"); - assertTrue(p.getAsBasicAuthHeader().startsWith("Basic")); - } - -} diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java b/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java new file mode 100644 index 0000000..ade9a55 --- /dev/null +++ b/core/src/test/java/org/onap/aaf/cadi/lur/JU_ConfigPrincipalTest.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 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==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.cadi.lur; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +public class JU_ConfigPrincipalTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void testConfigPrincipalStringString() { + ConfigPrincipal p = new ConfigPrincipal("User", "pass"); + + assertEquals(p.getName(), "User"); + assertEquals(p.toString(), "User"); + + } + + @Test + public void testConfigPrincipalStringByteArray() throws IOException { + byte[] bytes = "pass".getBytes(); + ConfigPrincipal p = new ConfigPrincipal("User", bytes); + + assertEquals(p.getName(), "User"); + assertEquals(p.getCred(), bytes); + assertEquals(p.toString(), "User"); + assertTrue(p.getAsBasicAuthHeader().startsWith("Basic")); + } + + @Test + public void testConfigPrincipalStringString1() { + ConfigPrincipal p = new ConfigPrincipal("Demo", "password"); + + assertEquals(p.getName(), "Demo"); + assertEquals(p.toString(), "Demo"); + + } + + @Test + public void testConfigPrincipalStringByteArray1() throws IOException { + byte[] bytes = "password".getBytes(); + ConfigPrincipal p = new ConfigPrincipal("Demo", bytes); + + assertEquals(p.getName(), "Demo"); + assertEquals(p.getCred(), bytes); + assertEquals(p.toString(), "Demo"); + assertTrue(p.getAsBasicAuthHeader().startsWith("Basic")); + } + +} diff --git a/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_TestAccess.java b/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_TestAccess.java new file mode 100644 index 0000000..1bdf765 --- /dev/null +++ b/core/src/test/java/org/onap/aaf/cadi/lur/test/JU_TestAccess.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 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==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.cadi.lur.test; + +import java.io.IOException; +import java.io.InputStream; + +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Symm; + +public class JU_TestAccess implements Access { + private Symm symm; + + public JU_TestAccess() { + symm = Symm.obtain(this); + } + + public JU_TestAccess(Symm symmetric) { + symm = symmetric; + } + + public void log(Level level, Object... elements) { + boolean first = true; + for(int i=0;i