SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Unit Testing Coursesites
Context PublicHomePageRedirector public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //on request to the site / or index.html redirect to the servlet //we only want to hit on / HttpServletRequesthttpRequest = (HttpServletRequest)request; HttpServletResponsehttpResponse = (HttpServletResponse)response; String serverName = httpRequest.getHeader("Host"); intfirstperiodIndex = serverName.indexOf('.'); intlastperiodIndex = serverName.lastIndexOf('.'); /*   * so for wayank12teacher2.coursesites-stage.com   * hostHeader will be wayank12teacher2 setting the stage to check whether   * to forward to homepage.jsp or redirects to pages/index.html as in the past  */ String hostHeader = serverName.substring(0, firstperiodIndex).toLowerCase();
“No class is an island …” PublicHomePageRedirectorcollaborates with (depends on) ServletRequest ServletResponse FilterChain
Context..(2) /* taking care of missing www in the request   * aka coursesites-stage.com, coursesites.com   * making sure that redirects from OpenID login through Facebook or Twitter   * happen flawlessly  * */ if (!serverName.startsWith("www") && (firstperiodIndex == lastperiodIndex)) { String responseUrlPath = "https://" + "www." + serverName + "/webapps/Bb-sites-course-creation-BBLEARN/pages/index.html"; httpResponse.sendRedirect(responseUrlPath); return; }
Context…(3) else if (serverName.equalsIgnoreCase("coursesites.blackboard.com")){ serverName = "coursesites.com"; String responseUrlPath = "https://" + "www." + serverName + "/webapps/Bb-sites-course-creation-BBLEARN/pages/index.html"; httpResponse.sendRedirect(responseUrlPath); return; }
Scenario(s) Request with missing www (1) Request from coursesites.blackboard.com (2)
Unit Test Junit (command line through Ant) Mock (for collaborators  ServletRequest, ServletResponse, Chain)
TestCase(s) public class CourseSitesFilterTest { 	@Test	public void testMissingWWW() throws Exception{ … } 	@Test	public void testBlackBoardDomain() throws Exception{ …}
Scenario 1 public void testMissingWWW() throws Exception{			MockHttpServletRequest request = new MockHttpServletRequest();        		MockHttpServletResponse response = new MockHttpServletResponse();				//request.setMethod("GET"); request.addHeader("Host","coursesites.com");	 			//MockHttpServletRequest request = new 				FilterChain chain = Mockito.mock(FilterChain.class);				CourseSitesFilter filter = new CourseSitesFilter();		filter.doFilter(request, response, chain);				//System.out.println(request.getAttribute("hello"));		//System.out.println(request.getRequestURI());				//System.out.println(response.getForwardedUrl());		System.out.println("Output: " + response.getRedirectedUrl());	 assertTrue("Redirects to index.html", response.getRedirectedUrl().contains("index.html"));			 }
Scenario 2 	public void testBlackBoardDomain() throws Exception{			MockHttpServletRequest request = new MockHttpServletRequest();        		 MockHttpServletResponse response = new MockHttpServletResponse();			//request.setMethod("GET");		request.addHeader("Host","coursesites.blackboard.com");				//MockHttpServletRequest request = new MockHttpServletRequest("GET", "/invoiceView.app");				FilterChain chain = Mockito.mock(FilterChain.class);				CourseSitesFilter filter = new CourseSitesFilter();		filter.doFilter(request, response, chain);					//System.out.println(request.getRequestURI());			//System.out.println(response.getForwardedUrl());		System.out.println("Output: " + response.getRedirectedUrl());				assertTrue("Redirects to index.html", response.getRedirectedUrl().contains("index.html"));	}
Junit/Ant  <target name="junit" depends="compile">        <mkdir dir="${report.dir}"/>        <junitprintsummary="yes" haltonfailure="yes" showoutput="yes">            <classpath>                <path refid="classpath"/>                <path location="${build.dest}"/>				<path location="${build.test.dest}"/>            </classpath>            <formatter type="xml"/>            <batchtest fork="yes">                <fileset dir="${test.dir}" includes="**/*Test.java"/>            </batchtest>        </junit>    </target>
Results

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Reactive Programming no Android
Reactive Programming no AndroidReactive Programming no Android
Reactive Programming no Android
 
Reactive Programming on Android
Reactive Programming on AndroidReactive Programming on Android
Reactive Programming on Android
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 
NestJS
NestJSNestJS
NestJS
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17
 
Anay - Fluent interfaces in testing
Anay - Fluent interfaces in testingAnay - Fluent interfaces in testing
Anay - Fluent interfaces in testing
 
Rethrowing exception- JAVA
Rethrowing exception- JAVARethrowing exception- JAVA
Rethrowing exception- JAVA
 
Agile Android
Agile AndroidAgile Android
Agile Android
 
Agile Swift
Agile SwiftAgile Swift
Agile Swift
 
Laporan tugas network programming
Laporan tugas network programmingLaporan tugas network programming
Laporan tugas network programming
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with Javassist
 
Testing JavaScript Applications
Testing JavaScript ApplicationsTesting JavaScript Applications
Testing JavaScript Applications
 
Code Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive ExtensionsCode Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive Extensions
 
Taking a Test Drive
Taking a Test DriveTaking a Test Drive
Taking a Test Drive
 
Como NÃO testar o seu projeto de Software. DevDay 2014
Como NÃO testar o seu projeto de Software. DevDay 2014Como NÃO testar o seu projeto de Software. DevDay 2014
Como NÃO testar o seu projeto de Software. DevDay 2014
 
Reactor Design Pattern
Reactor Design PatternReactor Design Pattern
Reactor Design Pattern
 
Programming JVM Bytecode with Jitescript
Programming JVM Bytecode with JitescriptProgramming JVM Bytecode with Jitescript
Programming JVM Bytecode with Jitescript
 
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)
 
Reliability and Reslience
Reliability and ReslienceReliability and Reslience
Reliability and Reslience
 

Andere mochten auch

CourseSites jQuery plug-in
CourseSites jQuery plug-inCourseSites jQuery plug-in
CourseSites jQuery plug-in
Wayan Wira
 

Andere mochten auch (8)

CourseSites jQuery plug-in
CourseSites jQuery plug-inCourseSites jQuery plug-in
CourseSites jQuery plug-in
 
Course sites new user profile pages
Course sites new user profile pagesCourse sites new user profile pages
Course sites new user profile pages
 
Spring batch
Spring batchSpring batch
Spring batch
 
Brasil Império: Primeiro Reinado (1822-1831)
Brasil Império:   Primeiro Reinado (1822-1831)Brasil Império:   Primeiro Reinado (1822-1831)
Brasil Império: Primeiro Reinado (1822-1831)
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Ähnlich wie Unit testing CourseSites Apache Filter

Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
celenarouzie
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
knight1128
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 
Keep your Wicket application in production
Keep your Wicket application in productionKeep your Wicket application in production
Keep your Wicket application in production
Martijn Dashorst
 

Ähnlich wie Unit testing CourseSites Apache Filter (20)

13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authentication
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
 
Client server part 12
Client server part 12Client server part 12
Client server part 12
 
Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long Multi Client Development with Spring - Josh Long
Multi Client Development with Spring - Josh Long
 
servlets
servletsservlets
servlets
 
Android dev 3
Android dev 3Android dev 3
Android dev 3
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testen
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best Practices
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Testing Java Code Effectively
Testing Java Code EffectivelyTesting Java Code Effectively
Testing Java Code Effectively
 
Keep your Wicket application in production
Keep your Wicket application in productionKeep your Wicket application in production
Keep your Wicket application in production
 
Retrofit 2 - O que devemos saber
Retrofit 2 - O que devemos saberRetrofit 2 - O que devemos saber
Retrofit 2 - O que devemos saber
 
Google guava
Google guavaGoogle guava
Google guava
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
Salesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP calloutsSalesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP callouts
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 

Kürzlich hochgeladen

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Kürzlich hochgeladen (20)

SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 

Unit testing CourseSites Apache Filter

  • 2. Context PublicHomePageRedirector public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //on request to the site / or index.html redirect to the servlet //we only want to hit on / HttpServletRequesthttpRequest = (HttpServletRequest)request; HttpServletResponsehttpResponse = (HttpServletResponse)response; String serverName = httpRequest.getHeader("Host"); intfirstperiodIndex = serverName.indexOf('.'); intlastperiodIndex = serverName.lastIndexOf('.'); /* * so for wayank12teacher2.coursesites-stage.com * hostHeader will be wayank12teacher2 setting the stage to check whether * to forward to homepage.jsp or redirects to pages/index.html as in the past */ String hostHeader = serverName.substring(0, firstperiodIndex).toLowerCase();
  • 3. “No class is an island …” PublicHomePageRedirectorcollaborates with (depends on) ServletRequest ServletResponse FilterChain
  • 4. Context..(2) /* taking care of missing www in the request * aka coursesites-stage.com, coursesites.com * making sure that redirects from OpenID login through Facebook or Twitter * happen flawlessly * */ if (!serverName.startsWith("www") && (firstperiodIndex == lastperiodIndex)) { String responseUrlPath = "https://" + "www." + serverName + "/webapps/Bb-sites-course-creation-BBLEARN/pages/index.html"; httpResponse.sendRedirect(responseUrlPath); return; }
  • 5. Context…(3) else if (serverName.equalsIgnoreCase("coursesites.blackboard.com")){ serverName = "coursesites.com"; String responseUrlPath = "https://" + "www." + serverName + "/webapps/Bb-sites-course-creation-BBLEARN/pages/index.html"; httpResponse.sendRedirect(responseUrlPath); return; }
  • 6. Scenario(s) Request with missing www (1) Request from coursesites.blackboard.com (2)
  • 7. Unit Test Junit (command line through Ant) Mock (for collaborators  ServletRequest, ServletResponse, Chain)
  • 8. TestCase(s) public class CourseSitesFilterTest { @Test public void testMissingWWW() throws Exception{ … } @Test public void testBlackBoardDomain() throws Exception{ …}
  • 9. Scenario 1 public void testMissingWWW() throws Exception{ MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); //request.setMethod("GET"); request.addHeader("Host","coursesites.com"); //MockHttpServletRequest request = new FilterChain chain = Mockito.mock(FilterChain.class); CourseSitesFilter filter = new CourseSitesFilter(); filter.doFilter(request, response, chain); //System.out.println(request.getAttribute("hello")); //System.out.println(request.getRequestURI()); //System.out.println(response.getForwardedUrl()); System.out.println("Output: " + response.getRedirectedUrl()); assertTrue("Redirects to index.html", response.getRedirectedUrl().contains("index.html")); }
  • 10. Scenario 2 public void testBlackBoardDomain() throws Exception{ MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); //request.setMethod("GET"); request.addHeader("Host","coursesites.blackboard.com"); //MockHttpServletRequest request = new MockHttpServletRequest("GET", "/invoiceView.app"); FilterChain chain = Mockito.mock(FilterChain.class); CourseSitesFilter filter = new CourseSitesFilter(); filter.doFilter(request, response, chain); //System.out.println(request.getRequestURI()); //System.out.println(response.getForwardedUrl()); System.out.println("Output: " + response.getRedirectedUrl()); assertTrue("Redirects to index.html", response.getRedirectedUrl().contains("index.html")); }
  • 11. Junit/Ant <target name="junit" depends="compile"> <mkdir dir="${report.dir}"/> <junitprintsummary="yes" haltonfailure="yes" showoutput="yes"> <classpath> <path refid="classpath"/> <path location="${build.dest}"/> <path location="${build.test.dest}"/> </classpath> <formatter type="xml"/> <batchtest fork="yes"> <fileset dir="${test.dir}" includes="**/*Test.java"/> </batchtest> </junit> </target>