Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

StartupLogsTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.app;
  21. import org.apache.catalina.connector.Connector;
  22. import org.apache.catalina.startup.Tomcat;
  23. import org.junit.Rule;
  24. import org.junit.Test;
  25. import org.junit.rules.ExpectedException;
  26. import org.mockito.Mockito;
  27. import org.sonar.api.utils.log.Logger;
  28. import static org.junit.Assert.fail;
  29. import static org.mockito.Mockito.mock;
  30. import static org.mockito.Mockito.verify;
  31. import static org.mockito.Mockito.verifyNoMoreInteractions;
  32. import static org.mockito.Mockito.when;
  33. public class StartupLogsTest {
  34. @Rule
  35. public ExpectedException expectedException = ExpectedException.none();
  36. private Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS);
  37. private Logger logger = mock(Logger.class);
  38. private TomcatStartupLogs underTest = new TomcatStartupLogs(logger);
  39. @Test
  40. public void fail_with_IAE_on_unsupported_protocol() {
  41. Connector connector = newConnector("AJP/1.3", "ajp");
  42. when(tomcat.getService().findConnectors()).thenReturn(new Connector[] {connector});
  43. expectedException.expect(IllegalArgumentException.class);
  44. expectedException.expectMessage("Unsupported connector: Connector[AJP/1.3-1234]");
  45. underTest.log(tomcat);
  46. }
  47. @Test
  48. public void logHttp() {
  49. Connector connector = newConnector("HTTP/1.1", "http");
  50. when(tomcat.getService().findConnectors()).thenReturn(new Connector[] {connector});
  51. underTest.log(tomcat);
  52. verify(logger).info("HTTP connector enabled on port 1234");
  53. verifyNoMoreInteractions(logger);
  54. }
  55. @Test
  56. public void unsupported_connector() {
  57. Connector connector = mock(Connector.class, Mockito.RETURNS_DEEP_STUBS);
  58. when(connector.getProtocol()).thenReturn("SPDY/1.1");
  59. when(connector.getScheme()).thenReturn("spdy");
  60. when(tomcat.getService().findConnectors()).thenReturn(new Connector[] {connector});
  61. try {
  62. underTest.log(tomcat);
  63. fail();
  64. } catch (IllegalArgumentException e) {
  65. // expected
  66. }
  67. }
  68. private Connector newConnector(String protocol, String schema) {
  69. Connector httpConnector = new Connector(protocol);
  70. httpConnector.setScheme(schema);
  71. httpConnector.setPort(1234);
  72. return httpConnector;
  73. }
  74. }