diff options
Diffstat (limited to 'aai-resources/src/test/java/org/onap/aai/util')
8 files changed, 0 insertions, 1031 deletions
diff --git a/aai-resources/src/test/java/org/onap/aai/util/AAIRSyncUtilityTest.java b/aai-resources/src/test/java/org/onap/aai/util/AAIRSyncUtilityTest.java deleted file mode 100644 index c1aeff9..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/AAIRSyncUtilityTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.aai.AAISetup; - -import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; -import java.util.UUID; - -import static org.junit.Assert.*; - -@Ignore -public class AAIRSyncUtilityTest extends AAISetup { - - AAIRSyncUtility syncUtil; - AAIRSyncUtility syncUtilOmitDoCommand; - AAIConfig aaiConfig; - String hostName; - String transId = UUID.randomUUID().toString(); - - /** - * Initialize. - */ - @Before - public void initialize(){ - syncUtil = new AAIRSyncUtility(); - - syncUtilOmitDoCommand = new AAIRSyncUtility(){ - /** - * {@inheritDoc} - */ - @Override - public int doCommand(List<String> command) throws Exception - { - return 1; - } - }; - - partialSetupForAAIConfig(); - - InetAddress ip = null; - try { - ip = InetAddress.getLocalHost(); - } catch (UnknownHostException e2) { - e2.printStackTrace(); - } - hostName = ip.getHostName(); - } - - - /** - * Test sendRsync. - */ - @Test - public void testSendRsyncCommand(){ - syncUtilOmitDoCommand.sendRsyncCommand(transId, "RandomFileName"); - //TODO write codes to check what is being logged - } - - /** - * Test getHost. - */ - @Test - public void testGetHost(){ - - String returnedHost = null; - Method getHostMethod = makePublic("getHost"); - try { - returnedHost = (String)getHostMethod.invoke(syncUtil, null); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - - assertEquals("Host name didn't match", returnedHost, hostName); - } - - /** - * Test getRemoteHostList. - */ - @Test - public void testGetRemoteHostList(){ - String localHost = "host_local"; - String remoteHost1 = "hostR1"; - String remoteHost2 = "hostR2"; - ArrayList<String> remotes = new ArrayList<String>(); - remotes.add(remoteHost1); - remotes.add(remoteHost2); - - StringTokenizer stTokenizer = new StringTokenizer(remoteHost1+"\r"+remoteHost2+"\r"+localHost); - - Method m = makePublic("getRemoteHostList"); - try { - assertEquals("Remote host missing", remotes, m.invoke(syncUtil, stTokenizer, localHost)); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - } - - /** - * Test doCommand. - */ - @Test - public void testDoCommand(){ - - assertTrue("Don't have execute permissions", Files.isExecutable(new File(".").toPath())); - - List<String> commands = new ArrayList<String>(); - commands.add("ping"); - commands.add("google.com"); - try { - assertEquals("Failed to execute commands", 1, syncUtilOmitDoCommand.doCommand(commands)); - } catch (Exception e) { - fail("Failed to execute a command"); - e.printStackTrace(); - } - - } - - /** - * Test doCommand with null. - */ - @Test - public void testDoCommand_withNull(){ - assertTrue("Don't have execute permissions", Files.isExecutable(new File(".").toPath())); - try { - assertEquals("This should be unreachable", 1, syncUtil.doCommand(null)); - } catch (Exception e) { - assertTrue("Expecting an NPE from ProcessBuilder", e instanceof NullPointerException); - } - - } - - - /** - * Helper method to covert access type of a method from private to public . - * - * @param privateMethodName Method which is private originally - * @return method object with 'access type = 'public' - */ - public Method makePublic(String privateMethodName){ - Method targetMethod = null; - try { - if (privateMethodName.equals("getHost")) - targetMethod = AAIRSyncUtility.class.getDeclaredMethod(privateMethodName, null); - else if (privateMethodName.equals("getRemoteHostList")) - targetMethod = AAIRSyncUtility.class.getDeclaredMethod(privateMethodName, StringTokenizer.class, String.class); - } catch (NoSuchMethodException | SecurityException e) { - e.printStackTrace(); - } - targetMethod.setAccessible(true); - return targetMethod; - } - - /** - * Helper method to load aai config from test configuration file - * This requires that the 'test_aaiconfig.properties' file is available - */ - static void setFinalStatic(Field field, Object newValue) throws Exception { - field.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, newValue); - } - - /** - * Helper method to setup AAIConfig for test. - */ - public void partialSetupForAAIConfig(){ - try { - setFinalStatic(AAIConfig.class.getDeclaredField("GlobalPropFileName"), "src/test/resources/bundleconfig-local/etc/appprops/aaiconfig.properties"); - } - catch (SecurityException e) {fail();} - catch (NoSuchFieldException e) {fail();} - catch (Exception e) {fail();} - - AAIConfig.reloadConfig(); - } - -} diff --git a/aai-resources/src/test/java/org/onap/aai/util/DataConversionHelperTest.java b/aai-resources/src/test/java/org/onap/aai/util/DataConversionHelperTest.java deleted file mode 100644 index 3acbf03..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/DataConversionHelperTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - -import org.junit.Rule; -import org.junit.Test; -import org.powermock.modules.agent.PowerMockAgent; -import org.powermock.modules.junit4.rule.PowerMockRule; - -import static org.junit.Assert.assertEquals; - -public class DataConversionHelperTest { - - @Rule - public PowerMockRule rule = new PowerMockRule(); - - static { - PowerMockAgent.initializeIfNeeded(); - } - - /** - * Test convertIPVersionNumToString with value "4". - */ - @Test - public void testConvertIPVersionNumToString_withNum4(){ - assertEquals(DataConversionHelper.IPVERSION_IPV4, DataConversionHelper.convertIPVersionNumToString("4")); - } - - /** - * Test convertIPVersionNumToString with value "6". - */ - @Test - public void testConvertIPVersionNumToString_withNum6(){ - assertEquals(DataConversionHelper.IPVERSION_IPV6, DataConversionHelper.convertIPVersionNumToString("6")); - } - - /** - * Test convertIPVersionNumToString with a value other than "4" or "6". - */ - @Test - public void testConvertIPVersionNumToString_withAThirdNumber(){ - assertEquals(DataConversionHelper.IPVERSION_UNKNOWN, DataConversionHelper.convertIPVersionNumToString("-1")); - } - - /** - * Test convertIPVersionStringToNum with "v4". - */ - @Test - public void testConvertIPVersionStringToNum_withV4(){ - assertEquals("4", DataConversionHelper.convertIPVersionStringToNum(DataConversionHelper.IPVERSION_IPV4)); - } - - /** - * Test convertIPVersionStringToNum with "v6". - */ - @Test - public void testConvertIPVersionStringToNum_withV6(){ - assertEquals("6", DataConversionHelper.convertIPVersionStringToNum(DataConversionHelper.IPVERSION_IPV6)); - } - - /** - * Test convertIPVersionStringToNum with an illegal version. - */ - @Test - public void testConvertIPVersionStringToNum_withRandomString(){ - assertEquals("0", DataConversionHelper.convertIPVersionStringToNum("test string")); - } - - -} diff --git a/aai-resources/src/test/java/org/onap/aai/util/DbTestConfig.java b/aai-resources/src/test/java/org/onap/aai/util/DbTestConfig.java deleted file mode 100644 index 09e4cd7..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/DbTestConfig.java +++ /dev/null @@ -1,294 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - -import java.io.*; -import java.net.InetAddress; -import java.util.*; - -public class DbTestConfig { - - public static final String AUDIT_FILESEP = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); - public static final String AUDIT_HOME = (System.getProperty("audit.home") == null) ? AUDIT_FILESEP + "opt" + AUDIT_FILESEP + "audit" : System.getProperty("audit.home"); - public static final String AuditPropFilename = "c:\\tmp\\auditConfig.prop"; - public static final String AUDIT_CONFIG_CHECKINGTIME = "audit.config.checktime"; - public static final String AUDIT_NODENAME = "localhost"; - public static final String AUDIT_DEBUG = "audit.config.debug"; - - private static Properties serverProps; - private static boolean propsInitialized = false; - private static boolean timerSet = false; - private static Timer timer = null; - - private static String propFile = null; - - /** - * Inits the. - * - * @param propertyFile the property file - */ - public synchronized static void init(String propertyFile) { - propFile = propertyFile; - init(); - } - - /** - * Inits the. - */ - public synchronized static void init() { - System.out.println("Initializing Config"); - - DbTestConfig.getConfigFile(); - DbTestConfig.reloadConfig(); - - if ( propFile == null) - propFile = AuditPropFilename; - TimerTask task = null; - task = new DbTestFileWatcher ( new File(propFile)) { - protected void onChange( File file ) { - // here we implement the onChange - DbTestConfig.reloadConfig(); - } - }; - - if (!timerSet) { - timerSet = true; - // repeat the check every second - timer = new Timer(); - String fwi = DbTestConfig.get(AUDIT_CONFIG_CHECKINGTIME); - timer.schedule( task , new Date(), Integer.parseInt(fwi) ); - System.out.println("Config Watcher Interval=" + fwi); - - System.out.println("File" + propFile+" Loaded!"); - } - - } - - /** - * Cleanup. - */ - public static void cleanup() { - timer.cancel(); - } - - /** - * Gets the config file. - * - * @return the config file - */ - public static String getConfigFile() { - return propFile; - } - - /** - * Reload config. - */ - public synchronized static void reloadConfig() { - - String propFileName = propFile; - - Properties newServerProps = null; - - System.out.println("Reloading config from "+propFileName); - - try { - InputStream is = new FileInputStream(propFileName); - newServerProps = new Properties(); - newServerProps.load(is); - propsInitialized = true; - - serverProps = newServerProps; - if (get(AUDIT_DEBUG).equals("on")) { - serverProps.list(System.out); - } - newServerProps = null; - - } catch (FileNotFoundException fnfe) { - System.out.println("AuditConfig: " + propFileName + ". FileNotFoundException: "+fnfe.getMessage()); - } catch (IOException e) { - System.out.println("AuditConfig: " + propFileName + ". IOException: "+e.getMessage()); - } - } - - /** - * Gets the. - * - * @param key the key - * @param defaultValue the default value - * @return the string - */ - public static String get(String key, String defaultValue) { - String result = defaultValue; - try { - result = get (key); - } - catch ( Exception a ) { - } - return result; - } - - /** - * Gets the. - * - * @param key the key - * @return the string - */ - public static String get(String key) { - String response = null; - - if (key.equals(AUDIT_NODENAME)) { - // Get this from InetAddress rather than the properties file - String nodeName = getNodeName(); - if (nodeName != null) { - return nodeName; - } - // else get from property file - } - - if (!propsInitialized || (serverProps == null)) { - reloadConfig(); - } - if (!serverProps.containsKey(key)) { - System.out.println( "Property key "+key+" cannot be found"); - } else { - response = serverProps.getProperty(key); - if (response == null || response.isEmpty()) { - System.out.println("Property key "+key+" is null or empty"); - } - } - return response; - } - - /** - * Gets the int. - * - * @param key the key - * @return the int - */ - public static int getInt(String key) { - return Integer.valueOf(DbTestConfig.get(key)); - } - - /** - * Gets the server props. - * - * @return the server props - */ - public static Properties getServerProps() { - return serverProps; - } - - /** - * Gets the node name. - * - * @return the node name - */ - public static String getNodeName() { - try { - InetAddress ip = InetAddress.getLocalHost(); - if (ip != null) { - String hostname = ip.getHostName(); - if (hostname != null) { - return hostname; - } - } - } catch (Exception e) { - return null; - } - return null; - } - - /** - * Extracts a specific property key subset from the known properties. - * The prefix may be removed from the keys in the resulting dictionary, - * or it may be kept. In the latter case, exact matches on the prefix - * will also be copied into the resulting dictionary. - * - * @param prefix is the key prefix to filter the properties by. - * @param keepPrefix if true, the key prefix is kept in the resulting - * dictionary. As side-effect, a key that matches the prefix exactly - * will also be copied. If false, the resulting dictionary's keys are - * shortened by the prefix. An exact prefix match will not be copied, - * as it would result in an empty string key. - * @return a property dictionary matching the filter key. May be - * an empty dictionary, if no prefix matches were found. - * - * @see #getProperty( String ) is used to assemble matches - */ - public static Properties matchingSubset(String prefix, boolean keepPrefix) { - Properties result = new Properties(); - - // sanity check - if (prefix == null || prefix.length() == 0) { - return result; - } - - String prefixMatch; // match prefix strings with this - String prefixSelf; // match self with this - if (prefix.charAt(prefix.length() - 1) != '.') { - // prefix does not end in a dot - prefixSelf = prefix; - prefixMatch = prefix + '.'; - } else { - // prefix does end in one dot, remove for exact matches - prefixSelf = prefix.substring(0, prefix.length() - 1); - prefixMatch = prefix; - } - // POSTCONDITION: prefixMatch and prefixSelf are initialized! - - // now add all matches into the resulting properties. - // Remark 1: #propertyNames() will contain the System properties! - // Remark 2: We need to give priority to System properties. This is done - // automatically by calling this class's getProperty method. - String key; - for (Enumeration e = serverProps.keys(); e.hasMoreElements(); ) { - key = (String) e.nextElement(); - - if (keepPrefix) { - // keep full prefix in result, also copy direct matches - if (key.startsWith(prefixMatch) || key.equals(prefixSelf)) { - result.setProperty(key, serverProps.getProperty(key)); - } - } else { - // remove full prefix in result, dont copy direct matches - if (key.startsWith(prefixMatch)) { - result.setProperty(key.substring(prefixMatch.length()), serverProps.getProperty(key)); - } - } - } - - // done - return result; - } - - - - /** - * The main method. - * - * @param args the arguments - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - DbTestConfig.init( ); - - } - -} diff --git a/aai-resources/src/test/java/org/onap/aai/util/DbTestFileWatcher.java b/aai-resources/src/test/java/org/onap/aai/util/DbTestFileWatcher.java deleted file mode 100644 index 60b9039..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/DbTestFileWatcher.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - -import java.io.File; -import java.util.TimerTask; - -public abstract class DbTestFileWatcher extends TimerTask { - private long timeStamp; - private File file; - - /** - * Instantiates a new db test file watcher. - * - * @param file the file - */ - public DbTestFileWatcher( File file ) { - this.file = file; - this.timeStamp = file.lastModified(); - } - - /** - * {@inheritDoc} - */ - public final void run() { - long timeStamp = file.lastModified(); - - if( (timeStamp - this.timeStamp) > 500 ) { - this.timeStamp = timeStamp; - onChange(file); - } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * On change. - * - * @param file the file - */ - protected abstract void onChange( File file ); -} diff --git a/aai-resources/src/test/java/org/onap/aai/util/DbTestGetFileTime.java b/aai-resources/src/test/java/org/onap/aai/util/DbTestGetFileTime.java deleted file mode 100644 index fb1f1ee..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/DbTestGetFileTime.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.attribute.BasicFileAttributeView; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.FileTime; - -public class DbTestGetFileTime { - - - /** - * Creates the file return time. - * - * @param path the path - * @return the file time - * @throws IOException Signals that an I/O exception has occurred. - */ - public FileTime createFileReturnTime( String path) throws IOException { - File file = new File(path); - if(!file.exists()) { - file.createNewFile(); - } - Path p = Paths.get(file.getAbsolutePath()); - BasicFileAttributes view - = Files.getFileAttributeView(p, BasicFileAttributeView.class) - .readAttributes(); - FileTime fileTime=view.creationTime(); - // also available view.lastAccessTine and view.lastModifiedTime - return fileTime; - } -} diff --git a/aai-resources/src/test/java/org/onap/aai/util/DbTestProcessBuilder.java b/aai-resources/src/test/java/org/onap/aai/util/DbTestProcessBuilder.java deleted file mode 100644 index 503ec0f..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/DbTestProcessBuilder.java +++ /dev/null @@ -1,213 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - -import java.io.*; -import java.nio.file.attribute.FileTime; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -public class DbTestProcessBuilder { - ///public static Logger clog = Logger.getLogger("auditConsole"); - //public static Logger alog = Logger.getLogger("auditLog"); - - /** - * Start audit process non blocking. - * - * @param wait the wait - * @param cmds the cmds - * @param dir the dir - */ - public void startAuditProcessNonBlocking(final long wait, final String cmds[], final String dir) { - - final ProcessBuilder pb = new ProcessBuilder(cmds).redirectErrorStream(true).directory(new File(dir)); - - new Thread(new Runnable() { - public void run() { - try { - //System.out.println( "sleeping seconds " + wait + " cmds " + Arrays.toString(cmds)); - Thread.sleep(wait*1000); - //System.out.println( "returned from sleep"); - final Process p = pb.start(); - //System.out.println( "returned from pb.start"); - final InputStream is = p.getInputStream(); - final BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); - final InputStreamReader isr = new InputStreamReader(is); - final BufferedReader br = new BufferedReader(isr); -//clog.debug("Output of running " + Arrays.toString(cmds) + " is:"); - System.out.println("Output of running is:" ); - String line; - while ((line = br.readLine()) != null ) { - System.out.println(line); - } - System.out.println("stderr of running is:" ); - - while ((line = stdError.readLine()) != null ) { - System.out.println(line); - } - - } catch (IOException ie) { - - } catch (InterruptedException itre) { - Thread.currentThread().interrupt(); - } - } - }).start(); - - } - - - private final ScheduledExecutorService auditProcessScheduler = - Executors.newScheduledThreadPool(10); - - /** - * Run W command every X seconds for Y minutes. - * - * @param w the w - * @param x the x - * @param y the y - * @param runningDir the running dir - */ - public void runWCommandEveryXSecondsForYMinutes(String[] w, int x, int y, final String runningDir) { - final String[] c1 = w; - final Runnable audit = new Runnable() { - public void run() { -//clog.debug("checkpoint "+(new Date()).toString()); - DbTestProcessBuilder a1 = new DbTestProcessBuilder(); - a1.startAuditProcessNonBlocking(1, c1, "/tmp"); - } - }; - - final ScheduledFuture<?> auditHandle = - auditProcessScheduler.scheduleAtFixedRate(audit, 0, x, TimeUnit.SECONDS); - auditProcessScheduler.schedule(new Runnable() { - public void run() { - auditHandle.cancel(true); - } - }, y * 60, TimeUnit.SECONDS); - } - - - /** - * The main method. - * - * @param args the arguments - */ - @SuppressWarnings({ "null", "static-access" }) - public static void main(String args[]) { - String props = "NA"; - if (args.length > 0) { - System.out.println( "DbTestProcessBuilder called with " + args.length + " arguments, " + args[0]); - props = args[0].trim(); - } else { - System.out.print("usage: DbTestProcessBuilder <auditConfig.prop path\n"); - return; - } - DbTestConfig.init(props); - String ail = DbTestConfig.get("audit.list"); - String path = DbTestConfig.get("audit.path"); - final String runningDir = DbTestConfig.get("audit.runningdir"); - try { - DbTestGetFileTime getFileTime = new DbTestGetFileTime(); - FileTime fileTime = getFileTime.createFileReturnTime( path ); - System.out.println(path + " creation time :" - + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss") - .format(fileTime.toMillis()) + " runningDir " + runningDir); - } catch ( IOException io ) { - System.out.println( "IOException getting creation time " + path + " message " + io.getMessage()); - io.printStackTrace(); - } - - List<String> items = Arrays.asList(ail.split("\\s*,\\s*")); - for (String ai: items) { - if (!DbTestConfig.get("audit.task."+ai+".status").startsWith("a")) { - continue; - } -//clog.debug("***audit item = " + ai + " Starting***"); - - String w1 = DbTestConfig.get("audit.task."+ai+".cmd"); - String[] w2 = w1.split("\\s*,\\s*"); - System.out.print( "task items are : " + Arrays.toString(w2)); - // append the audit item name as the prefix of the audit directory name - /*final int N = w2.length; - w2 = Arrays.copyOf(w2, N+1); - w2[N-2] = "\"-Dp=" + DbTestConfig.get("audit.task.odl.output.dir")+ai + "\""; -//clog.debug("***java -D:"+w2[N-2]); - //w2[N] = "\""+DbTestConfig.get("audit.task.odl.output.dir")+ai+"\""; - w2[N] = "\""+DbTestConfig.get("audit.task.odl.output.dir")+ai+"\""; - */ - DbTestProcessBuilder apb = new DbTestProcessBuilder(); - - String ts1 = DbTestConfig.get("audit.task."+ai+".schedule"); - String[] ts2 = ts1.split("\\s*,\\s*"); - // note ts2[0] is the wait-before time, and it is not being used right now. We start with ts2[1] - apb.runWCommandEveryXSecondsForYMinutes(w2,Integer.parseInt(ts2[1]),Integer.parseInt(ts2[2]), runningDir); -//clog.debug("***audit item = " + ai + " started***"); - System.out.println( "started test " + ai); - - /* - int ct = 0; - - while (true) try { - if (DbTestConfig.get("jcl").startsWith("q")) { - System.out.println("***Audit Main Program exiting..."); - System.exit(0); - } - - Thread.currentThread().sleep(1000); - if (ct < 10) { - ct++; - } else { - //clog.debug(AuditConfig.get("jcl").charAt(0)); - ct=0; - } - - } catch (InterruptedException ie) { - - } */ - } - int ct = 0; - - while (true) try { - if (DbTestConfig.get("jcl").startsWith("q")) { - System.out.println("***Audit Main Program exiting..."); - System.exit(0); - } - - Thread.currentThread().sleep(1000); - if (ct < 10) { - ct++; - } else { - //clog.debug(AuditConfig.get("jcl").charAt(0)); - ct=0; - } - - } catch (InterruptedException ie) { - - } - - } - -} diff --git a/aai-resources/src/test/java/org/onap/aai/util/HbaseSaltPrefixerTest.java b/aai-resources/src/test/java/org/onap/aai/util/HbaseSaltPrefixerTest.java deleted file mode 100644 index 6379240..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/HbaseSaltPrefixerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -public class HbaseSaltPrefixerTest { - - /** - * Test. - */ - @Test - public void test() { - String key = "imakey"; - String saltedKey = HbaseSaltPrefixer.getInstance().prependSalt(key); - assertTrue(saltedKey.equals("0-imakey")); - } - -} diff --git a/aai-resources/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java b/aai-resources/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java deleted file mode 100644 index 7c4abc9..0000000 --- a/aai-resources/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-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.aai.util; - -import org.junit.Ignore; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.junit.Assert.assertTrue; - -@Ignore -public class JettyObfuscationConversionCommandLineUtilTest { - private final ByteArrayOutputStream testOut = new ByteArrayOutputStream(); - - /** - * Test. - */ - @Test - public void test() { - //setup, this will catch main's print statements for evaluation -// System.setOut(new PrintStream(testOut)); - - /* ------ TEST OBFUSCATION ----*/ - JettyObfuscationConversionCommandLineUtil.main(new String[]{"-e", "hello world"}); - /* - * testOut was also catching any logging statements which interfered with result checking. - * This regex business was the workaround - it tries to find the expected value in - * the results and asserts against that. - */ - String obfResult = testOut.toString(); - String obfExpected = "OBF:1thf1ugo1x151wfw1ylz11tr1ymf1wg21x1h1uh21th7"; - Pattern obfExpectPat = Pattern.compile(obfExpected); - Matcher obfMatch = obfExpectPat.matcher(obfResult); - assertTrue(obfMatch.find()); - - testOut.reset(); //clear out previous result - - /* ------ TEST DEOBFUSCATION ----- */ - JettyObfuscationConversionCommandLineUtil.main(new String[]{"-d", obfExpected}); - String deobfResult = testOut.toString(); - String deobfExpected = "hello world"; - Pattern deobfExpectPat = Pattern.compile(deobfExpected); - Matcher deobfMatch = deobfExpectPat.matcher(deobfResult); - assertTrue(deobfMatch.find()); - - //clean up, resets to stdout -// System.setOut(null); - } - -} |