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;
}
}
};
}
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;
}
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;
}
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;
}
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;
}
}
}
Aggregations