Search in sources :

Example 1 with TestStartedEvent

use of org.eclipse.n4js.tester.events.TestStartedEvent in project n4js by eclipse.

the class TestEventQueueTest method testHappy.

/**
 */
@Test
public void testHappy() {
    final String sessionId = "sessionId";
    final String testId = "testId";
    queue.init(5);
    post(new SessionStartedEvent(sessionId));
    post(new TestStartedEvent(sessionId, testId, 0L));
    post(new TestPingedEvent(sessionId, testId, 0L));
    post(new TestEndedEvent(sessionId, testId, null));
    post(new SessionEndedEvent(sessionId));
    queue.assertEquals(sessionId, "SessionStartedEvent|SID:sessionId|", "TestStartedEvent|SID:sessionId|TID:testId|", "TestPingedEvent|SID:sessionId|TID:testId|", "TestEndedEvent|SID:sessionId|TID:testId|", "SessionEndedEvent|SID:sessionId|");
}
Also used : TestStartedEvent(org.eclipse.n4js.tester.events.TestStartedEvent) SessionEndedEvent(org.eclipse.n4js.tester.events.SessionEndedEvent) TestPingedEvent(org.eclipse.n4js.tester.events.TestPingedEvent) SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) TestEndedEvent(org.eclipse.n4js.tester.events.TestEndedEvent) Test(org.junit.Test)

Example 2 with TestStartedEvent

use of org.eclipse.n4js.tester.events.TestStartedEvent in project n4js by eclipse.

the class StartTestResource method createEvent.

@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String testId, final String body) throws ClientResourceException {
    if (isNullOrEmpty(body))
        throw new ClientResourceException(SC_BAD_REQUEST);
    final Map<?, ?> values = newHashMap();
    try {
        values.putAll(mapper.readValue(body, Map.class));
    } catch (JsonMappingException | JsonParseException e) {
        throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
    } catch (final IOException e) {
        throw new ClientResourceException(SC_BAD_REQUEST);
    }
    final Object value = values.get(TIMEOUT_KEY);
    // incorrect schema
    if (null == value) {
        throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
    }
    final Map<String, String> properties = newHashMap();
    if (null != values.get(PROPERTIES)) {
        if (!(values.get(PROPERTIES) instanceof Map)) {
            throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
        } else {
            ((Map<?, ?>) values.get(PROPERTIES)).entrySet().forEach(new Consumer<Entry<?, ?>>() {

                @Override
                public void accept(final Entry<?, ?> entry) {
                    properties.put(valueOf(entry.getKey()), valueOf(entry.getValue()));
                }
            });
        }
    }
    try {
        final long timeout = parseLong(valueOf(value));
        return new TestStartedEvent(sessionId, testId, timeout, properties);
    } catch (final NumberFormatException e) {
        // although schema was valid the data was indeed invalid
        throw new ClientResourceException(SC_BAD_REQUEST);
    }
}
Also used : IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ClientResourceException(org.eclipse.n4js.tester.server.resources.ClientResourceException) TestStartedEvent(org.eclipse.n4js.tester.events.TestStartedEvent) Entry(java.util.Map.Entry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap)

Example 3 with TestStartedEvent

use of org.eclipse.n4js.tester.events.TestStartedEvent in project n4js by eclipse.

the class TestResultsView method notifyTestEvent.

/**
 * Update UI according to given {@link TestEvent}.
 */
public void notifyTestEvent(TestEvent event) {
    if (event instanceof SessionStartedEvent) {
    // ignore
    } else if (event instanceof TestStartedEvent) {
        notifyTestCaseStarted(new ID(((TestStartedEvent) event).getTestId()));
    } else if (event instanceof TestEndedEvent) {
        final TestEndedEvent teev = (TestEndedEvent) event;
        notifyTestCaseEnded(new ID(teev.getTestId()), teev.getResult());
    } else if (event instanceof SessionEndedEvent) {
        // event received from client side
        notifySessionEnded(new ID(event.getSessionId()));
    } else if (event instanceof SessionFinishedEvent) {
    // server completed test session SUCCESS
    // ignore
    } else if (event instanceof SessionFailedEvent) {
    // server completed test session FAILURE
    // ignore
    } else {
    // ignore all other events (e.g. TestPingedEvent)
    }
}
Also used : TestStartedEvent(org.eclipse.n4js.tester.events.TestStartedEvent) SessionFinishedEvent(org.eclipse.n4js.tester.events.SessionFinishedEvent) SessionEndedEvent(org.eclipse.n4js.tester.events.SessionEndedEvent) SessionFailedEvent(org.eclipse.n4js.tester.events.SessionFailedEvent) ID(org.eclipse.n4js.tester.domain.ID) SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) TestEndedEvent(org.eclipse.n4js.tester.events.TestEndedEvent)

Example 4 with TestStartedEvent

use of org.eclipse.n4js.tester.events.TestStartedEvent in project n4js by eclipse.

the class TestFsmRegistryImpl method receivedTestEvent.

/**
 * Percepts any {@link TestEvent test event} and delegates it to the corresponding tester finite state machine.
 *
 * @param event
 *            the received event that will be processed.
 */
@Subscribe
@AllowConcurrentEvents
public void receivedTestEvent(final TestEvent event) {
    if (event instanceof SessionFailedEvent && ((SessionFailedEvent) event).getComment().isPresent()) {
        LOGGER.error("Received event: " + event + ". Reason: " + ((SessionFailedEvent) event).getComment().get());
    } else {
        if (debugEnabled) {
            LOGGER.debug("Received event: " + event);
        }
    }
    final String sessionId = event.getSessionId();
    if (event instanceof SessionStartedEvent) {
        if (!isSessionExist(sessionId)) {
            registerFsm(sessionId);
        }
        getSession(sessionId).startSession(sessionId);
    } else if (event instanceof SessionPingedEvent) {
        final long timeout = ((SessionPingedEvent) event).getTimeout();
        getSession(sessionId).pingSession(sessionId, timeout);
    } else if (event instanceof SessionEndedEvent) {
        final TestFsm fsm = getSession(sessionId).endSession(sessionId);
        if (fsm instanceof TestFsmImpl && !((TestFsmImpl) fsm).isFailed()) {
            if (!treeRegistry.validateTestTree(sessionId)) {
                ((TestFsmImpl) fsm).fail("Test session failed due to invalid final state of the test tree. " + "There are test cases without any test results after receiving session ended event.");
                return;
            }
        }
        bus.post(new SessionFinishedEvent(sessionId));
    } else if (event instanceof SessionFailedEvent) {
        treeRegistry.purgeTestTree(sessionId);
        unregisterFsm(sessionId);
    } else if (event instanceof SessionFinishedEvent) {
        unregisterFsm(sessionId);
    } else if (event instanceof TestStartedEvent) {
        final String testId = ((TestStartedEvent) event).getTestId();
        final long timeout = ((TestStartedEvent) event).getTimeout();
        getSession(sessionId).startTest(testId, timeout);
    } else if (event instanceof TestPingedEvent) {
        final long timeout = ((TestPingedEvent) event).getTimeout();
        final String testId = ((TestPingedEvent) event).getTestId();
        getSession(sessionId).pingTest(testId, timeout);
    } else if (event instanceof TestEndedEvent) {
        final TestEndedEvent testEndedEvent = (TestEndedEvent) event;
        final String testId = testEndedEvent.getTestId();
        final TestFsm fsm = getSession(sessionId).endTest(testId);
        if (fsm instanceof TestFsmImpl && !((TestFsmImpl) fsm).isFailed()) {
            treeRegistry.putTestResult(sessionId, testId, testEndedEvent.getResult());
        }
    } else {
        LOGGER.error("Unexpected test event: " + event);
    }
}
Also used : TestStartedEvent(org.eclipse.n4js.tester.events.TestStartedEvent) SessionFinishedEvent(org.eclipse.n4js.tester.events.SessionFinishedEvent) SessionEndedEvent(org.eclipse.n4js.tester.events.SessionEndedEvent) SessionFailedEvent(org.eclipse.n4js.tester.events.SessionFailedEvent) TestPingedEvent(org.eclipse.n4js.tester.events.TestPingedEvent) SessionPingedEvent(org.eclipse.n4js.tester.events.SessionPingedEvent) SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) TestEndedEvent(org.eclipse.n4js.tester.events.TestEndedEvent) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

TestStartedEvent (org.eclipse.n4js.tester.events.TestStartedEvent)4 SessionEndedEvent (org.eclipse.n4js.tester.events.SessionEndedEvent)3 SessionStartedEvent (org.eclipse.n4js.tester.events.SessionStartedEvent)3 TestEndedEvent (org.eclipse.n4js.tester.events.TestEndedEvent)3 SessionFailedEvent (org.eclipse.n4js.tester.events.SessionFailedEvent)2 SessionFinishedEvent (org.eclipse.n4js.tester.events.SessionFinishedEvent)2 TestPingedEvent (org.eclipse.n4js.tester.events.TestPingedEvent)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)1 Subscribe (com.google.common.eventbus.Subscribe)1 IOException (java.io.IOException)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ID (org.eclipse.n4js.tester.domain.ID)1 SessionPingedEvent (org.eclipse.n4js.tester.events.SessionPingedEvent)1 ClientResourceException (org.eclipse.n4js.tester.server.resources.ClientResourceException)1 Test (org.junit.Test)1