2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.util;
22 import static org.junit.Assert.assertTrue;
24 import java.io.ByteArrayOutputStream;
25 import java.io.PrintStream;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
29 import org.junit.Test;
31 public class JettyObfuscationConversionCommandLineUtilTest {
33 private final ByteArrayOutputStream testOut = new ByteArrayOutputStream();
40 //setup, this will catch main's print statements for evaluation
41 PrintStream oldOutputStream = System.out;
42 System.setOut(new PrintStream(testOut));
44 /* ------ TEST OBFUSCATION ----*/
45 JettyObfuscationConversionCommandLineUtil.main(new String[]{"-e", "hello world"});
47 * testOut was also catching any logging statements which interfered with result checking.
48 * This regex business was the workaround - it tries to find the expected value in
49 * the results and asserts against that.
51 String obfResult = testOut.toString();
52 String obfExpected = "OBF:1thf1ugo1x151wfw1ylz11tr1ymf1wg21x1h1uh21th7";
53 Pattern obfExpectPat = Pattern.compile(obfExpected);
54 Matcher obfMatch = obfExpectPat.matcher(obfResult);
55 assertTrue(obfMatch.find());
57 testOut.reset(); //clear out previous result
59 /* ------ TEST DEOBFUSCATION ----- */
60 JettyObfuscationConversionCommandLineUtil.main(new String[]{"-d", obfExpected});
61 String deobfResult = testOut.toString();
62 String deobfExpected = "hello world";
63 Pattern deobfExpectPat = Pattern.compile(deobfExpected);
64 Matcher deobfMatch = deobfExpectPat.matcher(deobfResult);
65 assertTrue(deobfMatch.find());
67 //clean up, resets to stdout
68 System.setOut(oldOutputStream);