Search in sources :

Example 1 with RestEngineSchemaListener

use of org.apache.servicecomb.common.rest.RestEngineSchemaListener in project incubator-servicecomb-java-chassis by apache.

the class TestCseClientHttpRequest method testNormal.

@Test
public void testNormal() throws IOException {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    UnitTestMeta meta = new UnitTestMeta();
    CseContext.getInstance().getSchemaListenerManager().setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(SpringmvcImpl.class);
    CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);
    Holder<Invocation> holder = new Holder<>();
    CseClientHttpRequest client = new CseClientHttpRequest(URI.create("cse://app:test/" + SpringmvcImpl.class.getSimpleName() + "/bytes"), HttpMethod.POST) {

        /**
         * {@inheritDoc}
         */
        @Override
        protected Response doInvoke(Invocation invocation) {
            holder.value = invocation;
            return Response.ok("result");
        }
    };
    byte[] body = "abc".getBytes();
    client.setRequestBody(body);
    client.execute();
    Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
}
Also used : RestEngineSchemaListener(org.apache.servicecomb.common.rest.RestEngineSchemaListener) UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) Invocation(org.apache.servicecomb.core.Invocation) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Holder(javax.xml.ws.Holder) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Test(org.junit.Test)

Aggregations

Holder (javax.xml.ws.Holder)1 RestEngineSchemaListener (org.apache.servicecomb.common.rest.RestEngineSchemaListener)1 Invocation (org.apache.servicecomb.core.Invocation)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 UnitTestMeta (org.apache.servicecomb.core.unittest.UnitTestMeta)1 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)1 Test (org.junit.Test)1