xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <!--<parent>
+ <parent>
<groupId>org.onap.aaf.authz</groupId>
<artifactId>parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
- </parent> -->
+ </parent>
<artifactId>authparent</artifactId>
<name>AAF Auth Parent</name>
<packaging>pom</packaging>
- <parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>1.1.0</version>
- </parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
* If you want a simple field comparison, it is faster without REGEX
*/
public boolean match(Permission p) {
+ boolean rv;
+ String aafType;
+ String aafInstance;
+ String aafAction;
if(p instanceof AAFPermission) {
AAFPermission ap = (AAFPermission)p;
// Note: In AAF > 1.0, Accepting "*" from name would violate multi-tenancy
// Current solution is only allow direct match on Type.
// 8/28/2014 Jonathan - added REGEX ability
- if(type.equals(ap.getName()))
- if(PermEval.evalInstance(instance,ap.getInstance()))
- if(PermEval.evalAction(action,ap.getAction()))
- return true;
+ aafType = ap.getName();
+ aafInstance = ap.getInstance();
+ aafAction = ap.getAction();
} else {
// Permission is concatenated together: separated by |
String[] aaf = p.getKey().split("[\\s]*\\|[\\s]*",3);
- if(aaf.length>0 && type.equals(aaf[0]))
- if(PermEval.evalInstance(instance,aaf.length>1?aaf[1]:"*"))
- if(PermEval.evalAction(action,aaf.length>2?aaf[2]:"*"))
- return true;
- }
- return false;
+ aafType = aaf[0];
+ aafInstance = (aaf.length > 1) ? aaf[1] : "*";
+ aafAction = (aaf.length > 2) ? aaf[2] : "*";
+ }
+ return ((type.equals(aafType)) &&
+ (PermEval.evalInstance(instance, aafInstance)) &&
+ (PermEval.evalAction(action, aafAction)));
}
public String getName() {
* 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.
public static final char START_REGEX_CHAR = '!';
public static final char START_INST_KEY_CHAR=':';
public static final char ALT_START_INST_KEY_CHAR='/';
-
+
public static final char LIST_SEP = ',';
public static final String INST_KEY_REGEX = new StringBuilder().append(START_INST_KEY_CHAR).toString();
public static final String ASTERIX = "*";
-
+
/**
* Evaluate Instance
- *
- * Instance can be more complex. It can be a string, a Regular Expression, or a ":" separated Key
+ *
+ * Instance can be more complex. It can be a string, a Regular Expression, or a ":" separated Key
* who's parts can also be a String, Regular Expression.
- *
+ *
* sInst = Server's Instance
* In order to prevent false matches, keys must be the same length to count as equal
* Changing this will break existing users, like Cassandra. Jonathan 9-4-2015
*/
- public static boolean evalInstance(String sInst, String pInst) {
- if(sInst==null || pInst == null) {
- return false;
- }
- if(ASTERIX.equals(sInst)) {
- return true; // If Server's String is "*", then it accepts every Instance
- }
- char firstChar = pInst.charAt(0);
- char startChar = firstChar==ALT_START_INST_KEY_CHAR?ALT_START_INST_KEY_CHAR:START_INST_KEY_CHAR;
- switch(pInst.charAt(0)) { // First char
- case START_REGEX_CHAR: // Evaluate as Regular Expression
- String pItem = pInst.substring(1);
- for(String sItem : Split.split(LIST_SEP,sInst)) { // allow for "," definition in Action
- return sItem.matches(pItem);
- }
-
- case START_INST_KEY_CHAR: // Evaluate a special Key field, i.e.:xyz:*:!df.*
- case ALT_START_INST_KEY_CHAR: // Also allow '/' as special Key Field, i.e. /xyz/*/!.*
- if(sInst.charAt(0)==startChar) { // To compare key-to-key, both strings must be keys
- String[] skeys=Split.split(startChar,sInst);
- String[] pkeys=Split.split(startChar,pInst);
- if(skeys.length!=pkeys.length) return false;
-
- boolean pass = true;
- for(int i=1;pass && i<skeys.length;++i) { // We start at 1, because the first one, being ":" is always ""
- if(ASTERIX.equals(skeys[i]))continue; // Server data accepts all for this key spot
- pass = false;
- for(String sItem : Split.split(LIST_SEP,skeys[i])) { // allow for "," definition in Action
- if(pkeys[i].length()==0) {
- if(pass=sItem.length()==0) {
- break; // Both Empty, keep checking
- }
-// } else if(pkeys[i].charAt(0)==START_REGEX_CHAR) {
-// if(pass=sItem.matches(pkeys[i].substring(1))) {
-// break; // Matches, keep checking
-// }
- } else if(sItem.charAt(0)==START_REGEX_CHAR) { // Check Server side when wildcarding like *
- if(pass=pkeys[i].matches(sItem.substring(1))) {
- break; // Matches, keep checking
- }
- } else if(skeys[i].endsWith(ASTERIX)) {
- if(pass=endAsterixCompare(skeys[i],pkeys[i])) {
- break;
- }
- } else {
- if(pass=sItem.equals(pkeys[i]))
- break; // Equal, keep checking
- }
- }
- }
- return pass; // return whether passed all key checks
- }
- return false; // if first chars aren't the same, further String compare not necessary
- default: // Evaluate as String Compare
- for(String sItem : Split.split(LIST_SEP,sInst)) { // allow for "," separator //TODO is this only for actions?
- if(sItem.endsWith(ASTERIX)) {
- if(endAsterixCompare(sInst, pInst));
- } else if(sItem.equals(pInst)) {
- return true;
- }
- }
- return false;
- }
- }
-
+ public static boolean evalInstance(String sInst, String pInst) {
+ if(sInst == null || pInst == null) {
+ return false;
+ }
+ if (sInst == "" || pInst == "") {
+ return false;
+ }
+ if(ASTERIX.equals(sInst)) {
+ return true; // If Server's String is "*", then it accepts every Instance
+ }
+ char firstChar = pInst.charAt(0);
+ char startChar = firstChar==ALT_START_INST_KEY_CHAR?ALT_START_INST_KEY_CHAR:START_INST_KEY_CHAR;
+ switch(pInst.charAt(0)) { // First char
+ case START_REGEX_CHAR: // Evaluate as Regular Expression
+ String pItem = pInst.substring(1);
+ String first = Split.split(LIST_SEP,sInst)[0]; // allow for "," definition in Action
+ return first.matches(pItem);
+
+ case START_INST_KEY_CHAR: // Evaluate a special Key field, i.e.:xyz:*:!df.*
+ case ALT_START_INST_KEY_CHAR: // Also allow '/' as special Key Field, i.e. /xyz/*/!.*
+ if(sInst.charAt(0)==startChar) { // To compare key-to-key, both strings must be keys
+ String[] skeys=Split.split(startChar,sInst);
+ String[] pkeys=Split.split(startChar,pInst);
+ if(skeys.length!=pkeys.length) return false;
+
+ boolean pass = true;
+ for(int i=1;pass && i<skeys.length;++i) { // We start at 1, because the first one, being ":" is always ""
+ if(ASTERIX.equals(skeys[i]))continue; // Server data accepts all for this key spot
+ pass = false;
+ for(String sItem : Split.split(LIST_SEP,skeys[i])) { // allow for "," definition in Action
+ if(pkeys[i].length()==0) {
+ if(pass=sItem.length()==0) {
+ break; // Both Empty, keep checking
+ }
+ } else if(sItem.charAt(0)==START_REGEX_CHAR) { // Check Server side when wildcarding like *
+ if(pass=pkeys[i].matches(sItem.substring(1))) {
+ break; // Matches, keep checking
+ }
+ } else if(skeys[i].endsWith(ASTERIX)) {
+ if(pass=endAsterixCompare(skeys[i],pkeys[i])) {
+ break;
+ }
+ } else if(pass=sItem.equals(pkeys[i])) {
+ break; // Equal, keep checking
+ }
+ }
+ }
+ return pass; // return whether passed all key checks
+ }
+ return false; // if first chars aren't the same, further String compare not necessary
+ default: // Evaluate as String Compare
+ for(String sItem : Split.split(LIST_SEP,sInst)) { // allow for "," separator //TODO is this only for actions?
+ if((sItem.endsWith(ASTERIX)) && (endAsterixCompare(sInst, pInst))) {
+ return true;
+ } else if(sItem.equals(pInst)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
private static boolean endAsterixCompare(String sInst, String pInst) {
- final int len = sInst.length()-1;
- if(pInst.length()<len) {
+ final int len = sInst.length()-1;
+ if(pInst.length()<len) {
+ return false;
+ }
+ for(int j=0;j<len;++j) {
+ if(pInst.charAt(j)!=sInst.charAt(j)) {
return false;
}
- for(int j=0;j<len;++j) {
- if(pInst.charAt(j)!=sInst.charAt(j)) {
- return false;
- }
- }
- return true;
+ }
+ return true;
}
/**
- * Evaluate Action
- *
- * sAction = Stored Action...
- * pAction = Present Action... the Permission to validate against.
- * Action is not quite as complex. But we write it in this function so it can be consistent
- */
- public static boolean evalAction(String sAction,String pAction) {
- if(ASTERIX.equals(sAction))return true; // If Server's String is "*", then it accepts every Action
- for(String sItem : Split.split(LIST_SEP,sAction)) { // allow for "," definition in Action
- if (pAction.charAt(0)==START_REGEX_CHAR? // First char
- sItem.matches(pAction.substring(1)): // Evaluate as Regular Expression
- sItem.equals(pAction)) // Evaluate as String Compare
- return true;
- }
- return false;
- }
-
- /**
- * Split.split by Char
- *
- * Note: I read the String Split.split and Pattern Split.split code, and we can do this more efficiently for a single Character
- */
+ * Evaluate Action
+ *
+ * sAction = Stored Action...
+ * pAction = Present Action... the Permission to validate against.
+ * Action is not quite as complex. But we write it in this function so it can be consistent
+ */
+ public static boolean evalAction(String sAction,String pAction) {
+ if(ASTERIX.equals(sAction))return true; // If Server's String is "*", then it accepts every Action
+ if(pAction == "") return false;
+ for(String sItem : Split.split(LIST_SEP,sAction)) { // allow for "," definition in Action
+ if (pAction.charAt(0)==START_REGEX_CHAR? // First char
+ sItem.matches(pAction.substring(1)): // Evaluate as Regular Expression
+ sItem.equals(pAction)) // Evaluate as String Compare
+ return true;
+ }
+ return false;
+ }
}
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.Answers;
private Error error;
private Future<?> future;
+
+ private ByteArrayOutputStream errStream;
@Before
public void setUp() throws Exception {
error.setText("Error Text");
errMessage = new ErrMessage(env);
-
+ errStream = new ByteArrayOutputStream();
}
@Test
public void testPrintErrMessage() throws APIException {
when(errDF.newData().in(TYPE.JSON).load(attErrJson).asObject()).thenReturn(error);
- errMessage.printErr(System.out, attErrJson);
+ errMessage.printErr(new PrintStream(errStream), attErrJson);
+ assertEquals("Error Message Id Error Text\n", errStream.toString());
}
@Test
--- /dev/null
+/*******************************************************************************
+ * ============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====================================================
+ * *
+ * *
+ ******************************************************************************/
+
+package org.onap.aaf.cadi.aaf.test;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
+import org.onap.aaf.cadi.Permission;
+import org.onap.aaf.cadi.aaf.AAFPermission;
+
+public class JU_AAFPermission {
+
+ private final static String type = "type";
+ private final static String instance = "instance";
+ private final static String action = "action";
+ private final static String key = type + '|' + instance + '|' + action;
+ private final static String role = "role";
+
+ private static List<String> roles;
+
+ @Before
+ public void setup() {
+ roles = new ArrayList<String>();
+ roles.add(role);
+ }
+
+ @Test
+ public void constructor1Test() {
+ AAFPermission perm = new AAFPermission(type, instance, action);
+ assertThat(perm.getName(), is(type));
+ assertThat(perm.getInstance(), is(instance));
+ assertThat(perm.getAction(), is(action));
+ assertThat(perm.getKey(), is(key));
+ assertThat(perm.permType(), is("AAF"));
+ assertThat(perm.roles().size(), is(0));
+ assertThat(perm.toString(), is("AAFPermission:\n\tType: " + type +
+ "\n\tInstance: " + instance +
+ "\n\tAction: " + action +
+ "\n\tKey: " + key));
+ }
+
+ @Test
+ public void constructor2Test() {
+ AAFPermission perm;
+
+ perm = new AAFPermission(type, instance, action, null);
+ assertThat(perm.getName(), is(type));
+ assertThat(perm.getInstance(), is(instance));
+ assertThat(perm.getAction(), is(action));
+ assertThat(perm.getKey(), is(key));
+ assertThat(perm.permType(), is("AAF"));
+ assertThat(perm.roles().size(), is(0));
+ assertThat(perm.toString(), is("AAFPermission:\n\tType: " + type +
+ "\n\tInstance: " + instance +
+ "\n\tAction: " + action +
+ "\n\tKey: " + key));
+
+ perm = new AAFPermission(type, instance, action, roles);
+ assertThat(perm.getName(), is(type));
+ assertThat(perm.getInstance(), is(instance));
+ assertThat(perm.getAction(), is(action));
+ assertThat(perm.getKey(), is(key));
+ assertThat(perm.permType(), is("AAF"));
+ assertThat(perm.roles().size(), is(1));
+ assertThat(perm.roles().get(0), is(role));
+ assertThat(perm.toString(), is("AAFPermission:\n\tType: " + type +
+ "\n\tInstance: " + instance +
+ "\n\tAction: " + action +
+ "\n\tKey: " + key));
+ }
+
+ @Test
+ public void matchTest() {
+ final AAFPermission controlPermission = new AAFPermission(type, instance, action);
+ PermissionStub perm;
+ AAFPermission aafperm;
+
+ aafperm = new AAFPermission(type, instance, action);
+ assertThat(controlPermission.match(aafperm), is(true));
+
+ perm = new PermissionStub(key);
+ assertThat(controlPermission.match(perm), is(true));
+
+ // Coverage tests
+ perm = new PermissionStub("not a valid key");
+ assertThat(controlPermission.match(perm), is(false));
+ perm = new PermissionStub("type");
+ assertThat(controlPermission.match(perm), is(false));
+ perm = new PermissionStub("type|instance|badAction");
+ assertThat(controlPermission.match(perm), is(false));
+ }
+
+ @Test
+ public void coverageTest() {
+ AAFPermissionStub aafps = new AAFPermissionStub();
+ assertThat(aafps.getName(), is(nullValue()));
+ assertThat(aafps.getInstance(), is(nullValue()));
+ assertThat(aafps.getAction(), is(nullValue()));
+ assertThat(aafps.getKey(), is(nullValue()));
+ assertThat(aafps.permType(), is("AAF"));
+ assertThat(aafps.roles().size(), is(0));
+ }
+
+ private class PermissionStub implements Permission {
+ private String key;
+
+ public PermissionStub(String key) { this.key = key; }
+ @Override public String permType() { return null; }
+ @Override public String getKey() { return key; }
+ @Override public boolean match(Permission p) { return false; }
+ }
+
+ private class AAFPermissionStub extends AAFPermission {
+
+ }
+}
* 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.
package org.onap.aaf.cadi.aaf.test;
import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
-import org.junit.AfterClass;
-import org.junit.Test;
import org.onap.aaf.cadi.aaf.PermEval;
public class JU_PermEval {
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
+ @Test
+ public void instanceNullTest() {
+ assertThat(PermEval.evalInstance(null, null), is(false));
+ assertThat(PermEval.evalInstance(null, "test"), is(false));
+ assertThat(PermEval.evalInstance("test", null), is(false));
}
@Test
- public void test() {
- // TRUE
- assertTrue(PermEval.evalAction("fred","fred"));
- assertTrue(PermEval.evalAction("fred,wilma","fred"));
- assertTrue(PermEval.evalAction("barney,betty,fred,wilma","fred"));
- assertTrue(PermEval.evalAction("*","fred"));
-
- assertTrue(PermEval.evalInstance("fred","fred"));
- assertTrue(PermEval.evalInstance("fred,wilma","fred"));
- assertTrue(PermEval.evalInstance("barney,betty,fred,wilma","fred"));
+ public void instanceEmptyTest() {
+ assertThat(PermEval.evalInstance("", ""), is(false));
+ assertThat(PermEval.evalInstance("", "test"), is(false));
+ assertThat(PermEval.evalInstance("test", ""), is(false));
+ }
+
+ @Test
+ public void instanceAsterixTest() {
+ assertThat(PermEval.evalInstance("*", "*"), is(true));
assertTrue(PermEval.evalInstance("*","fred"));
-
+ }
+
+ @Test
+ public void instanceRegexTest() {
+ assertThat(PermEval.evalInstance("test", "!test"), is(true));
+ assertThat(PermEval.evalInstance(",", "!"), is(true));
+ assertThat(PermEval.evalInstance("test,test", "!test"), is(true));
+
+ assertThat(PermEval.evalInstance("test", "!"), is(false));
+ assertThat(PermEval.evalInstance("test", "!mismatch"), is(false));
+ assertThat(PermEval.evalInstance("test,mismatch", "!mismatch"), is(false));
+ }
+
+ @Test
+ public void instanceKeyTest() {
+ // Reject non-keys
+ assertThat(PermEval.evalInstance("fred", ":fred"), is(false));
+
+ // Reject differing number of keys
+ assertThat(PermEval.evalInstance(":fred:barney", ":fred"), is(false));
+ assertThat(PermEval.evalInstance(":fred", ":fred:barney"), is(false));
+
+ // Accept all wildcard keys
+ assertThat(PermEval.evalInstance(":*", ":fred"), is(true));
+
+ // Accept matching empty keys
+ assertThat(PermEval.evalInstance(":", ":"), is(true));
+
+ // Reject non-matching empty keys
+ assertThat(PermEval.evalInstance(":fred", ":"), is(false));
+
+ // Accept matches starting with a wildcard
+ assertThat(PermEval.evalInstance(":!.*ed", ":fred"), is(true));
+
+ // Reject non-matches starting with a wildcard
+ assertThat(PermEval.evalInstance(":!.*arney", ":fred"), is(false));
+
+ // Accept matches ending with a wildcard
+ assertThat(PermEval.evalInstance(":fr*", ":fred"), is(true));
+
+ // Reject non-matches ending with a wildcard
+ assertThat(PermEval.evalInstance(":bar*", ":fred"), is(false));
+
+ // Accept exact keys
+ assertThat(PermEval.evalInstance(":fred", ":fred"), is(true));
+
+ // Reject mismatched keys
+ assertThat(PermEval.evalInstance(":fred", ":barney"), is(false));
+
+ // Check using alt-start character
+ assertThat(PermEval.evalInstance("/fred", "/fred"), is(true));
+ assertThat(PermEval.evalInstance("/barney", "/fred"), is(false));
+ }
+
+ @Test
+ public void instanceDirectTest() {
+ assertThat(PermEval.evalInstance("fred","fred"), is(true));
+ assertThat(PermEval.evalInstance("fred,wilma","fred"), is(true));
+ assertThat(PermEval.evalInstance("barney,betty,fred,wilma","fred"), is(true));
+ assertThat(PermEval.evalInstance("barney,betty,wilma","fred"), is(false));
+
+ assertThat(PermEval.evalInstance("fr*","fred"), is(true));
+ assertThat(PermEval.evalInstance("freddy*","fred"), is(false));
+ assertThat(PermEval.evalInstance("ba*","fred"), is(false));
+ }
+
+ @Test
+ public void actionTest() {
+ // Accept server *
+ assertThat(PermEval.evalAction("*", ""), is(true));
+ assertThat(PermEval.evalAction("*", "literally anything"), is(true));
+
+ // Reject empty actions
+ assertThat(PermEval.evalAction("literally anything", ""), is(false));
+
+ // Accept match as regex
+ assertThat(PermEval.evalAction("action", "!action"), is(true));
+
+ // Reject non-match as regex
+ assertThat(PermEval.evalAction("action", "!nonaction"), is(false));
+
+ // Accept exact match
+ assertThat(PermEval.evalAction("action", "action"), is(true));
+
+ // Reject non-match
+ assertThat(PermEval.evalAction("action", "nonaction"), is(false));
+ }
+
+ @Test
+ public void redundancyTest() {
+ // TRUE
assertTrue(PermEval.evalInstance(":fred:fred",":fred:fred"));
assertTrue(PermEval.evalInstance(":fred:fred,wilma",":fred:fred"));
assertTrue(PermEval.evalInstance(":fred:barney,betty,fred,wilma",":fred:fred"));
- assertTrue(PermEval.evalInstance("*","fred"));
assertTrue(PermEval.evalInstance(":*:fred",":fred:fred"));
assertTrue(PermEval.evalInstance(":fred:*",":fred:fred"));
assertTrue(PermEval.evalInstance(":!f.*:fred",":fred:fred"));
assertTrue(PermEval.evalInstance(":fred:!f.*",":fred:fred"));
-
- /// FALSE
+
+ // FALSE
assertFalse(PermEval.evalInstance("fred","wilma"));
assertFalse(PermEval.evalInstance("fred,barney,betty","wilma"));
assertFalse(PermEval.evalInstance(":fred:fred",":fred:wilma"));
assertTrue(PermEval.evalInstance("/v1/services/features/*","/v1/services/features/api1"));
assertTrue(PermEval.evalInstance(":v1:services:features:*",":v1:services:features:api2"));
// MSO - Xue Gao
- assertTrue(PermEval.evalInstance(":v1:requests:*",":v1:requests:test0-service"));
+ assertTrue(PermEval.evalInstance(":v1:requests:*",":v1:requests:test0-service"));
+
-
// Same tests, with Slashes
assertTrue(PermEval.evalInstance("/fred/fred","/fred/fred"));
assertTrue(PermEval.evalInstance("/fred/fred,wilma","/fred/fred"));
assertTrue(PermEval.evalInstance("/fred/*","/fred/fred"));
assertTrue(PermEval.evalInstance("/!f.*/fred","/fred/fred"));
assertTrue(PermEval.evalInstance("/fred/!f.*","/fred/fred"));
-
- /// FALSE
+
+ // FALSE
assertFalse(PermEval.evalInstance("fred","wilma"));
assertFalse(PermEval.evalInstance("fred,barney,betty","wilma"));
assertFalse(PermEval.evalInstance("/fred/fred","/fred/wilma"));
assertFalse(PermEval.evalInstance("/!f.*/!w.*","/fred/fred"));
assertFalse(PermEval.evalInstance("/fred/!x.*","/fred/fred"));
-
+
assertTrue(PermEval.evalInstance(":!com.att.*:role:write",":com.att.temp:role:write"));
// CPFSF-431 Group needed help with Wild Card
":!topic.com.att.ecomp_test.crm.pre.*",
":topic.com.att.ecomp_test.crm.predemo100"
));
-
+
+ // coverage
+ @SuppressWarnings("unused")
+ PermEval pe = new PermEval();
}
}
--- /dev/null
+/*******************************************************************************
+ * ============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====================================================
+ * *
+ * *
+ ******************************************************************************/
+package org.onap.aaf.cadi.cm.test;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
+
+import org.onap.aaf.cadi.cm.CertException;
+
+public class JU_CertException {
+
+ private static final String message = "The message associated with the exception";
+
+ @Test(expected = CertException.class)
+ public void test() throws CertException {
+ CertException except;
+
+ except = new CertException(message);
+ assertThat(except.getMessage(), is(message));
+
+ except = new CertException(new Exception(message));
+ assertThat(except.getMessage(), is("java.lang.Exception: " + message));
+
+ except = new CertException(message, new Exception(message));
+ assertThat(except.getMessage(), is(message));
+
+ throw new CertException();
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * ============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====================================================
+ * *
+ * *
+ ******************************************************************************/
+package org.onap.aaf.cadi.cm.test;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.mockito.Mockito.*;
+import org.junit.*;
+import org.mockito.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyPair;
+import java.security.PublicKey;
+
+import javax.crypto.Cipher;
+
+import org.onap.aaf.cadi.cm.Factory;
+import org.onap.aaf.cadi.cm.Factory.StripperInputStream;
+import org.onap.aaf.misc.env.Env;
+import org.onap.aaf.misc.env.LogTarget;
+import org.onap.aaf.misc.env.TimeTaken;
+import org.onap.aaf.misc.env.Trans;
+
+public class JU_Factory {
+
+ @Mock
+ Trans transMock;
+
+ @Mock
+ TimeTaken timeTakenMock;
+
+ @Mock
+ LogTarget logTargetMock;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+
+ when(transMock.start(anyString(), anyInt())).thenReturn(timeTakenMock);
+ when(transMock.debug()).thenReturn(logTargetMock);
+ }
+
+ @Test
+ public void generateKeyPairTest() throws Exception {
+ String message = "The quick brown fox jumps over the lazy dog.";
+
+ Cipher encryptor = Cipher.getInstance(Factory.KEY_ALGO);
+ Cipher decryptor = Cipher.getInstance(Factory.KEY_ALGO);
+
+ KeyPair kp1 = Factory.generateKeyPair(transMock);
+ encryptor.init(Cipher.ENCRYPT_MODE, kp1.getPublic());
+ decryptor.init(Cipher.DECRYPT_MODE, kp1.getPrivate());
+ byte[] encrypedMessage1 = encryptor.doFinal(message.getBytes(StandardCharsets.UTF_8));
+ String output1 = new String(decryptor.doFinal(encrypedMessage1));
+ assertThat(output1, is(message));
+
+ // coverage
+ when(transMock.start("Generate KeyPair", Env.SUB)).thenReturn(null);
+ KeyPair kp2 = Factory.generateKeyPair(transMock);
+ encryptor.init(Cipher.ENCRYPT_MODE, kp2.getPublic());
+ decryptor.init(Cipher.DECRYPT_MODE, kp2.getPrivate());
+ byte[] encrypedMessage2 = encryptor.doFinal(message.getBytes(StandardCharsets.UTF_8));
+ String output2 = new String(decryptor.doFinal(encrypedMessage2));
+ assertThat(output2, is(message));
+
+ KeyPair kp3 = Factory.generateKeyPair(null);
+ encryptor.init(Cipher.ENCRYPT_MODE, kp3.getPublic());
+ decryptor.init(Cipher.DECRYPT_MODE, kp3.getPrivate());
+ byte[] encrypedMessage3 = encryptor.doFinal(message.getBytes(StandardCharsets.UTF_8));
+ String output3 = new String(decryptor.doFinal(encrypedMessage3));
+ assertThat(output3, is(message));
+ }
+
+ @Test
+ public void keyToStringTest() throws IOException {
+ KeyPair kp = Factory.generateKeyPair(transMock);
+
+ String publicKeyString = Factory.toString(transMock, kp.getPublic());
+ String privateKeyString = Factory.toString(transMock, kp.getPrivate());
+
+ String[] publicKeyLines = publicKeyString.split("\n", 0);
+ assertThat(publicKeyLines.length, is(9));
+ assertThat(publicKeyLines[0], is("-----BEGIN PUBLIC KEY-----"));
+ assertThat(publicKeyLines[8], is("-----END PUBLIC KEY-----"));
+
+ String[] privateKeyLines = privateKeyString.split("\n", 0);
+ assertThat(privateKeyLines.length, is(28));
+ assertThat(privateKeyLines[0], is("-----BEGIN PRIVATE KEY-----"));
+ assertThat(privateKeyLines[27], is("-----END PRIVATE KEY-----"));
+ }
+}
package org.onap.aaf.cadi.oauth.test;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import org.junit.*;
+
import java.io.StringReader;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
import org.onap.aaf.cadi.Permission;
import org.onap.aaf.cadi.oauth.TokenPerm.LoadPermissions;
import org.onap.aaf.misc.rosetta.ParseException;
-public class JU_FastPerms {
+public class JU_TokenPerm {
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
+ @Test
+ public void test() throws ParseException {
+ String json;
+ LoadPermissions lp;
+ Permission p;
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
+ json = "{\"perm\":[" +
+ " {\"type\":\"com.access\",\"instance\":\"*\",\"action\":\"read,approve\"}," +
+ "]}";
- @Before
- public void setUp() throws Exception {
- }
+ lp = new LoadPermissions(new StringReader(json));
+ assertThat(lp.perms.size(), is(1));
+
+ p = lp.perms.get(0);
+ assertThat(p.getKey(), is("com.access|*|read,approve"));
+ assertThat(p.permType(), is("AAF"));
+
+ // Extra closing braces for coverage
+ json = "{\"perm\":[" +
+ " {\"type\":\"com.access\",\"instance\":\"*\",\"action\":\"read,approve\"}}," +
+ "]]}";
+
+ lp = new LoadPermissions(new StringReader(json));
+ assertThat(lp.perms.size(), is(1));
- @After
- public void tearDown() throws Exception {
+ p = lp.perms.get(0);
+ assertThat(p.getKey(), is("com.access|*|read,approve"));
+ assertThat(p.permType(), is("AAF"));
+
+ // Test without a type
+ json = "{\"perm\":[" +
+ " {\"instance\":\"*\",\"action\":\"read,approve\"}," +
+ "]}";
+
+ lp = new LoadPermissions(new StringReader(json));
+ assertThat(lp.perms.size(), is(0));
+
+ // Test without an instance
+ json = "{\"perm\":[" +
+ " {\"type\":\"com.access\",\"action\":\"read,approve\"}," +
+ "]}";
+
+ lp = new LoadPermissions(new StringReader(json));
+ assertThat(lp.perms.size(), is(0));
+
+ // Test without an action
+ json = "{\"perm\":[" +
+ " {\"type\":\"com.access\",\"instance\":\"*\"}," +
+ "]}";
+
+ lp = new LoadPermissions(new StringReader(json));
+ assertThat(lp.perms.size(), is(0));
}
@Test
- public void test() {
+ public void redundancyTest() {
String json = "{\"perm\":[" +
" {\"type\":\"com.access\",\"instance\":\"*\",\"action\":\"read,approve\"}," +
" {\"type\":\"org.osaaf.aaf.access\",\"instance\":\"*\",\"action\":\"*\"}," +
" {\"type\":\"com.test.access\",\"instance\":\"*\",\"action\":\"read\"}," +
" {\"type\":\"com.test.access\",\"instance\":\"*\",\"action\":\"read\"}" +
"]}";
-
try {
LoadPermissions lp = new LoadPermissions(new StringReader(json));
- for(Permission p : lp.perms) {
- System.out.println(p.toString());
- }
- System.out.println("done");
+ assertThat(lp.perms.size(), is(34));
} catch (ParseException e) {
- System.err.println(e);
+ fail(e.getMessage());
}
-
-
}
-
}
*
*/
-package org.onap.aaf.cadi.client.test;
+package org.onap.aaf.cadi.locator.test;
import java.net.URI;
import java.net.URL;
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <!--<parent>
+ <parent>
<groupId>org.onap.aaf.authz</groupId>
<artifactId>parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
- </parent> -->
+ </parent>
<groupId>org.onap.aaf.authz</groupId>
<artifactId>cadiparent</artifactId>
<name>AAF CADI Parent (Code, Access, Data, Identity)</name>
</organization>
<packaging>pom</packaging>
- <parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>1.1.0</version>
- </parent>
<properties>
<!-- <sonar.skip>true</sonar.skip> -->
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
+ <skipTests>false</skipTests>
+ <includes>
+ <include>**/JU*.java</include>
+ </includes>
+ <excludes>
+ </excludes>
</configuration>
</plugin>
<artifactId>log4j</artifactId>
<scope>compile</scope> <!-- Provides scope only, in case other users prefer another Logging Implementation -->
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class JU_APIExceptionTest {\r
+\r
+ private static final String EXCEPTION_MESSAGE = "New API Exception for test";\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ }\r
+\r
+ @Test\r
+ public void testNewAPIExceptionWithMessage() {\r
+ APIException exception = new APIException(EXCEPTION_MESSAGE);\r
+\r
+ assertEquals(exception.getMessage(), EXCEPTION_MESSAGE);\r
+ }\r
+\r
+ @Test\r
+ public void testNewAPIExceptionCreatedWithMessageAndThrowable() {\r
+ Throwable throwable = new Throwable();\r
+ APIException exception = new APIException(EXCEPTION_MESSAGE, throwable);\r
+\r
+ assertEquals(exception.getMessage(), EXCEPTION_MESSAGE);\r
+ assertEquals(exception.getCause(), throwable);\r
+ }\r
+\r
+ @Test\r
+ public void testNewAPIExceptionCreatedWithThrowable() {\r
+ Throwable throwable = new Throwable();\r
+ APIException exception = new APIException(throwable);\r
+\r
+ assertEquals(exception.getCause(), throwable);\r
+ }\r
+\r
+ @Test\r
+ public void testPayloadSetter() {\r
+ Throwable throwable = new Throwable();\r
+ Object payload = new Object();\r
+\r
+ APIException exception = new APIException(throwable);\r
+\r
+ exception.setPayload(payload);\r
+\r
+ assertEquals(exception.getPayload(), payload);\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.mockito.Mockito.when;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.onap.aaf.misc.env.impl.BasicTrans;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class JU_BasicTransTest {\r
+\r
+ BasicTrans trans = null;\r
+\r
+ @Mock\r
+ private EnvJAXB env;\r
+\r
+ @Mock\r
+ private TimeTaken timeTaken;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ trans = new BasicTrans(env);\r
+ }\r
+\r
+ @Test\r
+ public void testSlot() {\r
+ Slot slot = new Slot(1, "XML");\r
+ when(env.slot("XML")).thenReturn(slot);\r
+\r
+ Slot outputSlot = trans.slot("XML");\r
+ Object[] state = new Object[2];\r
+\r
+ slot.put(state, "JSON");\r
+\r
+ assertEquals(slot.get(state), "JSON");\r
+ assertEquals(slot.getKey(), outputSlot.getKey());\r
+ assertEquals(slot.toString(), outputSlot.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testGetStaticSlot() {\r
+ StaticSlot staticSlot = new StaticSlot(1, "XML");\r
+ when(env.get(staticSlot)).thenReturn(staticSlot.toString());\r
+\r
+ assertEquals(staticSlot.toString(), trans.get(staticSlot));\r
+ }\r
+\r
+ @Test\r
+ public void testGetStaticSlotWithT() {\r
+ StaticSlot staticSlot = new StaticSlot(1, "XML");\r
+ when(env.get(staticSlot, "XML")).thenReturn(staticSlot.getKey());\r
+\r
+ assertEquals(staticSlot.getKey(), trans.get(staticSlot, "XML"));\r
+ }\r
+\r
+ @Test\r
+ public void testSetProperty() {\r
+ String tag = "tag";\r
+ String value = "value";\r
+ String defltValue = "diffValue";\r
+ when(env.setProperty(tag, value)).thenReturn(value);\r
+ when(env.getProperty(tag)).thenReturn(value);\r
+ when(env.getProperty(tag, defltValue)).thenReturn(defltValue);\r
+\r
+ assertEquals(value, trans.setProperty(tag, value));\r
+ assertEquals(value, trans.getProperty(tag));\r
+ assertEquals(defltValue, trans.getProperty(tag, defltValue));\r
+ }\r
+\r
+ @Test\r
+ public void testDecryptor() {\r
+ when(env.decryptor()).thenReturn(Decryptor.NULL);\r
+\r
+ assertEquals(Decryptor.NULL, trans.decryptor());\r
+ assertEquals("tag", trans.decryptor().decrypt("tag"));\r
+ }\r
+\r
+ @Test\r
+ public void testEncryptor() {\r
+ when(env.encryptor()).thenReturn(Encryptor.NULL);\r
+\r
+ assertEquals(Encryptor.NULL, trans.encryptor());\r
+ assertEquals("tag", trans.encryptor().encrypt("tag"));\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.TransCreate;\r
+import org.onap.aaf.misc.env.TransJAXB;\r
+\r
+public class JU_EnvFactoryTest {\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ }\r
+\r
+ @Test\r
+ public void testSingleton() {\r
+ BasicEnv singleton = EnvFactory.singleton();\r
+\r
+ assertEquals(EnvFactory.singleton, singleton);\r
+ }\r
+\r
+ @Test\r
+ public void testSetSingleton() {\r
+ String[] str = { "argument1" };\r
+ BasicEnv env = new BasicEnv("tag", str);\r
+ EnvFactory.setSingleton(env);\r
+\r
+ assertEquals(EnvFactory.singleton(), env);\r
+ }\r
+\r
+ @Test\r
+ public void testNewTrans() {\r
+ TransJAXB newTrans = EnvFactory.newTrans();\r
+\r
+ assertTrue(newTrans instanceof BasicTrans);\r
+ }\r
+\r
+ @Test\r
+ public void testNewTransEnvJAXB() {\r
+ EnvJAXB env = new BasicEnv("");\r
+\r
+ TransJAXB trans = EnvFactory.newTrans(env);\r
+\r
+ assertTrue(trans instanceof BasicTrans);\r
+ }\r
+\r
+ @Test\r
+ public void testTransCreator() {\r
+ TransCreate<TransJAXB> transCreator = EnvFactory.transCreator();\r
+\r
+ TransJAXB newTrans = transCreator.newTrans();\r
+\r
+ assertTrue(newTrans instanceof BasicTrans);\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.IOStringifier;\r
+import org.onap.aaf.misc.env.old.Objectifier;\r
+import org.onap.aaf.misc.env.old.Stringifier;\r
+\r
+public class JU_JAXBDataTest {\r
+\r
+ @Mock\r
+ private Objectifier<String> objfr;\r
+\r
+ private String object = "Text";\r
+\r
+ @Mock\r
+ private Stringifier<String> strfr;\r
+\r
+ @Mock\r
+ private IOStringifier<String> ioStrfr;\r
+\r
+ @Mock\r
+ private JAXBDF<String> df;\r
+\r
+ @Mock\r
+ private Env env;\r
+\r
+ @Mock\r
+ private Class<String> typeClass;\r
+\r
+ @Mock\r
+ private OutputStream os;\r
+\r
+ @Mock\r
+ private Writer writer;\r
+\r
+ @Mock\r
+ private EnvJAXB env1;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ writer = mock(Writer.class);\r
+ os = mock(OutputStream.class);\r
+ strfr = mock(Stringifier.class);\r
+ ioStrfr = mock(IOStringifier.class);\r
+ objfr = mock(Objectifier.class);\r
+ env1 = mock(EnvJAXB.class);\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnv() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object, typeClass);\r
+\r
+ when(objfr.objectify(env, object)).thenReturn("String1");\r
+\r
+ jaxb.to(os);\r
+ jaxb.to(writer);\r
+\r
+ verify(writer).write(object);\r
+ verify(os).write(object.getBytes());\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ assertEquals(jaxb.asString(null), object);\r
+ assertEquals(jaxb.toString(), object);\r
+ assertEquals(jaxb.getTypeClass(), typeClass);\r
+ assertEquals(jaxb.out(null), jaxb);\r
+ assertEquals(jaxb.in(null), jaxb);\r
+ assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream);\r
+ assertEquals(jaxb.asObject(), "String1");\r
+ assertEquals(jaxb.asObject(env1), "String1");\r
+ assertEquals(jaxb.toString(), object);\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnvForObjectifier() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object, typeClass);\r
+\r
+ when(objfr.objectify(env1, object)).thenReturn("String1");\r
+\r
+ assertEquals(jaxb.asObject(env1), "String1");\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnvWithObject() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ jaxb.to(os);\r
+\r
+ verify(os).write(object.getBytes());\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ assertEquals(jaxb.asString(null), object);\r
+ assertEquals(jaxb.toString(), object);\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnvForWriter() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ jaxb.to(writer);\r
+\r
+ verify(writer).write(object);\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ assertEquals(jaxb.asString(null), object);\r
+ assertEquals(jaxb.toString(), object);\r
+ assertEquals(jaxb.asObject(), object);\r
+ assertEquals(jaxb.asObject(null), object);\r
+ }\r
+\r
+ @Test\r
+ public void testAsStringWithNullString() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ }\r
+\r
+ @Test\r
+ public void testAsStringWithNullStringWithEnv() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env1, object)).thenReturn(object);\r
+\r
+ assertEquals(jaxb.asString(env1), object);\r
+ }\r
+\r
+ @Test\r
+ public void testToWithIOStrifier() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ jaxb.option(0);\r
+\r
+ when(strfr.stringify(env1, object)).thenReturn(object);\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream);\r
+ assertEquals(jaxb.asString(env1), object);\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.never;\r
+import static org.mockito.Mockito.only;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_DoubleOutputStreamTest {\r
+\r
+ @Mock\r
+ private OutputStream stream1;\r
+\r
+ @Mock\r
+ private OutputStream stream2;\r
+\r
+ private DoubleOutputStream doubleOutputStream;\r
+\r
+ @Before\r
+ public void setup() {\r
+ stream1 = mock(OutputStream.class);\r
+ stream2 = mock(OutputStream.class);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteInt() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ doubleOutputStream.write(123);\r
+\r
+ verify(stream1, only()).write(123);\r
+ verify(stream2, only()).write(123);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArray() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+\r
+ doubleOutputStream.write(bytes);\r
+\r
+ verify(stream1, only()).write(bytes);\r
+ verify(stream2, only()).write(bytes);\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithOffset() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+\r
+ doubleOutputStream.write(bytes, 1, 3);\r
+ verify(stream1, only()).write(bytes, 1, 3);\r
+ verify(stream2, only()).write(bytes, 1, 3);\r
+ }\r
+\r
+ @Test\r
+ public void testFlush() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ doubleOutputStream.flush();\r
+\r
+ verify(stream1, only()).flush();\r
+ verify(stream2, only()).flush();\r
+ }\r
+\r
+ @Test\r
+ public void testClose() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false);\r
+\r
+ doubleOutputStream.close();\r
+\r
+ verify(stream1, only()).close();\r
+ verify(stream2, never()).close();\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_IndentPrintWriterTest {\r
+\r
+ @Mock\r
+ private OutputStream stream;\r
+\r
+ @Mock\r
+ private Writer writer;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ stream = mock(OutputStream.class);\r
+ writer = mock(Writer.class);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteInt() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.write(123);\r
+\r
+ verify(writer).write(123);\r
+\r
+ assertEquals(indentWriter.getIndent(), 0);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteIntWithNewLineCharacter() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.setIndent(12);\r
+\r
+ indentWriter.println();\r
+\r
+ indentWriter.write("123", 1, 2);\r
+\r
+ verify(writer).write('\n');\r
+ verify(writer).write('2');\r
+ verify(writer).write('3');\r
+ assertEquals(indentWriter.getIndent(), 12);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteString() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.inc();\r
+\r
+ indentWriter.write("123");\r
+\r
+ verify(writer).write('1');\r
+ verify(writer).write('2');\r
+ verify(writer).write('3');\r
+ assertEquals(indentWriter.getIndent(), 1);\r
+ }\r
+\r
+ @Test\r
+ public void testSetIndent() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(stream);\r
+\r
+ indentWriter.setIndent(12);\r
+ indentWriter.dec();\r
+\r
+ assertEquals(indentWriter.getIndent(), 11);\r
+ }\r
+\r
+ @Test\r
+ public void testToCol() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.toCol(5);\r
+ char[] chars = { 'a', 'b', 'c' };\r
+ indentWriter.write(chars, 1, 2);\r
+\r
+ verify(writer, times(5)).write(' ');\r
+ verify(writer).write('c');\r
+ verify(writer).write('b');\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.fail;\r
+\r
+import java.io.IOException;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class JU_StringBuilderOutputStreamTest {\r
+\r
+ StringBuilderOutputStream streamBuilder;\r
+\r
+ StringBuilder builder = new StringBuilder();\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ streamBuilder = new StringBuilderOutputStream(builder);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteIntAndReset() {\r
+ streamBuilder.write(123);\r
+\r
+ assertEquals("123", streamBuilder.toString());\r
+ streamBuilder.reset();\r
+ assertEquals("", streamBuilder.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithoutException() throws IOException {\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+ streamBuilder.write(bytes);\r
+ assertEquals(4, streamBuilder.getBuffer().length());\r
+\r
+ streamBuilder.write(bytes, 1, 2);\r
+ assertEquals(6, streamBuilder.getBuffer().length());\r
+\r
+ streamBuilder.write(bytes, 1, 0);\r
+ assertEquals(6, streamBuilder.getBuffer().length());\r
+\r
+ streamBuilder.append(bytes[0]);\r
+ assertEquals(7, streamBuilder.getBuffer().length());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithIndexOutOfBoundException() {\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+\r
+ try {\r
+ streamBuilder.write(bytes, -1, 2);\r
+ fail("This is supposed to throw IndexOutOfBounds Excetpion");\r
+ } catch (IndexOutOfBoundsException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IndexOutOfBounds Exception");\r
+ }\r
+ assertEquals(0, streamBuilder.getBuffer().length());\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testDefaultConstructor() throws IOException {\r
+ StringBuilderOutputStream stream = new StringBuilderOutputStream();\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithPositiveDefaultCapacity() throws IOException {\r
+ StringBuilderOutputStream stream = new StringBuilderOutputStream(10);\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ assertEquals(10, stream.getBuffer().capacity());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithNegativeCapacityException() {\r
+ try {\r
+ StringBuilderOutputStream stream = new StringBuilderOutputStream(-1);\r
+ fail("This should throw IllegalArgumentException");\r
+ } catch (IllegalArgumentException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IllegalArgumentException");\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testWriteString() {\r
+ streamBuilder.write("1234");\r
+\r
+ assertEquals("1234", streamBuilder.toString());\r
+\r
+ streamBuilder.write("1234", 1, 2);\r
+ assertEquals("12342", streamBuilder.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testAppendCharSequence() {\r
+ streamBuilder.append("1234");\r
+ assertEquals("1234", streamBuilder.toString());\r
+\r
+ streamBuilder.append(null);\r
+ assertEquals("1234null", streamBuilder.toString());\r
+\r
+ streamBuilder.append("1234", 1, 2);\r
+ assertEquals("1234null2", streamBuilder.toString());\r
+\r
+ streamBuilder.append(null, 1, 2);\r
+ assertEquals("1234null2u", streamBuilder.toString());\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.fail;\r
+\r
+import java.io.IOException;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class JU_StringBuilderWriterTest {\r
+\r
+ StringBuilderWriter streamWriter;\r
+\r
+ StringBuilder builder = new StringBuilder();\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ streamWriter = new StringBuilderWriter(builder);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteIntAndReset() {\r
+ streamWriter.write(1);\r
+\r
+ assertEquals(1, streamWriter.getBuffer().length());\r
+ streamWriter.reset();\r
+ assertEquals("", streamWriter.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithoutException() throws IOException {\r
+ char[] bytes = { 1, 2, 3, 4 };\r
+ streamWriter.write(bytes);\r
+ assertEquals(4, streamWriter.getBuffer().length());\r
+\r
+ streamWriter.write(bytes, 1, 2);\r
+ assertEquals(6, streamWriter.getBuffer().length());\r
+\r
+ streamWriter.write(bytes, 1, 0);\r
+ assertEquals(6, streamWriter.getBuffer().length());\r
+\r
+ streamWriter.append(bytes[0]);\r
+ assertEquals(7, streamWriter.getBuffer().length());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithIndexOutOfBoundException() {\r
+ char[] bytes = { 1, 2, 3, 4 };\r
+\r
+ try {\r
+ streamWriter.write(bytes, -1, 2);\r
+ fail("This is supposed to throw IndexOutOfBounds Excetpion");\r
+ } catch (IndexOutOfBoundsException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IndexOutOfBounds Exception");\r
+ }\r
+ assertEquals(0, streamWriter.getBuffer().length());\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testDefaultConstructor() throws IOException {\r
+ StringBuilderWriter stream = new StringBuilderWriter();\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithPositiveDefaultCapacity() throws IOException {\r
+ StringBuilderWriter stream = new StringBuilderWriter(10);\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ assertEquals(10, stream.getBuffer().capacity());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithNegativeCapacityException() {\r
+ try {\r
+ StringBuilderWriter stream = new StringBuilderWriter(-1);\r
+ fail("This should throw IllegalArgumentException");\r
+ } catch (IllegalArgumentException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IllegalArgumentException");\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testWriteString() {\r
+ streamWriter.write("1234");\r
+\r
+ assertEquals("1234", streamWriter.toString());\r
+\r
+ streamWriter.write("1234", 1, 2);\r
+ assertEquals("123423", streamWriter.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testAppendCharSequence() {\r
+ streamWriter.append("1234");\r
+ assertEquals("1234", streamWriter.toString());\r
+\r
+ streamWriter.append(null);\r
+ assertEquals("1234null", streamWriter.toString());\r
+\r
+ streamWriter.append("1234", 1, 2);\r
+ assertEquals("1234null2", streamWriter.toString());\r
+\r
+ streamWriter.append(null, 1, 2);\r
+ assertEquals("1234null2u", streamWriter.toString());\r
+ }\r
+}\r
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 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====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util.test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
-import org.junit.Test;
-import org.onap.aaf.misc.env.util.IPValidator;
-
-public class JU_IPValidator {
-
- @Test
- public void test() {
- assertTrue(IPValidator.ipv4("10.10.10.10"));
- assertTrue(IPValidator.ipv4("127.0.0.0"));
- assertFalse(IPValidator.ipv4("10"));
- assertFalse(IPValidator.ipv4("10.10.10"));
- assertFalse(IPValidator.ipv4("10.10.10."));
- assertFalse(IPValidator.ipv4("10.10.10.10."));
- assertFalse(IPValidator.ipv4("10.10.10.10.10"));
- assertFalse(IPValidator.ipv4("something10.10.10.10"));
- assertTrue(IPValidator.ipv4("0.10.10.10"));
- assertTrue(IPValidator.ipv4("0.0.0.0"));
- assertTrue(IPValidator.ipv4("0.10.10.10"));
- assertFalse(IPValidator.ipv4("011.255.255.255"));
- assertFalse(IPValidator.ipv4("255.01.255.255"));
- assertFalse(IPValidator.ipv4("255.255.255.256"));
- assertFalse(IPValidator.ipv4("255.299.255.255"));
-
-
- assertTrue(IPValidator.ipv6("0000:0000:0000:0000:0000:0000:0000:0000"));
- assertTrue(IPValidator.ipv6("0:0:0:0:0:0:0:0"));
- assertTrue(IPValidator.ipv6("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));
- assertTrue(IPValidator.ipv6("2001:8DB:0:0:23:F422:FE3B:AC10"));
- assertTrue(IPValidator.ipv6("2001:8DB::23:F422:FE3B:AC10"));
- assertTrue(IPValidator.ipv6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
- assertTrue(IPValidator.ipv6("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"));
- assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));
- assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));
- // more than one Double Colons
- assertFalse(IPValidator.ipv6("0000:0000:0000::0000::0000"));
- assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10:FFFF"));
-
-
-
- assertTrue(IPValidator.ip("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));
- assertTrue(IPValidator.ip("192.168.7.2"));
- }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util.test;\r
+\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+import org.junit.Test;\r
+import org.onap.aaf.misc.env.util.IPValidator;\r
+\r
+public class JU_IPValidator {\r
+\r
+ @Test\r
+ public void test() {\r
+ assertTrue(IPValidator.ipv4("10.10.10.10"));\r
+ assertTrue(IPValidator.ipv4("127.0.0.0"));\r
+ assertFalse(IPValidator.ipv4("10"));\r
+ assertFalse(IPValidator.ipv4("10.10.10"));\r
+ assertFalse(IPValidator.ipv4("10.10.10."));\r
+ assertFalse(IPValidator.ipv4("10.10.10.10."));\r
+ assertFalse(IPValidator.ipv4("10.10.10.10.10"));\r
+ assertFalse(IPValidator.ipv4("something10.10.10.10"));\r
+ assertTrue(IPValidator.ipv4("0.10.10.10"));\r
+ assertTrue(IPValidator.ipv4("0.0.0.0"));\r
+ assertTrue(IPValidator.ipv4("0.10.10.10"));\r
+ assertFalse(IPValidator.ipv4("011.255.255.255"));\r
+ assertFalse(IPValidator.ipv4("255.01.255.255"));\r
+ assertFalse(IPValidator.ipv4("255.255.255.256"));\r
+ assertFalse(IPValidator.ipv4("255.299.255.255"));\r
+\r
+ assertTrue(IPValidator.ipv6("0000:0000:0000:0000:0000:0000:0000:0000"));\r
+ assertTrue(IPValidator.ipv6("0:0:0:0:0:0:0:0"));\r
+ assertTrue(IPValidator.ipv6("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ipv6("2001:8DB:0:0:23:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ipv6("2001:8DB::23:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ipv6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));\r
+ assertTrue(IPValidator.ipv6("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"));\r
+ assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));\r
+ assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));\r
+ // more than one Double Colons\r
+ assertFalse(IPValidator.ipv6("0000:0000:0000::0000::0000"));\r
+ assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10:FFFF"));\r
+\r
+ assertTrue(IPValidator.ip("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ip("192.168.7.2"));\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util.test;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.util.Pool;\r
+\r
+public class JU_PoolTest {\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ }\r
+\r
+ @Test\r
+ public void test() {\r
+ Pool pool = new Pool<Integer>(new Pool.Creator<Integer>() {\r
+\r
+ Integer content = 0;\r
+\r
+ @Override\r
+ public Integer create() throws APIException {\r
+ return content++;\r
+ }\r
+\r
+ @Override\r
+ public void destroy(Integer t) {\r
+\r
+ }\r
+\r
+ @Override\r
+ public boolean isValid(Integer t) {\r
+ return t == content;\r
+ }\r
+\r
+ @Override\r
+ public void reuse(Integer t) {\r
+ content = t;\r
+ }\r
+ });\r
+ try {\r
+ // pool.drain();\r
+ assertEquals("Should return intial value", 0, pool.get().content);\r
+ // pooled.toss();\r
+ pool.prime(LogTarget.SYSOUT, 23);\r
+ assertEquals("Should Return 23 as added at last prime", 23, pool.get(LogTarget.SYSOUT).content);\r
+ pool.prime(LogTarget.SYSERR, 13);\r
+ assertEquals("Should add another 13 from SysErr and remove 1", 35, pool.get(LogTarget.SYSERR).content);\r
+ assertEquals("Create a new creator with create method", 1, pool.get().content);\r
+ assertEquals("Create a new creator with create method", 2, pool.get().content);\r
+ assertEquals("Should remove last from pool", 34, pool.get(LogTarget.SYSOUT).content);\r
+\r
+ pool.drain();\r
+ assertEquals("Should remove last from pool", 17, pool.get(LogTarget.SYSOUT).content);\r
+ } catch (APIException e) {\r
+ }\r
+ }\r
+\r
+}\r
<properties>
<!-- SONAR -->
- <sonar.skip>true</sonar.skip>
+ <!--<sonar.skip>true</sonar.skip> -->
<jacoco.version>0.7.7.201606060606</jacoco.version>
<sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
+ <skipTests>false</skipTests>
+ <includes>
+ <include>**/JU*.java</include>
+ </includes>
+ <excludes>
+ </excludes>
</configuration>
</plugin>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <!--<parent>
- <groupId>org.onap.aaf.authz</groupId>
- <artifactId>parent</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- </parent> -->
+ <parent>
+ <groupId>org.onap.aaf.authz</groupId>
+ <artifactId>parent</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
<groupId>org.onap.aaf.authz</groupId>
<artifactId>miscparent</artifactId>
<name>AAF Misc Parent</name>
<packaging>pom</packaging>
-
- <parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>1.1.0</version>
- </parent>
-
<properties>
<!-- SONAR -->
<!-- <sonar.skip>true</sonar.skip> -->
</dependency>
</dependencies>
+ <modules>
+ <module>env</module>
+ <module>xgen</module>
+ <module>rosetta</module>
+ <module>log4j</module> <!-- note: generates log4j, to avoid Jar conflict -->
+ </modules>
+
<!-- ============================================================== -->
<!-- Define common plugins and make them available for all modules -->
<!-- ============================================================== -->
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
+ <skipTests>false</skipTests>
+ <includes>
+ <include>**/JU*.java</include>
+ </includes>
+ <excludes>
+ </excludes>
</configuration>
</plugin>
</pluginManagement>
</build>
- <modules>
- <module>env</module>
- <module>xgen</module>
- <module>rosetta</module>
- <module>log4j</module> <!-- note: generates log4j, to avoid Jar conflict -->
- </modules>
+
<dependencyManagement>
<dependencies>