Просмотр исходного кода

Now using loggers for all output to reduce test noise

Andy Marks 9 лет назад
Родитель
Сommit
79e73f6cf3

+ 4
- 1
src/main/java/se/citerus/dddsample/application/util/SampleDataGenerator.java Просмотреть файл

@@ -1,5 +1,7 @@
1 1
 package se.citerus.dddsample.application.util;
2 2
 
3
+import org.apache.commons.logging.Log;
4
+import org.apache.commons.logging.LogFactory;
3 5
 import org.hibernate.SessionFactory;
4 6
 import org.hibernate.Session;
5 7
 import org.springframework.beans.factory.BeanFactoryUtils;
@@ -33,6 +35,7 @@ import java.util.Date;
33 35
  * Provides sample data.
34 36
  */
35 37
 public class SampleDataGenerator implements ServletContextListener {
38
+  private static final Log logger = LogFactory.getLog(SampleDataGenerator.class);
36 39
 
37 40
   private static final Timestamp base; 
38 41
   static {
@@ -202,7 +205,7 @@ public class SampleDataGenerator implements ServletContextListener {
202 205
   }
203 206
 
204 207
   public static void loadHibernateData(TransactionTemplate tt, final SessionFactory sf, final HandlingEventFactory handlingEventFactory, final HandlingEventRepository handlingEventRepository) {
205
-    System.out.println("*** Loading Hibernate data ***");
208
+    logger.info("*** Loading Hibernate data ***");
206 209
     tt.execute(new TransactionCallbackWithoutResult() {
207 210
       @Override
208 211
       protected void doInTransactionWithoutResult(TransactionStatus status) {

+ 7
- 4
src/test/java/se/citerus/dddsample/infrastructure/messaging/stub/SynchronousApplicationEventsStub.java Просмотреть файл

@@ -1,5 +1,7 @@
1 1
 package se.citerus.dddsample.infrastructure.messaging.stub;
2 2
 
3
+import org.apache.commons.logging.Log;
4
+import org.apache.commons.logging.LogFactory;
3 5
 import se.citerus.dddsample.application.ApplicationEvents;
4 6
 import se.citerus.dddsample.application.CargoInspectionService;
5 7
 import se.citerus.dddsample.domain.model.cargo.Cargo;
@@ -9,6 +11,7 @@ import se.citerus.dddsample.interfaces.handling.HandlingEventRegistrationAttempt
9 11
 public class SynchronousApplicationEventsStub implements ApplicationEvents {
10 12
 
11 13
   CargoInspectionService cargoInspectionService;
14
+  private final Log logger = LogFactory.getLog(getClass());
12 15
 
13 16
   public void setCargoInspectionService(CargoInspectionService cargoInspectionService) {
14 17
     this.cargoInspectionService = cargoInspectionService;
@@ -16,22 +19,22 @@ public class SynchronousApplicationEventsStub implements ApplicationEvents {
16 19
 
17 20
   @Override
18 21
   public void cargoWasHandled(HandlingEvent event) {
19
-    System.out.println("EVENT: cargo was handled: " + event);
22
+    logger.info("EVENT: cargo was handled: " + event);
20 23
     cargoInspectionService.inspectCargo(event.cargo().trackingId());
21 24
   }
22 25
 
23 26
   @Override
24 27
   public void cargoWasMisdirected(Cargo cargo) {
25
-    System.out.println("EVENT: cargo was misdirected");
28
+    logger.info("EVENT: cargo was misdirected");
26 29
   }
27 30
 
28 31
   @Override
29 32
   public void cargoHasArrived(Cargo cargo) {
30
-    System.out.println("EVENT: cargo has arrived: " + cargo.trackingId().idString());
33
+    logger.info("EVENT: cargo has arrived: " + cargo.trackingId().idString());
31 34
   }
32 35
 
33 36
   @Override
34 37
   public void receivedHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt) {
35
-    System.out.println("EVENT: received handling event registration attempt");
38
+    logger.info("EVENT: received handling event registration attempt");
36 39
   }
37 40
 }

+ 3
- 3
src/test/resources/log4j.properties Просмотреть файл

@@ -1,4 +1,4 @@
1
-log4j.rootLogger=info, stdout
1
+log4j.rootLogger=warn, stdout
2 2
 
3 3
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4 4
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
@@ -6,8 +6,8 @@ log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
6 6
 
7 7
 log4j.logger.net.sf.ehcache.config.ConfigurationFactory=error
8 8
 
9
-log4j.logger.se.citerus.dddsample=debug
10
-log4j.logger.org.hibernate.SQL=debug
9
+#log4j.logger.se.citerus.dddsample=info
10
+#log4j.logger.org.hibernate.SQL=info
11 11
 #log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=debug
12 12
 
13 13
 #log4j.logger.org.springframework.orm=debug