@@ -472,14 +472,136 @@ void shouldReturnOverridenPathTree() throws Exception {
472472 }
473473 }
474474
475+ @ Nested
476+ static class NodeNameTests {
477+
478+ private Model model ;
479+ private Session session ;
480+ private VariantFactory factory ;
481+
482+ HttpMessage getParams ;
483+ HttpMessage postParamsFormData ;
484+ HttpMessage postParamsJsonData ;
485+ HttpMessage postParamsXmlData ;
486+ HttpMessage postMultipartData ;
487+
488+ @ BeforeEach
489+ void setup () throws Exception {
490+ WithConfigsTest .setUpConstantMessages ();
491+ model = mock (Model .class );
492+ session = new Session (model );
493+ factory = new VariantFactory ();
494+ given (model .getSession ()).willReturn (session );
495+ given (model .getVariantFactory ()).willReturn (factory );
496+ getParams =
497+ new HttpMessage (new URI ("https://www.example.com/aaa/bbb?aa=bb&cc=dd" , false ));
498+ postParamsFormData =
499+ getPostMsgWithFormParams (
500+ "https://www.example.com/ccc" , "aa=bb&cc=dd" , "ee=ff&gg=ee" );
501+ postParamsJsonData =
502+ getPostMsg (
503+ "https://www.example.com/ccc" ,
504+ "aa=bb&cc=dd" ,
505+ "{\" aaa\" :\" bbb\" , \" ccc\" :\" ddd\" , \" eee\" :\" fff\" }" ,
506+ "application/json" );
507+ postParamsXmlData =
508+ getPostMsg (
509+ "https://www.example.com/ccc" ,
510+ "aa=bb&cc=dd" ,
511+ "<aaa><bbb>BBB</bbb><ccc>CCC</ccc><ddd>DDD</ddd></aaa>" ,
512+ "text/xml" );
513+ Control .initSingletonForTesting (model );
514+ }
515+
516+ @ AfterEach
517+ void cleanUp () {
518+ Constant .messages = null ;
519+ }
520+
521+ @ Test
522+ void shouldGetNodeName () throws URIException {
523+ assertThat (
524+ SessionStructure .getNodeName (model , getParams ),
525+ is (equalTo ("https://www.example.com/aaa/bbb (aa,cc)" )));
526+ assertThat (
527+ SessionStructure .getNodeName (model , postParamsFormData ),
528+ is (equalTo ("https://www.example.com/ccc (aa,cc)(ee,gg)" )));
529+ // FIXME should have the JSON key names
530+ assertThat (
531+ SessionStructure .getNodeName (model , postParamsJsonData ),
532+ is (equalTo ("https://www.example.com/ccc (aa,cc)" )));
533+ // FIXME should have the XML key names
534+ assertThat (
535+ SessionStructure .getNodeName (model , postParamsXmlData ),
536+ is (equalTo ("https://www.example.com/ccc (aa,cc)" )));
537+ }
538+
539+ @ Test
540+ void shouldGetLeafName1 () throws URIException {
541+ assertThat (
542+ SessionStructure .getLeafName (model , "test" , getParams ),
543+ is (equalTo ("GET:test(aa,cc)" )));
544+ assertThat (
545+ SessionStructure .getLeafName (model , "test" , postParamsFormData ),
546+ is (equalTo ("POST:test(aa,cc)(ee,gg)" )));
547+ // FIXME should have the JSON key names
548+ assertThat (
549+ SessionStructure .getLeafName (model , "test" , postParamsJsonData ),
550+ is (
551+ equalTo (
552+ "POST:test(aa,cc)({\" aaa\" :\" bbb\" , \" ccc\" :\" ddd\" , \" eee\" :\" fff\" })" )));
553+ // FIXME should have the XML key names
554+ assertThat (
555+ SessionStructure .getLeafName (model , "test" , postParamsXmlData ),
556+ is (equalTo ("POST:test(aa,cc)(<aaa><bbb>BBB</bbb><ccc>CCC</ccc><ddd>DD...)" )));
557+ }
558+
559+ @ Test
560+ void shouldGetLeafName2 () throws Exception {
561+ assertThat (getLeafName2 (getParams ), is (equalTo ("GET:test(aa,cc)" )));
562+ assertThat (getLeafName2 (postParamsFormData ), is (equalTo ("POST:test(aa,cc)(ee,gg)" )));
563+ // FIXME should have the JSON key names
564+ assertThat (
565+ getLeafName2 (postParamsJsonData ),
566+ is (
567+ equalTo (
568+ "POST:test(aa,cc)({\" aaa\" :\" bbb\" , \" ccc\" :\" ddd\" , \" eee\" :\" fff\" })" )));
569+ // FIXME should have the XML key names
570+ assertThat (
571+ getLeafName2 (postParamsXmlData ),
572+ is (equalTo ("POST:test(aa,cc)(<aaa><bbb>BBB</bbb><ccc>CCC</ccc><ddd>DD...)" )));
573+ }
574+
575+ String getLeafName2 (HttpMessage msg ) throws Exception {
576+ return SessionStructure .getLeafName (
577+ model ,
578+ "test" ,
579+ msg .getRequestHeader ().getURI (),
580+ msg .getRequestHeader ().getMethod (),
581+ msg .getRequestBody ().toString ());
582+ }
583+ }
584+
475585 private void createPostMsgWithFormParams (String uri , String queryParams , String formParams )
476586 throws URIException {
477- msg .getRequestHeader ().setMethod (HttpRequestHeader .POST );
587+ msg = getPostMsgWithFormParams (uri , queryParams , formParams );
588+ }
589+
590+ private static HttpMessage getPostMsgWithFormParams (
591+ String uri , String queryParams , String formParams ) throws URIException {
592+ return getPostMsg (uri , queryParams , formParams , "application/x-www-form-urlencoded" );
593+ }
594+
595+ private static HttpMessage getPostMsg (
596+ String uri , String queryParams , String formParams , String contentType )
597+ throws URIException {
598+ HttpMessage message = new HttpMessage ();
599+ message .getRequestHeader ().setMethod (HttpRequestHeader .POST );
478600 queryParams = queryParams == null ? "" : "?" + queryParams ;
479- msg .getRequestHeader ().setURI (new URI (uri + queryParams , true ));
480- msg .getRequestHeader ()
481- . setHeader ( HttpHeader . CONTENT_TYPE , "application/x-www-form-urlencoded" );
482- msg . setRequestBody ( formParams ) ;
601+ message .getRequestHeader ().setURI (new URI (uri + queryParams , true ));
602+ message .getRequestHeader (). setHeader ( HttpHeader . CONTENT_TYPE , contentType );
603+ message . setRequestBody ( formParams );
604+ return message ;
483605 }
484606
485607 public static final class PathTreeVariant implements Variant {
0 commit comments