Search in sources :

Example 1 with SessionStartedEvent

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

the class StartSessionResource method createEvent.

@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String body) throws ClientResourceException {
    final Map<?, ?> values = newHashMap();
    try {
        if (!isNullOrEmpty(body)) {
            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 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()));
                }
            });
        }
    }
    return new SessionStartedEvent(sessionId, properties);
}
Also used : IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) ClientResourceException(org.eclipse.n4js.tester.server.resources.ClientResourceException) Entry(java.util.Map.Entry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map)

Example 2 with SessionStartedEvent

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

the class TestEventQueueTest method testExpectedIsMoreThanActual.

/**
 */
@Test(expected = AssertionError.class)
public void testExpectedIsMoreThanActual() {
    final String sessionId = "sessionId";
    queue.init(1);
    post(new SessionStartedEvent(sessionId));
    queue.assertEquals(sessionId, "SessionStartedEvent|SID:sessionId|", "SessionStartedEvent|SID:sessionId|");
}
Also used : SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) Test(org.junit.Test)

Example 3 with SessionStartedEvent

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

the class TestEventQueueTest method testAssertFailedNonMatchingTailEvent.

/**
 */
@Test(expected = AssertionError.class)
public void testAssertFailedNonMatchingTailEvent() {
    final String sessionId = "sessionId";
    queue.init(1);
    post(new SessionStartedEvent(sessionId));
    queue.assertFailed(sessionId);
}
Also used : SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) Test(org.junit.Test)

Example 4 with SessionStartedEvent

use of org.eclipse.n4js.tester.events.SessionStartedEvent 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 5 with SessionStartedEvent

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

the class TestEventQueueTest method testExpectedNotEqualsActual.

/**
 */
@Test(expected = AssertionError.class)
public void testExpectedNotEqualsActual() {
    final String sessionId = "sessionId";
    queue.init(1);
    post(new SessionStartedEvent(sessionId));
    queue.assertEquals(sessionId, "SessionEndedEvent|SID:sessionId|");
}
Also used : SessionStartedEvent(org.eclipse.n4js.tester.events.SessionStartedEvent) Test(org.junit.Test)

Aggregations

SessionStartedEvent (org.eclipse.n4js.tester.events.SessionStartedEvent)11 Test (org.junit.Test)8 SessionEndedEvent (org.eclipse.n4js.tester.events.SessionEndedEvent)3 SessionFailedEvent (org.eclipse.n4js.tester.events.SessionFailedEvent)3 TestEndedEvent (org.eclipse.n4js.tester.events.TestEndedEvent)3 TestStartedEvent (org.eclipse.n4js.tester.events.TestStartedEvent)3 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 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