Search in sources :

Example 1 with Message

use of com.codename1.messaging.Message in project pact-jvm by DiUS.

the class MessagePactProviderRule method apply.

/* (non-Javadoc)
	 * @see org.junit.rules.ExternalResource#apply(org.junit.runners.model.Statement, org.junit.runner.Description)
	 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            PactVerifications pactVerifications = description.getAnnotation(PactVerifications.class);
            if (pactVerifications != null) {
                evaluatePactVerifications(pactVerifications, base, description);
                return;
            }
            PactVerification pactDef = description.getAnnotation(PactVerification.class);
            // no pactVerification? execute the test normally
            if (pactDef == null) {
                base.evaluate();
                return;
            }
            Message providedMessage = null;
            Map<String, Message> pacts;
            if (StringUtils.isNoneEmpty(pactDef.fragment())) {
                Optional<Method> possiblePactMethod = findPactMethod(pactDef);
                if (!possiblePactMethod.isPresent()) {
                    base.evaluate();
                    return;
                }
                pacts = new HashMap<>();
                Method method = possiblePactMethod.get();
                Pact pact = method.getAnnotation(Pact.class);
                MessagePactBuilder builder = MessagePactBuilder.consumer(pact.consumer()).hasPactWith(provider);
                messagePact = (MessagePact) method.invoke(testClassInstance, builder);
                for (Message message : messagePact.getMessages()) {
                    pacts.put(message.getProviderState(), message);
                }
            } else {
                pacts = parsePacts();
            }
            if (pactDef.value().length == 2 && !pactDef.value()[1].trim().isEmpty()) {
                providedMessage = pacts.get(pactDef.value()[1].trim());
            } else if (!pacts.isEmpty()) {
                providedMessage = pacts.values().iterator().next();
            }
            if (providedMessage == null) {
                base.evaluate();
                return;
            }
            setMessage(providedMessage.contentsAsBytes(), description);
            try {
                base.evaluate();
                messagePact.write(PactConsumerConfig$.MODULE$.pactRootDir());
            } catch (Throwable t) {
                throw t;
            }
        }
    };
}
Also used : Message(au.com.dius.pact.model.v3.messaging.Message) Statement(org.junit.runners.model.Statement) MessagePact(au.com.dius.pact.model.v3.messaging.MessagePact) Method(java.lang.reflect.Method)

Example 2 with Message

use of com.codename1.messaging.Message in project pact-jvm by DiUS.

the class MessagePactBuilder method withContent.

public MessagePactBuilder withContent(DslPart body) {
    if (messages == null || messages.isEmpty()) {
        throw new InvalidPactException("expectsToReceive is required before withMetaData");
    }
    Message message = messages.get(messages.size() - 1);
    @SuppressWarnings("unchecked") Map<String, String> metadata = message.getMetaData();
    if (metadata == null) {
        metadata = new HashMap<String, String>(1);
        metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
    } else if (!metadata.containsKey(CONTENT_TYPE)) {
        metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
    }
    message.setContents(OptionalBody.body(body.toString()));
    message.setMatchingRules(body.getMatchers());
    return this;
}
Also used : Message(au.com.dius.pact.model.v3.messaging.Message) InvalidPactException(au.com.dius.pact.model.InvalidPactException)

Example 3 with Message

use of com.codename1.messaging.Message in project pact-jvm by DiUS.

the class MessagePactBuilder method expectsToReceive.

/**
   * Adds a message expectation in the pact.
   *
   * @param description message description.
   */
public MessagePactBuilder expectsToReceive(String description) {
    Message message = new Message(description, providerState);
    if (messages == null) {
        messages = new ArrayList<Message>();
    }
    messages.add(message);
    return this;
}
Also used : Message(au.com.dius.pact.model.v3.messaging.Message)

Example 4 with Message

use of com.codename1.messaging.Message in project pact-jvm by DiUS.

the class MessagePactProviderRule method parsePacts.

@SuppressWarnings("unchecked")
private Map<String, Message> parsePacts() {
    if (providerStateMessages == null) {
        providerStateMessages = new HashMap<String, Message>();
        for (Method m : testClassInstance.getClass().getMethods()) {
            if (conformsToSignature(m)) {
                Pact pact = m.getAnnotation(Pact.class);
                if (pact != null) {
                    String provider = pact.provider();
                    if (provider != null && !provider.trim().isEmpty()) {
                        MessagePactBuilder builder = MessagePactBuilder.consumer(pact.consumer()).hasPactWith(provider);
                        List<Message> messages = null;
                        try {
                            messagePact = (MessagePact) m.invoke(testClassInstance, builder);
                            messages = messagePact.getMessages();
                        } catch (Exception e) {
                            throw new RuntimeException("Failed to invoke pact method", e);
                        }
                        for (Message message : messages) {
                            providerStateMessages.put(message.getProviderState(), message);
                        }
                    }
                }
            }
        }
    }
    return providerStateMessages;
}
Also used : Message(au.com.dius.pact.model.v3.messaging.Message) MessagePact(au.com.dius.pact.model.v3.messaging.MessagePact) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class Validator method setValid.

void setValid(Component cmp, boolean v) {
    Boolean b = (Boolean) cmp.getClientProperty(VALID_MARKER);
    if (b != null && b.booleanValue() == v) {
        return;
    }
    cmp.putClientProperty(VALID_MARKER, v);
    if (!v) {
        // if one component is invalid... just disable the submit buttons
        for (Component c : submitButtons) {
            c.setEnabled(false);
        }
    } else {
        boolean isV = isValid();
        for (Component c : submitButtons) {
            c.setEnabled(isV);
        }
        if (message != null && cmp.hasFocus()) {
            message.dispose();
        }
    }
    if (cmp instanceof InputComponent && ((InputComponent) cmp).isOnTopMode()) {
        InputComponent tc = (InputComponent) cmp;
        if (v) {
            tc.errorMessage(null);
        } else {
            tc.errorMessage(getErrorMessage(cmp));
        }
    }
    if (validationFailureHighlightMode == HighlightMode.EMBLEM || validationFailureHighlightMode == HighlightMode.UIID_AND_EMBLEM) {
        if (!(cmp.getComponentForm().getGlassPane() instanceof ComponentListener)) {
            cmp.getComponentForm().setGlassPane(new ComponentListener(null));
        }
    }
    if (v) {
        if (validationFailureHighlightMode == HighlightMode.UIID || validationFailureHighlightMode == HighlightMode.UIID_AND_EMBLEM) {
            String uiid = cmp.getUIID();
            if (uiid.endsWith("Invalid")) {
                uiid = uiid.substring(0, uiid.length() - 7);
                cmp.setUIID(uiid);
            }
            return;
        }
        if (validationFailureHighlightMode == HighlightMode.EMBLEM && validationFailedEmblem != null) {
        }
    } else {
        if (validationFailureHighlightMode == HighlightMode.UIID || validationFailureHighlightMode == HighlightMode.UIID_AND_EMBLEM) {
            String uiid = cmp.getUIID();
            if (!uiid.endsWith("Invalid")) {
                cmp.setUIID(uiid + "Invalid");
            }
            return;
        }
    }
}
Also used : InputComponent(com.codename1.ui.InputComponent) TextComponent(com.codename1.ui.TextComponent) Component(com.codename1.ui.Component) InputComponent(com.codename1.ui.InputComponent)

Aggregations

ConnectionRequest (com.codename1.io.ConnectionRequest)8 ActionListener (com.codename1.ui.events.ActionListener)6 IOException (java.io.IOException)5 Message (au.com.dius.pact.model.v3.messaging.Message)4 ActionEvent (com.codename1.ui.events.ActionEvent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 MessagePact (au.com.dius.pact.model.v3.messaging.MessagePact)2 BufferedInputStream (com.codename1.io.BufferedInputStream)2 NetworkEvent (com.codename1.io.NetworkEvent)2 Message (com.codename1.messaging.Message)2 Dialog (com.codename1.ui.Dialog)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 DataInputStream (java.io.DataInputStream)2 Method (java.lang.reflect.Method)2 Hashtable (java.util.Hashtable)2 Vector (java.util.Vector)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1