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 --- .../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 ------------ 20 files changed, 860 insertions(+), 860 deletions(-) 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 (limited to 'client') 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(); - } - } - -} -- cgit 1.2.3-korg