You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RuntimeInfoServiceTest.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package org.apache.archiva.web;
  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. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
  20. import org.apache.archiva.redback.rest.services.AbstractRestServicesTest;
  21. import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
  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.lang3.StringUtils;
  26. import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
  27. import org.apache.cxf.jaxrs.client.WebClient;
  28. import org.junit.AfterClass;
  29. import org.junit.Before;
  30. import org.junit.BeforeClass;
  31. import org.junit.Test;
  32. import org.junit.runner.RunWith;
  33. import java.io.IOException;
  34. import java.nio.file.Files;
  35. import java.nio.file.Path;
  36. import java.util.Collections;
  37. /**
  38. * @author Olivier Lamy
  39. */
  40. @RunWith( ArchivaBlockJUnit4ClassRunner.class )
  41. public class RuntimeInfoServiceTest
  42. extends AbstractRestServicesTest
  43. {
  44. private static Path appServerBase;
  45. private static String previousAppServerBase;
  46. @BeforeClass
  47. public static void setAppServerBase()
  48. throws IOException
  49. {
  50. previousAppServerBase = System.getProperty( "appserver.base" );
  51. appServerBase = Files.createTempDirectory( "archiva-common-web_appsrvrt_" );
  52. System.setProperty( "appserver.base", appServerBase.toString( ) );
  53. }
  54. @AfterClass
  55. public static void resetAppServerBase()
  56. {
  57. if (Files.exists(appServerBase)) {
  58. FileUtils.deleteQuietly( appServerBase.toFile() );
  59. }
  60. System.setProperty( "appserver.base", previousAppServerBase );
  61. }
  62. @Override
  63. @Before
  64. public void startServer()
  65. throws Exception
  66. {
  67. Path jcrDirectory = appServerBase.resolve( "jcr" );
  68. if ( Files.exists(jcrDirectory) )
  69. {
  70. org.apache.archiva.common.utils.FileUtils.deleteDirectory( jcrDirectory );
  71. }
  72. super.startServer();
  73. }
  74. @Override
  75. protected String getSpringConfigLocation()
  76. {
  77. return "classpath*:META-INF/spring-context.xml,classpath:/spring-context-with-jcr.xml";
  78. }
  79. @Override
  80. protected String getRestServicesPath()
  81. {
  82. return "restServices";
  83. }
  84. protected String getBaseUrl()
  85. {
  86. String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
  87. return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + getServerPort() : baseUrlSysProps;
  88. }
  89. @Test
  90. public void runtimeInfoService()
  91. throws Exception
  92. {
  93. RuntimeInfoService service =
  94. JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaUiServices/",
  95. RuntimeInfoService.class,
  96. Collections.singletonList( new JacksonJaxbJsonProvider() ) );
  97. WebClient.client(service).header("Referer","http://localhost");
  98. ApplicationRuntimeInfo applicationRuntimeInfo = service.getApplicationRuntimeInfo( "en" );
  99. assertEquals( System.getProperty( "expectedVersion" ), applicationRuntimeInfo.getVersion() );
  100. assertFalse( applicationRuntimeInfo.isJavascriptLog() );
  101. assertTrue( applicationRuntimeInfo.isLogMissingI18n() );
  102. }
  103. }