001 /****************************************************************************** 002 * Copyright (C) MActor Developers. All rights reserved. * 003 * ---------------------------------------------------------------------------* 004 * This file is part of MActor. * 005 * * 006 * MActor is free software; you can redistribute it and/or modify * 007 * it under the terms of the GNU General Public License as published by * 008 * the Free Software Foundation; either version 2 of the License, or * 009 * (at your option) any later version. * 010 * * 011 * MActor is distributed in the hope that it will be useful, * 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 014 * GNU General Public License for more details. * 015 * * 016 * You should have received a copy of the GNU General Public License * 017 * along with MActor; if not, write to the Free Software * 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * 019 ******************************************************************************/ 020 package org.mactor.framework; 021 022 import java.util.Calendar; 023 import java.util.Collections; 024 import java.util.Comparator; 025 import java.util.LinkedList; 026 import java.util.List; 027 import java.util.Map; 028 029 import org.mactor.brokers.Message; 030 import org.mactor.brokers.MessageContextInfo; 031 import org.mactor.framework.spec.SpecNode; 032 033 public class TestSummary_old { 034 private MessageInfo[] messageHistory; 035 private Map<String, String> contextValues; 036 private Calendar testStartTime; 037 private Calendar testCompleteTime; 038 private boolean success; 039 private String failedMessage; 040 public Map<String, String> getContextValues() { 041 return contextValues; 042 } 043 public String getFailedMessage() { 044 return failedMessage; 045 } 046 public MessageInfo[] getMessageHistory() { 047 return messageHistory; 048 } 049 public boolean isSuccess() { 050 return success; 051 } 052 public Calendar getTestCompleteTime() { 053 return testCompleteTime; 054 } 055 public Calendar getTestStartTime() { 056 return testStartTime; 057 } 058 public static TestSummary_old create(TestContext context, LinkedList<TestEvent> events) { 059 TestSummary_old ts = new TestSummary_old(); 060 ts.contextValues = context.getValues(); 061 ts.messageHistory = getSortedMessageHistory(context); 062 if (events != null && events.size() > 0) { 063 ts.testStartTime = events.getFirst().getTime(); 064 TestEvent last = events.getLast(); 065 ts.testCompleteTime = last.getTime(); 066 ts.success = last.isSuccessfulTestCompleteEvent(); 067 if (last.isFaultTestCompleteEvent()) { 068 TestEvent errorNode = events.get(events.size() - 2); 069 ts.failedMessage = errorNode.getNode().getName() + " - failed with: " + (errorNode.getCause() == null ? "unknown reason" : errorNode.getCause().getMessage()); 070 } 071 } 072 return ts; 073 } 074 private static MessageInfo[] getSortedMessageHistory(TestContext context) { 075 List<MessageInfo> result = new LinkedList<MessageInfo>(); 076 List<Message> all = context.getAllMessages(); 077 Collections.sort(all, new Comparator<Message>() { 078 public int compare(Message m0, Message m1) { 079 long n0 = m0.getMessageContextInfo().getMessageSequenceNumber(); 080 long n1 = m1.getMessageContextInfo().getMessageSequenceNumber(); 081 if (n0 == n1) 082 return 0; 083 if (n0 > n1) 084 return 1; 085 return -1; 086 } 087 }); 088 for (Message m : all) { 089 if (!m.getMessageContextInfo().isResponseMessage()) { 090 result.add(MessageInfo.create(m.getMessageContextInfo())); 091 if (m.getMessageContextInfo().hasResponseMessage()) 092 result.add(MessageInfo.create(m.getMessageContextInfo().getResponseMessage().getMessageContextInfo())); 093 } 094 } 095 return result.toArray(new MessageInfo[result.size()]); 096 } 097 public static class MessageInfo { 098 private String archivePath; 099 private SpecNode node; 100 private String channel; 101 private Calendar createdTime; 102 private boolean incoming; 103 private boolean response; 104 public static MessageInfo create(MessageContextInfo mci) { 105 MessageInfo mi = new MessageInfo(); 106 mi.archivePath = mci.getArchivePath(); 107 mi.channel = mci.getChannel(); 108 mi.createdTime = mci.getCreatedTime(); 109 mi.node = mci.getNode(); 110 mi.incoming = mci.isIncoming(); 111 mi.response = mci.isResponseMessage(); 112 return mi; 113 } 114 public String getArchivePath() { 115 return archivePath; 116 } 117 public String getChannel() { 118 return channel; 119 } 120 public Calendar getCreatedTime() { 121 return createdTime; 122 } 123 public boolean isIncoming() { 124 return incoming; 125 } 126 public SpecNode getNode() { 127 return node; 128 } 129 public boolean isResponse() { 130 return response; 131 } 132 } 133 }