X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cmd%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fcmd%2Ftest%2Fuser%2FJU_Cred.java;h=9432cbca752d5b8fccff5e3b172853765f1b2c2f;hb=795b295fca004dae777f4d05b46c5861ac38379b;hp=f32ce0e35302ff0c5ebfef84b486b9bef290130a;hpb=1efda07f5d8e14d028fddf62dec62c95af9c7342;p=aaf%2Fauthz.git diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/user/JU_Cred.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/user/JU_Cred.java index f32ce0e3..9432cbca 100644 --- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/user/JU_Cred.java +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/user/JU_Cred.java @@ -22,6 +22,8 @@ package org.onap.aaf.auth.cmd.test.user; import org.junit.Assert; +import org.junit.Before; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; @@ -29,6 +31,10 @@ import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.io.PrintWriter; +import java.io.Writer; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; import org.junit.BeforeClass; import org.junit.Test; @@ -41,85 +47,68 @@ import org.onap.aaf.auth.cmd.user.Cred; import org.onap.aaf.auth.cmd.user.User; import org.onap.aaf.auth.env.AuthzEnv; import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.SecuritySetter; +import org.onap.aaf.cadi.Locator.Item; +import org.onap.aaf.cadi.http.HMangr; +import org.onap.aaf.cadi.http.HRcli; import org.onap.aaf.misc.env.APIException; @RunWith(MockitoJUnitRunner.class) public class JU_Cred { - private static Cred testCred; - private static User testUser; - private static AuthzEnv env; - - - @BeforeClass - public static void setUp() throws FileNotFoundException, APIException { - - testCred = mock(Cred.class); - testUser = mock(User.class); - env = mock(AuthzEnv.class); - Mockito.when(env.getProperty(Cmd.STARTDATE,null)).thenReturn(null); - Mockito.when(env.getProperty(Cmd.ENDDATE,null)).thenReturn(null); - - } - - @Test - public void exec() throws CadiException, APIException, LocatorException, FileNotFoundException { - boolean isNullpointer=false; - AAFcli aaFcli= new AAFcli(env, new PrintWriter("temp"), null, null, null); - User user= new User(aaFcli); - Cred testCred= new Cred(user); - try { - testCred._exec(0, "add", "del", "reset", "extend"); - } catch (Exception e) { - isNullpointer=true; - } - assertEquals(isNullpointer, true); + User user; + Cred cred; + PropAccess prop; + AuthzEnv aEnv; + Writer wtr; + Locator loc; + HMangr hman; + AAFcli aafcli; + + @Before + public void setUp() throws FileNotFoundException, APIException, LocatorException { + prop = new PropAccess(); + aEnv = new AuthzEnv(); + wtr = mock(Writer.class); + loc = mock(Locator.class); + SecuritySetter secSet = mock(SecuritySetter.class); + hman = new HMangr(aEnv, loc); + aafcli = new AAFcli(prop, aEnv, wtr, hman, null, secSet); + user = new User(aafcli); + cred = new Cred(user); } - - + @Test - public void exec_add() { - try { - assertNotNull(testCred._exec(0, "zeroed","add","del","reset","extend")); - } catch (CadiException | APIException | LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - @Test - public void exec_del() { - try { - assertNotNull(testCred._exec(1, "zeroed","add","del","reset","extend")); - } catch (CadiException | APIException | LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - @Test - public void exec_reset() { - try { - assertNotNull(testCred._exec(2, "zeroed","add","del","reset","extend")); - } catch (CadiException | APIException | LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + public void testExec() throws APIException, LocatorException, CadiException, URISyntaxException { + Item value = mock(Item.class); + Locator.Item item = new Locator.Item() { + }; + when(loc.best()).thenReturn(value); + URI uri = new URI("http://java.sun.com/j2se/1.3/"); + when(loc.get(value)).thenReturn(uri); + SecuritySetter secSet = mock(SecuritySetter.class); + HRcli hcli = new HRcli(hman, uri, item, secSet); + String[] strArr = {"add","del","reset","extend"}; + cred._exec(0, strArr); + + String[] strArr1 = {"del","reset","extend","add"}; + cred._exec(0, strArr1); + + String[] strArr2 = {"reset","extend", "add","del"}; + cred._exec(0, strArr2); + + String[] strArr3 = {"extend","add","del","reset"}; + cred._exec(0, strArr3); } - + @Test - public void exec_extend() { - try { - assertNotNull(testCred._exec(3, "zeroed","add","del","reset","extend")); - } catch (CadiException | APIException | LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + public void testDetailedHelp() { + StringBuilder sb = new StringBuilder(); + cred.detailedHelp(0, sb); } }