X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Frserv%2Ftest%2FJU_Content1.java;h=0c35eaf0a560666a3b4082ffd35313abcb9453d9;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=18723962a22b743db01aea98ff00b977c2dcf03c;hpb=a46f569038869c77dbf7d34059c8ab2ae720e102;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java index 18723962..0c35eaf0 100644 --- a/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java +++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/rserv/test/JU_Content1.java @@ -41,90 +41,90 @@ import org.onap.aaf.misc.env.impl.EnvFactory; * Test the functioning of the "Content" class, which holds, and routes to the right code based on Accept values */ public class JU_Content1 { - - - @Test - public void test() throws Exception { - final String BOOL = "Boolean"; - final String XML = "XML"; - TransJAXB trans = EnvFactory.newTrans(); - try { - HttpCode cBool = new HttpCode(BOOL,"Standard String") { - @Override - public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) { - try { - resp.getOutputStream().write(context.getBytes()); - } catch (IOException e) { - } - } - }; - - HttpCode cXML = new HttpCode(XML, "Standard String") { - @Override - public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) { - try { - resp.getOutputStream().write(context.getBytes()); - } catch (IOException e) { - } - } - }; - - TypedCode ct = new TypedCode() - .add(cBool,"application/" + Boolean.class.getName()+"+xml;charset=utf8;version=1.1") - .add(cXML,"application/xml;q=.9"); - String expected = "application/java.lang.Boolean+xml;charset=utf8;version=1.1,application/xml;q=0.9"; - assertEquals(expected,ct.toString()); - - //BogusReq req = new BogusReq(); - //expected = (expected); - //HttpServletResponse resp = new BogusResp(); - - assertNotNull("Same Content String and Accept String",ct.prep(trans,expected)); - - //expects Null (not run) - // A Boolean xml that must have charset utf8 and match version 1.2 or greater - expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.2"); - assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected)); - - // Same with (too many) spaces - expected = (" application/java.lang.Boolean+xml ; charset = utf8 ; version = 1.2 "); - assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected)); - - //expects Null (not run) - expected = ("application/java.lang.Boolean+xml;charset=utf8;version=2.1"); - assertNull("Major Versions not the same",ct.prep(trans,expected)); - - expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.0"); - assertNotNull("Content Minor Version is greater than Accept Minor Version",ct.prep(trans,expected)); - - expected = "application/java.lang.Squid+xml;charset=utf8;version=1.0,application/xml;q=.9"; - assertNotNull("2nd one will have to do...",ct.prep(trans,expected)); - - expected = "application/java.lang.Boolean+xml;charset=UTF8;version=1.0"; - assertNotNull("Minor Charset in Caps acceptable",ct.prep(trans,expected)); - - // expects no run - expected="application/java.lang.Boolean+xml;charset=MyType;version=1.0"; - assertNull("Unknown Minor Charset",ct.prep(trans,expected)); - - expected=""; - assertNotNull("Blank Acceptance",ct.prep(trans,expected)); - - expected=null; - assertNotNull("Null Acceptance",ct.prep(trans,expected)); - - expected = ("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); - assertNotNull("Matches application/xml, and other content not known",ct.prep(trans,expected)); - - // No SemiColon - expected = ("i/am/bogus,application/xml"); - assertNotNull("Match second entry, with no Semis",ct.prep(trans,expected)); - - } finally { - StringBuilder sb = new StringBuilder(); - trans.auditTrail(0, sb); - //System.out.println(sb); - } - } + + + @Test + public void test() throws Exception { + final String BOOL = "Boolean"; + final String XML = "XML"; + TransJAXB trans = EnvFactory.newTrans(); + try { + HttpCode cBool = new HttpCode(BOOL,"Standard String") { + @Override + public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) { + try { + resp.getOutputStream().write(context.getBytes()); + } catch (IOException e) { + } + } + }; + + HttpCode cXML = new HttpCode(XML, "Standard String") { + @Override + public void handle(TransJAXB trans, HttpServletRequest req, HttpServletResponse resp) { + try { + resp.getOutputStream().write(context.getBytes()); + } catch (IOException e) { + } + } + }; + + TypedCode ct = new TypedCode() + .add(cBool,"application/" + Boolean.class.getName()+"+xml;charset=utf8;version=1.1") + .add(cXML,"application/xml;q=.9"); + String expected = "application/java.lang.Boolean+xml;charset=utf8;version=1.1,application/xml;q=0.9"; + assertEquals(expected,ct.toString()); + + //BogusReq req = new BogusReq(); + //expected = (expected); + //HttpServletResponse resp = new BogusResp(); + + assertNotNull("Same Content String and Accept String",ct.prep(trans,expected)); + + //expects Null (not run) + // A Boolean xml that must have charset utf8 and match version 1.2 or greater + expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.2"); + assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected)); + + // Same with (too many) spaces + expected = (" application/java.lang.Boolean+xml ; charset = utf8 ; version = 1.2 "); + assertNull("Accept Minor Version greater than Content Minor Version",ct.prep(trans,expected)); + + //expects Null (not run) + expected = ("application/java.lang.Boolean+xml;charset=utf8;version=2.1"); + assertNull("Major Versions not the same",ct.prep(trans,expected)); + + expected = ("application/java.lang.Boolean+xml;charset=utf8;version=1.0"); + assertNotNull("Content Minor Version is greater than Accept Minor Version",ct.prep(trans,expected)); + + expected = "application/java.lang.Squid+xml;charset=utf8;version=1.0,application/xml;q=.9"; + assertNotNull("2nd one will have to do...",ct.prep(trans,expected)); + + expected = "application/java.lang.Boolean+xml;charset=UTF8;version=1.0"; + assertNotNull("Minor Charset in Caps acceptable",ct.prep(trans,expected)); + + // expects no run + expected="application/java.lang.Boolean+xml;charset=MyType;version=1.0"; + assertNull("Unknown Minor Charset",ct.prep(trans,expected)); + + expected=""; + assertNotNull("Blank Acceptance",ct.prep(trans,expected)); + + expected=null; + assertNotNull("Null Acceptance",ct.prep(trans,expected)); + + expected = ("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); + assertNotNull("Matches application/xml, and other content not known",ct.prep(trans,expected)); + + // No SemiColon + expected = ("i/am/bogus,application/xml"); + assertNotNull("Match second entry, with no Semis",ct.prep(trans,expected)); + + } finally { + StringBuilder sb = new StringBuilder(); + trans.auditTrail(0, sb); + //System.out.println(sb); + } + } }