1 package org.apache.archiva;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
22 import org.apache.archiva.web.api.RuntimeInfoService;
23 import org.apache.archiva.web.model.ApplicationRuntimeInfo;
24 import org.apache.commons.io.FileUtils;
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
27 import org.apache.archiva.redback.rest.services.AbstractRestServicesTest;
28 import org.apache.cxf.jaxrs.client.WebClient;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 import java.io.File;
33 import java.util.Collections;
34 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
35 import org.junit.runner.RunWith;
36
37
38
39
40 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
41 public class RuntimeInfoServiceTest
42 extends AbstractRestServicesTest
43 {
44 @Override
45 @Before
46 public void startServer()
47 throws Exception
48 {
49 File appServerBase = new File( System.getProperty( "appserver.base" ) );
50
51 File jcrDirectory = new File( appServerBase, "jcr" );
52
53 if ( jcrDirectory.exists() )
54 {
55 FileUtils.deleteDirectory( jcrDirectory );
56 }
57
58 super.startServer();
59 }
60
61 @Override
62 protected String getSpringConfigLocation()
63 {
64 return "classpath*:META-INF/spring-context.xml,classpath:/spring-context-with-jcr.xml";
65 }
66
67 @Override
68 protected String getRestServicesPath()
69 {
70 return "restServices";
71 }
72
73 protected String getBaseUrl()
74 {
75 String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
76 return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + port : baseUrlSysProps;
77 }
78
79 @Test
80 public void runtimeInfoService()
81 throws Exception
82 {
83 RuntimeInfoService service =
84 JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaUiServices/",
85 RuntimeInfoService.class,
86 Collections.singletonList( new JacksonJaxbJsonProvider() ) );
87
88 WebClient.client(service).header("Referer","http://localhost");
89 ApplicationRuntimeInfo applicationRuntimeInfo = service.getApplicationRuntimeInfo( "en" );
90
91 assertEquals( System.getProperty( "expectedVersion" ), applicationRuntimeInfo.getVersion() );
92 assertFalse( applicationRuntimeInfo.isJavascriptLog() );
93 assertTrue( applicationRuntimeInfo.isLogMissingI18n() );
94
95 }
96 }