diff options
author | gabe.maurer <gabe.maurer@att.com> | 2018-04-16 12:33:28 -0500 |
---|---|---|
committer | gabe.maurer <gabe.maurer@att.com> | 2018-04-16 12:33:33 -0500 |
commit | ebdf1d62d6bc4bb87860a3ff5491bde6d96f8974 (patch) | |
tree | e3ab450c7b12a7616ce584f1263f2470c464242b | |
parent | ed39a027a78a0ca08230b1d34c5dac5421819018 (diff) |
Increased code coverage in auth-cmd cmd and help
Issue-ID: AAF-237
Change-Id: I4ab5892db08920cdaca70ef7a74b5d6e097221bc
Signed-off-by: gabe.maurer <gabe.maurer@att.com>
-rw-r--r-- | auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Cmd.java | 186 | ||||
-rw-r--r-- | auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Help.java | 124 |
2 files changed, 262 insertions, 48 deletions
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Cmd.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Cmd.java new file mode 100644 index 00000000..e87df80b --- /dev/null +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Cmd.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * ============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.auth.cmd.test; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.auth.cmd.AAFcli; +import org.onap.aaf.auth.cmd.Cmd; +import org.onap.aaf.auth.cmd.Param; +import org.onap.aaf.auth.cmd.mgmt.Cache; +import org.onap.aaf.auth.cmd.mgmt.Clear; +import org.onap.aaf.auth.cmd.mgmt.Mgmt; +import org.onap.aaf.auth.common.Define; +import org.onap.aaf.auth.server.AbsService; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.client.Future; +import org.onap.aaf.cadi.client.Retryable; +import org.onap.aaf.cadi.register.Registrant; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.impl.BasicEnv; + +import aaf.v2_0.History; +import aaf.v2_0.History.Item; + +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.GeneralSecurityException; +import java.util.List; + +import javax.servlet.Filter; + +import org.junit.Test; + +public class JU_Cmd { + + CmdStub cmd; + CmdStub cmd1; + CmdStub cmd2; + AAFcli cli; + + private class CmdStub extends Cmd { + + + public CmdStub(AAFcli aafcli, String name, Param[] params) { + super(aafcli, name, params); + // TODO Auto-generated constructor stub + } + + public CmdStub(Cmd parent, String name, Param[] params) { + super(parent, name, params); + // TODO Auto-generated constructor stub + } + + @Override + protected int _exec(int idx, String... args) throws CadiException, APIException, LocatorException { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void error(Future<?> future) { + super.error(future); + } + + } + + @Before + public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException { + cli = JU_AAFCli.getAAfCli(); + Param[] param = new Param[] {new Param("name",true)}; + + cmd = new CmdStub(cli,"test", param); + cmd1 = new CmdStub(cmd,"test", param); + cmd2 = new CmdStub(cmd,"test", param); + } + + @Test + public void testReportColHead() { + String[] args = new String[] {new String("test")}; + cmd.reportColHead("format", args); + } + + @Test + public void testBuilder() { + StringBuilder detail = new StringBuilder(); + StringBuilder sb = new StringBuilder("test 123"); + + cmd.build(sb, detail); + detail.append("test"); + cmd.build(sb, detail); + } + + @Test + public void testApi() throws APIException, CadiException { + StringBuilder sb = new StringBuilder("test 123"); + Define def = new Define(); + PropAccess prop = new PropAccess(); + def.set(prop); + Mgmt mgmt = new Mgmt(cli); + Cache cache = new Cache(mgmt); + Clear clr = new Clear(cache); + clr.detailedHelp(0, sb); + } + + @Test + public void testToString() { + cmd.toString(); + } + + @Test + public void testFullID() { + cmd.fullID("test"); + cmd.fullID("t@st"); + cmd.fullID(null); + } + + @Test + public void testError() { + Future<?> future = mock(Future.class); + cmd.error(future); + when(future.code()).thenReturn(401); + cmd.error(future); + when(future.code()).thenReturn(403); + cmd.error(future); + when(future.code()).thenReturn(404); + cmd.error(future); + when(future.body()).thenReturn("NotNull"); + cmd.error(future); + when(future.body()).thenReturn("{NotNull"); + cmd.error(future); + when(future.body()).thenReturn("<html>NotNull"); + cmd.error(future); + } + + @Test + public void testActivity() { + History hist = new History(); + cmd.activity(hist, "test"); + cmd.activity(hist, "te[st"); + } + + @Test + public void testWhichOption() throws CadiException { + String[] strArr = {"a", "b", "c"}; + cmd.whichOption(strArr, "b"); + } + + @Test + public void testOneOf() throws APIException, CadiException, LocatorException { + Retryable retryable = mock(Retryable.class); + //cmd.oneOf(retryable, "host"); //TODO: AAF-111 need input for hMan + } + + + +} diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Help.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Help.java index 67961824..bc1f4cc4 100644 --- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Help.java +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_Help.java @@ -30,6 +30,8 @@ import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; +import org.eclipse.jetty.http.HttpStatus; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,63 +40,89 @@ import org.mockito.runners.MockitoJUnitRunner; import org.onap.aaf.auth.cmd.AAFcli; import org.onap.aaf.auth.cmd.Cmd; import org.onap.aaf.auth.cmd.Help; +import org.onap.aaf.auth.cmd.Param; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.client.Future; import org.onap.aaf.misc.env.APIException; import junit.framework.Assert; -//import com.att.aft.dme2.internal.jetty.http.HttpStatus; -//TODO: Gabe [JUnit] Import missing @RunWith(MockitoJUnitRunner.class) public class JU_Help { -// private static AAFcli cli; -// private static Help help; -// -// @Mock -// private static List<Cmd> cmds; -// -// @BeforeClass -// public static void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException { -// cli = JU_AAFCli.getAAfCli(); -// cmds = new ArrayList<>(); -// help = new Help(cli, cmds); -// } -// -// @Test -// public void exec_HTTP_200() { -// try { -// assertEquals(help._exec(1, "helps"), HttpStatus.OK_200); -// } catch (CadiException | APIException | LocatorException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } -// -// @Test -// public void exec_HTTP_200_1() { -// try { -// assertEquals(help._exec(1, "helps","help"), HttpStatus.OK_200); -// } catch (CadiException | APIException | LocatorException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } -// -// @Test -// public void detailhelp() { -// boolean hasError=false; -// try { -// help.detailedHelp(2, new StringBuilder("detail help test")); -// } catch (Exception e) { -// hasError=true; -// } -// assertEquals(hasError,false); -// } + private static AAFcli cli; + private static Help help; + String[] strArr = {"null","null","b","c"}; + private class CmdStub extends Cmd { + + + public CmdStub(AAFcli aafcli, String name, Param[] params) { + super(aafcli, name, params); + // TODO Auto-generated constructor stub + } + + public CmdStub(Cmd parent, String name, Param[] params) { + super(parent, name, params); + // TODO Auto-generated constructor stub + } + + @Override + protected int _exec(int idx, String... args) throws CadiException, APIException, LocatorException { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void error(Future<?> future) { + super.error(future); + } - @Test //TODO: Temporary fix AAF-111 - public void netYetTested() { - Assert.assertTrue(true); } + + @Mock + private static List<Cmd> cmds; + + @Before + public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException { + cli = JU_AAFCli.getAAfCli(); + cmds = new ArrayList<>(); + Param[] param = new Param[] {new Param("name",true)}; + CmdStub cmd = new CmdStub(cli, "null", param); + cmds.add(cmd); + help = new Help(cli, cmds); + } + + @Test + public void exec_HTTP_200() { + try { + assertEquals(help._exec(1, "helps"), HttpStatus.OK_200); + assertEquals(help._exec(1, strArr), HttpStatus.OK_200); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void exec_HTTP_200_1() { + try { + assertEquals(help._exec(1, "helps","help"), HttpStatus.OK_200); + } catch (CadiException | APIException | LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void detailhelp() { + boolean hasError=false; + try { + help.detailedHelp(2, new StringBuilder("detail help test")); + } catch (Exception e) { + hasError=true; + } + assertEquals(hasError,false); + } + } |