]> source.dussan.org Git - archiva.git/blob
60796a3f8c9a685eba49593f9d48df0703c131d8
[archiva.git] /
1 package org.apache.archiva;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20
21 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
22 import org.apache.archiva.redback.rest.services.AbstractRestServicesTest;
23 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
24 import org.apache.archiva.web.api.RuntimeInfoService;
25 import org.apache.archiva.web.model.ApplicationRuntimeInfo;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
28 import org.apache.cxf.jaxrs.client.WebClient;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32
33 import java.nio.file.Files;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36 import java.util.Collections;
37
38 /**
39  * @author Olivier Lamy
40  */
41 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
42 public class RuntimeInfoServiceTest
43     extends AbstractRestServicesTest
44 {
45     @Override
46     @Before
47     public void startServer()
48         throws Exception
49     {
50         Path appServerBase = Paths.get( System.getProperty( "appserver.base" ) );
51
52         Path jcrDirectory =  appServerBase.resolve( "jcr" );
53
54         if ( Files.exists(jcrDirectory) )
55         {
56             org.apache.archiva.common.utils.FileUtils.deleteDirectory( jcrDirectory );
57         }
58
59         super.startServer();
60     }
61
62     @Override
63     protected String getSpringConfigLocation()
64     {
65         return "classpath*:META-INF/spring-context.xml,classpath:/spring-context-with-jcr.xml";
66     }
67
68     @Override
69     protected String getRestServicesPath()
70     {
71         return "restServices";
72     }
73
74     protected String getBaseUrl()
75     {
76         String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
77         return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + port : baseUrlSysProps;
78     }
79
80     @Test
81     public void runtimeInfoService()
82         throws Exception
83     {
84         RuntimeInfoService service =
85             JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaUiServices/",
86                                        RuntimeInfoService.class,
87                                        Collections.singletonList( new JacksonJaxbJsonProvider() ) );
88
89         WebClient.client(service).header("Referer","http://localhost");
90         ApplicationRuntimeInfo applicationRuntimeInfo = service.getApplicationRuntimeInfo( "en" );
91
92         assertEquals( System.getProperty( "expectedVersion" ), applicationRuntimeInfo.getVersion() );
93         assertFalse( applicationRuntimeInfo.isJavascriptLog() );
94         assertTrue( applicationRuntimeInfo.isLogMissingI18n() );
95
96     }
97 }