Search in sources :

Example 11 with JSONObject

use of org.jose4j.json.internal.json_simple.JSONObject in project open-ecard by ecsec.

the class TestRealVersionUpdate method versionUpdateinvalidSemanticVersionSpecified.

@Test(enabled = true)
public void versionUpdateinvalidSemanticVersionSpecified() {
    try {
        String invalidVersion = "0.0.0";
        JSONObject obj = new JSONObjectBuilder().version(invalidVersion).build();
        VersionUpdate update = VersionUpdate.fromJson(obj);
        // Exception expected
        Assert.fail();
    } catch (InvalidUpdateDefinition ex) {
        Assert.assertEquals(ex.getMessage(), "Invalid version specified.");
    }
}
Also used : JSONObject(org.jose4j.json.internal.json_simple.JSONObject) InvalidUpdateDefinition(org.openecard.common.util.InvalidUpdateDefinition) Test(org.testng.annotations.Test)

Example 12 with JSONObject

use of org.jose4j.json.internal.json_simple.JSONObject in project service-proxy by membrane.

the class GenericJsonParserTest method testChildElement.

@Test
public void testChildElement() {
    JSONObject spec = new JSONObject(new HashMap<String, Object>() {

        {
            put("path", new HashMap<String, Object>() {

                {
                    put("isRegExp", true);
                    put("value", "/abb");
                }
            });
        }
    });
    ServiceProxy sp = GenericJsonParser.parse(ServiceProxy.class, spec);
    assertTrue(sp.getPath().isRegExp());
    assertEquals("/abb", sp.getPath().getValue());
}
Also used : JSONObject(org.jose4j.json.internal.json_simple.JSONObject) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) HashMap(java.util.HashMap) JSONObject(org.jose4j.json.internal.json_simple.JSONObject) Test(org.junit.Test)

Example 13 with JSONObject

use of org.jose4j.json.internal.json_simple.JSONObject in project service-proxy by membrane.

the class GenericJsonParserTest method testAttributeBoolean.

@Test
public void testAttributeBoolean() {
    JSONObject spec = new JSONObject(new HashMap<String, Object>() {

        {
            put("blockRequest", true);
        }
    });
    ServiceProxy sp = GenericJsonParser.parse(ServiceProxy.class, spec);
    assertTrue(sp.isBlockRequest());
}
Also used : JSONObject(org.jose4j.json.internal.json_simple.JSONObject) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) JSONObject(org.jose4j.json.internal.json_simple.JSONObject) Test(org.junit.Test)

Example 14 with JSONObject

use of org.jose4j.json.internal.json_simple.JSONObject in project service-proxy by membrane.

the class GenericJsonParserTest method testMultipleChildElements.

@Test
public void testMultipleChildElements() {
    JSONObject spec = new JSONObject(new HashMap<String, Object>() {

        {
            put("interceptors", Arrays.asList(new HashMap<String, Object>() {

                {
                    put("groovy", new HashMap<String, Object>() {

                        {
                            put("src", "println()");
                        }
                    });
                }
            }, new HashMap<String, Object>() {

                {
                    put("target", new HashMap<String, Object>() {

                        {
                            put("host", "localhost");
                            put("port", 8080);
                        }
                    });
                }
            }));
        }
    });
    ServiceProxy sp = GenericJsonParser.parse(ServiceProxy.class, spec);
    assertEquals(2, sp.getInterceptors().size());
    assertTrue(sp.getInterceptors().get(0) instanceof GroovyInterceptor);
    assertEquals("println()", ((GroovyInterceptor) sp.getInterceptors().get(0)).getSrc());
    assertTrue(sp.getInterceptors().get(1) instanceof AbstractServiceProxy.Target);
    assertEquals("localhost", ((AbstractServiceProxy.Target) sp.getInterceptors().get(1)).getHost());
    assertEquals(8080, ((AbstractServiceProxy.Target) sp.getInterceptors().get(1)).getPort());
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) JSONObject(org.jose4j.json.internal.json_simple.JSONObject) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) GroovyInterceptor(com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor) HashMap(java.util.HashMap) JSONObject(org.jose4j.json.internal.json_simple.JSONObject) Test(org.junit.Test)

Example 15 with JSONObject

use of org.jose4j.json.internal.json_simple.JSONObject in project service-proxy by membrane.

the class GenericJsonParserTest method testChildElements.

@Test
public void testChildElements() {
    JSONObject spec = new JSONObject(new HashMap<String, Object>() {

        {
            put("interceptors", Collections.singletonList(new HashMap<String, Object>() {

                {
                    put("groovy", new HashMap<String, Object>() {

                        {
                            put("src", "println()");
                        }
                    });
                }
            }));
        }
    });
    ServiceProxy sp = GenericJsonParser.parse(ServiceProxy.class, spec);
    assertFalse(sp.getInterceptors().isEmpty());
    assertEquals("println()", ((GroovyInterceptor) sp.getInterceptors().get(0)).getSrc());
}
Also used : JSONObject(org.jose4j.json.internal.json_simple.JSONObject) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) HashMap(java.util.HashMap) JSONObject(org.jose4j.json.internal.json_simple.JSONObject) Test(org.junit.Test)

Aggregations

JSONObject (org.jose4j.json.internal.json_simple.JSONObject)31 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 Test (org.testng.annotations.Test)10 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)7 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)7 URI (java.net.URI)6 InvalidUpdateDefinition (org.openecard.common.util.InvalidUpdateDefinition)6 Http2Client (com.networknt.client.Http2Client)5 ApiException (com.networknt.exception.ApiException)5 ClientException (com.networknt.exception.ClientException)5 ClientConnection (io.undertow.client.ClientConnection)5 ClientRequest (io.undertow.client.ClientRequest)5 ClientResponse (io.undertow.client.ClientResponse)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 URL (java.net.URL)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 GroovyInterceptor (com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor)3 IOException (java.io.IOException)2