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 --- .../com/onap/aaf/cadi/aaf/AAFPermissionTest.java | 211 ----------- .../com/onap/aaf/cadi/aaf/AAFTransmutateTest.java | 118 ------ .../onap/aaf/cadi/aaf/JU_AAFPermissionTest.java | 211 +++++++++++ .../onap/aaf/cadi/aaf/JU_AAFTransmutateTest.java | 118 ++++++ .../aaf/cadi/aaf/marshal/CertsMarshalTest.java | 54 --- .../aaf/cadi/aaf/marshal/JU_CertsMarshalTest.java | 54 +++ .../org/onap/aaf/cadi/aaf/v2_0/AAFAuthnTest.java | 155 -------- .../onap/aaf/cadi/aaf/v2_0/JU_AAFAuthnTest.java | 155 ++++++++ .../cadi/lur/aaf/test/JU_MultiThreadPermHit.java | 145 ++++++++ .../onap/aaf/cadi/lur/aaf/test/JU_TestAccess.java | 122 +++++++ .../aaf/cadi/lur/aaf/test/MultiThreadPermHit.java | 145 -------- .../org/onap/aaf/cadi/lur/aaf/test/TestAccess.java | 122 ------- .../test/java/org/onap/aaf/example/CadiTest.java | 58 --- .../org/onap/aaf/example/ExampleAuthCheck.java | 57 --- .../java/org/onap/aaf/example/ExamplePerm2_0.java | 113 ------ .../org/onap/aaf/example/ExamplePerm2_0_DME2.java | 113 ------ .../java/org/onap/aaf/example/JU_CadiTest.java | 58 +++ .../org/onap/aaf/example/JU_ExampleAuthCheck.java | 57 +++ .../org/onap/aaf/example/JU_ExamplePerm2_0.java | 113 ++++++ .../onap/aaf/example/JU_ExamplePerm2_0_DME2.java | 113 ++++++ .../java/org/onap/aaf/example/JU_X509Test.java | 89 +++++ .../test/java/org/onap/aaf/example/X509Test.java | 89 ----- .../onap/aaf/cass/AAFAuthenticatedUserTest.java | 247 ------------- .../org/onap/aaf/cass/AAFAuthenticatorTest.java | 292 --------------- .../java/org/onap/aaf/cass/AAFAuthorizerTest.java | 378 ------------------- .../test/java/org/onap/aaf/cass/AAFBaseTest.java | 399 --------------------- .../onap/aaf/cass/JU_AAFAuthenticatedUserTest.java | 247 +++++++++++++ .../org/onap/aaf/cass/JU_AAFAuthorizerTest.java | 378 +++++++++++++++++++ .../java/org/onap/aaf/cass/JU_AAFBaseTest.java | 399 +++++++++++++++++++++ .../org/onap/aaf/cadi/dme2/DME2ClientSSTest.java | 55 --- .../onap/aaf/cadi/dme2/JU_DME2ClientSSTest.java | 55 +++ .../org/onap/aaf/cadi/http/HBasicAuthSSTest.java | 58 --- .../onap/aaf/cadi/http/JU_HBasicAuthSSTest.java | 58 +++ .../org/onap/aaf/client/test/BasicDME2Client.java | 61 ---- .../java/org/onap/aaf/client/test/HolderTest.java | 80 ----- .../onap/aaf/client/test/JU_BasicDME2Client.java | 61 ++++ .../org/onap/aaf/client/test/JU_HolderTest.java | 80 +++++ .../java/org/onap/aaf/client/test/JU_PaulUzee.java | 146 ++++++++ .../org/onap/aaf/client/test/JU_ResultTest.java | 109 ++++++ .../org/onap/aaf/client/test/JU_TestAccess.java | 90 +++++ .../onap/aaf/client/test/JU_TestDME2Client.java | 98 +++++ .../aaf/client/test/JU_TestDME2RcliClient.java | 79 ++++ .../org/onap/aaf/client/test/JU_TestHClient.java | 84 +++++ .../java/org/onap/aaf/client/test/PaulUzee.java | 146 -------- .../java/org/onap/aaf/client/test/ResultTest.java | 109 ------ .../java/org/onap/aaf/client/test/TestAccess.java | 90 ----- .../org/onap/aaf/client/test/TestDME2Client.java | 98 ----- .../onap/aaf/client/test/TestDME2RcliClient.java | 79 ---- .../java/org/onap/aaf/client/test/TestHClient.java | 84 ----- .../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 +-- 62 files changed, 3759 insertions(+), 4051 deletions(-) delete mode 100644 aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFPermissionTest.java delete mode 100644 aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFTransmutateTest.java create mode 100644 aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFPermissionTest.java create mode 100644 aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFTransmutateTest.java delete mode 100644 aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/CertsMarshalTest.java create mode 100644 aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/JU_CertsMarshalTest.java delete mode 100644 aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/AAFAuthnTest.java create mode 100644 aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFAuthnTest.java create mode 100644 aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_MultiThreadPermHit.java create mode 100644 aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_TestAccess.java delete mode 100644 aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/MultiThreadPermHit.java delete mode 100644 aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/TestAccess.java delete mode 100644 aaf/src/test/java/org/onap/aaf/example/CadiTest.java delete mode 100644 aaf/src/test/java/org/onap/aaf/example/ExampleAuthCheck.java delete mode 100644 aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0.java delete mode 100644 aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0_DME2.java create mode 100644 aaf/src/test/java/org/onap/aaf/example/JU_CadiTest.java create mode 100644 aaf/src/test/java/org/onap/aaf/example/JU_ExampleAuthCheck.java create mode 100644 aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0.java create mode 100644 aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0_DME2.java create mode 100644 aaf/src/test/java/org/onap/aaf/example/JU_X509Test.java delete mode 100644 aaf/src/test/java/org/onap/aaf/example/X509Test.java delete mode 100644 cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatedUserTest.java delete mode 100644 cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatorTest.java delete mode 100644 cass/src/test/java/org/onap/aaf/cass/AAFAuthorizerTest.java delete mode 100644 cass/src/test/java/org/onap/aaf/cass/AAFBaseTest.java create mode 100644 cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthenticatedUserTest.java create mode 100644 cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthorizerTest.java create mode 100644 cass/src/test/java/org/onap/aaf/cass/JU_AAFBaseTest.java delete mode 100644 client/src/test/java/org/onap/aaf/cadi/dme2/DME2ClientSSTest.java create mode 100644 client/src/test/java/org/onap/aaf/cadi/dme2/JU_DME2ClientSSTest.java delete mode 100644 client/src/test/java/org/onap/aaf/cadi/http/HBasicAuthSSTest.java create mode 100644 client/src/test/java/org/onap/aaf/cadi/http/JU_HBasicAuthSSTest.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/BasicDME2Client.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/HolderTest.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_BasicDME2Client.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_HolderTest.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_PaulUzee.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_ResultTest.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_TestAccess.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_TestDME2Client.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_TestDME2RcliClient.java create mode 100644 client/src/test/java/org/onap/aaf/client/test/JU_TestHClient.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/PaulUzee.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/ResultTest.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/TestAccess.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/TestDME2Client.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/TestDME2RcliClient.java delete mode 100644 client/src/test/java/org/onap/aaf/client/test/TestHClient.java 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 diff --git a/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFPermissionTest.java b/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFPermissionTest.java deleted file mode 100644 index f4ca955..0000000 --- a/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFPermissionTest.java +++ /dev/null @@ -1,211 +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 com.onap.aaf.cadi.aaf; -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 org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.aaf.cadi.aaf.AAFPermission; -import org.onap.aaf.cadi.lur.LocalPermission; - -public class AAFPermissionTest { - - private static final String INSTANCE = "*"; - private static final String ACTION = "*"; - private static final String TYPE = "Auth"; - private static final String KEY =TYPE + '|' + INSTANCE + '|' + ACTION; - - private String STRINGVALUE = - "AAFPermission:\n\tType: " + TYPE + - "\n\tInstance: " + INSTANCE + - "\n\tAction: " + ACTION + - "\n\tKey: " + KEY; - - @Mock - private LocalPermission localPermission; - - @Mock - private LocalPermission localPermission2; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - when(localPermission.getKey()).thenReturn(TYPE); - when(localPermission2.getKey()).thenReturn(TYPE+" Default"); - } - - @Test - public void test() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } - - @Test - public void test4() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } - - @Test - public void test1() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } - - @Test - public void test2() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } - - - @Test - public void test3() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } - - @Test - public void test5() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } - - @Test - public void test6() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } - - @Test - public void test7() { - AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); - - assertTrue("This should Match",permission.match(permission)); - - assertTrue("This should Match", permission.match(localPermission)); - - assertFalse("This should Not Match", permission.match(localPermission2)); - - assertThat(permission.getKey(), is(KEY)); - - assertThat(permission.permType(), is("AAF")); - - assertThat(permission.toString(), is(STRINGVALUE)); - - } -} diff --git a/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFTransmutateTest.java b/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFTransmutateTest.java deleted file mode 100644 index c143d2e..0000000 --- a/aaf/src/test/java/com/onap/aaf/cadi/aaf/AAFTransmutateTest.java +++ /dev/null @@ -1,118 +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 com.onap.aaf.cadi.aaf; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.security.Principal; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.aaf.cadi.aaf.AAFTransmutate; -import org.onap.aaf.cadi.lur.ConfigPrincipal; -import org.onap.aaf.cadi.principal.BasicPrincipal; - -public class AAFTransmutateTest { - - @Mock - Principal principal ; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - when(principal.getName()).thenReturn("Value"); - } - - @Test - public void testMutate() throws IOException { - BasicPrincipal p = new BasicPrincipal("content", "domain"); - AAFTransmutate transmutate = new AAFTransmutate(); -// assertNotNull(transmutate.mutate(p)); - - ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); -// assertNotNull(transmutate.mutate(cp)); - - assertNull(transmutate.mutate(principal)); - } - - - @Test - public void testMutate4() throws IOException { - BasicPrincipal p = new BasicPrincipal("content", "domain"); - AAFTransmutate transmutate = new AAFTransmutate(); -// assertNotNull(transmutate.mutate(p)); - - ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); -// assertNotNull(transmutate.mutate(cp)); - - assertNull(transmutate.mutate(principal)); - } - - - @Test - public void testMutate1() throws IOException { - BasicPrincipal p = new BasicPrincipal("content", "domain"); - AAFTransmutate transmutate = new AAFTransmutate(); -// assertNotNull(transmutate.mutate(p)); - - ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); -// assertNotNull(transmutate.mutate(cp)); - - assertNull(transmutate.mutate(principal)); - } - - - @Test - public void testMutate2() throws IOException { - BasicPrincipal p = new BasicPrincipal("content", "domain"); - AAFTransmutate transmutate = new AAFTransmutate(); -// assertNotNull(transmutate.mutate(p)); - - ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); -// assertNotNull(transmutate.mutate(cp)); - - assertNull(transmutate.mutate(principal)); - } - - - @Test - public void testMutate3() throws IOException { - BasicPrincipal p = new BasicPrincipal("content", "domain"); - AAFTransmutate transmutate = new AAFTransmutate(); -// assertNotNull(transmutate.mutate(p)); - - ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); -// assertNotNull(transmutate.mutate(cp)); - - assertNull(transmutate.mutate(principal)); - } - -} diff --git a/aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFPermissionTest.java b/aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFPermissionTest.java new file mode 100644 index 0000000..a809a0d --- /dev/null +++ b/aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFPermissionTest.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * ============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 com.onap.aaf.cadi.aaf; +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 org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.lur.LocalPermission; + +public class JU_AAFPermissionTest { + + private static final String INSTANCE = "*"; + private static final String ACTION = "*"; + private static final String TYPE = "Auth"; + private static final String KEY =TYPE + '|' + INSTANCE + '|' + ACTION; + + private String STRINGVALUE = + "AAFPermission:\n\tType: " + TYPE + + "\n\tInstance: " + INSTANCE + + "\n\tAction: " + ACTION + + "\n\tKey: " + KEY; + + @Mock + private LocalPermission localPermission; + + @Mock + private LocalPermission localPermission2; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + when(localPermission.getKey()).thenReturn(TYPE); + when(localPermission2.getKey()).thenReturn(TYPE+" Default"); + } + + @Test + public void test() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } + + @Test + public void test4() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } + + @Test + public void test1() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } + + @Test + public void test2() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } + + + @Test + public void test3() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } + + @Test + public void test5() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } + + @Test + public void test6() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } + + @Test + public void test7() { + AAFPermission permission = new AAFPermission(TYPE, INSTANCE, ACTION); + + assertTrue("This should Match",permission.match(permission)); + + assertTrue("This should Match", permission.match(localPermission)); + + assertFalse("This should Not Match", permission.match(localPermission2)); + + assertThat(permission.getKey(), is(KEY)); + + assertThat(permission.permType(), is("AAF")); + + assertThat(permission.toString(), is(STRINGVALUE)); + + } +} diff --git a/aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFTransmutateTest.java b/aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFTransmutateTest.java new file mode 100644 index 0000000..5b0df09 --- /dev/null +++ b/aaf/src/test/java/com/onap/aaf/cadi/aaf/JU_AAFTransmutateTest.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * ============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 com.onap.aaf.cadi.aaf; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.security.Principal; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aaf.cadi.aaf.AAFTransmutate; +import org.onap.aaf.cadi.lur.ConfigPrincipal; +import org.onap.aaf.cadi.principal.BasicPrincipal; + +public class JU_AAFTransmutateTest { + + @Mock + Principal principal ; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + when(principal.getName()).thenReturn("Value"); + } + + @Test + public void testMutate() throws IOException { + BasicPrincipal p = new BasicPrincipal("content", "domain"); + AAFTransmutate transmutate = new AAFTransmutate(); +// assertNotNull(transmutate.mutate(p)); + + ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); +// assertNotNull(transmutate.mutate(cp)); + + assertNull(transmutate.mutate(principal)); + } + + + @Test + public void testMutate4() throws IOException { + BasicPrincipal p = new BasicPrincipal("content", "domain"); + AAFTransmutate transmutate = new AAFTransmutate(); +// assertNotNull(transmutate.mutate(p)); + + ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); +// assertNotNull(transmutate.mutate(cp)); + + assertNull(transmutate.mutate(principal)); + } + + + @Test + public void testMutate1() throws IOException { + BasicPrincipal p = new BasicPrincipal("content", "domain"); + AAFTransmutate transmutate = new AAFTransmutate(); +// assertNotNull(transmutate.mutate(p)); + + ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); +// assertNotNull(transmutate.mutate(cp)); + + assertNull(transmutate.mutate(principal)); + } + + + @Test + public void testMutate2() throws IOException { + BasicPrincipal p = new BasicPrincipal("content", "domain"); + AAFTransmutate transmutate = new AAFTransmutate(); +// assertNotNull(transmutate.mutate(p)); + + ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); +// assertNotNull(transmutate.mutate(cp)); + + assertNull(transmutate.mutate(principal)); + } + + + @Test + public void testMutate3() throws IOException { + BasicPrincipal p = new BasicPrincipal("content", "domain"); + AAFTransmutate transmutate = new AAFTransmutate(); +// assertNotNull(transmutate.mutate(p)); + + ConfigPrincipal cp = new ConfigPrincipal("content", "cred"); +// assertNotNull(transmutate.mutate(cp)); + + assertNull(transmutate.mutate(principal)); + } + +} diff --git a/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/CertsMarshalTest.java b/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/CertsMarshalTest.java deleted file mode 100644 index 53067ad..0000000 --- a/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/CertsMarshalTest.java +++ /dev/null @@ -1,54 +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.aaf.marshal; -import static org.junit.Assert.*; - -import org.junit.Test; - - - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.aaf.rosetta.ParseException; - -public class CertsMarshalTest { - - @Test - public void test() throws ParseException { - CertsMarshal marshal = new CertsMarshal(); - assertNotNull(marshal); - } - - @Test - public void test2() throws ParseException { - CertsMarshal marshal = new CertsMarshal(); - assertNotNull(marshal); - } - - @Test - public void test3() throws ParseException { - CertsMarshal marshal = new CertsMarshal(); - assertNotNull(marshal); - } -} diff --git a/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/JU_CertsMarshalTest.java b/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/JU_CertsMarshalTest.java new file mode 100644 index 0000000..a3c12d3 --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/cadi/aaf/marshal/JU_CertsMarshalTest.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============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.aaf.marshal; +import static org.junit.Assert.*; + +import org.junit.Test; + + + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.aaf.rosetta.ParseException; + +public class JU_CertsMarshalTest { + + @Test + public void test() throws ParseException { + CertsMarshal marshal = new CertsMarshal(); + assertNotNull(marshal); + } + + @Test + public void test2() throws ParseException { + CertsMarshal marshal = new CertsMarshal(); + assertNotNull(marshal); + } + + @Test + public void test3() throws ParseException { + CertsMarshal marshal = new CertsMarshal(); + assertNotNull(marshal); + } +} diff --git a/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/AAFAuthnTest.java b/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/AAFAuthnTest.java deleted file mode 100644 index 961418c..0000000 --- a/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/AAFAuthnTest.java +++ /dev/null @@ -1,155 +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.aaf.v2_0; -import static org.junit.Assert.*; - -import org.junit.Test; - - - -import static org.junit.Assert.*; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Mockito.when; - - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Answers; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.aaf.cadi.AbsUserCache; -import org.onap.aaf.cadi.CadiException; -import org.onap.aaf.cadi.aaf.AAFPermission; -import org.onap.aaf.cadi.client.Future; -import org.onap.aaf.inno.env.APIException; - -import com.att.aft.dme2.internal.jersey.api.client.Client; - -public class AAFAuthnTest { - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private AAFCon con; - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Future fp; - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private AbsUserCache cache; - - - @Before - public void setup() throws APIException, CadiException { - MockitoAnnotations.initMocks(this); - when(con.client(AAFCon.AAF_LATEST_VERSION).read("/authn/basicAuth", "text/plain")).thenReturn(fp); - } - - @Test - public void testAAFAuthnAAFConOfCLIENT() throws Exception { - when(fp.get(anyInt())).thenReturn(false); - when(fp.code()).thenReturn(401); - when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); - AAFAuthn auth = new AAFAuthn(con); - - assertNotNull(auth.validate("NewUser", "New Password"));; - } - - @Test - public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission() throws Exception { - AAFAuthn auth = new AAFAuthn(con,cache); - } - - @Test - public void testAAFAuthnAAFConOfCLIENT1() throws Exception { - when(fp.get(anyInt())).thenReturn(false); - when(fp.code()).thenReturn(401); - when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); - AAFAuthn auth = new AAFAuthn(con); - - assertNotNull(auth.validate("NewUser1", "New Password1"));; - } - - @Test - public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission1() throws Exception { - AAFAuthn auth = new AAFAuthn(con,cache); - } - - @Test - public void testAAFAuthnAAFConOfCLIENT2() throws Exception { - when(fp.get(anyInt())).thenReturn(false); - when(fp.code()).thenReturn(401); - when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); - AAFAuthn auth = new AAFAuthn(con); - - assertNotNull(auth.validate("NewUser2", "New Password2"));; - } - - @Test - public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission2() throws Exception { - AAFAuthn auth = new AAFAuthn(con,cache); - } - - @Test - public void testAAFAuthnAAFConOfCLIENT3() throws Exception { - when(fp.get(anyInt())).thenReturn(false); - when(fp.code()).thenReturn(401); - when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); - AAFAuthn auth = new AAFAuthn(con); - - assertNotNull(auth.validate("NewUser3", "New Password3"));; - } - - @Test - public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission3() throws Exception { - AAFAuthn auth = new AAFAuthn(con,cache); - } - - @Test - public void testAAFAuthnAAFConOfCLIENT4() throws Exception { - when(fp.get(anyInt())).thenReturn(false); - when(fp.code()).thenReturn(401); - when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); - AAFAuthn auth = new AAFAuthn(con); - - assertNotNull(auth.validate("NewUser4", "New Password4"));; - } - - @Test - public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission4() throws Exception { - AAFAuthn auth = new AAFAuthn(con,cache); - } - - @Test - public void testAAFAuthnAAFConOfCLIENT5() throws Exception { - when(fp.get(anyInt())).thenReturn(false); - when(fp.code()).thenReturn(401); - when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); - AAFAuthn auth = new AAFAuthn(con); - - assertNotNull(auth.validate("NewUser5", "New Password5"));; - } - - @Test - public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission5() throws Exception { - AAFAuthn auth = new AAFAuthn(con,cache); - } -} diff --git a/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFAuthnTest.java b/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFAuthnTest.java new file mode 100644 index 0000000..9d95a6e --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/JU_AAFAuthnTest.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * ============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.aaf.v2_0; +import static org.junit.Assert.*; + +import org.junit.Test; + + + +import static org.junit.Assert.*; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.when; + + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aaf.cadi.AbsUserCache; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.client.Future; +import org.onap.aaf.inno.env.APIException; + +import com.att.aft.dme2.internal.jersey.api.client.Client; + +public class JU_AAFAuthnTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private AAFCon con; + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Future fp; + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private AbsUserCache cache; + + + @Before + public void setup() throws APIException, CadiException { + MockitoAnnotations.initMocks(this); + when(con.client(AAFCon.AAF_LATEST_VERSION).read("/authn/basicAuth", "text/plain")).thenReturn(fp); + } + + @Test + public void testAAFAuthnAAFConOfCLIENT() throws Exception { + when(fp.get(anyInt())).thenReturn(false); + when(fp.code()).thenReturn(401); + when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); + AAFAuthn auth = new AAFAuthn(con); + + assertNotNull(auth.validate("NewUser", "New Password"));; + } + + @Test + public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission() throws Exception { + AAFAuthn auth = new AAFAuthn(con,cache); + } + + @Test + public void testAAFAuthnAAFConOfCLIENT1() throws Exception { + when(fp.get(anyInt())).thenReturn(false); + when(fp.code()).thenReturn(401); + when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); + AAFAuthn auth = new AAFAuthn(con); + + assertNotNull(auth.validate("NewUser1", "New Password1"));; + } + + @Test + public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission1() throws Exception { + AAFAuthn auth = new AAFAuthn(con,cache); + } + + @Test + public void testAAFAuthnAAFConOfCLIENT2() throws Exception { + when(fp.get(anyInt())).thenReturn(false); + when(fp.code()).thenReturn(401); + when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); + AAFAuthn auth = new AAFAuthn(con); + + assertNotNull(auth.validate("NewUser2", "New Password2"));; + } + + @Test + public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission2() throws Exception { + AAFAuthn auth = new AAFAuthn(con,cache); + } + + @Test + public void testAAFAuthnAAFConOfCLIENT3() throws Exception { + when(fp.get(anyInt())).thenReturn(false); + when(fp.code()).thenReturn(401); + when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); + AAFAuthn auth = new AAFAuthn(con); + + assertNotNull(auth.validate("NewUser3", "New Password3"));; + } + + @Test + public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission3() throws Exception { + AAFAuthn auth = new AAFAuthn(con,cache); + } + + @Test + public void testAAFAuthnAAFConOfCLIENT4() throws Exception { + when(fp.get(anyInt())).thenReturn(false); + when(fp.code()).thenReturn(401); + when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); + AAFAuthn auth = new AAFAuthn(con); + + assertNotNull(auth.validate("NewUser4", "New Password4"));; + } + + @Test + public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission4() throws Exception { + AAFAuthn auth = new AAFAuthn(con,cache); + } + + @Test + public void testAAFAuthnAAFConOfCLIENT5() throws Exception { + when(fp.get(anyInt())).thenReturn(false); + when(fp.code()).thenReturn(401); + when(fp.header("WWW-Authenticate")).thenReturn("Basic realm=\"Value\""); + AAFAuthn auth = new AAFAuthn(con); + + assertNotNull(auth.validate("NewUser5", "New Password5"));; + } + + @Test + public void testAAFAuthnAAFConOfCLIENTAbsUserCacheOfAAFPermission5() throws Exception { + AAFAuthn auth = new AAFAuthn(con,cache); + } +} diff --git a/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_MultiThreadPermHit.java b/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_MultiThreadPermHit.java new file mode 100644 index 0000000..3779b4f --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_MultiThreadPermHit.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * ============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.aaf.test; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.List; + +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Permission; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; +import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; +import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; +import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.locator.PropertyLocator; + +public class JU_MultiThreadPermHit { + public static void main(String args[]) { + // Link or reuse to your Logging mechanism + PropAccess myAccess = new PropAccess(); // + + // + try { + AAFConHttp con = new AAFConHttp(myAccess,new PropertyLocator("https://mithrilcsp.sbc.com:8100")); + + // AAFLur has pool of DME clients as needed, and Caches Client lookups + final AAFLurPerm aafLur = con.newLur(); + aafLur.setDebug("m12345@aaf.att.com"); + + // Note: If you need both Authn and Authz construct the following: + AAFAuthn aafAuthn = con.newAuthn(aafLur); + + // Do not set Mech ID until after you construct AAFAuthn, + // because we initiate "401" info to determine the Realm of + // of the service we're after. + final String id = myAccess.getProperty(Config.AAF_MECHID,null); + final String pass = myAccess.decrypt(myAccess.getProperty(Config.AAF_MECHPASS,null),false); + if(id!=null && pass!=null) { + try { + + // Normally, you obtain Principal from Authentication System. + // // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() + // // If you use CADI as Authenticator, it will get you these Principals from + // // CSP or BasicAuth mechanisms. + // String id = "cluster_admin@gridcore.att.com"; + // + // // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. + String ok; + ok = aafAuthn.validate(id, pass); + if(ok!=null) { + System.out.println(ok); + } + + List pond = new ArrayList(); + for(int i=0;i<20;++i) { + pond.clear(); + aafLur.fishAll(i+id, pond); + if(ok!=null && i%1000==0) { + System.out.println(i + " " + ok); + } + } + + for(int i=0;i<1000000;++i) { + ok = aafAuthn.validate( i+ id, "wrongPass"); + if(ok!=null && i%1000==0) { + System.out.println(i + " " + ok); + } + } + + final AAFPermission perm = new AAFPermission("com.att.aaf.access","*","*"); + + // Now you can ask the LUR (Local Representative of the User Repository about Authorization + // With CADI, in J2EE, you can call isUserInRole("com.att.mygroup|mytype|write") on the Request Object + // instead of creating your own LUR + for(int i=0;i<4;++i) { + if(aafLur.fish(id, perm)) { + System.out.println("Yes, " + id + " has permission for " + perm.getKey()); + } else { + System.out.println("No, " + id + " does not have permission for " + perm.getKey()); + } + } + + + // Or you can all for all the Permissions available + List perms = new ArrayList(); + + + aafLur.fishAll(id,perms); + System.out.println("Perms for " + id); + for(Permission prm : perms) { + System.out.println(prm.getKey()); + } + + System.out.println("Press any key to continue"); + System.in.read(); + + for(int j=0;j<5;++j) { + new Thread(new Runnable() { + @Override + public void run() { + for(int i=0;i<20;++i) { + if(aafLur.fish(id, perm)) { + System.out.println("Yes, " + id + " has permission for " + perm.getKey()); + } else { + System.out.println("No, " + id + " does not have permission for " + perm.getKey()); + } + } + } + }).start(); + } + + + } finally { + aafLur.destroy(); + } + } else { // checked on IDs + System.err.println(Config.AAF_MECHID + " and/or " + Config.AAF_MECHPASS + " are not set."); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_TestAccess.java b/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_TestAccess.java new file mode 100644 index 0000000..f3d66a6 --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/JU_TestAccess.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * ============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.aaf.test; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; + +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Symm; +import org.onap.aaf.cadi.config.Config; + +public class JU_TestAccess implements Access { + private Symm symm; + private PrintStream out; + + public JU_TestAccess(PrintStream out) { + this.out = out; + InputStream is = ClassLoader.getSystemResourceAsStream("cadi.properties"); + try { + System.getProperties().load(is); + } catch (IOException e) { + e.printStackTrace(out); + } finally { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(out); + } + } + + String keyfile = System.getProperty(Config.CADI_KEYFILE); + if(keyfile==null) { + System.err.println("No " + Config.CADI_KEYFILE + " in Classpath"); + } else { + try { + is = new FileInputStream(keyfile); + try { + symm = Symm.obtain(is); + } finally { + is.close(); + } + } catch (IOException e) { + e.printStackTrace(out); + } + } + + + + } + + public void log(Level level, Object... elements) { + boolean first = true; + for(int i=0;i aafAuthn = con.newAuthn(aafLur); - - // Do not set Mech ID until after you construct AAFAuthn, - // because we initiate "401" info to determine the Realm of - // of the service we're after. - final String id = myAccess.getProperty(Config.AAF_MECHID,null); - final String pass = myAccess.decrypt(myAccess.getProperty(Config.AAF_MECHPASS,null),false); - if(id!=null && pass!=null) { - try { - - // Normally, you obtain Principal from Authentication System. - // // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() - // // If you use CADI as Authenticator, it will get you these Principals from - // // CSP or BasicAuth mechanisms. - // String id = "cluster_admin@gridcore.att.com"; - // - // // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. - String ok; - ok = aafAuthn.validate(id, pass); - if(ok!=null) { - System.out.println(ok); - } - - List pond = new ArrayList(); - for(int i=0;i<20;++i) { - pond.clear(); - aafLur.fishAll(i+id, pond); - if(ok!=null && i%1000==0) { - System.out.println(i + " " + ok); - } - } - - for(int i=0;i<1000000;++i) { - ok = aafAuthn.validate( i+ id, "wrongPass"); - if(ok!=null && i%1000==0) { - System.out.println(i + " " + ok); - } - } - - final AAFPermission perm = new AAFPermission("com.att.aaf.access","*","*"); - - // Now you can ask the LUR (Local Representative of the User Repository about Authorization - // With CADI, in J2EE, you can call isUserInRole("com.att.mygroup|mytype|write") on the Request Object - // instead of creating your own LUR - for(int i=0;i<4;++i) { - if(aafLur.fish(id, perm)) { - System.out.println("Yes, " + id + " has permission for " + perm.getKey()); - } else { - System.out.println("No, " + id + " does not have permission for " + perm.getKey()); - } - } - - - // Or you can all for all the Permissions available - List perms = new ArrayList(); - - - aafLur.fishAll(id,perms); - System.out.println("Perms for " + id); - for(Permission prm : perms) { - System.out.println(prm.getKey()); - } - - System.out.println("Press any key to continue"); - System.in.read(); - - for(int j=0;j<5;++j) { - new Thread(new Runnable() { - @Override - public void run() { - for(int i=0;i<20;++i) { - if(aafLur.fish(id, perm)) { - System.out.println("Yes, " + id + " has permission for " + perm.getKey()); - } else { - System.out.println("No, " + id + " does not have permission for " + perm.getKey()); - } - } - } - }).start(); - } - - - } finally { - aafLur.destroy(); - } - } else { // checked on IDs - System.err.println(Config.AAF_MECHID + " and/or " + Config.AAF_MECHPASS + " are not set."); - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/TestAccess.java b/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/TestAccess.java deleted file mode 100644 index 2af452d..0000000 --- a/aaf/src/test/java/org/onap/aaf/cadi/lur/aaf/test/TestAccess.java +++ /dev/null @@ -1,122 +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.aaf.test; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; - -import org.onap.aaf.cadi.Access; -import org.onap.aaf.cadi.Symm; -import org.onap.aaf.cadi.config.Config; - -public class TestAccess implements Access { - private Symm symm; - private PrintStream out; - - public TestAccess(PrintStream out) { - this.out = out; - InputStream is = ClassLoader.getSystemResourceAsStream("cadi.properties"); - try { - System.getProperties().load(is); - } catch (IOException e) { - e.printStackTrace(out); - } finally { - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(out); - } - } - - String keyfile = System.getProperty(Config.CADI_KEYFILE); - if(keyfile==null) { - System.err.println("No " + Config.CADI_KEYFILE + " in Classpath"); - } else { - try { - is = new FileInputStream(keyfile); - try { - symm = Symm.obtain(is); - } finally { - is.close(); - } - } catch (IOException e) { - e.printStackTrace(out); - } - } - - - - } - - public void log(Level level, Object... elements) { - boolean first = true; - for(int i=0;i si = new SecurityInfoC(access); - HClient hclient = new HClient( - new HX509SS(si), - new URI("https://mithrilcsp.sbc.com:8085"),3000); - hclient.setMethod("OPTIONS"); - hclient.setPathInfo("/gui/cadi/log/toggle/INFO"); - hclient.send(); - Future future = hclient.futureReadString(); - if(future.get(5000)) { - System.out.println(future.value); - } else { - System.out.printf("Error: %d-%s", future.code(),future.body()); - } - - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/aaf/src/test/java/org/onap/aaf/example/ExampleAuthCheck.java b/aaf/src/test/java/org/onap/aaf/example/ExampleAuthCheck.java deleted file mode 100644 index 65972cd..0000000 --- a/aaf/src/test/java/org/onap/aaf/example/ExampleAuthCheck.java +++ /dev/null @@ -1,57 +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.example; - -import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; -import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; -import org.onap.aaf.cadi.locator.DNSLocator; - -public class ExampleAuthCheck { - public static void main(String args[]) { - // Link or reuse to your Logging mechanism - PropAccess myAccess = new PropAccess(); // - - try { - AAFConHttp acon = new AAFConHttp(myAccess, new DNSLocator( - myAccess,"https","localhost","8100")); - AAFAuthn authn = acon.newAuthn(); - long start; - for (int i=0;i<10;++i) { - start = System.nanoTime(); - String err = authn.validate("", "gritty"); - if(err!=null) System.err.println(err); - else System.out.println("I'm ok"); - - err = authn.validate("bogus", "gritty"); - if(err!=null) System.err.println(err + " (correct error)"); - else System.out.println("I'm ok"); - - System.out.println((System.nanoTime()-start)/1000000f + " ms"); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0.java b/aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0.java deleted file mode 100644 index f83b15b..0000000 --- a/aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0.java +++ /dev/null @@ -1,113 +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.example; - -import java.security.Principal; -import java.util.ArrayList; -import java.util.List; - -import org.onap.aaf.cadi.Permission; -import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.aaf.AAFPermission; -import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; -import org.onap.aaf.cadi.aaf.v2_0.AAFCon; -import org.onap.aaf.cadi.aaf.v2_0.AAFConDME2; -import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; - -public class ExamplePerm2_0 { - public static void main(String args[]) { - - // Link or reuse to your Logging mechanism - PropAccess myAccess = new PropAccess(); - - // - try { - AAFCon acon = new AAFConDME2(myAccess); - - // AAFLur has pool of DME clients as needed, and Caches Client lookups - AAFLurPerm aafLur = acon.newLur(); - - // Note: If you need both Authn and Authz construct the following: - AAFAuthn aafAuthn = acon.newAuthn(aafLur); - - // Do not set Mech ID until after you construct AAFAuthn, - // because we initiate "401" info to determine the Realm of - // of the service we're after. - acon.basicAuth("mc0897@aaf.att.com", "XXXXXX"); - - try { - - // Normally, you obtain Principal from Authentication System. - // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() - // If you use CADI as Authenticator, it will get you these Principals from - // CSP or BasicAuth mechanisms. - String id = "mc0897@aaf.att.com"; //"cluster_admin@gridcore.att.com"; - - // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. - String ok = aafAuthn.validate(id, "XXXXXX"); - if(ok!=null)System.out.println(ok); - - ok = aafAuthn.validate(id, "wrongPass"); - if(ok!=null)System.out.println(ok); - - - // AAF Style permissions are in the form - // Type, Instance, Action - AAFPermission perm = new AAFPermission("com.att.grid.core.coh",":dev_cluster", "WRITE"); - - // Now you can ask the LUR (Local Representative of the User Repository about Authorization - // With CADI, in J2EE, you can call isUserInRole("com.att.mygroup|mytype|write") on the Request Object - // instead of creating your own LUR - System.out.println("Does " + id + " have " + perm); - if(aafLur.fish(id, perm)) { - System.out.println("Yes, you have permission"); - } else { - System.out.println("No, you don't have permission"); - } - - System.out.println("Does Bogus have " + perm); - if(aafLur.fish("Bogus", perm)) { - System.out.println("Yes, you have permission"); - } else { - System.out.println("No, you don't have permission"); - } - - // Or you can all for all the Permissions available - List perms = new ArrayList(); - - aafLur.fishAll(id,perms); - for(Permission prm : perms) { - System.out.println(prm.getKey()); - } - - // It might be helpful in some cases to clear the User's identity from the Cache - aafLur.remove(id); - } finally { - aafLur.destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0_DME2.java b/aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0_DME2.java deleted file mode 100644 index f6024a5..0000000 --- a/aaf/src/test/java/org/onap/aaf/example/ExamplePerm2_0_DME2.java +++ /dev/null @@ -1,113 +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.example; - -import java.security.Principal; -import java.util.ArrayList; -import java.util.List; - -import org.onap.aaf.cadi.Permission; -import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.aaf.AAFPermission; -import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; -import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; -import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; -import org.onap.aaf.cadi.locator.DNSLocator; - -public class ExamplePerm2_0_DME2 { - public static void main(String args[]) { - // Link or reuse to your Logging mechanism - PropAccess myAccess = new PropAccess(); - - // - try { - AAFConHttp acon = new AAFConHttp(myAccess, new DNSLocator( - myAccess,"https","localhost","8100")); - - // AAFLur has pool of DME clients as needed, and Caches Client lookups - AAFLurPerm aafLur = acon.newLur(); - - // Note: If you need both Authn and Authz construct the following: - AAFAuthn aafAuthn = acon.newAuthn(aafLur); - - // Do not set Mech ID until after you construct AAFAuthn, - // because we initiate "401" info to determine the Realm of - // of the service we're after. - acon.basicAuth("mc0897@aaf.att.com", "XXXXXX"); - - try { - - // Normally, you obtain Principal from Authentication System. - // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() - // If you use CADI as Authenticator, it will get you these Principals from - // CSP or BasicAuth mechanisms. - String id = "mc0897@aaf.att.com"; //"cluster_admin@gridcore.att.com"; - - // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. - String ok = aafAuthn.validate(id, "XXXXXX"); - if(ok!=null)System.out.println(ok); - - ok = aafAuthn.validate(id, "wrongPass"); - if(ok!=null)System.out.println(ok); - - - // AAF Style permissions are in the form - // Type, Instance, Action - AAFPermission perm = new AAFPermission("com.att.grid.core.coh",":dev_cluster", "WRITE"); - - // Now you can ask the LUR (Local Representative of the User Repository about Authorization - // With CADI, in J2EE, you can call isUserInRole("com.att.mygroup|mytype|write") on the Request Object - // instead of creating your own LUR - System.out.println("Does " + id + " have " + perm); - if(aafLur.fish(id, perm)) { - System.out.println("Yes, you have permission"); - } else { - System.out.println("No, you don't have permission"); - } - - System.out.println("Does Bogus have " + perm); - if(aafLur.fish("Bogus", perm)) { - System.out.println("Yes, you have permission"); - } else { - System.out.println("No, you don't have permission"); - } - - // Or you can all for all the Permissions available - List perms = new ArrayList(); - - aafLur.fishAll(id,perms); - for(Permission prm : perms) { - System.out.println(prm.getKey()); - } - - // It might be helpful in some cases to clear the User's identity from the Cache - aafLur.remove(id); - } finally { - aafLur.destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/aaf/src/test/java/org/onap/aaf/example/JU_CadiTest.java b/aaf/src/test/java/org/onap/aaf/example/JU_CadiTest.java new file mode 100644 index 0000000..17fd827 --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/example/JU_CadiTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============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.example; + +import java.net.HttpURLConnection; +import java.net.URI; + +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.client.Future; +import org.onap.aaf.cadi.config.SecurityInfoC; +import org.onap.aaf.cadi.http.HClient; +import org.onap.aaf.cadi.http.HX509SS; + +public class JU_CadiTest { + public static void main(String args[]) { + Access access = new PropAccess(); + try { + SecurityInfoC si = new SecurityInfoC(access); + HClient hclient = new HClient( + new HX509SS(si), + new URI("https://mithrilcsp.sbc.com:8085"),3000); + hclient.setMethod("OPTIONS"); + hclient.setPathInfo("/gui/cadi/log/toggle/INFO"); + hclient.send(); + Future future = hclient.futureReadString(); + if(future.get(5000)) { + System.out.println(future.value); + } else { + System.out.printf("Error: %d-%s", future.code(),future.body()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/aaf/src/test/java/org/onap/aaf/example/JU_ExampleAuthCheck.java b/aaf/src/test/java/org/onap/aaf/example/JU_ExampleAuthCheck.java new file mode 100644 index 0000000..cb4e48f --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/example/JU_ExampleAuthCheck.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * ============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.example; + +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; +import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; +import org.onap.aaf.cadi.locator.DNSLocator; + +public class JU_ExampleAuthCheck { + public static void main(String args[]) { + // Link or reuse to your Logging mechanism + PropAccess myAccess = new PropAccess(); // + + try { + AAFConHttp acon = new AAFConHttp(myAccess, new DNSLocator( + myAccess,"https","localhost","8100")); + AAFAuthn authn = acon.newAuthn(); + long start; + for (int i=0;i<10;++i) { + start = System.nanoTime(); + String err = authn.validate("", "gritty"); + if(err!=null) System.err.println(err); + else System.out.println("I'm ok"); + + err = authn.validate("bogus", "gritty"); + if(err!=null) System.err.println(err + " (correct error)"); + else System.out.println("I'm ok"); + + System.out.println((System.nanoTime()-start)/1000000f + " ms"); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0.java b/aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0.java new file mode 100644 index 0000000..652cadb --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * ============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.example; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.List; + +import org.onap.aaf.cadi.Permission; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; +import org.onap.aaf.cadi.aaf.v2_0.AAFCon; +import org.onap.aaf.cadi.aaf.v2_0.AAFConDME2; +import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; + +public class JU_ExamplePerm2_0 { + public static void main(String args[]) { + + // Link or reuse to your Logging mechanism + PropAccess myAccess = new PropAccess(); + + // + try { + AAFCon acon = new AAFConDME2(myAccess); + + // AAFLur has pool of DME clients as needed, and Caches Client lookups + AAFLurPerm aafLur = acon.newLur(); + + // Note: If you need both Authn and Authz construct the following: + AAFAuthn aafAuthn = acon.newAuthn(aafLur); + + // Do not set Mech ID until after you construct AAFAuthn, + // because we initiate "401" info to determine the Realm of + // of the service we're after. + acon.basicAuth("mc0897@aaf.att.com", "XXXXXX"); + + try { + + // Normally, you obtain Principal from Authentication System. + // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() + // If you use CADI as Authenticator, it will get you these Principals from + // CSP or BasicAuth mechanisms. + String id = "mc0897@aaf.att.com"; //"cluster_admin@gridcore.att.com"; + + // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. + String ok = aafAuthn.validate(id, "XXXXXX"); + if(ok!=null)System.out.println(ok); + + ok = aafAuthn.validate(id, "wrongPass"); + if(ok!=null)System.out.println(ok); + + + // AAF Style permissions are in the form + // Type, Instance, Action + AAFPermission perm = new AAFPermission("com.att.grid.core.coh",":dev_cluster", "WRITE"); + + // Now you can ask the LUR (Local Representative of the User Repository about Authorization + // With CADI, in J2EE, you can call isUserInRole("com.att.mygroup|mytype|write") on the Request Object + // instead of creating your own LUR + System.out.println("Does " + id + " have " + perm); + if(aafLur.fish(id, perm)) { + System.out.println("Yes, you have permission"); + } else { + System.out.println("No, you don't have permission"); + } + + System.out.println("Does Bogus have " + perm); + if(aafLur.fish("Bogus", perm)) { + System.out.println("Yes, you have permission"); + } else { + System.out.println("No, you don't have permission"); + } + + // Or you can all for all the Permissions available + List perms = new ArrayList(); + + aafLur.fishAll(id,perms); + for(Permission prm : perms) { + System.out.println(prm.getKey()); + } + + // It might be helpful in some cases to clear the User's identity from the Cache + aafLur.remove(id); + } finally { + aafLur.destroy(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0_DME2.java b/aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0_DME2.java new file mode 100644 index 0000000..88e2936 --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/example/JU_ExamplePerm2_0_DME2.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * ============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.example; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.List; + +import org.onap.aaf.cadi.Permission; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; +import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; +import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; +import org.onap.aaf.cadi.locator.DNSLocator; + +public class JU_ExamplePerm2_0_DME2 { + public static void main(String args[]) { + // Link or reuse to your Logging mechanism + PropAccess myAccess = new PropAccess(); + + // + try { + AAFConHttp acon = new AAFConHttp(myAccess, new DNSLocator( + myAccess,"https","localhost","8100")); + + // AAFLur has pool of DME clients as needed, and Caches Client lookups + AAFLurPerm aafLur = acon.newLur(); + + // Note: If you need both Authn and Authz construct the following: + AAFAuthn aafAuthn = acon.newAuthn(aafLur); + + // Do not set Mech ID until after you construct AAFAuthn, + // because we initiate "401" info to determine the Realm of + // of the service we're after. + acon.basicAuth("mc0897@aaf.att.com", "XXXXXX"); + + try { + + // Normally, you obtain Principal from Authentication System. + // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() + // If you use CADI as Authenticator, it will get you these Principals from + // CSP or BasicAuth mechanisms. + String id = "mc0897@aaf.att.com"; //"cluster_admin@gridcore.att.com"; + + // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. + String ok = aafAuthn.validate(id, "XXXXXX"); + if(ok!=null)System.out.println(ok); + + ok = aafAuthn.validate(id, "wrongPass"); + if(ok!=null)System.out.println(ok); + + + // AAF Style permissions are in the form + // Type, Instance, Action + AAFPermission perm = new AAFPermission("com.att.grid.core.coh",":dev_cluster", "WRITE"); + + // Now you can ask the LUR (Local Representative of the User Repository about Authorization + // With CADI, in J2EE, you can call isUserInRole("com.att.mygroup|mytype|write") on the Request Object + // instead of creating your own LUR + System.out.println("Does " + id + " have " + perm); + if(aafLur.fish(id, perm)) { + System.out.println("Yes, you have permission"); + } else { + System.out.println("No, you don't have permission"); + } + + System.out.println("Does Bogus have " + perm); + if(aafLur.fish("Bogus", perm)) { + System.out.println("Yes, you have permission"); + } else { + System.out.println("No, you don't have permission"); + } + + // Or you can all for all the Permissions available + List perms = new ArrayList(); + + aafLur.fishAll(id,perms); + for(Permission prm : perms) { + System.out.println(prm.getKey()); + } + + // It might be helpful in some cases to clear the User's identity from the Cache + aafLur.remove(id); + } finally { + aafLur.destroy(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/aaf/src/test/java/org/onap/aaf/example/JU_X509Test.java b/aaf/src/test/java/org/onap/aaf/example/JU_X509Test.java new file mode 100644 index 0000000..e756f6d --- /dev/null +++ b/aaf/src/test/java/org/onap/aaf/example/JU_X509Test.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * ============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.example; + +import java.security.Principal; + +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; +import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; +import org.onap.aaf.cadi.client.Future; +import org.onap.aaf.cadi.locator.DNSLocator; +import org.onap.aaf.cadi.lur.LocalPermission; + +public class JU_X509Test { + public static void main(String args[]) { + // Link or reuse to your Logging mechanism + + PropAccess myAccess = new PropAccess(); + + // + try { + AAFConHttp con = new AAFConHttp(myAccess, + new DNSLocator(myAccess,"https","mithrilcsp.sbc.com","8100")); + + // AAFLur has pool of DME clients as needed, and Caches Client lookups + AAFLurPerm aafLur = con.newLur(); + + // Note: If you need both Authn and Authz construct the following: +// AAFAuthn aafAuthn = con.newAuthn(aafLur); + + // con.x509Alias("aaf.att"); // alias in keystore + + try { + + // Normally, you obtain Principal from Authentication System. +// // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() +// // If you use CADI as Authenticator, it will get you these Principals from +// // CSP or BasicAuth mechanisms. +// String id = "cluster_admin@gridcore.att.com"; +// +// // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. + Future fs = + con.client("2.0").read("/authz/perms/com.att.aaf.ca","application/Perms+json"); + if(fs.get(3000)) { + System.out.println(fs.value); + } else { + System.out.println("Error: " + fs.code() + ':' + fs.body()); + } + + // Check on Perms with LUR + if(aafLur.fish(new Principal() { + @Override + public String getName() { + return "m12345@aaf.att.com"; + } + }, new LocalPermission("com.att.aaf.ca|aaf|request"))) { + System.out.println("Has Perm"); + } else { + System.out.println("Does NOT Have Perm"); + } + } finally { + aafLur.destroy(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/aaf/src/test/java/org/onap/aaf/example/X509Test.java b/aaf/src/test/java/org/onap/aaf/example/X509Test.java deleted file mode 100644 index ad5d4b2..0000000 --- a/aaf/src/test/java/org/onap/aaf/example/X509Test.java +++ /dev/null @@ -1,89 +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.example; - -import java.security.Principal; - -import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; -import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm; -import org.onap.aaf.cadi.client.Future; -import org.onap.aaf.cadi.locator.DNSLocator; -import org.onap.aaf.cadi.lur.LocalPermission; - -public class X509Test { - public static void main(String args[]) { - // Link or reuse to your Logging mechanism - - PropAccess myAccess = new PropAccess(); - - // - try { - AAFConHttp con = new AAFConHttp(myAccess, - new DNSLocator(myAccess,"https","mithrilcsp.sbc.com","8100")); - - // AAFLur has pool of DME clients as needed, and Caches Client lookups - AAFLurPerm aafLur = con.newLur(); - - // Note: If you need both Authn and Authz construct the following: -// AAFAuthn aafAuthn = con.newAuthn(aafLur); - - // con.x509Alias("aaf.att"); // alias in keystore - - try { - - // Normally, you obtain Principal from Authentication System. -// // For J2EE, you can ask the HttpServletRequest for getUserPrincipal() -// // If you use CADI as Authenticator, it will get you these Principals from -// // CSP or BasicAuth mechanisms. -// String id = "cluster_admin@gridcore.att.com"; -// -// // If Validate succeeds, you will get a Null, otherwise, you will a String for the reason. - Future fs = - con.client("2.0").read("/authz/perms/com.att.aaf.ca","application/Perms+json"); - if(fs.get(3000)) { - System.out.println(fs.value); - } else { - System.out.println("Error: " + fs.code() + ':' + fs.body()); - } - - // Check on Perms with LUR - if(aafLur.fish(new Principal() { - @Override - public String getName() { - return "m12345@aaf.att.com"; - } - }, new LocalPermission("com.att.aaf.ca|aaf|request"))) { - System.out.println("Has Perm"); - } else { - System.out.println("Does NOT Have Perm"); - } - } finally { - aafLur.destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatedUserTest.java b/cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatedUserTest.java deleted file mode 100644 index dbc923a..0000000 --- a/cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatedUserTest.java +++ /dev/null @@ -1,247 +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.cass; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.aaf.cadi.aaf.cass.AAFAuthenticatedUser; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class AAFAuthenticatedUserTest -{ - - - @Before - public void setUp() - { - - } - - @After - public void tearDown() - { - - } - - /* - * Testing Conditon(s): if: (endIndex >= 0) - */ - @Test - public void test_method_AAFAuthenticatedUser_0_branch_0() - { - System.out.println("Now Testing Method:AAFAuthenticatedUser Branch:0"); - - //Constructor - - - - } - - /* - * Testing Conditon(s): else: Not (endIndex >= 0) - */ - @Test - public void test_method_AAFAuthenticatedUser_0_branch_1() - { - System.out.println("Now Testing Method:AAFAuthenticatedUser Branch:1"); - - //Constructor - - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getFullName_1_branch_0() - { - System.out.println("Now Testing Method:getFullName Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_2_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_isAnonymous_3_branch_0() - { - System.out.println("Now Testing Method:isAnonymous Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_setAnonymous_4_branch_0() - { - System.out.println("Now Testing Method:setAnonymous Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getAnonymous_5_branch_0() - { - System.out.println("Now Testing Method:getAnonymous Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_isSuper_6_branch_0() - { - System.out.println("Now Testing Method:isSuper Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_setSuper_7_branch_0() - { - System.out.println("Now Testing Method:setSuper Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getSuper_8_branch_0() - { - System.out.println("Now Testing Method:getSuper Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_isLocal_9_branch_0() - { - System.out.println("Now Testing Method:isLocal Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_setLocal_10_branch_0() - { - System.out.println("Now Testing Method:setLocal Branch:0"); - - - - } - - /* - * Testing Conditon(s): if: (this == o) - */ - @Test - public void test_method_equals_11_branch_0() - { - System.out.println("Now Testing Method:equals Branch:0"); - - - } - - /* - * Testing Conditon(s): else: Not (this == o) - */ - @Test - public void test_method_equals_11_branch_1() - { - System.out.println("Now Testing Method:equals Branch:1"); - - } - - /* - * Testing Conditon(s): if: (!(o instanceof AAFAuthenticatedUser)) - */ - @Test - public void test_method_equals_11_branch_2() - { - System.out.println("Now Testing Method:equals Branch:2"); - - } - - /* - * Testing Conditon(s): else: Not (!(o instanceof AAFAuthenticatedUser)) - */ - @Test - public void test_method_equals_11_branch_3() - { - System.out.println("Now Testing Method:equals Branch:3"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_hashCode_12_branch_0() - { - System.out.println("Now Testing Method:hashCode Branch:0"); - - - - } - -} diff --git a/cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatorTest.java b/cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatorTest.java deleted file mode 100644 index 6482d06..0000000 --- a/cass/src/test/java/org/onap/aaf/cass/AAFAuthenticatorTest.java +++ /dev/null @@ -1,292 +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.cass; - -import static org.junit.Assert.*; - -import org.apache.cassandra.exceptions.AuthenticationException; -import org.junit.Test; -import org.onap.aaf.cadi.aaf.cass.AAFAuthenticator; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class AAFAuthenticatorTest -{ - - - @Before - public void setUp() - { - - } - - @After - public void tearDown() - { - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_requireAuthentication_0_branch_0() - { - System.out.println("Now Testing Method:requireAuthentication Branch:0"); - - //Constructor - AAFAuthenticator instance = new AAFAuthenticator(); - - //Get expected result and result - Object expResult = null; - Object result = instance.requireAuthentication(); - - //Check Return value - assertEquals(expResult, result); - - //Check Test Verification Points - assertEquals(null, instance.requireAuthentication()); - - } - - /* - * Testing Conditon(s): if: (username == null) - */ - @Test - public void test_method_authenticate_1_branch_0() - { - System.out.println("Now Testing Method:authenticate Branch:0"); - - - - } - - /* - * Testing Conditon(s): else: Not (username == null) - */ - @Test - public void test_method_authenticate_1_branch_1() throws AuthenticationException - { - System.out.println("Now Testing Method:authenticate Branch:1"); - - //Constructor - AAFAuthenticator instance = new AAFAuthenticator(); - - //Get expected result and result - Object expResult = null; - Object result = instance.authenticate(null); - - //Check Return value - assertEquals(expResult, result); - - - - } - - /* - * Testing Conditon(s): if: (password == null) - */ - @Test - public void test_method_authenticate_1_branch_2() - { - System.out.println("Now Testing Method:authenticate Branch:2"); - - - - } - - /* - * Testing Conditon(s): else: Not (password == null), if: (password.startsWith("bsf:")) - */ - @Test - public void test_method_authenticate_1_branch_3() - { - System.out.println("Now Testing Method:authenticate Branch:3"); - - - - } - - /* - * Testing Conditon(s): else: Not (password == null), else: Not (password.startsWith("bsf:")), if: (password.startsWith("enc:???")) - */ - @Test - public void test_method_authenticate_1_branch_4() - { - System.out.println("Now Testing Method:authenticate Branch:4"); - - } - - /* - * Testing Conditon(s): else: Not (password == null), else: Not (password.startsWith("bsf:")), else: Not (password.startsWith("enc:???")) - */ - @Test - public void test_method_authenticate_1_branch_5() - { - System.out.println("Now Testing Method:authenticate Branch:5"); - - - - } - - /* - * Testing Conditon(s): if: (localLur!=null), if: (localLur.validate(fullName, Type.PASSWORD, password.getBytes())) - */ - @Test - public void test_method_authenticate_1_branch_6() - { - System.out.println("Now Testing Method:authenticate Branch:6"); - - - - } - - /* - * Testing Conditon(s): if: (localLur!=null), else: Not (localLur.validate(fullName, Type.PASSWORD, password.getBytes())) - */ - @Test - public void test_method_authenticate_1_branch_7() - { - System.out.println("Now Testing Method:authenticate Branch:7"); - - - } - - /* - * Testing Conditon(s): else: Not (localLur!=null) - */ - @Test - public void test_method_authenticate_1_branch_8() - { - System.out.println("Now Testing Method:authenticate Branch:8"); - - - - } - - /* - * Testing Conditon(s): if: (aafResponse != null) - */ - @Test - public void test_method_authenticate_1_branch_9() - { - System.out.println("Now Testing Method:authenticate Branch:9"); - - - } - - /* - * Testing Conditon(s): else: Not (aafResponse != null) - */ - @Test - public void test_method_authenticate_1_branch_10() - { - System.out.println("Now Testing Method:authenticate Branch:10"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_create_2_branch_0() - { - System.out.println("Now Testing Method:create Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_alter_3_branch_0() - { - System.out.println("Now Testing Method:alter Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_drop_4_branch_0() - { - System.out.println("Now Testing Method:drop Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_evaluateResponse_5_branch_0() - { - System.out.println("Now Testing Method:evaluateResponse Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_isComplete_6_branch_0() - { - System.out.println("Now Testing Method:isComplete Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getAuthenticatedUser_7_branch_0() - { - System.out.println("Now Testing Method:getAuthenticatedUser Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_newAuthenticator_8_branch_0() - { - System.out.println("Now Testing Method:newAuthenticator Branch:0"); - - - - } - -} diff --git a/cass/src/test/java/org/onap/aaf/cass/AAFAuthorizerTest.java b/cass/src/test/java/org/onap/aaf/cass/AAFAuthorizerTest.java deleted file mode 100644 index 1671f7e..0000000 --- a/cass/src/test/java/org/onap/aaf/cass/AAFAuthorizerTest.java +++ /dev/null @@ -1,378 +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.cass; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class AAFAuthorizerTest -{ - - - @Before - public void setUp() - { - - } - - @After - public void tearDown() - { - - } - - /* - * Testing Conditon(s): if: (user instanceof AAFAuthenticatedUser), if: (aafUser.isLocal()) - */ - @Test - public void test_method_authorize_0_branch_0() - { - System.out.println("Now Testing Method:authorize Branch:0"); - - - - } - - /* - * Testing Conditon(s): if: (user instanceof AAFAuthenticatedUser), else: Not (aafUser.isLocal()) - */ - @Test - public void test_method_authorize_0_branch_1() - { - System.out.println("Now Testing Method:authorize Branch:1"); - - - } - - /* - * Testing Conditon(s): else: Not (user instanceof AAFAuthenticatedUser) - */ - @Test - public void test_method_authorize_0_branch_2() - { - System.out.println("Now Testing Method:authorize Branch:2"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_PermHolder_1_branch_0() - { - System.out.println("Now Testing Method:PermHolder Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_PermHolder_2_branch_0() - { - System.out.println("Now Testing Method:PermHolder Branch:0"); - - - - } - - /* - * Testing Conditon(s): if: (permissions==Permission.NONE) - */ - @Test - public void test_method_mutable_3_branch_0() - { - System.out.println("Now Testing Method:mutable Branch:0"); - - - - } - - /* - * Testing Conditon(s): else: Not (permissions==Permission.NONE) - */ - @Test - public void test_method_mutable_3_branch_1() - { - System.out.println("Now Testing Method:mutable Branch:1"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_mutable_4_branch_0() - { - System.out.println("Now Testing Method:mutable Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_mutable_5_branch_0() - { - System.out.println("Now Testing Method:mutable Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_6_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_exec_7_branch_0() - { - System.out.println("Now Testing Method:exec Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_8_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_exec_9_branch_0() - { - System.out.println("Now Testing Method:exec Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_10_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_exec_11_branch_0() - { - System.out.println("Now Testing Method:exec Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_12_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_exec_13_branch_0() - { - System.out.println("Now Testing Method:exec Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_14_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_exec_15_branch_0() - { - System.out.println("Now Testing Method:exec Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_16_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_exec_17_branch_0() - { - System.out.println("Now Testing Method:exec Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_getName_18_branch_0() - { - System.out.println("Now Testing Method:getName Branch:0"); - - //Constructor - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_exec_19_branch_0() - { - System.out.println("Now Testing Method:exec Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_grant_20_branch_0() - { - System.out.println("Now Testing Method:grant Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_revoke_21_branch_0() - { - System.out.println("Now Testing Method:revoke Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_list_22_branch_0() - { - System.out.println("Now Testing Method:list Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_revokeAll_23_branch_0() - { - System.out.println("Now Testing Method:revokeAll Branch:0"); - - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_revokeAll_24_branch_0() - { - System.out.println("Now Testing Method:revokeAll Branch:0"); - - - - } - -} diff --git a/cass/src/test/java/org/onap/aaf/cass/AAFBaseTest.java b/cass/src/test/java/org/onap/aaf/cass/AAFBaseTest.java deleted file mode 100644 index 52f005b..0000000 --- a/cass/src/test/java/org/onap/aaf/cass/AAFBaseTest.java +++ /dev/null @@ -1,399 +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.cass; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.aaf.cadi.aaf.cass.AAFBase; - -import static org.junit.Assert.*; - -public class AAFBaseTest -{ - - - @Before - public void setUp() - { - - } - - @After - public void tearDown() - { - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_setAccess_0_branch_0() - { - System.out.println("Now Testing Method:setAccess Branch:0"); - - //Call Method - AAFBase.setAccess(null); - - } - - /* - * Testing Conditon(s): if: (!props_ok) - */ - @Test - public void test_method_validateConfiguration_1_branch_0() - { - System.out.println("Now Testing Method:validateConfiguration Branch:0"); - - - - } - - /* - * Testing Conditon(s): else: Not (!props_ok) - */ - @Test - public void test_method_validateConfiguration_1_branch_1() - { - System.out.println("Now Testing Method:validateConfiguration Branch:1"); - - - - //Call Method - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (access==null), if: (cadi_props == null), if: (cp.exists()) - */ - @Test - public void test_method_setup_2_branch_0() - { - System.out.println("Now Testing Method:setup Branch:0"); - - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (access==null), if: (cadi_props == null), else: Not (cp.exists()) - */ - @Test - public void test_method_setup_2_branch_1() - { - System.out.println("Now Testing Method:setup Branch:1"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (access==null), else: Not (cadi_props == null) - */ - @Test - public void test_method_setup_2_branch_2() - { - System.out.println("Now Testing Method:setup Branch:2"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not (access==null) - */ - @Test - public void test_method_setup_2_branch_3() - { - System.out.println("Now Testing Method:setup Branch:3"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: ((perm_type = Config.logProp(access, "cass_group_name",null))==null) - */ - @Test - public void test_method_setup_2_branch_4() - { - System.out.println("Now Testing Method:setup Branch:4"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not ((perm_type = Config.logProp(access, "cass_group_name",null))==null) - */ - @Test - public void test_method_setup_2_branch_5() - { - System.out.println("Now Testing Method:setup Branch:5"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: ((cluster_name = Config.logProp(access,"cass_cluster_name",null))==null), if: ((cluster_name = DatabaseDescriptor.getClusterName())==null) - */ - @Test - public void test_method_setup_2_branch_6() - { - System.out.println("Now Testing Method:setup Branch:6"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: ((cluster_name = Config.logProp(access,"cass_cluster_name",null))==null), else: Not ((cluster_name = DatabaseDescriptor.getClusterName())==null) - */ - @Test - public void test_method_setup_2_branch_7() - { - System.out.println("Now Testing Method:setup Branch:7"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not ((cluster_name = Config.logProp(access,"cass_cluster_name",null))==null) - */ - @Test - public void test_method_setup_2_branch_8() - { - System.out.println("Now Testing Method:setup Branch:8"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: ((default_realm = Config.logProp(access, Config.AAF_DEFAULT_REALM, null))==null) - */ - @Test - public void test_method_setup_2_branch_9() - { - System.out.println("Now Testing Method:setup Branch:9"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not ((default_realm = Config.logProp(access, Config.AAF_DEFAULT_REALM, null))==null) - */ - @Test - public void test_method_setup_2_branch_10() - { - System.out.println("Now Testing Method:setup Branch:10"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (props_ok==false) - */ - @Test - public void test_method_setup_2_branch_11() - { - System.out.println("Now Testing Method:setup Branch:11"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not (props_ok==false) - */ - @Test - public void test_method_setup_2_branch_12() - { - System.out.println("Now Testing Method:setup Branch:12"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: (int i=0; (lur = elur.get(i))!=null;++i), if: (lur instanceof AbsAAFLur) - */ - @Test - public void test_method_setup_2_branch_13() - { - System.out.println("Now Testing Method:setup Branch:13"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: (int i=0; (lur = elur.get(i))!=null;++i), else: Not (lur instanceof AbsAAFLur), if: (lur instanceof LocalLur) - */ - @Test - public void test_method_setup_2_branch_14() - { - System.out.println("Now Testing Method:setup Branch:14"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: (int i=0; (lur = elur.get(i))!=null;++i), else: Not (lur instanceof AbsAAFLur), else: Not (lur instanceof LocalLur) - */ - @Test - public void test_method_setup_2_branch_15() - { - System.out.println("Now Testing Method:setup Branch:15"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: Not (int i=0; (lur = elur.get(i))!=null;++i) - */ - @Test - public void test_method_setup_2_branch_16() - { - System.out.println("Now Testing Method:setup Branch:16"); - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not (lur instanceof EpiLur), if: (lur instanceof AbsAAFLur) - */ - @Test - public void test_method_setup_2_branch_17() - { - System.out.println("Now Testing Method:setup Branch:17"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not (lur instanceof EpiLur), else: Not (lur instanceof AbsAAFLur) - */ - @Test - public void test_method_setup_2_branch_18() - { - System.out.println("Now Testing Method:setup Branch:18"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (aafAuthn==null) - */ - @Test - public void test_method_setup_2_branch_19() - { - System.out.println("Now Testing Method:setup Branch:19"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not (aafAuthn==null) - */ - @Test - public void test_method_setup_2_branch_20() - { - System.out.println("Now Testing Method:setup Branch:20"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), if: (access!=null) - */ - @Test - public void test_method_setup_2_branch_21() - { - System.out.println("Now Testing Method:setup Branch:21"); - - - - } - - /* - * Testing Conditon(s): if: (aafAuthn == null), else: Not (access!=null) - */ - @Test - public void test_method_setup_2_branch_22() - { - System.out.println("Now Testing Method:setup Branch:22"); - - - } - - /* - * Testing Conditon(s): else: Not (aafAuthn == null) - */ - @Test - public void test_method_setup_2_branch_23() - { - System.out.println("Now Testing Method:setup Branch:23"); - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_protectedResources_3_branch_0() - { - System.out.println("Now Testing Method:protectedResources Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_supportedOptions_4_branch_0() - { - System.out.println("Now Testing Method:supportedOptions Branch:0"); - - - } - - /* - * Testing Conditon(s): Default - */ - @Test - public void test_method_alterableOptions_5_branch_0() - { - System.out.println("Now Testing Method:alterableOptions Branch:0"); - - - - } - -} diff --git a/cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthenticatedUserTest.java b/cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthenticatedUserTest.java new file mode 100644 index 0000000..50e35df --- /dev/null +++ b/cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthenticatedUserTest.java @@ -0,0 +1,247 @@ +/******************************************************************************* + * ============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.cass; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.aaf.cadi.aaf.cass.AAFAuthenticatedUser; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class JU_AAFAuthenticatedUserTest +{ + + + @Before + public void setUp() + { + + } + + @After + public void tearDown() + { + + } + + /* + * Testing Conditon(s): if: (endIndex >= 0) + */ + @Test + public void test_method_AAFAuthenticatedUser_0_branch_0() + { + System.out.println("Now Testing Method:AAFAuthenticatedUser Branch:0"); + + //Constructor + + + + } + + /* + * Testing Conditon(s): else: Not (endIndex >= 0) + */ + @Test + public void test_method_AAFAuthenticatedUser_0_branch_1() + { + System.out.println("Now Testing Method:AAFAuthenticatedUser Branch:1"); + + //Constructor + + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getFullName_1_branch_0() + { + System.out.println("Now Testing Method:getFullName Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_2_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_isAnonymous_3_branch_0() + { + System.out.println("Now Testing Method:isAnonymous Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_setAnonymous_4_branch_0() + { + System.out.println("Now Testing Method:setAnonymous Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getAnonymous_5_branch_0() + { + System.out.println("Now Testing Method:getAnonymous Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_isSuper_6_branch_0() + { + System.out.println("Now Testing Method:isSuper Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_setSuper_7_branch_0() + { + System.out.println("Now Testing Method:setSuper Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getSuper_8_branch_0() + { + System.out.println("Now Testing Method:getSuper Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_isLocal_9_branch_0() + { + System.out.println("Now Testing Method:isLocal Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_setLocal_10_branch_0() + { + System.out.println("Now Testing Method:setLocal Branch:0"); + + + + } + + /* + * Testing Conditon(s): if: (this == o) + */ + @Test + public void test_method_equals_11_branch_0() + { + System.out.println("Now Testing Method:equals Branch:0"); + + + } + + /* + * Testing Conditon(s): else: Not (this == o) + */ + @Test + public void test_method_equals_11_branch_1() + { + System.out.println("Now Testing Method:equals Branch:1"); + + } + + /* + * Testing Conditon(s): if: (!(o instanceof AAFAuthenticatedUser)) + */ + @Test + public void test_method_equals_11_branch_2() + { + System.out.println("Now Testing Method:equals Branch:2"); + + } + + /* + * Testing Conditon(s): else: Not (!(o instanceof AAFAuthenticatedUser)) + */ + @Test + public void test_method_equals_11_branch_3() + { + System.out.println("Now Testing Method:equals Branch:3"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_hashCode_12_branch_0() + { + System.out.println("Now Testing Method:hashCode Branch:0"); + + + + } + +} diff --git a/cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthorizerTest.java b/cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthorizerTest.java new file mode 100644 index 0000000..4e2f0a3 --- /dev/null +++ b/cass/src/test/java/org/onap/aaf/cass/JU_AAFAuthorizerTest.java @@ -0,0 +1,378 @@ +/******************************************************************************* + * ============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.cass; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class JU_AAFAuthorizerTest +{ + + + @Before + public void setUp() + { + + } + + @After + public void tearDown() + { + + } + + /* + * Testing Conditon(s): if: (user instanceof AAFAuthenticatedUser), if: (aafUser.isLocal()) + */ + @Test + public void test_method_authorize_0_branch_0() + { + System.out.println("Now Testing Method:authorize Branch:0"); + + + + } + + /* + * Testing Conditon(s): if: (user instanceof AAFAuthenticatedUser), else: Not (aafUser.isLocal()) + */ + @Test + public void test_method_authorize_0_branch_1() + { + System.out.println("Now Testing Method:authorize Branch:1"); + + + } + + /* + * Testing Conditon(s): else: Not (user instanceof AAFAuthenticatedUser) + */ + @Test + public void test_method_authorize_0_branch_2() + { + System.out.println("Now Testing Method:authorize Branch:2"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_PermHolder_1_branch_0() + { + System.out.println("Now Testing Method:PermHolder Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_PermHolder_2_branch_0() + { + System.out.println("Now Testing Method:PermHolder Branch:0"); + + + + } + + /* + * Testing Conditon(s): if: (permissions==Permission.NONE) + */ + @Test + public void test_method_mutable_3_branch_0() + { + System.out.println("Now Testing Method:mutable Branch:0"); + + + + } + + /* + * Testing Conditon(s): else: Not (permissions==Permission.NONE) + */ + @Test + public void test_method_mutable_3_branch_1() + { + System.out.println("Now Testing Method:mutable Branch:1"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_mutable_4_branch_0() + { + System.out.println("Now Testing Method:mutable Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_mutable_5_branch_0() + { + System.out.println("Now Testing Method:mutable Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_6_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_exec_7_branch_0() + { + System.out.println("Now Testing Method:exec Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_8_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_exec_9_branch_0() + { + System.out.println("Now Testing Method:exec Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_10_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_exec_11_branch_0() + { + System.out.println("Now Testing Method:exec Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_12_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_exec_13_branch_0() + { + System.out.println("Now Testing Method:exec Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_14_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_exec_15_branch_0() + { + System.out.println("Now Testing Method:exec Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_16_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_exec_17_branch_0() + { + System.out.println("Now Testing Method:exec Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_getName_18_branch_0() + { + System.out.println("Now Testing Method:getName Branch:0"); + + //Constructor + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_exec_19_branch_0() + { + System.out.println("Now Testing Method:exec Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_grant_20_branch_0() + { + System.out.println("Now Testing Method:grant Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_revoke_21_branch_0() + { + System.out.println("Now Testing Method:revoke Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_list_22_branch_0() + { + System.out.println("Now Testing Method:list Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_revokeAll_23_branch_0() + { + System.out.println("Now Testing Method:revokeAll Branch:0"); + + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_revokeAll_24_branch_0() + { + System.out.println("Now Testing Method:revokeAll Branch:0"); + + + + } + +} diff --git a/cass/src/test/java/org/onap/aaf/cass/JU_AAFBaseTest.java b/cass/src/test/java/org/onap/aaf/cass/JU_AAFBaseTest.java new file mode 100644 index 0000000..172a3dc --- /dev/null +++ b/cass/src/test/java/org/onap/aaf/cass/JU_AAFBaseTest.java @@ -0,0 +1,399 @@ +/******************************************************************************* + * ============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.cass; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aaf.cadi.aaf.cass.AAFBase; + +import static org.junit.Assert.*; + +public class JU_AAFBaseTest +{ + + + @Before + public void setUp() + { + + } + + @After + public void tearDown() + { + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_setAccess_0_branch_0() + { + System.out.println("Now Testing Method:setAccess Branch:0"); + + //Call Method + AAFBase.setAccess(null); + + } + + /* + * Testing Conditon(s): if: (!props_ok) + */ + @Test + public void test_method_validateConfiguration_1_branch_0() + { + System.out.println("Now Testing Method:validateConfiguration Branch:0"); + + + + } + + /* + * Testing Conditon(s): else: Not (!props_ok) + */ + @Test + public void test_method_validateConfiguration_1_branch_1() + { + System.out.println("Now Testing Method:validateConfiguration Branch:1"); + + + + //Call Method + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (access==null), if: (cadi_props == null), if: (cp.exists()) + */ + @Test + public void test_method_setup_2_branch_0() + { + System.out.println("Now Testing Method:setup Branch:0"); + + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (access==null), if: (cadi_props == null), else: Not (cp.exists()) + */ + @Test + public void test_method_setup_2_branch_1() + { + System.out.println("Now Testing Method:setup Branch:1"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (access==null), else: Not (cadi_props == null) + */ + @Test + public void test_method_setup_2_branch_2() + { + System.out.println("Now Testing Method:setup Branch:2"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not (access==null) + */ + @Test + public void test_method_setup_2_branch_3() + { + System.out.println("Now Testing Method:setup Branch:3"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: ((perm_type = Config.logProp(access, "cass_group_name",null))==null) + */ + @Test + public void test_method_setup_2_branch_4() + { + System.out.println("Now Testing Method:setup Branch:4"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not ((perm_type = Config.logProp(access, "cass_group_name",null))==null) + */ + @Test + public void test_method_setup_2_branch_5() + { + System.out.println("Now Testing Method:setup Branch:5"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: ((cluster_name = Config.logProp(access,"cass_cluster_name",null))==null), if: ((cluster_name = DatabaseDescriptor.getClusterName())==null) + */ + @Test + public void test_method_setup_2_branch_6() + { + System.out.println("Now Testing Method:setup Branch:6"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: ((cluster_name = Config.logProp(access,"cass_cluster_name",null))==null), else: Not ((cluster_name = DatabaseDescriptor.getClusterName())==null) + */ + @Test + public void test_method_setup_2_branch_7() + { + System.out.println("Now Testing Method:setup Branch:7"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not ((cluster_name = Config.logProp(access,"cass_cluster_name",null))==null) + */ + @Test + public void test_method_setup_2_branch_8() + { + System.out.println("Now Testing Method:setup Branch:8"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: ((default_realm = Config.logProp(access, Config.AAF_DEFAULT_REALM, null))==null) + */ + @Test + public void test_method_setup_2_branch_9() + { + System.out.println("Now Testing Method:setup Branch:9"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not ((default_realm = Config.logProp(access, Config.AAF_DEFAULT_REALM, null))==null) + */ + @Test + public void test_method_setup_2_branch_10() + { + System.out.println("Now Testing Method:setup Branch:10"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (props_ok==false) + */ + @Test + public void test_method_setup_2_branch_11() + { + System.out.println("Now Testing Method:setup Branch:11"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not (props_ok==false) + */ + @Test + public void test_method_setup_2_branch_12() + { + System.out.println("Now Testing Method:setup Branch:12"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: (int i=0; (lur = elur.get(i))!=null;++i), if: (lur instanceof AbsAAFLur) + */ + @Test + public void test_method_setup_2_branch_13() + { + System.out.println("Now Testing Method:setup Branch:13"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: (int i=0; (lur = elur.get(i))!=null;++i), else: Not (lur instanceof AbsAAFLur), if: (lur instanceof LocalLur) + */ + @Test + public void test_method_setup_2_branch_14() + { + System.out.println("Now Testing Method:setup Branch:14"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: (int i=0; (lur = elur.get(i))!=null;++i), else: Not (lur instanceof AbsAAFLur), else: Not (lur instanceof LocalLur) + */ + @Test + public void test_method_setup_2_branch_15() + { + System.out.println("Now Testing Method:setup Branch:15"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (lur instanceof EpiLur), for: Not (int i=0; (lur = elur.get(i))!=null;++i) + */ + @Test + public void test_method_setup_2_branch_16() + { + System.out.println("Now Testing Method:setup Branch:16"); + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not (lur instanceof EpiLur), if: (lur instanceof AbsAAFLur) + */ + @Test + public void test_method_setup_2_branch_17() + { + System.out.println("Now Testing Method:setup Branch:17"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not (lur instanceof EpiLur), else: Not (lur instanceof AbsAAFLur) + */ + @Test + public void test_method_setup_2_branch_18() + { + System.out.println("Now Testing Method:setup Branch:18"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (aafAuthn==null) + */ + @Test + public void test_method_setup_2_branch_19() + { + System.out.println("Now Testing Method:setup Branch:19"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not (aafAuthn==null) + */ + @Test + public void test_method_setup_2_branch_20() + { + System.out.println("Now Testing Method:setup Branch:20"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), if: (access!=null) + */ + @Test + public void test_method_setup_2_branch_21() + { + System.out.println("Now Testing Method:setup Branch:21"); + + + + } + + /* + * Testing Conditon(s): if: (aafAuthn == null), else: Not (access!=null) + */ + @Test + public void test_method_setup_2_branch_22() + { + System.out.println("Now Testing Method:setup Branch:22"); + + + } + + /* + * Testing Conditon(s): else: Not (aafAuthn == null) + */ + @Test + public void test_method_setup_2_branch_23() + { + System.out.println("Now Testing Method:setup Branch:23"); + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_protectedResources_3_branch_0() + { + System.out.println("Now Testing Method:protectedResources Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_supportedOptions_4_branch_0() + { + System.out.println("Now Testing Method:supportedOptions Branch:0"); + + + } + + /* + * Testing Conditon(s): Default + */ + @Test + public void test_method_alterableOptions_5_branch_0() + { + System.out.println("Now Testing Method:alterableOptions Branch:0"); + + + + } + +} diff --git a/client/src/test/java/org/onap/aaf/cadi/dme2/DME2ClientSSTest.java b/client/src/test/java/org/onap/aaf/cadi/dme2/DME2ClientSSTest.java deleted file mode 100644 index 0971939..0000000 --- a/client/src/test/java/org/onap/aaf/cadi/dme2/DME2ClientSSTest.java +++ /dev/null @@ -1,55 +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.dme2; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; - -import javax.servlet.annotation.HttpMethodConstraint; - -import org.junit.Before; -import org.junit.Test; - -import com.att.aft.dme2.api.DME2Client; -import com.att.aft.dme2.api.DME2Exception; - -public class DME2ClientSSTest { - - - @Before - public void setUp() throws Exception { - } - - @Test - public void test() throws IOException, DME2Exception { - DME2ClientSS client = new DME2ClientSS(null, "user", "pass"); - - assertNotNull(client); - - assertEquals(client.getID(), "user"); - assertEquals(client.setLastResponse(0), 0); - } - -} diff --git a/client/src/test/java/org/onap/aaf/cadi/dme2/JU_DME2ClientSSTest.java b/client/src/test/java/org/onap/aaf/cadi/dme2/JU_DME2ClientSSTest.java new file mode 100644 index 0000000..a511344 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/cadi/dme2/JU_DME2ClientSSTest.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============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.dme2; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.annotation.HttpMethodConstraint; + +import org.junit.Before; +import org.junit.Test; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Exception; + +public class JU_DME2ClientSSTest { + + + @Before + public void setUp() throws Exception { + } + + @Test + public void test() throws IOException, DME2Exception { + DME2ClientSS client = new DME2ClientSS(null, "user", "pass"); + + assertNotNull(client); + + assertEquals(client.getID(), "user"); + assertEquals(client.setLastResponse(0), 0); + } + +} diff --git a/client/src/test/java/org/onap/aaf/cadi/http/HBasicAuthSSTest.java b/client/src/test/java/org/onap/aaf/cadi/http/HBasicAuthSSTest.java deleted file mode 100644 index 446585b..0000000 --- a/client/src/test/java/org/onap/aaf/cadi/http/HBasicAuthSSTest.java +++ /dev/null @@ -1,58 +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.http; - -import static org.junit.Assert.*; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -public class HBasicAuthSSTest { - - @Before - public void setUp() throws Exception { - } - - @Test - public void testHBasicAuthSSStringStringSecurityInfoCOfHttpURLConnection() throws IOException { - HBasicAuthSS basicAuth = new HBasicAuthSS("user", "pass", null); - - assertEquals(basicAuth.getID(), "user"); - assertFalse(basicAuth.isDenied()); - assertEquals(basicAuth.count(), 0); - assertEquals(basicAuth.setLastResponse(401), 1); - } - - @Test - public void testHBasicAuthSSStringStringSecurityInfoCOfHttpURLConnection1() throws IOException { - HBasicAuthSS basicAuth = new HBasicAuthSS("demo", "demopass", null); - - assertEquals(basicAuth.getID(), "demo"); - assertFalse(basicAuth.isDenied()); - assertEquals(basicAuth.count(), 0); - assertEquals(basicAuth.setLastResponse(401), 1); - } - -} diff --git a/client/src/test/java/org/onap/aaf/cadi/http/JU_HBasicAuthSSTest.java b/client/src/test/java/org/onap/aaf/cadi/http/JU_HBasicAuthSSTest.java new file mode 100644 index 0000000..d7c4857 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/cadi/http/JU_HBasicAuthSSTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============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.http; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +public class JU_HBasicAuthSSTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void testHBasicAuthSSStringStringSecurityInfoCOfHttpURLConnection() throws IOException { + HBasicAuthSS basicAuth = new HBasicAuthSS("user", "pass", null); + + assertEquals(basicAuth.getID(), "user"); + assertFalse(basicAuth.isDenied()); + assertEquals(basicAuth.count(), 0); + assertEquals(basicAuth.setLastResponse(401), 1); + } + + @Test + public void testHBasicAuthSSStringStringSecurityInfoCOfHttpURLConnection1() throws IOException { + HBasicAuthSS basicAuth = new HBasicAuthSS("demo", "demopass", null); + + assertEquals(basicAuth.getID(), "demo"); + assertFalse(basicAuth.isDenied()); + assertEquals(basicAuth.count(), 0); + assertEquals(basicAuth.setLastResponse(401), 1); + } + +} diff --git a/client/src/test/java/org/onap/aaf/client/test/BasicDME2Client.java b/client/src/test/java/org/onap/aaf/client/test/BasicDME2Client.java deleted file mode 100644 index 4619a0f..0000000 --- a/client/src/test/java/org/onap/aaf/client/test/BasicDME2Client.java +++ /dev/null @@ -1,61 +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.client.test; - -import java.net.URI; -import java.util.Properties; - -import com.att.aft.dme2.api.DME2Client; -import com.att.aft.dme2.api.DME2Manager; - -public class BasicDME2Client { - public static void main(String[] args) { - try { - Properties props = System.getProperties(); - - DME2Manager dm = new DME2Manager("DME2Manager TestBasicDME2Client",props); - URI uri = new URI(System.getProperty("aaf_url")); - DME2Client client = new DME2Client(dm,uri,3000); - - System.out.println(props.getProperty("aaf_id")); - client.setCredentials(props.getProperty("aaf_id"),props.getProperty("aaf_password")); - - String path = String.format("/authz/perms/user/%s@csp.att.com",args.length>0?args[0]:"xx9999"); - System.out.printf("Path: %s\n",path); - client.addHeader("Accept", "application/Perms+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*"); - client.setMethod("GET"); - client.setContext(path); - client.setPayload("");// Note: Even on "GET", you need a String in DME2 - - String o = client.sendAndWait(5000); // There are other Asynchronous call options, see DME2 Docs - if(o==null) { - System.out.println('[' + o + ']' + " (blank is good)"); - } - - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/client/src/test/java/org/onap/aaf/client/test/HolderTest.java b/client/src/test/java/org/onap/aaf/client/test/HolderTest.java deleted file mode 100644 index 32f021c..0000000 --- a/client/src/test/java/org/onap/aaf/client/test/HolderTest.java +++ /dev/null @@ -1,80 +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.client.test; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.aaf.cadi.client.Holder; - -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -public class HolderTest { - - @Test - public void testSet() { - Holder holder = new Holder("StringHolder"); - assertEquals(holder.get(), "StringHolder"); - - holder.set("New String"); - assertEquals(holder.get(), "New String"); - } - - @Test - public void testSet4() { - Holder holder = new Holder("StringHolder"); - assertEquals(holder.get(), "StringHolder"); - - holder.set("New String1"); - assertEquals(holder.get(), "New String1"); - } - @Test - public void testSet1() { - Holder holder = new Holder("StringHolder"); - assertEquals(holder.get(), "StringHolder"); - - holder.set("New String2"); - assertEquals(holder.get(), "New String2"); - } - - @Test - public void testSet2() { - Holder holder = new Holder("StringHolder"); - assertEquals(holder.get(), "StringHolder"); - - holder.set("New String3"); - assertEquals(holder.get(), "New String3"); - } - - @Test - public void testSet3() { - Holder holder = new Holder("StringHolder"); - assertEquals(holder.get(), "StringHolder"); - - holder.set("New String4"); - assertEquals(holder.get(), "New String4"); - } -} diff --git a/client/src/test/java/org/onap/aaf/client/test/JU_BasicDME2Client.java b/client/src/test/java/org/onap/aaf/client/test/JU_BasicDME2Client.java new file mode 100644 index 0000000..c6638a3 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/client/test/JU_BasicDME2Client.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============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.client.test; + +import java.net.URI; +import java.util.Properties; + +import com.att.aft.dme2.api.DME2Client; +import com.att.aft.dme2.api.DME2Manager; + +public class JU_BasicDME2Client { + public static void main(String[] args) { + try { + Properties props = System.getProperties(); + + DME2Manager dm = new DME2Manager("DME2Manager TestBasicDME2Client",props); + URI uri = new URI(System.getProperty("aaf_url")); + DME2Client client = new DME2Client(dm,uri,3000); + + System.out.println(props.getProperty("aaf_id")); + client.setCredentials(props.getProperty("aaf_id"),props.getProperty("aaf_password")); + + String path = String.format("/authz/perms/user/%s@csp.att.com",args.length>0?args[0]:"xx9999"); + System.out.printf("Path: %s\n",path); + client.addHeader("Accept", "application/Perms+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*"); + client.setMethod("GET"); + client.setContext(path); + client.setPayload("");// Note: Even on "GET", you need a String in DME2 + + String o = client.sendAndWait(5000); // There are other Asynchronous call options, see DME2 Docs + if(o==null) { + System.out.println('[' + o + ']' + " (blank is good)"); + } + + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/client/src/test/java/org/onap/aaf/client/test/JU_HolderTest.java b/client/src/test/java/org/onap/aaf/client/test/JU_HolderTest.java new file mode 100644 index 0000000..3250b61 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/client/test/JU_HolderTest.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * ============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.client.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.aaf.cadi.client.Holder; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class JU_HolderTest { + + @Test + public void testSet() { + Holder holder = new Holder("StringHolder"); + assertEquals(holder.get(), "StringHolder"); + + holder.set("New String"); + assertEquals(holder.get(), "New String"); + } + + @Test + public void testSet4() { + Holder holder = new Holder("StringHolder"); + assertEquals(holder.get(), "StringHolder"); + + holder.set("New String1"); + assertEquals(holder.get(), "New String1"); + } + @Test + public void testSet1() { + Holder holder = new Holder("StringHolder"); + assertEquals(holder.get(), "StringHolder"); + + holder.set("New String2"); + assertEquals(holder.get(), "New String2"); + } + + @Test + public void testSet2() { + Holder holder = new Holder("StringHolder"); + assertEquals(holder.get(), "StringHolder"); + + holder.set("New String3"); + assertEquals(holder.get(), "New String3"); + } + + @Test + public void testSet3() { + Holder holder = new Holder("StringHolder"); + assertEquals(holder.get(), "StringHolder"); + + holder.set("New String4"); + assertEquals(holder.get(), "New String4"); + } +} diff --git a/client/src/test/java/org/onap/aaf/client/test/JU_PaulUzee.java b/client/src/test/java/org/onap/aaf/client/test/JU_PaulUzee.java new file mode 100644 index 0000000..ca0a743 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/client/test/JU_PaulUzee.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * ============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.client.test; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.net.URI; +import java.util.Properties; + +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Locator; +import org.onap.aaf.cadi.Access.Level; +import org.onap.aaf.cadi.Locator.Item; +import org.onap.aaf.cadi.dme2.DME2Locator; + +import com.att.aft.dme2.api.DME2Manager; + +public class JU_PaulUzee { + public static void main(String[] args) { + try { + // You'll want to put this on Command line "-D" probably + Properties props = System.getProperties(); + props.put("AFT_LATITUDE","32.780140"); + props.put("AFT_LONGITUDE","-96.800451"); + props.put("AFT_ENVIRONMENT","AFTPRD"); + + // + // Use an "Access" class to hook up logging, properties, etc. + // Make one that ties into your code's logging, property mechanism, etc. + // + Access access = new PaulAccess(); + + DME2Manager dm = new DME2Manager("Paul Uzee's Test",props); + Locator loc = new DME2Locator(access ,dm,"com.att.authz.AuthorizationService","2.0","PROD","DEFAULT"); + + + for(Item item = loc.first(); item!=null; item=loc.next(item)) { + URI location = (URI) loc.get(item); + access.log(Level.INFO,location); + access.log(Level.INFO,location.getScheme()); + access.log(Level.INFO,location.getHost()); + access.log(Level.INFO, location.getPort()); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private static class PaulAccess implements Access { + private Level willWrite = Level.INFO; + + @Override + public ClassLoader classLoader() { + return getClass().getClassLoader(); + } + + @Override + public String decrypt(String data, boolean def) throws IOException { + return data; + } + + @Override + public String getProperty(String tag, String def) { + return System.getProperty(tag, def); + } + + @Override + public void load(InputStream is) throws IOException { + System.getProperties().load(is); + } + + @Override + public void log(Level level, Object... obj) { + if(level.compareTo(willWrite)<0) return; + PrintStream ps; + switch(level) { + case DEBUG: + case AUDIT: + case ERROR: + case WARN: + ps = System.err; + break; + case INFO: + case INIT: + default: + ps = System.out; + } + boolean first = true; + for(Object o : obj) { + if(first)first=false; + else ps.print(' '); + ps.print(o.toString()); + } + ps.println(); + } + + @Override + public void log(Exception e, Object... obj) { + Object[] objs = new Object[obj.length+1]; + objs[0]=e.getMessage(); + System.arraycopy(objs, 1, obj, 0, obj.length); + log(Level.ERROR,e,objs); + } + + @Override + public void setLogLevel(Level l) { + willWrite = l; + } + + /* (non-Javadoc) + * @see com.att.cadi.Access#willLog(com.att.cadi.Access.Level) + */ + @Override + public boolean willLog(Level level) { + return true; + } + + @Override + public void printf(Level level, String fmt, Object... elements) { + // TODO Auto-generated method stub + + } + }; +} diff --git a/client/src/test/java/org/onap/aaf/client/test/JU_ResultTest.java b/client/src/test/java/org/onap/aaf/client/test/JU_ResultTest.java new file mode 100644 index 0000000..ae16f78 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/client/test/JU_ResultTest.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * ============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.client.test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.onap.aaf.cadi.client.Result; + +public class JU_ResultTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void testOk() { + Result t = Result.ok(1, "Ok"); + assertNotNull(t); + assertThat(t.code, is(1)); + assertTrue(t.isOK()); + assertThat(t.toString(), is("Code: 1")); + } + + @Test + public void testErr() { + Result t = Result.err(1, "Error Body"); + assertNotNull(t); + assertThat(t.error, is("Error Body")); + assertFalse(t.isOK()); + assertThat(t.toString(), is("Code: 1 = Error Body")); + } + + @Test + public void testOk1() { + Result t = Result.ok(1, "Ok"); + assertNotNull(t); + assertThat(t.code, is(1)); + assertTrue(t.isOK()); + assertThat(t.toString(), is("Code: 1")); + } + + @Test + public void testErr1() { + Result t = Result.err(1, "Error Body"); + assertNotNull(t); + assertThat(t.error, is("Error Body")); + assertFalse(t.isOK()); + assertThat(t.toString(), is("Code: 1 = Error Body")); + } + + @Test + public void testOk2() { + Result t = Result.ok(1, "Ok"); + assertNotNull(t); + assertThat(t.code, is(1)); + assertTrue(t.isOK()); + assertThat(t.toString(), is("Code: 1")); + } + + @Test + public void testErr2() { + Result t = Result.err(1, "Error Body"); + assertNotNull(t); + assertThat(t.error, is("Error Body")); + assertFalse(t.isOK()); + assertThat(t.toString(), is("Code: 1 = Error Body")); + } + + @Test + public void testOk3() { + Result t = Result.ok(1, "Ok"); + assertNotNull(t); + assertThat(t.code, is(1)); + assertTrue(t.isOK()); + assertThat(t.toString(), is("Code: 1")); + } + + @Test + public void testErr3() { + Result t = Result.err(1, "Error Body"); + assertNotNull(t); + assertThat(t.error, is("Error Body")); + assertFalse(t.isOK()); + assertThat(t.toString(), is("Code: 1 = Error Body")); + } +} diff --git a/client/src/test/java/org/onap/aaf/client/test/JU_TestAccess.java b/client/src/test/java/org/onap/aaf/client/test/JU_TestAccess.java new file mode 100644 index 0000000..266f702 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/client/test/JU_TestAccess.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============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.client.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 void log(Level level, Object... elements) { + boolean first = true; + for(int i=0;i ft = client.read("/authz/nss/com.att.aaf","text/json"); + if(ft.get(10000)) { + System.out.println("Hurray,\n"+ft.body()); + } else { + System.out.println("not quite: " + ft.code()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/client/src/test/java/org/onap/aaf/client/test/JU_TestHClient.java b/client/src/test/java/org/onap/aaf/client/test/JU_TestHClient.java new file mode 100644 index 0000000..5340380 --- /dev/null +++ b/client/src/test/java/org/onap/aaf/client/test/JU_TestHClient.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============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.client.test; + +import java.net.HttpURLConnection; +import java.net.URI; +import java.util.Properties; + +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.Locator; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.SecuritySetter; +import org.onap.aaf.cadi.Locator.Item; +import org.onap.aaf.cadi.client.Future; +import org.onap.aaf.cadi.client.Rcli; +import org.onap.aaf.cadi.client.Retryable; +import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.config.SecurityInfoC; +import org.onap.aaf.cadi.http.HBasicAuthSS; +import org.onap.aaf.cadi.http.HMangr; +import org.onap.aaf.cadi.locator.DME2Locator; + +import com.att.aft.dme2.api.DME2Manager; +import org.onap.aaf.inno.env.APIException; + +public class JU_TestHClient { + public static void main(String[] args) { + try { + PropAccess access = new PropAccess(); + DME2Manager dm = new DME2Manager("DME2Manager TestHClient",access.getProperties()); + Locator loc = new DME2Locator(access,dm,"com.att.authz.AuthorizationService","2.0","DEV","BAU_SE"); + + for(Item item = loc.first(); item!=null; item=loc.next(item)) { + System.out.println(loc.get(item)); + } + + + SecurityInfoC si = new SecurityInfoC(access); + SecuritySetter ss = new HBasicAuthSS("m12345@aaf.att.com", + access.decrypt("enc:7K6yjLQqha_S9yApkIul2K_by5Moemcos1HRAVnhMXu",false), si); +// SecuritySetter ss = new X509SS(si, "aaf"); + + HMangr hman = new HMangr(access,loc); + try { + hman.best(ss, new Retryable() { + @Override + public Void code(Rcli cli) throws APIException, CadiException { + Future ft = cli.read("/authz/nss/com.att.aaf","text/json"); + if(ft.get(10000)) { + System.out.println("Hurray,\n"+ft.body()); + } else { + System.out.println("not quite: " + ft.code()); + } + return null; + }}); + } finally { + hman.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/client/src/test/java/org/onap/aaf/client/test/PaulUzee.java b/client/src/test/java/org/onap/aaf/client/test/PaulUzee.java deleted file mode 100644 index 4bec3fd..0000000 --- a/client/src/test/java/org/onap/aaf/client/test/PaulUzee.java +++ /dev/null @@ -1,146 +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.client.test; - -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.net.URI; -import java.util.Properties; - -import org.onap.aaf.cadi.Access; -import org.onap.aaf.cadi.Locator; -import org.onap.aaf.cadi.Access.Level; -import org.onap.aaf.cadi.Locator.Item; -import org.onap.aaf.cadi.dme2.DME2Locator; - -import com.att.aft.dme2.api.DME2Manager; - -public class PaulUzee { - public static void main(String[] args) { - try { - // You'll want to put this on Command line "-D" probably - Properties props = System.getProperties(); - props.put("AFT_LATITUDE","32.780140"); - props.put("AFT_LONGITUDE","-96.800451"); - props.put("AFT_ENVIRONMENT","AFTPRD"); - - // - // Use an "Access" class to hook up logging, properties, etc. - // Make one that ties into your code's logging, property mechanism, etc. - // - Access access = new PaulAccess(); - - DME2Manager dm = new DME2Manager("Paul Uzee's Test",props); - Locator loc = new DME2Locator(access ,dm,"com.att.authz.AuthorizationService","2.0","PROD","DEFAULT"); - - - for(Item item = loc.first(); item!=null; item=loc.next(item)) { - URI location = (URI) loc.get(item); - access.log(Level.INFO,location); - access.log(Level.INFO,location.getScheme()); - access.log(Level.INFO,location.getHost()); - access.log(Level.INFO, location.getPort()); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - private static class PaulAccess implements Access { - private Level willWrite = Level.INFO; - - @Override - public ClassLoader classLoader() { - return getClass().getClassLoader(); - } - - @Override - public String decrypt(String data, boolean def) throws IOException { - return data; - } - - @Override - public String getProperty(String tag, String def) { - return System.getProperty(tag, def); - } - - @Override - public void load(InputStream is) throws IOException { - System.getProperties().load(is); - } - - @Override - public void log(Level level, Object... obj) { - if(level.compareTo(willWrite)<0) return; - PrintStream ps; - switch(level) { - case DEBUG: - case AUDIT: - case ERROR: - case WARN: - ps = System.err; - break; - case INFO: - case INIT: - default: - ps = System.out; - } - boolean first = true; - for(Object o : obj) { - if(first)first=false; - else ps.print(' '); - ps.print(o.toString()); - } - ps.println(); - } - - @Override - public void log(Exception e, Object... obj) { - Object[] objs = new Object[obj.length+1]; - objs[0]=e.getMessage(); - System.arraycopy(objs, 1, obj, 0, obj.length); - log(Level.ERROR,e,objs); - } - - @Override - public void setLogLevel(Level l) { - willWrite = l; - } - - /* (non-Javadoc) - * @see com.att.cadi.Access#willLog(com.att.cadi.Access.Level) - */ - @Override - public boolean willLog(Level level) { - return true; - } - - @Override - public void printf(Level level, String fmt, Object... elements) { - // TODO Auto-generated method stub - - } - }; -} diff --git a/client/src/test/java/org/onap/aaf/client/test/ResultTest.java b/client/src/test/java/org/onap/aaf/client/test/ResultTest.java deleted file mode 100644 index af70558..0000000 --- a/client/src/test/java/org/onap/aaf/client/test/ResultTest.java +++ /dev/null @@ -1,109 +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.client.test; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; -import org.onap.aaf.cadi.client.Result; - -public class ResultTest { - - @Before - public void setUp() throws Exception { - } - - @Test - public void testOk() { - Result t = Result.ok(1, "Ok"); - assertNotNull(t); - assertThat(t.code, is(1)); - assertTrue(t.isOK()); - assertThat(t.toString(), is("Code: 1")); - } - - @Test - public void testErr() { - Result t = Result.err(1, "Error Body"); - assertNotNull(t); - assertThat(t.error, is("Error Body")); - assertFalse(t.isOK()); - assertThat(t.toString(), is("Code: 1 = Error Body")); - } - - @Test - public void testOk1() { - Result t = Result.ok(1, "Ok"); - assertNotNull(t); - assertThat(t.code, is(1)); - assertTrue(t.isOK()); - assertThat(t.toString(), is("Code: 1")); - } - - @Test - public void testErr1() { - Result t = Result.err(1, "Error Body"); - assertNotNull(t); - assertThat(t.error, is("Error Body")); - assertFalse(t.isOK()); - assertThat(t.toString(), is("Code: 1 = Error Body")); - } - - @Test - public void testOk2() { - Result t = Result.ok(1, "Ok"); - assertNotNull(t); - assertThat(t.code, is(1)); - assertTrue(t.isOK()); - assertThat(t.toString(), is("Code: 1")); - } - - @Test - public void testErr2() { - Result t = Result.err(1, "Error Body"); - assertNotNull(t); - assertThat(t.error, is("Error Body")); - assertFalse(t.isOK()); - assertThat(t.toString(), is("Code: 1 = Error Body")); - } - - @Test - public void testOk3() { - Result t = Result.ok(1, "Ok"); - assertNotNull(t); - assertThat(t.code, is(1)); - assertTrue(t.isOK()); - assertThat(t.toString(), is("Code: 1")); - } - - @Test - public void testErr3() { - Result t = Result.err(1, "Error Body"); - assertNotNull(t); - assertThat(t.error, is("Error Body")); - assertFalse(t.isOK()); - assertThat(t.toString(), is("Code: 1 = Error Body")); - } -} diff --git a/client/src/test/java/org/onap/aaf/client/test/TestAccess.java b/client/src/test/java/org/onap/aaf/client/test/TestAccess.java deleted file mode 100644 index c054bc0..0000000 --- a/client/src/test/java/org/onap/aaf/client/test/TestAccess.java +++ /dev/null @@ -1,90 +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.client.test; - -import java.io.IOException; -import java.io.InputStream; - -import org.onap.aaf.cadi.Access; -import org.onap.aaf.cadi.Symm; - -public class TestAccess implements Access { - private Symm symm; - - public TestAccess() { - symm = Symm.obtain(this); - } - - public void log(Level level, Object... elements) { - boolean first = true; - for(int i=0;i ft = client.read("/authz/nss/com.att.aaf","text/json"); - if(ft.get(10000)) { - System.out.println("Hurray,\n"+ft.body()); - } else { - System.out.println("not quite: " + ft.code()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/client/src/test/java/org/onap/aaf/client/test/TestHClient.java b/client/src/test/java/org/onap/aaf/client/test/TestHClient.java deleted file mode 100644 index 2476caf..0000000 --- a/client/src/test/java/org/onap/aaf/client/test/TestHClient.java +++ /dev/null @@ -1,84 +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.client.test; - -import java.net.HttpURLConnection; -import java.net.URI; -import java.util.Properties; - -import org.onap.aaf.cadi.CadiException; -import org.onap.aaf.cadi.Locator; -import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.SecuritySetter; -import org.onap.aaf.cadi.Locator.Item; -import org.onap.aaf.cadi.client.Future; -import org.onap.aaf.cadi.client.Rcli; -import org.onap.aaf.cadi.client.Retryable; -import org.onap.aaf.cadi.config.Config; -import org.onap.aaf.cadi.config.SecurityInfoC; -import org.onap.aaf.cadi.http.HBasicAuthSS; -import org.onap.aaf.cadi.http.HMangr; -import org.onap.aaf.cadi.locator.DME2Locator; - -import com.att.aft.dme2.api.DME2Manager; -import org.onap.aaf.inno.env.APIException; - -public class TestHClient { - public static void main(String[] args) { - try { - PropAccess access = new PropAccess(); - DME2Manager dm = new DME2Manager("DME2Manager TestHClient",access.getProperties()); - Locator loc = new DME2Locator(access,dm,"com.att.authz.AuthorizationService","2.0","DEV","BAU_SE"); - - for(Item item = loc.first(); item!=null; item=loc.next(item)) { - System.out.println(loc.get(item)); - } - - - SecurityInfoC si = new SecurityInfoC(access); - SecuritySetter ss = new HBasicAuthSS("m12345@aaf.att.com", - access.decrypt("enc:7K6yjLQqha_S9yApkIul2K_by5Moemcos1HRAVnhMXu",false), si); -// SecuritySetter ss = new X509SS(si, "aaf"); - - HMangr hman = new HMangr(access,loc); - try { - hman.best(ss, new Retryable() { - @Override - public Void code(Rcli cli) throws APIException, CadiException { - Future ft = cli.read("/authz/nss/com.att.aaf","text/json"); - if(ft.get(10000)) { - System.out.println("Hurray,\n"+ft.body()); - } else { - System.out.println("not quite: " + ft.code()); - } - return null; - }}); - } finally { - hman.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - -} 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