use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUriPatternException in project mule-coap-connector by teslanet-nl.
the class Listener method onStart.
@Override
public void onStart(SourceCallback<InputStream, CoAPRequestAttributes> sourceCallback) throws MuleException {
try {
operationalListener = new OperationalListener(pathPattern, new RequestCodeFlags(get, post, put, delete), sourceCallback);
server.addListener(operationalListener);
} catch (InternalResourceUriException | InternalUriPatternException e) {
new DefaultMuleException(this + " start failed.", e);
}
logger.info(this + " started.");
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUriPatternException in project mule-coap-connector by teslanet-nl.
the class ResourceRegistryStaticMethodsTest method testMatchUri.
@Test
public void testMatchUri() throws InvalidResourceUriException, InternalUriPatternException {
String uri1 = "/resource1";
String uri2 = "/resource1/resource2";
String uri3 = "/resource1/resource2/resource3";
String uri4 = "/resource1/resource4";
String pattern1 = "/*";
String pattern2 = "/resource1/*";
String pattern3 = "/resource1/resource2/*";
String pattern4 = "/resource1/resource4/*";
// actually not supported:
String pattern5 = "/*/resource4";
assertEquals("wrong match against pattern: " + uri1 + " on uri: " + uri1, Integer.MAX_VALUE, ResourceRegistry.matchUri(uri1, uri1));
assertEquals("wrong match against pattern: " + uri2 + " on uri: " + uri2, Integer.MAX_VALUE, ResourceRegistry.matchUri(uri2, uri2));
assertEquals("wrong match against pattern: " + uri3 + " on uri: " + uri3, Integer.MAX_VALUE, ResourceRegistry.matchUri(uri3, uri3));
assertEquals("wrong match against pattern: " + uri4 + " on uri: " + uri4, Integer.MAX_VALUE, ResourceRegistry.matchUri(uri4, uri4));
assertEquals("wrong match against pattern: " + pattern1 + " on uri: " + uri1, 1, ResourceRegistry.matchUri(pattern1, uri1));
assertEquals("wrong match against pattern: " + pattern1 + " on uri: " + uri2, 1, ResourceRegistry.matchUri(pattern1, uri2));
assertEquals("wrong match against pattern: " + pattern1 + " on uri: " + uri3, 1, ResourceRegistry.matchUri(pattern1, uri3));
assertEquals("wrong match against pattern: " + pattern1 + " on uri: " + uri4, 1, ResourceRegistry.matchUri(pattern1, uri4));
assertEquals("wrong match against pattern: " + pattern2 + " on uri: " + uri1, 0, ResourceRegistry.matchUri(pattern2, uri1));
assertEquals("wrong match against pattern: " + pattern2 + " on uri: " + uri2, 2, ResourceRegistry.matchUri(pattern2, uri2));
assertEquals("wrong match against pattern: " + pattern2 + " on uri: " + uri3, 2, ResourceRegistry.matchUri(pattern2, uri3));
assertEquals("wrong match against pattern: " + pattern2 + " on uri: " + uri4, 2, ResourceRegistry.matchUri(pattern2, uri4));
assertEquals("wrong match against pattern: " + pattern3 + " on uri: " + uri1, 0, ResourceRegistry.matchUri(pattern3, uri1));
assertEquals("wrong match against pattern: " + pattern3 + " on uri: " + uri2, 0, ResourceRegistry.matchUri(pattern3, uri2));
assertEquals("wrong match against pattern: " + pattern3 + " on uri: " + uri3, 3, ResourceRegistry.matchUri(pattern3, uri3));
assertEquals("wrong match against pattern: " + pattern3 + " on uri: " + uri4, 0, ResourceRegistry.matchUri(pattern3, uri4));
assertEquals("wrong match against pattern: " + pattern4 + " on uri: " + uri1, 0, ResourceRegistry.matchUri(pattern4, uri1));
assertEquals("wrong match against pattern: " + pattern4 + " on uri: " + uri2, 0, ResourceRegistry.matchUri(pattern4, uri2));
assertEquals("wrong match against pattern: " + pattern4 + " on uri: " + uri3, 0, ResourceRegistry.matchUri(pattern4, uri3));
assertEquals("wrong match against pattern: " + pattern4 + " on uri: " + uri4, 0, ResourceRegistry.matchUri(pattern4, uri4));
InternalUriPatternException e1 = assertThrows("No exception from uri: \" + uri4", InternalUriPatternException.class, () -> ResourceRegistry.matchUri(pattern5, uri1));
InternalUriPatternException e2 = assertThrows("No exception from uri: \" + uri4", InternalUriPatternException.class, () -> ResourceRegistry.matchUri(pattern5, uri2));
InternalUriPatternException e3 = assertThrows("No exception from uri: \" + uri4", InternalUriPatternException.class, () -> ResourceRegistry.matchUri(pattern5, uri3));
InternalUriPatternException e4 = assertThrows("No exception from uri: \" + uri4", InternalUriPatternException.class, () -> ResourceRegistry.matchUri(pattern5, uri4));
assertTrue("Wrong exceptionmessage from uri: " + uri1, e1.getMessage().contains("Wildcard is only allowed on pattern ending"));
assertTrue("Wrong exceptionmessage from uri: " + uri2, e2.getMessage().contains("Wildcard is only allowed on pattern ending"));
assertTrue("Wrong exceptionmessage from uri: " + uri3, e3.getMessage().contains("Wildcard is only allowed on pattern ending"));
assertTrue("Wrong exceptionmessage from uri: " + uri4, e4.getMessage().contains("Wildcard is only allowed on pattern ending"));
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUriPatternException in project mule-coap-connector by teslanet-nl.
the class ResourceRegistryStaticMethodsTest method testUriHasWildcard.
@Test
public void testUriHasWildcard() throws InvalidResourceUriException, InternalUriPatternException {
String uri1 = "/*";
String uri2 = "/resource1/*";
String uri3 = "/resource1/resource2/*";
// actually not supported:
String uri4 = "/*/resource4";
String uri5 = "/resource1";
String uri6 = "/resource1/resource2";
String uri7 = "/resource1/resource2/resource3";
String uri8 = "/resource1/resource4";
assertTrue("got wrong wildcard flag from uri: " + uri1, ResourceRegistry.uriHasWildcard(uri1));
assertTrue("got wrong wildcard flag from uri: " + uri2, ResourceRegistry.uriHasWildcard(uri2));
assertTrue("got wrong wildcard flag from uri: " + uri3, ResourceRegistry.uriHasWildcard(uri3));
InternalUriPatternException e = assertThrows("No exception from uri: \" + uri4", InternalUriPatternException.class, () -> {
ResourceRegistry.uriHasWildcard(uri4);
});
assertTrue("Wrong exceptionmessage from uri: " + uri4, e.getMessage().contains("Wildcard is only allowed on pattern ending"));
assertFalse("got wrong wildcard flag from uri: " + uri5, ResourceRegistry.uriHasWildcard(uri5));
assertFalse("got wrong wildcard flag from uri: " + uri6, ResourceRegistry.uriHasWildcard(uri6));
assertFalse("got wrong wildcard flag from uri: " + uri7, ResourceRegistry.uriHasWildcard(uri7));
assertFalse("got wrong wildcard flag from uri: " + uri8, ResourceRegistry.uriHasWildcard(uri8));
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUriPatternException in project mule-coap-connector by teslanet-nl.
the class ResourceRegistryStaticMethodsTest method testInvalidUriPattern.
@Test
public void testInvalidUriPattern() throws InvalidResourceUriException, InternalUriPatternException {
String uri1 = "/*";
String uri2 = "/resource1/*";
String uri3 = "/resource1/resource2/*";
// actually not supported:
String uri4 = "/*/resource4";
String uri5 = "/resource1";
String uri6 = "/resource1/resource2";
String uri7 = "/resource1/resource2/resource3";
String uri8 = "/resource1/resource4";
assertTrue("got wrong wildcard flag from uri: " + uri1, ResourceRegistry.uriHasWildcard(uri1));
assertTrue("got wrong wildcard flag from uri: " + uri2, ResourceRegistry.uriHasWildcard(uri2));
assertTrue("got wrong wildcard flag from uri: " + uri3, ResourceRegistry.uriHasWildcard(uri3));
InternalUriPatternException e = assertThrows("No exception from uri: \" + uri4", InternalUriPatternException.class, () -> {
ResourceRegistry.uriHasWildcard(uri4);
});
assertTrue("Wrong exceptionmessage from uri: " + uri4, e.getMessage().contains("Wildcard is only allowed on pattern ending"));
assertFalse("got wrong wildcard flag from uri: " + uri5, ResourceRegistry.uriHasWildcard(uri5));
assertFalse("got wrong wildcard flag from uri: " + uri6, ResourceRegistry.uriHasWildcard(uri6));
assertFalse("got wrong wildcard flag from uri: " + uri7, ResourceRegistry.uriHasWildcard(uri7));
assertFalse("got wrong wildcard flag from uri: " + uri8, ResourceRegistry.uriHasWildcard(uri8));
}
Aggregations