PageRenderTime 60ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/qpid-0.14/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java

#
Java | 132 lines | 62 code | 25 blank | 45 comment | 0 complexity | 5dc42a5092b13588f22ec25294985960 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  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. package org.apache.qpid.server.logging.actors;
  22. import org.apache.qpid.AMQException;
  23. import org.apache.qpid.server.logging.LogMessage;
  24. import org.apache.qpid.server.logging.LogSubject;
  25. import java.util.List;
  26. /**
  27. * Test : AMQPConnectionActorTest
  28. * Validate the AMQPConnectionActor class.
  29. *
  30. * The test creates a new AMQPActor and then logs a message using it.
  31. *
  32. * The test then verifies that the logged message was the only one created and
  33. * that the message contains the required message.
  34. */
  35. public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
  36. {
  37. @Override
  38. public void configure()
  39. {
  40. // Prevent defaulting Logging to ON
  41. }
  42. @Override
  43. public void createBroker()
  44. {
  45. //Prevent auto-broker startup
  46. }
  47. /**
  48. * Test the AMQPActor logging as a Connection level.
  49. *
  50. * The test sends a message then verifies that it entered the logs.
  51. *
  52. * The log message should be fully repalaced (no '{n}' values) and should
  53. * not contain any channel identification.
  54. */
  55. public void testConnection() throws Exception
  56. {
  57. getConfigXml().setProperty("status-updates", "ON");
  58. super.createBroker();
  59. final String message = sendLogMessage();
  60. List<Object> logs = _rawLogger.getLogMessages();
  61. assertEquals("Message log size not as expected.", 1, logs.size());
  62. // Verify that the logged message is present in the output
  63. assertTrue("Message was not found in log message",
  64. logs.get(0).toString().contains(message));
  65. // Verify that the message has the correct type
  66. assertTrue("Message does not contain the [con: prefix",
  67. logs.get(0).toString().contains("[con:"));
  68. // Verify that all the values were presented to the MessageFormatter
  69. // so we will not end up with '{n}' entries in the log.
  70. assertFalse("Verify that the string does not contain any '{'.",
  71. logs.get(0).toString().contains("{"));
  72. // Verify that the logged message does not contains the 'ch:' marker
  73. assertFalse("Message was logged with a channel identifier." + logs.get(0),
  74. logs.get(0).toString().contains("/ch:"));
  75. }
  76. public void testConnectionLoggingOff() throws Exception, AMQException
  77. {
  78. getConfigXml().setProperty("status-updates", "OFF");
  79. // Start the broker now.
  80. super.createBroker();
  81. sendLogMessage();
  82. List<Object> logs = _rawLogger.getLogMessages();
  83. assertEquals("Message log size not as expected.", 0, logs.size());
  84. }
  85. private String sendLogMessage()
  86. {
  87. final String message = "test logging";
  88. _amqpActor.message(new LogSubject()
  89. {
  90. public String toLogString()
  91. {
  92. return "[AMQPActorTest]";
  93. }
  94. }, new LogMessage()
  95. {
  96. public String toString()
  97. {
  98. return message;
  99. }
  100. public String getLogHierarchy()
  101. {
  102. return "test.hieracrchy";
  103. }
  104. });
  105. return message;
  106. }
  107. }