X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Ftaf%2Ftest%2FJU_HttpEpiTaf.java;h=6952a04238a697aa78e3cb3590b1fb03fd4908bd;hb=refs%2Fchanges%2F75%2F65275%2F1;hp=93a20474af62d08505b76a4919d22fe683d40f0c;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/taf/test/JU_HttpEpiTaf.java b/cadi/core/src/test/java/org/onap/aaf/cadi/taf/test/JU_HttpEpiTaf.java index 93a20474..6952a042 100644 --- a/cadi/core/src/test/java/org/onap/aaf/cadi/taf/test/JU_HttpEpiTaf.java +++ b/cadi/core/src/test/java/org/onap/aaf/cadi/taf/test/JU_HttpEpiTaf.java @@ -54,92 +54,92 @@ import org.onap.aaf.cadi.taf.TafResp.RESP; public class JU_HttpEpiTaf { - private PropAccess access; - - @Mock private Locator locMock; - @Mock private TrustChecker trustCheckerMock; - @Mock private HttpServletRequest reqMock; - @Mock private HttpServletResponse respMock; - @Mock private HttpTaf tafMock; - @Mock private TafResp trespMock; - @Mock private Redirectable redirMock; - - @Before - public void setup() throws URISyntaxException { - MockitoAnnotations.initMocks(this); - - access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); - } - - @Test - public void test() throws Exception { - HttpEpiTaf taf; - try { - taf = new HttpEpiTaf(access, locMock, trustCheckerMock); - fail("Should've thrown an exception"); - } catch (CadiException e) { - assertThat(e.getMessage(), is("Need at least one HttpTaf implementation in constructor")); - } - - taf = new HttpEpiTaf(access, locMock, trustCheckerMock, new NullTaf()); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - // Coverage of tricorderScan - taf.validate(LifeForm.LFN, reqMock, respMock); - when(reqMock.getHeader("User-Agent")).thenReturn("Non-mozilla-header"); - taf.validate(LifeForm.LFN, reqMock, respMock); - when(reqMock.getHeader("User-Agent")).thenReturn("Mozilla-header"); - taf.validate(LifeForm.LFN, reqMock, respMock); - - access.setLogLevel(Level.DEBUG); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - when(tafMock.validate(LifeForm.CBLF, reqMock, respMock)).thenReturn(trespMock); - when(trespMock.isAuthenticated()).thenReturn(RESP.TRY_ANOTHER_TAF); - taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - when(trespMock.isAuthenticated()).thenReturn(RESP.IS_AUTHENTICATED); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - when(trespMock.isAuthenticated()).thenReturn(RESP.TRY_AUTHENTICATING); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock, tafMock); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - when(tafMock.validate(LifeForm.CBLF, reqMock, respMock)).thenReturn(redirMock); - when(redirMock.isAuthenticated()).thenReturn(RESP.TRY_AUTHENTICATING); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock, tafMock); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock); - taf.validate(LifeForm.CBLF, reqMock, respMock); - - taf = new HttpEpiTaf(access, locMock, null, tafMock); - when(redirMock.isAuthenticated()).thenReturn(RESP.IS_AUTHENTICATED); - try { - taf.validate(LifeForm.CBLF, reqMock, respMock); - fail("Should've thrown an exception"); - } catch (Exception e) { - } - - assertThat(taf.revalidate(null), is(false)); - assertThat(taf.revalidate(null), is(false)); - - when(tafMock.revalidate(null, null)).thenReturn(Resp.NOT_MINE); - assertThat(taf.revalidate(null, null), is(Resp.NOT_MINE)); - when(tafMock.revalidate(null, null)).thenReturn(Resp.REVALIDATED); - assertThat(taf.revalidate(null, null), is(Resp.REVALIDATED)); - - when(tafMock.revalidate(null, null)).thenReturn(Resp.NOT_MINE).thenReturn(Resp.NOT_MINE).thenReturn(Resp.REVALIDATED); - taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock, tafMock, tafMock); - assertThat(taf.revalidate(null, null), is(Resp.REVALIDATED)); - - taf.toString(); - - } + private PropAccess access; + + @Mock private Locator locMock; + @Mock private TrustChecker trustCheckerMock; + @Mock private HttpServletRequest reqMock; + @Mock private HttpServletResponse respMock; + @Mock private HttpTaf tafMock; + @Mock private TafResp trespMock; + @Mock private Redirectable redirMock; + + @Before + public void setup() throws URISyntaxException { + MockitoAnnotations.initMocks(this); + + access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); + } + + @Test + public void test() throws Exception { + HttpEpiTaf taf; + try { + taf = new HttpEpiTaf(access, locMock, trustCheckerMock); + fail("Should've thrown an exception"); + } catch (CadiException e) { + assertThat(e.getMessage(), is("Need at least one HttpTaf implementation in constructor")); + } + + taf = new HttpEpiTaf(access, locMock, trustCheckerMock, new NullTaf()); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + // Coverage of tricorderScan + taf.validate(LifeForm.LFN, reqMock, respMock); + when(reqMock.getHeader("User-Agent")).thenReturn("Non-mozilla-header"); + taf.validate(LifeForm.LFN, reqMock, respMock); + when(reqMock.getHeader("User-Agent")).thenReturn("Mozilla-header"); + taf.validate(LifeForm.LFN, reqMock, respMock); + + access.setLogLevel(Level.DEBUG); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + when(tafMock.validate(LifeForm.CBLF, reqMock, respMock)).thenReturn(trespMock); + when(trespMock.isAuthenticated()).thenReturn(RESP.TRY_ANOTHER_TAF); + taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + when(trespMock.isAuthenticated()).thenReturn(RESP.IS_AUTHENTICATED); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + when(trespMock.isAuthenticated()).thenReturn(RESP.TRY_AUTHENTICATING); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock, tafMock); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + when(tafMock.validate(LifeForm.CBLF, reqMock, respMock)).thenReturn(redirMock); + when(redirMock.isAuthenticated()).thenReturn(RESP.TRY_AUTHENTICATING); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock, tafMock); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock); + taf.validate(LifeForm.CBLF, reqMock, respMock); + + taf = new HttpEpiTaf(access, locMock, null, tafMock); + when(redirMock.isAuthenticated()).thenReturn(RESP.IS_AUTHENTICATED); + try { + taf.validate(LifeForm.CBLF, reqMock, respMock); + fail("Should've thrown an exception"); + } catch (Exception e) { + } + + assertThat(taf.revalidate(null), is(false)); + assertThat(taf.revalidate(null), is(false)); + + when(tafMock.revalidate(null, null)).thenReturn(Resp.NOT_MINE); + assertThat(taf.revalidate(null, null), is(Resp.NOT_MINE)); + when(tafMock.revalidate(null, null)).thenReturn(Resp.REVALIDATED); + assertThat(taf.revalidate(null, null), is(Resp.REVALIDATED)); + + when(tafMock.revalidate(null, null)).thenReturn(Resp.NOT_MINE).thenReturn(Resp.NOT_MINE).thenReturn(Resp.REVALIDATED); + taf = new HttpEpiTaf(access, locMock, trustCheckerMock, tafMock, tafMock, tafMock); + assertThat(taf.revalidate(null, null), is(Resp.REVALIDATED)); + + taf.toString(); + + } }