
    S                     4   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddl
mZ ej                  j                  ej                  j                  ej                  j                  e                  Zej                  j%                  ej                  j'                  ed             ddlZej                  j                  ej                  j                  e            Z G d dej,                        Zedk(  r e	j2                          yy)	zTests of the java runtime.    N)testutil)ext_runtimelibc                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZ S )RuntimeTestsc                 @    t         | _        t        t        |           y N)RUNTIME_DEF_ROOTruntime_def_rootsuperr   setUp)self	__class__s    .platform/ext-runtime/java/test/runtime_test.pyr   zRuntimeTests.setUp0   s     0lD')    c                 z    | j                  t        j                  j                   | j                  |              y r	   )assertFalseospathexists	full_path)r   r   s     r   assert_no_filezRuntimeTests.assert_no_file4   s(    (=>?r   c                 &    dj                  |      S )Nzenv: flex
runtime: {runtime}
)runtime)format)r   r   s     r   make_app_yamlzRuntimeTests.make_app_yaml7   s    0777HHr   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d       | j                  d| j                  d	d
             t        j                  t        j                  j                  d      t        j                  j                  d      g}| j                  ddj                  |             | j                  t        t        j                  | j                               h d       y )Nfoo.jar app.yamljava
Dockerfile.dockerignoreTdeploydatadockerignore>   r"   r   r    r#   )
write_filegenerate_configs assert_file_exists_with_contentsr   r   read_runtime_def_file	constantsDOCKERFILE_JAVA_PREAMBLEDOCKERFILE_INSTALL_APPr   DOCKERFILE_JAVA8_JAR_CMDjoinassertEqualsetr   listdir	temp_pathr   dockerfile_contentss     r   test_java_all_defaultsz#RuntimeTests.test_java_all_defaults:   s   	2&--j.2.@.@.H	JL)O,T*--&&v~>	@ ..,,33I>..55i@

 	--l.0gg6I.J	L 	RZZ78O	Qr   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d      }| j                  |d| j                  d	d
             t        j                  t        j                  j                  d      t        j                  j                  d      g}| j                  |ddj                  |             | j                  t        t!        j"                  | j$                              ddh       y)z1Test generate_config_data after writing app.yaml.r   r   r    r!   r"   r#   Tr$   r&   r'   N)r(   r)   r*   r   r   generate_config_data#assert_genfile_exists_with_contentsr+   r,   r-   r.   r   r/   r0   r1   r2   r   r3   r4   r   	cfg_filesr6   s      r   test_java_all_defaults_no_writez,RuntimeTests.test_java_all_defaults_no_writeT   s   	2&--j.2.@.@.H	JL)O,--T-:	00&&v~>	@
 ..,,33I>..55i@

 	00GG'(	*
 	RZZ78$i0	2r   c                    | j                  dd       | j                  dd       | j                  d| j                  d             | j                  d| j	                  d	d
             t
        j                  t
        j                  j                  d      t
        j                  j                  d      g}| j                  ddj                  |             y )Nr   r   FTr%   customr    r@   r#   r&   r'   r"   )r(   r)   r*   r   r+   r,   r-   r.   r   r/   r0   r5   s     r   test_java_customzRuntimeTests.test_java_customr   s    	2&U48--j.2.@.@.J	L 	--&&v~>	@ ..,,33I>..55i@

 	--l.0gg6I.J	Lr   c                    | j                  dd       | j                  dd      }| j                  d| j                  d             | j	                  |d| j                  d	d
             t        j                  t        j                  j                  d      t        j                  j                  d      g}| j	                  |ddj                  |             y)zTest generate_config_data with custom=True.

        app.yaml should be written to disk. Also tests correct dockerfile
        contents with a .jar.
        r   r   FTr?   r    r@   r#   r&   r'   r"   N)r(   r9   r*   r   r:   r+   r,   r-   r.   r   r/   r0   r;   s      r   test_java_custom_no_writez&RuntimeTests.test_java_custom_no_write   s     		2&--U4-H	--j.2.@.@.J	L 	00&&v~>	@
 ..,,33I>..55i@

 	00GG'(	*r   c                     | j                  dd       | j                  | j                                | j                  t	        j
                  | j                        dg       y )Nz
foo.nojavar   )r(   r   r)   r1   r   r3   r4   )r   s    r   test_java_files_no_javaz$RuntimeTests.test_java_files_no_java   sF    b)..01DNN3l^Dr   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d       t
        j                  t
        j                  j                  d      g}| j                  ddj                  |             | j                  d| j                  d	d
             y )Nfoo.warr   r    r!   r"   r#   Tr$   r&   r'   )r(   r)   r*   r   r   r,   DOCKERFILE_JETTY_PREAMBLEDOCKERFILE_INSTALL_WARr   r0   r+   r5   s     r   test_java_files_with_warz%RuntimeTests.test_java_files_with_war   s    	2&--j.2.@.@.H	JL)O,T*//,,33I>
 	--l,.GG4G,H	J--T77O	Qr   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d      }t        j                  t        j                  j                  d      g}| j                  |ddj                  |             | j                  |d| j                  d	d
             y)z=Test generate_config_data Dockerfile contents with .war file.rG   r   r    r!   r"   r#   Tr$   r&   r'   N)r(   r)   r*   r   r   r9   r,   rH   rI   r   r:   r0   r+   r;   s      r   !test_java_files_with_war_no_writez.RuntimeTests.test_java_files_with_war_no_write   s    	2&--j.2.@.@.H	JL)O,--T-:	//,,33I>
 	00GG'(	* 	00&&v~>	@r   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d       t
        j                  t
        j                  j                  d      t
        j                  j                  d      g}| j                  ddj                  |             | j                  d| j                  d	d
             y )Nr   r   r    r!   r"   r#   Tr$   r&   r'   )r(   r)   r*   r   r   r,   r-   r.   r   r/   r0   r+   r5   s     r   test_java_files_with_jarz%RuntimeTests.test_java_files_with_jar   s    	2&--j.2.@.@.H	JL)O,T*..,,33I>..55i@

 	--l.0gg6I.J	L--&&v~>	@r   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d      }t        j                  t        j                  j                  d      t        j                  j                  d      g}| j                  |ddj                  |             | j                  |d| j                  d	d
             y)z=Test generate_config_data Dockerfile contents with .jar file.r   r   r    r!   r"   r#   Tr$   r&   r'   N)r(   r)   r*   r   r   r9   r,   r-   r.   r   r/   r:   r0   r+   r;   s      r   !test_java_files_with_jar_no_writez.RuntimeTests.test_java_files_with_jar_no_write   s    	2&--j.2.@.@.H	JL)O,--T-:	..,,33I>..55i@

 	00GG'(	* 	00&&v~>	@r   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d       t
        j                  t
        j                  j                  d	      g}| j                  ddj                  |             | j                  d| j                  d
d             y )NWEB-INFr   r    r!   r"   r#   Tr$   .r&   r'   )r(   r)   r*   r   r   r,   DOCKERFILE_COMPAT_PREAMBLEr.   r   r0   r+   r5   s     r   test_java_files_with_webinfz(RuntimeTests.test_java_files_with_webinf   s    	2&--j.2.@.@.H	JL)O,T*00,,33C8
 	--l.0gg6I.J	L--&&v~>	@r   c                    | j                  dd       | j                          | j                  d| j                  d             | j	                  d       | j	                  d       | j                  d      }t        j                  t        j                  j                  d	      g}| j                  |ddj                  |             | j                  |d| j                  d
d             y)zBTest generate_config_data Dockerfile contents with 'WEB-INF' file.rR   r   r    r!   r"   r#   Tr$   rS   r&   r'   N)r(   r)   r*   r   r   r9   r,   rT   r.   r   r:   r0   r+   r;   s      r   $test_java_files_with_webinf_no_writez1RuntimeTests.test_java_files_with_webinf_no_write  s    	2&--j.2.@.@.H	JL)O,--T-:	00,,33C8
 	00GG'(	* 	00&&v~>	@r   c                 J   | j                  dd       | j                  dd       g fd}t        j                  j                  t        j
                  d|i      5  | j                  | j                                d d d        | j                  dg       y # 1 sw Y   xY w)NrR   r   r   c                 (    j                  |        y r	   appendmessageerrorss    r   	ErrorFakezGRuntimeTests.test_java_files_with_too_many_artifacts.<locals>.ErrorFake.      
--
 r   errorz@Too many java artifacts to deploy (.jar, .war, or Java Web App).)	r(   mockpatchdictr   
_LOG_FUNCSr   r)   r1   )r   r_   r^   s     @r   'test_java_files_with_too_many_artifactsz4RuntimeTests.test_java_files_with_too_many_artifacts(  s    	2&	2&	! ZZ__[33gy5IJT2245 K 	+ ,	- KJs    BB"c                 x   | j                  dd       t        j                  ddt        dd            }| j	                  |d	
       t
        j                  t
        j                  j                  d      g}| j                  ddj                  |             | j                  d| j                  dd             y )NrG   r   r!   flexopenjdk8jetty9jdkserverr   envruntime_configTappinfor%   r"   r#   r&   r'   )r(   r   AppInfoFakerd   r)   r,   rH   rI   r   r*   r0   r+   )r   rr   r6   s      r   !test_java_files_with_war_and_yamlz.RuntimeTests.test_java_files_with_war_and_yaml;  s    	2&&&!" 	gd;//,,33I>
 	--l.0gg6I.J	L--&&v~>	@r   c                 |   | j                  dd       t        j                  ddt        dd            }| j	                  |d	
      }t
        j                  t
        j                  j                  d      g}| j                  |ddj                  |             | j                  |d| j                  dd             y)z5Test generate_config_data with .war and fake appinfo.rG   r   r!   2ri   rj   rk   rn   Trq   r"   r#   r&   r'   N)r(   r   rs   rd   r9   r,   rH   rI   r   r:   r0   r+   )r   rr   r<   r6   s       r   *test_java_files_with_war_and_yaml_no_writez7RuntimeTests.test_java_files_with_war_and_yaml_no_writeN  s    	2&&&!" --gd-K	//,,33I>
 	00GG'(	* 	00&&v~>	@r   c                 x   | j                  dd       t        j                  ddt        dd            }| j	                  |d	
       t
        j                  t
        j                  j                  d      g}| j                  ddj                  |             | j                  d| j                  dd             y )NrR   r   r!   rv   ri   rj   rk   rn   Trq   rS   r"   r#   r&   r'   r(   r   rs   rd   r)   r,   rT   r.   r   r*   r0   r+   r   configr6   s      r   .test_java_files_with_web_inf_and_yaml_and_env2z;RuntimeTests.test_java_files_with_web_inf_and_yaml_and_env2e  s    	2&%%  	fT:00,,33C8
 	--l.0gg6I.J	L--&&v~>	@r   c                 |   | j                  dd       t        j                  ddt        dd            }| j	                  |d	
      }t
        j                  t
        j                  j                  d      g}| j                  |ddj                  |             | j                  |d| j                  dd             y)z9Test generate_config_data with .war, fake appinfo, env=2.rR   r   r!   rv   ri   rj   rk   rn   Trq   rS   r"   r#   r&   r'   Nr(   r   rs   rd   r9   r,   rT   r.   r   r:   r0   r+   r   r{   r<   r6   s       r   7test_java_files_with_web_inf_and_yaml_and_env2_no_writezDRuntimeTests.test_java_files_with_web_inf_and_yaml_and_env2_no_writex  s    	2&%%!" --fT-J	00,,33C8
 	00GG'(	* 	00&&v~>	@r   c                 v   | j                  dd       t        j                  ddt        d            }| j	                  |d       t
        j                  t
        j                  j                  d	      g}| j                  d
dj                  |             | j                  d| j                  dd             y )NrR   r   r!   Trj   rm   r   vmrp   rq   rS   r"   r#   r&   r'   )r(   r   rs   rd   r)   r,   DOCKERFILE_LEGACY_PREAMBLEr.   r   r*   r0   r+   rz   s      r   1test_java_files_with_web_inf_and_yaml_and_no_env2z>RuntimeTests.test_java_files_with_web_inf_and_yaml_and_no_env2  s    	2&%%x02 	fT:00,,33C8
 	--l.0gg6I.J	L--&&v~>	@r   c                 z   | j                  dd       t        j                  ddt        d            }| j	                  |d      }t
        j                  t
        j                  j                  d	      g}| j                  |d
dj                  |             | j                  |d| j                  dd             y)z<Test generate_config_data with .war, fake appinfo, env != 2.rR   r   r!   Trj   r   r   rq   rS   r"   r#   r&   r'   N)r(   r   rs   rd   r9   r,   r   r.   r   r:   r0   r+   r   s       r   :test_java_files_with_web_inf_and_yaml_and_no_env2_no_writezGRuntimeTests.test_java_files_with_web_inf_and_yaml_and_no_env2_no_write  s    	2&%%x02 --fT-J	00,,33C8
 	00GG'(	* 	00&&v~>	@r   c                 x   | j                  dd       t        j                  ddt        dd            }| j	                  |d	       t
        j                  t
        j                  j                  d
      g}| j                  ddj                  |             | j                  d| j                  dd             y )NrR   r   r!   Tri   rj   rk   r   rq   rS   r"   r#   r&   r'   ry   rz   s      r   ;test_java_files_with_web_inf_and_yaml_and_open_jdk8_no_env2zHRuntimeTests.test_java_files_with_web_inf_and_yaml_and_open_jdk8_no_env2  s    	2&%%!" 	fT:00,,33C8
 	--l.0gg6I.J	L--&&v~>	@r   c                 |   | j                  dd       t        j                  ddt        dd            }| j	                  |d	      }t
        j                  t
        j                  j                  d
      g}| j                  |ddj                  |             | j                  |d| j                  dd             y)z:Test generate_config_data with WEB-INF file, fake appinfo.rR   r   r!   Tri   rj   rk   r   rq   rS   r"   r#   r&   r'   Nr~   r   s       r   Dtest_java_files_with_web_inf_and_yaml_and_open_jdk8_no_env2_no_writezQRuntimeTests.test_java_files_with_web_inf_and_yaml_and_open_jdk8_no_env2_no_write  s     		2&%%!" --fT-J	00,,33C8
 	00GG'(	* 	00&&v~>	@r   c                 p   | j                  dd       g fd}t        j                  ddt        d            }t        j
                  j                  t        j                  d	|i      5  | j                  | j                  |d
             d d d        | j                  dg       y # 1 sw Y   xY w)NrG   r   c                 (    j                  |        y r	   rZ   r\   s    r   r_   zARuntimeTests.test_java_files_with_config_error.<locals>.ErrorFake  r`   r   r!   rv   openjdk9)rl   rn   ra   Trq   zUnknown JDK : openjdk9.)r(   r   rs   rd   rb   rc   r   re   r   r)   r1   )r   r_   r{   r^   s      @r   !test_java_files_with_config_errorz.RuntimeTests.test_java_files_with_config_error  s    	2&	! %% !
 ZZ__[33gy5IJT226$2OP K";!<= KJs   -#B,,B5c                     | j                  dd       t        j                  dd      }| j                  | j	                  |d             y )Nr   r   r!   rv   r   ro   Trq   )r(   r   rs   
assertTruer)   )r   r{   s     r   test_java_custom_runtime_fieldz+RuntimeTests.test_java_custom_runtime_field  sD    	2&%% 	--fT-JKr   c                 `   | j                  dd       t        j                  dd      }| j                  |d       t        j
                  t        j                  j                  d      g}| j                  ddj                  |             | j                  d	| j                  d
d             y )NrR   r   java7Tr   r   rq   rS   r"   r#   r&   r'   )r(   r   rs   r)   r,   r   r.   r   r*   r0   r+   rz   s      r   test_java7_runtimezRuntimeTests.test_java7_runtime  s    	2&%% 	fT:00,,33C8
 	--l.0gg6I.J	L--&&v~>	@r   c                 d   | j                  dd       t        j                  dd      }| j                  |d      }t        j
                  t        j                  j                  d      g}| j                  |ddj                  |             | j                  |d	| j                  d
d             y)z-Test generate_config_data with java7 runtime.rR   r   r   Tr   rq   rS   r"   r#   r&   r'   N)r(   r   rs   r9   r,   r   r.   r   r:   r0   r+   r   s       r   test_java7_runtime_no_writez(RuntimeTests.test_java7_runtime_no_write  s    	2&%% --fT-J	00,,33C8
 	00GG'(	* 	00&&v~>	@r   c                     | j                  dd       | j                         }| j                  |j                  ddd       y )NrG   r   r!   rh   r   r(   detectr1   generated_appinfor   configurators     r   test_detect_appinfo_warz$RuntimeTests.test_detect_appinfo_war  =    	2&{{}77FAG:I 	Jr   c                     | j                  dd       | j                         }| j                  |j                  ddd       y )Nr   r   r!   rh   r   r   r   s     r   test_detect_appinfo_jarz$RuntimeTests.test_detect_appinfo_jar"  r   r   )!__name__
__module____qualname__r   r   r   r7   r=   rA   rC   rE   rJ   rL   rN   rP   rU   rW   rf   rt   rw   r|   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r   .   s    *@IQ42<L$*4E
Q&@0@*@2@(@0-&@&@.@&@.@"@*@&@0>"L@ @(JJr   r   __main__)__doc__loggingrb   r   resysshutiltempfiletextwrapunittestgae_ext_runtimer   r   r   dirnameabspath__file__ROOT_DIRr[   r0   r,   r
   TestBaser   r   main r   r   <module>r      s     !   	 	 
     $ ' 77??277??277??8+DEF Xu- .  77??277??8#<= xJ8$$ xJt z(--/ r   