blob: f36663c38b56991a2bdaecb8e5131c0fd82bdec8 [file] [log] [blame]
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.deploy;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.deploy.AppLifeCycle.Phase;
import org.eclipse.jetty.deploy.AppLifeCycle.State;
import org.eclipse.jetty.deploy.TrackedEvent.Call;
import org.junit.Assert;
/**
* Binds to all lifecycle phases, and tracks the order of the lifecycle phases for testing purposes.
*/
public class AppLifeCycleEventsAssert
{
private List<TrackedEvent> events = new ArrayList<TrackedEvent>();
public void addSuccessfulStep(Phase phase, State state)
{
AppLifeCycleEvent phaseEvent = new AppLifeCycleEvent();
phaseEvent.setLifeCyclePhase(phase);
events.add(new TrackedEvent(Call.BEFORE_PHASE,phaseEvent));
events.add(new TrackedEvent(Call.PHASE,phaseEvent));
AppLifeCycleEvent stateEvent = new AppLifeCycleEvent();
stateEvent.setLifeCycleState(state);
events.add(new TrackedEvent(Call.STATE,stateEvent));
}
public void assertCollected(String msg, List<TrackedEvent> actualEvents)
{
if (actualEvents.size() != events.size())
{
System.out.println("/* Expected Events */");
for (TrackedEvent event : events)
{
System.out.println(event);
}
System.out.println("/* Actual Events */");
for (TrackedEvent event : actualEvents)
{
System.out.println(event);
}
Assert.assertEquals(msg + " / count",0,events.size());
}
for (int i = 0, n = actualEvents.size(); i < n; i++)
{
TrackedEvent expected = actualEvents.get(i);
TrackedEvent actual = events.get(i);
Assert.assertEquals(msg + "[" + i + "].call",expected.getCall(),actual.getCall());
Assert.assertEquals(msg + "[" + i + "].event.phase",expected.getEvent().getLifeCyclePhase(),actual.getEvent().getLifeCyclePhase());
Assert.assertEquals(msg + "[" + i + "].event.state",expected.getEvent().getLifeCycleState(),actual.getEvent().getLifeCycleState());
}
}
public void clear()
{
events.clear();
}
public List<TrackedEvent> getEvents()
{
return events;
}
}